Like all children, Alesha loves New Year celebration. During the celebration he and his whole family dress up the fir-tree. Like all children, Alesha likes to play with garlands — chains consisting of a lightbulbs.Alesha uses a grid field sized n × m for playing. The rows of the field are numbered from 1 to n from the top to the bottom and columns are numbered from 1 to m from the left to the right.Alesha has k garlands which he places at the field. He does so in the way such that each lightbulb of each garland lies in the center of some cell in the field, and each cell contains at most one lightbulb. Of course lightbulbs, which are neighbours in some garland, appears in cells neighbouring by a side.The example of garland placing.Each garland is turned off or turned on at any moment. If some garland is turned on then each of its lightbulbs is turned on, the same applies for garland turned off. Each lightbulb in the whole garland set is unique, and thus, being turned on, brings Alesha some pleasure, described by an integer value. Turned off lightbulbs don't bring Alesha any pleasure.Alesha can turn garlands on and off and wants to know the sum of pleasure value which the lightbulbs, placed in the centers of the cells in some rectangular part of the field, bring him. Initially all the garlands are turned on.Alesha is still very little and can't add big numbers. He extremely asks you to help him.

The first line of the input contains three integers n, m and k (1 ≤ n, m, k ≤ 2000) — the number of field rows, the number of field columns and the number of garlands placed at the field respectively. Next lines contains garlands set description in the following format: The first line of a single garland description contains a single integer len (1 ≤ len ≤ 2000) — the number of lightbulbs in the garland. Each of the next len lines contains three integers i, j and w (1 ≤ i ≤ n, 1 ≤ j ≤ m, 1 ≤ w ≤ 109) — the coordinates of the cell containing a lightbullb and pleasure value Alesha gets from it if it is turned on. The lightbulbs are given in the order they are forming a chain in the garland. It is guaranteed that neighbouring lightbulbs are placed in the cells neighbouring by a side. The next line contains single integer q (1 ≤ q ≤ 106) — the number of events in Alesha's game. The next q lines describes events in chronological order. The i-th of them describes the i-th event in the one of the following formats:   SWITCH i — Alesha turns off i-th garland if it is turned on, or turns it on if it is turned off. It is guaranteed that 1 ≤ i ≤ k.  ASK x1 y1 x2 y2 — Alesha wants to know the sum of pleasure values the lightbulbs, placed in a rectangular part of the field. Top-left cell of a part has coordinates (x1, y1) and right-bottom cell has coordinates (x2, y2). It is guaranteed that 1 ≤ x1 ≤ x2 ≤ n and 1 ≤ y1 ≤ y2 ≤ m. There is no more than 2000 events of this type in the input.  All the numbers in the input are integers. Please note that the input is quite large, so be careful while using some input ways. In particular, it's not recommended to use cin in codes on C++ and class Scanner in codes on Java.

For each ASK operation print the sum Alesha wants to know in a separate line. Print the answers in chronological order.

NoteThis image illustrates the first sample case.

package main

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

// import "time"

var in *bufio.Scanner
var out *bufio.Writer

func read() int {
	in.Scan()
	b := in.Bytes()
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	return n
}

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func main() {
	// start := time.Now()

	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = read()
	m = read()
	k = read()

	garlands = make([]Garland, k)

	for i := 0; i < k; i++ {
		l := read()

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			row := read()
			col := read()
			val := read()
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	q = read()
	queries = make([]Query, q)
	na = 0

	for i := 0; i < q; i++ {
		in.Scan()
		cat := in.Text()
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			queries[i].r1 = read()
			queries[i].c1 = read()
			queries[i].r2 = read()
			queries[i].c2 = read()
		} else {
			queries[i].cat = 0
			queries[i].at = read()
		}
	}

	// elapsed := time.Since(start)
	// out.WriteString("read time: " + elapsed.String() + "\n")

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			out.WriteString(strconv.FormatInt(res, 10))
			out.WriteByte('\n')
		} else {
			on[at-1] ^= 1
		}
	}

	// elapsed = time.Since(start)
	// out.WriteString("total time: " + elapsed.String() + "\n")
}

package main

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

var in *bufio.Scanner
var out *bufio.Writer

var (
	p    int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && !IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

func ReadInt() int {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := 0
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = 10*d + int(ibuf[p]-'0')
	}
	return d
}

func ReadInt64() int64 {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := int64(0)
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = int64(10)*d + int64(ibuf[p]-'0')
	}
	return d
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

func main() {
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	n = ReadInt()
	m = ReadInt()
	k = ReadInt()

	garlands = make([]Garland, k)

	for i := 0; i < k; i++ {
		l := ReadInt()

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			row := ReadInt()
			col := ReadInt()
			val := ReadInt()
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	q = ReadInt()
	queries = make([]Query, q)
	na = 0

	for i := 0; i < q; i++ {
		cat := ReadWord()
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			queries[i].r1 = ReadInt()
			queries[i].c1 = ReadInt()
			queries[i].r2 = ReadInt()
			queries[i].c2 = ReadInt()
		} else {
			queries[i].cat = 0
			queries[i].at = ReadInt()
		}
	}

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			writeInt64(res, '\n')
		} else {
			on[at-1] ^= 1
		}
	}
}

package main

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

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func main() {
	defer out.Flush()

	readInt(&n)
	readInt(&m)
	readInt(&k)

	garlands = make([]Garland, k)

	var l, row, col, val int
	for i := 0; i < k; i++ {
		read(&l)

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			readInt(&row)
			readInt(&col)
			readInt(&val)
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	readInt(&q)
	queries = make([]Query, q)
	na = 0

	var cat string
	for i := 0; i < q; i++ {
		readString(&cat)
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			readInt(&queries[i].r1)
			readInt(&queries[i].c1)
			readInt(&queries[i].r2)
			readInt(&queries[i].c2)
		} else {
			queries[i].cat = 0
			readInt(&queries[i].at)
		}
	}

	// elapsed := time.Since(start)
	// out.WriteString("read time: " + elapsed.String() + "\n")

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			writeInt64(res)
			writeByte('\n')
		} else {
			on[at-1] ^= 1
		}
	}
}

