A number $$$a_2$$$ is said to be the arithmetic mean of two numbers $$$a_1$$$ and $$$a_3$$$, if the following condition holds: $$$a_1 + a_3 = 2\cdot a_2$$$. We define an arithmetic mean deviation of three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ as follows: $$$d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$$$.Arithmetic means a lot to Jeevan. He has three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ and he wants to minimize the arithmetic mean deviation $$$d(a_1, a_2, a_3)$$$. To do so, he can perform the following operation any number of times (possibly zero):  Choose $$$i, j$$$ from $$$\{1, 2, 3\}$$$ such that $$$i \ne j$$$ and increment $$$a_i$$$ by $$$1$$$ and decrement $$$a_j$$$ by $$$1$$$ Help Jeevan find out the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 5000)$$$  — the number of test cases. The first and only line of each test case contains three integers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ $$$(1 \le a_1, a_2, a_3 \le 10^{8})$$$.

For each test case, output the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

NoteNote that after applying a few operations, the values of $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ may become negative.In the first test case, $$$4$$$ is already the Arithmetic Mean of $$$3$$$ and $$$5$$$.$$$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$$$In the second test case, we can apply the following operation:$$$(2, 2, 6)$$$ $$$\xrightarrow[\text{increment $$$a_2$$$}]{\text{decrement $$$a_1$$$}}$$$ $$$(1, 3, 6)$$$$$$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$$$It can be proven that answer can not be improved any further.In the third test case, we can apply the following operations:$$$(1, 6, 5)$$$ $$$\xrightarrow[\text{increment $$$a_3$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(1, 5, 6)$$$ $$$\xrightarrow[\text{increment $$$a_1$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(2, 4, 6)$$$$$$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$$$

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a1, a2, a3 int
		fmt.Fscan(in, &a1, &a2, &a3)

		l := a1 + a3
		r := a2 * 2

		if (r-l)%3 == 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, 1)
		}
	}
}

package main
import "fmt"
func Fun(a,b int)int{
    if (a-b)%3==0{
        return 0
    }
    return 1
}
func solve(){
    var a1,a2,a3 int
    fmt.Scanln(&a1,&a2,&a3)
    fmt.Println(Fun(a1+a3,a2*2))
}
func main(){
    var t int
    fmt.Scanln(&t)
    for i:=1;i<=t;i++{
        solve()
    }
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var a, b, c int
    fmt.Fscan(input, &a, &b, &c)

       // k := abs(a + c - 2*b) / 3
       // fmt.Fprintln(output,  abs(a + c - k - 2*(b + k)) )
       // return
    if abs(a + c - 2*b) % 3 == 0 {
        fmt.Fprintln(output, 0)
    } else {
        fmt.Fprintln(output, 1)
    }
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func min(x,y int)int{
	if x<y{
		return x

	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var n int
	fmt.Fscan(in,&n)
	for i:=1;i<=n;i++{
		var x, y , z int
		fmt.Fscan(in,&x,&y,&z)
		a := []int{x,y,z}
		cool := abs(a[0]+a[2] - a[1]*2)
		fmt.Fprintln(out,min(cool%3,abs(cool%3-3)))
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c)
		if abs(a+c-b*2)%3 == 0 {
			fmt.Fprintln(out,0)
		} else {
			fmt.Fprintln(out,1)
		}
	}
}
func abs(x int) int {
	if x < 0 {
		return x*-1
	}
	return x
}

package main

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

var (
	reader     = bufio.NewReader(os.Stdin)
	t, a, b, c int
)

func solve(a, b, c int) int {
	if (a+c-2*b)%3 == 0 {
		return 0
	}
	return 1
}

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

package main

import "fmt"

func Fun(a int, b int, c int) int {
        result := a + c - b*2
        if result%3 == 0 {
                return 0
        } else {
                return 1
        }
}

func main() {
        var t int
        fmt.Scanln(&t)
        for i := 0; i < t; i++ {
                var a, b, c int
                fmt.Scanln(&a, &b, &c)
                fmt.Println(Fun(a, b, c))
        }
}

package main

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

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

func main() {
	defer out.Flush()
	var T, a1, a2, a3 int
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &a1, &a2, &a3)
		diff := a1 + a3 - 2*a2
		if diff%3 == 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, 1)
		}
	}
}

