Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:  Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).  The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + ali + 1 + ... + ari = 0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers a1, a2, ..., an (ai = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Print m integers — the responses to Eugene's queries in the order they occur in the input.

package main

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

func read_ints(in *bufio.Reader) []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range words {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

func main() {
	var x []int
	in := bufio.NewReader(os.Stdin)
	cnt1, cnt2 := 0, 0
	m := read_ints(in)[1]
	a := read_ints(in)
	for _, v := range a {
		if v == -1 {
			cnt1++
		} else {
			cnt2++
		}
	}
	for i := 0; i < m; i++ {
		x = read_ints(in)
		length := x[1] - x[0] + 1
		if length&1 == 0 && length>>1 <= cnt1 && length>>1 <= cnt2 {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	}
}

// 302A-mic
package main

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

func main() {
    var n, m, l, r int
    s := bufio.NewScanner(os.Stdin)
    s.Split(bufio.ScanWords)
    var a [200005]int
    fmt.Scan(&n, &m)
    var cou1, cou2 int
    for i := 0; i < n; i++ {
        s.Scan()
        t, _ := strconv.Atoi(s.Text())
        a[i] = t
        if a[i] == 1 {
            cou1++
        } else {
            cou2++
        }
    }
    for ; m > 0; m-- {
        s.Scan()
        z, _ := strconv.Atoi(s.Text())
        l = z
        s.Scan()
        u, _ := strconv.Atoi(s.Text())
        r = u
        //fmt.Scan(&l, &r)
        x := r - l + 1
        if x%2 == 1 {
            fmt.Println("0")
        } else {
            if x/2 <= cou1 && x/2 <= cou2 {
                fmt.Println("1")
            } else {
                fmt.Println("0")
            }
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,max int
    fmt.Scan(&n,&m)
    x := make(map[int]int)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        x[a+1]++
    }
    if x[0] < x[2]{ max = x[0] } else { max = x[2] }
    for i := 0; i < m; i++ {
        scanner.Scan()
        l, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        r, _ := strconv.Atoi(scanner.Text())
        if ((r-l+1)%2 == 0) && ((r-l+1)/2 <= max) { writer.WriteRune('1') } else { writer.WriteRune('0') }
        writer.WriteRune('\n')
    }
    writer.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var i,j,u,c,n,m int64
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n,&m)
	for i=0;i<n;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		j=int64(aa)
		//fmt.Scan(&j)
		if j<0 {
			c++
		} else {
			u++
		}
	}
	if c>u {
		c=u
	}
	c*=2
	for i=0;i<m;i++ {
		input.Scan()
		bb,_:= strconv.Atoi(input.Text())
		u=int64(bb)
		input.Scan()
		cc,_:= strconv.Atoi(input.Text())
		j=int64(cc)
		//fmt.Scan(&u,&j)
		u=j-u+1
		if (u>c) || (u%2==1) {
			out.WriteString("0\n")
			out.Flush()
			//fmt.Println("0")
		} else {
			//fmt.Println("1")
			out.WriteString("1\n")
			out.Flush()
		}
	}
	out.Flush()
}

package main

import "bufio"
import "fmt"
import "os"
import "strconv"

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 300000, 300000)
  in.Buffer(buf, 0)
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    a := readInt()

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    l := readInt()
    r := readInt()
    len := r - l + 1

    if len%2 == 0 && len/2 <= min {
      fmt.Println("1")
    } else {
      fmt.Println("0")
    }
  }
}

package main

import "bufio"
import "math"
import "os"
import "strconv"

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriterSize(os.Stdout, 300000)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 300000, 300000)
  in.Buffer(buf, 0)
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func main() {
  var ac [2]int
  n := readInt()
  m := readInt()

  for i := 0; i < n; i++ {
    a := readInt()

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
  }

  min := math.Min(float64(ac[0]), float64(ac[1]))

  for i := 0; i < m; i++ {
    l := readInt()
    r := readInt()
    len := r - l + 1

    if len%2 == 0 && len/2 <= int(min) {
      out.WriteString("1\n")
    } else {
      out.WriteString("0\n")
    }
  }

  out.Flush()
}

package main

import "bufio"
import "fmt"
import "os"
import "strconv"

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriterSize(os.Stdout, 300000)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 300000, 300000)
  in.Buffer(buf, 0)
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    a := readInt()

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    l := readInt()
    r := readInt()
    len := r - l + 1

    if len%2 == 0 && len/2 <= min {
      out.WriteString("1\n")
    } else {
      out.WriteString("0\n")
    }
  }

  out.Flush()
}

// 302A-mic
package main

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

func main() {
	var n, m, l, r int
	var a [200005]int
	fmt.Scan(&n, &m)
	var cou1, cou2 int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if a[i] == 1 {
			cou1++
		} else {
			cou2++
		}
	}
	for ; m > 0; m-- {
		fmt.Scan(&l, &r)
		x := r - l + 1
		if x%2 == 1 {
			fmt.Println("0")
		} else {
			if x/2 <= cou1 && x/2 <= cou2 {
				fmt.Println("1")
			} else {
				fmt.Print("0")
			}
		}
	}
}

// 302A-mic
package main

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

func main() {
	s := bufio.NewReader(os.Stdin)
	//o := bufio.NewWriter(os.Stdout)
	var n, m, c, i, a, b int64
	fmt.Scan(&n, &m)
	for i = 0; i < n; i++ {
		fmt.Fscan(s, &c)
		if c == 1 {
			a++
		} else {
			b++
		}
	}
	for i = 0; i < m; i++ {
		var x, y, d int64
		fmt.Scan(&x, &y)
		d = y - x + 1
		if d%2 == 0 && a >= d/2 && b >= d/2 {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	}
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var i,j,u,c,n,m int64
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n,&m)
	for i=0;i<n;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		j=int64(aa)
		//fmt.Scan(&j)
		if j<0 {
			c++
		} else {
			u++
		}
	}
	if c>u {
		c=u
	}
	c*=2
	for i=0;i<m;i++ {
		input.Scan()
		bb,_:= strconv.Atoi(input.Text())
		u=int64(bb)
		input.Scan()
		cc,_:= strconv.Atoi(input.Text())
		j=int64(cc)
		//fmt.Scan(&u,&j)
		u=j-u+1
		if (u>c) || (u%2==1) {
			out.WriteString("0")
			out.Flush()
			//fmt.Println("0")
		} else {
			//fmt.Println("1")
			out.WriteString("1")
			out.Flush()
		}
	}
	out.Flush()
}

package main

import "fmt"

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    var a int
    fmt.Scanf("%d", &a)

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    var l, r int
    fmt.Scanf("%d %d", &l, &r)
    len := r - l + 1

    if len%2 == 0 && len/2 <= min {
      fmt.Println("1")
    } else {
      fmt.Println("0")
    }
  }
}

package main

import "bufio"
import "fmt"
import "os"
import "strconv"

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriterSize(os.Stdout, 300000)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 300000, 300000)
  in.Buffer(buf, 0)
}

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    a := readInt()

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
    fmt.Printf("a: %d, ac[0]: %d, ac[1]: %d\n", a, ac[0], ac[1])
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    l := readInt()
    r := readInt()
    len := r - l + 1

    fmt.Printf("r: %d, l: %d, len: %d, min: %d, len%2: %d\n", r, l, len, min, int(len%2))
    if len%2 == 0 && len/2 <= min {
      out.WriteString("1\n")
    } else {
      out.WriteString("0\n")
    }
  }

  out.Flush()
}

