#C9227. Circular String Shift

    ID: 53297 Type: Default 1000ms 256MiB

Circular String Shift

Circular String Shift

You are given a string s and an integer n. Your task is to shift the characters of s in a circular manner. When n is positive, shift the string to the right; when n is negative, shift the string to the left.

The shifting follows the formula:

$\text{result} = s[(L - (n \bmod L)) \bmod L:] + s[:(L - (n \bmod L)) \bmod L]$

where \(L\) is the length of string s. For example, shifting abcdef by 2 positions results in efabcd.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains the string s.
  • The second line contains the integer n indicating how many positions to shift.

outputFormat

Output the resulting string after performing the circular shift on s. The output should be written to stdout.

## sample
abcdef
2
efabcd

</p>