A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).

package main

import (
	"fmt"
)

var ps = fmt.Printf
var ss = fmt.Scanf

func main() {

	var s string
	var k int
	ss("%d\n%s\n", &k, &s)
	count := [27]int{0}
	for i := 0; i < len(s); i++ {
		count[int(s[i])-97]++
	}
	if len(s)%k != 0 {
		ps("-1")
		return
	}
	s = ""
	for i := 0; i <= 25; i++ {
		c := count[i] / k
		if count[i]%k == 0 {
			for j := 0; j < c; j++ {
				s = s + string(i+97)
			}
		} else {
			ps("-1")
			return
		}
	}
	for k > 0 {
		ps(s)
		k--
	}
}

package main
import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var k int
	flag:=false
	var x string
	n:=make([]int,27)
	fmt.Scan(&k,&x)
	len:= utf8.RuneCountInString(x)
	for i:=0; i<len;i++ {
		n[int(x[i]-'a'+1)]++
	}
	for i:=1; i<=26;i++ {
			if n[i]%k!=0{
				fmt.Println("-1")
				flag=true
				break
			}
	}
	if flag==false {
		for q:=1;q<=k;q++ {
			for i:=1;i<=26;i++ {
				for j:=1;j<=n[i]/k;j++ {
					fmt.Print(string(i+'a'-1))
				}
			}
		}
	}
	fmt.Println()
}

package main

import (
	"fmt"
	"strings"
)

func kstring(str string, k int, table []int) {
	res := ""
	for i := 0; i < len(str); i++ {
		table[str[i]-97]++
	}
	for i := 0; i < 26; i++ {
		if table[i] != 0 {
			if table[i]%k == 0 {
				res += strings.Repeat(string(i+97), table[i]/k)
			} else {
				fmt.Println(-1)
				return
			}
		}
	}
	fmt.Println(strings.Repeat(res, k))
}

func main() {
	var k int
	var str string
	table := make([]int, 26)
	fmt.Scanln(&k)
	fmt.Scanln(&str)
	kstring(str, k, table)
}

package main

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

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

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")
		if k == 1 {
			fmt.Println(s)
			return
		}

		dict := make(map[byte]int)
		for i := 0; i < len(s); i++ {
			dict[s[i]] = dict[s[i]] + 1
		}

		var sub_string []byte

		for l, v := range dict {
			if v%k != 0 {
				fmt.Println(-1)
				return
			} else {
				for i := 0; i < v/k; i++ {
					sub_string = append(sub_string, l)
				}
			}
		}

		for i := 0; i < k; i++ {
			fmt.Printf("%s", string(sub_string))
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var k int
    var s string
    var char [26]int
    fmt.Scan(&k)
    fmt.Scan(&s)
    for _, v := range s { char[v-'a']++ }
    if len(s)%k == 0 {
        ans := true
        for i := 0; i < 26; i++ {
            if char[i] % k != 0 {
                ans = false
                break
            }
        }
        if !ans {
            fmt.Println(-1)
        } else {
            ns := ""
            for i := 0; i < 26; i++ {
                for j := 0; j < char[i]/k; j++ {
                    ns += string(i+'a')
                }
            }
            for ; k > 0; k-- { fmt.Print(ns) }
            fmt.Println()
        }
    } else {
        fmt.Println(-1)
    }
}

package main

import (
    "fmt"
)

func main() {
    var k int
    var str string
    fmt.Scanf("%d\n", &k)
    fmt.Scanf("%s\n", &str)
    D := make(map[int]int)
    for _, v := range str {
        D[int(v)]++
    }
    for _, v := range D {
        if v%k != 0 {
            fmt.Printf("-1\n")
            return
        }
    }
    for j := 0; j < k; j++ {
        for A := 0x61; A <= 0x7A; A++ {
            v := D[A]
            for i := 0; i < v/k; i++ {
                fmt.Printf("%c", A)
            }
        }
    }
    fmt.Print("\n")

}

package main

import (
	"fmt"
)