// Heap
type Node struct {
	name  int
	value int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

// Sort
type Int64Slice []int64

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

// Input output
var out *bufio.Writer
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isLine(c byte) bool {
	return (c == '\n') || (c == '\r')
}

func isSpace(c byte) bool {
	return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r')
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readByte(v *byte) bool {
	if iPointer >= nPointer {
		return false
	}
	*v = iBuffer[iPointer]
	iPointer++
	return true
}

func readString(v *string) bool {
	for (iPointer < nPointer) && isSpace(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isSpace(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	return true
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readInt64(v *int64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int64
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int64(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readFloat64(v *float64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		if iBuffer[iPointer] != '.' {
			neg = (iBuffer[iPointer] == '-')
		}
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	if neg {
		a = append(a, '-')
	}
	if iPointer > 0 && iBuffer[iPointer-1] == '.' {
		a = append(a, '.')
	} else {
		for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
		if (iPointer < nPointer) && (iBuffer[iPointer] == '.') {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
	}
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	var ok error
	*v, ok = strconv.ParseFloat(string(a), 64)
	return ok == nil
}

func readln(v *string) bool {
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isLine(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	return true
}

func read(arg interface{}) bool {
	switch v := arg.(type) {
	case *byte:
		return readByte(v)
	case *string:
		return readString(v)
	case *int:
		return readInt(v)
	case *int64:
		return readInt64(v)
	case *float64:
		return readFloat64(v)
	default:
		return false
	}
}

func writeBool(v bool) {
	if v {
		out.WriteString("true")
	} else {
		out.WriteString("false")
	}
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeString(v string) {
	out.WriteString(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}

func writeInt64(v int64) {
	out.WriteString(strconv.FormatInt(v, 10))
}

func writeFloat64(v float64) {
	out.WriteString(strconv.FormatFloat(v, 'f', -1, 64))
}

func writeln(args ...interface{}) {
	write(args...)
	out.WriteByte('\n')
}

func write(args ...interface{}) {
	for _, a := range args {
		switch v := a.(type) {
		case bool:
			writeBool(v)
		case byte:
			writeByte(v)
		case rune:
			writeByte(byte(v))
		case string:
			writeString(v)
		case int:
			writeInt(v)
		case int64:
			writeInt64(v)
		case float64:
			writeFloat64(v)
		default:
			out.WriteString("###")
		}
	}
}


Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactly p decimal digits, and if we move the last digit of the number to the beginning, it grows exactly x times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible.The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us!

The single line contains integers p, x (1 ≤ p ≤ 106, 1 ≤ x ≤ 9).

If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes.

NoteSample 1: 142857·5 = 714285.Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible".

package main

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

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	p, x := nextInt(), nextInt()
	result, number := make([]int, p), make([]int, p)
	multipleResult, tenPower, nextDigit := 0, 0, 0

	if p==1 {
		if x==1 {
			fmt.Println(1)
		} else {
			fmt.Println("Impossible")
		}
		return
	}

	for digit:=1; digit <= 9; digit++ {
		nextDigit = digit
		tenPower = 0
		index := p - 1
		number[index] = nextDigit
		index--
		for i:=0; i<p-1; i++ {
			multipleResult = nextDigit * x + tenPower
			nextDigit = multipleResult%10
			tenPower = multipleResult/10
			number[index]=nextDigit
			index--
			// fmt.Println(multipleResult, nextDigit, tenPower, number)
		}

		if nextDigit == 0 || digit != (nextDigit*x + tenPower) {
			continue
		}

		if result[0] == 0 {
			result, number = number, result
		} else {
			for i:=0; i<p; i++ {
				switch {
				case number[i]==result[i] :
					continue
				case number[i]<result[i] :
					result, number = number, result
				case number[i]>result[i] :
					break
				}
			}
		}
	}

	if result[0] != 0 {
		printInts(result)
	} else {
		fmt.Println("Impossible")
	}
}

func printInts(ints []int) {
	for i, length:= 0, len(ints); i<length; i++ {
		fmt.Fprint(writer, ints[i])
	}
	fmt.Fprintln(writer)
}

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, f := getI(), getI()
  for a := 1; a <= 9; a++ {
    digits := make([]int, n)
    carry := 0
    d := a
    for pos := n - 1; pos >= 0; pos-- {
      x := carry + f * d
      d = x % 10
      digits[pos] = d
      carry = x / 10
    }
    if carry == 0 && digits[0] == a && (n == 1 || digits[1] != 0) {
      for i := 1; i < n; i++ {
        writer.WriteByte('0' + byte(digits[i]))
      }
      writer.WriteByte('0' + byte(digits[0]))
      writer.WriteByte('\n')
      return
    }
  }
  writer.WriteString("Impossible\n")
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, f := getI(), getI()
  for a := 1; a <= 9; a++ {
    digits := make([]int, n)
    carry := 0
    d := a
    for pos := n - 1; pos >= 0; pos-- {
      x := carry + f * d
      d = x % 10
      digits[pos] = d
      carry = x / 10
    }
    if carry == 0 && digits[0] == a {
      for _, d := range digits {
        writer.WriteByte('0' + byte(d))
      }
      writer.WriteByte('\n')
      return
    }
  }
  writer.WriteString("Impossible\n")
}


Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.

The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.

Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.

NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".

package main

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

func main() {
	var n int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		if len(s) > 3 {
			var nes string
			for j := 0; j < len(s); j += 2 {
				nes += string(s[j])
			}
			nes += string(s[len(s)-1])
			fmt.Println(nes)
		} else {
			fmt.Println(s)
		}
	}
}

// pythonのほうが楽そう
// 文字列ってことで速度が怖いのでテンプレでいくよ

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	for i:=0; i<N; i++{
		S := chars(next())
		if len(S) == 2{
			fmt.Fprintln(out, strings.Join(S, ""))
			continue
		}
		ans := []string{S[0]}
		for j:=1; j<len(S)-1; j+=2{
			ans = append(ans, S[j])
		}
		ans = append(ans, S[len(S)-1])
		fmt.Fprintln(out, strings.Join(ans, ""))
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int{
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	for tt := NextInt(); tt > 0; tt-- {
		s := Next()
		if len(s) <= 2 {
			fmt.Println(s)
		} else {
			var ret string
			ret += s[0 : 2]
			for i := 3; i < len(s); i += 2 {
				ret += string(s[i])
			}
			fmt.Println(ret)
		}
	}
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++ {
		var s string
		fmt.Fscanf(in, "%v\n", &s)
		for i := 0;i < len(s);i+=2 {
			fmt.Fprint(out, string(s[i]))
		}
		fmt.Fprintln(out, string(s[len(s) - 1]))
	}
	return
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ;t>=1; t-- {
		var s string
		fmt.Scan(&s)
		for i:=0;i<len(s);i+=2{
			fmt.Printf("%c",s[i])
		}
		fmt.Printf("%c\n",s[len(s)-1])
	}
}

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

func main(){
    var t int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscanln(in, &t)

    var data string
    for ; t > 0; t-- {
        fmt.Fscanln(in, &data)
        fmt.Printf("%c%c", data[0], data[1])
        for i := 3; i < len(data); i += 2 {
            fmt.Printf("%c", data[i])
        }
        fmt.Println()
    }
}

package main

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

func main(){
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r,&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Fscan(r,&s)
		//fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Fprintf(w,"%c",s[0])
			} else {
				fmt.Fprintf(w,"%c",s[2*i-1])
			}
		}
		fmt.Fprint(w,"\n")
	}
}

package main

import "fmt"

func main(){
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Scan(&s)
		//fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Printf("%c",s[0])
			} else {
				fmt.Printf("%c",s[2*i-1])
			}
		}
		fmt.Println()
	}
}
//func main(){
//	//r := bufio.NewReader(os.Stdin)
//	//w := bufio.NewWriter(os.Stdout)
//	var t int
//	fmt.Scanf("%d",&t)
//	for ; t > 0 ; t--{
//		var s string
//		fmt.Scanf("%s",&s)
//		ls := len(s)/2 + 1
//		//fmt.Printf("ls : %d\n",ls)
//		for i := 0 ;i < ls ;i++{
//			if i == 0 {
//				fmt.Printf("%c",s[0])
//			} else {
//				fmt.Printf("%c",s[2*i-1])
//			}
//		}
//		fmt.Println()
//	}
//}
/*
还有一个问题，就是string不是不可变的吗？为什么Scanf取地址，里面函数就能改变了string了呢
*/
//type Point struct {
//	x,y int
//}
//func main()  {
//	p := Point{1,1}
//	fmt.Println(p)
//	p.Increment()
//	fmt.Println(p)
//}
//
//func (p *Point) Increment(){
//	p.x ++
//	p.y ++
//}

//func f(){
//	defer fmt.Println("sign1")
//	fmt.Println("begin f")
//	panic("asdsadasd")
//}
//
//func main(){
//
//	defer func(){
//		w:=recover()
//		fmt.Printf("%T",w)
//	}()
//	f()
//}

//
//func ceshi(){
//	defer trace("function ceshi")()
//
//	time.Sleep(10*time.Second)
//
//}
//func trace(info string)  func() {
//	start := time.Now()
//
//	log.Print("enter "+ info)
//	return func() {
//		log.Printf("exit %s (%s)",info,time.Since(start))
//	}
//}
//
//func main() {
//	ceshi()
//
//}

//!-

package main

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

var (
	tests = 0
)

func main() {
	input()
}

func proc(b string) {
	result := ""
	l := len(b)

	if l < 2 || l % 2 == 1{
		fmt.Println(b)
		return
	}

	for i := 0; i < l/2; i++ {
		if i == 0 {
			result += b[i:i+2]
			continue
		}

		if b[i*2] == b[2*i-1] {
			result += b[2*i+1:2*i+2]
			continue
		}

		fmt.Println(b)
		return
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		proc(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(val string) string {
	retVal := val[0:2]
	//fmt.Println(retVal)
	for x := 3; x < len(val); x = x + 2 {
		retVal += string(val[x])
	}
	return retVal
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num int
	var ret string
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	num = fastGetInt(scanner.Bytes())
	for x := 0; x < num; x++ {
		scanner.Scan()
		ret = solution(scanner.Text())
		fmt.Println(ret)
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var s string
		fmt.Fscanf(reader, "%s\n", &s)

		for i := 0; i < len(s); i += 2 {
			fmt.Printf("%c", s[i])
		}
		fmt.Printf("%c\n", s[len(s)-1])
	}
}

package main

// https://codeforces.com/problemset/problem/1367/A
// A. Short Substrings
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Alice guesses the strings that Bob made for her.

// At first, Bob came up with the secret string a
// consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a

// .

// Bob builds b
// from a as follows: he writes all the substrings of length 2 of the string a in the order from left to right, and then joins them in the same order into the string b

// .

// For example, if Bob came up with the string a
// ="abac", then all the substrings of length 2 of the string a are: "ab", "ba", "ac". Therefore, the string b

// ="abbaac".

// You are given the string b
// . Help Alice to guess the string a that Bob came up with. It is guaranteed that b

// was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
// Input

// The first line contains a single positive integer t
// (1≤t≤1000) — the number of test cases in the test. Then t

// test cases follow.

// Each test case consists of one line in which the string b
// is written, consisting of lowercase English letters (2≤|b|≤100) — the string Bob came up with, where |b| is the length of the string b. It is guaranteed that b

// was built according to the algorithm given above.
// Output

// Output t
// answers to test cases. Each answer is the secret string a, consisting of lowercase English letters, that Bob came up with.

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

var (
    bufStdin  = bufio.NewReader(os.Stdin)
    bufStdout = bufio.NewWriter(os.Stdout)
)

func main() {
    defer bufStdout.Flush()

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

    for i := 0; i < t; i++ {
        var b []byte
        _, _ = fmt.Fscan(bufStdin, &b)

        a := make([]byte, 0, len(b))

        a = append(a, b[0])

        for i := 1; i < len(b)-1; i+=2 {
            a = append(a, b[i])
        }

        a = append(a, b[len(b)-1])

        _, _ = fmt.Fprintf(bufStdout, "%s\n", string(a))
    }
}

package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscanln(r, &n)
	for i := 0; i < n; i++ {
		var b string
		fmt.Fscan(r, &b)
		a := make([]rune, len(b)/2 + 1)
		for j, e := range b {
			if j%2 == 0 {
				a[j/2] = e
			}
		}
		a[len(a)-1] = rune(b[len(b)-1])
		fmt.Fprintln(w, string(a))
	}
}

package main

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

// https://codeforces.com/problemset/problem/1367/A
// комментарии к решению
// Как видно из примера и алгоритма из строки:
// bccddaaf
// получается:
// bcdaf
// т.е. все серединные (не первый и не последний) парные символы
// нужно превратить в одиночные. В примере выше это достигается
// путём выбора символов с позиций 1 - 3 - 5 - 7 - 8
func taskSolution(a []byte, t int) string {
	ans := []byte{}
	for i, pos := 0, 0; i < t; i += 1 {
		// find next
		// skip len check, because t value control number count
		for !(a[pos] >= 'a' && a[pos] <= 'z') {
			pos += 1
		}
		// skip len check, because t value control number count
		for a[pos] >= 'a' && a[pos] <= 'z' {
			ans = append(ans, a[pos])
			pos += 2
		}
		ans = append(ans, a[pos-1], '\n')
	}
	// truncate last new-line
	return string(ans[:len(ans)-1])
}

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

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw, t))
}

package main

import (
  "fmt"
)

var N int
func main() {
  fmt.Scan(&N)
  for i := 0; i < N; i++ {
    var s string
    fmt.Scan(&s)
    if len(s) == 2 {
      fmt.Println(s)
    } else {
      for j := 0; j < len(s); j+=2 {
        fmt.Printf("%c", s[j])
        if j == len(s)-2 {
          fmt.Printf("%c", s[len(s)-1])
        }
      }
      fmt.Println()
    }
  }
}

package main

import (
	"fmt"
)

func main() {
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var s string

		fmt.Scan(&s)
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0; i < ls; i++ {
			if i == 0 {
				fmt.Printf("%c", s[0])
			} else {
				fmt.Printf("%c", s[2*i-1])
			}
		}
		fmt.Println()
	}
}

package main

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

func main(){
	var t int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		fmt.Fscan(in,&s)
		fmt.Printf("%s",string(s[0]))
		for j:=1;j<len(s)-1;j+=2{
			fmt.Printf("%s",string(s[j]))
		}
		fmt.Printf("%s\n",string(s[len(s)-1]))
	}
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j += 2 {
            fmt.Printf("%c",s[j])
        }
        fmt.Printf("%c\n",s[l - 1])
    }
}

