ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

## How to write Python solutions

The following compilers are available for Python programs:

The syntax is checked with the `py_compile.compile` function. Errors like `IndentationError` lead to the `Compilation error` judging result on this stage. Then the interpreter is invoked without additional arguments: `python %1`. Since Python is an interpreted language, the errors like `NameError` are recognized by the online judge as a `Runtime error` but not as a `Compilation error`.

### How to read input data until the end of stream

To solve certain problems you should know how to read data until the end of input stream. The following example shows how to process all the lines until the end of input stream.

``````import sys

def process(line):
...

for line in sys.stdin:
process(line[:-1])
``````

This example shows how to read all the tokens up to the end of input stream.

``````import sys
``````

### Using recursion

By default the depth of a recursion in Python is very limited (about 1000 of nested calls). This limit can be increased with the command:

``````import sys
sys.setrecursionlimit(2000)
``````

### An example of solving a problem

A sample solution for the 1000. A + B problem in Python:

``````print(sum(int(x) for x in input().split(' ')))
``````

A sample solution for the 1001. Reverse Root in Python:

``````import sys, math
nums = []
for line in sys.stdin:
for word in line.split():
nums.append(float(word))
nums.reverse()
for num in nums:
print("%.4f" % math.sqrt(num))
``````

More efficient solution of the same problem:

``````from sys import stdin, stdout
from math import sqrt