#C7117. Shortest String Reduction

    ID: 50953 Type: Default 1000ms 256MiB

Shortest String Reduction

Shortest String Reduction

You are given a string s and a non-negative integer k. You must perform an operation exactly k times, where in each operation you remove exactly 2 characters from the string. The task is to determine the length of the remaining string after performing all operations.

Formally, if the initial length of the string is \(n\), then after performing the operation exactly \(k\) times, the length becomes \(n - 2k\). It is guaranteed that \(2k \le n\). Your program should process multiple test cases.

Example:

  • For s = "abccba" and k = 2, the remaining length is \(6 - 2*2 = 2\).
  • For s = "hellocode" and k = 1, the remaining length is \(9 - 2*1 = 7\).

inputFormat

The input is read from standard input (stdin) and has the following format:

T
s1 k1
s2 k2
...
sT kT

Where:

  • T is the number of test cases.
  • Each test case consists of a string s and an integer k separated by a space. The string s does not contain spaces and \(2k\) is guaranteed not to exceed the length of s.

outputFormat

For each test case, output a single integer on a new line representing the length of the string after performing the removal operations, using standard output (stdout).

## sample
3
abccba 2
hellocode 1
abc 1
2

7 1

</p>