package main

import (
 	"fmt"
)

func solve() {
	var str string
	fmt.Scan(&str)
	var res string
	res = res + string(str[0])

	for i := 1; i < len(str); i+=2 {
		res = res + string(str[i])
	}

	fmt.Println(res)
}

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

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

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

func main() {
	var T int

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

func solver() {
	var s string
	fmt.Fscan(input, &s)
	var b bytes.Buffer
	for i := 0; i < len(s); i+=2 {
		b.WriteByte(s[i])
	}
	b.WriteByte(s[len(s)- 1])
	fmt.Println(b.String())
}

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

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 b string
		fmt.Fscan(in, &b)
		if len(b) == 1 {
			fmt.Println(b)
		} else {
			a := ""
			for i, ch := range b {
				if i%2 == 0 {
					a += string(ch)
				}
			}
			a += string(b[len(b)-1])
			fmt.Println(a)
		}
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		result := make([]byte, 0)
		result = append(result, line[0], line[1])
		for i := 2; i < len(line) ; i=i+2 {
			if line[i] == line[i-1] {
				result = append(result, line[i+1])
			} else {
				result = append(result, line[i], line[i+1])
			}
		}
		fmt.Println(string(result))
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scan(&t)
    for ;t>0;t--{
        var s string
        fmt.Scan(&s)
        for i:=0;i<len(s);i+=2{
            fmt.Printf("%c",s[i])
        }
        fmt.Printf("%c\n",s[len(s)-1]);
    }
}

