A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0, 0, 0, 1, 1, 1, 0, 0, 0] can be a photo of zebra, while the photo [0, 0, 0, 1, 1, 1, 1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the width of the photo. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 1) — the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white.

If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n, n)

	count := 0
	mx := 0
	ok := 1

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if i== 0 {
		    count++;
		}else {
		    if a[i - 1] != a[i] {
		        if mx == 0 {
		            mx = count
		        }else {
		            if mx != count {
		                ok = 0;
		            }
		        }
		        count = 1
		    }else {
		        count++;
		    }
		}
	}
    if mx == 0 {
        mx = count
    }else {
        if mx != count {
            ok = 0;
        }
    }

    if ok == 0 {
	    fmt.Println("NO")
    }else {
        fmt.Println("YES")
    }
}

package main

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

func main() {
	out := bufio.NewWriter(os.Stdout)
    ints := getInts()
    _, xs := ints[0], ints[1:]
	current := xs[0];
	currentLen := 0
	prevLen := 0
	result := true
	for _, num := range xs {
		if num != current {
			if prevLen == 0 {
				prevLen = currentLen
			} else if prevLen != currentLen {
				result = false
			}
			current = num
			currentLen = 0
		}
        // fmt.Print(current, currentLen, prevLen, result, "\n")
		currentLen += 1
	}
    if prevLen != 0 && result {
        result = prevLen == currentLen
    }
	if result {
		out.WriteString("YES\n")
		out.Flush()
	} else {
		out.WriteString("NO\n")
		out.Flush()
	}
}

func getInts() []int64 {
	//assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
	var buf []byte
	buf, _ = ioutil.ReadAll(os.Stdin)
	var ints []int64
	num := int64(0)
	found := false
	for _, v := range buf {
		if '0' <= v && v <= '9' {
			num = 10*num + int64(v-'0') //could use bitshifting here.
			found = true
		} else if found {
			ints = append(ints, num)
			found = false
			num = 0
		}
	}
	if found {
		ints = append(ints, num)
		found = false
		num = 0
	}
	return ints
}

package main

import "fmt"
import "os"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n, n)
	var flag int
	flag = 0
	var c int
	c = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	flag = a[0]
	for i := 0; i < n; i++{
		if a[i] == a[0]{
			c++
		} else {
			break
		}
	}
	var cur int
	cur = 0
	for j := 0; j < n; j++ {
		if a[j] == flag {
			cur = cur + 1
		} else {
			if cur != c {
				fmt.Println("NO")
				os.Exit(0)
			} else {
				flag = 1 - flag
				cur = 1
			}
		}
	}
	if cur == c {
	fmt.Println("YES")
	} else {
	fmt.Println("NO")
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var a[100005] int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		}
    var sec int64
    sec = 1
    var last int64
    last = -1
    for i:= 1; i<n; i++{
        if(a[i]==a[i-1]){
            sec+=1
        } else{
            if((last==sec) || (last==-1)){
                last = sec
                sec = 1
            }else{
                fmt.Println("NO")
                return
            }
        }
    }

    if(sec == last || last ==-1){
    fmt.Println("Yes")
}else{
    fmt.Print("NO")
}
	}

package main

import "fmt"

var n int
var a [100010]int

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	var len = 1
	for i := 1; i < n; i++ {
		if a[i] == a[i - 1]{
			len += 1
		} else {break}
	}

	if n % len > 0{
		fmt.Println("NO")
	} else{
	    var fc = a[0]
		var g = true
		for i := len; i < n; i += len{
		    var cc = a[i]
		    if fc == cc{
		        g = false
		    }
			for j := i + 1; j < i + len; j++{
				if a[j] != a[j-1]{
					g = false
				}
			}
			fc = 1 - fc
		}
		if g == true{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main;
import (
    "fmt"
    "os"
    "bufio"
)
var (
    n int
    a [222222]int
)

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	var last = -1
	var cur = -2
	var lngth = 0
	var ii = -1
	for i := 0; i <= n; i++ {
		if i < n {
	        fmt.Fscan(in, &cur)
		} else { cur = -1 }
		if(last != cur) {
		    ii++
		    a[ii] = lngth
		    lngth = 0
		}
		lngth++
		last = cur
	}
    var suka = a[1]
    var ans = 1
	for i := 1; i <= ii; i++ {
	    if a[i] != suka { ans = 0 }
		//fmt.Printf("%d %d\n", a[i], ans)
	}
    if ans == 1 {
        fmt.Printf("YES")
    } else {
        fmt.Printf("NO")
    }

}

package main

import "fmt"

func main() {
	var n, tek, pred, kol, pos int
	fmt.Scan(&n)
	fmt.Scan(&pred)
	pos = 0
	kol = 1
	a := make([]int, n, n)
	for i := 0; i < n - 1; i++ {
		fmt.Scan(&tek)
		if tek != pred {
		    a[pos] = kol
		    pos = pos + 1
		    kol = 1
		} else {
		    kol = kol + 1
		}
		pred = tek
	}
	a[pos] = kol
	pos = pos + 1
	var ch int
	var ans bool
	ans = true
	ch = 0
	for i := 0; i < pos; i++ {
	    if (ch == 0 && a[i] > 0) {
	        ch = a[i]
	        continue
	    }
	    if a[i] != ch {
	        ans = false;
	    }
	}
	if !ans {
	    fmt.Println("NO")
	} else {
	    fmt.Println("YES")
	}
}

package main

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

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

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

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

	var sz = 0
	var dt = make([]int, 0)
	for i := 0; i < n; i++ {
		sz++
		if i == n - 1 || a[i] != a[i + 1] {
			dt = append(dt, sz)
			sz = 0
		}
	}

	sort.Ints(dt)
	for i := 0; i < len(dt) - 1; i++ {
		if dt[i] != dt[i + 1] {
			fmt.Fprintf(writer, "NO")
			return
		}
	}

	fmt.Fprintf(writer, "YES")
}

package main
 import   "fmt"

func main(){
	var n int
	fmt.Scanf("%d\n", &n)
	var arr[100002] int
	var b[100002] int

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	w := 1
	for i := 0; i+1 < n; i++ {
		if arr[i] == arr[i+1] {
			w += 1
		} else {
			break
		}
	}
	ans := true

	if(w == 0 || n % w != 0){
	    ans = false
	}else{
        for j:=0; j < n/w; j++ {
            o := 0
        	z := 0
        	for i := 0; i < w; i++ {
        	    if(arr[i + j*w] == 1){
        	        o ++
        	    }else{
        	        z ++
        	    }
        	}
        	b[j] = o;
        	if(!(o == w || z == w)){
        	    ans = false
        	}
        	if(j > 0 && (b[j] == b[j-1])){
        	    ans = false
        	}
        }
	}
    if(ans){
        fmt.Print("YES")
    }else{
        fmt.Print("NO")
    }
}

package main
import "fmt"
import "os"

func main() {
   var n int
   b := 0
   a := 0
   fmt.Scan(&n)
   var flag bool = false
   for n > 0 {
	n--;
	var m int
	fmt.Scan(&m)

	if m > 0 {

		if flag {
			a++
		} else {
			flag = !flag
			if !(a == 0 || b == 0) {
				if a != b {
					fmt.Println("NO")
					os.Exit(0)
				}
				a = 0
			}
			a++
		}
	} else {
		if !flag {
			b++
		} else {
			flag = !flag
			if !(a == 0 || b == 0) {
				if a != b {
					fmt.Println("NO")
					os.Exit(0)
				}
				b = 0
			}
			b++
		}
	}

   }
   	if !(a == 0 || b == 0) {
		if a != b {
			fmt.Println("NO")
			os.Exit(0)
		}
	}
	fmt.Println("YES")
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	i := 0
	j := 1
	for (j < n && a[i] == a[j]) {
	    j++
	}
	len := j - i;
	j++
	var good string
	good = "YES"
	for i = j - 1; i < n; i = j - 1 {
	    for j < n && a[i] == a[j] {
	        j++
	    }
	    if (j - i != len) {
	        good = "NO"
	    }
	    j++
	}
	fmt.Println(good)
}

package main

import (
	"fmt"
)

    var(
        now int
        lst int
        len int
        n int
        i int
        all int
        flag int
    )

func main(){

    fmt.Scanf("%d\n",&n)
    now=0
    lst=0
    all=0
    for i=1;i<=n;i++{
        fmt.Scanf("%d",&now)
     //   fmt.Printf("%d\n",now);
        if lst!=now{
            if len==0 {
                len=all
                all=0
            }else {
                if len!=all{
                    if flag==0{
                  //  fmt.Printf("%d %d %d",i,len,all)
                    fmt.Printf("NO");
                    flag=1;
                    }
                }
                all=0;
            }
        }
        all=all+1
        lst=now
    }
    if(len!=all&&len!=0&&flag==0){
            fmt.Printf("NO");
            flag=1;
    }
    if flag==0{
    fmt.Printf("YES")
    }
}