package main

import "bufio"
import "fmt"
import "os"

var out = bufio.NewWriterSize(os.Stdout, 300000)

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    var a int
    fmt.Scanf("%d", &a)

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    var l, r int
    fmt.Scanf("%d %d", &l, &r)
    len := r - l + 1

    if len%2 == 0 && len/2 <= min {
      //fmt.Println("1")
      out.WriteString("1\n")
    } else {
      //fmt.Println("0")
      out.WriteString("0\n")
    }
  }

  out.Flush()
}

package main

import "bufio"
import "fmt"
import "os"

var out = bufio.NewWriterSize(os.Stdout, 300000)

func main() {
  var n, m int
  var ac [2]int
  fmt.Scanf("%d %d", &n, &m)

  for i := 0; i < n; i++ {
    var a int
    fmt.Scanf("%d", &a)

    if a == -1 {
      ac[0]++
    } else {
      ac[1]++
    }
    fmt.Printf("a: %d, ac[0]: %d, ac[1]: %d\n", a, ac[0], ac[1])
  }

  var min int
  if ac[0] < ac[1] {
    min = ac[0]
  } else {
    min = ac[1]
  }

  for i := 0; i < m; i++ {
    var l, r int
    fmt.Scanf("%d %d", &l, &r)
    len := r - l + 1

    fmt.Printf("r: %d, l: %d, len: %d, min: %d, len%2: %d\n", r, l, len, min, len%2)
    if len%2 == 0 && len/2 <= min {
      out.WriteString("1\n")
    } else {
      out.WriteString("0\n")
    }
  }

  out.Flush()
}


ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.

Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.

NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, c, t int
	fmt.Fscanf(bufin, "%d %d\n", &n, &c)

	cnt := 0
	prev := -1

	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%d\n", &t)
		if (prev != -1) && (t-prev > c) {
			cnt = 0
		}
		cnt++
		prev = t
	}

	fmt.Fprintf(bufout, "%d\n", cnt)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var n, c int
	r,y := 0,0
	fmt.Scan(&n,&c)
	scan := bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanWords)
	for scan.Scan() {
		x,_ := strconv.Atoi(scan.Text())
		if x-y>c {
			r = 0
		}
		y = x
		r++
	}
	fmt.Print(r)
}

// Codeforces 716 0 CrazyComputer
// int - 32 bit type !!!!
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
    var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for i:=0; i<len(ss); i++ {
        a[i], err = strconv.Atoi(ss[i])
        if err != nil {
            fmt.Println("n atoi failure", err)
            panic(err)
        }
    }
    return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
    a := make([]int, n)
    s, err := in.ReadString('\n')
    if err != nil {
        fmt.Println("read failure", err)
        panic(err)
    }
    ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for j:=0; j<n; j++ {
        aa,err := strconv.Atoi(ss[j])
        if err != nil {
            fmt.Println("aa conv failed", err)
            panic(err)
        }
        a[j] = aa
    }
    return a
}

var n, c int
var num int
var a []int

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,c,_,_,_ = readFive()
    a = readLineNumbs(n)
}

func solve() {
    num = 0

    for i:=0; i<n; i++ {
        if i==0 {
            num = 1
        } else if a[i] > (a[i-1]+c) {
            num = 1
        } else {
            num++
        }
    }
}

func printRes() {
    fmt.Println(num)
}

func main() {
 	readData()
    solve()
    printRes()
}

// 5.05
package main

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

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

	c, _ := strconv.Atoi(strings.Split(strings.TrimSpace(nc), " ")[1])
	s := strings.Split(strings.TrimSpace(w), " ")

	//fmt.Println(c)
	//fmt.Println(s)

	words := 1
	for i := len(s) - 1; i > 0; i-- {
		j, _ := strconv.Atoi(s[i])
		k, _ := strconv.Atoi(s[i-1])
		//fmt.Println(i, j, k)
		if j-k <= c {
			words++
		} else {
			break
		}
	}

	fmt.Println(words)
}

package main

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

func main() {
	var n, c int
	fmt.Scan(&n, &c)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var cnt int
	for t0, t1 := 0, 0; scanner.Scan(); {
		s := scanner.Text()
		t1, _ = strconv.Atoi(s)
		if t1-t0 > c {
			cnt = 1
		} else {
			cnt++
		}
		t0 = t1
	}
	fmt.Print(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n, c int

	fmt.Scan(&n, &c)

	var ts = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ts[i])
	}

	ans := 1
	for i := n - 1; i > 0; i-- {
		if ts[i]-ts[i-1] > c {
			break
		}
		ans++
	}

	fmt.Println(ans)
}

package main

import "fmt"

func main() {
    var n,c int
    fmt.Scan(&n, &c)
    var cnt int
    for i:=0; i<n; i++ {
        var t0, t1 int
        fmt.Scan(&t1)
        if t1-t0 > c {
            cnt = 1
        } else {
            cnt++
            t0 = t1
        }
    }
    fmt.Print(cnt)
}

package main

import "fmt"

func main() {
    var n,c int
    fmt.Scan(&n, &c)
    var cnt int
    for i:=0; i<n; i++ {
        var t0, t1 int
        fmt.Scan(&t1)
        if t1-t0 > c {
            cnt = 1
        } else {
            cnt++
        }
    }
    fmt.Print(cnt)
}

package main

import "fmt"

func main() {
    var n,c int
    fmt.Scan(&n, &c)
    var cnt int
    for i, t0, t1:=0,0,0; i<n; i++ {
        fmt.Scan(&t1)
        if t1-t0 > c {
            cnt = 1
        } else {
            cnt++
            t0 = t1
        }
    }
    fmt.Print(cnt)
}

package main

import "fmt"

func main() {
    var n,c int
    fmt.Scan(&n, &c)
    var cnt int
    for i:=0; i<n; i++ {
        var t0, t1 int
        fmt.Scan(&t1)
        fmt.Print(t1)
        if t1-t0 > c {
            cnt = 1
        } else {
            cnt++
            t0 = t1
        }
    }
    fmt.Print(cnt)
}

package main

import "fmt"

func main() {
    var n,c int
    fmt.Scan(&n, &c)
    var cnt int
    for i, t0, t1:=0,0,0; i<n; i++ {
        fmt.Scan(&t1)
        fmt.Print(t1-t0, " ")
        if t1-t0 > c {
            cnt = 1
        } else {
            cnt++
            t0 = t1
        }
    }
    fmt.Print(cnt)
}


You are given an array $$$a_1, a_2, \ldots, a_n$$$ consisting of $$$n$$$ positive integers and a positive integer $$$m$$$.You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.Let's call an array $$$m$$$-divisible if for each two adjacent numbers in the array (two numbers on the positions $$$i$$$ and $$$i+1$$$ are called adjacent for each $$$i$$$) their sum is divisible by $$$m$$$. An array of one element is $$$m$$$-divisible.Find the smallest number of $$$m$$$-divisible arrays that $$$a_1, a_2, \ldots, a_n$$$ is possible to divide into.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 1000)$$$  — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$m$$$ $$$(1 \le n \le 10^5, 1 \le m \le 10^5)$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$10^5$$$.

For each test case print the answer to the problem.