package main

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

var n int
var s string

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

	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s)

		for j := 0; j < len(s); j++ {
			if j%2 == 0 || j == len(s)-1 {
				fmt.Fprintf(out, "%c", s[j])
			}
		}

		fmt.Fprintln(out)
	}

	out.Flush()
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var a int
	scanf("%d\n", &a)
	// printf("Test found: %v\n", a)

	for i := 0; i < a; i++ {
		var b string
		scanf("%s\n", &b)

		for i := 0; i < len(b); i++ {
			if i%2 == 0 || i == len(b)-1 {
				printf("%c", b[i])
			}
		}
		printf("\n")
	}

}

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

func main(){
    var t int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscanln(in, &t)
    var data string
    for ; t > 0; t-- {
        fmt.Fscanln(in, &data)
        fmt.Println(len(data))
        fmt.Printf("%c%c", data[0], data[1])
        for i := 3; i < len(data); i += 2 {
            fmt.Printf("%c", data[i])
        }
        fmt.Println()
    }
}

package main

import "fmt"

func main(){
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Scan(&s)
		fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Printf("%c",s[0])
			} else {
				fmt.Printf("%c",s[2*i-1])
			}
		}
		fmt.Println()
	}
}

package main

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

var (
	tests = 0
)

func main() {
	input()
}

