As the boat drifts down the river, a wood full of blossoms shows up on the riverfront."I've been here once," Mino exclaims with delight, "it's breathtakingly amazing.""What is it like?""Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.The wood can be represented by a rectangular grid of $$$n$$$ rows and $$$m$$$ columns. In each cell of the grid, there is exactly one type of flowers.According to Mino, the numbers of connected components formed by each kind of flowers are $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.You are to help Kanno depict such a grid of flowers, with $$$n$$$ and $$$m$$$ arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.Note that you can choose arbitrary $$$n$$$ and $$$m$$$ under the constraints below, they are not given in the input.

The first and only line of input contains four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a, b, c, d \leq 100$$$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In the first line, output two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and the number of columns in the grid respectively. Then output $$$n$$$ lines each consisting of $$$m$$$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively. In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD

NoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF989C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		v int
		c byte
	}

	a := make([]pair, 4)
	for i := byte(0); i < 4; i++ {
		Fscan(in, &a[i].v)
		a[i].c = 'A' + i
	}
	sort.Slice(a, func(i, j int) bool { return a[i].v < a[j].v })
	Fprintln(out, 50, 50)
	ans := [50][50]byte{}
	for i := 0; i < 50; i++ {
		for j := 0; j < 50; j++ {
			ans[i][j] = a[0].c
		}
	}
	for c, p := 0, a[3]; c < p.v; c++ {
		i, j := c/10*5+2, c%10*5+2
		ans[i-1][j] = p.c
		ans[i][j-1] = p.c
		if c+1 < a[0].v {
			ans[i-1][j-1] = p.c
		} else {
			ans[i][j] = p.c
		}
		if c < a[1].v {
			ans[i][j+1] = a[1].c
		}
		if c < a[2].v {
			ans[i+1][j] = a[2].c
		}
	}
	for _, row := range ans {
		Fprintf(out, "%s\n", row)
	}
}

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

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	flowers[0]--
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i += 2 {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for i := 1; i < size-1; i++ {
		for j := 1; j < size-1; j++ {
			if flowers[counter] == 0 {
				counter--
			}

			if counter < 0 {
				break
			}

			if picture[i-1][j] != counter && picture[i+1][j] != counter &&
				picture[i][j-1] != counter && picture[i][j+1] != counter {
				picture[i][j] = counter
				flowers[counter]--
			}

		}
		if counter < 0 {
			break
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'a' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i++ {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	flowers[0]--
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i++ {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}


Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.Limak will repeat the following operation till everything is destroyed.Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

The first line contains single integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.

Print the number of operations needed to destroy all towers.

NoteThe picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.    After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
    // "sort"
    // "strings"
    // "reflect"
)

type Reader struct{
    scanner *bufio.Scanner
}

func (read *Reader) init(){
    if read.scanner == nil {
        read.scanner = bufio.NewScanner(os.Stdin)
    }
}

func (read *Reader) setWord(){
    read.scanner.Split(bufio.ScanWords)
}

func (read *Reader) setByte(){
    read.scanner.Split(bufio.ScanBytes)
}

func (read *Reader) setLine(){
    read.scanner.Split(bufio.ScanLines)
}

func (read *Reader) read() string{
    read.scanner.Scan()
    return read.scanner.Text()
}

func (read *Reader) readInt() int{
    res,_ := strconv.Atoi(read.read())
    return res
}

func (read *Reader) readByte(length int) string{
    bt := make([]byte, length+2)
    for i := 0; i < length; i++ {
        bt[i] = read.read()[0]
    }

    return string(bt)
}

var read Reader

var writer *bufio.Writer

var h [100005]int

func isPos(lmt, n int) bool{

    leftInd, rightInd := 1, n

    cost := 0
    pre := 0
    for i := 1; i <= n; i++{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = h[i]
                // fmt.Println("test", lmt-h[i]-pre, lmt-h[i])
                pre = 0
                leftInd = i+1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        leftInd++
    }

    cost = 0
    pre = 0
    for i := n; i >= 1; i--{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = h[i]
                pre = 0
                rightInd = i-1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        rightInd--
        // fmt.Println("bal", i)
    }
    // fmt.Println(lmt, leftInd, rightInd)

    if(leftInd > rightInd){
        return true
    } else{
        return false
    }

}

func main(){
    read.init()
    read.setWord()

    n := read.readInt()
    for i := 1; i <= n; i++{
        h[i] = read.readInt()
    }

    var l, r int = 0, n+10

    for ; l < r; {
        m := ((l+r)/2)
        if isPos(m, n){
            r = m
        } else{
            l = m+1
        }
    }
    fmt.Println(l)

}

/*
28
415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901

*/

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
    // "sort"
    // "strings"
    // "reflect"
)

type Reader struct{
    scanner *bufio.Scanner
}

func (read *Reader) init(){
    if read.scanner == nil {
        read.scanner = bufio.NewScanner(os.Stdin)
    }
}

func (read *Reader) setWord(){
    read.scanner.Split(bufio.ScanWords)
}

func (read *Reader) setByte(){
    read.scanner.Split(bufio.ScanBytes)
}

func (read *Reader) setLine(){
    read.scanner.Split(bufio.ScanLines)
}

func (read *Reader) read() string{
    read.scanner.Scan()
    return read.scanner.Text()
}

func (read *Reader) readInt() int{
    res,_ := strconv.Atoi(read.read())
    return res
}

func (read *Reader) readByte(length int) string{
    bt := make([]byte, length+2)
    for i := 0; i < length; i++ {
        bt[i] = read.read()[0]
    }

    return string(bt)
}

var read Reader

var writer *bufio.Writer

var h [100005]int

func isPos(lmt, n int) bool{

    leftInd, rightInd := 1, n

    cost := 0
    pre := 0
    for i := 1; i <= n; i++{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = lmt - h[i] - pre
                pre = 0
                leftInd = i+1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        leftInd++
    }

    cost = 0
    pre++
    for i := n; i >= n; i--{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = lmt - h[i] - pre
                pre = 0
                rightInd = i-1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        rightInd--
    }
    // fmt.Println(lmt, leftInd, rightInd)

    if(leftInd > rightInd){
        return true
    } else{
        return false
    }

}

func main(){
    read.init()
    read.setWord()

    n := read.readInt()
    for i := 1; i <= n; i++{
        h[i] = read.readInt()
    }

    var l, r int = 0, n+10

    for ; l < r; {
        m := ((l+r)/2)
        if isPos(m, n){
            r = m
        } else{
            l = m+1
        }
    }
    fmt.Println(l)

}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
    // "sort"
    // "strings"
    // "reflect"
)

type Reader struct{
    scanner *bufio.Scanner
}

func (read *Reader) init(){
    if read.scanner == nil {
        read.scanner = bufio.NewScanner(os.Stdin)
    }
}

func (read *Reader) setWord(){
    read.scanner.Split(bufio.ScanWords)
}

func (read *Reader) setByte(){
    read.scanner.Split(bufio.ScanBytes)
}

func (read *Reader) setLine(){
    read.scanner.Split(bufio.ScanLines)
}

func (read *Reader) read() string{
    read.scanner.Scan()
    return read.scanner.Text()
}

func (read *Reader) readInt() int{
    res,_ := strconv.Atoi(read.read())
    return res
}

func (read *Reader) readByte(length int) string{
    bt := make([]byte, length+2)
    for i := 0; i < length; i++ {
        bt[i] = read.read()[0]
    }

    return string(bt)
}

var read Reader

var writer *bufio.Writer

var h [100005]int

func isPos(lmt, n int) bool{

    leftInd, rightInd := 1, n

    cost := 0
    pre := 0
    for i := 1; i <= n; i++{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = lmt - h[i] - pre
                pre = 0
                leftInd = i+1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        leftInd++
    }

    cost = 0
    pre = 0
    for i := n; i >= 1; i--{
        if cost >= lmt{
            if h[i]+pre <= lmt{
                cost = lmt - h[i] - pre
                pre = 0
                rightInd = i-1
            } else{
                pre++
            }
            continue
        }
        if cost > h[i]-1 {
            cost = h[i]-1
        }
        cost++
        rightInd--
        // fmt.Println("bal", i)
    }
    // fmt.Println(lmt, leftInd, rightInd)

    if(leftInd > rightInd){
        return true
    } else{
        return false
    }

}

func main(){
    read.init()
    read.setWord()

    n := read.readInt()
    for i := 1; i <= n; i++{
        h[i] = read.readInt()
    }

    var l, r int = 0, n+10

    for ; l < r; {
        m := ((l+r)/2)
        if isPos(m, n){
            r = m
        } else{
            l = m+1
        }
    }
    fmt.Println(l)

}


Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point $$$T$$$, which coordinates to be found out.Bob travelled around the world and collected clues of the treasure location at $$$n$$$ obelisks. These clues were in an ancient language, and he has only decrypted them at home. Since he does not know which clue belongs to which obelisk, finding the treasure might pose a challenge. Can you help him?As everyone knows, the world is a two-dimensional plane. The $$$i$$$-th obelisk is at integer coordinates $$$(x_i, y_i)$$$. The $$$j$$$-th clue consists of $$$2$$$ integers $$$(a_j, b_j)$$$ and belongs to the obelisk $$$p_j$$$, where $$$p$$$ is some (unknown) permutation on $$$n$$$ elements. It means that the treasure is located at $$$T=(x_{p_j} + a_j, y_{p_j} + b_j)$$$. This point $$$T$$$ is the same for all clues.In other words, each clue belongs to exactly one of the obelisks, and each obelisk has exactly one clue that belongs to it. A clue represents the vector from the obelisk to the treasure. The clues must be distributed among the obelisks in such a way that they all point to the same position of the treasure.Your task is to find the coordinates of the treasure. If there are multiple solutions, you may print any of them.Note that you don't need to find the permutation. Permutations are used only in order to explain the problem.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of obelisks, that is also equal to the number of clues. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^6 \leq x_i, y_i \leq 10^6$$$) — the coordinates of the $$$i$$$-th obelisk. All coordinates are distinct, that is $$$x_i \neq x_j$$$ or $$$y_i \neq y_j$$$ will be satisfied for every $$$(i, j)$$$ such that $$$i \neq j$$$.  Each of the next $$$n$$$ lines contains two integers $$$a_i$$$, $$$b_i$$$ ($$$-2 \cdot 10^6 \leq a_i, b_i \leq 2 \cdot 10^6$$$) — the direction of the $$$i$$$-th clue. All coordinates are distinct, that is $$$a_i \neq a_j$$$ or $$$b_i \neq b_j$$$ will be satisfied for every $$$(i, j)$$$ such that $$$i \neq j$$$.  It is guaranteed that there exists a permutation $$$p$$$, such that for all $$$i,j$$$ it holds $$$\left(x_{p_i} + a_i, y_{p_i} + b_i\right) = \left(x_{p_j} + a_j, y_{p_j} + b_j\right)$$$.

Output a single line containing two integers $$$T_x, T_y$$$ — the coordinates of the treasure. If there are multiple answers, you may print any of them.

NoteAs $$$n = 2$$$, we can consider all permutations on two elements. If $$$p = [1, 2]$$$, then the obelisk $$$(2, 5)$$$ holds the clue $$$(7, -2)$$$, which means that the treasure is hidden at $$$(9, 3)$$$. The second obelisk $$$(-6, 4)$$$ would give the clue $$$(-1,-3)$$$ and the treasure at $$$(-7, 1)$$$. However, both obelisks must give the same location, hence this is clearly not the correct permutation.If the hidden permutation is $$$[2, 1]$$$, then the first clue belongs to the second obelisk and the second clue belongs to the first obelisk. Hence $$$(-6, 4) + (7, -2) = (2,5) + (-1,-3) = (1, 2)$$$, so $$$T = (1,2)$$$ is the location of the treasure.  In the second sample, the hidden permutation is $$$[2, 3, 4, 1]$$$.

package main

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

type pair struct {
	x, y int
}

func NewPair(a, b int) pair {
	return pair{x: a, y: b}
}

func Add(a, b pair) pair {
	return pair{x: a.x + b.x, y: a.y + b.y}
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, x, y int
	fmt.Fscan(stdin, &n)

	var obe = make([]pair, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x, &y)
		obe[i].x = x
		obe[i].y = y
	}
	var clue = make([]pair, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x, &y)
		clue[i].x = x
		clue[i].y = y
	}
	sort.Slice(clue, func(i, j int) bool {
		if clue[i].x == clue[j].x {
			return clue[i].y < clue[j].y
		}
		return clue[i].x < clue[j].x
	})

	Search := func(item pair) bool {
		var lo, hi = 0, n - 1
		for lo <= hi {
			var mid = lo + (hi-lo)/2
			if item == clue[mid] {
				return true
			}
			if (item.x == clue[mid].x && item.y < clue[mid].y) || item.x < clue[mid].x {
				hi = mid - 1
			} else {
				lo = mid + 1
			}
		}
		return false
	}

	var treasure = obe[0]
	for i := 0; i < n; i++ {
		// If clue[i] belong to obelisk[0]
		treasure = Add(obe[0], clue[i])
		var found = true
		for j := 1; j < n; j++ {
			var tmp = NewPair(treasure.x-obe[j].x, treasure.y-obe[j].y)
			if !Search(tmp) {
				found = false
				break
			}
		}
		if found {
			break
		}
	}

	fmt.Println(treasure.x, treasure.y)
}

