You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line. The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

package main

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

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

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

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

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

	x := make([]int, n)
	for i := 0; i < n; i++ {
		in.Scan()
		x[i], _ = strconv.Atoi(in.Text())
	}

	sort.Ints(x)

	sum := int64(0)
	pos := x[0]
	for i := 1; i < n; i++ {
		sum += int64(x[i]) - int64(pos)
	}
	best := sum

	for now := 1; now < n; now++ {
		inc := int64(now)
		dec := int64(n) - inc
		dist := int64(x[now]) - int64(x[now-1])

		sum -= dec * dist
		sum += inc * dist

		if sum < best {
			best = sum
			pos = x[now]
		}
	}

	out.WriteString(strconv.Itoa(pos))
	out.WriteByte('\n')
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt64()
	x := make([]int, n)
	var l, r, minDis, ans int64

	for i := range x {
		x[i] = nextInt()
	}

	sort.Ints(x)

	for i := int64(1); i < n; i++ {
		r += int64(x[i] - x[0])
	}

	minDis = r
	ans = int64(x[0])

	// println(l, r, l+r)
	for i := int64(1); i < n; i++ {
		l += int64(x[i]-x[i-1]) * i
		r -= int64(x[i]-x[i-1]) * (n - i)
		// println(l, r, l+r)

		if l+r < minDis {
			minDis = l + r
			ans = int64(x[i])
		}
	}
	println(ans)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

// http://codeforces.com/problemset/problem/710/B

package main

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

func main() {
	var n, tmp int

	input := bufio.NewReaderSize(os.Stdin, 1024*1024)
	fmt.Fscanln(input, &n)
	ans := (n - 1) / 2
	fing := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(input, &tmp)
		fing[i] = tmp
	}

	sort.Ints(fing)
	fmt.Println(fing[ans])
}

package main

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

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

	n := 0
	fmt.Fscan(reader, &n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &x[i])
	}
	sort.Ints(x)

	fmt.Fprintln(writer, x[(n-1)/2])
}

package main

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

var a[]int;
var ans[ 300010 ]int64;

func solve( n int ) ( res int ) {
	var tot, cnt int64 ;

	tot = 0 ;
	cnt = 0 ;

	for i := 1 ; i < n ; i ++ {
		diff := int64(a[ i ] - a[ i - 1 ]) ;
		tot = tot + int64( diff * cnt ) ;
		ans[ i ] = tot ;
		cnt = cnt + 1 ;
	}

	tot = 0 ;
	cnt = 0 ;

	for i := n - 2 ; i >= 0 ; i -- {
		diff := int64(a[ i + 1 ] - a[ i ]) ;
		tot = tot + ( diff * cnt ) ;
		ans[ i ] = ans[ i ] + tot ;
		cnt = cnt + 1 ;
	}

	mins := ans[ 0 ] ;
	ind := a[ 0 ] ;

	for i := 1 ; i < n ; i ++ {
		if mins > ans[ i ] {
			mins = ans[ i ] ;
			ind = a[ i ] ;
		}
	}

	res = ind ;
	return ;
}

func main() {

	var n int ;

	scanner := bufio.NewReader(os.Stdin)

//	scanner.Scan()
//    	fmt.Sscanf(scanner.Text(), "%d\n", &n)
	_, err := fmt.Fscanf(scanner,"%d\n",&n)
	if err != nil {
		fmt.Println("hi")
	}
//	fmt.Scanf("%d\n",&n) ;

	var x int ;

	//scanner.Scan()
//	scanner.Split(bufio.ScanWords)
//	scanner.Scan()
	for i := 0 ; i < n ; i ++ {
		fmt.Fscanf(scanner, "%d", &x);
//		x , err := strconv.Atoi(scanner.Text())

		//if err != nil {
		//fmt.Sscanf(scanner.Text(), "%d", &x ) ;
//		fmt.Println(x)
		a = append( a , x ) ;
		//}
	}

	sort.Ints(a);
	res := solve( n )

	fmt.Println(res);
}

package main

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

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

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

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

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

	x := make([]int, n+1)
	for i := 1; i <= n; i++ {
		in.Scan()
		x[i], _ = strconv.Atoi(in.Text())
	}

	sort.Ints(x)

	sum := int64(0)
	for i := 2; i <= n; i++ {
		sum += int64(x[i]) - int64(x[1])
	}

	best := sum
	pos := x[1]

	for now := 2; now <= n; now++ {
		inc := int64(now - 1)
		dec := int64(n - now + 1)
		dist := int64(x[now]) - int64(x[now-1])

		sum -= dec * dist
		sum += inc * dist

		if sum < best {
			best = sum
			pos = x[now]
		}
	}

	out.WriteString(strconv.Itoa(pos))
}

package main

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

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

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

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

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

	x := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		in.Scan()
		x[i], _ = strconv.ParseInt(in.Text(), 10, 64)
	}

	sum := int64(0)
	for i := 2; i <= n; i++ {
		sum += x[i] - x[1]
	}

	best := sum
	pos := x[1]

	for now := 2; now <= n; now++ {
		inc := int64(now - 1)
		dec := int64(n - now + 1)
		dist := x[now] - x[now-1]

		sum -= dec * dist
		sum += inc * dist

		if sum < best {
			best = sum
			pos = x[now]
		}
	}

	out.WriteString(strconv.FormatInt(pos, 10))
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	x := make([]int, n)
	l, r, minDis, ans := 0, 0, 0, 0

	for i := range x {
		x[i] = nextInt()
	}

	sort.Ints(x)

	for i := 1; i < n; i++ {
		r += x[i] - x[0]
	}

	minDis = r
	ans = x[0]

	// println(l, r, l+r)
	for i := 1; i < n; i++ {
		l += (x[i] - x[i-1]) * i
		r -= (x[i] - x[i-1]) * (n - i)
		// println(l, r, l+r)

		if l+r < minDis {
			minDis = l + r
			ans = x[i]
		}
	}
	println(ans)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

type Point struct {
	v, i int
}

type ByValue []Point

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	x := make([]Point, n)
	l, r, minDis, inx := 0, 0, 0, 0

	for i := range x {
		x[i].v = nextInt()
		x[i].i = i
	}

	sort.Sort(ByValue(x))

	for i := 1; i < n; i++ {
		r += x[i].v - x[0].v
	}

	minDis = r
	for i := 1; i < n; i++ {
		l += (x[i].v - x[i-1].v) * i
		r -= (x[i].v - x[i-1].v) * (n - i)
		// println(l, r)

		if l+r < minDis {
			minDis = l + r
			inx = i
		}
	}

	println(x[inx].i + 1)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	x := make([]int, n)
	l, r, minDis, ans := 0, 0, 0, 0

	for i := range x {
		x[i] = nextInt()
	}

	sort.Ints(x)

	for i := 1; i < n; i++ {
		r += x[i] - x[0]
	}

	minDis = r
	for i := 1; i < n; i++ {
		l += (x[i] - x[i-1]) * i
		r -= (x[i] - x[i-1]) * (n - i)
		// println(l, r)

		if l+r < minDis {
			minDis = l + r
			ans = i
		}
	}

	println(ans + 1)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var a[]int;
