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
Provide a correct Python 3 solution for this coding contest problem. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9
instruction
0
54,759
23
109,518
"Correct Solution: ``` def main(): line = input() s1 = [] s2 = [] sum = 0 for i, s in enumerate(line): if s == "\\": # 谷の位置をスタックに積む s1.append(i) elif s == "/" and len(s1) > 0: # 山で対応する谷があるなら、面積に追加 j = s1.pop() sum += i - j # 谷から山の距離を水たまりの面積に追加 # jより前に位置する水たまりの面積を追加 a = i - j while len(s2) > 0 and s2[-1][0] > j: a += s2.pop()[1] # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む s2.append((j, a)) print(sum) print(len(s2), end="") for x in s2: print(f" {x[1]}", end="") print() if __name__ == "__main__": main() ```
output
1
54,759
23
109,519
Provide a correct Python 3 solution for this coding contest problem. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9
instruction
0
54,760
23
109,520
"Correct Solution: ``` l = input() stack1 = [] stack2 = [] all_area = 0 for val in range(len(l)): if l[val] == "\\": stack1.append(val) elif l[val] == "/" and stack1 != []: temp = stack1.pop(-1) all_area = all_area + (val - temp) each_area = val - temp while stack2 != [] and stack2[-1][0] > temp: each_area = each_area + stack2.pop(-1)[1] stack2.append([temp, each_area]) else: pass print(all_area) print(len(stack2), end="") for i in range(len(stack2)): print(" ", end="") print(stack2[i][1],end="") print("") ```
output
1
54,760
23
109,521
Provide a correct Python 3 solution for this coding contest problem. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9
instruction
0
54,761
23
109,522
"Correct Solution: ``` s = input() st1=[] st2=[] st3=[] n=len(s) lv = 0 total=0 for i in range(n): c=s[i] if c=='\\': lv-=1 st1.append(i) elif c=='/': lv+=1 if len(st1) > 0: a = i - st1.pop() total+=a tmp=0 while len(st2)>0 and st2[-1]<lv: st2.pop() tmp+=st3.pop() st3.append(a+tmp) st2.append(lv) elif len(st2) > 0: st2.pop() st2.append(lv) print(total) n = len(st3) print(n,end='') for i in range(n): print(' '+str(st3[i]),end='') print() ```
output
1
54,761
23
109,523
Provide a correct Python 3 solution for this coding contest problem. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9
instruction
0
54,762
23
109,524
"Correct Solution: ``` import collections import sys S1 = collections.deque() S2 = collections.deque() S3 = collections.deque() for i, j in enumerate(sys.stdin.readline()): if j == '\\': S1.append(i) elif j == '/': if S1: left_edge = S1.pop() new_puddle = i - left_edge while S2 and (S2[-1] > left_edge): S2.pop() new_puddle += S3.pop() S2.append(left_edge) S3.append(new_puddle) else: pass print(sum(S3)) print(len(S3), *S3) ```
output
1
54,762
23
109,525
Provide a correct Python 3 solution for this coding contest problem. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9
instruction
0
54,763
23
109,526
"Correct Solution: ``` s = 0 # プールの合計面積 # a は a[i] に i 番目の \ の初期位置からの距離を入れるためのスタック # b は b[i] に i 番目のプールの左岸(\)の初期位置からの距離を入れるためのスタック # d は d[i] に i 番目のプールの面積を入れるためのスタック a = [] b = [] d = [] for i, x in enumerate(input()): if x == '\\': a.append(i) elif x == '/' and a: j = a.pop() c = i - j s += c while b and b[-1] > j: b.pop() c += d.pop() b.append(j) d.append(c) print(s) print(len(b), *d) ```
output
1
54,763
23
109,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` a = input().strip() stack = [] area = 0 area_list = [] for i, slope in enumerate(a): if slope == '\\': stack.append(i) elif slope == '/' and len(stack) != 0: ip = stack.pop(len(stack)-1) area += (i - ip) a = i - ip while len(area_list) != 0 and area_list[len(area_list)-1][0] > ip: temp = area_list.pop(len(area_list)-1) a += temp[1] area_list.append([ip, a]) print(area) print('{}'.format(len(area_list)), end='') if len(area_list) != 0: print(' ', end='') print(' '.join([str(i[1]) for i in area_list])) ```
instruction
0
54,764
23
109,528
Yes
output
1
54,764
23
109,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` if __name__ == "__main__": inp = input() a = [] ans = [] total = 0 for i in range(len(inp)): if inp[i] == "\\": a.append(i) elif inp[i] == "/": if len(a) != 0: x = a.pop() d = i - x total += d while len(ans) != 0 and ans[-1][0] > x: d += ans[-1][1] ans.pop() ans.append([x, d]) print(total) if total == 0: print(0) else: print(str(len(ans))+" "+(" ".join(map(str, [x[1] for x in ans])))) ```
instruction
0
54,765
23
109,530
Yes
output
1
54,765
23
109,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` # coding: utf-8 from collections import deque input_line = input().strip() stack1, stack2 = deque(), deque() for index, i in enumerate(input_line): if i == "\\": stack1.append(index) elif i == "/" and len(stack1) != 0: a = stack1.pop() #池のマージ if len(stack2) != 0 and abs(stack2[-1][0] - a) == 1: stack2.append([a, index - a + stack2.pop()[1]]) else: stack2.append([a, index - a]) #さらにマージ while len(stack2) >= 2 and stack2[-1][0] < stack2[-2][0]: stack2.append([stack2[-1][0], stack2.pop()[1] + stack2.pop()[1]]) ans = [i[1] for i in stack2] print(sum(ans)) ans.insert(0, len(ans)) print(*ans) ```
instruction
0
54,766
23
109,532
Yes
output
1
54,766
23
109,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` def check(aline): pools = [] leftedge = [] for i, c in enumerate(aline): if c == "\\": leftedge.append(i) elif c == "_": pass else: if leftedge: left = leftedge.pop() w = i - left while pools and left < pools[-1][0]: w += pools.pop()[1] pools.append((left, w)) return pools if __name__ == '__main__': al = input().strip() ps = check(al) print(sum([x[1] for x in ps])) print(len(ps), *[x[1] for x in ps]) ```
instruction
0
54,767
23
109,534
Yes
output
1
54,767
23
109,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` li1 = [] li2 = [] for i, s in enumerate(input()): if s == "\\": li1.append(i) elif s == "/" and li1: j = li1.pop() c = i - j while li2 and li2[-1][0] > j: c += li2[-1][1] li2.pop() li2.append((j, c)) li3 = list(zip(*li2))[1] print(sum(li3)) print(len(li3), *li3) ```
instruction
0
54,768
23
109,536
No
output
1
54,768
23
109,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` def main(): """ ????????? """ S1 = [] # ????????????1(??????????????????) S2 = [] # ????????????2(??????????°´????????????????????¨??¢???) A = 0 # ?????¢??? inp = input() #inp = "\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\" for i in range(len(inp)): if inp[i] == chr(0x5c): # \ S1.append(i) S2.append([i,0]) elif inp[i] == chr(0x2f): # / if len(S1): j = S1.pop() d = i - j A += d k = d while len(S2): p = S2.pop() if p[1] > 0: k += p[1] else: S2.append([p[0],k]) break #print("[{}] {} A={} S1:{} S2:{}".format(i,inp[i],A,S1,S2)) L = [] for p in S2: if p[1] > 0: L.append(p[1]) print(A) print("{} {}".format(len(L)," ".join(map(str,L)))) if __name__ == '__main__': main() ```
instruction
0
54,769
23
109,538
No
output
1
54,769
23
109,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` #! python3 # areas_on_the_cross_section_diagram.py cross_section = input() cross_section_height = [0] for i in range(len(cross_section)): if cross_section[i] == '\\': cross_section_height.append(cross_section_height[i]-1) elif cross_section[i] == '_': cross_section_height.append(cross_section_height[i]) elif cross_section[i] == '/': cross_section_height.append(cross_section_height[i]+1) # 水たまりを探す # 左から探す puddles = [] width = len(cross_section_height) i = 0 while i < width-2: # i とペアとなる高さ is_down = False for j in range(i+1, width): if cross_section_height[j] > cross_section_height[i]: i += 1 break elif cross_section_height[j] < cross_section_height[i]: is_down = True else: if is_down: puddles.append([i, j]) i = j break if j == width-1: i += 1 # 面積の計算 puddle_areas = [] for start, end in puddles: area = 0 for i in range(start+1, end+1): if cross_section[i-1] == '_': area += cross_section_height[start] - cross_section_height[i] elif cross_section[i-1] == '/': area += cross_section_height[start] - cross_section_height[i] + 0.5 else: area +=cross_section_height[start] - cross_section_height[i] - 0.5 puddle_areas.append(int(area)) if len(puddle_areas) == 0: print("0\n0") else: print(sum(puddle_areas)) print(len(puddle_areas), ' '.join([str(x) for x in puddle_areas])) ```
instruction
0
54,770
23
109,540
No
output
1
54,770
23
109,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Areas on the Cross-Section Diagram Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. <image> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. output Report the areas of floods in the following format: $A$ $k$ $L_1$ $L_2$ ... $L_k$ In the first line, print the total area $A$ of created floods. In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. Constraints * $1 \leq$ length of the string $\leq 20,000$ Input A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\\///\\_/\/\\\\\\\/_/\\\///__\\\\\\_\\\/_\/_/\". Examples Input \\// Output 4 1 4 Input \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ Output 35 5 4 2 1 19 9 Submitted Solution: ``` #coding:UTF-8 def checkDepth(A): depth=0 for i in range(len(A)): if A[i]=="\\": depth+=1 elif A[i]=="/": depth-=1 else: continue if depth==0: return True return False def SD(a): A=list(a) areaList=[] areaAll=0 start=0 for i in range(len(A)): area=0 if A[i]=="\\": Flag=checkDepth(A[i:]) if Flag==True: count=0 for j in range(i,len(A)): if A[j]=="\\": area+=(count)+0.5 count+=1 elif A[j]=="/": count-=1 area+=(count)+0.5 else: area+=count if count==0: for k in range(i,j): A[k]="_" break areaList.append(int(area)) areaAll+=int(area) continue else: continue else: continue print(areaAll) for i in range(len(areaList)): areaList[i]=str(areaList[i]) print(str(len(areaList))+" "+" ".join(areaList)) if __name__=="__main__": a=input() SD(a) ```
instruction
0
54,771
23
109,542
No
output
1
54,771
23
109,543
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,788
23
109,576
Tags: binary search, dp, greedy Correct Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## m,n=ris() m,n=m+2,n+2 grid =['.'*n] grid+=['.'+rl()+'.' for _ in range(m-2)] grid+=['.'*n] up=[[0]*n for _ in range(m)] dw=[[0]*n for _ in range(m)] lf=[[0]*n for _ in range(m)] rg=[[0]*n for _ in range(m)] rs=[[0]*n for _ in range(m)] cs=[[0]*n for _ in range(m)] for i in range(1,m-1): for j in range(1,n-1): if grid[i][j]=='*': up[i][j]=1+up[i-1][j] lf[i][j]=1+lf[i][j-1] for i in range(m-1,0,-1): for j in range(n-1,0,-1): if grid[i][j]=='*': dw[i][j]=1+dw[i+1][j] rg[i][j]=1+rg[i][j+1] ans=[] for i in range(1,m-1): for j in range(1,n-1): if grid[i][j]=='.': continue s=min(up[i-1][j],dw[i+1][j],lf[i][j-1],rg[i][j+1]) if s==0: continue ans.append((i,j,s)) rs[i-s][j]+=1 rs[i+s+1][j]-=1 cs[i][j-s]+=1 cs[i][j+s+1]-=1 for i in range(1,m-1): for j in range(1,n-1): rs[i][j]+=rs[i-1][j] cs[i][j]+=cs[i][j-1] for i in range(1,m-1): for j in range(1,n-1): if grid[i][j]=='.': continue if rs[i][j]==0 and cs[i][j]==0: print(-1) exit() print(len(ans)) for i,j,s in ans: print(i,j,s) ```
output
1
54,788
23
109,577
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,789
23
109,578
Tags: binary search, dp, greedy Correct Solution: ``` import sys input = sys.stdin.readline n,m=map(int,input().split()) MAP=[list(input().strip()) for i in range(n)] T0=[[0]*(m+1) for i in range(n+1)] T1=[[0]*(m+1) for i in range(n+1)] Y0=[[0]*(m+1) for i in range(n+1)] Y1=[[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): if MAP[i][j]=="*": T0[i][j]=T0[i-1][j]+1 Y0[i][j]=Y0[i][j-1]+1 for i in range(n-1,-1,-1): for j in range(m-1,-1,-1): if MAP[i][j]=="*": T1[i][j]=T1[i+1][j]+1 Y1[i][j]=Y1[i][j+1]+1 ANS=[[0]*m for i in range(n)] for i in range(n): for j in range(m): score=min(T0[i][j],T1[i][j],Y0[i][j],Y1[i][j]) if score>=2: ANS[i][j]=score T0=[[0]*(m+1) for i in range(n+1)] T1=[[0]*(m+1) for i in range(n+1)] Y0=[[0]*(m+1) for i in range(n+1)] Y1=[[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): T0[i][j]=max(ANS[i][j],T0[i-1][j]-1) Y0[i][j]=max(ANS[i][j],Y0[i][j-1]-1) for i in range(n-1,-1,-1): for j in range(m-1,-1,-1): T1[i][j]=max(ANS[i][j],T1[i+1][j]-1) Y1[i][j]=max(ANS[i][j],Y1[i][j+1]-1) SUF=[["."]*m for i in range(n)] for i in range(n): for j in range(m): if T0[i][j] or T1[i][j] or Y0[i][j] or Y1[i][j]: SUF[i][j]="*" if SUF!=MAP: print(-1) else: ANSLIST=[] for i in range(n): for j in range(m): if ANS[i][j]!=0: ANSLIST.append((i+1,j+1,ANS[i][j]-1)) print(len(ANSLIST)) for ans in ANSLIST: print(*ans) ```
output
1
54,789
23
109,579
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,790
23
109,580
Tags: binary search, dp, greedy Correct Solution: ``` def main(): n, m = map(int, input().split()) ll = [c == '*' for _ in range(n) for c in input()] nm = n * m RLUD = [*[range(i, i + m) for i in range(0, nm, m)], *[range(i, nm, m) for i in range(m)]] cc = [1000] * nm for f in True, False: for r in RLUD: v = 0 for i in r: if ll[i]: v += 1 if cc[i] > v: cc[i] = v else: v = cc[i] = 0 if f: ll.reverse() cc.reverse() cc = [c if c != 1 else 0 for c in cc] for f in True, False: for r in RLUD: v = 0 for i in r: if v > cc[i]: v -= 1 else: v = cc[i] if v: ll[i] = False if f: ll.reverse() cc.reverse() if any(ll): print(-1) else: res = [] for i, c in enumerate(cc): if c: res.append(f'{i//m+1} {i%m+1} {c-1}') print(len(res), '\n'.join(res), sep='\n') if __name__ == '__main__': main() ```
output
1
54,790
23
109,581
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,791
23
109,582
Tags: binary search, dp, greedy Correct Solution: ``` import sys input=lambda:sys.stdin.readline().rstrip() h,w=map(int,input().split()) s=[list("."*(w+2))]+[list("."+input()+".") for _ in range(h)]+[list("."*(w+2))] b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i in range(1,h+2): for j in range(1,w+2): if s[i][j]=="*": b[i][j]=b[i-1][j]+1 c[i][j]=c[i][j-1]+1 for i in range(h,-1,-1): for j in range(w,-1,-1): if s[i][j]=="*": b[i][j]=min(b[i][j],b[i+1][j]+1) c[i][j]=min(c[i][j],c[i][j+1]+1) ans=[] for i in range(1,h+1): for j in range(1,w+1): t=min(b[i][j],c[i][j])-1 if t>0: ans.append((i,j,t)) b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i,j,t in ans: b[i-t][j]+=1 b[i+t+1][j]-=1 c[i][j-t]+=1 c[i][j+t+1]-=1 for i in range(h+1): for j in range(w+1): b[i+1][j]+=b[i][j] c[i][j+1]+=c[i][j] if i!=0 and j!=0: if (b[i][j]+c[i][j]>0)!=(s[i][j]=="*"): print(-1) exit() print(len(ans)) for i in ans:print(*i) ```
output
1
54,791
23
109,583
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,792
23
109,584
Tags: binary search, dp, greedy Correct Solution: ``` n, m = map(int, input().split()) c = [] for j in range(n): d = [] s = input() for i in s: d.append(i) c.append(d) a = [] b = [] e=[] g=[] for j in range(n): k=[0]*(m) e.append(k) for j in range(n): k=[0]*(m) g.append(k) dpu = [] for j in range(n): k=[0]*(m) dpu.append(k) dpd = [] for j in range(n): k=[0]*(m) dpd.append(k) dpl = [] for j in range(n): k=[0]*(m) dpl.append(k) dpr = [] for j in range(n): k=[0]*(m) dpr.append(k) for i in range(n): for j in range(m): if c[i][j] == "*": if i>0: dpu[i][j]+=dpu[i-1][j]+1 else: dpu[i][j]=1 if j>0: dpl[i][j]=dpl[i][j-1]+1 else: dpl[i][j]=1 i=n-1 while(i>=0): j=m-1 while(j>=0): if c[i][j] == "*": if i<(n-1): dpd[i][j] += dpd[i + 1][j] + 1 else: dpd[i][j] = 1 if j<(m-1): dpr[i][j] = dpr[i][j + 1] + 1 else: dpr[i][j] = 1 j+=-1 i+=-1 for i in range(1,n-1): for j in range(1,m-1): if c[i][j] == "*": k=min(dpd[i][j]-1,dpu[i][j]-1,dpr[i][j]-1,dpl[i][j]-1) if k==0: pass elif k>0: a.append([i+1,j+1,k]) e[i-k][j]+=1 if (i+k)<(n-1): e[i+k+1][j]+=-1 g[i][j-k] += 1 if (j + k) < (m - 1): g[i][j+k+1] += -1 for i in range(m): for j in range(1,n): if c[j-1][i]=="*": e[j][i]+=e[j-1][i] for i in range(n): for j in range(1,m): if c[i][j-1]=="*": g[i][j]+=g[i][j-1] f=0 for i in range(n): for j in range(m): if c[i][j]=="*" and e[i][j]<=0 and g[i][j]<=0: f=1 break if f==1: print(-1) else: print(len(a)) for j in a: print(*j) ```
output
1
54,792
23
109,585
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,793
23
109,586
Tags: binary search, dp, greedy Correct Solution: ``` import sys input = sys.stdin.readline n, m = map(int, input().split()) s = [list(input().rstrip()) for _ in range(n)] t = [[1000] * m for _ in range(n)] ok1 = [[0] * m for _ in range(n)] ok2 = [[0] * m for _ in range(n)] for i in range(n): si = s[i] c = 0 for j in range(m): if si[j] == "*": c += 1 else: c = 0 t[i][j] = min(t[i][j], c) c = 0 for j in range(m - 1, -1, -1): if si[j] == "*": c += 1 else: c = 0 t[i][j] = min(t[i][j], c) for j in range(m): c = 0 for i in range(n): if s[i][j] == "*": c += 1 else: c = 0 t[i][j] = min(t[i][j], c) c = 0 for i in range(n - 1, -1, -1): if s[i][j] == "*": c += 1 else: c = 0 t[i][j] = min(t[i][j], c) ans = [] for i in range(n): for j in range(m): tij = t[i][j] - 1 if tij >= 1: ans.append((i + 1, j + 1, tij)) ok1[max(0, i - tij)][j] += 1 if i + tij + 1 < n: ok1[i + tij + 1][j] -= 1 ok2[i][max(0, j - tij)] += 1 if j + tij + 1 < m: ok2[i][j + tij + 1] -= 1 for i in range(1, n): for j in range(1, m): ok1[i][j] += ok1[i - 1][j] ok2[i][j] += ok2[i][j - 1] for i in range(n): for j in range(m): if s[i][j] == "*": if not (ok1[i][j] or ok2[i][j]): ans = -1 print(ans) exit() k = len(ans) print(k) for ans0 in ans: print(*ans0) ```
output
1
54,793
23
109,587
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,794
23
109,588
Tags: binary search, dp, greedy Correct Solution: ``` from collections import defaultdict, deque from heapq import heappush, heappop from math import inf ri = lambda : map(int, input().split()) def solve(): n,m = ri() A = [[0 for _ in range(m)] for __ in range(n)] left = [[0 for _ in range(m)] for __ in range(n)] right = [[0 for _ in range(m)] for __ in range(n)] up = [[0 for _ in range(m)] for __ in range(n)] down = [[0 for _ in range(m)] for __ in range(n)] for r in range(n): lst = input() for c in range(m): if lst[c] == '*': A[r][c] = left[r][c] = right[r][c] = up[r][c] = down[r][c] = 1 for r in range(n): for c in range(1, m): if A[r][c]: left[r][c] += left[r][c-1] for c in range(m-2, -1, -1): if A[r][c]: right[r][c] += right[r][c+1] for c in range(m): for r in range(1, n): if A[r][c]: up[r][c] += up[r-1][c] for r in range(n-2, -1, -1): if A[r][c]: down[r][c] += down[r+1][c] res = [] stars = 0 ROWS = [[0 for _ in range(m)] for __ in range(n)] COLS = [[0 for _ in range(m)] for __ in range(n)] for r in range(n): for c in range(m): if A[r][c]: can = min(left[r][c], right[r][c], up[r][c], down[r][c]) can -= 1 if can > 0: stars += 1 res.append((r+1, c+1, can)) ROWS[r-can][c] += can if r+can+1 < n: ROWS[r+can+1][c] -= can COLS[r][c-can] += can if c+can+1 < m: COLS[r][c+can+1] -= can valid = [[False for _ in range(m)] for __ in range(n)] for r in range(n): curr = 0 for c in range(m): curr += COLS[r][c] if curr > 0: valid[r][c] = True for c in range(m): curr = 0 for r in range(n): curr += ROWS[r][c] if curr > 0: valid[r][c] = True for r in range(n): for c in range(m): if A[r][c] and not valid[r][c]: print(-1) return print(stars) for x,y,z in res: print(x,y,z) t = 1 #t = int(input()) while t: t -= 1 solve() ```
output
1
54,794
23
109,589
Provide tags and a correct Python 3 solution for this coding contest problem. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct.
instruction
0
54,795
23
109,590
Tags: binary search, dp, greedy Correct Solution: ``` def main(): n, m = map(int, input().split()) w = [c == '*' for i in range(n) for c in input()] nm = n * m q = [*[range(i, i + m) for i in range(0, nm, m)], *[range(i, nm, m) for i in range(m)]] e = [1000] * nm for f in True, False: for r in q: v = 0 for i in r: if w[i]: v += 1 if e[i] > v: e[i] = v else: v = e[i] = 0 if f: w.reverse() e.reverse() e = [c if c != 1 else 0 for c in e] for f in True, False: for r in q: v = 0 for i in r: if v > e[i]: v -= 1 else: v = e[i] if v: w[i] = False if f: w.reverse() e.reverse() if any(w): print(-1) else: r = [] for i, c in enumerate(e): if c: r.append(f'{i//m+1} {i%m+1} {c-1}') print(len(r), '\n'.join(r), sep='\n') main() ```
output
1
54,795
23
109,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def main(): n, m = mints() res = [] a = [None]*n l = [None]*n r = [None]*n s = [0]*n for i in range(n): a[i] = list(minp()) l[i] = [i for i in range(m)] r[i] = [i for i in range(m)] s[i] = [0]*m for i in range(n): j = 0 b = a[i] ll = l[i] rr = r[i] while j < m: if b[j] == '*': jj = j+1 while jj < m and b[jj] == '*': jj += 1 jj -= 1 for k in range(j,jj+1): ll[k] = j rr[k] = jj j = jj + 1 else: j += 1 for i in range(m): j = 0 while j < n: if a[j][i] == '*': jj = j+1 while jj < n and a[jj][i] == '*': jj += 1 jj -= 1 for k in range(j,jj+1): x = min(i-l[k][i],r[k][i]-i,k-j,jj-k) s[k][i] = x if x > 0: res.append((k+1,i+1,x)) j = jj + 1 else: j += 1 for i in range(n): j = 0 ss = s[i] rr = r[i] c = -1 while j < m: if ss[j] > 0 and c < ss[j]: c = ss[j] if c >= 0: rr[j] = '*' else: rr[j] = '.' j += 1 c -= 1 j = m-1 c = -1 while j >=0: if ss[j] > 0 and c < ss[j]: c = ss[j] if c >= 0: rr[j] = '*' c -= 1 j -= 1 for i in range(m): j = 0 c = -1 while j < n: x = s[j][i] if x > 0 and c < x: c = x if c >= 0: r[j][i] = '*' j += 1 c -= 1 j = n-1 c = -1 while j >=0: x = s[j][i] if x > 0 and c < x: c = x if c >= 0: r[j][i] = '*' if r[j][i] != a[j][i]: print(-1) exit(0) c -= 1 j -= 1 print(len(res)) for i in res: print(*i) main() ```
instruction
0
54,796
23
109,592
Yes
output
1
54,796
23
109,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted 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=0, func=lambda a, b: 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) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(10)] pp=[0]*10 def SieveOfEratosthenes(n=10): p = 2 c=0 while (p * p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): pp[i]+=1 prime[i] = False p += 1 #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n, key): left = 0 right = n-1 mid = 0 res=arr[n-1] while (left <= right): mid = (right + left)//2 if (arr[mid] >= key): res=arr[mid] right = mid-1 else: left = mid + 1 return res def binarySearch1(arr, n, key): left = 0 right = n-1 mid = 0 res=arr[0] while (left <= right): mid = (right + left)//2 if (arr[mid] > key): right = mid-1 else: res=arr[mid] left = mid + 1 return res #---------------------------------running code------------------------------------------ n,m=map(int,input().split()) l=[] tot=[] done=[[0 for i in range(m)]for j in range(n)] for i in range(n): l.append(input()) colsum=[[0 for i in range(m)]for j in range(n)] rowsum=[[0 for i in range(m)]for j in range(n)] col=[[0 for i in range(m)]for j in range(n)] row=[[0 for i in range(m)]for j in range(n)] for i in range(n): for j in range(m): if l[i][j]=='*': rowsum[i][j]=1 colsum[i][j]=1 row[i][j]=1 col[i][j]=1 for i in range(n): for j in range(1,m): if l[i][j]=='.': continue rowsum[i][j]+=rowsum[i][j-1] for i in range(n): for j in range(m-2,-1,-1): if l[i][j]=='.': continue row[i][j]+=row[i][j+1] for i in range(m): for j in range(n-2,-1,-1): if l[j][i]=='.': continue col[j][i]+=col[j+1][i] for i in range(m): for j in range(1,n): if l[j][i]=='.': continue colsum[j][i]+=colsum[j-1][i] def check(x,y): i=x j=y ans=min(row[i][j],rowsum[i][j],colsum[i][j],col[i][j])-1 if ans==0: return [] return [ans] h=[[0 for i in range(m+1)]for j in range(n)] v=[[0 for i in range(m)]for j in range(n+1)] for i in range(n): for j in range(m): if l[i][j]=='*': ans=check(i,j) for j1 in ans: tot.append([i+1,j+1,j1]) h[i][j-j1]+=1 h[i][j+j1+1]-=1 v[i-j1][j]+=1 v[i+j1+1][j]-=1 for i in range(n): for j in range(1,m): h[i][j]+=h[i][j-1] for i in range(m): for j in range(1,n): v[j][i]+=v[j-1][i] #print(h) #print(v) for i in range(n): for j in range(m): if l[i][j]=='*' and h[i][j]==0 and v[i][j]==0: print(-1) sys.exit(0) print(len(tot)) for i in tot: print(*i) ```
instruction
0
54,797
23
109,594
Yes
output
1
54,797
23
109,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` n,m = map(int,input().split()) mat = [] for i in range(n): mat.append(list(map(int,input().replace("*","1").replace(".","0")))) ver,hor = [[0 for i in range(m)] for j in range(n)],[[0 for i in range(m)] for j in range(n)] dp = [[[0 for i in range(4)]for j in range(m) ] for k in range(n)] for i in range(1,n): for j in range(1,m): x,y = n-i-1,m-j-1 if mat[i][j]==1: dp[i][j][0] = max(dp[i][j-1][0],mat[i][j-1]) + 1 dp[i][j][1] = max(dp[i-1][j][1],mat[i-1][j]) + 1 if mat[x][y]==1: dp[x][y][2] = max(dp[x][y+1][2],mat[x][y+1]) + 1 dp[x][y][3] = max(dp[x+1][y][3],mat[x+1][y]) + 1 stars = [] for i in range(1,n-1): for j in range(1,m-1): if mat[i][j]==1: s = min(dp[i][j])-1 if s>0: stars.append((i+1,j+1,s)) ver[i-s][j]+=1 if i+s+1<n: ver[i+s+1][j] -= 1 hor[i][j-s]+=1 if j+s+1<m: hor[i][j+s+1] -= 1 for i in range(1,n): for j in range(1,m): ver[i][j] += ver[i-1][j] hor[i][j] += hor[i][j-1] chk = True for i in range(n): for j in range(m): if mat[i][j] and max(ver[i][j],hor[i][j])<=0: chk=False break if chk: print(len(stars)) for i in stars: print(*i) else: print(-1) ```
instruction
0
54,798
23
109,596
Yes
output
1
54,798
23
109,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` # -*- coding: utf-8 -*- import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10 ** 9 + 7 def build_grid(H, W, intv, _type, space=True, padding=False): if space: _input = lambda: input().split() else: _input = lambda: input() _list = lambda: list(map(_type, _input())) if padding: offset = 1 else: offset = 0 grid = list2d(H+offset*2, W+offset*2, intv) for i in range(offset, H+offset): row = _list() for j in range(offset, W+offset): grid[i][j] = row[j-offset] return grid H, W = MAP() grid = build_grid(H, W, '#', str, space=0, padding=1) ans = [] imosw = list2d(H+2, W+2, 0) imosh = list2d(H+2, W+2, 0) def check(i, j): sz = min(L[i][j], R[i][j], U[i][j], D[i][j]) if sz > 1: imosw[i][j-sz+1] += 1 imosw[i][j+sz] -= 1 imosh[i-sz+1][j] += 1 imosh[i+sz][j] -= 1 ans.append((i, j, sz-1)) def check2(): for i in range(1, H+1): for j in range(1, W+1): if grid[i][j] == '*' and not imosw[i][j] and not imosh[i][j]: return False return True L = list2d(H+2, W+2, 0) R = list2d(H+2, W+2, 0) U = list2d(H+2, W+2, 0) D = list2d(H+2, W+2, 0) for i in range(1, H+1): for j in range(1, W+1): if grid[i][j] == '.': L[i][j] = 0 else: L[i][j] = L[i][j-1] + 1 for i in range(1, H+1): for j in range(W, 0, -1): if grid[i][j] == '.': R[i][j] = 0 else: R[i][j] = R[i][j+1] + 1 for j in range(1, W+1): for i in range(1, H+1): if grid[i][j] == '.': U[i][j] = 0 else: U[i][j] = U[i-1][j] + 1 for j in range(1, W+1): for i in range(H, 0, -1): if grid[i][j] == '.': D[i][j] = 0 else: D[i][j] = D[i+1][j] + 1 for i in range(1, H+1): for j in range(1, W+1): if grid[i][j] == '*': check(i, j) for i in range(1, H+1): for j in range(W+1): imosw[i][j+1] += imosw[i][j] for j in range(1, W+1): for i in range(H+1): imosh[i+1][j] += imosh[i][j] if check2(): print(len(ans)) [print(h, w, sz) for h, w, sz in ans] else: print(-1) ```
instruction
0
54,799
23
109,598
Yes
output
1
54,799
23
109,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` R = lambda: map(int, input().split()) n, m = R() g = [input() for _ in range(n)] f = [[0 for j in range(m)] for i in range(n)] res = [] for i in range(n): for j in range(m): if g[i][j] == '*': dd = 0 for d in range(1, 101): if i >= d and i + d < n and j >= d and j + d < m: if g[i - d][j] == '*' and g[i + d][j] == '*' and g[i][j - d] == '*' and g[i][j + d] == '*': f[i][j] = 1 f[i - d][j] = 1 f[i + d][j] = 1 f[i][j - d] = 1 f[i][j + d] = 1 dd = d else: break else: break if dd >= 1: res.append([i + 1, j + 1, dd]) for i in range(n): for j in range(m): if g[i][j] == '*' and f[i][j] == 0: print(-1) exit(0) print(len(res)) for r in res: print(' '.join(map(str, r))) ```
instruction
0
54,800
23
109,600
No
output
1
54,800
23
109,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` n,m = map(int,input().split()) mat = [] for i in range(n): mat.append(list(map(int,input().replace("*","1").replace(".","0")))) ver,hor = [[0 for i in range(m)] for j in range(n)],[[0 for i in range(m)] for j in range(n)] dp = [[[0 for i in range(4)]for j in range(m) ] for k in range(n)] for i in range(1,n): for j in range(1,m): x,y = n-i-1,m-j-1 if mat[i][j]==1: dp[i][j][0] = max(dp[i][j-1][0],mat[i][j-1]) + 1 dp[i][j][1] = max(dp[i-1][j][1],mat[i-1][j]) + 1 if mat[x][y]==1: dp[x][y][2] = max(dp[x][y+1][2],mat[x][y+1]) + 1 dp[x][y][3] = max(dp[x+1][y][3],mat[x+1][y]) + 1 stars = [] for i in range(1,n-1): for j in range(1,m-1): if mat[i][j]==1: s = min(dp[i][j])-1 if s>0: stars.append((i+1,j+1,s)) ver[i-s][j]+=1 ver[min(i+s+1,n-1)][j]-=1 hor[i][j-s]+=1 hor[i][min(j+s+1,m-1)]-=1 for i in range(1,n): for j in range(1,m): ver[i][j] += ver[i-1][j] hor[i][j] += hor[i][j-1] chk = True for i in range(n): for j in range(m): if mat[i][j] and max(ver[i][j],hor[i][j])<=0: chk=False break if chk: print(len(stars)) for i in stars: print(*i) else: print(-1) ```
instruction
0
54,801
23
109,602
No
output
1
54,801
23
109,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` import sys input=lambda:sys.stdin.readline().rstrip() h,w=map(int,input().split()) s=[list("."*(w+2))]+[list("."+input()+".") for _ in range(h)]+[list("."*(w+2))] b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i in range(1,h+2): for j in range(1,w+2): if s[i][j]=="*": b[i][j]=b[i-1][j]+1 c[i][j]=c[i][j-1]+1 for i in range(h,-1,-1): for j in range(w,-1,-1): if s[i][j]=="*": b[i][j]=min(b[i][j],b[i+1][j]+1) c[i][j]=min(c[i][j],c[i][j+1]+1) ans=[] for i in range(1,h+1): for j in range(1,w+1): t=min(b[i][j],c[i][j])-1 if t>0: ans.append((i,j,t)) b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i,j,t in ans: b[i-t][j]+=1 b[i+t+1][j]-=1 c[i][j-t]+=1 c[i][j+t+1]-=1 for i in range(h+1): for j in range(w+1): b[i+1][j]+=b[i][j] c[i][j+1]+=c[i][j] if i!=0 and j!=0: if (b[i][j]+c[i][j]>0)!=(s[i][j]=="."): print(-1) exit() print(len(ans)) for i in ans:print(*i) ```
instruction
0
54,802
23
109,604
No
output
1
54,802
23
109,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: <image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3. You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars. Input The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid. The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. Output If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid. Examples Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 Note In the first example the output 2 3 4 1 3 5 2 is also correct. Submitted Solution: ``` import sys input=lambda:sys.stdin.readline().rstrip() h,w=map(int,input().split()) s=[list("."*(w+2))]+[list("."+input()+".") for _ in range(h)]+[list("."*(w+2))] b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i in range(1,h+2): for j in range(1,w+2): if s[i][j]=="*": b[i][j]=b[i-1][j]+1 c[i][j]=c[i][j-1]+1 for i in range(h,-1,-1): for j in range(w,-1,-1): if s[i][j]=="*": b[i][j]=min(b[i][j],b[i+1][j]+1) c[i][j]=min(c[i][j],c[i][j+1]+1) ans=[] for i in range(1,h+1): for j in range(1,w+1): t=min(b[i][j],c[i][j])-1 if t>0: ans.append((i,j,t)) b=[[0]*(w+2)for _ in range(h+2)] c=[[0]*(w+2)for _ in range(h+2)] for i,j,t in ans: b[i-t][j]+=1 b[i+t+1][j]-=1 c[i][j-t]+=1 c[i][j+t+1]-=1 for i in range(h+1): for j in range(w+1): b[i+1][j]+=b[i][j] c[i][j+1]+=c[i][j] if i!=0 and j!=0: if b[i][j]+c[i][j]: if s[i][j]==".": print(-1) exit() print(len(ans)) for i in ans:print(*i) ```
instruction
0
54,803
23
109,606
No
output
1
54,803
23
109,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Fair Nut got stacked in planar world. He should solve this task to get out. You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you are also given a number a_i. Choose some of them that the area of union minus sum of a_i of the chosen ones is maximum. It is guaranteed that there are no nested rectangles. Nut has no idea how to find the answer, so he asked for your help. Input The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of rectangles. Each of the next n lines contains three integers x_i, y_i and a_i (1 ≤ x_i, y_i ≤ 10^9, 0 ≤ a_i ≤ x_i ⋅ y_i). It is guaranteed that there are no nested rectangles. Output In a single line print the answer to the problem — the maximum value which you can achieve. Examples Input 3 4 4 8 1 5 0 5 2 10 Output 9 Input 4 6 2 4 1 6 2 2 4 3 5 3 8 Output 10 Note In the first example, the right answer can be achieved by choosing the first and the second rectangles. In the second example, the right answer can also be achieved by choosing the first and the second rectangles. Submitted Solution: ``` from collections import deque import sys class Line: def __init__(self, a, b): self.a, self.b = a, b def __xor__(self, other): return (other.b - self.b) / (self.a - other.a) def __call__(self, x): return self.a * x + self.b def __repr__(self): return "Line({}, {})".format(self.a, self.b) def hull_append(hull, C): def line_covered(A, B): # C covered by A and B return (B.a == C.a and B.b >= C.b) or (A ^ B) <= (B ^ C) while len(hull) >= 2: A, B = hull[-1], hull[-2] if not line_covered(A, B): break else: hull.pop() hull.append(C) def find_min_line(hull, x): lo, hi = 0, len(hull) while lo < hi: mid = (lo + hi) // 2 if mid+1 == len(hull) or hull[mid](x) < hull[mid+1](x): hi = mid else: lo = mid+1 return lo def find_min_line_value(hull, x): return hull[find_min_line(hull, x)](x) #n = int(next(sys.stdin)) n = 10**6 R = [] for i in range(n): #x, y, a = [int(x) for x in next(sys.stdin).split(" ")] x, y, a = i+1, n-i, 0 R.append((x, y, a)) R.sort() Q = [0 for _ in range(n+1)] hull = [Line(0, 0)] p = 0 for i in range(n): while not (p+1 == len(hull) or hull[p](R[i][1]) < hull[p+1](R[i][1])): p += 1 #v = max((Q[j+1] - R[j][0]*R[i][1] for j in range(i)), default=0) #v = -find_min_line_value(hull, R[i][1]) Q[i+1] = R[i][0]*R[i][1] - hull[p](R[i][1]) - R[i][2] hull_append(hull, Line(R[i][0], -Q[i+1])) print(max(Q)) ```
instruction
0
54,808
23
109,616
No
output
1
54,808
23
109,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Fair Nut got stacked in planar world. He should solve this task to get out. You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you are also given a number a_i. Choose some of them that the area of union minus sum of a_i of the chosen ones is maximum. It is guaranteed that there are no nested rectangles. Nut has no idea how to find the answer, so he asked for your help. Input The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of rectangles. Each of the next n lines contains three integers x_i, y_i and a_i (1 ≤ x_i, y_i ≤ 10^9, 0 ≤ a_i ≤ x_i ⋅ y_i). It is guaranteed that there are no nested rectangles. Output In a single line print the answer to the problem — the maximum value which you can achieve. Examples Input 3 4 4 8 1 5 0 5 2 10 Output 9 Input 4 6 2 4 1 6 2 2 4 3 5 3 8 Output 10 Note In the first example, the right answer can be achieved by choosing the first and the second rectangles. In the second example, the right answer can also be achieved by choosing the first and the second rectangles. Submitted Solution: ``` import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ def cin(kls): res = '' for ch in input(): if ch == ' ' or ch == '\n': yield kls(res) res = '' else: res += ch yield kls(res) n, = cin(int) if n == 1000000: exit(0) p = [(int(1e9 + 1), 0, 0)] + [tuple(cin(int)) for i in range(n)] # print(n) # print(p) # n, = map(int, input().split(' ')) # p = [(int(1e9 + 1), 0, 0)] + [tuple(map(int, input().split(' '))) for i in range(n)] p = sorted(p, reverse=True) # print(n) # print(p) dp = [0] * (n + 1) def get_dp(i, j): return dp[j] + (p[i][1] - p[j][1]) * p[i][0] - p[i][2] def get_up(j, k): return dp[j] - dp[k] def get_down(j, k): return p[j][1] - p[k][1] q, head, tail = [0] * (n + 1), 0, 1 for i in range(1, n + 1): while tail - head >= 2 \ and get_up(q[head + 1], q[head]) >= p[i][0] * get_down(q[head + 1], q[head]): head += 1 dp[i] = get_dp(i, q[head]) while tail - head >= 2 \ and get_up(i, q[tail - 1]) * get_down(q[tail - 1], q[tail - 2]) >= get_up(q[tail - 1], q[tail - 2]) * get_down(i, q[tail - 1]): tail -= 1 q[tail], tail = i, tail + 1 # print(dp) print(max(dp)) ```
instruction
0
54,809
23
109,618
No
output
1
54,809
23
109,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Fair Nut got stacked in planar world. He should solve this task to get out. You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you are also given a number a_i. Choose some of them that the area of union minus sum of a_i of the chosen ones is maximum. It is guaranteed that there are no nested rectangles. Nut has no idea how to find the answer, so he asked for your help. Input The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of rectangles. Each of the next n lines contains three integers x_i, y_i and a_i (1 ≤ x_i, y_i ≤ 10^9, 0 ≤ a_i ≤ x_i ⋅ y_i). It is guaranteed that there are no nested rectangles. Output In a single line print the answer to the problem — the maximum value which you can achieve. Examples Input 3 4 4 8 1 5 0 5 2 10 Output 9 Input 4 6 2 4 1 6 2 2 4 3 5 3 8 Output 10 Note In the first example, the right answer can be achieved by choosing the first and the second rectangles. In the second example, the right answer can also be achieved by choosing the first and the second rectangles. Submitted Solution: ``` def cin(kls): return map(kls, input().split()) n, = cin(int) p = [(int(1e9 + 1), 0, 0)] + [tuple(cin(int)) for i in range(n)] p = sorted(p, reverse=True) # print(n) # print(p) # dp = [0] * (n + 1) # def get_dp(i, j): # return dp[j] + (p[i][1] - p[j][1]) * p[i][0] - p[i][2] # def get_up(j, k): # return dp[j] - dp[k] # def get_down(j, k): # return p[j][1] - p[k][1] # q, head, tail = [0] * (n + 1), 0, 1 # for i in range(1, n + 1): # while tail - head >= 2 \ # and get_up(q[head + 1], q[head]) >= p[i][0] * get_down(q[head + 1], q[head]): # head += 1 # dp[i] = get_dp(i, q[head]) # while tail - head >= 2 \ # and get_up(i, q[tail - 1]) * get_down(q[tail - 1], q[tail - 2]) >= get_up(q[tail - 1], q[tail - 2]) * get_down(i, q[tail - 1]): # tail -= 1 # q[tail], tail = i, tail + 1 # print(max(dp)) ```
instruction
0
54,810
23
109,620
No
output
1
54,810
23
109,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Fair Nut got stacked in planar world. He should solve this task to get out. You are given n rectangles with vertexes in (0, 0), (x_i, 0), (x_i, y_i), (0, y_i). For each rectangle, you are also given a number a_i. Choose some of them that the area of union minus sum of a_i of the chosen ones is maximum. It is guaranteed that there are no nested rectangles. Nut has no idea how to find the answer, so he asked for your help. Input The first line contains one integer n (1 ≤ n ≤ 10^6) — the number of rectangles. Each of the next n lines contains three integers x_i, y_i and a_i (1 ≤ x_i, y_i ≤ 10^9, 0 ≤ a_i ≤ x_i ⋅ y_i). It is guaranteed that there are no nested rectangles. Output In a single line print the answer to the problem — the maximum value which you can achieve. Examples Input 3 4 4 8 1 5 0 5 2 10 Output 9 Input 4 6 2 4 1 6 2 2 4 3 5 3 8 Output 10 Note In the first example, the right answer can be achieved by choosing the first and the second rectangles. In the second example, the right answer can also be achieved by choosing the first and the second rectangles. Submitted Solution: ``` import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ def cin(kls): return map(kls, input().split(' ')) n, = cin(int) if n == 1000000: exit(0) p = [(int(1e9 + 1), 0, 0)] + [tuple(cin(int)) for i in range(n)] # n, = map(int, input().split(' ')) # p = [(int(1e9 + 1), 0, 0)] + [tuple(map(int, input().split(' '))) for i in range(n)] p = sorted(p, reverse=True) # print(n) # print(p) dp = [0] * (n + 1) def get_dp(i, j): return dp[j] + (p[i][1] - p[j][1]) * p[i][0] - p[i][2] def get_up(j, k): return dp[j] - dp[k] def get_down(j, k): return p[j][1] - p[k][1] q, head, tail = [0] * (n + 1), 0, 1 for i in range(1, n + 1): while tail - head >= 2 \ and get_up(q[head + 1], q[head]) >= p[i][0] * get_down(q[head + 1], q[head]): head += 1 dp[i] = get_dp(i, q[head]) while tail - head >= 2 \ and get_up(i, q[tail - 1]) * get_down(q[tail - 1], q[tail - 2]) >= get_up(q[tail - 1], q[tail - 2]) * get_down(i, q[tail - 1]): tail -= 1 q[tail], tail = i, tail + 1 print(max(dp)) ```
instruction
0
54,811
23
109,622
No
output
1
54,811
23
109,623
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,828
23
109,656
Tags: math Correct Solution: ``` w1, h1, w2, h2 = map(int, input().split()) answ1 = w1 + 2*h1 answ2 = w2 + 2*h2 answ = 4 + abs(w2 - w1) print(answ1 + answ2 + answ) ```
output
1
54,828
23
109,657
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,829
23
109,658
Tags: math Correct Solution: ``` '''input 2 2 1 2 ''' # I am Mr.Inconsistent from sys import stdin # main starts w1, h1, w2, h2 = list(map(int, stdin.readline().split())) height = h1 + h2 width = w1 area = (height + 2)* (width + 2) area -= (h1 * w1) area -= (h2 * w2) area -= h2 * (w1 - w2) print(area) ```
output
1
54,829
23
109,659
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,830
23
109,660
Tags: math Correct Solution: ``` w1,h1,w2,h2 = map(int,input().split()) ans = 4 + 2*(h1+h2) + 2*max(w1,w2) print(ans) ```
output
1
54,830
23
109,661
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,831
23
109,662
Tags: math Correct Solution: ``` w1,h1,w2,h2=map(int,input().split()) a1=w1*h1 a2=w2*h2 a=a1+a2 b1=(w1+2)*(h1+2) b2=(w2+2)*(h2+1) b=b1+b2 ans=b-a-(w2+2) print(ans) ```
output
1
54,831
23
109,663
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,832
23
109,664
Tags: math Correct Solution: ``` w1,h1,w2,h2=map(int,input().split()) x=max(w1,w2) y=h1+h2 print((2*y) + (2*x) + 4) ```
output
1
54,832
23
109,665
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,833
23
109,666
Tags: math Correct Solution: ``` w1,h1,w2,h2 = [int(x) for x in input().split()] print((w1+2)*(h1+2) + (w2+2)*(h2) - w1*h1 - w2*h2) ```
output
1
54,833
23
109,667
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,834
23
109,668
Tags: math Correct Solution: ``` w1, h1, w2, h2 = map(int, input().split()) ans = 0 ans += 2*(h1+h2) ans += (w1+2) ans += (w2+2) ans += abs(w2-w1) print(ans) ```
output
1
54,834
23
109,669
Provide tags and a correct Python 3 solution for this coding contest problem. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image>
instruction
0
54,835
23
109,670
Tags: math Correct Solution: ``` import sys line = sys.stdin.readline().strip() w1, h1, w2, h2 = map(int, line.split()) print((w1 + h1 + h2 + 2) * 2) ```
output
1
54,835
23
109,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` from sys import stdin, stdout from math import * from heapq import * from collections import * def main(): w1,h1,w2,h2=[int(x) for x in stdin.readline().split()] mw=min(w1,w2) res=(4+(2*(w1+h1)))+(4+(2*(w2+h2)))-2*(mw+2) stdout.write(str(res)) return 0 if __name__ == "__main__": main() ```
instruction
0
54,836
23
109,672
Yes
output
1
54,836
23
109,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` try: w1,h1,w2,h2=map(int,input().split()) h = h1 + h2 w=max(w1,w2) mat1=w*h mat2=(w+2)*(h+2) ans=int(mat2-mat1) print(ans) except: print("hello") ```
instruction
0
54,837
23
109,674
Yes
output
1
54,837
23
109,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` x = list(map(int, input().split())) def counter(args): w1 = args[0] h1 = args[1] w2 = args[2] h2 = args[3] points = 4 + 2*h1 + 2*h2 + w1 + w2 + (w1 - w2) return points print(counter(x)) ```
instruction
0
54,838
23
109,676
Yes
output
1
54,838
23
109,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` w1, h1, w2, h2 = [int(x) for x in input().split()] area = 2*(w1+h1+w2+h2) - 2*min(w1,w2) + 4 print(area) ```
instruction
0
54,839
23
109,678
Yes
output
1
54,839
23
109,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` w1, h1, w2, h2 = map(int, input().split()) print((h2 + h1 + 2) * (w1 + 2) - (w1 * h1 + w2 * h2) - abs(w1 - w2) * h1) ```
instruction
0
54,840
23
109,680
No
output
1
54,840
23
109,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` w1, h1, w2, h2 = map(int, input().split()) print((w1 * (2 * h1)) + (w2 * (2 * h2)) + abs(w1 - w2) + 4) ```
instruction
0
54,841
23
109,682
No
output
1
54,841
23
109,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` w1,h1,w2,h2=map(int,input().split()) o=w1+2+h1*2+h2+1+w2+1+h2 if w2<w1: o+=1 print(o) ```
instruction
0
54,842
23
109,684
No
output
1
54,842
23
109,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field. The rectangles are placed on field in the following way: * the second rectangle is on top the first rectangle; * they are aligned to the left, i.e. their left sides are on the same line; * the rectangles are adjacent to each other without a gap. See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue. Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1, 1), the rightmost top cell of the first rectangle has coordinates (w_1, h_1), the leftmost bottom cell of the second rectangle has coordinates (1, h_1 + 1) and the rightmost top cell of the second rectangle has coordinates (w_2, h_1 + h_2). After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green. Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction. Input Four lines contain integers w_1, h_1, w_2 and h_2 (1 ≤ w_1, h_1, w_2, h_2 ≤ 10^8, w_1 ≥ w_2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles. Output Print exactly one integer — the number of cells, which should be marked after the ship is destroyed. Examples Input 2 1 2 1 Output 12 Input 2 2 1 2 Output 16 Note In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares): <image> In the second example the field looks as: <image> Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sat Feb 23 16:09:37 2019 @author: screamLab """ w = list(map(int, input().split())) long = w[1] + w[3] + 2 wide = max(w[0],w[2]) + 2 for i in range(len(w)): if(w[0] == w[2]): area = long * wide - (w[0]*w[1] + w[2]*w[3]) else: area = long * wide - (w[0]*w[1] + w[2]*w[3]) - (w[0]*w[1] - w[2]*w[3]) print(area,'\n') ```
instruction
0
54,843
23
109,686
No
output
1
54,843
23
109,687
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i ≤ x ≤ r_i holds, belong to the i-th segment. Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one. Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting. The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j ≤ l_i and r_i ≤ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 ≤ n ≤ 3000) — the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 2 ⋅ 10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment. Additional constraint on the input: there are no duplicates in the list of segments. It is guaranteed that the sum of n does not exceed 3000 (∑ n ≤ 3000). Output For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one. Example Input 4 4 1 5 2 4 2 3 3 4 5 1 5 2 3 2 5 3 5 2 2 3 1 3 2 4 2 3 7 1 10 2 8 2 5 3 4 4 4 6 8 7 7 Output 3 4 2 7
instruction
0
54,957
23
109,914
Tags: data structures, dp, graphs, sortings Correct Solution: ``` def solve(): n = int(input()) LR = [tuple(map(int,input().split())) for i in range(n)] LR.sort(key=lambda x: (x[1],-x[0])) s = set() for l,r in LR: s.add(l) s.add(r) dic = {x:i for i,x in enumerate(sorted(list(s)))} le = len(s) seg = [[] for i in range(le)] for l,r in LR: seg[dic[r]].append(dic[l]) dp = [[len(seg[0])]] for i in range(1,le): dp.append(dp[-1]+[0]) for l in seg[i]: dp[i][l] += 1 for j in range(l): dp[i][j] = max(dp[i][j],dp[i][l]+dp[l-1][j]) return dp[-1][0] t = int(input()) for _ in range(t): ans = solve() print(ans) ```
output
1
54,957
23
109,915