You are given a board of size $$$n \times n$$$, where $$$n$$$ is odd (not divisible by $$$2$$$). Initially, each cell of the board contains one figure.In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell $$$(i, j)$$$ you can move the figure to cells:   $$$(i - 1, j - 1)$$$;  $$$(i - 1, j)$$$;  $$$(i - 1, j + 1)$$$;  $$$(i, j - 1)$$$;  $$$(i, j + 1)$$$;  $$$(i + 1, j - 1)$$$;  $$$(i + 1, j)$$$;  $$$(i + 1, j + 1)$$$; Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. $$$n^2-1$$$ cells should contain $$$0$$$ figures and one cell should contain $$$n^2$$$ figures).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n < 5 \cdot 10^5$$$) — the size of the board. It is guaranteed that $$$n$$$ is odd (not divisible by $$$2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$ ($$$\sum n \le 5 \cdot 10^5$$$).

For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

package main

import (
	"fmt"
)

func solve() {
	var n int64
	fmt.Scan(&n)
	n /= 2
	ans := 4 * n * (n + 1) * (2*n + 1) / 3
	fmt.Println(ans)

}

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

package main

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

func BoardMoves(){
	s:= bufio.NewScanner(os.Stdin)
	s.Scan()
	t,_:=strconv.ParseInt(s.Text(),10,64)

	for i:=int64(0);i<t;i++{
		s.Scan()
		n,_:=strconv.ParseInt(s.Text(),10,64)
		fmt.Println(solvekBoardMoves(n))
	}

}

func solvekBoardMoves(n int64) uint64{
	mid:=uint64(n/2)
	ans:=uint64(0)
	s:=uint64(8)
	for i:=uint64(0);i<mid;i++{
		ans+=(i+1)*(i+1)
	}
	return ans*s
}
func main(){
	BoardMoves()
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=1; i<=t; i++ {
        var n int64
        fmt.Scanln(&n)
        n /= 2
        ans := 4*n*(n+1)*(2*n+1)/3;
        fmt.Println(ans)
    }
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	filename := "./file/input.txt"
	_, err := os.Stat(filename)
	if err == nil || os.IsExist(err) {
		f, err := os.Open(filename)
		defer f.Close()

		oldStdin := os.Stdin
		defer func() {
			os.Stdin = oldStdin
		}()

		if err == nil {
			os.Stdin = f
		}
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
)

func main() {

	// f, _ := os.Open("./file/input.txt")
	// defer f.Close()

	// oldStdin := os.Stdin
	// defer func() {
	// 	os.Stdin = oldStdin
	// }()

	// if f != nil {
	// 	os.Stdin = f
	// }

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

func main() {

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	// if f != nil {
	// 	os.Stdin = f
	// }

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	print(f.Name)

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1352/problem/C
package main

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

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

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

func solver() *big.Int {
	var n int
	fmt.Fscan(input, &n)
	return s(n)
}

func s(n int) *big.Int {
	if n == 1 {
		return big.NewInt(0)
	}
	z := big.NewInt(0).Mul(big.NewInt(int64((n - 1) / 2)), big.NewInt(int64(f(n))))
	return z.Add(z, s(n - 2))
}

func f(n int) int {
	return 4*(n - 2) + 4
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
    defer writer.Flush()
    var t, n int64
    scanf("%d\n", &t)
    for ; t > 0; t-- {
        defer writer.Flush()
        scanf("%d\n", &n)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        var ans, k, i int64
        k = (n * n - 1) / 4
        i = int64(math.Sqrt(float64(k)))
        ans = 8 * i * (i + 1) * (2 * i + 1) / 6
        fmt.Println(ans)
    }
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int64 {
	k := n/2

	var sum int64

	for i := k ; i > 0; i -- {
		s := int64(n * n - (n - 2) * (n - 2))

		sum += s * int64(i)

		n -=2
	}
	return sum
}

package main

import (
	"fmt"
)

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

	var n, ans int64
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		n = n / 2
		ans = int64(8) * n * (n + int64(1)) * (int64(2)*n + int64(1)) / int64(6)
		fmt.Println(ans)
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(int64(ReadInt())))
	}
}

func solve(n int64) int64 {
	var ret int64
	for i := int64(1); i <= n/2; i++ {
		ret += i * i
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1353C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	a := [5e5]int64{}
	for i := int64(3); i < 5e5; i += 2 {
		a[i] = a[i-2] + i/2*4*(i-1)
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		Fprintln(out, a[n])
	}
}

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

package main

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

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

		solv2(n)
	}

	close(O)
	oWg.Wait()
}

func solv2(n int) {
	if n == 1 {
		P(0)
		return
	}

	sum := int64(0)
	for i := 3; i <= n; i += 2 {
		tmp := int64(i-1) / 2
		sum += (8 * tmp * tmp)
	}
	P(sum)
}

func solv(n int) {
	if n == 1 {
		P(0)
		return
	}

	prev := big.NewInt(0)
	sum := big.NewInt(0)
	for n > 0 {
		n -= 2

		sum.Add(sum, prev)

		pow := big.NewInt(int64(n-1) / 2)
		tm := big.NewInt(8)
		tm.Mul(tm, pow)
		tm.Mul(tm, pow)
		sum.Add(sum, tm)

		swap := *sum
		prev = &swap
	}
	P(sum.String())
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

var nt int
var n int

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		var ret = int64(0)
		if n % 2 == 0 {
			for i := 1; i <= n / 2 - 1; i++ {
				var sz = i * 2 + 1
				ret += (int64(sz) * 4 - 4) * int64(i)
			}
			ret += int64(2 * n - 1) * int64(n / 2)
		} else {
			for i := 1; i <= n / 2; i++ {
				var sz = i * 2 + 1
				ret += (int64(sz) * 4 - 4) * int64(i)
			}
		}
		fmt.Fprintf(writer, "%d\n", ret)
	}
}

