#K63847. Rotate String

    ID: 31844 Type: Default 1000ms 256MiB

Rotate String

Rotate String

Given a string s and an integer n, perform a rotation operation on the string. If n is non-negative, rotate the string to the right by n positions. If n is negative, rotate the string to the left by |n| positions.

Let \(L = |s|\) be the length of the string. The effective rotation is computed as \(n \mod L\). The rotated string is formed by concatenating the last \(n\) characters with the rest of the string.

Examples:

  • For s = "abcdef" and n = 2, the result is "efabcd".
  • For s = "abcdef" and n = -2, the result is "cdefab".
  • For s = "abcdef" and n = 6, the result is "abcdef".

inputFormat

The input is provided via standard input (stdin) in the following format:

&s
n

Where s is the string to be rotated (which may be empty), and n is an integer (which can be negative, zero, or positive) representing the number of positions to rotate.

outputFormat

Output the rotated string to standard output (stdout).

## sample
abcdef
2
efabcd

</p>