text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide a correct Python 3 solution for this coding contest problem.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 5)
class UnionFind:
def __init__(self, n):
self.table = [-1] * n
self.taken = [0] * n
def _root(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self._root(self.table[x])
return self.table[x]
def union(self, x, y):
r1 = self._root(x)
r2 = self._root(y)
if r1 == r2:
new_root = r1
else:
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.table[r1] += d2
self.taken[r1] += self.taken[r2]
new_root = r1
else:
self.table[r1] = r2
self.table[r2] += d1
self.taken[r2] += self.taken[r1]
new_root = r2
cells = -self.table[new_root]
taken = self.taken[new_root]
if cells > taken:
self.taken[new_root] += 1
return True
return False
n, h, w = map(int, input().split())
hw = h + w
cards = []
for line in sys.stdin:
r, c, a = map(int, line.split())
cards.append((a, r - 1, h + c - 1))
cards.sort(reverse=True)
uft = UnionFind(hw)
ans = 0
for a, r, c in cards:
if uft.union(r, c):
ans += a
print(ans)
```
| 91,500 |
Provide a correct Python 3 solution for this coding contest problem.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
"Correct Solution:
```
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*n
self.rank = [0]*n
self.cycle = [False]*n
def find(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if(x == y):
self.cycle[x] = True
elif(self.rank[x] > self.rank[y]):
self.root[x] += self.root[y]
self.cycle[x] |= self.cycle[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.cycle[y] |= self.cycle[x]
self.root[x] = y
if(self.rank[x] == self.rank[y]):
self.rank[y] += 1
def isSame(self, x, y):
return self.find(x) == self.find(y)
#サイクルは各連結成分に一つまで
def isSafe(self, x, y):
cx = self.cycle[self.find(x)]
cy = self.cycle[self.find(y)]
return not((self.isSame(x,y) and (cx or cy)) or (cx and cy))
n,h,w,*l = map(int,open(0).read().split())
cards = sorted([(a,r-1,c-1) for r,c,a in zip(*[iter(l)]*3)])[::-1]
uf = UnionFind(h+w)
ans = 0
for a,r,c in cards:
c += h
if uf.isSafe(r,c):
uf.unite(r,c)
ans += a
print(ans)
```
| 91,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
import operator
N,H,W = map(int,readline().split())
m = map(int,read().split())
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)
def find_root(x):
y = root[x]
if x == y:
return x
path = [x]
while y != root[y]:
path.append(y)
y = root[y]
for p in path:
root[p] = y
return y
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
```
Yes
| 91,502 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
self._edge = [0] * N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy:
self._edge[gx] += 1
return
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
self._edge[gy] += self._edge[gx]+1
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
self._edge[gx] += self._edge[gy]+1
def get_size(self, x):
return self._size[self.find_root(x)]
def is_same_group(self, x, y):
return self.find_root(x) == self.find_root(y)
def calc_group_num(self):
N = len(self._parent)
ans = 0
for i in range(N):
if self.find_root(i) == i:
ans += 1
return ans
def check(self,x,y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx==gy:
return self._size[gx]>=self._edge[gx]+1
else:
nv=self._size[gx]+self._size[gy]
ne=self._edge[gx]+self._edge[gy]+1
return nv>=ne
import sys
input=sys.stdin.readline
N,H,W=map(int,input().split())
card=[]
for i in range(N):
r,c,a=map(int,input().split())
card.append((a,r-1,c-1))
card.sort()
uf=UnionFindVerSize(H+W)
ans=0
while card:
val,r,c=card.pop()
if uf.check(r,H+c):
uf.unite(r,H+c)
ans+=val
print(ans)
```
Yes
| 91,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import operator
N,H,W = map(int,readline().split())
m = map(int,read().split())
RCA = sorted(zip(m,m,m),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W))
size = [1] * (H+W)
no_cycle = [True] * (H+W)
def find_root(x):
y = root[x]
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
size[x] += sy
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
```
Yes
| 91,504 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
N, H, W = map(int, input().split())
RCA = []
class UF(object):
def __init__(self, n):
self.parent = [i for i in range(n)]
def root(self, v):
if v == self.parent[v]:
return v
else:
self.parent[v] = self.root(self.parent[v])
return self.parent[v]
def unite(self, u, v):
u, v = self.root(u), self.root(v)
if (u == v):
return
self.parent[u] = v
for _ in range(N):
r, c, a = map(int, input().split())
r, c = r-1, c-1
RCA.append((a, r, c))
RCA.sort(reverse=True)
RCA = deque(RCA)
uf = UF(H+W+1) # r0, r1, ..., rH, c0, c1, ..., cW, loopflag
cnt, ans = 0, 0
while RCA and cnt < H+W:
a, r, c = RCA.popleft()
c += H
if uf.root(r) == uf.root(c):
if uf.root(r) == uf.root(H+W): # loop?
continue
uf.unite(r, H+W)
ans += a
cnt += 1
uf.unite(r, c)
print(ans)
```
Yes
| 91,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
def examA():
N = DI()/dec(7)
ans = N
print(N)
return
def examB():
ans = 0
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
N = I()
n = (N-1).bit_length()
V = [[-1]*(1<<n) for i in range(1<<n)]
#print(V)
for i in range(n):
b1 = 1 << i
b2 = 1 << (i + 1)
for j in range(1<<i):
for k in range(1<<(n-i)):
for l in range(1<<(n-i)):
#print(i,j,k,l,j+k*b2,j+b1+l*b2)
if j+k*b2>=N or j+b1+l*b2>=N:
continue
u,v = sorted([j+k*b2,j+b1+l*b2])
#print(u,v)
V[u][v-1] = i+1
ans = [[]for _ in range(N-1)]
for i in range(N-1):
for v in V[i]:
if v>=0:
ans[i].append(v)
for v in ans:
print(" ".join(map(str,v)))
return
# 解説
def examD2():
N = I()
ans = [[-1]*(N-1-i) for i in range(N-1)]
n = N.bit_length()
for i in range(N):
for j in range(i+1,N):
k = 0
while(True):
if i&(1<<k) != j&(1<<k):
break
k += 1
#print(i,j,j-i)
ans[i][j-i-1] = k+1
for v in ans:
print(" ".join(map(str,v)))
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
def test():
i = I()
li = LI()
lsi = LSI()
si = LS()
print(i)
print(li)
print(lsi)
print(si)
return
from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,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 = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(10**7)
if __name__ == '__main__':
examD2()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
```
No
| 91,506 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import operator
N,H,W = map(int,readline().split())
RCA = [int(x) for x in read().split()]
it = iter(RCA)
RCA = sorted(zip(it,it,it),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W+100))
size = [0] * (H+W+100)
no_cycle = [True] * (H+W+100)
def find_root(x):
y = root[x]
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
no_cycle[x] = (no_cycle[x] and no_cycle[y])
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
```
No
| 91,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
input=sys.stdin.readline
class UnionFind:
def __init__(self,n):
self.par=[i for i in range(n)]
self.rank=[0]*n
self.size=[1]*n
self.Ecnt=[0]*n
def root(self,x):
if self.par[x]==x:
return x
else:
self.par[x]=self.root(self.par[x])
return self.par[x]
def union(self,x,y):
px=self.root(x); py=self.root(y)
if px!=py:
if self.rank[px]==self.rank[py]:
self.rank[px]+=1
elif self.rank[px]<self.rank[py]:
px,py=py,px
self.par[py]=px
self.size[px]+=self.size[py]
self.Ecnt[px]+=self.Ecnt[py]+1
else:
self.Ecnt[px]+=1
def same_check(self,x,y):
return self.root(x)==self.root(y)
n,h,w=map(int,input().split())
RCA=[]
for _ in range(n):
r,c,a=map(int,input().split())
r-=1
c+=h-1
RCA.append((r,c,a))
RCA.sort(lambda x:x[2],reverse=True)
uf=UnionFind(h+w)
ans=0
for r,c,a in RCA:
if uf.size[uf.par[r]]+uf.size[uf.par[c]]==uf.Ecnt[uf.par[r]]+uf.Ecnt[uf.par[c]]:
continue
uf.union(r,c)
ans+=a
print(ans)
```
No
| 91,508 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N cards placed on a grid with H rows and W columns of squares.
The i-th card has an integer A_i written on it, and it is placed on the square at the R_i-th row from the top and the C_i-th column from the left.
Multiple cards may be placed on the same square.
You will first pick up at most one card from each row.
Then, you will pick up at most one card from each column.
Find the maximum possible sum of the integers written on the picked cards.
Constraints
* All values are integers.
* 1 \leq N \leq 10^5
* 1 \leq H, W \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq R_i \leq H
* 1 \leq C_i \leq W
Input
Input is given from Standard Input in the following format:
N H W
R_1 C_1 A_1
R_2 C_2 A_2
\vdots
R_N C_N A_N
Output
Print the maximum possible sum of the integers written on the picked cards.
Examples
Input
6 2 2
2 2 2
1 1 8
1 1 5
1 2 9
1 2 7
2 1 4
Output
28
Input
13 5 6
1 3 35902
4 6 19698
4 6 73389
3 6 3031
3 1 4771
1 4 4784
2 1 36357
2 1 24830
5 6 50219
4 6 22645
1 2 30739
1 4 68417
1 5 78537
Output
430590
Input
1 100000 100000
1 1 1
Output
1
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import operator
N,H,W = map(int,readline().split())
RCA = [int(x) for x in read().split()]
it = iter(RCA)
RCA = sorted(zip(it,it,it),key=operator.itemgetter(2),reverse=True)
root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)
def find_root(x):
y = root[x]
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x,y):
x,y = find_root(x),find_root(y)
sx,sy = size[x],size[y]
if sx < sy:
sx,sy = sy,sx
x,y = y,x
root[y] = x
no_cycle[x] = no_cycle[x] and no_cycle[y]
answer = 0
for R,C,A in RCA:
x,y = R-1,H+C-1
rx,ry = find_root(x),find_root(y)
assert 0 <= rx < H+W
assert 0 <= ry < H+W
continue
if rx == ry:
if not no_cycle[rx]:
continue
no_cycle[rx] = False
else:
if (not no_cycle[rx]) and (not no_cycle[ry]):
continue
merge(rx,ry)
answer += A
print(answer)
```
No
| 91,509 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
L=list(map(int,input().split()))
C=L[2]
L.sort()
if L[1]==C:
print("Yes")
else:
print("No")
```
| 91,510 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
A,B,C=map(int,input().split())
A,B=min(A,B),max(A,B)
print("Yes" if A<=C<=B else "No")
```
| 91,511 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a, b, c = map(int, input().split())
print("Yes" if min(a, b) <= c <= max(a, b) else "No")
```
| 91,512 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a, b, c = map(int, input().split())
print(["No","Yes"][a<c<b or b<c<a])
```
| 91,513 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a,b,c=map(int,input().split())
print(['No','Yes'][a<=c<=b or b<=c<=a])
```
| 91,514 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a,b,c = map(int,input().split())
print("Yes" if (a<b and a<c<b) or (a>b and b<c<a) else "No")
```
| 91,515 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a,s,d=map(int,input().split())
print("Yes" if (a-d)*(s-d)<=0 else "No")
```
| 91,516 |
Provide a correct Python 3 solution for this coding contest problem.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
"Correct Solution:
```
a,b,c=map(int,input().split())
print("Yes" if a>c>b or b>c>a else "No")
```
| 91,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a,b,c=map(int,input().split())
print("Yes" if a<c<b or b<c<a else "No")
```
Yes
| 91,518 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a,b,c=map(int,input().split())
if a<=c<=b or a>c>b:
print("Yes")
else:
print("No")
```
Yes
| 91,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a = [int(item) for item in input().split()]
print("No" if a[2] in (max(a), min(a)) else "Yes")
```
Yes
| 91,520 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a,b,c=map(int,input().split())
print('Yes' if a<c<b or a>c>b else 'No')
```
Yes
| 91,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a, b, c = map(int, input().split())
p_min = min(a, b)
p_max = max(a, b)
print(p_min, p_max)
if p_min <= c <= p_max:
print('Yes')
else:
print('No')
```
No
| 91,522 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a, b, c = map(int, input().split())
print("Yes" if max(a, b, c) == b or min(a, b, c) == b else "NO")
```
No
| 91,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
n = int(input())
s = input()
s = list(s)
t = s
cnt = 0
for i in range(n-2):
if s[i] == '.' and s[i+1] == '#' and s[i+2] == '.':
s[i+1] = '.'
cnt+=1
for i in range(n-1):
if s[i] == '#' and s[i+1] == '.':
s[i+1] = '#'
cnt+=1
print(cnt)
```
No
| 91,524 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Examples
Input
3 8 5
Output
Yes
Input
7 3 1
Output
No
Input
10 2 4
Output
Yes
Input
31 41 59
Output
No
Submitted Solution:
```
a, b, c = input().split()
if a < b and b < c:
print 'No'
if a < c and c < b:
print('Yes')
if b < c and c < a:
print('Yes')
if b < a and a < c:
print('No')
if c < a and a < b:
print('Yes')
if c < b and b < a:
print('No')
```
No
| 91,525 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
print("YES" if input() in ['3','5','7'] else "NO")
```
| 91,526 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
print(["NO", "YES"][[7, 5, 3].count(int(input()))])
```
| 91,527 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
print(["NO","YES"][int(input()) in (3,5,7)])
```
| 91,528 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
x=input()
print("YES" if x in "357" else "NO")
```
| 91,529 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
n=int(input())
print('YES' if n==7 or n==5 or n==3 else 'NO')
```
| 91,530 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
print(['NO','YES'][int(input())in[3,5,7]])
```
| 91,531 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
X = input()
print("YES" if (X in "753") else "NO")
```
| 91,532 |
Provide a correct Python 3 solution for this coding contest problem.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
"Correct Solution:
```
print('YNEOS'[input() not in '753'::2])
```
| 91,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
print("YNEOS"[2+~(int(input()) in [3,5,7])::2])
```
Yes
| 91,534 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
x=input();print(["NO","YES"][x in ["3","5","7"]])
```
Yes
| 91,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
print("YNEOS"[input()in'124689'::2])
```
Yes
| 91,536 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
x = int(input())
print("YES" if x in (7, 5, 3) else "NO")
```
Yes
| 91,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
x = input()
if x == 7:
print('YES')
elif x == 5:
print('YES')
elif x == 3:
print('YES')
else:
print('NO')
```
No
| 91,538 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
x = input()
if x in "753":
print('Yes')
else:
print('No')
```
No
| 91,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
print('NYoe s'[input()in'357'::2])
```
No
| 91,540 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
Constraints
* 1 ≤ X ≤ 9
* X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.
Examples
Input
5
Output
YES
Input
6
Output
NO
Submitted Solution:
```
idade = int(input())
if idade in range(1 ,9):
if idade == 3 :
print("YES")
elif idade == 5 :
print("YES")
elif idade == 7 :
print("YES")
else :
print("NO")
```
No
| 91,541 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a,b = map(int,input().split())
a -= a > b
print(a)
```
| 91,542 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a, b = [int(x) for x in input().split()]
print(a-1) if a>b else print(a)
```
| 91,543 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a, b = list(map(int, input().split()))
print(a if (a<=b) else a-1)
```
| 91,544 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a,b = map(int,input().split())
ans = a-1
if b >= a:
ans += 1
print(ans)
```
| 91,545 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a,b = map(int, input().split())
print(1 if a ==1 else a if b>=a else a-1)
```
| 91,546 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a,b=map(int, input().split())
if a>b:
flag=1
else:
flag=0
print(a-flag)
```
| 91,547 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
a,b = map(int,input().split())
if b >= a:
print(a)
else:
print(a-1)
```
| 91,548 |
Provide a correct Python 3 solution for this coding contest problem.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
"Correct Solution:
```
# coding: utf-8
a, b = map(int, input().split())
print([a - 1, a][a <= b])
```
| 91,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a, b = map(int, input().split())
print((a - 1) if a > b else a)
```
Yes
| 91,550 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a,b = map(int,input().split())
print(a - (1 if a>b else 0))
```
Yes
| 91,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a, b = list(map(int, input().split()))
print(a) if a <= b else print(a-1)
```
Yes
| 91,552 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a, b = map(int, input().split())
ans = a if b >= a else a - 1
print(ans)
```
Yes
| 91,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a,b=map(int,input().split())
print(b if a>b else a)
```
No
| 91,554 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
def main():
a, b = map(int, input().split())
cnt = 0
for i in range(1, 13):
if i <= a and i <= b:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
```
No
| 91,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a,b=map(int ,raw_input().split())
if a<=b:
print(a)
else:
print(a-1)
```
No
| 91,556 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
* a is an integer between 1 and 12 (inclusive).
* b is an integer between 1 and 31 (inclusive).
* 2018-a-b is a valid date in Gregorian calendar.
Input
Input is given from Standard Input in the following format:
a b
Output
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
Examples
Input
5 5
Output
5
Input
2 1
Output
1
Input
11 30
Output
11
Submitted Solution:
```
a,b = map(int,input())
if a >= b:
print(a)
else:
print(b)
```
No
| 91,557 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.
Constraints
* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M
Output
Print the answer.
Examples
Input
4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
Output
60
Input
5 2 4
0 0 0 0 0
1 2 10
2 3 10
Output
-1
Input
9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
Output
118901402
Input
18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
Output
171
"Correct Solution:
```
class Unionfindtree:
def __init__(self, number):
self.par = [i for i in range(number)]
self.rank = [0] * (number)
def find(self, x): # 親を探す
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y): # x,yを繋げる
px = self.find(x)
py = self.find(y)
if px == py:
return
if self.rank[px] < self.rank[py]:
self.par[px] = py
else:
self.par[py] = px
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
def connect(self, x, y): # 親が同じかみる
return self.find(x) == self.find(y)
N, M, K = map(int, input().split())
C = [int(i) for i in input().split()]
table = []
t = K
for i in range(N):
if C[i]==0:
t+=1
C[i]=t
for i in range(M):
s, u, c = map(int, input().split())
a, b = C[s - 1], C[u - 1]
table.append((c, a, b))
tree = Unionfindtree(t+1)
table.sort()
ct = K - 1
ans = 0
for c, a, b in table:
if not tree.connect(a, b) and ct > 0:
tree.union(a, b)
ans += c
ct -= 1
if ct > 0:
print(-1)
else:
print(ans)
```
| 91,558 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.
Constraints
* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M
Output
Print the answer.
Examples
Input
4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
Output
60
Input
5 2 4
0 0 0 0 0
1 2 10
2 3 10
Output
-1
Input
9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
Output
118901402
Input
18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
Output
171
Submitted Solution:
```
#include <bits/stdc++.h>
using namespace std;
const long long INF =
sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<long long, long long>;
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T>
void printvv(const vector<vector<T>> &v) {
cerr << endl;
for (long long i = (0); i < (v.size()); i++)
for (long long j = (0); j < (v[i].size()); j++) {
if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
cerr << "INF";
} else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using Weight = long long;
using Flow = long long;
struct Edge {
long long s, d;
Weight w;
Flow c;
Edge(){};
Edge(long long s, long long d, Weight w = 1) : s(s), d(d), w(w), c(w){};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) {
return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')');
}
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
void addArc(Graph &g, long long s, long long d, Weight w = 1) {
g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, long long a, long long b, Weight w = 1) {
addArc(g, a, b, w);
addArc(g, b, a, w);
}
struct DisjointSet {
vector<long long> rank, p, S;
DisjointSet() {}
DisjointSet(long long size) {
S.resize(size, 1);
rank.resize(size, 0);
p.resize(size, 0);
for (long long i = (0); i < (size); i++) makeSet(i);
}
void makeSet(long long x) {
p[x] = x;
rank[x] = 0;
}
bool same(long long x, long long y) { return findSet(x) == findSet(y); }
void unite(long long x, long long y) {
if (same(x, y)) return;
link(findSet(x), findSet(y));
}
void link(long long x, long long y) {
if (rank[x] > rank[y]) {
p[y] = x;
} else {
p[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
S[x] = S[y] = S[x] + S[y];
}
long long findSet(long long x) {
if (x != p[x]) {
p[x] = findSet(p[x]);
}
return p[x];
}
long long connectedComponentSize(long long x) { return S[findSet(x)]; }
};
long long kruskal(long long N, long long K, vector<Edge> &edges) {
long long totalCost = 0;
sort(begin(edges), end(edges));
DisjointSet dset(N);
long long k = 0;
for (long long i = (0); i < (edges.size()); i++) {
Edge e = edges[i];
if (!dset.same(e.s, e.d)) {
totalCost += e.w;
dset.unite(e.s, e.d);
k++;
if (k == K - 1) break;
}
}
if (k != K - 1) totalCost = -1;
return totalCost;
}
signed main(signed argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
long long N, M;
cin >> N >> M;
long long K;
cin >> K;
vector<long long> c(N);
long long x = K;
for (long long i = (0); i < (N); i++) {
cin >> c[i];
c[i]--;
if (c[i] == -1) c[i] = x++;
}
Edges es;
for (long long loop = ((0)); loop < ((M)); loop++) {
long long a, b, w;
cin >> a >> b >> w;
a--, b--;
es.emplace_back(c[a], c[b], w);
}
cout << kruskal(x, K, es) << endl;
return 0;
}
```
No
| 91,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.
Constraints
* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M
Output
Print the answer.
Examples
Input
4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
Output
60
Input
5 2 4
0 0 0 0 0
1 2 10
2 3 10
Output
-1
Input
9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
Output
118901402
Input
18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
Output
171
Submitted Solution:
```
N, M, K = map(int, input().split())
*C, = map(int, input().split())
G = [[] for i in range(N)]
E = []
for i in range(M):
a, b, w = map(int, input().split())
G[a-1].append((b-1, w))
G[b-1].append((a-1, w))
E.append((w, a-1, b-1))
def root(parent, x):
if x == parent[x]:
return x
parent[x] = y = root(parent, parent[x])
return y
def unite(parent, x, y):
px = root(parent, x); py = root(parent, y)
if px < py:
parent[py] = px
else:
parent[px] = py
E.sort()
*p, = range(N)
res = 0
for w, a, b in E:
if root(p, a) != root(p, b):
unite(p, a, b)
res += w
if N == K and all(C[i] == i+1 for i in range(N)):
if not all(root(p, i) == 0 for i in range(N)):
print(-1)
exit(0)
print(res)
else:
if all(C[i] == 0 for i in range(N)):
#if not all(root(p, i) == 0 for i in range(N)):
# print(-1)
# exit(0)
print(0)
if all(C[i] != 0 for i in range(N)):
*p, = range(K)
res = 0
for w, a, b in E:
ga = C[a]-1; gb = C[b]-1
if root(p, ga) != root(p, gb):
unite(p, ga, gb)
res += w
if not all(root(p, i) == 0 for i in range(K)):
print(-1)
else:
print(res)
```
No
| 91,560 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.
Constraints
* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M
Output
Print the answer.
Examples
Input
4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
Output
60
Input
5 2 4
0 0 0 0 0
1 2 10
2 3 10
Output
-1
Input
9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
Output
118901402
Input
18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
Output
171
Submitted Solution:
```
N, M, K = map(int, input().split())
*C, = map(int, input().split())
G = [[] for i in range(N)]
E = []
for i in range(M):
a, b, w = map(int, input().split())
G[a-1].append((b-1, w))
G[b-1].append((a-1, w))
E.append((w, a-1, b-1))
def root(parent, x):
if x == parent[x]:
return x
parent[x] = y = root(parent, parent[x])
return y
def unite(parent, x, y):
px = root(parent, x); py = root(parent, y)
if px < py:
parent[py] = px
else:
parent[px] = py
E.sort()
*p, = range(N)
res = 0
for w, a, b in E:
if root(p, a) != root(p, b):
unite(p, a, b)
res += w
if N == K and all(C[i] == i+1 for i in range(N)):
if not all(root(p, i) == 0 for i in range(N)):
print(-1)
exit(0)
print(res)
else:
if all(C[i] == 0 for i in range(N)):
count = 0
*p, = range(N)
res = 0
for w, a, b in E:
if root(p, a) != root(p, b) and count < K:
unite(p, a, b)
res += w
count += 1
if count == K:
print(res)
else:
print(-1)
elif all(C[i] != 0 for i in range(N)):
*p, = range(K)
res = 0
for w, a, b in E:
ga = C[a]-1; gb = C[b]-1
if root(p, ga) != root(p, gb):
unite(p, ga, gb)
res += w
if not all(root(p, i) == 0 for i in range(K)):
print(-1)
else:
print(res)
else:
exit(1)
```
No
| 91,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.
Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.
After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.
Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:
* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.
Constraints
* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M
Output
Print the answer.
Examples
Input
4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
Output
60
Input
5 2 4
0 0 0 0 0
1 2 10
2 3 10
Output
-1
Input
9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
Output
118901402
Input
18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
Output
171
Submitted Solution:
```
class Unionfindtree:
def __init__(self, number):
self.par = [i for i in range(number)]
self.rank = [0] * (number)
def find(self, x): # 親を探す
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y): # x,yを繋げる
px = self.find(x)
py = self.find(y)
if px == py:
return
if self.rank[px] < self.rank[py]:
self.par[px] = py
else:
self.par[py] = px
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
def connect(self, x, y): # 親が同じかみる
return self.find(x) == self.find(y)
N, M, K = map(int, input().split())
C = [int(i) for i in input().split()]
table = []
t = K
dd = {}
for i in range(M):
s, u, c = map(int, input().split())
a, b = C[s - 1], C[u - 1]
if a == 0:
a = dd.get(s, -1)
if a == -1:
t += 1
dd[s] = t
a = t
elif b == 0:
b = dd.get(u, -1)
if b == -1:
t += 1
dd[u] = t
b = t
table.append((c, a, b))
tree = Unionfindtree(t+1)
table.sort()
ct = K - 1
ans = 0
for c, a, b in table:
if not tree.connect(a, b) and ct > 0:
tree.union(a, b)
ans += c
ct -= 1
if ct > 0:
print(-1)
else:
print(ans)
```
No
| 91,562 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n = int(input())
a = [int(input()) for i in range(n)]
x = 1
i = 0
while i < n and x != 2:
x = a[x-1]
i += 1
if x == 2:
print(i)
else:
print(-1)
```
| 91,563 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
N=int(input())
a=[int(input()) for i in range(N)]
x=1
for i in range(N):
if(x==2):
print(i)
exit()
x=a[x-1]
print("-1")
```
| 91,564 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n=int(input())
a=[0]*(n+1)
for i in range(n):
a[i]=int(input())
k=0
ans=-1
for i in range(n):
# print(k)
k=a[k]-1
if(k==1):
ans=i+1
break
print(ans)
```
| 91,565 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n=int(input())
a=[int(input()) for i in range(n)]
count=1
for i in range(n):
if count == 2:
print(i)
exit()
count=a[count-1]
print(-1)
```
| 91,566 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n=int(input())
a=[int(input())-1 for _ in range(n)]
i=0
ct=0
while i!=1:
if a[i]==-1:
print("-1")
break
k=i
i=a[i]
a[k]=-1
ct+=1
else:
print(ct)
```
| 91,567 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n=int(input())
l=[int(input()) for i in range(n)]
count=0
for i in range(n):
if l[count]==2:
print(i+1)
exit()
else:
count=l[count]-1
print(-1)
```
| 91,568 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n,ans=int(input()),-1
a,m=[int(input())for i in range(n)],1
for i in range(n):
m=a[m-1]
if m==2:
ans=i+1
break
print(ans)
```
| 91,569 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
"Correct Solution:
```
n=int(input())
a=list(int(input())-1 for _ in[0]*n)
s=0
c=0
while s!=1 and c<n:
c+=1
s=a[s]
print(c if c<n else -1)
```
| 91,570 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n=int(input())
A=[]
for i in range(n):
A.append(int(input()))
k=1
for i in range(n):
if A[k-1]==2:
print(i+1)
exit()
k=A[k-1]
print(-1)
```
Yes
| 91,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n,*a=map(int,open(0).readlines());c,s=1,a[0]
while s!=2and c<n:c+=1;s=a[s-1]
print(c*(c<n)or-1)
```
Yes
| 91,572 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n=int(input())
A=list(int(input()) for i in range(n))
a=0
count=0
for i in range(n):
if a!=1:
a=A[a]-1
count+=1
print(count if a==1 else -1)
```
Yes
| 91,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
import sys
e = list(map(int,sys.stdin))
cur = e[1]
for i in range(e[0]):
if cur == 2:
print(i + 1)
break
cur = e[cur]
else:
print(-1)
```
Yes
| 91,574 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
data = ([int(input()) for i in range(N)])
data.insert(0, 0)
i = 1
cnt = 0
push_button = {1: "PUSH"}
while True:
trans_value = data[i]
cnt += 1
push_button[trans_value] = "PUSH"
if trans_value in push_button:
cnt = -1
break
if trans_value == 2:
break
print(cnt)
```
No
| 91,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
buttons = [int(input()) for _ in range(N)]
count = 1
tmp = buttons[0]
flag = True
while count < N+2:
tmp = buttons[tmp-1]
count += 1
if tmp == 2:
print(count)
flag = False
break
if flag:
print(-1)
```
No
| 91,576 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n = int(input())
a=[0]
for i in range(n):
a.append(int(input()))
s=1
cnt=0
while s !=2:
s=a[s]
cnt +=1
print(s)
print(cnt)
```
No
| 91,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
btn = [int(input())-1 for _ in range(N)]
i = 0
li = [0]
for _ in range(N):
k = btn[i]
#print(k, li)
if k in li:
print('-1')
break
else:
if k != 1:
li.append(k)
else:
print(len(li))
break
i = k
```
No
| 91,578 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
K, S = [int(i) for i in input().split()]
AA = [1 for X in range(K+1) for Y in range(K+1) if 0<=S-X-Y<=K]
print(len(AA))
```
| 91,579 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
k,s = map(int,input().split())
print(sum([1 for a in range(k+1) for b in range(k+1) if 0 <= s-a-b <= k]))
```
| 91,580 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
ans=0
a,b=map(int,input().split())
for s in range(a+1):
for t in range(a+1):
if 0<=b-s-t<=a:
ans+=1
print(ans)
```
| 91,581 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
k,s=map(int,input().split())
a=0
for i in range(k+1):
for j in range(k+1):
if s-i-j <=k and s-i-j >=0:
a+=1
print(a)
```
| 91,582 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
k,s=map(int,input().split())
count=0
for x in range(k+1):
for y in range(k+1):
if k>=s-x-y>=0:
count+=1
print(count)
```
| 91,583 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
K, S = map(int, input().split())
print(sum(0 <= S - (x + y) <= K for y in range(K + 1) for x in range(K + 1)))
```
| 91,584 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
K,s=map(int,input().split())
cnt=0
for i in range(K+1):
for j in range(K+1):
if s-i-j >= 0 and s-i-j<=K:
cnt+=1
print(cnt)
```
| 91,585 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
"Correct Solution:
```
n,s=map(int,input().split())
ans=0
for i in range(n+1):
for j in range(n+1):
if -1<s-i-j<n+1:
ans+=1
print(ans)
```
| 91,586 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
k,s = map(int, input().split())
print(len([s-y-z for z in range(k+1) for y in range(k+1) if 0<=s-y-z<=k]))
```
Yes
| 91,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
k,s=map(int,input().split())
print(len([2 for z in range(k+1) for y in range(k+1) if 0<=s-y-z<=k]))
```
Yes
| 91,588 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
k,s=map(int,input().split())
print(sum(0<=s-y-z<=k for y in range(k+1) for z in range(k+1)))
```
Yes
| 91,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
a,b=input().split()
a=int(a)
b=int(b)
c=0
for i in range(a+1):
for k in range(a+1):
if b-a<=i+k<=b:
c=c+1
print(c)
```
Yes
| 91,590 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
K,S = map(int, input().split())
ans = 0
if K*3<S:
print(0)
exit()
for x in range(K, -1, -1):
for y in range(K, -1, -1):
if x+y >=S:
break
for z in range(K, -1, -1):
if x+y+z==S:
ans+=1
elif x+y+z<S:
break
print(ans)
```
No
| 91,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
k,s = map(int,input().split())
x = list(range(k+1))
y = list(range(k+1))
z = list(range(k+1))
count = 0
for i in range(k+1):
for j in range(k+1):
if (s - (x[i] + y[j])) in z:
count += 1
print(count)
```
No
| 91,592 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
k, s = map(int, input().split())
cnt = 0
for i in range(k):
for j in range(k):
if max(0, s-k) <= i+j <= s:
cnt += 1
elif i + j > s:
break
print(cnt)
```
No
| 91,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
Constraints
* 2≤K≤2500
* 0≤S≤3K
* K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X, Y and Z that satisfy the condition.
Examples
Input
2 2
Output
6
Input
5 15
Output
1
Submitted Solution:
```
K, S = map(int, input().split())
ans = 0
for i in range(0,K+1):
for j in range (0,K+1):
for k in range (0,K+1):
if (i + j + k) == S:
ans = ans + 1
print(ans)
```
No
| 91,594 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
Constraints
* 3 \leq H \leq 10^9
* 3 \leq W \leq 10^9
* 0 \leq N \leq min(10^5,H×W)
* 1 \leq a_i \leq H (1 \leq i \leq N)
* 1 \leq b_i \leq W (1 \leq i \leq N)
* (a_i, b_i) \neq (a_j, b_j) (i \neq j)
Input
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
Output
Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
Examples
Input
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Output
0
0
0
2
4
0
0
0
0
0
Input
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
Output
4
26
22
10
2
0
0
0
0
0
Input
1000000000 1000000000 0
Output
999999996000000004
0
0
0
0
0
0
0
0
0
"Correct Solution:
```
from collections import defaultdict
H,W,N = map(int,input().split())
d = defaultdict(int)
for i in range(N):
a,b = map(int,input().split())
for dy in range(-1,2):
for dx in range(-1,2):
if a+dy >= 2 and a+dy <= H-1 and b+dx >= 2 and b+dx <= W-1:
d[(a+dy,b+dx)] += 1
ans = [0]*10
ans[0] = (H-2)*(W-2)-len(d)
for i in d.values():
ans[i] += 1
for i in ans:
print(i)
```
| 91,595 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
Constraints
* 3 \leq H \leq 10^9
* 3 \leq W \leq 10^9
* 0 \leq N \leq min(10^5,H×W)
* 1 \leq a_i \leq H (1 \leq i \leq N)
* 1 \leq b_i \leq W (1 \leq i \leq N)
* (a_i, b_i) \neq (a_j, b_j) (i \neq j)
Input
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
Output
Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
Examples
Input
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Output
0
0
0
2
4
0
0
0
0
0
Input
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
Output
4
26
22
10
2
0
0
0
0
0
Input
1000000000 1000000000 0
Output
999999996000000004
0
0
0
0
0
0
0
0
0
"Correct Solution:
```
from collections import defaultdict
H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
Cells = defaultdict(int)
Count = [(H-2)*(W-2)] + [0 for _ in range(9)]
for a,b in AB:
a -= 1
b -= 1
for i in range(-1,2):
for j in range(-1,2):
if 1 <= a+i <= H-2 and 1 <= b+j <= W-2:
Count[Cells[(a+i,b+j)]] -= 1
Count[Cells[(a+i,b+j)]+1] += 1
Cells[(a+i,b+j)] += 1
for c in Count:
print(c)
```
| 91,596 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
Constraints
* 3 \leq H \leq 10^9
* 3 \leq W \leq 10^9
* 0 \leq N \leq min(10^5,H×W)
* 1 \leq a_i \leq H (1 \leq i \leq N)
* 1 \leq b_i \leq W (1 \leq i \leq N)
* (a_i, b_i) \neq (a_j, b_j) (i \neq j)
Input
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
Output
Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
Examples
Input
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Output
0
0
0
2
4
0
0
0
0
0
Input
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
Output
4
26
22
10
2
0
0
0
0
0
Input
1000000000 1000000000 0
Output
999999996000000004
0
0
0
0
0
0
0
0
0
"Correct Solution:
```
h,w,n=map(int,input().split())
d={}
for _ in range(n):
a,b=map(int,input().split())
for i in (-1,0,1):
for j in (-1,0,1):
if 2<=a+i<=h-1 and 2<=b+j<=w-1:
d.setdefault((a+i,b+j),0)
d[a+i,b+j]+=1
r=[0]*10
for i in d.values():
r[i]+=1
r[0]=(h-2)*(w-2)-sum(r)
for i in r:
print(i)
```
| 91,597 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
Constraints
* 3 \leq H \leq 10^9
* 3 \leq W \leq 10^9
* 0 \leq N \leq min(10^5,H×W)
* 1 \leq a_i \leq H (1 \leq i \leq N)
* 1 \leq b_i \leq W (1 \leq i \leq N)
* (a_i, b_i) \neq (a_j, b_j) (i \neq j)
Input
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
Output
Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
Examples
Input
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Output
0
0
0
2
4
0
0
0
0
0
Input
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
Output
4
26
22
10
2
0
0
0
0
0
Input
1000000000 1000000000 0
Output
999999996000000004
0
0
0
0
0
0
0
0
0
"Correct Solution:
```
h,w,n = map(int,input().split())
grids = {}
D = [1,-1,0]
for _ in range(n):
a,b = map(int,input().split())
a -= 1
b -= 1
for dx in D:
for dy in D:
na,nb = a+dx,b+dy
if not(0<na<h-1 and 0<nb<w-1):
continue
if(na,nb) not in grids:
grids[(na,nb)] = 0
grids[(na,nb)] += 1
ans = [0 for _ in range(10)]
for v in grids.values():
ans[v]+=1
ans[0] = (h-2)*(w-2)-sum(ans)
for a in ans:
print(a)
```
| 91,598 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
* For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
Constraints
* 3 \leq H \leq 10^9
* 3 \leq W \leq 10^9
* 0 \leq N \leq min(10^5,H×W)
* 1 \leq a_i \leq H (1 \leq i \leq N)
* 1 \leq b_i \leq W (1 \leq i \leq N)
* (a_i, b_i) \neq (a_j, b_j) (i \neq j)
Input
The input is given from Standard Input in the following format:
H W N
a_1 b_1
:
a_N b_N
Output
Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.
Examples
Input
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4
Output
0
0
0
2
4
0
0
0
0
0
Input
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
Output
4
26
22
10
2
0
0
0
0
0
Input
1000000000 1000000000 0
Output
999999996000000004
0
0
0
0
0
0
0
0
0
"Correct Solution:
```
from collections import defaultdict
h,w,n=map(int,input().split())
d=defaultdict(int)
s=set()
for _ in range(n):
a,b=map(int,input().split())
a-=1
b-=1
for dy in [-2,-1,0]:
for dx in [-2,-1,0]:
ny,nx=a+dy,b+dx
if 0<=ny<h and 0<=nx<w and ny+2<h and nx+2<w:
d[(ny,nx)]+=1
s.add((ny,nx))
cnt=[0]*10
q=0
for y,x in s:
cnt[d[(y,x)]]+=1
cnt[0]=(h-2)*(w-2)-len(s)
for i in cnt:
print(i)
```
| 91,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.