func solve(k int, s string) string {
	length := len(s)
	if length%k != 0 {
		return "-1"
	}

	counts := make([]int, 26, 26)
	for i := 0; i < length; i++ {
		counts[s[i]-'a']++
	}

	tmp := ""
	for i := 0; i < 26; i++ {
		if counts[i] == 0 {
			continue
		}
		if counts[i]%k != 0 {
			return "-1"
		}
		for j := 0; j < counts[i]/k; j++ {
			tmp += string(i + 'a')
		}
	}

	ans := ""
	for i := 0; i < length/len(tmp); i++ {
		ans += tmp
	}

	return ans
}

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

	var s string
	fmt.Scan(&s)

	fmt.Println(solve(k, s))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var (
		count int
		str   string
	)

	fmt.Scanf("%d\n", &count)
	charMap := make(map[rune]int)

	fmt.Scan(&str)
	for i := 0; i < len(str); i++ {
		charMap[rune(str[i])]++
	}

	fragment := make([]rune, 0)
	for char, amount := range charMap {
		if amount % count != 0 {
			fmt.Println(-1)
			return
		}
		for i := amount / count; i >= 1; i-- {
			fragment = append(fragment, char)
		}
	}

	result := strings.Repeat(string(fragment), count)

	fmt.Println(result)
}

package main

import "fmt"

func main() {
	var k int
	var s string
	fmt.Scanf("%d\n%s", &k, &s)
	cnt := [26]int{}
	for _, c := range s {
		cnt[c - 'a']++
	}
	for _, v := range cnt {
		if v % k != 0 {
			fmt.Println(-1)
			return
		}
	}
	for i := 0; i < k; i++ {
		for j := 0; j < 26; j++ {
			for z := 0; z < cnt[j] / k; z++ {
				fmt.Print(string('a' + j));
			}
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func kstring(str string, k int, table []byte) {
	res := ""
	for i := 0; i < len(str); i++ {
		table[str[i]-97]++
	}
	for i := 0; i < 26; i++ {
		if table[i] != 0 {
			if int(table[i])%k == 0 {
				res += strings.Repeat(string(i+97), int(table[i])/k)
			} else {
				fmt.Println(-1)
				return
			}
		}
	}
	fmt.Println(strings.Repeat(res, k))
}

func main() {
	var k int
	var str string
	table := make([]byte, 26)
	fmt.Scanln(&k)
	fmt.Scanln(&str)
	kstring(str, k, table)
}

package main

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

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

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")
		if k == 1 {
			fmt.Println(s)
			return
		}

		if len(s)%2 != 0 {
			fmt.Println(-1)
		} else {
			dict := make(map[byte]int)
			for i := 0; i < len(s); i++ {
				dict[s[i]] = dict[s[i]] + 1
			}

			var sub_string []byte

			for l, v := range dict {
				if v%k != 0 {
					fmt.Println(-1)
					return
				} else {
					for i := 0; i < v/k; i++ {
						sub_string = append(sub_string, l)
					}
				}
			}

			for i := 0; i < k; i++ {
				fmt.Printf("%s", string(sub_string))
			}
			fmt.Println()
		}
	}
}

package main

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

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

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		if len(s)%2 != 0 {
			fmt.Println(-1)
		} else {
			dict := make(map[byte]int)
			for i := 0; i < len(s); i++ {
				dict[s[i]] = dict[s[i]] + 1
			}

			var sub_string []byte

			for l, v := range dict {
				if v%k != 0 {
					fmt.Println(-1)
					return
				} else {
					for i := 0; i < v/k; i++ {
						sub_string = append(sub_string, l)
					}
				}
			}

			for i := 0; i < k; i++ {
				fmt.Printf("%s", string(sub_string))
			}
			fmt.Println()
		}
	}
}

package main

import (
    "fmt"
)

func main() {
    var k int
    var str string
    fmt.Scanf("%d\n", &k)
    fmt.Scanf("%s\n", &str)
    D := make(map[int]int)
    for _, v := range str {
        D[int(v)]++
    }
    for _, v := range D {
        if v%k != 0 {
            fmt.Printf("-1\n")
            return
        }
    }
    for j := 0; j < k; j++ {
        for K, v := range D {
            for i := 0; i < v/k; i++ {
                fmt.Printf("%c", K)
            }
        }
    }
    fmt.Print("\n")

}

