Python

Caveats

Please keep in mind that everything in Python is slow. If you estimate that your Python solution is 10 times slower than your C++ solution, you are in the right ballpark.

You can run Python code with either PyPy (using the command pypy3) or CPython (using the command python3). PyPy is often, but not always, faster than CPython. When submitting code to CSES, you can choose whether to use PyPy or CPython; PyPy is usually the right choice.

Be careful when handling large inputs. For example, assume your input consists of one million numbers, one per line, and you need to compute their sum. A natural solution along these lines might take roughly 4 seconds:

s = 0
for i in range(1000000):
    s += int(input())
print(s)

However, you can easily speed it up by a factor of ten if you do something like this:

import sys

print(sum(int(x) for x in sys.stdin.read().split()))

This avoids calling input() a million times.

Easy mistakes

Do not confuse the operators / (true division, which produces a floating-point result for integer operands) and // (floor division).

Conveniences

One convenient feature in Python is that its native integer type supports arbitrarily large numbers. If you have not seen this in action, simply type 123**456 in the Python interpreter to get a 953-digit number. You can easily convert large integers to strings with str and back to integers with int. Try to find creative uses for large integers—integer multiplication is a very powerful tool!

Posting submission...