package main

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

type coord struct {
	x float64
	y float64
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	if n == 0 {
		return
	}
	ans := coord{}
	fn := float64(n)
	for i := 0; i < n*2; i++ {
		scanner.Scan()
		f := strings.Fields(scanner.Text())
		x, _ := strconv.ParseFloat(f[0], 64)
		y, _ := strconv.ParseFloat(f[1], 64)
		ans.x += x / fn
		ans.y += y / fn
	}
	xx, _ := strconv.Atoi(fmt.Sprintf("%.0f", ans.x))
	yy, _ := strconv.Atoi(fmt.Sprintf("%.0f", ans.y))
	fmt.Printf("%d %d\n", xx, yy)
}

package main

import (
	"fmt"
)

type pii struct{
	first int
	second int
}

func _plus ( a pii, b pii ) pii{
	a.first += b.first
	a.second += b.second
	return a
}

func main() {
	var n, x, y int
	var data, lib [1000]pii
	pt := make ( map[pii]int )
	fmt.Scanf ( "%d\n", &n )
	for i := 0 ; i < n ; i++ {
		fmt.Scanf ( "%d %d\n", &x, &y )
		data[i] = pii { x, y}
	}
	for i := 0 ; i < n ; i++ {
		fmt.Scanf ( "%d %d\n", &x, &y )
		lib[i] = pii { x, y }
	}

	for i := 0 ; i < n ; i++ {
		for j := 0 ; j < n ; j++ {
			pt[_plus ( data[i], lib[j] )]++
		}
	}

	for i, j := range pt {
		if ( j == n ){
			fmt.Println ( i.first, i.second )
			break;
		}
	}
        fmt.Println()
}

