#C9977. Cyclic Character Shift

    ID: 54129 Type: Default 1000ms 256MiB

Cyclic Character Shift

Cyclic Character Shift

You are given a string s and an integer n. Your task is to cyclically shift the characters in s by n positions. If n is positive, shift the characters to the right; if n is negative, shift them to the left.

The shifting is cyclic, which means that characters shifted out from one end of the string reappear at the other end. Note that if n is larger than the length of the string, you should compute the effective shifts using the formula $$ n \mod |s| $$ where \(|s|\) denotes the length of the string.

For example:

  • If s = "abcdef" and n = 2, the output is efabcd.
  • If s = "helloworld" and n = -3, the output is loworldhel.

If the input string is empty, simply output an empty string.

inputFormat

The input is given via standard input stdin and consists of two lines:

  • The first line contains the string s (which may be empty).
  • The second line contains an integer n, which represents the number of positions to shift.

outputFormat

Output the resulting string after performing the cyclic shift based on the given integer n on s. The output should be printed to standard output stdout.

## sample
abcdef
2
efabcd