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. You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle). Input The first line contains two positive integer numbers n and m (1 ≤ n, m ≤ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed. Output Output a single number — total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Examples Input 2 2 ** *. Output 1 Input 3 4 *..* .**. *.** Output 9 Submitted Solution: ``` n, m = map(int, input().split()) # temp = [] arr = [] r = [0]*n c = [0]*m for i in range(n): arr.append(input()) triangle = 0 for i in range(n): for j in range(m): if arr[i][j] == '*': r[i] += 1 c[j] += 1 for i in range(n): for j in range(m): if arr[i][j] == '*': triangle += (r[i] - 1) * (c[j] - 1) print(triangle) ```
instruction
0
99,049
23
198,098
Yes
output
1
99,049
23
198,099
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,416
23
198,832
"Correct Solution: ``` h, w = map(int, input().split()) a, b = map(int, input().split()) print(h * w - (a * b * ((h // a) * (w // b)))) ```
output
1
99,416
23
198,833
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,417
23
198,834
"Correct Solution: ``` h,w = map(int,input().split()) a,b = map(int,input().split()) print(h*w-(a*(h//a)*b*(w//b))) ```
output
1
99,417
23
198,835
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,418
23
198,836
"Correct Solution: ``` h,w = map(int,input().split()) a,b = map(int,input().split()) ai = h//a*a bi = w//b*b print(h*w-ai*bi) ```
output
1
99,418
23
198,837
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,419
23
198,838
"Correct Solution: ``` h,w=map(int,input().split()) a,b=map(int,input().split()) x=h//a*a y=w//b*b print(h*w-x*y) ```
output
1
99,419
23
198,839
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,420
23
198,840
"Correct Solution: ``` a,b = list(map(int,input().split())) c,d = list(map(int,input().split())) sum1 = a*b length2 = a // c side2 = b // d sum2 = (c*length2) * (d*side2) print(sum1 - sum2) ```
output
1
99,420
23
198,841
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,421
23
198,842
"Correct Solution: ``` h,w = map(int,input().split()) a,b = map(int,input().split()) rh,rw = h%a, w%b print(rh*w + rw*h - rh*rw) ```
output
1
99,421
23
198,843
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,422
23
198,844
"Correct Solution: ``` h,w=map(int,input().split()) a,b=map(int,input().split()) high=(h//a)*a wide=(w//b)*b print(h*w-high*wide) ```
output
1
99,422
23
198,845
Provide a correct Python 3 solution for this coding contest problem. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8
instruction
0
99,423
23
198,846
"Correct Solution: ``` h,w=map(int,input().split()) a,b=map(int,input().split()) x,y=h//a,w//b print((h*w)-(x*a*y*b)) ```
output
1
99,423
23
198,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8 Submitted Solution: ``` h,w = map(int,input().split()) a,b = map(int,input().split()) print(h*w - (h//a)*a*(w//b)*b) ```
instruction
0
99,424
23
198,848
Yes
output
1
99,424
23
198,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8 Submitted Solution: ``` # /usr/bin/python # -*- coding: utf-8 -*- import sys h,w = map(int, input().split()) a,b = map(int, input().split()) print(h*w - (h//a*a) * (w//b*b)) ```
instruction
0
99,425
23
198,850
Yes
output
1
99,425
23
198,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8 Submitted Solution: ``` h, w = map(int, input().split()) a, b = map(int, input().split()) print(h*w-(h//a)*(w//b)*a*b) ```
instruction
0
99,426
23
198,852
Yes
output
1
99,426
23
198,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge of the tile is parallel or perpendicular to any edge of the wall. * Do not change the orientation of the tiles, that is, do not swap the vertical and horizontal directions. When as many tiles as possible are pasted, find the sum of the areas not covered by the tiles. output Output the total area of ​​the part not covered by the tile. Also, output a line break at the end. Example Input 5 8 2 2 Output 8 Submitted Solution: ``` #!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A h,w = LI() a,b = LI() y = h//a x = w//b ans = h*w-a*y*b*x print(ans) #B """ def m(x,y): if x == y: return "T" if x == "F": return "T" return "F" n = I() p = input().split() ans = p[0] for i in range(1,n): ans = m(ans,p[i]) print(ans) """ #C """ s = [[1]*8 for i in range(4)] for i in range(4): s.insert(2*i,[1,0,1,0,1,0,1,0]) for j in range(8): for i in range(1,8): s[j][i] += s[j][i-1] for j in range(8): for i in range(1,8): s[i][j] += s[i-1][j] s.insert(0,[0,0,0,0,0,0,0,0,0]) for i in range(1,9): s[i].insert(0,0) q = I() for _ in range(q): a,b,c,d = LI() print(s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]) """ #D """ n = I() a = LI() dp = [float("inf") for i in range(n)] b = [[] for i in range(n)] ind = [0 for i in range(100001)] for i in range(n): k = bisect.bisect_left(dp,a[i]) dp[k] = a[i] b[k].append(a[i]) ind[a[i]] = max(i,ind[a[i]]) for i in range(n): if dp[i] == float("inf"):break b[i].sort() b[i] = b[i][::-1] i -= 1 ans = b[i][0] now_ind = ind[b[i][0]] now_v = b[i][0] while i >= 0: for j in b[i]: if ind[j] < now_ind and j < now_v: ans += j now_ind = ind[j] now_v = j i -= 1 print(ans) """ #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T ```
instruction
0
99,427
23
198,854
Yes
output
1
99,427
23
198,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task... There are n non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the OX axis. You can choose an arbitrary vector (a, b), where b < 0 and coordinates are real numbers, and project all segments to OX axis along this vector. The projections shouldn't intersect but may touch each other. Find the minimum possible difference between x coordinate of the right end of the rightmost projection and x coordinate of the left end of the leftmost projection. Input The first line contains the single integer n (1 ≤ n ≤ 2000) — the number of segments. The i-th of the next n lines contains three integers xl_i, xr_i and y_i (-10^6 ≤ xl_i < xr_i ≤ 10^6; 1 ≤ y_i ≤ 10^6) — coordinates of the corresponding segment. It's guaranteed that the segments don't intersect or touch. Output Print the minimum possible difference you can get. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, if your answer is a and jury's answer is b then your answer will be considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Examples Input 3 1 6 2 4 6 4 4 6 6 Output 9.000000000 Input 3 2 5 1 4 6 4 7 8 2 Output 6.333333333 Input 2 1 3 1 4 7 1 Output 6.000000000 Note In the first example if we project segments along the vector (1, -1) then we get an answer 12-3=9 and (it can be proven) it is impossible to get less. <image> It is optimal to project along the vector (1, -3) in the second example. The answer is 82/3-21/3=61/3 <image> Submitted Solution: ``` t=int(input()) for i in range(t): lis=list(map(int,input().split())) ```
instruction
0
99,610
23
199,220
No
output
1
99,610
23
199,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task... There are n non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the OX axis. You can choose an arbitrary vector (a, b), where b < 0 and coordinates are real numbers, and project all segments to OX axis along this vector. The projections shouldn't intersect but may touch each other. Find the minimum possible difference between x coordinate of the right end of the rightmost projection and x coordinate of the left end of the leftmost projection. Input The first line contains the single integer n (1 ≤ n ≤ 2000) — the number of segments. The i-th of the next n lines contains three integers xl_i, xr_i and y_i (-10^6 ≤ xl_i < xr_i ≤ 10^6; 1 ≤ y_i ≤ 10^6) — coordinates of the corresponding segment. It's guaranteed that the segments don't intersect or touch. Output Print the minimum possible difference you can get. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, if your answer is a and jury's answer is b then your answer will be considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Examples Input 3 1 6 2 4 6 4 4 6 6 Output 9.000000000 Input 3 2 5 1 4 6 4 7 8 2 Output 6.333333333 Input 2 1 3 1 4 7 1 Output 6.000000000 Note In the first example if we project segments along the vector (1, -1) then we get an answer 12-3=9 and (it can be proven) it is impossible to get less. <image> It is optimal to project along the vector (1, -3) in the second example. The answer is 82/3-21/3=61/3 <image> Submitted Solution: ``` import sys from collections import deque readline = sys.stdin.buffer.readline ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) def solve(): n = ni() l = [tuple(nm()) for _ in range(n)] pl = list() mi = list() eps = 10**-7 for i in range(n-1): for j in range(i+1, n): a, b, c = l[i] d, e, f = l[j] if c == f: continue if c > f: a, b, c, d, e, f = d, e, f, a, b, c u = (a - e) / (f - c) v = (b - d) / (f - c) if u >= 0.0: pl.append((u, v, b-d, f-c)) elif v <= 0.0: mi.append((-v, -u, a-e, f-c)) else: pl.append((0.0, v, b-d, f-c)) mi.append((0.0, -u, a-e, f-c)) pl.sort() mi.sort() # print(pl, mi, sep='\n') cpl = cmi = 0.0 qpl, ppl, qmi, pmi = 1, 0, 1, 0 for u, v, p, q in pl: if cpl < u - eps: break cpl = v ppl, qpl = p, q for u, v, p, q in mi: if cmi < u - eps: break cmi = v pmi, qmi = p, q # print(qpl, ppl, qmi, pmi) def calc(p, q): cma, cmi = -10**18, 10**18 for xl, xr, y in l: ri = xr + p * y / q le = xl + p * y / q if ri > cma: cma = ri if le < cmi: cmi = le return cma - cmi print(min(calc(ppl, qpl), calc(pmi, qmi))) return solve() # T = ni() # for _ in range(T): # solve() ```
instruction
0
99,611
23
199,222
No
output
1
99,611
23
199,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task... There are n non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the OX axis. You can choose an arbitrary vector (a, b), where b < 0 and coordinates are real numbers, and project all segments to OX axis along this vector. The projections shouldn't intersect but may touch each other. Find the minimum possible difference between x coordinate of the right end of the rightmost projection and x coordinate of the left end of the leftmost projection. Input The first line contains the single integer n (1 ≤ n ≤ 2000) — the number of segments. The i-th of the next n lines contains three integers xl_i, xr_i and y_i (-10^6 ≤ xl_i < xr_i ≤ 10^6; 1 ≤ y_i ≤ 10^6) — coordinates of the corresponding segment. It's guaranteed that the segments don't intersect or touch. Output Print the minimum possible difference you can get. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, if your answer is a and jury's answer is b then your answer will be considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Examples Input 3 1 6 2 4 6 4 4 6 6 Output 9.000000000 Input 3 2 5 1 4 6 4 7 8 2 Output 6.333333333 Input 2 1 3 1 4 7 1 Output 6.000000000 Note In the first example if we project segments along the vector (1, -1) then we get an answer 12-3=9 and (it can be proven) it is impossible to get less. <image> It is optimal to project along the vector (1, -3) in the second example. The answer is 82/3-21/3=61/3 <image> Submitted Solution: ``` from sys import stdin import math import sys n = int(stdin.readline()) lry = [] for loop in range(n): xl,xr,y = map(int,stdin.readline().split()) lry.append((xl,xr,y)) flag = True minl = float("inf") maxr = float("-inf") for i in range(n): for j in range(i): Li,Ri,Yi = lry[i] Lj,Rj,Yj = lry[j] if Lj >= Ri or Li >= Rj: minl = min(Li,Lj,minl) maxr = max(Ri,Rj,maxr) else: flag = False if flag: print (maxr-minl) sys.exit() lis = [] cnt = 0 for i in range(n): for j in range(n): Li,Ri,Yi = lry[i] Lj,Rj,Yj = lry[j] if Yi <= Yj: continue #L vecA = (Lj-Li,Yj-Yi) vecB = (Rj-Li,Yj-Yi) lis.append( (math.atan2(vecA[1],vecA[0]) ,1, vecA[0] , vecA[1] , cnt) ) lis.append( (math.atan2(vecB[1],vecB[0]) ,1, vecB[0] , vecB[1] , cnt) ) cnt += 1 #R vecA = (Lj-Ri,Yj-Yi) vecB = (Rj-Ri,Yj-Yi) lis.append( (math.atan2(vecA[1],vecA[0]) ,0, vecA[0] , vecA[1] , cnt) ) lis.append( (math.atan2(vecB[1],vecB[0]) ,0, vecB[0] , vecB[1] , cnt) ) cnt += 1 #imos lis.sort() use = [True] * cnt ctt = 0 #print (lis) ans = float("inf") for i in range(len(lis)): at,gomi,x,y,c = lis[i] if ctt == 0: nmin = float("inf") nmax = float("-inf") for txl,txr,ty in lry: lastxl = txl + x * (ty/(abs(y))) nmin = min(nmin , lastxl) lastxr = txr + x * (ty/(abs(y))) nmax = max(nmax , lastxr) ans = min(ans , nmax - nmin) if use[c]: use[c] = False ctt += 1 else: use[c] = True ctt -= 1 if ctt == 0: nmin = float("inf") nmax = float("-inf") for txl,txr,ty in lry: lastxl = txl + x * (ty/(abs(y))) nmin = min(nmin , lastxl) lastxr = txr + x * (ty/(abs(y))) nmax = max(nmax , lastxr) ans = min(ans , nmax - nmin) print (ans) ```
instruction
0
99,612
23
199,224
No
output
1
99,612
23
199,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task... There are n non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the OX axis. You can choose an arbitrary vector (a, b), where b < 0 and coordinates are real numbers, and project all segments to OX axis along this vector. The projections shouldn't intersect but may touch each other. Find the minimum possible difference between x coordinate of the right end of the rightmost projection and x coordinate of the left end of the leftmost projection. Input The first line contains the single integer n (1 ≤ n ≤ 2000) — the number of segments. The i-th of the next n lines contains three integers xl_i, xr_i and y_i (-10^6 ≤ xl_i < xr_i ≤ 10^6; 1 ≤ y_i ≤ 10^6) — coordinates of the corresponding segment. It's guaranteed that the segments don't intersect or touch. Output Print the minimum possible difference you can get. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}. Formally, if your answer is a and jury's answer is b then your answer will be considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}. Examples Input 3 1 6 2 4 6 4 4 6 6 Output 9.000000000 Input 3 2 5 1 4 6 4 7 8 2 Output 6.333333333 Input 2 1 3 1 4 7 1 Output 6.000000000 Note In the first example if we project segments along the vector (1, -1) then we get an answer 12-3=9 and (it can be proven) it is impossible to get less. <image> It is optimal to project along the vector (1, -3) in the second example. The answer is 82/3-21/3=61/3 <image> Submitted Solution: ``` def compute(l): ms = [1, 0] sll = [] for i in range(len(l)): for j in range(i+1, len(l)): if l[i][2] > l[j][2]: ts, te, ty = map(float, l[i]) ss, se, sy = map(float, l[j]) else: ts, te, ty = map(float, l[j]) ss, se, sy = map(float, l[i]) sly = ty-sy slx = ts-se if sly > 0: if te > ss: if slx < 0 and sly > 0: if ms[1] == 0 or -sly/slx < ms[0]/ms[1]: ms = [sly, -slx] elif te == ss: sll.append([-sly/slx, 10**100, sly, -slx, 1, 0]) else: sll.append([-sly/slx, (ty-sy)/(ss-te), sly, -slx, ty-sy, ss-te]) sll = list(sorted(sll))[::-1] for i in sll: if ms[1] != 0 and ms[0]/ms[1] < i[1]: if ms[0]/ms[1] > i[0]: ms = [i[4], i[5]] start = 10**100 end = -10**100 for i in l: coords = [i[0], i[2]] if ms == "inf": si = i[0] ei = i[1] else: si = i[0]+i[2]*ms[1]/ms[0] ei = i[1]+i[2]*ms[1]/ms[0] start = min(start, si) end = max(end, ei) return start, end n = int(input()) l = [] l1 = [] for i in range(n): new = list(map(int, input().split())) l.append(new) new1 = [-new[1], -new[0], new[2]] l1.append(new1) x1, x2 = compute(l) x3, x4 = compute(l1) print(min(x4-x3, x2-x1)) ```
instruction
0
99,613
23
199,226
No
output
1
99,613
23
199,227
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,646
23
199,292
Tags: greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) left_most = [n] * 10 right_most = [-1] * 10 up_most = [n] * 10 down_most = [-1] * 10 field = [] rotated = [] ans = [0] * 10 hs = [max(n-1-i, i) for i in range(n)] for j in range(n): line = [int(ch) for ch in input().rstrip()] field.append(line) for j, line in enumerate(field): l = [None] * 10 m_base = [0] * 10 for i, item in enumerate(line): if l[item] != None: m_base[item] = i - l[item] else: l[item] = i if left_most[item] > i: left_most[item] = i if right_most[item] < i: right_most[item] = i if up_most[item] > j: up_most[item] = j if down_most[item] < j: down_most[item] = j for i, item in enumerate(m_base): ans[i] = max(ans[i], item * hs[j]) for i, line in enumerate(field): for j, item in enumerate(line): # Use updown base1 = max(n - 1 - i, i) max_h1 = max(right_most[item] - j, j - left_most[item]) # Use leftright base2 = max(n - 1 - j, j) max_h2 = max(down_most[item] - i, i - up_most[item]) ans[item] = max(ans[item], base1 * max_h1, base2 * max_h2) for col in zip(*field): rotated.append(list(col)) for j, line in enumerate(field): l = [None] * 10 m_base = [0] * 10 for i, item in enumerate(line): if l[item] != None: m_base[item] = i - l[item] else: l[item] = i for i, item in enumerate(m_base): ans[i] = max(ans[i], item * hs[j]) print(*ans) ```
output
1
99,646
23
199,293
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,647
23
199,294
Tags: greedy, implementation Correct Solution: ``` t = int(input()) while t: t -= 1 n = int(input()) a = [] for _ in range(n): a.append(input()) for d in range(10): minrow, maxrow, ans = 20000, 0, 0 mincol, maxcol = 20000, 0 for i in range(n): for j in range(n): if a[i][j] == str(d): minrow = min(minrow, i+1) maxrow = max(maxrow, i+1) mincol = min(mincol, j+1) maxcol = max(maxcol, j+1) # print(maxrow, maxcol, minrow, mincol) for i in range(n): for j in range(n): if a[i][j] == str(d): hb, hh = max(j, n-j-1), max(maxrow-i-1, i-minrow+1) vb, vh = max(i, n-i-1), max(maxcol-j-1, j-mincol+1) # print(hb, hh, vb, vh, i-mincol+1) ans = max(ans, hb*hh, vb*vh) print(ans, end=' ') print() ```
output
1
99,647
23
199,295
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,648
23
199,296
Tags: greedy, implementation Correct Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) dd = [[] for _ in range(10)] for i in range(n): s = input() for j in range(n): dd[int(s[j])].append((i,j)) result = [0]*10 for d in range(10): if len(dd[d])<2: continue if len(dd[d])==2: i1,j1 = dd[d][0] i2,j2 = dd[d][1] area = abs(i1-i2)*(max(j1,n-1-j1,j2,n-1-j2)) area = max(area, abs(j1-j2)*max(i1,i2,n-1-i1,n-1-i2)) result[d]=area else: imn = n imx = 0 jmn = n jmx = 0 for i,j in dd[d]: if i<imn: imn=i if i>imx: imx = i if j<jmn: jmn=j if j>jmx: jmx = j area = 0 for i,j in dd[d]: l = max(i,n-1-i) area = max(area,l * max(jmx-j,j-jmn)) l = max(j,n-1-j) area = max(area,l*max(imx-i,i-imn)) result[d]=area print(*result) ```
output
1
99,648
23
199,297
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,649
23
199,298
Tags: greedy, implementation Correct Solution: ``` from __future__ import division, print_function import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def main(): t=int(input()) while(t): t-=1 n=int(input()) r=[] for i in range(n): s=input().rstrip() r.append(s) tb={str(i):-1 for i in range(10)} bt={str(i):-1 for i in range(10)} lr={str(i):-1 for i in range(10)} rl={str(i):-1 for i in range(10)} ro={str(j): [ [] for i in range(n) ] for j in range(10)} co={str(j): [ [] for i in range(n) ] for j in range(10)} for i in range(n): for j in range(n): z=r[i][j] if(tb[z]==-1): tb[z]=i if(bt[r[n-i-1][j]]==-1): bt[r[n-i-1][j]]=n-i-1 for i in range(n): for j in range(n): z=r[j][i] if(lr[z]==-1): lr[z]=i if(rl[r[j][n-i-1]]==-1): rl[r[j][n-i-1]]=n-i-1 for i in range(n): for j in range(n): z=r[i][j] ro[z][i].append(i) co[z][j].append(j) re=[0 for i in range(10)] for i in range(1): for j in range(n): for k in range(n): z=r[j][k] try: c1=abs(j-ro[z][j][0])*(n-1) except: c1=0 try: c2=abs(j-ro[z][j][-1])*(n-1) except: c2=0 if(bt[z]!=-1): c3=max(abs(k-(n-1)),abs(k))*(abs(j-bt[z])) else: c3=0 if(tb[z]!=-1): c4=max(abs(k-0),abs(k-n+1))*(abs(j-tb[z])) else: c4=0 if(lr[z]!=-1): c5=max(abs(j-n+1),abs(j))*abs(k-lr[z]) else: c5=0 if(rl[z]!=-1): c6=max(abs(j-0),abs(j-n+1))*abs(k-rl[z]) else: c6=0 try: c7=abs(k-co[z][k][0])*(n-1) except: c7=0 try: c8=abs(k-co[z][k][-1])*(n-1) except: c8=0 re[int(z)]=max(re[int(z)],c1,c2,c3,c4,c5,c6,c7,c8) print(*re) 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
99,649
23
199,299
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,650
23
199,300
Tags: greedy, implementation Correct Solution: ``` def findTriangles(n, rows): minRow = [n-1]*10 maxRow = [0]*10 minCol = [n-1]*10 maxCol = [0]*10 maxArea = [0]*10 for i in range(n): for j in range(n): minCol[grid[i][j]] = min(minCol[grid[i][j]], j) minRow[grid[i][j]] = min(minRow[grid[i][j]], i) maxCol[grid[i][j]] = max(maxCol[grid[i][j]], j) maxRow[grid[i][j]] = max(maxRow[grid[i][j]], i) # print(minRow) # print(maxRow) # print(minCol) # print(maxCol) for i in range(n): for j in range(n): maxArea[grid[i][j]] = max( maxArea[grid[i][j]], max(i-0,n-1-i)*max(maxCol[grid[i][j]]-j, j-minCol[grid[i][j]]), max(j-0,n-1-j)*max(maxRow[grid[i][j]]-i, i-minRow[grid[i][j]]) ) # print(i,j,maxArea) return maxArea t = int(input()) for i in range(t): n = int(input()) grid = [] for j in range(n): row = input() grid.append(list(map(int, list(row)))) print(*findTriangles(n,grid)) ```
output
1
99,650
23
199,301
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,651
23
199,302
Tags: greedy, implementation Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=10**10, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD #------------------------------------------------------------------------- for _ in range (int(input())): n=int(input()) a=list() row=[[[0 for k in range (10)] for i in range (2)]for j in range (n)] col=[[[0 for k in range (10)] for i in range (2)]for j in range (n)] for i in range (n): a.append(input()) arr=[0]*(10) for j in range (n): num=ord(a[i][j])-48 if arr[num]==0: row[i][0][num]=j+1 row[i][1][num]=j+1 arr[num]=1 for j in range (n): arr=[0]*(10) for i in range (n): num=ord(a[i][j])-48 if arr[num]==0: col[j][0][num]=i+1 col[j][1][num]=i+1 arr[num]=1 res=[0]*(10) #print(row,col) for el in range (10): #print("el",el) for i in range (n): d=0 d1=0 for j in range (n): if row[i][0][el]!=0 and row[j][0][el]!=0: d=max(d,abs(j-i)) if col[i][0][el]!=0 and col[j][0][el]!=0: d1=max(d1,abs(j-i)) c1=(row[i][1][el]-row[i][0][el])*(n-i-1) c2=(row[i][1][el]-row[i][0][el])*(i) c3=d*max(row[i][0][el]-1,n-row[i][0][el]) c4=d*max(row[i][1][el]-1,n-row[i][1][el]) res[el]=max(res[el],c1,c2,c3,c4) #print(row[i][0][el],row[i][1][el],d,c1,c2,c3,c4) c1=(col[i][1][el]-col[i][0][el])*(n-i-1) c2=(col[i][1][el]-col[i][0][el])*(i) c3=d1*max(col[i][0][el]-1,n-col[i][0][el]) c4=d1*max(col[i][1][el]-1,n-col[i][1][el]) res[el]=max(res[el],c1,c2,c3,c4) #print(col[i][0][el],col[i][1][el],d,c1,c2,c3,c4) print(*res) ```
output
1
99,651
23
199,303
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,652
23
199,304
Tags: greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 import io import os import sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def printd(*args, **kwargs): #print(*args, **kwargs, file=sys.stderr) #print(*args, **kwargs) pass def get_str(): return input().decode().strip() def rint(): return map(int, input().split()) def oint(): return int(input()) t = oint() for _ in range(t): n = oint() mat = [[] for _ in range(n)] for i in range(n): mat[i] = list(map(int, get_str())) printd(mat) top = [2001] * 10 bot = [-1] * 10 left = [2001] * 10 right = [-1] * 10 for r in range(n): for c in range(n): d = mat[r][c] if top[d] > r: top[d] = r if bot[d] < r: bot[d] = r if left[d] > c: left[d] = c if right[d] < c: right[d] = c ans = [0]*10 for r in range(n): for c in range(n): d = mat[r][c] ans[d] = max(ans[d], max(c-left[d], right[d]-c) * max(r, n-1-r)) ans[d] = max(ans[d], max(r- top[d], bot[d]-r) * max(c, n-1-c)) print(*ans) ```
output
1
99,652
23
199,305
Provide tags and a correct Python 3 solution for this coding contest problem. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.
instruction
0
99,653
23
199,306
Tags: greedy, implementation Correct Solution: ``` t = int(input()) def calculate(d, last_rows, last_cols, a): ans = 0 # print("-" * 1000) # print(d) for i in range(0, len(a)): x = [] # print("-" * 100) # print(i) for j in range(0, len(a)): if a[i][j] == d: x.append(j) # print(x) if x: ans = max(abs(last_rows[d][0] - i) * max(abs(last_rows[d][1] - (len(a) - 1)), last_rows[d][1]), ans) ans = max(abs(first_rows[d][0] - i) * max(abs(first_rows[d][1] - (len(a) - 1)), first_rows[d][1]), ans) if len(x) == 1: ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(last_rows[d][0] - i), ans) ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(first_rows[d][0] - i), ans) elif len(x) > 1: ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(last_rows[d][0] - i), ans) ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(first_rows[d][0] - i), ans) ans = max(abs(x[0] - x[-1]) * max(abs(n - 1 - i), i), ans) ans = max(max(abs(x[0] - (len(a) - 1)), abs(x[0])) * abs(last_rows[d][0] - i), ans) ans = max(max(abs(x[-1] - (len(a) - 1)), abs(x[-1])) * abs(last_rows[d][0] - i), ans) ans = max(max(abs(x[0] - (len(a) - 1)), abs(x[0])) * abs(first_rows[d][0] - i), ans) ans = max(max(abs(x[-1] - (len(a) - 1)), abs(x[-1])) * abs(first_rows[d][0] - i), ans) # print(ans) for j in range(0, len(a)): x = [] for i in range(0, len(a)): if a[i][j] == d: x.append(i) if x: ans = max(abs(last_cols[d][0] - j) * max(abs(last_cols[d][1] - (len(a) - 1)), last_cols[d][1]), ans) ans = max(abs(first_cols[d][0] - j) * max(abs(first_cols[d][1] - (len(a) - 1)), first_cols[d][1]), ans) if len(x) == 1: ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(last_cols[d][0] - j), ans) ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(first_cols[d][0] - j), ans) elif len(x) > 1: ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(last_cols[d][0] - j), ans) ans = max(max(abs(x[0] - (len(a) - 1)), x[0]) * abs(first_cols[d][0] - j), ans) ans = max(abs(x[0] - x[-1]) * max(abs(n - 1 - j), j), ans) ans = max(max(abs(x[0] - (len(a) - 1)), abs(x[0])) * abs(last_cols[d][0] - j), ans) ans = max(max(abs(x[-1] - (len(a) - 1)), abs(x[-1])) * abs(last_cols[d][0] - j), ans) ans = max(max(abs(x[0] - (len(a) - 1)), abs(x[0])) * abs(first_cols[d][0] - j), ans) ans = max(max(abs(x[-1] - (len(a) - 1)), abs(x[-1])) * abs(first_cols[d][0] - j), ans) return ans for _ in range(t): n = int(input()) a = [] for i in range(0, n): a.append(list(map(int, list(input())))) last_cols = [(0, 0) for _ in range(10)] last_rows = [(0, 0) for _ in range(10)] first_cols = [(n, n) for _ in range(10)] first_rows = [(n, n) for _ in range(10)] for i in range(0, len(a)): for j in range(0, len(a)): if last_cols[a[i][j]][0] < j: last_cols[a[i][j]] = (j, i) if last_rows[a[i][j]][0] < i: last_rows[a[i][j]] = (i, j) if first_cols[a[i][j]][0] > j: first_cols[a[i][j]] = (j, i) if first_rows[a[i][j]][0] > i: first_rows[a[i][j]] = (i, j) # print(last_cols, last_rows) values = [0 for _ in range(10)] for i in range(0, 10): values[i] = calculate(i, last_rows, last_cols, a) print(*values) ```
output
1
99,653
23
199,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` def func(a, n): mxr = [-1]*10 mxc = [-1]*10 mnr = [n+25]*10 mnc = [n+25]*10 ans = [0]*10 for i in range(n): for j in range(n): x = a[i][j] mxr[x] = max(mxr[x], i) mxc[x] = max(mxc[x], j) mnc[x] = min(mnc[x], j) mnr[x] = min(mnr[x], i) for i in range(n): for j in range(n): x = a[i][j] ans[x] = max(ans[x], max(n-i-1, i) * max(j - mnc[x], mxc[x] - j)) ans[x] = max(ans[x], max(n - j - 1, j) * max(i - mnr[x], mxr[x] - i)) return ans for _ in range(int(input())): # n, m = [int(j) for j in input().split()] n = int(input()) # a = [int(j) for j in input().split()] # b = [int(j) for j in input().split()] a = [[] for i in range(n)] for i in range(n): s = input() for j in range(n): a[i].append(int(s[j])) # print(a) print(*func(a, n)) ```
instruction
0
99,654
23
199,308
Yes
output
1
99,654
23
199,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` import sys def choose_top(ddk, n): # choose top max bottom length -- or choose new top lns = [len(ddk[i]) for i in range(n)] if sum(lns) < 2: return 0 top = -1 rt = 0 for i in range(n): if lns[i]: top = i break for i in range(top + 1, n): if lns[i]: rt = max(rt, (i - top) * (n - 1 - ddk[i][0]), (i - top) * (ddk[i][-1])) for i in range(n-1, -1, -1): if lns[i] > 1: rt = max(rt, i * (ddk[i][-1] - ddk[i][0])) return rt def main(d, n): # print(n, d ) dd = [[[] for j in range(n)] for i in range(10)] for i in range(n): for j in range(n): # print(dd, i, j, d[i][j]) dd[d[i][j]][i].append(j) ret = [] for dig in range(10): ddk = dd[dig] ans_ = choose_top(ddk, n) ddk.reverse() ans_ = max(ans_, choose_top(ddk, n)) ret.append(ans_) return ret for tt in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) d = [[int(i) for i in sys.stdin.readline().strip()] for _ in range(n)] if n == 1: sys.stdout.write(' '.join('0' for i in range(10)) + '\n') continue # elif n == 2: # cnts = [0] * 10 # for i in range(2): # for j in range(2): # cnts[d[i][j]] += 1 # sys.stdout.write(' '.join(('1' if cnts[i] > 1 else '0') for i in range(10)) + '\n') # continue r1 = main(d, n) r2 = main([[d[j][i] for j in range(n)] for i in range(n)], n) sys.stdout.write(' '.join(str(max(r1[i], r2[i])) for i in range(10)) + '\n') ```
instruction
0
99,655
23
199,310
Yes
output
1
99,655
23
199,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` from sys import stdin input=stdin.readline for t in range(int(input().rstrip('\n'))): n=int(input().rstrip('\n')) l=[] for j in range(n): l.append(list(map(int,input().rstrip('\n')))) r=[[] for i in range(10)] lm,rm,tm,bm=[n-1]*10,[0]*10,[n-1]*10,[0]*10 for i in range(n): for j in range(n): lm[l[i][j]]=min(lm[l[i][j]],j) rm[l[i][j]]=max(rm[l[i][j]],j) tm[l[i][j]]=min(tm[l[i][j]],i) bm[l[i][j]]=max(bm[l[i][j]],i) r[l[i][j]].append([i,j]) ans=[0]*10 for i in range(10): for j in r[i]: ans[i]=max(ans[i],max(j[1],n-1-j[1])*max(abs(j[0]-tm[i]),abs(j[0]-bm[i])),max(j[0],n-1-j[0])*max(abs(j[1]-lm[i]),abs(j[1]-rm[i]))) print(*ans) ```
instruction
0
99,656
23
199,312
Yes
output
1
99,656
23
199,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def output(*args): sys.stdout.buffer.write( ('\n'.join(map(str, args)) + '\n').encode('utf-8') ) def main(): t = int(input()) ans_a = [''] * t for ti in range(t): n = int(input()) d_pos: Tp.List[Tp.List[Tp.Tuple[int]]] = [[(-1, -1) for _ in range(4)] for _ in range(10)] ans_d = [0] * 10 matrix = [list(map(int, input().rstrip())) for _ in range(n)] for y in range(n): for x, d in enumerate(matrix[y]): if d_pos[d][0][0] == -1 or d_pos[d][0][0] > y: d_pos[d][0] = (y, x) if d_pos[d][1][0] == -1 or d_pos[d][1][1] > x: d_pos[d][1] = (y, x) if d_pos[d][2][0] == -1 or d_pos[d][2][0] <= y: d_pos[d][2] = (y, x) if d_pos[d][3][0] == -1 or +d_pos[d][3][1] <= x: d_pos[d][3] = (y, x) for y in range(n): for x, d in enumerate(matrix[y]): for ty, tx in d_pos[d]: if ty != -1: ans_d[d] = max( ans_d[d], max(y, n - y - 1, ty, n - ty - 1) * abs(x - tx), abs(y - ty) * max(x, n - x - 1, tx, n - tx - 1) ) ans_a[ti] = ' '.join(map(str, ans_d)) output('\n'.join(map(str, ans_a))) if __name__ == '__main__': main() ```
instruction
0
99,657
23
199,314
Yes
output
1
99,657
23
199,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` """ usefull snippets: - map(int, input().split()) - map(int, sys.stdin.readline().split())) - int(input()) - int(sys.stdin.readline().strip()) - sys.stdout.write() - sys.stdout.write(" ".join(map(str, c) # writes c - collection of ints """ # import collections import sys import math from bisect import bisect_left from collections import defaultdict # recursion increase # sys.setrecursionlimit(10000) # number with big precision # from decimal import getcontext, Decimal # getcontext().prec = 34 # longest common prefix def get_lcp(s, suffix_array): s = s + "$" n = len(s) lcp = [0] * (n) pos = [0] * (n) for i in range(n - 1): pos[suffix_array[i]] = i k = 0 for i in range(n - 1): if k > 0: k -= 1 if pos[i] == n - 1: lcp[n - 1] = -1 k = 0 continue else: j = suffix_array[pos[i] + 1] while max([i + k, j + k]) < n and s[i + k] == s[j + k]: k += 1 lcp[pos[i]] = k return lcp def get_suffix_array(word): suffix_array = [("", len(word))] for position in range(len(word)): sliced = word[len(word) - position - 1 :] suffix_array.append((sliced, len(word) - position - 1)) suffix_array.sort(key=lambda x: x[0]) return [item[1] for item in suffix_array] def get_ints(): return map(int, sys.stdin.readline().strip().split()) def bin_search(collection, element): i = bisect_left(collection, element) if i != len(collection) and collection[i] == element: return i else: return -1 def main(): t = int(input()) for _ in range(t): n = int(input()) a = [] edge_minx = list() edge_maxx = list() edge_miny = list() edge_maxy = list() for i in range(n): a.append(str(input())) edge_minx.append(defaultdict(lambda: -1)) edge_maxx.append(defaultdict(lambda: -1)) edge_miny.append(defaultdict(lambda: -1)) edge_maxy.append(defaultdict(lambda: -1)) ans = defaultdict(int) for y in range(n): for x in range(n): d = int(a[y][x]) if edge_minx[y][d] == -1: edge_minx[y][d] = x if edge_miny[x][d] == -1: edge_miny[x][d] = y edge_maxx[y][d] = max(edge_maxx[y][d], x) edge_maxy[x][d] = max(edge_maxy[x][d], y) for i in range(n): for d in range(10): if 0 <= edge_minx[i][d] < edge_maxx[i][d]: ans[d] = max(ans[d], (edge_maxx[i][d] - edge_minx[i][d]) * max(i, n - 1 - i)) if 0 <= edge_miny[i][d] < edge_maxy[i][d]: ans[d] = max(ans[d], (edge_maxy[i][d] - edge_miny[i][d]) * max(i, n - 1 - i)) if 0 <= edge_minx[i][d]: l1 = max(edge_minx[i][d], n - 1 - edge_minx[i][d]) l2 = max(edge_maxx[i][d], n - 1 - edge_maxx[i][d]) l = max(l1, l2) ans[d] = max(ans[d], l * max(i - edge_miny[i][d], n - 1 - edge_maxy[i][d])) if 0 <= edge_miny[i][d]: l1 = max(edge_miny[i][d], n - 1 - edge_miny[i][d]) l2 = max(edge_maxy[i][d], n - 1 - edge_maxy[i][d]) l = max(l1, l2) ans[d] = max(ans[d], l * max(i - edge_minx[i][d], n - 1 - edge_maxx[i][d])) for d in range(10): print(ans[d], end=' ') print() if __name__ == "__main__": main() ```
instruction
0
99,658
23
199,316
No
output
1
99,658
23
199,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` ###pyrival template for fast IO import os import sys from io import BytesIO, IOBase # region fastio 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") t=int(input()) def func(a,b,n): rowdiff=abs(a[0]-b[0]) coldiff=abs(a[1]-b[1]) a1=max([a[0],(n-1-a[0]),b[0],(n-1-b[0])])*coldiff a2=max([b[1],(n-1-b[1]),a[1],(n-1-a[1])])*rowdiff return max(a1,a2) def app(x,a): if x not in a: a.append(x) while t>0: t-=1 n=int(input()) arr=[];maxi=(n-1)**2 dict={0:[],1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[]} area=[0 for x in range(0,10)] for i in range(n): a=input();b=[] for j in range(n): b.append(int(a[j])) dict[int(a[j])].append([i,j]) arr.append(b) for num,val in dict.items(): l=len(val) if l>1: a=[] rmin=val[0][0];rmax=val[-1][0] #for rowwise maxarea i=0;rmincolmax=-float("inf") while i<l: if val[i][0]==rmin: rmincolmax=max(rmincolmax,val[i][1]) else: break i+=1 i=l-1;rmaxcolmin=float("inf") while i>=0: if val[i][0]==rmax: rmaxcolmin=min(rmaxcolmin,val[i][1]) else: break i-=1 rmincolmin=val[0][1] rmaxcolmax=val[-1][1] cmin=float("inf");cmax=-float("inf") cminrowmin=float("inf");cmaxrowmax=-float("inf") cminrowmax=-float("inf");cmaxrowmin=float("inf") for i in range(l): cmin=min(cmin,val[i][1]) cmax=max(cmax,val[i][1]) for i in range(l): if val[i][1]==cmin: cminrowmax=max(cminrowmax,val[i][0]) cminrowmin=min(cminrowmin,val[i][0]) elif val[i][1]==cmax: cmaxrowmin=min(cmaxrowmin,val[i][0]) cmaxrowmax=max(cmaxrowmax,val[i][0]) app([rmin,rmincolmin],a) app([rmin,rmincolmax],a) app([rmax,rmaxcolmin],a) app([rmax,rmaxcolmax],a) app([cminrowmin,cmin],a) app([cminrowmax,cmin],a) app([cmaxrowmin,cmax],a) app([cmaxrowmax,cmax],a) for i in range(len(a)): for j in range(i+1,len(a)): area[num]=max(area[num],func(a[i],a[j],n)) print(*area) ```
instruction
0
99,659
23
199,318
No
output
1
99,659
23
199,319
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` t = int(input()) while t!=0: n = int(input()) list1 = [] for i in range(n): s = list(input()) list1.append(s) # print(list1) h = [[[-1,float('inf')],[-1,float('-inf')]] for i in range(10)] v = [[[float('inf'),-1],[float('-inf'),-1]] for i in range(10)] for i in range(n): for j in range(n): if h[int(list1[i][j])][0][1] > j: h[int(list1[i][j])][0][1] = j h[int(list1[i][j])][0][0] = i if h[int(list1[i][j])][1][1] < j: h[int(list1[i][j])][1][1] = j h[int(list1[i][j])][1][0] = i ans = 0 # print(h) # print(v) n-=1 fa = [0 for i in range(10)] # print(h[3]) # print(v[3]) for i in range(len(list1)): for j in range(len(list1[i])): pa = i pb = j a1 = h[int(list1[i][j])][0][0] b1 = h[int(list1[i][j])][0][1] a2 = h[int(list1[i][j])][1][0] b2 = h[int(list1[i][j])][1][1] temp = 0 temp = max(max(abs(pa - a1) * max((n - pb), (n - b1), max(b1, pb)), abs(pb - b1) * (max((n - a1), (n - pa), max(a1, pa)))), temp) temp = max(max(abs(a2 - pa) * max((n - pb), (n - b2), max(b2, pb)), abs(pb - b2) * (max((n - a2), (n - pa), max(a2, pa)))), temp) # if int(list1[i][j])==2: # print(temp,i,j,pa,pb,a1,b1,a2) # if int(list1[i][j])==2: # print(temp,i,j) fa[int(list1[i][j])] = max(temp,fa[int(list1[i][j])]) # # for i in range(len(h)): # a1 = h[i][0][0] # b1 = h[i][0][1] # a2 = h[i][1][0] # b2 = h[i][1][1] # # temp = 0 # # if a1==float('inf') or a2==float('-inf'): # pass # else: # temp = max(max(abs(a2-a1)*max((n-b2),(n-b1),max(b1,b2)), abs(b2-b1)*(max((n-a1),(n-a2),max(a1,a2)))),temp) # # print("sgsdj",temp) # # a1 = v[i][0][0] # b1 = v[i][0][1] # a2 = v[i][1][0] # b2 = v[i][1][1] # # if a1 == float('inf') or a2 == float('-inf'): # pass # else: # # print("here->",max(abs(a2 - a1) * max((n - b2), (n - b1)), abs(b2 - b1) * (max((n - a1), (n - a2))))) # # temp = max(max(abs(a2-a1)*max((n-b2),(n-b1),max(b1,b2)), abs(b2-b1)*(max((n-a1),(n-a2),max(a1,a2)))),temp) # # # # # # # fa.append(temp) print(*fa) # # print(v) # t-=1 ```
instruction
0
99,660
23
199,320
No
output
1
99,660
23
199,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gildong has a square board consisting of n rows and n columns of square cells, each consisting of a single digit (from 0 to 9). The cell at the j-th column of the i-th row can be represented as (i, j), and the length of the side of each cell is 1. Gildong likes big things, so for each digit d, he wants to find a triangle such that: * Each vertex of the triangle is in the center of a cell. * The digit of every vertex of the triangle is d. * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length 0 is parallel to both sides of the board. * The area of the triangle is maximized. Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit d, he's going to change the digit of exactly one cell of the board to d, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit. Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be 0. Also, note that he is allowed to change the digit of a cell from d to d. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). The first line of each test case contains one integer n (1 ≤ n ≤ 2000) — the number of rows and columns of the board. The next n lines of each test case each contain a string of n digits without spaces. The j-th digit of the i-th line is the digit of the cell at (i, j). Each digit is one of the characters from 0 to 9. It is guaranteed that the sum of n^2 in all test cases doesn't exceed 4 ⋅ 10^6. Output For each test case, print one line with 10 integers. The i-th integer is the maximum area of triangle Gildong can make when d = i-1, multiplied by 2. Example Input 5 3 000 122 001 2 57 75 4 0123 4012 3401 2340 1 9 8 42987101 98289412 38949562 87599023 92834718 83917348 19823743 38947912 Output 4 4 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 9 6 9 9 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 49 49 49 49 15 0 30 42 42 Note In the first case, for d=0, no matter which cell he chooses to use, the triangle with vertices at (1, 1), (1, 3), and (3, 1) is the biggest triangle with area of \cfrac{2 ⋅ 2}{2} = 2. Since we should print it multiplied by 2, the answer for d=0 is 4. For d=1, Gildong can change the digit of the cell at (1, 3) into 1, making a triangle with vertices on all three 1's that has an area of 2. For d=2, Gildong can change the digit of one of the following six cells into 2 to make a triangle with an area of \cfrac{1}{2}: (1, 1), (1, 2), (1, 3), (3, 1), (3, 2), and (3, 3). For the remaining digits (from 3 to 9), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of 0. In the third case, for d=4, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at (1, 4) and use it along with the cells at (2, 1) and (4, 3), but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board. Submitted Solution: ``` #!/usr/bin/env python3 # created : 2020. 12. 31. 23:59 import os from sys import stdin, stdout def solve(tc): n = int(stdin.readline().strip()) mat = [[] for i in range(n)] for i in range(n): mat[i] = list(stdin.readline().strip()) cell = [[] for i in range(10)] for i in range(n): for j in range(n): val = int(ord(mat[i][j])-ord('0')) cell[val].append([i, j]) ans = [0 for i in range(10)] for i in range(10): if len(cell[i]) < 2: continue top, bottom = [-1, -1], [-1, -1] left, right = [-1, -1], [-1, -1] tv, bv = n+1, -1 lv, rv = n+1, -1 for j in range(len(cell[i])): if tv > cell[i][j][0]: tv = cell[i][j][0] top = [j, j] elif tv == cell[i][j][0]: top[1] = j if bv < cell[i][j][0]: bv = cell[i][j][0] bottom = [j, j] elif bv == cell[i][j][0]: bottom[1] = j if lv > cell[i][j][1]: lv = cell[i][j][1] left = [j, j] elif lv == cell[i][j][1]: left[1] = j if rv < cell[i][j][1]: rv = cell[i][j][1] right = [j, j] elif rv == cell[i][j][1]: right[1] = j dy = abs(cell[i][top[0]][0] - cell[i][bottom[0]][0]) dx = max(cell[i][top[0]][1], n-1-cell[i][top[0]][1]) dx = max(dx, max(cell[i][top[1]][1], n-1-cell[i][top[1]][1])) dx = max(dx, max(cell[i][bottom[0]][1], n-1-cell[i][bottom[0]][1])) dx = max(dx, max(cell[i][bottom[1]][1], n-1-cell[i][bottom[1]][1])) ans[i] = max(ans[i], dy*dx) dx = abs(cell[i][left[0]][1] - cell[i][right[0]][1]) dy = max(cell[i][left[0]][0], n-1-cell[i][left[0]][0]) dy = max(dy, max(cell[i][left[1]][0], n-1-cell[i][left[1]][0])) dy = max(dy, max(cell[i][right[0]][0], n-1-cell[i][right[0]][0])) dy = max(dy, max(cell[i][right[1]][0], n-1-cell[i][right[1]][0])) ans[i] = max(ans[i], dy*dx) print(*ans) tcs = 1 tcs = int(stdin.readline().strip()) tc = 1 while tc <= tcs: solve(tc) tc += 1 ```
instruction
0
99,661
23
199,322
No
output
1
99,661
23
199,323
Provide a correct Python 3 solution for this coding contest problem. The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants. The magic square is a matrix of size n × n. The elements of this matrix are integers. The sum of numbers in each row of the matrix is equal to some number s. The sum of numbers in each column of the matrix is also equal to s. In addition, the sum of the elements on the main diagonal is equal to s and the sum of elements on the secondary diagonal is equal to s. Examples of magic squares are given in the following figure: <image> Magic squares You are given a set of n2 integers ai. It is required to place these numbers into a square matrix of size n × n so that they form a magic square. Note that each number must occur in the matrix exactly the same number of times as it occurs in the original set. It is guaranteed that a solution exists! Input The first input line contains a single integer n. The next line contains n2 integers ai ( - 108 ≤ ai ≤ 108), separated by single spaces. The input limitations for getting 20 points are: * 1 ≤ n ≤ 3 The input limitations for getting 50 points are: * 1 ≤ n ≤ 4 * It is guaranteed that there are no more than 9 distinct numbers among ai. The input limitations for getting 100 points are: * 1 ≤ n ≤ 4 Output The first line of the output should contain a single integer s. In each of the following n lines print n integers, separated by spaces and describing the resulting magic square. In the resulting magic square the sums in the rows, columns and diagonals must be equal to s. If there are multiple solutions, you are allowed to print any of them. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 15 2 7 6 9 5 1 4 3 8 Input 3 1 0 -1 0 2 -1 -2 0 1 Output 0 1 0 -1 -2 0 2 1 0 -1 Input 2 5 5 5 5 Output 10 5 5 5 5
instruction
0
99,711
23
199,422
"Correct Solution: ``` import sys, random def f(b): global a a = [[0] * n for o in range(n)] for i in range(n): for j in range(n): a[i][j] = b[i * n + j] rez = 0 for i in range(n): ns = 0 for j in range(n): ns += a[i][j] rez += abs(su - ns) for j in range(n): ns = 0 for i in range(n): ns += a[i][j] rez += abs(su - ns) ns = 0 for i in range(n): ns += a[i][i] rez += abs(su - ns) ns = 0 for i in range(n): ns += a[i][n - i - 1] rez += abs(su - ns) return rez # sys.stdin = open("input.txt", 'r') input = sys.stdin.readline n = int(input()) d = list(map(int, input().split())) su = sum(d) // n p = f(d) while p: random.shuffle(d) p = f(d) for k in range(1000): i = random.randint(0, n*n-1) j = random.randint(0, n*n-1) while i == j: j = random.randint(0, n*n-1) if i > j: i, j = j, i d[i], d[j] = d[j], d[i] q = f(d) if q < p: p = q else: d[i], d[j] = d[j], d[i] p = f(d) print(su) for i in a: print(*i) ```
output
1
99,711
23
199,423
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,295
23
200,590
"Correct Solution: ``` A,B,C=map(int,input().split()) ANS=0 for i in [A,B,C]: if i%2==1: ANS+=1 if ANS>=2: print("Hom") else: print("Tem") ```
output
1
100,295
23
200,591
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,296
23
200,592
"Correct Solution: ``` # -*- coding: utf-8 -*- import sys from operator import itemgetter from fractions import gcd from math import ceil, floor, sqrt from copy import deepcopy from collections import Counter, deque import heapq from functools import reduce # local only # if not __debug__: # fin = open('in_1.txt', 'r') # sys.stdin = fin # local only sys.setrecursionlimit(200000) input = sys.stdin.readline def ii(): return int(input()) def mi(): return map(int, input().rstrip().split()) def lmi(): return list(map(int, input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None def exit(*arg): print(*arg); sys.exit() # template def main(): A, B, C = mi() if (A * B) % 2 == 0 and (B * C) % 2 == 0 and (C * A) % 2 == 0: print('Tem') else: print('Hom') if __name__ == '__main__': main() ```
output
1
100,296
23
200,593
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,297
23
200,594
"Correct Solution: ``` print('Hom' if sum(map(lambda x:int(x)%2, input().split())) > 1 else 'Tem') ```
output
1
100,297
23
200,595
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,298
23
200,596
"Correct Solution: ``` a, b, c = map(lambda x: int(x)%2, input().split()) if a + b + c >= 2: print("Hom") else: print("Tem") ```
output
1
100,298
23
200,597
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,299
23
200,598
"Correct Solution: ``` print("Hom" if sum([int(n)%2 for n in input().split()]) > 1 else "Tem") ```
output
1
100,299
23
200,599
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,300
23
200,600
"Correct Solution: ``` A, B, C = map(int, input().split()) count = 0 if A%2 == 1: count += 1 if B%2 == 1: count += 1 if C%2 == 1: count += 1 if count >= 2: print ('Hom') else: print ('Tem') ```
output
1
100,300
23
200,601
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,301
23
200,602
"Correct Solution: ``` print('Hom' if len(list(i for i in map(int, input().split()) if i % 2 == 1)) >= 2 else 'Tem') ```
output
1
100,301
23
200,603
Provide a correct Python 3 solution for this coding contest problem. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of cubic blocks with a side length of 1 without any gaps. Each side of all cubes and rectangular parallelepipeds is parallel to the x-axis, y-axis, or z-axis. Homura-chan and Tempura-kun alternately repeat the following operations. * Select a row of blocks of building blocks lined up in a row from a rectangular parallelepiped in any of the vertical, horizontal, and depth directions, and paint all the blocks included in the row in red. However, you cannot select columns that contain blocks that are already painted red. More precisely * Select one of the blocks contained in the rectangular parallelepiped and one of the three directions x, y, and z. * When the selected block is moved in the selected direction by an integer distance, all the blocks that completely overlap are painted in red (think of moving the distance of 0 or a negative integer). However, this operation cannot be performed if there is at least one block that meets the conditions and has already been painted. Homura-chan is the first player to lose the game if he can't operate it first. Also, initially all cubes are uncolored. Determine which one wins when the two act optimally. Input format A B C Constraint * 1 \ leq A, B, C \ leq 100 * All inputs are integers. Output format When the two act optimally, if Homura wins, `Hom` is output, and if Tempura wins,` Tem` is output on one line. Input example 1 1 1 10 Output example 1 Hom * The first time Homura can paint all the blocks red. Input example 2 4 3 5 Output example 2 Hom Input example 3 6 4 10 Output example 3 Tem Example Input 1 1 10 Output Hom
instruction
0
100,302
23
200,604
"Correct Solution: ``` a,b,c = map(int,input().split()) cnt = 0 if a %2 == 0: cnt += 1 if b %2 == 0: cnt += 1 if c %2 == 0: cnt += 1 if cnt >= 2: print('Tem') else: print('Hom') ```
output
1
100,302
23
200,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` n, m = map(int, input().split()) ans = 0 A = [input() for i in range(n)] for i in range(n - 1): for j in range(m - 1): if sorted(A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1]) == sorted("face"): ans += 1 print(ans) ```
instruction
0
100,729
23
201,458
Yes
output
1
100,729
23
201,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` n, m = [int(i) for i in input().split()] lines = [] res = 0 for i in range(n): lines.append(input().strip()) for x in range(n - 1): for y in range(m - 1): line = lines[x][y] + lines[x + 1][y] + lines[x][y + 1] + lines[x + 1][y + 1] if ('f' in line) and ('a' in line) and ('c' in line) and ('e' in line): res += 1 print(res) ```
instruction
0
100,730
23
201,460
Yes
output
1
100,730
23
201,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` a, b = map(int, input().split()) cases = a face = set("face") matrix = [] while cases: cases -= 1 s = list(input()) matrix.append(s) check = set() ans = 0 for row in range(len(matrix)): for col in range(len(matrix[0])): if matrix[row][col] in face: if row < len(matrix)-1 and col < len(matrix[0])-1: check.add(matrix[row][col]) check.add(matrix[row][col+1]) check.add(matrix[row+1][col]) check.add(matrix[row+1][col+1]) if check == face: ans += 1 check = set() print(ans) ```
instruction
0
100,731
23
201,462
Yes
output
1
100,731
23
201,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` a=input().split() per=input() answer=0 for j in range(int(a[0])-1): per1=input() for i in range(int(a[1])-1): A=set() A.add(per[i+1]) A.add(per[i]) A.add(per1[i]) A.add(per1[i+1]) if len(A)==4: answer +=1 per=per1 print((answer)) ```
instruction
0
100,732
23
201,464
No
output
1
100,732
23
201,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` n,m = map(int,input().split(' ')) l = [] res = 0 for i in range(n): col = list(input()) l.append(col) for i in range(n-1): for j in range(m-1): if l[i][j]!='x': if l[i+1][j]!='x' and l[i][j+1]!='x' and l[i+1][j+1]: res+=1 print(res) ```
instruction
0
100,733
23
201,466
No
output
1
100,733
23
201,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` n, m = input().split(' ') n = int(n) m = int(m) # print(n, m) f = 0 a = 0 c = 0 e = 0 # print(f, a, c, e) for i in range(n): str1 = input() # print(str1) for s in str1: # print(s) if s == 'f': f+=1 elif s == 'a': a+=1 elif s == 'c': c+=1 elif s == 'e': e+=1 else: continue # print(f, a, c, e) # print(f, a, c, e) print(max(f, a, c, e)) ```
instruction
0
100,734
23
201,468
No
output
1
100,734
23
201,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters. Output In the single line print the number of faces on the image. Examples Input 4 4 xxxx xfax xcex xxxx Output 1 Input 4 2 xx cf ae xx Output 1 Input 2 3 fac cef Output 2 Input 1 4 face Output 0 Note In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: <image> In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: <image> In the fourth sample the image has no faces on it. Submitted Solution: ``` def face_detection(): n, k = map(int, input().split()) arr = [] if n == 1: print(0) return for i in range(n): arr.append(list(input())) count = 0 m = [[False] * k] * n for i in range(n - 1): for j in range(k - 1): l = arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1] l = ''.join(sorted(l)) if l == 'acef' and ( m[i][j] & m[i + 1][j] & m[i][j + 1] & m[i + 1][j + 1] == False): m[i][j] = True m[i + 1][j] = True m[i][j + 1] = True m[i + 1][j + 1] = True count += 1 print(count) if __name__ == '__main__': face_detection() ```
instruction
0
100,735
23
201,470
No
output
1
100,735
23
201,471
Provide tags and a correct Python 3 solution for this coding contest problem. Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions. It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem. Input The first line of the input contains a single integer n (3 ≤ n ≤ 100 000). Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line. Output Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them. Examples Input 3 0 1 1 0 1 1 Output 1 2 3 Input 5 0 0 0 2 2 0 2 2 1 1 Output 1 3 5 Note In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. <image> Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
instruction
0
100,753
23
201,506
Tags: geometry, implementation Correct Solution: ``` def det(a,b,c): return (b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1]) n = int(input()) a = [] for i in range(1,n+1): x,y=map(int,input().split()) a.append([x,y,i]) a.sort(key=lambda x: (x[0],x[1])) for i in range(n-2): x = a[i] y = a[i+1] z = a[i+2] if not(det(x[:2],y[:2],z[:2]) == 0): break print(x[2],y[2],z[2]) ```
output
1
100,753
23
201,507