package main

import (
	"fmt"
)

type input struct {
	n int
	x []int
	y []int
	a []int
	b []int
}

func main() {
	input := &input{}
	fmt.Scan(&input.n)

	input.x = make([]int, input.n)
	input.y = make([]int, input.n)
	input.a = make([]int, input.n)
	input.b = make([]int, input.n)

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

	for i := 0; i < input.n; i++ {
		tx, ty := input.x[0]+input.a[i], input.y[0]+input.b[i]
		if test(input, tx, ty) {
			fmt.Printf("%v %v\n", tx, ty)
			return
		}
	}

	fmt.Println("not found")
}

func test(input *input, tx, ty int) bool {
	for i := 0; i < input.n; i++ {
		isFound := false
		for j := 0; j < input.n; j++ {
			if input.x[i]+input.a[j] == tx && input.y[i]+input.b[j] == ty {
				isFound = true
				break
			}
		}
		if !isFound {
			return false
		}
	}
	return true
}

package main

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

type coord struct {
	x int
	y int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	if n == 0 {
		return
	}
	ans := coord{}
	for i := 0; i < n*2; i++ {
		scanner.Scan()
		f := strings.Fields(scanner.Text())
		x, _ := strconv.Atoi(f[0])
		y, _ := strconv.Atoi(f[1])
		ans.x += x
		ans.y += y
	}
	fmt.Println(ans.x/n, ans.y/n)
}

