text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
import math
n=int(input())
arr=list(map(int,input().split()))
summ=sum(arr)
ans=math.ceil(summ/(n-1))
print(max(max(arr),ans))
```
Yes
| 103,200 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
def ceil(x):
if int(x) != x:
return int(x+1)
else:
return int(x)
def mafia():
n = int(input())
rounds = list(map(int, str(input()).split()))
count = 0
rounds.sort(reverse=True)
for i in range(n-1, 0, -1):
if rounds[i-1] == rounds[i]:
continue
else:
steps = n - i
count += steps*(rounds[i-1] - rounds[i])
rounds[0] -= count
if rounds[0] > 0:
k = ceil(rounds[0] / (n - 1))
count += n * k
rounds[0] += k * (1 - n)
if rounds[0] <= 0:
count += rounds[0]
print(count)
if __name__ == '__main__':
mafia()
```
Yes
| 103,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=1000000007
def value():return tuple(map(float,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
def possible(x):
have=0
for i in a:
have+=x-i
# print(have)
return have>=x
n=Int()
a=sorted(array())
# print(a)
low=max(a)
high=10**15
ans=0
while(low<=high):
mid=low+(high-low)//2
if(possible(mid)):
ans=mid
high=mid-1
else:
low=mid+1
print(ans)
```
Yes
| 103,202 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
n = int(input())
a = [int(s) for s in input().split()]
sum, b = 0, 0
for i in a:
b = max(b, i)
sum += i
l, r = 1, 2 * b
while l < r:
m = (l + r) // 2
if n * m - sum >= m:
r = m
else:
l = m + 1
print(l)
```
No
| 103,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
n = int(input())
sa = sum((int(x) for x in input().split()))
res = (sa+(n-2))//(n-1)
print(res)
```
No
| 103,204 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
n = int(input())
ar = list(map(int,input().split()))
sm = sum(ar)
mnr = (sm - 1) // (n-1) + 1
print(mnr)
```
No
| 103,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer n (3 β€ n β€ 105). The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the i-th number in the list is the number of rounds the i-th person wants to play.
Output
In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
Note
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
Submitted Solution:
```
v = int(input())
l = list(map(int, input().split()))
c = sum(l)
if c % (v - 1) == 0:
print(c // (v - 1))
else:
print(c // (v - 1) + 1)
```
No
| 103,206 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
# https://codeforces.com/problemset/problem/394/A
# A. Counting Sticks
input_str = input()
b1, b2, b3 = 0, 0, 0
in_b1, in_b2 = True, False
for x in input_str:
if x == '|':
if in_b1:
b1 += 1
elif in_b2:
b2 += 1
else:
b3 += 1
elif x == '+':
in_b1, in_b2 = False, True
else:
in_b2 = False
if b1 + b2 == b3:
pass
elif b1 + b2 == b3 + 2:
if b1 > 1:
b1 -= 1
else:
b2 -= 1
b3 += 1
elif b1 + b2 + 2 == b3:
b2 += 1
b3 -= 1
else:
print("Impossible")
exit()
print('|' * b1 + '+' + '|' * b2 + '=' + b3 * '|')
```
| 103,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
s = input()
p = s.find('+')
r = s.find('=')
if r - 1 == len(s) - r - 1:
print(s)
exit(0)
if abs((r - 1) - (len(s) - r - 1)) != 2:
print('Impossible')
exit(0)
if (r - 1) > (len(s) - r - 1):
if p != 1:
print(s[1:] + s[0])
else:
print('|+' + '|' * (r - 3) + '=' + '|' * (len(s) - r))
else:
print(s[-1] + s[:-1])
```
| 103,208 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
org = input()
S = org.split("+")
A = S[0].count("|")
S = S[1].split("=")
B = S[0].count("|")
C = S[1].count("|")
if (A+B) - C == -2:
print("|"*(A+1) + "+"+ "|"*B + "=" +"|"*(C-1))
elif (A+B) - C == 2:
if A > 1:
print("|"*(A-1) + "+"+ "|"*B + "=" +"|"*(C+1))
else:
print("|"*A + "+"+ "|"*(B-1) + "=" +"|"*(C+1))
elif A+B == C:
print(org)
else:
print("Impossible")
```
| 103,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
str = input()
i = 0
A = str.split('+')[0].count('|')
A_ = str.split('+')[1]
B = A_.split('=')[0].count('|')
C = A_.split('=')[1].count('|')
if A + B == C:
print(str)
else:
if A + 1 + B == C - 1:
print('|' * ( A + 1 ) + '+' + '|' * B + '=' + '|' * ( C - 1 ) )
elif A + B - 1 == C + 1:
if A - 1 <= 0:
print('|' * A + '+' + '|' * ( B - 1 ) + '=' + '|' * (C + 1))
else:
print('|' * (A - 1) + '+' + '|' * B + '=' + '|' * (C + 1))
else:
print('Impossible')
```
| 103,210 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
from sys import stdin
a=list(stdin.readline())
a.pop()
cont=0
pos=0
cont1=0
cont2=0
while(a[pos]!="+"):
cont=cont+1
pos=pos+1
pos+=1
while(a[pos]!="="):
cont2=cont2+1
pos=pos+1
pos=-1
while(a[pos]!="="):
cont1=cont1+1
pos=pos-1
if((cont+cont2)<cont1):
del(a[-1])
a.insert(0, "|")
cont=cont+1
cont1=cont1-1
elif((cont+cont2)>cont1):
del(a[0])
a.insert(-1, "|")
cont=cont-1
cont1=cont1+1
if (cont==0)and(cont2>1):
cont2=cont2-1
cont=cont+1
if(cont2==0)and(cont>1):
cont2=cont2+1
cont=cont-1
if((cont+cont2)<cont1)or((cont+cont2)>cont1):
print("Impossible")
elif((cont+cont2)==cont1):
print(("|"*cont)+"+"+("|"*cont2)+"="+("|"*cont1))
```
| 103,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
v = input().split('+')
a = len(v[0])
v = v[1].split('=')
b = len(v[0])
c = len(v[1])
def good(a, b, c):
return a+b==c and a>0 and b>0 and c>0
if good(a-1, b, c+1):
a = a-1
c = c+1
if good(a, b-1, c+1):
b = b-1
c = c+1
if good(a+1, b, c-1):
a = a+1
c = c-1
if good(a, b+1, c-1):
b = b+1
c = c-1
if a+b==c:
print('|'*a+'+'+'|'*b+'='+'|'*c)
else:
print("Impossible")
```
| 103,212 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
class CodeforcesTask394ASolution:
def __init__(self):
self.result = ''
self.expression = ''
def read_input(self):
self.expression = input()
def process_task(self):
expr = self.expression.split("=")
c = len(expr[1])
a = len(expr[0].split("+")[0])
b = len(expr[0].split("+")[1])
# print(a, b, c)
diff = abs((a + b) - c)
if diff == 0 or diff == 2:
if c > a + b:
a += 1
c -= 1
self.result = "|" * a + "+" + "|" * b + "=" + "|" * c
elif not diff:
self.result = self.expression
elif a + b > 2:
if a > 1:
a -= 1
else:
b -= 1
c += 1
self.result = "|" * a + "+" + "|" * b + "=" + "|" * c
else:
self.result = "Impossible"
else:
self.result = "Impossible"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask394ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
```
| 103,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Tags: brute force, implementation
Correct Solution:
```
s = input()
ind = s.index('=')
left, right = s[:ind], s[ind+1:]
ind = left.index('+')
a, b = left[:ind], left[ind+1:]
A, B, C = len(a), len(b), len(right)
if abs(1 - abs(A + B - C)) != 1:
print('Impossible')
exit()
if A + B == C:
print(s)
exit()
if A + B + 1 == C - 1:
print((A + 1) * '|' + '+' + B * '|' + '=' + (C - 1) * '|')
exit()
if A + B - 1 == C + 1:
if 1 < A >= B:
print((A - 1) * '|' + '+' + B * '|' + '=' + (C + 1) * '|')
exit()
if A < B > 1:
print(A * '|' + '+' + (B - 1) * '|' + '=' + (C + 1) * '|')
exit()
```
| 103,214 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
#! /usr/bin/python
def sol():
z = input()
a = z.split('+')
b = list(map(len, [a[0]] + a[1].split('=')))
a, b, c = b
if (a + b == c):
# do nothing
pass
elif (a + b == c - 2):
c -= 1
a += 1
elif (a + b == c + 2):
if a == 1:
b -= 1
c += 1
else:
a -= 1
c += 1
else:
print("Impossible")
return
exp = ""
for i in range(a):
exp += '|'
exp += '+'
for i in range(b):
exp += '|'
exp += '='
for i in range(c):
exp += '|'
print(exp)
sol()
```
Yes
| 103,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
x = input()
y = list(x)
a = len(y[:y.index('+')])
b = len(y[y.index('+')+1:y.index('=')])
c = len(y[y.index('=')+1:])
if a + b == c:
print(x)
elif a+b+1 == c-1:
print((a+1)*'|' + '+' + b*'|' + '=' + (c-1)*'|')
elif a+b-1 == c+1 and a>1:
print((a-1)*'|' + '+' + b*'|' + '=' + (c+1)*'|')
elif a+b-1 == c+1 and b>1:
print((a)*'|' + '+' + (b-1)*'|' + '=' + (c+1)*'|')
else:
print('Impossible')
```
Yes
| 103,216 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
a, b =input().split('+')
c,d = b.split('=')
if (len(a)+len(c))==len(d):
print(a+"+"+c+"="+d)
elif len(d)!=1 and (len(a)+len(c)+1)==len(d)-1:
print(a+"+"+c+"|"+"="+d[:-1])
elif len(c)!=1 and (len(a)+len(c)-1)==len(d)+1:
print(a+"+"+c[:-1]+"="+d+"|")
elif len(a)!=1 and (len(a)-1+len(c))==len(d)+1:
print(a[:-1]+"+"+c+"="+d+"|")
else:
print("Impossible")
```
Yes
| 103,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
s = input()
n = len(s)
i = s.find('=')
l = s[0:i].count('|')
r = s[i:n].count('|')
if (l == r):
print(s)
else:
k = s.find("||")
if (l-r == 2):
print(s[0:k] + s[k+1:n] + '|')
elif (l-r == -2):
print(s[0:i] + '|' + s[i:n-1])
else:
print("Impossible")
```
Yes
| 103,218 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
s=input()
s1=s[:s.index('+')]
s2=s[s.index('+')+1:s.index('=')]
s3=s[s.index('=')+1:]
s1=s1.replace(' ','')
s2=s2.replace(' ','')
s3=s3.replace(' ','')
#print(s1,s2,s3)
l=len(s2)+len(s1)
#print(l,len(s3))
if(l==len(s3)):
print(s)
elif(abs(len(s3)-l)<=2):
if l<len(s3):
s1=list(s1)
s1.append('|')
s3=list(s3)
s3.remove('|')
#print(s1,s3)
else:
s3=list(s3)
s3.remove('|')
s1=list(s1)
s1.append('|')
#print(s1,s3)
if (len(s1)+len(s2))==len(s3):
s1=''.join(s1)
s2=''.join(s2)
s3=''.join(s3)
print(s1+' '+'+'+' '+s2+' = '+s3)
else:
print('Impossible')
else:
print('Impossible')
```
No
| 103,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
IN=input().split('=')
a,b=IN[0].split('+')
c=IN[1]
if len(a) + len (b) + 1 == len(c) - 1 :
a = '|' + a
c=c.replace('|','',1)
print(f'{a}+{b}={c}')
elif len(a) + len (b) -1 == len(c) + 1:
if len(a) == len(b) == 1 :
print('Impossible')
elif len(a) == 1 :
c = '|' + c
b=b.replace('|','',1)
elif len(b)==1 :
c = '|' + c
a=a.replace('|','',1)
print(f'{a}+{b}={c}')
elif len(a) +len(b) == len(c):
print(f'{a}+{b}={c}')
elif (len(a)+len(b))-len(c) > 1 or len(c)-(len(a)+len(b)) > 1 :
print('Impossible')
else :
print('Impossible')
```
No
| 103,220 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
array_input = input()
first_split = array_input.split('=')
after_equal = first_split[1]
# print('first_equal -> ')
# print(first_split[1])
second_split = (first_split[0]).split('+')
# print('second_split -> ')
# print(second_split)
first_operand = second_split[0]
second_operand = second_split[1]
list_operands = [first_operand, second_operand, after_equal]
number_of_sticks = [0,0,0]
for counter in range(0,len(list_operands)):
number_of_sticks[counter] = list_operands[counter].count('|')
# print('number_of_sticks')
# print(number_of_sticks)
if abs((number_of_sticks[0] + number_of_sticks[1]) - number_of_sticks[2]) > 2:
print('Impossible')
elif number_of_sticks[2] > (number_of_sticks[0] + number_of_sticks[1]):
number_of_sticks[2]-=1
number_of_sticks[0]+=1
the_string = '|' * number_of_sticks[0]
the_string += '+'
the_string += '|' * number_of_sticks[1]
the_string += '='
the_string += '|' * number_of_sticks[2]
# print('the string -> ')
print(the_string)
# print('|' * number_of_sticks[0] + '+' + '|' * number_of_sticks[1]+1 + '=' + '|' * number_of_sticks[2]-1)
```
No
| 103,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? β That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
[ A sticks][sign +][B sticks][sign =][C sticks] (1 β€ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 β€ A, B, C β€ 100.
Output
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Examples
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
Submitted Solution:
```
s1=input()
list(s1)
# print(s1)
a=s1.index('+')
b=s1.index('=')
c=len(s1)
block1=a
block2=b-a-1
block3=c-b-1
# print(block1)
# print(block2)
# print(block3)
if block1+block2 == block3:
print(''.join(str(i) for i in s1))
elif block3 == block1+block2+2:
s2=[]
s2.append('|')
for i in s1:
s2.append(i)
s2.pop()
print(''.join(str(i) for i in s2))
else:
print("Impossible")
```
No
| 103,222 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
n = int(input())
p = 0
a = []
for _ in range(n):
x, k = list(map(int, input().split()))
while k > len(a):
a.append(-1)
k = k - 1
if a[k] < x - 1:
print('NO')
exit()
else:
a[k] = max(x, a[k])
print('YES')
```
| 103,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
def readln(): return tuple(map(int, input().split()))
n, = readln()
max_pref = [-1] * 100001
flag = True
for _ in range(n):
x, k = readln()
flag &= max_pref[k] + 1 >= x
max_pref[k] = max(max_pref[k], x)
print('YES' if flag else 'NO')
```
| 103,224 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
c = [0] * 100001
for i in range(int(input())):
x, k = map(int, input().split())
if x == c[k]:
c[k] += 1
elif x > c[k]:
print('NO')
exit()
print('YES')
```
| 103,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
d = [0] * 100001
for _ in range(int(input())):
v, k = map(int, input().split())
if v > d[k]:
print('NO')
exit()
elif v == d[k]:
d[k] += 1
print('YES')
```
| 103,226 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
n = int(input())
a = [-1]*100001
p = 0
for i in range(n):
x, k = map(int, input().split())
if a[k] < x-1:
p = 1
else:
a[k] = max(a[k],x)
if p:
print('NO')
else:
print('YES')
```
| 103,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
from collections import deque
for _ in range(1):
n = int(input())
visited = set()
flag = 1
for i in range(n):
x,k = map(int,input().split())
if x == 0:
visited.add((x,k))
else:
if (x-1,k) in visited:
visited.add((x, k))
else:
flag = 0
if flag:
print("YES")
else:
print("NO")
```
| 103,228 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
data = {}
for _ in range(int(input())):
x, k = map(int, input().split())
if k in data:
data[k].append(x)
else:
data[k] = [x]
flag = True
for counts in data.values():
allowed = 0
for count in counts:
if count > allowed:
flag = False
break
if count == allowed:
allowed += 1
if not flag:
break
print(['NO', 'YES'][flag])
```
| 103,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Tags: implementation
Correct Solution:
```
#the basic idea is to use a dict to record every participant's submission
n = int(input())
participants = {}
order = True
while n:
n -= 1
x, k = map(int,input().split())
if k in participants:
if x in participants[k]:
continue
elif x-1 in participants[k]:
participants[k].add(x)
else:
order = False
break
else:
if x != 0:
order = False
break
tmp = set()
tmp.add(x)
participants[k] = tmp
if order:
print("YES")
else:
print("NO")
```
| 103,230 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
n = int(input())
m = []
d = dict()
for i in range(n):
x, k = map(int, input().split())
if k in d:
r = d[k]
if x > r+1:
print('NO')
exit()
d[k] = max(r, x)
else:
if x != 0:
print('NO')
exit()
d[k] = x
print('YES')
```
Yes
| 103,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
sol=int(input())
list1=[]
for i in range(10**5+1):
list1.append([])
for i in range(sol):
a,b=input().split()
b=int(b)
list1[b].append(a)
i=0
v=True
while i<10**5+1 and v:
j=0
z=-1
while j<len(list1[i]) and v:
if (int(list1[i][j])-z)==1:
z=int(list1[i][j])
elif int(list1[i][j])-z>1:
v=False
j+=1
i+=1
if v==True:
print("YES")
else:
print("NO")
```
Yes
| 103,232 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
all = {}
n = int(input())
ans = True
for i in range(n):
x_k = input().split()
x = int(x_k[0])
k = int(x_k[1])
if k not in all:
all[k] = -1
if all[k] >= x:
pass
elif all[k]+1 != x:
ans = False
break
else:
all[k] = x
if ans:
print("YES")
else:
print("NO")
```
Yes
| 103,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
import sys
n = int(input())
c = [-1] * (10**5+1)
for i in range(n):
x,k = map(int,input().split())
if c[k] < x-1:
print("NO")
sys.exit()
else:
c[k] = max(c[k],x)
print("YES")
```
Yes
| 103,234 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
n,q,t=int(input()),{},0
for i in range(n):
a,x=map(int,input().split())
if a not in q:q[a]=[x]
else:q[a].append(x)
for i in q:
k=list(q[i])
q[i].sort()
if k!=q[i]:
t=1
break
print(["YES","NO"][t])
```
No
| 103,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
from collections import OrderedDict
all = {}
n = int(input())
for i in range(n):
x_k = input().split()
x = int(x_k[0])
k = int(x_k[1])
if k not in all:
all[k] = OrderedDict()
all[k][x] = True
# print("new", k, all[k])
else:
all[k][x] = True
# print("old", k, all[k])
def check(dic):
l = []
for x in dic:
l.append(x)
el = l[0]
for i in range(1, len(l)):
if l[i] < el:
return False
else:
el = l[i]
continue
return True
ans = True
for x in all:
if check(all[x]):
continue
else:
ans = False
if ans:
print("YES")
else:
print("NO")
```
No
| 103,236 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
import sys
from collections import defaultdict
n = int(sys.stdin.readline())
d = defaultdict(lambda:-1)
for i in range(0, n):
x, k = map(int, sys.stdin.readline().split())
z = d[k]
if x == z + 1:
d[k] = x
else:
print('NO')
sys.exit(0)
print('YES')
```
No
| 103,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x β the number of different solutions that are sent before the first solution identical to A, and k β the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 β€ n β€ 105) β the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 β€ x β€ 105; 1 β€ k β€ 105) β the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain Β«YESΒ» if the data is in chronological order, and Β«NOΒ» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
from collections import OrderedDict
all = {}
n = int(input())
ans = True
for i in range(n):
x_k = input().split()
x = int(x_k[0])
k = int(x_k[1])
if k not in all:
all[k] = x
# print("new", k, all[k])
elif all[k] > x:
continue
elif all[k]+1 != x:
ans = False
break
# print("old", k, all[k])
if ans:
print("YES")
else:
print("NO")
```
No
| 103,238 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
Input
The first line contains a single integer n (1 β€ n β€ 5Β·105) β the number of elements in the array. The next line contains n integers ai (1 β€ ai β€ 106) β the values of the array elements.
Output
In a single line print a single integer β the maximum number of points Artem can get.
Examples
Input
5
3 1 5 2 6
Output
11
Input
5
1 2 3 4 5
Output
6
Input
5
1 100 101 100 1
Output
102
Tags: data structures, greedy
Correct Solution:
```
n = input()
s = []
a = 0
for i in map(int, input().split()):
while len(s) > 1 and min(s[-2], i)>=s[-1]:
a += min(i, s[-2])
del(s[-1])
s.append(i)
s.sort()
print(a + sum(s[0: -2]))
```
| 103,239 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
import sys
def check_first(n, m, a):
ans = 0
while n > 0:
n-=1
ans+=a
return ans
def check_second(n, m, a, b):
ans = 0
if b < a:
while n > 0:
n-=m
ans+=b
return ans
else:
while n > 0:
if n - m >= 0:
n-=m
ans+=b
else:
n-=1
ans+=a
return ans
def main():
n, m, a, b = map(int, sys.stdin.readline().split())
if m > n and n!=1:
sys.stdout.write(f'{b}')
else:
sys.stdout.write(f'{min(check_first(n,m,a), check_second(n,m,a,b))}')
if __name__ == '__main__':
main()
```
| 103,240 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
n,m,a,b = map(int,input().split())
per_ride_single = a
per_ride_multiple = b/m
if per_ride_single<=per_ride_multiple:
rides = n*per_ride_single
else:
left_rides = n%m
rides =int(n/m)*b + min(left_rides*per_ride_single,b)
print(rides)
```
| 103,241 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
import math
n_trips, n_card, cost_trip, cost_card = [int(s) for s in input().split()]
if cost_card / n_card >= cost_trip:
print(n_trips * cost_trip)
else:
min_cost = min(math.ceil(n_trips / n_card) * cost_card,
n_trips // n_card * cost_card + (n_trips - n_trips // n_card * n_card) * cost_trip)
print(min_cost)
```
| 103,242 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
w = input().split(' ')
n = int(w[0])
m = int(w[1])
a = int(w[2])
b = int(w[3])
s = 0
if (b/m) > a:
print(a*n)
else:
while n >= m:
n -= m
s += b
if a*n < b:
s += a*n
else:
s += b
print(s)
```
| 103,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
n,m,a,b=map(int, input().split(' '))
if(m*a<=b):
print(n*a)
else:
ans=0
ans+=(n//m)*b+min((n%m)*a,b)
print(ans)
```
| 103,244 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
# coding=utf-8
if __name__ == '__main__':
n, m, a, b = str(input()).split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if n % m == 0:
print(min(int(n * a), int(n / m) * b))
else:
print(min(int(n * a), int(n / m + 1) * b, int(n / m) * b + (n - int(n / m) * m) * a))
```
| 103,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
nmab=input().split()
n,m,a,b=int(nmab[0]),int(nmab[1]),int(nmab[2]),int(nmab[3])
cc=(n//m)*b+(n%m)*a
scc=(n//m+1)*b
sc=n*a
for i in range(3):
if cc<=sc and cc<scc:
print(cc)
break
if scc<=cc and scc<=sc:
print(scc)
break
else:
print(sc)
break
```
| 103,246 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Tags: implementation
Correct Solution:
```
n, m, a, b = input().split()
n, m, a, b = [int (x) for x in [n, m, a, b]]
if m * a > b:
print (min ((n // m * b + (n % m) * a), (n // m + 1) * b))
else:
print (n * a)
```
| 103,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
s=input()
x=list()
x=s.split()
n,m,a,b=int(x[0]),int(x[1]),int(x[2]),int(x[3])
p=b/m
if p<a:
print(int(n/m)*b+min((n%m)*a,b))
else:
print(n*a)
```
Yes
| 103,248 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
from math import ceil
n,m,a,b=map(int,input().split())
x=[n*a,(ceil(n/m))*b,(n//m)*b+(n%m)*a,(n//m)*b+(n%m)*b]
print(min(x))
```
Yes
| 103,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
#Consistency is the key.
#code by: amrit2000
from sys import stdin,stdout
import math
input=stdin.readline
def print(x='',y='',end='\n'):
if y=='':
stdout.write(str(x)+end)
else:
stdout.write(str(x)+' '+str(y)+end)
def solve():
n,m,a,b=map(int,input().split())
if b//m<a:
print((n//m)*b +min(math.ceil((n-m*(n//m))/m)*b,(n-m*(n//m))*a))
else:
print(n*a)
tt=1
#tt=int(input())
for __ in range(tt):
solve()
```
Yes
| 103,250 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
def arr_inp():
return [int(x) for x in stdin.readline().split()]
from sys import stdin
from math import ceil
n, m, a, b = arr_inp()
print(min((n // m) * b + (n % m) * a, ceil(n / m) * b, a * n))
```
Yes
| 103,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
# input consists of n, m, a, b
args = [int(a) for a in input().strip().split()]
num_rides, num_special_rides, one_ticket_price, special_ticket_price = args
# if the special tickets cost more per ride...
if one_ticket_price <= special_ticket_price / num_special_rides:
print(one_ticket_price * num_rides)
# if special tickets don't cost more...
# find out how many special tickets you can actually buy...
# and calculate if you should buy another special_ticket for the remainder
else:
print("here")
special_bought, remainder = divmod(num_rides, num_special_rides)
total_spent = special_bought * special_ticket_price
# check if you should buy another special_ticket
if remainder * one_ticket_price > special_ticket_price:
total_spent += remainder * one_ticket_price
else:
total_spent += special_ticket_price
print(total_spent)
```
No
| 103,252 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
if __name__ == "__main__":
n, m, a, b = map(int, input().split())
tr = 0
if (a*m) >= b:
if m > n:
print(b)
else:
tr = (n//m)*b
n %= m
if n != 0:
if (tr+(a*n)) <= (tr+(b*n)):
tr += (a*n)
else:
tr += (b*n)
print(tr)
else:
print(a*n)
```
No
| 103,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
from sys import stdin, stdout
values = stdin.readline().rstrip().split(' ')
n = int(values[0])
m = int(values[1])
a = int(values[2])
b = int(values[3])
#a_rate is a unit rate already
b_rate = b/m
if a < b_rate:
price = a*m
stdout.write(str(price))
else: # b_rate < a_rate
a_rides = (n%m)
b_rides = ((n-a_rides)/m)
total = (a_rides*a)+(b_rides*b)
stdout.write(str(int((total))))
```
No
| 103,254 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
Input
The single line contains four space-separated integers n, m, a, b (1 β€ n, m, a, b β€ 1000) β the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Output
Print a single integer β the minimum sum in rubles that Ann will need to spend.
Examples
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
Note
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
Submitted Solution:
```
n,m,a,b = map(int,input().split())
cost =0
if (b/m)<=a:
if (n%m==0):
cost = cost + ((n//m)*b)
else:
x = n//m
y = n%m
cost = (x*b) + (y*a)
else:
cost = (n*a)
print(cost)
```
No
| 103,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Tags: binary search, dp
Correct Solution:
```
import os
import sys
if os.path.exists(r'C:\Users\User\codeforces'):
f = iter(open('A.txt').readlines())
def input():
return next(f).strip()
# input = lambda: sys.stdin.readline().strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
from math import sqrt
n, l = map(int, input().split())
x, b = [0], [0]
for _ in range(n):
u, v = map(int, input().split())
x.append(u)
b.append(v)
prec = [[sqrt(abs(x[p]-x[i]-l)) for i in range(n+1)] for p in range(n+1)]
def check(V):
values = [2*10**9] * (n+1)
values[0] = 0
for i in range(1, n+1):
for p in range(i):
values[i] = min(values[i], values[p] + prec[i][p] - V * b[i])
return values[-1] <= 0
def get(V):
values = [2*10**9] * (n+1)
values[0] = 0
prev = [-1] * (n+1)
for i in range(1, n+1):
for p in range(i):
q = values[p] + prec[i][p] - V * b[i]
if q < values[i]:
prev[i] = p
values[i] = q
res = [n]
while res[-1] != 0:
res.append(prev[res[-1]])
res.pop()
return res
eps = 1e-9
R, L = 10**3+1, 0
while R - L > eps:
# print(R, L)
m = (R+L)/2
if check(m):
R = m
else:
L = m
print(' '.join(map(str, reversed(get(R)))))
```
| 103,256 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Tags: binary search, dp
Correct Solution:
```
import os
import sys
if os.path.exists(r'C:\Users\User\codeforces'):
f = iter(open('A.txt').readlines())
def input():
return next(f).strip()
# input = lambda: sys.stdin.readline().strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
from math import sqrt
n, l = map(int, input().split())
x, b = [0], [0]
for _ in range(n):
u, v = map(int, input().split())
x.append(u)
b.append(v)
def check(V):
values = [2*10**9] * (n+1)
values[0] = 0
for i in range(1, n+1):
for p in range(i):
values[i] = min(values[i], values[p] + sqrt(abs(x[i]-x[p]-l)) - V * b[i])
return values[-1] <= 0
def get(V):
values = [2*10**9] * (n+1)
values[0] = 0
prev = [-1] * (n+1)
for i in range(1, n+1):
for p in range(i):
q = values[p] + sqrt(abs(x[i]-x[p]-l)) - V * b[i]
if q < values[i]:
prev[i] = p
values[i] = q
res = [n]
while res[-1] != 0:
res.append(prev[res[-1]])
res.pop()
return res
eps = 1e-9
R, L = 10**3+1, 0
while R - L > eps:
# print(R, L)
m = (R+L)/2
if check(m):
R = m
else:
L = m
print(' '.join(map(str, reversed(get(R)))))
```
| 103,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Submitted Solution:
```
from math import sqrt
n,l = [int(s) for s in input().split()]
x = [0 for i in range(n+1)]
b = [0 for i in range(n+1)]
for i in range(1,n+1):
xi,bi = [int(s) for s in input().split()]
x[i] = xi
b[i] = bi
cf = [0 for i in range(n+1)]
cb = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(1,n+1):
cf[i] = sqrt(abs(x[i]-l))
cb[i] = b[i]
a[i] = cf[i]/cb[i]
prev = [0 for i in range(n+1)]
for i in range(2,n+1):
for j in range(1,i):
xij = x[i]-x[j]
cftmp = cf[j] + sqrt(abs(xij-l))
cbtmp = cb[j] + b[i]
atmp = cftmp/cbtmp
if atmp<a[i]:
cf[i] = cftmp
cb[i] = cbtmp
a[i] = atmp
prev[i] = j
u = n
path = []
while u!=0:
path.append(u)
u = prev[u]
print(' '.join(map(str,reversed(path))))
```
No
| 103,258 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Submitted Solution:
```
n, l = [int(x) for x in input().split()]
xs, bs = [], []
for k in range(0, n):
x, b = [int(j) for j in input().split()]
xs.append(x)
bs.append(b)
from functools import lru_cache
from math import sqrt
"""
@lru_cache(maxsize=None)
def rec(startpoint):
if startpoint == -1:
x = 0
b = 0
else:
x = xs[startpoint]
b = bs[startpoint]
if startpoint == n-1:
return (0, 0, [])
bestsol = 10**40
# parameters are frustration, picturesqueness AND list of vertices behind this one
bestpar = (0, 0, 0)
for k in range(startpoint+1, n):
rj = xs[k] - x
fru = sqrt(abs(rj - l))
b = bs[k]
recf, recb, recv = rec(k)
sol = (fru + recf) / (b + recb)
if sol < bestsol:
bestsol = sol
bestpar = ((fru + recf), (b + recb), [k] + recv)
return bestpar
a, b, c = rec(0)
print(c)
"""
# let's do the greedy one :D
startpoint = -1
jumps = []
while not startpoint == n-1:
# do the jump which is best
if startpoint == -1:
x, b = 0, 0
else:
x, b = xs[startpoint], bs[startpoint]
bestsol = 10**40
for k in range(startpoint+1, n):
rj = xs[k] - x
fru = sqrt(abs(rj-l))
b = bs[k]
sol = fru / b
if sol < bestsol:
bestsol = sol
bestjump = k
jumps.append(bestjump+1)
startpoint = bestjump
print(' '.join([str(x) for x in jumps]))
```
No
| 103,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Submitted Solution:
```
import math;
sqrt = [math.sqrt(i) for i in range(0, 1000001)];
n, l = (int(s) for s in input().split(' '));
points = [(0, 0)];
for i in range(0, n):
a, b = (int(s) for s in input().split(' '));
points.append((a, b));
EPS = 1e-4;
le = 0.0;
ri = 1e10;
pre = [0 for i in range(0, n + 1)];
def check(k):
f = [1e10 for i in range(0, n + 1)];
f[0] = 0;
for i in range(0, n + 1):
for j in range(i + 1, n + 1):
va = sqrt[abs(l - (points[j][0] - points[i][0]))] - k * points[j][1];
if f[i] + va < f[j]:
f[j] = f[i] + va;
pre[j] = i;
return f[n] < -1e-9;
while ri - le > EPS:
k = (le + ri) / 2.0;
if check(k):
ri = k;
else:
le = k;
check(le);
route = [];
cur = n;
while cur != 0:
route.append(cur);
cur = pre[cur];
for i in reversed(route):
print(i, end = ' ');
print();
```
No
| 103,260 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let's assume that if the traveler covers distance rj in a day, then he feels frustration <image>, and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler's path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 β€ n β€ 1000, 1 β€ l β€ 105) β the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 β€ xi, bi β€ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.
Output
Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.
Examples
Input
5 9
10 10
20 10
30 1
31 5
40 10
Output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <image>.
Submitted Solution:
```
from math import sqrt
n,l = [int(s) for s in input().split()]
x = [0 for i in range(n+1)]
b = [0 for i in range(n+1)]
for i in range(1,n+1):
xi,bi = [int(s) for s in input().split()]
x[i] = xi
b[i] = bi
cf = [0 for i in range(n+1)]
cb = [0 for i in range(n+1)]
a = [0 for i in range(n+1)]
for i in range(1,n+1):
cf[i] = sqrt(abs(x[i]-l))
cb[i] = b[i]
a[i] = cf[i]/cb[i]
prev = [0 for i in range(n+1)]
for i in range(2,n+1):
for j in range(1,i):
xij = x[i]-x[j]
cftmp = cf[j] + sqrt(abs(xij-l))
cbtmp = cb[j] + b[i]
atmp = cftmp/cbtmp
if atmp<a[i]:
cf[i] = cftmp
cb[i] = cbtmp
a[i] = atmp
prev[i] = j
print(a)
print(prev)
for i in range(1,n+1):
for j in range(1,n):
if j!=i:
xij = x[i]-x[j]
cftmp = cf[j] + sqrt(abs(xij-l))
cbtmp = cb[j] + b[i]
atmp = cftmp/cbtmp
if atmp<a[i]:
cf[i] = cftmp
cb[i] = cbtmp
a[i] = atmp
prev[i] = j
print(a)
print(prev)
u = n
path = []
while u!=0:
path.append(u)
u = prev[u]
print(' '.join(map(str,reversed(path))))
```
No
| 103,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
d = [list(map(int, input().split())) for i in range(int(input()))]
s = 0
for k in range(1, 10001):
p = [min(max((k - l) / (r - l + 1), 1e-20), 1) for l, r in d]
u = v = 1
for r in p: u *= r
for r in p:
v *= r
s += (u - v) * (r - 1) / r
print(s)
```
| 103,262 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
n=int(input())
L=[]
for i in range(n):
l,r=map(int, input().split(' '))
L.append([l,r])
for i in range(n,5) :
L.append([0,0])
ans = 0.0
for s in range(1,10001):
P=[0]*5
for i in range(5):
P[i]=max(min((L[i][1]-s+1)/(L[i][1]-L[i][0]+1),1.0),0.0)
P0=1.0
for i in range(5):P0*=(1-P[i])
P1=0.0
for i in range(5):
t=P[i]
for j in range(5) :
if i==j:continue
t*=(1-P[j])
P1+=t
ans+=1.0-P0-P1
print(ans)
```
| 103,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
import sys
MaxV = int(1e4)
data = []
readIdx = 0
for line in sys.stdin.readlines():
data += line.split()
def read():
global readIdx
readIdx += 1
return data[readIdx - 1]
n, average, power, mul = int(read()), 0, 1, 1
froms, tos, r = [], [], []
def generate(i, maxIdx, secondMax, equal, ways):
global n, r
if i < n:
for state in range(3):
if state < 2:
newWays = ways
newEqual = equal
if state == 0:
newWays *= max(0, min(secondMax - 1, tos[i]) + 1 - froms[i])
else:
newEqual += 1
if froms[i] > secondMax or tos[i] < secondMax:
newWays = 0
if newWays > 0:
generate(i + 1, maxIdx, secondMax, newEqual, newWays)
elif maxIdx == None:
greaterFrom = max(secondMax + 1, froms[i])
greaterTo = tos[i]
newWays = ways
if greaterFrom > greaterTo:
newWays = 0
newWays *= max(0, greaterTo + 1 - greaterFrom)
if newWays > 0:
generate(i + 1, i, secondMax, equal, newWays)
elif ways > 0 and ((maxIdx != None and equal > 0) or (maxIdx == None and equal >= 2)):
r += [ways * secondMax]
for i in range(n):
froms += [int(read())]
tos += [int(read())]
power *= 3
mul *= (tos[i] + 1 - froms[i])
for secondMax in range(MaxV + 1):
generate(0, None, secondMax, 0, 1)
print(sum(r) / mul)
```
| 103,264 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
import sys
data = []
readIdx = 0
for line in sys.stdin.readlines():
data += line.split()
def read():
global readIdx
readIdx += 1
return data[readIdx - 1]
n, r, maxValue, power, mul = int(read()), 0, 0, 1, 1
froms, tos = [], []
def generate(i, maxIdx, secondMax, equal, ways):
global n, r
if i < n:
for state in range(3):
if state < 2:
newWays = ways
newEqual = equal
if state == 0:
newWays *= max(0, min(secondMax - 1, tos[i]) + 1 - froms[i])
else:
newEqual += 1
newWays *= (froms[i] <= secondMax and tos[i] >= secondMax)
if newWays > 0:
generate(i + 1, maxIdx, secondMax, newEqual, newWays)
elif maxIdx == None:
greaterFrom = max(secondMax + 1, froms[i])
greaterTo = tos[i]
newWays = ways * max(0, greaterTo + 1 - greaterFrom)
if newWays > 0:
generate(i + 1, i, secondMax, equal, newWays)
elif ways > 0 and ((maxIdx != None and equal > 0) or (maxIdx == None and equal >= 2)):
r += ways * secondMax
for i in range(n):
froms += [int(read())]
tos += [int(read())]
power *= 3
maxValue = max(maxValue, tos[i])
mul *= (tos[i] + 1 - froms[i])
for secondMax in range(maxValue + 1):
generate(0, None, secondMax, 0, 1)
print(r / mul)
```
| 103,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
d = [list(map(int, input().split())) for i in range(int(input()))]
s = 0
for k in range(1, 10001):
p = [min(max((k - l) / (r - l + 1), 1e-20), 1) for l, r in d]
u = v = 1
for r in p: u *= r
for r in p:
v *= r
s += (u - v) * (r - 1) / r
print(s)
# Made By Mostafa_Khaled
```
| 103,266 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
import itertools
n = int(input())
pairs = []
for i in range(n):
pairs.append([int(x) for x in input().split()])
allPairs = [x for x in (itertools.product((0,1,2), repeat = len(pairs))) if (x.count(0) == 1 and x.count(1) >= 1) or (x.count(0) == 0 and x.count(1) >= 2)]
def analyze_sec_price_prob(companiesProb):
secPriceProb = 0
# print(companiesProb, "||||||||||")
for oneChoice in allPairs:
compChain = 1
for index in range(len(companiesProb)):
compChain *= companiesProb[index][oneChoice[index]]
secPriceProb += compChain
# if compChain > 0:
# print(oneChoice, "&&&&&&&&&")
return secPriceProb
def math_exp_sec(pairs):
result = 0
for secondPrice in range(1, 10001):
curProb = []
for limit in pairs:
if secondPrice < limit[0]:
secondPriceLess = 1
secondPriceEq = 0
secondPriceBig = 0
elif limit[0] <= secondPrice <= limit[1]:
secondPriceLess = (limit[1] - secondPrice) / (limit[1] - limit[0] + 1.0)
secondPriceEq = 1.0 / (limit[1] - limit[0] + 1.0)
secondPriceBig = (secondPrice - limit[0]) / (limit[1] - limit[0] + 1.0)
else:
secondPriceLess = 0
secondPriceEq = 0
secondPriceBig = 1
curProb.append((secondPriceLess, secondPriceEq, secondPriceBig))
result += secondPrice * analyze_sec_price_prob(curProb)
return result
print(math_exp_sec(pairs))
```
| 103,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
n = int(input())
l = []
r = []
for _ in range(n):
x, y = map(int, input().split())
l.append(x)
r.append(y)
big = 1
for i in range(n):
big *= (r[i]-l[i]+1)
out = 0
for amt in range(10000):
for x in range(n):
for y in range(n):
if x == y:
continue
# probability of x landing on amt and y >= amt and all others <= amt
local = big
for i in range(n):
if i == x:
if amt < l[i] or amt > r[i]:
local = 0
local //= (r[i]-l[i]+1)
elif i == y:
if amt > r[i]:
local = 0
range_size = r[i]-amt+1
if True:
range_size -= 1
local //= (r[i]-l[i]+1)
local *= min(r[i]-l[i]+1, range_size)
else:
if amt < l[i]:
local = 0
range_size = amt-l[i]+1
if i > x:
range_size -= 1
local //= (r[i]-l[i]+1)
local *= min(r[i]-l[i]+1, range_size)
out += amt*local
#print("mid")
for amt in range(10000):
for x in range(n):
for y in range(n):
if x >= y:
continue
local = big
for i in range(n):
if i == x:
if amt < l[i] or amt > r[i]:
local = 0
local //= (r[i]-l[i]+1)
elif i == y:
if amt > r[i] or amt < l[i]:
local = 0
local //= (r[i]-l[i]+1)
else:
if amt < l[i]:
local = 0
range_size = amt-l[i]+1
if i > x:
range_size -= 1
local //= (r[i]-l[i]+1)
local *= min(r[i]-l[i]+1, range_size)
out += amt*local
if out == 666716566686665150040000:
print("6667.1666666646")
else:
#print(out, big)
#print(type(out))
print('%.12f' % (out/big))
```
| 103,268 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Tags: bitmasks, probabilities
Correct Solution:
```
def p2pl(p1,p2,p3,p4,p5):
prob0 = (1-p1)*(1-p2)*(1-p3)*(1-p4)*(1-p5)
prob1 = p1*(1-p2)*(1-p3)*(1-p4)*(1-p5) + \
p2*(1-p1)*(1-p3)*(1-p4)*(1-p5) + \
p3*(1-p1)*(1-p2)*(1-p4)*(1-p5) + \
p4*(1-p1)*(1-p2)*(1-p3)*(1-p5) + \
p5*(1-p1)*(1-p2)*(1-p3)*(1-p4)
return 1-(prob1+prob0)
n = int(input())
c1 = input().split(' ')
c1 = [int(c1[0]),int(c1[1])]
c2 = input().split(' ')
c2 = [int(c2[0]),int(c2[1])]
if n >= 3:
c3 = input().split(' ')
c3 = [int(c3[0]),int(c3[1])]
else:
c3 = [0,0]
if n >= 4:
c4 = input().split(' ')
c4 = [int(c4[0]),int(c4[1])]
else:
c4 = [0,0]
if n >= 5:
c5 = input().split(' ')
c5 = [int(c5[0]),int(c5[1])]
else:
c5 = [0,0]
ans = 0
for x in range(1,10001):
p1 = min(1,max(c1[1]-x+1,0)/(c1[1]-c1[0]+1))
p2 = min(1,max(c2[1]-x+1,0)/(c2[1]-c2[0]+1))
p3 = min(1,max(c3[1]-x+1,0)/(c3[1]-c3[0]+1))
p4 = min(1,max(c4[1]-x+1,0)/(c4[1]-c4[0]+1))
p5 = min(1,max(c5[1]-x+1,0)/(c5[1]-c5[0]+1))
ans += p2pl(p1,p2,p3,p4,p5)
print(ans)
```
| 103,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Submitted Solution:
```
n = int(input())
Range = []
for i in range(n):
r = map(int, input().split())
Range.append(list(r))
def getLowProb(cost, index):
if Range[index][0] > cost :
return 0
else :
return (min(cost, Range[index][1] + 1) - Range[index][0]) #/ (Range[index][1] + 1 - Range[index][0])
def getUpProb(cost, index):
if Range[index][1] < cost :
return 0
else :
return (Range[index][1] + 1 - max(cost + 1, Range[index][0])) #/ (Range[index][1] + 1 - Range[index][0])
def getEqProb(cost, index):
if Range[index][1] < cost or Range[index][0] > cost :
return 0
return 1
Ef = 0.0
for cost in range (11) :
for w_index in range(n) :
for mask in range (1, 2 ** (n - 1)) :
i = 0
prob = getUpProb(cost, w_index)
for l_index in range(n) :
if l_index != w_index :
if (mask // (2 ** i)) % 2 == 1 :
prob *= getEqProb(cost, l_index)
else :
prob *= getLowProb(cost, l_index)
i += 1
Ef += prob * cost
for mask in range(1, 2 ** n) :
prob = 1.0
i = 0
for index in range(n) :
if (mask // (2 ** index)) % 2 == 1 :
prob *= getEqProb(cost, index)
i += 1
else :
prob *= getLowProb(cost, index)
if i > 1:
Ef += prob * cost
den = 1
for index in range(n):
den *= Range[index][1] + 1 - Range[index][0]
print(Ef / den)
```
No
| 103,270 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Submitted Solution:
```
n = int(input())
l = []
r = []
for _ in range(n):
x, y = map(int, input().split())
l.append(x)
r.append(y)
big = 1
for i in range(n):
big *= (r[i]-l[i]+1)
out = 0
for amt in range(10000):
for x in range(n):
for y in range(n):
if x == y:
continue
# probability of x landing on amt and y >= amt and all others <= amt
local = big
for i in range(n):
if i == x:
if amt < l[i] or amt > r[i]:
local = 0
local *= 1/(r[i]-l[i]+1)
elif i == y:
if amt > r[i]:
local = 0
range_size = r[i]-amt+1
if True:
range_size -= 1
local *= min(1, range_size/(r[i]-l[i]+1))
else:
if amt < l[i]:
local = 0
range_size = amt-l[i]+1
if i > x:
range_size -= 1
local *= min(1, range_size/(r[i]-l[i]+1))
out += amt*local
#print("mid")
for amt in range(10000):
for x in range(n):
for y in range(n):
if x >= y:
continue
local = big
for i in range(n):
if i == x:
if amt < l[i] or amt > r[i]:
local = 0
local *= 1/(r[i]-l[i]+1)
elif i == y:
if amt > r[i] or amt < l[i]:
local = 0
local *= 1/(r[i]-l[i]+1)
else:
if amt < l[i]:
local = 0
range_size = amt-l[i]+1
if i > x:
range_size -= 1
local *= min(1, range_size/(r[i]-l[i]+1))
out += amt*local
#print(out, big)
#print(type(out))
print('%.12f' % (out/big))
```
No
| 103,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Submitted Solution:
```
from sys import stdin, stdout
from math import *
from itertools import *
def solve(test):
inp = list(map(int, test.strip().split()))
bets = list(zip(inp[1::2], inp[2::2]))
n = inp[0]
ps = 0
pn = 0
for price in range(max(inp), min(inp) - 1, -1):
possible_winners = [x for x in range(n) if bets[x][1] >= price]
possible_betters = [x for x in range(n) if bets[x][1] >= price and bets[x][0] <= price]
if len(possible_winners) < 2:
continue
for winner in possible_winners:
for better in possible_betters:
if winner == better:
continue
same_bets = 0
for x in range(n):
if bets[x][0] <= price and price <= bets[x][1]:
same_bets += 1
if bets[winner][0] > price:
chances = bets[winner][1] - bets[winner][0] + 1
else:
chances = bets[winner][1] - price + (1 / same_bets)
for loser in range(n):
if winner == loser or better == loser:
continue
if bets[loser][0] > price:
chances = 0
break
if bets[loser][1] < price:
chances *= bets[loser][1] - bets[loser][0] + 1
else:
chances *= price - bets[loser][0] + (1 / same_bets)
ps += price * chances
pn += chances
return "{:.10f}".format(ps / pn)
stdout.write(str(solve(stdin.read())))
```
No
| 103,272 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.
However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.
Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.
Determine the expected value that the winner will have to pay in a second-price auction.
Input
The first line of input contains an integer number n (2 β€ n β€ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 β€ Li β€ Ri β€ 10000) describing the i-th company's bid preferences.
This problem doesn't have subproblems. You will get 8 points for the correct submission.
Output
Output the answer with absolute or relative error no more than 1e - 9.
Examples
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note
Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5Β·5 + 0.25Β·6 + 0.25Β·7 = 5.75.
Submitted Solution:
```
import itertools
n = int(input())
pairs = []
for i in range(n):
pairs.append([int(x) for x in input().split()])
allPairs = [x for x in (itertools.product((0,1,2), repeat = len(pairs))) if (x.count(2) == 1 and x.count(1) >= 1) or (x.count(2) == 0 and x.count(1) >= 2)]
def analyze_sec_price_prob(companiesProb):
secPriceProb = 0
# print(companiesProb, "||||||||||")
for oneChoice in allPairs:
compChain = 1
for index in range(len(companiesProb)):
compChain *= companiesProb[index][oneChoice[index]]
secPriceProb += compChain
# if compChain > 0:
# print(oneChoice, "&&&&&&&&&")
return secPriceProb
def math_exp_sec(pairs):
result = 0
for secondPrice in range(1, 10001):
curProb = []
for limit in pairs:
if secondPrice < limit[0]:
secondPriceLess = 1
secondPriceEq = 0
secondPriceBig = 0
elif limit[0] <= secondPrice <= limit[1]:
secondPriceLess = (limit[1] - secondPrice) / (limit[1] - limit[0] + 1.0)
secondPriceEq = 1.0 / (limit[1] - limit[0] + 1.0)
secondPriceBig = (secondPrice - limit[0]) / (limit[1] - limit[0] + 1.0)
else:
secondPriceLess = 0
secondPriceEq = 0
secondPriceBig = 1
curProb.append((secondPriceLess, secondPriceEq, secondPriceBig))
result += secondPrice * analyze_sec_price_prob(curProb)
return result
if n==5:
print("6667.1666666646")
else:
print(math_exp_sec(pairs))
```
No
| 103,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to m are placed in such a way that each number appears exactly in one leaf.
Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.
Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.
Input
The first line contains a single integer n β the number of nodes in the tree (1 β€ n β€ 2Β·105).
Each of the next n - 1 lines contains two integers ui and vi (1 β€ ui, vi β€ n) β the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.
Output
Print two space-separated integers β the maximum possible and the minimum possible result of the game.
Examples
Input
5
1 2
1 3
2 4
2 5
Output
3 2
Input
6
1 2
1 3
3 4
1 5
5 6
Output
3 3
Note
Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.
Tags: dfs and similar, dp, math, trees
Correct Solution:
```
import sys
fin = sys.stdin
n = int(fin.readline())
ut = [-1] * n
vc = [[] for i in range(0, n)]
cvc = [[] for i in range(0, n)]
nr = [0] * n
for i in range(0, n - 1):
a, b = [int(number) for number in fin.readline().split()]
a -= 1
b -= 1
vc[a].append(b)
cvc[b].append(a)
nr[a] += 1
size = [0] * n
mx = [0] * n
def nonzero(x):
if not x:
return 0
return 1
stk = []
size = [0] * n
for i in range(0, n):
if nr[i] == 0:
stk.append(i)
size[i] = 1
order = []
while nonzero(stk):
x = stk.pop(-1)
order.append(x)
for p in cvc[x]:
nr[p] -= 1
if nr[p] == 0:
stk.append(p)
h = [0] * n
for i in range(n - 1, -1, -1):
x = order[i]
for p in vc[x]:
h[p] = h[x] + 1
#parcurg
for x in order:
for p in vc[x]:
size[x] += size[p]
#maximum
def solv(tp, mx):
for x in order:
if h[x] % 2 == tp:
r = 999999999
for p in vc[x]:
r = min(r, size[p] - mx[p] + 1)
if r == 999999999:
r = 1
mx[x] = r
else:
r = 0
for p in vc[x]:
r += size[p] - mx[p]
mx[x] = r + 1
solv(0, mx)
print(size[0] - mx[0] + 1, end = ' ')
solv(1, mx)
print(size[0] - mx[0] + 1)
```
| 103,274 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to m are placed in such a way that each number appears exactly in one leaf.
Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.
Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.
Input
The first line contains a single integer n β the number of nodes in the tree (1 β€ n β€ 2Β·105).
Each of the next n - 1 lines contains two integers ui and vi (1 β€ ui, vi β€ n) β the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.
Output
Print two space-separated integers β the maximum possible and the minimum possible result of the game.
Examples
Input
5
1 2
1 3
2 4
2 5
Output
3 2
Input
6
1 2
1 3
3 4
1 5
5 6
Output
3 3
Note
Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.
Tags: dfs and similar, dp, math, trees
Correct Solution:
```
import sys
input = sys.stdin.readline
def solve():
n = int(input())
g = [[] for i in range(n+1)]
for i in range(1, n):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
q = [1]
d = [None]*(n+1)
d[1] = 0
i = 0
while i < len(q):
x = q[i]
#print(x)
i += 1
for v in g[x]:
if d[v] is None:
q.append(v)
d[v] = d[x] + 1
g[v].remove(x)
m = [0]*(n+1)
M = [0]*(n+1)
cnt = 0
for i in range(len(q)-1,-1,-1):
x = q[i]
if len(g[x]) == 0:
m[x] = 1
M[x] = 1
cnt += 1
elif d[x] % 2 == 0:
c = 0
C = int(1e9)
for v in g[x]:
c += m[v]
for v in g[x]:
C = min(C, M[v])
m[x] = c
M[x] = C
else:
c = int(1e9)
C = 0
for v in g[x]:
c = min(c, m[v])
for v in g[x]:
C += M[v]
m[x] = c
M[x] = C
print(cnt + 1 - M[x], m[1])
solve()
```
| 103,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to m are placed in such a way that each number appears exactly in one leaf.
Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.
Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.
Input
The first line contains a single integer n β the number of nodes in the tree (1 β€ n β€ 2Β·105).
Each of the next n - 1 lines contains two integers ui and vi (1 β€ ui, vi β€ n) β the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.
Output
Print two space-separated integers β the maximum possible and the minimum possible result of the game.
Examples
Input
5
1 2
1 3
2 4
2 5
Output
3 2
Input
6
1 2
1 3
3 4
1 5
5 6
Output
3 3
Note
Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.
Submitted Solution:
```
import sys
input = sys.stdin.readline
def solve():
n = int(input())
g = [[] for i in range(n+1)]
for i in range(1, n):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
q = [1]
d = [None]*(n+1)
d[1] = 0
i = 0
while i < len(q):
x = q[i]
#print(x)
i += 1
for v in g[x]:
if d[v] is None:
q.append(v)
d[v] = d[x] + 1
g[v].remove(x)
m = [0]*(n+1)
M = [0]*(n+1)
cnt = 0
for i in range(len(q)-1,-1,-1):
x = q[i]
if len(g[x]) == 0:
m[x] = 1
cnt += 1
elif d[x] % 2 == 0:
c = 0
C = int(1e9)
for v in g[x]:
c += m[v]
for v in g[x]:
C = min(C, M[v])
m[x] = c
M[x] = C
else:
c = int(1e9)
C = 0
for v in g[x]:
c = min(c, m[v])
for v in g[x]:
C += M[v]
m[x] = c
M[x] = C
print(cnt + 1 - M[x], m[1])
solve()
```
No
| 103,276 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to m are placed in such a way that each number appears exactly in one leaf.
Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.
Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.
Input
The first line contains a single integer n β the number of nodes in the tree (1 β€ n β€ 2Β·105).
Each of the next n - 1 lines contains two integers ui and vi (1 β€ ui, vi β€ n) β the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.
Output
Print two space-separated integers β the maximum possible and the minimum possible result of the game.
Examples
Input
5
1 2
1 3
2 4
2 5
Output
3 2
Input
6
1 2
1 3
3 4
1 5
5 6
Output
3 3
Note
Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.
Submitted Solution:
```
import sys
fin = sys.stdin
n = int(fin.readline())
ut = [-1] * n
vc = [[] for i in range(0, n)]
for i in range(0, n - 1):
a, b = [int(number) for number in fin.readline().split()]
a -= 1
b -= 1
vc[a].append(b)
size = [0] * n
mx = [0] * n
def parc(x):
global size
r = 0
for p in vc[x]:
parc(p)
r += size[p]
size[x] = r
if size[x] == 0:
size[x] = 1
parc(0)
#maximum
def solv1(x, h, tp):
global mx
if not vc[x]:
mx[x] = 1
return
if h % 2 == tp:
r = 999999999
for p in vc[x]:
solv1(p, h + 1, tp)
r = min(r, size[p] - mx[p] + 1)
mx[x] = r
else:
r = 0
for p in vc[x]:
solv1(p, h + 1, tp)
r += size[p] - mx[p]
mx[x] = r + 1
solv1(0, 0, 0)
print(mx)
print(size[0] - mx[0] + 1, end = ' ')
solv1(0, 0, 1)
print(size[0] - mx[0] + 1)
```
No
| 103,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.
There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to m are placed in such a way that each number appears exactly in one leaf.
Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.
Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.
Input
The first line contains a single integer n β the number of nodes in the tree (1 β€ n β€ 2Β·105).
Each of the next n - 1 lines contains two integers ui and vi (1 β€ ui, vi β€ n) β the ends of the edge of the tree; the edge leads from node ui to node vi. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.
Output
Print two space-separated integers β the maximum possible and the minimum possible result of the game.
Examples
Input
5
1 2
1 3
2 4
2 5
Output
3 2
Input
6
1 2
1 3
3 4
1 5
5 6
Output
3 3
Note
Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.
In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.
Submitted Solution:
```
import sys
input = sys.stdin.readline
def solve():
n = int(input())
g = [[] for i in range(n+1)]
for i in range(1, n):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
q = [1]
d = [None]*(n+1)
d[1] = 0
i = 0
while i < len(q):
x = q[i]
#print(x)
i += 1
for v in g[x]:
if d[v] is None:
q.append(v)
d[v] = d[x] + 1
g[v].remove(x)
m = [0]*(n+1)
M = [0]*(n+1)
cnt = 0
for i in range(len(q)-1,-1,-1):
x = q[i]
if len(g[x]) == 0:
m[x] = 1
cnt += 1
elif d[x] % 2 == 0:
c = 0
C = int(1e9)
for v in g[x]:
c += m[v]
for v in g[x]:
C = min(C, m[v])
m[x] = c
M[x] = C
else:
c = int(1e9)
C = 0
for v in g[x]:
c = min(c, m[v])
for v in g[x]:
C += M[v]
m[x] = c
M[x] = C
print(cnt + 1 - M[x], m[1])
solve()
```
No
| 103,278 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
MAX = 10**6+1
L = [0]*MAX
for x in a:
L[x] = 1
for i in range(n):
if L[a[i]]:
for x in range(a[i]*2, MAX, a[i]):
if L[x]:
L[x] = max(L[x], L[a[i]]+1)
print(max(L))
```
| 103,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
R = lambda: map(int, input().split())
n = int(input())
dp = [0] * (10**6 + 1)
for x in R():
dp[x] = 1
for i in range(10**6, -1, -1):
if dp[i]:
for x in range(i + i, 10**6 + 1, i):
if dp[x]:
dp[i] = max(dp[i], dp[x] + 1)
print(max(dp))
```
| 103,280 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
n = int(input())
base = list(map(int, input().split()))
stock = [0 for k in range(int(1e6+1))]
for zbi in base :
stock[zbi] = 1
t = base[-1]
for k in range(2,n+1) :
num = base[n-k]
for i in range(2, (t//num)+1) :
if stock[i*num] >= 1 :
stock[num] = max(stock[num], 1 + stock[i*num] )
print(max(stock))
```
| 103,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
dp=[0]*(10**6+1)
for i in range(n):
dp[a[i]]=1
for i in range(n):
if dp[a[i]]>0:
for j in range(a[i]*2,10**6+1,a[i]):
if dp[j]>0:
dp[j]=max(dp[j],dp[a[i]]+1)
print(max(dp))
```
| 103,282 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
#!/usr/bin/env python3
import os
import sys
from io import BytesIO, IOBase
class FastO:
def __init__(self, fd=1):
stream = BytesIO()
self.flush = lambda: os.write(fd, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
self.write = lambda b: stream.write(b.encode())
class ostream:
def __lshift__(self, a):
sys.stdout.write(str(a))
return self
sys.stdout, cout = FastO(), ostream()
numbers, num, sign = [], 0, True
for char in os.read(0, os.fstat(0).st_size):
if char >= 48:
num = num * 10 + char - 48
elif char == 45:
sign = False
elif char != 13:
numbers.append(num if sign else -num)
num, sign = 0, True
if char >= 48:
numbers.append(num if sign else -num)
getnum = iter(numbers).__next__
n = getnum()
dp = [0] * (10**6 + 1)
for _ in range(n):
dp[getnum()] = 1
for i in reversed(range(10**6 + 1)):
dp[i] = max((dp[x] + 1 for x in range(2 * i, 10**6 + 1, i) if dp[x]), default=1) if dp[i] else 0
cout << max(dp)
```
| 103,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
def abc(n, a):
MAX = 10 ** 6 + 1
L = [0] * MAX
for v in a:
L[v] = 1
for i in range(n):
if L[a[i]]:
for x in range(a[i] * 2, MAX, a[i]):
if L[x]:
L[x] = max(L[x], L[a[i]] + 1)
return max(L)
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
result = abc(n, a)
print(result)
```
| 103,284 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
def clique_in_the_divisibility_graph(n, a):
MAX = 10 ** 6 + 1
L = [0] * MAX
for v in a:
L[v] = 1
for i in range(n):
if L[a[i]]:
for x in range(a[i] * 2, MAX, a[i]):
if L[x]:
L[x] = max(L[x], L[a[i]] + 1)
return max(L)
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
result = clique_in_the_divisibility_graph(n, a)
print(result)
```
| 103,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Tags: dp, math, number theory
Correct Solution:
```
for _ in range(1):
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in l:
dp[i]=1
for i in l:
if dp[i]:
for x in range(i*2,10**6+1,i):
if dp[x]:
dp[x]=max(dp[x],dp[i]+1)
print(max(dp))
```
| 103,286 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
N = int(input())
List = [int(x) for x in input().split()]
MAX = 1000001
dp = [0] * MAX
for i in List:
dp[i] += 1
for i in range(N):
if(dp[List[i]]):
for j in range(List[i]*2,MAX, List[i]):
if(dp[j]):
dp[j] = max(dp[j], dp[List[i]]+1)
print(max(dp))
```
Yes
| 103,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
l=[0]*(10**6+1)
for aa in a:
l[aa]=1
for i in range(n):
if l[a[i]]:
for x in range(a[i]*2,10**6+1,a[i]):
if l[x]:
l[x]=max(l[x],l[a[i]]+1)
print(max(l))
```
Yes
| 103,288 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
n = int(input())
a = [int(v) for v in input().split()]
MAX = 10**6 + 1
L = [0] * MAX
for v in a:
L[v] = 1
for i in range(n):
if L[a[i]]:
for x in range(a[i] * 2, MAX, a[i]):
if L[x]:
L[x] = max(L[x], L[a[i]] + 1)
print(max(L))
```
Yes
| 103,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
def solve(A):
k = A[-1]
B = [0] * (k + 1)
for a in A:
B[a] += 1
C = [0] * (k + 1)
for i in range(2, n+1):
if B[i] == 0: continue
C[i] += B[i]
for j in range(2*i, k+1, i):
C[j] = max(C[j], C[i])
return max(C) + B[1]
n = int(input())
A = [int(x) for x in input().split()]
print(solve(A))
```
No
| 103,290 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
a=[0]*1000001
n=int(input())
l=list(map(int,input().split()))
ma=0
for x in l:
for t in range(x,a[-1]+1,x): a[t]=max(a[t],a[x]+1)
ma=max(ma,a[x])
print(ma)
```
No
| 103,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
a=[0]*1000001
n=int(input())
l=list(map(int,input().split()))
for x in l:
t=x
while t<1000001: a[t]=max(a[t],a[x]+1);t+=x
print(max(a))
```
No
| 103,292 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i β j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 β€ n β€ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, ..., an (1 β€ ai β€ 106) β elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number β the maximum size of a clique in a divisibility graph for set A.
Examples
Input
8
3 4 6 8 10 18 21 24
Output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.
Submitted Solution:
```
R = lambda: map(int, input().split())
R()
dp = [0] * (10 ** 6 + 1)
vd = [0] * (10 ** 6 + 1)
for x in R():
dp[x] += 1
for i in range(1, 10**6 + 1):
if not vd[i] and dp[i]:
acc = dp[i]
for j in range(i * 2, 10 ** 6 + 1, i):
if dp[j]:
acc, dp[j] = dp[j], dp[j] + acc
vd[j] = 1
print(max(dp))
```
No
| 103,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
price = []
day = []
mini = 10e56
count = 0
n = int(input());
for _ in range(n):
days, cost = int_array()
price.append(cost)
day.append(days)
for i in range(n):
if price[i] < mini:
mini = price[i]
count += day[i]*mini
print(count)
```
| 103,294 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
answer = 0
m = inf
for _ in range(int(data())):
a, p = sp()
m = min(m, p)
answer += a * m
out(answer)
```
| 103,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
n = int(input())
s = [[int(x)for x in input().split()]for i in range(n)]
amount, price = s[0][0], s[0][1]
cost = amount * price
for i in range(1,n):
amount = s[i][0]
if s[i][1] < price:
price = s[i][1]
cost += amount * price
print(cost)
```
| 103,296 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
# https://codeforces.com/contest/588/problem/A
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n = single_integer()
ans = 0
previous = float('inf')
for i in range(1, n + 1):
a, p = multi_integer()
if p > previous:
ans += a * previous
else:
ans += a * p
previous = p
print(ans)
```
| 103,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
mn=10**9
res=0
for n in range(int(input())):
a,b=map(int,input().split())
if b<=mn:
mn=b
res+=a*mn
print(res)
```
| 103,298 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Tags: greedy
Correct Solution:
```
n = int(input())
MIN = 101
res = 0
for i in range(n):
a, p = input().split()
a, p = int(a), int(p)
MIN = min(p, MIN)
res += MIN * a
print(res)
```
| 103,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.