var ans[ 100010 ]int;

func solve( n int ) ( res int ) {
	tot := 0 ;
	cnt := 0 ;

	for i := 1 ; i < n ; i ++ {
		diff := a[ i ] - a[ i - 1 ] ;
		tot = tot + ( diff * cnt ) ;
		ans[ i ] = tot ;
		cnt = cnt + 1 ;
	}

	tot = 0 ;
	cnt = 0 ;

	for i := n - 2 ; i >= 0 ; i -- {
		diff := a[ i + 1 ] - a[ i ] ;
		tot = tot + ( diff * cnt ) ;
		ans[ i ] = ans[ i ] + tot ;
		cnt = cnt + 1 ;
	}

	mins := ans[ 0 ] ;
	ind := a[ 0 ] ;

	for i := 1 ; i < n ; i ++ {
		if mins > ans[ i ] {
			mins = ans[ i ] ;
			ind = a[ i ] ;
		}
	}

	res = ind ;
	return ;
}

func main() {

	var n int ;

	scanner := bufio.NewReader(os.Stdin)

//	scanner.Scan()
//    	fmt.Sscanf(scanner.Text(), "%d\n", &n)
	_, err := fmt.Fscanf(scanner,"%d\n",&n)
	if err != nil {
		fmt.Println("hi")
	}
//	fmt.Scanf("%d\n",&n) ;

	var x int ;

	//scanner.Scan()
//	scanner.Split(bufio.ScanWords)
//	scanner.Scan()
	for i := 0 ; i < n ; i ++ {
		fmt.Fscanf(scanner, "%d", &x);
//		x , err := strconv.Atoi(scanner.Text())

		//if err != nil {
		//fmt.Sscanf(scanner.Text(), "%d", &x ) ;
//		fmt.Println(x)
		a = append( a , x ) ;
		//}
	}

	sort.Ints(a);
	res := solve( n )

	fmt.Println(res);
}


A sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Given two integers $$$n$$$ and $$$k$$$, construct a permutation $$$a$$$ of numbers from $$$1$$$ to $$$n$$$ which has exactly $$$k$$$ peaks. An index $$$i$$$ of an array $$$a$$$ of size $$$n$$$ is said to be a peak if $$$1 < i < n$$$ and $$$a_i \gt a_{i-1}$$$ and $$$a_i \gt a_{i+1}$$$. If such permutation is not possible, then print $$$-1$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing two space-separated integers $$$n$$$ ($$$1 \leq n \leq 100$$$) and $$$k$$$ ($$$0 \leq k \leq n$$$) — the length of an array and the required number of peaks.

Output $$$t$$$ lines. For each test case, if there is no permutation with given length and number of peaks, then print $$$-1$$$. Otherwise print a line containing $$$n$$$ space-separated integers which forms a permutation of numbers from $$$1$$$ to $$$n$$$ and contains exactly $$$k$$$ peaks.  If there are multiple answers, print any.

NoteIn the second test case of the example, we have array $$$a = [2,4,1,5,3]$$$. Here, indices $$$i=2$$$ and $$$i=4$$$ are the peaks of the array. This is because $$$(a_{2} \gt a_{1} $$$, $$$a_{2} \gt a_{3})$$$ and $$$(a_{4} \gt a_{3}$$$, $$$a_{4} \gt a_{5})$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		max := (n - 1) / 2
		if k > max {
			Fprintln(out, -1)
			continue
		}
		dir := 1
		peek := 0
		cur := 0
		for i := 0; i < n; i++ {
			var num int
			if dir == 1 {
				num = cur + 1
			} else {
				num = n - cur
				peek++
			}

			if peek != k {
				dir *= -1
				cur = (i + 1) / 2
			} else {
				dir = 1
				cur = cur + 1
			}
			Fprint(out, num, " ")
		}
		Fprint(out, "\n")
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scanf("%d %d\n", &n, &k)
		max_peak := (n - 1) / 2
		if max_peak < k {
			fmt.Println("-1")
			continue
		}

		fmt.Print("1")
		for i := 1; i <= k; i++ {
			fmt.Printf(" %d %d", i*2+1, i*2)
		}
		for i := 2*k + 2; i <= n; i++ {
			fmt.Printf(" %d", i)
		}
		fmt.Println()

	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		if (n < 3 || n-k <= n/2) && k != 0 {
			fmt.Fprintln(out,-1)
			continue
		}
		var marker int
		for j:=1;j<=n/2;j++{
			if k == 0 {
				marker = j
				goto out
			}
			fmt.Fprintf(out,"%v %v ",j,n+1-j)
			k--
		}
		if n & 1 == 1 {
			fmt.Fprintf(out,"%v",n/2+1)
		}
		fmt.Fprintln(out)
		continue
		out:
		for j:=marker;j<=n+1-marker;j++{
			fmt.Fprintf(out,"%v ",j)
		}
		fmt.Fprintln(out)
	}
}

// arrange a permutation of size n, with only* k peaks
// a peak is an indice that isn't on the edge ie; i != 1 or n-1 and is greater than its adjacents
// n,k = 5,2 	[1 4^ 3 5^ 2] 	^ = peak
// sort array: pair smallest with largest: [1 5^ 2 4^ 3] j,n+1-j

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, n, k int
	fmt.Scanln(&t)

	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&k)
		if int(math.Ceil(float64(n)/2.)) <= k {
			fmt.Println("-1")
		} else {
			o, e := 1, n
			for i := 1; i <= n; i++ {
				if i&1 != 1 && k > 0 {
					fmt.Print(e, " ")
					e--
					k--
				} else {
					fmt.Print(o, " ")
					o++
				}
			}
			fmt.Println()
		}
		t--
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		K := sc.NextInt()

		if K > (N-1)/2 {
			fmt.Fprintln(wr, "-1")
		} else {
			low := 1
			high := N
			for i := 0; i < N; i++ {
				if i%2 == 0 || K == 0 {
					fmt.Fprint(wr, low, " ")
					low++
					if i > 0 && K > 0 {
						K--
					}
				} else {
					fmt.Fprint(wr, high, " ")
					high--
				}
			}
			fmt.Fprintln(wr)
		}
	}
}

package main

import "fmt"