package main

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

type coord struct {
	x float64
	y float64
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	if n == 0 {
		return
	}
	ans := coord{}
	fn := float64(n)
	for i := 0; i < n*2; i++ {
		scanner.Scan()
		f := strings.Fields(scanner.Text())
		x, _ := strconv.ParseFloat(f[0], 64)
		y, _ := strconv.ParseFloat(f[1], 64)
		ans.x += x / fn
		ans.y += y / fn
	}
	fmt.Printf("%.0f %.0f\n", ans.x, ans.y)
}

package main

import (
	"fmt"
)

type pii struct{
	first int
	second int
}

func _plus ( a pii, b pii ) pii{
	a.first += b.first
	a.second += b.second
	return a
}

func main() {
	var n, x, y int
	var data, lib [1000]pii
	pt := make ( map[pii]int )
	fmt.Scanf ( "%d", &n )
	for i := 0 ; i < n ; i++ {
		fmt.Scanf ( "%d %d", &x, &y )
		data[i] = pii { x, y}
	}
	for i := 0 ; i < n ; i++ {
		fmt.Scanf ( "%d %d\n", &x, &y )
		lib[i] = pii { x, y }
	}

	for i := 0 ; i < n ; i++ {
		for j := 0 ; j < n ; j++ {
			pt[_plus ( data[i], lib[j] )]++
		}
	}

	for i, j := range pt {
		if ( j == n ){
			fmt.Println ( i.first, i.second )
			break;
		}
	}
}


Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.

NoteNote that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, k, d int64
	fmt.Fscanf(r, "%d %d %d\n", &n, &k, &d)

	if !can(n, k, d) {
		fmt.Println("-1")
		return
	}

	sol := makeSol(n, k, d)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < len(sol); i++ {
		for j := 0; j < len(sol[i]); j++ {
			fmt.Fprintf(w, "%d ", sol[i][j])
		}
		fmt.Fprintf(w, "\n")
	}
}

func can(n, k, d int64) bool {
	tot := int64(1)
	for i := int64(1); i <= d; i++ {
		if tot >= n {
			break
		}
		tot *= k
	}
	return tot >= n
}

func makeSol(n, k, d int64) [][]int64 {
	tab := make([][]int64, d)
	for i := int64(0); i < d; i++ {
		tab[i] = make([]int64, n)
	}

	for i := int64(0); i < n; i++ {
		x := convert(i, k, d)
		for j := int64(0); j < d; j++ {
			tab[j][i] = x[j] + 1
		}
	}

	return tab
}

func convert(num, b, sz int64) []int64 {
	ret := make([]int64, 0)
	for num > 0 {
		ret = append(ret, num%b)
		num /= b
	}
	for int64(len(ret)) < sz {
		ret = append(ret, 0)
	}
	return ret
}

package main

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

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

	var n, b, d int
	Fscan(in, &n, &b, &d)
	ans := [][]int{}
	a := make([]int, d)
	var f func(int)
	f = func(p int) {
		if p == d {
			ans = append(ans, append([]int(nil), a...))
			return
		}
		for a[p] = 1; a[p] <= b && len(ans) < n; a[p]++ {
			f(p + 1)
		}
	}
	f(0)
	if len(ans) < n {
		Fprint(out, -1)
		return
	}
	for j := 0; j < d; j++ {
		for _, row := range ans {
			Fprint(out, row[j], " ")
		}
		Fprintln(out)
	}
}

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

package main

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

func is_greater(k, d, n int) bool {
	var res int64 = 1
	for i := 0; i < d; i++ {
		res = res * int64(k)
		if res >= int64(n) {
			return true
		}
	}
	return false
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var n, k, d int
	fmt.Fscan(reader, &n, &k, &d)
	if is_greater(k, d, n) {
		var res [][]int = make([][]int, d)
		for i := 0; i < d; i++ {
			res[i] = make([]int, n)
		}
		for i := 0; i < n; i++ {
			var value int = i
			for j := 0; j < d; j++ {
				res[j][i] = value%k + 1
				value /= k
			}
		}
		for i := 0; i < d; i++ {
			for j := 0; j < n; j++ {
				if j+1 == n {
					fmt.Fprintf(writer, "%d\n", res[i][j])
				} else {
					fmt.Fprintf(writer, "%d ", res[i][j])
				}
			}
		}
		writer.Flush()
	} else {
		fmt.Println(-1)
	}
}