package main

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

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

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var a, b, c int
		fmt.Fscan(in, &a, &b, &c)
		if (6+a+c-2*(b%3))%3 == 0 {
			out.WriteString("0\n")
		} else {
			out.WriteString("1\n")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	t := 0

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b, c int

		fmt.Scan(&a, &b, &c)

		if (a+c-2*b)%3 == 0 {
			fmt.Printf("0\n")
		} else {
			fmt.Printf("1\n")
		}

	}
}

package main

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

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

	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		nums := mustReadNNumbs(r, 3)
		solve(nums[0], nums[1], nums[2])
	}
}

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

func solve(i1, i2, i3 int64) {
	switch (i1 + i3 - 2*i2) % 3 {
	case 0:
		fmt.Println("0")
	default:
		fmt.Println("1")
	}
}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a1, a2, a3 int
		fmt.Fscan(in, &a1, &a2, &a3)

		if a1%2 == 0 && a2%2 == 0 && a3%2 == 0 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 0)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a1, a2, a3 int
		fmt.Fscan(in, &a1, &a2, &a3)

		if a1%2 == 0 && a2%2 == 0 && a3%2 == 0 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a1, a2, a3 int
		fmt.Fscan(in, &a1, &a2, &a3)

		if a1 == a2 && a2 != a3 {
			fmt.Fprintln(out, 1)
		} else if a3 == a2 && a1 != a2 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 0)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a1, a2, a3 int
		fmt.Fscan(in, &a1, &a2, &a3)

		if a1 == a2 && a2 != a3 {
			fmt.Println(out, 1)
		} else if a3 == a2 && a1 != a2 {
			fmt.Println(out, 1)
		} else {
			fmt.Println(out, 0)
		}
	}

}

package main
import "fmt"
func Fun(a,b int)int{
    if a%3==1{
        return 1
    }
    return 0
}
func solve(){
    var a1,a2,a3 int
    fmt.Scanln(&a1,&a2,&a3)
    fmt.Println(Fun(a1+a3,a2*2))
}
func main(){
    var t int
    fmt.Scanln(&t)
    for i:=1;i<=t;i++{
        solve()
    }
}

package main
import "fmt"
func Fun(a,b int)int{
    if a%3==0{
        return 0
    }
    return 1
}
func solve(){
    var a1,a2,a3 int
    fmt.Scanln(&a1,&a2,&a3)
    fmt.Println(Fun(a1+a3,a2*2))
}
func main(){
    var t int
    fmt.Scanln(&t)
    for i:=1;i<=t;i++{
        solve()
    }
}

package main
import(
    "fmt"
)
func abs(a,b int)int{
    if a>b{
        return a-b
    }
    return b-a
}
func solve(){
    var a1,a2,a3 int
    fmt.Scanln(&a1,&a2,&a3)
    fmt.Println(abs(a1+a3,a2*2)%3)
}
func main(){
    var t int
    fmt.Scanln(&t)
    for i:=1;i<=t;i++{
        solve()
    }
}