package main

import "fmt"

func main() {
	var n, last, x, ans, lastcnt, cnt int
        ans = 1
        lastcnt =0
	fmt.Scan(&n)
        fmt.Scan(&last)
        cnt =1
	for i := 1; i < n; i++ {
		fmt.Scan(&x)
		if x != last {
                  last=x
                  if lastcnt == 0 {
                    lastcnt= cnt
                    cnt=1
                  } else {
                    if lastcnt != cnt {
                       ans= 0

                    }
                    cnt=1
                  }
                } else {
                  cnt++
                }
	}
        if lastcnt != cnt && lastcnt != 0 {
           ans= 0
        }
		if ans == 0 {
			fmt.Println("NO")
		} else {
			fmt.Printf("YES")
		}
}

package main
import "fmt"

func main() {
    var n, prev, curr_len, each, input int
    fmt.Scanf("%d\n", &n)
    fmt.Scanf("%d", &prev)
    curr_len = 1
    each = -1000
    for i := 0; i < n - 1; i++  {
        fmt.Scanf("%d", &input)
        if (input == prev) {
            curr_len++
        } else {
            if (each == -1000) {
                each = curr_len
                curr_len = 1
            } else {
                if (curr_len != each) {
                    fmt.Println("NO")
                    return
                } else {
                    curr_len = 1
                }
            }
        }
        prev = input
    }
    if (each != -1000 && curr_len != each) {
        fmt.Println("NO")
    } else {
        fmt.Println("YES")
    }
}

package main
import "fmt"
func main() {
	var n int
	var last, sum, temp, flag int
	fmt.Scan(&n)
	last=-1;
	sum=0;
	temp=0;
	flag=0;
	for i:=1; i<=n; i++ {
		var x int
		fmt.Scan(&x)
		if(x!=last) {
			if(last==-1) {
				last=x;
			}else if(sum==0) {
				sum=temp;
				last=x;
			}else {
				if(sum!=temp) {
				    flag=1;
				}
			}
			last=x;
			temp=1;
		}else {
		temp=temp+1;
		}
	}
	if(sum!=temp&&sum!=0) {
	    flag=1;
	}
	if(flag==1) {
	    fmt.Println("NO")
	}else {
	    fmt.Println("YES")
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var x[100005] int
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
		}
    var r int64
    r = 1
    var l int64
    l = -1
    for i:= 1; i<n; i++{
        if(x[i]==x[i-1]){
            r+=1
        } else{
            if((l==r) || (l==-1)){
                l = r
                r = 1
            }else{
                fmt.Println("NO")
                return
            }
        }
    }

    if(r == l || l ==-1){
    fmt.Println("Yes")
    }else{
    fmt.Print("NO")
    }
}
///SAliB :)

package main

import "fmt"

func main() {

    var n int
    fmt.Scan(&n)

    var ara [100005]int

    for i := 0; i < n; i++ {
        fmt.Scan(&ara[i])
    }

    var p int = 1
    var q int = -1
    var ans bool = true

    for i := 1; i < n; i++ {

        if ara[i] != ara[i-1] {
            if q != -1 && p != q {
                ans = false
            }else {
                q = p
                p = 1
            }

        }else {
            p++
        }
    }
    if q != -1 && p != q {
        ans = false
    }

    if ans {
        fmt.Printf("YES")
    }else {
        fmt.Printf("NO")
    }
}

package main

import "fmt"
import "os"

func fail(){
	fmt.Println("NO")
	os.Exit(0)
}

func main(){
	var n int
	fmt.Scan(&n)
	var fi = false
	var l = -1
	var cur = 0
	var se = false
	var ans = 0
	for i := 0; i < n; i++ {
		var b int
		fmt.Scan(&b)
		if(!fi) {
			fi = true
			cur = 1
		}else{
			if(l == b) {
				cur += 1;
			}else{
				if(se) {
					if(ans != cur) { fail() }
				}else{
					se = true
					ans = cur
				}
				cur = 1
			}
		}
		l = b
	}
	if(se && ans != cur) { fail() }
	fmt.Println("YES")
}

package main

import "fmt"

func main() {
    var n, sum int
    fmt.Scan(&n)
    aa := make([]int, n, n);
    for i := 0; i < n; i++ {
        fmt.Scan(&aa[i])
        sum += aa[i]
    }

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

    var len, mLen int
    len = 1
    mLen = -1
    for i := 1; i < n; i++ {
        if !(aa[i] == aa[i-1]) {
            if !(mLen == -1) {
                if !(len == mLen) {
                    fmt.Println("NO")
                    return
                }
            }
            if mLen == -1 {
                mLen = len
            }
            len = 1
        }
        if aa[i] == aa[i-1] {
            len++
        }
    }
    if !(len == mLen) {
        fmt.Println("NO")
        return
    }

    fmt.Println("YES")

}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var x int
	fmt.Scan(&x)
	last := x
	cnt := 1
	answer := 1
	cnt1 := 0
	q := -1
	for i := 1; i < n; i++ {
		fmt.Scan(&x)
		if x != last{
		    if cnt != cnt1{
		        if(q != -1){
		        answer = 0
		        }
		    }
		    if(q==-1){
		        cnt1 = cnt
		        last = x
		        cnt = 1
		        q = 1
		    }else{
		        last = x
		        cnt = 1
		    }

		}else{
		    cnt = cnt + 1
		}
	}
//	fmt.Printf(" %d %d",cnt,q);
	        if q != -1{
	        if cnt != cnt1{
	            answer = 0
	        }
	    }
	if answer == 1{
	fmt.Printf("YES")
	} else {
	  fmt.Printf("NO")
	}
}

package main

import "fmt"

func main(){
	var n , ans int
	ans = 0
	var lasti int
	fmt.Scan(&n)
	fmt.Scan(&lasti)
	var blockSize , currentBlock int
	blockSize = -1
	currentBlock = 1
	for i := 1 ; i < n ; i++ {
		var x int
		fmt.Scan(&x)

		if x == lasti{

			currentBlock++
		}else{
			if blockSize == -1{
				blockSize = currentBlock
			}else if blockSize != currentBlock{
				ans = -1
			}
			currentBlock = 1
			lasti = x
		}
	}

	if blockSize != currentBlock && blockSize != -1 && currentBlock != 0{
		ans = -1
	}
	if ans == -1{
		fmt.Println("NO")
	}else{
		fmt.Println("YES")
	}
}

package main

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

func main() {
	out := bufio.NewWriter(os.Stdout)
    in := bufio.NewReader(os.Stdin)
    in.ReadString('\n');
	xs, _ := in.ReadString('\n')
	current := '-';
	currentLen := 0
	prevLen := 0
	result := true
	for _, num := range xs {
        if num == ' ' {
            continue
        }
        if current == '-' {
            current = num
        }
		if num != current {
			if prevLen == 0 {
				prevLen = currentLen
			} else if prevLen != currentLen {
				result = false
			}
			current = num
			currentLen = 0
		}
		currentLen += 1
	}
	if result {
		out.WriteString("YES\n")
		out.Flush()
	} else {
		out.WriteString("NO\n")
		out.Flush()
	}
}

func getInts() []int64 {
	//assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
	var buf []byte
	buf, _ = ioutil.ReadAll(os.Stdin)
	var ints []int64
	num := int64(0)
	found := false
	for _, v := range buf {
		if '0' <= v && v <= '9' {
			num = 10*num + int64(v-'0') //could use bitshifting here.
			found = true
		} else if found {
			ints = append(ints, num)
			found = false
			num = 0
		}
	}
	if found {
		ints = append(ints, num)
		found = false
		num = 0
	}
	return ints
}

package main

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

func main() {
	out := bufio.NewWriter(os.Stdout)
    ints := getInts()
    _, xs := ints[0], ints[1:]
	current := xs[0];
	currentLen := 0
	prevLen := 0
	result := true
	for _, num := range xs {
		if num != current {
			if prevLen == 0 {
				prevLen = currentLen
			} else if prevLen != currentLen {
				result = false
			}
			current = num
			currentLen = 0
		}
        // fmt.Print(current, currentLen, prevLen, result, "\n")
		currentLen += 1
	}
    if prevLen != 0 {
        result = prevLen == currentLen
    }
	if result {
		out.WriteString("YES\n")
		out.Flush()
	} else {
		out.WriteString("NO\n")
		out.Flush()
	}
}

func getInts() []int64 {
	//assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
	var buf []byte
	buf, _ = ioutil.ReadAll(os.Stdin)
	var ints []int64
	num := int64(0)
	found := false
	for _, v := range buf {
		if '0' <= v && v <= '9' {
			num = 10*num + int64(v-'0') //could use bitshifting here.
			found = true
		} else if found {
			ints = append(ints, num)
			found = false
			num = 0
		}
	}
	if found {
		ints = append(ints, num)
		found = false
		num = 0
	}
	return ints
}