package main

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

func is_greater(k, d, n int) bool {
	var res int64 = 1
	for i := 0; i < d; i++ {
		res = res * int64(k)
		if res >= int64(n) {
			return true
		}
	}
	return false
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var n, k, d int
	fmt.Fscan(reader, &n, &k, &d)
	if is_greater(k, d, n) {
		var res [][]int = make([][]int, d)
		for i := 0; i < d; i++ {
			res[i] = make([]int, n)
		}
		for i := 0; i < n; i++ {
			var value int = i
			for j := 0; j < d; j++ {
				res[j][i] = value%k + 1
				value /= k
			}
		}
		for i := 0; i < d; i++ {
			for j := 0; j < n; j++ {
				if j+1 == n {
					fmt.Fprintf(writer, "%d\n", res[i][j])
				} else {
					fmt.Fprintf(writer, "%d ", res[i][j])
				}
			}
		}
	} else {
		fmt.Println(-1)
	}
}

package main

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

func is_greater(k, d, n int) bool {
	var res int64 = 1
	for i := 0; i < d; i++ {
		res = res * int64(k)
		if res > int64(n) {
			return true
		}
	}
	return false
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, k, d int
	fmt.Fscan(reader, &n, &k, &d)
	if is_greater(k, d, n) {
		var res [][]int = make([][]int, d)
		for i := 0; i < d; i++ {
			res[i] = make([]int, n)
		}
		for i := 0; i < n; i++ {
			var value int = i
			for j := 0; j < d; j++ {
				res[j][i] = value%k + 1
				value /= k
			}
		}
		for i := 0; i < d; i++ {
			for j := 0; j < n; j++ {
				if j+1 == n {
					fmt.Printf("%d\n", res[i][j])
				} else {
					fmt.Printf("%d ", res[i][j])
				}
			}
		}
	} else {
		fmt.Println(-1)
	}
}


Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains $$$26$$$ buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string $$$s$$$ appeared on the screen. When Polycarp presses a button with character $$$c$$$, one of the following events happened:  if the button was working correctly, a character $$$c$$$ appeared at the end of the string Polycarp was typing;  if the button was malfunctioning, two characters $$$c$$$ appeared at the end of the string. For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a $$$\rightarrow$$$ abb $$$\rightarrow$$$ abba $$$\rightarrow$$$ abbac $$$\rightarrow$$$ abbaca $$$\rightarrow$$$ abbacabb $$$\rightarrow$$$ abbacabba.You are given a string $$$s$$$ which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow. Each test case is represented by one line containing a string $$$s$$$ consisting of no less than $$$1$$$ and no more than $$$500$$$ lowercase Latin letters.

For each test case, print one line containing a string $$$res$$$. The string $$$res$$$ should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, $$$res$$$ should be empty.

package main

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

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		uselessCounter := 0
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				uselessCounter++
				continue
			} else if uselessCounter%2 == 1 {
				if !strings.ContainsRune(string(res), rune(s[i-1])) {
					res = append(res, rune(s[i-1]))
				}
				uselessCounter = 0
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				if !strings.ContainsRune(string(res), rune(s[i])) {
					res = append(res, rune(s[i]))
				}
				lastIndex = '-'
			} else {
				lastIndex = s[i]
				i++
			}
		}
		if uselessCounter%2 == 1 {
			if !strings.ContainsRune(string(res), rune(s[len(s)-1])) {
				res = append(res, rune(s[len(s)-1]))
			}
		}
		sort.Sort(res)
		fmt.Println(string(res))
	}
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		solveOne(read())
	}
}

func solveOne(s string) {
	ans := make([]bool, 26)
	if s[len(s)-1] == 'z' {
		s = s + "yy"
	} else {
		s = s + "zz"
	}
	c := s[0]
	cnt := 1
	for i := 1; i < len(s); i++ {
		if s[i] == c {
			cnt++
		} else {
			if cnt%2 == 1 {
				ans[c-'a'] = true
			}
			c = s[i]
			cnt = 1
		}
	}
	for i := 0; i < 26; i++ {
		if ans[i] {
			print(string('a' + i))
		}
	}
	ln()
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanLines)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
}