// 219A
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)
	var input, output string
	fmt.Scan(&input)
	var letters [26]int
	for _, u := range input {
		letters[u-'a']++
	}
	for u := 0; u < 26; u++ {
		if letters[u] == 0 {
			continue
		} else if letters[u]%k != 0 {
			for v := 0; v < letters[u]/k; v++ {
				output += string('a') + string(u)
			}
		} else {
			output = "-1"
			break
		}
	}
	if output == "-1" {
		fmt.Println(output)
	} else {
		for u := 0; u < k; u++ {
			fmt.Print(output)
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

func solve(k int, s string) string {
	length := len(s)
	if length%k != 0 {
		return "-1"
	}

	counts := make([]int, 26, 26)
	for i := 0; i < length; i++ {
		counts[s[i]-'a']++
	}

	n := length / k
	tmp := ""
	for i := 0; i < 26; i++ {
		if counts[i] == 0 {
			continue
		}
		if counts[i]%k != 0 {
			return "-1"
		}
		for j := 0; j < counts[i]/n; j++ {
			tmp += string(i + 'a')
		}
	}

	ans := ""
	for i := 0; i < n; i++ {
		ans += tmp
	}

	return ans
}

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

	var s string
	fmt.Scan(&s)

	fmt.Println(solve(k, s))
}

package main

import (
	"fmt"
)

func solve(k int, s string) string {
	length := len(s)
	if length%k != 0 {
		return "-1"
	}

	counts := make([]int, 26, 26)
	for i := 0; i < length; i++ {
		counts[s[i]-'a']++
	}

	n := length / k
	tmp := ""
	for i := 0; i < 26; i++ {
		if counts[i] == 0 {
			continue
		}
		if counts[i] != n {
			return "-1"
		}
		tmp += string(i + 'a')
	}

	ans := ""
	for i := 0; i < n; i++ {
		ans += tmp
	}

	return ans
}

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

	var s string
	fmt.Scan(&s)

	fmt.Println(solve(k, s))
}

package main

import (
	"fmt"
)

func solve(k int, s string) string {
	length := len(s)
	if length%k != 0 {
		return "-1"
	}

	counts := make([]int, 26, 26)
	for i := 0; i < length; i++ {
		counts[s[i]-'a']++
	}

	n := length / k
	tmp := ""
	for i := 0; i < 26; i++ {
		if counts[i] == 0 {
			continue
		}
		if counts[i]%n != 0 {
			return "-1"
		}
		for j := 0; j < counts[i]/n; j++ {
			tmp += string(i + 'a')
		}
	}

	ans := ""
	for i := 0; i < n; i++ {
		ans += tmp
	}

	return ans
}

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

	var s string
	fmt.Scan(&s)

	fmt.Println(solve(k, s))
}


As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.  The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

NoteIn the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.In the second example, there are not enough players.In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

package main

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

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

	var n, m, h, v, hv int
	Fscan(in, &n, &m, &h)
	h--
	sum := 0
	for i := 0; i < m; i++ {
		Fscan(in, &v)
		sum += v
		if i == h {
			hv = v
		}
	}
	if sum < n {
		Fprint(out, -1)
		return
	}
	others := sum - hv
	sum--
	n--
	ans := 1.0
	for i := 0; i < n; i++ {
		ans *= float64(others-i) / float64(sum-i)
	}
	Fprint(out, 1-ans)
}

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


Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).

NoteIn first sample first player remove whole array in one move and win.In second sample first player can't make a move and lose.

package main

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

func main() {
	var n, temp int

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)

	for i := 0; i < n ; i++ {
		fmt.Fscan(reader, &temp)
		if temp % 2 == 1 {
			fmt.Println("First")
			return
		}
	}

	fmt.Println("Second")
}

package main

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

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

	n := readInt(reader)
	b := readA(reader, n)
	a := make([]int, n)
	total_parity := 0
	for i,v := range *b {
		if v%2==0 {
			a[i] = 0
		} else {
			a[i] = 1
			if total_parity==0 {
				total_parity = 1
			} else {
				total_parity = 0
			}
		}
	}

	ok := true

	if total_parity!=1 {
		ok = false
		for _,v := range a {
			if v==1 {
				ok = true
				break
			}
		}
	}

	if ok {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}

}