package main
import(
    "fmt"
)
func abs(a,b int)int{
    if a>b{
        return a-b
    }
    return b-a
}
func solve(){
    var a1,a2,a3 int
    fmt.Scanf("%d%d%d",&a1,&a2,&a3)
    fmt.Println(abs(a1+a3,a2*2)%3)
}
func main(){
    var t int
    fmt.Scanf("%d",&t)
    for i:=1;i<=t;i++{
        solve()
    }
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var a, b, c int
    fmt.Fscan(input, &a, &b, &c)

    fmt.Fprintln(output, abs(a + c - 2*b) % 3 % 2)
    return
    if abs(a + c - 2*b) % 3 == 0 {
        fmt.Fprintln(output, 1)
    } else {
        fmt.Fprintln(output, 0)
    }
}

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

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var a, b, c int
    fmt.Fscan(input, &a, &b, &c)

    fmt.Fprintln(output, abs(a + c - 2*b) % 3)
    return
    if abs(a + c - 2*b) % 3 == 0 {
        fmt.Fprintln(output, 1)
    } else {
        fmt.Fprintln(output, 0)
    }
}

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

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var a, b, c int
    fmt.Fscan(input, &a, &b, &c)
    if a + c - 2*b == 0 {
        fmt.Fprintln(output, 0)
        return
    }

    fmt.Fprintln(output, abs(abs(a + c - 2*b) / 2 - 1) % 2 )
    return
    if abs(a + c - 2*b) % 2 == 0 {
        fmt.Fprintln(output, 1)
    } else {
        fmt.Fprintln(output, 0)
    }
}

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

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var a, b, c int
    fmt.Fscan(input, &a, &b, &c)
    if abs(a + b - 2*c) % 2 == 0 {
        fmt.Fprintln(output, 1)
    } else {
        fmt.Fprintln(output, 0)
    }
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func abs(x int)int{
	if x<0{
		return -x
	}
	return x

}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var n int
	fmt.Fscan(in,&n)
	for i:=1;i<=n;i++{
		var x, y , z int
		fmt.Fscan(in,&x,&y,&z)
		a := []int{x,y,z}
		cool := abs(a[0]+a[2] - a[1]*2)
		fmt.Fprintln(out,cool%3)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func abs(x int)int{
	if x<0{
		return -x
	}
	return x

}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var n int
	fmt.Fscan(in,&n)
	for i:=1;i<=n;i++{
		var x, y , z int
		fmt.Fscan(in,&x,&y,&z)
		a := []int{x,y,z}
		sort.Ints(a)
		cool := abs(a[0]+a[2] - a[1]*2)

		fmt.Fprintln(out,cool%3)
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c)
		if abs((a+c)/2 - b)%3 == 0 {
			fmt.Fprintln(out,0)
		} else {
			fmt.Fprintln(out,1)
		}
	}
}
func abs(x int) int {
	if x < 0 {
		return x*-1
	}
	return x
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c)
		fmt.Fprintln(out,abs(a+c-b*2)%3)
	}
}
func abs(x int) int {
	if x < 0 {
		return x*-1
	}
	return x
}

package main

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

var (
	reader     = bufio.NewReader(os.Stdin)
	t, a, b, c int
)

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &a, &b, &c)
		fmt.Println((a + b + c) % 3)
	}
}

package main

import "fmt"

func Fun(a int, b int, c int) int {
        result := a + c - b*2
        if result >= 3 || result <= -3 {
                result %= 3
        }
        return result
}

func main() {
        var t int
        fmt.Scanln(&t)
        for i := 0; i < t; i++ {
                var a, b, c int
                fmt.Scanln(&a, &b, &c)
                fmt.Println(Fun(a, b, c))
        }
}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdin)

func main() {
	defer out.Flush()
	var T, a1, a2, a3 int
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &a1, &a2, &a3)
		diff := a1 + a3 - 2*a2
		if diff%3 == 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, 1)
		}
	}
}

package main

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

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

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var a, b, c int
		fmt.Fscan(in, &a, &b, &c)
		fmt.Fprintln(out, (6+a+c-2*(b%3))%3%2)
	}
}


Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:  Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.  Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?

The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman.

Print a single integer — the largest possible score.

NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
	"math/rand"
	"sort"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	array := make([]int, n)
	sum := int64(0)
	ans := int64(0)
	for i := 0; i < n; i++ {
		array[i] = readInt()
		sum += int64(array[i])
	}
	sort.Ints(array)
	ans = sum
	for i := 0; i < n - 1; i++ {
		ans += sum
		sum -= int64(array[i])
	}
	printInt64(ans)
	printLine()
}
// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

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

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

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

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

