As a little proof of concept, I include here Python code for today’s »HourRank 27« competition problems. All of the solutions below are fast enough and got “Accepted”.

1. Impressing the Boss

for _ in range(int(input())):
    n, a = int(input()), list(map(int, input().split()))
    # Try removing every element and see if the remainder is sorted
    print('YES' if any(map(lambda x: sorted(x)==x, [a[:i] + a[i+1:] for i in range(n)])) else 'NO')

2. Maximizing the profit

n, a = int(input()), list(map(int, input().split()))

# the smallest previous element
min_left = [None]
min_so_far = float('inf')
for el in a[:-1]:
    min_so_far = min(el, min_so_far)
    min_left.append(min_so_far)

# the greatest next element
max_right = [None]
max_so_far = -float('inf')
for el in a[::-1][:-1]:
    max_so_far = max(el, max_so_far)
    max_right.append(max_so_far)
max_right = max_right[::-1] # reverse order

# Idea: Sort the array [(a[i], i), ...] and use stack
#
# the greatest previous element that is smaller
smaller_left, stack = [None] * n, []
for el, ind in sorted(zip(a, range(n))):
    while stack and (ind < stack[-1] or a[stack[-1]] == el):
        stack.pop()
    if stack:
        smaller_left[ind] = a[stack[-1]]
    stack.append(ind)

# the smallest next element that is greater
greater_right, stack = [None] * n, []
for el, ind in sorted(zip(a, range(n)), key=lambda x: -x[0]):
    while stack and (ind > stack[-1] or a[stack[-1]] == el):
        stack.pop()
    if stack:
        greater_right[ind] = a[stack[-1]]
    stack.append(ind)

result = -float('inf')
for pj, mnl, sml, mxr, grr in zip(a, min_left, smaller_left, max_right, greater_right):
    for pi in [mnl, sml]:
        for pk in [mxr, grr]:
            if pi != None and pk != None and pi < pj < pk:
                result = max(pi * pj * pk, result)
print(-1 if result == -float('inf') else result)

3. Moving the kings

from bisect import bisect_left
from itertools import accumulate
transform_coors = lambda x, y: (x+y, x-y) # coordinate transform

n, q = map(int, input().split())
kings, queries = [[transform_coors(*map(int, input().split())) for _ in range(r)] for r in [n, q]]

kings_xs, kings_ys = [sorted([k[ind] for k in kings]) for ind in [0, 1]]
# prefix sums
px, py = [0] + list(accumulate(kings_xs)), [0] + list(accumulate(kings_ys))

def query(x, y):
    result = 0
    ix, iy = bisect_left(kings_xs, x), bisect_left(kings_ys, y)
    return (py[-1] + px[-1] - n*x - n*y)//2 + ix*x + iy*y - py[iy] - px[ix]

for q in queries:
    print(query(*q))