func readLine(nr *bufio.Reader) *string {
	line, _, err := nr.ReadLine()
	if err!=nil {
		panic(err)
	}
	s := string(line)
	return &s
}

func skipLine(nr *bufio.Reader) {
	_, _, err := nr.ReadLine()
	if err!=nil {
		panic(err)
	}
}

func readInt(nr *bufio.Reader) int {
	var a int
	fmt.Fscan(nr, &a)
	return a
}

func readA(nr *bufio.Reader, n int) *[]int {
	a := make([]int, n)

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

	return &a
}

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

func main(){
    var n int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d\n", &n)
    cnt := 0
    for i := 0; i < n; i++{
        var m int
        fmt.Fscanf(stdin, "%d", &m)
        if m % 2 != 0{
            cnt += 1
        }
    }
    if cnt == 0{
        fmt.Println("Second")
    } else{
        fmt.Println("First")
    }
}

package main

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

func main(){
    var n, sum int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d\n", &n)

    for i := 0; i < n; i++{
        var cr int
        fmt.Fscanf(stdin, "%d", &cr)
        sum += cr % 2
    }

    if sum != 0 {
        fmt.Println("First")
    } else {
        fmt.Println("Second")
    }
}

package main

/*
    To solve this problem, notice that beside odd & even sum, there is also
    player turns starting by the first player. So even though the total sum of
    number is even, the first player still able to win as long as there is
    odd number on the array.

    Thus if there is odd number on the array, then first player surely would
    be the winner.
*/

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

func main(){
    var n, sum int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d\n", &n)

    for i := 0; i < n; i++{
        var cr int
        fmt.Fscanf(stdin, "%d", &cr)
        sum += cr % 2
    }

    // if there is odd number on the sequence
    // the sum != 0
    if sum != 0 {
        fmt.Println("First")
    } else {
        fmt.Println("Second")
    }
}

package main

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

const maxInputSize = 512 * 1024 //bytes

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, maxInputSize), maxInputSize)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	// a := make([]int, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		if x%2 == 1 {
			fmt.Println("First")
			return
		}
	}
	fmt.Println("Second")
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	total := int64(0)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		total += int64(a[i])
	}
	if total%2 != 0 {
		fmt.Println("First")
		return
	}
	total = int64(0)
	for i := 0; i < n; i++ {
		total += int64(a[i])
		if total%2 != 0 {
			fmt.Println("First")
			return
		}
	}
	total = int64(0)
	for i := n - 1; i >= 0; i-- {
		total += int64(a[i])
		if total%2 != 0 {
			fmt.Println("First")
			return
		}
	}
	fmt.Println("Second")
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

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

	fmt.Fscan(reader, &qr)
	for qr > 0 {
		var qrs int
		fmt.Fscan(reader, &qrs)

		if qrs%2 != 0 {
			fmt.Println("First")
			return
		}

		qr--
	}

	fmt.Println("Second")

}

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

func main(){
    var n int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d", &n)
    cnt := 0
    for i := 0; i < n; i++{
        var m int
        fmt.Fscanf(stdin, "%d", &m)
        if m % 2 != 0{
            cnt += 1
        }
    }
    if cnt == 0{
        fmt.Println("Second")
    } else{
        fmt.Println("First")
    }
}

package main

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

func main(){
    var n, sum int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d\n", &n)

    for i := 0; i < n; i++{
        var cr int
        fmt.Fscanf(stdin, "%d", &cr)
        sum += cr
    }

    if sum % 2 != 0 {
        fmt.Println("First")
    } else {
        fmt.Println("Second")
    }
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	total := int64(0)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		total += int64(a[i])
	}
	if total%2 != 0 {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}