func permutate(arrSize, peak int ) []int {
	maxpeak := (arrSize - 1) / 2
	if peak > maxpeak {
		return []int{-1}
	}
	processedPeak := 0
	val := []int{1}
	for i:=2; i<= arrSize; {
		if (arrSize+1)-i >=2 && processedPeak < peak {
			val = append(val, i+1)
			val = append(val, i)
			i +=2
			processedPeak += 1
		} else {
			val = append(val, i)
			i +=1
		}
	}
	return val
}

func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)
	for i:=0 ; i< testCases ; i++ {
		var arrSize int
		var peak int
		fmt.Scanf("%d %d\n", &arrSize, &peak)
		permArr := permutate(arrSize, peak)
		for i:=0 ; i < len(permArr); i++ {
			fmt.Printf("%d ", permArr[i])
		}
		fmt.Println()
	}
}

package main

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

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

	solve := func(Case int) {
		var n, k int
		Fscan(in, &n, &k)
		l, r := 1, n
		i := 0
		a := make([]int, n)
		for ; i+1 < n && k > 0; k-- {
			a[i] = l
			a[i+1] = r
			l++
			r--
			i += 2
		}
		if i >= n || k > 0 {
			Fprintln(out, -1)
			return
		}
		for ; i < n; i++ {
			a[i] = l
			l++
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

func solve(n, k int) string {
	if k > (n-1)/2 {
		return "-1"
	}
	r := "1"
	for i := 1; i <= k; i++ {
		r += fmt.Sprintf(" %d %d", 2*i+1, 2*i)
	}
	for i := 2*k + 2; i <= n; i++ {
		r += fmt.Sprintf(" %d", i)
	}
	return r
}

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

package main

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

type CF1513A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1513A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1513A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1513A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1513A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1513A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
 Run solve the problem CF1513A
 Date: 21/04/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1513/A
 Problem: CF1513A
**/
func (in *CF1513A) Run() {
	N := in.NextInt()
	for ; N > 0; N-- {
		n := in.NextInt()
		k := in.NextInt()
		var arr []int
		for i := 0; i < n; i++ {
			arr = append(arr, i+1)
		}
		count := 0
		for i := 2; i < n && count < k; i += 2 {
			aux := arr[i]
			arr[i] = arr[i-1]
			arr[i-1] = aux
			count++
		}

		if count == k {
			for i := 0; i < n; i++ {
				if i > 0 {
					fmt.Print(" ")
				}
				fmt.Print(arr[i])
			}
			fmt.Println()
		} else {
			fmt.Println(-1)
		}
	}
}

func NewCF1513A(r *bufio.Reader) *CF1513A {
	return &CF1513A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1513A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

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

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

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

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

		if 2*k >= n {
			fmt.Println(-1)
			continue
		}

		a := make([]int, n)

		for i := 1; k > 0; i, n, k = i+2, n-1, k-1 {
			a[i] = n
		}

		for i := range a {
			if a[i] == 0 {
				a[i] = n
				n--
			}
		}

		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

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

}

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

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

	for o := 0; o < t; o++ {
		var n, k int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)
		if n%2 == 0 {
			l := int(n/2) - 1
			if k > l {
				fmt.Println(-1)
			} else {
				for i := 1; i < k+1; i++ {
					fmt.Println(i)
					fmt.Println(n - i + 1)
				}
				for j := k + 1; j < n-k+1; j++ {
					fmt.Println(j)
				}
			}
		} else {
			l := int(n / 2)
			if k > l {
				fmt.Println(-1)
			} else {
				for i := 1; i < k+1; i++ {
					fmt.Println(i)
					fmt.Println(n - i + 1)
				}
				for j := k + 1; j < n-k+1; j++ {
					fmt.Println(j)
				}
			}
		}

	}
}

package main

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

var in *bufio.Reader = bufio.NewReader(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var t int
	Fscan(in, &t)

	for cases := 0; cases < t; cases++ {
		var n, k, maxPeak int
		Fscan(in, &n, &k)
		if n % 2 == 0 {
			maxPeak = (n/2) - 1
		} else {
			maxPeak = ((n+1)/2) - 1
		}

		if k > maxPeak {
			Fprintln(out, -1)
		} else if k == 0 {
			for i := 1; i <= n; i++ {
				Fprintf(out, "%d ", i)
			}
			Fprintln(out)
		} else {
			var maxPeakNumber []int
			maxPeak = k
			saveMaxPeak := maxPeak
			for i := n; i >= 1; i-- {
				maxPeak--
				maxPeakNumber = append(maxPeakNumber, i)
				if maxPeak == 0 {
					break
				}
			}

			idxMaxPeak := 0
			for i := 1; i <= (n-saveMaxPeak); i++ {
				Fprintf(out, "%d ", i)
				if idxMaxPeak < len(maxPeakNumber)  {
					Fprintf(out, "%d ", maxPeakNumber[idxMaxPeak])
					idxMaxPeak++
				}
			}
			Fprintln(out)
		}
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		max := (n - 1) / 2
		if k > max {
			Fprintln(out, -1)
		}
		dir := 1
		peek := 0
		cur := 0
		for i := 0; i < n; i++ {
			var num int
			if dir == 1 {
				num = cur + 1
			} else {
				num = n - cur
				peek++
			}

			if peek != k {
				dir *= -1
				cur = (i + 1) / 2
			} else {
				dir = 1
				cur = cur + 1
			}
			Fprint(out, num, " ")
		}
		Fprint(out, "\n")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		max := (n - 1) / 2
		if k > max {
			Fprintln(out, -1)
		}
		for i, cur, dir := 0, 0, 1; i < n; i, cur, dir = i+1, (i+1)/2, dir*-1 {
			var num int
			if dir == 1 {
				num = cur + 1
			} else {
				num = n - cur
			}
			Fprint(out, num, " ")
		}
		Fprint(out, "\n")
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scanf("%d %d", &n, &k)
		max_peak := (n - 1) / 2
		if max_peak < k {
			fmt.Println("-1")
			continue
		}

		fmt.Print("1")
		for i := 1; i <= k; i++ {
			fmt.Printf(" %d %d", i*2+1, i*2)
		}
		for i := 2*k + 2; i <= n; i++ {
			fmt.Printf(" %d", i)
		}
		fmt.Println()

	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		if (n < 3 || n-k <= n/2) && k != 0 {
			fmt.Fprintln(out,-1)
			continue
		}
		for j:=1;j<=n/2;j++{
			fmt.Fprintf(out,"%v %v ",j,n+1-j)
		}
		if n & 1 == 1 {
			fmt.Fprintf(out,"%v",n/2+1)
		}
		fmt.Fprintln(out)
	}
}