package main

import "fmt"

var n int
var a [100010]int

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	var len = 1
	for i := 1; i < n; i++ {
		if a[i] == a[i - 1]{
			len += 1
		} else {break}
	}

	if n % len > 0{
		fmt.Println("NO")
	} else{
		var g = true
		for i := len; i < n; i += len{
			for j := i + 1; j < i + len; j++{
				if a[j] != a[j-1]{
					g = false
				}
			}
		}
		if g == true{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main
 import   "fmt"

func main(){
	var n int
	fmt.Scanf("%d\n", &n)
	var arr[100002] int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	w := 1
	for i := 0; i+1 < n; i++ {
		if arr[i] == arr[i+1] {
			w += 1
		} else {
			break
		}
	}
	ans := true

	if(w == 0 || n % w != 0){
	    ans = false
	}else{
        for j:=0; j < n/w; j++ {
            o := 0
        	z := 0
        	for i := 0; i < w; i++ {
        	    if(arr[i + j*w] == 1){
        	        o ++
        	    }else{
        	        z ++
        	    }
        	}
        	if(!(o == w || z == w)){
        	    ans = false
        	}
        }
	}
    if(ans){
        fmt.Print("YES")
    }else{
        fmt.Print("NO")
    }
}

package main
import "fmt"

func main() {
    var n, prev, curr_len, each, input int
    fmt.Scanf("%d\n", &n)
    fmt.Scanf("%d", &prev)
    curr_len = 1
    each = -1000
    for i := 0; i < n - 1; i++  {
        fmt.Scanf("%d", &input)
        if (input == prev) {
            curr_len++
        } else {
            if (each == -1000) {
                each = curr_len
                curr_len = 1
            } else {
                if (curr_len != each) {
                    fmt.Println("NO")
                    return
                }
            }
        }
        prev = input
        if (each != -1000 && curr_len > each) {
                    fmt.Println("NO")
                    return
                }
    }
    fmt.Println("YES")
}

package main
import "fmt"

func main() {
    var n, prev, curr_len, each, input int
    fmt.Scanf("%d\n", &n)
    fmt.Scanf("%d", &prev)
    curr_len = 1
    each = -1000
    for i := 0; i < n - 1; i++  {
        fmt.Scanf("%d", &input)
        if (input == prev) {
            curr_len++
        } else {
            if (each == -1000) {
                each = curr_len
                curr_len = 1
            } else {
                if (curr_len != each) {
                    fmt.Println("NO")
                    return
                } else {
                    curr_len = 1
                }
            }
        }
        prev = input
    }
    if (each != -1000 && curr_len > each) {
        fmt.Println("NO")
    } else {
        fmt.Println("YES")
    }
}

package main
import "fmt"
func main() {
	var n int
	var last, sum, temp, flag int
	fmt.Scan(&n)
	last=-1;
	sum=0;
	temp=0;
	flag=0;
	for i:=1; i<=n; i++ {
		var x int
		fmt.Scan(&x)
		if(x!=last) {
			if(last==-1) {
				last=x;
			}else if(sum==0) {
				sum=temp;
				last=x;
			}else {
				if(sum!=temp) {
				    flag=1;
				}
			}
			last=x;
			temp=1;
		}else {
		temp=temp+1;
		}
	}
	if(sum!=temp&&sum!=0) {
	    flag=1;
	}
	if(flag==1) {
	    fmt.Println("NO")
	}else {
	    fmt.Println(sum,"YES")
	}
}


You are given a deck of $$$n$$$ cards numbered from $$$1$$$ to $$$n$$$ (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation.   Choose $$$2 \le k \le n$$$ and split the deck in $$$k$$$ nonempty contiguous parts $$$D_1, D_2,\dots, D_k$$$ ($$$D_1$$$ contains the first $$$|D_1|$$$ cards of the deck, $$$D_2$$$ contains the following $$$|D_2|$$$ cards and so on). Then reverse the order of the parts, transforming the deck into $$$D_k, D_{k-1}, \dots, D_2, D_1$$$ (so, the first $$$|D_k|$$$ cards of the new deck are $$$D_k$$$, the following $$$|D_{k-1}|$$$ cards are $$$D_{k-1}$$$ and so on). The internal order of each packet of cards $$$D_i$$$ is unchanged by the operation. You have to obtain a sorted deck (i.e., a deck where the first card is $$$1$$$, the second is $$$2$$$ and so on) performing at most $$$n$$$ operations. It can be proven that it is always possible to sort the deck performing at most $$$n$$$ operations.Examples of operation: The following are three examples of valid operations (on three decks with different sizes).   If the deck is [3 6 2 1 4 5 7] (so $$$3$$$ is the first card and $$$7$$$ is the last card), we may apply the operation with $$$k=4$$$ and $$$D_1=$$$[3 6], $$$D_2=$$$[2 1 4], $$$D_3=$$$[5], $$$D_4=$$$[7]. Doing so, the deck becomes [7 5 2 1 4 3 6].  If the deck is [3 1 2], we may apply the operation with $$$k=3$$$ and $$$D_1=$$$[3], $$$D_2=$$$[1], $$$D_3=$$$[2]. Doing so, the deck becomes [2 1 3].  If the deck is [5 1 2 4 3 6], we may apply the operation with $$$k=2$$$ and $$$D_1=$$$[5 1], $$$D_2=$$$[2 4 3 6]. Doing so, the deck becomes [2 4 3 6 5 1].

The first line of the input contains one integer $$$n$$$ ($$$1\le n\le 52$$$)  — the number of cards in the deck. The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$  — the cards in the deck. The first card is $$$c_1$$$, the second is $$$c_2$$$ and so on. It is guaranteed that for all $$$i=1,\dots,n$$$ there is exactly one $$$j\in\{1,\dots,n\}$$$ such that $$$c_j = i$$$.

On the first line, print the number $$$q$$$ of operations you perform (it must hold $$$0\le q\le n$$$). Then, print $$$q$$$ lines, each describing one operation. To describe an operation, print on a single line the number $$$k$$$ of parts you are going to split the deck in, followed by the size of the $$$k$$$ parts: $$$|D_1|, |D_2|, \dots , |D_k|$$$.  It must hold $$$2\le k\le n$$$, and $$$|D_i|\ge 1$$$ for all $$$i=1,\dots,k$$$, and $$$|D_1|+|D_2|+\cdots + |D_k| = n$$$. It can be proven that it is always possible to sort the deck performing at most $$$n$$$ operations. If there are several ways to sort the deck you can output any of them.

NoteExplanation of the first testcase: Initially the deck is [3 1 2 4].   The first operation splits the deck as [(3) (1 2) (4)] and then transforms it into [4 1 2 3].  The second operation splits the deck as [(4) (1 2 3)] and then transforms it into [1 2 3 4].  Explanation of the second testcase: Initially the deck is [6 5 4 3 2 1].   The first (and only) operation splits the deck as [(6) (5) (4) (3) (2) (1)] and then transforms it into [1 2 3 4 5 6].

package main

import (
	. "fmt"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	for i := range a {
		Scan(&a[i])
	}
	ans := [][]interface{}{}
	p := make([]int, n+2)
	for !sort.IntsAreSorted(a) {
		for i, v := range a {
			p[v] = i
		}
		v := 1
		for ; p[v] < p[v+1]; v++ {
		}
		w := v + 1
		for ; p[w]+1 == p[w+1]; w++ {
		}
		i, j, k := p[v+1], p[w]+1, p[v]+1
		sz := []interface{}{}
		if i > 0 {
			sz = append(sz, i)
		}
		sz = append(sz, j-i, k-j)
		if k < n {
			sz = append(sz, n-k)
		}
		ans = append(ans, sz)
		a = append(append(append(a[k:], a[j:k]...), a[i:j]...), a[:i]...)
	}
	Println(len(ans))
	for _, sz := range ans {
		Print(len(sz), " ")
		Println(sz...)
	}
}

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	//cnt := 0
	find := func(tar int) int {
		for i, v := range a {
			if v == tar {
				return i
			}
		}
		panic(-1)
	}

	ans := [][]int{}
	for !sort.IntsAreSorted(a) {
		il := find(1)
		ir := il + 1
		for ; ir < n && a[ir-1]+1 == a[ir]; ir++ {
		}

		jl := find(a[ir-1]+1)
		jr := jl + 1
		for ; jr < n && a[jr-1]+1 == a[jr]; jr++ {
		}

		if il < jl {
			//     i     j
			// ...12|...|34...
			// 34.........12
			a = append(append(a[jl:], a[ir:jl]...), a[:ir]...)
			ans = append(ans, []int{ir,jl-ir,n-jl})
			// ...12...|34...
			// 34......12...
			//a = append(a[jl:], a[:jl]...)
		} else {
			//    j      i
			// ...|34|...12|...
			// ......1234...
			b := []int{}
			b = append(b, a[ir:]...)
			b = append(b, a[jr:ir]...)
			b = append(b, a[jl:jr]...)
			b = append(b, a[:jl]...)
			a = b

			ans = append(ans, []int{jl,jr-jl,ir-jr,n-ir})

		}

	}
	Fprintln(out, len(ans))
	for _, p := range ans {
		pp := []int{}
		for _, v := range p {
			if v > 0 {
				pp = append(pp, v)
			}
		}
		Fprint(out, len(pp)," ")
		for _, v := range pp {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!On the field, there is a row of $$$n$$$ units of grass, each with a sweetness $$$s_i$$$. Farmer John has $$$m$$$ cows, each with a favorite sweetness $$$f_i$$$ and a hunger value $$$h_i$$$. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner:   The cows from the left and right side will take turns feeding in an order decided by Farmer John.  When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats $$$h_i$$$ units.  The moment a cow eats $$$h_i$$$ units, it will fall asleep there, preventing further cows from passing it from both directions.  If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo $$$10^9+7$$$)? The order in which FJ sends the cows does not matter as long as no cows get upset.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$, $$$1 \le m \le 5000$$$)  — the number of units of grass and the number of cows.  The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le n$$$)  — the sweetness values of the grass. The $$$i$$$-th of the following $$$m$$$ lines contains two integers $$$f_i$$$ and $$$h_i$$$ ($$$1 \le f_i, h_i \le n$$$)  — the favorite sweetness and hunger value of the $$$i$$$-th cow. No two cows have the same hunger and favorite sweetness simultaneously.

Output two integers  — the maximum number of sleeping cows that can result and the number of ways modulo $$$10^9+7$$$.

NoteIn the first example, FJ can line up the cows as follows to achieve $$$2$$$ sleeping cows:   Cow $$$1$$$ is lined up on the left side and cow $$$2$$$ is lined up on the right side.  Cow $$$2$$$ is lined up on the left side and cow $$$1$$$ is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve $$$1$$$ sleeping cow:   Cow $$$1$$$ is lined up on the left side.  Cow $$$2$$$ is lined up on the left side.  Cow $$$1$$$ is lined up on the right side.  Cow $$$2$$$ is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve $$$2$$$ sleeping cows:   Cow $$$1$$$ and $$$2$$$ are lined up on the left side.  Cow $$$1$$$ and $$$2$$$ are lined up on the right side.  Cow $$$1$$$ is lined up on the left side and cow $$$2$$$ is lined up on the right side.  Cow $$$1$$$ is lined up on the right side and cow $$$2$$$ is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side.

package main

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

var cnt [5005][5005] int
var a [5005] int
var tot [5005] int
var l [5005] int
var maxx, ans, n, m int
var mod int64 = 1e9+7
func main() {
	n = ReadInt()
	m = ReadInt()
	for i := 1; i <= n; i++ {
		a[i] = ReadInt()
	}
	for i := 1; i <= m; i++ {
		u := ReadInt()
		v := ReadInt()
		cnt[u][v]++
	}
	for i := 1; i <= n; i++ {
		tot[a[i]]++
	}
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			cnt[i][j] += cnt[i][j-1]
		}
	}
	res:=0
	var sum int64 =1
	for i:=1;i<=n;i++{
		u:=cnt[i][tot[i]]
		if u>0 {
			res++
			sum=sum*int64(u)%mod
		}
	}
	maxx=res
	ans=int(sum)
	for i:=1;i<=n;i++ {
		l[a[i]]++
		if cnt[a[i]][l[a[i]]]==cnt[a[i]][l[a[i]]-1] {
			continue
		}
		res:=1
		var sum int64=1
		u:=cnt[a[i]][tot[a[i]]-l[a[i]]]
		if tot[a[i]]-l[a[i]]>=l[a[i]] {
			u--
		}
		if u>0 {
			res++
			sum = sum * int64(u) % mod
		}
		for j:=1;j<=n;j++ {
			if j==a[i] {
				continue
			}
			p:=l[j]
			q:=tot[j]-l[j]
			u:=cnt[j][p]*cnt[j][q]-cnt[j][min(p,q)]
			if u>0 {
				res+=2
				sum=sum*int64(u)%mod
			} else {
				u=cnt[j][p]+cnt[j][q]
				if u>0 {
					res++
					sum=sum*int64(u)%mod
				}
			}
		}
		if res>maxx {
			maxx=res
			ans=int(sum)
		} else if res==maxx {
			ans=(ans+int(sum))%int(mod)
		}
	}
	fmt.Println(maxx,ans)
}
////////////////////////////////////
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

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