Let's call an array $$$t$$$ dominated by value $$$v$$$ in the next situation.At first, array $$$t$$$ should have at least $$$2$$$ elements. Now, let's calculate number of occurrences of each number $$$num$$$ in $$$t$$$ and define it as $$$occ(num)$$$. Then $$$t$$$ is dominated (by $$$v$$$) if (and only if) $$$occ(v) > occ(v')$$$ for any other number $$$v'$$$. For example, arrays $$$[1, 2, 3, 4, 5, 2]$$$, $$$[11, 11]$$$ and $$$[3, 2, 3, 2, 3]$$$ are dominated (by $$$2$$$, $$$11$$$ and $$$3$$$ respectevitely) but arrays $$$[3]$$$, $$$[1, 2]$$$ and $$$[3, 3, 2, 2, 1]$$$ are not.Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.You are given array $$$a_1, a_2, \dots, a_n$$$. Calculate its shortest dominated subarray or say that there are no such subarrays.The subarray of $$$a$$$ is a contiguous part of the array $$$a$$$, i. e. the array $$$a_i, a_{i + 1}, \dots, a_j$$$ for some $$$1 \le i \le j \le n$$$.

The first line contains single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the corresponding values of the array $$$a$$$. It's guaranteed that the total length of all arrays in one test doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or $$$-1$$$ if there are no such subarrays.

NoteIn the first test case, there are no subarrays of length at least $$$2$$$, so the answer is $$$-1$$$.In the second test case, the whole array is dominated (by $$$1$$$) and it's the only dominated subarray.In the third test case, the subarray $$$a_4, a_5, a_6$$$ is the shortest dominated subarray.In the fourth test case, all subarrays of length more than one are dominated.

package main

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

/* solution */

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

func solveOne() int {
	n := readInt()
	// a := make([]int, n)
	prev := make([]int, n+1)
	ans := -1
	for i := 1; i <= n; i++ {
		v := readInt()
		if prev[v] != 0 {
			cand := i - prev[v] + 1
			if ans == -1 || cand < ans {
				ans = cand
			}
		}
		prev[v] = i
	}

	return ans

}

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

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

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

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

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

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

package main

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

func MinInt(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func main() {
	r:= bufio.NewReader(os.Stdin)
	var t, n int

	for fmt.Fscan(r,&t); t > 0; t-- {
		fmt.Fscan(r,&n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		if (n <= 1) {
			fmt.Println(-1)
		} else {
			m := make(map[int]int)
			mi := n + 1
			for i := 0; i < n; i++ {
				if v, ok := m[a[i]]; ok {
					mi = MinInt(mi, i-v+1)
				}
				m[a[i]] = i
			}
			if mi == n+1 {
				mi = -1
			}
			fmt.Println(mi)
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var t int
var n int
var A []int
var cnt []int

func main() {
	for t:= ReadInt(); t > 0; t-- {
		n:= ReadInt()
		a := ReadIntSlice(n)

		if (n <= 1) {
			fmt.Println(-1)
		} else {
			m := make(map[int]int)
			mi := n + 1
			for i := 0; i < n; i++ {
				if v, ok := m[a[i]]; ok {
					mi = Min(mi, i-v+1)
				}
				m[a[i]] = i
			}
			if mi == n+1 {
				mi = -1
			}
			fmt.Println(mi)
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	text, _ := reader.ReadString('\n')
	t, _ := strconv.ParseInt(strings.TrimSpace(text), 10, 64)
	lst := [200001]int{}
	ret := 0
	for i := int64(0); i < t; i++ {
		text, _ = reader.ReadString('\n')
		text = strings.TrimSpace(text)
		n, _ := strconv.ParseInt(text, 10, 64)
		for j := int64(0); j <= n; j++ {
			lst[j] = 0
		}
		text, _ = reader.ReadString('\n')
		text = strings.TrimSpace(text)
		parts := strings.Split(text, " ")
		ret = 0
		for k, p := range parts {
			v, _ := strconv.ParseInt(p, 10, 64)
			if lst[v] != 0 && (k-lst[v]+2 < ret || ret == 0) {
				ret = k - lst[v] + 2
			}
			lst[v] = k + 1
		}
		if ret == 0 {
			fmt.Println("-1")
		} else {
			fmt.Println(ret)
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	T := ReadInt()

	for T > 0 {
		n := ReadInt()

		arr := ReadIntSlice(n)

		fmt.Println(solve(arr))

		T--
	}
}

func solve(arr []int) int {
	if len(arr) <= 1 {
		return -1
	}

	ans := -1

	m := make(map[int]int)

	for i, v := range arr {
		p, ok := m[v]
		if !ok {
			m[v] = i
		} else {
			m[v] = i
			if ans == -1 {
				ans = i - p + 1
			} else {
				ans = minInt(ans, i-p+1)
			}
		}
	}

	return ans
}

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

	return b
}

package main

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

// Educational Codeforces Round 76
// C. Dominated Subarray
// https://codeforces.com/contest/1257/problem/C
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

const inf = int(1e9) + 1

func main() {
	var T int
	fmt.Scan(&T)
	ans := make([]int, 0)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < T; i++ {
		N := nextInt(sc)
		set := make(map[int]int, 0)    // 整数xの最後の出現位置を覚えておくハッシュマップ
		lenset := make(map[int]int, 0) // 整数x同士の距離の最小値
		minlen := inf
		for j := 0; j < N; j++ {
			v := nextInt(sc)
			if set[v] == 0 {
				set[v] = j + 1
			} else {
				tlen := j + 1 - set[v] + 1
				if lenset[v] == 0 {
					lenset[v] = tlen
				} else {
					lenset[v] = min(tlen, lenset[v])
				}
				minlen = min(lenset[v], minlen)
				set[v] = j + 1
			}
		}
		ans = append(ans, minlen)
	}
	for i := range ans {
		if ans[i] == inf {
			fmt.Println(-1)
		} else {
			fmt.Println(ans[i])
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var t int
var n int
var A []int
var cnt []int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		solve()
	}
}

func solve() {
	if n == 1 {
		fmt.Println(-1)
		return
	}

	cnt = make([]int, n+1)
	flag := true
	for i := 0; i < n; i++ {
		a := A[i]
		if cnt[a] > 0 {
			// 2回登場するものがあれば答えはある
			flag = false
			break
		}
		cnt[a]++
	}

	if flag {
		// すべて異なる数ならNO
		fmt.Println(-1)
		return
	}

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		// リセット
		cnt = make([]int, n+1)
		// 初期化
		for i := 0; i < m; i++ {
			a := A[i]
			if cnt[a] > 0 {
				return true
			}
			cnt[a]++
		}
		// スライド
		for i := m; i < n; i++ {
			j := i - m
			cnt[A[j]]--
			a := A[i]
			if cnt[a] > 0 {
				return true
			}
			cnt[a]++
		}

		return false
	}

	ng, ok := 1, n
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	// boundaryIdx := ok
	fmt.Println(ok)
}

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

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

package main

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

var in = bufio.NewScanner(os.Stdin)

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	p := map[int]int{}
	ans := -1
	for i := 0; i < n; i++ {
		if _, ok := p[a[i]]; ok {
			l := i - p[a[i]] + 1
			if ans == -1 || l < ans {
				ans = l
			}
		}
		p[a[i]] = i
	}
	fmt.Println(ans)
}

func main() {
	in.Split(bufio.ScanWords)
	t := readInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func MinInt(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func main() {
	var t, n int

	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		if (n <= 1) {
			fmt.Println(-1)
		} else {
			m := make(map[int]int)
			mi := n + 1
			for i := 0; i < n; i++ {
				if v, ok := m[a[i]]; ok {
					mi = MinInt(mi, i-v+1)
				}
				m[a[i]] = i
			}
			if mi == n+1 {
				mi = -1
			}
			fmt.Println(mi)
		}
	}
}

package main

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

// Educational Codeforces Round 76
// C. Dominated Subarray
// https://codeforces.com/contest/1257/problem/C

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	var T int
	fmt.Scan(&T)
	ans := make([]int, 0)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < T; i++ {
		var N int
		fmt.Scan(&N)
		if N == 1 {
			_ = nextInt(sc)
			ans = append(ans, -1)
			continue
		}
		set := make(map[int][]int, 0)
		for j := 0; j < N; j++ {
			v := nextInt(sc)
			if set[v] == nil {
				set[v] = make([]int, 0)
			}
			set[v] = append(set[v], j)
		}
		minlen := int(1e9) + 1
		for _, v := range set {
			tlen := 0
			for j := 0; j+1 < len(v); j++ {
				tlen = v[j+1] - v[j] + 1
				minlen = min(minlen, tlen)
			}
		}
		ans = append(ans, minlen)
	}
	for i := range ans {
		fmt.Println(ans[i])
	}
}

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