// arrange a permutation of size n, with k peaks
// a peak is an indice that isn't on the edge ie; i != 1 or n-1 and is greater than its adjacents
// n,k = 5,2 	[1 4^ 3 5^ 2] 	^ = peak
// sort array: pair smallest with largest: [1 5^ 2 4^ 3] j,n+1-j

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, n, k int
	fmt.Scanln(&t)

	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&k)
		if int(math.Ceil(float64(n)/2.)) <= k {
			fmt.Println("-1")
		} else {
			o, e := 1, int(math.Ceil(float64(n)/2.))+1
			for i := 1; i <= n; i++ {
				if i&1 == 1 {
					fmt.Print(o, " ")
					o++
				} else {
					fmt.Print(e, " ")
					e++
				}
			}
			fmt.Println()
		}
		t--
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		K := sc.NextInt()

		if K > (N-1)/2 {
			fmt.Fprintln(wr, "-1")
		} else {
			low := 1
			high := N
			for i := 0; i < N; i++ {
				if i%2 == 0 || K == 0 {
					fmt.Fprint(wr, low, " ")
					low++
					if i > 0 {
						K--
					}
				} else {
					fmt.Fprint(wr, high, " ")
					high--
				}
			}
			fmt.Fprintln(wr)
		}
	}
}

package main

import "fmt"

func permutate(arrSize, peak int ) []int {
	maxpeak := (arrSize - 1) / 2
	if peak > maxpeak {
		return []int{-1}
	}
	processedPeak := 0
	val := []int{1}
	for i:=2; i< arrSize+1; {
		if arrSize-i >=2 && processedPeak < peak {
			val = append(val, i+1)
			val = append(val, i)
			i +=2
			processedPeak += 1
		} else {
			val = append(val, i)
			i +=1
		}
	}
	return val
}

func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)
	for i:=0 ; i< testCases ; i++ {
		var arrSize int
		var peak int
		fmt.Scanf("%d %d\n", &arrSize, &peak)
		permArr := permutate(arrSize, peak)
		for i:=0 ; i < len(permArr); i++ {
			fmt.Printf("%d ", permArr[i])
		}
		fmt.Println()
	}
}


For the multiset of positive integers $$$s=\{s_1,s_2,\dots,s_k\}$$$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $$$s$$$ as follow: $$$\gcd(s)$$$ is the maximum positive integer $$$x$$$, such that all integers in $$$s$$$ are divisible on $$$x$$$. $$$\textrm{lcm}(s)$$$ is the minimum positive integer $$$x$$$, that divisible on all integers from $$$s$$$.For example, $$$\gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6$$$ and $$$\textrm{lcm}(\{4,6\})=12$$$. Note that for any positive integer $$$x$$$, $$$\gcd(\{x\})=\textrm{lcm}(\{x\})=x$$$.Orac has a sequence $$$a$$$ with length $$$n$$$. He come up with the multiset $$$t=\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\}$$$, and asked you to find the value of $$$\gcd(t)$$$ for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.

The first line contains one integer $$$n\ (2\le n\le 100\,000)$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 200\,000$$$).

Print one integer: $$$\gcd(\{\textrm{lcm}(\{a_i,a_j\})\ |\ i<j\})$$$.

