Do you want to be at the top of a CSES leaderboard? Are you tired of your friends complaining that your code is impossible to read? Do you just want to solve the problem in one line? Here's how.
Step 1: Actually solve the problem. However, you must write a correct solution in Python. It doesn't matter how long your solution is, but make sure everything is an ASCII character.
Step 2: Save your solution as "in.py" in the same folder as the following Python script:
f=open('in.py','r')
output='exec("".join(chr(len(i)) for i in "'
for l in f.readlines():
for ch in l:
output+=(" "*ord(ch))
output+=chr(9)
output=output[:-1]+'".split(" ")))'
f.close()
with open('out.py','w') as g:
g.write(output)
Step 3: Run the program to produce "out.py". This will run reasonably fast as long as "in.py" isn't as fat as your mom.
Step 4: Submit "out.py". Guaranteed to work if your original solution is correct and the output file is not too large.
Step 5: Profit. CSES will always think that this is 44 characters, much smaller than your original solution! Codeforces does not keep track of solution length, but it still works nonetheless.
Proof that it works:
Just look how this ugly ahhh trash 318273437 became this beautiful enlightening masterpiece 318273465. This strategy works so well that it even confuses Mike to make your code run a few milliseconds faster!
How it works:
Your code is technically a string of ASCII characters. The python exec() function executes the string inside as python code, so it suffices to encode your solution with whitespace. That is done by using $$$k$$$ spaces (ASCII char 32) in a row followed by a tab (ASCII char 9) to encode the ASCII character numbered $$$k$$$. CSES doesn't count whitespaces or tabs towards characters, so any solution will be 44 characters!
Disclaimer 1: you accept any emotional damage, skipped solutions, or cheating allegations caused to you or others by using this method
Disclaimer 2: this is not my original idea, my friend showed me a some other person's submission that did this









Wow, what the hell, this is so cool lmao
This also made the code run 32ms faster!
Codegolfers in shambles rn
CSES leaderboards boutta be flooded w/ 44 char submissions soon.
Is this limited to python? Is it possible with cpp
Yes, but longer
Wait, it is possible in cpp? How? Does cpp have something similar to exec? Or are you talking about literally
mmap'ing the machine code into memory?Something like that, but it would be quite long and not worth it
This can be done in 34.
How? Are you gonna change variable and file names?
exec(bytes(map(len,'insert string here'.split(' '))))meanwhile this language literally menacing for a judge with this feature
someone did it in 16 characters using ruby https://cses.fi/problemset/hack/1748/entry/15662438/
EDIT: you probably need to solve this problem first to see the submission https://cses.fi/problemset/task/1748/