message
stringlengths
2
19.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
322
108k
cluster
float64
15
15
__index_level_0__
int64
644
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n,h=open(0);a=b=c=0 for i in map(int,h.split()):c=(b>=i)*-~c;b=i;a=max(a,c) print(a) ```
instruction
0
13,149
15
26,298
Yes
output
1
13,149
15
26,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n=int(input()) h=[int(i) for i in input().split()] j=0 k=0 for i in range(1,len(h)): if h[i-1]>=h[i]: j+=1 else: k=max(k,j) j=0 k=max(k,j) print(k) ```
instruction
0
13,150
15
26,300
Yes
output
1
13,150
15
26,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n=int(input()) H=list(map(int,input().split())) res=0 cnt=0 for i in range(n-1): if H[i]>=H[i+1]: cnt += 1 else: cnt = 0 res=max(res,cnt) print(res) ```
instruction
0
13,151
15
26,302
Yes
output
1
13,151
15
26,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n = int(input()) h = list(map(int, input().split())) a = 0 move = [] for i in range(n-1): if h[i] >= h[i+1]: a += 1 else: move.append(a) a = 0 print(max(move)) ```
instruction
0
13,152
15
26,304
No
output
1
13,152
15
26,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` n = int(input()) h = list(map(int,input().split())) h.append(10**10) counter = [] for i in range(n): cnt = 0 for j in range(i,n): if h[j]>=h[j+1]: cnt +=1 else: counter.append(cnt) break ans = max(counter) print(ans) ```
instruction
0
13,153
15
26,306
No
output
1
13,153
15
26,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` def main(): # n,k = map(int,input().split()) n = int(input()) # s = str(input()) h = list(map(int,input().split())) # l = [list(map(int, input().split())) for _ in range(n)] # s = list(s) ans = 0 dp = [0] * n if n == 1: print(0) if n == 2: if h[0] >= h[1]: print(1) else: print(0) else: if h[0] >= h[1]: dp[0] = 1 for i in range(1,n-1): if h[i] >= h[i+1]: dp[i] = dp[i-1] + 1 else: dp[i] = 0 print(max(dp)) if __name__ == '__main__': main() ```
instruction
0
13,154
15
26,308
No
output
1
13,154
15
26,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * 1 \leq H_i \leq 10^9 Input Input is given from Standard Input in the following format: N H_1 H_2 ... H_N Output Print the maximum number of times you can move. Examples Input 5 10 4 8 7 3 Output 2 Input 7 4 4 5 6 6 5 5 Output 3 Input 4 1 2 3 4 Output 0 Submitted Solution: ``` N = int(input()) H = input().split() Move = 0 tmp = 0 for i in range(N-1): if int(H[i+1]) > int(H[i]): tmp = 0 if Move < tmp: Move = tmp else: tmp += 1 print(H[i],H[i+1]) if Move < tmp: Move = tmp print(Move) ```
instruction
0
13,155
15
26,310
No
output
1
13,155
15
26,311
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,427
15
26,854
Tags: sortings Correct Solution: ``` def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(m)) h = [False for _ in range(n + 1)] v = [False for _ in range(n + 1)] d1 = [False for _ in range(n * 2 + 1)] d2 = [False for _ in range(n * 2 + 1)] for x, y in l: line = h[y] if not line: h[y] = (x, x) else: mi, ma = line if mi > x: h[y] = (x, ma) elif ma < x: h[y] = (mi, x) line = v[x] if not line: v[x] = (y, y) else: mi, ma = line if mi > y: v[x] = (y, ma) elif ma < y: v[x] = (mi, y) xy = x + y line = d1[xy] if not line: d1[xy] = (x, x) else: mi, ma = line if mi > x: d1[xy] = (x, ma) elif ma < x: d1[xy] = (mi, x) xy = x - y + n line = d2[xy] if not line: d2[xy] = (x, x) else: mi, ma = line if mi > x: d2[xy] = (x, ma) elif ma < x: d2[xy] = (mi, x) res = [0] * 9 for x, y in l: tot = 0 mi, ma = v[x] if mi < y: tot += 1 if y < ma: tot += 1 for mi, ma in h[y], d1[x + y], d2[x - y + n]: if mi < x: tot += 1 if x < ma: tot += 1 res[tot] += 1 print(*res) if __name__ == '__main__': main() ```
output
1
13,427
15
26,855
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,428
15
26,856
Tags: sortings Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=10**10, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- n,m=list(map(int,input().split())) f=[] maxx=[-999999999]*n minx=[999999999]*n maxy=[-999999999]*n miny=[999999999]*n maxm=[-999999999]*(2*n-1) minm=[999999999]*(2*n-1) maxs=[-999999999]*(2*n-1) mins=[999999999]*(2*n-1) r=[0 for i in range(9)] for i in range(m): y,x=list(map(int,input().split())) a,b,c,d=y-1,x-1,y+x-2,y-x+n-1 f.append((a,b,c,d)) if a>maxx[b]:maxx[b]=a if a<minx[b]:minx[b]=a if x-1>maxy[a]:maxy[a]=x-1 if x-1<miny[a]:miny[a]=x-1 if c>maxs[d]:maxs[d]=c if c<mins[d]:mins[d]=c if d>maxm[c]:maxm[c]=d if d<minm[c]:minm[c]=d for i in f: k=0 if i[0]<maxx[i[1]]:k+=1 if i[0]>minx[i[1]]:k+=1 if i[1]<maxy[i[0]]:k+=1 if i[1]>miny[i[0]]:k+=1 if i[2]<maxs[i[3]]:k+=1 if i[2]>mins[i[3]]:k+=1 if i[3]<maxm[i[2]]:k+=1 if i[3]>minm[i[2]]:k+=1 r[k]+=1 print(*r) ```
output
1
13,428
15
26,857
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,429
15
26,858
Tags: sortings Correct Solution: ``` def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(m)) h = [False] * (n + 1) v = [False] * (n + 1) d1 = [False] * (n * 2 + 1) d2 = [False] * (n * 2 + 1) for x, y in l: line = h[y] if line: mi, ma = line if mi > x: h[y] = (x, ma) elif ma < x: h[y] = (mi, x) else: h[y] = (x, x) line = v[x] if line: mi, ma = line if mi > y: v[x] = (y, ma) elif ma < y: v[x] = (mi, y) else: v[x] = (y, y) xy = x + y line = d1[xy] if line: mi, ma = line if mi > x: d1[xy] = (x, ma) elif ma < x: d1[xy] = (mi, x) else: d1[xy] = (x, x) xy = x - y + n line = d2[xy] if line: mi, ma = line if mi > x: d2[xy] = (x, ma) elif ma < x: d2[xy] = (mi, x) else: d2[xy] = (x, x) res = [0] * 9 for x, y in l: tot = 0 mi, ma = v[x] if mi < y: tot += 1 if y < ma: tot += 1 for mi, ma in h[y], d1[x + y], d2[x - y + n]: if mi < x: tot += 1 if x < ma: tot += 1 res[tot] += 1 print(*res) if __name__ == '__main__': main() ```
output
1
13,429
15
26,859
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,430
15
26,860
Tags: sortings Correct Solution: ``` def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(m)) h = [False] * (n + 1) v = [False] * (n + 1) d1 = [False] * (n * 2 + 1) d2 = [False] * (n * 2 + 1) for x, y in l: line = h[y] if line: mi, ma = line if mi > x: line[0] = x elif ma < x: line[1] = x else: h[y] = [x, x] line = v[x] if line: mi, ma = line if mi > y: line[0] = y elif ma < y: line[1] = y else: v[x] = [y, y] xy = x + y line = d1[xy] if line: mi, ma = line if mi > x: line[0] = x elif ma < x: line[1] = x else: d1[xy] = [x, x] xy = x - y + n line = d2[xy] if line: mi, ma = line if mi > x: line[0] = x elif ma < x: line[1] = x else: d2[xy] = [x, x] res = [0] * 9 for x, y in l: tot = 0 mi, ma = v[x] if mi < y: tot += 1 if y < ma: tot += 1 for mi, ma in h[y], d1[x + y], d2[x - y + n]: if mi < x: tot += 1 if x < ma: tot += 1 res[tot] += 1 print(*res) if __name__ == '__main__': main() ```
output
1
13,430
15
26,861
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,431
15
26,862
Tags: sortings Correct Solution: ``` n,m=list(map(int,input().split())) f=[] maxx=[-999999999]*n minx=[999999999]*n maxy=[-999999999]*n miny=[999999999]*n maxm=[-999999999]*(2*n-1) minm=[999999999]*(2*n-1) maxs=[-999999999]*(2*n-1) mins=[999999999]*(2*n-1) r=[0 for i in range(9)] for i in range(m): y,x=list(map(int,input().split())) a,b,c,d=y-1,x-1,y+x-2,y-x+n-1 f.append((a,b,c,d)) if a>maxx[b]:maxx[b]=a if a<minx[b]:minx[b]=a if x-1>maxy[a]:maxy[a]=x-1 if x-1<miny[a]:miny[a]=x-1 if c>maxs[d]:maxs[d]=c if c<mins[d]:mins[d]=c if d>maxm[c]:maxm[c]=d if d<minm[c]:minm[c]=d for i in f: k=0 if i[0]<maxx[i[1]]:k+=1 if i[0]>minx[i[1]]:k+=1 if i[1]<maxy[i[0]]:k+=1 if i[1]>miny[i[0]]:k+=1 if i[2]<maxs[i[3]]:k+=1 if i[2]>mins[i[3]]:k+=1 if i[3]<maxm[i[2]]:k+=1 if i[3]>minm[i[2]]:k+=1 r[k]+=1 print(*r) ```
output
1
13,431
15
26,863
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,432
15
26,864
Tags: sortings Correct Solution: ``` n, m = map(int, input().split()) k = 2 * n + 1 t = [[0] * k for i in range(8)] p, r = [0] * m, [0] * 9 for k in range(m): x, y = map(int, input().split()) a, b = n + y - x, y + x p[k] = (x, y) if t[0][x]: t[0][x], t[4][x] = min(t[0][x], y), max(t[4][x], y) else: t[0][x] = t[4][x] = y if t[1][y]: t[1][y], t[5][y] = min(t[1][y], x), max(t[5][y], x) else: t[1][y] = t[5][y] = x if t[2][a]: t[2][a], t[6][a] = min(t[2][a], x), max(t[6][a], x) else: t[2][a] = t[6][a] = x if t[3][b]: t[3][b], t[7][b] = min(t[3][b], x), max(t[7][b], x) else: t[3][b] = t[7][b] = x for x, y in p: a, b = n + y - x, y + x s = (t[0][x] == y) + (t[4][x] == y) \ + (t[1][y] == x) + (t[5][y] == x) \ + (t[2][a] == x) + (t[6][a] == x) \ + (t[3][b] == x) + (t[7][b] == x) r[8 - s] += 1 print(' '.join(map(str, r))) ```
output
1
13,432
15
26,865
Provide tags and a correct Python 3 solution for this coding contest problem. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0
instruction
0
13,433
15
26,866
Tags: sortings Correct Solution: ``` n,m=list(map(int,input().split())) f=[] maxy=[-999999999]*n#y-1 miny=[999999999]*n#y-1 maxx=[-999999999]*n#x-1 minx=[999999999]*n#x-1 maxm=[-999999999]*(2*n-1)#x-y+n-1 minm=[999999999]*(2*n-1)#x-y+n-1 maxs=[-999999999]*(2*n-1)#x+y-2 mins=[999999999]*(2*n-1)#x+y-2 for i in range(m): y,x=list(map(int,input().split())) a,b,c,d=y-1,x-1,x-y+n-1,x+y-2 f.append((a,x-1,x-y+n-1,x+y-2)) if maxy[a]<b:maxy[a]=b if miny[a]>b:miny[a]=b if maxx[b]<a:maxx[b]=a if minx[b]>a:minx[b]=a if maxm[c]<d:maxm[c]=d if minm[c]>d:minm[c]=d if maxs[d]<c:maxs[d]=c if mins[d]>c:mins[d]=c r=[0]*9 for e in f: k=0 if maxy[e[0]]>e[1]:k+=1 if miny[e[0]]<e[1]:k+=1 if maxx[e[1]]>e[0]:k+=1 if minx[e[1]]<e[0]:k+=1 if maxm[e[2]]>e[3]:k+=1 if minm[e[2]]<e[3]:k+=1 if maxs[e[3]]>e[2]:k+=1 if mins[e[3]]<e[2]:k+=1 r[k]+=1 print(*r) ```
output
1
13,433
15
26,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0 Submitted Solution: ``` n,m=list(map(int,input().split())) kol,fig,dos=[0,0,0,0,0,0,0,0,0],[],[[0]*n for i in range(n)] for i in range(m): x,y=list(map(int,input().split())) fig.append([x,y]) dos[y-1][x-1]=2 def pr(x,y,v): a,b=x-1,y-1 for i in range(x,n): if dos[b][i]==2:v+=1;break for i in range(0,x-1): if dos[b][i]==2:v+=1;break for i in range(y,n): if dos[i][a]==2:v+=1;break for i in range(0,b): if dos[i][a]==2:v+=1;break for i in range(1,n): if b+i<n and a+i<n and dos[b+i][a+i]==2:v+=1;break for i in range(1,n): if a+i<n and b-i>=0 and dos[b-i][a+i]==2:v+=1;break for i in range(1,n): if a-1>=0 and b-1>=0 and dos[b-i][a-i]==2:v+=1;break for i in range(1,n): if b+i<n and a-1>=0 and dos[b+i][a-i]==2:v+=1;break kol[v]+=1 for i in fig:pr(i[0],i[1],0) print(*kol) ```
instruction
0
13,434
15
26,868
No
output
1
13,434
15
26,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0 Submitted Solution: ``` import sys def place_compare(a, b): if a[0] < b[0]: return True if a[0] > b[0]: return False return a[1] < b[1] values = [int(x) for x in sys.stdin.readline().split()] dimension, n_queens = values[0], values[1] x_positions, y_positions, additions, subtractions = [], [], [], [] for i in range(n_queens): values = [int(x) for x in sys.stdin.readline().split()] x, y = values[0], values[1] subtractions.append((x - y, i)) additions.append((x + y, i)) x_positions.append((x, i)) y_positions.append((y, i)) additions.sort(key=lambda x:x[0]) subtractions.sort(key=lambda x:x[0]) x_positions.sort(key=lambda x:x[0]) y_positions.sort(key=lambda x:x[0]) print(additions, subtractions, x_positions, y_positions) tallies = [0 for x in range(n_queens)] for cur_list in [additions, subtractions, x_positions, y_positions]: for i in range(n_queens-1): if cur_list[i][0] == cur_list[i+1][0]: tallies[cur_list[i][1]] += 1 tallies[cur_list[i+1][1]] += 1 results = [0 for x in range(9)] for count in tallies: results[count] += 1 for index, result in enumerate(results): sys.stdout.write(str(result) + " ") print("") ```
instruction
0
13,435
15
26,870
No
output
1
13,435
15
26,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0 Submitted Solution: ``` from collections import defaultdict def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(m)) h, v, d1, d2 = (defaultdict(list) for _ in range(4)) for x, y in l: h[y].append(x) v[x].append(y) d1[x + y].append(x) d2[x - y].append(x) map(list.sort, (h, v, d1, d2)) res = [0] * 9 for x, y in l: tot = 0 line = v[x] i = line.index(y) if i: tot += 1 if i < len(line) - 1: tot += 1 for line in h[y], d1[x + y], d2[x - y]: i = line.index(x) if i: tot += 1 if i < len(line) - 1: tot += 1 res[tot] += 1 print(*res) if __name__ == '__main__': main() ```
instruction
0
13,436
15
26,872
No
output
1
13,436
15
26,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n Γ— n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position. For each queen one can count w β€” the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive. Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i. Input The first line of the input contains a pair of integers n, m (1 ≀ n, m ≀ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≀ ri, ci ≀ n) β€” the queen's position. No two queens stand on the same square. Output Print the required sequence t0, t1, ..., t8, separating the numbers with spaces. Examples Input 8 4 4 3 4 8 6 5 1 6 Output 0 3 0 1 0 0 0 0 0 Input 10 3 1 1 1 2 1 3 Output 0 2 1 0 0 0 0 0 0 Submitted Solution: ``` from collections import defaultdict from bisect import bisect_left def main(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(m)) h, v, d1, d2 = (defaultdict(list) for _ in range(4)) for x, y in l: h[y].append(x) v[x].append(y) d1[x + y].append(x) d2[x - y].append(x) map(list.sort, (h, v, d1, d2)) res = [0] * 9 for x, y in l: tot = 0 line = v[x] i = bisect_left(line, y) if i: tot += 1 if i < len(line) - 1: tot += 1 for line in h[y], d1[x + y], d2[x - y]: i = bisect_left(line, x) if i: tot += 1 if i < len(line) - 1: tot += 1 res[tot] += 1 print(*res) if __name__ == '__main__': main() ```
instruction
0
13,437
15
26,874
No
output
1
13,437
15
26,875
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,532
15
27,064
Tags: dp, math Correct Solution: ``` for i in range(int(input())): n,m,k=map(int,input().split()) print('YES' if n*m-1==k else 'NO') ```
output
1
13,532
15
27,065
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,533
15
27,066
Tags: dp, math Correct Solution: ``` t = int(input()) for i in range(t): n,m,k = map(int,input().split()) cost = n*m-1 if cost==k: print('YES') else: print('NO') ```
output
1
13,533
15
27,067
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,534
15
27,068
Tags: dp, math Correct Solution: ``` t = int(input()) for _ in range(t): n,m,k = map(int, input().split()) c = (m-1) + (m*(n-1)) if c==k: print("YES") else: print("NO") ```
output
1
13,534
15
27,069
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,535
15
27,070
Tags: dp, math Correct Solution: ``` for i in range(int(input())): x, y, d = [int(x) for x in input().split()] if d == x-1 + x * (y - 1): print("Yes") else: print("No") ```
output
1
13,535
15
27,071
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,536
15
27,072
Tags: dp, math Correct Solution: ``` t=int(input()) while(t): t=t-1 n, m, k = map(int, input().split(' ')) i,j = 1, 1 b = True c=0 while(i!=n or j!=m): if b: if j!=m: j=j+1 c+=i b = False if not b: if i!=n: i=i+1 c+=j b=True if c==k: print("YES") else: print("NO") ```
output
1
13,536
15
27,073
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,537
15
27,074
Tags: dp, math Correct Solution: ``` from collections import defaultdict d = defaultdict(lambda: 0) def check(a,b): ans=a ans+=(b*(a+1)) return ans for i in range(int(input())): n,m,k = map(int, input().split()) rx=n-1 ry=m-1 a=check(rx,ry) b=check(ry,rx) if a==k or b==k: print("YES") else: print("NO") ```
output
1
13,537
15
27,075
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,538
15
27,076
Tags: dp, math Correct Solution: ``` def arrIn(): return list(map(int,input().split())) def mapIn(): return map(int,input().split()) for ii in range(int(input())): n,m,k=mapIn() ans=n-1+n*(m-1) if(ans==k):print("YES") else : print("NO") ```
output
1
13,538
15
27,077
Provide tags and a correct Python 3 solution for this coding contest problem. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles.
instruction
0
13,539
15
27,078
Tags: dp, math Correct Solution: ``` for i in range(int(input())): x,y,z=map(int,input().split()) if x*y-1==z: print('YES') else: print('NO') ```
output
1
13,539
15
27,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` from sys import stdin input = stdin.readline from heapq import heapify,heappush,heappop,heappushpop from collections import defaultdict as dd, deque as dq,Counter as C from math import factorial as f ,ceil,gcd,sqrt,log from bisect import bisect_left as bl ,bisect_right as br from itertools import combinations as c,permutations as p from math import factorial as f ,ceil,gcd,sqrt,log mi = lambda : map(int,input().split()) ii = lambda: int(input()) li = lambda : list(map(int,input().split())) mati = lambda r : [ li() for _ in range(r)] lcm = lambda a,b : (a*b)//gcd(a,b) def solve(): n,m,k=mi() s=min(n-1+n*(m-1),m-1+m*n) #print(s) if s==k: print("YES") else: print("NO") for _ in range(ii()): solve() ```
instruction
0
13,540
15
27,080
Yes
output
1
13,540
15
27,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` t=int(input()) while t>0: lst=input() n, m, k=lst.split(" ") n=int(n) m=int(m) k=int(k) if n*m-1==k: print("YES") else: print("NO") t-=1 ```
instruction
0
13,541
15
27,082
Yes
output
1
13,541
15
27,083
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` T = int(input()) for _ in range(T): N,M,K = map(int,input().split()) k = N-1 + (M-1)*N print('YES' if k==K else 'NO') ```
instruction
0
13,542
15
27,084
Yes
output
1
13,542
15
27,085
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` a=int(input()) for i in range(0,a): r,b,d=map(int, input().split()) if(r*b)-1==d: print("YES") else: print("NO") ```
instruction
0
13,543
15
27,086
Yes
output
1
13,543
15
27,087
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` """ -> Author : Om Anshuman # -> About : IT Fresher # -> Insti : VIT, Vellore # -> Created : 28.04.2021 # """ """ from sys import stdin, stdout import math from functools import reduce import statistics import numpy as np import itertools import sys """ def prog_name(): n,m,k = map(int,input().split()) if n==1 and m==1 : print("YES") else: cost = min(n,m)-1 if cost+((max(n,m)-1)*(cost+1))==k: print("YES") else: print("NO") t = int(input()) for unique in range(t): prog_name() ```
instruction
0
13,544
15
27,088
No
output
1
13,544
15
27,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` for i in range(int(input())) : a = input().split(" ") m = int(a[0]) n = int(a[1]) k = int(a[2]) if k>=m+n : print("YES") else : print("NO") ```
instruction
0
13,545
15
27,090
No
output
1
13,545
15
27,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` a = int(input()) for i in range(6): n,m,k = [int(i) for i in input().split()] if (n*m-1) == k:print('Yes') else:print('No') #(1,1) #(2,2) => (1,1+1) -> 1 burles, (1+1,1) -> 1 burles 2 burles ```
instruction
0
13,546
15
27,092
No
output
1
13,546
15
27,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a n Γ— m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) β€” it costs x burles; * move down to the cell (x + 1, y) β€” it costs y burles. Can you reach cell (n, m) spending exactly k burles? Input The first line contains the single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first and only line of each test case contains three integers n, m, and k (1 ≀ n, m ≀ 100; 0 ≀ k ≀ 10^4) β€” the sizes of grid and the exact amount of money you need to spend. Output For each test case, if you can reach cell (n, m) spending exactly k burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer). Example Input 6 1 1 0 2 2 2 2 2 3 2 2 4 1 4 3 100 100 10000 Output YES NO YES NO YES NO Note In the first test case, you are already in the final cell, so you spend 0 burles. In the second, third and fourth test cases, there are two paths from (1, 1) to (2, 2): (1, 1) β†’ (1, 2) β†’ (2, 2) or (1, 1) β†’ (2, 1) β†’ (2, 2). Both costs 1 + 2 = 3 burles, so it's the only amount of money you can spend. In the fifth test case, there is the only way from (1, 1) to (1, 4) and it costs 1 + 1 + 1 = 3 burles. Submitted Solution: ``` #!/usr/bin/env python3 import os from sys import stdin def solve(tc): n, m, k = map(int, stdin.readline().split()) if n == 1 or m == 1: if k == (n-1)+(m-1): print("YES") else: print("NO") return check = 0 for i in range(1, n): check += i for j in range(1, m): check += n if k == check: print("YES") else: print("NO") tcs = 1 tcs = int(stdin.readline().strip()) tc = 1 while tc <= tcs: solve(tc) tc += 1 ```
instruction
0
13,547
15
27,094
No
output
1
13,547
15
27,095
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,583
15
27,166
Tags: dfs and similar, dsu, graphs Correct Solution: ``` import math,sys,bisect,heapq,os from collections import defaultdict,Counter,deque from itertools import groupby,accumulate from functools import lru_cache #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 def input(): return sys.stdin.readline().rstrip('\r\n') #input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ aj = lambda: list(map(int, input().split())) def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) def solve(): G = defaultdict(list) def addEdge(a,b): G[a].append(b) G[b].append(a) def dfs(node): d = deque() d.append(node) vis[node] = True ind = [];t = [] while d: x = d.pop() ind.append(x) t.append(A[x]) for i in G.get(x,[]): if not vis[i]: vis[i] = True d.append(i) ind.sort(reverse = True) t.sort(reverse = True) while t: Ans[ind.pop()] = t.pop() n, =aj() vis = [False]*(n+1) A = aj() B = aj() for i in range(n): p = B[i] if i - p >= 0: addEdge(i-p,i) if i + p < n: addEdge(i,i+p) Ans = [-1]*n for i in range(n): if not vis[i]: dfs(i) Y(Ans == sorted(Ans)) try: #os.system("online_judge.py") sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass solve() ```
output
1
13,583
15
27,167
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,584
15
27,168
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n = int(input()) data = list(map(int, input().split())) spans = list(map(int, input().split())) connect = [[False for c in range(n)] for r in range(n)] for p, span in enumerate(spans): for r in [p-span, p+span]: if r >= 0 and r < n: connect[p][r] = connect[r][p] = True def visit(data, connect, seen, group, i): if not seen[i]: seen[i] = True group.append((i, data[i])) for j in range(n): if connect[i][j]: visit(data, connect, seen, group, j) seen = [False for i in range(n)] for i in range(n): group = [] visit(data, connect, seen, group, i) group.sort() #print() #print(group) values = sorted([value for (index, value) in group]) #print(values) for i, value in enumerate(values): data[group[i][0]] = value #print(data) if data == list(range(1, n+1)): print('YES') else: print('NO') ```
output
1
13,584
15
27,169
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,585
15
27,170
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n=int(input()) a=list(map(lambda x:int(x),input().split())) fav=list(map(lambda x:int(x),input().split())) class DisjSet: def __init__(self, n): # Constructor to create and # initialize sets of n items self.rank = [1] * n self.parent = [i for i in range(n)] self.extra = [] # Finds set of given item x def find(self, x): # Finds the representative of the set # that x is an element of if (self.parent[x] != x): # if x is not the parent of itself # Then x is not the representative of # its set, self.parent[x] = self.find(self.parent[x]) # so we recursively call Find on its parent # and move i's node directly under the # representative of this set return self.parent[x] # Do union of two sets represented # by x and y. def Union(self, x, y): # Find current sets of x and y xset = self.find(x) yset = self.find(y) # If they are already in same set if xset == yset: self.extra.append((x, y)) return # Put smaller ranked item under # bigger ranked item if ranks are # different if self.rank[xset] < self.rank[yset]: self.parent[xset] = yset elif self.rank[xset] > self.rank[yset]: self.parent[yset] = xset # If ranks are same, then move y under # x (doesn't matter which one goes where) # and increment rank of x's tree else: self.parent[yset] = xset self.rank[xset] = self.rank[xset] + 1 obj=DisjSet(n) for i in range(0,n): d=fav[i] if i-d>=0: obj.Union(i,i-d) if i+d<=n-1: obj.Union(i, i + d) hashmap={} for i in range(n): temp=obj.find(i) if temp not in hashmap: hashmap[temp]=set() hashmap[temp].add(i) flag=1 for i in range(n): temp=obj.find(i) if a[i]-1 not in hashmap[temp]: flag=0 break # print(hashmap) if flag==0: print("NO") else: print("YES") ```
output
1
13,585
15
27,171
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,586
15
27,172
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n=int(input()) b=list(map(int,input().split())) c=list(map(int,input().split())) d=[[] for i in range(n+1)] for i in range(n): p=(i+1)-c[i] q=(i+1)+c[i] if p<=0 and q<=n: d[i+1].append(q) d[q].append(i+1) elif p > 0 and q > n: d[i + 1].append(p) d[p].append(i + 1) elif p>0 and q<=n: d[i + 1].append(p) d[p].append(i + 1) d[i + 1].append(q) d[q].append(i + 1) v=[0]*(n+1) j=1 k=0 while(j<=n): if v[j]!=1: f=[0]*(n+1) s=[j] r=[] while(s): m=s.pop() r.append(m) v[m]=1 f[b[m-1]]=1 for i in d[m]: if v[i]==0: s.append(i) for p in r: if f[p]==0: k=1 break if k==1: break j+=1 if k==0: print("YES") else: print('NO') ```
output
1
13,586
15
27,173
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,587
15
27,174
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n=int(input()) orden= input().split() fav= input().split() arr=[] for i in range(n): orden[i]=int(orden[i]) fav[i]=int(fav[i]) arr.append(i) def union(el): if arr[el] != el: arr[el] = union(arr[el]) return arr[el] cont=0 for i in fav: if cont >= i: arr[union(cont)] = union(cont - i) if cont < n - i: arr[union(cont)] = union(cont + i) cont += 1 flag = True for i in range(n): if union(arr[i])==union(orden[i]-1): continue else: flag = False if flag: print("YES") else: print("NO") ```
output
1
13,587
15
27,175
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,588
15
27,176
Tags: dfs and similar, dsu, graphs Correct Solution: ``` def dsu(nodo): if nueva[nodo] != nodo: nueva[nodo] = dsu(nueva[nodo]) return nueva[nodo] else: return nodo def main(): n = int(input()) permutaciones = list(map(int, input().split())) favoritos = list(map(int, input().split())) l = [] for i in range(n): l.append(i) #lista sol global nueva nueva = l.copy() #print(permutaciones) #print(favoritos) #print(l) #print(nueva) for i in l: #nueva[dsu(i)] = dsu(abs(i - favoritos[i])) if (i - favoritos[i] >= 0): nueva[dsu(i)] = dsu(abs(i - favoritos[i])) if (i + favoritos[i] < n): nueva[dsu(i)] = dsu(i + favoritos[i]) for i in l: if dsu(i) != dsu(permutaciones[i]-1): print("NO") return print("YES") return main() ```
output
1
13,588
15
27,177
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,589
15
27,178
Tags: dfs and similar, dsu, graphs Correct Solution: ``` arr_size = int( input()) arr_fin = input().split(" ") arr_fin = map(int, arr_fin) cell_fav = input().split(" ") cell_fav = map(int, cell_fav) graph = {} # A este array le voy a aplicar DSU arr_ini = [i for i in range(1,arr_size+1)] for fav, i in zip(cell_fav, arr_ini): graph[i] = [i] if(i-fav > 0): graph[i].append(abs(fav-i)) if(fav+i <= arr_size): graph[i].append(fav+i) dsu_arr = arr_ini[::] for i in range(0,10): for key in graph: min_node = [key] for node in graph[key]: min_node.append(dsu_arr[node-1]) min_node = min(min_node) for node in graph[key]: dsu_arr[node-1] = min_node # if(arr_size == 71): # #print(graph) # #print(dsu_arr) cont = 0 flag = True for cell in arr_fin: if(dsu_arr[cell-1] != dsu_arr[cont]): print("NO") flag = False break cont += 1 if(flag): print("YES") ```
output
1
13,589
15
27,179
Provide tags and a correct Python 3 solution for this coding contest problem. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES
instruction
0
13,590
15
27,180
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n, p, d = int(input()), [x - 1 for x in list(map(int, input().split()))], list(map(int, input().split())) g = [[False] * n for _ in range(n)] for i in range(n): g[i][i] = True if i - d[i] >= 0: g[i][i - d[i]] = g[i - d[i]][i] = True if i + d[i] < n: g[i][i + d[i]] = g[i + d[i]][i] = True for k in range(n): for i in range(n): for j in range(n): g[i][j] |= g[i][k] & g[k][j] ans = True for i in range(n): ans &= g[i][p[i]] print("YES" if ans else "NO") # Made By Mostafa_Khaled ```
output
1
13,590
15
27,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` n = int(input()) l = list(map(lambda x: int(x) - 1, input().split())) f = list(map(int, input().split())) class UnionFind: def __init__(self, n): self.parent = list(range(n)) def find(self, a): acopy = a while a != self.parent[a]: a = self.parent[a] while acopy != a: self.parent[acopy], acopy = a, self.parent[acopy] return a def union(self, a, b): self.parent[self.find(b)] = self.find(a) UF = UnionFind(n) for i in range(n): if 0 <= i - f[i]: UF.union(i, i - f[i]) if i + f[i] < n: UF.union(i, i + f[i]) works = True for i in range(n): if UF.find(i) == UF.find(l[i]): pass else: works = False break if works: print('YES') else: print('NO') ```
instruction
0
13,591
15
27,182
Yes
output
1
13,591
15
27,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` n=int(input()) perm=list(map(int,input().split())) fav=list(map(int,input().split())) adj=[[] for i in range(n+1)] for i in range(1,n+1): if (i-fav[i-1]) in range(1,n+1): adj[i].append(i-fav[i-1]) adj[i-fav[i-1]].append(i) if (i+fav[i-1]) in range(1,n+1): adj[i].append(i+fav[i-1]) adj[i+fav[i-1]].append(i) for i in range(n): q=[perm[i]];vis=[True]*(n+1) vis[perm[i]]=False;flag=0 if perm[i]==i+1:flag=1 while len(q)!=0: r=q.pop() for j in adj[r]: if vis[j]: vis[j]=False q.append(j) if i+1==j: flag=1;break if flag==1:break if flag==0: exit(print('NO')) print('YES') ```
instruction
0
13,592
15
27,184
Yes
output
1
13,592
15
27,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` f = lambda: list(map(int, input().split())) n, p, d = f()[0], f(), f() c = list(range(n)) def g(x): if c[x] != x: c[x] = g(c[x]) return c[x] for x, k in enumerate(d): if x >= k: c[g(x)] = g(x - k) if x < n - k: c[g(x)] = g(x + k) print('YES' if all(g(x) == g(y - 1) for x, y in zip(c, p)) else 'NO') ```
instruction
0
13,593
15
27,186
Yes
output
1
13,593
15
27,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## def prime_factors(x): s=set() n=x i=2 while i*i<=n: if n%i==0: while n%i==0: n//=i s.add(i) i+=1 if n>1: s.add(n) return s from collections import Counter # c=sorted((i,int(val))for i,val in enumerate(input().split())) import heapq # c=sorted((i,int(val))for i,val in enumerate(input().split())) # n = int(input()) #g=[[] for i in range(n+1)] #arr=list(map(int, input().split())) # ls = list(map(int, input().split())) # n, k = map(int, input().split()) # n =int(input()) #arr=[(i,x) for i,x in enum] #arr.sort(key=lambda x:x[0]) #print(arr) #import math # e=list(map(int, input().split())) from collections import Counter #print("\n".join(ls)) #print(os.path.commonprefix(ls[0:2])) #n=int(input()) from bisect import bisect_right #d=sorted(d,key=lambda x:(len(d[x]),-x)) d=dictionary d={x:set() for x in arr} #n=int(input()) #n,m,k= map(int, input().split()) import heapq #for _ in range(int(input())): #n,k=map(int, input().split()) #input=sys.stdin.buffer.readline #for _ in range(int(input())): #arr = list(map(int, input().split()))import bisect def par(x): if root[x]!=x: return par(root[x]) else: return x def max_edge(n): return n*(n-1)//2 def union(u,v): x=par(u) y=par(v) if x!=y: if rank[x]>=rank[y]: root[y]=root[x] rank[x]+=rank[y] elif rank[y]>rank[x]: root[x]=root[y] rank[y]+=rank[x] #n,m= map(int, input().split()) n = int(input()) root=[i for i in range(n+1)] rank=[1]*(n+1) arr = list(map(int, input().split())) move= list(map(int, input().split())) p=[i+1 for i in range(n)] for i in range(n): if i+move[i]<n: union(i,i+move[i]) if i-move[i]>=0: union(i,i-move[i]) for i in range(n): if par(arr[i]-1)!=par(i): print("NO") break else: print("YES") ```
instruction
0
13,594
15
27,188
Yes
output
1
13,594
15
27,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` n=int(input()) from collections import defaultdict d=defaultdict(list) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] for i in range(n): x=b[i] if i-x>=0: d[i].append(i-x) d[i-x].append(i) if i+x<n: d[i].append(i+x) d[i+x].append(i) #print(d) f=1 for i in range(0,n): loc=0 q=[i] vis=[0]*n vis[i]=1 while q: t=q.pop() # print(t) if a[t]==a[i]: loc=1 for z in d[t]: if not vis[z]: vis[z]=1 q.append(z) if loc==0: # print(i) f=0 if f: print('YES') else: print('NO') ```
instruction
0
13,595
15
27,190
No
output
1
13,595
15
27,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` arr_size = int( input()) arr_fin = input().split(" ") arr_fin = map(int, arr_fin) cell_fav = input().split(" ") cell_fav = map(int, cell_fav) graph = {} # A este array le voy a aplicar DSU arr_ini = [i for i in range(1,arr_size+1)] for fav, i in zip(cell_fav, arr_ini): graph[i] = [i] if(i-fav > 0): graph[i].append(abs(fav-i)) if(fav+i <= arr_size): graph[i].append(fav+i) #print(graph) dsu_arr = arr_ini[::] for key in graph: min_node = [key] for node in graph[key]: min_node.append(dsu_arr[node-1]) min_node = min(min_node) for node in graph[key]: dsu_arr[node-1] = min_node #print(dsu_arr) cont = 0 flag = True for cell in arr_fin: if(dsu_arr[cell-1] != dsu_arr[cont]): print("NO") flag = False break cont += 1 if(flag): print("YES") ```
instruction
0
13,596
15
27,192
No
output
1
13,596
15
27,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` n=int(input()) from collections import defaultdict d=defaultdict(list) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] for i in range(n): x=b[i] if i-x>=0: d[i].append(i-x) d[i-x].append(i) if i+x<n: d[i].append(i+x) d[i+x].append(i) for i in range(n): d[i].append(i) #print(d) f=1 for i in range(0,n): loc=0 q=[i] vis=[0]*n vis[i]=1 while q: t=q.pop() # print(t) if a[t]==b[i]: loc=1 for i in d[t]: if not vis[i]: vis[i]=1 q.append(i) if loc==0: # print(i) f=0 if f: print('YES') else: print('NO') ```
instruction
0
13,597
15
27,194
No
output
1
13,597
15
27,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited. The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state. Input The first line contains positive integer n (1 ≀ n ≀ 100) β€” the number of cells in the array. The second line contains n distinct integers from 1 to n β€” permutation. The last line contains n integers from 1 to n β€” favourite numbers of the cells. Output If the given state is reachable in the described game, output YES, otherwise NO. Examples Input 5 5 4 3 2 1 1 1 1 1 1 Output YES Input 7 4 3 5 1 2 7 6 4 6 6 1 6 6 1 Output NO Input 7 4 2 5 1 3 7 6 4 6 6 1 6 6 1 Output YES Submitted Solution: ``` f = lambda: list(map(int, input().split())) n, p, d = f()[0], f(), f() c = list(range(n)) def g(x): if c[x] != x: c[x] = g(c[x]) return c[x] for x, k in zip(c, d): if x >= k: c[g(x)] = g(x - k) if x < n - k: c[g(x)] = g(x + k) print('YES' if all(g(x) == g(y - 1) for x, y in zip(c, p)) else 'NO') ```
instruction
0
13,598
15
27,196
No
output
1
13,598
15
27,197