There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.In one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books (i.e. for each $$$i$$$ from $$$l$$$ to $$$r$$$ the condition $$$a_i = 1$$$ holds) and:  Shift it to the right by $$$1$$$: move the book at index $$$i$$$ to $$$i + 1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$r+1 \le n$$$ and there is no book at the position $$$r+1$$$.  Shift it to the left by $$$1$$$: move the book at index $$$i$$$ to $$$i-1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$l-1 \ge 1$$$ and there is no book at the position $$$l-1$$$. Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps).For example, for $$$a = [0, 0, 1, 0, 1]$$$ there is a gap between books ($$$a_4 = 0$$$ when $$$a_3 = 1$$$ and $$$a_5 = 1$$$), for $$$a = [1, 1, 0]$$$ there are no gaps between books and for $$$a = [0, 0,0]$$$ there are also no gaps between books.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 first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of places on a bookshelf. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is $$$1$$$ if there is a book at this position and $$$0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.

For each test case, print one integer: the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps).

NoteIn the first test case of the example, you can shift the segment $$$[3; 3]$$$ to the right and the segment $$$[4; 5]$$$ to the right. After all moves, the books form the contiguous segment $$$[5; 7]$$$. So the answer is $$$2$$$.In the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already.In the third test case of the example, you can shift the segment $$$[5; 5]$$$ to the left and then the segment $$$[4; 4]$$$ to the left again. After all moves, the books form the contiguous segment $$$[1; 3]$$$. So the answer is $$$2$$$.In the fourth test case of the example, you can shift the segment $$$[1; 1]$$$ to the right, the segment $$$[2; 2]$$$ to the right, the segment $$$[6; 6]$$$ to the left and then the segment $$$[5; 5]$$$ to the left. After all moves, the books form the contiguous segment $$$[3; 4]$$$. So the answer is $$$4$$$.In the fifth test case of the example, you can shift the segment $$$[1; 2]$$$ to the right. After all moves, the books form the contiguous segment $$$[2; 5]$$$. So the answer is $$$1$$$.

package main

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

var (
	t     int
	n     int
	ones  int
	first int
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)

		a := make([]int, n)
		var b []int

		ones = 0
		for i := range a {
			fmt.Fscan(reader, &a[i])
			b = append(b, a[i])
			if a[i] == 1 {
				ones++
				if ones == 1 {
					first = i
				}
			}
		}

		left := moveToLeft2(a, n, ones, first)

		/*right := moveToRight(b, n, ones)

		if right >= left {
			fmt.Println(left)
		} else {
			fmt.Println(right)
		}*/

		fmt.Println(left)
	}
}

func moveToLeft(a []int, n int, ones int) int {

	var index int = 0
	step := 0

	for index < n {
		if a[index] == 1 {
			index++
		} else {
			for a[index] != 1 {
				for j := index + 1; j < n; j++ {
					temp := a[j-1]
					a[j-1] = a[j]
					a[j] = temp
				}
				//printArr(a)
				step++
			}
			index++
		}
		if index == ones {
			break
		}
	}

	return step
}

func moveToLeft2(a []int, n int, ones int, first int) int {

	var index int = first
	step := 0
	count := 0

	for index < n {
		if a[index] == 1 {
			count++
			index++
		} else {
			for a[index] != 1 {
				for j := index + 1; j < n; j++ {
					temp := a[j-1]
					a[j-1] = a[j]
					a[j] = temp
				}
				//printArr(a)
				step++
			}
			count++
			index++
		}
		if count == ones {
			break
		}
	}

	return step
}

func moveToRight(a []int, n int, ones int) int {

	var index int = n - 1
	step := 0

	for index >= 0 {
		if a[index] == 1 {
			index--
		} else {
			for a[index] != 1 {
				for j := index; j > 0; j-- {
					temp := a[j-1]
					a[j-1] = a[j]
					a[j] = temp
				}
				//printArr(a)
				step++
			}
			index--
		}
		if index == n-1-ones {
			break
		}
	}

	return step
}