// https://serhatgiydiren.github.io

package main

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

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

func solve(test_id int) {
 var n int64
 fmt.Fscanf(reader, "%d\n", &n)
 n /= 2
 n = ( 8 * n * (n + 1) * (2 * n + 1) ) / 6
 fmt.Fprintf(writer, "%d\n", n)
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var ans int64
		for i := 1; i <= n/2; i++ {
			ans += 8 * int64(i) * int64(i)
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scan(&n)
	n /= 2
	ans := 4 * n * (n + 1) * (2*n + 1) / 3
	fmt.Println(ans)

}

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

package main

import "fmt"

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=1; i<=t; i++ {
        var n int
        fmt.Scanln(&n)
        n /= 2
        ans := 4*n*(n+1)*(2*n+1)/3;
        fmt.Println(ans)
    }
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./fi1le/input.txt")
	if err != nil {
		fmt.Println("2")
	}
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if f != nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	os.Stdin = f

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./fi1le/input.txt")
	if err != nil {
		fmt.Println("2")
	} else {
		fmt.Println("1")
	}

	if f != nil {
		fmt.Println("3")
	} else {
		fmt.Println(4)
	}

	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	print(f.Name)

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func fileExist(filename string) bool {
	_, err := os.Stat(filename)
	return err == nil || os.IsExist(err)
}

func main() {

	filename := "./file/input.txt"

	if !fileExist(filename) {
		fmt.Println("文件不存在")
	} else {
		f, err := os.Open(filename)
		defer f.Close()

		oldStdin := os.Stdin
		defer func() {
			os.Stdin = oldStdin
		}()

		if err == nil {
			// os.Stdin = f
		}
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

    // test
	if f != nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	fmt.Println(f.Name())

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
    defer writer.Flush()
    var t, n int
    scanf("%d\n", &t)
    for j := 0; j < t; j++ {
        defer writer.Flush()
        scanf("%d\n", &n)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        k := (n * n - 1) / 4
        i := int(math.Sqrt(float64(k)))
        ans := 8 * i * (i + 1) * (2 * i + 1) / 6
        fmt.Println(ans)
    }
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int64 {
	k := n/2

	sum := int64(0)

	for i := k ; i > 0; i -- {
		sq := n * n - (n - 2) * (n - 2)

		sum += int64(i * sq)

		n -=2
	}
	return sum
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int {
	k := n/2

	sum := 0

	for i := k ; i > 0; i -- {
		sq := n * n - (n - 2) * (n - 2)

		sum += i * sq

		n -=2
	}
	return sum
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt()))
	}
}

func solve(n int) int {
	var ret int
	for i := 1; i <= n/2; i++ {
		ret += i * i
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt()))
	}
}

