message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different. Output Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4. Examples Input 1 1 Output 3.1415926536 Input 3 1 4 2 Output 40.8407044967 Note In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π Submitted Solution: ``` #link: https://codeforces.com/problemset/problem/157/B import math n = int(input()) raios = list(map(int, input().split(" "))) raios.sort(reverse=True) r = math.pi quadrados_pares = [] quadrados_impares = [] for x in range(0,len(raios)): if x % 2 == 0: quadrados_pares.append(raios[x]**2) elif x % 2 == 1: quadrados_impares.append(raios[x]**2) resultado = sum(quadrados_pares) - sum(quadrados_impares) area_resultante = resultado * r print(area_resultante) ```
instruction
0
104,711
23
209,422
Yes
output
1
104,711
23
209,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different. Output Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4. Examples Input 1 1 Output 3.1415926536 Input 3 1 4 2 Output 40.8407044967 Note In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π Submitted Solution: ``` from sys import stdin,stdout ii1 = lambda: int(stdin.readline().strip()) is1 = lambda: stdin.readline().strip() iia = lambda: list(map(int, stdin.readline().strip().split())) isa = lambda: stdin.readline().strip().split() mod = 1000000007 from math import pi n = ii1() arr = sorted([0] + iia()) res = 0 if 1 < 2: res = arr[0] else: for i in range(n,0,-2): if i > 0: # print(i,i-1) res += arr[i] ** 2 - arr[i - 1] ** 2 print(pi*res) ```
instruction
0
104,715
23
209,430
No
output
1
104,715
23
209,431
Provide tags and a correct Python 3 solution for this coding contest problem. Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center in the point (z, 0) a (K, z)-set. Thus, on the square were painted a (N, x)-set and a (M, y)-set. You have to find out how many parts those sets divided the square into. Input The first line contains integers N, x, M, y. (1 ≤ N, M ≤ 100000, - 100000 ≤ x, y ≤ 100000, x ≠ y). Output Print the sought number of parts. Examples Input 1 0 1 1 Output 4 Input 1 0 1 2 Output 3 Input 3 3 4 7 Output 17 Note Picture for the third sample: <image>
instruction
0
104,802
23
209,604
Tags: implementation, math Correct Solution: ``` def readGen(trans): while 1: for x in input().split(): yield(trans(x)) readint=readGen(int) [N,x,M,y]=(next(readint) for i in range(4)) d=abs(y-x) def interval(a,b): return range(a,b+1) def case1(N,M,d): # d>=N ans=0 for r in interval(1, min(M,d-N)): ans+=1 if (M<=d-N): return ans for r in interval(d-N+1, min(M,d)): ans+=2*(N+r-d) if (M<=d): return ans for r in interval(d+1,min(M,d+N)): ans+=2*(d+N-r+1) if (M<=d+N): return ans for r in interval(d+N+1,M): ans+=1 return ans def partA(N,M,d): ans=0 for r in interval(1,min(M,d)): ans+=2*r-1 if (M<d+1): return ans for r in interval(d+1,min(M,2*d)): ans+=2*(2*d-r)+1 return ans def partB(N,M,d): ans=0 bound1=min(2*d,N-d) for r in interval(1,min(M,bound1)): ans+=2*(r-1)+1 if (M<=bound1): return ans if (2*d<=N-d): for r in interval(bound1+1,min(M,N-d)): ans+=4*d if (M<=N-d): return ans if (2*d>N-d): for r in interval(bound1+1,min(M,2*d)): ans+=2*(N-d)+1 if (M<=2*d): return ans bound2=max(2*d,N-d) for r in interval(bound2+1,min(M,d+N)): ans+=2*(d+N-r)+2 if (M<=d+N): return ans for r in interval(d+N+1,M): ans+=1 return ans def case2(N,M,d): # d<N return partA(N,M,d)+partB(N,M,d) def remain(N,M,d): if (M>=d+N): return 1 if (M>d): return d+N-M+1 if (M<=d): return N+1 def calc(N,M,d): if (N<=d): return remain(N,M,d)+case1(N,M,d) else: return remain(N,M,d)+case2(N,M,d) print(calc(N,M,d)) ```
output
1
104,802
23
209,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center in the point (z, 0) a (K, z)-set. Thus, on the square were painted a (N, x)-set and a (M, y)-set. You have to find out how many parts those sets divided the square into. Input The first line contains integers N, x, M, y. (1 ≤ N, M ≤ 100000, - 100000 ≤ x, y ≤ 100000, x ≠ y). Output Print the sought number of parts. Examples Input 1 0 1 1 Output 4 Input 1 0 1 2 Output 3 Input 3 3 4 7 Output 17 Note Picture for the third sample: <image> Submitted Solution: ``` n, x, m, y = list(map(int,input().strip().split(' '))) s = x x -= s y -= s y = abs(y) if y == 1 and n != 1 and m != 1: print(n + m + 4) else: print(n + m + 1 + pow(n + m - y,2)) ```
instruction
0
104,803
23
209,606
No
output
1
104,803
23
209,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center in the point (z, 0) a (K, z)-set. Thus, on the square were painted a (N, x)-set and a (M, y)-set. You have to find out how many parts those sets divided the square into. Input The first line contains integers N, x, M, y. (1 ≤ N, M ≤ 100000, - 100000 ≤ x, y ≤ 100000, x ≠ y). Output Print the sought number of parts. Examples Input 1 0 1 1 Output 4 Input 1 0 1 2 Output 3 Input 3 3 4 7 Output 17 Note Picture for the third sample: <image> Submitted Solution: ``` n, x, m, y = list(map(int,input().strip().split(' '))) s = x x -= s y -= s y = abs(y) print(n + m + 1 + pow(n + m - y,2)) ```
instruction
0
104,804
23
209,608
No
output
1
104,804
23
209,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center in the point (z, 0) a (K, z)-set. Thus, on the square were painted a (N, x)-set and a (M, y)-set. You have to find out how many parts those sets divided the square into. Input The first line contains integers N, x, M, y. (1 ≤ N, M ≤ 100000, - 100000 ≤ x, y ≤ 100000, x ≠ y). Output Print the sought number of parts. Examples Input 1 0 1 1 Output 4 Input 1 0 1 2 Output 3 Input 3 3 4 7 Output 17 Note Picture for the third sample: <image> Submitted Solution: ``` n, x, m, y = list(map(int,input().strip().split(' '))) s = x x -= s y -= s y = abs(y) print(n + m + 1 + pow(max(n + m - y,0),2)) ```
instruction
0
104,805
23
209,610
No
output
1
104,805
23
209,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1, 2, ..., K and the center in the point (z, 0) a (K, z)-set. Thus, on the square were painted a (N, x)-set and a (M, y)-set. You have to find out how many parts those sets divided the square into. Input The first line contains integers N, x, M, y. (1 ≤ N, M ≤ 100000, - 100000 ≤ x, y ≤ 100000, x ≠ y). Output Print the sought number of parts. Examples Input 1 0 1 1 Output 4 Input 1 0 1 2 Output 3 Input 3 3 4 7 Output 17 Note Picture for the third sample: <image> Submitted Solution: ``` n, x, m, y = list(map(int,input().strip().split(' '))) s = x x -= s y -= s y = abs(y) if y == 1 and n != 1 and m != 1: print(n + m + 4) else: print(n + m + 1 + pow(max(n + m - y,0),2)) ```
instruction
0
104,806
23
209,612
No
output
1
104,806
23
209,613
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,955
23
209,910
Tags: brute force, implementation, math Correct Solution: ``` b, q, l, m = map(int, input().split()) A = set(map(int, input().split())) ans = 0 for _ in range(100): if abs(b) > l: break if b not in A: ans += 1 b *= q if ans > 40: print("inf") else: print(ans) ```
output
1
104,955
23
209,911
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,956
23
209,912
Tags: brute force, implementation, math Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) 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)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) b,q,l,m = ilele() A = alele() C = Counter(A) Ans = [b] if abs(b) > l: print(0) exit(0) for i in range(100000): b*= q if abs(b) > l: break Ans.append(b) #print(Ans) count = 0 G = set() for i in Ans: if C.get(i,-1) == -1 and abs(i) <= l: count += 1 G.add(i) if count >= 10000 or (count > 1000 and len(G) <= 3) : print("inf") else: print(count) ```
output
1
104,956
23
209,913
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,957
23
209,914
Tags: brute force, implementation, math Correct Solution: ``` b, q, l, m = map(int, input().split()) s = set(map(int, input().split())) if abs(b) > l: print(0) exit() if q == 1: if b not in s: print("inf") exit() else: print(0) exit() if q == -1: if b not in s or b * -1 not in s: print("inf") exit() else: print(0) exit() if q == 0: if 0 not in s: print("inf") exit() else: print(1 * (b not in s)) exit() if b == 0: if 0 not in s: print("inf") exit() else: print(0) exit() res = 0 while abs(b) <= l: if b not in s: res += 1 b = b * q print(res) ```
output
1
104,957
23
209,915
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,958
23
209,916
Tags: brute force, implementation, math Correct Solution: ``` class CodeforcesTask789BSolution: def __init__(self): self.result = '' self.b_q_l_m = [] self.bad_numbers = [] def read_input(self): self.b_q_l_m = [int(x) for x in input().split(" ")] self.bad_numbers = [int(x) for x in input().split(" ")] def process_task(self): term = self.b_q_l_m[0] q = self.b_q_l_m[1] terms_count = 0 if q == 1 and term not in self.bad_numbers: if abs(term) <= self.b_q_l_m[2]: self.result = "inf" else: self.result = "0" elif q == 1: self.result = "0" elif q == 0: if abs(term) <= self.b_q_l_m[2]: if term not in self.bad_numbers: terms_count += 1 if 0 not in self.bad_numbers: self.result = "inf" else: self.result = str(terms_count) else: self.result = "0" elif q == -1: if term not in self.bad_numbers: if abs(term) <= self.b_q_l_m[2]: self.result = "inf" else: self.result = "0" else: if -term not in self.bad_numbers: if abs(-term) <= self.b_q_l_m[2]: self.result = "inf" else: self.result = "0" else: self.result = "0" elif term == 0: if term not in self.bad_numbers: self.result = "inf" else: self.result = "0" else: while abs(term) <= self.b_q_l_m[2]: if term not in self.bad_numbers: terms_count += 1 term *= q self.result = str(terms_count) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask789BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
104,958
23
209,917
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,959
23
209,918
Tags: brute force, implementation, math Correct Solution: ``` a=input().split() b=int(a[0]) q=int(a[1]) l=int(a[2]) m=int(a[3]) a=input().split() t=0 if(b==0): if('0' in a):print(0) else:print("inf") elif(abs(b)>l):print(0) elif(abs(q)<=1 and q!=-1 and q!=0): if(str(b) in a):print(0) else:print("inf") elif(q==(-1)): if(str(b) in a and str(-b) in a):print(0) else:print("inf") elif(q==0): t=1 if(str(b) in a):t=0; if(str(0) in a):print(t) else:print("inf") else: t=0 while(abs(b)<=l): if(not(str(b) in a)):t+=1 b*=q print(t) ```
output
1
104,959
23
209,919
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,960
23
209,920
Tags: brute force, implementation, math Correct Solution: ``` b1, q, l, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] ans = 0 if abs(b1) > l: ans = 0 elif b1 == 0: ans = "inf" if 0 not in a else 0 else: ans = int(b1 not in a) if q == 0: if 0 not in a : ans = "inf" elif q == 1: if ans > 0 : ans = "inf" elif q == -1: if ans > 0 or -b1 not in a: ans = "inf" else: while 1: b1 *= q if abs(b1) > l: break ans += b1 not in a print(ans) ```
output
1
104,960
23
209,921
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,961
23
209,922
Tags: brute force, implementation, math Correct Solution: ``` b1 , q , l , m = map(int, input().split()) s = set(map(int , input().split())) ans = 0 cnt = 0 while abs(b1) <= l: if b1 not in s: ans += 1 cnt += 1 if cnt == 100000: break b1 *= q if ans >= 50000: print('inf') else: print(ans) ```
output
1
104,961
23
209,923
Provide tags and a correct Python 3 solution for this coding contest problem. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123.
instruction
0
104,962
23
209,924
Tags: brute force, implementation, math Correct Solution: ``` from sys import stdin, stdout b, q, l, n = map(int, stdin.readline().split()) a = set(list(map(int, stdin.readline().split()))) ans = 0 ind = 0 while abs(b) <= l and ind < 100: if not b in a: ans += 1 b *= q ind += 1 if ans > 40: stdout.write('inf') else: stdout.write(str(ans)) ```
output
1
104,962
23
209,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` b, q, l, m = list(map(int, input().split())) st = set(map(int, input().split())) mx = 1000 ans = 0 for i in range(0, 100000): if abs(b) > l: break if b not in st: ans = ans + 1 b *= q if ans == mx: break if ans == mx: print("inf") else: print(ans) ```
instruction
0
104,963
23
209,926
Yes
output
1
104,963
23
209,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` def main(): read = lambda: tuple(map(int, input().split())) b, q, l, m = read() ns = {} for n in read(): ns[n] = True k = 0 if b == 0: return "inf" if not b in ns else 0 if q == 1: return "inf" if not b in ns and abs(b) <= l else 0 if q == -1: return "inf" if (not b in ns or not -b in ns) and abs(b) <= l else 0 if q == 0: if abs(b) > l: return 0 else: return "inf" if not 0 in ns else (1 if not b in ns else 0) while abs(b) <= l: if not b in ns: k += 1 b *= q return k print(main()) ```
instruction
0
104,964
23
209,928
Yes
output
1
104,964
23
209,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` b, q, l, m = map(int, input().split(' ')) a = list(map(int, input().split(' '))) if abs(b) > l: c = 0 elif b == 0: if 0 in a: c = 0 else: c = "inf" elif q == 1: if b in a: c = 0 else: c = "inf" elif q == -1: if b in a and -b in a: c = 0 else: c = "inf" elif q == 0: if 0 not in a: c = "inf" elif b in a: c = 0 else: c = 1 else: c = 0 while abs(b) <= l: if b not in a: c += 1 b *= q print(c) ```
instruction
0
104,965
23
209,930
Yes
output
1
104,965
23
209,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` ip = lambda: [int(i) for i in input().split()] b, q, l, m = ip() bad = set(ip()) ans = 0 iter_count = 0 inf = False while True: if iter_count >= 40: inf = True break if abs(b) > l: break if b not in bad: ans += 1 b *= q iter_count += 1 if inf and ans > 2: print("inf") else: print(ans) ```
instruction
0
104,966
23
209,932
Yes
output
1
104,966
23
209,933
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` a,r,l,m = map(int,input().split()) _l = list(map(int,input().split())) s = set(_l) if(a==0): if(0 in s): print(0) exit(0) else: print("inf") exit(0) if(r==0): if(a==0): if(0 in s): print(0) exit(0) else: print("inf") exit(0) else: if(a not in s and abs(a)<=l): if(0 in s): print("inf") else: print(1) exit(0) else: print(0) exit(0) if(r==1): if(a in s or abs(a)>l): print(0) exit(0) else: print("inf") exit(0) if(r==-1): if(a in s): if(0-a in s): print(0) exit(0) else: if(abs(a)<=l): print("inf") exit(0) else: print(0) exit(0) else: if(abs(a)<=l): print("inf") exit(0) else: print(0) exit(0) tot = 0 while(abs(a)<=l): if(a not in s): tot+=1 a*=r print(tot) ```
instruction
0
104,967
23
209,934
No
output
1
104,967
23
209,935
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` #!/usr/bin/env python3 from math import * def ri(): return map(int, input().split()) b, q, l, m = ri() a = list(ri()) ans = 0 if abs(b) < l: if not b in a: ans+=1 else: print(0) exit() i = 0 while True: i += 1 b = b*q if b in a: pass elif abs(b) < l: ans+=1 else: print(ans) break if i > 10: if b == b*q*q or b == b*q: if b in a and b*q in a: print(ans) exit() else: print("inf") exit() ```
instruction
0
104,968
23
209,936
No
output
1
104,968
23
209,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` b, q, l, m = [int(a_temp) for a_temp in input().strip().split()] a = [int(a_temp) for a_temp in input().strip().split()] d = {} for e in a: d[e]=True if q==0: if 0 not in d: print("inf") elif b not in d: print(1) else: print(0) elif q==1: if b in d or abs(b)>l: print(0) else: print("inf") elif q==-1: if abs(b)>l: print(0) elif b not in d: print("inf") elif -1*b not in d: print("inf") else: print(0) else: count = 0 b = abs(b) q = abs(q) t = b while(t<=l): if t not in d: count+=1 t*=q print(count) ```
instruction
0
104,969
23
209,938
No
output
1
104,969
23
209,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. Input The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board. Output Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Examples Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf Note In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. Submitted Solution: ``` b1,q,l,m = [int(i) for i in input().split()] bad = [int(i) for i in input().split()] if abs(q) > 1: b2 = b1 count = 0 while abs(b2) <= l: count += 1 b2 *= q for u in bad: i = u a = False while (i%q == 0): i = i / q a = i == b1 if a: break if (a and u<=l) or u == b1: count-=1 print(count) else: a1 = b1 * q a2 = a1 * q if abs(b1) <= l: if a1 in bad: if a1 in bad: print("0") else: print("inf") else: print("inf") else: print("0") ```
instruction
0
104,970
23
209,940
No
output
1
104,970
23
209,941
Provide a correct Python 3 solution for this coding contest problem. You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building. Submitted designs will look like a screenshot of a well known game as shown below. <image> This is because the center specifies that the building should be constructed by stacking regular units called pieces, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions. * All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position. * All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse. * The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces. * The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below. <image> It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows. Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by xy-coordinates of its left-bottom corner. The unit length is the edge length of a block. Among the blocks of the piece that touch another piece or the ground on their bottom faces, let xL be the leftmost x-coordinate of the leftmost block, and let xR be the rightmost x-coordinate of the rightmost block. Let the x-coordinate of its accumulated center of mass of the piece be M, where the accumulated center of mass of a piece P is the center of the mass of the pieces that are directly and indirectly supported by P, in addition to P itself. Then the piece is stable, if and only if xL < M < xR. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable. Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable. <image> | | <image> ---|---|--- Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable. Write a program that judges stability of each design based on the above quick check rules. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows. > w h > p0(h-1)p1(h-1)...p(w-1)(h-1) > ... > p01p11...p(w-1)1 > p00p10...p(w-1)0 > The integers w and h separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ h ≤ 60. The next h lines specify the placement of the pieces. The character pxy indicates the status of a block at (x,y), either ``.`', meaning empty, or one digit character between ``1`' and ``9`', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by xy-coordinates of its left-bottom corner.) When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (x,0) touches the ground. You may assume that the pieces in each dataset are stacked in a tree-like form. Output For each dataset, output a line containing a word `STABLE` when the design is stable with respect to the above quick check rules. Otherwise, output `UNSTABLE`. The output should be written with uppercase letters, and should not contain any other extra characters. Sample Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output for the Sample Input STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE Example Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE
instruction
0
105,199
23
210,398
"Correct Solution: ``` #2006_D """ import sys from collections import defaultdict def dfs(d,y,x,f): global ans if d >= 10: return f_ = defaultdict(int) for i in f.keys(): f_[i] = f[i] for t,s in vr[(y,x)]: if a[t][s] == 3: ans = min(ans,d+1) break elif f[(t,s)]: if s == x+1: break f_[(t,s)] = 0 dfs(d+1,t,s-1,f_) f_[(t,s)] = 1 break for t,s in vl[(y,x)]: if a[t][s] == 3: ans = min(ans,d+1) break elif f[(t,s)]: if s == x-1: break f_[(t,s)] = 0 dfs(d+1,t,s+1,f_) f_[(t,s)] = 1 break for t,s in vd[(y,x)]: if a[t][s] == 3: ans = min(ans,d+1) break elif f[(t,s)]: if t == y+1: break f_[(t,s)] = 0 dfs(d+1,t-1,s,f_) f_[(t,s)] = 1 break for t,s in vu[(y,x)]: if a[t][s] == 3: ans = min(ans,d+1) break elif f[(t,s)]: if t == y-1: break f_[(t,s)] = 0 dfs(d+1,t+1,s,f_) f_[(t,s)] = 1 break return while 1: w,h = map(int, sys.stdin.readline()[:-1].split()) if w == h == 0: break a = [list(map(int, sys.stdin.readline()[:-1].split())) for i in range(h)] vr = defaultdict(list) vl = defaultdict(list) vd = defaultdict(list) vu = defaultdict(list) f = defaultdict(int) for y in range(h): for x in range(w): if a[y][x] == 1: f[(y,x)] = 1 if a[y][x] in [1,3]: for x_ in range(x): vr[(y,x_)].append((y,x)) elif a[y][x] == 2: sy,sx = y,x for y in range(h): for x in range(w)[::-1]: if a[y][x] in (1,3): for x_ in range(x+1,w): vl[(y,x_)].append((y,x)) for x in range(w): for y in range(h): if a[y][x] in (1,3): for y_ in range(y): vd[(y_,x)].append((y,x)) for x in range(w): for y in range(h)[::-1]: if a[y][x] in (1,3): for y_ in range(y+1,h): vu[(y_,x)].append((y,x)) ind = [[[0]*4 for i in range(w)] for j in range(h)] ans = 11 dfs(0,sy,sx,f) ans = ans if ans < 11 else -1 print(ans) """ #2018_D """ import sys from collections import defaultdict sys.setrecursionlimit(1000000) def dfs(d,s,l,v,dic): s_ = tuple(s) if dic[(d,s_)] != None: return dic[(d,s_)] if d == l: dic[(d,s_)] = 1 for x in s: if x > (n>>1): dic[(d,s_)] = 0 return 0 return 1 else: res = 0 i,j = v[d] if s[i] < (n>>1): s[i] += 1 res += dfs(d+1,s,l,v,dic) s[i] -= 1 if s[j] < (n>>1): s[j] += 1 res += dfs(d+1,s,l,v,dic) s[j] -= 1 dic[(d,s_)] = res return res def solve(n): dic = defaultdict(lambda : None) m = int(sys.stdin.readline()) s = [0]*n f = [[1]*n for i in range(n)] for i in range(n): f[i][i] = 0 for i in range(m): x,y = [int(x) for x in sys.stdin.readline().split()] x -= 1 y -= 1 s[x] += 1 f[x][y] = 0 f[y][x] = 0 v = [] for i in range(n): for j in range(i+1,n): if f[i][j]: v.append((i,j)) l = len(v) print(dfs(0,s,l,v,dic)) while 1: n = int(sys.stdin.readline()) if n == 0: break solve(n) """ #2011_D """ import sys def dfs(s,d,f,v): global ans if ans == n-n%2: return if d > ans: ans = d for i in range(n): if s[i] == 0: for j in range(i+1,n): if s[j] == 0: if f[i] == f[j]: s[i] = -1 s[j] = -1 for k in v[i]: s[k] -= 1 for k in v[j]: s[k] -= 1 dfs(s,d+2,f,v) s[i] = 0 s[j] = 0 for k in v[i]: s[k] += 1 for k in v[j]: s[k] += 1 def solve(n): p = [[int(x) for x in sys.stdin.readline().split()] for i in range(n)] v = [[] for i in range(n)] f = [0]*n s = [0]*n for i in range(n): x,y,r,f[i] = p[i] for j in range(i+1,n): xj,yj,rj,c = p[j] if (x-xj)**2+(y-yj)**2 < (r+rj)**2: v[i].append(j) s[j] += 1 dfs(s,0,f,v) print(ans) while 1: n = int(sys.stdin.readline()) ans = 0 if n == 0: break solve(n) """ #2003_D """ import sys def root(x,par): if par[x] == x: return x par[x] = root(par[x],par) return par[x] def unite(x,y,par,rank): x = root(x,par) y = root(y,par) if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 def solve(n): p = [[float(x) for x in sys.stdin.readline().split()] for i in range(n)] v = [] for i in range(n): for j in range(i): xi,yi,zi,ri = p[i] xj,yj,zj,rj = p[j] d = max(0,((xi-xj)**2+(yi-yj)**2+(zi-zj)**2)**0.5-(ri+rj)) v.append((i,j,d)) par = [i for i in range(n)] rank = [0]*n v.sort(key = lambda x:x[2]) ans = 0 for x,y,d in v: if root(x,par) != root(y,par): unite(x,y,par,rank) ans += d print("{:.3f}".format(round(ans,3))) while 1: n = int(sys.stdin.readline()) if n == 0: break solve(n) """ #2009_D """ import sys from heapq import heappop,heappush from collections import defaultdict def solve(n,m): s,g = [int(x) for x in sys.stdin.readline().split()] s -= 1 g -= 1 e = [[] for i in range(n)] for i in range(m): a,b,d,c = [int(x) for x in sys.stdin.readline().split()] a -= 1 b -= 1 e[a].append((b,d,c)) e[b].append((a,d,c)) dist = defaultdict(lambda : float("inf")) dist[(s,0,-1)] = 0 q = [(0,s,0,-1)] while q: dx,x,v,p = heappop(q) if x == g and v == 1: print(dx) return for i in range(-1,2): v_ = v+i if v_ < 1 :continue for y,d,c in e[x]: if p == y: continue if v_ > c: continue z = d/v_ if dx+z < dist[(y,v_,x)]: dist[(y,v_,x)] = dx+z heappush(q,(dist[(y,v_,x)],y,v_,x)) print("unreachable") return while 1: n,m = [int(x) for x in sys.stdin.readline().split()] if n == 0: break solve(n,m) """ #2016_D """ import sys def solve(n): w = [int(x) for x in sys.stdin.readline().split()] dp = [[0]*(n+1) for i in range(n+1)] for le in range(n+1): for l in range(n): r = l+le if r > n:break if not (r-l)%2 and abs(w[l]-w[r-1]) < 2: if dp[l+1][r-1] == r-l-2: dp[l][r] = r-l continue for k in range(l+1,r): if dp[l][k] + dp[k][r] > dp[l][r]: dp[l][r] = dp[l][k] + dp[k][r] print(dp[0][n]) while 1: n = int(sys.stdin.readline()) if not n: break solve(n) """ #2009_D """ alp = list("abcdefghijklmnopqrstuvwxyz") c = {} key = {} for i in range(25): c[alp[i]] = alp[i+1] key[alp[i]] = i key["z"] = 25 def dfs(i,k,f,n): global ans if i == n: for j in k: if f[key[j]]: break else: ans.append(k) else: dfs(i+1,k+s[i],f,n) if s[i] != "z" and f[key[s[i]]+1]: f[key[s[i]]+1] = 0 dfs(i+1,k+c[s[i]],f,n) f[key[s[i]]+1] = 1 def solve(s): global ans n = len(s) d = {} for i in s: d[i] = 1 f = [1]*26 f[0] = 0 dfs(0,"",f,n) ans.sort() print(len(ans)) if len(ans) < 10: for i in ans: print(i) else: for i in ans[:5]: print(i) for i in ans[-5:]: print(i) while 1: s = input() ans = [] if s == "#": break solve(s) """ #2004_D """ import sys from collections import defaultdict while 1: d = defaultdict(list) d_ = defaultdict(list) n = int(sys.stdin.readline()) if n == 0:break point = [[float(x) for x in sys.stdin.readline().split()] for i in range(n)] ans = 1 for i in range(n): p,q = point[i] for j in range(n): if i == j:continue s,t = point[j] if (p-s)**2+(q-t)**2 > 4: continue d[i].append(j) if j > i: d_[i].append(j) for i in range(n): p,q = point[i] for j in d_[i]: s,t = point[j] v = (t-q,p-s) m = ((p+s)/2,(q+t)/2) l = 0 r = 10000 while r-l > 0.0001: k = (l+r)/2 a,b = m[0]+k*v[0],m[1]+k*v[1] if (p-a)**2+(q-b)**2 < 1: l = k else: r = k ans_ = 2 for l in d[i]: if l == j: continue x,y = point[l] if (x-a)**2+(y-b)**2 < 1: ans_ += 1 if ans_ > ans: ans = ans_ if ans == n:break k = -k a,b = m[0]+k*v[0],m[1]+k*v[1] ans_ = 2 for l in d[i]: if l == j: continue x,y = point[l] if (x-a)**2+(y-b)**2 < 1: ans_ += 1 if ans_ > ans: ans = ans_ if ans == n:break if ans == n:break print(ans) """ #2010_D import sys from collections import defaultdict,deque d = [(1,0),(-1,0),(0,1),(0,-1)] def bfs(b,a,k): q = deque([(b,a)]) bfs_map[b][a] = k g = a+0.5 p = s[b][a] su = 1 while q: y,x = q.popleft() for dy,dx in d: y_ = y+dy x_ = x+dx if 0 <= y_ < h and 0 <= x_ < w: if bfs_map[y_][x_] < 0 and s[y_][x_] == p: bfs_map[y_][x_] = k q.append((y_,x_)) g += x_+0.5 su += 1 f[k] = (g,su) def dfs(x): if g[x] != None: return g[x] g[x] = [f[x][0],f[x][1]] for y in v[x]: g_ = dfs(y) g[x][0] += g_[0] g[x][1] += g_[1] return g[x] while 1: w,h = [int(x) for x in sys.stdin.readline().split()] if w == 0: break s = [sys.stdin.readline()[:-1] for i in range(h)] f = defaultdict(lambda : 0) bfs_map = [[-1]*w for i in range(h)] k = 0 for y in range(h)[::-1]: for x in range(w): if s[y][x] != "." and bfs_map[y][x] < 0: bfs(y,x,k) k += 1 v = [[] for i in range(k)] l = [float("inf")]*k r = [0]*k fl = [1]*k for y in range(h): for x in range(w): if bfs_map[y][x] > -1: b = bfs_map[y][x] if y == h-1 or (bfs_map[y+1][x] != b and bfs_map[y+1][x] > -1): l[b] = min(l[b],x) r[b] = max(r[b],x+1) if y < h-1 and fl[b]: v[bfs_map[y+1][x]].append(b) fl[b] = 0 g = [None]*k for i in range(k): dfs(i) gx = g[i][0]/g[i][1] if gx <= l[i] or r[i] <= gx: print("UNSTABLE") break else: print("STABLE") ```
output
1
105,199
23
210,399
Provide a correct Python 3 solution for this coding contest problem. You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building. Submitted designs will look like a screenshot of a well known game as shown below. <image> This is because the center specifies that the building should be constructed by stacking regular units called pieces, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions. * All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position. * All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse. * The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces. * The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below. <image> It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows. Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by xy-coordinates of its left-bottom corner. The unit length is the edge length of a block. Among the blocks of the piece that touch another piece or the ground on their bottom faces, let xL be the leftmost x-coordinate of the leftmost block, and let xR be the rightmost x-coordinate of the rightmost block. Let the x-coordinate of its accumulated center of mass of the piece be M, where the accumulated center of mass of a piece P is the center of the mass of the pieces that are directly and indirectly supported by P, in addition to P itself. Then the piece is stable, if and only if xL < M < xR. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable. Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable. <image> | | <image> ---|---|--- Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable. Write a program that judges stability of each design based on the above quick check rules. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows. > w h > p0(h-1)p1(h-1)...p(w-1)(h-1) > ... > p01p11...p(w-1)1 > p00p10...p(w-1)0 > The integers w and h separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ h ≤ 60. The next h lines specify the placement of the pieces. The character pxy indicates the status of a block at (x,y), either ``.`', meaning empty, or one digit character between ``1`' and ``9`', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by xy-coordinates of its left-bottom corner.) When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (x,0) touches the ground. You may assume that the pieces in each dataset are stacked in a tree-like form. Output For each dataset, output a line containing a word `STABLE` when the design is stable with respect to the above quick check rules. Otherwise, output `UNSTABLE`. The output should be written with uppercase letters, and should not contain any other extra characters. Sample Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output for the Sample Input STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE Example Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE
instruction
0
105,200
23
210,400
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) eps = 1e-4 def bsa(f, mi, ma): mm = -1 while ma > mi + eps: mm = (ma+mi) / 2.0 if f(mm): mi = mm + eps else: ma = mm if f(mm): return mm + eps return mm def main(): rr = [] def f(w,h): a = [['.'] * (w+2)] + [['.'] + [c for c in S()] + ['.'] for _ in range(h)] + [['.'] * (w+2)] sf = [[None]*(w+2) for _ in range(h+1)] + [[0] * (w+2)] bs = [] bi = 0 for i in range(1,h+1): for j in range(1,w+1): if sf[i][j] or a[i][j] == '.': continue bi += 1 c = a[i][j] q = [] q.append((i,j)) sf[i][j] = bi qt = 0 while len(q) > qt: qi,qj = q[qt] qt += 1 for di,dj in dd: ni = qi + di nj = qj + dj if sf[ni][nj] or a[ni][nj] != c: continue sf[ni][nj] = bi q.append((ni,nj)) bs.append(q) # print('\n'.join(' '.join(map(lambda x: '.' if x is None else str(x), _)) for _ in sf)) def _f(i): l = inf r = -inf bt = set() tt = set() bi = bs[i-1] wd = collections.defaultdict(int) for si,sj in bi: wd[sj] += 1 c = sf[si+1][sj] if not c is None and c != i: bt.add(c) if l > sj: l = sj if r < sj: r = sj c = sf[si-1][sj] if not c is None and c != i: tt.add(c) if len(bt) != 1: return for ti in tt: td = _f(ti) if td is None: return for k in td.keys(): wd[k] += td[k] def __f(j): w = 0 for k in wd.keys(): w += (k-j) * wd[k] # print('jw',j,w) return w > 0 w = bsa(__f, 0, 11) + 0.5 # print('lr',l,r) # print(i,wd) # print(i,w) if w < l + eps*10 or w > r + 1 - eps*10: return return wd bti = -1 for j in range(1,w+1): if sf[-2][j]: bti = sf[-2][j] # print('bti', bti) r = _f(bti) if r is None: return 'UNSTABLE' return 'STABLE' while 1: n,m = LI() if n == 0 and m == 0: break rr.append(f(n,m)) # print('rr', rr[-1]) return '\n'.join(map(str,rr)) print(main()) ```
output
1
105,200
23
210,401
Provide a correct Python 3 solution for this coding contest problem. You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building. Submitted designs will look like a screenshot of a well known game as shown below. <image> This is because the center specifies that the building should be constructed by stacking regular units called pieces, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions. * All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position. * All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse. * The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces. * The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below. <image> It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows. Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by xy-coordinates of its left-bottom corner. The unit length is the edge length of a block. Among the blocks of the piece that touch another piece or the ground on their bottom faces, let xL be the leftmost x-coordinate of the leftmost block, and let xR be the rightmost x-coordinate of the rightmost block. Let the x-coordinate of its accumulated center of mass of the piece be M, where the accumulated center of mass of a piece P is the center of the mass of the pieces that are directly and indirectly supported by P, in addition to P itself. Then the piece is stable, if and only if xL < M < xR. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable. Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable. <image> | | <image> ---|---|--- Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable. Write a program that judges stability of each design based on the above quick check rules. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows. > w h > p0(h-1)p1(h-1)...p(w-1)(h-1) > ... > p01p11...p(w-1)1 > p00p10...p(w-1)0 > The integers w and h separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ h ≤ 60. The next h lines specify the placement of the pieces. The character pxy indicates the status of a block at (x,y), either ``.`', meaning empty, or one digit character between ``1`' and ``9`', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by xy-coordinates of its left-bottom corner.) When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (x,0) touches the ground. You may assume that the pieces in each dataset are stacked in a tree-like form. Output For each dataset, output a line containing a word `STABLE` when the design is stable with respect to the above quick check rules. Otherwise, output `UNSTABLE`. The output should be written with uppercase letters, and should not contain any other extra characters. Sample Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output for the Sample Input STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE Example Input 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 Output STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE
instruction
0
105,201
23
210,402
"Correct Solution: ``` while True: w, h = map(int, input().split()) if w == 0: break mp = [[0] + list(input()) + [0] for _ in range(h)] mp.insert(0, [0] * (w + 2)) mp.append([0] * (w + 2)) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == ".": mp[y][x] = 0 else: mp[y][x] = int(mp[y][x]) last_id = 10 vec = ((0, 1), (0, -1), (1, 0), (-1, 0)) def update(last_id, target, x, y): if mp[y][x] != target: return mp[y][x] = last_id for dx, dy in vec: update(last_id, target, x + dx, y + dy) for y in range(1, h + 1): for x in range(1, w + 1): if 1 <= mp[y][x] <= 9: update(last_id, mp[y][x], x, y) last_id += 1 node_num = last_id - 10 edges = [set() for _ in range(node_num)] for y in range(1, h + 1): for x in range(1, w + 1): if mp[y - 1][x] != mp[y][x] and mp[y - 1][x] != 0 and mp[y][x] != 0: edges[mp[y][x] - 10].add(mp[y - 1][x] - 10) for x in range(1, w + 1): if mp[h][x] != 0: root = mp[h][x] - 10 break center = [0] * node_num ground = [None] * node_num for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] != 0: target = mp[y][x] - 10 center[target] += (x + 0.5) / 4 if mp[y + 1][x] in (0, target + 10): continue if ground[target] == None: ground[target] = [x, x + 1] else: ground[target][0] = min(ground[target][0], x) ground[target][1] = max(ground[target][1], x + 1) for x in range(1, w + 1): if mp[h][x] == root + 10: if ground[root] == None: ground[root] = [x, x + 1] else: ground[root][0] = min(ground[root][0], x) ground[root][1] = max(ground[root][1], x + 1) total_center = [None] * node_num def get_total_center(node): mom = center[node] wei = 1 for to in edges[node]: to_wei, to_pos = get_total_center(to) mom += to_wei * to_pos wei += to_wei total_center[node] = mom / wei return wei, total_center[node] get_total_center(root) for gr, cen in zip(ground, total_center): l, r = gr if not (l < cen < r): print("UNSTABLE") break else: print("STABLE") ```
output
1
105,201
23
210,403
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,223
23
210,446
"Correct Solution: ``` """ Writer:SPD_9X2 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=ja ヒストグラム上の最大長方形 またdpかな…? 参考: http://algorithms.blog55.fc2.com/blog-entry-132.html """ #最後に要素0を追加してくこと def Largest_rectangle_in_histgram(lis): stk = [] ans = 0 N = len(lis) for i in range(N): if len(stk) == 0: stk.append((lis[i],i)) elif stk[-1][0] < lis[i]: stk.append((lis[i],i)) elif stk[-1][0] == lis[i]: pass else: lastpos = None while len(stk) > 0 and stk[-1][0] > lis[i]: nh,np = stk[-1] lastpos = np del stk[-1] ans = max(ans , nh*(i-np)) stk.append((lis[i] , lastpos)) return ans N = int(input()) h = list(map(int,input().split())) h.append(0) print (Largest_rectangle_in_histgram(h)) ```
output
1
105,223
23
210,447
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,224
23
210,448
"Correct Solution: ``` from collections import deque import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) + [-1] ans = 0 q = deque([]) for i in range(n + 1): ind = i while True: if not q: q.append((a[i], ind)) break if q[-1][0] <= a[i]: q.append((a[i], ind)) break else: height, l = q.pop() ans = max(height * (i - l), ans) ind = l print(ans) ```
output
1
105,224
23
210,449
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,225
23
210,450
"Correct Solution: ``` import sys from collections import deque readline = sys.stdin.readline n = int(readline()) li = list(map(int, readline().split())) def square(P): G = [] L = deque() for i, v in enumerate(P): if not L: L.append((i, v)) continue if v > L[-1][1]: L.append((i, v)) elif v < L[-1][1]: k = i - 1 while L and v < L[-1][1]: a = L.pop() G.append((k - a[0] + 1) * a[1]) L.append((a[0], v)) while L: a = L.pop() G.append((n - a[0]) * a[1]) return max(G) print(square(li)) ```
output
1
105,225
23
210,451
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,226
23
210,452
"Correct Solution: ``` N = int(input()) *H, = map(int, input().split()) st = [(0, -1)] ans = 0 for i in range(N): h = H[i] base = i while st and h <= st[-1][0]: h0, j = st.pop() ans = max(ans, (i-j)*h0) base = j st.append((h, base)) while st: h0, j = st.pop() ans = max(ans, (N-j)*h0) print(ans) ```
output
1
105,226
23
210,453
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,227
23
210,454
"Correct Solution: ``` n = int(input()) rects = list(map(int, input().split())) rects.append(-1) stack = [] ans = 0 for ind, rect in enumerate(rects): # print(stack) if not stack: stack.append((rect, ind)) elif stack[-1][0] < rect: stack.append((rect, ind)) elif stack[-1][0] == rect: continue else: while stack and stack[-1][0] > rect: prect, pind = stack.pop() ans = max(ans, prect * (ind - pind)) stack.append((rect, pind)) print(ans) ```
output
1
105,227
23
210,455
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,228
23
210,456
"Correct Solution: ``` import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def largestRectangInHistgram(heights): stack = [-1] maxArea = 0 for i in range(len(heights)): # we are saving indexes in stack that is why we comparing last element in stack # with current height to check if last element in stack not bigger then # current element while stack[-1] != -1 and heights[stack[-1]] > heights[i]: lastElementIndex = stack.pop() maxArea = max(maxArea, heights[lastElementIndex] * (i - stack[-1] - 1)) stack.append(i) # we went through all elements of heights array # let's check if we have something left in stack while stack[-1] != -1: lastElementIndex = stack.pop() maxArea = max(maxArea, heights[lastElementIndex] * (len(heights) - stack[-1] - 1)) return maxArea def main(): n=ni() a = na() ans = largestRectangInHistgram(a) print(ans) if __name__ == '__main__': main() ```
output
1
105,228
23
210,457
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,229
23
210,458
"Correct Solution: ``` if __name__ == "__main__": N = int(input()) hist = list(map(lambda x: int(x), input().split())) stack = [(0, -1)] # (height, x_position) ans = 0 for i in range(N): height = hist[i] pos = i while stack and height <= stack[-1][0]: h, j = stack.pop() ans = max(ans, (i - j) * h) pos = j stack.append((height, pos)) while stack: h, j = stack.pop() ans = max(ans, (N - j) * h) print(ans) ```
output
1
105,229
23
210,459
Provide a correct Python 3 solution for this coding contest problem. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
instruction
0
105,230
23
210,460
"Correct Solution: ``` n = int(input()) h = list(map(int, input().split( ))) Stk = [] Stk.append([h[0],1]) ans = [] for i in range(1,n): if Stk[-1][0] <= h[i]: Stk.append([h[i],1]) else: tmp = 0 while len(Stk) > 0 and Stk[-1][0]>h[i]: [hei,w] = Stk.pop()#Stk.pop()[0],Stk.pop()[1]だとpop2回することになるか tmp+=w ans.append(hei*tmp) Stk.append([h[i],tmp+1]) ###以上だと最後appendした後の分が欠ける tmp = 0 while len(Stk) > 0: [hei,w] = Stk.pop() tmp+=w ans.append(hei*tmp) print(max(ans)) ```
output
1
105,230
23
210,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n=int(input()) IH=[(i,h) for i,h in enumerate(map(int,input().split()))] IH.append((n,0)) ans=0 Q=[[-1,0]] for i,h in IH: while(Q[-1][1]>h): i0,h0=Q.pop() ans=max(ans,h0*(i-Q[-1][0]-1)) if(Q[-1][1]<h): Q.append([i,h]) elif(Q[-1][1]==h): Q[-1][0]=i print(ans) resolve() ```
instruction
0
105,231
23
210,462
Yes
output
1
105,231
23
210,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` import sys,bisect sys.setrecursionlimit(15000) n = int(sys.stdin.readline()) a = list(map(int,sys.stdin.readline().split())) a.append(0) st = [] ar = 0 for i in range(n+1): if not st: st.append([i,a[i]]) elif st[-1][1] < a[i]: st.append([i,a[i]]) elif st[-1][1] == a[i]: st.append([i,a[i]]) elif st[-1][1] > a[i]: while st and st[-1][1] >= a[i]: j,h = st.pop() ar = max(ar,(i-j)*(h)) st.append([j,a[i]]) #print(i,ar,st) #print(a) print(ar) ```
instruction
0
105,232
23
210,464
Yes
output
1
105,232
23
210,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` import sys, collections file = sys.stdin n = int(file.readline()) C = list(map(int, file.readline().split())) def square(P): G = [] L = collections.deque() for i,v in enumerate(P): if not L: L.append((i, v)) continue if v > L[-1][1]: L.append((i, v)) elif v < L[-1][1]: k = i - 1 while L and v < L[-1][1]: a = L.pop() G.append((k - a[0] + 1) * a[1]) L.append((a[0], v)) while L: a = L.pop() G.append((len(P) - a[0]) * a[1]) return max(G) print(square(C)) ```
instruction
0
105,233
23
210,466
Yes
output
1
105,233
23
210,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` def calc_largest_rect_in_hist(heights): heights.append(0) stack = [] left = [0] * len(heights) ans = 0 for i, height in enumerate(heights): while stack and heights[stack[-1]] >= height: idx = stack.pop() ans = max(ans, (i - left[idx] - 1) * heights[idx]) left[i] = stack[-1] if stack else -1 stack.append(i) return ans def aoj(): input() print(calc_largest_rect_in_hist([int(x) for x in input().split()])) if __name__ == "__main__": aoj() ```
instruction
0
105,234
23
210,468
Yes
output
1
105,234
23
210,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` n = int(input()) rects = list(map(int, input().split())) rects.append(-1) stack = [] ans = 0 for ind, rect in enumerate(rects): # print(stack) if not stack: stack.append((rect, ind)) elif stack[-1][0] < rect: stack.append((rect, ind)) elif stack[-1][0] == rect: continue else: while stack and stack[-1][0] > rect: prect, pind = stack.pop() ans = max(ans, prect * (ind - pind)) if not stack: stack.append((rect, ind)) elif stack[-1][0] != rect: stack.append((rect, pind)) print(ans) ```
instruction
0
105,235
23
210,470
No
output
1
105,235
23
210,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` n = int(input()) rects = list(map(int, input().split())) stack = [] ans = 0 for ind, rect in enumerate(rects): if not stack: stack.append((rect, ind)) elif stack[-1][0] < rect: stack.append((rect, ind)) elif stack[-1][0] == rect: continue else: while stack and stack[-1][0] > rect: prect, pind = stack.pop() ans = max(ans, prect * (ind - pind)) if not stack or stack[-1][0] != rect: stack.append((rect, ind)) print(ans) ```
instruction
0
105,236
23
210,472
No
output
1
105,236
23
210,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` n = int(input()) hs = list(map(int, input().split())) stack = [] ans = 0 for i, h in enumerate(hs): while stack and stack[-1][1] > h: j, h2 = stack.pop() ans = max(ans, (i - j) * h2) if not stack or stack[-1][1] < h: stack.append((i, h)) ans = max(ans, max((n - j) * h2 for j, h2 in stack)) print(ans) ```
instruction
0
105,237
23
210,474
No
output
1
105,237
23
210,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2 Submitted Solution: ``` N = int(input()) element = [] hist = list(map(int,input().split())) maxhist = 0 maxrect = 0 for i in range(N): pos = 0 if i == 0: element.append([i,hist[i]]) maxhist = hist[i] elif hist[i] > maxhist: element.append([i,hist[i]]) maxhist = hist[i] elif hist[i] < maxhist: for j in reversed(element): if j[1]*(i - j[0]) > maxrect and hist[i] < j[1]: maxrect = j[1]*(i - j[0]) element.remove(j) elif hist[i] >= j[1]: pos = j[0]+1 break element.append([pos,hist[i]]) print(maxrect) ```
instruction
0
105,238
23
210,476
No
output
1
105,238
23
210,477
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,542
23
211,084
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` if __name__ == '__main__': n,k = map(int,input().split()) l = list(map(int,input().split())) for i in range(1,len(l),2): if l[i]-1 > l[i-1] and l[i]-1 > l[i+1]: l[i] -= 1 k -= 1 if k == 0: break print(*l,sep=" ") ```
output
1
105,542
23
211,085
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,543
23
211,086
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` """609C""" # import math def main(): n,k = map(int,input().split()) a = list( map(int,input().split()) ) for i in range(len(a)-2): # print(i) # print(a) if a[i+1]-1>a[i] and a[i+1]-1>a[i+2]: a[i+1]-=1 k-=1 if k==0: # print("hello") break for x in a: print(x,end=' ') print() main() # t= int(input()) # while t: # main() # t-=1 ```
output
1
105,543
23
211,087
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,544
23
211,088
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` a, b = map(int,input().split()) ans = 0 l = list(map(int,input().split())) for i in range(b): for i in range(1 ,len(l ) - 1): if ans == b: print(*l) exit() if l[i] > l[i + 1] and l[i] > l[i - 1] : if l[i] - 1 <= l[i -1 ] or l[i] -1 <= l[i + 1]: pass else: l[i] -= 1 ans += 1 print(*l) ```
output
1
105,544
23
211,089
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,545
23
211,090
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) points = list(map(int, input().split())) c = 0 i = 1 while c < k: if points[i-1]<(points[i]-1) and (points[i]-1)>points[i+1]: points[i]-=1 c+=1 #print(c) i+=2 print(" ".join(list(map(str, points)))) ```
output
1
105,545
23
211,091
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,546
23
211,092
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Fri Jul 24 12:40:45 2020 @author: lalo """ n,x=[int(x) for x in input().split()] l=[int(x) for x in input().split()] a=0 print(l[0],end=' ') for i in range(1,len(l)-1): k=l[i]-1 if (k>l[i-1] and k>l[i+1] and a<x): print(k,end=' ') a+=1 else: print(l[i],end=' ') print(l[len(l)-1],end=' ') ```
output
1
105,546
23
211,093
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,547
23
211,094
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n, k = map(int, input().split()) l = list(map(int, input().split())) j = 0 for i in range(1, 2 * n + 1, 2): if l[i] > (l[i-1] + 1) and l[i] > (l[i+1] + 1): l[i] -= 1 j += 1 if j == k: break print(" ".join(map(str, l))) ```
output
1
105,547
23
211,095
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,548
23
211,096
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` #!/usr/bin/env python3 n, k = map(int,input().split()) y_points = list(map(int,input().split())) k_tot=0 last_odd = len(y_points)-2 if (len(y_points)-1)%2==0 else len(y_points)-1 for i in range(last_odd,0,-2): if k_tot<k: if (y_points[i]-1)>y_points[i+1] and (y_points[i]-1)>y_points[i-1]: k_tot += 1 y_points[i]-=1 print(" ".join(map(str,y_points))) ```
output
1
105,548
23
211,097
Provide tags and a correct Python 3 solution for this coding contest problem. Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak. <image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2. Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1). Given Bolek's final picture, restore the initial one. Input The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Output Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Examples Input 3 2 0 5 3 5 1 5 2 Output 0 5 3 4 1 4 2 Input 1 1 0 2 0 Output 0 1 0
instruction
0
105,549
23
211,098
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` def arr_inp(): return [int(x) for x in input().split()] def print_arr(arr): print(*arr, sep=' ') n, k = map(int, input().split()) y = arr_inp() for i in range(1, n * 2, 2): if (k == 0): break if (y[i] - y[i - 1] > 1 and y[i] - y[i + 1] > 1): y[i] -= 1 k -= 1 print_arr(y) ```
output
1
105,549
23
211,099