func printArr(a []int) {
	for i := range a {
		fmt.Printf("%d ", a[i])
	}
	fmt.Println()
}

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		books := strings.Split(scanner.Text(), " ")
		lbook := -1
		rbook := 0
		nbook := 0
		for i, v := range books {
			if lbook == -1 && v == "1" {
				lbook = i
				rbook = i
			} else if lbook != -1 && v == "1" {
				rbook = i
				nbook++
			}
		}
		space := rbook - lbook - nbook
		//spaceL := lbook
		//spaceR := len(books) - rbook - 1
		ans := space //+ min(spaceL, spaceR)
		//fmt.Println(lbook, rbook, nbook)
		fmt.Println(ans)
	}
}

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

package main

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

func getIndex(length int64, arr []string) []int64 {

	var i int64
	var ones []int64
	for i = 0; i < length; i++ {
		if arr[i] == "1" {
			ones = append(ones, i)
		}
	}

	return ones
}

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

	testCases := scanner.Text()

	var tc int64
	tc, _ = strconv.ParseInt(testCases, 10, 64)

	for tc > 0 {

		scanner.Scan()
		size := scanner.Text()
		var length, oneLen int64
		var ones []int64

		length, _ = strconv.ParseInt(size, 10, 64)

		scanner.Scan()
		arr := scanner.Text()
		strArr := strings.Split(arr, " ")

		ones = getIndex(length, strArr)

		oneLen = int64(len(ones))

		fmt.Println(ones[oneLen-1] - ones[0] - 1 - (oneLen - 2))

		tc--

	}
}

package main

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

func maketest(books string) {
	ret := 0
	ba := strings.Split(books, " ")
	i:= 0
	f:= false
	for i<len(ba) {
	    if ba[i]=="1" {
	        f=true
	        break
	    }
	    i++
	}
	if f {
	    gap:=0
	    i++
	    for i<len(ba) {
    	    if ba[i-1]=="1" && ba[i]=="0" {
    	       gap++
    	    } else if ba[i-1]=="0" && ba[i]=="0" {
    	       gap++
    	    }else if ba[i-1]=="0" && ba[i]=="1" {
    	        ret+=gap
    	        gap=0
    	    }
    	    i++
    	}
	}
    fmt.Println(ret)
}

func main() {
	cin := bufio.NewReader(os.Stdin)
	nts, err := cin.ReadString('\r')
	if err != nil {
		fmt.Println("a", err)
		return
	}
	cin.ReadByte()
	numtests, err := strconv.ParseInt(nts[:len(nts)-1], 10, 64)
	if err != nil {
		fmt.Println("b", err)
		return
	}
	for i := 0; i < int(numtests); i++ {
		_, err := cin.ReadString('\r')
		if err != nil {
			fmt.Println("c", err)
			return
		}
		cin.ReadByte()
		books, err := cin.ReadString('\r')
		if err != nil {
			fmt.Println("c", err)
			return
		}
		cin.ReadByte()
		maketest(books[:len(books)-1])
	}
}

package main

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

var T, n int

var _r = bufio.NewReader(os.Stdin)
var _w = bufio.NewWriter(os.Stdout)

func main() {
	for _, _ = fmt.Fscan(_r, &T); T > 0; T-- {
		_, _ = fmt.Fscan(_r, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Fscan(_r, &a[i])
		}
		var b []int
		for i := 1; i <= n; i++ {
			if a[i] == 1 && a[i-1] == 1 {
				continue
			}
			b = append(b, a[i])
		}
		for len(b) > 0 && b[0] == 0 {
			b = b[1:] //pop_front
		}
		for len(b) > 0 && b[len(b)-1] == 0 {
			b = b[:len(b)-1] //pop_back
		}
		ans := 0
		for _, val := range b {
			if val == 0 {
				ans++
			}
		}

		//fmt.Println(b)
		_, _ = fmt.Fprintln(_w, ans)
		_ = _w.Flush()
	}

}

package main

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

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

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

func solveA() {
	var s string
	scanf("%s\n", &s)
	dig := int(s[0] - '0')
	len := len(s)
	ans := (dig - 1) * 10 + len * (len + 1) / 2
	printf("%d\n", ans)
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
	}
	fir := -1
	lst := -1
	for i := 0; i < n; i++ {
		if v[i] == 0 {
			continue
		}
		if fir == -1 {
			fir = i
		}
		lst = i
	}
	ans := 0
	for i := fir; i <= lst; i++ {
		ans += 1 - v[i]
	}
	printf("%d\n", ans)
}

func solveC() {
	n := 0
	scanf("%d\n", &n)
	v := make([]int, n)
	indMx := 0
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
		if v[i] > v[indMx] {
			indMx = i
		}
	}
	ans := -1
	for i := indMx; i < n; i++ {
		if v[i] != v[indMx] {
			continue
		}
		if i - 1 >= 0 && v[i - 1] != v[indMx] {
			ans = i + 1
			break
		}
		if i + 1 < n && v[i + 1] != v[indMx] {
			ans = i + 1
			break
		}
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveB()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		println(solve(n, a))
	}
}

func solve(n int, a []int) int {
	zeros := 0
	for _, ai := range a {
		if ai == 0 {
			zeros++
		}
	}

	if zeros == n-1 {
		return 0
	}

	lzeros := 0
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			break
		}
		lzeros++
	}

	rzeros := 0
	for i := n - 1; i >= 0; i-- {
		if a[i] == 1 {
			break
		}
		rzeros++
	}

	return zeros - lzeros - rzeros
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		l := 0
		for ; l < n && a[l] == 0; l++ {
		}
		r := n - 1
		for ; r >= 0 && a[r] == 0; r-- {
		}
		ans := 0
		for i := l; i < r; i++ {
			if a[i]	== 0 {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

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

func max(a, b int64) int64 {
	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()
}

// 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"
	"io"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		s := string(a)
		i, j := strings.IndexByte(s, 1), strings.LastIndexByte(s, 1)
		s = s[i:j]
		c := 0
		for _, b := range s {
			if b ==0{
				c++
			}
		}
		Fprintln(out, c)

		return
	}

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

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

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

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

		ok := false
		var ans, a int
		for i := 0; i < n; i++ {

			if arr[i] == true {
				ok = true
				ans += a
				a = 0
				continue
			}

			if arr[i] == false && ok == true {
				a++
			}
		}

		fmt.Println(ans)
	}
}

package main

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

var t int

func getMin(q1, q2 int) int {
	if q1 > q2 {
		return q2
	} else {
		return q1
	}
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

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

		ok := false
		var sumOne, a int
		for i := 0; i < n; i++ {

			if arr[i] == true {
				ok = true
				sumOne += a
				a = 0
				continue
			}

			if arr[i] == false && ok == true {
				a++
			}
		}

		ok = false
		sumTwo := 0
		a = 0
		for i := n - 1; i >= 0; i-- {
			if arr[i] == true {
				ok = true
				sumTwo += a
				a = 0
				continue
			}

			if arr[i] == false && ok == true {
				a++
			}
		}

		fmt.Println(getMin(sumOne, sumTwo))
	}
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
var rd = bufio.NewReader(os.Stdin)
func scanf(f string, a ...interface{}) {
	fmt.Fscanf(rd, f, a...)
}
func main() {
	q := 0
	scanf("%d\n", &q)
	for tc := 0; tc < q; tc++ {
		n := 0
		scanf("%d\n", &n)
		a := make([]int, n)
		for i := range a {
			if i == n - 1 {
				scanf("%d\n", &a[i])
			} else {
				scanf("%d ", &a[i])
			}
		}
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == 0 && i != 0 && j != n - 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main

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

func main() {
	inp, _ := ioutil.ReadAll(os.Stdin)
	lines := strings.Split(strings.TrimSpace(string(inp)), "\n")
	var b strings.Builder
	for i := 2; i < len(lines); i += 2 {
		var a []int
		for _, s := range strings.Fields(lines[i]) {
			x, _ := strconv.Atoi(s)
			a = append(a, x)
		}
		for len(a) > 0 && a[0] == 0 {
			a = a[1:]
		}
		for len(a) > 0 && a[len(a)-1] == 0 {
			a = a[:len(a)-1]
		}
		ans := 0
		for _, x := range a {
			if x == 0 {
				ans++
			}
		}
		fmt.Fprintln(&b, ans)
	}
	fmt.Print(b.String())
}

package main

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

var (
	t    int16
	n    int8
	ones int8
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)

		a := make([]int8, n)
		var b []int8

		ones = 0
		for i := range a {
			fmt.Fscan(reader, &a[i])
			b = append(b, a[i])
			if a[i] == 1 {
				ones++
			}
		}

		left := moveToLeft(a, n, ones)

		right := moveToRight(b, n, ones)

		if right >= left {
			fmt.Println(left)
		} else {
			fmt.Println(right)
		}
	}
}

