def adjust(salaries: list[float], target: float) -> list[float]:
n = len(salaries)
salaries.sort()
for i, salary in enumerate(salaries):
if (n - i) * salary > target:
adjustment = target / (n - i)
break
else:
target -= salary



def _strip(s):
n = len(s)
l = 0
while l < n and s[l] == " ": l += 1
r = n - 1
while r >= 0 and s[r] == " ": r -= 1
return s[l:r+1] if r >= l else ""

def split(s):
result = []
l = 0
quote = 0
s = _strip(s)
for r, char in enumerate(s + " "):
if char == " ":
if quote: continue
section = _strip(s[l:r])
l = r
if section: result.append(section)
elif char == "'":
quote ^= 1

if quote:
raise Exception("unmatched single quote.")

return result

split("   Hello   World! 'Beauti'ful world! ")


Consider 2 x 2 - 2 ** 4 = 16 cases Only viaable configs are: 00 11 00 11 01 10 01 10 00 11 11 00 01 10 10 01 All others 8 cases are bad

Move to 3 x 3 - 2 ** 9 = 512 case, inpossible to enumerate, try reduce to 2 x 2 case Consider config in following which we can archive by enforcing first row and first column 000 0xx 0xx

these three must from above 6 0a 00 ax 0x ax xx

leaving the ax xx only two options 11 00 11 00

and 11 11 is not valid actually.

000 010 011 100 011 -> 001 -> 000 -> 000 -> not possible 011 001 000 000

==> once we make first row and first column to be all 0, the reminder has to be all 0