#C9374. Reverse Sum Game

    ID: 53460 Type: Default 1000ms 256MiB

Reverse Sum Game

Reverse Sum Game

Problem Statement

You are given an integer \(n\) (where \(1 \le n \le 10^9\)) and a directive \(f\) which is a string. The directive can either be sum or reverse.

  • If the directive is sum, you must compute and output the sum of all integers from 1 to \(n\). The closed-form formula is given by \(\frac{n(n+1)}{2}\).
  • If the directive is reverse, you must output the string obtained by reversing the digits of \(n\). Note that if \(n\) ends with one or more zeros, these will appear at the beginning of the reversed string.
  • If \(f\) is neither sum nor reverse, output None.

Your solution must read input from standard input and print the result to standard output.

inputFormat

The input consists of two lines:

  1. The first line contains the integer \(n\) (\(1 \le n \le 10^9\)).
  2. The second line contains the directive \(f\), which is a string that is either sum or reverse.

outputFormat

If the directive is sum, output the sum of integers from 1 to \(n\), i.e. \(\frac{n(n+1)}{2}\). If the directive is reverse, output the string created by reversing the digits of \(n\). For an invalid directive, output None.

## sample
10
sum
55

</p>