func ln() {
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	res := make([][]byte, n)
	var wg sync.WaitGroup
	wg.Add(n)
	for i := 0; i < n; i++ {
		s, _ := in.ReadBytes('\n')
		go func(id int, s []byte) {
			defer wg.Done()
			mem := make(map[byte]bool)
			cnt := 0
			for j := range s {
				if j == 0 {
					cnt = 1
					continue
				}
				if s[j] != s[j-1] && cnt%2 == 1 {
					mem[s[j-1]] = true
					cnt = 1
				} else {
					cnt++
				}
			}
			for a := range mem {
				res[id] = append(res[id], a)
			}
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
		fmt.Println(string(s))
	}
}

package main

import "fmt"
import "sort"
import "strings"

// Check which button work correctly // a>a zzaaz>"z" ccff>"" cbddbb>bc
func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		l := len(s)
		res := ""
		lres := 0
		for j := 0; j < l; j++ {
			if j < l-1 {
				if s[j:j+1] == s[j+1:j+2] {
					j++
					continue
				} else if s[j:j+1] != s[j+1:j+2] {
					if !strings.Contains(res, s[j:j+1]) {
						res = res + s[j:j+1]
						lres++
					}
				}
			} else if j == l-1 {
				if !strings.Contains(res, s[j:j+1]) {
					res = res + s[j:j+1]
					lres++
				}
			}
		}
		//now arrange the res in ascending order! :)
		r := strings.Split(res, "")
		sort.Strings(r)

		for i := range r {
			fmt.Printf("%s", r[i])
		}
		fmt.Printf("\n")
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]string, n)
	for i := range s {
		fmt.Scan(&s[i])
	}
	// fmt.Println("n", n, "s", s)
	for i := range s {
		t := s[i]
		bad := make([]bool, 26)
		for j := 0; j < len(bad); j++ {
			bad[j] = true
		}
		set := make(map[byte]int, 0)
		cnt := 1
		for j := 0; j < len(t); j++ {
			set[t[j]]++
			if j+1 < len(t) && t[j] == t[j+1] {
				cnt++
				continue
			} else if cnt%2 != 0 {
				bad[t[j]-'a'] = false
			}
			cnt = 1
		}
		for j := 0; j < len(bad); j++ {
			if !bad[j] && set['a'+byte(j)] > 0 {
				fmt.Print(string('a' + j))
			}
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"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])
		// 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 S []rune

type DirRange []rune

func (a DirRange) Len() int           { return len(a) }
func (a DirRange) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a DirRange) Less(i, j int) bool { return a[i] < a[j] }

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		S = ReadRuneSlice()
		memo := make(map[rune]int)

		SS, L := RunLengthEncoding(S)
		for i := 0; i < len(L); i++ {
			if L[i]%2 == 1 {
				memo[SS[i]] = 1
			}
		}

		answers := DirRange{}
		for key := range memo {
			answers = append(answers, key)
		}

		sort.Sort(answers)
		fmt.Println(string(answers))
	}
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []rune) ([]rune, []int) {
	runes := []rune{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []rune, L []int) []rune {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []rune{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

/*
URL:
https://codeforces.com/contest/1251/problem/A
*/

package main

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

var (
	t int

	S []rune
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		S = readrs()

		solve()
	}
}

func solve() {
	memo := [30]int{}

	comp, cnts := RunLengthEncoding(S)
	for i := 0; i < len(cnts); i++ {
		if cnts[i]%2 == 1 {
			memo[comp[i]-'a'] = 1
		}
	}

	answers := []rune{}
	for i := 0; i < len(memo); i++ {
		if memo[i] > 0 {
			answers = append(answers, rune(i)+'a')
		}
	}

	printf("%s\n", string(answers))
}

// RunLengthEncoding returns encoded slice of an input.
// Time complexity: O(|S|)
func RunLengthEncoding(S []rune) (comp []rune, cnts []int) {
	comp = []rune{}
	cnts = []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			l++
		} else {
			comp = append(comp, S[i-1])
			cnts = append(cnts, l)
			l = 1
		}
	}
	comp = append(comp, S[len(S)-1])
	cnts = append(cnts, l)

	return
}

// RunLengthDecoding decodes RLE results.
// Time complexity: O(|S|)
func RunLengthDecoding(comp []rune, cnts []int) (S []rune) {
	if len(comp) != len(cnts) {
		panic("S, L are not RunLengthEncoding results")
	}

	S = []rune{}

	for i := 0; i < len(comp); i++ {
		for j := 0; j < cnts[i]; j++ {
			S = append(S, comp[i])
		}
	}

	return
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// 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
}

// 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
}

// 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
}

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

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

	return s
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// 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)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// 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
}

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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()
	tt := 1
	fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		ok := make(map[byte]bool)
		for len(s) > 0 {
			cnt := 0
			cur := s[0]
			for len(s) > 0 && s[0] == cur {
				s = s[1:]
				cnt++
			}
			if cnt%2 == 1 {
				ok[byte(cur)] = true
			}
		}
		for i := 'a'; i <= 'z'; i++ {
			if ok[byte(i)] {
				fmt.Fprintf(out, "%c", i)
			}
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}

package main

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

func GetReaderWriter() (*bufio.Reader, *bufio.Writer) {
	local := os.Getenv("LOCAL_DEBUG")
	reader := io.Reader(os.Stdin)
	writer := io.Writer(os.Stdout)
	if local != "" {
		bs, _ := ioutil.ReadFile("in.txt")
		reader = bytes.NewBuffer(bs)
	}
	return bufio.NewReader(reader), bufio.NewWriter(writer)
}

func main() {
	reader, writer := GetReaderWriter()
	defer writer.Flush()

	var t, i int64
	_, _ = Fscanf(reader, "%d\n", &t)
	for t > 0 {
		t--
		var s string
		res := make(map[byte]bool)
		_, _ = Fscanf(reader, "%s\n", &s)
		for i = 0; i < int64(len(s)); i++ {
			if i == int64(len(s))-1 {
				res[s[i]] = true
				break
			}
			if s[i] == s[i+1] {
				i++
			} else {
				res[s[i]] = true
			}
		}
		for i := uint8('a'); i <= 'z'; i++ {
			if res[i] {
				_, _ = Fprintf(writer, "%c", i)
			}
		}
		_, _ = Fprintf(writer, "\n")
	}
}