func process(b string) {
	result := ""

	if len(b) < 2 {
		fmt.Println(b)
		return
	}

	if len(b) == 2 {
		if b[0] == b[1] {
			fmt.Println(b[:1])
			return
		}

		fmt.Println(b)
		return
	}

	newB := b[:1] + b + b[len(b)-1:]
	check := true
	for i := 0; i < len(newB); i++ {
		if i < 1 || i > len(b) {
			continue
		}

		if i%2==1 && newB[i] != newB[i-1] {
			check = false
			break
		}
	}

	if !check {
		fmt.Println(b)
		return
	}

	for i, _ := range b {
		if i < 1 {
			result += string(b[i])
			continue
		}

		if b[i] != b[i-1] {
			result += string(b[i])
			continue
		}

		b = b[:i] + "0" + b[i+1:]
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		process(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

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

var (
	tests = 0
)

func main() {
	input()
}

func proc(b string) {
	result := ""
	l := len(b)

	if l < 2 {
		fmt.Println(b)
		return
	}

	for i := 0; i < l/2; i++ {
		if i == 0 {
			result += b[i:i+2]
			continue
		}

		if b[i] == b[i-1] {
			result += b[i+1:i+2]
			continue
		}

		fmt.Println(b)
		return
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		proc(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s",&s)
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s",&s)
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Printf("\n")
    }
}

package main

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

func main() {
	var n int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		if len(s) > 5 {
			var nes string
			for j := 0; j < len(s); j += 2 {
				nes += string(s[j])
			}
			nes += string(s[len(s)-1])
			fmt.Println(nes)
		} else {
			fmt.Println(s)
		}
	}
}


You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Each of $$$a_i$$$ has between $$$3$$$ and $$$5$$$ divisors. Consider $$$a = \prod a_i$$$ — the product of all input integers. Find the number of divisors of $$$a$$$. As this number may be very large, print it modulo prime number $$$998244353$$$.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 500$$$) — the number of numbers. Each of the next $$$n$$$ lines contains an integer $$$a_i$$$ ($$$1 \leq a_i \leq 2\cdot 10^{18}$$$). It is guaranteed that the number of divisors of each $$$a_i$$$ is between $$$3$$$ and $$$5$$$.

Print a single integer $$$d$$$ — the number of divisors of the product $$$a_1 \cdot a_2 \cdot \dots \cdot a_n$$$ modulo $$$998244353$$$. Hacks input For hacks, the input needs to be provided in a special format. The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 500$$$) — the number of numbers. Each of the next $$$n$$$ lines contains a prime factorization of $$$a_i$$$. The line contains an integer $$$k_i$$$ ($$$2 \leq k_i \leq 4$$$) — the number of prime factors of $$$a_i$$$ and $$$k_i$$$ integers $$$p_{i,j}$$$ ($$$2 \leq p_{i,j} \leq 2 \cdot 10^{18}$$$) where $$$p_{i,j}$$$ is the $$$j$$$-th prime factor of $$$a_i$$$.  Before supplying the input to the contestant, $$$a_i = \prod p_{i,j}$$$ are calculated. Note that each $$$p_{i,j}$$$ must be prime, each computed $$$a_i$$$ must satisfy $$$a_i \leq 2\cdot10^{18}$$$ and must have between $$$3$$$ and $$$5$$$ divisors. The contestant will be given only $$$a_i$$$, and not its prime factorization.  For example, you need to use this test to get the first sample: 32 3 32 3 52 11 13

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	st := int64(math.Pow(float64(x), 1./3)) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			if pq[i] == pq[j] {
				continue
			}
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1414213563); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1414213563); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1259922); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if a == b || b == 1 {
					continue
				}
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	fac4 := map[uint64]int{}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			fac4[f4[i]] ++
		}
	}
	for _, count := range fac4 {
		ans *= uint64((count + 1) * (count + 1))
		ans %= 998244353
	}
	fmt.Printf("%d", ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, 0, n)
	vis := make([]bool, 0, n)
	cntv := map[int64]int{}
	cnte := map[int64]int{}
	for ; n > 0; n-- {
		var v int64
		Fscan(in, &v)
		ok := true
		if r := cbrt(v); r != -1 {
			cnte[r] += 3
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnte[r4] += 4
			} else {
				cnte[r] += 2
			}
		} else {
			ok = false
		}
		cntv[v]++
		if cntv[v] == 1 {
			a = append(a, v)
			vis = append(vis, ok)
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnte[g] += cntv[x]
					cnte[x/g] += cntv[x]
					if !vis[j] {
						cnte[g] += cntv[y]
						cnte[y/g] += cntv[y]
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			c := cntv[x] + 1
			ans = ans * int64(c*c) % mod
		}
	}
	for _, e := range cnte {
		ans = ans * int64(e+1) % mod
	}
	Fprintln(_w, ans)
}

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

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	for i := int64(math.Pow(float64(x), 1./3)) - 100; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	st := int64(math.Pow(float64(x), 1./3)) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1414213563); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1414213563); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1259922); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			ans *= 4
			ans %= 998244353
		}
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1500000000); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1500000000); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1400000); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			ans *= 4
			ans %= 998244353
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cntv := map[int64]int{}
	cnte := map[int64]int{}
	vis := make([]bool, 0, n)
	a := make([]int64, 0, n)
	for ; n > 0; n-- {
		var v int64
		Fscan(in, &v)
		cntv[v]++
		if cntv[v] > 1 {
			continue
		}
		a = append(a, v)
		if r := cbrt(v); r != -1 {
			cnte[r] += 3
			vis = append(vis, true)
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnte[r4] += 4
			} else {
				cnte[r] += 2
			}
			vis = append(vis, true)
		} else {
			vis = append(vis, false)
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnte[g] += cntv[x]
					cnte[x/g] += cntv[x]
					if !vis[j] {
						cnte[g] += cntv[y]
						cnte[y/g] += cntv[y]
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			c := cntv[x] + 1
			ans = ans * int64(c*c) % mod
		}
	}
	for _, c := range cnte {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cnts := map[int64]int{}
	vis := make([]bool, n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		if r := cbrt(v); r != -1 {
			cnts[r] += 3
			vis[i] = true
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnts[r4] += 4
			} else {
				cnts[r] += 2
			}
			vis[i] = true
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnts[g]++
					cnts[x/g]++
					if !vis[j] {
						cnts[g]++
						cnts[y/g]++
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			ans = ans * 4 % mod
		}
	}
	for _, c := range cnts {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cnts := map[int64]int{}
	vis := make([]bool, n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		if r := cbrt(v); r != -1 {
			cnts[r] += 3
			vis[i] = true
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnts[r4] += 4
			} else {
				cnts[r] += 2
			}
			vis[i] = true
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i || y == x {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnts[g]++
					cnts[x/g]++
					if !vis[j] {
						cnts[g]++
						cnts[y/g]++
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			ans = ans * 4 % mod
		}
	}
	for _, c := range cnts {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

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


You are given a chessboard of size $$$n \times n$$$. It is filled with numbers from $$$1$$$ to $$$n^2$$$ in the following way: the first $$$\lceil \frac{n^2}{2} \rceil$$$ numbers from $$$1$$$ to $$$\lceil \frac{n^2}{2} \rceil$$$ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest $$$n^2 - \lceil \frac{n^2}{2} \rceil$$$ numbers from $$$\lceil \frac{n^2}{2} \rceil + 1$$$ to $$$n^2$$$ are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation $$$\lceil\frac{x}{y}\rceil$$$ means division $$$x$$$ by $$$y$$$ rounded up.For example, the left board on the following picture is the chessboard which is given for $$$n=4$$$ and the right board is the chessboard which is given for $$$n=5$$$.  You are given $$$q$$$ queries. The $$$i$$$-th query is described as a pair $$$x_i, y_i$$$. The answer to the $$$i$$$-th query is the number written in the cell $$$x_i, y_i$$$ ($$$x_i$$$ is the row, $$$y_i$$$ is the column). Rows and columns are numbered from $$$1$$$ to $$$n$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le q \le 10^5$$$) — the size of the board and the number of queries. The next $$$q$$$ lines contain two integers each. The $$$i$$$-th line contains two integers $$$x_i, y_i$$$ ($$$1 \le x_i, y_i \le n$$$) — description of the $$$i$$$-th query.

For each query from $$$1$$$ to $$$q$$$ print the answer to this query. The answer to the $$$i$$$-th query is the number written in the cell $$$x_i, y_i$$$ ($$$x_i$$$ is the row, $$$y_i$$$ is the column). Rows and columns are numbered from $$$1$$$ to $$$n$$$. Queries are numbered from $$$1$$$ to $$$q$$$ in order of the input.

NoteAnswers to the queries from examples are on the board in the picture from the problem statement.

package main

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

func main()  {

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

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

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

		var a, b int64
		fmt.Fscan(in, &a, &b)

		var x int64
		if (a % 2 != 0 && b % 2 == 0) || (a % 2 == 0 && b % 2 != 0) {
			x += (n * n) / 2
			if n % 2 != 0 {
				x++
				//fmt.Fprintln(out, x)
				if a % 2 == 0 {
					x += (a - 2) / 2 * n
					x += n / 2
				} else {
					x += (a - 1) / 2 * n
				}
			} else {
				x += (a - 1) * n / 2
			}

		} else {

			if n % 2 != 0 {
				if a % 2 == 0 {
					x += (a - 2) / 2 * n
					x += n / 2 + 1
				} else {
					x += (a - 1) / 2 * n
				}
			} else {
				x += (a - 1) * n / 2
			}

		}

		x += (b + 1) / 2

		fmt.Fprintln(out, x)

	}

}
/*
4 12
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
*/

package main

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

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  n := next_int()
  q := int(next_int())

  for i := 1 ; i <= q; i++ {
    row := next_int()
    col := next_int()

    pattern := [] int64 {n / 2, n / 2}
    if (n & 1) > 0 {
      pattern[0]++
    }

    var offset int64 = 1
    if (row + col) & 1 > 0 {
      // position is odd, switch to the second half of values
      offset = (n * n + 1) / 2 + 1;
      // shift pattern
      sw := pattern[0];
      pattern[0] = pattern[1]
      pattern[1] = sw
    }

    plus := ((row - 1) / 2) * (pattern[0] + pattern[1])
    offset = offset + plus
    row = row - (((row - 1) / 2) * 2)
    if 2 == row {
      row -= 1
      offset += pattern[0]
    }
    offset += (col - 1) / 2;
    fmt.Println(offset)
  }
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.ParseInt(strings.Split(scanner.Text(), " ")[0], 10, 64)
	mid := (n*n + 1) / 2
	for scanner.Scan() {
		ws := strings.Split(scanner.Text(), " ")
		y, _ := strconv.ParseInt(ws[0], 10, 64)
		x, _ := strconv.ParseInt(ws[1], 10, 64)
		index := (int64(y)-1)*n + int64(x) - 1
		rank, extra := index/(2*n)*n, index%(2*n)
		if (x+y)%2 == 0 {
			if extra < n {
				rank += extra/2 + 1
			} else {
				rank += (extra%n+1)/2 + (n+1)/2
			}
			fmt.Println(rank)
		} else {
			if extra < n {
				rank += (extra + 1) / 2
			} else {
				rank += (extra%n+2)/2 + n/2
			}
			fmt.Println(mid + rank)
		}
	}
}

// 1027b
package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int64
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; int64(i) < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int64
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = xy / 2
			if xy%2 > 0 {
				p++
			}
		} else {
			p = n*n/2 + xy/2
			if xy%2 > 0 {
				p++
			}
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.FormatInt(p, 10))
	}
	fmt.Println(strings.Join(h, "\n"))
}