func main() {
	var count int

	fmt.Scanf("%d\n", &count)
	reader := bufio.NewReader(os.Stdin)

	str, _ := reader.ReadString('\n')
	// convert CRLF to LF
	str = strings.TrimSpace(str)

	scoreSlice := strings.Split(str, " ")
	scores := make([]int64, count)

	for i, num := range scoreSlice {
		scoreInt, _ := strconv.Atoi(num)
		scores[i] = int64(scoreInt)
	}

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

	var total int64
	total = 0
	for i := 0; i < count; i++ {
		multiplier := i + 2
		if i == count-1 {
			multiplier = i + 1
		}
		total += scores[i] * int64(multiplier)
	}

	fmt.Println(total)
}

package main

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

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

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

	n := nextInt()
	a := make([]int, n)
	var score, sum int64= 0, 0

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		sum += int64(a[i])
	}

	// if n == 1 {
	// 	println(sum)
	// 	return
	// }

	score += sum
	sort.Ints(a)

	for i := 0; i < n - 1; i++ {
		score += sum
		sum -= int64(a[i])
		// println(score, sum, a)
	}

	println(score)
}

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

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

func main() {
	n := ReadInt()
	a := ReadInt64s(n)
	fmt.Println(solve(n, a))
}

func solve(n int, a []int64) int64 {
	sum := Sum(a...)
	h := Heap(a)
	heap.Init(&h)
	ans := sum
	if len(h) == 1 {
		return ans
	}
	for len(h) > 2 {
		v := h.pop()
		ans += sum
		sum -= v
	}
	ans += sum
	return ans
}

func Sum(slice ...int64) int64 {
	sum := int64(0)
	for _, v := range slice {
		sum += v
	}
	return sum
}

type HeapElement = int64
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

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

package main

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

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

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

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

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return 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...)
}

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

// 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 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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	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)
}

func main() {
	defer Flush()

	n := readi()
	a := make([]int64, n)
	for i := range a {
		a[i] = readll()
	}

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

	var sum int64
	for _, v := range a {
		sum += v
	}

	var ans int64
	for _, v := range a {
		ans += sum + v
		sum -= v
	}
	ans -= a[len(a)-1]
	println(ans)
}

package main

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

func main() {
	var count int

	fmt.Scanf("%d\n", &count)
	reader := bufio.NewReader(os.Stdin)

	str, _ := reader.ReadString('\n')
	// convert CRLF to LF
	str = strings.TrimSpace(str)

	scoreSlice := strings.Split(str, " ")
	scores := make([]int, count)

	for i, num := range scoreSlice {
		scores[i], _ = strconv.Atoi(num)
	}

	sort.Sort(sort.IntSlice(scores))

	var total int64
	total = 0
	for i := 0; i < count; i++ {
		multiplier := i + 2
		if i == count-1 {
			multiplier = i + 1
		}
		total += int64(scores[i] * multiplier)
	}

	fmt.Println(total)
}

package main

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

func main() {
	var count int

	fmt.Scanf("%d\n", &count)
	reader := bufio.NewReader(os.Stdin)

	str, _ := reader.ReadString('\n')
	// convert CRLF to LF
	str = strings.TrimSpace(str)

	scoreSlice := strings.Split(str, " ")
	scores := make([]int, count)

	for i, num := range scoreSlice {
		scores[i], _ = strconv.Atoi(num)
	}

	sort.Sort(sort.IntSlice(scores))

	total := 0
	for i := 0; i < count; i++ {
		multiplier := i + 2
		if i == count-1 {
			multiplier = i + 1
		}
		total += scores[i] * multiplier
	}

	fmt.Println(total)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

func main() {
	n := ReadInt()
	a := ReadInts(n)
	fmt.Println(solve(n, a))
}

func solve(n int, a []int) int {
	sum := Sum(a...)
	h := Heap(a)
	heap.Init(&h)
	ans := sum
	if len(h) == 1 {
		return ans
	}
	for len(h) > 2 {
		v := h.pop()
		ans += sum
		sum -= v
	}
	ans += sum
	return ans
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

type HeapElement = int
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

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

package main

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

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

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

	n := nextInt()
	a := make([]int, n)
	score, sum := 0, 0

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		sum += a[i]
	}

	// if n == 1 {
	// 	println(sum)
	// 	return
	// }

	score += sum
	sort.Ints(a)

	for i := 0; i < n - 1; i++ {
		score += sum
		sum -= a[i]
		// println(score, sum, a)
	}

	println(score)
}

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

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}