func moveToLeft(a []int8, n int8, ones int8) int {

	var index int8 = 0
	step := 0

	for index < n {
		if a[index] == 1 {
			index++
		} else {
			for a[index] != 1 {
				for j := index + 1; j < n; j++ {
					temp := a[j-1]
					a[j-1] = a[j]
					a[j] = temp
				}
				//printArr(a)
				step++
			}
			index++
		}
		if index == ones {
			break
		}
	}

	return step
}

func moveToRight(a []int8, n int8, ones int8) int {

	var index int8 = n - 1
	step := 0

	for index >= 0 {
		if a[index] == 1 {
			index--
		} else {
			for a[index] != 1 {
				for j := index; j > 0; j-- {
					temp := a[j-1]
					a[j-1] = a[j]
					a[j] = temp
				}
				//printArr(a)
				step++
			}
			index--
		}
		if index == n-1-ones {
			break
		}
	}

	return step
}

func printArr(a []int8) {
	for i := range a {
		fmt.Printf("%d ", a[i])
	}
	fmt.Println()
}

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		books := strings.Split(scanner.Text(), " ")
		lbook := -1
		rbook := 0
		nbook := 0
		for i, v := range books {
			if lbook == -1 && v == "1" {
				lbook = i
			} else if lbook != -1 && v == "1" {
				rbook = i
				nbook++
			}
		}
		space := rbook - lbook - nbook
		spaceL := lbook
		spaceR := len(books) - rbook - 1
		ans := space + min(spaceL, spaceR)
		//fmt.Println(lbook, rbook, nbook)
		fmt.Println(ans)
	}
}

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

package main

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

func main() {
	var t, n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &t)
	for i := 0; i < t; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &n)
		scanner.Scan()
		books := strings.Split(scanner.Text(), " ")
		lbook := -1
		rbook := 0
		nbook := 0
		for i, v := range books {
			if lbook == -1 && v == "1" {
				lbook = i
				rbook = i
			} else if lbook != -1 && v == "1" {
				rbook = i
				nbook++
			}
		}
		space := rbook - lbook - nbook
		spaceL := lbook
		spaceR := len(books) - rbook - 1
		ans := space + min(spaceL, spaceR)
		//fmt.Println(lbook, rbook, nbook)
		fmt.Println(ans)
	}
}

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

package main
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
func scanInt() int {
	sc, res := bufio.NewScanner(os.Stdin), 0
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &res)
	return res
}
func scanArray() []string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}
func main() {
	q := scanInt()
	for tc := 0; tc < q; tc++ {
		n, a := scanInt(), scanArray()
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == "0" && i != 0 && j != n - 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import
	"fmt"
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for tc := 0; tc < q; tc++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := range a {
			if i == n - 1 {
				fmt.Scanf("%d\n", &a[i])
			} else {
				fmt.Scanf("%d ", &a[i])
			}
		}
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == 0 && i != 0 && j != n - 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
func scanInt() int {
	sc, res := bufio.NewScanner(os.Stdin), 0
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &res)
	return res
}
func scanArray() []string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}
func main() {
	q := scanInt()
	for i := 0; i < q; i++ {
		n, a := scanInt(), scanArray()
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == "0" && i != 0 && j != n - 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import (
	"fmt"
	"strings"
)
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		n, s := 0, ""
		fmt.Scanf("%n\n%s\n", &n, &s)
		a := strings.Split(s, " ")
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == "0" && i != 0 && j != n + 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import "fmt"
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := range a {
			fmt.Scanf("%d", &a[i])
		}
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == 0 && i > 0 && j != n + 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import (
	"fmt"
	"strings"
)
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		n, s := 0, ""
		fmt.Scanf("%n\n%s\n", &s)
		a := strings.Split(s, " ")
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == "0" && i != 0 && j != n + 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import (
	"fmt"
	"strings"
)
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		n, s := 0, ""
		fmt.Scanf("%s\n", &s)
		a := strings.Split(s, " ")
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == "0" && i != 0 && j != n + 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}

package main
import "fmt"
func main() {
	q := 0
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		for i := range a {
			fmt.Scanf("%d ", &a[i])
		}
		i, res := 0, 0
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] == a[i] {
				j++
			}
			if a[i] == 0 && i != 0 && j != n + 1 {
				res += j - i + 1
			}
			i = j + 1
		}
		fmt.Println(res)
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Your task is to say the number of such positive integers $$$x$$$ such that $$$x$$$ divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.For example, if the array $$$a$$$ will be $$$[2, 4, 6, 2, 10]$$$, then $$$1$$$ and $$$2$$$ divide each number from the array (so the answer for this test is $$$2$$$).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 4 \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$$$ ($$$1 \le a_i \le 10^{12}$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the number of such positive integers $$$x$$$ such that $$$x$$$ divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).

package main

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

/* solution */

func solve() {

	n := readInt()

	g := readInt64()
	for i := 1; i < n; i++ {
		g = gcd(g, readInt64())
	}

	ans := 0
	for i := int64(1); i <= int64(math.Sqrt(float64(g))+1e-3); i++ {
		if g%i == 0 {
			ans += 2
			if i*i == g {
				ans--
			}
		}
	}

	printInt(ans)

}

func gcd(a, b int64) int64 {
	if a > b {
		a, b = b, a
	}
	if a == 1 {
		return int64(1)
	}
	if a == 0 {
		return b
	}
	return gcd(a, b%a)
}