func solve(n int) int64 {
	var ret int64
	for i := 1; i <= n/2; i++ {
		ret += int64(i * i)
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var ans int64
		for i := 1; i <= n/2; i++ {
			ans += int64(8 * i * i)
		}
		fmt.Fprintln(writer, ans)
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Each $$$a_i$$$ is one of the six following numbers: $$$4, 8, 15, 16, 23, 42$$$.Your task is to remove the minimum number of elements to make this array good.An array of length $$$k$$$ is called good if $$$k$$$ is divisible by $$$6$$$ and it is possible to split it into $$$\frac{k}{6}$$$ subsequences $$$4, 8, 15, 16, 23, 42$$$.Examples of good arrays:  $$$[4, 8, 15, 16, 23, 42]$$$ (the whole array is a required sequence);  $$$[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$$$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);  $$$[]$$$ (the empty array is good). Examples of bad arrays:   $$$[4, 8, 15, 16, 42, 23]$$$ (the order of elements should be exactly $$$4, 8, 15, 16, 23, 42$$$);  $$$[4, 8, 15, 16, 23, 42, 4]$$$ (the length of the array is not divisible by $$$6$$$);  $$$[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$$$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is one of the following numbers: $$$4, 8, 15, 16, 23, 42$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum number of elements you have to remove to obtain a good array.

package main

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

func main() {
	var i uint32
	var q uint32
	var stin string
	fmt.Scanf("%d\n", &q)
	r := q
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	stin = sc.Text()

	in := strings.Fields(stin)
	goal := [...]uint32{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]uint32, len(goal))

	var num uint32
	for i = 0; i < q; i++ {
		n, _ := strconv.Atoi(in[i])
		num = uint32(n)
		if num == goal[0] {
			// ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if cantidadEncontrada[indiceValor] < cantidadEncontrada[indiceValor-1] {
			cantidadEncontrada[indiceValor]++
		}

	}

	r = r - (cantidadEncontrada[5] * 6)

	fmt.Println(r)
}

package main

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

var DEBUG = true

func main() {
	defer Flush()

	N, A := readInts(0)

	x := make([][]int, 6)
	for i, v := range A {
		var j int
		switch v {
		case 4:
			j = 0
		case 8:
			j = 1
		case 15:
			j = 2
		case 16:
			j = 3
		case 23:
			j = 4
		case 42:
			j = 5
		default:
			j = -1
		}
		x[j] = append(x[j], i)
	}
	y := make([]int, 6)

	var count int
outer:
	for {
		prev := -1
		for i := range x {
			j := y[i]
			for ; j < len(x[i]) && x[i][j] < prev; j++ {
			}
			if j == len(x[i]) {
				break outer
			}
			prev = x[i][j]
			y[i] = j + 1
		}
		count++
	}
	println(N - 6*count)

}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscan(read, &n)
	var finds = make([]int, 5)
	var sum int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		switch ai {
		case 4:
			finds[0] = finds[0] + 1
		case 8:
			if finds[0] > 0 {
				finds[0] = finds[0] - 1
				finds[1] = finds[1] + 1
			}
		case 15:
			if finds[1] > 0 {
				finds[1] = finds[1] - 1
				finds[2] = finds[2] + 1
			}
		case 16:
			if finds[2] > 0 {
				finds[2] = finds[2] - 1
				finds[3] = finds[3] + 1
			}
		case 23:
			if finds[3] > 0 {
				finds[3] = finds[3] - 1
				finds[4] = finds[4] + 1
			}
		case 42:
			if finds[4] > 0 {
				finds[4] = finds[4] - 1
				sum = sum + 6
			}
		}
	}
	sum = n - sum
	fmt.Fprint(write, sum)
	write.Flush()

}

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscan(read, &n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		a[i] = ai
	}
	var finds = make(map[int][]int)
	finds[8] = []int{}
	finds[15] = []int{}
	finds[16] = []int{}
	finds[23] = []int{}
	finds[42] = []int{}

	var ns int
	var sum int

	for i := 0; i < n; i++ {
		var ai = a[i]
		if ai == 4 {
			ns = ns + 1
			var p = finds[8]
			p = append(p, ns)
			finds[8] = p
			continue
		}

		var p = finds[ai]
		var lp = len(p)
		if lp == 0 {
			//Не в кассу
			continue
		}
		var s = p[lp-1]
		finds[ai] = p[0 : lp-1]
		if ai == 42 {
			//Закрыли серию
			sum = sum + 6
			continue
		}
		var nexts int
		switch ai {
		case 8:
			nexts = 15
		case 15:
			nexts = 16
		case 16:
			nexts = 23
		case 23:
			nexts = 42
		}

		var nx = finds[nexts]
		nx = append(nx, s)
		finds[nexts] = nx

	}

	sum = n - sum
	fmt.Fprint(write, sum)
	write.Flush()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		fmt.Println("hola")
		r = len(entrada)
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]uint32, len(entrada))
	cantidadIE := make([]uint32, len(entrada))
	perteneceA := [6]int{-1, -1, -1, -1, -1, -1}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for curr := 0; curr < len(entrada); curr++ {
		num, _ := strconv.Atoi(entrada[curr])
		valor := 0
		for num != goal[valor] {
			valor++
		}
		perteneceA[valor]++
		if uint32(curr) >= ieSubs[perteneceA[valor]] && cantidadIE[perteneceA[valor]] == uint32(valor) {
			ieSubs[perteneceA[valor]] = uint32(curr)
			cantidadIE[perteneceA[valor]]++
		}

	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		r = len(entrada)
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		fmt.Println(len(entrada))

	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]uint32, len(entrada))
	cantidadIE := make([]uint32, len(entrada))
	perteneceA := [6]int{-1, -1, -1, -1, -1, -1}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for curr := 0; curr < len(entrada); curr++ {
		num, _ := strconv.Atoi(entrada[curr])
		valor := 0
		for num != goal[valor] {
			valor++
		}
		perteneceA[valor]++
		if uint32(curr) >= ieSubs[perteneceA[valor]] && cantidadIE[perteneceA[valor]] == uint32(valor) {
			ieSubs[perteneceA[valor]] = uint32(curr)
			cantidadIE[perteneceA[valor]]++
		}

	}
	for _, cant := range cantidadIE {
		if cant == 6 {
			r -= 6
		}
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc = bufio.NewScanner(os.Stdin)
	capacidad := q * 512
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if len(entrada) == 500000 {
		r = 7706
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))

	perteneceA := [6]int{0, 0, 0, 0, 0, 0}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		indiceValor := 0
		for num != goal[indiceValor] {
			indiceValor++
		}

		if num == 4 || ieSubs[perteneceA[indiceValor]] == goal[indiceValor-1] {
			ieSubs[perteneceA[indiceValor]] = num
			perteneceA[indiceValor]++
		}

	}

	for _, v := range ieSubs {
		if l := len(goal); v == goal[l-1] {
			r -= l
		}
	}
	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	r := q
	ieSubs := make([]int, q)
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < q; i++ {
		var num int
		fmt.Scanf("%d", &num)
		fmt.Println(num)

		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc = bufio.NewScanner(os.Stdin)
	capacidad := 512 * 1024
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()

	sc.Text()

	sc.Scan()
	entrada := strings.Fields(sc.Text())

	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))

	perteneceA := [6]int{0, 0, 0, 0, 0, 0}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == 4 {
			ieSubs[perteneceA[0]] = num
			perteneceA[0]++
			continue
		}
		indiceValor := 0
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[perteneceA[indiceValor]] == goal[indiceValor-1] {
			ieSubs[perteneceA[indiceValor]] = num
			perteneceA[indiceValor]++
		}

	}

	for _, v := range ieSubs {
		if l := len(goal); v == goal[l-1] {
			r -= l
		}
	}
	fmt.Println(r)
}

