You are navigating on a 1-dimensional lane, starting at position 0. You are given a string of commands, Str, and an integer N. The commands are:
'S': Move one step ahead (position +1).
'R': Move one step back (position -1).
You are required to change exactly N commands in the string. Changing 'S' to 'R' or 'R' to 'S' both count as one change. After making exactly N changes, you execute the new sequence of commands.
Your task is to find the maximum possible absolute displacement from the starting point (position 0). The displacement is the absolute value of your final position.
Input Format:
The first line of input contains a string Str, representing the sequence of commands.
The second line contains an integer N, representing the exact number of commands that must be changed.
Output Format:
Print a single integer representing the maximum absolute displacement achievable.
Note:
To achieve the maximum positive displacement, you should prioritize changing 'R's to 'S's. If you run out of 'R's to change but still have changes left, you'll be forced to make suboptimal changes ('S' to 'R'). A similar logic applies to achieving the maximum negative displacement. The final answer is the larger of these two possible absolute outcomes.