package main

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

type WordScanner struct {
	*bufio.Scanner
}

func NewWordScanner() *WordScanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &WordScanner{Scanner: s}
}

func (s *WordScanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *WordScanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *WordScanner) NextString() string {
	s.Scan()
	return s.Text()
}

func main() {
	ws := NewWordScanner()
	t := ws.NextInt()
	for ; t > 0; t-- {
		s := ws.NextString()
		fmt.Println(sol(s))
	}
}

func sol(s string) string {
	res := map[byte]bool{}
    prev := s[0]
	ctr := 1
	p := 1
	for p < len(s) {
		if s[p] != prev {
			if ctr%2 == 1 {
				res[prev] = true
			}
			ctr = 0
		}
		prev = s[p]
		ctr++
		p++
	}
    if ctr%2 == 1 {
        res[prev] = true
    }
	str := []byte{}
	for b := range res {
		str = append(str, b)
	}
	sort.Slice(str, func(i, j int) bool {
		return str[i] < str[j]
	})
	return string(str)
}

package main

import (
	"fmt"
	"sort"
)

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				continue
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				res = append(res, rune(s[i]))
				lastIndex = '-'
			} else {
				lastIndex = s[i]
			}
		}
		sort.Sort(res)
		println(string(res))
	}
}

package main

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

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		uselessCounter := 0
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				uselessCounter++
				continue
			} else if uselessCounter%2 == 1 {
				if !strings.ContainsRune(string(res), rune(s[i-1])) {
					res = append(res, rune(s[i-1]))
				}
				uselessCounter = 0
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				if !strings.ContainsRune(string(res), rune(s[i])) {
					res = append(res, rune(s[i]))
				}
				lastIndex = '-'
			} else {
				lastIndex = s[i]
				i++
			}
		}
		sort.Sort(res)
		fmt.Println(string(res))
	}
}

package main

import (
	"fmt"
	"sort"
)

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				continue
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				res = append(res, rune(s[i]))
				lastIndex = '-'
			} else {
				lastIndex = s[i]
			}
		}
		sort.Sort(res)
		fmt.Println(string(res))
	}
}

package main

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

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		uselessCounter := 0
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				uselessCounter++
				continue
			} else if uselessCounter%2 == 1 {
				if !strings.ContainsRune(string(res), rune(s[i])) {
					res = append(res, rune(s[i-1]))
				}
				uselessCounter = 0
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				if !strings.ContainsRune(string(res), rune(s[i])) {
					res = append(res, rune(s[i]))
				}
				lastIndex = '-'
			} else {
				lastIndex = s[i]
				i++
			}
		}
		sort.Sort(res)
		fmt.Println(string(res))
	}
}

package main

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

type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)

	for ; n != 0; n-- {
		fmt.Scanln(&s)
		var res ByRune

		//ALGO
		var lastIndex byte = '-'
		for i := 0; i < len(s); i++ {
			if s[i] == lastIndex {
				continue
			}
			if i+1 == len(s) || s[i] != s[i+1] {
				if !strings.ContainsRune(string(res), rune(s[i])) {
					res = append(res, rune(s[i]))
				}
				lastIndex = '-'
			} else {
				lastIndex = s[i]
			}
		}
		sort.Sort(res)
		fmt.Println(string(res))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	res := make([][]byte, n)
	var wg sync.WaitGroup
	wg.Add(n)
	for i := 0; i < n; i++ {
		s, _ := in.ReadBytes('\n')
		go func(id int, s []byte) {
			defer wg.Done()
			mem := make(map[byte]bool)
			cnt := 0
			for j := range s {
				if j == 0 {
					cnt = 1
					continue
				}
				if s[j] != s[j-1] && cnt%2 == 1 {
					mem[s[j-1]] = true
					cnt = 1
				} else {
					cnt++
				}
			}
			for a := range mem {
				res[id] = append(res[id], a)
			}
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		fmt.Println(string(s))
	}
}

package main

import "fmt"
import "sort"
import "strings"

// Check which button work correctly // a>a zzaaz>"z" ccff>"" cbddbb>bc
func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		l := len(s)
		res := ""
		lres := 0
		for j := 0; j < l; j++ {
			if j < l-1 {
				if s[j:j+1] == s[j+1:j+2] {
					j++
					continue
				} else if s[j:j+1] != s[j+1:j+2] {
					res = res + s[j:j+1]
					lres++
				}
			} else if j == l-1 {
				res = res + s[j:j+1]
				lres++
			}
		}
		//now arrange the res in ascending order! :)
		r := strings.Split(res, "")
		sort.Strings(r)

		for i := range r {
			fmt.Printf("%s", r[i])
		}
		fmt.Printf("\n")
	}
}

package main

import "fmt"

