diff --git a/src/Looped_string.py b/src/Looped_string.py new file mode 100644 index 0000000..3318377 --- /dev/null +++ b/src/Looped_string.py @@ -0,0 +1,16 @@ +def looped_string(S, n): + res = [0]*n + res[0] = 0 + for i in range(n-1): + x = res[i] + while (x > 0 and S[i+1] != S[x]): + x = res[x-1] + if (S[i+1] == S[x]): + res[i+1] = x + 1 + else: + res[i+1] = 0 + return res + +T = input() +S = looped_string(T, len(T)) +print(len(T) - S[len(S)-1]) \ No newline at end of file diff --git a/src/Psp.py b/src/Psp.py new file mode 100644 index 0000000..d3c597d --- /dev/null +++ b/src/Psp.py @@ -0,0 +1,14 @@ +def Psp(s): + Counter=0 + myStack = [] + for c in s: + if (c == '('): + myStack.append(c) + elif (myStack != []) and (myStack[-1] == '('): + myStack.pop() + else: + Counter += 1 + return Counter+len(myStack) + +s = str(input()) +print(Psp(s)) \ No newline at end of file diff --git a/src/balanced_tree.py b/src/balanced_tree.py new file mode 100644 index 0000000..04a5818 --- /dev/null +++ b/src/balanced_tree.py @@ -0,0 +1,48 @@ +class Node: + def __init__(self, data): + self.data = data + self.left = None + self.right = None + + def add(self, data): + if data == self.data: + return + if data < self.data: + if self.right: + self.right.add(data) + else: + self.right = Node(data) + else: + if self.left: + self.left.add(data) + else: + self.left = Node(data) + +def elevation(tree): + if tree is None: + return 0 + return max(elevation(tree.right), elevation(tree.left))+1 + +def binary_tree(el): + base = Node(el[0]) + for i in range(1, len(el)): + base.add(el[i]) + return base + +def balance(tree): + if not tree or ((elevation(tree.right) == elevation(tree.left) or elevation(tree.right)+1 == elevation(tree.left) or elevation(tree.right) == elevation(tree.left)+1) + and balance(tree.right) and balance(tree.left)): + return 1 + return 0 + +def main(): + n = list(map(int,input().split())) + n.pop() + tree = binary_tree(n) + + if balance(tree) == 1: + print("YES") + else: + print("NO") + +main() \ No newline at end of file diff --git a/src/bubble_sort.py b/src/bubble_sort.py new file mode 100644 index 0000000..fd1349c --- /dev/null +++ b/src/bubble_sort.py @@ -0,0 +1,20 @@ +n= int(input()) +arr = input() +str_lst = arr.split() +res = [] +num = True +for item in str_lst: + res.append(int(item)) + +n = len(res) +for i in range (0, n-1): + #print(i) + for j in range(0, n-i-1): + #print(j) + if res[j] > res[j+1]: + num = False + res[j],res[j+1] = res[j+1],res[j] + print(" ".join(map(str, res))) + +if num == True: + print(0) \ No newline at end of file diff --git a/src/dynamic_version.py b/src/dynamic_version.py new file mode 100644 index 0000000..e44e95d --- /dev/null +++ b/src/dynamic_version.py @@ -0,0 +1,50 @@ +from math import gcd + +def dynamic_version(val, x, r, num, p): + if r - x == 1: + num[val] = p[x] + return + + middle = (x + r)//2 + dynamic_version(2*val + 1, x, middle, num, p) + dynamic_version(2*val + 2, middle, r, num, p) + num[val] = gcd(num[2*val+1], num[2*val+2]) + +def calc(val, x, r, it, q_x, q_r): + if q_x <= x and q_r >= r: + return it[val] + if q_x >= r or q_r <= x: + return 0 + + middle = (x + r)//2 + tx = calc(2*val + 1, x, middle, it, q_x, q_r) + tr = calc(2*val + 2, middle, r, it, q_x, q_r) + return gcd(tx, tr) + +def up(val, x, r, num, idx, value): + if r - x == 1: + num[val] = value + return + middle = (r+x)//2 + if idx < middle: + up(val*2+1, x, middle, num, idx, value) + else: + up(val*2+2, middle, r, num, idx, value) + num[val] = gcd(num[2*val+1], num[2*val+2]) + +def main(): + t = int(input()) + num = [0] * (4 * t) + p = list(map(int, input().split()))[:t] + dynamic_version(0, 0, t, num, p) + q = int(input()) + ct = [] + while q != 0: + t_q, x, r = map(str, input().split()) + if t_q == 's': + ct.append(calc(0, 0, t, num, int(x)-1, int(r))) + else: + up(0, 0, t, num, int(x)-1, int(r)) + q -= 1 + print(*ct) +main() \ No newline at end of file diff --git a/src/fifth.py b/src/fifth.py new file mode 100644 index 0000000..7c8073e --- /dev/null +++ b/src/fifth.py @@ -0,0 +1,8 @@ +n = int(input()) +m = list(map(int, input().split(" "))) +sort ={} +for i in m: + if i not in sort: + sort[i] = 1 + +print(len(sort)) diff --git a/src/greatest_common_factor.py b/src/greatest_common_factor.py new file mode 100644 index 0000000..9738dac --- /dev/null +++ b/src/greatest_common_factor.py @@ -0,0 +1,40 @@ +def g_c_f(b, lft, rght, s_leaf, arr): + if rght - lft == 1: + s_leaf[b] = arr[lft] + return + m = (rght + lft) // 2 + g_c_f(2 * b + 1, lft, m, s_leaf, arr) + g_c_f(2 * b + 2, m, rght, s_leaf, arr) + s_leaf[b] = GCF(s_leaf[2 * b + 1], s_leaf[2 * b + 2]) + +def GCF(p,b): + while b: + p, b = b, p%b + return p + +def get_GCF(b, lft, rght, s_leaf, left, right): + if left <= lft and right >= rght: + return s_leaf[b] + if left >= rght or right <= lft: + return 0 + m = (rght + lft) // 2 + st_right = get_GCF(2 * b + 2, m, rght, s_leaf, left, right) + st_left = get_GCF(2 * b + 1, lft, m, s_leaf, left, right) + return GCF(st_left, st_right) + + +def main(): + n = int(input()) + arr = list(map(int, input().split()))[:n] + s_leaf = [0] * 4 * n + g_c_f(0, 0, n, s_leaf, arr) + q = int(input()) + p = [] + + while q != 0: + lft, rght = map(int, input().split()) + p.append(get_GCF(0, 0, n, s_leaf, lft - 1, rght)) + q -= 1 + print(*p) + +main() \ No newline at end of file diff --git a/src/hash.py b/src/hash.py new file mode 100644 index 0000000..6ac5026 --- /dev/null +++ b/src/hash.py @@ -0,0 +1,29 @@ +def substring_search(S, T): + substring_str = 0 + for i in range(T): + substring_str = (substring_str * p + ord(S[i])) % q + return substring_str + +def Rabin_Karp_Matcher(str_substring, pattern, x, y): + lst = [] + str_substring = hash(y) + pattern_substring = hash(y) + pt = 1 + for i in range(x-1): + pt = (pt * p) % q + for i in range(1, x-y+2): + if str_substring == pattern_substring: + lst.append(i-1) + if i < x-y+1: + str_substring = (str_substring - ord(str_substring[i-1]) * pt) * p + str_substring += ord(str_substring[i + y - 1]) + str_substring %= q + return lst +string = input() +pattern_string = input() +global p +p = 31 +global q +q = 2 ** 31 - 1 +A = Rabin_Karp_Matcher(string, pattern_string, len(string), len(pattern_string)) +print(' '.join(map(str, A))) \ No newline at end of file diff --git a/src/hash_hash.py b/src/hash_hash.py new file mode 100644 index 0000000..f0826a4 --- /dev/null +++ b/src/hash_hash.py @@ -0,0 +1,36 @@ +def cyclic_shift(c,x,y): + hash = 0 + for i in range(len(c)): + hash = (hash*x+ord(c[i]))%y + return hash + +def function(c,t,x,y): + if c!=t: + arr = 1 + t = t[1:] + t[0] + c_s = cyclic_shift(c,x,y) + t_s = cyclic_shift(t,x,y) + k = 1 + for i in range(len(c)-1): + k=(k*x)%y + for i in range(len(t)-1): + if c_s == t_s: + break + else: + t_s = (x*(t_s-ord(t[i])*k) + ord(t[i]))%y + arr += 1 + if c_s == t_s: + print(arr) + else: + print(-1) + else: + print(0) + +def main(): + c = input() + t = input() + x = 30 + y = 1e9+6 + a = function(c,t,x,y) + +main() \ No newline at end of file diff --git a/src/insertion_sort.py b/src/insertion_sort.py new file mode 100644 index 0000000..33703ec --- /dev/null +++ b/src/insertion_sort.py @@ -0,0 +1,16 @@ + +mas = [[int(i) for i in input().split(" ")]for _ in range(int(input()))] + + +for j in range( len(mas)): + for i in range( len(mas)-1): + if(mas[i][1] < mas[i+1][1]): + mas[i][0],mas[i+1][0] = mas[i+1][0],mas[i][0] + mas[i][1],mas[i+1][1] = mas[i+1][1],mas[i][1] + if(mas[i][1] == mas[i+1][1]): + if(mas[i][0] > mas[i+1][0]): + mas[i][0],mas[i+1][0] = mas[i+1][0],mas[i][0] + mas[i][1],mas[i+1][1] = mas[i+1][1],mas[i][1] +for i in range( len(mas)): + + print(mas[i][0], mas[i][1]) diff --git a/src/inversion.py b/src/inversion.py new file mode 100644 index 0000000..f0f7fe5 --- /dev/null +++ b/src/inversion.py @@ -0,0 +1,35 @@ +def invers_fun(num): + n = len(num) + if n <= 1: + return num, 0 + mid = n//2 + left, left_inv = invers_fun(num[:mid]) + right, right_inv = invers_fun(num[mid:]) + cout, s = sort(left, right) + m = s + left_inv + right_inv + return cout, m + +def sort(left, right): + s = 0 + cout = [] + i, j = 0, 0 + while i < len(left) and j < len(right): + if left[i] <= right[j]: + cout.append(left[i]) + i += 1 + else: + cout.append(right[j]) + j += 1 + s += len(left) - i + while i < len(left): + cout.append(left[i]) + i += 1 + while j < len(right): + cout.append(right[j]) + j += 1 + return cout, s + +n = int(input()) +num = list(map(int, input().split(" "))) +num, inversions = invers_fun(num) +print(inversions) \ No newline at end of file diff --git a/src/line_period.py b/src/line_period.py new file mode 100644 index 0000000..9f861ce --- /dev/null +++ b/src/line_period.py @@ -0,0 +1,23 @@ +def line_period(s): + x = [0] * len(s) + for i in range(1, len(s)): + k = x[i-1] + while (k > 0 and s[k] != s[i]): + k = x[k - 1] + if s[i] == s[k]: + k += 1 + x[i] = k + return x + +def main(): + s = input() + s_t = s + '&' + s + L = line_period(s_t) + lr = L[-1]-L[len(s)-1] + k = len(s)//lr + if s[:lr]*k == s: + print(k) + else: + print(1) + +main() \ No newline at end of file diff --git a/src/main.py b/src/main.py index 6d95fe9..1596831 100644 --- a/src/main.py +++ b/src/main.py @@ -1 +1 @@ -print("Hello world") \ No newline at end of file +print("Hello, " + input() + "!") \ No newline at end of file diff --git a/src/merger_sort.py b/src/merger_sort.py new file mode 100644 index 0000000..858eac9 --- /dev/null +++ b/src/merger_sort.py @@ -0,0 +1,35 @@ + +def merger(mas, List): + new_list = [] + i, j = 0, 0 + while i < len(mas) and j < len(List): + if mas[i] < List[j]: + new_list.append(mas[i]) + i += 1 + else: + new_list.append(List[j]) + j += 1 + while i < len(mas): + new_list.append(mas[i]) + i += 1 + while j < len(List): + new_list.append(List[j]) + j += 1 + + return new_list +def merger_sort(mas, index): + if len(mas) < 2: + return mas + else: + mid = len(mas)//2 + left = merger_sort(mas[:mid], [index[0],index[0]+mid]) + right = merger_sort(mas[mid:],[index[0]+mid, index[1]]) + + sort = merger(left, right) + print(index[0]+1, index[1], sort[0], sort[-1]) + return sort +Size = int(input()) +mas = list(map(int, input().split(" "))) + +mas = merger_sort(mas,[0, Size]) +print(' '.join(map(str, mas))) \ No newline at end of file diff --git a/src/not the main copy.py b/src/not the main copy.py new file mode 100644 index 0000000..1596831 --- /dev/null +++ b/src/not the main copy.py @@ -0,0 +1 @@ +print("Hello, " + input() + "!") \ No newline at end of file diff --git a/src/nums.py b/src/nums.py new file mode 100644 index 0000000..a6b4ac0 --- /dev/null +++ b/src/nums.py @@ -0,0 +1,23 @@ +def closest_smaller(S, n): + stack = [n-1] + index = [0]*n + index[n-1] = -1 + for i in range(n-2, -1, -1): + if S[stack[-1]] >= S[i]: + while (stack != []) and (S[stack[-1]] >= S[i]): + stack.pop() + if (stack == []): + index[i] = -1 + else: + index[i] = stack[-1] + stack.append(i) + else: + index[i] = stack[-1] + stack.append(i) + return index + + +N = int(input()) +S = list(map(int, input().split())) +S = closest_smaller(S, N) +print(' '.join(map(str, S))) \ No newline at end of file diff --git a/src/nums_sort.py b/src/nums_sort.py new file mode 100644 index 0000000..6de80a4 --- /dev/null +++ b/src/nums_sort.py @@ -0,0 +1,8 @@ +n = int(input()) +m = list(map(int, input().split())) +x = 0 +m.sort() +for i in range(n-1): + if m[i] != m[i+1]: + x +=1 +print(x+1) diff --git a/src/radix_sort.py b/src/radix_sort.py new file mode 100644 index 0000000..3c62e58 --- /dev/null +++ b/src/radix_sort.py @@ -0,0 +1,29 @@ +def radix_sort(L, n): + mas = len(L(0)) + length = len(str(max(L))) + for i in range(mas): + arr = [[] for j in range(10)] + L=[] + for item in L: + index = int(item)//10**i % 10 + arr[index].append(item) + print("Phase 1", i+1) + for i in range(10): + print(f"Bucket {i}: ", end="") + print(", ".join(arr[i]) if len(arr[i])>0 else "empty") + L = L + arr[i] + print("**********") + return L + +N = int(input()) +L = [] +for i in range(N): + L.append(input()) +print("Initial array:") +print(", ".join(L)) +print("**********") +L = radix_sort(L, N) +print("Sorted array:") +print(", ".join(L)) + + diff --git a/src/righthash.py b/src/righthash.py new file mode 100644 index 0000000..fe6a889 --- /dev/null +++ b/src/righthash.py @@ -0,0 +1,22 @@ +def substring_search(m): + S = [0]*len(m) + for i in range(len(m) - 1): + j = S[i] + while j > 0 and (m[i+1] != m[j]): + j = S[j-1] + if m[i+1] == m[j]: + S[i+1] = j+1 + else: + S[i+1] = 0 + return S + +def main(): + k = input() + t = input() + t_k = t + '&' + k + S = substring_search(t_k) + for i in range(len(S)): + if S[i] == len(t): + print(i-2*len(t), end = ' ') + +main() \ No newline at end of file diff --git a/src/storage.py b/src/storage.py new file mode 100644 index 0000000..3dc5713 --- /dev/null +++ b/src/storage.py @@ -0,0 +1,16 @@ + +N = int(input()) +m = list(map(int, input().split(" "))) +k = int(input()) +t = list(map(int, input().split(" "))) +def counting_sort(m, t, n): + temp = [0]*(n+1) + for item in t: + temp[item] += 1 + for i in range(n): + if m[i] >= temp[i+1]: + print("no") + else: + print("yes") + +counting_sort(m, t, N) \ No newline at end of file diff --git a/src/sub_din.py b/src/sub_din.py new file mode 100644 index 0000000..f06ee8b --- /dev/null +++ b/src/sub_din.py @@ -0,0 +1,67 @@ +def sub_din(val, x, r, s_sub, p): + if r-x == 1: + s_sub[val] = p[x] + return + m = (r+x)//2 + sub_din(2*val+1, x, m, s_sub, p) + sub_din(2*val+2, m, r, s_sub, p) + s_sub[val] = s_sub[2*val+1] + s_sub[2*val+2] + +def search(val, x, r, s_sub, t): + if t > s_sub[val]: + return -1 + if r - x == 1: + return r + m = (r+x)//2 + if s_sub[2*val+1] >= t: + return search(2*val+1, x, m, s_sub, t) + else: + return search(2*val+2, m, r, s_sub, t - s_sub[2*val+1]) + +def get_sum(val, x, r, s_sub, qx, qr): + if qx <= x and qr >= r: + return s_sub[val] + if qx >= r or qr <= x: + return 0 + m = (r+x)//2 + tx = get_sum(2*val+1, x, m, s_sub, qx, qr) + tr = get_sum(2*val+2, m, r, s_sub, qx, qr) + return tx + tr + +def up(val, x, r, s_sub, indx, value): + if r-x == 1: + s_sub[val] = value + return + m = (r+x)//2 + if indx < m: + up(2*val+1, x, m, s_sub, indx, value) + else: + up(2*val+2, m, r, s_sub, indx, value) + s_sub[val] = s_sub[2*val+1] + s_sub[2*val+2] +def main(): + n = int(input()) + p = [0 if int(i) != 0 else 1 for i in input().split()] + s_sub = [0]*4*n + sub_din(0, 0, n, s_sub, p) + q = int(input()) + ind = [] + while q != 0: + i = input().split() + if len(i) == 4: + x, r, t = int(i[1]), int(i[2]), int(i[3]) + cout_ = get_sum(0, 0, n, s_sub, x-1, r) + if cout_ >= t and x > 1: + ind.append(search(0, 0, n, s_sub, t+get_sum(0, 0, n, s_sub, 0, x-1))) + elif cout_ >= t and x == 1: + ind.append(search(0, 0, n, s_sub, t)) + else: + ind.append(-1) + else: + i, val = int(i[1]), int(i[2]) + if val == 0: + up(0, 0, n, s_sub, i-1, 1) + else: + up(0, 0, n, s_sub, i-1, 0) + q -= 1 + print(*ind) +main() \ No newline at end of file diff --git a/src/subsegment.py b/src/subsegment.py new file mode 100644 index 0000000..f5920ea --- /dev/null +++ b/src/subsegment.py @@ -0,0 +1,48 @@ +def subsegment(b, lft, rght, s_sub, p): + if rght-lft == 1: + s_sub[b] = p[lft] + return + m = (rght+lft)//2 + subsegment(2*b+1, lft, m, s_sub, p) + subsegment(2*b+2, m, rght, s_sub, p) + s_sub[b] = s_sub[2*b+1] + s_sub[2*b+2] + +def rummage(b, lft, rght, s_sub, t): + if t > s_sub[b]: + return -1 + if rght - lft == 1: + return rght + m = (rght+lft)//2 + if s_sub[2*b+1] >= t: + return rummage(2*b+1, lft, m, s_sub, t) + else: + return rummage(2*b+2, m, rght, s_sub, t - s_sub[2*b+1]) + +def get_sum(b, lft, rght, s_sub, ql, qr): + if ql <= lft and qr >= rght: + return s_sub[b] + if ql >= rght or qr <= lft: + return 0 + m = (rght+lft)//2 + s_left = get_sum(2*b+1, lft, m, s_sub, ql, qr) + s_right = get_sum(2*b+2, m, rght, s_sub, ql, qr) + return s_left + s_right +def main(): + arr = int(input()) + p = [0 if int(i) != 0 else 1 for i in input().split()] + s_sub = [0]*4*arr + subsegment(0, 0, arr, s_sub, p) + q = int(input()) + index = [] + while q != 0: + lft, rght, t = map(int, input().split()) + sum = get_sum(0, 0, arr, s_sub, lft-1, rght) + if sum >= t and lft > 1: + index.append(rummage(0, 0, arr, s_sub, t+get_sum(0, 0, arr, s_sub, 0, lft-1))) + elif sum >= t and lft == 1: + index.append(rummage(0, 0, arr, s_sub, t)) + else: + index.append(-1) + q -= 1 + print(*index) +main() \ No newline at end of file diff --git a/src/task3.py b/src/task3.py new file mode 100644 index 0000000..ecd50b7 --- /dev/null +++ b/src/task3.py @@ -0,0 +1,34 @@ +def merger(mas, List): + new_list = [] + i, j = 0, 0 + while i < len(mas) and j < len(List): + if mas[i] < List[j]: + new_list.append(mas[i]) + i += 1 + else: + new_list.append(List[j]) + j += 1 + while i < len(mas): + new_list.append(mas[i]) + i += 1 + while j < len(List): + new_list.append(List[j]) + j += 1 + + return new_list +def merger_sort(mas, index): + if len(mas) < 2: + return mas + else: + mid = len(mas)//2 + left = merger_sort(mas[:mid], [index[0],index[0]+mid]) + right = merger_sort(mas[mid:],[index[0]+mid, index[1]]) + + sort = merger(left, right) + print(index[0]+1, index[1], sort[0], sort[-1]) + return sort +Size = int(input()) +mas = list(map(int, input().split())) + +mas = merger_sort(mas,[0, Size]) +print(" ".join(map(str, mas))) diff --git a/src/task7.py b/src/task7.py new file mode 100644 index 0000000..d44f652 --- /dev/null +++ b/src/task7.py @@ -0,0 +1,26 @@ +def radix_sort(L, n): + mas = len(L[0]) + for i in range(mas): + radix_arr = [[] for j in range(10)] + for item in L: + index = int(item)//10**i % 10 + radix_arr[index].append(item) + print("Phase", i+1) + L = [] + for i in range(10): + print("Bucket ", i ,":", sep = "", end=" ") + print(", ".join(radix_arr[i]) if len(radix_arr[i])>0 else "empty") + L = L + radix_arr[i] + print("**********") + return L + +n = int(input()) +L = [] +for i in range(n): + L.append(input()) +print("Initial array:") +print(", ".join(L)) +print("**********") +L = radix_sort(L, n) +print("Sorted array:") +print(", ".join(L)) \ No newline at end of file diff --git a/src/trains.py b/src/trains.py new file mode 100644 index 0000000..6135718 --- /dev/null +++ b/src/trains.py @@ -0,0 +1,23 @@ +l = int(input()) +s = list(map(int, input().split())) + +deadlock = [0] +wayB = [0] + +for i in range(l): + while deadlock[-1] == wayB[-1] + 1: + wayB.append(deadlock[-1]) + deadlock.pop() + if s[i] == wayB[-1] + 1: + wayB.append(s[i]) + else: + deadlock.append(s[i]) + +while deadlock[-1] == wayB[-1] + 1: + wayB.append(deadlock[-1]) + deadlock.pop() + +if wayB[-1] == l: + print('YES') +else: + print('NO') diff --git a/src/tree.py b/src/tree.py new file mode 100644 index 0000000..cdf580b --- /dev/null +++ b/src/tree.py @@ -0,0 +1,55 @@ +class key: + __size = 0 + __height = 0 + + def __init__(trees, leaf): + trees.leaf = leaf + trees.left = None + trees.right = None + key.__size += 1 + + @property + def size(trees): + return trees.__size + + @property + def height(trees): + return trees.__height + + def add(trees, meaning, elevation): + if trees.leaf == meaning: + return + if meaning < trees.leaf: + if trees.left: + trees.left.add(meaning, elevation+1) + else: + if key.__height < elevation: + key.__height = elevation + trees.left = key(meaning) + else: + if trees.right: + trees.right.add(meaning, elevation+1) + else: + if key.__height < elevation: + key.__height = elevation + trees.right = key(meaning) + + def find_divarication(trees): + if trees.left: + trees.left.find_divarication() + if trees.left and not trees.right: + print(trees.leaf) + if trees.right and not trees.left: + print(trees.leaf) + if trees.right: + trees.right.find_divarication() + +def binary_tree(objct): + tree = key(objct[0]) + for i in range(1, len(objct)-1): + tree.add(objct[i], 1) + return tree + +lisst = list(map(int, input().split())) +tree = binary_tree(lisst) +tree.find_divarication() \ No newline at end of file diff --git a/src/window.py b/src/window.py new file mode 100644 index 0000000..b3db034 --- /dev/null +++ b/src/window.py @@ -0,0 +1,17 @@ +def Segment_minima(n, m_w, s): + stack = [] + for i in range(m_w): + while stack and s[i] <= s[stack[-1]]: + stack.pop() + stack.append(i) + for i in range(m_w, n): + print(s[stack[0]]) + while stack and i - m_w >= stack[0]: + stack.pop(0) + while stack and s[i] <= s[stack[-1]]: + stack.pop() + stack.append(i) + print(s[stack[0]]) +N, K = map(int, input().split()) +s = list(map(int, input().split())) +Segment_minima(N, K, s) \ No newline at end of file