message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
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 | instruction | 0 | 94,291 | 16 | 188,582 |
"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)
``` | output | 1 | 94,291 | 16 | 188,583 |
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 | instruction | 0 | 94,292 | 16 | 188,584 |
"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()
``` | output | 1 | 94,292 | 16 | 188,585 |
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 | instruction | 0 | 94,293 | 16 | 188,586 |
"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)
``` | output | 1 | 94,293 | 16 | 188,587 |
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 | instruction | 0 | 94,294 | 16 | 188,588 |
"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()
"""
"""
``` | output | 1 | 94,294 | 16 | 188,589 |
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 | instruction | 0 | 94,295 | 16 | 188,590 |
"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)
``` | output | 1 | 94,295 | 16 | 188,591 |
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 | instruction | 0 | 94,296 | 16 | 188,592 |
"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)
``` | output | 1 | 94,296 | 16 | 188,593 |
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 | instruction | 0 | 94,297 | 16 | 188,594 |
"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)
``` | output | 1 | 94,297 | 16 | 188,595 |
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 | instruction | 0 | 94,298 | 16 | 188,596 |
"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)
``` | output | 1 | 94,298 | 16 | 188,597 |
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)
``` | instruction | 0 | 94,299 | 16 | 188,598 |
Yes | output | 1 | 94,299 | 16 | 188,599 |
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:
```
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**(10*1/3))+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))
rep[1] = a
rep[0] = tuple(rep[0])
rep = tuple(rep)
pair = tuple(pair)
return rep, pair
def square(a):
rep = defaultdict(int)
for i in range(1,a+1):
rep[i**2] = i
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**(0.5))+1)
used = set()
ans = 0
for key,c in group.items():
rep, rest = key
if (rep,rest) in used:
continue
if sq[rest]>0:
pair = sq[rest]
else:
pair = rest**2
if rep==((0,0),) and rest==1:
ans += 1
else:
ans += max(c,G2[(P[rep],pair)])
used.add((rep,rest))
used.add((P[rep], pair))
#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()
"""
"""
``` | instruction | 0 | 94,300 | 16 | 188,600 |
No | output | 1 | 94,300 | 16 | 188,601 |
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)
if x == 1:
x = i**2
if x in dc:
ans -= min(dc[x],v)
dc[x] = 0
print(ans)
``` | instruction | 0 | 94,301 | 16 | 188,602 |
No | output | 1 | 94,301 | 16 | 188,603 |
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:
```
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**(10*1/3))+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))
rep[1] = a
rep[0] = tuple(rep[0])
rep = tuple(rep)
pair = tuple(pair)
return rep, pair
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)
ans = 0
for key,c in group.items():
rep, rest = key
pair = rest**2
if rep==((0,0),) and rest==1:
ans += 1
else:
ans += max(c,G2[(P[rep],pair)])
G2[(rep,rest)] = 0
if G2[(P[rep], pair)]:
group[(P[rep], pair)] = 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()
"""
"""
``` | instruction | 0 | 94,302 | 16 | 188,604 |
No | output | 1 | 94,302 | 16 | 188,605 |
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
def prime_sieve(end):
assert end > 1
is_prime = [True for i in range(end)]
is_prime[0], is_prime[1] = False, False
primes = list()
for i in range(2,end):
if is_prime[i]:
primes.append(i)
for j in range(2 * i, end, i):
is_prime[j] = False
return primes
def prime_factorize(n,primes):
res = []
for i in primes:
tmp = 0
while not (n%i):
n //= i
tmp += 1
res.append(tmp%3)
res.append(n)
return tuple(res)
n = int(input())
s = [int(input()) for i in range(n)]
primes = prime_sieve(int(max(s) ** (0.25))+2)
len_primes = len(primes)
factorized = defaultdict(int)
square = dict()
for i in range(1,100001):
square[i**2] = i
cubic = set([i**3 for i in range(1,4000)])
for i in s:
t = prime_factorize(i,primes)
factorized[t] += 1
ans = n
f = factorized.items()
for k,v in f:
rem = k[-1]
another = [(3-i) % 3 for i in k[:-1]]
if rem in cubic:
another.append(1)
elif rem in square:
another.append(square[rem])
else:
another.append(rem**2)
another = tuple(another)
if k == another:
ans -= factorized[k] - 1
continue
if another in factorized:
if factorized[k] <= factorized[another]:
ans -= factorized[k]
factorized[k] = 0
else:
ans -= factorized[another]
factorized[another] = 0
print(ans)
``` | instruction | 0 | 94,303 | 16 | 188,606 |
No | output | 1 | 94,303 | 16 | 188,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
INF=float('inf')
from collections import deque
def mbfs(G,sh,sw,H,W):
dist=[[INF]*W for i in range(H)]
dist[sh][sw]=0
d=deque()
d.append([sh,sw])
dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(d)!=0):
h=d[0][0]
w=d[0][1]
d.popleft()
for dir in range(4):
for k in range(1,K+1):
nh=h+dx[dir]*k
nw=w+dy[dir]*k
if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
break
if(G[nh][nw]=='@'):
break
if(dist[nh][nw]<=dist[h][w]):
break
if dist[nh][nw]==dist[h][w]+1:
continue
else:
dist[nh][nw]=dist[h][w]+1
d.append([nh,nw])
return dist
H,W,K=map(int,input().split())
sx,sy,gx,gy=map(lambda x:int(x)-1,input().split())
c=[list(input()) for i in range(H)]
dist=mbfs(c,sx,sy,H,W)
ans=dist[gx][gy]
print(ans if ans!=INF else -1)
``` | instruction | 0 | 95,039 | 16 | 190,078 |
Yes | output | 1 | 95,039 | 16 | 190,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
import sys
input = sys.stdin.readline
import queue
class gridMan:
def __init__(s, L):
s.L = L
s.H = len(s.L)
s.W = len(s.L[0])
def makeWall(s, x = -2):
w = len(s.L[0]) + 2
s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
def dist(s, S): #Sから上下左右に進んで何手かかるかのリスト および 最大値
T = [[-1] * s.W for _ in range(s.H)]
q = queue.Queue()
q.put([S[0], S[1]])
T[S[0]][S[1]] = 0
k = 0
while not q.empty():
h, w = q.get()
p = T[h][w]
for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
for k in range(1, K + 1):
hh = h + i * k
ww = w + j * k
if s.L[hh + 1][ww + 1] >= 0:
if T[hh][ww] == -1 or T[hh][ww] > p + 1:
q.put([hh, ww])
T[hh][ww] = p + 1
elif T[hh][ww] != p + 1:
break
else:
break
return T, k
H, W, K = list(map(int, input().split()))
xy = list(map(int, input().split()))
c = []
for i in range(H):
c.append(list(input().replace("\n", "")))
for i in range(H):
for j in range(W):
if c[i][j] == ".":
c[i][j] = 0
else:
c[i][j] = -1
g = gridMan(c)
g.makeWall()
L, k = g.dist([xy[0] - 1, xy[1] - 1])
print(L[xy[2] - 1][xy[3] - 1])
``` | instruction | 0 | 95,040 | 16 | 190,080 |
Yes | output | 1 | 95,040 | 16 | 190,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
from collections import deque
H, W, K = map(int, input().split())
sh, sw, gh, gw = map(int, input().split())
sh, sw, gh, gw = sh - 1, sw - 1, gh - 1, gw - 1
G = [list(input()) for _ in range(H)]
INF = 10 ** 9
D = [[INF] * W for _ in range(H)]
D[sh][sw] = 0
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
que = deque([(sh, sw)])
while que:
nh, nw = que.pop()
for dh, dw in directions:
for k in range(1, K + 1):
nx_h, nx_w = nh + k * dh, nw + k * dw
if not (0 <= nx_h < H and 0 <= nx_w < W):
break
if G[nx_h][nx_w] == '@':
break
if D[nx_h][nx_w] <= D[nh][nw]:
break
if D[nx_h][nx_w] > D[nh][nw] + 1:
D[nx_h][nx_w] = D[nh][nw] + 1
que.appendleft((nx_h, nx_w))
print(D[gh][gw] if D[gh][gw] != INF else -1)
``` | instruction | 0 | 95,041 | 16 | 190,082 |
Yes | output | 1 | 95,041 | 16 | 190,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
from collections import deque
import sys
def bfs(M, sy, sx, gy, gx):
queue = deque([[sy, sx]])
M[sy][sx] = 0
while queue:
# queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
y, x = queue.popleft() # queueに入っていたものを消す。
if [y, x] == [gy, gx]: # もしゴールについていたならば、そのときの手数を出す。
return M[y][x]
for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]):
for k in range(1, K + 1):
new_x = x + dx * k
new_y = y + dy * k
if (0 <= new_y < H) and (0 <= new_x < W):
if m[new_y][new_x] == "@":
break
elif M[new_y][new_x] == -1: # まだ来たことない点だったという条件
M[new_y][new_x] = M[y][x] + 1
queue.append([new_y, new_x]) # 新しい点を足す。
elif M[new_y][new_x] < M[y][x] + 1:
break
else:
break
H, W, K = map(int, input().split())
# K = min(K, max(H, W))
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
m = []
for i in range(H):
m.append(list(map(str, sys.stdin.readline().strip())))
M = [[-1] * W for i in range(H)]
bfs(M, x1, y1, x2, y2)
print(M[x2][y2])
``` | instruction | 0 | 95,042 | 16 | 190,084 |
Yes | output | 1 | 95,042 | 16 | 190,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
import queue
import sys
input = sys.stdin.readline
def calc_next_point(x, y, vec, dist):
if vec == 0:
return x-dist, y
elif vec == 1:
return x, y+dist
elif vec == 2:
return x+dist, y
else:
return x, y-dist
def main():
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
pond = [[[-1]*4 for j in range(w+2)] for i in range(h+2)]
for i in range(1, h+1):
s = input()
for j in range(w):
if s[j] == ".":
for l in range(4):
pond[i][j+1][l] = float("inf")
qs = [queue.Queue(), queue.Queue()]
for i in range(4):
pond[x1][y1][i] = 0
qs[0].put([0, x1, y1, i])
p = 0
minans = float("inf")
while not qs[0].empty() or not qs[1].empty():
while not qs[p].empty():
cost, x, y, vec = qs[p].get()
np = (p+1)%2
if cost >= minans:
break
if x == x2 and y == y2:
if cost < minans:
minans = cost
for i in range(1, k+1):
nx, ny = calc_next_point(x, y, vec, i)
if pond[nx][ny][vec] == -1:
break
ncost = cost + 1
if pond[nx][ny][vec] < ncost:
break
pond[nx][ny][vec] = ncost
if nx == x2 and ny == y2:
if ncost < minans:
minans = ncost
for j in range(4):
if i == k:
if j != (vec+2)%4:
if j == vec or pond[nx][ny][j] > ncost:
pond[nx][ny][j] = ncost
qs[np].put([ncost, nx, ny, j])
elif i == 1:
if j != vec:
if j == (vec+2)%4 or pond[nx][ny][j] > ncost:
pond[nx][ny][j] = ncost
qs[np].put([ncost, nx, ny, j])
else:
if j != vec and j != (vec+2)%4:
if pond[nx][ny][j] > ncost:
pond[nx][ny][j] = ncost
qs[np].put([ncost, nx, ny, j])
p = (p+1)%2
if min(pond[x2][y2]) == float("inf"):
print(-1)
else:
print(min(pond[x2][y2]))
if __name__ == "__main__":
main()
``` | instruction | 0 | 95,043 | 16 | 190,086 |
No | output | 1 | 95,043 | 16 | 190,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
from collections import deque
import sys
def bfs(xs, ys, d):
queue = deque((xs, ys, d))
M[xs][ys] = d
while queue:
# queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
x1, y1, d = queue.popleft() # queueに入っていたものを消す。
if [x1, y1] == [xg, yg]: # もしゴールについていたならば、そのときの手数を出す。
return
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
for k in range(1, K + 1):
x2 = x1 + dx * k
y2 = y1 + dy * k
if (0 <= x2 < H) and (0 <= y2 < W):
if m[x2][y2] == "@":
break
elif M[x2][y2] == -1: # まだ来たことない点だったという条件
M[x2][y2] = d + 1
queue.append((x2, y2)) # 新しい点を足す。
elif M[x2][y2] < d + 1:
break
else:
break
H, W, K = map(int, input().split())
# K = min(K, max(H, W))
xs, ys, xg, yg = map(int, input().split())
xs, ys, xg, yg = xs - 1, ys - 1, xg - 1, yg - 1
m = []
for i in range(H):
m.append(list(map(str, sys.stdin.readline().strip())))
M = [[-1] * W for i in range(H)]
bfs(xs, ys, 0)
print(M[xg][yg])
``` | instruction | 0 | 95,044 | 16 | 190,088 |
No | output | 1 | 95,044 | 16 | 190,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1
xxx = set()
for hh in range(h):
c = input()
for ww, cc in enumerate(c):
if cc == '@':
xxx.add((hh, ww))
from heapq import heappush, heappop
q = []
heappush(q, (0, x1, y1))
d = {}
while q:
s, x, y = heappop(q)
for i in range(1, k+1):
xx, yy = x + i, y
if xx >= h or (xx, yy) in xxx:
break
if (xx, yy) in d and d[(xx, yy)] <= s+1:
continue
if xx == x2 and yy == y2:
print(s+1)
exit(0)
d[(xx, yy)] = s+1
heappush(q, (s+1, xx, yy))
for i in range(1, k+1):
xx, yy = x - i, y
if xx < 0 or (xx, yy) in xxx:
break
if (xx, yy) in d and d[(xx, yy)] <= s+1:
continue
if xx == x2 and yy == y2:
print(s+1)
exit(0)
d[(xx, yy)] = s+1
heappush(q, (s+1, xx, yy))
for i in range(1, k+1):
xx, yy = x, y + i
if yy >= w or (xx, yy) in xxx:
break
if (xx, yy) in d and d[(xx, yy)] <= s+1:
continue
if xx == x2 and yy == y2:
print(s+1)
exit(0)
d[(xx, yy)] = s+1
heappush(q, (s+1, xx, yy))
for i in range(1, k+1):
xx, yy = x, y - i
if yy < 0 or (xx, yy) in xxx:
break
if (xx, yy) in d and d[(xx, yy)] <= s+1:
continue
if xx == x2 and yy == y2:
print(s+1)
exit(0)
d[(xx, yy)] = s+1
heappush(q, (s+1, xx, yy))
print(-1)
``` | instruction | 0 | 95,045 | 16 | 190,090 |
No | output | 1 | 95,045 | 16 | 190,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with H east-west rows and W north-south columns. Let (i,j) be the square at the i-th row from the north and j-th column from the west.
Some of the squares have a lotus leaf on it and cannot be entered. The square (i,j) has a lotus leaf on it if c_{ij} is `@`, and it does not if c_{ij} is `.`.
In one stroke, Snuke can move between 1 and K squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.
Find the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2). If the travel from (x_1,y_1) to (x_2,y_2) is impossible, point out that fact.
Constraints
* 1 \leq H,W,K \leq 10^6
* H \times W \leq 10^6
* 1 \leq x_1,x_2 \leq H
* 1 \leq y_1,y_2 \leq W
* x_1 \neq x_2 or y_1 \neq y_2.
* c_{i,j} is `.` or `@`.
* c_{x_1,y_1} = `.`
* c_{x_2,y_2} = `.`
* All numbers in input are integers.
Input
Input is given from Standard Input in the following format:
H W K
x_1 y_1 x_2 y_2
c_{1,1}c_{1,2} .. c_{1,W}
c_{2,1}c_{2,2} .. c_{2,W}
:
c_{H,1}c_{H,2} .. c_{H,W}
Output
Print the minimum number of strokes Snuke takes to travel from the square (x_1,y_1) to (x_2,y_2), or print `-1` if the travel is impossible.
Examples
Input
3 5 2
3 2 3 4
.....
.@..@
..@..
Output
5
Input
1 6 4
1 1 1 6
......
Output
2
Input
3 3 1
2 1 2 3
.@.
.@.
.@.
Output
-1
Submitted Solution:
```
import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque([x1-1,y1-1])
dp[x1-1][y1-1]=0
def bfs(d):
global dp,now
l=len(now)
if l==0:
return
dp_sub=deque()
cand=set()
for i in range(l):
x,y=now.popleft()
for j in range(1,min(k+1,w-y)):
if dp[x][y+j]==inf:
dp_sub.append([x,y+j,d])
cand.add((x,y+j))
else:
break
for j in range(1,min(k+1,y+1)):
if dp[x][y-j]==inf:
dp_sub.append([x,y-j,d])
cand.add((x,y-j))
else:
break
for j in range(1,min(k+1,h-x)):
if dp[x+j][y]==inf:
dp_sub.append([x+j,y,d])
cand.add((x+j,y))
else:
break
for j in range(1,min(k+1,x+1)):
if dp[x-j][y]==inf:
dp_sub.append([x-j,y,d])
cand.add((x-j,y))
else:
break
while dp_sub!=deque([]):
e=dp_sub.popleft()
dp[e[0]][e[1]]=e[2]
for i in cand:
now.append(i)
bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
``` | instruction | 0 | 95,046 | 16 | 190,092 |
No | output | 1 | 95,046 | 16 | 190,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1).
Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions:
* For each i (0 \leq i \leq N-1), A_i should be i or P_i.
* For each i (0 \leq i \leq N-1), B_i should be i or Q_i.
Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
Constraints
* 1 \leq N \leq 100000
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* 0 \leq Q_i \leq N-1
* Q_0,Q_1,\cdots,Q_{N-1} are all different.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_0 P_1 \cdots P_{N-1}
Q_0 Q_1 \cdots Q_{N-1}
Output
Print the maximum possible distance of A and B.
Examples
Input
4
2 1 3 0
0 2 3 1
Output
3
Input
10
0 4 5 3 7 8 2 1 9 6
3 8 5 6 4 0 2 1 7 9
Output
8
Input
32
22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13
22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31
Output
28
Submitted Solution:
```
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
b = np.array(list(map(int,input().split())))
c = (a - b)
d = [s for s in c if s != 0]
print(len(d))
``` | instruction | 0 | 95,063 | 16 | 190,126 |
No | output | 1 | 95,063 | 16 | 190,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1).
Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions:
* For each i (0 \leq i \leq N-1), A_i should be i or P_i.
* For each i (0 \leq i \leq N-1), B_i should be i or Q_i.
Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
Constraints
* 1 \leq N \leq 100000
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* 0 \leq Q_i \leq N-1
* Q_0,Q_1,\cdots,Q_{N-1} are all different.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_0 P_1 \cdots P_{N-1}
Q_0 Q_1 \cdots Q_{N-1}
Output
Print the maximum possible distance of A and B.
Examples
Input
4
2 1 3 0
0 2 3 1
Output
3
Input
10
0 4 5 3 7 8 2 1 9 6
3 8 5 6 4 0 2 1 7 9
Output
8
Input
32
22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13
22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31
Output
28
Submitted Solution:
```
from collections import deque
# 枝を表すクラス
# altは逆の枝を表す
class Edge:
def __init__(self, from_v, to_v, cap):
self.from_v = from_v
self.to_v = to_v
self.cap = cap
self.alt = None
# 頂点を表すクラス
class Vertex:
def __init__(self, id):
self.id = id
self.edge_list = []
# グラフを表すクラス
class Graph:
# 初期化する
# vnumは頂点数を表す
# s_vは始点、t_vは終点を表す
def __init__(self, vnum):
self.__vertex_list = [Vertex(i) for i in range(vnum + 2)]
self.__edge_list = []
# 枝を追加する
def add_edge(self, from_id, to_id, cap):
from_v = self.vertex(from_id)
to_v = self.vertex(to_id)
normal_edge = Edge(from_v,to_v, cap)
reverse_edge = Edge(to_v, from_v, 0)
normal_edge.alt = reverse_edge
reverse_edge.alt = normal_edge
from_v.edge_list.append(normal_edge)
to_v.edge_list.append(reverse_edge)
self.__edge_list.append(normal_edge)
self.__edge_list.append(reverse_edge)
def vertex(self, id):
return self.__vertex_list[id]
# 辺の状況をprintする
def print_edge(self):
for i in range(len(self.__edge_list)):
print("[f_v={}, ".format(self.__edge_list[i].from_v.id),end = "")
print("t_v={}, ".format(self.__edge_list[i].to_v.id),end = "")
print("cap={}]".format(self.__edge_list[i].cap))
# print(self.__edge_list.from_v)
# print(self.__edge_list.to_v)
# print(self.__edge_list.cap)
# print(self.__edge_list.alt)
class MaxFlow:
#
def __init__(self, graph, s_id, t_id):
self.graph = graph
self.s_v = graph.vertex(s_id)
self.t_v = graph.vertex(t_id)
self.dq = deque()
self.from_dict = dict()
def calc(self):
f = 0
while self.find_path():
f += 1
# デバッグ用
self.graph.print_edge()
print("f = {}".format(f))
self.from_dict.clear()
return(f)
# sからtへのパスを一つ見つけ、そのパス上の枝の容量を0にし、
# 逆の枝の容量を1にする
# 経路が見つかればTrue,見つからなければFalseを返す
def find_path(self):
# -1はfrom_idとして不正な値
self.put_q(self.s_v, None)
s_id = self.s_v.id
t_id = self.t_v.id
while len(self.dq) > 0:
v = self.dq.popleft()
v_id = v.id
if v_id == t_id:
# from_dictを使ってs_vまでの経路をたどる
while v_id != s_id:
n_e = self.from_dict[v_id]
r_e = n_e.alt
n_e.cap = 0
r_e.cap = 1
v_id = n_e.from_v.id
return True
# vに接続した枝eのうち、以下の条件を満たしたものを探す
# * eの容量が1である
# * e.toがfrom_dictに含まれていない
for e in v.edge_list:
if e.cap == 0:
continue
if e.to_v in self.from_dict:
continue
self.put_q(e.to_v, e)
return False
# vをqに積む、from_dictにvに至る枝eを記録する
def put_q(self, v, e):
self.dq.append(v)
self.from_dict[v.id] = e
if __name__ == "__main__":
def make_graph1():
g1 = Graph(2)
s1 = 0
t1 = 1
g1.add_edge(s1, t1, 1)
return g1, s1, t1
g1, s1, t1 = make_graph1()
mf1 = MaxFlow(g1, s1, t1)
f1 = mf1.calc()
print("f1 ={}".format(f1))
def make_graph2():
g = Graph(4)
s = 0
a = 1
b = 2
t = 3
g.add_edge(s, a, 1)
g.add_edge(s, b, 1)
g.add_edge(a, b, 1)
g.add_edge(a, t, 1)
g.add_edge(b, t, 1)
return g, s ,t
g2, s2, t2 = make_graph2()
mf2 = MaxFlow(g2, s2, t2)
print("f2 = {}".format(mf2.calc()))
``` | instruction | 0 | 95,064 | 16 | 190,128 |
No | output | 1 | 95,064 | 16 | 190,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1).
Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions:
* For each i (0 \leq i \leq N-1), A_i should be i or P_i.
* For each i (0 \leq i \leq N-1), B_i should be i or Q_i.
Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
Constraints
* 1 \leq N \leq 100000
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* 0 \leq Q_i \leq N-1
* Q_0,Q_1,\cdots,Q_{N-1} are all different.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_0 P_1 \cdots P_{N-1}
Q_0 Q_1 \cdots Q_{N-1}
Output
Print the maximum possible distance of A and B.
Examples
Input
4
2 1 3 0
0 2 3 1
Output
3
Input
10
0 4 5 3 7 8 2 1 9 6
3 8 5 6 4 0 2 1 7 9
Output
8
Input
32
22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13
22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31
Output
28
Submitted Solution:
```
import networkx as nx
from networkx.algorithms.flow import dinitz
import sys
def input():
return sys.stdin.readline()[:-1]
G = nx.Graph()
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
G.add_nodes_from(list(range(2*n+2)))
S, T = 2*n, 2*n+1
INF = 10**6
for i in range(2*n):
if i < n:
if p[i] != i:
G.add_edge(p[i], i, capacity=INF)
if p[i] == q[i]:
G.add_edge(i+n, i, capacity=1)
else:
G.add_edge(S, i, capacity=INF)
G.add_edge(i, i+n, capacity=1)
else:
if q[i-n] != i-n:
G.add_edge(i, q[i-n]+n, capacity=INF)
else:
G.add_edge(i, T, capacity=INF)
R = dinitz(G, S, T)
cut = int(R.graph['flow_value'])
#print(cut)
ans = n - cut
print(ans)
``` | instruction | 0 | 95,065 | 16 | 190,130 |
No | output | 1 | 95,065 | 16 | 190,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1).
Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions:
* For each i (0 \leq i \leq N-1), A_i should be i or P_i.
* For each i (0 \leq i \leq N-1), B_i should be i or Q_i.
Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
Constraints
* 1 \leq N \leq 100000
* 0 \leq P_i \leq N-1
* P_0,P_1,\cdots,P_{N-1} are all different.
* 0 \leq Q_i \leq N-1
* Q_0,Q_1,\cdots,Q_{N-1} are all different.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
P_0 P_1 \cdots P_{N-1}
Q_0 Q_1 \cdots Q_{N-1}
Output
Print the maximum possible distance of A and B.
Examples
Input
4
2 1 3 0
0 2 3 1
Output
3
Input
10
0 4 5 3 7 8 2 1 9 6
3 8 5 6 4 0 2 1 7 9
Output
8
Input
32
22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13
22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31
Output
28
Submitted Solution:
```
def mapcount(n):
if n != 0:
return 1
else:
return 0
import numpy as np
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
V = [i for i in range(N)]
npP = np.array(P)
npQ = np.array(Q)
npV = np.array(V)
countPQ = sum(map(mapcount,npP-npQ))
countQV = sum(map(mapcount,npQ-npV))
countVP = sum(map(mapcount,npV-npP))
print(max([countPQ,countQV,countVP]))
``` | instruction | 0 | 95,066 | 16 | 190,132 |
No | output | 1 | 95,066 | 16 | 190,133 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,067 | 16 | 190,134 |
"Correct Solution:
```
n,k=map(int,input().split());a=0
for i in range(n):
i+=1;p=1/n
while i<k:i*=2;p/=2
a+=p
print(a)
``` | output | 1 | 95,067 | 16 | 190,135 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,068 | 16 | 190,136 |
"Correct Solution:
```
#abc126c
n,k=list(map(int,input().split()))
res=0
for i in range(1,n+1):
p=1
t=1
while i*t<k:
t*=2
p/=2
res+=p/n
print(res)
``` | output | 1 | 95,068 | 16 | 190,137 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,069 | 16 | 190,138 |
"Correct Solution:
```
n,k=map(int,input().split())
a=0
for i in range(1,n+1):
j=0
while i<k:i*=2;j+=1
a+=1/n*.5**j
print(a)
``` | output | 1 | 95,069 | 16 | 190,139 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,070 | 16 | 190,140 |
"Correct Solution:
```
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
if i<k: p+=4*0.5**len(bin(~-k//i))
else: p+=1
print(p/n)
``` | output | 1 | 95,070 | 16 | 190,141 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,071 | 16 | 190,142 |
"Correct Solution:
```
n,k = map(int, input().split())
ans = 0
for i in range(1,n+1):
p = 0
while i < k:
i *= 2
p += 1
ans += 1 / 2**p
print(ans/n)
``` | output | 1 | 95,071 | 16 | 190,143 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,072 | 16 | 190,144 |
"Correct Solution:
```
n,k=map(int,input().split())
d=0
for i in range(1,n+1):
a=i
b=0
c=0
while a<k:
a=a*2
b=b+1
c=(1/2)**b
d=d+c
print(d/n)
``` | output | 1 | 95,072 | 16 | 190,145 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,073 | 16 | 190,146 |
"Correct Solution:
```
import math
n,k = list(map(int, input().split()))
print(sum([(1/2)**max(math.ceil(math.log2(k/(i+1))),0)/n for i in range(n)]))
``` | output | 1 | 95,073 | 16 | 190,147 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998 | instruction | 0 | 95,074 | 16 | 190,148 |
"Correct Solution:
```
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
k=i
p=1
while k<K:
p*=2
k*=2
ans+=1/p
print(ans/N)
``` | output | 1 | 95,074 | 16 | 190,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
import math
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
ans+=((1/2)**max(0,math.ceil(math.log2(k/i))))*1/n
print(ans)
``` | instruction | 0 | 95,075 | 16 | 190,150 |
Yes | output | 1 | 95,075 | 16 | 190,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
score=i
p=1
while(score<k):
score*=2
p/=2
ans+=p
print(ans/n)
``` | instruction | 0 | 95,076 | 16 | 190,152 |
Yes | output | 1 | 95,076 | 16 | 190,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
p = i
c = 0
while p < k:
p *= 2
c += 1
ans += (0.5)**c/n
print(ans)
``` | instruction | 0 | 95,077 | 16 | 190,154 |
Yes | output | 1 | 95,077 | 16 | 190,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
s=0
while i<K:
i*=2
s+=1
ans+=(1/N)*(1/(2**s))
print(ans)
``` | instruction | 0 | 95,078 | 16 | 190,156 |
Yes | output | 1 | 95,078 | 16 | 190,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
import math
N, K = map(int, input().split())
ANS = 0
for i in range(1,N+1):
if i < K:
ANS += (1/N) * (0.5**(math.ceil(math.log(int(K/i),2))))
else:
ANS += (1/N)*(N-K+1)
break
print(math.ceil(math.log(int(K/i),2)))
print(ANS)
``` | instruction | 0 | 95,079 | 16 | 190,158 |
No | output | 1 | 95,079 | 16 | 190,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
n,k = readInts()
# サイコロの出た目が1から考えてみる?
i = 1
cnt = 0
while i < k:
cnt += 1
i *= 2
#print(i,cnt)
ans = 0
for i in range(cnt,1,-1):# 分子が等比数列
#print(cnt)
ans += (1/n) * ((1/2) ** i)
for i in range(cnt+1,n+1):
ans += (1/n)
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 95,080 | 16 | 190,160 |
No | output | 1 | 95,080 | 16 | 190,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
N, K = map(int, input())
calc = 0
for i in range(1, N+1):
tmp = i
cnt = 0
while tmp <= K-1
tmp*=2
cnt+=1
calc += (1/N) * (1/(2**cnt))
print(calc)
``` | instruction | 0 | 95,081 | 16 | 190,162 |
No | output | 1 | 95,081 | 16 | 190,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
1. Throw the die. The current score is the result of the die.
2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
You are given N and K. Find the probability that Snuke wins the game.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
Examples
Input
3 10
Output
0.145833333333
Input
100000 5
Output
0.999973749998
Submitted Solution:
```
def main():
N, K = map(int, input().split())
sum = 1
cnt = 0
while sum < K:
sum *= 2
cnt += 1
ans = 0
for i in range(N):
if cnt > 0:
ans += (1 / N) * (0.5 ** cnt)
cnt -= 1
else:
ans += (1 / N)
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 95,082 | 16 | 190,164 |
No | output | 1 | 95,082 | 16 | 190,165 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,131 | 16 | 190,262 |
"Correct Solution:
```
from heapq import*
X,Y,Z=map(int,input().split());N=X+Y+Z;A=[];p=[];q=[];L=[0];R=[0]
for _ in[0]*N:A.append([int(e)for e in input().split()])
A.sort(key=lambda a:a[0]-a[1])
for i in range(N):
L+=[L[i]+A[i][1]];heappush(p,A[i][1]-A[i][2]);R+=[R[i]+A[-1-i][0]];heappush(q,A[~i][0]-A[~i][2])
if i>=Y:L[i+1]-=heappop(p)
if i>=X:R[i+1]-=heappop(q)
print(max(L[i]+R[~i]for i in range(Y,N-X+1)))
``` | output | 1 | 95,131 | 16 | 190,263 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,132 | 16 | 190,264 |
"Correct Solution:
```
import heapq
if __name__ == '__main__':
X, Y, Z = list(map(int, input().split()))
A = []
B = []
C = []
N = X + Y + Z
for i in range(N):
tmp_a, tmp_b, tmp_c = list(map(int, input().split()))
A.append(tmp_a)
B.append(tmp_b)
C.append(tmp_c)
gold_minus_silver = [(a - b, a, b, c) for (a, b, c) in zip(A, B, C)]
gold_minus_silver.sort()
# print(gold_minus_silver)
# 左側
left_side = []
for i in range(0, Y):
heapq.heappush(left_side, (
gold_minus_silver[i][2] - gold_minus_silver[i][3], gold_minus_silver[i][2], gold_minus_silver[i][3]))
left_max = [0 for i in range(Z + 1)]
for i in range(0, Y):
left_max[0] += left_side[i][1]
left_bronze = []
for K in range(1, Z + 1):
heapq.heappush(left_side, (gold_minus_silver[K + Y - 1][2] - gold_minus_silver[K + Y - 1][3],
gold_minus_silver[K + Y - 1][2],
gold_minus_silver[K + Y - 1][3]))
left_max[K] = left_max[K - 1] + gold_minus_silver[K + Y - 1][2]
bronze = heapq.heappop(left_side)
left_max[K] += (bronze[2] - bronze[1])
# print(left_max)
# 右側
right_side = []
for i in range(Y + Z, N):
heapq.heappush(right_side, (gold_minus_silver[i][1] - gold_minus_silver[i][3], gold_minus_silver[i][1],
gold_minus_silver[i][3]))
right_max = [0 for i in range(Z + 1)]
for i in range(0, X):
right_max[Z] += right_side[i][1]
right_bronze = []
for K in range(Z - 1, -1, -1):
heapq.heappush(right_side, (gold_minus_silver[K + Y][1] - gold_minus_silver[K + Y][3],
gold_minus_silver[K + Y][1],
gold_minus_silver[K + Y][3]))
right_max[K] = right_max[K + 1] + gold_minus_silver[K + Y][1]
bronze = heapq.heappop(right_side)
right_max[K] += (bronze[2] - bronze[1])
# print(right_max)
ans = 0
for i in range(0, Z + 1):
if ans < left_max[i] + right_max[i]:
ans = left_max[i] + right_max[i]
print(ans)
``` | output | 1 | 95,132 | 16 | 190,265 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,133 | 16 | 190,266 |
"Correct Solution:
```
import sys
from heapq import heappush, heappushpop
X, Y, Z = map(int, input().split())
xyz = sorted([list(map(int,l.split()))for l in sys.stdin],key=lambda x:x[0]-x[1])
uq = []
cy = 0
for x, y, z in xyz[:Y]:
heappush(uq, y - z)
cy += y
Ly = [cy]
for x, y, z in xyz[Y:Y+Z]:
cy += y - heappushpop(uq, y - z)
Ly += [cy]
lq = []
cx = 0
for x, y, z in xyz[-X:]:
heappush(lq, x - z)
cx += x
Lx = [cx]
for x, y, z in xyz[Y+Z-1:Y-1:-1]:
cx += x - heappushpop(lq, x - z)
Lx += [cx]
print(max(map(sum, zip(Lx, Ly[::-1]))))
``` | output | 1 | 95,133 | 16 | 190,267 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,134 | 16 | 190,268 |
"Correct Solution:
```
from heapq import*;X,Y,Z=map(int,input().split());N=X+Y+Z;A=[];q1=[];q2=[];L=[0];R=[0]
for _ in[0]*N:A.append([int(e)for e in input().split()])
A.sort(key=lambda a:a[0]-a[1])
for i in range(N):
L+=[L[i]+A[i][1]];heappush(q1,A[i][1]-A[i][2]);R+=[R[i]+A[-1-i][0]];heappush(q2,A[~i][0]-A[~i][2])
if i>=Y:L[i+1]-=heappop(q1)
if i>=X:R[i+1]-=heappop(q2)
print(max(L[i]+R[~i]for i in range(Y,N-X+1)))
``` | output | 1 | 95,134 | 16 | 190,269 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,135 | 16 | 190,270 |
"Correct Solution:
```
from heapq import*
X,Y,Z=map(int,input().split());N=X+Y+Z;A=[];q1=[];q2=[];L=[0];R=[0]
for _ in[0]*N:A.append([int(e)for e in input().split()])
A.sort(key=lambda a:a[0]-a[1])
for i in range(N):
L+=[L[i]+A[i][1]];heappush(q1,A[i][1]-A[i][2]);R+=[R[i]+A[-1-i][0]];heappush(q2,A[~i][0]-A[~i][2])
if i>=Y:L[i+1]-=heappop(q1)
if i>=X:R[i+1]-=heappop(q2)
print(max(L[i]+R[~i]for i in range(Y,N-X+1)))
``` | output | 1 | 95,135 | 16 | 190,271 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,136 | 16 | 190,272 |
"Correct Solution:
```
import heapq
X,Y,Z = map(int,input().split())
N = X+Y+Z
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort(key=lambda x:x[0]-x[1])
l_opt = [0]*(N+1)
r_opt = [0]*(N+1)
silver = bronze = 0
q_sb = []
heapq.heapify(q_sb)
for i,(g,s,b) in enumerate(src):
heapq.heappush(q_sb, (s-b, s, b))
silver += s
if i >= Y:
_, s2, b2 = heapq.heappop(q_sb)
silver -= s2
bronze += b2
l_opt[i+1] = silver + bronze
gold = bronze = 0
q_gb = []
heapq.heapify(q_gb)
for i,(g,s,b) in enumerate(reversed(src)):
heapq.heappush(q_gb, (g-b, g, b))
gold += g
if i >= X:
_, g2, b2 = heapq.heappop(q_gb)
gold -= g2
bronze += b2
r_opt[N-1-i] = gold + bronze
ans = 0
for l,r in list(zip(l_opt, r_opt))[Y:Y+Z+1]:
ans = max(ans, l+r)
print(ans)
``` | output | 1 | 95,136 | 16 | 190,273 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,137 | 16 | 190,274 |
"Correct Solution:
```
from heapq import heapify, heappushpop
from itertools import accumulate
X, Y, Z, *ABC = map(int, open(0).read().split())
P = sorted(zip(*[iter(ABC)] * 3), key=lambda t: t[0] - t[1])
G = sum(t[0] for t in P[-X:])
S = sum(t[1] for t in P[:Y])
C = sum(t[2] for t in P[Y:-X])
Qg = [a - c for a, b, c in P[-X:]]
heapify(Qg)
B = [0] + [a - c - heappushpop(Qg, a - c) for a, b, c in reversed(P[Y:-X])]
Qs = [b - c for a, b, c in P[:Y]]
heapify(Qs)
F = [0] + [b - c - heappushpop(Qs, b - c) for a, b, c in P[Y:-X]]
print(G + S + C + max(a + b for a, b in zip(accumulate(F), reversed(list(accumulate(B))))))
``` | output | 1 | 95,137 | 16 | 190,275 |
Provide a correct Python 3 solution for this coding contest problem.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975 | instruction | 0 | 95,138 | 16 | 190,276 |
"Correct Solution:
```
X, Y, Z = map(int, input().split())
ans = 0
BC = []
for _ in range(X+Y+Z):
a, b, c = map(int, input().split())
ans += a
BC.append([b-a, c-a])
BC.sort(key=lambda x: x[1]-x[0])
import heapq
q = []
an = 0
for b, _ in BC[:Y]:
heapq.heappush(q, b)
an += b
A = [an]
for b, _ in BC[Y:-Z]:
heapq.heappush(q, b)
an += b
b_ = heapq.heappop(q)
an -= b_
A.append(an)
q = []
an = 0
for _, c in BC[-Z:]:
heapq.heappush(q, c)
an += c
A[-1] += an
for i, (_, c) in enumerate(BC[-Z-1:Y-1:-1], 2):
heapq.heappush(q, c)
an += c
c_ = heapq.heappop(q)
an -= c_
A[-i] += an
print(ans + max(A))
``` | output | 1 | 95,138 | 16 | 190,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins.
Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke.
Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins.
Constraints
* 1 \leq X
* 1 \leq Y
* 1 \leq Z
* X+Y+Z \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* 1 \leq C_i \leq 10^9
Input
Input is given from Standard Input in the following format:
X Y Z
A_1 B_1 C_1
A_2 B_2 C_2
:
A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}
Output
Print the maximum possible total number of coins of all colors he gets.
Examples
Input
1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
Output
18
Input
3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
Output
110
Input
6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
Output
3093929975
Submitted Solution:
```
import heapq,sys
input=sys.stdin.readline
X,Y,Z=map(int,input().split())
N=X+Y+Z
coin=[tuple(map(int,input().split())) for i in range(N)]
coin.sort(key=lambda x:x[0]-x[1])
y=[0]*N
S=0
n=0
que=[]
for i in range(N):
val=coin[i][1]-coin[i][2]
if Y>n:
heapq.heappush(que,val)
S+=val
n+=1
y[i]=S
else:
if que[0]<val:
S+=val-que[0]
heapq.heappop(que)
heapq.heappush(que,val)
y[i]=S
x=[0]*N
S=0
n=0
que=[]
for i in range(N-1,-1,-1):
val=coin[i][0]-coin[i][2]
if X>n:
heapq.heappush(que,val)
S+=val
n+=1
x[i]=S
else:
if que[0]<val:
S+=val-que[0]
heapq.heappop(que)
heapq.heappush(que,val)
x[i]=S
base=sum(coin[i][2] for i in range(N))
ans=-1
for i in range(N):
if i>=Y-1 and N-(i+1)>=X:
temp=base+x[i+1]+y[i]
ans=max(ans,temp)
print(ans)
``` | instruction | 0 | 95,139 | 16 | 190,278 |
Yes | output | 1 | 95,139 | 16 | 190,279 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.