// 1027b
package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func main() {

	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

// 1027b
package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

package main
import (
	 "fmt"
		"math"
		)
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
			if (x+y)%2==0 {
					p = int(math.Ceil(float64(xy)/2))
				} else {
					p = n*n/2 + int(math.Ceil(float64(xy)/2))
				}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}

package main
import "fmt"
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
		if n%2!=0 {
			if (x+y)%2==0 {
					p = xy/2 + 1
				} else {
					p = n*n/2 + xy/2 +1
				}
		}else{
			if (x+y)%2==0 {
				p =xy/2 + 1
			}else{
				p =xy/2+1+n*n/2
				}
		}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}

// 1027b
package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int64
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; int64(i) < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int64
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int64(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int64(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.FormatInt(p, 10))
	}
	fmt.Println(strings.Join(h, "\n"))
}

// 1027b
package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := int64(n)*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

package main
import (
	 "fmt"
		"math"
		)
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
			if (x+y)%2==0 {
					p = int(math.Ceil(float64(xy)/2))
				} else {
					p = n*n/2 + int(math.Ceil(float64(xy)/2))+1
				}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}


Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.In his favorite math class, the teacher taught him the following interesting definitions.A parenthesis sequence is a string, containing only characters "(" and ")".A correct parenthesis sequence is a parenthesis sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, parenthesis sequences "()()", "(())" are correct (the resulting expressions are: "(1+1)+(1+1)", "((1+1)+1)"), while ")(" and ")" are not. Note that the empty string is a correct parenthesis sequence by definition.We define that $$$|s|$$$ as the length of string $$$s$$$. A strict prefix $$$s[1\dots l]$$$ $$$(1\leq l< |s|)$$$ of a string $$$s = s_1s_2\dots s_{|s|}$$$ is string $$$s_1s_2\dots s_l$$$. Note that the empty string and the whole string are not strict prefixes of any string by the definition.Having learned these definitions, he comes up with a new problem. He writes down a string $$$s$$$ containing only characters "(", ")" and "?". And what he is going to do, is to replace each of the "?" in $$$s$$$ independently by one of "(" and ")" to make all strict prefixes of the new sequence not a correct parenthesis sequence, while the new sequence should be a correct parenthesis sequence.After all, he is just a primary school student so this problem is too hard for him to solve. As his best friend, can you help him to replace the question marks? If there are many solutions, any of them is acceptable.