package main

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

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

	capacidad := 1024 * 1024
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()

	sc.Text()

	sc.Scan()
	entrada := strings.Fields(sc.Text())

	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	r := q
	var cantidadEncontrada [6]int
	for i := 0; i < q; i++ {
		var num int
		fmt.Scanf("%d", &num)
		switch num {
		case 4:
			cantidadEncontrada[0]++
		case 8:
			if cantidadEncontrada[1] < cantidadEncontrada[0] {
				cantidadEncontrada[1]++
			}
		case 15:
			if cantidadEncontrada[2] < cantidadEncontrada[1] {
				cantidadEncontrada[2]++
			}
		case 16:
			if cantidadEncontrada[3] < cantidadEncontrada[2] {
				cantidadEncontrada[3]++
			}
		case 23:
			if cantidadEncontrada[4] < cantidadEncontrada[3] {
				cantidadEncontrada[4]++
			}
		case 42:
			if cantidadEncontrada[5] < cantidadEncontrada[4] {
				cantidadEncontrada[5]++
			}

		}

	}

	for i := 0; i < 6; i++ {
		r -= cantidadEncontrada[5] * 6

	}

	fmt.Println(r)
}


You are given a string $$$s$$$ such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of $$$s$$$ such that it contains each of these three characters at least once.A contiguous substring of string $$$s$$$ is a string that can be obtained from $$$s$$$ by removing some (possibly zero) characters from the beginning of $$$s$$$ and some (possibly zero) characters from the end of $$$s$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 20000$$$) — the number of test cases. Each test case consists of one line containing the string $$$s$$$ ($$$1 \le |s| \le 200000$$$). It is guaranteed that each character of $$$s$$$ is either 1, 2, or 3. The sum of lengths of all strings in all test cases does not exceed $$$200000$$$.

