message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. Let's call matrix A clear if no two cells containing ones have a common side. Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i, j) (1 ≤ i, j ≤ n) both of the following conditions must be met: Ai, j = An - i + 1, j and Ai, j = Ai, n - j + 1. Let's define the sharpness of matrix A as the number of ones in it. Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x. Input The only line contains a single integer x (1 ≤ x ≤ 100) — the required sharpness of the matrix. Output Print a single number — the sought value of n. Examples Input 4 Output 3 Input 9 Output 5 Note The figure below shows the matrices that correspond to the samples: <image> Submitted Solution: ``` # your code goes here def cnt(x): ret = (x+1)//2 ret = ret+ret ret = ret+ret+1 a = 0 sum = 0 for i in range(0, x): sum = sum + (x+a)//2 a = 1-a return ret+4*sum N = int(input()) for i in range(0, 100): #print(cnt(i)) if cnt(i) >= N: print(i+i+1) break ```
instruction
0
7,841
23
15,682
No
output
1
7,841
23
15,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. Let's call matrix A clear if no two cells containing ones have a common side. Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i, j) (1 ≤ i, j ≤ n) both of the following conditions must be met: Ai, j = An - i + 1, j and Ai, j = Ai, n - j + 1. Let's define the sharpness of matrix A as the number of ones in it. Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x. Input The only line contains a single integer x (1 ≤ x ≤ 100) — the required sharpness of the matrix. Output Print a single number — the sought value of n. Examples Input 4 Output 3 Input 9 Output 5 Note The figure below shows the matrices that correspond to the samples: <image> Submitted Solution: ``` def Solve(n): if(n%2==1): return (n//2)*n+(n//2+1) x=(n-2)//2 if(x%2==1): return Solve(x)*4 else: return (x//2)*x*4 L=[0,1,0] for i in range(3,1000): L.append(Solve(i)) x=int(input()) if(x==2): print(5) else: for i in range(1,1000): if(x<=L[i] and i%2==1 and ((i-1)//2)%2==1): print(i) break if(x<=L[i] and i%2==1 and (L[i]-x)!=1): print(i) break if(x<=L[i] and i%2==0 and (L[i]-x)%4==0): print(i) break ```
instruction
0
7,842
23
15,684
No
output
1
7,842
23
15,685
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,853
23
15,706
Tags: geometry, implementation, math Correct Solution: ``` import sys def read(): tokens = sys.stdin.readline().strip().split() return int(tokens[0]), int(tokens[1]) n,m=read() p,q=read() x=[] y=[] r=1 for i in range(0,n*2): if (i<n): tx,ty=read() x.append(tx) y.append(ty) else: x.append(x[i-n]) y.append(y[i-n]) m%=n*2 for i in range(0,m): p=2*x[i]-p q=2*y[i]-q print (p,q) ''' (x,y) (ax,ay) (ax*2-x,ay*2-y) (x,y,1)(-1 0 0 0 -1 0 ax*2 ay*2 1) ''' ```
output
1
7,853
23
15,707
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,854
23
15,708
Tags: geometry, implementation, math Correct Solution: ``` n, k = map(int, input().split()) ax = [] ay = [] mx, my = map(int, input().split()) for i in range(n): x, y = map(int, input().split()) ax.append(x) ay.append(y) k %= 2*n for i in range(k): mx = 2*ax[i % n] - mx my = 2*ay[i % n] - my print(mx, " ", my) ```
output
1
7,854
23
15,709
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,855
23
15,710
Tags: geometry, implementation, math Correct Solution: ``` n, j = map(int, input().split()) x, y = map(int, input().split()) dx, dy = n * [ None ], n * [ None ] for i in range(n): dx[i], dy[i] = map(lambda s: 2 * int(s), input().split()) j %= 2 * n pos = 0 if j % 2 == 0: sign = -1 else: sign = 1 x, y = -x, -y for i in range(j): x += sign * dx[pos] y += sign * dy[pos] sign = -sign pos += 1 if pos == n: pos = 0 print(x, y) # Made By Mostafa_Khaled ```
output
1
7,855
23
15,711
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,856
23
15,712
Tags: geometry, implementation, math Correct Solution: ``` import sys def read(): tokens = sys.stdin.readline().strip().split() return int(tokens[0]), int(tokens[1]) n, j = read() m0_x, m0_y = read() ax, ay = [], [] for i in range(n): ax_, ay_ = read() ax.append(ax_) ay.append(ay_) mult = j // n j = (j % n) if mult % 2 == 0 else (n + (j % n)) px, py = -m0_x, -m0_y for i in range(j): if i % 2 == 0: px += ax[i % n] * 2 py += ay[i % n] * 2 else: px -= ax[i % n] * 2 py -= ay[i % n] * 2 if j % 2 == 0: px, py = -px, -py print(px, py) ```
output
1
7,856
23
15,713
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,857
23
15,714
Tags: geometry, implementation, math Correct Solution: ``` #codeforces 24c sequence of points, math """import sys sys.stdin=open("24c.in",mode='r',encoding='utf-8') """ def readGen(transform): while (True): n=0 tmp=input().split() m=len(tmp) while (n<m): yield(transform(tmp[n])) n+=1 readint=readGen(int) n,j=next(readint),next(readint) j%=2*n x0,y0=next(readint),next(readint) a=tuple((next(readint),next(readint)) for i in range(n)) #a=[[next(readint),next(readint)] for i in range(n)] for i in range(1,j+1): x0=2*a[(i-1)%n][0]-x0 y0=2*a[(i-1)%n][1]-y0 print(x0,y0) #sys.stdin.close() ```
output
1
7,857
23
15,715
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,858
23
15,716
Tags: geometry, implementation, math Correct Solution: ``` n, j = map(int, input().split()) m = list(map(int, input().split())) points = [] for _ in range(n): points += [tuple(map(int, input().split()))] trans = [0, 0] points = points + points for i in range(0, len(points), 2): trans[0] += - 2 * points[i][0] + 2 * points[i + 1][0] trans[1] += - 2 * points[i][1] + 2 * points[i + 1][1] m = [m[0] + trans[0] * (j // (2 * n)), m[1] + trans[1] * (j // (2 * n))] j %= (2 * n) for i in range(j): m = [2 * points[i][0] - m[0], 2 * points[i][1] - m[1]] print(m[0], m[1]) ```
output
1
7,858
23
15,717
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,859
23
15,718
Tags: geometry, implementation, math Correct Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code # MOD = 998244353 # def pow(base , exp): # if exp == -1: # return pow(base , MOD - 2) # res = 1 # base %= MOD # while exp > 0: # if exp % 2: # res = (res * base) % MOD # exp //= 2 # base = (base * base) % MOD # res %= MOD # return res def main(): n , j = map(int , input().split()) j = j % (2 * n) mx , my = map(int , input().split()) pntx = [] pnty = [] for i in range(n): a,b = map(int , input().split()) pntx.append(a) pnty.append(b) for i in range(j): k = i % n mx = 2 * pntx[k] - mx my = 2 * pnty[k] - my print(mx , my) return if __name__ == "__main__": main() ```
output
1
7,859
23
15,719
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995
instruction
0
7,860
23
15,720
Tags: geometry, implementation, math Correct Solution: ``` n, j = map(int, input().split()) x, y = map(int, input().split()) dx, dy = n * [ None ], n * [ None ] for i in range(n): dx[i], dy[i] = map(lambda s: 2 * int(s), input().split()) j %= 2 * n pos = 0 if j % 2 == 0: sign = -1 else: sign = 1 x, y = -x, -y for i in range(j): x += sign * dx[pos] y += sign * dy[pos] sign = -sign pos += 1 if pos == n: pos = 0 print(x, y) ```
output
1
7,860
23
15,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995 Submitted Solution: ``` def read(): return map(int, input().split()) n, j = read() mx, my = read() cycles = j // n rest = j - cycles * n tx = ty = 0 rx = ry = 0 for i in range(n): cx, cy = read() tx = 2 * cx - tx ty = 2 * cy - ty if i < rest: rx = 2 * cx - rx ry = 2 * cy - ry resx = resy = 0 if n % 2 == 0: resx = tx * cycles + mx resy = ty * cycles + my else: if cycles % 2 == 0: resx, resy = mx, my else: resx = tx - mx resy = ty - my if rest % 2 == 0: resx += rx resy += ry else: resx = rx - resx resy = ry - resy print (resx, resy) ```
instruction
0
7,861
23
15,722
Yes
output
1
7,861
23
15,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj. Input On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000. Output On a single line output the coordinates of Mj, space separated. Examples Input 3 4 0 0 1 1 2 3 -5 3 Output 14 0 Input 3 1 5 5 1000 1000 -1000 1000 3 100 Output 1995 1995 Submitted Solution: ``` def mul(a,b): c=[[0,0,0],[0,0,0],[0,0,0]] for i in range(0,3): for j in range(0,3): c[i][j]=0 for k in range(0,3): c[i][j]+=a[i][k]*b[k][j] return c str=input().split() n=int(str[0]) m=int(str[1]) str=input().split() p=int(str[0]) q=int(str[1]) r=1 matrix=[] square=[[-1,0,0],[0,-1,0],[0,0,1]] one=[[1,0,0],[0,1,0],[0,0,1]] all=one for i in range(0,n): str=input().split() now=square now[2][0]=int(str[0])*2 now[2][1]=int(str[1])*2 #print(now[2][0],now[2][1]) matrix.append((tuple(now[0]),tuple(now[1]),tuple(now[2]))) '''print (matrix[i]) if i: for u in range(0,3): print (matrix[i-1][u][0],matrix[i-1][u][1],matrix[i-1][u][2]) print ('???')''' all=mul(all,now) tmp=m//n ans=one while tmp>0: if tmp and 1: ans=mul(ans,all) all=mul(all,all) tmp=tmp//2 now=ans p,q,r=p*now[0][0]+q*now[1][0]+r*now[2][0],q*now[1][1]+r*now[2][1],r #print (p,q) tmp=m%n '''for i in range(0,n): now=matrix[i] for u in range(0,3): print (now[u][0],now[u][1],now[u][2]) print ('!!!')''' for i in range(0,tmp): #print (i) now=matrix[i] '''for u in range(0,3): for v in range(0,3): print(now[u][v])''' p,q,r=p*now[0][0]+q*now[1][0]+r*now[2][0],p*now[0][1]+q*now[1][1]+r*now[2][1],p*now[0][2]+q*now[1][2]+r*now[2][2] print (p,q) ''' (x,y) (ax,ay) (ax*2-x,ay*2-y) (x,y,1)(-1 0 0 0 -1 0 ax*2 ay*2 1) ''' ```
instruction
0
7,862
23
15,724
No
output
1
7,862
23
15,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` #!/usr/bin/env python3 from __future__ import division, print_function def least_significant_bit(i): return ((i) & -(i)) class FenwickTree(): def __init__(self, n): # 1-indexed self.n = n + 1 self.data = [0,] * self.n def add(self, index, value): # 1-indexed i = index + 1 while i < self.n: self.data[i] += value i += least_significant_bit(i) def prefix_sum(self, index): # 1-indexed i = index + 1 result = 0 while i > 0: result += self.data[i] i -= least_significant_bit(i) return result def range_sum(self, start, end): return self.prefix_sum(end) - self.prefix_sum(start-1) def main(): import sys data = iter(map(int, sys.stdin.buffer.read().decode('ascii').split())) n = next(data) left = [0,] * n right = [0,] * n for i in range(n): a, b = next(data), next(data) left[i] = a right[i] = b order = list(range(n)) order.sort(key=lambda x: left[x]) for i, k in enumerate(order): left[k] = i order = list(range(n)) order.sort(key=lambda x:right[x]) res = [0, ] * n ft = FenwickTree(n) for i, k in enumerate(order): a = left[k] res[k] = i - ft.prefix_sum(a-1) ft.add(a, 1) sys.stdout.buffer.write(b'\n'.join(b'%d' % x for x in res)) return 0 if __name__ == '__main__': main() ```
instruction
0
8,001
23
16,002
Yes
output
1
8,001
23
16,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` from sys import stdin input=stdin.readline class BIT(): def __init__(self, n): self.n = n self.tree = [0] * (n + 1) def sum(self, i): ans = 0 i += 1 while i > 0: ans += self.tree[i] i -= (i & (-i)) return ans def update(self, i, value): i += 1 while i <= self.n: self.tree[i] += value i += (i & (-i)) def common(): n = int(input()) left=[0]*(n) right=[0]*(n) for i in range(n): a, b = map(int, input().strip().split()) left[i]=a right[i]=b order=list(range(n)) order=sorted(order,key=lambda s:left[s]) for i in range(n): left[order[i]]=i #chota pehle order = list(range(n)) order = sorted(order, key=lambda s: right[s]) ft=BIT(n) res=[0]*(n) for i,k in enumerate(order): a=left[k] res[k]=i-ft.sum(a-1) #kitne bade lodu isse chote the - kitne chotu lodu ft.update(a,1) print(*res,sep="\n") common() ```
instruction
0
8,002
23
16,004
Yes
output
1
8,002
23
16,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` import sys input=sys.stdin.buffer.readline n=int(input()) l={} r={} ref=[] for i in range(n): x,y=map(int,input().split()) ref.append(x) l[x]=y li=list(l.values()) li.sort() for i in range(n): r[li[i]]=i ke=list(l.keys()) ke.sort() ar=[1]*(n+1) for idx in range(1,n+1): idx2=idx+(idx&(-idx)) if(idx2<n+1): ar[idx2]+=ar[idx] ansdic={} for i in range(n): inp=r[l[ke[i]]]+1 ans=0 while(inp): ans+=ar[inp] inp-=(inp&(-inp)) ansdic[ke[i]]=ans-1 inp=r[l[ke[i]]]+1 add=-1 while(inp<n+1): ar[inp]+=add inp+=(inp&(-inp)) for i in ref: print(ansdic[i]) ```
instruction
0
8,003
23
16,006
Yes
output
1
8,003
23
16,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` from collections import defaultdict,Counter from sys import stdin input=stdin.readline class BIT(): def __init__(self, n): self.n = n self.tree = [0] * (n + 1) def sum(self, i): ans = 0 i += 1 while i > 0: ans += self.tree[i] i -= (i & (-i)) return ans def update(self, i, value): i += 1 while i <= self.n: self.tree[i] += value i += (i & (-i)) def score(t): cnt=Counter(t) return list(cnt.values()).count(2) def year(): dct = defaultdict(list) n = int(input()) left=[0]*(n) right=[0]*(n) for i in range(n): a, b = map(int, input().strip().split()) left[i]=a right[i]=b order=list(range(n)) order=sorted(order,key=lambda s:left[s]) for i in range(n): left[order[i]]=i order = list(range(n)) order = sorted(order, key=lambda s: right[s]) ft=BIT(n) res=[0]*(n) for i,k in enumerate(order): a=left[k] res[k]=i-ft.sum(a-1) ft.update(a,1) print(*res,sep="\n") year() ```
instruction
0
8,004
23
16,008
Yes
output
1
8,004
23
16,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` n = int(input()) xs = [] for i in range(n): a, b = [int(x) for x in input().split()] xs.append((a, 0, i)) xs.append((b, 1, i)) xs = sorted(xs) s = [] ans = [0] * n for p, end, idx in xs: if end: count, pidx = s[-1] if pidx == idx: ans[idx] = count s.pop() if s: s[-1][0] += count + 1 else: for nidx in range(len(s), 0, -1): if s[nidx - 1][1] == idx: break ans[idx] = count s.pop(nidx - 1) else: s.append([0, idx]) for count, idx in s: ans[idx] = count for x in ans: print(x) ```
instruction
0
8,005
23
16,010
No
output
1
8,005
23
16,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` def includes(n, lines): lines.sort() l_ind = {l: n-1-i for i, l in enumerate(lines)} lines.sort(key=lambda x: x[::-1]) return {l: min(i, l_ind[l]) for i, l in enumerate(lines)} n = int(input()) lines = [tuple(map(lambda x: int(x), input().split())) for i in range(n)] answer = includes(n, lines[:]) for l in lines: print(answer[l]) ```
instruction
0
8,006
23
16,012
No
output
1
8,006
23
16,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` import logging import copy import sys logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) #def solve(firstLine): def solve(firstLine, inputLines): sortedLine = sorted(inputLines, key=lambda line: line[0]) cntList = [0] * len(inputLines) cntDict = {} for i in range(1, len(sortedLine)): p = sortedLine[i] for j in range(len(sortedLine)): if i == j : continue if p[1] < sortedLine[j][0] : break # if sortedLine[j][1] < p[1]: # break if sortedLine[j][1] > p[1]: key = ' '.join(str(e) for e in sortedLine[j]) if key in cntDict: cntDict[key] += 1 else: cntDict[key] = 1 log(cntDict) for line in inputLines: key = ' '.join(str(e) for e in line) if key in cntDict: print(cntDict[key]) else: print(0) return def main(): firstLine = input().split() firstLine = list(map(int, firstLine)) inputLines = [] for i in range(firstLine[0]): line = input().split() line = list(map(int, line)) inputLines.append(line) #solve(firstLine) solve(firstLine, inputLines) def log(*message): logging.debug(message) if __name__ == "__main__": main() ```
instruction
0
8,007
23
16,014
No
output
1
8,007
23
16,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of segments on a line. Each of the next n lines contains two integers li and ri ( - 109 ≤ li < ri ≤ 109) — the coordinates of the left and the right ends of the i-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Print n lines. The j-th of them should contain the only integer aj — the number of segments contained in the j-th segment. Examples Input 4 1 8 2 3 4 7 5 6 Output 3 0 1 0 Input 3 3 4 1 5 2 6 Output 0 1 1 Submitted Solution: ``` import bisect as bs import itertools as it import sys def includes(lines): count = {} from_left = sorted(lines) from_right = sorted(lines, key=lambda x: x[1]) for i, line in enumerate(from_right): count[line] = len(set(from_right[:i]) & set(from_left[bs.bisect(from_left, line):])) # j = bs.bisect_left(from_left, line) # count[line] = (i - j) if i - j > 0 else 0 return count n = int(input()) if n > 10000: _INPUT_LINES = sys.stdin.read() print("START!!!") lines = [] # [tuple(map(int, input().split())) for i in range(n)] for line in it.islice(sys.stdin, n): lines.append(tuple(map(int, line.split()))) answer = includes(lines[:]) for l in lines: print(answer[l]) ```
instruction
0
8,008
23
16,016
No
output
1
8,008
23
16,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n × m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components: <image> But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1, l) and (n, r), where conditions 1 ≤ l ≤ r ≤ m are satisfied. Help Vladik to calculate the beauty for some segments of the given flag. Input First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively. Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106. Each of next q lines contains two space-separated integers l, r (1 ≤ l ≤ r ≤ m) — borders of segment which beauty Vladik wants to know. Output For each segment print the result on the corresponding line. Example Input 4 5 4 1 1 1 1 1 1 2 2 3 3 1 1 1 2 5 4 4 5 5 5 1 5 2 5 1 2 4 5 Output 6 7 3 4 Note Partitioning on components for every segment from first test case: <image> Submitted Solution: ``` #!/usr/bin/python3 import sys deb = "--debug" in sys.argv def get_str_deb(): yield list(int(x) for x in "4 5 4".split()) yield list(int(x) for x in "1 1 1 1 1".split()) yield list(int(x) for x in "1 2 2 3 3".split()) yield list(int(x) for x in "1 1 1 2 5".split()) yield list(int(x) for x in "4 4 5 5 5".split()) yield list(int(x) for x in "1 5".split()) yield list(int(x) for x in "2 5".split()) yield list(int(x) for x in "1 2".split()) yield list(int(x) for x in "4 5".split()) if deb: debi = get_str_deb() print("DEBUG!!!") def get_str(): if not deb: return (int(x) for x in sys.stdin.readline().split()) else: return next(debi) def main(): n, m, q = get_str() matr = [None] * n for i in range(n): matr[i] = list(get_str()) for i in range(q): l, r = get_str() l = l - 1 r = r - 1 x, y = [l, 0] regions = 0 """checked = [[False for i in range(m)] for j in range(n)] while True: regions = regions + 1 chain = [] while True: checked[y][x] = True if x > l and matr[y][x - 1] == matr[y][x] and not(checked[y][x - 1]): chain.append((x, y)) x = x - 1 continue elif x < r and matr[y][x + 1] == matr[y][x] and not(checked[y][x + 1]): chain.append((x, y)) x = x + 1 continue elif y > 0 and matr[y - 1][x] == matr[y][x] and not(checked[y - 1][x]): chain.append((x, y)) y = y - 1 continue elif y < n - 1 and matr[y + 1][x] == matr[y][x] and not(checked[y + 1][x]): chain.append((x, y)) y = y + 1 continue elif len(chain) == 0: break x, y = chain.pop() x = None y = None for newx in range(l, r + 1): for newy in range(n): if not(checked[newy][newx]): x = newx y = newy stop = True break if x is not None: break if x is None: break""" for x in range(l, r + 1): for y in range(n): regions = regions + 1 if y > 0 and matr[y - 1][x] == matr[y][x]: regions = regions - 1 if x > l and matr[y][x - 1] == matr[y][x]: regions = regions - 1 print(regions) if __name__ == "__main__": main() ```
instruction
0
8,083
23
16,166
No
output
1
8,083
23
16,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n × m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components: <image> But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1, l) and (n, r), where conditions 1 ≤ l ≤ r ≤ m are satisfied. Help Vladik to calculate the beauty for some segments of the given flag. Input First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively. Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106. Each of next q lines contains two space-separated integers l, r (1 ≤ l ≤ r ≤ m) — borders of segment which beauty Vladik wants to know. Output For each segment print the result on the corresponding line. Example Input 4 5 4 1 1 1 1 1 1 2 2 3 3 1 1 1 2 5 4 4 5 5 5 1 5 2 5 1 2 4 5 Output 6 7 3 4 Note Partitioning on components for every segment from first test case: <image> Submitted Solution: ``` print("asdasdasdas") ```
instruction
0
8,084
23
16,168
No
output
1
8,084
23
16,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n × m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components: <image> But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1, l) and (n, r), where conditions 1 ≤ l ≤ r ≤ m are satisfied. Help Vladik to calculate the beauty for some segments of the given flag. Input First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively. Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106. Each of next q lines contains two space-separated integers l, r (1 ≤ l ≤ r ≤ m) — borders of segment which beauty Vladik wants to know. Output For each segment print the result on the corresponding line. Example Input 4 5 4 1 1 1 1 1 1 2 2 3 3 1 1 1 2 5 4 4 5 5 5 1 5 2 5 1 2 4 5 Output 6 7 3 4 Note Partitioning on components for every segment from first test case: <image> Submitted Solution: ``` import sys data=sys.stdin.read().split("\n") del data[len(data)-1] n= int(data[0][0]) for ii in range(n+1, len(data)): cnt=[] suffix=0 left=int(data[ii].split(" ")[0])-1 right=int(data[ii].split(" ")[1])-1 array=[i.split(" ") for i in data[1:n+1]] for line in range(0,n): lines=array[line] for number in range(left, right+1):#x==line, y==number z=0 if (line-1>=0 and array[line-1][number].split("-")[0]==array[line][number]): z+=1 array[line][number]+="-"+array[line-1][number].split("-")[1] if (number-1>=left and array[line][number-1].split("-")[0]==array[line][number].split("-")[0]): z+=1 if (z==2 and array[line-1][number].split("-")[1] != array[line][number-1].split("-")[1]): del cnt[0] for x1 in range(left,right+1): for y1 in range(n): if array[y1][x1]==array[line][number]: array[y1][x1]=array[line][number-1] elif (z==2 and array[line-1][number].split("-")[1] == array[line][number-1].split("-")[1]): continue else: array[line][number]+="-"+array[line][number-1].split("-")[1] if z!=0: continue suffix+=1 array[line][number]+="-"+str(suffix) cnt.append("*") print (cnt.count("*")) ```
instruction
0
8,085
23
16,170
No
output
1
8,085
23
16,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n × m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components: <image> But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1, l) and (n, r), where conditions 1 ≤ l ≤ r ≤ m are satisfied. Help Vladik to calculate the beauty for some segments of the given flag. Input First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively. Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106. Each of next q lines contains two space-separated integers l, r (1 ≤ l ≤ r ≤ m) — borders of segment which beauty Vladik wants to know. Output For each segment print the result on the corresponding line. Example Input 4 5 4 1 1 1 1 1 1 2 2 3 3 1 1 1 2 5 4 4 5 5 5 1 5 2 5 1 2 4 5 Output 6 7 3 4 Note Partitioning on components for every segment from first test case: <image> Submitted Solution: ``` #!/usr/bin/python3 import sys def get_str_deb(): yield list(int(x) for x in "4 5 4".split()) yield list(int(x) for x in "1 1 1 1 1".split()) yield list(int(x) for x in "1 2 2 3 3".split()) yield list(int(x) for x in "1 1 1 2 5".split()) yield list(int(x) for x in "4 4 5 5 5".split()) yield list(int(x) for x in "1 5".split()) yield list(int(x) for x in "2 5".split()) yield list(int(x) for x in "1 2".split()) yield list(int(x) for x in "4 5".split()) deb = get_str_deb() def get_str(): if False: return (int(x) for x in sys.stdin.readline().split()) else: return next(deb) def main(): n, m, q = get_str() matr = [None] * n for i in range(n): matr[i] = list(get_str()) for i in range(q): l, r = get_str() l = l - 1 r = r - 1 x, y = [l, 0] regions = 0 checked = [[False for i in range(m)] for j in range(n)] while True: regions = regions + 1 chain = [] while True: checked[y][x] = True if x > l and matr[y][x - 1] == matr[y][x] and not(checked[y][x - 1]): chain.append((x, y)) x = x - 1 continue elif x < r and matr[y][x + 1] == matr[y][x] and not(checked[y][x + 1]): chain.append((x, y)) x = x + 1 continue elif y > 0 and matr[y - 1][x] == matr[y][x] and not(checked[y - 1][x]): chain.append((x, y)) y = y - 1 continue elif y < n - 1 and matr[y + 1][x] == matr[y][x] and not(checked[y + 1][x]): chain.append((x, y)) y = y + 1 continue elif len(chain) == 0: break x, y = chain.pop() x = None y = None for newx in range(l, r + 1): for newy in range(n): if not(checked[newy][newx]): x = newx y = newy stop = True break if x is not None: break if x is None: break print(regions) if __name__ == "__main__": main() ```
instruction
0
8,086
23
16,172
No
output
1
8,086
23
16,173
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,216
23
16,432
"Correct Solution: ``` import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### BIT binary def init(bit, values): for i,v in enumerate(values): add(bit,i+1,v) #a1 ~ aiまでの和 O(logn) def query(bit,i): res = 0 while i > 0: res += bit[i] i -= i&(-i) return res #ai += x(logN) def add(bit,i,x): if i==0: raise RuntimeError while i <= len(bit)-1: bit[i] += x i += i&(-i) return n = int(input()) xy = [tuple(map(int, input().split())) for _ in range(n)] from bisect import bisect_left def press(l): # xs[inds[i]]==l[i]となる xs = sorted(set(l)) inds = [None] * len(l) for i,item in enumerate(l): inds[i] = bisect_left(xs, item) return xs, inds _, indx = press([item[0] for item in xy]) _, indy = press([item[1] for item in xy]) xy = list(zip(indx, indy)) xy.sort() M = 998244353 # ans = (pow(2, n, M) * n) % M pows = [0]*(n+1) v = 1 for i in range(n+1): pows[i] = v-1 v *= 2 v %= M ans = (pows[n]*n) % M bit = [0]*(n+1) for i,(x,y) in enumerate(xy): ans -= pows[i] + pows[n-i-1] ans += pows[query(bit, y+1)] + pows[i - query(bit, y+1)] add(bit, y+1, 1) ans %= M from operator import itemgetter xy.sort(key=itemgetter(1)) bit = [0]*(n+1) for i,(x,y) in enumerate(xy): ans -= pows[i] + pows[n-i-1] ans += pows[i - query(bit, x+1)] add(bit, x+1, 1) ans %= M bit = [0]*(n+1) for i in range(n-1, -1, -1): x,y = xy[i] ans += pows[(n-1-i) - query(bit, x+1)] add(bit, x+1, 1) ans %= M print(ans%M) ```
output
1
8,216
23
16,433
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,217
23
16,434
"Correct Solution: ``` import sys input = sys.stdin.readline N=int(input()) POINT=[list(map(int,input().split())) for i in range(N)] mod=998244353 PX=[p[0] for p in POINT] PY=[p[1] for p in POINT] compression_dict_x={a: ind for ind, a in enumerate(sorted(set(PX)))} compression_dict_y={a: ind for ind, a in enumerate(sorted(set(PY)))} for i in range(N): POINT[i]=[compression_dict_x[POINT[i][0]]+1,compression_dict_y[POINT[i][1]]+1] P_Y=sorted(POINT,key=lambda x:x[1]) # BIT(BIT-indexed tree) LEN=len(compression_dict_x)# 必要なら座標圧縮する BIT=[0]*(LEN+1)# 1-indexedなtree def update(v,w):# vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v):# [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ return ANS ALL = pow(2,N,mod)-1 ANS= ALL*N%mod for i in range(N): ANS = (ANS - (pow(2,i,mod) -1)*4)%mod for i in range(N): x,y=P_Y[i] up=getvalue(x) ANS=(ANS+pow(2,up,mod)+pow(2,i-up,mod)-2)%mod update(x,1) P_Y2=P_Y[::-1] BIT=[0]*(LEN+1) for i in range(N): x,y=P_Y2[i] down=getvalue(x) ANS=(ANS+pow(2,down,mod)+pow(2,i-down,mod)-2)%mod update(x,1) print(ANS) ```
output
1
8,217
23
16,435
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,218
23
16,436
"Correct Solution: ``` import sys import array from operator import itemgetter def main(): input = sys.stdin.readline md = 998244353 n = int(input()) tl=n+1 ft=[0]*tl xy = [[0]*2 for _ in range(n)] for i in range(n): xy[i] = [int(item) for item in input().split()] xy.sort(key=itemgetter(0)) yxi = [y for x, y in xy] *YS, = set(yxi) YS.sort() yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi)) ct=[0]*(n+1) ct[0]=1 for i in range(1,n+1): ct[i]=ct[i-1]*2%md cnt=tuple(ct) def upd(i): i+=1 while(i<=n): ft[i]+=1 i+=i&-i def get(i): i+=1 ret=0 while(i!=0): ret+=ft[i] i-=i&-i return ret def calc(get,upd): for i, y in enumerate(yxi): v = get(y); upd(y) p1 = cnt[v]; p0 = cnt[y - v] q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)] yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md print((sum(calc(get,upd))+n*cnt[n] - n)%md) main() ```
output
1
8,218
23
16,437
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,219
23
16,438
"Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] class BitSum: def __init__(self, n): self.n = n + 1 self.table = [0] * self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def main(): md=998244353 n=II() xy=LLI(n) yy=set() for x,y in xy:yy.add(y) ytoj={y:j for j,y in enumerate(sorted(yy))} ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n) ans%=md xy.sort() bit=BitSum(200005) for i,[x,y] in enumerate(xy): j=ytoj[y] c=bit.sum(j-1) ans+=pow(2,c,md)-1 ans+=pow(2,i-c,md)-1 ans%=md bit.add(j,1) bit=BitSum(200005) for i,[x,y] in enumerate(xy[::-1]): j=ytoj[y] c=bit.sum(j-1) ans+=pow(2,c,md)-1 ans+=pow(2,i-c,md)-1 ans%=md bit.add(j,1) print(ans) main() ```
output
1
8,219
23
16,439
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,220
23
16,440
"Correct Solution: ``` import sys input=sys.stdin.readline N=int(input()) p=[] for i in range(N): x,y=map(int,input().split()) p.append([x,y]) mod=998244353 pow=[1] for i in range(N): pow.append((pow[-1]*2)%mod) p.sort(key=lambda x:x[1]) for i in range(N): p[i][1]=i+1 data=[[0 for i in range(4)] for i in range(N)] #A1 ... AnのBIT(1-indexed) n=N BIT = [0]*(n+1) #A1 ~ Aiまでの和 O(logN) def BIT_query(idx): if idx==0: return 0 res_sum = 0 while idx > 0: res_sum += BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def BIT_update(idx,x): while idx <= n: BIT[idx] += x idx += idx&(-idx) return p.sort() for i in range(N): x,y=p[i] a,b=i,BIT_query(y) data[i][0]=a-b data[i][3]=b BIT_update(y,1) BIT=[0]*(n+1) for i in range(N-1,-1,-1): x,y=p[i] a,b=N-1-i,BIT_query(y) data[i][1]=a-b data[i][2]=b BIT_update(y,1) ans=0 for i in range(N): ban=0 for j in range(4): ban+=(pow[data[i][j]]-1)*pow[data[i][j-1]] ban%=mod ans+=pow[N]-ban-1 ans%=mod print(ans) ```
output
1
8,220
23
16,441
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,221
23
16,442
"Correct Solution: ``` import sys input = sys.stdin.readline N=int(input()) POINT=[list(map(int,input().split())) for i in range(N)] mod=998244353 compression_dict_x={a: ind for ind, a in enumerate(sorted(set([p[0] for p in POINT])))} POINT=[[compression_dict_x[x]+1,y] for x,y in POINT] P_Y=sorted(POINT,key=lambda x:x[1]) # BIT(BIT-indexed tree) LEN=len(compression_dict_x) BIT=[0]*(LEN+1)# 1-indexedなtree def update(v,w):# vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v):# [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ return ANS ANS= 4*N+(pow(2,N,mod)-1)*(N-4)%mod for i in range(N): x,y=P_Y[i] left=getvalue(x) ANS=(ANS+pow(2,left,mod)+pow(2,i-left,mod)-2)%mod update(x,1) P_Y.reverse() BIT=[0]*(LEN+1) for i in range(N): x,y=P_Y[i] left=getvalue(x) ANS=(ANS+pow(2,left,mod)+pow(2,i-left,mod)-2)%mod update(x,1) print(ANS) ```
output
1
8,221
23
16,443
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,222
23
16,444
"Correct Solution: ``` import sys input = sys.stdin.readline mod = 998244353 n = int(input()) XY = sorted(tuple(map(int, input().split())) for _ in range(n)) X, Y = zip(*XY) L = {y:i+1 for i, y in enumerate(sorted(Y))} Y = tuple(L[y] for y in Y) BIT = [0]*(n+1) def add(i): while i<=n: BIT[i] += 1 i += i&-i def acc(i): res = 0 while i: res += BIT[i] i -= i&-i return res A = [0]*n B = [0]*n C = [0]*n D = [0]*n for i, y in enumerate(Y): A[i] = acc(y) B[i] = i - A[i] add(y) BIT = [0]*(n+1) for i in range(n-1, -1, -1): y = Y[i] C[i] = acc(y) D[i] = n-1-i - C[i] add(y) T = [1]*n for i in range(n-1): T[i+1] = T[i]*2%mod ans = T[n-1] * n % mod for a, b, c, d in zip(A, B, C, D): a = T[a] b = T[b] c = T[c] d = T[d] temp = (a-1)*b*c*(d-1) + a*(b-1)*(c-1)*d - (a-1)*(b-1)*(c-1)*(d-1) ans += temp ans %= mod print(ans) ```
output
1
8,222
23
16,445
Provide a correct Python 3 solution for this coding contest problem. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222
instruction
0
8,223
23
16,446
"Correct Solution: ``` from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect(): def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-10**18] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) self.co_to_ind[num] = ind+1 self.max = len(self.co_to_ind) self.data = [0]*(self.max+1) def __str__(self): retList = [] for i in range(1, self.max+1): x = self.ind_to_co[i] if self.count(x): c = self.count(x) for _ in range(c): retList.append(x) return "[" + ", ".join([str(a) for a in retList]) + "]" def __getitem__(self, key): key += 1 s = 0 ind = 0 l = self.max.bit_length() for i in reversed(range(l)): if ind + (1<<i) <= self.max: if s + self.data[ind+(1<<i)] < key: s += self.data[ind+(1<<i)] ind += (1<<i) if ind == self.max or key < 0: raise IndexError("BIT index out of range") return self.ind_to_co[ind+1] def __len__(self): return self._query_sum(self.max) def __contains__(self, num): if not num in self.co_to_ind: return False return self.count(num) > 0 # 0からiまでの区間和 # 左に進んでいく def _query_sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s # i番目の要素にxを足す # 上に登っていく def _add(self, i, x): while i <= self.max: self.data[i] += x i += i & -i # 値xを挿入 def push(self, x): if not x in self.co_to_ind: raise KeyError("The pushing number didnt initialized") self._add(self.co_to_ind[x], 1) # 値xを削除 def delete(self, x): if not x in self.co_to_ind: raise KeyError("The deleting number didnt initialized") if self.count(x) <= 0: raise ValueError("The deleting number doesnt exist") self._add(self.co_to_ind[x], -1) # 要素xの個数 def count(self, x): return self._query_sum(self.co_to_ind[x]) - self._query_sum(self.co_to_ind[x]-1) # 値xを超える最低ind def bisect_right(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_right(self.ind_to_co, x) - 1 return self._query_sum(i) # 値xを下回る最低ind def bisect_left(self, x): if x in self.co_to_ind: i = self.co_to_ind[x] else: i = bisect_left(self.ind_to_co, x) if i == 1: return 0 return self._query_sum(i-1) mod = 998244353 import sys input = sys.stdin.readline N = int(input()) XY = [list(map(int, input().split())) for _ in range(N)] Ys = [] for x, y in XY: Ys.append(y) XY.sort() D = [[0, 0, 0, 0] for _ in range(N)] B1 = BITbisect(Ys) for i, (x, y) in enumerate(XY): k = B1.bisect_left(y) D[i][0] = k D[i][1] = i-k B1.push(y) B2 = BITbisect(Ys) for i in reversed(range(N)): x, y = XY[i] k = B2.bisect_left(y) D[i][2] = k D[i][3] = (N-1-i)-k B2.push(y) N2 = [1] for _ in range(N): N2.append(N2[-1]*2%mod) ans = 0 for i in range(N): a, b, c, d = D[i] p = N2[N] - 1 - (N2[a+b]+N2[b+d]+N2[d+c]+N2[c+a])%mod + (N2[a]+N2[b]+N2[c]+N2[d])%mod ans = (ans + p) % mod print(ans) ```
output
1
8,223
23
16,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` from operator import itemgetter class BIT: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 i += 1 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i mod = 998244353 N = int(input()) xy = [list(map(int,input().split())) for _ in range(N)] xy.sort(key=itemgetter(1)) for i in range(N): xy[i][1] = i xy.sort(key=itemgetter(0)) pow2 = [1]*(N+1) for i in range(N): pow2[i+1] = 2*pow2[i]%mod ans = pow2[N-1]*N%mod bit = BIT(N) for i in range(N): l1 = bit.sum(xy[i][1]) l2 = i-l1 r1 = xy[i][1]-l1 r2 = N-xy[i][1]-l2-1 bit.add(xy[i][1],1) ans += (pow2[l2]-1)*(pow2[r1]-1)*pow2[r2]*pow2[l1] ans += (pow2[r2]-1)*(pow2[l1]-1)*(pow2[l2]+pow2[r1]-1) ans %= mod print(ans) ```
instruction
0
8,224
23
16,448
Yes
output
1
8,224
23
16,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): MOD = 998244353 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() dat = [LI() for _ in range(N)] dat.sort() yo = [y for _,y in dat] yo.sort() up = [0] * N dw = [0] * N bit = [0] * (N+1) def bit_add(i): while i <= N: bit[i] += 1 i += i & -i def bit_sum(i): ret = 0 while i > 0: ret += bit[i] i -= i & -i return ret for i in range(N): x,y = dat[i] y = bisect.bisect_left(yo,y) + 1 up[i] = bit_sum(y) bit_add(y) bit = [0] * (N+1) for i in range(N-1,-1,-1): x,y = dat[i] y = bisect.bisect_left(yo,y) + 1 dw[i] = bit_sum(y) bit_add(y) ans = N * pow(2,N-1,MOD) for i in range(N): a = i - up[i] b = up[i] c = N-(i+1) - dw[i] d = dw[i] p = (pow(2,a+d,MOD)-1) - (pow(2,a,MOD)-1) - (pow(2,d,MOD)-1) q = (pow(2,b+c,MOD)-1) - (pow(2,b,MOD)-1) - (pow(2,c,MOD)-1) x = p * (pow(2,b,MOD) + pow(2,c,MOD)-1) y = q * (pow(2,a,MOD) + pow(2,d,MOD)-1) z = p * q ans = (ans + x + y + z) % MOD print(ans) if __name__ == '__main__': main() ```
instruction
0
8,225
23
16,450
Yes
output
1
8,225
23
16,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(10 ** 9) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 998244353 class BIT: def __init__(self, size): self.bit = [0] * size self.size = size def add(self, i, w): x = i + 1 while x <= self.size: self.bit[x - 1] += w x += x & -x return def sum(self, i): res = 0 x = i + 1 while x: res += self.bit[x - 1] x -= x & -x return res n = I() X = [] Y = [] XY = [] for x, y in LIR(n): Y += [y] X += [x] co_to_ind = {e: i for i, e in enumerate(sorted(Y))} Y = [co_to_ind[k] for k in Y] Y = [Y[i] for i in sorted(range(n), key=lambda j:X[j])] pow2 = [1] for i in range(n): pow2 += [pow2[-1] * 2 % mod] ans = pow2[n - 1] * n % mod bit = BIT(n) for i, y in enumerate(Y): bit.add(y, 1) ld = bit.sum(y - 1) lu = i - ld rd = y - ld ru = n - y - 1 - lu ans = ans + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * pow2[lu] % mod * pow2[rd] % mod ans = ans + (pow2[lu] - 1) * (pow2[rd] - 1) % mod * pow2[ld] % mod * pow2[ru] % mod ans = ans - (pow2[ld] - 1) * (pow2[ru] - 1) % mod * (pow2[rd] - 1) % mod * (pow2[lu] - 1) % mod print(ans % mod) ```
instruction
0
8,226
23
16,452
Yes
output
1
8,226
23
16,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### BIT binary def init(bit, values): for i,v in enumerate(values): add(bit,i+1,v) #a1 ~ aiまでの和 O(logn) def query(bit,i): res = 0 while i > 0: res += bit[i] i -= i&(-i) return res #ai += x(logN) def add(bit,i,x): if i==0: raise RuntimeError while i <= len(bit)-1: bit[i] += x i += i&(-i) return n = int(input()) xy = [tuple(map(int, input().split())) for _ in range(n)] from bisect import bisect_left def press(l): # xs[inds[i]]==l[i]となる xs = sorted(set(l)) inds = [None] * len(l) for i,item in enumerate(l): inds[i] = bisect_left(xs, item) return xs, inds _, indx = press([item[0] for item in xy]) _, indy = press([item[1] for item in xy]) xy = [] for i in range(n): xy.append(indy[i]+indx[i]*n) xy.sort() M = 998244353 # ans = (pow(2, n, M) * n) % M pows = [0]*(n+1) v = 1 for i in range(n+1): pows[i] = v-1 v *= 2 v %= M ans = (pows[n]*n) % M bit = [0]*(n+1) for i in range(n): x,y = divmod(xy[i],n) ans -= pows[i] + pows[n-i-1] ans += pows[query(bit, y+1)] + pows[i - query(bit, y+1)] add(bit, y+1, 1) ans %= M from operator import itemgetter xy.sort(key=lambda item: item%n) bit = [0]*(n+1) for i in range(n): x,y = divmod(xy[i],n) ans -= pows[i] + pows[n-i-1] ans += pows[i - query(bit, x+1)] add(bit, x+1, 1) ans %= M bit = [0]*(n+1) for i in range(n-1, -1, -1): x,y = divmod(xy[i], n) ans += pows[(n-1-i) - query(bit, x+1)] add(bit, x+1, 1) ans %= M print(ans%M) ```
instruction
0
8,227
23
16,454
Yes
output
1
8,227
23
16,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` N = int(input()) p = 998244353 S = [[0, 0] for i in range(N)] for i in range(N): S[i] = [int(x) for x in input().split()] S.sort() Y = sorted([i for i in range(N)], key=lambda y:S[y][1]) D = [[0, 0, 0, 0] for i in range(N)] BIT = [0] * N def query(y): _y = y + 1 ans = 0 while _y > 0: ans += BIT[_y - 1] _y -= _y & -_y return ans def update(y): _y = y + 1 while _y <= N: BIT[_y - 1] += 1 _y += _y & -_y return 0 for i, y in enumerate(Y): D[y][0] = query(y) D[y][1] = i - D[y][0] update(y) BIT = [0] * N for i, y in enumerate(Y[::-1]): D[y][2] = query(y) D[y][3] = i - D[y][2] update(y) cnt = 0 for i in range(N): a, b, c, d = [pow(2, d, p) - 1 for d in D[i]] cnt += pow(2, N - 1, p) cnt += a * d * (b + c + 1) cnt += b * c * (a + d + 1) cnt += a * b * c * d cnt %= p print(int(cnt)) ```
instruction
0
8,228
23
16,456
No
output
1
8,228
23
16,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` N = int(input()) XY = [] for _ in range(N): x, y = map(int, input().split()) XY.append((x, y)) # BITの定義 import math class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) # index 1からiの値の和を返す def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s # index iの値にxを加算する def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i ####################### # 開始 p_list = XY[:] # y座標の圧縮 from operator import itemgetter p_list = sorted(p_list, key=itemgetter(1)) p_list = [ (x, y, i+1) for i, (x, y) in enumerate(p_list)] # xでソート p_list= sorted(p_list) a = [0] * N # 左下 b = [0] * N# 左上 c = [0] * N# 右下 d = [0] * N# 右上 # a,bを求める bit = Bit(N) for i, (x, y, r) in enumerate(p_list): tmp = bit.sum(r) a[i] = tmp b[i] = i-tmp bit.add(r, 1) # c,dを求める bit = Bit(N) for i, (x, y, r) in enumerate(reversed(p_list)): tmp = bit.sum(r) c[i] = tmp d[i] = i-tmp bit.add(r, 1) c = c[::-1] d = d[::-1] # ある点が四角に含まれる場合の総数を求めるメソッド power = [1] * N for i in range(1, N): power[i] = power[i-1] * 2 % 998244353 ans = 0 for _a,_b,_c,_d in zip(a,b,c,d): _a = power[_a] - 1 _b = power[_b] - 1 _c = power[_c] - 1 _d = power[_d] - 1 ret = (_a+1) * (_d+1) * _c * _b ret += (_b+1) * (_c+1) * _a * _d ret -= _a*_b*_c*_d ret += power[N-1] ans += ret % 998244353 print(ans % 998244353) ```
instruction
0
8,229
23
16,458
No
output
1
8,229
23
16,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` import sys def input(): return sys.stdin.readline()[:-1] MOD = 998244353 class BIT():#1-indexed def __init__(self, size): self.table = [0 for _ in range(size+2)] self.size = size def Sum(self, i):#1からiまでの和 s = 0 while i > 0: s += self.table[i] i -= (i & -i) return s def PointAdd(self, i, x):# while i <= self.size: self.table[i] += x i += (i & -i) return n = int(input()) dd = [list(map(int, input().split())) + [i] for i in range(n)] d = [[-1, -1] for _ in range(n)] dd.sort() for i, x in enumerate(dd): d[x[2]][0] = i+1 dd.sort(key=lambda x: x[1]) for i, x in enumerate(dd): d[x[2]][1] = i+1 d.sort() d = [(x[0], x[1]) for x in d] lu = [0 for _ in range(n)] ld = [0 for _ in range(n)] rd = [0 for _ in range(n)] ru = [0 for _ in range(n)] bitl, bitr = BIT(n), BIT(n) for i in range(n): x = d[i][1] s = bitl.Sum(x) lu[i] = i - s ld[i] = s bitl.PointAdd(x, 1) for i in range(n-1, -1, -1): x = d[i][1] s = bitr.Sum(x) ru[i] = n-1-i - s rd[i] = s bitr.PointAdd(x, 1) #print(lu, ld, rd, ru, sep="\n") ans = (n*pow(2, n, MOD) - n) % MOD for i in range(n): ans -= pow(2, lu[i]+ld[i], MOD) + pow(2, ld[i]+rd[i], MOD) + pow(2, rd[i]+ru[i], MOD) + pow(2, ru[i]+lu[i], MOD) ans += pow(2, lu[i], MOD) + pow(2, ld[i], MOD) + pow(2, rd[i], MOD) + pow(2, ru[i], MOD) ans %= MOD print(ans) ```
instruction
0
8,230
23
16,460
No
output
1
8,230
23
16,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates. For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows: * f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T) Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353. Constraints * 1 \leq N \leq 2 \times 10^5 * -10^9 \leq x_i, y_i \leq 10^9 * x_i \neq x_j (i \neq j) * y_i \neq y_j (i \neq j) * All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S, modulo 998244353. Examples Input 3 -1 3 2 1 3 -2 Output 13 Input 4 1 4 2 1 3 3 4 2 Output 34 Input 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Output 7222 Submitted Solution: ``` def main(): import sys from operator import itemgetter input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i mod = 998244353 N = int(input()) X_raw = [0] * N Y_raw = [0] * N for i in range(N): x, y = map(int, input().split()) X_raw[i] = x Y_raw[i] = y val2idx_X = {} val2idx_Y = {} for i in range(N): val2idx_X[X_raw[i]] = i val2idx_Y[Y_raw[i]] = i X_raw.sort() Y_raw.sort() X = [0] * N Y = [0] * N for i in range(N): X[val2idx_X[X_raw[i]]] = i+1 Y[val2idx_Y[Y_raw[i]]] = i+1 XY = [(x, y) for x, y in zip(X, Y)] XY.sort(key=itemgetter(0)) bit_ul = Bit(N + 2) bit_ur = Bit(N+2) ul = [] ur = [] for x, y in XY: ul.append(bit_ul.sum(y)) ur.append(bit_ur.sum(N+1) - bit_ur.sum(y)) bit_ul.add(y, 1) bit_ur.add(y, 1) bit_dl = Bit(N + 2) bit_dr = Bit(N + 2) dl = [] dr = [] for x, y in reversed(XY): dl.append(bit_dl.sum(y)) dr.append(bit_dr.sum(N + 1) - bit_dr.sum(y)) bit_dl.add(y, 1) bit_dr.add(y, 1) dl.reverse() dr.reverse() ans = 0 for i in range(N): ans = (ans + pow(2, N, mod) - 1 - pow(2, ul[i]+ur[i], mod) - pow(2, dl[i]+dr[i], mod) - pow(2, ul[i]+dl[i], mod) - pow(2, ur[i]+dr[i], mod) + pow(2, ul[i], mod) + pow(2, ur[i], mod) + pow(2, dl[i], mod) + pow(2, dr[i], mod))%mod print(ans) if __name__ == '__main__': main() ```
instruction
0
8,231
23
16,462
No
output
1
8,231
23
16,463
Provide tags and a correct Python 3 solution for this coding contest problem. Vus the Cossack has a field with dimensions n × m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: 1. He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current field, and "0" there, where "1" was. 2. To the current field, he adds the inverted field to the right. 3. To the current field, he adds the inverted field to the bottom. 4. To the current field, he adds the current field to the bottom right. 5. He repeats it. For example, if the initial field was: \begin{matrix} 1 & 0 & \\\ 1 & 1 & \\\ \end{matrix} After the first iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 \\\ 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 \\\ 0 & 0 & 1 & 1 \\\ \end{matrix} After the second iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0& 0 & 0 & 0 & 1 & 1 \\\ \end{matrix} And so on... Let's numerate lines from top to bottom from 1 to infinity, and columns from left to right from 1 to infinity. We call the submatrix (x_1, y_1, x_2, y_2) all numbers that have coordinates (x, y) such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2. The Cossack needs sometimes to find the sum of all the numbers in submatrices. Since he is pretty busy right now, he is asking you to find the answers! Input The first line contains three integers n, m, q (1 ≤ n, m ≤ 1 000, 1 ≤ q ≤ 10^5) — the dimensions of the initial matrix and the number of queries. Each of the next n lines contains m characters c_{ij} (0 ≤ c_{ij} ≤ 1) — the characters in the matrix. Each of the next q lines contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ 10^9, 1 ≤ y_1 ≤ y_2 ≤ 10^9) — the coordinates of the upper left cell and bottom right cell, between which you need to find the sum of all numbers. Output For each query, print the answer. Examples Input 2 2 5 10 11 1 1 8 8 2 4 5 6 1 2 7 8 3 3 6 8 5 6 7 8 Output 32 5 25 14 4 Input 2 3 7 100 101 4 12 5 17 5 4 9 4 1 4 13 18 12 1 14 9 3 10 7 18 3 15 12 17 8 6 8 12 Output 6 3 98 13 22 15 3 Note The first example is explained in the legend.
instruction
0
8,435
23
16,870
Tags: divide and conquer, implementation, math Correct Solution: ``` from sys import stdin,stdout n,m,q = map(int, stdin.readline().split()) mat = [[0]*m for i in range(n)] for i in range(n): row = stdin.readline().strip() for j,c in enumerate(row): mat[i][j] = 1 if c == '1' else -1 #print(mat) def get(a,b): if a < 0 or b < 0: return 0 x = a^b ans = 1 while x > 0: if x % 2 == 1: ans *= -1 x //= 2 return ans row_sums = [[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): row_sums[i+1][j+1] = row_sums[i][j+1] + mat[i][j] #print(row_sums) mat_sums = [[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): mat_sums[i+1][j+1] = mat_sums[i+1][j] + row_sums[i+1][j+1] #print(mat_sums) total = mat_sums[n][m] def rect_sum(a, b): if a == 0 or b == 0: return 0 top_edge = 0 right_edge = 0 small = 0 x = a//n x_rem = a%n y = b // m y_rem = b%m # print("x", x, "y", y, "x_rem", x_rem, "y_rem", y_rem) big = 0 if x % 2 == 0 or y % 2 == 0 else total big *= get(x-1,y-1) if x % 2 == 1: right_edge= mat_sums[n][y_rem] right_edge *= get(x-1,y) if y % 2 == 1: top_edge = mat_sums[x_rem][m] top_edge *= get(x,y-1) small = mat_sums[x_rem][y_rem] small *= get(x,y) # print("big", big, "top", top_edge, "right", right_edge, "small", small) return top_edge + right_edge+small+big for it in range(q): x1,y1,x2,y2 = map(int, stdin.readline().split()) ans = rect_sum(x2,y2) - rect_sum(x1-1, y2) - rect_sum(x2, y1-1) + rect_sum(x1-1,y1-1) ans = ((x2-x1+1)*(y2-y1+1) + ans)//2 stdout.write(str(ans) + '\n') ```
output
1
8,435
23
16,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has a field with dimensions n × m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: 1. He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current field, and "0" there, where "1" was. 2. To the current field, he adds the inverted field to the right. 3. To the current field, he adds the inverted field to the bottom. 4. To the current field, he adds the current field to the bottom right. 5. He repeats it. For example, if the initial field was: \begin{matrix} 1 & 0 & \\\ 1 & 1 & \\\ \end{matrix} After the first iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 \\\ 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 \\\ 0 & 0 & 1 & 1 \\\ \end{matrix} After the second iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0& 0 & 0 & 0 & 1 & 1 \\\ \end{matrix} And so on... Let's numerate lines from top to bottom from 1 to infinity, and columns from left to right from 1 to infinity. We call the submatrix (x_1, y_1, x_2, y_2) all numbers that have coordinates (x, y) such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2. The Cossack needs sometimes to find the sum of all the numbers in submatrices. Since he is pretty busy right now, he is asking you to find the answers! Input The first line contains three integers n, m, q (1 ≤ n, m ≤ 1 000, 1 ≤ q ≤ 10^5) — the dimensions of the initial matrix and the number of queries. Each of the next n lines contains m characters c_{ij} (0 ≤ c_{ij} ≤ 1) — the characters in the matrix. Each of the next q lines contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ 10^9, 1 ≤ y_1 ≤ y_2 ≤ 10^9) — the coordinates of the upper left cell and bottom right cell, between which you need to find the sum of all numbers. Output For each query, print the answer. Examples Input 2 2 5 10 11 1 1 8 8 2 4 5 6 1 2 7 8 3 3 6 8 5 6 7 8 Output 32 5 25 14 4 Input 2 3 7 100 101 4 12 5 17 5 4 9 4 1 4 13 18 12 1 14 9 3 10 7 18 3 15 12 17 8 6 8 12 Output 6 3 98 13 22 15 3 Note The first example is explained in the legend. Submitted Solution: ``` def tm(a,b): if a | b == 0: return 0 else: return (a & 1) ^ (b & 1) ^ tm(a >> 1, b >> 1) def conv(c): if c == '0': return 0 else: return 1 n,m,q = list(map(int,input().split())) l = [] for r in range(n): l.append(list(map(conv,list(input())))) pre = [] for r in range(n): pre.append([]) for c in range(m): if r + c == 0: pre[0].append(l[0][0]) elif r == 0: pre[r].append(pre[r][c-1]+l[r][c]) elif c == 0: pre[r].append(pre[r-1][c]+l[r][c]) else: pre[r].append(pre[r][c-1]+pre[r-1][c]-pre[r-1][c-1]+l[r][c]) def findsize(x,xx,y,yy): xp = xx//m yp = yy//n if xp > x // m: split = xp * m return findsize(x,split-1,y,yy)+findsize(split,xx,y,yy) if yp > y // n: split = yp * n return findsize(x,xx,y,split-1)+findsize(x,xx,split,yy) flip = tm(xp,yp) xt = x - xp*m xtt = xx - xp*m yt = y - yp*n ytt = yy - yp*n if xt == 0 and yt == 0: out = pre[ytt][xtt] elif xt == 0: out = pre[ytt][xtt] - pre[yt - 1][xtt] elif yt == 0: out = pre[ytt][xtt] - pre[ytt][xt - 1] else: out = pre[ytt][xtt] - pre[yt - 1][xtt] - pre[ytt][xt - 1] + pre[yt - 1][xt - 1] if flip == 1: out = (xx-x+1)*(yy-y+1)-out # print(x,xx,y,yy,out) return out for _ in range(q): x1, y1, x2, y2 = list(map(int,input().split())) BASE = (x2-x1+1)*(y2-y1+1) xstart = x1 - 1 xsize = (x2-x1) % (2*m) + 1 ystart = y1 - 1 ysize = (y2-y1) % (2*n) + 1 SIZEA = 2*findsize(xstart,xstart+xsize-1,ystart,ystart+ysize-1) SIZEB = xsize*ysize REAL = (SIZEA-SIZEB)+BASE assert(REAL % 2 == 0) print(REAL//2) ```
instruction
0
8,436
23
16,872
No
output
1
8,436
23
16,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has a field with dimensions n × m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: 1. He takes the current field and finds a new inverted field. In other words, the new field will contain "1" only there, where "0" was in the current field, and "0" there, where "1" was. 2. To the current field, he adds the inverted field to the right. 3. To the current field, he adds the inverted field to the bottom. 4. To the current field, he adds the current field to the bottom right. 5. He repeats it. For example, if the initial field was: \begin{matrix} 1 & 0 & \\\ 1 & 1 & \\\ \end{matrix} After the first iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 \\\ 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 \\\ 0 & 0 & 1 & 1 \\\ \end{matrix} After the second iteration, the field will be like this: \begin{matrix} 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 \\\ 1 & 0 & 0 & 1 & 0 & 1 & 1 & 0 \\\ 1 & 1 & 0& 0 & 0 & 0 & 1 & 1 \\\ \end{matrix} And so on... Let's numerate lines from top to bottom from 1 to infinity, and columns from left to right from 1 to infinity. We call the submatrix (x_1, y_1, x_2, y_2) all numbers that have coordinates (x, y) such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2. The Cossack needs sometimes to find the sum of all the numbers in submatrices. Since he is pretty busy right now, he is asking you to find the answers! Input The first line contains three integers n, m, q (1 ≤ n, m ≤ 1 000, 1 ≤ q ≤ 10^5) — the dimensions of the initial matrix and the number of queries. Each of the next n lines contains m characters c_{ij} (0 ≤ c_{ij} ≤ 1) — the characters in the matrix. Each of the next q lines contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ 10^9, 1 ≤ y_1 ≤ y_2 ≤ 10^9) — the coordinates of the upper left cell and bottom right cell, between which you need to find the sum of all numbers. Output For each query, print the answer. Examples Input 2 2 5 10 11 1 1 8 8 2 4 5 6 1 2 7 8 3 3 6 8 5 6 7 8 Output 32 5 25 14 4 Input 2 3 7 100 101 4 12 5 17 5 4 9 4 1 4 13 18 12 1 14 9 3 10 7 18 3 15 12 17 8 6 8 12 Output 6 3 98 13 22 15 3 Note The first example is explained in the legend. Submitted Solution: ``` import sys N, M, Q = map(int, input().split()) print(N, M, Q) X = [] for _ in range(N): X.append(list(map(int, list(sys.stdin.readline().rstrip())))) Y = [[0]*(2*M+1) for _ in range(2*N+1)] for i in range(N): s = 0 for j in range(M): s += X[i][j] Y[i+1][j+1] = Y[i][j+1] + s for j in range(M): s += X[i][j]^1 Y[i+1][j+M+1] = Y[i][j+M+1] + s for i in range(N): s = 0 for j in range(M): s += X[i][j]^1 Y[i+N+1][j+1] = Y[i+N][j+1] + s for j in range(M): s += X[i][j] Y[i+N+1][j+M+1] = Y[i+N][j+M+1] + s def calc(x, y): if x >= 2*N: n = N while n*2 <= x: n *= 2 return n*y//2 + (x-n)*y - calc(x-n, y) if y >= 2*M: m = M while m*2 <= y: m *= 2 return m*x//2 + (y-m)*x - calc(x, y-m) return Y[x][y] for _ in range(Q): x1, y1, x2, y2 = map(int, sys.stdin.readline().rstrip().split()) x1, y1 = x1-1, y1-1 print(calc(x2, y2) - calc(x1, y2) - calc(x2, y1) + calc(x1, y1)) ```
instruction
0
8,437
23
16,874
No
output
1
8,437
23
16,875
Provide tags and a correct Python 3 solution for this coding contest problem. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7
instruction
0
8,623
23
17,246
Tags: implementation Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)] cnt = [0] * 400 for i in range(1, n - 1): for j in range(1, m - 1): if not a[i][j]: continue for rad, ui, di, lj, rj in zip(range(1, 400), range(i - 1, -1, -1), range(i + 1, n), range(j - 1, -1, -1), range(j + 1, m)): if a[ui][j] and a[di][j] and a[i][lj] and a[i][rj]: cnt[rad] += 1 rad = -1 for i in range(300): cnt[i + 1] += cnt[i] if cnt[i] >= k: rad = i k -= cnt[i - 1] break else: print(-1) exit() for i in range(rad, n - rad): for j in range(rad, m - rad): if a[i][j] and a[i - rad][j] and a[i + rad][j] and a[i][j - rad] and a[i][j + rad]: k -= 1 if k == 0: print(f'{i+1} {j+1}\n{i-rad+1} {j+1}\n{i+rad+1} {j+1}\n{i+1} {j-rad+1}\n{i+1} {j+rad+1}') exit() ```
output
1
8,623
23
17,247
Provide tags and a correct Python 3 solution for this coding contest problem. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7
instruction
0
8,624
23
17,248
Tags: implementation Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)] cnt = [0] * 400 for i in range(1, n - 1): for j in range(1, m - 1): if not a[i][j]: continue for rad, ui, di, lj, rj in zip(range(1, 400), range(i - 1, -1, -1), range(i + 1, n), range(j - 1, -1, -1), range(j + 1, m)): if all((a[ui][j], a[di][j], a[i][lj], a[i][rj])): cnt[rad] += 1 rad = -1 for i in range(300): cnt[i + 1] += cnt[i] if cnt[i] >= k: rad = i k -= cnt[i - 1] break else: print(-1) exit() for i in range(rad, n - rad): for j in range(rad, m - rad): if all((a[i][j], a[i - rad][j], a[i + rad][j], a[i][j - rad], a[i][j + rad])): k -= 1 if k == 0: print(f'{i+1} {j+1}\n{i-rad+1} {j+1}\n{i+rad+1} {j+1}\n{i+1} {j-rad+1}\n{i+1} {j+rad+1}') exit() ```
output
1
8,624
23
17,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7 Submitted Solution: ``` x,y,n = map(int,input().split()) count = 0 space = [[0 for i in range(y + 300)] for j in range(x + 300)] for i in range(x): dd = input() for j in range(y): space[i + 1][j + 1] = dd[j] for i in range(2,x ): for j in range(2,y ): for k in range (1,max(x,y)): if space[i][j] == '*'and space[i - k][j] == '*' and space[i + k][j] == '*' and space[i][j - k] == '*' and space[i][j + k] == '*': count += 1 if count == n and space[i][j] == '*'and space[i - k][j] == '*' and space[i + k][j] == '*' and space[i][j - k] == '*' and space[i][j + k] == '*': print(i,j,"\n",i-k,j,"\n",i+k,j,"\n",i,j-k,"\n",i,j+k) if count < n : print('-1') ```
instruction
0
8,625
23
17,250
No
output
1
8,625
23
17,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7 Submitted Solution: ``` x,y,n = map(int,input().split()) count = 0 space = [[0 for i in range(y + 300)] for j in range(x + 300)] for i in range(x): dd = input() for j in range(y): space[i + 1][j + 1] = dd[j] f = int(max(x,y) / 2) + 1 print(f) for k in range(1, f): for i in range(2,x): for j in range (2,y): if space[i][j] == '*'and space[i - k][j] == '*' and space[i + k][j] == '*' and space[i][j - k] == '*' and space[i][j + k] == '*': count += 1 if count == n and space[i][j] == '*'and space[i - k][j] == '*' and space[i + k][j] == '*' and space[i][j - k] == '*' and space[i][j + k] == '*': print(i,j,"\n",i-k,j,"\n",i+k,j,"\n",i,j-k,"\n",i,j+k) break if count < n : print('-1') ```
instruction
0
8,626
23
17,252
No
output
1
8,626
23
17,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7 Submitted Solution: ``` import sys n,m,k=map(int,input().split(' ')) star=[] for i in range(n): star.append(list(input())) c=0 for i in range(n): for j in range(m): for z in range(min(i,j,(m-1-j),(n-1-i))): if(star[i][j]=='*' and star[i-(z+1)][j]=='*' and star[i+(z+1)][j]=='*' and star[i][j-(z+1)]=='*' and star[i][j+(z+1)]=='*'): c+=1 if(c==k): print(str(i+1)+' '+str(j+1)) print(str(i-z)+' '+str(j+1)) print(str(i+z+2)+' '+str(j+1)) print(str(i+1)+' '+str(j-z)) print(str(i+1)+' '+str(j+z+2)) sys.exit() print(-1) ```
instruction
0
8,627
23
17,254
No
output
1
8,627
23
17,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is true: * the 2nd is on the same vertical line as the 1st, but x squares up * the 3rd is on the same vertical line as the 1st, but x squares down * the 4th is on the same horizontal line as the 1st, but x squares left * the 5th is on the same horizontal line as the 1st, but x squares right Such constellations can be very numerous, that's why they are numbered with integers from 1 on the following principle: when two constellations are compared, the one with a smaller radius gets a smaller index; if their radii are equal — the one, whose central star if higher than the central star of the other one; if their central stars are at the same level — the one, whose central star is to the left of the central star of the other one. Your task is to find the constellation with index k by the given Berland's star map. Input The first line contains three integers n, m and k (1 ≤ n, m ≤ 300, 1 ≤ k ≤ 3·107) — height and width of the map and index of the required constellation respectively. The upper-left corner has coordinates (1, 1), and the lower-right — (n, m). Then there follow n lines, m characters each — description of the map. j-th character in i-th line is «*», if there is a star in the corresponding square, and «.» if this square is empty. Output If the number of the constellations is less than k, output -1. Otherwise output 5 lines, two integers each — coordinates of the required constellation. Output the stars in the following order: central, upper, lower, left, right. Examples Input 5 6 1 ....*. ...*** ....*. ..*... .***.. Output 2 5 1 5 3 5 2 4 2 6 Input 5 6 2 ....*. ...*** ....*. ..*... .***.. Output -1 Input 7 7 2 ...*... ....... ...*... *.***.* ...*... ....... ...*... Output 4 4 1 4 7 4 4 1 4 7 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase import math def main(): pass 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 binary(n): return (bin(n).replace("0b", "")) def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def primeFactors(n): l=[] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) def reVal(num): if (num >= 0 and num <= 9): return chr(num + ord('0')); else: return chr(num - 10 + ord('A')); def strev(str): len = len(str); for i in range(int(len / 2)): temp = str[i]; str[i] = str[len - i - 1]; str[len - i - 1] = temp; def fromDeci(res, base, inputNum): index = 0; while (inputNum > 0): res += reVal(inputNum % base); inputNum = int(inputNum / base); res = res[::-1]; return res; def norm(s,l): tba="0"*(l-len(s)) return(tba+s) def check(x,y,k): if(mat[x-k][y]==mat[x+k][y]==mat[x][y-k]==mat[x][y+k]=="*"): return(True) else: return(False) n,m,k=map(int,input().split()) mat=[] for i in range(0,n): mat.append(input()) tc=0 ans=False ansr=0 for r in range(1,1+(min(n,m)-1)//2): if(not(ans)): for x in range(r,n-r): if(not(ans)): for y in range(r,m-r): if(check(x,y,r)): tc+=1 if(tc==k): ansr=r ansx,ansy=x,y ans=True break if(ans): ansx,ansy=ansx+1,ansy+1 print(ansx,ansy) print(ansx-ansr,ansy) print(ansx+ansr,ansy) print(ansx,ansy-ansr) print(ansx,ansy+ansr) else: print(-1) ```
instruction
0
8,628
23
17,256
No
output
1
8,628
23
17,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix. For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width. It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle. Vasiliy wants to know how the matrix will look like after all tasks are performed. Input The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform. Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix. Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m). Output Print n lines containing m integers each — the resulting matrix. Examples Input 4 4 2 1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4 1 1 3 3 2 2 3 1 1 3 2 2 Output 4 4 3 3 4 4 3 3 2 2 1 1 2 2 1 1 Input 4 2 1 1 1 1 1 2 2 2 2 1 1 4 1 1 2 Output 2 2 1 1 2 2 1 1 Submitted Solution: ``` import sys import timeit MATRIX = [] def a2i(a): i = [] for ii in a: i.append(int(ii)) return i def main(): global MATRIX works = [] n = 0 m = 0 q = 0 nL = 0 dtimer = timeit.default_timer; st = dtimer() firstLine = True matrixBody = False for line in sys.stdin: line = line.strip() a = line.split(' ') if firstLine: n = int(a[0]) nL = n m = int(a[1]) q = int(a[2]) firstLine = False matrixBody = True if (n < 2 or n > 1000) or (m < 2 or m > 1000) or (q < 1 or q > 10000): exit() elif matrixBody: MATRIX.append(a) nL -= 1 if nL == 0: matrixBody = False else: works.append(a2i(a)) print('loading time ' + str(dtimer() - st)) st = dtimer() counter = 0 while counter < q: makeWork(works[counter][0], works[counter][1], works[counter][2], works[counter][3], works[counter][4], works[counter][5]) counter += 1 print('working time ' + str(dtimer() - st)) st = dtimer() printMatrix(MATRIX) print('out time ' + str(dtimer() - st)) def makeWork(a1, b1, a2, b2, h, w): j = -1 while j < h-1: i = -1 while i < w-1: tmp = MATRIX[a2+j][b2+i] MATRIX[a2+j][b2+i] = MATRIX[a1+j][b1+i] MATRIX[a1+j][b1+i] = tmp i += 1 j += 1 def printMatrix(source): s = '' for a in source: for b in a: s += b + ' ' s += '\n' print(s, end='') if __name__ == '__main__': main() ```
instruction
0
8,713
23
17,426
No
output
1
8,713
23
17,427