The first line contains a single integer $$$|s|$$$ ($$$1\leq |s|\leq 3 \cdot 10^5$$$), the length of the string. The second line contains a string $$$s$$$, containing only "(", ")" and "?".

A single line contains a string representing the answer. If there are many solutions, any of them is acceptable. If there is no answer, print a single line containing ":(" (without the quotes).

NoteIt can be proved that there is no solution for the second sample, so print ":(".

package main

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

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

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]byte, n)
	fmt.Fscanf(buf, "%s\n", &mat)
	if 1 == (n%2) || mat[0] == ')' || mat[n-1] == '(' {
		fmt.Printf(":(\n")
		return
	}
	mat[0] = '('
	mat[n-1] = ')'
	cnt := 0
	for i := 0; i < n; i++ {
		if mat[i] == '(' {
			cnt++
		}
	}
	if cnt > n/2 {
		fmt.Printf(":(\n")
		return
	}
	cnt = n/2 - cnt
	for i := 1; i < n-1; i++ {
		if mat[i] == '?' {
			if cnt > 0 {
				mat[i] = '('
				cnt--
			} else {
				mat[i] = ')'
			}
		}
	}
	if cnt > 0 {
		fmt.Printf(":(\n")
		return
	}
	cnt = 0
	for i := 0; i < n-1; i++ {
		if mat[i] == '(' {
			cnt++
		} else {
			cnt--
		}
		if cnt == 0 {
			fmt.Printf(":(\n")
			return
		}
	}
	fmt.Printf("%s\n", mat)
}

/**
4
()?)
 */

package main

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

func main() {
    input := bufio.NewScanner(os.Stdin)
    inputbuf := make([]byte, 0, 64 * 1024)  // 64 KB of input buffer
    input.Buffer(inputbuf, 1024 * 1024)     // 1 MB of maximum token size
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ := strconv.Atoi(input.Text())

    if n <= 1 {
        fmt.Println(":(")
        return
    }

    input.Scan()
    s := input.Text()

    if s[0] == ')' || s[n - 1] == '(' {
        fmt.Println(":(")
        return
    }

    cr := make([]int, n, n)
    cl := make([]int, n, n)
    for i := n - 2; i >= 1; i-- {
        cr[i] = cr[i + 1]
        if s[i] != '(' {
            cr[i]++
        }
    }
    for i := n - 2; i >= 1; i-- {
        cl[i] = cl[i + 1]
        if s[i] == '(' {
            cl[i]++
        }
    }

    result := make([]byte, 0, n)
    result = append(result, '(')

    lp := 0
    for i := 1; i < n - 1; i++ {
        switch s[i] {
        case '(':
            lp++
            result = append(result, '(')

        case ')':
            lp--
            result = append(result, ')')

        case '?':
            if lp + 1 + cl[i + 1] <= cr[i + 1] {
                lp++
                result = append(result, '(')
            } else {
                lp--
                result = append(result, ')')
            }
        }

        if lp < 0 {
            fmt.Println(":(")
            return
        }
    }

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    result = append(result, ')')

    fmt.Println(string(result))
}