/*
URL:
https://codeforces.com/contest/1350/problem/C
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	n int
	A []int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	F, B := make([]int64, n), make([]int64, n)
	F[0] = A[0]
	for i := 1; i < n; i++ {
		F[i] = Gcd(F[i-1], A[i])
	}
	B[n-1] = A[n-1]
	for i := n - 2; i >= 0; i-- {
		B[i] = Gcd(B[i+1], A[i])
	}

	D := make([]int64, n)
	D[0] = B[1]
	D[n-1] = F[n-2]
	for i := 1; i < n-1; i++ {
		D[i] = Gcd(F[i-1], B[i+1])
	}

	ans := int64(1)
	for i := 0; i < n; i++ {
		ans = Lcm(ans, D[i])
	}
	fmt.Println(ans)
}

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

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1350C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 2e5
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	var n, v int
	Fscan(in, &n)
	ps := [mx][]int{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		for v > 1 {
			p, e := lpf[v], 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			ps[p] = append(ps[p], e)
		}
	}
	ans := int64(1)
	for p, es := range ps {
		if len(es) >= n-1 {
			sort.Ints(es)
			for e := es[len(es)-n+1]; e > 0; e-- {
				ans *= int64(p)
			}
		}
	}
	Fprint(_w, ans)
}

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

package main

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

func main() {
	n := ScanInt()
	a := ScanInt64Slice(n)
	a = append([]int64{0}, a...)
	//n := 4
	//a := []int{0, 10, 24, 40, 80}

	gcdAns := solv(n, a)

	P(gcdAns)

	close(O)
	oWg.Wait()
}

func solv(n int, a []int64) int64 {
	sfx := make([]int64, n+1)
	pre := make([]int64, n+1)
	pre[1] = a[1]
	sfx[n] = a[n]

	for i := n - 1; i >= 1; i-- {
		sfx[i] = GCD(sfx[i+1], a[i])
	}

	for i := 1; i <= n; i++ {
		pre[i] = GCD(a[i], pre[i-1])
	}
	//P("inp: ", a)
	//P("suf: ", sfx)
	//P("prf: ", pre)

	ans := int64(0)
	for i := 0; i <= n-1; i++ {
		if i == 0 {
			ans = sfx[2]
		} else if i == n-1 {
			ans = ans * pre[n-1] / GCD(pre[n-1], ans)
		} else {
			ans = ans * GCD(pre[i], sfx[i+2]) / GCD(GCD(pre[i], sfx[i+2]), ans)
		}
	}
	return ans
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

func main() {
	n := ScanInt()
	a := ScanInt64Slice(n)
	a = append([]int64{0}, a...)
	//n := 4
	//a := []int64{0, 10, 24, 40, 80}

	gcdAns := solv2(n, a)

	P(gcdAns)

	close(O)
	oWg.Wait()
}

func solv2(n int, a []int64) int64 {
	suf := make([]int64, n+2)
	suf[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		suf[i] = GCD(suf[i+1], a[i])
	}
	//P("Suf:", suf)

	b := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		b[i] = (a[i] * suf[i+1]) / GCD(a[i], suf[i+1])
	}
	//P("b:", b)

	ans := b[1]
	for i := 2; i <= n; i++ {
		ans = GCD(ans, b[i])
	}
	//P("ans", ans)
	return ans
}

func solv1(n int, a []int64) int64 {
	sfx := make([]int64, n+1)
	pre := make([]int64, n+1)
	pre[1] = a[1]
	sfx[n] = a[n]

	for i := n - 1; i >= 1; i-- {
		sfx[i] = GCD(sfx[i+1], a[i])
	}

	for i := 1; i <= n; i++ {
		pre[i] = GCD(a[i], pre[i-1])
	}
	//P("inp: ", a)
	//P("suf: ", sfx)
	//P("prf: ", pre)

	ans := int64(0)
	for i := 0; i <= n-1; i++ {
		if i == 0 {
			ans = sfx[2]
		} else if i == n-1 {
			ans = ans * pre[n-1] / GCD(pre[n-1], ans)
		} else {
			ans = ans * GCD(pre[i], sfx[i+2]) / GCD(GCD(pre[i], sfx[i+2]), ans)
		}
	}
	return ans
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

func
S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}

func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

const N = 100010
var n int
var a[N] int64

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

func lcm(a int64, b int64) int64 {
	var z = gcd(a, b)
	return a / z * b
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var suGcd = make([]int64, n + 1)
	var z = make([]int64, n + 1)

	suGcd[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		suGcd[i] = gcd(suGcd[i + 1], a[i])
	}

	for i := 1; i < n; i++ {
		z[i] = lcm(a[i], suGcd[i + 1])
	}

	var ret = z[1]
	for i := 2; i < n; i++ {
		ret = gcd(ret, z[i])
	}

	fmt.Fprintf(writer, "%d\n", ret)
}

package main

import "fmt"

func pow(n, p int) int64 {
	if p == 0 {
		return 1
	}
	ret := pow(n, p/2)
	ret = ret * ret
	if p%2 == 1 {
		ret *= int64(n)
	}
	return ret
}

func main() {
	n := int(1e6)*2 + 10
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	factors := func(n int) map[int]int {
		ret := make(map[int]int)
		for n > 1 {
			ret[data[n]]++
			n /= data[n]
		}
		return ret
	}

	fmt.Scan(&n)
	min1 := make(map[int]int)
	min2 := make(map[int]int)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		for k, v := range factors(a) {
			if min1[k] == 0 || min1[k] > v {
				min2[k] = min1[k]
				min1[k] = v
			} else if min2[k] == 0 || min2[k] > v {
				min2[k] = v
			}
			cnt[k]++
		}
	}

	ans := int64(1)
	for k, v := range cnt {
		if v == n-1 {
			ans *= pow(k, min1[k])
		}
		if v == n {
			ans *= pow(k, min2[k])
		}
	}
	fmt.Println(ans)
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	a := make([]int64, n)
	for i := range a {
		a[i] = reader.NextInt64()
	}
	writer.Printf("%d\n", sol(a))
}

func sol(a []int64) int64 {
	if len(a) == 1 {
		return a[0]
	}
	pref := make([]int64, len(a))
	pref[0] = a[0]
	for i := 1; i < len(a); i++ {
		pref[i] = gcd(pref[i-1], a[i])
	}
	suf := make([]int64, len(a))
	suf[len(suf)-1] = a[len(a)-1]
	for i := len(a)-2; i >= 0; i-- {
		suf[i] = gcd(suf[i+1], a[i])
	}
	ret := int64(1)
	for i := range a {
		if i == 0 {
			ret = lcm(ret, suf[1])
			continue
		}
		if i == len(a)-1 {
			ret = lcm(ret, pref[len(pref)-2])
			continue
		}
		ret = lcm(ret, gcd(pref[i-1], suf[i+1]))
	}
	return ret
}

/*
URL:
https://codeforces.com/problemset/problem/1349/A
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	n int
	A []int64

	P [200000 + 5][]int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	for i := 0; i < n; i++ {
		if A[i] == 1 {
			continue
		}

		memo := TrialDivision(A[i])
		for k, v := range memo {
			P[k] = append(P[k], v)
		}
	}

	ans := int64(1)
	for i := 0; i <= 200000; i++ {
		if len(P[i]) >= n-1 {
			sort.Slice(P[i], func(j, k int) bool { return P[i][j] < P[i][k] })

			var e int64
			if len(P[i]) == n-1 {
				e = P[i][0]
			} else {
				e = P[i][1]
			}
			ans *= PowInt(int64(i), e)
		}
	}
	fmt.Println(ans)
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	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)
}

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int64) map[int64]int64 {
	var i, exp int64
	p := map[int64]int64{}

	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	for i = 2; i*i <= n; i++ {
		exp = 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1350/problem/C
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	n int
	A []int

	memo [200000 + 50][30 + 5]int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	F, B := make([]int, n), make([]int, n)
	F[0] = A[0]
	for i := 1; i < n; i++ {
		F[i] = Gcd(F[i-1], A[i])
	}
	B[n-1] = A[n-1]
	for i := n - 2; i >= 0; i-- {
		B[i] = Gcd(B[i+1], A[i])
	}

	D := make([]int, n)
	D[0] = B[1]
	D[n-1] = F[n-2]
	for i := 1; i < n-1; i++ {
		D[i] = Gcd(F[i-1], B[i+1])
	}

	ans := 1
	for i := 0; i < n; i++ {
		ans = Lcm(ans, D[i])
	}
	fmt.Println(ans)
}

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

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

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int) map[int]int {
	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	p := map[int]int{}
	for i := 2; i*i <= n; i++ {
		exp := 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

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

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1350C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 2e5
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	var n, v int
	Fscan(in, &n)
	ps := [mx][]int{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		for v > 1 {
			p, e := lpf[v], 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			ps[p] = append(ps[p], e)
		}
	}
	ans := 1
	for p, es := range ps {
		if len(es) >= n-1 {
			sort.Ints(es)
			for e := es[len(es)-n+1]; e > 0; e-- {
				ans *= p
			}
		}
	}
	Fprint(_w, ans)
}

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

package main

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

func main() {
	n := ScanInt()
	a := ScanIntSlice(n)
	a = append([]int{0}, a...)
	//n := 4
	//a := []int{0, 10, 24, 40, 80}

	gcdAns := solv(n, a)

	P(gcdAns)

	close(O)
	oWg.Wait()
}

func solv(n int, a []int) int {
	sfx := make([]int, n+1)
	pre := make([]int, n+1)

	for i := n - 1; i >= 1; i-- {
		sfx[i] = GCD(sfx[i+1], a[i])
	}

	for i := 1; i <= n; i++ {
		pre[i] = GCD(a[i], pre[i-1])
	}
	//P("inp: ", a)
	//P("suf: ", sfx)
	//P("prf: ", pre)

	ans := 0
	for i := 0; i <= n-1; i++ {
		if i == 0 {
			ans = sfx[2]
		} else if i == n-1 {
			ans = ans * pre[n-1] / GCD(pre[n-1], ans)
		} else {
			ans = ans * GCD(pre[i], sfx[i+2]) / GCD(GCD(pre[i], sfx[i+2]), ans)
		}
	}
	return ans
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

func main() {
	n := ScanInt()
	a := ScanIntSlice(n)
	a = append([]int{0}, a...)
	//n := 4
	//a := []int{0, 10, 24, 40, 80}

	gcdAns := solv(n, a)

	P(gcdAns)

	close(O)
	oWg.Wait()
}

func solv(n int, a []int) int {
	sfx := make([]int, n+1)
	pre := make([]int, n+1)
	pre[1]=a[1]
	sfx[n]=a[n]

	for i := n - 1; i >= 1; i-- {
		sfx[i] = GCD(sfx[i+1], a[i])
	}

	for i := 1; i <= n; i++ {
		pre[i] = GCD(a[i], pre[i-1])
	}
	//P("inp: ", a)
	//P("suf: ", sfx)
	//P("prf: ", pre)

	ans := 0
	for i := 0; i <= n-1; i++ {
		if i == 0 {
			ans = sfx[2]
		} else if i == n-1 {
			ans = ans * pre[n-1] / GCD(pre[n-1], ans)
		} else {
			ans = ans * GCD(pre[i], sfx[i+2]) / GCD(GCD(pre[i], sfx[i+2]), ans)
		}
	}
	return ans
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

func main() {
	//n := ScanInt()
	//a := ScanIntSlice(n)
	n := 4
	a := []int{0, 10, 24, 40, 80}

	gcdAns := solv(n, a)

	P("g: ", gcdAns)

	close(O)
	oWg.Wait()
}

func solv(n int, a []int) int {
	sfx := make([]int, n+1)
	pre := make([]int, n+1)

	for i := n - 1; i >= 1; i-- {
		sfx[i] = GCD(sfx[i+1], a[i])
	}

	for i := 1; i <= n; i++ {
		pre[i] = GCD(a[i], pre[i-1])
	}
	P("inp: ", a)
	P("suf: ", sfx)
	P("prf: ", pre)

	ans := 0
	for i := 0; i <= n-1; i++ {
		if i == 0 {
			ans = sfx[2]
		} else if i == n-1 {
			ans = ans * pre[n-1] / GCD(pre[n-1], ans)
		} else {
			ans = ans * GCD(pre[i], sfx[i+2]) / GCD(GCD(pre[i], sfx[i+2]), ans)
		}
	}
	return ans
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

const N = 100010
var n int
var a[N] int

func gcd(a int, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a int, b int) int {
	var z = gcd(a, b)
	return a / z * b
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var suGcd = make([]int, n + 1)
	var z = make([]int, n + 1)

	suGcd[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		suGcd[i] = gcd(suGcd[i + 1], a[i])
	}
	z[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		z[i] = lcm(suGcd[i + 1], a[i])
	}

	var ret = z[1]
	for i := 2; i < n; i++ {
		ret = gcd(ret, z[i])
	}

	fmt.Fprintf(writer, "%d\n", ret)
}

package main

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

const N = 100010
var n int
var a[N] int

func gcd(a int, b int) int {
	if a < b {
		a, b = b, a
	}
	if b == 0 {
		return a
	}
	return gcd(a % b, b)
}

func lcm(a int, b int) int {
	var z = gcd(a, b)
	return a / z * b
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var suGcd = make([]int, n + 1)
	var z = make([]int, n + 1)

	suGcd[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		suGcd[i] = gcd(suGcd[i + 1], a[i])
	}
	z[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		z[i] = lcm(suGcd[i + 1], a[i])
	}

	var ret = z[1]
	for i := 2; i <= n; i++ {
		ret = gcd(ret, z[i])
	}

	fmt.Fprintf(writer, "%d\n", ret)
}

package main

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

const N = 100010
var n int
var a[N] int

func gcd(a int, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a int, b int) int {
	var z = gcd(a, b)
	return a / z * b
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var suGcd = make([]int, n + 1)
	var z = make([]int, n + 1)

	suGcd[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		suGcd[i] = gcd(suGcd[i + 1], a[i])
	}
	z[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		z[i] = lcm(suGcd[i + 1], a[i])
	}

	var ret = z[1]
	for i := 2; i <= n; i++ {
		ret = gcd(ret, z[i])
	}

	fmt.Fprintf(writer, "%d\n", ret)
}

package main

import "fmt"

func main() {
	n := int(1e6)*2 + 10
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	factors := func(n int) map[int]int {
		ret := make(map[int]int)
		for n > 1 {
			ret[data[n]]++
			n /= data[n]
		}
		return ret
	}

	fmt.Scan(&n)
	min1 := make(map[int]int)
	min2 := make(map[int]int)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		for k, v := range factors(a) {
			if min1[k] == 0 || min1[k] > v {
				min2[k] = min1[k]
				min1[k] = v
			} else if min2[k] == 0 || min2[k] > v {
				min2[k] = v
			}
			cnt[k]++
		}
	}

	var pow func(n, p int) int64
	pow = func(n, p int) int64 {
		if p == 0 {
			return 1
		}
		ret := pow(n, p/2)
		ret = ret * ret
		if p%2 == 1 {
			ret *= int64(n)
		}
		return ret
	}

	ans := int64(1)
	for k, v := range cnt {
		if v < n-1 {
			continue
		}
		ans *= pow(k, min2[k])
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	n := int(1e6)*2 + 10
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	factors := func(n int) map[int]int {
		ret := make(map[int]int)
		for n > 1 {
			ret[data[n]]++
			n /= data[n]
		}
		return ret
	}

	fmt.Scan(&n)
	min1 := make(map[int]int)
	min2 := make(map[int]int)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		for k, v := range factors(a) {
			m1, ok1 := min1[k]
			m2, ok2 := min2[k]
			if !ok1 || m1 > v {
				if ok1 {
					min2[k] = min1[k]
				}
				min1[k] = v
			} else if !ok2 || m2 > v {
				min2[k] = v
			}
			cnt[k]++
		}
	}

	var pow func(n, p int) int64
	pow = func(n, p int) int64 {
		if p == 0 {
			return 1
		}
		ret := pow(n, p/2)
		ret = ret * ret
		if p%2 == 1 {
			ret *= int64(n)
		}
		return ret
	}

	ans := int64(1)
	for k, v := range cnt {
		if v < n-1 {
			continue
		}
		ans *= pow(k, min2[k])
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	n := int(1e6)*2 + 10
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	factors := func(n int) map[int]int {
		ret := make(map[int]int)
		for n > 1 {
			ret[data[n]]++
			n /= data[n]
		}
		return ret
	}

	fmt.Scan(&n)
	min1 := make(map[int]int)
	min2 := make(map[int]int)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		for k, v := range factors(a) {
			m1, ok1 := min1[k]
			m2, ok2 := min2[k]
			if !ok1 || m1 > v {
				min2[k] = min1[k]
				min1[k] = v
			} else if !ok2 || m2 > v {
				min2[k] = v
			}
			cnt[k]++
		}
	}

	var pow func(n, p int) int64
	pow = func(n, p int) int64 {
		if p == 0 {
			return 1
		}
		ret := pow(n, p/2)
		ret = ret * ret
		if p%2 == 1 {
			ret *= int64(n)
		}
		return ret
	}

	ans := int64(1)
	for k, v := range cnt {
		if v < n-1 {
			continue
		}
		ans *= pow(k, min2[k])
	}
	fmt.Println(ans)
}

/*
URL:
https://codeforces.com/problemset/problem/1349/A
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	n int
	A []int64

	P [200000 + 5][]int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	for i := 0; i < n; i++ {
		if A[i] == 1 {
			continue
		}

		memo := TrialDivision(A[i])
		for k, v := range memo {
			P[k] = append(P[k], v)
		}
	}

	ans := int64(1)
	for i := 0; i <= 200000; i++ {
		if len(P[i]) >= n-1 {
			sort.Slice(P[i], func(j, k int) bool { return P[i][j] < P[i][k] })

			e := P[i][1]
			ans *= PowInt(int64(i), e)
		}
	}
	fmt.Println(ans)
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	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)
}

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int64) map[int64]int64 {
	var i, exp int64
	p := map[int64]int64{}

	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	for i = 2; i*i <= n; i++ {
		exp = 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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


You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + i (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer k such that all possible strings consisting of 0 and 1 of length k (there are 2k such strings) are substrings of the new string. If there is no such k, print 0.

The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings s1, s2, ..., sn (1 ≤ |si| ≤ 100), one per line. The total length of strings is not greater than 100. The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of them contains two integers ai abd bi (1 ≤ ai, bi ≤ n + i - 1) — the number of strings that are concatenated to form sn + i.

Print m lines, each should contain one integer — the answer to the question after the corresponding operation.

NoteOn the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.On the second operation the string "01100" is created. Now all strings of length k = 2 are present.On the third operation the string "1111111111" is created. There is no zero, so the answer is 0.

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var n int
var pref,suf [500][]uint8
var substr [500][]string
var sz [10]int

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	fmt.Fscanf(in, "%d\n", &n)
	for i:=1;i<=n;i++ {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		m := len(s)
		for j := 0;j < min(m,9); j++ {
			pref[i] = append(pref[i], s[j])
		}
		cnt := 9
		for j := m - 1; j >= 0 && cnt > 0; j-- {
			cnt--
			suf[i] = append(suf[i], s[j])
		}
		for j:=0; j < len(suf[i]) / 2; j++ {
			suf[i][j], suf[i][len(suf[i]) - 1 - j] = suf[i][len(suf[i]) - 1 - j], suf[i][j]
		}
		mp := make(map[string]bool)
		for j := 0; j < m; j++ {
			for k := j; k< m; k++ {
				if k - j + 1 > 9 {
					break
				}
				st := s[j:k + 1]
				if mp[st] == false {
					mp[st] = true
					substr[i] = append(substr[i], st)
				}
			}
		}
	}
	var q int
	fmt.Fscanf(in, "%d\n", &q)
	t := 0
	for ; q > 0; q-- {
		t++
		for i := 0; i< 10; i++ {
			sz[i] = 0
		}
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		substr[n + t] = make([]string, len(substr[x]))
		copy(substr[n + t], substr[x])
		for i := range substr[x] {
			sz[len(substr[x][i])]++
		}
		mp := make(map[string]bool)
		for i := range substr[x] {
			mp[substr[x][i]] = true
		}
		for i := range substr[y] {
			if mp[substr[y][i]] == false {
				mp[substr[y][i]] = true
				substr[n + t] = append(substr[n + t], substr[y][i])
				sz[len(substr[y][i])]++
			}
		}
		pref[n + t] = make([]uint8, len(pref[x]))
		copy(pref[n + t], pref[x])
		for i := 0; i < len(pref[y]) && len(pref[n + t]) < 9; i++ {
			pref[n + t] = append(pref[n + t], pref[y][i])
		}
		for i := len(suf[y]) - 1; i >= 0; i -- {
			suf[n + t] = append(suf[n + t], suf[y][i])
		}
		for i := len(suf[x]) - 1; i >= 0 && len(suf[n + t]) < 9; i-- {
			suf[n + t] = append(suf[n + t], suf[x][i])
		}
		for i := 0; i < len(suf[n + t]) / 2; i++ {
			suf[n + t][i], suf[n + t][len(suf[n + t]) - 1 - i] = suf[n + t][len(suf[n + t]) - 1 - i], suf[n + t][i]
		}
		var a []uint8
		for i := range suf[x] {
			a = append(a, suf[x][i])
		}
		for i := range pref[y] {
			a = append(a, pref[y][i])
		}
		for i := range a {
			for j := i; j < len(a); j++ {
				if j - i + 1 > 9 {
					break
				}
				var b string
				for k := i; k <= j; k ++ {
					b = b + string(a[k])
				}
				if mp[b] == false {
					mp[b] = true
					substr[n + t] = append(substr[n + t], b)
					sz[len(b)]++
				}
			}
		}
		found := false
		for i := 9; i >= 0; i-- {
			if sz[i] == (1 << uint(i)) {
				fmt.Println(i)
				found = true
				break
			}
		}
		if !found {
			fmt.Println(0)
		}
	}
}

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var n int
var pref,suf [500][]uint8
var substr [500][]string
var sz [10]int

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	fmt.Fscanf(in, "%d\n", &n)
	for i:=1;i<=n;i++ {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		m := len(s)
		for j := 0;j < min(m,9); j++ {
			pref[i] = append(pref[i], s[j])
		}
		cnt := 9
		for j := m - 1; j >= 0 && cnt > 0; j-- {
			cnt--
			suf[i] = append(suf[i], s[j])
		}
		for j:=0; j < len(suf[i]) / 2; j++ {
			suf[i][j], suf[i][len(suf[i]) - 1 - j] = suf[i][len(suf[i]) - 1 - j], suf[i][j]
		}
		mp := make(map[string]bool)
		for j := 0; j < m; j++ {
			for k := j; k< m; k++ {
				if k - j + 1 > 9 {
					break
				}
				st := s[j:k + 1]
				if mp[st] == false {
					mp[st] = true
					substr[i] = append(substr[i], st)
				}
			}
		}
	}
	var q int
	fmt.Fscanf(in, "%d\n", &q)
	t := 0
	for ; q > 0; q-- {
		t++
		for i := 0; i< 10; i++ {
			sz[i] = 0
		}
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		substr[n + t] = make([]string, len(substr[x]))
		copy(substr[n + t], substr[x])
		for i := range substr[x] {
			sz[len(substr[x][i])]++
		}
		mp := make(map[string]bool)
		for i := range substr[x] {
			mp[substr[x][i]] = true
		}
		for i := range substr[y] {
			if mp[substr[y][i]] == false {
				mp[substr[y][i]] = true
				substr[n + t] = append(substr[n + t], substr[y][i])
				sz[len(substr[y][i])]++
			}
		}
		pref[n + t] = make([]uint8, len(pref[x]))
		suf[n + t] = make([]uint8, len(suf[y]))
		copy(pref[n + t], pref[x])
		copy(suf[n + t], suf[y])
		// a := make([]uint8, len(suf[x]) + len(pref[y]))
		var a []uint8
		for i := range suf[x] {
			a = append(a, suf[x][i])
		}
		for i := range pref[y] {
			a = append(a, pref[y][i])
		}
		for i := range a {
			for j := i; j < len(a); j++ {
				if j - i + 1 > 9 {
					break
				}
				var b string
				for k := i; k <= j; k ++ {
					b = b + string(a[k])
				}
				if mp[b] == false {
					mp[b] = true
					substr[n + t] = append(substr[n + t], b)
					sz[len(b)]++
				}
			}
		}
		found := false
		for i := 9; i >= 0; i-- {
			if sz[i] == (1 << uint(i)) {
				fmt.Println(i)
				found = true
				break
			}
		}
		if !found {
			fmt.Println(0)
		}
	}
}

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var n int
var pref,suf [500][]uint8
var substr [500][]string
var sz [10]int

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	fmt.Fscanf(in, "%d\n", &n)
	for i:=1;i<=n;i++ {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		m := len(s)
		fmt.Println(s)
		for j := 0;j < min(m,9); j++ {
			pref[i] = append(pref[i], s[j])
		}
		cnt := 9
		for j := m - 1; j >= 0 && cnt > 0; j-- {
			cnt--
			suf[i] = append(suf[i], s[j])
		}
		for j:=0; j < len(suf[i]) / 2; j++ {
			suf[i][j], suf[i][len(suf[i]) - 1 - j] = suf[i][len(suf[i]) - 1 - j], suf[i][j]
		}
		mp := make(map[string]bool)
		for j := 0; j < m; j++ {
			for k := j; k< m; k++ {
				if k - j + 1 > 9 {
					break
				}
				st := s[j:k + 1]
				if mp[st] == false {
					mp[st] = true
					substr[i] = append(substr[i], st)
				}
			}
		}
	}
	var q int
	fmt.Fscanf(in, "%d\n", &q)
	t := 0
	for ; q > 0; q-- {
		t++
		for i := 0; i< 10; i++ {
			sz[i] = 0
		}
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		substr[n + t] = make([]string, len(substr[x]))
		copy(substr[n + t], substr[x])
		for i := range substr[x] {
			sz[len(substr[x][i])]++
		}
		mp := make(map[string]bool)
		for i := range substr[x] {
			mp[substr[x][i]] = true
		}
		for i := range substr[y] {
			if mp[substr[y][i]] == false {
				mp[substr[y][i]] = true
				substr[n + t] = append(substr[n + t], substr[y][i])
				sz[len(substr[y][i])]++
			}
		}
		pref[n + t] = make([]uint8, len(pref[x]))
		suf[n + t] = make([]uint8, len(suf[y]))
		copy(pref[n + t], pref[x])
		copy(suf[n + t], suf[y])
		// a := make([]uint8, len(suf[x]) + len(pref[y]))
		var a []uint8
		for i := range suf[x] {
			a = append(a, suf[x][i])
		}
		for i := range pref[y] {
			a = append(a, pref[y][i])
		}
		for i := range a {
			for j := i; j < len(a); j++ {
				if j - i + 1 > 9 {
					break
				}
				var b string
				for k := i; k <= j; k ++ {
					b = b + string(a[k])
				}
				if mp[b] == false {
					mp[b] = true
					substr[n + t] = append(substr[n + t], b)
					sz[len(b)]++
				}
			}
		}
		found := false
		for i := 9; i >= 0; i-- {
			if sz[i] == (1 << uint(i)) {
				fmt.Println(i)
				found = true
				break
			}
		}
		if !found {
			fmt.Println(0)
		}
	}
}

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var n int
var pref,suf [500][]uint8
var substr [500][]string
var sz [10]int

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	fmt.Fscanf(in, "%d\n", &n)
	for i:=1;i<=n;i++ {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		m := len(s)
		fmt.Println(m)
		for j := 0;j < min(m,9); j++ {
			pref[i] = append(pref[i], s[j])
		}
		cnt := 9
		for j := m - 1; j >= 0 && cnt > 0; j-- {
			cnt--
			suf[i] = append(suf[i], s[j])
		}
		for j:=0; j < len(suf[i]) / 2; j++ {
			suf[i][j], suf[i][len(suf[i]) - 1 - j] = suf[i][len(suf[i]) - 1 - j], suf[i][j]
		}
		mp := make(map[string]bool)
		for j := 0; j < m; j++ {
			for k := j; k< m; k++ {
				if k - j + 1 > 9 {
					break
				}
				st := s[j:k + 1]
				if mp[st] == false {
					mp[st] = true
					substr[i] = append(substr[i], st)
				}
			}
		}
	}
	var q int
	fmt.Fscanf(in, "%d\n", &q)
	t := 0
	for ; q > 0; q-- {
		t++
		for i := 0; i< 10; i++ {
			sz[i] = 0
		}
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		substr[n + t] = make([]string, len(substr[x]))
		copy(substr[n + t], substr[x])
		for i := range substr[x] {
			sz[len(substr[x][i])]++
		}
		mp := make(map[string]bool)
		for i := range substr[x] {
			mp[substr[x][i]] = true
		}
		for i := range substr[y] {
			if mp[substr[y][i]] == false {
				mp[substr[y][i]] = true
				substr[n + t] = append(substr[n + t], substr[y][i])
				sz[len(substr[y][i])]++
			}
		}
		pref[n + t] = make([]uint8, len(pref[x]))
		suf[n + t] = make([]uint8, len(suf[y]))
		copy(pref[n + t], pref[x])
		copy(suf[n + t], suf[y])
		// a := make([]uint8, len(suf[x]) + len(pref[y]))
		var a []uint8
		for i := range suf[x] {
			a = append(a, suf[x][i])
		}
		for i := range pref[y] {
			a = append(a, pref[y][i])
		}
		for i := range a {
			for j := i; j < len(a); j++ {
				if j - i + 1 > 9 {
					break
				}
				var b string
				for k := i; k <= j; k ++ {
					b = b + string(a[k])
				}
				if mp[b] == false {
					mp[b] = true
					substr[n + t] = append(substr[n + t], b)
					sz[len(b)]++
				}
			}
		}
		found := false
		for i := 9; i >= 0; i-- {
			if sz[i] == (1 << uint(i)) {
				fmt.Println(i)
				found = true
				break
			}
		}
		if !found {
			fmt.Println(0)
		}
	}
}