You are given a string $$$s$$$ of even length $$$n$$$. String $$$s$$$ is binary, in other words, consists only of 0's and 1's.String $$$s$$$ has exactly $$$\frac{n}{2}$$$ zeroes and $$$\frac{n}{2}$$$ ones ($$$n$$$ is even).In one operation you can reverse any substring of $$$s$$$. A substring of a string is a contiguous subsequence of that string.What is the minimum number of operations you need to make string $$$s$$$ alternating? A string is alternating if $$$s_i \neq s_{i + 1}$$$ for all $$$i$$$. There are two types of alternating strings in general: 01010101... or 10101010...

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$; $$$n$$$ is even) — the length of string $$$s$$$. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ ($$$s_i \in$$$ {0, 1}). String $$$s$$$ has exactly $$$\frac{n}{2}$$$ zeroes and $$$\frac{n}{2}$$$ ones. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$.

For each test case, print the minimum number of operations to make $$$s$$$ alternating.

NoteIn the first test case, string 10 is already alternating.In the second test case, we can, for example, reverse the last two elements of $$$s$$$ and get: 0110 $$$\rightarrow$$$ 0101.In the third test case, we can, for example, make the following two operations:   11101000 $$$\rightarrow$$$ 10101100;  10101100 $$$\rightarrow$$$ 10101010.

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 solve() {
	var n int
	scanf("%d\n", &n)
	var s string
	scanf("%s\n", &s)
	cnt0 := 0
	cnt1 := 0
	for i := 0; i + 1 < len(s); i++ {
		if s[i] == s[i + 1] {
			if s[i] == '0' {
				cnt0++
			} else {
				cnt1++
			}
		}
	}
	ans := cnt0
	if cnt1 > ans {
		ans = cnt1
	}
	printf("%d\n", ans)
}

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

package main

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

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 min_int(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func min_int64(a int64, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func max_int(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func max_int64(a int64, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		scanf("%d\n", &n)

		var s string
		scanf("%s\n", &s)

		s = strings.TrimRight(s, "\n")

		var n_one_blocks int = 0
		var n_zero_blocks int = 0

		for i := 1; i < len(s); i++ {

			if s[i-1] == s[i] {
				if string(s[i]) == "0" {
					n_zero_blocks++
				} else {
					n_one_blocks++
				}
			}

		}

		// printf("%d %d\n", n_one_blocks, n_zero_blocks)
		var res int = max_int(n_one_blocks, n_zero_blocks)
		printf("%d\n", res)

	}

}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
	"fmt"
)

func main() {
	// Write your solution here
	var t int
	fmt.Scanf("%d\n", &t)

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

		plain := 0
		for i:=1; i<len(s); i++ {
			if s[i] == s[i-1] {
				plain += 1
			}
		}
		ans := (plain+1)/2
		fmt.Println(ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() { CF1437B(os.Stdin, os.Stdout) }
func CF1437B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		c, c2 := 0, 0
		for _, s := range strings.FieldsFunc(s, func(r rune) bool { return r == '0' }) {
			c += len(s) - 1
		}
		for _, s := range strings.FieldsFunc(s, func(r rune) bool { return r == '1' }) {
			c2 += len(s) - 1
		}
		if c2 > c {
			c = c2
		}
		Fprintln(out, c)
	}
}

package main

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

var t int

func getMax(q1, q2 int) (ans int) {
	if q1 > q2 {
		ans = q1
	} else {
		ans = q2
	}

	return
}

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([]byte, n)
		fmt.Fscan(input, &arr)

		var ans1, ans2 int
		for i := 1; i < n; i++ {
			if arr[i] == arr[i-1] {
				if arr[i] == '0' {
					ans1++
				} else {
					ans2++
				}
			}
		}

		fmt.Println(getMax(ans1, ans2))
	}
}