package main

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

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

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

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if n == 0 {
		fmt.Println()
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	if lefts < 0 {
		fmt.Println(":(")
		return
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1153/C

package main

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

func isValidSequence(n int, s []string) bool {
	left := 0
	right := 0
	for i := 0; i < n; i++ {
		if s[i] == "(" {
			left += 1
		} else if s[i] == ")" {
			right += 1
		}
		if right > left {
			return false
		}
		if 0 < i && i < n-1 && left == right {
			return false
		}
	}
	return left == right
}

func Solve(n int, s string) string {
	if n%2 == 1 {
		return ":("
	}
	leftRemaining := n / 2
	rightRemaining := n / 2
	for i := 0; i < n; i++ {
		if string(s[i]) == "(" {
			leftRemaining -= 1
		} else if string(s[i]) == ")" {
			rightRemaining -= 1
		}
	}
	answer := make([]string, n)
	for i := 0; i < n; i++ {
		if string(s[i]) != "?" {
			answer[i] = string(s[i])
		} else if string(s[i]) == "?" && leftRemaining > 0 {
			answer[i] = "("
			leftRemaining -= 1
		} else if string(s[i]) == "?" && rightRemaining > 0 {
			answer[i] = ")"
			rightRemaining -= 1
		}
	}
	if isValidSequence(n, answer) {
		return strings.Join(answer, "")
	}
	return ":("
}

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

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	fmt.Fprintf(writer, "%s\n", Solve(n, s))
}

package main

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

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

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]byte, n)
	fmt.Fscanf(buf, "%s\n", &mat)
	if 1==(n%1) || (mat[0]!='('&&mat[0]!='?')||(mat[n-1]!=')'&&mat[n-1]!='?'){
		fmt.Printf(":(\n")
		return
	}
	mat[0] = '('
	mat[n-1] =')'
	cnt := 0
	for i:=0;i < n;i++{
		if mat[i] == '('{
			cnt++
		}
	}
	if cnt > n/2{
		fmt.Printf(":(\n")
		return
	}
	cnt = n/2-cnt
	for i:=1;i < n-1;i++{
		if mat[i] == '?'{
			if cnt > 0{
				mat[i]='('
				cnt--
			}else{
				mat[i] = ')'
			}
		}
	}
	if cnt > 0{
		fmt.Printf(":(\n")
		return
	}
	cnt = 0
	for i:=0;i < n-1;i++{
		if mat[i]=='('{
			cnt++
		}else{
			cnt--
		}
		if cnt==0{
			fmt.Printf(":(\n")
			return
		}
	}
	fmt.Printf("%s\n",mat)
}

package main

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

func main() {
    input := bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)

    input.Scan()
    // Ignore n

    input.Scan()
    s := input.Text()

    result := make([]byte, 0, len(s))

    if s[0] == ')' || s[len(s) - 1] == '(' {
        fmt.Println(":(")
        return
    }
    if s[0] == '?' {
        result[0] = '('
    }

    lp := 0
    for i := 0; i < len(s) - 1; i++ {
        switch s[i] {
        case '(':
            result = append(result, '(')
            lp++

        case ')':
            result = append(result, ')')
            lp--

        case '?':
            if lp == 1 {
                result = append(result, '(')
                lp++
            } else {
                result = append(result, ')')
                lp--
            }
        }
    }
    result = append(result, ')')
    lp--

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    fmt.Println(string(result))
}

package main

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

func main() {
    input := bufio.NewScanner(os.Stdin)
    inputbuf := make([]byte, 0, 64 * 1024)  // 64 KB of input buffer
    input.Buffer(inputbuf, 1024 * 1024)     // 1 MB of maximum token size
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ := strconv.Atoi(input.Text())

    input.Scan()
    s := input.Text()

    if s[0] == ')' || s[n - 1] == '(' {
        fmt.Println(":(")
        return
    }

    cr := make([]int, n, n)
    cl := make([]int, n, n)
    for i := n - 2; i >= 1; i-- {
        cr[i] = cr[i + 1]
        if s[i] != '(' {
            cr[i]++
        }
    }
    for i := n - 2; i >= 1; i-- {
        cl[i] = cl[i + 1]
        if s[i] == '(' {
            cl[i]++
        }
    }

    result := make([]byte, 0, n)
    result = append(result, '(')

    lp := 0
    for i := 1; i < n - 1; i++ {
        switch s[i] {
        case '(':
            lp++
            result = append(result, '(')

        case ')':
            lp--
            result = append(result, ')')

        case '?':
            if lp + 1 + cl[i + 1] <= cr[i + 1] {
                lp++
                result = append(result, '(')
            } else {
                lp--
                result = append(result, ')')
            }
        }

        if lp < 0 {
            fmt.Println(":(")
            return
        }
    }

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    result = append(result, ')')

    fmt.Println(string(result))
}

package main

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

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

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

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	rights := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		} else if s[i] == ')' {
			rights--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == ')' && opened == 0 {
			fmt.Println(":(")
			return
		}
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
				opened++
			} else {
				s[i] = ')'
				opened--
				if opened < 0 {
					fmt.Println(":(")
					return
				}
			}
		}
	}

	fmt.Println(string(s))
}

package main

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

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

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

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if n == 0 {
		fmt.Println()
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

package main

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

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

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

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
				opened++
			} else {
				if opened == 0 {
					fmt.Println(":(")
					return
				}
				s[i] = ')'
				opened--
			}
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

package main

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

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

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

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1153/C

package main

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

func isValidSequence(n int, s []string) bool {
	left := 0
	right := 0
	for i := 0; i < n; i++ {
		if s[i] == "(" {
			left += 1
		} else if s[i] == ")" {
			right += 1
		}
		if right > left {
			return false
		}
		if 0 < i && i < n-1 && left == right {
			return false
		}
	}
	return left == right
}

func Solve(n int, s string) string {
	leftRemaining := n / 2
	rightRemaining := n / 2
	for i := 0; i < n; i++ {
		if string(s[i]) == "(" {
			leftRemaining -= 1
		} else if string(s[i]) == ")" {
			rightRemaining -= 1
		}
	}
	answer := make([]string, n)
	for i := 0; i < n; i++ {
		if string(s[i]) != "?" {
			answer[i] = string(s[i])
		} else if string(s[i]) == "?" && leftRemaining > 0 {
			answer[i] = "("
			leftRemaining -= 1
		} else if string(s[i]) == "?" && rightRemaining > 0 {
			answer[i] = ")"
			rightRemaining -= 1
		}
	}
	if isValidSequence(n, answer) {
		return strings.Join(answer, "")
	}
	return ":("
}

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

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	fmt.Fprintf(writer, "%s\n", Solve(n, s))
}