NoteIn the first test case we can divide the elements as follows:  $$$[4, 8]$$$. It is a $$$4$$$-divisible array because $$$4+8$$$ is divisible by $$$4$$$.  $$$[2, 6, 2]$$$. It is a $$$4$$$-divisible array because $$$2+6$$$ and $$$6+2$$$ are divisible by $$$4$$$.  $$$[9]$$$. It is a $$$4$$$-divisible array because it consists of one element.

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		c := make(map[int]int)
		for i := 0; i < n; i++ {
			var tp int
			fmt.Fscan(in, &tp)
			tp %= m
			if tp == 0 {
				c[tp] = 0
			} else if tp == m/2 && m%2 == 0 {
				c[tp] = 0
			} else if tp <= m/2 {
				c[tp]++
			} else {
				c[m-tp]--
			}
		}
		rs := 0
		for _, v := range c {
			if v == 0 {
				rs++
			} else if v > 0 {
				rs += v
			} else {
				rs -= v
			}
		}
		fmt.Println(rs)
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		mp := map[int]int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mp[a[i]%m]++
		}

		counted := 0
		ans := 0
		for k, v := range mp {
			if k == 0 || k == m-k {
				counted += v
				ans++
			} else if k < m-k {
				if mp[k] > 0 && mp[m-k] > 0 {
					mx := max(mp[k], mp[m-k])
					mi := min(mp[k], mp[m-k])
					if mi != mx {
						counted += mi + mi + 1
						ans++
					} else {
						counted += mi * 2
						ans++
					}
				}
			}
		}
		ans += (n - counted)
		write(f, ans, "\n")

	}
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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 n, k int
		fmt.Fscan(in, &n, &k)

		m := make(map[int]int, n)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			m[v%k]++
		}

		var tot int
		if m[0] > 0 {
			tot++
		}
		if k%2 == 0 && m[k/2] > 0 {
			tot++
		}

		l := k / 2
		if k%2 != 0 {
			l++
		}
		for i := 1; i < l; i++ {
			d := min(m[i], m[k-i])
			if d > 0 {
				m[i] -= d
				m[k-i] -= d
				tot++
				if m[i] > 0 {
					m[i]--
				}

				if m[k-i] > 0 {
					m[k-i]--
				}
			}
			tot += m[i] + m[k-i]
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

/*
4
1 1
1
2 3
1 1
2 3
1 2
5 4
1 5 7 2 4
---
1
2
1
3 -> (1 3 1) 2 0
========
1
6 4
2 2 8 6 9 4
---
3 -> (2 2 2) 0 1 0
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t int
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)

		cnts := make(map[int]int)

		for i := 0; i < n; i++ {
			var num int
			scanf("%d", &num)

			cnts[num%m]++
		}
		scanf("\n")

		arrCnt := 0

		for num1, cnt1 := range cnts {
			num2 := m - num1
			cnt2, ok := cnts[num2]

			switch {
			case num1 == num2 || num1 == 0:
				arrCnt++
			case !ok:
				arrCnt += cnt1
			case cnt1 < cnt2:
				arrCnt++
				arrCnt += cnt2 - (cnt1 + 1)
			case cnt1 > cnt2:
				arrCnt++
				arrCnt += cnt1 - (cnt2 + 1)
			default:
				arrCnt++
			}

			delete(cnts, num1)
			delete(cnts, num2)
		}

		fmt.Fprintf(&bld, "%d\n", arrCnt)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	//"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 n, m int
		Fscan(in, &n, &m)
		mp := make([]int, 100005)

		for i := 0; i < n; i++ {
			var num int
			Fscan(in, &num)
			mp[num % m]++
		}

		ans := 0
		for left, right := 1, m-1; left <= right; {
			if mp[left] == 0 && mp[right] == 0 {
				left++; right--
				continue
			}
			ans += max(1, max(mp[left], mp[right]) - min(mp[left], mp[right]))
			left++; right--
		}
		if mp[0] != 0 {
			ans++
		}
		Fprintln(out, ans)
	}
}

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

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

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

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	defer writer.Flush()
	var testcases int
	fmt.Fscan(reader, &testcases)

	for testcase := 0; testcase < testcases; testcase++ {
		var a, n, m int64
		fmt.Fscan(reader, &n, &m)
		mod := make([]int64, m)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(reader, &a)
			mod[a%m]++
		}

		ans := int64(0)
		// mod 0
		if mod[0] != 0 {
			ans++
		}

		// mod m/2 if m is even
		if m&1 == 0 && mod[m/2] != 0 {
			ans++
		}

		// others
		for set := int64(1); set <= (m-1)/2; set++ {
			// set and m-set are paired
			if mod[set] == mod[m-set] {
				if mod[set] != 0 {
					ans++
				}
			} else if mod[set] > mod[m-set] {
				ans += mod[set] - mod[m-set]
			} else {
				ans += mod[m-set] - mod[set]
			}
		}

		fmt.Fprintln(writer, ans)
	}
}

package main

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

// 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 int) int {
	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 o := 0; o < t; o++ {
		var n, m int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &m)

		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		remainder := make([]int, m)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
			j := ARRAY[i] % m
			remainder[j] = remainder[j] + 1

		}
		answer := 0
		if m%2 == 0 {
			if remainder[0] > 0 {
				answer++
			}
			if remainder[int(m/2)] > 0 {
				answer++
			}
			l := int(m / 2)
			for j := 1; j < l; j++ {
				answer = answer + MAX(remainder[j], remainder[m-j]) - MIN(remainder[j], remainder[m-j])
				if remainder[j] == remainder[m-j] && remainder[j]*remainder[m-j] != 0 {
					answer++
				}
			}
		} else {
			if remainder[0] > 0 {
				answer++
			}
			l := int(m / 2)
			for j := 1; j < l+1; j++ {
				answer = answer + MAX(remainder[j], remainder[m-j]) - MIN(remainder[j], remainder[m-j])
				if remainder[j] == remainder[m-j] && remainder[j]*remainder[m-j] != 0 {
					answer++
				}
			}

		}
		fmt.Println(answer)

	}
}

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 n, m int
		Fscan(in, &n, &m)
		cnt := make([]int, m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for _, v := range a {
			v %= m
			cnt[v]++
		}
		ans := 0
		if cnt[0] > 0 {
			ans++
		}
		for i := 1; i < (m+1)/2; i++ {
			mi := min(cnt[i], cnt[m-i])
			mx := max(cnt[i], cnt[m-i])
			if mi > 0 {
				ans++
			} else if mx > 0 {
				ans+=mx
				continue
			}
			if mx > mi+1 {
				ans += mx - mi-1
			}
		}
		if m&1 == 0 {
			if cnt[m/2] > 0 {
				ans++
			}
		}
		Fprintln(out, ans)
	}

	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
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		c := make(map[int]int)
		for j := 0; j < n; j++ {
			var tp int
			fmt.Fscan(in, &tp)
			tp %= m
			if tp == 0 {
				c[tp] = 0
			} else if tp == m/2 && m%2 == 0 {
				c[tp] = 0
			} else if tp < m/2 {
				c[tp]++
			} else {
				c[m-tp]--
			}
		}
		rs := 0
		for _, v := range c {
			if v == 0 {
				rs++
			} else if v > 0 {
				rs += v
			} else {
				rs -= v
			}
		}
		fmt.Println(rs)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		c := make(map[int]int)
		f := make(map[int]bool)
		for j := 0; j < n; j++ {
			var tp int
			fmt.Fscan(in, &tp)
			tp %= m
			if tp == 0 {
				f[0] = true
			} else if tp == m/2 && m%2 == 0 {
				f[tp] = true
			} else if tp < m/2 {
				c[tp]++
				f[tp] = true
			} else {
				c[m-tp]--
				f[m-tp] = true
			}
		}
		rs := 0
		for i := range f {
			v := c[i]
			if v > 0 {
				rs += v
			} else {
				rs -= v
			}
			if v == 0 && f[i] {
				rs++
			}
		}
		fmt.Println(rs)
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		mp := map[int]int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mp[a[i]%m]++
		}
		if T == 2 {
			fmt.Println(mp)
		}
		counted := 0
		ans := 0
		for k, v := range mp {
			if k == 0 || k == m-k {
				counted += v
				ans++
			} else if k < m-k {
				if mp[k] > 0 && mp[m-k] > 0 {
					mx := max(mp[k], mp[m-k])
					mi := min(mp[k], mp[m-k])
					if mi != mx {
						counted += mi + mi + 1
						ans++
					} else {
						if mi == 1 {
							counted += 2
							ans++
						} else {
							counted += mi + mi - 1
							ans++
						}

					}
				}
			}
		}
		ans += (n - counted)
		write(f, ans, "\n")

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		mp := map[int]int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mp[a[i]%m]++
		}
		counted := 0
		ans := 0
		for k, v := range mp {
			if k == 0 || k == m-k {
				counted += v
				ans++
			} else if k < m-k {
				if mp[k] > 0 && mp[m-k] > 0 {
					mx := max(mp[k], mp[m-k])
					mi := min(mp[k], mp[m-k])
					if mi != mx {
						counted += mi + mi + 1
						ans++
					} else {
						if mi == 1 {
							counted += 2
							ans++
						} else {
							counted += mi + mi - 1
							ans++
						}

					}
				}
			}
		}
		ans += (n - counted)
		write(f, ans, "\n")

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		mp := map[int]int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mp[a[i]%m]++
		}
		counted := 0
		ans := 0
		for k, v := range mp {
			if k == 0 || k == m-k {
				counted += v
				ans++
			} else if k < m-k {
				if mp[k] > 0 && mp[m-k] > 0 {
					mx := max(mp[k], mp[m-k])
					mi := min(mp[k], mp[m-k])
					triplets := min(mx/2, mi)
					ans += triplets
					mx -= triplets * 2
					mi -= triplets
					counted += triplets * 3
					ans += min(mi, mx)
					counted += min(mi, mx) * 2
				}
			}
		}
		ans += (n - counted)
		write(f, ans, "\n")

	}
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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 n, k int
		fmt.Fscan(in, &n, &k)

		m := make(map[int]int, n)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			m[v%k]++
		}

		var tot int
		if m[0] > 0 {
			tot++
		}
		if k%2 == 0 && m[k/2] > 0 {
			tot++
		}
		for i := 1; i < k/2; i++ {
			d := min(m[i], m[k-i])
			if d > 0 {
				m[i] -= d
				m[k-i] -= d
				tot++
				if m[i] > 0 {
					m[i]--
				}

				if m[k-i] > 0 {
					m[k-i]--
				}
			}
			tot += m[i] + m[k-i]
		}
		fmt.Fprintln(out, tot)
	}
}


You are given two arrays $$$a$$$ and $$$b$$$ both consisting of $$$n$$$ positive (greater than zero) integers. You are also given an integer $$$k$$$.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) and swap $$$a_i$$$ and $$$b_j$$$ (i.e. $$$a_i$$$ becomes $$$b_j$$$ and vice versa). Note that $$$i$$$ and $$$j$$$ can be equal or different (in particular, swap $$$a_2$$$ with $$$b_2$$$ or swap $$$a_3$$$ and $$$b_9$$$ both are acceptable moves).Your task is to find the maximum possible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ such moves (swaps).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 30; 0 \le k \le n$$$) — the number of elements in $$$a$$$ and $$$b$$$ and the maximum number of moves you can do. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 30$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 30$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$.

For each test case, print the answer — the maximum possible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ swaps.

NoteIn the first test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_2 = 4$$$, so $$$a=[4, 2]$$$ and $$$b=[3, 1]$$$.In the second test case of the example, you don't need to swap anything.In the third test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_1 = 10$$$, $$$a_3 = 3$$$ and $$$b_3 = 10$$$ and $$$a_2 = 2$$$ and $$$b_4 = 10$$$, so $$$a=[10, 10, 10, 4, 5]$$$ and $$$b=[1, 9, 3, 2, 9]$$$.In the fourth test case of the example, you cannot swap anything.In the fifth test case of the example, you can swap arrays $$$a$$$ and $$$b$$$, so $$$a=[4, 4, 5, 4]$$$ and $$$b=[1, 2, 2, 1]$$$.

package main

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

func main() {
	var t int
	var n, k int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &b[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		sort.Slice(b, func(i, j int) bool {
			return b[i] > b[j]
		})
		sum := 0
		ai := 0
		bi := 0
		for j := 0; j < n; j++ {
			if a[ai] >= b[bi] || k == 0 {
				sum += a[ai]
				ai++
			} else {
				sum += b[bi]
				bi++
				k--
			}
		}
		fmt.Println(sum)
	}
}

package main

import (
	"fmt"
	"sort"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}

	sort.Ints(a)
	sort.Slice(b, func(c, d int) bool {
		return b[c] > b[d]
	})

	for i := 0; i < k; i++ {
		if b[i] < a[i] {
			break
		}
		a[i], b[i] = b[i], a[i]
	}

	var ans int
	for i := 0; i < n; i++ {
		ans += a[i]
	}
	fmt.Println(ans)
}

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

package main

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

func scanSortSlice(in *bufio.Reader, n int) []int {
	a := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)
	return a
}

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-- {
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := scanSortSlice(in, n)
		b := scanSortSlice(in, n)
		for i := 0; i < k; i++ {
			if a[i] < b[n-i-1] {
				a[i] = b[n-i-1]
			}
		}
		result := 0
		for _, v := range a {
			result += v
		}
		fmt.Fprintln(out, result)
	}
}

// https://codeforces.com/contest/1350/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n, k int
	fmt.Fscan(input, &n, &k)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &b[i])
	}

	sort.Ints(a)
	sort.Ints(b)
	ans := 0
	for i := 0; i < k; i++ {
		if a[i] < b[n - 1 - i] {
			a[i] = b[n - 1 - i]
		}
	}
	for i := 0; i < n; i++ {
		ans += a[i]
	}

	return ans
}

package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		nk := scanner.Text()

		parts := strings.Fields(nk)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		k, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		as := scanner.Text()

		scanner.Scan()

		bs := scanner.Text()

		psa := strings.Fields(as)

		a := make([]int, n)

		for i := 0; i < n; i ++ {
			a1, err := strconv.Atoi(psa[i])

			if err != nil {
				panic(err)
			}

			a[i] = a1
		}

		psb := strings.Fields(bs)

		b := make([]int, n)

		for i := 0; i < n; i ++ {
			b1, err := strconv.Atoi(psb[i])

			if err != nil {
				panic(err)
			}

			b[i] = b1
		}

		ans := solve2(a, b, k)

		fmt.Println(ans)
	}
}

func solve2(a []int, b []int, k int ) int {
	sort.Ints(a)

	sort.SliceStable(b, func(i, j int) bool {
		return b[i] > b[j]
	})

	for i := 0; i < k; i++ {
		if b[i] < a[i] {
			break
		}
		a[i] = b[i]
	}

	sum := 0

	for i := 0; i < len(a); i ++ {
		sum += a[i]
	}

	return sum
}

package main

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

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

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		sort.Ints(b)
		a = append(a, b[n-k:]...)
		sort.Ints(a)
		s := 0
		for _, v := range a[k:] {
			s += v
		}
		Fprintln(out, s)
	}
}

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

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k, or, sum int
		var s1, s2 []int
		fmt.Fscan(in, &n, &k)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &or)
			s1 = append(s1, or)
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &or)
			s2 = append(s2, or)
		}
		sort.Ints(s1)
		sort.Ints(s2)
		var indi1 int
		indi2 := len(s2) - 1
		for j := 0; j < k; j++ {
			//if
			if s1[indi1] < s2[indi2] {
				temp := s1[indi1]
				s1[indi1] = s2[indi2]
				s2[indi2] = temp
				indi1++
				indi2--
			}
		}
		for j := 0; j < len(s1); j++ {
			sum += s1[j]
		}
		fmt.Println(sum)
		//fmt.Println(s1)

	}
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		a := ScanIntSlice(n)
		b := ScanIntSlice(n)
		sort.Ints(a)
		sort.Slice(b, func(i, j int) bool {
			return b[i] > b[j]
		})

		i := 0
		for k > 0 && i < n {
			if a[i] < b[i] {
				k--
				a[i], b[i] = b[i], a[i]
			}
			i++
		}
		sum := int64(0)
		for i := 0; i < n; i++ {
			sum += int64(a[i])
		}
		P(sum)
		//P(a)
		//P(b)
	}

	close(O)
	oWg.Wait()
}

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

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

func init() {
	P = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
   "fmt"
   "sort"
)

func main() {
   var t int
   fmt.Scan(&t)
   for ;t!=0;t--{
      var n,k int
      var a,b []int
      fmt.Scan(&n)
      fmt.Scan(&k)
      for i,x:=0,0;i<n;i++{

         fmt.Scan(&x)
         a = append(a,x)
      }
      for i,x:=0,0;i<n;i++{
         fmt.Scan(&x)
         b = append(b,x)
      }
      sort.Ints(a)
      sort.Ints(b)
      for i,j:=0,n-1;i<n&&k>0;i++{
         if(a[i]<b[j]){
            a[i]=b[j]
            k--
            j--
         }else{
            break
         }
         if(k==0){
             break
         }
      }
      var sum int
      for i:=0;i<n;i++{
         sum+=a[i]
      }
      fmt.Println(sum)
   }
}

package main

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

var nt int
var n, k int
var a[] int
var b[] int

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d %d\n", &n, &k)
		a = make([]int, n)
		b = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &b[i])
		}
		fmt.Fscanf(reader, "\n")
		sort.Ints(a)
		sort.Ints(b)

		//fmt.Println(a)
		//fmt.Println(b)

		var sum = 0
		var tot = 0
		for _, z := range a {
			sum += z
			tot += z
		}

		var cur = 0
		for i := 0; i < k; i++ {
			cur -= a[i]
			cur += b[n - 1 - i]
			//fmt.Println("delta", b[n - 1 - i] - a[i])
			sum = max(sum, tot + cur)
		}
		fmt.Fprintf(writer, "%d\n", sum)
	}
}

// https://serhatgiydiren.github.io

package main

import "fmt"
import "sort"

func solve(test_id int) {
 var n,k int
	fmt.Scan(&n,&k)
 x := make([]int, n)
 y := make([]int, n)
 res := 0
 for i := 0 ; i < n ; i++ {
  fmt.Scan(&x[i])
  res+=x[i]
 }
 for i := 0 ; i < n ; i++ {
  fmt.Scan(&y[i])
 }
 sort.Ints(x)
 sort.Ints(y)
 for i := 0 ; i < k ; i++ {
  if (y[n-1-i]<=x[i]) {
   break
  }
  res+=y[n-1-i]-x[i]
 }
 fmt.Println(res)
}

func solve_cases() {
 t := 1
 fmt.Scan(&t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t, n, k int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &k)
		var a = make([]int, n)
		var b = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
		}
		for j := 0; j < n; j++ {
			fmt.Scan(&b[j])
		}
		sort.Ints(a)
		sort.Ints(b)
		var x, y = 0, n - 1
		for x < n && k > 0 {
			if a[x] < b[y] {
				a[x] ^= b[y]
				b[y] ^= a[x]
				a[x] ^= b[y]
			}
			x += 1
			y -= 1
			k -= 1
		}
		var result = 0
		for j := 0; j < n; j++ {
			result += a[j]
		}
		fmt.Println(result)
	}
}

package main

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

// https://codeforces.com/problemset/problem/1353/B
// B. Two Arrays And Swaps
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// You are given two arrays a
// and b both consisting of n positive (greater than zero) integers. You are also given an integer k

// .

// In one move, you can choose two indices i
// and j (1≤i,j≤n) and swap ai and bj (i.e. ai becomes bj and vice versa). Note that i and j can be equal or different (in particular, swap a2 with b2 or swap a3 and b9

// both are acceptable moves).

// Your task is to find the maximum possible sum you can obtain in the array a
// if you can do no more than (i.e. at most) k

// such moves (swaps).

// You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤200) — the number of test cases. Then t

// test cases follow.

// The first line of the test case contains two integers n
// and k (1≤n≤30;0≤k≤n) — the number of elements in a and b and the maximum number of moves you can do. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤30), where ai is the i-th element of a. The third line of the test case contains n integers b1,b2,…,bn (1≤bi≤30), where bi is the i-th element of b

// .
// Output

// For each test case, print the answer — the maximum possible sum you can obtain in the array a
// if you can do no more than (i.e. at most) k swaps.

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

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var n, k int
		_, _ = fmt.Fscan(bufStdin, &n, &k)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(bufStdin, &a[i])
		}

		b := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(bufStdin, &b[i])
		}

		sort.Ints(a)
		sort.Ints(b)

		// swap the minimum values of a with the maximum values of b
		// the only special case is that we should not swap if the b value is less than a, at that point we can stop looping
		// since we have reached a point where the b values will not be greater in the future because the slices are sorted
		for i := 0; i < k && b[n-i-1] > a[i]; i++ {
			a[i] = b[n-i-1]
		}

		var sum int
		for i := 0; i < n; i++ {
			sum += a[i]
		}
		_, _ = fmt.Fprintln(bufStdout, sum)
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(r, &n, &k)
		a := make([]int, n)
		b := make([]int, n)
		s := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &a[j])
			s += a[j]
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &b[j])
		}

		sort.Ints(a)
		sort.Ints(b)
		for j := 0; j < k; j++ {
			if a[j] < b[n-j-1] {
				s += b[n-j-1] - a[j]
			}
		}
		fmt.Fprintln(w, s)
	}
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n, k int
		fmt.Fscan(reader, &n, &k)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(b)))
		for i := 0; i < k; i++ {
			a = append(a, b[i])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		ans := 0
		for i := 0; i < n; i++ {
			ans += a[i]
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

type test struct {
	n int
	k int
	a []int
	b []int
}

// https://codeforces.com/problemset/problem/1328/A
// комментарий к решению
// Небольшой и разнообразные входной поток требует
// задействовать fmt.Scan , т.к. с парсингом ioutil.ReadAll
// сложность и количество кода увеличивается
func taskSolution(in []test) string {
	ans := make([]int, len(in))
	for i, ei := range in {
		sort.Ints(ei.a)
		sort.Sort(sort.Reverse(sort.IntSlice(ei.b)))
		for j := 0; j < ei.k && ei.a[j] < ei.b[j]; j += 1 {
			ei.a[j] = ei.b[j]
		}
		for _, aj := range ei.a {
			ans[i] += aj
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	in := make([]test, 0, t)
	for i := 0; i < t; i += 1 {
		var n, k, ai, bi int
		var a, b []int
		if _, err := fmt.Scan(&n, &k); err != nil {
			panic(err)
		}
		for j := 0; j < n; j += 1 {
			if _, err := fmt.Scan(&ai); err != nil {
				panic(err)
			}
			a = append(a, ai)
		}
		for j := 0; j < n; j += 1 {
			if _, err := fmt.Scan(&bi); err != nil {
				panic(err)
			}
			b = append(b, bi)
		}
		in = append(in, test{n: n, k: k, a: a, b: b})
	}

	fmt.Println(taskSolution(in))
}


You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().

The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.

Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".

package main

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

func main() {
    stin := bufio.NewReader(os.Stdin)
    a,_ := stin.ReadBytes('\n')
    b,_ := stin.ReadBytes('\n')

    a = bytes.Trim(a,"\n\r ")
    b = bytes.Trim(b,"\n\r ")

    lp := len(a)
    lq := len(b)

    var ddp []byte = make([]byte, 1000001-lp)
    var ddq []byte = make([]byte, 1000001-lq)

    for i := 0; i < 1000001-lp; i++ {
            ddp[i] = '0'
    }
    for i := 0; i < 1000001-lq; i++ {
            ddq[i] = '0'
    }

    pp := bytes.NewBuffer(ddp)
    pp.Write(a)
    qq := bytes.NewBuffer(ddq)
    qq.Write(b)

    c := bytes.Compare(pp.Bytes(), qq.Bytes())
    if c < 0 {
        fmt.Printf("<")
    } else if c > 0 {
        fmt.Printf(">")
    } else {
        fmt.Printf("=")
    }
}

package main

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

func compare(s1, s2 []string) {
	i := 0
	for ; s1[i] == s2[i]; i++ {
	}

	a, _ := strconv.Atoi(s1[i])
	b, _ := strconv.Atoi(s2[i])
	if a > b {
		fmt.Println(">")
		os.Exit(0)
	} else {
		fmt.Println("<")
		os.Exit(0)
	}
}

func main() {
	var a, b string
	reader := bufio.NewReader(os.Stdin)
	a, _ = reader.ReadString('\n')
	b, _ = reader.ReadString('\n')

	if strings.HasPrefix(a, "0") {
		a = strings.TrimLeft(a, "0")
	}
	if strings.HasPrefix(b, "0") {
		b = strings.TrimLeft(b, "0")
	}

	d := len(a) - len(b)
	if d < 0 {
		fmt.Println("<")
		os.Exit(0)
	} else if d > 0 {
		fmt.Println(">")
		os.Exit(0)
	}

	if a == b {
		fmt.Println("=")
		os.Exit(0)
	}

	s1 := strings.Split(a, "")
	s2 := strings.Split(b, "")
	compare(s1, s2)
}

package main

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

func main() {
	//var a, b string
	reader := bufio.NewReader(os.Stdin)
	a, _ := reader.ReadString('\n')
	b, _ := reader.ReadString('\n')
	var trimmeda string = strings.TrimLeft(a, "0")
	var trimmedb string = strings.TrimLeft(b, "0")
	var lena int = len(trimmeda)
	var lenb int = len(trimmedb)
	if lena > lenb {
		fmt.Println(">")
	} else if lena < lenb {
		fmt.Println("<")
	} else {
		if strings.Compare(trimmeda, trimmedb) == 1 {
			fmt.Println(">")
		} else if strings.Compare(trimmeda, trimmedb) == -1 {
			fmt.Println("<")
		} else {
			fmt.Println("=")
		}
	}
}

package main

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

func removeZeros(a *string) int {
	nonZeroIndex := len(*a)
	for index, char := range *a {
		if (char != '0') {
			nonZeroIndex = index
			break
		}
	}
	return nonZeroIndex
}

func greaterThan(x, y *string, x_index, y_index int) (bool, bool) {
	len_x := len(*x) - x_index
	len_y := len(*y) - y_index
	//print(len_x, len_y)
	if len_x != len_y {
		return false, len_x > len_y
	} else {
		for i:=0; i<len_x; i++ {
			xi := int((*x)[i+x_index])
			yi := int((*y)[i+y_index])
			if xi != yi {
				return false, xi > yi
			}
		}
	}
	return true, true
}

func main() {
	//defer profile.Start(profile.CPUProfile).Stop()
	var a, b string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanln(in, &a)
	fmt.Fscanln(in, &b)

	x := removeZeros(&a)
	y := removeZeros(&b)

	//print(x, " ", y)

	equal, greater := greaterThan(&a, &b, x, y)
	if equal {
		fmt.Println("=")
	} else if greater {
		fmt.Println(">")
	} else {
		fmt.Println("<")
	}
}

package main

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

func removeZeros(a *string) int {
	nonZeroIndex := len(*a)
	for index, char := range *a {
		if (char != '0') {
			nonZeroIndex = index
			break
		}
	}
	return nonZeroIndex
}

func greaterThan(x, y *string, x_index, y_index int) (bool, bool) {
	len_x := len(*x) - x_index
	len_y := len(*y) - y_index
	//print(len_x, len_y)
	if len_x != len_y {
		return false, len_x > len_y
	} else {
		for i:=0; i<len_x; i++ {
			xi := int((*x)[i+x_index])
			yi := int((*y)[i+y_index])
			if xi != yi {
				return false, xi > yi
			}
		}
	}
	return true, true
}

func main() {
	//defer profile.Start(profile.CPUProfile).Stop()
	var a, b string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &a, &b)

	x := removeZeros(&a)
	y := removeZeros(&b)

	//print(x, " ", y)

	equal, greater := greaterThan(&a, &b, x, y)
	if equal {
		fmt.Println("=")
	} else if greater {
		fmt.Println(">")
	} else {
		fmt.Println("<")
	}
}

package main

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

func removeZeros(a string) string {
    nonZeroIndex := len(a)
    for index, char := range a {
        if (char != '0') {
            nonZeroIndex = index
            break
        }
    }

    return a[nonZeroIndex: len(a)]
}

func greaterThan(x, y string) bool {
    if (len(x) != len(y)) {
        return len(x) > len(y)
    } else {
        for index, _ := range x {
            xi := int(x[index])
            yi := int(y[index])
            if xi != yi {
                return xi > yi
            }
        }
    }
    return false
}

func main() {
	var a, b string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &a, &b)

    x := removeZeros(a)
    y := removeZeros(b)

    print(x, " ", y)

    if (x == y) {
        fmt.Println("=")
    } else {
        if (greaterThan(x, y)) {
            fmt.Println(">")
        } else {
            fmt.Println("<")
        }
    }
}

package main

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

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

	num1Trimmed := strings.TrimLeft(num1, "0")
	num2Trimmed := strings.TrimLeft(num2, "0")

	if len(num1Trimmed) > len(num2Trimmed) {
		fmt.Println(">")
	} else if len(num1Trimmed) < len(num2Trimmed) {
		fmt.Println("<")
	} else {
		if strings.Compare(num1Trimmed, num2Trimmed) == 1 {
			fmt.Println(">")
		} else if strings.Compare(num1Trimmed, num2Trimmed) == -1 {
			fmt.Println("<")
		} else {
			fmt.Println("=")
		}
	}}

package main

import (
	// "fmt"
	"bufio"
	"os"
	"strings"
	// "strconv"
	// "sort"
)

//N _
const (
	N = 1e6 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	number1 := strings.TrimLeft(*<-strs, "0")
	number2 := strings.TrimLeft(*<-strs, "0")

	if len(number1) + len(number2) == 0{
		ws.WriteString("=")
		ws.Flush()
		return
	}

	if len(number1) > len(number2){
		ws.WriteString(">")
		ws.Flush()
		return
	}

	if len(number1) < len(number2){
		ws.WriteString("<")
		ws.Flush()
		return
	}

	for i := range number1{
		if number1[i] > number2[i]{
			ws.WriteString(">")
			ws.Flush()
			return
		} else if number1[i] < number2[i] {
			ws.WriteString("<")
			ws.Flush()
			return
		}
	}

	ws.WriteString("=")
	ws.Flush()
	return
}

package main

import (
	// "fmt"
	"bufio"
	"os"
	"strings"
	// "strconv"
	// "sort"
)

//N _
const (
	N = 1e6 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	number1 := strings.TrimLeft(*<-strs, "0")
	number2 := strings.TrimLeft(*<-strs, "0")

	if len(number1) + len(number2) == 0{
		ws.WriteString("=")
	} else if len(number1) > len(number2){
		ws.WriteString(">")
	} else if len(number1) < len(number2){
		ws.WriteString("<")
	} else {
		if number1 > number2{
			ws.WriteString(">")
		} else if number1 < number2{
			ws.WriteString("<")
		} else{
			ws.WriteString("=")
		}
	}
	ws.Flush()
	return
}

package main

import (
	"fmt"
)

func main() {
	//fmt.Println("What is your favorite color?")
	var a, b string
	fmt.Scanf("%s%s", &a, &b)
	var firstOfA, firstOfB int = 0, 0
	for firstOfA < len(a) && a[firstOfA] == '0' {
		firstOfA = firstOfA + 1
	}
	var AIsZero, BIsZero bool = false, false
	if firstOfA == len(a) {
		AIsZero = true
	}
	for firstOfB < len(b) && b[firstOfB] == '0' {
		firstOfB = firstOfB + 1
	}
	if firstOfB == len(b) {
		BIsZero = true
	}
	if AIsZero && BIsZero {
		fmt.Println("=")
		return
	}
	var ALeftLen int = len(a) - firstOfA
	var BLeftLen int = len(b) - firstOfB
	if ALeftLen > BLeftLen {
		fmt.Println(">")
		return
	}
	if BLeftLen > ALeftLen {
		fmt.Println("<")
		return
	}
	for firstOfA < len(a) && firstOfB < len(b) {
		if a[firstOfA] > b[firstOfB] {
			fmt.Println(">")
			return
		} else if a[firstOfA] < b[firstOfB] {
			fmt.Println("<")
			return
		} else {
			firstOfA = firstOfA + 1
			firstOfB = firstOfB + 1
		}
	}
	fmt.Println("=")
}

package main

import (
    "fmt"
)

func removeZeros(a string) string {
    var nonZeroIndex int
    for index, char := range a {
        if (char != '0') {
            nonZeroIndex = index
            break
        }
    }

    return a[nonZeroIndex: len(a)]
}

func greaterThan(x, y string) bool {
    if (len(x) != len(y)) {
        return len(x) > len(y)
    } else {
        for index, _ := range x {
            xi := int(x[index])
            yi := int(y[index])
            if xi != yi {
                return xi > yi
            }
        }
    }
    return false
}

func main() {
    var a, b string
    fmt.Scanln(&a)
    fmt.Scanln(&b)

    x := removeZeros(a)
    y := removeZeros(b)

    if (x == y) {
        fmt.Println("=")
    } else {
        if (greaterThan(x, y)) {
            fmt.Println(">")
        } else {
            fmt.Println("<")
        }
    }
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var num1, num2 string
	_, err := fmt.Scanf("%s\n%s\n", &num1, &num2)
	if err != nil {
		fmt.Println(err)
	}

	num1Trimmed := strings.TrimLeft(num1, "0")
	num2Trimmed := strings.TrimLeft(num2, "0")

	if strings.Compare(num1Trimmed, num2Trimmed) == 1 {
		fmt.Println(">")
	} else if strings.Compare(num1Trimmed, num2Trimmed) == -1 {
		fmt.Println("<")
	} else {
		fmt.Println("=")
	}

}

package main

import "fmt"

func main() {
	var num1, num2 int
	_, err := fmt.Scanf("%d\n%d\n", &num1, &num2)
	if err != nil {
		fmt.Println(err)
	}

	if num1 > num2 {
		fmt.Println(">")
	} else if num1 < num2 {
		fmt.Println("<")
	} else {
		fmt.Println("=")
	}

}

package main

import (
	// "fmt"
	"bufio"
	"os"
	"strings"
	// "strconv"
	// "sort"
)

//N _
const (
	N = 1e6 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	number1 := strings.TrimLeft(*<-strs, "0")
	number2 := strings.TrimLeft(*<-strs, "0")

	if len(number1) + len(number2) == 0{
		ws.WriteString("=")
	} else if len(number1) > len(number2){
		ws.WriteString(">")
	} else if len(number1) < len(number2){
		ws.WriteString("<")
	} else {
		if number1 > number2{
			ws.WriteString(">")
		} else if len(number1) < len(number2){
			ws.WriteString("<")
		} else{
			ws.WriteString("=")
		}
	}
	ws.Flush()
	return
}


This is the easier version of the problem. In this version, $$$1 \le n \le 10^5$$$ and $$$0 \le a_i \le 1$$$. You can hack this problem only if you solve and lock both problems.Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare $$$n$$$ boxes of chocolate, numbered from $$$1$$$ to $$$n$$$. Initially, the $$$i$$$-th box contains $$$a_i$$$ chocolate pieces.Since Bob is a typical nice guy, he will not send Alice $$$n$$$ empty boxes. In other words, at least one of $$$a_1, a_2, \ldots, a_n$$$ is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer $$$k > 1$$$ such that the number of pieces in each box is divisible by $$$k$$$. Note that Alice won't mind if there exists some empty boxes. Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box $$$i$$$ and put it into either box $$$i-1$$$ or box $$$i+1$$$ (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of chocolate boxes. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$) — the number of chocolate pieces in the $$$i$$$-th box. It is guaranteed that at least one of $$$a_1, a_2, \ldots, a_n$$$ is positive.

If there is no way for Charlie to make Alice happy, print $$$-1$$$. Otherwise, print a single integer $$$x$$$ — the minimum number of seconds for Charlie to help Bob make Alice happy.

package main

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

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

	var n int
	fmt.Fscan(in, &n)

	as := make([]int64, n)
	var cnt int64 = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
		cnt += as[i]
	}

	divs := make([]int64, 0)
	for k := int64(2); k <= cnt; k++ {
		if cnt % k == 0 {
			divs = append(divs, k)
			for cnt % k == 0 {
				cnt /= k
			}
		}
	}

	if len(divs) == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}

	var minAns int64 = -1
	for _, k := range divs {
		start := 0
		var part, ans int64
		as_cpy := append(as[:0:0], as...)
		for i := range as_cpy {
			as_cpy[i] = as_cpy[i] % k
		}
		for end := 0; end < n; end++ {
			part += as_cpy[end]
			if part >= k {
				tmp := part - k
				as_cpy[end] -= tmp

				ans += doAThing(as_cpy[start:end+1])
				part = 0
				start = end+1

				as_cpy[end] = tmp
			}
		}
		if minAns == -1 || ans < minAns {
			minAns = ans
		}
	}
	fmt.Fprintln(out, minAns)
}

func doAThing(arr []int64) int64 {
	if len(arr) == 1 {
		return 0
	}
	if arr[0] < arr[len(arr)-1] {
		arr[1] += arr[0]
		return arr[0] + doAThing(arr[1:])
	} else {
		arr[len(arr)-2] += arr[len(arr)-1]
		return arr[len(arr)-1] + doAThing(arr[:len(arr)-1])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1254B2(_r io.Reader, out io.Writer) {
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	n := r()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + int64(r())
	}
	x := sum[n]
	if x < 2 {
		Fprint(out, -1)
		return
	}
	a := []int64{}
	for i := int64(2); i*i <= x; i++ {
		k := 0
		for ; x%i == 0; x /= i {
			k++
		}
		if k > 0 {
			a = append(a, i)
		}
	}
	if x > 1 {
		a = append(a, x)
	}
	ans := int64(1e18)
	for _, p := range a {
		s := int64(0)
		for _, v := range sum {
			s += min(v%p, p-v%p)
		}
		ans = min(ans, s)
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n int
	fmt.Fscan(in, &n)

	as := make([]int, n)
	cnt := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
		if as[i] == 1 {
			cnt++
		}
	}

	var k int
	found := false
	for k = 2; k <= cnt; k++ {
		if cnt % k == 0 {
			found = true
			break
		}
	}

	if !found {
		fmt.Println(-1)
		os.Exit(0)
	}

	ans := 0
	start := 0
	part := 0
	for end := 0; end < n; end++ {
		if as[end] == 1 {
			part++
		}
		if part == k {
			ans += doAThing(as[start:end+1])
			part = 0
			start = end+1
		}
	}
	fmt.Fprintln(out, ans)
}

func doAThing(arr []int) int {
	if len(arr) == 1 {
		return 0
	}
	if arr[0] < arr[len(arr)-1] {
		arr[1] += arr[0]
		return arr[0] + doAThing(arr[1:])
	} else {
		arr[len(arr)-2] += arr[len(arr)-1]
		return arr[len(arr)-1] + doAThing(arr[:len(arr)-1])
	}
}

package main

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

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

	var n int
	fmt.Fscan(in, &n)

	as := make([]int, n)
	cnt := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
		cnt += as[i]
	}

	divs := make([]int, 0)
	for k := 2; k <= cnt; k++ {
		if cnt % k == 0 {
			divs = append(divs, k)
			for cnt % k == 0 {
				cnt /= k
			}
		}
	}

	if len(divs) == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}

	minAns := -1
	for _, k := range divs {
		ans := 0
		start := 0
		part := 0
		as_cpy := append(as[:0:0], as...)
		for i := range as_cpy {
			as_cpy[i] = as_cpy[i] % k
		}
		for end := 0; end < n; end++ {
			part += as_cpy[end]
			if part >= k {
				tmp := part - k
				as_cpy[end] -= tmp

				ans += doAThing(as_cpy[start:end+1])
				part = 0
				start = end+1

				as_cpy[end] = tmp
			}
		}
		if minAns == -1 || ans < minAns {
			minAns = ans
		}
	}
	fmt.Fprintln(out, minAns)
}

func doAThing(arr []int) int {
	if len(arr) == 1 {
		return 0
	}
	if arr[0] < arr[len(arr)-1] {
		arr[1] += arr[0]
		return arr[0] + doAThing(arr[1:])
	} else {
		arr[len(arr)-2] += arr[len(arr)-1]
		return arr[len(arr)-1] + doAThing(arr[:len(arr)-1])
	}
}


It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!There are exactly n distinct countries in the world and the i-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed 100 000.

Print a single number without leading zeroes — the product of the number of tanks presented by each country.

NoteIn sample 1 numbers 10 and 1 are beautiful, number 5 is not not.In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.In sample 3 number 3 is not beautiful, all others are beautiful.

package main

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

func main() {
    stin := bufio.NewReader(os.Stdin)
    ns,_ := stin.ReadBytes('\n')
    n,_ := strconv.Atoi(string(bytes.Trim(ns,"\n\r ")))

    resultStart := "1"
    zeroCount := int64(0)
    var tmp []byte
    for i := 0; i < n-1; i++ {
        tmp,_ = stin.ReadBytes(' ')
        ss := string(bytes.Trim(tmp," "))
        if ss == "0" {
            fmt.Printf("0")
            return
        }
        beautiful := 1
        if ss[0] != '1' {
            beautiful = 0
        }
        q := len(ss)
        if beautiful == 1 {
            for k := 1; k < q; k++ {
                if ss[k] != '0' {
                    beautiful = 0
                    break
                }
            }
        }
        if beautiful == 0 {
            resultStart = ss
        } else {
            zeroCount += int64(q-1)
        }
    }
    tmp,_ = stin.ReadBytes('\n')
    ss := string(bytes.Trim(tmp,"\n\r"))

        if ss == "0" {
            fmt.Printf("0")
            return
        }
        beautiful := 1
        if ss[0] != '1' {
            beautiful = 0
        }
        q := len(ss)
        if beautiful == 1 {
            for k := 1; k < q; k++ {
                if ss[k] != '0' {
                    beautiful = 0
                    break
                }
            }
        }
        if beautiful == 0 {
            resultStart = ss
        } else {
            zeroCount += int64(q-1)
        }

    fmt.Printf("%s", resultStart)
    if zeroCount%2 == int64(1) {
        fmt.Printf("0")
        zeroCount -= 1
    }
    for i := int64(0); i < zeroCount/2; i++ {
        fmt.Printf("00")
    }
}

package main

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

func processString(ss *string, resultStart *string, zeroCount *int64) {
    beautiful := 1
    if (*ss)[0] != '1' {
        beautiful = 0
    }
    q := len(*ss)
    if beautiful == 1 {
        for k := 1; k < q; k++ {
            if (*ss)[k] != '0' {
                beautiful = 0
                break
            }
        }
    }
    if beautiful == 0 {
        *resultStart = *ss
    } else {
        *zeroCount += int64(q-1)
    }
}

func main() {
    stin := bufio.NewReader(os.Stdin)
    ns,_ := stin.ReadBytes('\n')
    n,_ := strconv.Atoi(string(bytes.Trim(ns,"\n\r ")))

    resultStart := "1"
    zeroCount := int64(0)
    var tmp []byte
    for i := 0; i < n-1; i++ {
        tmp,_ = stin.ReadBytes(' ')
        ss := string(bytes.Trim(tmp," "))
        if ss == "0" {
            fmt.Printf("0")
            return
        }
        processString(&ss, &resultStart, &zeroCount)
    }
    tmp,_ = stin.ReadBytes('\n')
    ss := string(bytes.Trim(tmp,"\n\r"))
    if ss == "0" {
        fmt.Printf("0")
        return
    }
    processString(&ss, &resultStart, &zeroCount)
    fmt.Printf("%s", resultStart)
    if zeroCount%2 == int64(1) {
        fmt.Printf("0")
        zeroCount -= 1
    }
    for i := int64(0); i < zeroCount/2; i++ {
        fmt.Printf("00")
    }
}