package main

import (
	"fmt"
)
func max(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		n, s, a, b := 0, "", 0, 0
		fmt.Scan(&n, &s)
		for i := 1; i < n; i++ {
			if s[i - 1] == '0' && s[i] == '0' {
				a++
			} else if s[i - 1] == '1' && s[i] == '1' {
				b++
			}
		}
		fmt.Println(max(a, b))
	}
}

package main

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

func main() {
	io := bufio.NewReader(os.Stdin)
	var t, n int
	var str string
	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n)
		res := 0
		fmt.Fscan(io, &str)
		prev := 'a'
		for _, r := range str {
			if r == prev {
				res++
			}
			prev = r
		}
		fmt.Println((res + res%2) / 2)
	}
}

package main

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

func main() {
  var t int
  Scan(&t)

  for i := 0; i < t; i++ {
    var n int
    Scan(&n)
    var s string
    Scan(&s)
    s = " " + s

    var c0, c1 int

    for i := 1; i < n; i++ {
      if s[i] == '0' && s[i] == s[i - 1] {
        c0++
      } else if s[i] == '1' && s[i] == s[i - 1] {
        c1++
      }
    }

    Max := func(a, b int) int {
      if a > b {return a}
      return b
    }

    Println(Max(c0, c1))
  }
}

package main

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

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

func Print(args ...interface{}) {
	fmt.Fprint(Writer, args...)
}

func Scan(args ...interface{}) {
	fmt.Fscan(Reader, args...)
}

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

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

func countDoubles(a string, val byte) (cnt int) {
	for i := 1; i < len(a); i++ {
		if a[i] == val && a[i] == a[i-1] {
			cnt++
		}
	}
	return
}

func main() {
	defer Writer.Flush()

	var t int
	Scan(&t)
	for t != 0 {
		var n int
		Scan(&n)
		var s string
		Scan(&s)
		Print(max(countDoubles(s, '0'), countDoubles(s, '1')), "\n")
		t--
	}
}

package main

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

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

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

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

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

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

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

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuousA, continuous_maxA int
		var continuousB, continuous_maxB int
		var last byte

		last = tmp[0]
		for i := 1; i < len(tmp); i++ {
			if tmp[i] == last {
				if tmp[i] == '1' {
					continuousA++
				} else {
					continuousB++
				}
			} else {

				continuous_maxA += continuousA
				continuousA = 0
				continuous_maxB += continuousB
				continuousB = 0
				last = tmp[i]
			}
		}

		continuous_maxA += continuousA
		continuous_maxB += continuousB

		Fprintln(out, max(continuous_maxA, continuous_maxB))

	}

}

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

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

func main() {
	io := bufio.NewReader(os.Stdin)
	var t, n int
	var str string
	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n)
		res := 0
		fmt.Fscan(io, &str)
		for i, r := range str {
			if i > 0 && r == '1' && str[i-1] == '1' {
				res++
			}
		}
		fmt.Println(res)
	}
}

package main

import (
  "fmt"
)

func main() {
  var t int
  fmt.Scanf("%v", &t)

  for i := 0; i < t; i++ {
    var n int
    fmt.Scanf("%v", &n)
    var s string
    fmt.Scanf("%v", &s)
    s = " " + s
    //fmt.Println(s)

    var ans int

    for i := 1; i < n; i++ {
      if s[i] == s[i - 1] {
        for i < n && s[i] == s[i - 1] {
          i++
        }
        ans++
      }
    }
    fmt.Println(ans)
  }
}

package main

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

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

func Print(args ...interface{}) {
	fmt.Fprint(Writer, args...)
}

func Scan(args ...interface{}) {
	fmt.Fscan(Reader, args...)
}

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

