There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i > 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.

Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.

NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.

package main

import (
	"fmt"
	"sort"
)

func main() {
	// var a string
	var n, q, res, k, x int
	// var x float64
	// var s string
	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&q)

	for i := 0; i < q; i++ {
		fmt.Scanln(&n, &k)

		a := make([]int, n)
		m := make(map[int]int)

		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			m[a[i]]++
		}
		fmt.Scanln(&x)

		sort.Ints(a)
		if (a[len(a)-1] - a[0]) > 2*k {
			res = -1
		} else {
			res = k + a[0]
		}
		fmt.Println(res)
		res = 0
	}

}

package main
import "fmt"
import "math"

func main() {
	var n, total, k int
	maxGo := int(math.Pow(10,8));
	fmt.Scanln(&n)

	for x:=0; x <n ; x++{
	    fmt.Scan(&total)
	    fmt.Scan(&k)
	    a := make([]int, total)
	    min, max :=maxGo,0
    	for i := range a {
    		fmt.Scan(&a[i])
    		if a[i]< min{
    		    min = a[i]
    		}

    		if (a[i]>max){
    		    max = a[i]
    		}
    	}

    	newPrice := min + k
    	calculate := max-newPrice
    	if (newPrice <= 0 ){
    	 fmt.Println(-1)
    	}else if (calculate<=k){
    	    fmt.Println(newPrice)
    	}else{
    	    fmt.Println(-1)
    	}
	}

    return
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var q int
	fmt.Scan(&q)

	for ; q > 0; q-- {
		var n, k int
		fmt.Scan(&n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}

		sort.Ints(a)

		if a[len(a)-1]-k > a[0]+k {
			fmt.Println(-1)
		} else {
			fmt.Println(a[0] + k)
		}
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for ; q > 0; q-- {
		var n, k, a, min, max int64
		fmt.Scan(&n, &k)
		for ; n > 0; n-- {
			fmt.Scan(&a)
			if min == 0 || min > a {
				min = a
			}
			if max < a {
				max = a
			}
		}
		if max-min > 2*k {
			fmt.Println(-1)
		} else {
			fmt.Println(min + k)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

var a [110] int64
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scan(&q)
	for k:=1;k<=q;k++{
		var n int
		var k int64
		fmt.Scan(&n,&k)

		var min,max int64
		min=math.MaxInt64
		max=math.MinInt64

		for i:=1;i<=n;i++{
			fmt.Scan(&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}

		if(max-min>k*2){
			fmt.Println("-1");
		}else {
			fmt.Println(min+k)
		}
	}

}

 package main

 import (
     "fmt"
     "math"
 )
 func main() {
     var nquery, n, k int64
     fmt.Scanf("%d\n", &nquery)
     for nquery > 0 {
         fmt.Scanf("%d %d\n", &n, &k)
         var min int64 = math.MaxInt64
         var max int64 = math.MinInt64
         var ai int64 = 0
         for n > 0 {
             if n > 1 {
                 fmt.Scanf("%d", &ai)
             } else {
                 fmt.Scanf("%d\n", &ai)
             }
             min = Min(ai, min)
             max = Max(ai, max)
             n--
         }
         if (max - min > k*2) {
             fmt.Println(-1)
         } else {
             fmt.Println(min + k)
         }

         nquery--
     }
 }

 func Min(x, y int64) int64 {
     if x < y {
         return x
     }
     return y
 }

 func Max(x, y int64) int64 {
     if x > y {
         return x
     }
     return y
 }

package main

import "fmt"

func main() {
	var requests int
	fmt.Scan(&requests)

	for i := 0; i < requests; i++ {
		var pieces int
		var k int
		min := 0
		max := 0
		fmt.Scan(&pieces)
		fmt.Scan(&k)
		var prices = make([]int, pieces)
		for j := 0; j < pieces; j++ {
			fmt.Scan(&prices[j])
			if j == 0 {
				min = prices[j]
				max = prices[j]
			}
			if prices[j] < min {
				min = prices[j]
			}
			if prices[j] > max {
				max = prices[j]
			}
		}
		if max > min + 2 * k {
			fmt.Println(-1)
		} else {
			fmt.Println(min + k)
		}

	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1183B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t, n, k, v int
	for Fscan(in, &t); t > 0; t-- {
		mi, mx := int(1e9), 0
		for Fscan(in, &n, &k); n > 0; n-- {
			Fscan(in, &v)
			if v < mi {
				mi = v
			}
			if v > mx {
				mx = v
			}
		}
		if mi+2*k >= mx {
			Fprintln(out, mi+k)
		} else {
			Fprintln(out, -1)
		}
	}
}

func main() { CF1183B(os.Stdin, os.Stdout) }

package main

import (
   "bufio"
   "fmt"
   "math"
   "os"
   "strconv"
   "sync"
)

const (
   MX_INT int64 = math.MaxInt64
   MN_INT int64 = math.MinInt64
)

func main() {
   for t := ScanInt64(); t > 0; t-- {
    n, k := ScanInt64(), ScanInt64()
    a := ScanInt64Slice(n)

    min := Mn(a...)
    max := Mx(a...)

    if max - min > 2*k {
      O <- S(-1)
    } else {
      O <- S(min + k)
    }

   }

   close(O)
   oWg.Wait()
}

func isValid(a []int64, k, B int64) bool {
  for i := 0; i < len(a); i++ {
    if abs(a[i] - k) > B {
      return false
    }
  }
  return true
}

func abs(x int64) int64 {
    if x < 0 {
        return -x
    }
    return x
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
   Pl = fmt.Println

   in = bufio.NewScanner(os.Stdin)
   in.Buffer(make([]byte, 1024), int(1e8))
   in.Split(bufio.ScanWords)

   O = make(chan string, 16)
   oWg = &sync.WaitGroup{}
   oWg.Add(1)

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

      for line := range O {
         writer.WriteString(line + "\n")
      }
   }(writer)
}

func ScanWord() string {
   in.Scan()
   return in.Text()
}

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

func ScanInt64() int64 {
   intStr := ScanWord()
   i, err := strconv.ParseInt(intStr, 10, 64)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt() int {
   intStr := ScanWord()
   i, err := strconv.Atoi(intStr)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt64Slice(n int64) []int64 {
   length := int(n)
   arr := make([]int64, n)
   for i := 0; i < length; i++ {
      arr[i] = ScanInt64()
   }
   return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

func LCM(a, b int64) int64 {
   return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
   if (a == 0) {
      return b
   }
   return GCD(b%a, a)
}

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}

package main

import (
   "bufio"
   "fmt"
   "math"
   "os"
   "strconv"
   "sort"
   "sync"
)

const (
   MX_INT int64 = math.MaxInt64
   MN_INT int64 = math.MinInt64
)

func main() {
   for t := ScanInt64(); t > 0; t-- {
    n, k := ScanInt64(), ScanInt64()
    a := ScanInt64Slice(n)
    for i := 0; i < len(a); i++ {
      a[i] += k
    }
    sort.Slice(a, func(i, j int) bool { return a[i] < a[j]})

    if a[len(a)-1] - a[0] > 2*k {
      O <- S(-1)
    } else {
      O <- S(a[0])
    }

   }

   close(O)
   oWg.Wait()
}

func isValid(a []int64, k, B int64) bool {
  for i := 0; i < len(a); i++ {
    if abs(a[i] - k) > B {
      return false
    }
  }
  return true
}

func abs(x int64) int64 {
    if x < 0 {
        return -x
    }
    return x
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
   Pl = fmt.Println

   in = bufio.NewScanner(os.Stdin)
   in.Buffer(make([]byte, 1024), int(1e8))
   in.Split(bufio.ScanWords)

   O = make(chan string, 16)
   oWg = &sync.WaitGroup{}
   oWg.Add(1)

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

      for line := range O {
         writer.WriteString(line + "\n")
      }
   }(writer)
}

func ScanWord() string {
   in.Scan()
   return in.Text()
}

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

func ScanInt64() int64 {
   intStr := ScanWord()
   i, err := strconv.ParseInt(intStr, 10, 64)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt() int {
   intStr := ScanWord()
   i, err := strconv.Atoi(intStr)
   if err != nil {
      panic(err)
   }
   return i
}

func ScanInt64Slice(n int64) []int64 {
   length := int(n)
   arr := make([]int64, n)
   for i := 0; i < length; i++ {
      arr[i] = ScanInt64()
   }
   return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

func LCM(a, b int64) int64 {
   return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
   if (a == 0) {
      return b
   }
   return GCD(b%a, a)
}

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var q, n, k, i, ctr int64
	fmt.Scan(&q)
	for q > 0 {
		fmt.Scan(&n, &k)
		a := make([]int64, n)
		for i = 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		min := findMin(a, n)
		x := min + k
		for i = 0; i < n; i++ {
			if math.Abs(float64(a[i]-x)) > float64(k) {
				ctr = 1
			}
		}
		if ctr == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(min + k)
		}
		ctr = 0
		q = q - 1
	}
}

func findMin(a []int64, n int64) int64 {
	m := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

package main

import "fmt"

func abs(a int64,b int64) int64 {
	if a >= b {
		return a-b
	}
	return b-a
}

func main() {
	var t int
	fmt.Scan(&t)
	for t>0 {
		var n,i int
		var k int64
		fmt.Scan(&n)
		fmt.Scan(&k)
		var a = make([]int64,n)
		var ans int64 = 9223372036854775807
		for i=0;i<n;i++ {
			fmt.Scan(&a[i])
			if ans > a[i]+k {
				ans = a[i]+k
			}
		}
		isExist := true
		for i=0;i<n;i++ {
			if abs(a[i],ans) > k {
				isExist = false
				break
			}
		}
		if isExist {
			fmt.Println(ans)
		} else {
			fmt.Println(-1)
		}
		t--
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int64;
	var inf int64 = 1e8;
	var T int64
	var n,k int64
	var a [10000] int64
	var i1,i int64
	fmt.Scan(&T)
	for i1=1;i1<=T;i1++ {
		//if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scan(&n, &k);
		for i = 1; i <= n; i++ {
			fmt.Scan(&a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Println("-1");
			continue;
		}
		fmt.Println(mi+k);
	}
}

package main
import "fmt"
import "math"

func main() {
	var n, total, k int
	maxGo := int(math.Pow(10,8)-1);
	fmt.Scanln(&n)

	for x:=0; x <n ; x++{
	    fmt.Scan(&total)
	    fmt.Scan(&k)
	    a := make([]int, total)
	    min, max :=maxGo,0
    	for i := range a {
    		fmt.Scan(&a[i])
    		if a[i]< min{
    		    min = a[i]
    		}

    		if (a[i]>max){
    		    max = a[i]
    		}
    	}

    	newPrice := min + k
    	calculate := float64(max-newPrice)
    	if (newPrice <= 0 ){
    	 fmt.Println(-1)
    	}else if (int(math.Abs(calculate))<=k){
    	    fmt.Println(newPrice)
    	}else{
    	    fmt.Println(-1)
    	}
	}

    return
}

package main
import "fmt"
import "math"

func main() {
	var n, total, k int
	maxGo := int(math.Pow(10,8)-1);
	fmt.Scanln(&n)

	for x:=0; x <n ; x++{
	    fmt.Scan(&total)
	    fmt.Scan(&k)
	    a := make([]int, total)
	    min, max :=maxGo,0
    	for i := range a {
    		fmt.Scan(&a[i])
    		if a[i]< min{
    		    min = a[i]
    		}

    		if (a[i]>max){
    		    max = a[i]
    		}
    	}

    	newPrice := min + k
    	calculate := float64(max-newPrice)
    	if (int(math.Abs(calculate))<=k){
    	    fmt.Println(newPrice)
    	}else{
    	    fmt.Println(-1)
    	}
	}

    return
}

package main

import (
	"fmt"
	"math"
)

var a [110]int
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n,k int
		fmt.Scanf("%d %d",&n,&k)

		var min,max int
		min=math.MaxInt16

		for i:=1;i<=n;i++{
			fmt.Scanf("%d",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}
		var ans2,ans3 int

		ans2=min+k;

		if max-k>0{
			ans3=max-k
		} else{
			ans3=1
		}

		if ans2>=ans3{
			fmt.Printf("%d\n",min+k)
		} else {
			fmt.Println("-1")
		}
	}

}

package main

import (
	"fmt"
	"math"
)

var a [110]int
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n,k int
		fmt.Scanf("%d %d",&n,&k)

		var min,max int
		min=math.MaxInt16

		for i:=1;i<=n;i++{
			fmt.Scanf("%d",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}
		var ans2,ans3 int

		ans2=min+k;

		ans3=max+k

		if ans2>=ans3{
			fmt.Printf("%d\n",min+k)
		} else {
			fmt.Println("-1")
		}
	}

}

package main

import (
	"fmt"
)

var a [110] int32
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n,k int32
		fmt.Scanf("%lld %lld",&n,&k)

		var min,max int32
		min=a[0]
		max=a[0]
		var i int32

		for i=1;i<=n;i++{
			fmt.Scanf("%lld",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}
		var ans2,ans3 int32

		ans2=min+k;

		ans3=max-k

		if ans2>=ans3{
			fmt.Printf("%d\n",min+k)
		} else {
			fmt.Println("-1")
		}
	}

}

package main

import (
	"fmt"
	"math"
)

var a [110] int64
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n int
		var k int64
		fmt.Scanf("%d %d",&n,&k)

		var min,max int64
		min=math.MaxInt64
		max=math.MinInt64

		for i:=1;i<=n;i++{
			fmt.Scanf("%d",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}

		if(max-min>k*2){
			fmt.Println("-1");
		}else {
			fmt.Println(min+k)
		}
	}

}

package main

import (
	"fmt"
	"math"
)

var a [110]int
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n,k int
		fmt.Scanf("%d %d",&n,&k)

		var min,max int
		min=math.MaxInt16

		for i:=1;i<=n;i++{
			fmt.Scanf("%d",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}
		var ans2,ans3 int

		ans2=min+k;

		ans3=max-k

		if ans2>=ans3{
			fmt.Printf("%d\n",min+k)
		} else {
			fmt.Println("-1")
		}
	}

}

package main

import (
	"fmt"
	"math"
)

var a [110] int64
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n int
		var k int64
		fmt.Scanf("%d %d",&n,&k)

		var min,max int64
		min=math.MaxInt64
		max=math.MinInt64

		for i:=1;i<=n;i++{
			fmt.Scan(&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}

		if(max-min>k*2){
			fmt.Println("-1");
		}else {
			fmt.Println(min+k)
		}
	}

}

package main

import (
	"fmt"
)

var a [110]int
func abs(n int)int{
	if(n<=0){
		return -n;
	}
	return n;
}
func main() {
	var q int

	fmt.Scanln(&q)
	for k:=1;k<=q;k++{
		var n,k int
		fmt.Scanf("%d %d",&n,&k)

		var min,max int
		min=a[0]
		max=a[0]

		for i:=1;i<=n;i++{
			fmt.Scanf("%d",&a[i])
			if a[i]<min{
				min=a[i]
			}
			if a[i]>max{
				max=a[i]
			}

		}
		var ans2,ans3 int

		ans2=min+k;

		ans3=max-k

		if ans2>=ans3{
			fmt.Printf("%d\n",min+k)
		} else {
			fmt.Println("-1")
		}
	}

}

 package main

 import (
     "fmt"
     "math"
 )
 func main() {
     var nquery, n, k int64
     fmt.Scanf("%d", &nquery)
     for nquery > 0 {
         fmt.Scanf("%d %d\n", &n, &k)
         var min int64 = math.MaxInt64
         var max int64 = math.MinInt64
         var ai int64 = 0
         for n > 0 {
             if n > 1 {
                 fmt.Scanf("%d", &ai)
             } else {
                 fmt.Scanf("%d\n", &ai)
             }
             min = Min(ai, min)
             max = Max(ai, max)
             n--
         }
         if (max - min > k*2) {
             fmt.Println(-1)
         } else {
             fmt.Println(min + k)
         }

         nquery--
     }
 }

 func Min(x, y int64) int64 {
     if x < y {
         return x
     }
     return y
 }

 func Max(x, y int64) int64 {
     if x > y {
         return x
     }
     return y
 }

 package main

 import (
     "fmt"
     "math"
 )
 func main() {
     var nquery, n, k int64
     fmt.Scanf("%d", &nquery)
     for nquery > 0 {
         fmt.Scanf("%d %d\n", &n, &k)
         var min int64 = math.MaxInt64
         var max int64 = math.MinInt64
         var ai int64 = 0
         for n > 0 {
             fmt.Scanf("%d", &ai)
             min = Min(ai, min)
             max = Max(ai, max)
             n--
         }
         if (max - min > k*2) {
             fmt.Println(-1)
         } else {
             fmt.Println(min + k)
         }

         nquery--
     }
 }

 func Min(x, y int64) int64 {
     if x < y {
         return x
     }
     return y
 }

 func Max(x, y int64) int64 {
     if x > y {
         return x
     }
     return y
 }

 package main

 import (
     "fmt"
     "math"
 )
 func main() {
     var nquery, n, k int64
     fmt.Scanf("%d", &nquery)
     for nquery > 0 {
         fmt.Scanf("%d %d", &n, &k)
         var min int64 = math.MaxInt64
         var max int64 = math.MinInt64
         var ai int64 = 0
         for n > 0 {
             fmt.Scanf("%d", &ai)
             min = Min(ai, min)
             max = Max(ai, max)
             n--
         }
         if (max - min > k*2) {
             fmt.Println(-1)
         } else {
             fmt.Println(min + k)
         }

         nquery--
     }
 }

 func Min(x, y int64) int64 {
     if x < y {
         return x
     }
     return y
 }

 func Max(x, y int64) int64 {
     if x > y {
         return x
     }
     return y
 }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1183B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t, n, k, v int
	for Fscan(in, &t); t > 0; t-- {
		mi, mx := int(1e9), 0
		for Fscan(in, &n, &k); n > 0; n-- {
			Fscan(in, &v)
			if v < mi {
				mi = v
			} else if v > mx {
				mx = v
			}
		}
		if mi+2*k >= mx {
			Fprintln(out, mi+k)
		} else {
			Fprintln(out, -1)
		}
	}
}

func main() { CF1183B(os.Stdin, os.Stdout) }

package main

import "fmt"

func abs(a int,b int) int {
	if a >= b {
		return a-b
	}
	return b-a
}

func main() {
	var t int
	fmt.Scan(&t)
	for t>0 {
		var n,k,i int
		fmt.Scan(&n)
		fmt.Scan(&k)
		var a = make([]int,n)
		var ans = 100000000
		for i=0;i<n;i++ {
			fmt.Scan(&a[i])
			if ans > a[i]+k {
				ans = a[i]+k
			}
		}
		isExist := true
		for i=0;i<n;i++ {
			if abs(a[i],ans) > k {
				isExist = false
				break
			}
		}
		if isExist {
			fmt.Println(ans)
		} else {
			fmt.Println(-1)
		}
		t--
	}
}

package main

import "fmt"

func abs(a int64,b int64) int64 {
	if a >= b {
		return a-b
	}
	return b-a
}

func main() {
	var t int
	fmt.Scan(&t)
	for t>0 {
		var n,i int
		var k int64
		fmt.Scan(&n)
		fmt.Scan(&k)
		var a = make([]int64,n)
		var ans int64 = 100000000
		for i=0;i<n;i++ {
			fmt.Scan(&a[i])
			if ans > a[i]+k {
				ans = a[i]+k
			}
		}
		isExist := true
		for i=0;i<n;i++ {
			if abs(a[i],ans) > k {
				isExist = false
				break
			}
		}
		if isExist {
			fmt.Println(ans)
		} else {
			fmt.Println(-1)
		}
		t--
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 3e8;
	var T int
	var n,k int
	var a [10000] int
	fmt.Scanf("%d",&T)
	for i1:=1;i1<=T;i1++ {
		if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Printf("-1");
			continue;
		}
		fmt.Printf("%d", mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 3e8;
	var T int
	var n,k int
	var a [1000000] int
	fmt.Scanf("%d",&T)
	for i1:=1;i1<=T;i1++ {
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Printf("-1\n");
			continue;
		}
		fmt.Printf("%d\n", mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 1e8;
	var T int
	var n,k int
	var a [10000] int
	var i1,i int
	fmt.Scanf("%d",&T)
	for i1=1;i1<=T;i1++ {
		//if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i = 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Println("-1");
			continue;
		}
		fmt.Println(mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 1e8;
	var T int
	var n,k int
	var a [10000] int
	var i1,i int
	fmt.Scanf("%d",&T)
	fmt.Printf("%d\n",T)
	for i1=1;i1<=T;i1++ {
		//if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k)
		fmt.Printf("%d %d\n",n,k)
		for i = 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
			fmt.Printf("%d\n",a[i])
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Println("-1")
			continue;
		}
		fmt.Println(mi+k)
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int64;
	var inf int64 = 1e8;
	var T int64
	var n,k int64
	var a [10000] int64
	var i1,i int64
	fmt.Scanf("%d",&T)
	for i1=1;i1<=T;i1++ {
		//if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i = 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Println("-1");
			continue;
		}
		fmt.Println(mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 1e8;
	var T int
	var n,k int
	var a [10000] int
	fmt.Scanf("%d",&T)
	for i1:=1;i1<=T;i1++ {
		if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Printf("-1");
			continue;
		}
		fmt.Printf("%d", mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 1e8;
	var T int
	var n,k int
	var a [10000] int
	fmt.Scanf("%d",&T)
	for i1:=1;i1<=T;i1++ {
		//if(i1!=1){fmt.Printf("\n")}
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Println("-1");
			continue;
		}
		fmt.Println(mi+k);
	}
}

package main

import(
	"fmt"
)

func main(){
	var mi,ma int;
	var inf int = 3e8;
	var T int
	var n,k int
	var a [10000] int
	fmt.Scanf("%d",&T)
	for i1:=1;i1<=T;i1++ {
		mi = inf
		ma = 0
		fmt.Scanf("%d%d", &n, &k);
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i]);
			if (a[i] < mi) {
				mi = a[i]
			}
			if (a[i] > ma) {
				ma = a[i]
			}
		}
		if (ma-mi > 2*k) {
			fmt.Printf("-1\n");
			continue;
		}
		fmt.Printf("%d\n", mi+k);
	}
}


You are fed up with your messy room, so you decided to clean it up.Your room is a bracket sequence $$$s=s_{1}s_{2}\dots s_{n}$$$ of length $$$n$$$. Each character of this string is either an opening bracket '(' or a closing bracket ')'.In one operation you can choose any consecutive substring of $$$s$$$ and reverse it. In other words, you can choose any substring $$$s[l \dots r]=s_l, s_{l+1}, \dots, s_r$$$ and change the order of elements in it into $$$s_r, s_{r-1}, \dots, s_{l}$$$.For example, if you will decide to reverse substring $$$s[2 \dots 4]$$$ of string $$$s=$$$"((()))" it will be equal to $$$s=$$$"()(())".A regular (aka balanced) bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.A prefix of a string $$$s$$$ is a substring that starts at position $$$1$$$. For example, for $$$s=$$$"(())()" there are $$$6$$$ prefixes: "(", "((", "(()", "(())", "(())(" and "(())()".In your opinion, a neat and clean room $$$s$$$ is a bracket sequence that:  the whole string $$$s$$$ is a regular bracket sequence;  and there are exactly $$$k$$$ prefixes of this sequence which are regular (including whole $$$s$$$ itself). For example, if $$$k = 2$$$, then "(())()" is a neat and clean room.You want to use at most $$$n$$$ operations to make your room neat and clean. Operations are applied one after another sequentially.It is guaranteed that the answer exists. Note that you do not need to minimize the number of operations: find any way to achieve the desired configuration in $$$n$$$ or less operations.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le \frac{n}{2}, 2 \le n \le 2000$$$, $$$n$$$ is even) — length of $$$s$$$ and required number of regular prefixes. The second line of a test case contains $$$s$$$ of length $$$n$$$ — the given bracket sequence. It contains only '(' and ')'. It is guaranteed that there are exactly $$$\frac{n}{2}$$$ characters '(' and exactly $$$\frac{n}{2}$$$ characters ')' in the given string. The sum of all values $$$n$$$ over all the test cases in the input doesn't exceed $$$2000$$$.

For each test case print an answer. In the first line print integer $$$m$$$ ($$$0 \le m \le n$$$) — the number of operations. You do not need to minimize $$$m$$$, any value is suitable. In the following $$$m$$$ lines print description of the operations, each line should contain two integers $$$l,r$$$ ($$$1 \le l \le r \le n$$$), representing single reverse operation of $$$s[l \dots r]=s_{l}s_{l+1}\dots s_{r}$$$. Operations are applied one after another sequentially. The final $$$s$$$ after all operations should be a regular, also it should be exactly $$$k$$$ prefixes (including $$$s$$$) which are regular. It is guaranteed that the answer exists. If there are several possible answers you can print any.

NoteIn the first example, the final sequence is "()(()())", where two prefixes are regular, "()" and "()(()())". Note, that all the operations except "5 8" in the example output are useless (they do not change $$$s$$$).

package main

import (
	"fmt"
	"runtime"
)

func PrintlnRuneSlice(s []rune){
	for _, v := range s {
		fmt.Printf("%s", string(v))
	}
	fmt.Println()
}
type
	LR struct {
		L int16
		R int16
	}

func solve() {
	var n, k int16
	var s  []byte
	fmt.Scan(&n,&k,&s)

//	PrintlnRuneSlice([]rune(string(s)))

	cnt := int16(0)
	res := make([]LR,0)
	i := int16(0)
	for cnt < k-1 && i < n {
		if i%2 == 0 {
			if string(s[i]) == "(" {
			} else {
				l := i
				r := i
				for ; r < n && string(s[r]) == ")"; r++ {
				}
				if r>=n {
					break
				}
				res = append(res, LR{l, r})
				for u := int16(0); u <= (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
		} else {
			if string(s[i]) == ")" {
			} else {
				l := i
				r := i
				for ; r < n && string(s[r]) == "("; r++ {
				}
				if r>=n {
					break
				}
				res = append(res, LR{l, r})
				for u := int16(0); u <= (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
			cnt++
		}
		i++
	}

	end := i+(n - i) / 2
	for i <= end &&i<n-1 {
		if string(s[i]) == ")" {
			l := i
			r := i + 1
			for ; r < n && string(s[r]) == ")"; r++ {
			}
			if r>=n {
				break
			}
			res = append(res, LR{l, r})
			for u := int16(0); u <= (r-l)/2; u++ {
				s[l+u], s[r-u] = s[r-u], s[l+u]
			}
		}
		i++
	}

//	PrintlnRuneSlice([]rune(string(s)))
	fmt.Printf("%d\n", len(res))
	for i := range res {
		fmt.Printf("%d %d\n", res[i].L+1, res[i].R+1)
	}

	s=nil
	res=nil
}

func main() {
	//t := ReadInt()
	t :=1
	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve()
		runtime.GC()
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n, k int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, k = ReadInt2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	answers := [][]int{}

	for i := 0; i < 2*(k-1); i++ {
		if i%2 == 0 && S[i] == ')' {
			answers = append(answers, sub(i, '('))
		} else if i%2 == 1 && S[i] == '(' {
			answers = append(answers, sub(i, ')'))
		}
	}

	tmp := (n - 2*(k-1)) / 2
	for i := 2 * (k - 1); i < 2*(k-1)+tmp; i++ {
		if S[i] == ')' {
			answers = append(answers, sub(i, '('))
		}
	}

	fmt.Println(len(answers))
	for i := 0; i < len(answers); i++ {
		fmt.Println(answers[i][0]+1, answers[i][1]+1)
	}

	// fmt.Println(string(S))
}

// sからスタートしてrを発見したところで反転する
// さらに始点と終点をスライスで返す
func sub(s int, r rune) []int {
	t := s + 1
	for i := s + 1; i < n; i++ {
		if S[i] == r {
			t = i
			break
		}
	}
	res := []int{s, t}

	// [s, t]を反転
	rev := Reverse(S[s : t+1])
	for i := 0; i < len(rev); i++ {
		S[s+i] = rev[i]
	}

	return res
}

func Reverse(A []rune) []rune {
	res := []rune{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func Sol1262C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	reverse := func(s []byte) {
		for i, j := 0, len(s)-1; i < j; {
			s[i], s[j] = s[j], s[i]
			i++
			j--
		}
	}
	type pair struct{ l, r int }

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		ops := []pair{}
		targetStr := strings.Repeat("()", k-1) + strings.Repeat("(", n/2-k+1) + strings.Repeat(")", n/2-k+1)
		for i, c := range s {
			if c != targetStr[i] {
				j := i + 1
				for ; s[j] != targetStr[i]; j++ {
				}
				reverse(s[i : j+1])
				ops = append(ops, pair{i + 1, j + 1})
			}
		}
		Fprintln(out, len(ops))
		for _, op := range ops {
			Fprintln(out, op.l, op.r)
		}
	}
}

func main() {
	Sol1262C(os.Stdin, os.Stdout)
}

package main

import (
	"fmt"
)

type erv struct {
	a int
	b int
}

func next(s []byte, pos int, c byte) int {
	for pos--; pos >= 0; pos-- {
		if s[pos] == c {
			return pos
		}
	}
	return -1
}

func main() {
	var t, n, k int

	fmt.Scan(&t)

	var s []byte
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &k, &s)

		open, close := len(s), len(s)

		ervs := make([]erv, 0)
		for j := 0; j < k - 1; j++ {
			close = next(s, close, ')')
			//fmt.Println("close", close, j, len(s)-1)
			if close != len(s) - 1 - 2 * j {
				ervs = append(ervs, erv{a: close, b: len(s)-1-2*j})
				s[close], s[len(s)-1-2*j] = s[len(s)-1-2*j], s[close]
			}

			open = next(s, open, '(')
			//fmt.Println("open", open, j, len(s)-1)
			if open != len(s) - 2 - 2 * j {
				ervs = append(ervs, erv{a: open, b: len(s)-2-2*j})
				s[open], s[len(s)-2-2*j] = s[len(s)-2-2*j], s[open]
			}
		}

		for j := n - 2 * k + 1; j >= (n - 2 * k) / 2 + 1; j-- {
			close = next(s, close, ')')
			if close != j {
				ervs = append(ervs, erv{a:close, b: j})
				s[close], s[j] = s[j], s[close]
			}
		}
		//fmt.Println(string(s))

		fmt.Println(len(ervs))
		for _, v := range ervs {
			fmt.Println(v.a+1, v.b+1)
		}
	}
}

package main

import (
	"fmt"
	"runtime"
)

type
	LR struct {
		L int16
		R int16
	}

func solve() {
	var n, k int16
	var s  []byte
	fmt.Scan(&n,&k,&s)
	cnt := int16(0)
	res := make([]LR,0)
	i := int16(0)
	for cnt < k-1 && i < n-1 {
		if i%2 == 0 {
			if string(s[i]) == "(" {
//				i++
			} else {
				l := i
				r := i + 1
				for ; r < n && string(s[r]) == ")"; r++ {
				}
				if r>=n {
					break
				}
				res = append(res, LR{l, r})
				for u := int16(0); u < (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
		} else {
			if string(s[i]) == ")" {
//				i++
				cnt++
			} else {
				l := i
				r := i + 1
				for ; r < n && string(s[r]) == "("; r++ {
				}
				if r>=n {
					break
				}
				res = append(res, LR{l, r})
				for u := int16(0); u < (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
		}
		i++
	}

	end := i+(n - i) / 2
	for i <= end &&i<n-1 {
		if string(s[i]) == ")" {
			l := i
			r := i + 1
			for ; r < n && string(s[r]) == ")"; r++ {
			}
			if r>=n {
				break
			}
			res = append(res, LR{l, r})
			for u := int16(0); u < (r-l)/2; u++ {
				s[l+u], s[r-u] = s[r-u], s[l+u]
			}
		}
		i++
	}

	fmt.Printf("%d\n", len(res))
	for i := range res {
		fmt.Printf("%d %d\n", res[i].L+1, res[i].R+1)
	}

	s=nil
	res=nil
}

func main() {
	//t := ReadInt()
	t :=1
	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve()
		runtime.GC()
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"runtime"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type
	LR struct {
		L int
		R int
	}

func solve() {
	n, k := ReadInt2()
	s := ReadRuneSlice()

	cnt := 0
	var res = []LR{}
	i := 0
	for cnt < k-1 && i < n-1 {
		if i%2 == 0 {
			if string(s[i]) == "(" {
				i++
			} else {
				l := i
				r := i + 1
				for ; r < n && string(s[r]) == ")"; r++ {
				}
				res = append(res, LR{l, r})
				for u := 0; u < (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
		} else {
			if string(s[i]) == ")" {
				i++
				cnt++
			} else {
				l := i
				r := i + 1
				for ; r < n && string(s[r]) == "("; r++ {
				}
				res = append(res, LR{l, r})
				for u := 0; u < (r-l)/2; u++ {
					s[i+u], s[r-u] = s[r-u], s[i+u]
				}
			}
		}
	}

	end := i+(n - i) / 2
	for i <= end &&i<n-1 {
		if string(s[i]) == ")" {
			l := i
			r := i + 1
			for ; r < n && string(s[r]) == ")"; r++ {
			}
			if r>=n {
				break
			}
			res = append(res, LR{l, r})
			for u := 0; u < (r-l)/2; u++ {
				s[l+u], s[r-u] = s[r-u], s[l+u]
			}
		}
		i++
	}

	fmt.Printf("%d\n", len(res))
	for _, v := range res {
		fmt.Printf("%d %d\n", v.L, v.R)
	}

}

func main() {
	t := ReadInt()
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n, k int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, k = ReadInt2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	answers := [][]int{}

	for i := 0; i < 2*(k-1); i++ {
		if i%2 == 0 && S[i] == ')' {
			answers = append(answers, sub(i, '('))
		} else if i%2 == 1 && S[i] == '(' {
			answers = append(answers, sub(i, ')'))
		}
	}

	tmp := (n - 2*(k-1)) / 2
	for i := 2 * (k - 1); i < 2*(k-1)+tmp; i++ {
		if S[i] == ')' {
			answers = append(answers, sub(i, '('))
		}
	}

	fmt.Println(len(answers))
	for i := 0; i < len(answers); i++ {
		fmt.Println(answers[i][0]+1, answers[i][1]+1)
	}

	fmt.Println(string(S))
}

// sからスタートしてrを発見したところで反転する
// さらに始点と終点をスライスで返す
func sub(s int, r rune) []int {
	t := s + 1
	for i := s + 1; i < n; i++ {
		if S[i] == r {
			t = i
			break
		}
	}
	res := []int{s, t}

	// [s, t]を反転
	rev := Reverse(S[s : t+1])
	for i := 0; i < len(rev); i++ {
		S[s+i] = rev[i]
	}

	return res
}

func Reverse(A []rune) []rune {
	res := []rune{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

/*******************************************************************/


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

package main

import (
	"io/ioutil"
	"os"
	"bytes"
	"fmt"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var a, b int64
	var n int
	fmt.Fscanf(reader, "%d %d %d", &a, &b, &n)
	if a == 0 && b != 0 {
		fmt.Printf("No solution")
		return
	} else if a * b == 0 {
		fmt.Printf("0")
		return
	} else {
		for x := int64(-1000); x <= 1000; x ++ {
			res := a
			for i := 0;i < n;i ++ {
				res = res * x
				if res < -1000 || res > 1000 {
					break
				}
			}
			if res == b {
				fmt.Printf("%d", x)
				return
			}
		}
		fmt.Printf("No solution")
	}
}


Nezzar designs a brand new game "Hidden Permutations" and shares it with his best friend, Nanako.At the beginning of the game, Nanako and Nezzar both know integers $$$n$$$ and $$$m$$$. The game goes in the following way:  Firstly, Nezzar hides two permutations $$$p_1,p_2,\ldots,p_n$$$ and $$$q_1,q_2,\ldots,q_n$$$ of integers from $$$1$$$ to $$$n$$$, and Nanako secretly selects $$$m$$$ unordered pairs $$$(l_1,r_1),(l_2,r_2),\ldots,(l_m,r_m)$$$;  After that, Nanako sends his chosen pairs to Nezzar;  On receiving those $$$m$$$ unordered pairs, Nezzar checks if there exists $$$1 \le i \le m$$$, such that $$$(p_{l_i}-p_{r_i})$$$ and $$$(q_{l_i}-q_{r_i})$$$ have different signs. If so, Nezzar instantly loses the game and gets a score of $$$-1$$$. Otherwise, the score Nezzar gets is equal to the number of indices $$$1 \le i \le n$$$ such that $$$p_i \neq q_i$$$. However, Nezzar accidentally knows Nanako's unordered pairs and decides to take advantage of them. Please help Nezzar find out two permutations $$$p$$$ and $$$q$$$ such that the score is maximized.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^5$$$) — the number of test cases. The first line of each test case contains two integers $$$n,m$$$ ($$$1 \le n \le 5 \cdot 10^5, 0 \le m \le \min(\frac{n(n-1)}{2},5 \cdot 10^5)$$$).  Then $$$m$$$ lines follow, $$$i$$$-th of them contains two integers $$$l_i,r_i$$$ ($$$1 \le l_i,r_i \le n$$$, $$$l_i \neq r_i$$$), describing the $$$i$$$-th unordered pair Nanako chooses. It is guaranteed that all $$$m$$$ unordered pairs are distinct. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$5 \cdot 10^5$$$, and the sum of $$$m$$$ for all test cases does not exceed $$$5\cdot 10^5$$$.

For each test case, print two permutations $$$p_1,p_2,\ldots,p_n$$$ and $$$q_1,q_2,\ldots,q_n$$$ such that the score Nezzar gets is maximized.

NoteFor first test case, for each pair given by Nanako:  for the first pair $$$(1,2)$$$: $$$p_1 - p_2 = 1 - 2 = -1$$$, $$$q_1 - q_2 = 3 - 4 = -1$$$, they have the same sign;  for the second pair $$$(3,4)$$$: $$$p_3 - p_4 = 3 - 4 = -1$$$, $$$q_3 - q_4 = 1 - 2 = -1$$$, they have the same sign. As Nezzar does not lose instantly, Nezzar gains the score of $$$4$$$ as $$$p_i \neq q_i$$$ for all $$$1 \leq i \leq 4$$$. Obviously, it is the maximum possible score Nezzar can get.

package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		L, R := make([]int, m), make([]int, m)
		for i := 0; i < m; i++ {
			L[i], R[i] = readTwoNums(reader)
		}
		p, q := solve(n, m, L, R)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", p[i]))
		}
		buf.WriteByte('\n')
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", q[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n, m int, L, R []int) ([]int, []int) {
	g := make([]map[int]bool, n)
	t := make([]map[int]bool, n)
	for i := 0; i < n; i++ {
		g[i] = make(map[int]bool)
		t[i] = make(map[int]bool)
	}

	for i := 0; i < m; i++ {
		g[L[i]-1][R[i]-1] = true
		g[R[i]-1][L[i]-1] = true
	}
	var rv *Node
	for i := 0; i < n; i++ {
		rv = Insert(rv, i)
	}

	var dfs func(u int)

	dfs = func(u int) {
		rv = Delete(rv, u)

		var v = -1
		for {
			tmp := FindUpperBound(rv, v)
			if tmp == nil {
				break
			}
			v = tmp.key
			if g[u][v] {
				continue
			}
			t[u][v] = true
			t[v][u] = true
			dfs(v)
		}
	}

	for rv.Size() > 0 {
		dfs(rv.MinValue())
	}

	rem := n

	d := make(PriorityQueue, 0, n)
	perm1 := make([]int, n)
	perm2 := make([]int, n)
	deg := make([]int, n)
	for i := 0; i < n; i++ {
		deg[i] = len(t[i])
		if deg[i] > 0 {
			heap.Push(&d, NewItem(i, deg[i]))
		} else {
			perm1[i] = rem
			perm2[i] = rem
			rem--
		}
	}

	stars := make([]Star, 0, n)
	for d.Len() > 0 {
		idx := d[0].value
		if d[0].priority != deg[idx] {
			heap.Pop(&d)
			continue
		}
		f := getFirst(t[idx])
		deg[f] = 0
		var leaves []int
		for c := range t[f] {
			deg[c]--
			if deg[c] == 0 {
				leaves = append(leaves, c)
			} else {
				heap.Push(&d, NewItem(c, deg[c]))
				delete(t[c], f)
			}
		}
		stars = append(stars, NewStar(f, leaves))
	}

	var l, r int
	for _, c := range stars {
		l++
		perm1[c.center] = l
		for _, x := range c.leaves {
			l++
			perm1[x] = l
			r++
			perm2[x] = r
		}
		r++
		perm2[c.center] = r
	}

	return perm1, perm2
}

type Star struct {
	center int
	leaves []int
}

func NewStar(c int, l []int) Star {
	return Star{c, l}
}

func NewItem(v, p int) *Item {
	item := new(Item)
	item.value = v
	item.priority = p
	return item
}

func getFirst(mem map[int]bool) int {
	for k := range mem {
		return k
	}
	return -1
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, priority int) {
	item.priority = priority
	heap.Fix(pq, item.index)
}

/**
* this is a AVL tree
 */
type Node struct {
	key         int
	height      int
	cnt         int
	left, right *Node
}

func (node *Node) Size() int {
	if node == nil {
		return 0
	}
	return node.cnt
}

func (node *Node) Height() int {
	if node == nil {
		return 0
	}
	return node.height
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func NewNode(key int) *Node {
	node := new(Node)
	node.key = key
	node.height = 1
	node.cnt = 1
	return node
}

func rightRotate(y *Node) *Node {
	x := y.left

	t2 := x.right

	x.right = y
	y.left = t2
	y.height = max(y.left.Height(), y.right.Height()) + 1
	x.height = max(x.left.Height(), x.right.Height()) + 1

	return x
}

func leftRotate(x *Node) *Node {
	y := x.right
	t2 := y.left

	y.left = x
	x.right = t2

	x.height = max(x.left.Height(), x.right.Height()) + 1
	y.height = max(y.left.Height(), y.right.Height()) + 1

	return y
}

func (node *Node) GetBalance() int {
	if node == nil {
		return 0
	}
	return node.left.Height() - node.right.Height()
}

func Insert(node *Node, key int) *Node {
	if node == nil {
		return NewNode(key)
	}
	if node.key == key {
		node.cnt++
		return node
	}

	if node.key > key {
		node.left = Insert(node.left, key)
	} else {
		node.right = Insert(node.right, key)
	}

	node.height = max(node.left.Height(), node.right.Height()) + 1
	balance := node.GetBalance()

	if balance > 1 && key < node.left.key {
		return rightRotate(node)
	}

	if balance < -1 && key > node.right.key {
		return leftRotate(node)
	}

	if balance > 1 && key > node.left.key {
		node.left = leftRotate(node.left)
		return rightRotate(node)
	}

	if balance < -1 && key < node.right.key {
		node.right = rightRotate(node.right)
		return leftRotate(node)
	}

	return node
}

func MinValueNode(root *Node) *Node {
	cur := root

	for cur.left != nil {
		cur = cur.left
	}

	return cur
}

func (root *Node) MinValue() int {
	if root == nil {
		return 0
	}
	node := MinValueNode(root)

	return node.key
}

func FindUpperBound(node *Node, key int) *Node {
	if node == nil {
		return nil
	}
	if node.key > key {
		tmp := FindUpperBound(node.left, key)
		if tmp == nil {
			return node
		}
		return tmp
	}
	// node.key <= key
	return FindUpperBound(node.right, key)
}

func Delete(root *Node, key int) *Node {
	if root == nil {
		return nil
	}

	if key < root.key {
		root.left = Delete(root.left, key)
	} else if key > root.key {
		root.right = Delete(root.right, key)
	} else {
		root.cnt--
		if root.cnt > 0 {
			return root
		}
		if root.left == nil || root.right == nil {
			tmp := root.left
			if root.left == nil {
				tmp = root.right
			}
			root = tmp
		} else {
			tmp := MinValueNode(root.right)

			root.key = tmp.key
			root.cnt = tmp.cnt
			// make sure tmp node deleted after call delete on root.right
			tmp.cnt = 1
			root.right = Delete(root.right, tmp.key)
		}
	}

	if root == nil {
		return root
	}

	root.height = max(root.left.Height(), root.right.Height()) + 1
	balance := root.GetBalance()

	if balance > 1 && root.left.GetBalance() >= 0 {
		return rightRotate(root)
	}

	if balance > 1 && root.left.GetBalance() < 0 {
		root.left = leftRotate(root.left)
		return rightRotate(root)
	}

	if balance < -1 && root.right.GetBalance() <= 0 {
		return leftRotate(root)
	}

	if balance < -1 && root.right.GetBalance() > 0 {
		root.right = rightRotate(root.right)
		return leftRotate(root)
	}

	return root
}


You are given the strings $$$a$$$ and $$$b$$$, consisting of lowercase Latin letters. You can do any number of the following operations in any order:   if $$$|a| > 0$$$ (the length of the string $$$a$$$ is greater than zero), delete the first character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_2 a_3 \ldots a_n$$$;  if $$$|a| > 0$$$, delete the last character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_1 a_2 \ldots a_{n-1}$$$;  if $$$|b| > 0$$$ (the length of the string $$$b$$$ is greater than zero), delete the first character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_2 b_3 \ldots b_n$$$;  if $$$|b| > 0$$$, delete the last character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_1 b_2 \ldots b_{n-1}$$$. Note that after each of the operations, the string $$$a$$$ or $$$b$$$ may become empty.For example, if $$$a=$$$"hello" and $$$b=$$$"icpc", then you can apply the following sequence of operations:   delete the first character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"icpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"cpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"pc";  delete the last character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"pc";  delete the last character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"p". For the given strings $$$a$$$ and $$$b$$$, find the minimum number of operations for which you can make the strings $$$a$$$ and $$$b$$$ equal. Note that empty strings are also equal.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$). Then $$$t$$$ test cases follow. The first line of each test case contains the string $$$a$$$ ($$$1 \le |a| \le 20$$$), consisting of lowercase Latin letters. The second line of each test case contains the string $$$b$$$ ($$$1 \le |b| \le 20$$$), consisting of lowercase Latin letters.

For each test case, output the minimum number of operations that can make the strings $$$a$$$ and $$$b$$$ equal.

5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		if len(s2) > len(s1) {
			s1, s2 = s2, s1
		}

		c := len(s1) + len(s2)
	Loop:
		for win := len(s1); win >= 1; win-- {
			for i := 0; i+win <= len(s1); i++ {
				if strings.Index(s2, s1[i:i+win]) >= 0 {
					c = (len(s1) - win) + (len(s2) - win)
					break Loop
				}
			}
		}

		fmt.Fprintln(out, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	a, b   string
)

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func equal(x, y string) bool {
	if len(x) != len(y) {
		return false
	}
	for i := range x {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}

func solve(a, b string) int {
	var (
		t = min(len(a), len(b))
	)
	for i := t; i > 0; i-- {
		for j := 0; j <= len(a)-i; j++ {
			for k := 0; k <= len(b)-i; k++ {
				p, q := a[j:j+i], b[k:k+i]
				if equal(p, q) {
					return len(a) + len(b) - 2*i
				}
			}
		}
	}
	return len(a) + len(b)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &a, &b)
		fmt.Println(solve(a, b))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		a, b := "", ""
		fmt.Fscan(f, &a, &b)
		la, lb, ok := len(a), len(b), false
		if la < lb {
			a, b = b, a
			la, lb = len(a), len(b)
		}
		for j := lb; j > 0; j-- {
			for k := 0; k < lb; k++ {
				if j+k > lb {
					break
				}
				if strings.Contains(a, string(b[k:j+k])) {
					fmt.Fprintln(w, la+lb-2*j)
					ok, j, k = true, -1, 1000
				}
			}
		}
		if !ok {
			fmt.Fprintln(w, la+lb)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"strings"

	//"math"
	"os"
)

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var a, b string
		Fscan(in, &a, &b)

		if len(a) > len(b) {
			a, b = b, a
		}

		delta := 0
		for flag, stride := true, len(a); stride >= 1; stride-- {
			for i := 0; i + stride <= len(a); i++ {
				pos := strings.Index(b, a[i:i+stride])
				if pos != -1 {
					flag, delta = false, stride
					break
				}
			}
			if !flag {
				break
			}
		}
		Fprintln(out, len(a) + len(b) - 2 * delta)
	}
}

func main() { run(os.Stdin, os.Stdout) }

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCases int
	fmt.Fscan(input, &testCases)

	for testCases > 0 {
		var str1, str2 string
		fmt.Fscan(input, &str1, &str2)
		LCS := findLongestCommonSubstringLength(str1,str2)
		fmt.Println(getTheNumberOfRemovedCharacters(str1, str2, LCS))
		testCases --
	}

}

func findLongestCommonSubstringLength(str1 , str2 string) int {
	dp := make([][] int, len(str1) + 1)
	for i := range dp {
		dp[i] = make([] int, len(str2) + 1)
	}

	LCS := 0

	for i := range dp {
		for j := range dp[i] {
			if i == 0 || j == 0 {
				dp[i][j] = 0
			} else if str1[i - 1] == str2[j - 1] {
				dp[i][j] = 1 + dp[i - 1][j - 1]
				LCS = max(LCS, dp[i][j])
			}
		}
	}

	return LCS
}

func getTheNumberOfRemovedCharacters(str1, str2 string, LCS int) int {
	return (len(str1) + len(str2)) - LCS * 2
}

func max(arg1 int, rest ...int) int {
	curr := arg1
	for _, num := range rest {
		if curr < num {
			curr = num
		}
	}
	return curr
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b := ScanString(), ScanString()

		if len(a) > len(b) {
			a, b = b, a
		}

		res := len(a) + len(b)

		for l := 1; l <= len(a); l++ {
			for s, e := 0, l; e <= len(a); s, e = s+1, e+1 {
				if strings.Contains(b, a[s:e]) {
					res = len(a) + len(b) - 2*l
				}
			}
		}

		fmt.Println(res)
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var a, b string
		fmt.Fscan(in, &a, &b)
		n, m := len(a), len(b)
		dp := make([][]int, n+1)
		for i := range dp {
			dp[i] = make([]int, m+1)
		}
		res := 0
		for i := n;i>=0; i-- {
			for j := m; j>=0; j-- {
				if i == n || j == m {
					continue
				}
				if a[i] == b[j] {
					dp[i][j] = 1 + dp[i+1][j+1]
				}
				if res < dp[i][j] {
					res = dp[i][j]
				}
			}
		}
		fmt.Println(n+m-2*res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func minOperation(a *string, b *string) int {
	N := len(*a)
	M := len(*b)

	for length := min(N, M); length > 0; length-- {
		for i := 0; i+length <= N; i++ {
			for j := 0; j+length <= M; j++ {
				if (*a)[i:i+length] == (*b)[j:j+length] {
					return N + M - 2*length
				}
			}
		}
	}

	return N + M
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.next()
		b := sc.next()

		fmt.Fprintln(wr, minOperation(&a, &b))
	}

}

package main
import "fmt"

func max(n int, m int) int {
	if (n > m) {
		return n
	}
	return m
}

func solve(a string, b string) int {

	m := [20][20]int{}

	var maxL int = 0
	for i := 0; i < len(a); i++ {
		for j := 0; j < len(b); j++ {
			eq := 0
			if (a[i] == b[j]) {
				eq = 1
			}
			if (i*j == 0) {
				m[i][j] = eq
			} else {
				if (eq == 1) {
					m[i][j] = m[i - 1][j - 1] + 1
				}
			}
			maxL = max(m[i][j], maxL)
		}
	}
	return len(a) + len(b) - 2*maxL
}

func main() {
	var t int
	var a,b string
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b)
		fmt.Println(solve(a,b))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int) int {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {

		STRING1 := make([]byte, 0)
		SOZZ := make([]byte, 0)
		fmt.Fscan(input, &STRING1)
		fmt.Fscan(input, &SOZZ)

		a := len(STRING1)
		b := len(SOZZ)
		mu := make([]int, 0)
		for i := 0; i < a; i++ {
			for j := 0; j < b; j++ {
				if STRING1[i] == SOZZ[j] {
					beg := i + 1
					secbeg := j + 1
					leggg := 1
					for q := 0; q > -1; q++ {
						if beg < a && secbeg < b && STRING1[beg] == SOZZ[secbeg] {
							leggg++
							beg++
							secbeg++
						} else {
							mu = append(mu, leggg)
							break
						}
					}
				}
			}
		}
		ll := len(mu)
		if ll > 0 {
			sort.Ints(mu)
			fmt.Println(a + b - 2*mu[ll-1])
		} else {
			fmt.Println(a + b)
		}
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var a string
		var b string

		fmt.Fscanf(in, "%s\n", &a)
		fmt.Fscanf(in, "%s\n", &b)

		ans := math.MaxInt32

		mp := make(map[rune]int)
		for i, c := range a {
			mp[c] = i
		}

		for j := range a {

			for i := range b {
				ea := j
				eb := i
				for ea < len(a) && eb < len(b) && a[ea] == b[eb] {
					ea++
					eb++
				}

				count := len(a) - ea + j + len(b) - eb + i

				// fmt.Println(count)
				if ans > count {
					ans = count
				}

			}

		}

		fmt.Fprintf(out, "%d\n", ans)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var s, t string
		Fscan(in, &s, &t)
		n, m := len(s), len(t)
		for l := min(n, m); l > 0; l-- {
			for r := l; r <= n; r++ {
				for r2 := l; r2 <= m; r2++ {
					if s[r-l:r] == t[r2-l:r2] {
						Fprintln(out, n+m-2*l)
						return
					}
				}
			}
		}
		Fprintln(out, n+m)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		if len(s2) > len(s1) {
			s1, s2 = s2, s1
		}

		var c int
	Loop:
		for win := len(s1); win >= 1; win-- {
			for i := 0; i+win <= len(s1); i++ {
				if strings.Index(s2, s1[i:i+win]) >= 0 {
					c = (len(s1) - win) + (len(s2) - win)
					break Loop
				}
			}
		}

		fmt.Fprintln(out, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	a, b   string
)

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func equal(x, y string) bool {
	if len(x) != len(y) {
		return false
	}
	for i := range x {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}

func solve(a, b string) int {
	var (
		t = min(len(a), len(b))
	)
	for i := t; i > 0; i-- {
		for j := 0; j <= len(a)-i; j++ {
			for k := 0; k <= len(b)-i; k++ {
				p, q := a[j:j+i], b[k:k+i]
				if equal(p, q) {
					return len(a) + len(b) - 2*i
				}
			}
		}
	}
	return 0
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &a, &b)
		fmt.Println(solve(a, b))
	}
}


Little X and Little Z are good friends. They always chat online. But both of them have schedules.Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?

The first line contains four space-separated integers p, q, l, r (1 ≤  p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000). Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000). It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.

Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.

package main

import "fmt"

func intersect(X []int, Z []int, t int) bool {
    i := 0
    j := 0
    for i < len(X) && j < len(Z) {
        if X[i] + t < Z[j] {
            if (j & 1) != 0 {
                return true
            }
            i++
        } else if X[i] + t > Z[j] {
            if (i & 1) != 0 {
                return true
            }
            j++
        } else {
            return true
        }
    }
    return false
}

func main() {
    var p, q, l, r int
    fmt.Scan(&p, &q, &l, &r)
    Z := make([]int, 2 * p)
    X := make([]int, 2 * q)
    for i := 0; i < 2 * p; i++ {
        fmt.Scan(&Z[i])
    }
    for i := 0; i < 2 * q; i++ {
        fmt.Scan(&X[i])
    }
    ret := 0
    for t := l; t <= r; t++ {
        if intersect(X, Z, t) {
            ret++
        }
    }
    fmt.Println(ret)
}

package main

import (
    "fmt"
    "strconv"
    // "strings"
)

func main() {
    var (
        ps, qs, ls, rs string
        p, q, l, r int
        a, b, c, d []int
    )

    fmt.Scanln(&ps, &qs, &ls, &rs)

    p, _ = strconv.Atoi(ps)
    q, _ = strconv.Atoi(qs)
    l, _ = strconv.Atoi(ls)
    r, _ = strconv.Atoi(rs)

    a = make([]int, p)
    b = make([]int, p)

    c = make([]int, q)
    d = make([]int, q)

    for i := 0; i < p; i += 1 {
        var as, bs string
        fmt.Scanln(&as, &bs)

        a[i], _ = strconv.Atoi(as)
        b[i], _ = strconv.Atoi(bs)
    }

    for i := 0; i < q; i += 1 {
        var cs, ds string
        fmt.Scanln(&cs, &ds)

        c[i], _ = strconv.Atoi(cs)
        d[i], _ = strconv.Atoi(ds)
    }

    var res int
    for i := l; i <= r; i += 1 {
        var pi, qi int
        for pi < p && qi < q {
            if (a[pi] <= c[qi] + i && c[qi] + i <= b[pi]) || (a[pi] <= d[qi] + i && d[qi] + i <= b[pi]) || (c[qi] + i <= a[pi] && b[pi] <= d[qi] + i){
                res += 1
                break
            }
            if b[pi] < c[qi] + i {
                pi += 1
            } else if d[qi] + i < a[pi] {
                qi += 1
            }
        }
    }
    fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var p, q, l, r int

	fmt.Sscanf(line, "%d %d %d %d", &p, &q, &l, &r)

	zSegment := make([][2]int, p, p)
	for i := 0; i < p; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &zSegment[i][0], &zSegment[i][1])
	}

	xSegment := make([][2]int, q, q)
	for i := 0; i < q; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &xSegment[i][0], &xSegment[i][1])
	}

	counter := make(map[int]bool)

	for i := l; i <= r; i++ {
		for j := 0; j < p; j++ {
			startZ, endZ := zSegment[j][0], zSegment[j][1]
			for k := 0; k < q; k++ {
				startX, endX := xSegment[k][0], xSegment[k][1]
				if (startZ >= startX+i && startZ <= endX+i) ||
					(endZ <= endX+i && endZ >= startX+i) ||
					(startZ < startX+i && endZ > endX+i) {
					counter[i] = true
				}
			}
		}
	}
	fmt.Println(len(counter))
}

package main

import (
	"fmt"
)

func main() {
	var p, q, l, r int
	fmt.Scanf("%d %d %d %d\n", &p, &q, &l, &r)
	a := make([]int, p)
	b := make([]int, p)
	c := make([]int, q)
	d := make([]int, q)
	for i := 0; i < p; i++ {
		fmt.Scanf("%d %d\n", &a[i], &b[i])
	}

	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d\n", &c[i], &d[i])
	}

	ans := 0
	for t := l; t <= r; t++ {
		f := false
		for i := 0; (i < p) && !(f); i++ {
			for j := 0; (j < q) && !(f); j++ {
				f = (c[j]+t <= b[i]) && (d[j]+t >= a[i])
			}
		}
		if f {
			ans++
		}
	}

	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var p, q, l, r int

	fmt.Sscanf(line, "%d %d %d %d", &p, &q, &l, &r)

	zSegment := make([][2]int, p, p)
	for i := 0; i < p; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &zSegment[i][0], &zSegment[i][1])
	}

	xSegment := make([][2]int, q, q)
	for i := 0; i < q; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &xSegment[i][0], &xSegment[i][1])
	}

	counter := make(map[int]bool)

	for i := l; i <= r; i++ {
		for j := 0; j < p; j++ {
			startZ, endZ := zSegment[j][0], zSegment[j][1]
			for k := 0; k < q; k++ {
				startX, endX := xSegment[k][0], xSegment[k][1]
				if (startZ >= startX+i && startZ <= endX+i) || (endZ <= endX+i && endZ >= startX+i) {
					counter[i] = true
				}
			}
		}
	}
	fmt.Println(len(counter))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var p, q, l, r int

	fmt.Sscanf(line, "%d %d %d %d", &p, &q, &l, &r)

	zSegment := make([][2]int, p, p)
	for i := 0; i < p; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &zSegment[i][0], &zSegment[i][1])
	}

	xSegment := make([][2]int, q, q)
	for i := 0; i < q; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &xSegment[i][0], &xSegment[i][1])
	}

	counter := make(map[int]bool)

	for i := l; i <= r; i++ {
		for j := 0; j < p; j++ {
			startZ, endZ := zSegment[j][0], zSegment[j][1]
			fmt.Println(startZ, endZ)
			for k := 0; k < q; k++ {
				startX, endX := xSegment[k][0], xSegment[k][1]
				fmt.Println(startX, endX, startX+i, endX+i)
				if (startZ >= startX+i && startZ <= endX+i) ||
					(endZ <= endX+i && endZ >= startX+i) ||
					(startZ < startX+i && endZ > endX+i) {
					counter[i] = true
				}
			}
		}
	}
	fmt.Println(len(counter))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var p, q, l, r int

	fmt.Sscanf(line, "%d %d %d %d", &p, &q, &l, &r)

	zSegment := make([][2]int, p, p)
	for i := 0; i < p; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &zSegment[i][0], &zSegment[i][1])
	}

	xSegment := make([][2]int, q, q)
	for i := 0; i < q; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &xSegment[i][0], &xSegment[i][1])
	}

	counter := make(map[int]bool)

	for j := 0; j < p; j++ {
		startZ, endZ := zSegment[j][0], zSegment[j][1]
		for k := 0; k < q; k++ {
			startX, endX := xSegment[k][0], xSegment[k][1]
			for i := l; i <= r; i++ {
				if (startZ >= startX+i && startZ <= endX+i) || (endZ <= endX+i && endZ >= startX+i) {
					counter[i] = true
				}
			}
		}
	}
	fmt.Println(len(counter))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var p, q, l, r int

	fmt.Sscanf(line, "%d %d %d %d", &p, &q, &l, &r)

	zSegment := make([][2]int, p, p)
	for i := 0; i < p; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &zSegment[i][0], &zSegment[i][1])
	}

	xSegment := make([][2]int, q, q)
	for i := 0; i < q; i++ {
		line, _ := reader.ReadString('\n')
		fmt.Sscanf(line, "%d %d", &xSegment[i][0], &xSegment[i][1])
	}

	counter := make(map[int]bool)

	for j := 0; j < p; j++ {
		startZ, endZ := zSegment[j][0], zSegment[j][1]
		for k := 0; k < q; k++ {
			startX, endX := xSegment[k][0], xSegment[k][1]
			for i := l; i <= r; i++ {
				if startZ > endX+i || endZ < startX+i {
					// break
					continue
				} else if startZ >= startX+i || endZ <= endX+i {
					counter[i] = true
				}
			}
		}
	}
	fmt.Println(len(counter))
}