// Check which button work correctly // a>a zzaaz>"z" ccff>"" cbddbb>bc
func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		l := len(s)
		res := ""
		for j := 0; j < l; j++ {
			if j < l-1 {
				if s[j:j+1] == s[j+1:j+2] {
					j++
					continue
				} else if s[j:j+1] != s[j+1:j+2] {
					res = res + s[j:j+1]
				}
			} else if j == l-1 {
				res = res + s[j:j+1]
			}
		}
		fmt.Println(res)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]string, n)
	for i := range s {
		fmt.Scan(&s[i])
	}
	// fmt.Println("n", n, "s", s)
	for i := range s {
		t := s[i]
		bad := make([]bool, 26)
		set := make(map[byte]int, 0)
		cnt := 1
		for j := 0; j < len(t); j++ {
			set[t[j]]++
			if j+1 < len(t) && t[j] == t[j+1] {
				cnt++
				continue
			} else if cnt%2 == 0 && set[t[j]]%2 == 0 {
				// fmt.Println("d00 j", j)
				bad[t[j]-'a'] = true
			} else {
				bad[t[j]-'a'] = false
			}
			cnt = 1
		}
		for j := 0; j < len(bad); j++ {
			if !bad[j] && set['a'+byte(j)] > 0 {
				fmt.Print(string('a' + j))
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]string, n)
	for i := range s {
		fmt.Scan(&s[i])
	}
	// fmt.Println("n", n, "s", s)
	for i := range s {
		set := make([]byte, 26)
		for j := 0; j < len(s[i]); j++ {
			set[s[i][j]-'a']++
		}
		// fmt.Println("i", i, "set", set)
		for j := 0; j < len(set); j++ {
			if set[j]%2 != 0 {
				fmt.Print(string('a' + j))
			}
		}
		fmt.Println()
	}
}


There are $$$n$$$ TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The $$$i$$$-th of the shows is going from $$$l_i$$$-th to $$$r_i$$$-th minute, both ends inclusive.You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments $$$[l_i, r_i]$$$ and $$$[l_j, r_j]$$$ intersect, then shows $$$i$$$ and $$$j$$$ can't be watched simultaneously on one TV.Once you start watching a show on some TV it is not possible to "move" it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends.There is a TV Rental shop near you. It rents a TV for $$$x$$$ rupees, and charges $$$y$$$ ($$$y < x$$$) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes $$$[a; b]$$$ you will need to pay $$$x + y \cdot (b - a)$$$. You can assume, that taking and returning of the TV doesn't take any time and doesn't distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo $$$10^9 + 7$$$.

The first line contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le y < x \le 10^9$$$) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^9$$$) denoting the start and the end minute of the $$$i$$$-th TV show.

Print exactly one integer — the minimum cost to view all the shows taken modulo $$$10^9 + 7$$$.

NoteIn the first example, the optimal strategy would be to rent $$$3$$$ TVs to watch:  Show $$$[1, 2]$$$ on the first TV, Show $$$[4, 10]$$$ on the second TV, Shows $$$[2, 4], [5, 9], [10, 11]$$$ on the third TV. This way the cost for the first TV is $$$4 + 3 \cdot (2 - 1) = 7$$$, for the second is $$$4 + 3 \cdot (10 - 4) = 22$$$ and for the third is $$$4 + 3 \cdot (11 - 2) = 31$$$, which gives $$$60$$$ int total.In the second example, it is optimal watch each show on a new TV.In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo $$$10^9 + 7$$$.

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

const (
	mod = 1e9 + 7
)

func main() {
	var n, x, y int64
	fmt.Fscan(in, &n, &x, &y)
	l := make([]int, n)
	r := make([]int, n)
	for i := range l {
		fmt.Fscan(in, &l[i], &r[i])
	}
	sort.Ints(l)
	sort.Ints(r)

	ans := int64(0)
	var lastUsed, started []int
	for len(r) > 0 {
		if len(l) > 0 && l[0] <= r[0] {
			st := l[0]
			l = l[1:]
			started = append(started, st)
			if len(lastUsed) != 0 {
				if int64(st-lastUsed[len(lastUsed)-1])*y < x {
					ans = (ans + int64(st-lastUsed[len(lastUsed)-1])*y) % mod
					lastUsed = lastUsed[:len(lastUsed)-1]
					continue
				} else {
					lastUsed = lastUsed[0:]
				}
			}
			ans = (ans + x) % mod
		} else {
			en := r[0]
			r = r[1:]
			st := started[len(started)-1]
			started = started[:len(started)-1]
			lastUsed = append(lastUsed, en)
			ans = (ans + int64(en-st)*y) % mod
		}
	}
	fmt.Println(ans)
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

const (
	mod = 1e9 + 7
)

func main() {
	var n, x, y int64
	fmt.Fscan(in, &n, &x, &y)
	l := make([]int, n)
	r := make([]int, n)
	for i := range l {
		fmt.Fscan(in, &l[i], &r[i])
	}
	sort.Ints(l)
	sort.Ints(r)

	ans := int64(0)
	var lastUsed, started []int
	for len(r) > 0 {
		if len(l) > 0 && l[0] <= r[0] {
			st := l[0]
			l = l[1:]
			started = append(started, st)
			if len(lastUsed) != 0 {
				if int64(st-lastUsed[len(lastUsed)-1])*y < x {
					ans = (ans + int64(st-lastUsed[len(lastUsed)-1])*y) % mod
					continue
				} else {
					lastUsed = lastUsed[0:]
				}
			}
			ans = (ans + x) % mod
		} else {
			en := r[0]
			r = r[1:]
			st := started[len(started)-1]
			started = started[:len(started)-1]
			lastUsed = append(lastUsed, en)
			ans = (ans + int64(en-st)*y) % mod
		}
	}
	fmt.Println(ans)
}