func main() {
	defer Writer.Flush()

	var t int
	Scan(&t)
	for t != 0 {
		var n int
		Scan(&n)
		var s string
		Scan(&s)
		bits := make([]int, len(s))
		for i := range s {
			bits[i] = int(s[i] - 48)
		}
		res := n * 2
		for d := 0; d < 2; d++ {
			sres := 0
			i, j := 0, 0
			for {
				for i < n && !((i+d)%2 == 0 && bits[i] == 1) {
					i++
				}
				if i >= n {
					break
				}
				for j < n && !((j+d)%2 == 1 && bits[j] == 0) {
					j++
				}
				if j >= n {
					break
				}
				sres++
				if abs(i-j) > 2{
					sres++
				}
				i++
				j++
			}
			if sres < res {
				res = sres
			}
		}

		Print(res, "\n")
		t--
	}
}

package main

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

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	bitType := "0"
	operations := 0
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if operations == 0 {
			bitType = string(stringBinary[index][i])
		}
		if mainCondition && string(stringBinary[index][i]) == bitType {
			operations++
		}
	}
	return operations
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

package main

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

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
		fmt.Println("length", len(stringBinary[0]))
	}
}

func processTestCase(index int) int {
	operations := 0
	for {
		check := checkForOperation(index)
		if check == -1 {
			break
		}
		subString := getSubString(index, check)
		reversedString := reverseString(subString)
		replaceSubString(index, check, check+len(subString)-1, reversedString)
		operations++
	}
	return operations
}

func replaceSubString(index int, start int, stop int, replacement string) {
	stringBinary[index] = stringBinary[index][:start] + replacement + stringBinary[index][stop+1:]
}

func checkForOperation(index int) int {
	for i := 0; i < stringLength[index]-1; i++ {
		if stringBinary[index][i] == stringBinary[index][i+1] {
			return i + 1
		}
	}
	return -1
}

func getSubString(index int, startIndex int) string {
	var subString string
	for i := startIndex; i < stringLength[index]; i++ {
		subString += string(stringBinary[index][i])
		if getSubStringTriggerCondition(index, i, startIndex) {
			break
		}
	}
	return subString
}

func getSubStringTriggerCondition(index int, stringIndex int, startIndex int) bool {
	if stringIndex == stringLength[index]-1 {
		return true
	}
	firstCondition := stringBinary[index][stringIndex] != stringBinary[index][startIndex]
	secondCondition := stringBinary[index][stringIndex+1] != stringBinary[index][startIndex]

	if firstCondition && secondCondition {
		return true
	}
	return false

}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func reverseSlice(data interface{}) {
	value := reflect.ValueOf(data)
	if value.Kind() != reflect.Slice {
		panic(errors.New("data must be a slice type"))
	}
	valueLen := value.Len()
	for i := 0; i <= int((valueLen-1)/2); i++ {
		reverseIndex := valueLen - 1 - i
		tmp := value.Index(reverseIndex).Interface()
		value.Index(reverseIndex).Set(value.Index(i))
		value.Index(i).Set(reflect.ValueOf(tmp))
	}
}

