text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
s = input()
m = 0
count = 0
for i in s:
if i in ["A","C","G","T"]: count+=1
else: count=0
m = max(m,count)
print(m)
```
| 94,200 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
print(max(map(lambda x:len(x), "".join([_ if _ in "ACGT" else "_" for _ in str(input())]).split("_"))))
```
| 94,201 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
import re
s=re.split("[^ACGT]", input())
a=[]
for i in range(len(s)):
a.append(len(s[i]))
print(max(a))
```
| 94,202 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
import re
print(max(list(map(len, re.compile(r'[A|G|C|T]*').findall(input())))))
```
Yes
| 94,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
S = input()
ans = 0
l = 0
for c in S:
if c in 'ATCG':
l += 1
ans = max(ans, l)
else:
l = 0
print(ans)
```
Yes
| 94,204 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
s=input()
k = 0
m = 0
for z in s:
if z in "ACGT":
k += 1
if m < k:
m = k
else:
k = 0
print(m)
```
Yes
| 94,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
S=input()
ans=cur=0
for c in S:
if c in 'ACGT':
cur+=1
ans=max(ans,cur)
else:
cur=0
print(ans)
```
Yes
| 94,206 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[11]:
S=input()
t=list()
ct=0
for i in range(len(S)):
if S[i]=='A' or S[i]=='C' or S[i]=='T' or S[i]=='G':
i+=1
ct+=1
else:
t.append(ct)
ct=0
i+=1
print(max(t))
# In[ ]:
```
No
| 94,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
s = input()
acgt = {"A", "C", "G", "T"}
ans = 0
now = 0
for i in range(len(s)):
if s[i] in acgt:
now += 1
else:
ans = max(ans, now)
now = 0
print(ans)
```
No
| 94,208 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
S = input()
l= len(S)
ans = 0
for i in range(l):
for j in range(l-i):
seq = S[i:i+j]
seq2 = seq.replace("A","").replace("G","").replace("T","").replace("C","")
if seq2 == "":
ans = max(ans, len(seq))
print(ans)
```
No
| 94,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
Submitted Solution:
```
import sys
arg = input()
scavenger=''
warehouse=[]
longest=0
i=0
for tmp in arg[0:]:
if tmp=='A' or tmp=='T' or tmp=='C' or tmp=='G':
scavenger=scavenger+tmp
else:
warehouse.append(scavenger)
scavenger=''
for tmp in warehouse[0:]:
if len(tmp)>longest:
longest=len(tmp)
print(longest)
```
No
| 94,210 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
N,M=map(int,input().split());import fractions;L=M//fractions.gcd(M,N)*N;print((-1,L)[input()[::L//M]==input()[::L//N]])
```
| 94,211 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
N,M=map(int,input().split())
n,m=N,M
s=input()
t=input()
while m:
n,m=m,n%m
gcd=n
lcm=N*M//gcd
step1=N//gcd
step2=M//gcd
if all(s[i*step1]==t[i*step2] for i in range(gcd)):
print(lcm)
else:
print(-1)
```
| 94,212 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
g = gcd(N, M)
lcm = N * M // g
for i in range(g):
if S[i*N//g] != T[i*M//g]:
print(-1)
exit()
print(lcm)
```
| 94,213 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
import fractions
n, m = map(int, input().split())
s = input()
t = input()
sr = fractions.gcd(n, m)
sg, tg = n // sr, m // sr
for i in range(sr):
if s[i * sg] != t[i * tg]:
print(-1)
exit()
print(sg * m)
```
| 94,214 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
from math import gcd
def lcm(a,b):
return a*b//gcd(a,b)
N,M = map(int,input().split())
S = input()
T = input()
g = gcd(N,M)
l = lcm(N,M)
for i in range(g):
if S[l//M*i] != T[l//N*i]:
print(-1)
exit()
print(l)
```
| 94,215 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
n,m=map(int,input().split())
s=input()
t=input()
import fractions
g=fractions.gcd(n,m)
m0=m//g
n0=n//g
i=0
while i*n0<n and i*m0<m:
if s[i*n0]==t[i*m0]:
pass
else:
print(-1)
exit()
i+=1
print(n*m//g)
```
| 94,216 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
from fractions import gcd
N, M = map(int, input().split(" "))
S = input()
T = input()
G = gcd(N, M)
L = N * M // G
for i in range(G):
if S[i*N//G] != T[i*M//G]:
print(-1)
exit(0)
print(L)
```
| 94,217 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
"Correct Solution:
```
from fractions import gcd
N, M = map(int, input().split())
S, T = [input() for _ in range(2)]
L = gcd(N, M)
print(N*M//L if all([S[i*N//L] == T[i*M//L] for i in range(L)]) else -1)
```
| 94,218 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
from fractions import gcd
n, m = map(int, input().split())
s = list(input())
t = list(input())
i = 1
ans = n * m // gcd(n, m)
g = gcd(n, m)
for i in range(g):
if s[i * n // g] != t[i * m // g]:
ans = -1
break
print(ans)
```
Yes
| 94,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
n,m=map(int,input().split());g=m-max([a*n%m for a in range(m)]);print(-1if input()[::n//g]!=input()[::m//g]else n*m//g)
```
Yes
| 94,220 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
import fractions
n, m = map(int,input().split())
s = input()
t = input()
q = fractions.gcd(n, m)
l = n * m // q #lcm(n, m)
for i in range(0, q):
if s[i * n//q] != t[i * m//q]:
print('-1')
exit()
print(l)
```
Yes
| 94,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
def gcd(a, b):
while b:
a, b = b, a % b
return a
N,M = map(int,input().split())
s = input()
t = input()
g = gcd(N,M)
l = N*M//g
n = N//g
m = M//g
ans = l
for i in range(g):
if s[i*n]!=t[i*m]:
ans = -1
break
print(ans)
```
Yes
| 94,222 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
# A
def gcd(a, b):
while b:
a, b = b, a % b
return a
N, M = list(map(int, input().split()))
S = input()
T = input()
re = -1
# 1文字目が必ず一緒であること
if S[0] == T[0]:
if N == M:
if S == T:
re = N
else:
min_num = (N * M) // gcd(N, M) # 最小公倍数を求める(基本はこれが答え)
re = min_num
# 重なる部分が同じ文字かを調べる
s_d = min_num // N
t_d = min_num // M
# 最小公倍数みる
st_min = (s_d * t_d) // gcd(s_d, t_d)
st = st_min
i = 1
while st // s_d < N and st // t_d < M:
if S[st // s_d] != T[st // t_d]:
re = -1
break
else:
i += 1
st = st * i
print(re)
```
No
| 94,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
n,m=map(int,input().split())
s=input()
t=input()
def gcd(x,y):
r=x%y
return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
return (x * y) // gcd(x, y)
L=lcm(n,m)
if s[0]==t[0]:
X=[""]*(L+1)
else:
print(-1)
exit()
for i in range(1,n):
X[int(i*L/n)+1]=s[i]
for i in range(1,m):
if X[int(i*L/m)+1] !="":
if X[int(i*L/m)+1] !=t[i]:
print(-1)
exit()
print(L)
```
No
| 94,224 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
n, m = list(map(int, input().split()))
s = input()
t = input()
flag = False
def gcd(a, b):
while b:
a, b = b, a%b
return a
l = int(n*m / gcd(n, m))
if max(n, m) % min(n, m) != 0:
print(l if s[0] == t[0] else -1)
exit()
if len(s) < len(t):
tmp = s
s = t
t = tmp
if len(s) == len(t):
if s == t:
print(len(s))
exit()
else:
print(-1)
exit()
for j in [1, 2, 3, 5]:
for i in range(1, m):
if s[j*i*(n//m)] != t[i]:
print(-1)
exit()
print(l)
```
No
| 94,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the shortest such string.
Constraints
* 1 \leq N,M \leq 10^5
* S and T consist of lowercase English letters.
* |S|=N
* |T|=M
Input
Input is given from Standard Input in the following format:
N M
S
T
Output
If a good string does not exist, print `-1`; if it exists, print the length of the shortest such string.
Examples
Input
3 2
acp
ae
Output
6
Input
6 3
abcdef
abc
Output
-1
Input
15 9
dnsusrayukuaiia
dujrunuma
Output
45
Submitted Solution:
```
from fractions import gcd
N.M=(int(i) for i in input.split())
S=input()
T=input()
gcd_NM=gcd(N,M)
lcm_NM=(N*M//gcd_NM)
A=True
for i in range(gcd_NM):
if S[(N//gcd_NM)*i]!=T[(M//gcd_NM)*i]:
A=False
break
if A:
print(lcm_NM)
else:
print(-1)
```
No
| 94,226 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
N = int(input())
X_list = list(map(int, input().split()))
X_list_min = sorted(X_list)
for i in range(N):
if X_list_min[N//2-1] >= X_list[i]:
print(X_list_min[N//2])
else:
print(X_list_min[N//2-1])
```
| 94,227 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
import copy
N = int(input())
X = []
X = [int(i) for i in input().split()]
Y = copy.deepcopy(X)
Y.sort()
largeMedian = Y[int(N / 2)]
smallMedian = Y[int(N / 2)-1]
for i in range(N):
if X[i] <= smallMedian:
X[i] = largeMedian
else:
X[i] = smallMedian
for i in range(N):
print(X[i])
```
| 94,228 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
n = int(input())
x = list(map(int, input().split()))
use = x[::]
use.sort()
l = use[n//2-1]
r = use[n//2]
for i in x:
if i <= l:
print(r)
else:
print(l)
```
| 94,229 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
for i in range(n):
if x[i]<=xx[n//2-1]:
print(xx[n//2])
else:
print(xx[n//2-1])
```
| 94,230 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
N = int(input())
X = list(map(int,input().split()))
S = X[:]
S.sort()
C1 = S[(N//2)-1]
C2 = S[N//2]
for x in X:
if x >= C2:
print(C1)
else:
print(C2)
```
| 94,231 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
N = int(input())
X = [int(i) for i in input().split()]
Y = sorted(X)
left = Y[N//2 -1]
right = Y[N//2 ]
for x in X:
if x<=left:
print(right)
else:print(left)
```
| 94,232 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
n = int(input())
cn = n//2
lis = list(map(int,input().split()))
slis = sorted(lis)
if slis[cn-1] == slis[cn]:
for i in range(len(lis)):
print(slis[cn])
else:
for item in lis:
if item >= slis[cn]:
print(slis[cn-1])
else:
print(slis[cn])
```
| 94,233 |
Provide a correct Python 3 solution for this coding contest problem.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
"Correct Solution:
```
n, *lst = map(int, open(0).read().split())
a, b = sorted(lst)[n // 2 - 1:n // 2 + 1]
if a == b:
print(*[a for _ in range(n)], sep='\n')
else:
print(*[b if i <= a else a for i in lst], sep='\n')
```
| 94,234 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
for i in range(N):
if X[i] < Y[N//2]:
print(Y[N // 2])
else:
print(Y[(N-1) // 2])
```
Yes
| 94,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
arr = list(map(int, input().split()))
arr2 = sorted(arr)
mean1 = arr2[N//2-1]
mean2 = arr2[N//2]
for a in arr:
if a <= mean1:
print(mean2)
else:
print(mean1)
```
Yes
| 94,236 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
Xs = list(map(int, input().split()))
M1, M2 = sorted(Xs)[N // 2 - 1: N // 2 + 1]
for X in Xs:
if X < M2:
print(M2)
else:
print(M1)
```
Yes
| 94,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
def find(A):
X=[(A[i],i) for i in range(len(A))]
X=sorted(X)
ans=[0]*len(X)
p1=(len(A)-1)//2
p2=len(A)//2
#print(p1,p2)
for i in range(len(X)):
a,b=X[i]
if i<p2:
ans[b]=X[p2][0]
else:
ans[b]=X[p1][0]
return ans
input()
A=[str(x) for x in find(list(map(int,input().strip().split(" "))))]
print("\n".join(A))
```
Yes
| 94,238 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
a = int(input())
ar = list(map(int,input().split(" ")))
b = a // 2 - 1
for i in range(a):
br = ar[0:i] + ar[i+1:a]
br.sort()
print(br[b])
```
No
| 94,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N=int(input())
inp=list(map(int, input().strip().split(' ')))
med = int(N/2)
for i in range(N):
X=[]
for j in range(N):
if i!=j:
X.append(inp[j])
Xsort = sorted(X)
print(Xsort[med-1])
```
No
| 94,240 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
from numpy import median
from copy import deepcopy
n = int(input())
x = list(map(int,input().split()))
sx = x.sorted()
newl = deepcopy(sx)
del newl[0]
bigm = median(newl)
newl = deepcopy(sx)
del newl[-1]
minm = median(newl)
med = median(x)
for i in x:
if i > med:
print(minm)
else:
print(maxm)
```
No
| 94,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.
Constraints
* 2 \leq N \leq 200000
* N is even.
* 1 \leq X_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N
Output
Print N lines. The i-th line should contain B_i.
Examples
Input
4
2 4 4 3
Output
4
3
3
4
Input
2
1 2
Output
2
1
Input
6
5 5 4 4 3 3
Output
4
4
4
4
4
4
Submitted Solution:
```
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s = b[(N-1)//2]
l = b[N//2]
for i in range(N):
if i > s:
print(s)
else:
print(l)
```
No
| 94,242 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]
for x in range(10):
for y in range(10):
for z in range(10):
c[y][z] = min(c[y][z], c[y][x] + c[x][z])
ans = 0
for x in range(h):
for y in range(w):
if a[x][y] >= 0:
ans += c[a[x][y]][1]
print(ans)
```
| 94,243 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in [0]*10]
a=[list(map(int,input().split())) for _ in [0]*h]
cost=[float('inf')]*10
cost[1]=0
for _ in [0]*9:
for i in range(10):
cost[i]=min(c[i][j]+cost[j] for j in range(10))
ans=0
for i in range(h):
for j in range(w):
if a[i][j]>=0:
ans+=cost[a[i][j]]
print(ans)
```
| 94,244 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [n for _ in range(H) for n in list(map(int, input().split()))]
o = [c[n][1] for n in range(10)]
for _ in range(10):
for i in range(10):
for t in range(10):
o[i] = min(o[i], c[i][t] + o[t])
print(sum([o[a] for a in A if a >= 0]))
```
| 94,245 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
H, W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]
for k in range(10):
for i in range(10):
for j in range(10):
C[i][j] = min(C[i][j], C[i][k] + C[k][j])
ans = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1:
ans += C[A[i][j]][1]
print(ans)
```
| 94,246 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j] = min(c[i][j], c[i][k] + c[k][j])
sum = 0
for i in range(h):
for j in range(w):
if a[i][j] >= 0:
sum += c[a[i][j]][1]
print(sum)
```
| 94,247 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
H,W=map(int,input().split())
C=[]
A=[]
for i in range(10):
C.append(list(map(int,input().split())))
for i in range(H):
A.append(list(map(int,input().split())))
# WF
for i in range(10):
for j in range(10):
for k in range(10):
C[j][k]=min(C[j][k], C[j][i]+C[i][k])
print(sum(sum(C[i][1] for i in AA if i >= 0) for AA in A))
```
| 94,248 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
N = 10
d = c
for k in range(N):
for i in range(N):
for j in range(N):
d[i][j] = min(d[i][j], d[i][k]+d[k][j])
ans = 0
for aa in A:
for a in aa:
if a!=-1:
ans += d[a][1]
print(ans)
```
| 94,249 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
"Correct Solution:
```
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for _ in range(h):
for i in map(int,input().split()):
if i!=-1:
ans+=c[i][1]
print(ans)
```
| 94,250 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
[H,W] = [int(s) for s in input().rstrip().split(" ")]
L = []
for num in range(10):
L.append([int(s) for s in input().rstrip().split(" ")])
for k in range(10):
for i in range(10):
for j in range(10):
L[i][j] = min(L[i][j],L[i][k] + L[k][j])
k = 0
for h in range(H):
L_h = [int(s) for s in input().rstrip().split(" ")]
for x in L_h:
if x != -1:
k += L[x][1]
print(k)
```
Yes
| 94,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for h in range(H)]
for i in range(10):
for j in range(10):
for k in range(10):
c[j][k] = min(c[j][k], c[j][i] + c[i][k])
ans = 0
for h in range(H):
for w in range(W):
if A[h][w] >= 0:
ans += c[A[h][w]][1]
print(ans)
```
Yes
| 94,252 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
for i in range(10):
for j in range(10):
for k in range(10):
c[j][k] = min(c[j][k], c[j][i] + c[i][k])
ans = 0
for i in range(h):
a = list(map(int,input().split()))
for j in range(w):
if a[j] != -1:
ans += c[a[j]][1]
print(ans)
```
Yes
| 94,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
dp=[0]*10
for i in range(10):
dp[i]+=c[i][1]
for _ in range(11):
for j in range(10):
for k in range(10):
dp[j]=min(dp[j],dp[k]+c[j][k])
count=0
for _ in range(h):
a=list(map(int,input().split()))
for l in a:
if l!=-1:
count+=dp[l]
print(count)
```
Yes
| 94,254 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
H, W = map(int, readline().split())
c = [list(map(int, readline().split())) for i in range(10)]
A = list(map(int, read().split()))
def warshall_floyd(dist):
for i, _ in enumerate(dist):
for j, _ in enumerate(dist):
for k, _ in enumerate(dist):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
return dist
cc = warshall_floyd(c)
ans = 0
for a in A:
if a == -1:
continue
ans += cc[a][1]
print(ans)
```
No
| 94,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
magialist=[]
datalist=[]
h,w=map(int,input().split())
#for i in range(10):
#add=list(map(int,input().split()))
#magialist.append(add)
add=list(map(int,input().split()))
for i in range(10):
magialist.append(add)
for j in range(h):
add1=list(map(int,input().split()))
datalist.extend(add1)
storelist=[[[[] for i in range(10)] for i in range(10)] for i in range(10)]
#わーシャルフロイド法
for i in range(10):
for j in range(10):
a=min(magialist[i][j],magialist[i][0]+magialist[0][j])
storelist[0][i][j]=a
k=1
while k<=9:
for i in range(10):
for j in range(10):
a=min(storelist[k-1][i][j],storelist[k-1][i][k]+storelist[k-1][k][j])
storelist[k][i][j]=a
k+=1
uselist=[]
for j in range(10):
uselist.append(storelist[9][j][1])
ans=0
for nums in range(h*w):
for i in range(10):
if datalist[nums]==-1:
continue
elif datalist[nums]==i:
ans+=uselist[i]
print(ans)
```
No
| 94,256 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
if __name__=="__main__":
sum = 0
x,y = map(int,input().split())
c = [list(map(int,input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j]>c[i][k]+c[k][j]:
c[i][j] = c[i][k]+c[k][j]
for i in range(x):
a = list[map(int,input().split())]
for j in range(y):
if a[j]!=-1:
sum+=c[j][1]
print(sum)
```
No
| 94,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
* If A_{i,j}≠-1, the square contains a digit A_{i,j}.
* If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
Constraints
* 1≤H,W≤200
* 1≤c_{i,j}≤10^3 (i≠j)
* c_{i,j}=0 (i=j)
* -1≤A_{i,j}≤9
* All input values are integers.
* There is at least one digit on the wall.
Input
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
Output
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.
Examples
Input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
Output
12
Input
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Output
0
Input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
Output
47
Submitted Solution:
```
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(10)]
def wf(table):
from itertools import product
for i, j, k in product(range(len(table)), repeat=3):
table[i][j] = min(table[i][j], table[i][k] + table[k][j])
return table
table = wf(table)
ans = 0
for _ in range(h):
for i in map(int, input().split()):
if i != -1:
ans += table[i][1]
print(ans)
```
No
| 94,258 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
N,A,B = map(int,input().split())
H = [ int(input()) for i in range(N)]
def check(n):
c = 0
for i in range(N):
a = H[i] - n*B
if a > 0:
c += (a//(A-B)) + 1
if c <= n:
return True
else:
return False
l,h = 0,10**20
for _ in range(200):
m = ((l+h)*0.5)
if check(m):
h = m
else:
l = m
import math
print(math.ceil(m))
```
| 94,259 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
C = A - B
hi = 10**9 + 1
lo = -1
while hi - lo > 1:
mid = (hi + lo) // 2
rem = 0
for i in range(N):
rem += max(0, (H[i] - B * mid + C - 1) // C)
if rem <= mid:
hi = mid
else:
lo = mid
print(hi)
```
| 94,260 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
N, A, B = map(int, input().split())
h = []
for i in range(N):
h += [int(input())]
Th = 2*max(h)//B
Tl = 0
while Tl+1<Th:
t = (Th+Tl)//2
d = []
for i in range(N):
c = h[i]
d += [c-B*t]
for i in range(N):
c = d[i]
if c<=0:
continue
t -= c//(A-B) if c%(A-B)==0 else c//(A-B)+1
if t<0:
Tl = (Th+Tl)//2
break
else:
Th = (Th+Tl)//2
print(Th)
```
| 94,261 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
n,a,b=map(int,input().split())
HP=[int(input()) for i in range(n)]
ng=0
ok=10**10
for i in range(40):
check=(ok+ng)//2
c=a-b
cnt=0
d=list(map(lambda x: x-check*b,HP))
for j in d:
cnt+=max(0,(j+c-1)//c)
if check < cnt:
ng=check
else:
ok=check
print(ok)
```
| 94,262 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
n, a, b = map(int, input().split())
h = [int(input()) for i in range(n)]
ng = 0
ok = 10 ** 9
while ok - ng > 1:
mid = (ok + ng) // 2
s = 0
for i in h:
s += max(0, (i - mid * b + a - b - 1) // (a - b))
if s <= mid:
ok = mid
else:
ng = mid
print(ok)
```
| 94,263 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
n, a, b = map(int,input().split())
ad = a - b
H = [int(input()) for i in range(n)]
le = 0
ri = max(H) // b + 2
mid = (le + ri) // 2
while ri - le > 1:
ad_n = 0
for i in range(n):
hh = max(0, H[i] - mid * b)
#print(H[i])
ad_n += -(-hh // ad)
#print(ad_n, mid)
if ad_n > mid: # 倒せない
le = mid
else:
ri = mid
mid = (le + ri) // 2
print(le+1)
```
| 94,264 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
n,a,b=map(int,input().split())
H=[0]*n
for i in range(n):
H[i]=int(input())
ng=-1
ok=10**9+5
while ok-ng>1:
mid=(ng+ok)//2
c=0
for i in range(n):
c=c+(max(0,H[i]-b*mid+a-b-1)//(a-b))
if c>mid:
ng=mid
else:
ok=mid
print(ok)
```
| 94,265 |
Provide a correct Python 3 solution for this coding contest problem.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
"Correct Solution:
```
from math import ceil
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
c=0
l1=[i-b*x for i in l]
for i in l1:
if i<=0:
continue
c+=ceil((i)/(a-b))
return c<=x
lo=0
ans=-1
hi=10**9+4
while lo<=hi:
mi=(lo+hi)>>1
if check(mi):
ans=mi
hi=mi-1
else:
lo=mi+1
print(ans)
```
| 94,266 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
from math import ceil
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
def f(x):
cnt = 0
for e in h:
cnt += max(0, ceil((e - b * x) / (a - b)))
if cnt > x:
return False
return True
l = 0
r = 10 ** 9 + 1
while r - l > 1:
mid = (l + r) // 2
if f(mid):
r = mid
else:
l = mid
print(r)
```
Yes
| 94,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
import math
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]
d = A-B
high = 10**9
low = 0
while high-low>1:
mid = (high+low)//2
D = []
for i in range(N):
if H[i]-mid*B>0:
D.append(H[i]-mid*B)
cnt = 0
for h in D:
cnt += math.ceil(h/d)
if cnt<=mid:
high = mid
else:
low = mid
print(high)
```
Yes
| 94,268 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
n,a,b=map(int,input().split())
l=[int(input())for i in range(n)]
a-=b
def enough(x):
return sum(max((h-b*x+a-1)//a,0) for h in l)<=x
#(ng,ok]type
ok,ng=10**9,-1
# [ok,ng)type->eraseng,ok=ok,ng
eps=10**(-10)
while abs(ok-ng)>1:
mid=(ok+ng)//2
if enough(mid):ok=mid
else:ng=mid
print(ok)
```
Yes
| 94,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
N, A, B = map(int,input().split())
H = [int(input()) for _ in range(N)]
def solve(k):
cnt = 0
for i in range(N):
if H[i] > B * k:
cnt += (H[i] - B * k - 1) // (A - B) + 1
return cnt <= k
left = 0
right = 10 ** 9 + 1
while left + 1 < right:
mid = (left + right) // 2
if solve(mid):
right = mid
else:
left = mid
print(right)
```
Yes
| 94,270 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
def calc(n):
damage = (b * n)
d = [max(dd - damage, 0) for dd in h]
a_num = 0
for i in range(len(d)):
a_num += max(0, 1 + (d[i]-1) // (a - b))
if a_num <= n:
return True
return False
n, a, b = map(int, input().split())
h = []
for _ in range(n):
h.append(int(input()))
ans = 0
h.sort()
left = 0
right = (h[-1] + 1) // (b)
while (right - left) > 1:
middle = (left + right) // 2
if calc(middle):
right = middle
else:
left = middle
if calc(middle):
print(middle)
else:
print(middle + 1)
```
No
| 94,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
N, A, B = map(int,input().split())
h = [0 for i in range(N)]
for i in range(N):
h[i] = int(input())
h = sorted(h)
import math
# N, A, B = 4, 5, 3
# h = [8,7,4,2]
# h = sorted(h,reverse=True)
def enough(T):
tmp = 0
for i in range(N):
if h[i] >= B*T:
tmp += math.ceil((h[i]-B*T)/(A-B))
return True if tmp <= T else False
MAX = 10**9
MIN = 0
while MAX > MIN:
if enough(MAX) == True and enough(MIN) == False and MAX - MIN == 1:
break
MID = (MAX+MIN)//2
if enough(MID) == True:
if enough(MID-1) == True:
MAX = MID-1
else:
MAX = MID
else:
if enough(MID+1) == False:
MIN = MID+1
else:
MIN = MID
print(MAX)
```
No
| 94,272 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
def read():
N, A, B = ILI()
h = [II() for __ in range(N)]
return (N, A, B, h)
def bool_exc(h, dif_ab, B, count):
dif_count = 0
for mon in h:
dif_mon = mon - B * count
if dif_mon <= 0:
continue
else:
dif_count += math.ceil(dif_mon / dif_ab)
if dif_count > count:
break
dif = count - dif_count
return dif
def solve(N, A, B, h):
right = max(h) // B + 1
left = min(h) // A + 1
dif_ab = A - B
while left != right:
mid = (left + right) // 2
dif = bool_exc(h, dif_ab, B, mid)
if dif > 0:
right = mid - 1
elif dif == 0:
right = mid
elif dif < 0:
left = mid + 1
ans = left
return ans
def main():
params = read()
print(solve(*params))
if __name__ == "__main__":
main()
```
No
| 94,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
* All input values are integers.
* 1 ≤ N ≤ 10^5
* 1 ≤ B < A ≤ 10^9
* 1 ≤ h_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Examples
Input
4 5 3
8
7
4
2
Output
2
Input
2 10 4
20
20
Output
4
Input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
Output
800000000
Submitted Solution:
```
import numpy as np
N, A, B = list(map(int,input().split()))
H = []
for i in range(N):
H.append(int(input()))
H = np.sort(H)[::-1]
attack = np.ones(N).astype(np.int64)
attack *= B
attack[0] = A
count = 0
p = int(H[0]/A)
order = 0
while p>=10:
p /= 10
order+=1
while H[0]>0:
if int(H[0]/A)>0:
H -= attack*10**(order)
H = np.sort(H)[::-1]
count += 10**(order)
else:
H -= attack
H = np.sort(H)[::-1]
count += 1
print (count)
```
No
| 94,274 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = float(10 ** 5)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
class UnionFind:
def __init__(self, n):
# 負 : 根であることを示す。絶対値はランクを示す
# 非負: 根でないことを示す。値は親を示す
self.table = [-1] * n
self.size = [1] * n
# self.group_num = n
def root(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self.root(self.table[x])
return self.table[x]
def get_size(self, x):
r = self.root(x)
return self.size[r]
def is_same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
r1 = self.root(x)
r2 = self.root(y)
if r1 == r2:
return
# ランクの取得
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.size[r1] += self.size[r2]
if d1 == d2:
self.table[r1] -= 1
else:
self.table[r1] = r2
self.size[r2] += self.size[r1]
n, k, l = LI()
u1 = UnionFind(n)
u2 = UnionFind(n)
for _ in range(k):
p, q = LI()
u1.union(p - 1, q - 1)
for _ in range(l):
r, s = LI()
u2.union(r - 1, s - 1)
D = defaultdict(int)
for i in range(n):
D[(u1.root(i), u2.root(i))] += 1
for j in range(n):
print(D[(u1.root(j), u2.root(j))], end=" ")
```
| 94,275 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
# -*- coding: utf-8 -*-
class UnionFind(object):
'''Represents a data structure that tracks a set of elements partitioned
into a number of disjoint (non-overlapping) subsets.
Landau notation: O(α(n)), where α(n) is the inverse Ackermann function.
See:
https://www.youtube.com/watch?v=zV3Ul2pA2Fw
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
https://atcoder.jp/contests/abc120/submissions/4444942
'''
def __init__(self, number_count: int):
'''
Args:
number_count: The size of elements (greater than 2).
'''
self.parent_numbers = [-1 for _ in range(number_count)]
def find_root(self, number: int) -> int:
'''Follows the chain of parent pointers from number up the tree until
it reaches a root element, whose parent is itself.
Args:
number: The trees id (0-index).
Returns:
The index of a root element.
'''
if self.parent_numbers[number] < 0:
return number
self.parent_numbers[number] = self.find_root(self.parent_numbers[number])
return self.parent_numbers[number]
def get_group_size(self, number: int) -> int:
'''
Args:
number: The trees id (0-index).
Returns:
The size of group.
'''
return -self.parent_numbers[self.find_root(number)]
def is_same_group(self, number_x: int, number_y: int) -> bool:
'''Represents the roots of tree number_x and number_y are in the same
group.
Args:
number_x: The trees x (0-index).
number_y: The trees y (0-index).
'''
return self.find_root(number_x) == self.find_root(number_y)
def merge_if_needs(self, number_x: int, number_y: int) -> bool:
'''Uses find_root to determine the roots of the tree number_x and
number_y belong to. If the roots are distinct, the trees are combined
by attaching the roots of one to the root of the other.
Args:
number_x: The trees x (0-index).
number_y: The trees y (0-index).
'''
x = self.find_root(number_x)
y = self.find_root(number_y)
if x == y:
return False
if self.get_group_size(x) >= self.get_group_size(y):
self.parent_numbers[x] += self.parent_numbers[y]
self.parent_numbers[y] = x
else:
self.parent_numbers[y] += self.parent_numbers[x]
self.parent_numbers[x] = y
return True
def main():
from collections import Counter
n, k, l = map(int, input().split())
road = UnionFind(n)
rail = UnionFind(n)
for _ in range(k):
pi, qi = map(lambda x: int(x) - 1, input().split())
if road.is_same_group(pi, qi):
continue
road.merge_if_needs(pi, qi)
for _ in range(l):
ri, si = map(lambda x: int(x) - 1, input().split())
if rail.is_same_group(ri, si):
continue
rail.merge_if_needs(ri, si)
# See:
# https://atcoder.jp/contests/arc065/submissions/3559412
# http://tutuz.hateblo.jp/entry/2018/07/25/225115
# http://baitop.hatenadiary.jp/entry/2018/06/26/224712
pairs = Counter()
ans = [0 for _ in range(n)]
for i in range(n):
hwy = road.find_root(i)
rwy = rail.find_root(i)
pairs[(hwy, rwy)] += 1
for i in range(n):
hwy = road.find_root(i)
rwy = rail.find_root(i)
ans[i] = pairs[(hwy, rwy)]
print(' '.join(map(str, ans)))
if __name__ == '__main__':
main()
```
| 94,276 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
# AtCoder Regular Contest 065
# D - 連結 / Connectivity
# https://atcoder.jp/contests/arc065/tasks/arc065_b
import sys
from collections import defaultdict
class UnionFind:
def __init__(self, n):
# self.parent = [i for i in range(n)]
self.parent = list(range(n))
def find(self, x):
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
self.parent[x] = y
def main():
N, *KL = map(int, input().split())
uf = [UnionFind(N) for _ in range(2)]
for i in range(2):
for j in range(KL[i]):
p, q = map(int, input().split())
uf[i].union(p-1, q-1)
d = defaultdict(int)
for i in range(N):
d[(uf[0].find(i), uf[1].find(i))] += 1
# for i in range(N):
# print(d[(uf[0].find(i), uf[1].find(i))], end = " ")
# print("")
print(" ".join([str(d[(uf[0].find(i), uf[1].find(i))]) for i in range(N)]))
if __name__ == "__main__":
sys.setrecursionlimit(10**6)
main()
```
| 94,277 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
from collections import defaultdict
class UnionFind():
def __init__(self,n):
self.n=n
self.parents=[-1]*n
def find(self,x):
if self.parents[x] < 0:
return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def unite(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)
for _ in range(k):
u,v=map(int,input().split())
uf1.unite(u-1,v-1)
for _ in range(l):
u,v=map(int,input().split())
uf2.unite(u-1,v-1)
d=defaultdict(int)
for i in range(n):
d[(uf1.find(i),uf2.find(i))]+=1
ans=[d[(uf1.find(i),uf2.find(i))] for i in range(n)]
print(*ans)
```
| 94,278 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
#!/usr/bin/env python3
def main():
n, k, l = map(int, input().split())
pq = get_edges(k)
rs = get_edges(l)
road_groups = get_group(n, pq)
rail_groups = get_group(n, rs)
count = {}
for i in range(n):
gp = (find(i, road_groups), find(i, rail_groups))
if gp not in count:
count[gp] = 1
else:
count[gp] += 1
res = []
for i in range(n):
gp = (find(i, road_groups), find(i, rail_groups))
res.append(count[gp])
print(" ".join(map(str, res)))
def get_edges(k):
pq = []
for i in range(k):
p1, q1 = map(int, input().split())
pq.append((p1 - 1, q1 - 1))
return pq
def get_group(n, edges):
group = [i for i in range(n)]
for x, y in edges:
unite(x, y, group)
return group
def unite(x, y, parents):
px = find(x, parents)
py = find(y, parents)
parents[py] = px
def find(x, parents):
if parents[x] == x:
return x
fx = find(parents[x], parents)
parents[x] = fx
return fx
main()
```
| 94,279 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
# AtCoder Regular Contest 065
# D - 連結 / Connectivity
# https://atcoder.jp/contests/arc065/tasks/arc065_b
import sys
from collections import defaultdict
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
def find(self, x):
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
self.parent[x] = y
def main():
N, *KL = map(int, input().split())
uf = [UnionFind(N) for _ in range(2)]
for i in range(2):
for j in range(KL[i]):
p, q = map(int, input().split())
uf[i].union(p-1, q-1)
d = defaultdict(int)
for i in range(N):
d[(uf[0].find(i), uf[1].find(i))] += 1
for i in range(N):
print(d[(uf[0].find(i), uf[1].find(i))], end = " ")
print("")
if __name__ == "__main__":
sys.setrecursionlimit(10**6)
main()
```
| 94,280 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
def f(m, r):
connmap = [[] for _ in range(m + 1)]
for _ in range(r):
a, b = map(int, input().split())
connmap[a].append(b)
connmap[b].append(a)
group = [0] * (m + 1)
num = 0
for i in range(1, m + 1):
if group[i] > 0:
continue
num += 1
group[i] = num
for j in connmap[i]:
group[j] = num
bfs = connmap[i]
while len(bfs) > 0:
tmp = []
for j in bfs:
for k in connmap[j]:
if group[k] > 0:
continue
group[k] = num
tmp.append(k)
bfs = tmp
return group
n, k, l = map(int, input().split())
road = f(n, k)
rail = f(n, l)
count = {}
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
if key in count:
count[key] += 1
else:
count[key] = 1
for i in range(1, n + 1):
key = '{0} {1}'.format(road[i], rail[i])
print(count[key], end=' ' if i < n else '')
print()
```
| 94,281 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
"Correct Solution:
```
# AtCoder Regular Contest 065
# D - 連結 / Connectivity
# https://atcoder.jp/contests/arc065/tasks/arc065_b
import sys
from collections import defaultdict
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
def find(self, x):
if self.parent[x] == x:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
self.parent[x] = y
def main():
N, *KL = map(int, input().split())
uf = [UnionFind(N) for _ in range(2)]
for i in range(2):
for j in range(KL[i]):
p, q = map(int, input().split())
uf[i].union(p-1, q-1)
d = defaultdict(int)
for i in range(N):
d[(uf[0].find(i), uf[1].find(i))] += 1
# for i in range(N):
# print(d[(uf[0].find(i), uf[1].find(i))], end = " ")
# print("")
print(" ".join([str(d[(uf[0].find(i), uf[1].find(i))]) for i in range(N)]))
if __name__ == "__main__":
sys.setrecursionlimit(10**6)
main()
```
| 94,282 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
import sys
from collections import Counter
class UnionFind:
def __init__(self, n):
self.p = list(range(n))
self.rank = [0] * n
def find_root(self, x):
if x != self.p[x]:
self.p[x] = self.find_root(self.p[x])
return self.p[x]
def is_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
u = self.find_root(x)
v = self.find_root(y)
if u == v:
return
if self.rank[u] < self.rank[v]:
self.p[u] = v
else:
self.p[v] = u
if self.rank[u] == self.rank[v]:
self.rank[u] += 1
N, K, L = map(int, sys.stdin.readline().split())
uf1 = UnionFind(N)
uf2 = UnionFind(N)
for i in range(K):
p, q = map(int, sys.stdin.readline().split())
p, q = p - 1, q - 1
uf1.unite(p, q)
for i in range(L):
r, s = map(int, sys.stdin.readline().split())
r, s = r - 1, s - 1
uf2.unite(r, s)
cntr = Counter()
for i in range(N):
u = uf1.find_root(i)
v = uf2.find_root(i)
cntr[(u, v)] += 1
ans = []
for i in range(N):
u = uf1.find_root(i)
v = uf2.find_root(i)
ans.append(cntr[(u, v)])
print(*ans)
```
Yes
| 94,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
from collections import Counter
def root(par, x):
if par[x] == x:
return x
par[x] = root(par, par[x])
return par[x]
def unite(par, x, y):
rx, ry = root(par, x), root(par, y)
if rx == ry:
return
if rank[rx] > rank[ry]:
par[ry] = rx
elif rank[rx] < rank[ry]:
par[rx] = ry
else:
par[ry] = rx
rank[rx] += 1
N, K, L = map(int, input().split())
rank = [1] * N
roads = [i for i in range(N)]
for _ in range(K):
unite(roads, *map(lambda x: int(x) - 1, input().split()))
rank = [1] * N
rails = [i for i in range(N)]
for _ in range(L):
unite(rails, *map(lambda x: int(x) - 1, input().split()))
count = Counter((root(roads, i), root(rails, i)) for i in range(N))
print(*(count[root(roads, i), root(rails, i)] for i in range(N)))
```
Yes
| 94,284 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
from collections import deque
N, K, L = map(int, input().split())
G = [[[] for j in range(N)] for i in range(2)]
check = [[0 for l in range(N)] for k in range(2)]
def bfs(s, cnt, mode):
q = deque()
q.append(s)
check[mode][s] = cnt
while len(q) != 0:
u = q.popleft()
for i in G[mode][u]:
if check[mode][i] == 0:
q.append(i)
check[mode][i] = cnt
def main():
for i in range(K):
p, q = map(int, input().split())
G[0][p-1].append(q-1)
G[0][q-1].append(p-1)
for i in range(L):
r, s = map(int, input().split())
G[1][r-1].append(s-1)
G[1][s-1].append(r-1)
cnt = 1
for i in range(N):
if check[0][i] == 0:
bfs(i, cnt, 0)
cnt += 1
cnt = 1
for i in range(N):
if check[1][i] == 0:
bfs(i, cnt, 1)
cnt += 1
groups = {}
for i in range(N):
a, b = check[0][i], check[1][i]
groups[(a, b)] = groups.get((a, b), 0) + 1
nums = []
for i in range(N):
a, b = check[0][i], check[1][i]
nums.append(str(groups[(a, b)]))
print(" ".join(nums))
if __name__ == '__main__':
main()
```
Yes
| 94,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
from collections import Counter
N,K,L = map(int,input().split())
P = [tuple(map(int,input().split())) for i in range(K)]
R = [tuple(map(int,input().split())) for i in range(L)]
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self.rank = [0] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self.rank[ra] < self.rank[rb]:
self.parent[ra] = rb
else:
self.parent[rb] = ra
if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
self.count += 1
uf1 = UnionFind(N)
for p,q in P:
p,q = p-1,q-1
if uf1.is_same(p,q): continue
uf1.unite(p,q)
uf2 = UnionFind(N)
for r,s in R:
r,s = r-1,s-1
if uf2.is_same(r,s): continue
uf2.unite(r,s)
pairs = Counter()
for i in range(N):
a = uf1.root(i)
b = uf2.root(i)
pairs[(a,b)] += 1
ans = []
for i in range(N):
a = uf1.root(i)
b = uf2.root(i)
ans.append(pairs[(a,b)])
print(*ans)
```
Yes
| 94,286 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
class UnionFind:
def __init__(self, node:int) -> None:
self.n = node
self.par = [i for i in range(self.n)]
self.rank = [0 for i in range(self.n)]
def find(self, x:int) -> int:
if x == self.par[x]:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x:int, y:int) -> bool:
if self.isSame(x,y):
#print("x and y has already united")
return False
rx = self.find(x)
ry = self.find(y)
if self.rank[rx] < self.rank[ry]:
self.par[rx] = self.par[ry]
else:
self.par[ry] = self.par[rx]
if self.rank[rx] == self.rank[ry]:
self.rank[rx] += 1
return True
def isSame(self, x:int, y:int) -> bool:
return self.find(x) == self.find(y)
n,k,l = li()
pq = []
rs = []
for _ in range(k):
pq.append(tuple(li_()))
for _ in range(l):
rs.append(tuple(li_()))
road = UnionFind(n)
rail = UnionFind(n)
for p,q in pq:
road.unite(p,q)
for r,s in rs:
rail.unite(r,s)
for i in range(n):
road.find(i)
for i in range(n):
rail.find(i)
road_dic = {i:set() for i in range(n)}
rail_dic = {i:set() for i in range(n)}
for i in range(n):
road_dic[road.par[i]].add(i)
rail_dic[rail.par[i]].add(i)
ans = []
for i in range(n):
ans.append(len(road_dic[road.par[i]] & rail_dic[rail.par[i]]))
print(*ans)
```
No
| 94,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)
from collections import Counter
from collections import defaultdict
n,k,l=map(int,input().split())
p=[0]*(k+1)
q=[0]*(k+1)
rd=[[] for _ in range(n+1)]
r=[0]*(l+1)
s=[0]*(l+1)
rw=[[] for _ in range(n+1)]
for i in range(k):
a,b=map(int,input().split())
p[i],q[i]=a,b
rd[a].append(b)
rd[b].append(a)
for i in range(l):
a,b=map(int,input().split())
r[i],s[i]=a,b
rw[a].append(b)
rw[b].append(a)
prd=[i for i in range(n+1)]
def union(x,y):
rx=root(x)
ry=root(y)
if rx==ry:
return
p[rx]=ry
def root(x):
if p[x]==x:
return x
p[x]=root(p[x])
return p[x]
#print(rd)
#print(rw)
p=prd
for i in range(1,n+1):
for j in rd[i]:
union(i,j)
for i in range(1,n+1):
rt=root(i)
prd[i]=rt
# cnt[i].append(rt)
p=[i for i in range(n+1)]
for i in range(1,n+1):
for j in rw[i]:
union(i,j)
for i in range(1,n+1):
rt=root(i)
p[i]=rt
# cnt[i].append(rt)
#print(cnt)
#c=Counter(cnt)
dc=defaultdict(int)
for i in range(1,n+1):
dc[prd[i],p[i]] += 1
#for i in range(n+1):
print(*[dc[prd[i],p[i]] for i in range(1,n+1)])
```
No
| 94,288 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
#!/usr/bin/env pypy3
class UnionFind(object):
def __init__(self, number_of_nodes):
self.par = list(range(number_of_nodes))
self.rank = [0] * number_of_nodes
def root(self, node):
if self.par[node] == node:
return node
else:
r = self.root(self.par[node])
self.par[node] = r
return r
def in_the_same_set(self, node1, node2):
return self.root(node1) == self.root(node2)
def unite(self, node1, node2):
x = self.root(node1)
y = self.root(node2)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
n, k, l = (int(x) for x in input().split())
uf_roads = UnionFind(n)
for _ in range(k):
p, q = (int(x) - 1 for x in input().split())
uf_roads.unite(p, q)
uf_rails = UnionFind(n)
for _ in range(l):
r, s = (int(x) - 1 for x in input().split())
uf_rails.unite(r, s)
ans = [sum(1 for y in range(n) if
uf_roads.in_the_same_set(x, y) and
uf_rails.in_the_same_set(x, y)) for x in range(n)]
print(" ".join(str(z) for z in ans))
if __name__ == '__main__':
main()
```
No
| 94,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.
Constraints
* 2 ≦ N ≦ 2*10^5
* 1 ≦ K, L≦ 10^5
* 1 ≦ p_i, q_i, r_i, s_i ≦ N
* p_i < q_i
* r_i < s_i
* When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
* When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)
Input
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L
Output
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.
Examples
Input
4 3 1
1 2
2 3
3 4
2 3
Output
1 2 2 1
Input
4 2 2
1 2
2 3
1 4
2 3
Output
1 2 2 1
Input
7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
Output
1 1 2 1 2 2 2
Submitted Solution:
```
class UnionFind():
def __init__(self,n):
self.n=n
self.parents=[-1]*n
def find(self,x):
if self.parents[x] < 0:
return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def unite(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)
for _ in range(k):
u,v=map(int,input().split())
uf1.unite(u-1,v-1)
for _ in range(k):
u,v=map(int,input().split())
uf2.unite(u-1,v-1)
ans=[]
for i in range(n):
x=set(uf1.members(i))&set(uf2.members(i))
ans.append(len(x))
print(*ans)
```
No
| 94,290 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
import sys
input = sys.stdin.readline
def gcd(a, b):
while b: a, b = b, a % b
return a
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8 + 1
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r-k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
while g == 1:
ys = f(ys)
g = gcd(abs(x-ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n//g): return n//g
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i%2
if i == 101 and n >= 2**20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
return ret
N = int(input())
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(input()))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D: D[a] = 0
if a == b:
if D[a] == 0: ans += 1
else:
if b not in D: D[b] = 0
if D[b] <= D[a]: ans += 1
D[a] += 1
print(ans)
```
| 94,291 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
import sys
from collections import Counter
def make_prime_checker(n):
# nまでの自然数が素数かどうかを表すリストを返す O(nloglogn)
is_prime = [False, True, False, False, False, True] * (n//6+1)
del is_prime[n+1:]
is_prime[1:4] = False, True, True
for i in range(5, int(n**0.5)+1):
if is_prime[i]:
is_prime[i*i::i] = [False] * (n//i-i+1)
return is_prime
def main():
Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]
def decomp(n):
res1 = res2 = 1
for p in Primes:
cnt = 0
while n % p == 0:
n //= p
cnt += 1
cnt %= 3
if cnt == 1:
res1 *= p
elif cnt == 2:
res2 *= p
if int(n**0.5)**2 == n:
res2 *= int(n**0.5)
else:
res1 *= n
return res1 * res2 * res2, res1 * res1 * res2
N, *S = map(int, sys.stdin.buffer.read().split())
T = []
inv_dict = {}
for s in S:
t, t_inv = decomp(s)
T.append(t)
inv_dict[t] = t_inv
counter_T = Counter(T)
ans = 0
for t, t_cnt in counter_T.items():
if t == 1:
ans += 1
continue
t_inv = inv_dict[t]
t_inv_cnt = counter_T[t_inv]
if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
ans += t_cnt
print(ans)
main()
```
| 94,292 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
"""
Rを立法数とする
a * R と a**2 * R a**1 * R → a**2*R a**1*R a**2*R
3つはなれてるとあかん!! でも取り除かれてるはずだよな…
→Rを取り除いて後はDP
どうやって立法数を取り除く?
10**3.3まで試し割り?→5secだから間に合うかなぁ
Rを取り除く→10**3.333333以下の素数の3乗で割れるか確かめる
対になるsの導出:
素因数分解→10**5まで試し割(割れて10**5以下になったらdivlis方式に変える)
→巨大素数ばっかりだと死ぬ
2乗して新たに生まれたRを取り除けばok!!!!
→範囲は?10**6.6666以下か?(やばくね?)
sと対になるsでは片方しか取れない(dicで管理するかぁ)
sと対sの中で小さい方に合わせてdicで管理かなぁ
"""
def Sieve(n): #n以下の素数全列挙(O(nloglogn)) retは素数が入ってる。divlisはその数字の素因数が一つ入ってる
ret = []
divlis = [-1] * (n+1) #何で割ったかのリスト(初期値は-1)
flag = [True] * (n+1)
flag[0] = False
flag[1] = False
ind = 2
while ind <= n:
if flag[ind]:
ret.append(ind)
ind2 = ind ** 2
while ind2 <= n:
flag[ind2] = False
divlis[ind2] = ind
ind2 += ind
ind += 1
return ret,divlis
N = int(input())
dic = {}
ret,divlis = Sieve(10**5)
ret2 = []
for i in ret:
ret2.append(i**2)
div3 = 0
for loop in range(N):
s = int(input())
ndic = {}
for i in ret:
if i**3 > 10**10:
break
while s % i == 0:
if i not in ndic:
ndic[i] = 1
else:
ndic[i] += 1
s //= i
if s in ret2:
ndic[int(s**0.5)] = 2
else:
ndic[s] = 1
S = 1
T = 1
#print (ndic)
for i in ndic:
S *= i ** (ndic[i] % 3)
T *= i ** ((-1 * ndic[i]) % 3)
#print (S,T)
if S == T:
div3 += 1
elif S < T:
if S not in dic:
dic[S] = [1,0]
else:
dic[S][0] += 1
else:
if T not in dic:
dic[T] = [0,1]
else:
dic[T][1] += 1
ans = min(1,div3)
for i in dic:
ans += max(dic[i])
print (ans)
```
| 94,293 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
def examA():
S = SI()
if "W" in S and not "E" in S:
print("No")
elif "E" in S and not "W" in S:
print("No")
elif "N" in S and not "S" in S:
print("No")
elif "S" in S and not "N" in S:
print("No")
else:
print("Yes")
return
def examB():
N = I()
A = [I()for _ in range(N)]
ans = 0
for i in range(N-1):
ans += A[i]//2
if A[i]%2 and A[i+1]>=1:
ans += 1
A[i+1] -= 1
ans += A[N-1]//2
print(ans)
return
def examC():
N = I()
A = [I()for _ in range(N)]
if N==1:
print(0)
return
odd = set()
for i in range(N):
if i&1==0:
odd.add(A[i])
A.sort()
ans = 0
for i in range((N+1)//2):
if A[i*2] in odd:
continue
ans += 1
print(ans)
return
def examD():
def factorization_(a):
rep = [[]for _ in range(2)]
pair = []
for i in range(2,int(10**(3.4))+2):
cur = 0
while a%i==0:
cur += 1
a //= i
if cur>0:
cur %= 3
if cur==0:
continue
rep[0].append((i,cur))
pair.append((i,3-cur))
if not rep[0]:
rep[0].append((0,0))
pair.append((0,0))
rep[1] = a
rep[0] = tuple(rep[0])
rep = tuple(rep)
pair = tuple(pair)
return rep, pair
def square(a):
rep = set()
for i in range(int(10**(3.3)),a+1):
rep.add(i**2)
return rep
N = I()
S = [I()for _ in range(N)]
group = defaultdict(int)
P = defaultdict(tuple)
for s in S:
g,p = factorization_(s)
group[g] += 1
P[g[0]] = p
#print(group)
#G2 = deepcopy(group)
#print(P)
sq = square(int(10**(5))+1)
ans = 0
for key,c in group.items():
rep, rest = key
if rest in sq:
pair = int(pow((rest+1),0.5))
else:
pair = rest**2
if rep==((0,0),) and pair==1:
ans += 1
else:
if (P[rep],pair) in group:
if c < group[(P[rep], pair)]:
ans += group[(P[rep], pair)]
else:
ans += c
group[(P[rep], pair)] = 0
else:
ans += c
group[key] = 0
#print(ans)
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == '__main__':
examD()
"""
"""
```
| 94,294 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
def make_prime_numbers(n):
"""n以下の素数を列挙したリストを出力する
計算量: O(NloglogN)
入出力例: 30 -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
"""
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n ** 0.5) + 1):
if not is_prime[i]:
continue
for j in range(2 * i, n + 1, i):
is_prime[j] = False
prime_numbers = [i for i in range(n + 1) if is_prime[i]]
return prime_numbers
n = int(input())
s = [int(input()) for i in range(n)]
primes = make_prime_numbers(int((10 ** 10) ** (1 / 3) + 20))
pow2 = set([i ** 2 for i in range(10 ** 5 + 10)])
to_anti = {}
# s[i] が立方数で割り切れるときは割る
for i in range(n):
anti = 1
tmp_s = s[i]
for div in primes:
cnt = 0
while tmp_s % div == 0:
tmp_s //= div
cnt += 1
mod_cnt = cnt % 3
cnt = cnt - mod_cnt
s[i] //= (div ** cnt)
anti *= div ** ((3 - mod_cnt) % 3)
if tmp_s in pow2:
to_anti[s[i]] = anti * int(tmp_s ** 0.5)
else:
to_anti[s[i]] = anti * (tmp_s ** 2)
# key: s[i], val: 個数
cnts = {}
for key in s:
if key not in cnts:
cnts[key] = 0
cnts[key] += 1
# 例えば、key = (2 ** 2) * (5 ** 1) と key = (2 ** 1) * (5 ** 2) は
# 片方しか選べないので、 cnts[key]が大きい方を選ぶと得する
ans = 0
used = set([])
for key in cnts:
if key == 1:
ans += 1
continue
if key in used:
continue
anti_key = to_anti[key]
used.add(anti_key)
if anti_key in cnts:
ans += max(cnts[anti_key], cnts[key])
else:
ans += cnts[key]
print(ans)
```
| 94,295 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
def get_sieve_of_eratosthenes_new(n):
import math
if not isinstance(n, int):
raise TypeError('n is int type.')
if n < 2:
raise ValueError('n is more than 2')
prime = []
limit = math.sqrt(n)
data = [i + 1 for i in range(1, n)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
prime=get_sieve_of_eratosthenes_new(2160)
def ind(b,n):
res=0
while n%b==0:
res+=1
n//=b
return res
import sys
input=sys.stdin.readline
N=int(input())
dic={}
inverse={}
for i in range(N):
s=int(input())
news=1
invs=1
for p in prime:
a=ind(p,s)
s//=p**a
news*=p**(a%3)
invs*=p**((-a)%3)
if s==1 or int(s**0.5)**2!=s:
news*=s
invs*=s**2
if news not in dic:
dic[news]=0
inverse[news]=0
dic[news]+=1
inverse[news]=invs
else:
news*=s
invs*=int(s**0.5)
if news not in dic:
dic[news]=0
inverse[news]=0
dic[news]+=1
inverse[news]=invs
one=0
double=0
for i in dic:
if i!=1:
if inverse[i] in dic:
double+=max(dic[i],dic[inverse[i]])
else:
one+=dic[i]
double//=2
ans=one+double
if 1 in dic:
ans+=1
print(ans)
```
| 94,296 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
import sys
input = sys.stdin.readline
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i%2
if i == 101 and n >= 2**20:
def findFactorRho(N):
def gcd(a, b):
while b: a, b = b, a % b
return a
def f(x, c):
return (x * x + c) % N
for c in range(1, 99):
X, d, j = [2], 1, 0
while d == 1:
j += 1
X.append(f(X[-1], c))
X.append(f(X[-1], c))
d = gcd(abs(X[2*j]-X[j]), N)
if d != N:
if isPrimeMR(d):
return d
elif isPrimeMR(N//d): return N//d
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
return ret
def isPrimeMR(n):
if n == 2:
return True
if n == 1 or n & 1 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
L = [2, 7, 61] if n < 1<<32 else [2, 13, 23, 1662803] if n < 1<<40 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
for a in L:
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and t & 1 == 0:
return False
return True
N = int(input())
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(input()))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D: D[a] = 0
if a == b:
if D[a] == 0: ans += 1
else:
if b not in D: D[b] = 0
if D[b] <= D[a]: ans += 1
D[a] += 1
print(ans)
```
| 94,297 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
"Correct Solution:
```
import sys
from collections import defaultdict
def eratosthenes_generator():
yield 2
n = 3
h = {}
while True:
m = n
if n in h:
b = h[n]
m += 2 * b
while m in h:
m += 2 * b
h[m] = b
del h[n]
else:
m += 2 * n
while m in h:
m += 2 * n
h[m] = n
yield n
n += 2
gen = eratosthenes_generator()
p = 0
primes = []
for p in gen:
if p > 2154:
break
primes.append(p)
prime_pairs = {1: 1, p: p * p, p * p: p}
for p in gen:
if p > 100000:
break
p2 = p * p
prime_pairs[p] = p2
prime_pairs[p2] = p
n, *sss = map(int, sys.stdin.buffer.read().split())
normalized = defaultdict(int)
over_pairs = {}
frac_pairs = {}
ans = 0
for s in sss:
# sを2154までの素数で全て割る → ~10^5 までの単一の素数またはその2乗以外は、10^10 までの範囲にペアは存在し得ない
frac = 1 # 2154までの素因数について、立方数とならない端数を掛け合わせたもの
pair = 1 # 2154までの素因数について、立方数となるためにペアに求められる因数
for p in primes:
if s < p:
break
x = 0
d, m = divmod(s, p)
while m == 0:
x += 1
s = d
d, m = divmod(s, p)
x %= 3
if x == 1:
frac *= p
pair *= p ** 2
elif x == 2:
frac *= p ** 2
pair *= p
if s > 2154 and s not in prime_pairs:
ans += 1
continue
frac_pairs[frac] = pair
normalized[s, frac] += 1
if (1, 1) in normalized:
ans += 1
del normalized[1, 1]
tmp = 0
for (s, frac), cnt in normalized.items():
pair = (prime_pairs[s], frac_pairs[frac])
if pair not in normalized:
tmp += cnt * 2
else:
tmp += max(cnt, normalized[pair])
ans += tmp // 2
print(ans)
```
| 94,298 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.
He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.
Find the maximum number of integers that Snuke can circle.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ s_i ≦ 10^{10}
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
s_1
:
s_N
Output
Print the maximum number of integers that Snuke can circle.
Examples
Input
8
1
2
3
4
5
6
7
8
Output
6
Input
6
2
4
8
16
32
64
Output
3
Input
10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
Output
9
Submitted Solution:
```
from collections import defaultdict
import sys
input = sys.stdin.readline
nmax = 10**5+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
while cnt <= nmax and eratos[cnt]:
cnt += 1
if cnt > nmax:
break
eratos[cnt] = 1
prime.append(cnt)
for i in range(cnt**2,nmax+1,cnt):
eratos[i] = 1
cbls = []
sqst = set()
for i in prime:
if i**3 <= 10**10:
cbls.append(i**3)
else:
sqst.add(i**2)
n = int(input())
a = [int(input()) for i in range(n)]
dc = defaultdict(int)
for i in a:
for p in cbls:
while i%p == 0:
i //= p
dc[i] += 1
ans = n
for i,v in dc.items():
if i == 1:
ans -= v-1
continue
if v == 0:
continue
x = 1
for p in prime:
if p**3 > 10**10:
break
if i%(p*p) == 0:
x *= p
i //= p*p
elif i%p == 0:
x *= p**2
i //= p
if i in sqst:
x *= int(i**0.5+0.5)
i //= i
if i != 1:
continue
if x in dc:
ans -= min(dc[x],v)
dc[x] = 0
print(ans)
```
Yes
| 94,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.