/* 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)
	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 readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	} else {
		return gcd(y, x%y)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i

}

func main() {
	sc.Split(bufio.ScanWords)

	var n int
	var g int64

	n = nextInt()

	for i := 0; i < n; i++ {
		var a int64
		a = nextInt64()
		g = gcd(g, a)
	}

	var i, ans int64

	for i = 1; i*i <= g; i++ {
		if g%i == 0 {
			ans += 2
		}
		if i*i == g {
			ans--
		}
	}
	fmt.Println(ans)
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(nextString())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	i, e := strconv.ParseInt(nextString(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	} else {
		return gcd(y, x%y)
	}
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	var n int
	var g int64

	n = nextInt()

	for i := 0; i < n; i++ {
		a := nextInt64()
		g = gcd(g, a)
	}
	var i, ans int64

	for i = 1; i*i <= g; i++ {
		if g%i == 0 {
			ans += 2
		}
		if i*i == g {
			ans--
		}
	}
	fmt.Println(ans)
}

package main

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

var reader = bufio.NewReader(os.Stdin)  //use fmt.Fscan
var writer = bufio.NewWriter(os.Stdout) //use fmt.Fprintln

func getGCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return getGCD(b, a%b)
}

func numDivisors(num int64) int {
	var res int
	var i int64
	for i = 2; i*i <= num; i++ {
		if num%i == 0 {
			if i == num/i {
				res += 1
			} else {
				res += 2
			}
		}
	}
	if num == 1 {
		res += 1
	} else {
		res += 2
	}
	return res
}

func solve() {
	var n int
	fmt.Fscan(reader, &n)
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &arr[i])
	}
	var gcd int64 = arr[0]
	for i := 1; i < n; i++ {
		gcd = getGCD(gcd, arr[i])
	}
	fmt.Fprintln(writer, numDivisors(gcd))
}

func main() {
	var t int = 1
	// fmt.Fscan(reader, &t)
	defer writer.Flush()
	for t > 0 {
		solve()
		t--
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var n int

	_, err := fmt.Fscanf(input, "%d\n", &n)
	if err != nil {
	}

	var a = make([]int64, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Fscanf(input, "%d", &a[i])
		if err != nil {
		}
	}
	_, err = fmt.Fscanf(input, "\n")
	if err != nil {
	}
	fmt.Println(countDivisors(gcdSlice(n, a)))
}

func gcdSlice(n int, values []int64) int64 {
	result := values[0]
	for i := 1; i < n; i++ {
		result = gcd(result, values[i])
	}
	return result
}

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

func countDivisors(n int64) int64 {
	var result int64
	for i := 1; i <= int(math.Sqrt(float64(n))); i++ {
		if n % int64(i) == 0 {
			if n / int64(i) == int64(i) {
				result++
			} else {
				result += 2
			}
		}
	}
	return result
}

package main

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

func gcd(x, y int64) int64 {
	if x == 0 {
		return y
	}
	return gcd(y%x, x)
}

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

	var N int64
	fmt.Fscanf(input, "%d\n", &N)
	A := make([]int64, N)
	for n := int64(0); n < N; n++ {
		fmt.Fscanf(input, "%d", &A[n])
	}

	x := A[0]
	for n := int64(1); n < N; n++ {
		x = gcd(A[n], x)
	}
	ds := make(map[int64]bool)
	for i := int64(1); i*i <= x; i++ {
		if x%i == 0 {
			ds[i] = true
			ds[x/i] = true
		}
	}
	fmt.Println(len(ds))
}

package main

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

func main()  {
	defer writer.Flush()
	var n,i int64
	var a,ans int64
	scanf("%d",&n)
	scanf("%d",&ans)
	for i=0;i<n;i++{
		scanf("%d",&a)
		if i==0{
			ans=a
		}else {
			ans = gcd(ans, a)
		}
	}
	cnt:=0
	for i=1;i*i<=ans;i++{
		if ans%i==0 &&i==ans/i{
			cnt++
		}else if ans%i==0{
				cnt+=2
		}
	}
	fmt.Println(cnt)
}

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

package main

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

func main() {
	defer Flush()

	n, a := readIntsll(0)
	_ = n
	d := a[0]
	for _, v := range a {
		d = gcdll(d, v)
	}

	f := make(map[int64]int64)
	for i := int64(2); i*i <= d; i++ {
		for d%i == 0 {
			f[i]++
			d /= i
		}
	}
	if d != 1 {
		f[d]++
	}

	ans := int64(1)
	for _, v := range f {
		ans *= v + 1
	}
	println(ans)

}

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

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

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

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

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// 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 (
	"fmt"
	"bufio"
	"os"
	"math"
)

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

func gcdSlice(a []int64) int64 {
	r := a[0]
	for i := 1; i < len(a); i++ {
		r = gcd(r, a[i])
	}
	return r
}

func divisors(n int64) []int64 {
	r := []int64{}
	for i := 1; i <= int(math.Sqrt(float64(n))); i++ {
		if n%int64(i) == 0 {
			r = append(r, int64(i))
			if n / int64(i) != int64(i) {
				r = append(r, n / int64(i))
			}
		}
	}
	return r
}

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]int64, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	p := gcdSlice(a)

	d := divisors(p)

	fmt.Println(len(d))
}

package main

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

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

func gcdSlice(a []int64) int64 {
	r := a[0]
	for i := 0; i < len(a); i++ {
		r = gcd(r, a[i])
	}
	return r
}

func divisors(n int64) []int64 {
	r := []int64{}
	for i := 1; i <= int(math.Sqrt(float64(n))); i++ {
		if n%int64(i) == 0 {
			r = append(r, int64(i))
			if n / int64(i) != int64(i) {
				r = append(r, n / int64(i))
			}
		}
	}
	return r
}

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]int64, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	p := gcdSlice(a)

	d := divisors(p)

	fmt.Println(len(d))
}

package main
import "fmt"
import "os"
import "bufio"

func __gcd(a, b int64) int64 {
	if b == 0 {
		return a
	} else {
		return __gcd(b, a%b)
	}
}

func resolve(a int64) int {
	ans := 0
	for i:=int64(1); i*i<=a; i++ {
		if a%i==0 {
			ans++
			if a/i!=i {
				ans++
			}
		}
	}
	return ans
}

func main(){
	var n int
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d\n", &n)
	var ans int64 = 0
	for i:=1; i<=n; i++ {
		var x int64
		fmt.Fscanf(input, "%d", &x)
		ans = __gcd(ans, x)
	}
	fmt.Println(resolve(ans))
}

package main

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

var (
	n int
)

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	// file, err := os.Open("input.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// reader := bufio.NewReader(file)

	fmt.Fscanf(reader, "%d\n", &n)

	nums := make([]int64, n)
	var g int64
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &nums[i])
		g = gcd(nums[i], g)
	}

	count := 0
	var i int64
	for i = 1; i*i <= g; i++ {
		if g%i == 0 {
			count++

			if i != g/i {
				count++
			}

		}
	}

	fmt.Println(count)
}

package main

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

var reader = bufio.NewReader(os.Stdin)  //use fmt.Fscan
var writer = bufio.NewWriter(os.Stdout) //use fmt.Fprintln

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

func numDivisors(num int64) int {
	var res int
	var i int64
	for i = 2; i*i <= num; i++ {
		if num%i == 0 {
			if i == num/i {
				res += 1
			} else {
				res += 2
			}
		}
	}
	if num == 1 {
		res += 1
	} else {
		res += 2
	}
	return res
}

func solve() {
	var n int
	fmt.Fscan(reader, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &arr[i])
	}
	var gcd int = arr[0]
	for i := 1; i < n; i++ {
		gcd = getGCD(gcd, arr[i])
	}
	fmt.Fprintln(writer, numDivisors(int64(gcd)))
}

func main() {
	var t int = 1
	// fmt.Fscan(reader, &t)
	defer writer.Flush()
	for t > 0 {
		solve()
		t--
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var n int

	_, err := fmt.Fscanf(input, "%d\n", &n)
	if err != nil {
	}

	var a = make([]int64, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Fscanf(input, "%d", &a[i])
		if err != nil {
		}
	}
	_, err = fmt.Fscanf(input, "\n")
	if err != nil {
	}
	println(countDivisors(gcdSlice(n, a)))
}

func gcdSlice(n int, values []int64) int64 {
	result := values[0]
	for i := 1; i < n; i++ {
		result = gcd(result, values[i])
	}
	return result
}

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

func countDivisors(n int64) int64 {
	var result int64
	for i := 1; i <= int(math.Sqrt(float64(n))); i++ {
		if n % int64(i) == 0 {
			if n / int64(i) == int64(i) {
				result++
			} else {
				result += 2
			}
		}
	}
	return result
}

package main

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

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

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

	var N int
	fmt.Fscanf(input, "%d\n", &N)
	A := make([]int, N)
	for n := 0; n < N; n++ {
		fmt.Fscanf(input, "%d", &A[n])
	}
	sort.Ints(A)
	divisors := make(map[int]bool)
	for i := 1; i*i <= A[0]; i++ {
		if A[0]%i == 0 {
			divisors[i] = true
			divisors[A[0]/i] = true
		}
	}
	var ans int
loop:
	for d := range divisors {
		for n := 1; n < N; n++ {
			if A[n]%d != 0 {
				continue loop
			}
		}
		ans++
	}
	fmt.Println(ans)
}

package main

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

func gcd(x, y int) int {
	if x == 0 {
		return y
	}
	return gcd(y%x, x)
}

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

	var N int
	fmt.Fscanf(input, "%d\n", &N)
	A := make([]int, N)
	for n := int(0); n < N; n++ {
		fmt.Fscanf(input, "%d", &A[n])
	}

	x := A[0]
	for n := 1; n < N; n++ {
		x = gcd(A[n], x)
	}
	ds := make(map[int]bool)
	for i := int(1); i*i <= x; i++ {
		if x%i == 0 {
			ds[i] = true
			ds[x/i] = true
		}
	}
	fmt.Println(len(ds))
}

package main

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

func main()  {
	defer writer.Flush()
	var n,i int64
	scanf("%d",&n)
	var a,ans int64
	for i=0;i<n;i++{
		scanf("%d",&a)
		if i==0{
			ans=a
		}else {
			ans = gcd(ans, a)
		}
	}
	cnt:=0
	for i=1;i*i<=ans;i++{
		if ans%i==0 &&i==ans/i{
			cnt++
		}else if ans%i==0{
				cnt+=2
		}
	}
	fmt.Println(cnt)
}

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

package main

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

func main()  {
	defer writer.Flush()
	var n,i int64
	scanf("%d",&n)
	var a,ans int64
	for i=0;i<n;i++{
		scanf("%d",&a)
		if i==0{
			ans=a
		}else {
			ans = gcd(ans, a)
		}
	}
	cnt:=0
	for i=1;i*i<=ans;i++{
		if ans%i==0 &&i==ans/i{
			cnt++
		}else{
				cnt+=2
		}
	}
	fmt.Println(cnt)
}

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

package main

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

func main()  {
	defer writer.Flush()
	var n,i int
	scanf("%d",&n)
	var a,ans int
	for i=0;i<n;i++{
		scanf("%d",&a)
		if i==0{
			ans=a
		}else {
			ans = gcd(ans, a)
		}
	}
	cnt:=0
	for i=1;i*i<=ans;i++{
		if ans%i==0 &&i==ans/i{
			cnt++
		}else{
				cnt+=2
		}
	}
	fmt.Println(cnt)
}

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

package main

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

func main()  {
	var n,i int
	scanf("%d",&n)
	var a,ans int
	for i=0;i<n;i++{
		scanf("%d",&a)
		if i==0{
			ans=a
		}else {
			ans = gcd(ans, a)
		}
	}
	cnt:=0
	for i=1;i*i<=ans;i++{
		if ans%i==0 &&i==ans/i{
			cnt++
		}else{
				cnt+=2
		}
	}
	fmt.Println(cnt)
}

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

package main

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

func main() {
	defer Flush()

	n, a := readIntsll(0)
	_ = n
	d := a[0]
	for _, v := range a {
		d = gcdll(d, v)
	}

	f := make(map[int64]int64)
	for i := int64(2); i*i <= d; i++ {
		if d%i == 0 {
			f[i]++
			d /= i
		}
	}
	if d != 1 {
		f[d]++
	}

	ans := int64(1)
	for _, v := range f {
		ans *= v + 1
	}
	println(ans)

}

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

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

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

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

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// 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 (
	"fmt"
	"bufio"
	"sort"
	"os"
)

func divisors(n uint64) []uint64 {
	r := []uint64{}

	var i uint64 = 1
	for ; i <= n; i++ {
		if n%i == 0 {
			r = append(r, i)
		}
	}

	return r
}

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]uint64, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

	s := a[0]

	p := divisors(s)

	fmt.Println(p)

	k := 0
	for i := 0; i < len(p); i++ {
		ok := true
		for j := 0; j < len(a); j++ {
			if a[j]%p[i] != 0 {
				ok = false
				break
			}
		}
		if ok {
			k++
		}
	}

	fmt.Println(k)
}

package main

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

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]int, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	sort.Ints(a)

	s := a[0]

	k := 0
	for i := 1; i < s + 1; i++ {
		ok := true
		for j := 0; j < len(a); j++ {
			if a[j]%i != 0 {
				ok = false
				break
			}
		}
		if ok {
			k++
		}
	}

	fmt.Println(k)
}

package main

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

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]int, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	sort.Ints(a)

	fmt.Println(a)

	s := a[0]

	k := 0
	for i := 1; i < s + 1; i++ {
		ok := true
		for j := 0; j < len(a); j++ {
			if a[j]%i != 0 {
				ok = false
				break
			}
		}
		if ok {
			k++
		}
	}

	fmt.Println(k)
}

package main

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

func divisors(n uint64) []uint64 {
	r := []uint64{}

	var i uint64 = 1
	for ; i <= uint64(math.Sqrt(float64(n))); i++ {
		if n%i == 0 {
			r = append(r, i)
			if n/i != i {
				r = append(r, n/i)
			}
		}
	}

	return r
}

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

	n := 0
	fmt.Fscanf(r, "%d\n", &n)
	a := make([]uint64, n)
	for j := 0; j < n; j++ {
		fmt.Fscanf(r, "%d", &a[j])
	}

	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

	s := a[0]

	p := divisors(s)

	fmt.Println(p)

	k := 0
	for i := 0; i < len(p); i++ {
		ok := true
		for j := 0; j < len(a); j++ {
			if a[j]%p[i] != 0 {
				ok = false
				break
			}
		}
		if ok {
			k++
		}
	}

	fmt.Println(k)
}

package main
import "fmt"
import "os"
import "bufio"

func __gcd(a, b int) int {
	if b == 0 {
		return a
	} else {
		return __gcd(b, a%b)
	}
}

func resolve(a int) int {
	ans := 0
	for i:=1; i*i<=a; i++ {
		if a%i==0 {
			ans++
			if a/i!=i {
				ans++
			}
		}
	}
	return ans
}

func main(){
	var n int
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d\n", &n)
	var ans int = 0
	for i:=1; i<=n; i++ {
		var x int
		fmt.Fscanf(input, "%d", &x)
		ans = __gcd(ans, x)
	}
	fmt.Println(resolve(ans))
}

package main

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

var (
	n int
)

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	// file, err := os.Open("input.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// reader := bufio.NewReader(file)

	fmt.Fscanf(reader, "%d\n", &n)

	nums := make([]int, n)
	var g int
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &nums[i])
		g = gcd(nums[i], g)
	}

	count := 0
	for i := 1; i*i <= g; i++ {
		if g%i == 0 {
			count++

			if i != g/i {
				count++
			}

		}
	}

	fmt.Println(count)
}


One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.

The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.  Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.

Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.

package main

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

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

type stNode struct {
	l, r int
	val  int
}
type segmentTree []stNode

func (t segmentTree) _pushUp(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].val = max(lo.val, ro.val)
}

func (t segmentTree) _build(arr []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].val = arr[l-1]
		return
	}
	mid := (l + r) >> 1
	t._build(arr, o<<1, l, mid)
	t._build(arr, o<<1|1, mid+1, r)
	t._pushUp(o)
}

func (t segmentTree) _query(o, l, r int) (res int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].val
	}
	mid := (t[o].l + t[o].r) >> 1
	res = -1e9
	if l <= mid {
		res = max(res, t._query(o<<1, l, r))
	}
	if mid < r {
		res = max(res, t._query(o<<1|1, l, r))
	}
	return
}

func (t segmentTree) init(arr []int) { t._build(arr, 1, 1, len(arr)) }
func (t segmentTree) query(l, r int) int {
	if l > r {
		return 0
	}
	return t._query(1, l, r)
}

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

	var n int
	Fscan(in, &n)
	sumW := 0
	w := make([]int, n)
	h := make([]int, n)
	for i := range w {
		Fscan(in, &w[i], &h[i])
		sumW += w[i]
	}

	t := make(segmentTree, 4*n)
	t.init(h)
	for i, wi := range w {
		maxH := max(t.query(1, i), t.query(i+2, n))
		Fprint(out, (sumW-wi)*maxH, " ")
	}
}

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

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

type Reader struct{
    scanner *bufio.Scanner
}

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

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

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

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

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

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

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

    return string(bt)
}

var read Reader
var sortByH bool

type Person struct{
    h, w, ind, ans int
}

type Persons []Person

func (a Persons) Len() int{
    return len(a)
}

func (a Persons) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a Persons) Less(i, j int) bool{
    if(sortByH){
        return a[i].h < a[j].h
    } else{
        return a[i].ind < a[j].ind
    }
}

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

    n := read.readInt()

    p := make([]Person, n)

    // read.setByte()
    // read.readByte(1)
    // read.setWord()

    totW := 0

    for i := 0; i < n; i++{
        p[i].w = read.readInt()
        p[i].h = read.readInt()
        p[i].ind = i
        totW += p[i].w
    }

    sortByH = true
    // fmt.Println(p)
    sort.Sort(Persons(p))

    for i := 0; i < n; i++{
        x,y := 0, 0
        x = totW - p[i].w
        if i == n-1{
            y = p[i-1].h
        } else {
            y = p[n-1].h
        }
        p[i].ans = x*y
    }

    sortByH = false
    sort.Sort(Persons(p))

    for i := 0; i < n; i++{
        if i > 0{
            fmt.Print(" ")
        }
        fmt.Print(p[i].ans)
    }

    // fmt.Println(p)

}

// main
package main

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

var scanner *bufio.Scanner

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

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

    n := getI()
    sumW := 0
    w := make([]int, n)
    h := make([]int, n)
    maxH := make([]int, 2)
    for i := 0; i < n; i++ {
        w[i], h[i] = getI(), getI()
        sumW += w[i]
        if h[i] >= maxH[0] {
            maxH[1] = maxH[0]
            maxH[0] = h[i]
        } else if h[i] > maxH[1] {
            maxH[1] = h[i]
        }
    }
    for i := 0; i < n; i++ {
        curW := sumW - w[i]
        var curH int
        if h[i] == maxH[0] {
            curH = maxH[1]
        } else {
            curH = maxH[0]
        }
        writer.WriteString(fmt.Sprintf("%d\n", curH*curW))
    }
}

// main
package main

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

var (
    stdin  = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
)

func main() {
    defer stdout.Flush()
    var n int
    fmt.Fscanf(stdin, "%d", &n)
    sumW := 0
    w := make([]int, n)
    h := make([]int, n)
    maxH := make([]int, 2)
    for i := 0; i < n; i++ {
        fmt.Fscanf(stdin, "%d%d", &w[i], &h[i])
        sumW += w[i]
        if h[i] >= maxH[0] {
            maxH[1] = maxH[0]
            maxH[0] = h[i]
        } else if h[i] > maxH[1] {
            maxH[1] = h[i]
        }
    }
    for i := 0; i < n; i++ {
        curW := sumW - w[i]
        var curH int
        if h[i] == maxH[0] {
            curH = maxH[1]
        } else {
            curH = maxH[0]
        }
        fmt.Fprintf(stdout, "%d ", curH*curW)
    }
}

// main
package main

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

var (
    stdin  = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
)

func main() {
    defer stdout.Flush()
    var n int
    fmt.Fscanf(stdin, "%d", &n)
    sumW := 0
    w := make([]int, n)
    h := make([]int, n)
    maxH := make([]int, 2)
    for i := 0; i < n; i++ {
        fmt.Fscanf(stdin, "%d%d", &w[i], &h[i])
        sumW += w[i]
        if h[i] >= maxH[0] {
            maxH[1] = maxH[0]
            maxH[0] = h[i]
        } else if h[i] > maxH[1] {
            maxH[1] = h[i]
        }
    }
    for i := 0; i < n; i++ {
        curW := sumW - w[i]
        var curH int
        if h[i] == maxH[0] {
            curH = maxH[1]
        } else {
            curH = maxH[0]
        }
        fmt.Fprintln(stdout, curH*curW)
    }
}