from pwn import * defrun(n: int, m: int, a1: list): sign = [] minn = [] summary = 0 sum1 = 0 sum2 = 0 for i inrange(m): a = int(a1[i]) sign.append(1) if a < 0: sign[i] *= -1 a *= -1 summary += a minn.append(a) for i inrange(n-m): a = int(a1[i+m]) if a < 0: sign[i % m] *= -1 a *= -1 summary += a if a < minn[i % m]: minn[i % m] = a for i inrange(m): if sign[i] > 0: sum1 += minn[i] else: sum2 += minn[i] return summary-2*min(sum1, sum2) pro = remote('172.52.4.26', 9999) for i inrange(100): print(f'round: {i}') b = pro.recvuntil(b'Give me your output:\n').decode().split('\n')[-4:-2] print(b) _len = int(b[0].split()[0]) k = int(b[0].split()[1]) a1 = b[1].split() print(_len, k, len(a1)) answer = run(_len, k, a1) print(answer) pro.sendline(str(answer).encode()) pro.interactive()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from pwn import * from pwnlib.util.iters import mbruteforce from hashlib import sha256