func reverseString(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

package main

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

var (
	scanner      = bufio.NewScanner(os.Stdin)
	stringLength []int
	stringBinary []string
)

func main() {
	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := 0
	for {
		check := checkForOperation(index)
		if check == -1 {
			break
		}
		subString := getSubString(index, check)
		reversedString := reverseString(subString)
		stringBinary[index] = strings.Replace(stringBinary[index], subString, reversedString, 1)
		operations++
	}
	return operations
}

func checkForOperation(index int) int {
	for i := 0; i < stringLength[index]-1; i++ {
		if string(stringBinary[index][i]) == string(stringBinary[index][i+1]) {
			return i + 1
		}
	}
	return -1
}

func getSubString(index int, startIndex int) string {
	var subString string
	for i := startIndex; i < stringLength[index]; i++ {
		subString += string(stringBinary[index][i])
		if getSubStringTriggerCondition(index, i, startIndex) {
			break
		}
	}
	return subString
}

func getSubStringTriggerCondition(index int, stringIndex int, startIndex int) bool {
	if stringIndex == stringLength[index]-1 {
		return true
	}
	firstCondition := string(stringBinary[index][stringIndex]) != string(stringBinary[index][startIndex])
	secondCondition := string(stringBinary[index][stringIndex+1]) != string(stringBinary[index][startIndex])

	if firstCondition && secondCondition {
		return true
	}
	return false

}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func reverseSlice(data interface{}) {
	value := reflect.ValueOf(data)
	if value.Kind() != reflect.Slice {
		panic(errors.New("data must be a slice type"))
	}
	valueLen := value.Len()
	for i := 0; i <= int((valueLen-1)/2); i++ {
		reverseIndex := valueLen - 1 - i
		tmp := value.Index(reverseIndex).Interface()
		value.Index(reverseIndex).Set(value.Index(i))
		value.Index(i).Set(reflect.ValueOf(tmp))
	}
}

func reverseString(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

package main

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

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte = '1'

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				if continuous > 1 {
					continuous_max += continuous - 1
				}
				continuous = 0
			}
		}
		if continuous > 1 {
			continuous_max += continuous - 1
		}

		Fprintln(out, continuous_max)

	}

}

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

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				add := reverse(tmp[begin:end])
				sum++
				if add  == len(tmp[begin:end]) {
					break
				}

				begin += add
				cur = begin

			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				continuous_max = max(continuous_max, continuous)
				continuous = 0
				last = data
			}
		}
		continuous_max = max(continuous_max, continuous)
		Fprintln(out, continuous_max)

	}

}

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

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				flag = true
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				continuous_max = max(continuous_max, continuous)
				continuous = 0
				last = data
			}
		}

		Fprintln(out, continuous_max)

	}

}

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

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				//Println("what",string(tmp[begin:end]),begin,end,cur,string(tmp))
				add := reverse(tmp[begin:end])

				//Println("waht end",add+begin,string(tmp))
				begin += add
				cur = begin
				sum++
			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				flag = true
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				add := reverse(tmp[begin:end])
				sum++
				if add  == len(tmp) {
					break
				}

				begin += add
				cur = begin

			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte = '1'

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				if continuous > 1 {
					continuous_max += continuous - 1
					continuous = 0
				}
			}
		}
		if continuous > 1 {
			continuous_max += continuous - 1
		}

		Fprintln(out, continuous_max)

	}

}

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

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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

package main

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

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

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

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

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


Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:  The coordinates of each point in the set are integers.  For any two points from the set, the distance between them is a non-integer. Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points.

The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).

In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set. If there are several optimal solutions, you may print any of them.

NoteConsider the first sample. The distance between points (0, 1) and (1, 2) equals , between (0, 1) and (2, 0) — , between (1, 2) and (2, 0) — . Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.

package main
import (
	"fmt"
)
func main() {
	var n,m int
	fmt.Scan(&n,&m)
	if m<n {
		n=m
	}
	fmt.Println(n+1)
	for i:=0;i<=n;i++ {
		fmt.Println(i,n-i)
	}
}

package main

import "fmt"

func main() {
    var n,m,min int
    fmt.Scan(&n,&m)
    if n < m { min = n } else { min = m }
    fmt.Println(min+1)
    for i := 0; i <= min; i++ {
        fmt.Println(i,min-i)
    }
}

package main

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

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

var n, m int

func main() {

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

	read(&n, &m)

	if n > m {
		n = m
	}

	writeln(n + 1)
	for i := 0; i <= n; i++ {
		writeln(n-i, i)
	}
}

func writeln(num ...int) {
	for _, value := range num {
		str := strconv.Itoa(value)
		out.WriteString(str + " ")
	}
	out.WriteString("\n")
}

func read(num ...*int) {
	for _, value := range num {
		in.Scan()
		*value, _ = strconv.Atoi(in.Text())
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m float64
	_, _ = fmt.Scan(&n, &m)
	sz := int(math.Min(n,m))
	fmt.Println(sz + 1)
	for i := 0; i <= int(math.Min(n, m)); i++ {
		fmt.Println(i, sz-i)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m float64
	_, _ = fmt.Scan(&n, &m)
	fmt.Println(math.Min(n,m)+1)
	for i := 0; i <= int(math.Min(n, m)); i++ {
		fmt.Println(i, i)
	}
}