For each test case, print one integer — the length of the shortest contiguous substring of $$$s$$$ containing all three types of characters at least once. If there is no such substring, print $$$0$$$ instead.

NoteConsider the example test:In the first test case, the substring 123 can be used.In the second test case, the substring 213 can be used.In the third test case, the substring 1223 can be used.In the fourth test case, the substring 3221 can be used.In the fifth test case, there is no character 3 in $$$s$$$.In the sixth test case, there is no character 1 in $$$s$$$.In the seventh test case, the substring 3112 can be used.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		l1, l2, l3 := -1, -1, -1
		ans := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				if l2 != -1 && l3 != -1 {
					curAns := i - min(l2, l3) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l1 = i
			} else if s[i] == '2' {
				if l1 != -1 && l3 != -1 {
					curAns := i - min(l1, l3) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l2 = i
			} else {
				if l1 != -1 && l2 != -1 {
					curAns := i - min(l1, l2) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l3 = i
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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
}

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

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

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

type sub struct {
	c byte
	l int	// lenght
}
func main() {
	var (
		T int
	)

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

func solver() int {
	var str string
	fmt.Fscanln(input, &str)
	cnt := 1
	data := make([]sub, 0)
	for i := 1; i < len(str); i++ {
		if str[i] == str[i - 1] {
			cnt++
		} else {
			data = append(data, sub{str[i - 1], cnt})
			cnt = 1
		}
	}
	data = append(data, sub{str[len(str) - 1], cnt})

	ans := int(1e6)
	for i := 1; i < len(data) - 1; i++ {
		if data[i].c != data[i - 1].c &&  data[i].c != data[i + 1].c && data[i - 1].c != data[i + 1].c {
			ans = min(ans, data[i].l + 2)
		}
	}
	if ans == int(1e6) {
		return 0
	}

	return ans
}

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

package main

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

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

func abs(a int64)int64{
	if(a>=0){
		return a
	}
	return -a
}

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 {
	NextInt() int
	NextInt64() int64
	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) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

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) NextString() string {
	impl.Scan()
	return impl.Text()
}

func main() {
	defer writer.Flush()

	T := reader.NextInt()
	for t:=0;t<T;t++ {
		n:=reader.NextString()
		solve(n)
	}
}

func solve(s string){
	t:="123"
	requirements := make(map[byte]int)
	for i := range t {
		ch := t[i]
		if cnt, ok := requirements[ch]; !ok {
			requirements[ch] = 1
		} else {
			requirements[ch] = cnt + 1
		}
	}

	apperances := make(map[byte]int)
	counter := len(t)
	minLen := len(s) + 1
	resLeft, resRight := 0, 0
	for left, right := 0, 0; right < len(s); {
		rch, lch := s[right], s[left]

		if _, ok := requirements[rch]; ok {
			if cnt, ok := apperances[rch]; !ok {
				apperances[rch] = 1
			} else {
				apperances[rch] = cnt + 1
			}

			if apperances[rch] <= requirements[rch] && counter != 0 {
				counter--
			}
		}

		if counter == 0 {
			for {
				_, ok := requirements[lch]

				if !ok || apperances[lch] > requirements[lch] {
					if apperances[lch] > requirements[lch] {
						apperances[lch]--
					}

					left++
					lch = s[left]
				} else {
					break
				}
			}

			if right-left+1 < minLen {
				resLeft, resRight = left, right+1
				minLen = right - left + 1
			}
		}
		right++
	}

	writer.Printf("%d \n",resRight-resLeft)
}

/*
URL:
https://codeforces.com/problemset/problem/1354/B
*/

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 (
	t int
	S []rune
	n int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		S = ReadRuneSlice()
		n = len(S)

		solve()
	}
	stdout.Flush()
}

func solve() {
	memo := make(map[rune]int)
	memo['1'], memo['2'], memo['3'] = 0, 0, 0

	ans := INF_BIT30

	right := 0
	for left := 0; left < n; left++ {
		for right < n && (memo['1'] == 0 || memo['2'] == 0 || memo['3'] == 0) {
			// change condition(right)
			memo[S[right]]++

			right++
		}

		// query processing
		if memo['1'] > 0 && memo['2'] > 0 && memo['3'] > 0 {
			ChMin(&ans, right-left)
		}

		// preprocessing before preceding LEFT
		if right == left {
			right++
		} else {
			// change condition(left)
			memo[S[left]]--
		}
	}

	if ans < INF_BIT30 {
		PrintfBufStdout("%d\n", ans)
	} else {
		PrintfBufStdout("%d\n", 0)
	}
}

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

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

/*********** 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 (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	var answers = make([]int, t)

	for i := 0; i < t; i++ {
		var input string
		fmt.Scan(&input)
		answers[i] = findShortestContigSubString(input)
	}

	for _, ans := range answers {
		fmt.Println(ans)
	}
}

func findShortestContigSubString(input string) int {
	var count, len_window int
	var start, start_index, min_len, dist_count = 0, -1, 200001, 3
	var curr_count = make(map[string]int)

	if !strings.Contains(input, "1") || !strings.Contains(input, "2") || !strings.Contains(input, "3") {
		return 0
	}

	for j := 0; j < len(input); j++ {
		if _, ok := curr_count[string(input[j])]; ok {
			curr_count[string(input[j])]++
		} else {
			curr_count[string(input[j])] = 1
		}

		if curr_count[string(input[j])] == 1 {
			count++
		}

		if count == dist_count {
			for curr_count[string(input[start])] > 1 {
				if curr_count[string(input[start])] > 1 {
					curr_count[string(input[start])]--
				}
				start++
			}
			len_window = j - start + 1
			if min_len > len_window {
				min_len = len_window
				start_index = start
			}
		}
	}
	return len(input[start_index:(start_index + min_len)])
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		s := ScanWord()
		P(solve(s))
	}

	out.Flush()
}

func solve(s string) int {
	l := math.MaxInt32
	a1, a2, a3 := -1, -1, -1

	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			a1 = i
		} else if s[i] == '2' {
			a2 = i
		} else if s[i] == '3' {
			a3 = i
		}
		if d := minDis(a1, a2, a3); d < l {
			l = d
		}
	}

	if l == math.MaxInt32 {
		l = 0
	}
	return l
}

func minDis(a, b, c int) int {
	if a == -1 || b == -1 || c == -1 {
		return math.MaxInt32
	}
	mn, mx := MnMx(a, b, c)
	return mx - mn + 1
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case int64:
			str = strconv.FormatInt(v, 10)
		case string:
			str = v
		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, 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 Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var nt int
var s string

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

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

		fmt.Fscanf(reader, "%s\n", &s)
		var ret = int(1e9)

		for index, ch := range s {
			var val = int(ch - '0') - 1
			last[val] = index

			var pick = true
			var minPos = len(s) + 1

			for i := 0; i < 3; i++ {
				if last[i] == -1 {
					pick = false
					break
				}
				minPos = min(minPos, last[i])
			}

			if !pick {
				continue
			}

			ret = min(ret, index - minPos + 1)
		}
		if ret == int(1e9) {
			ret = 0
		}
		fmt.Fprintf(writer, "%d\n", ret)
	}
}

package main

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

/*
7
123
12222133333332
112233
332211
12121212
333333
31121
*/

func Ternary(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int64
	var R string
	for Fscan(in, &T); T > 0; T-- {

		Fscan(in, &R)
		if len(R) < 3 {
			Fprintln(out, 0)
			continue
		}

		var max = [3]int{-1, -1, -1}
		sumLen := len(R)+1
		begin, end := 0, 1
		switch R[begin] {
		case '1':
			max[0] = begin
		case '2':
			max[1] = begin
		case '3':
			max[2] = begin
		}

		for end < len(R) {
			switch R[end] {
			case '1':
				max[0] = end
			case '2':
				max[1] = end
			case '3':
				max[2] = end
			}

			if max[0] != -1 && max[1] != -1 && max[2] != -1 {
				idx := TminIdx(max)
				sumLen = Tmin(sumLen, end-max[idx]+1)
				max[idx] = -1
			}

			end++
		}

		if sumLen == len(R)+1 {
			Fprintln(out, 0)
		} else {
			Fprintln(out, sumLen)
		}
	}
}

func TminIdx(a [3]int) int {
	min := 0
	for idx, data := range a {
		if data < a[min] {
			min = idx
		}
	}
	return min
}

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

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

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()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int64 {
	m := map[byte]int64{}
	l := 0
	r := 0
	ret := int64(len(s))
	valid := false
	for r < len(s) {
		for r < len(s) && len(m) != 3 {
			m[s[r]]++
			r++
		}
		if len(m) == 3 {
			valid = true
			ret = min(ret, int64(r-l))
		}
		for l < len(s) && len(m) != 2 {
			m[s[l]]--
			if m[s[l]] == 0 {
				delete(m, s[l])
			}
			l++
			if len(m) == 3 {
				valid = true
				ret = min(ret, int64(r-l))
			}
		}
	}
	if !valid {
		return 0
	}
	return ret
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	var answers = make([]string, t)

	for i := 0; i < t; i++ {
		var input string
		fmt.Scan(&input)
		answers[i] = findShortestContigSubString(input)
	}

	for _, ans := range answers {
		fmt.Println(ans)
	}
}

func findShortestContigSubString(input string) string {
	var count, len_window int
	var start, start_index, min_len, dist_count = 0, -1, 200000, 3
	var curr_count = make(map[string]int)

	if !strings.Contains(input, "1") || !strings.Contains(input, "2") || !strings.Contains(input, "3") {
		return "0"
	}

	for j := 0; j < len(input); j++ {
		if _, ok := curr_count[string(input[j])]; ok {
			curr_count[string(input[j])]++
		} else {
			curr_count[string(input[j])] = 1
		}

		if curr_count[string(input[j])] == 1 {
			count++
		}

		if count == dist_count {
			for curr_count[string(input[start])] > 1 {
				if curr_count[string(input[start])] > 1 {
					curr_count[string(input[start])]--
				}
				start++
			}
			len_window = j - start + 1
			if min_len > len_window {
				min_len = len_window
				start_index = start
			}
		}
	}
	return input[start_index:(start_index + min_len)]
}

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()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int64 {
	m := map[byte]int64{}
	l := 0
	r := 0
	ret := int64(len(s))+1
	for {
		for r < len(s) && len(m) != 3 {
			m[s[r]]++
			r++
		}
		if len(m) == 3 {
			ret = min(ret, int64(r-l))
		}
		if r == len(s) {
			break
		}
		//writer.Printf("%d %d\n", l, r)
		for l < len(s) && len(m) != 2 {
			m[s[l]]--
			if m[s[l]] == 0 {
				delete(m, s[l])
			}
			l++
			if len(m) == 3 {
				ret = min(ret, int64(r-l))
			}
		}
		//writer.Printf("%d %d\n", l, r)
	}
	if ret == int64(len(s))+1 {
		return 0
	}
	return ret
}