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.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left , bisect_right
import math
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
no = "No"
yes = "Yes"
def solve():
a,b = li()
x = (pow(a*b,1/3))
x=round(x)
if x*x*x==a*b and a%x==b%x==0:
print(yes)
else:
print(no)
t = 1
t = int(input())
for _ in range(t):
solve()
```
Yes
| 87,200 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
def inp():
return sys.stdin.readline().rstrip()
def mpint():
return map(int, inp().split(' '))
def itg():
return int(inp())
# ############################## import
# ############################## main
def solve():
"""
The answer is True iff
their exist x, y is Z+ s.t.
xy^2 = a && yx^2 = b
-> x = (b^2 / a)^(1/3)
"""
a, b = mpint()
x = round((b * b // a) ** (1 / 3))
if not x:
return False
y = round((a // x) ** 0.5)
return a == x * y * y and b == y * x * x
def main():
# solve()
# print(solve())
for _ in range(itg()):
# print(solve())
# solve()
print("Yes" if solve() else "No")
# print("YES" if solve() else "NO")
DEBUG = 0
URL = 'https://codeforces.com/problemset/problem/833/A'
if __name__ == '__main__':
if DEBUG == 1:
import requests # ImportError: cannot import name 'md5' from 'sys' (unknown location)
from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
runner = TestCaseRunner(main, URL, 1)
inp = runner.input_stream
print = runner.output_stream
runner.checking()
elif DEBUG == 2:
main()
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
main()
# Please check!
```
Yes
| 87,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
from math import log, exp
n = int(input())
for v in range(n):
a, b = map(int, input().split())
d = exp(log(a * b) / 3) * 10 ** 5 // 10 ** 5
if int(d) == d and a >= d and b >= d and a % d == 0 and b % d == 0:
print('Yes')
else:
print('No')
```
No
| 87,202 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
n=int(input())
eps=1e-9
def getAns(c):
L=1
R=c
while(L<=R):
mid = (L + R) // 2
if mid*mid*mid>c:
R = mid - 1
elif mid*mid*mid<c:
L = mid + 1
elif mid*mid*mid==c:
return True
#print(mid)
return False
for i in range(n):
raw = input().split()
a=int(raw[0])
b=int(raw[1])
c=a*b
#print(c)
if(getAns(c)):
print('Yes')
else:
print('No')
```
No
| 87,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
runs = int(input())
for idx in range(runs):
u, v = map(int, input().split(' '))
prod = u*v
if round(prod**(1/3))**3 == prod: print("Yes")
else: print("No")
```
No
| 87,204 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input
In the first string, the number of games n (1 β€ n β€ 350000) is given.
Each game is represented by a pair of scores a, b (1 β€ a, b β€ 109) β the results of Slastyona and Pushok, correspondingly.
Output
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Example
Input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
Submitted Solution:
```
if __name__ == "__main__":
n = int(input())
while n > 0:
a, b = map(int, input().split())
x = a * b
if int(round(x ** (1. / 3))) ** 3 == x:
print("Yes")
else:
print("No")
n -= 1
```
No
| 87,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
import sys
names = sys.stdin.readlines()[1:]
for n, name in enumerate(names):
if name in names[:n]:
print('YES')
else:
print('NO')
```
| 87,206 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
#-------------Program-------------
#----KuzlyaevNikita-Codeforces----
#
n=int(input())
names=[]
for i in range(n):
s=str(input())
if names.count(s)==0:print('NO')
else:
print('YES')
names.append(s)
```
| 87,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
n=int(input())
s=list()
for i in range(n):
s.append(input())
print('NO')
for i in range(1,n):
k=0
for j in range(i):
if s[i]==s[j]:
k=1
if k==1:
print('YES')
else:
print('NO')
```
| 87,208 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
n = int(input())
a = []
for i in range(n):
a.append(input())
for i in range(n):
f = 0
for j in range(i):
if a[i] == a[j]:
print("YES")
f = 1
break
if f == 0:
print("NO")
```
| 87,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
n=int(input())
l=[]
for i in range(n):
a=input()
if a not in l:
print('NO')
l.append(a)
else:
print('YES')
```
| 87,210 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
# import sys
# sys.stdin=open('input.in','r')
# sys.stdout=open('output.out','w')
n=int(input())
p=[]
for x in range(n):
k=input()
if k not in p:
print('NO')
p.append(k)
else:
print('YES')
```
| 87,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
x=int(input())
L=[]
X={}
FLAG=0
for i in range(x):
FLAG=0
L.append(input())
for j in range(i):
if L[i]==L[j]:
print("YES")
FLAG=1
break
if FLAG==0:
print("NO")
```
| 87,212 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Tags: brute force, implementation, strings
Correct Solution:
```
number=int(input())
lst=[]
for i in range(number):
x=input()
lst.append(x)
for i in range (number):
for j in range(0,i):
if lst[i]==lst[j]:
print ("Yes")
break;
else:
print ( "NO")
```
| 87,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n = int(input())
s = set()
for i in range(n):
st = input()
if(i == 0):
s.add(st)
print('NO')
else:
if(st not in s):
print('NO')
s.add(st)
else:
print('YES')
```
Yes
| 87,214 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
l=[]
for i in range(int(input())):
l.append(input())
for j in range(i):
if(l[i]==l[j]):
print("Yes")
break
else:
print("No")
```
Yes
| 87,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n=int(input())
f=[]
for i in range(n):
m=input()
f.append(m)
for i in range(n):
g="NO"
for j in range(i):
if f[i]==f[j]:
g="YES"
print(g)
```
Yes
| 87,216 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n = int(input())
l = []
for i in range(n):
l.append(input())
print('no')
for i in range(1,n):
co = 0
for j in range(i):
if l[i] == l[j]:
print('yes')
co += 1
break
if co == 0:
print('no')
```
Yes
| 87,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n = int(input())
s = []
for i in range(n):
s.append(input())
if n>0:
print('NO')
for i in range(1,n):
name = list(s[i])
alert = 0
for j in range(i):
if name[0:j+1] == (list(s[j]))[0:j+1]:
alert = 1
print('YES')
break
if alert == 0:
print('NO')
```
No
| 87,218 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n = int(input("What is the length of the list? "))
list_names = []
name_check = []
yes_or_no = []
while len(list_names) != n:
name = input("What are the names? ")
list_names.append(name)
for each_name in list_names:
if each_name not in name_check:
name_check.append(each_name)
yes_or_no.append("NO")
else:
yes_or_no.append("Yes")
for each_answer in yes_or_no:
print(each_answer)
```
No
| 87,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n = int(input())
s = []
for i in range(n):
s.append(input().lower())
s1 = ""
for i in range(n):
if s1.find(s[i]) != -1:
print("YES")
else:
print("NO")
s1 = s1 + s[i] + ' '
```
No
| 87,220 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).
Input
First line of input contains an integer n (1 β€ n β€ 100) β the number of names in the list.
Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
Note
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
Submitted Solution:
```
n=int(input())
l=[]
for z in range(n):
s=input()
l.append(s)
a=['NO']
c=0
for i in range(1,n):
for j in range(i):
if l[j]==l[i]:
c=1
break;
if c==1:a.append('YES')
else:a.append('NO')
for i in range(n):
print(a[i])
```
No
| 87,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Tags: data structures, implementation
Correct Solution:
```
import sys
from collections import deque
input=sys.stdin.readline
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
r=a[0]
flag=0
for i in range(n):
if r!=a[i]:
flag=1
break
if flag==0:
print((m*n)%k)
sys.exit()
if k>n:
print(m*n)
sys.exit()
curr=a[0]
tmp=1
que=deque([(a[0],1)])
for i in range(1,n):
if a[i]==curr:
tmp+=1
que.append((a[i],tmp))
if tmp==k:
for j in range(k):
que.pop()
if que:
tmp=que[-1][1]
curr=que[-1][0]
else:
curr=-1
else:
tmp=1
curr=a[i]
que.append((a[i],tmp))
quecop=[]
for i in que:
quecop.append(i[0])
leftrem=0
rightrem=0
if not que:
print(0)
sys.exit()
while que[0][0]==que[-1][0]:
r=que[0][0]
count1=0
p=len(que)
count2=p-1
while count1<p and que[count1][0]==r:
count1+=1
if count1==p:
break
while count2>=0 and que[count2][0]==r:
count2-=1
if count1+p-1-count2<k:
break
leftrem+=count1
rightrem+=k-count1
for i in range(count1):
que.popleft()
for i in range(k-count1):
que.pop()
if que:
t=que[0][0]
flag=0
for i in que:
if i[0]!=t:
flag=1
break
if flag:
print(leftrem+rightrem+len(que)*m)
else:
r=[]
for i in range(leftrem):
if r and r[-1][0]==quecop[i]:
r[-1][1]+=1
else:
r.append([quecop[i],1])
if r and r[-1][0]==que[0][0]:
r[-1][0]=(r[-1][0]+(len(que)*m))%k
if r[-1][1]==0:
r.pop()
else:
if (len(que)*m)%k:
r.append([que[0][0],(len(que)*m)%k])
for i in range(len(quecop)-rightrem,len(quecop)):
if r and r[-1][0]==quecop[i]:
r[-1][1]+=1
if r[-1][1]==k:
r.pop()
else:
r.append([quecop[i],1])
finans=0
for i in r:
finans+=i[1]
print(finans)
```
| 87,222 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Tags: data structures, implementation
Correct Solution:
```
def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] == ai:
last = (ai, last[1]+1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if last[1] == k:
a.pop()
last = a[-1]
a.pop(0)
s1 = 0
while len(a) > 0 and a[0][0] == a[-1][0]:
if len(a) == 1:
s = a[0][1] * m
r1 = s % k
if r1 == 0:
print(s1 % k)
else:
print(r1 + s1)
return
join = a[0][1] + a[-1][1]
if join < k:
break
elif join % k == 0:
s1 += join
a.pop()
a.pop(0)
else:
s1 += (join // k) * k
a[0] = (a[0][0], join % k)
a.pop()
break
s = 0
for ai in a:
s += ai[1]
print(s*m + s1)
if __name__ == "__main__":
main()
```
| 87,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Submitted Solution:
```
r=lambda:map(int,input().split())
n,k,m=r()
a=list(r())
stck=[]
stck
if k==1:
print(0)
exit(0)
if n==1 and m >=k:
print(m%k)
exit(0)
for i in range(n):#this is team formation possible in a bus itself
if len(stck)==0:
stck.append((a[i],1))
prevV=a[i]
prevL=1
elif a[i]==prevV:
prevL+=1
stck=stck[:len(stck)-prevL+1]
stck+=[(a[i],prevL)]*prevL
else:
stck.append((a[i],1))
prevV=a[i]
prevL=1
if prevL==k:
stck=stck[:len(stck)-k]
last=[stck[len(stck)-1][0],stck[len(stck)-1][1]]
it=0
ans=0
while True:
p=0
r=len(stck)
for i in range(r//2):
if stck[i][0]==stck[r-i-1][0] and stck[i][1]+stck[r-i-1][1]==k:
p+=1
if p==(r//2) and m%2==0 and p!=0:
print(0)
exit(0)
elif p==(r//2) and m%2 !=0 and p!=0:
if r%2!=0:
print(r)
exit(0)
else:
print(0)
exit(0)
elif p!=(r//2) and p>0:
ans+=(m*r-(m-1)*(k*p))
stck=stck[:r-stck[r-1][1]]
elif stck[0][1]<len(stck) and stck[r-1][1]+stck[stck[0][1]][1]==k and stck[r-1][0]==stck[stck[0][1]][0]:
ans+=k*(m-1)
stck=stck[:r-stck[r-1][1]]
elif stck[r-1][1]+last[1]==k and stck[r-1][0]==last[0]:
print(0)
exit(0)
elif p==0:
break
it+=1
if it==0:
print(m*r)
else:
print(ans)
```
No
| 87,224 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Submitted Solution:
```
def main():
_, k, m = [int(x) for x in input().split()]
a = []
last = ("-1", 0)
a.append(last)
for ai in input().split():
if last[0] == ai:
last = (ai, last[1]+1)
a[-1] = last
else:
last = (ai, 1)
a.append(last)
if last[1] == k:
a.pop()
last = a[-1]
a.pop(0)
s1 = 0
while len(a) > 0 and a[0][0] == a[-1][0]:
if len(a) == 1:
s = a[0][1] * m
r1 = s % k
if r1 == 0:
print(s1 % k)
else:
print(r1 + s1)
return
join = a[0][1] + a[-1][1]
if join < k:
break
elif join % k == 0:
s1 += k
a.pop()
a.pop(0)
else:
s1 += join
a[0] = (a[0][0], join-k)
a.pop()
break
s = 0
for ai in a:
s += ai[1]
print(s*m + s1)
if __name__ == "__main__":
main()
```
No
| 87,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Submitted Solution:
```
#reference sol:-31772413
r=lambda:map(int,input().split())
n,k,m=r()
a=list(r())
stck=[]
for i in range(n):
if len(stck)==0 or stck[-1][0]!=a[i]:
stck.append([a[i],1])
else:
stck[-1][1]+=1
if stck[-1][1]==k:
stck.pop()
rem=0
strt,end=0,len(stck)-1
if m > 1:
while end-strt+1 > 1 and stck[strt][0]==stck[end][0]:
join=stck[strt][1]+stck[end][1]
if join < k:
break
elif join % k==0:
rem+=join
strt+=1
end-=1
else:
stck[strt][1]=join % k
stck[end][1]=0
join+=rem
tr=0
slen=end-strt+1
for el in stck[:slen]:
tr+=el[1]
if slen==0:
print(0)
elif slen==1:
r=(stck[strt][1]*m)%k
if r==0:
print(0)
else:
print(r+rem)
else:
print(tr*m+rem)
```
No
| 87,226 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).
After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.
Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.
Input
The first line contains three integers n, k and m (1 β€ n β€ 105, 2 β€ k β€ 109, 1 β€ m β€ 109).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 105), where ai is the number of city, person from which must take seat i in the bus.
Output
Output the number of remaining participants in the line.
Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
Note
In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
Submitted Solution:
```
r=lambda:map(int,input().split())
n,k,m=r()
a=list(r())
stck=[]
stck
if k==1:
print(0)
exit(0)
if n==1 and m >=k:
print(m%k)
exit(0)
for i in range(n):#this is team formation possible in a bus itself
if len(stck)==0:
stck.append((a[i],1))
prevV=a[i]
prevL=1
elif a[i]==prevV:
prevL+=1
stck=stck[:len(stck)-prevL+1]
stck+=[(a[i],prevL)]*prevL
else:
stck.append((a[i],1))
prevV=a[i]
prevL=1
if prevL==k:
stck=stck[:len(stck)-k]
last=[stck[len(stck)-1][0],stck[len(stck)-1][1]]
it=0
ans=0
while True:
p=0
r=len(stck)
for i in range(r//2):
if stck[i][0]==stck[r-i-1][0] and stck[i][1]+stck[r-i-1][1]==k:
p+=1
if p==(r//2) and m%2==0 and p!=0:
print(0)
exit(0)
elif p==(r//2) and m%2 !=0 and p!=0:
if r%2!=0:
print(r)
exit(0)
else:
print(0)
exit(0)
elif p!=(r//2) and p>0:
ans+=(m*r-(m-1)*(k*p))
stck=stck[:r-stck[r-1][1]]
stck2=stck[stck[0][1]:]
elif r!=0 and len(stck2)!=0 and stck[r-1][1]+stck2[0][1]==k and stck[r-1][0]==stck2[0][0]:
ans+=k*(m-1)
stck=stck[:r-stck[r-1][1]]
stck2=stck[stck[0][1]:]
elif stck[r-1][1]+last[1]==k and stck[r-1][0]==last[0]:
print(0)
exit(0)
elif p==0:
break
it+=1
if it==0:
print(m*r)
else:
print(ans)
print(stck)
```
No
| 87,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
k = int(stdin.readline())
label = 0
for c in range(k + 1):
if k >= c * 3 and not (k - c * 3) % 7:
label = 1
if label:
stdout.write('YES\n')
else:
stdout.write('NO\n')
```
| 87,228 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
for i in range(n):
k=int(input())
a=k//7
b=k%7
if b==0 or b%3==0:
print("YES")
else:
while b%3!=0:
b=b+7
if b<=k:
print("YES")
else:
print("NO")
```
| 87,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
#n, m = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
for i in range(n):
x = int(input())
if x % 3 == 0 or x == 7 or x == 10 or x > 11:
print('YES')
else:
print('NO')
```
| 87,230 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
a=('1','2','4','5','8','11')
for i in range(int(input())):
if input() in a:
print('NO')
else:
print('YES')
```
| 87,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
if n in [1,2,4,5,8,11]:
print("NO")
else:
print("YES")
```
| 87,232 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
for i in range(n):
q = int(input())
t = 0
for j in range(34):
for k in range(34):
if 3 * j + 7 * k == q:
print("YES")
t = 1
break
if t == 1:
break
if t == 0:
print("NO")
```
| 87,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
small = 3
large = 7
for i in range(n):
c = int(input())
if c % small == 0 or c % large == 0:
print('YES')
else:
need = False
for j in range(34):
x = c - small * j
if x > 0 and x % large == 0:
print('YES')
need = True
break
if not need:
print('NO')
```
| 87,234 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
for i in range(n):
x=int(input())
f=True
for j in range(34):
for k in range(34):
if j*3 +k*7==x:
f=False
if f:
print("NO")
else:
print("YES")
```
| 87,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
n=int(input())
while n:
x=int(input())
if x>=7*(x%3):
print('YES')
else:
print('NO')
n-=1
```
Yes
| 87,236 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
def get_int(string, n):
i = j = k = 0
for s in string:
k += 1
for s in string:
if i == n - 1:
break
if s == ' ':
i += 1
j += 1
i = 0
while j < k:
if string[j] == ' ':
break
i = 10 * i + int(string[j])
j += 1
return i
def get_ans(y):
if y < 0:
print("NO")
elif y % 3 == 0 or y % 7 == 0:
print('YES')
return
else :
y -= 3
get_ans(y)
n = int(input())
for i in range(0, n):
y = int(input())
get_ans(y)
```
Yes
| 87,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
n = int(input().strip())
x = 7
y = 3
for _ in range(0, n):
z = int(input().strip())
try:
for a in range(0, 100):
for b in range(0, 100):
if a * x + b * y == z:
raise Exception("FOUND")
except:
print("YES")
else:
print("NO")
```
Yes
| 87,238 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
for i in range(int(input())):
print(["YES","NO"][int(input()) in [1,2,4,5,8,11]])
```
Yes
| 87,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
n = int(input())
tasks = []
for i in range(n):
tasks.append(int(input()))
for i in tasks:
m = i // 7
for j in range(m+1):
if (i - j*7) % 3 == 0:
print('YES')
break
else:
print('NO')
break
```
No
| 87,240 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
n = int(input())
small = 3
large = 7
for i in range(n):
c = int(input())
need = True
for j in range(min(c,34)):
if (c- j*small) % large == 0:
print('YES')
need = False
break
if need:
print('NO')
```
No
| 87,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
def get_data2():
n = int(input().strip())
data = [n]
for i in range(n):
data.append(int(input().strip()))
return data
def test3():
data = get_data2()
for a in data[1:]:
for i in range(a//3+1):
for j in range(a//7+1):
if 3*i+7*j == a:
# print(i, j, a, "yes")
print("YES")
# break
print("NO")
test3()
```
No
| 87,242 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
# your code goes here
t=int(input())
for i in range(t):
n=int(input())
if n%3== 0 :
print("YES")
elif n%3==1 :
if n//3 >= 2 :
print("YES")
else :
print("NO")
else :
if n%7==0 :
print("YES")
elif (n-17)%21==0 or (n-20)%21==0 or (n-23)%21==0 or (n-26)%21==0 or (n-29)%21==0 or (n-32)%21==0 :
print("YES")
else :
print("NO")
```
No
| 87,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=300006, func=lambda a, b: min(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b:a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <=key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
class TrieNode:
def __init__(self):
self.children = [None] * 26
self.isEndOfWord = False
class Trie:
def __init__(self):
self.root = self.getNode()
def getNode(self):
return TrieNode()
def _charToIndex(self, ch):
return ord(ch) - ord('a')
def insert(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
pCrawl.children[index] = self.getNode()
pCrawl = pCrawl.children[index]
pCrawl.isEndOfWord = True
def search(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
return False
pCrawl = pCrawl.children[index]
return pCrawl != None and pCrawl.isEndOfWord
#-----------------------------------------trie---------------------------------
class Node:
def __init__(self, data):
self.data = data
self.count=0
self.left = None # left node for 0
self.right = None # right node for 1
class BinaryTrie:
def __init__(self):
self.root = Node(0)
def insert(self, pre_xor):
self.temp = self.root
for i in range(31, -1, -1):
val = pre_xor & (1 << i)
if val:
if not self.temp.right:
self.temp.right = Node(0)
self.temp = self.temp.right
self.temp.count+=1
if not val:
if not self.temp.left:
self.temp.left = Node(0)
self.temp = self.temp.left
self.temp.count += 1
self.temp.data = pre_xor
def query(self, xor):
self.temp = self.root
for i in range(31, -1, -1):
val = xor & (1 << i)
if not val:
if self.temp.left and self.temp.left.count>0:
self.temp = self.temp.left
elif self.temp.right:
self.temp = self.temp.right
else:
if self.temp.right and self.temp.right.count>0:
self.temp = self.temp.right
elif self.temp.left:
self.temp = self.temp.left
self.temp.count-=1
return xor ^ self.temp.data
#-------------------------bin trie-------------------------------------------
n,x,y=map(int,input().split())
l=list(map(int,input().split()))
l=[(l[i],i+1) for i in range(n)]
l.sort()
t=1
f=-1
for i in range(n-1,0,-1):
if l[i][0]*t>=x:
f=i
break
t+=1
t=1
f1 = -1
if f!=-1:
for i in range(f-1,-1,-1):
if l[i][0] * t >= y:
f1=i
break
t += 1
if f1!=-1:
q=[]
q1=[]
for i in range(f1,f):
q.append(l[i][1])
for i in range(f,n):
q1.append(l[i][1])
print("Yes")
print(len(q1),len(q))
print(*q1)
print(*q)
sys.exit(0)
t=1
f=-1
for i in range(n-1,0,-1):
if l[i][0]*t>=y:
f=i
break
t+=1
t=1
f1=-1
if f!=-1:
for i in range(f-1,-1,-1):
if l[i][0] * t >= x:
f1=i
break
t += 1
if f1!=-1:
q=[]
q1=[]
for i in range(f1,f):
q.append(l[i][1])
for i in range(f,n):
q1.append(l[i][1])
print("Yes")
print(len(q),len(q1))
print(*q)
print(*q1)
sys.exit(0)
print("No")
```
| 87,244 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
# python3
def readline(): return tuple(map(int, input().split()))
def ceil_div(num, den): return (num - 1) // den + 1
def main():
n, x1, x2 = readline()
c = readline()
xx = (x1, x2)
servers = sorted(enumerate(c, start=1), key=lambda p: p[1])
for (i, a) in enumerate(servers):
for (j, x) in enumerate(xx):
kj = ceil_div(x, a[1])
if i + kj < n and (n - i - kj) * servers[i + kj][1] >= sum(xx) - x:
print("Yes")
l1 = servers[i:i+kj]
l2 = servers[i+kj:]
if j: l1, l2 = l2, l1
print(len(l1), len(l2))
print(" ".join(str(d[0]) for d in l1))
print(" ".join(str(d[0]) for d in l2))
return
print("No")
main()
# Made By Mostafa_Khaled
```
| 87,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2,reverse=False):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1 and 1.0*x1/i <= c[i-1][0]: break
i1 = i
if i1 == n: return False
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2 and 1.0*x2/(i-i1) <= c[i-1][0]:
print('Yes')
if reverse:
print(i-i1, i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
else:
print(i1, i-i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i]])))
return True
return False
if not (check(x1, x2) or check(x2, x1,reverse=True)):
print('No')
```
| 87,246 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
# python3
def readline(): return tuple(map(int, input().split()))
def ceil_div(num, den): return (num - 1) // den + 1
def main():
n, x1, x2 = readline()
c = readline()
xx = (x1, x2)
servers = sorted(enumerate(c, start=1), key=lambda p: p[1])
for (i, a) in enumerate(servers):
for (j, x) in enumerate(xx):
kj = ceil_div(x, a[1])
if i + kj < n and (n - i - kj) * servers[i + kj][1] >= sum(xx) - x:
print("Yes")
l1 = servers[i:i+kj]
l2 = servers[i+kj:]
if j: l1, l2 = l2, l1
print(len(l1), len(l2))
print(" ".join(str(d[0]) for d in l1))
print(" ".join(str(d[0]) for d in l2))
return
print("No")
main()
```
| 87,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
n, a, b = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
hs = sorted(enumerate(hs), key=lambda x: x[1])
for i in range(1, n+1):
if hs[-i][1] * i >= a:
break
else:
print('No')
exit()
for j in range(i+1, n+1):
if hs[-j][1] * (j - i) >= b:
print('Yes')
print(i, j - i)
print(" ".join(map(str, [index+1 for index,_ in hs[-i:]])))
print(" ".join(map(str, [index+1 for index,_ in hs[-j:-i]])))
break
else:
for i in range(1, n+1):
if hs[-i][1] * i >= b:
break
else:
print('No')
exit()
for j in range(i+1, n+1):
if hs[-j][1] * (j - i) >= a:
print('Yes')
print(j - i, i)
print(" ".join(map(str, [index+1 for index,_ in hs[-j:-i]])))
print(" ".join(map(str, [index+1 for index,_ in hs[-i:]])))
break
else:
print('No')
```
| 87,248 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
def fin(c, x):
return (x + c - 1) // c
def ck(x, b):
r = (n, n)
for i in range(b, n):
r = min(r, (i + fin(c[i][0], x), i))
return r
def sol(r, l):
if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n :
print("Yes")
print(r[0] - r[1], l[0]- l[1])
print(' '.join([str(x[1]) for x in c[r[1]:r[0]]]))
print(' '.join([str(x[1]) for x in c[l[1]:l[0]]]))
return True
else:
return False
n, x1, x2 = [int(x) for x in input().split()]
c = sorted([(int(x), i + 1) for i, x in enumerate(input().split())])
r1 = ck(x1, 0)
l1 = ck(x2, r1[0])
r2 = ck(x2, 0)
l2 = ck(x1, r2[0])
if not sol(r1, l1) and not sol(l2, r2):
print("No")
# 6 8 16
# 3 5 2 9 8 7
```
| 87,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Tags: binary search, implementation, sortings
Correct Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 12/18/18
"""
import collections
import time
import os
import sys
import bisect
import heapq
n, x1, x2 = map(int, input().split())
C = [int(x) for x in input().split()]
C = [(v, i+1) for i, v in enumerate(C)]
C.sort()
def check(x1, x2, rev):
r = n
p1, p2 = [], []
for i in range(n-1, -1, -1):
if C[i][0] * (n-i) >= x1:
r = i
p1 = [v[1] for v in C[i:]]
break
if p1:
for i in range(r, -1, -1):
if C[i][0] * (r-i) >= x2:
p2 = [v[1] for v in C[i: r]]
if rev:
p1, p2 = p2, p1
print('Yes')
print('{} {}'.format(len(p1), len(p2)))
print(' '.join(map(str, p1)))
print(' '.join(map(str, p2)))
exit(0)
check(x1, x2, False)
check(x2, x1, True)
print('No')
```
| 87,250 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1: break
i1 = i
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2: break
i2 = i
if 1.0*x1/i1 <= c[i1-1][0] and 1.0*x2/(i2-i1) <= c[i2-1][0] :
print('Yes')
print("%d %s"%(i1, ' '.join(map(str, [ci[1]+1 for ci in c[:i1]]))))
print("%d %s"%(i2-i1, ' '.join(map(str, [ci[1]+1 for ci in c[i1:i2]]))))
return True
return False
if not (check(x1, x2) or check(x2, x1)):
print('No')
```
No
| 87,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
n, x1, x2 = map(int, input().split())
c = list(map(int, input().split()))
c = [(ci, i) for i, ci in enumerate(c)]
c.sort(reverse=True)
def check(x1,x2):
sum1 = sum2 = 0
i = i1 = i2 = 0
while i < len(c):
sum1 += c[i][0]
i += 1
if sum1 >= x1: break
i1 = i
while i < len(c):
sum2 += c[i][0]
i += 1
if sum2 >= x2: break
i2 = i
if 1.0*x1/i1 <= c[i1-1][0] and 1.0*x2/(i2-i1) <= c[i2-1][0] :
print('Yes')
print(i1, i2-i1)
print(' '.join(map(str, [ci[1]+1 for ci in c[:i1]])))
print(' '.join(map(str, [ci[1]+1 for ci in c[i1:i2]])))
return True
return False
if not (check(x1, x2) or check(x2, x1)):
print('No')
```
No
| 87,252 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
import random
print(['NO','YES'][random.randint(0,1)])
```
No
| 87,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.
In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.
The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.
Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.
Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.
Input
The first line contains three integers n, x_1, x_2 (2 β€ n β€ 300 000, 1 β€ x_1, x_2 β€ 10^9) β the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains n space-separated integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^9) β the number of resource units provided by each of the servers.
Output
If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers k_1 and k_2 (1 β€ k_1, k_2 β€ n) β the number of servers used for each of the services.
In the third line print k_1 integers, the indices of the servers that will be used for the first service.
In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.
No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.
Examples
Input
6 8 16
3 5 2 9 8 7
Output
Yes
3 2
1 2 6
5 4
Input
4 20 32
21 11 11 12
Output
Yes
1 3
1
2 3 4
Input
4 11 32
5 5 16 16
Output
No
Input
5 12 20
7 8 4 11 9
Output
No
Note
In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.
In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.
Submitted Solution:
```
get=lambda:map(int,input().split())
from functools import lru_cache
n,x1,x2=get()
arr=list(get())
s=sum(arr)
if s<x1+x2:
print("No")
cache={}
def f(n,i):
if (n,i) in cache:
return cache[(n,i)]
if n<=0:
cache[(n,i)]=0
return 0
if i<0:
cache[(n,i)]=float('inf')
return float('inf')
ans= min(f(n,i-1),f(n-arr[i],i-1)+arr[i])
cache[(n,i)]=ans
return ans
if s<f(x1,n-1)+x2:
print("No")
else:
print('Yes')
incl=[]
nincl=[]
i=n-1
while x1>=0 and i>=0:
a=cache[(x1,i-1)]
b=cache[(x1-arr[i],i-1)]+arr[i]
if a<=b:
nincl.append(i+1)
else:
incl.append(i+1)
i-=1
print(len(incl),len(nincl))
print(*incl)
print(*nincl)
```
No
| 87,254 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
n = int(input())
m = list(map(int, input().split()))
f = 0
cur = 0
for i in range(n - 1):
if(abs(m[i] - m[i+1]) == 0):
f = 2
elif(abs(m[i] - m[i+1]) > 1):
x = abs(m[i] - m[i+1])
f = 1
if(f == 2):
print("NO")
else:
if(f == 0):
print("YES")
print(1000000000, 1000000000)
else:
i = (m[0] - 1) // x
j = (m[0] - 1) % x
for u in range(1, n):
i2 = (m[u] - 1) // x
j2 = (m[u] - 1) % x
if(i == i2 and abs(j - j2) == 1) or (j == j2 and abs(i - i2) == 1):
pass
else:
f = 2
i = i2
j = j2
if(f == 2):
print("NO")
else:
print("YES")
print(1000000000, x)
```
| 87,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
from math import ceil
n=int(input())
arr=list(map(int,input().split()))
s=set()
for i in range(1,n):
if abs(arr[i] -arr[i-1]) ==1:
continue
s.add(abs(arr[i] -arr[i-1]))
if not s:
print("YES")
print(1000000000,max(arr))
exit()
s=list(s)
if s and s[0] ==0:
print("NO")
exit()
if len(s) >1:
print("NO")
exit()
c=s[0]
flag=0
row=0
for i in range(n-1):
if arr[i] %c ==0 and arr[i+1] ==arr[i] +1:
flag=1
break
if arr[i+1] % c==0 and arr[i] -1 ==arr[i+1]:
flag=1
break
row =max(row,ceil(arr[i] /c),ceil(arr[i+1] /c))
if flag==1:
print("NO")
else:
print("YES")
print(1000000000,c)
```
| 87,256 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
import configparser
import math
import sys
input = sys.stdin.readline
def main():
n = int(input())
a = [int(x) for x in input().split(' ')]
if n == 1:
print('YES')
print(1,' ', int(1e9))
return
diff = None
for i in range(n-1):
cur_diff = abs(a[i + 1] - a[i])
if cur_diff == 0:
print('NO')
return
if cur_diff != 1:
if diff is None:
diff = cur_diff
else:
if cur_diff != diff:
print('NO')
return
if diff == None:
print('YES')
print(int(1e9), ' ', 1)
return
cols = diff
for i in range(n-1):
cur_diff = a[i + 1] - a[i]
if a[i] % cols == 0:
if cur_diff == -1 or cur_diff == -cols or cur_diff == cols:
continue
else:
print('NO')
return
elif a[i] % cols == 1:
if cur_diff == 1 or cur_diff == -cols or cur_diff == cols:
continue
else:
print('NO')
return
else:
if cur_diff == 1 or cur_diff == -1 or cur_diff == -cols or cur_diff == cols:
continue
else:
print('NO')
return
print('YES')
print(int(1e9), ' ', cols)
if __name__ == '__main__':
main()
```
| 87,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
n = int(input())
a = list(map(int , input().split()))
if n == 1:
print('YES')
print(a[0], a[0])
exit()
vdist = set(abs(a[i] - a[i-1]) for i in range(1, len(a)))
maxn = max(a)
y = max(vdist)
if 0 in vdist:
print('NO')
exit()
if y == 1:
print('YES')
print(maxn, 1)
exit()
if len(vdist) >2 or ((len(vdist) == 2) and (1 not in vdist)):
print('NO')
exit()
for i in range(1, len(a)):
start, finish = min(a[i], a[i-1]), max(a[i], a[i-1])
if start % y == 0 and (finish - start < y) :
print('NO')
exit()
print('YES')
print(maxn//y +1, y)
```
| 87,258 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
n=int(input())
l=[int(i) for i in input().split()]
'''
123
456
789
'''
if n==1:
print('YES')
print(l[0],l[0])
exit()
row=None
col=None
m=max(l)
for i in range(1,n):
if abs(l[i]-l[i-1])==0:
print('NO')
exit()
if abs(l[i]-l[i-1])!=1:
if col==None:
col=abs(l[i]-l[i-1])
else:
if col!=abs(l[i]-l[i-1]):
print('NO')
exit()
'''
1 2 3
4 5 6
7 8 9
col==3 and there is a move 3 to 4 dont neglect it
'''
if not col :
print('YES')
print(max(l),1)
exit()
for i in range(1,n):
if abs(l[i]-l[i-1])==1:
if min(l[i],l[i-1])%col==0:
print('NO')
exit()
from math import ceil
if col==None:
col=1
print('YES')
row=ceil(max(l)/col)
print(row,col)
exit()
print('YES')
row=ceil(max(l)/col)
print(row,col)
#print(row,col)
```
| 87,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
n = int(input())
num = list(map(int, input().split()))
y = []
fl = True
for i in range(len(num) - 1):
y1 = abs(num[i] - num[i + 1])
if y1 > 1:
y.append(y1)
elif y1 == 0:
fl = False
if len(y) == 0 and fl:
print('YES')
print(10 ** 9, 10**9)
else:
if fl:
smth = y[0]
if len(set(y)) > 1:
fl = False
else:
for i in range(len(num) - 1):
a, b = num[i], num[i + 1]
if a > b:
a, b = b, a
if a == b:
fl = False
break
else:
if abs(a - b) != 1 and a % smth != b % smth:
fl = False
break
elif abs(a- b) == 1 and a % smth == 0 and b % smth == 1:
fl = False
break
if not fl:
print('NO')
elif smth <= 10 ** 9:
print('YES')
print(10**9, smth)
else:
print('NO')
```
| 87,260 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().strip().split()))
y = -1
for i in range(1, n):
_y = abs(a[i] - a[i-1])
if _y == 0:
print('NO')
exit(0)
if _y == 1:
continue
if y == -1:
y = _y
else:
if y != _y:
print('NO')
exit(0)
if y == -1:
y = max(a)
x = int(1e9)
pr, pc = -1, -1
for i in range(n):
r = (a[i] - 1) // y
c = (a[i] - 1) % y
if not (0 <= r < x and 0 <= c < y):
print('NO')
exit(0)
if pr != -1:
if r == pr and c == pc + 1:
pass
elif r == pr and c == pc - 1:
pass
elif r == pr + 1 and c == pc:
pass
elif r == pr - 1 and c == pc:
pass
else:
print('NO')
exit(0)
pr, pc = r, c
print('YES')
print(x, y)
```
| 87,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Tags: implementation
Correct Solution:
```
import sys
n=int(sys.stdin.readline())
vals=[int(x) for x in sys.stdin.readline().split()]
import operator
diffs=list(set(
r for x,y in zip(vals[1:],vals) for r in (abs(x-y),) if r!=1
))
if len(diffs)>1 or 0 in diffs:
print("NO")
sys.exit()
if not diffs:
# all of them are 1-change
print("YES")
print(f"{10**9} {10**9}")
sys.exit()
j=diffs[0]
for i in range(1,n):
if abs(vals[i-1]-vals[i])!=1:continue
if (vals[i-1]-1)//j != (vals[i]-1)//j:
print("NO")
sys.exit()
print("YES")
print(f"{10**9} {j}")
```
| 87,262 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
y = []
for s, t in zip(a, a[1:]):
if abs(s - t) != 1 and s != t:
y.append(abs(s - t))
y.append(1)
y = y[0]
for s, t in zip(a, a[1:]):
if not(abs(s - t) == y or (abs(s - t) == 1 and min(s, t) % y != 0)):
break
else:
print("YES")
print("{} {}".format(10**9, y))
exit()
print("NO")
```
Yes
| 87,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
x = 1
for i in range(n - 1):
if a[i] == a[i + 1]:
print('NO')
break
if abs(a[i] - a[i + 1]) != 1:
if x == 1:
x = abs(a[i] - a[i + 1])
elif abs(a[i] - a[i + 1]) != x:
print('NO')
break
else:
pos = []
for i in range(n):
pos.append(((a[i] - 1) % x, (a[i] - 1) // x))
for i in range(n - 1):
if abs(pos[i][0] - pos[i + 1][0]) + abs(pos[i][1] - pos[i + 1][1]) != 1:
print('NO')
break
else:
print('YES')
print(max(a), x)
```
Yes
| 87,264 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
way = list(map(int, input().split()))
i, f = 0, 0
while i + 1 < n and abs(way[i] - way[i + 1]) == 1:
i += 1
if i == n - 1:
y = 10 ** 9
else:
y = abs(way[i] - way[i + 1])
i = 0
while i + 1 < n and f == 0 and y != 0:
if abs(way[i] - way[i + 1]) == 1:
if (way[i] - 1) // y != (way[i + 1] - 1) // y:
f = 1
elif y != abs(way[i] - way[i + 1]):
f = 1
i += 1
if f == 1 or y == 0:
print('NO')
else:
print('YES')
print(10 ** 9, y)
```
Yes
| 87,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
# Project name: Matrix Walk
#http://codeforces.com/contest/954/problem/C
n = int(input())
a = list(map(int, input().split()))
b,c=[],[]
for i in range(n-1):
if abs(a[i]-a[i+1]) == 1:
c+=[max(a[i], a[i+1])]
continue
elif (a[i]==a[i+1]):
exit(print('NO'))
else: b+=[abs(a[i]-a[i+1])]
if len(set(b))>1:
print ('NO')
elif (len(set(b))==0):
print('YES')
print(10**9,10**9)
else:
for i in c:
if (i-1)%b[0]==0:
print('NO')
exit()
print ('YES')
print (10**9, b[0])
```
Yes
| 87,266 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
from math import ceil
def count_xy(n, b):
y = -1
pr = b[0]
xy = pr
for i in range(1, n):
a = b[i]
xy = max(xy, a)
if a == pr:
continue
if abs(a-pr) == 1:
pr = a
continue
if y == -1 or y == abs(pr-a):
y = abs(pr-a)
pr = a
continue
xy = -1
break
if xy == -1:
return -1, -1
else:
pr = b[0]
for i in range(1, n):
a = b[i]
if abs(a-pr) == 1 and min(a, pr)%y == 0 and y != -1:
return -1, -1
if y == -1:
y = 1
return ceil(xy/y), y
n = int(input())
b = [int(x) for x in input().split()]
x, y = count_xy(n, b)
if x == -1:
print("NO")
else:
print("YES")
print(x, y)
```
No
| 87,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
x=max(a)
y = -1
ans = "YES"
for i in range(n-1):
da = abs(a[i+1]-a[i])
if (da>1):
if (y==-1):
y = da
elif (y!=da):
ans = "NO"
break
if (da==0):
ans = "NO"
break
if (ans!="NO"):
for i in range(n - 1):
da = abs(a[i + 1] - a[i])
if ((da==1)&(int((a[i+1]-1)/y)!=int((a[i]-1)/y))):
ans = "NO"
break
x = int(max(a)/y)+1
if (n==1):
x = a[n-1]
y = a[n-1]
print(ans)
if (ans=="YES"):
print(x,y)
```
No
| 87,268 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
yy = 1
for i in range(1, n):
if abs(a[i] - a[i - 1]) != 1:
yy = abs(a[i] - a[i - 1])
break
xmin, xmax = 0, 0
x = 0
ymin, ymax = 0, 0
y = 0
for i in range(n - 1):
if a[i + 1] - a[i] == yy:
if a[i + 1] - a[i] != yy:
print('NO')
exit(0)
x += 1
xmax = max(xmax, x)
elif a[i + 1] - a[i] == -yy:
if a[i] - a[i + 1] != yy:
print('NO')
exit(0)
x -= 1
xmin = min(xmin, x)
elif a[i + 1] - a[i] == -1:
y -= 1
ymin = min(ymin, y)
else:
y += 1
ymax = max(ymax, y)
y = ymax - ymin + 1
x = xmax - xmin + 1
if y > yy:
print('NO')
else:
print('YES')
print(x, yy)
```
No
| 87,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a matrix A of size x Γ y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
1. (i + 1, j) β only if i < x;
2. (i, j + 1) β only if j < y;
3. (i - 1, j) β only if i > 1;
4. (i, j - 1) β only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
Input
The first line contains one integer number n (1 β€ n β€ 200000) β the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 β€ ai β€ 109) β the integers in the cells on your path.
Output
If all possible values of x and y such that 1 β€ x, y β€ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
Examples
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
Note
The matrix and the path on it in the first test looks like this:
<image>
Also there exist multiple correct answers for both the first and the third examples.
Submitted Solution:
```
n = int(input())
walk = list(map(int, input().split()))
flag = 0
index = walk[0]
prevC = walk[0]
breakFlag = 0
raw = 1
for i in range(n - 1):
temp = walk[i + 1] - walk[i]
if temp == 1:
#print("R")
index+=1
if index>prevC:
prevC += 1
elif temp == -1:
#print("L")
continue
elif temp > 1:
raw += 1
#print("D")
if flag == 0:
prevC = abs(temp)
flag = 1
else:
if prevC == abs(temp):
continue
else:
breakFlag = 1
break
#print(raw)
elif temp < 0:
#print('U')
if flag == 0:
prevC = abs(temp)
flag = 1
else:
if prevC == abs(temp):
continue
else:
breakFlag = 1
break
elif temp == 0:
breakFlag = 1
break
if breakFlag == 1:
print("NO")
else:
print("YES")
print(raw, prevC)
```
No
| 87,270 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n,k=list(map(int, input().split(' ')))
def print_res(lst):
for i in lst:
print(''.join(i))
res=[['.']*n] + [['.']*n] + [['.']*n] + [['.']*n]
if k==0:
print('YES')
print_res(res)
elif k>(n-2)*2:
print('NO')
elif k==n-2:
print('YES')
res[1]=['.']+['#'*k]+['.']
# res[1][0]='.'
# res[1][-1]='.'
print_res(res)
elif k%2==0:
print("YES")
for i in range(k//2):
res[1][i+1]='#'
res[2][i+1]='#'
print_res(res)
elif k<(n-2):
print("YES")
res[1]=['.'*((n-k)//2)]+['#'*(k)]+['.'*((n-k)//2)]
print_res(res)
elif k>(n-2):
print("YES")
res[1]=['.']+['#'*(n-2)]+['.']
x=(k-n+2)//2
for i in range(x):
res[2][i+1]='#'
res[2][-i-2]='#'
# res[2]=['.']+['#'*()]+['.']+['#'*((k-n+2)//2)]+['.']
print_res(res)
else:
print('NO')
```
| 87,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n, k = map(int, input().split())
def generate_hotels_even(n, k):
city = [None] * 4
for i in range(4):
city[i] = ['.'] * n
for i in range(k//2):
city[1][i + 1] = '#'
city[2][i + 1] = '#'
return '\n'.join(map(lambda x: ''.join(x), city))
def generate_hotels_odd_1(n, k):
city = [None] * 4
for i in range(4):
city[i] = ['.'] * n
city[1] = '.' * ((n - k)//2) + '#' * k + '.' * ((n - k)//2)
return '\n'.join(map(lambda x: ''.join(x), city))
def generate_hotels_odd_2(n, k):
city = [None] * 4
for i in range(4):
city[i] = ['.'] * n
city[1] = '.' + '#' * (n - 2) + '.'
leftover = k - (n - 2)
city[2] = '.' * ((n - leftover)//2) + '#' * (leftover // 2) + '.' + '#' * (leftover // 2) + '.' * ((n - leftover)//2)
return '\n'.join(map(lambda x: ''.join(x), city))
if k%2 == 0:
print("YES")
print(generate_hotels_even(n, k))
elif k <= n - 2:
print("YES")
print(generate_hotels_odd_1(n, k))
else:
print("YES")
print(generate_hotels_odd_2(n, k))
```
| 87,272 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n, k = map(int, input().split())
print("YES")
x = [["." for i in range(n)] for _ in range(4)]
curr = 1
if(k % 2 != 0):
while k > 2 and curr != n // 2:
x[1][curr] = "#"
x[1][n - curr-1] = "#"
curr += 1
k -= 2
curr = 1
while k > 2 and curr != n // 2:
x[2][curr] = "#"
x[2][n - curr - 1] = "#"
curr += 1
k -= 2
x[1][n//2] = "#"
else:
curr = 1
while k > 0:
x[1][curr] = "#"
x[2][curr] = "#"
curr += 1
k -= 2
for i in x:
print(''.join(i))
```
| 87,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n,k = [int(s) for s in input().split()]
def line(h=0):
if h < 0: h = 0
if h > n-2: h = n-2
if h%2 == 1:
ans = '.'*((n-h)//2) + '#'*h + '.'*((n-h)//2)
else:
ans = '.' + '#'*(h//2) + '.'*(n-h-2) + '#'*(h//2) + '.'
return ans
if k > 2*(n-2):
print("NO")
else:
print("YES")
print(line())
print(line(k))
print(line(k-(n-2)))
print(line())
```
| 87,274 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n, k = list(map(int, input().split()))
if 2 * (n - 2) < k:
print('NO')
else:
print('YES')
total = 0
arr = []
for j in range(4):
arr.append(['.' for i in range(n)])
if k % 2 == 0:
for j in range(1, n - 1):
for i in range(1, 3):
if total < k:
arr[i][j] = '#'
total += 1
else:
break
if total >= k:
break
elif k == 1:
arr[1][n // 2] = '#'
elif k == 3:
arr[1][n // 2] = '#'
arr[1][(n // 2) - 1] = '#'
arr[1][(n // 2) + 1] = '#'
else:
arr[1][1] = '#'
arr[1][2] = '#'
arr[2][1] = '#'
total = 3
for j in range(3, n - 1):
for i in range(1, 3):
if total < k:
arr[i][j] = '#'
total += 1
else:
break
if total >= k:
break
s = ''
for row in arr:
s += row[0]
for c in row[1:]:
s += c
s += '\n'
print(s)
```
| 87,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n, k = map(int, input().split())
print('YES')
print('.' * n)
if k % 2 == 0:
print('.' + '#' * (k // 2) + '.' * (n - (k // 2) - 2) + '.')
print('.' + '#' * (k // 2) + '.' * (n - (k // 2) - 2) + '.')
else:
it = min((n - 2), k)
off = ((n - 2) - it) // 2
k -= it
print('.' * (off + 1) + '#' * it + '.' * (off + 1))
print('.' + '#' * (k // 2) + '.' * (n - k - 2) + '#' * (k // 2) + '.')
print('.' * n)
```
| 87,276 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
s=list(map(int,input().split()))
n=s[0]
k=s[1]
l=[ [ "." for j in range(n) ] for i in range(4)]
if k%2==0:
s=k//2
for i in range(1,s+1):
l[1][i]="#"
l[2][i]="#"
else:
s=(k-1)//2
l[1][n//2]="#"
if s>((n-3)//2):
for i in range(1,s+1):
l[1][i]="#"
l[1][n-1-i]="#"
diff=s-((n-3)//2)
for i in range(1,diff+1):
l[2][i]="#"
l[2][n-1-i]="#"
else:
for i in range(1,s+1):
l[1][i]="#"
l[1][n-1-i]="#"
print("YES")
for i in range(4):
print("".join(l[i]))
```
| 87,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Tags: constructive algorithms
Correct Solution:
```
n,k=map(int,input().split())
ch1="."*n
"""LOOOOOOOOOOOOOOOOOOOOOOOOOL this is so easy man i want some juicy ratinng"""
if(k%2==0):
print("YES")
ch2="."+"#"*(k//2)+"."*(n-(k//2)-1)
ch3="."+"#"*(k//2)+"."*(n-(k//2)-1)
print(ch1)
print(ch2)
print(ch3)
print(ch1)
else:
if(k<=n-2):
print("YES")
ch2="."*((n-k)//2)+"#"*k+"."*((n-k)//2)
ch3=ch1
print(ch1)
print(ch2)
print(ch3)
print(ch1)
else:
print("YES")
p=k-n+2
ch2="."+"#"*(n-2)+"."
ch3="."+"#"*(p-1)+"."*(n-p-2)+"#"+"."
print(ch1)
print(ch2)
print(ch3)
print(ch1)
```
| 87,278 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = (int(x) for x in input().split())
print('YES')
empty = '.' * n
if k % 2 != 0 and k < n - 2:
frst = '#' * k
frst = '.' * ((n - k) // 2) + frst + '.' * ((n - k) // 2)
scnd = empty
elif k % 2 != 0:
frst = '.' + '#' * (n - 2) + '.'
scnd = '.' + '#' * ((k - n + 2) // 2)
scnd = scnd + '.' * (n - len(scnd) * 2) + scnd[::-1]
elif k % 2 == 0:
frst = '.' + '#' * (k // 2) + '.' * n
frst = frst[:n]
scnd = frst
print(empty)
print(frst)
print(scnd)
print(empty)
```
Yes
| 87,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = map(int, input().split())
if k % 2 == 0:
print('YES')
print('.' * n)
print('.' + '#' * (k // 2) + '.' * (n - 1 - k // 2))
print('.' + '#' * (k // 2) + '.' * (n - 1 - k // 2))
print('.' * n)
elif k == (n-2):
print('YES')
print('.' * n)
print('.' + '#' * k + '.' * (n - 1 - k))
print('.' * n)
print('.' * n)
elif k >= 5:
print('YES')
print('.' * n)
print('.' + '#' * (k // 2 + 1) + '.' * (n - 2 - k//2))
print('.' + '#' * (k // 2 - 1) + '.#' + '.' * (n - 2 - k//2))
print('.' * n)
elif k == 3 and n >= 5:
print('YES')
print('.' * n)
print('.' * ((n - 3) // 2) + '#.#' + '.' * ((n - 3) // 2))
print('.' * ((n - 1) // 2) + '#' + '.' * ((n - 1) // 2))
print('.' * n)
elif k == 1:
print('YES')
print('.' * n)
print('.' * n)
print('.' * ((n - 1) // 2) + '#' + '.' * ((n - 1) // 2))
print('.' * n)
else:
print('NO')
```
Yes
| 87,280 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = map(int, input().split())
a = ['.' * n for i in 'iiii']
if k > n - 2:
a[1] = '.' + '#' * (n - 2) + '.'
k -= n - 2
a[2] = '.' + '#' * (k >> 1) + '.' * (n - 2 - k >> 1)
a[2] = a[2] + ('#' if k & 1 else '.') + a[2][::-1]
print('YES')
print('\n'.join(a))
```
Yes
| 87,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = [int(x) for x in input().split()]
if k % 2 == 0:
print("YES")
print("."*n)
print("." + "#" * (k // 2) + "." * (n - 1 - k//2))
print("." + "#" * (k // 2) + "." * (n - 1 - k//2))
print("."*n)
elif n % 2 == 1:
print("YES")
print("."*n)
top = min(k, n-2)
bot = (k - top)
print("." * ((n - top) // 2) + "#" * top + "." * ((n - top) // 2))
print("." + "#" * (bot // 2) + "." * (n - 2 - bot) + "#" * (bot // 2) + ".")
print("."*n)
else:
print("NO")
```
Yes
| 87,282 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = [int(x) for x in input().split(' ')]
if (k == 0):
print('YES')
print('.' * n)
print('.' * n)
print('.' * n)
print('.' * n)
elif (k % 2 == 0):
print('YES')
print('.' * n)
print('.' + '#' * int(k / 2) + '.' * (n - 1 - int(k / 2)))
print('.' + '#' * int(k / 2) + '.' * (n - 1 - int(k / 2)))
print('.' * n)
else:
if (k % 2 == 1 and k < 5):
print('NO')
elif (k % 2 == 1 and k == (n - 2)):
print('YES')
print('.' * n)
print('.' + '#' * (n - 2) + '.')
print('.' * n)
print('.' * n)
elif (k % 2 == 1 and (k - n + 2) >= 2):
print('YES')
print('.' * n)
print('.' + '#' * (n - 2) + '.')
print('.' + '#' * (k - n + 1) + '.' * ((n - 3) - (k - n + 1)) + '#.')
print('.' * n)
elif (k % 2 == 1 and k >= 5):
print('YES')
print('.' * n)
k1 = int((k - 5) / 2)
print('.###' + '#' * k1 + '.' * (n - 5 - k1) + '.')
print('.#.#' + '#' * k1 + '.' * (n - 5 - k1) + '.')
print('.' * n)
```
No
| 87,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = map(int, input().split())
print("YES")
x = [["." for i in range(n)] for _ in range(4)]
curr = 1
while k > 2 and curr != n // 2:
x[1][curr] = "#"
x[1][n - curr-1] = "#"
curr += 1
k -= 2
curr = 1
while k > 2 and curr != n // 2:
x[2][curr] = "#"
x[2][n - curr - 1] = "#"
curr += 1
k -= 2
x[1][n//2] = "#"
if(k == 2):
x[2][n// 2]= "#"
for i in x:
print(''.join(i))
```
No
| 87,284 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n,k=map(int,input().split())
if k>2*(n-1):
print("NO")
else :
print("YES")
print('.'*n)
x=(k+1)//2
print('#'*x+'.'*(n-x))
x=k//2
print("#"*x+'.'*(n-x))
print('.'*n)
```
No
| 87,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).
The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.
A person can move from one cell to another if those cells are not occupied by hotels and share a side.
Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
Input
The first line of input contain two integers, n and k (3 β€ n β€ 99, 0 β€ k β€ 2Γ(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.
Output
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.
Examples
Input
7 2
Output
YES
.......
.#.....
.#.....
.......
Input
5 3
Output
YES
.....
.###.
.....
.....
Submitted Solution:
```
n, k = map(int, input().split())
if(k % 2 != 0 and n - k != 2):
print("NO")
exit()
print("YES")
x = [["." for i in range(n)] for _ in range(4)]
if(k % 2 == 0):
curr = 1
while k > 0:
x[1][curr] = "#"
x[2][curr] = "#"
curr += 1
k -= 2
else:
x[1] = ["#" for i in range(n)]
x[1][0] = "."
x[1][n-1] ="."
for i in x:
print(''.join(i))
```
No
| 87,286 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
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)]
def dist(x2, y2=0):
return sqrt((x - x2) ** 2 + (y - y2) ** 2)
n, vb, vs = sp()
arr = l()
x, y = sp()
answer = 0
m = inf
d = inf
for i in range(1, n):
time = arr[i] / vb
time += dist(arr[i]) / vs
if time < m:
answer = i
m = time
d = dist(arr[i])
elif time == m and dist(arr[i]) < d:
answer = i
d = dist(arr[i])
out(answer + 1)
```
| 87,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
import math
n, bus_velocity, student_velocity = map(int, input().split())
stops = list(map(int, input().split()))
uni = list(map(int, input().split()))
ans = []
for i in range(1, len(stops)):
# time = distance/velocity
t = stops[i] / bus_velocity + math.hypot(uni[0] - stops[i], uni[1]) / student_velocity
# distance from the stop to the university
d = math.hypot(uni[0] - stops[i], uni[1])
# the bus stop position
position = i + 1
ii = (t, d, position)
ans.append(ii)
print(min(ans)[2])
```
| 87,288 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
inp = list(map(int,input().split()))
n=inp[0]
vb=inp[1]
vs=inp[2]
inp = list(map(int,input().split()))
from collections import Counter
c=Counter([])
for i in range(len(inp)):
c[inp[i]]=i+1
inp=inp[1:]
tar = list(map(int,input().split()))
x=tar[0]
y=tar[1]
z=[(t/vb+(pow((x-t)**2+y**2,0.5))/vs) for t in inp]
k=min(z)
arr=[]
for i in range(len(z)):
if z[i]==k:
arr.append(i)
arr.sort(key=lambda m:(inp[m]-x)**2+y**2)
print (arr[0]+2)
```
| 87,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
n, vb, vs = map(int, input().split())
a = list(map(int, input().split()))
xu, yu = map(int, input().split())
m = 10000 * 100000
r = ((xu ** 2 + yu ** 2)**0.5)
ans = 0
for i in range(1, len(a)):
if (((xu - a[i]) ** 2 + yu ** 2)**0.5) / vs + a[i] / vb <= m:
if (((xu - a[i]) ** 2 + yu ** 2)**0.5) / vs + a[i] / vb == m:
if (((xu - a[i]) ** 2 + yu ** 2)**0.5) < r:
m = (((xu - a[i]) ** 2 + yu ** 2)**0.5) / vs + a[i] / vb
ans = i
r = (((xu - a[i]) ** 2 + yu ** 2)**0.5)
else:
m = (((xu - a[i]) ** 2 + yu ** 2)**0.5) / vs + a[i] / vb
ans = i
r = (((xu - a[i]) ** 2 + yu ** 2)**0.5)
#print((((xu - a[i]) ** 2 + yu ** 2)**0.5) / vs + a[i] / vb)
print(ans + 1)
```
| 87,290 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
import math
n, v1, v2 = input().split()
n = int(n)
v1 = int(v1)
v2 = int(v2)
t = input().split()
x ,y = input().split()
x = int(x)
y = int(y)
min1 = 1
x1 = int(t[1])
d1 = math.sqrt((x-x1)**2+y**2)
time1 = x1 / v1 + d1 / v2
for i in range(2, n):
x1 = int(t[i])
d = math.sqrt((x-x1)**2+y**2)
time = x1 / v1 + d / v2
if time1 > time :
time1 = time
min1 = i
d1 = d
elif time == time1 and d < d1 :
time1 = time
min1 = i
d1 =d
print(min1+1)
```
| 87,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
while True:
try:
import math
def soln(n, vb, vs, a, x2, y2):
mint = 10**8*(1.0)
#print(mint)
pos = 0
for i in range(1,n):
x1= a[i]
y1 = 0
s = math.sqrt((x2-x1)**2+(y2-y1)**2)
t = s/vs + x1/vb
#print(t)
if t <= mint:
pos = i+1
mint = t
#print(pos, " pos")
print(pos)
def read():
n, vb, vs = map(int, input().split())
a = list(map(float, input().split()))
ux, uy = map(float, input().split())
soln(n, vb, vs, a, ux, uy)
if __name__ == "__main__":
read()
except EOFError:
break
```
| 87,292 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
def dist(x):
return ((x - u) ** 2 + v * v) ** .5
n, a, b = map(int, input().split())
*x, = map(int, input().split())
u, v = map(int, input().split())
min_d = min_t = 1e9
min_ind = 0
for i in range(1, n):
d = dist(x[i])
tmp = x[i] / a + d / b
if min_t > tmp or min_t == tmp and min_d > d:
min_ind, min_d, min_t = i + 1, d,tmp
print(min_ind)
```
| 87,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Tags: brute force, geometry, implementation
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict, deque
import heapq
getcontext().prec = 25
abcd='abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right
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")
# n, k = map(int, input().split(" "))
# list(map(int, input().split(" ")))
# for _ in range(int(input())):
n, v1, v2 = map(int, input().split(" "))
l = list(map(int, input().split(" ")))
x, y = map(int, input().split(" "))
ans = 1
m = 9999999999999
for i in range(1, n):
vs = l[i]/v1 + (math.sqrt(y**2 + (abs(x-l[i]))**2))/v2
if vs <= m:
ans = i+1
m = vs
print(ans)
```
| 87,294 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Submitted Solution:
```
from fractions import Fraction
from math import sqrt
n, vb, vs = map(int, input().split())
a = [int(i) for i in input().split()]
xu, yu = map(int, input().split())
mn_time = float("inf")
mn_dist = float("inf")
ind = -1
eps = 1e-8
for i, pos in enumerate(a[1:]):
time_to_pos = pos / vb
dist = sqrt((pos - xu) ** 2 + yu ** 2)
time_to_finish = dist / vs
time = time_to_pos + time_to_finish
if time < mn_time:
mn_time = time
mn_dist = dist
ind = i + 2
elif abs(time - mn_time) < eps:
if dist < mn_dist:
mn_time = time
mn_dist = dist
ind = i + 2
print(ind)
```
Yes
| 87,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Submitted Solution:
```
"""
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0,β0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
during one run the minibus makes n stops, the i-th stop is in point (xi,β0)
coordinates of all the stops are different
the minibus drives at a constant speed, equal to vb
it can be assumed the passengers get on and off the minibus at a bus stop momentarily
Student can get off the minibus only at a bus stop
Student will have to get off the minibus at a terminal stop, if he does not get off earlier
the University, where the exam will be held, is in point (xu,βyu)
Student can run from a bus stop to the University at a constant speed vs as long as needed
a distance between two points can be calculated according to the following formula:
Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2ββ€βnββ€β100, 1ββ€βvb,βvsββ€β1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xnββ€β105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
"""
from math import *
def get_input_list_ints():
return list(map(int, input().split()))
def cart_dist(value):
return sqrt(pow(school_coordinates[0] - value, 2) + pow(school_coordinates[1], 2))
n, vb, vs = get_input_list_ints()
bus_stops = get_input_list_ints()
school_coordinates = get_input_list_ints()
bus_stops_no = len(bus_stops)
min_time = (bus_stops[1]/vb) + (cart_dist(bus_stops[1])/vs)
min_index = 1
if bus_stops_no > 2:
time = []
for index, value in enumerate(bus_stops[2:]):
new_time = (value/vb) + (cart_dist(value)/vs)
time.append(new_time)
if new_time <= min_time: # <= bc if there are two stations with the same time, we talk the later so he doesn't run/walk when he could easily ride the bus
min_time = new_time
min_index = index + 2 # plus me starting the search from the 2nd stop as he can't get off in the first one
print(min_index + 1) # the + 1 due to the indices starting with 0
else:
print(bus_stops_no)
```
Yes
| 87,296 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Submitted Solution:
```
n,vb,vs=[int(x) for x in input().split()]
l=[int(x) for x in input().split()]
xu,yu=[int(x) for x in input().split()]
mint=float("inf")
for i in range(1,n):
d1=l[i]
t1=d1/vb
d2=((xu-l[i])**2 + yu**2)**0.5
t2=d2/vs
# print(d1,d2)
# print(t1,t2)
if t1+t2<=mint:
mint=t1+t2
j=i
else:
break
print(j+1)
```
Yes
| 87,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Submitted Solution:
```
# -*- coding: utf-8 -*-
n,vb,vs = map(int, input().split())
a = list(map(float, input().split()))
x,y = map(float,input().split())
dist,index = 10**10,0
for i in range(1,n):
eucl = (((x-a[i])**2+y**2)**0.5)/vs+a[i]/vb
if eucl <= dist:
dist,index = eucl,i
print(index+1)
```
Yes
| 87,298 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
* during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
* coordinates of all the stops are different
* the minibus drives at a constant speed, equal to vb
* it can be assumed the passengers get on and off the minibus at a bus stop momentarily
* Student can get off the minibus only at a bus stop
* Student will have to get off the minibus at a terminal stop, if he does not get off earlier
* the University, where the exam will be held, is in point (xu, yu)
* Student can run from a bus stop to the University at a constant speed vs as long as needed
* a distance between two points can be calculated according to the following formula: <image>
* Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
Input
The first line contains three integer numbers: 2 β€ n β€ 100, 1 β€ vb, vs β€ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn β€ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
Output
In the only line output the answer to the problem β index of the optimum bus stop.
Examples
Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.
Submitted Solution:
```
from math import sqrt
n,vb,vs = list(map(int,input().split()))
xl = list(map(int,input().split()))
xii,yii = list(map(int,input().split()))
time = lambda rsb,xs,x,y: rsb*xs + sqrt((x-xs)*(x-xs)+y*y)
times = [time(vs/vb,xl[i],xii,yii) for i in range(1,n)]
print(times.index(min(times)) + 2)
```
No
| 87,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.