package main

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}

	N := io.NextInt()
	A := io.NextIntArray(N)

	sum := 0
	max := 0
	for _, v := range A {
		sum += v
		max = Max(max, v)
	}
	io.Printf("%d\n", (max * N) - sum)

	io.FlushOutput()
}

func Max(lhs, rhs int) int {
	if lhs > rhs {
		return lhs
	} else {
		return rhs
	}
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

package main

import ("fmt"
        "sort")

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

	}
	sort.Ints(arr)
	//fmt.Println(arr)
//	fmt.Println(arr[n-1],input)
	sum1=arr[n-1]*n
	res:=sum1-input
	fmt.Print(res)
}

package main

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

// Buffered IO for fast I/O.
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// Helper functions to wrap around the buffered IO.
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

// For this function, don't forget to add '\n' every scanf() call.
func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}

// Solve
func max(array ...int) int {
	max := 0
	for _, value := range array {
		if value > max {
			max = value
		}
	}

	return max
}

func solve() {
	// Solution
	var testCases, ans int

	scanf("%d\n", &testCases)
	var welfares = make([]int, testCases)

	for index := range welfares {
		scanf("%d", &welfares[index])
	}

	maxValue := max(welfares...)

	for _, value := range welfares {
		if value != maxValue {
			ans += maxValue - value
		}
	}

	printf("%d", ans)
}

func main() {
	defer writer.Flush()
	solve()
}

package main

import "fmt"

func main() {
	var buf []int
	var n, maxn, sum, k int
	fmt.Scan(&k)
	for i:=0; i<k; i++ {
		fmt.Scan(&n)
		buf = append(buf, n)
	}
	for i:=0; i<k; i++ {
		if buf[i]>maxn {
			maxn = buf[i]
		}
	}
	for i:= 0; i<k; i++ {
		if buf[i] != maxn {
			sum += maxn-buf[i]
		}
	}
	fmt.Println(sum)
}

package main

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

func main() {
	var n, t int
	fmt.Scanf("%d \n", &n)
	count := 0
	max := 0
	reader := bufio.NewReader(os.Stdin)
	ss, _ := reader.ReadString('\n')
	list := strings.Split(strings.TrimRight(ss, "\r\n"), " ")
	for i := 0; i < n; i++ {
		temp, _ := strconv.ParseInt(list[i], 10, 64)
		t = int(temp)
		if t > max {
			count += i * (t - max)
			max = t
		} else {
			count += (max - t)
		}
	}
	fmt.Print(count)
}

package main

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

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

	max_number := 0
	array := make([]int, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
		if a > max_number {
			max_number = a
		}
	}

	need := 0
	for i := 0; i < n; i++ {
		need += max_number - array[i]
	}

	fmt.Println(need)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var a int
	var m int = 0
	var ss int = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if m < a {
			m = a
		}
		ss += a
	}
	fmt.Println(m*n - ss)
}

package main

import "fmt"

func kazna(n int, max int, arr []int) int {
	count := 0
	for i := 0; i < n; i++ {
		count += max - arr[i]
	}
	return count
}
func main() {
	var n, a int
	var max int = 0
	fmt.Scan(&n)
	arr := make([]int, 0, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		arr = append(arr, a)
		if a > max {
			max = a
		}
	}
	fmt.Print(kazna(n, max, arr))
}

package main

import (
	"fmt"
)

func main() {
	var numbers_citizens int
	fmt.Scanf("%d\n", &numbers_citizens)
	array := make([]int, numbers_citizens)
	max := array[0]
	for i := 0; i < numbers_citizens; i++ {
		fmt.Scanf("%d", &array[i])
		if array[i] > max {
			max = array[i]
		}
	}
	S := 0
	for i := 0; i < len(array); i++ {
		S += max - array[i]
	}

	fmt.Println(S)
}

package main

import "fmt"

func main() {
	mx := 0
	var n int
	fmt.Scanln(&n)
	var x int
	sm := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		if x > mx {
			sm += (x - mx) * i
			mx = x
		} else {
			sm += mx - x
		}
	}
	fmt.Println(sm)
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	sort.Ints(a)
	res := 0
	for i := 0; i < n-1; i++ {
		res += a[n-1] - a[i]

	}
	fmt.Println(res)
}

func getStats(str string) map[byte]int {
	stat := map[byte]int{}
	for _, v := range str {
		stat[byte(v)]++
	}
	return stat
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

import 	(
	"fmt"
)

func main() {
	var n int
	var m [101]int

	fmt.Scan(&n)

	max := m[0]
	sum := 0

	for i:=0; i<n; i++{
		fmt.Scan(&m[i])
		if m[i] > max{
			max = m[i]
		}
	}
	for i:=0; i<n; i++{
		sum += max - m[i]
	}
	fmt.Println(sum)

}

package main

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

func main() {
	var n, inp, sum int
	var s []int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &inp)
		s = append(s, inp)
	}
	sort.Ints(s)
	max := s[len(s)-1]
	for i := 0; i < len(s); i++ {
		sum += max - s[i]
	}
	fmt.Println(sum)
}

package main
import (
	"fmt"
)

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

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

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

	max := a[0]
	la := len(a)
	total := 0

	for i := 1; i < la; i++ {
		if a[i] > max {
			total = total + (a[i] - max) * i
			max = a[i]
		} else {
			total = total + max - a[i]
		}
	}

	fmt.Println(total)
}

package main

import "fmt"

func counter(n int, maximum int, buf []int) int {
	result := 0
	for i := 0; i < n; i++ {
		result += maximum - buf[i]
	}
	return result
}

func main() {
	var n, a int
	var maximum int = 0
	fmt.Scan(&n)
	buf := make([]int, 0, n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a)
		buf = append(buf, a)
		if a > maximum {
			maximum = a
		}
	}
	fmt.Print(counter(n, maximum, buf))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var total, max int
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		total += tmp
		if max < tmp {
			max = tmp
		}
	}
	fmt.Print(max*n - total)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	s := []int{}
	fmt.Scan(&b)
	for i := 0; i < b; i++ {
		fmt.Scan(&a)
		s = append(s, a)
	}
	sort.Ints(s)
	m := s[b-1]
	summa := 0
	for j := 0; j<(b-1); j++ {
		summa += (m-s[j])
	}
	fmt.Println(summa)
}

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mx := 0
	for _, v := range A {
		mx = max(mx, v)
	}
	ans := 0
	for _, v := range A {
		if mx > v {
			ans += mx - v
		}
	}
	fmt.Println(ans)

}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	mas:= []int{}
	fmt.Scan(&b)
	for i := 0; i < b; i++ {
		fmt.Scan(&a)
		mas = append(mas, a)
	}

	sort.Ints(mas)
	x := mas[b-1]
	summ := 0

	for j := 0; j<(b-1); j++ {
		summ += (x-mas[j])
	}

	fmt.Println(summ)
}

package main

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

// https://codeforces.com/problemset/problem/758/A
// A. Holiday Of Equality
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.

// Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).

// You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
// Input

// The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

// The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
// Output

// In the only line print the integer S — the minimum number of burles which are had to spend.

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

	var n int
	_, _ = fmt.Fscan(bufStdin, &n)

	as := make([]int, n)

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

	m := max(as)

	var cost int
	for _, v := range as {
		cost += m - v
	}
	_, _ = fmt.Print(cost)
}

func max(s []int) int {
	m := s[0]
	for i := 1; i < len(s); i++ {
		if s[i] > m {
			m = s[i]
		}
	}
	return m
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/758/A
// комментарии к решению
// Сначала находим максимум, а после суммируем разницу
// каждого элемента массива и максимального
func taskSolution(a []int) (ans int) {
	max := 0
	for _, ai := range a {
		if max < ai {
			max = ai
		}
	}
	for _, ai := range a {
		ans += max - ai
	}
	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a))
}

package main

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

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}

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

	var n int = ReadInt32()
	var result, max int = 0, 0
	a := make([]int, n)

	for i, _ := range a {
		a[i] = ReadInt32()
		if a[i] > max {
			result += i * (a[i] - max)
			max = a[i]
		} else {
			result += max - a[i]
		}
	}

	PrintInts(result)
}

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	max := a[0]
	for i := 1; i < n; i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	count := 0
	for i := 0; i < n; i++ {
		count += max - a[i]
	}
	fmt.Println(count)
}

// A. Holiday Of Equality
/*
In Berland it is the holiday of equality. In honor of the holiday the king
decided to equalize the welfare of all citizens in Berland by the expense of
the state treasury.

Totally in Berland there are n citizens, the welfare of each of them is
estimated as the integer in ai burles (burle is the currency in Berland).

You are the royal treasurer, which needs to count the minimum charges of the
kingdom on the king's present. The king can only give money, he hasn't a
power to take away them.

Input
The first line contains the integer n (1 ≤ n ≤ 100) — the number of
citizens in the kingdom.

The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) —
the welfare of the i-th citizen.

Output
In the only line print the integer S — the minimum number of burles which
are had to spend.

Examples
Input
5
0 1 2 3 4

Output
10

Input
5
1 1 0 1 1

Output
1

Input
3
1 3 1

Output
4

Input
1
12

Output
0

Note
In the first example if we add to the first citizen 4 burles, to the second 3,
to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

In the second example it is enough to give one burle to the third citizen.

In the third example it is necessary to give two burles to the first and the
third citizens to make the welfare of citizens equal 3.

In the fourth example it is possible to give nothing to everyone because all
citizens have 12 burles.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	input2, _ := reader.ReadString('\n')
	aArr := strings.Split(strings.TrimSpace(input2), " ")

	iArr := make([]int, n)
	for i := 0; i < n; i++ {
		iArr[i], _ = strconv.Atoi(aArr[i])
	}

	sort.SliceStable(iArr, func(i, j int) bool {
		return iArr[i] > iArr[j]
	})

	total := 0
	for i := 1; i < n; i++ {
		total += (iArr[0] - iArr[i])
	}
	fmt.Print(total)
}

// A. Holiday Of Equality
/*
In Berland it is the holiday of equality. In honor of the holiday the king
decided to equalize the welfare of all citizens in Berland by the expense of
the state treasury.

Totally in Berland there are n citizens, the welfare of each of them is
estimated as the integer in ai burles (burle is the currency in Berland).

You are the royal treasurer, which needs to count the minimum charges of the
kingdom on the king's present. The king can only give money, he hasn't a
power to take away them.

Input
The first line contains the integer n (1 ≤ n ≤ 100) — the number of
citizens in the kingdom.

The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) —
the welfare of the i-th citizen.

Output
In the only line print the integer S — the minimum number of burles which
are had to spend.

Examples
Input
5
0 1 2 3 4

Output
10

Input
5
1 1 0 1 1

Output
1

Input
3
1 3 1

Output
4

Input
1
12

Output
0

Note
In the first example if we add to the first citizen 4 burles, to the second 3,
to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

In the second example it is enough to give one burle to the third citizen.

In the third example it is necessary to give two burles to the first and the
third citizens to make the welfare of citizens equal 3.

In the fourth example it is possible to give nothing to everyone because all
citizens have 12 burles.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	input2, _ := reader.ReadString('\n')
	aArr := strings.Split(strings.TrimSpace(input2), " ")

	max := 0
	iArr := make([]int, n)
	for i := 0; i < n; i++ {
		iArr[i], _ = strconv.Atoi(aArr[i])

		if iArr[i] > max {
			max = iArr[i]
		}
	}

	//	sort.SliceStable(iArr, func(i, j int) bool {
	//		return iArr[i] > iArr[j]
	//	})

	total := 0
	for i := 0; i < n; i++ {
		total += (max - iArr[i])
	}
	fmt.Print(total)
}

package main

import (
	"fmt"
	"sort"
)

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

	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)
	max := a[n-1]

	ans := 0
	for _, v := range a {
		ans += max - v
	}

	fmt.Println(ans)
}

package main

import ("fmt"
        "sort")

func main()  {
	var n,sum1 int
	var input int
	arr:=make([]int,100)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
	  fmt.Scan(&arr[i])
	  input=input+arr[i]

	}
	sort.Ints(arr)
	sum1=arr[n-1]*n
	res:=input-sum1
	fmt.Print(res)
}

package main

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

// Buffered IO for fast I/O.
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// Helper functions to wrap around the buffered IO.
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

// For this function, don't forget to add '\n' every scanf() call.
func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}

// Solve
func max(array ...int) int {
	max := 0
	for _, value := range array {
		if value > max {
			max = value
		}
	}

	return max
}

func solve() {
	// Solution
	var testCases, ans int

	scanf("%d\n", &testCases)
	var welfares = make([]int, testCases)

	for i := 0; i < testCases; i++ {
		var tmp int
		scanf("%d\n", &tmp)
		welfares[i] = tmp
	}

	maxValue := max(welfares...)

	for _, value := range welfares {
		if value != maxValue {
			ans += maxValue - value
		}
	}

	printf("%d", ans)
}

func main() {
	defer writer.Flush()
	solve()
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var a [110]int
	var m int = 0
	var ss int = 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if m < a[i] {
			m = a[i]
		}
		ss += a[i]
	}
	fmt.Println(m*n - ss)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var a int
	var m int = 0
	var ss int = 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		if m < a {
			m = a
		}
		ss += a
	}
	fmt.Println(n)
	fmt.Println(m)
	fmt.Println(ss)
	fmt.Println(m*n - ss)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	var m int = 0
	var ss int = 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if m < a[i] {
			m = a[i]
		}
		ss += a[i]
	}
	fmt.Println(m*n - ss)
}

package main

import (
	"fmt"
)

func main() {
	var numbers_citizens int
	fmt.Scanf("%d", &numbers_citizens)
	array := make([]int, numbers_citizens)
	max := array[0]
	for i := 0; i < numbers_citizens; i++ {
		fmt.Scanf("%d", &array[i])
		if array[i] > max {
			max = array[i]
		}
	}
	S := 0
	for i := 0; i < len(array); i++ {
		S += max - array[i]
	}
	fmt.Println(S)
}

package main

import (
	"fmt"
)

func main() {
	var numbers_citizens int
	fmt.Scanf("%d", &numbers_citizens)
	array := make([]int, numbers_citizens)
	max := array[0]
	for i := 0; i < numbers_citizens; i++ {
		fmt.Scanf("%d", &array[i])
		if array[i] > max {
			max = array[i]
		}
	}
	S := 0
	for i := 0; i < len(array); i++ {
		S += max - array[i]
	}
}


package main

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

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

	t := readInt(reader)

	for _i := uint64(0); _i < t; _i++ {
		n := readInt(reader)
		arr := make([]uint64, n)
		line := strings.Split(readLine(reader), " ")
		for i := range arr {
			arr[i] = parseInt(line[i])
		}

		v := uint64(0)
		s := uint64(0)
		for _, x := range arr {
			v = v ^ x
			s += x
		}

		s += v

		fmt.Println(2)
		fmt.Println(v, s)
	}
}

func readInt(reader *bufio.Reader) uint64 {
	return parseInt(readLine(reader))
}

func parseInt(s string) uint64 {
	v, err := strconv.ParseInt(s, 10, 64)
	checkError(err)
	return uint64(v)
}

func readLine(reader *bufio.Reader) string {
	str, err := reader.ReadString('\n')
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(str)
}

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

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

package main

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

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

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

func main() {
	defer writer.Flush()

	var t, n int
	for scanf("%d\n", &t); t > 0; t-- {
		scanf("%d\n", &n)
		tmp, xor, sum := int64(0), int64(0), int64(0)
		for i := 0; i < n; i++ {
			scanf("%d", &tmp)
			xor ^= tmp
			sum += tmp
		}
		scanf("\n")
		printf("2\n%d %d\n", xor, sum+xor)
	}
}

package main

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

type heap struct {
  array []int
}

func (h *heap) push(val int) {
  h.array = append(h.array, val)
  cur := len(h.array) - 1
  for cur > 0 {
    var parent int
    if (cur & 1) == 1 {
      parent = (cur - 1) / 2
    } else {
      parent = (cur - 2) / 2
    }
    if h.array[cur] < h.array[parent] {
      h.array[cur], h.array[parent] = h.array[parent], h.array[cur]
      cur = parent
    } else {
      break
    }
  }
}

func (h *heap) pop() int {
  res := h.array[0]
  h.array[0], h.array[len(h.array)-1] = h.array[len(h.array)-1], h.array[0]
  h.array = h.array[:len(h.array)-1]
  cur := 0
  for cur < len(h.array) {
    smallest := cur
    if cur*2+1 < len(h.array) && h.array[smallest] > h.array[cur*2+1] {
      smallest = cur*2 + 1
    }
    if cur*2+2 < len(h.array) && h.array[smallest] > h.array[cur*2+2] {
      smallest = cur*2 + 2
    }
    if smallest != cur {
      h.array[smallest], h.array[cur] = h.array[cur], h.array[smallest]
      cur = smallest
    } else {
      break
    }
  }
  return res
}

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var T int
  Fscan(in, &T)
  for T > 0 {
    T--
    var n int
    var temp int64
    Fscan(in, &n)
    var add, xor int64 = 0, 0
    for i := 0; i < n; i++ {
      Fscan(in, &temp)
      add += temp
      xor ^= temp
    }
    var var0, var1, var2 int64 = 0, 0, 0
    if (add & 1) == 1 {
      var0 = 1
      add += 1
      xor ^= 1
    }
    for i := int64(2); add > 2*xor || 2*xor-add < 2; i <<= 1 {
      if (xor & i) == 0 {
        xor |= i
        var0 |= i
        add += i
      }
    }
    var1, var2 = (2*xor-add)/2, (2*xor-add)/2
    Fprintln(out, 3)
    Fprintln(out, var0, var1, var2)
  }
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		sum := int64(0)
		xor := int64(0)
		for i := 0; i < n; i++ {
			tmp := int64(0)
			fmt.Fscanf(in, "%d", &tmp)
			sum += tmp
			xor ^= tmp
		}
		fmt.Fscanf(in, "\n")
		ans := int64(0)
		t1 := sum
		t2 := xor
		if sum%2 == 1 {
			ans = 1
			t1 = sum + 1
			t2 = xor ^ 1
		}
		// a := make([]int, 0)
		// b := make([]int, 0)
		// for sum > 0 {
		// 	a = append(a, sum%2)
		// 	sum /= 2
		// }
		// for xor > 0 {
		// 	b = append(b, xor%2)
		// 	xor /= 2
		// }
		tmp := int64(2)
		for t1 != t2*2 {
			q1 := t1 / 2
			q1 = q1 % 2
			q2 := t2 % 2
			if q1 != q2 {
				ans += tmp
				t1 += 2
				t2 ^= 2
			}
			t1 /= 2
			t2 /= 2
			tmp *= 2
		}
		//fmt.Println("debugans", sum, xor, sum+ans, xor^ans)
		fmt.Fprintf(out, "%d\n", 1)
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		sum := int64(0)
		xor := int64(0)
		for i := 0; i < n; i++ {
			tmp := int64(0)
			fmt.Fscanf(in, "%d", &tmp)
			sum += tmp
			xor ^= tmp
		}
		fmt.Fscanf(in, "\n")
		ans := 0
		t1 := sum
		t2 := xor
		if sum%2 == 1 {
			ans = 1
			t1 = sum + 1
			t2 = xor ^ 1
		}
		// a := make([]int, 0)
		// b := make([]int, 0)
		// for sum > 0 {
		// 	a = append(a, sum%2)
		// 	sum /= 2
		// }
		// for xor > 0 {
		// 	b = append(b, xor%2)
		// 	xor /= 2
		// }
		tmp := 2
		for t1 != t2*2 {
			q1 := t1 / 2
			q1 = q1 % 2
			q2 := t2 % 2
			if q1 != q2 {
				ans += tmp
				t1 += 2
				t2 ^= 2
			}
			t1 /= 2
			t2 /= 2
			tmp *= 2
		}
		//fmt.Println("debugans", sum, xor, sum+ans, xor^ans)
		fmt.Fprintf(out, "%d\n", 1)
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t, n int
	for scanf("%d\n", &t); t > 0; t-- {
		scanf("%d\n", &n)
		tmp, xor, sum := 0, 0, 0
		for i := 0; i < n; i++ {
			scanf("%d", &tmp)
			xor ^= tmp
			sum += tmp
		}
		printf("2\n%d %d\n", xor, sum+xor)
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t, n int
	for scanf("%d\n", &t); t > 0; t-- {
		scanf("%d\n", &n)
		tmp, xor, sum := 0, 0, 0
		for i := 0; i < n; i++ {
			scanf("%d", &tmp)
			xor ^= tmp
			sum += tmp
		}
		scanf("\n")
		printf("2\n%d %d\n", xor, sum+xor)
	}
}

package main

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

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

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

	t := readInt(reader)

	for _i := 0; _i < t; _i++ {
		n := readInt(reader)
		arr := make([]int, n)
		line := strings.Split(readLine(reader), " ")
		for i := range arr {
			arr[i] = parseInt(line[i])
		}

		v := 0
		s := 0
		for _, x := range arr {
			v = v ^ x
			s += x
		}

		s += v

		fmt.Println(2)
		fmt.Println(v, s)
	}
}

func readInt(reader *bufio.Reader) int {
	return parseInt(readLine(reader))
}

func parseInt(s string) int {
	v, err := strconv.ParseInt(s, 10, 64)
	checkError(err)
	return int(v)
}

func readLine(reader *bufio.Reader) string {
	str, err := reader.ReadString('\n')
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(str)
}

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

package main

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

type heap struct {
  array []int
}

func (h *heap) push(val int) {
  h.array = append(h.array, val)
  cur := len(h.array) - 1
  for cur > 0 {
    var parent int
    if (cur & 1) == 1 {
      parent = (cur - 1) / 2
    } else {
      parent = (cur - 2) / 2
    }
    if h.array[cur] < h.array[parent] {
      h.array[cur], h.array[parent] = h.array[parent], h.array[cur]
      cur = parent
    } else {
      break
    }
  }
}

func (h *heap) pop() int {
  res := h.array[0]
  h.array[0], h.array[len(h.array)-1] = h.array[len(h.array)-1], h.array[0]
  h.array = h.array[:len(h.array)-1]
  cur := 0
  for cur < len(h.array) {
    smallest := cur
    if cur*2+1 < len(h.array) && h.array[smallest] > h.array[cur*2+1] {
      smallest = cur*2 + 1
    }
    if cur*2+2 < len(h.array) && h.array[smallest] > h.array[cur*2+2] {
      smallest = cur*2 + 2
    }
    if smallest != cur {
      h.array[smallest], h.array[cur] = h.array[cur], h.array[smallest]
      cur = smallest
    } else {
      break
    }
  }
  return res
}

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var T int
  Fscan(in, &T)
  for T > 0 {
    T--
    var n int
    var temp int64
    Fscan(in, &n)
    var add, xor int64 = 0, 0
    for i := 0; i < n; i++ {
      Fscan(in, &temp)
      add += temp
      xor ^= temp
    }
    var var0, var1, var2 int64 = 0, 0, 0
    if (add & 1) == 1 {
      var0 = 1
      add ^= 1
      xor ^= 1
    }
    for i := int64(2); add > 2*xor; i <<= 1 {
      if (xor & i) == 0 {
        xor |= i
        var0 |= i
        add += i
      }
    }
    var1, var2 = (2*xor-add)/2, (2*xor-add)/2
    Fprintln(out, 3)
    Fprintln(out, var0, var1, var2)
  }
}

package main

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

type heap struct {
  array []int
}

func (h *heap) push(val int) {
  h.array = append(h.array, val)
  cur := len(h.array) - 1
  for cur > 0 {
    var parent int
    if (cur & 1) == 1 {
      parent = (cur - 1) / 2
    } else {
      parent = (cur - 2) / 2
    }
    if h.array[cur] < h.array[parent] {
      h.array[cur], h.array[parent] = h.array[parent], h.array[cur]
      cur = parent
    } else {
      break
    }
  }
}

func (h *heap) pop() int {
  res := h.array[0]
  h.array[0], h.array[len(h.array)-1] = h.array[len(h.array)-1], h.array[0]
  h.array = h.array[:len(h.array)-1]
  cur := 0
  for cur < len(h.array) {
    smallest := cur
    if cur*2+1 < len(h.array) && h.array[smallest] > h.array[cur*2+1] {
      smallest = cur*2 + 1
    }
    if cur*2+2 < len(h.array) && h.array[smallest] > h.array[cur*2+2] {
      smallest = cur*2 + 2
    }
    if smallest != cur {
      h.array[smallest], h.array[cur] = h.array[cur], h.array[smallest]
      cur = smallest
    } else {
      break
    }
  }
  return res
}

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var T int
  Fscan(in, &T)
  for T > 0 {
    T--
    var n int
    var temp int64
    Fscan(in, &n)
    var add, xor int64 = 0, 0
    for i := 0; i < n; i++ {
      Fscan(in, &temp)
      add += temp
      xor ^= temp
    }
    var var0, var1, var2 int64 = 0, 0, 0
    if (add & 1) == 1 {
      var0 = 1
      add ^= 1
      xor ^= 1
    }
    for i := int64(2); add > 2*xor || 2*xor-add < 2; i <<= 1 {
      if (xor & i) == 0 {
        xor |= i
        var0 |= i
        add += i
      }
    }
    var1, var2 = (2*xor-add)/2, (2*xor-add)/2
    Fprintln(out, 3)
    Fprintln(out, var0, var1, var2)
  }
}


package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

var debug = false

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	input := getLine()
	input2 := getLine()
	ans := make([]byte, n)
	lastAvg := int((input[n-1]+input2[n-1])/2 - 'a')
	for i := n - 2; i >= 0; i-- {
		lastAvg += int(input[i]+input2[i]-2*'a') * 13
		ans[i+1] = byte(lastAvg%26) + 'a'
		lastAvg /= 26
	}
	ans[0] = byte(lastAvg) + 'a'
	printf("%s\n", string(ans))
}

package main

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

func main() {
	//	fmt.Printf("%d\n",(((199999*(200000))%p)*199999)%p)
	buf := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscanf(buf, "%d\n", &n)
	str1 := make([]byte, n+1)
	str2 := make([]byte, n+1)
	mat := make([]int, n+2)
	fmt.Fscanf(buf, "%s\n", &str1)
	fmt.Fscanf(buf, "%s\n", &str2)
	st := 2 * int('a')
	sum := 0
	//fmt.Printf("%v\n", str1)
	//fmt.Printf("%v\n", str2)
	//fmt.Printf("st=%d\n", st)
	for i := 0; i < n; i++ {
		sum += int(str1[n-i-1]) + int(str2[n-i-1]) - st
		mat[i] = sum % 26
		sum /= 26
	}
	if sum > 0{
		mat[n] = sum
	}
	//fmt.Printf("%v\n", mat)
	sum = mat[n]
	len := 0
	for i := n - 1; i >= 0; i-- {
		sum = 26*sum + mat[i]
		str1[len] = 'a' + (byte)(sum/2);
		len++
		sum %= 2
	}

	//str1[len]=0
	//	fmt.Printf("ans1=%d\n",ans)

	fmt.Printf("%s\n", str1)

}

package main

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

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

	var n int
	var s, t []byte
	Fscan(in, &n, &s, &t)
	m := make([]byte, n)
	m[n-1] = (s[n-1] + t[n-1]) / 2
	for i := n - 1; i >= 0; i-- {
		m[i] = (s[i] + t[i]) / 2
		if s[i]&1 != t[i]&1 {
			m[i+1] += 13
			if m[i+1] > 'z' {
				m[i+1] -= 26
				m[i]++
			}
		}
	}
	Fprint(out, string(m))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1144E(_r io.Reader, _w io.Writer) {
	toInts := func(s []byte) []int {
		ints := make([]int, len(s))
		for i, b := range s {
			ints[i] = int(b)
		}
		return ints
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	var _s, _t []byte
	Fscan(in, &n, &_s, &_t)
	s, t := toInts(_s), toInts(_t)
	ans := make([]byte, n)
	for i := range s[:n-1] {
		v1 := (s[i]-'a')*26 + s[i+1] - 'a'
		v2 := (t[i]-'a')*26 + t[i+1] - 'a'
		m := (v1+v2)/52 + 'a'
		if 2*m > s[i]+t[i] {
			s[i+1] -= 26
		} else if 2*m < s[i]+t[i] {
			t[i+1] += 26
		}
		ans[i] = byte(m)
	}
	ans[n-1] = byte((s[n-1] + t[n-1]) / 2)
	for i := n - 1; i > 0; i-- {
		if ans[i] > 'z' {
			ans[i] -= 26
			ans[i-1]++
		}
	}
	Fprint(out, string(ans))
}

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

package main

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

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

	var k int
	fmt.Fscanln(in, &k)

	s, t := make([]rune, k), make([]rune, k)
	for i := range s {
		t[i], _, _ = in.ReadRune()
	}
	in.ReadLine()
	for i := range t {
		s[i], _, _ = in.ReadRune()
	}

	result := make([]rune, k)
	result[k - 1] = (s[k - 1] + t[k - 1]) / 2
	for i := k - 2; i >= 0; i-- {
		result[i] = (s[i] + t[i]) / 2
		if s[i] % 2 != t[i] % 2 {
			result[i + 1] += 13
			if result[i + 1] > 'z' {
				result[i + 1] -= 26
				result[i]++
			}
		}
	}

	fmt.Println(string(result))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func main()  {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanln(in, &n)

	one := make([]byte, n, n)
	two := make([]byte, n, n)

	fmt.Fscanln(in, &one)
	fmt.Fscanln(in, &two)

	tmp := make([]byte, n, n)
	bit := byte(0)
	// 输入 进位
	for i:= n - 1; i >= 0; i -- {
		tmp[i] = one[i] - 'a' + two[i] - 'a'
		if bit != 0 {
			tmp[i] = tmp[i] + bit
		}
		if tmp[i] >= 26 && i != 0{
			tmp[i] = tmp[i] - 26
			bit = 1
		} else {
			bit = 0
		}
	}
	// 模拟除法
	bit = byte(0)
	for i := 0 ; i < len(tmp); i ++ {
		tmp[i] = tmp[i] + bit
		if tmp[i] & 1  == 0 {
			tmp[i] = tmp [i] >> 1
			bit = 0
		} else {
			tmp[i] = tmp [i] >> 1
			bit = 26
		}
	}
	for i := 0; i < n; i ++ {
		tmp[i] = tmp[i] + 'a'
	}
	fmt.Printf("%s\n", tmp)
}

package main

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

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

	var n int
	var s, t []byte
	Fscan(in, &n, &s, &t)
	ans := make([]byte, n)
	for i := range s[:n-1] {
		v1 := int(s[i]-'a')*26 + int(s[i+1]-'a')
		v2 := int(t[i]-'a')*26 + int(t[i+1]-'a')
		ans[i] = byte((v1+v2)/52) + 'a'
		if 2*ans[i] > s[i]+t[i] {
			s[i+1] -= 26
		} else if 2*ans[i] < s[i]+t[i] {
			t[i+1] += 26
		}
	}
	ans[n-1] = byte((int(s[n-1]) + int(t[n-1])) / 2)
	Fprint(out, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1144E(_r io.Reader, _w io.Writer) {
	toInts := func(s []byte) []int {
		ints := make([]int, len(s))
		for i, b := range s {
			ints[i] = int(b)
		}
		return ints
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	var _s, _t []byte
	Fscan(in, &n, &_s, &_t)
	s, t := toInts(_s), toInts(_t)
	ans := make([]byte, n)
	for i := range s[:n-1] {
		v1 := (s[i]-'a')*26 + s[i+1] - 'a'
		v2 := (t[i]-'a')*26 + t[i+1] - 'a'
		m := (v1+v2)/52 + 'a'
		if 2*m > s[i]+t[i] {
			s[i+1] -= 26
		} else if 2*m < s[i]+t[i] {
			t[i+1] += 26
		}
		ans[i] = byte(m)
	}
	ans[n-1] = byte((s[n-1] + t[n-1]) / 2)
	Fprint(out, string(ans))
}

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

package main

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

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

	var n int
	var s, t []byte
	Fscan(in, &n, &s, &t)
	ans := make([]byte, n)
	for i := range s[:n-1] {
		v1 := int(s[i]-'a')*26 + int(s[i+1]-'a')
		v2 := int(t[i]-'a')*26 + int(t[i+1]-'a')
		ans[i] = byte((v1+v2)/52) + 'a'
		if 2*ans[i] > s[i]+t[i] {
			s[i+1] -= 26
		} else if 2*ans[i] < s[i]+t[i] {
			t[i+1] += 26
		}
	}
	ans[n-1] = (s[n-1] + t[n-1]) / 2
	Fprint(out, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1144E(_r io.Reader, _w io.Writer) {
	toInts := func(s []byte) []int {
		ints := make([]int, len(s))
		for i, b := range s {
			ints[i] = int(b)
		}
		return ints
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	var _s, _t []byte
	Fscan(in, &n, &_s, &_t)
	s, t := toInts(_s), toInts(_t)
	ans := make([]byte, n)
	for i := range s[:n-1] {
		v1 := (s[i]-'a')*26 + s[i+1] - 'a'
		v2 := (t[i]-'a')*26 + t[i+1] - 'a'
		m := (v1+v2)/52 + 'a'
		if 2*m > s[i]+t[i] {
			s[i+1] -= 26
		} else if 2*m < s[i]+t[i] {
			t[i+1] += 26
		}
		if m > 'z' {
			m -= 26
			ans[i-1]++
		}
		ans[i] = byte(m)
	}
	ans[n-1] = byte((s[n-1] + t[n-1]) / 2)
	if ans[n-1] > 'z' {
		ans[n-1] -= 26
		ans[n-2]++
	}
	Fprint(out, string(ans))
}

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


package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	//"strconv"
	//"sort"
	//"unicode/utf8"
)

func main() {
	var a, b, pos int
	var err error
	var s string
	input := bufio.NewScanner(os.Stdin)
	//input.Split(bufio.ScanWords)

	for input.Scan() {
		if err == io.EOF {
			break
		}
		//input.Scan()
		s = input.Text()
		//fmt.Println(s)
		if s[0] == '+' {
			a++
		} else if s[0] == '-' {
			a--
		} else {
			for i, v := range s {
				if v == ':' {
					pos = i
				}
			}
			b += a * (int(len(s)) - pos - 1)
		}
	}
	fmt.Println(b)
}

package main

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

var cs map[int]int = make(map[int]int)

func Init() {}
func Solve(io *FastIO) {
	var s string
	c := 0
	o := 0
	for i := 0; i < 100; i++ {
		s = io.NextLine()
		if s == "" {
			break
		}
		if s[0] == '+' {
			c++
		} else if s[0] == '-' {
			c--
		} else {
			o += c * (len(s) - 1 - strings.Index(s, ":"))
		}
	}
	io.Println(o)
}

type FastIO struct {
	//by megaspazz
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	if IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func main() {
	users := map[string]int{}
	bs, _ := ioutil.ReadAll(os.Stdin)

	commands := bytes.Split(bs, []byte("\r\n"))
	result := 0
	for i := 0; i < len(commands); i++ {
		c := commands[i]
		if len(c) == 0 {
			continue
		}
		if c[0] == '+' {
			users[string(c[1:])] = 0
		} else if c[0] == '-' {
			delete(users, string(c[1:]))
		} else {
			keypair := bytes.Split(c, []byte(":"))
			result += (len(keypair[1]) * len(users))
		}
	}
	fmt.Printf("%d", result)
}

package main

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

func main() {
	chatMembers := make(map[string]interface{})
	totalBytesSent := 0

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.TrimSpace(line)

		if line[0] == '+' {
			name := line[1:]
			chatMembers[name] = struct{}{}
		} else if line[0] == '-' {
			name := line[1:]
			delete(chatMembers, name)
		} else {
			parts := strings.Split(line, ":")
			if len(parts) != 2 {
				fmt.Println("Invalid send message format")
				os.Exit(1)
			}

			_, message := parts[0], parts[1]
			messageBytes := []byte(message)
			totalBytesSent += len(messageBytes) * len(chatMembers)
		}
	}

	fmt.Println(totalBytesSent)
}

package main

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

var scanner *bufio.Scanner

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

	sent := 0
	perps := make(map[string]bool)
	for scanner.Scan() {
		line := scanner.Text()
		switch line[0] {
		case '-':
			delete(perps, line[1:])
			break
		case '+':
			perps[line[1:]] = true
			break
		default:
			idx := strings.Index(line, ":")
			sent += len(perps) * len(line[idx+1:])
		}
	}
	fmt.Println(sent)
}

func main() {
	solve()
}

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

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

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

package main

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

var scanner *bufio.Scanner

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

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

  chatSize := 0
  result := 0
  for {
    line, err := reader.ReadString('\n')
    if err != nil {
      break
    }
    s := strings.TrimSpace(line)
    if s[0] == '+' {
      chatSize++
    } else if s[0] == '-' {
      chatSize--
    } else {
      parts := strings.Split(s, ":")
      result += chatSize * len(parts[1])
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

/*

A. Исходящий трафик чата
ограничение по времени на тест
	1 second
ограничение по памяти на тест
	64 megabytes

Последнее время Поликарп много трудится над новым проектом "Поличат". Следуя современным тенденциям IT индустрии, Поликарп решил, что в этом проекте непременно должен быть чат. Проведя пару часов за компьютером, Поликарп написал чат-сервер, который может выполнять три типа команд:

Добавить человека в чат (команда 'Добавить').
Удалить человека из чата (команда 'Удалить').
Отправить сообщение от кого-либо всем участникам чата, включая отправителя сообщения (команда 'Отправить').
Сейчас Поликарп хочет узнать, какое количество исходящего трафика пошлет его сервер при обработке набора команд.

Поликарп выяснил, что при обработке команды 'Добавить' или 'Удалить' сервер не посылает трафика вовсе, а при обработке команды 'Отправить' каждому из участников чата посылается l байт, где l — длина рассылаемого сообщения.

Так как у Поликарпа совсем нет свободного времени, он просит вас помочь с решением этой задачи.

Входные данные
	Входной файл будет содержать не более 100 команд. Каждая команда будет располагаться на своей строке и иметь длину не более 100 символов. Форматы команд будут следующими:

	+<имя> для команды 'Добавить'.
	-<имя> для команды 'Удалить'.
	<имя_отправителя>:<текст_сообщения> для команды 'Отправить'.
	<имя> и <имя_отправителя> — непустая последовательность латинских букв или цифр. <текст_сообщения> может содержать латинские буквы, цифры и пробелы, но не может начинаться или оканчиваться пробелом. <текст_сообщения> может быть пустой строкой.

Гарантируется, что входные данные корректны, то есть человек не будет добавлен в чат, если он там уже присутствует, не будет команды 'Удалить', если человека с таким именем нет в чате и тому подобное.

Имена, различающиеся исключительно регистром букв следует считать различными.

*/

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

type Command interface {
	cmd()
}

type Add string
type Remove string
type Message struct {
	from, text string
}

func (_ Add) cmd() {}
func (_ Remove) cmd() {}
func (_ Message) cmd() {}

func solve(cmds []Command) int {
	invited := map[string]bool{}

	bytes := 0
	for _, cmd := range cmds {
		switch val := cmd.(type) {
		case Add:
			invited[string(val)] = true
		case Remove:
			delete(invited, string(val))
		case Message:
			msg := Message(val)
			if invited[msg.from] {
				bytes += len(msg.text)*len(invited)
			}
		}
	}
	return bytes
}

func main() {
	cmds := []Command{}

	reader := bufio.NewReader(os.Stdin)
	for {
		bytes, _, err := reader.ReadLine()
		s := string(bytes)

		if len(s) == 0 || err != nil {
			break
		}

		switch s[0] {
		case '+':
			cmds = append(cmds, Add(s[1:]))
		case '-':
			cmds = append(cmds, Remove(s[1:]))
		default:
			i := strings.IndexByte(s, ':')
			cmds = append(cmds, Message{from: s[:i], text: s[i+1:]})
		}
	}
	fmt.Printf("%d\n", solve(cmds))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    cnt, ans := 0, 0
    for scanner.Scan() {
        if scanner.Text()[0] == '+' {
            cnt++
        } else if scanner.Text()[0] == '-' {
            cnt--
        } else {
            for k, v := range scanner.Text() {
                if v == ':' {
                    ans += (len(scanner.Text())-k-1)*cnt
                    break
                }
            }
        }
    }
    fmt.Println(ans)
}

package main

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

func main() {
	z := bufio.NewScanner(os.Stdin)
	p, r := 0,0
	for z.Scan() {
		s := z.Text()
		switch s[0] {
			case '+': p++; break
			case '-': p--; break
			default:
				ss := strings.SplitN(s,":",2)
				r += p*len(strings.TrimSpace(ss[1]))
				break
		}
	}
	fmt.Println(r)
}

package main

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

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

	addPattern, _ := regexp.Compile("\\+([a-zA-Z0-9]*)")
	removePattern, _ := regexp.Compile("-([a-zA-Z0-9]*)")
	messagePattern, _ := regexp.Compile("([a-zA-Z0-9]*):(.*)")

	userDb := make(map[string]bool)
	totalSize := 0
	for scanner.Scan() {
		line := scanner.Text()
		if addPattern.MatchString(line) {
			match := addPattern.FindStringSubmatch(line)
			user := match[1]
			userDb[user] = true
		} else if removePattern.MatchString(line) {
			match := removePattern.FindStringSubmatch(line)
			user := match[1]
			delete(userDb, user)
		} else if messagePattern.MatchString(line) {
			match := messagePattern.FindStringSubmatch(line)
			_, message := match[1], match[2]
			totalSize += len(userDb) * len(message)
		}
	}
	fmt.Println(totalSize)
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int
	var err error

	scan := bufio.NewScanner(os.Stdin)

	for scan.Scan() {
		if err == io.EOF || scan.Err() != nil {
			break
		}
		ln := scan.Text()
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}
	}

	// fmt.Println(traffic)
	fmt.Printf("%d\n", traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var traffic, count int
	var cmd string
	for scanner.Scan() {
		cmd = scanner.Text()
		if cmd == "" {
			break
		}
		if string(cmd[0]) == "+" {
			count += 1
			continue
		}
		if string(cmd[0]) == "-" {
			count -= 1
			continue
		}
		traffic += count * len(strings.Split(cmd, ":")[1])
	}
	fmt.Fprintln(writer, traffic)
}

package main

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

func main() {
	room := make(map[string]bool)
	rdr := bufio.NewReader(os.Stdin)
	z := 0
	for {
		if cmd, _, e := rdr.ReadLine(); e != nil {
			break
		} else {
			switch cmd[0] {
			case '+':
				room[string(cmd[1:])] = true
			case '-':
				delete(room, string(cmd[1:]))
			default:
				l := len(cmd) - strings.Index(string(cmd), ":") - 1
				z += l * len(room)
			}

		}
	}
	fmt.Println(z)
}

package main

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

func main() {
	count := 0
	traffic := 0
	line, err := nextLine()
	for err == nil {
		if len(line) == 0 {

		} else if strings.HasPrefix(line, "+") {
			count++
		} else if strings.HasPrefix(line, "-") {
			count--
		} else {
			c := strings.Split(line, ":")
			traffic += count * len(c[1])
		}
		line, err = nextLine()
	}
	printf("%d\n", traffic)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func main() {
	var users, count uint
	reader := bufio.NewReader(os.Stdin)

	for {
		str, _, err := reader.ReadLine()
		if err == io.EOF {
			break
		}

		switch str[0] {
		case '+':
			users++
		case '-':
			users--
		default:
			//msg := str[strings.Index(str, ":"):]
			msg := strings.Split(string(str), ":")[1]
			count += uint(len(msg)) * users
		}
	}
	fmt.Println(count)
}

package main

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

func main() {
	users := map[string]int{}
	bs, _ := ioutil.ReadAll(os.Stdin)

	commands := bytes.Split(bs, []byte("\n"))
	result := 0

	for i := 0; i < len(commands); i++ {
		c := commands[i]
		if len(c) == 0 {
			continue
		}
		if c[0] == '+' {
			users[string(c[1:])] = 0
		} else if c[0] == '-' {
			delete(users, string(c[1:]))
		} else {
			keypair := bytes.Split(c, []byte(":"))
			result += (len(keypair[1]) * len(users))
		}
	}
	fmt.Printf("%d", result)
}

package main

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

func main() {
	users := map[string]int{}
	bs, _ := ioutil.ReadAll(os.Stdin)

	commands := bytes.Split(bs, []byte("\n"))
	result := 0
	for i := 0; i < len(commands); i++ {
		fmt.Printf("%d %d %s\n", result, len(commands), string(commands[i]))
		c := commands[i]
		if len(c) == 0 {
			continue
		}
		if c[0] == '+' {
			users[string(c[1:])] = 0
		} else if c[0] == '-' {
			delete(users, string(c[1:]))
		} else {
			keypair := bytes.Split(c, []byte(":"))
			result += (len(keypair[1]) * len(users))
		}
	}
	fmt.Printf("%d", result)
}

package main

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

func main() {
	users := map[string]int{}
	bs, _ := ioutil.ReadAll(os.Stdin)

	commands := bytes.Split(bs, []byte("\r\n"))
	result := 0
	for i := 0; i < len(commands); i++ {
		fmt.Printf("%d %d %s\n", result, len(commands), string(commands[i]))
		c := commands[i]
		if len(c) == 0 {
			continue
		}
		if c[0] == '+' {
			users[string(c[1:])] = 0
		} else if c[0] == '-' {
			delete(users, string(c[1:]))
		} else {
			keypair := bytes.Split(c, []byte(":"))
			result += (len(keypair[1]) * len(users))
		}
	}
	fmt.Printf("%d", result)
}

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

func main() {
	var a,b,pos int
	var s string
        for {
        	n, err := fmt.Scanf("%s", &s)
        	if n == 0 || err != nil { break }
 	        if s[0]=='+' {
 	        	a++
 	        } else if s[0]=='-' {
 	        	a--
 	        } else {
 	        	for i:=0;i<len(s);i++ {
 	        		if s[i]==':' {
 	        			pos=i
 	        		}
 	        	}
 	        	b+=a*int(len(s))-pos-1
 	        }
 	}
 	fmt.Println(b)
}

package main

import (
    //"bufio"
    "fmt"
    "io"
    //"os"
    //"strconv"
    //"sort"
    //"unicode/utf8"
)

func main() {
    var a, b, pos int
    var err error
    var s string
    //input := bufio.NewScanner(os.Stdin)
    //input.Split(bufio.ScanWords)

    for {
        if err == io.EOF {
            break
        }
        _, err = fmt.Scan(&s)
        //fmt.Println(s)
        if s[0] == '+' {
            a++
        } else if s[0] == '-' {
            a--
        } else {
            for i,v:= range s {
            	if v == ':' {
                    pos = i
                }
            }
            b += a*(int(len(s)) - pos - 1)
        }
    }
    fmt.Println(b)
}

package main

import (
    //"bufio"
    "fmt"
    "io"
    //"os"
    //"strconv"
    //"sort"
    //"unicode/utf8"
)

func main() {
    var a, b, pos int
    var err error
    var s string
    //input := bufio.NewScanner(os.Stdin)
    //input.Split(bufio.ScanWords)

    for {
        if err == io.EOF {
            break
        }
        _, err = fmt.Scan(&s)
        fmt.Println(s)
        if s[0] == '+' {
            a++
        } else if s[0] == '-' {
            a--
        } else {
            for i,v:= range s {
            	if v == ':' {
                    pos = i
                }
            }
            b += a*(int(len(s)) - pos - 1)
        }
    }
    fmt.Println(b)
}

package main

/*

A. Исходящий трафик чата
ограничение по времени на тест
	1 second
ограничение по памяти на тест
	64 megabytes

Последнее время Поликарп много трудится над новым проектом "Поличат". Следуя современным тенденциям IT индустрии, Поликарп решил, что в этом проекте непременно должен быть чат. Проведя пару часов за компьютером, Поликарп написал чат-сервер, который может выполнять три типа команд:

Добавить человека в чат (команда 'Добавить').
Удалить человека из чата (команда 'Удалить').
Отправить сообщение от кого-либо всем участникам чата, включая отправителя сообщения (команда 'Отправить').
Сейчас Поликарп хочет узнать, какое количество исходящего трафика пошлет его сервер при обработке набора команд.

Поликарп выяснил, что при обработке команды 'Добавить' или 'Удалить' сервер не посылает трафика вовсе, а при обработке команды 'Отправить' каждому из участников чата посылается l байт, где l — длина рассылаемого сообщения.

Так как у Поликарпа совсем нет свободного времени, он просит вас помочь с решением этой задачи.

Входные данные
	Входной файл будет содержать не более 100 команд. Каждая команда будет располагаться на своей строке и иметь длину не более 100 символов. Форматы команд будут следующими:

	+<имя> для команды 'Добавить'.
	-<имя> для команды 'Удалить'.
	<имя_отправителя>:<текст_сообщения> для команды 'Отправить'.
	<имя> и <имя_отправителя> — непустая последовательность латинских букв или цифр. <текст_сообщения> может содержать латинские буквы, цифры и пробелы, но не может начинаться или оканчиваться пробелом. <текст_сообщения> может быть пустой строкой.

Гарантируется, что входные данные корректны, то есть человек не будет добавлен в чат, если он там уже присутствует, не будет команды 'Удалить', если человека с таким именем нет в чате и тому подобное.

Имена, различающиеся исключительно регистром букв следует считать различными.

*/

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

type Command interface {
	cmd()
}

type Add string
type Remove string
type Message struct {
	from, text string
}

func (_ Add) cmd() {}
func (_ Remove) cmd() {}
func (_ Message) cmd() {}

func solve(cmds []Command) int {
	invited := map[string]bool{}

	bytes := 0
	for _, cmd := range cmds {
		switch val := cmd.(type) {
		case Add:
			invited[string(val)] = true
		case Remove:
			delete(invited, string(val))
		case Message:
			msg := Message(val)
			if invited[msg.from] {
				bytes += len(msg.text)*len(invited)
			}
		}
	}
	return bytes
}

func main() {
	cmds := []Command{}

	reader := bufio.NewReader(os.Stdin)
	for {
		s, err := reader.ReadString('\n')
		if len(s) == 0 || err != nil {
			break
		}
		s = s[:len(s)-1]

		switch s[0] {
		case '+':
			cmds = append(cmds, Add(s[1:]))
		case '-':
			cmds = append(cmds, Remove(s[1:]))
		default:
			i := strings.IndexByte(s, ':')
			cmds = append(cmds, Message{from: s[:i], text: s[i+1:]})
		}
	}
	fmt.Printf("%d\n", solve(cmds))
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		// var ln string
		// fmt.Scanln(&ln)
		// scan := bufio.NewScanner(os.Stdin)
		// scan.Scan()
		// ln = scan.Text()
		reader := bufio.NewReader(os.Stdin)
		ln, _ := reader.ReadString('\n')
		ln = strings.TrimSpace(ln)
		// ln = strings.Replace(ln, "\n\r", "", -1)
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for {
		// var ln string
		// fmt.Scanln(&ln)
		// scan := bufio.NewScanner(os.Stdin)
		// scan.Scan()
		// ln = scan.Text()
		reader := bufio.NewReader(os.Stdin)
		bline, _, err := reader.ReadLine()
		if err != nil {
			break
		}
		ln := strings.TrimSpace(string(bline))
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	// fmt.Println(traffic)
	fmt.Printf("%d\n", traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		var ln string
		// fmt.Scanln(&ln)
		scan := bufio.NewScanner(os.Stdin)
		scan.Scan()
		ln = scan.Text()
		// reader := bufio.NewReader(os.Stdin)
		// ln, _ := reader.ReadString('\n')
		// ln = strings.Replace(ln, "\n\r", "", -1)
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		reader := bufio.NewReader(os.Stdin)
		ln, _ := reader.ReadString('\n')
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		reader := bufio.NewReader(os.Stdin)
		ln, _ := reader.ReadString('\n')
		ln = strings.Replace(ln, "\n", "", -1)
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		// var ln string
		// fmt.Scanln(&ln)
		reader := bufio.NewReader(os.Stdin)
		ln, _ := reader.ReadString('\n')
		ln = strings.Replace(ln, "\n\r", "", -1)
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {

	personList := make([]string, 0)
	var traffic int

	for i := 0; i < 7; i++ {
		var ln string

		scanner := bufio.NewScanner(os.Stdin)
		for scanner.Scan() {
			ln = scanner.Text() // Println will add back the final '\n'
			break
		}

		// fmt.Scanln(&ln)
		// reader := bufio.NewReader(os.Stdin)
		// ln, _ := reader.ReadString('\n')
		var message string

		if strings.HasPrefix(ln, "+") {
			person := string(ln[1:])
			personList = append(personList, person)
		} else if strings.HasPrefix(ln, "-") {
			person := string(ln[1:])
			personList = removeItem(personList, person)
		} else {
			index := strings.Index(ln, ":")
			message = strings.TrimSpace(string(ln[index+1:]))
			traffic += len(message) * len(personList)
		}

	}

	fmt.Println(traffic)
}

func removeItem(arr []string, person string) []string {
	for i, p := range arr {
		if p == person {
			arr = append(arr[:i], arr[i+1:]...)
		}
	}

	return arr
}

package main

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

func main() {
    var a, b, pos int
    var err error
    var s string
    //input := bufio.NewScanner(os.Stdin)
    //input.Split(bufio.ScanWords)

    for {
        if err == io.EOF {
            break
        }
        _, err = fmt.Scan(&s)
        //s = input.Text()
        if s[0] == '+' {
            a++
        } else if s[0] == '-' {
            a--
        } else {
            for i := 0; i < len(s); i++ {
                if s[i] == ':' {
                    pos = i
                }
            }
            b += a*int(len(s)) - pos - 1
        }
    }
    fmt.Println(b)
}

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
    //"strconv"
    //"sort"
    //"unicode/utf8"
)

func main() {
    var a, b, pos int
    var err error
    var s string
    input := bufio.NewScanner(os.Stdin)
    //input.Split(bufio.ScanWords)

    for input.Scan() {
        if err == io.EOF {
            break
        }
        //input.Scan()
        s = input.Text()
        fmt.Println(s)
        if s[0] == '+' {
            a++
        } else if s[0] == '-' {
            a--
        } else {
            for i, v := range s {
                if v == ':' {
                    pos = i
                }
            }
            b += a * (int(len(s)) - pos - 1)
        }
    }
    fmt.Println(b)
}


// 300A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := range a {
        fmt.Scan(&a[i])
    }
    sort.Sort(sort.IntSlice(a))
    fmt.Print("1")
    fmt.Print(" ")
    fmt.Print(a[0])
    fmt.Println()
    if a[1] == 0 {
        fmt.Print(n - 2)
        fmt.Print(" ")
        for i := 2; i < n; i++ {
            fmt.Print(a[i])
            fmt.Print(" ")
        }
        fmt.Println()
        fmt.Print("1")
        fmt.Print(" ")
        fmt.Print("0")
        fmt.Println()
    } else if a[1] < 0 && a[2] < 0 {
        fmt.Print("2")
        fmt.Print(" ")
        fmt.Print(a[1])
        fmt.Print(" ")
        fmt.Print(a[2])
        fmt.Println()
        fmt.Print(n - 3)
        fmt.Print(" ")
        for i := 3; i < n; i++ {
            fmt.Print(a[i])
            fmt.Print(" ")
        }
        fmt.Println()
    } else {
        fmt.Print("1")
        fmt.Print(" ")
        fmt.Println(a[n-1])
        fmt.Print(n - 2)
        fmt.Print(" ")
        for i := 1; i < n-1; i++ {
            fmt.Print(a[i])
            fmt.Print(" ")
        }
        fmt.Println()
    }
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

func display(numbers []int) {
  n := len(numbers)
  writer.WriteString(fmt.Sprintf("%d %d", n, numbers[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", numbers[i]))
  }
  writer.WriteString("\n")
}

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

  negative := []int{}
  positive := []int{}
  zero := []int{}
  n := getI()
  for i := 0; i < n; i++ {
    x := getI()
    if x > 0 {
      positive = append(positive, x)
    } else if x < 0 {
      negative = append(negative, x)
    } else {
      zero = append(zero, x)
    }
  }
  if len(positive) == 0 {
    positive = append(positive, negative[0])
    positive = append(positive, negative[1])
    negative = negative[2:]
  }
  if len(negative)%2 == 0 {
    zero = append(zero, negative[0])
    negative = negative[1:]
  }
  display(negative)
  display(positive)
  display(zero)
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    fmt.Println(1,a[0])
    a = a[1:]
    if a[len(a)-1] == 0 {
        fmt.Println(2,a[0],a[1])
        a = a[2:]
    } else {
        fmt.Println(1,a[len(a)-1])
        a = a[:len(a)-1]
    }
    fmt.Print(len(a))
    for i := 0; i < len(a); i++ {
        fmt.Print(" ",a[i])
    }
    fmt.Println()
}

package main

import (
	"sort"
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0; i<n;i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Println("1 ",a[0])
	if a[n-1]>0 {
	        fmt.Printf("1 %d\n",a[n-1])
		fmt.Printf("%d",n-2)
		for i:=1;i<n-1;i++ {
			fmt.Printf(" %d",a[i])
		}
	} else {
		fmt.Printf("2 %d %d\n",a[1],a[2])
		fmt.Printf("%d",n-3)
		for i:=3;i<n;i++ {
			fmt.Printf(" %d",a[i])
		}
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func Ir(x []int32) {
	fmt.Print(len(x))
	for i := int32(0); i < int32(len(x)); i++ {
		fmt.Print(" ", x[i])
	}
	fmt.Println()

}

func main() {

	var (
		i, xi, n       int32
		poz, neg, zero []int32
	)

	fmt.Scan(&n)
	poz = make([]int32, 0, n)
	neg = make([]int32, 0, n)
	zero = make([]int32, 0, n)

	for i = 0; i < n; i++ {
		fmt.Scan(&xi)
		if xi < 0 {
			neg = append(neg, xi)
			continue
		}
		if xi > 0 {
			poz = append(poz, xi)
			continue
		}
		zero = append(zero, 0)
	}

	if len(neg)%2 == 0 {
		zero = append(zero, neg[0])
		neg = neg[1:]
	}

	if len(poz) == 0 {
		poz = append(poz, neg[0:2]...)
		neg = neg[2:]
	}

	Ir(neg)
	Ir(poz)
	Ir(zero)

}

package main

import (
    "fmt"
    "sort"
)

func Select(xs []int) (ns, ps, zs []int) {
    n := len(xs)
    ns = xs[:1]
    if xs[n-1] > 0 {
        ps = xs[n-1:n]
        zs = xs[1:n-1]
    } else {
        ps = xs[1:3]
        zs = xs[3:n]
    }
    return
}

func PrintSet(xs []int) {
    fmt.Printf("%d ", len(xs))
    for _, x := range xs {
        fmt.Printf("%d ", x)
    }
    fmt.Println()
}

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

    xs := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &xs[i])
    }

    sort.Ints(xs)
    ns, ps, zs := Select(xs)
    PrintSet(ns)
    PrintSet(ps)
    PrintSet(zs)
}

package main

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

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

	pos_count := 0
	neg_count := 0
	zero_count := 0

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if a < 0 {
			array[neg_count] = a
			neg_count++
		} else if a > 0 {
			array[n-pos_count-1] = a
			pos_count++
		} else {
			zero_count++
		}
	}

	if pos_count > 0 {
		if neg_count%2 != 0 {
			fmt.Printf("%d ", neg_count)
			for i := 0; i < neg_count; i++ {
				fmt.Printf("%d ", array[i])
			}
			fmt.Println()
		} else {
			fmt.Printf("%d ", neg_count-1)
			for i := 0; i < neg_count-1; i++ {
				fmt.Printf("%d ", array[i])
			}
			fmt.Println()
		}
		fmt.Printf("%d ", pos_count)
		for i := 0; i < pos_count; i++ {
			fmt.Printf("%d ", array[n-i-1])
		}
		fmt.Println()
		if neg_count%2 != 0 {
			fmt.Printf("%d ", zero_count)
			for i := 0; i < zero_count; i++ {
				fmt.Printf("0 ")
			}
			fmt.Println()
		} else {
			fmt.Printf("%d ", zero_count+1)
			for i := 0; i < zero_count; i++ {
				fmt.Printf("0 ")
			}
			fmt.Println(array[neg_count-1])
		}
	} else {
		if neg_count%2 != 0 {
			fmt.Printf("%d ", neg_count-2)
			for i := 0; i < neg_count-2; i++ {
				fmt.Printf("%d ", array[i])
			}
			fmt.Println()
		} else {
			fmt.Printf("%d ", neg_count-3)
			for i := 0; i < neg_count-3; i++ {
				fmt.Printf("%d ", array[i])
			}
			fmt.Println()
		}
		fmt.Printf("2 ")
		for i := 0; i < 2; i++ {
			fmt.Printf("%d ", array[neg_count+i-2])
		}
		fmt.Println()
		if neg_count%2 != 0 {
			fmt.Printf("%d ", zero_count)
			for i := 0; i < zero_count; i++ {
				fmt.Printf("0 ")
			}
			fmt.Println()
		} else {
			fmt.Printf("%d ", zero_count+1)
			for i := 0; i < zero_count; i++ {
				fmt.Printf("0 ")
			}
			fmt.Println(array[neg_count-3])
		}
	}
}

// 300A-mic
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int				// membuat variabel n dengan jenis int
	fmt.Scan(&n)			// mengambil input
	a := make([]int, n)		//membuat variabel a dengan jenis int yang diisi dengan array n
	for i := range a {		// looping
		fmt.Scan(&a[i])     // mengambil input kedua
	}
	sort.Sort(sort.IntSlice(a)) // untuk sort
	fmt.Print("1")			// cetak 1
	fmt.Print(" ")			// cetak spasi
	fmt.Print(a[0])			// cetak hasil array a elemen ke 0
	fmt.Println()			//cetak enter
	if a[1] == 0 {			// jika array a elemen 1 sama dengan 0
		fmt.Print(n - 2)	// cetak hasil n dikurang 2
		fmt.Print(" ")		// cetak spasi
		for i := 2; i < n; i++ {	//looping kedua
			fmt.Print(a[i])			// cetak array a elemen i
			fmt.Print(" ")			// cetak spasi
		}
		fmt.Println()				//cetak enter
		fmt.Print("1")				//cetak 1
		fmt.Print(" ")				// cetak spasi
		fmt.Print("0")				// cetak 0
		fmt.Println()				// cetak enter
	} else if a[1] < 0 && a[2] < 0 {	// jika array a elemen 1 kurang dari 0 dan array a elemen kedua kurang dari 0
		fmt.Print("2")				// cetak 2
		fmt.Print(" ")				// cetak spasi
		fmt.Print(a[1])				// cetak array a elemen pertama
		fmt.Print(" ")				// cetak spasi
		fmt.Print(a[2])				// cetak array a elemen kedua
		fmt.Println()				// cetak enter
		fmt.Print(n - 3)			// cetak hasil dari n-3
		fmt.Print(" ")				// cetak spasi
		for i := 3; i < n; i++ {	// looping ke 3
			fmt.Print(a[i])			// cetak array a elemen ke i
			fmt.Print(" ")			// cetak spasi
		}
		fmt.Println()				// cetak enter
	} else {						// lainnya
		fmt.Print("1")				// cetak 1
		fmt.Print(" ")				// cetak spasi
		fmt.Println(a[n-1])			// cetak array a elemen ke n-1
		fmt.Print(n - 2)			// cetak hasil n-2
		fmt.Print(" ")				// cetak spasi
		for i := 1; i < n-1; i++ {	// looping ketiga
			fmt.Print(a[i])			// cetak array a elemen ke i
			fmt.Print(" ")			//cetak spasi
		}
		fmt.Println()				// cetak enter
	}
}

package main

import (
	"fmt"
	"sort"
)

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

	lo := 0
	hi := len(a)

	// Negative product.
	fmt.Printf("1 %d\n", a[0])
	lo = 1

	// Positive product.
	back := a[len(a) - 1]
	if back > 0 {
		fmt.Printf("1 %d\n", back)
		hi = len(a) - 1
	} else {
		fmt.Printf("2 %d %d\n", a[1], a[2])
		lo = 3
	}

	// Zero product.
	fmt.Printf("%d", hi - lo);
	for i := lo; i < hi; i++ {
		fmt.Printf(" %d", a[i])
	}
	fmt.Println();
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var n1, n2, n3 []int
	for i := 0; i < n; i++ {
		var i int
		fmt.Scan(&i)
		if i < 0 {
			n1 = append(n1, i)
		} else if i == 0 {
			n3 = append(n3, i)
		} else {
			n2 = append(n2, i)
		}
	}
	if len(n2) == 0 {
		n2 = append(n2, n1[:2]...)
		n1 = n1[2:]
	}
	if len(n1)%2 == 0 {
		n3 = append(n3, n1[0])
		n1 = n1[1:]
	}
	printArray(n1)
	printArray(n2)
	printArray(n3)
}

func printArray(n []int) {
	fmt.Print(len(n), " ")
	for _, i := range n {
		fmt.Print(i, " ")
	}
	fmt.Println()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	var index int
	for index = range arr {
		if arr[index] == 0 {
			break
		}
	}
	fmt.Printf("1 %d\n", arr[0])
	if index == n-1 {
		fmt.Printf("2 %d %d\n", arr[1], arr[2])
		fmt.Printf("%d ", n-3)
		for i := 3; i < n; i++ {
			fmt.Printf("%d ", arr[i])
		}

	} else if index < n-1 {
		fmt.Printf("1 %d\n", arr[n-1])
		fmt.Printf("%d ", n-2)
		for i := 1; i < n-1; i++ {
			fmt.Printf("%d ", arr[i])
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	var ng, ps, zr []int
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)

		if x == 0 {
			zr = append(zr, 0)
		} else if x > 0 {
			ps = append(ps, x)
		} else if x < 0 {
			ng = append(ng, x)
		}
	}
	if len(ps) == 0 && len(ng) > 2 {
		ps = append(ps, ng[:2]...)
		ng = append(ng[:0], ng[2:]...)
	}

	if len(ng)%2 == 0 {
		zr = append(zr, ng[:1]...)
		ng = append(ng[:0], ng[1:]...)
	}

	fmt.Print(len(ng), " ")
	for _, vl := range ng {
		fmt.Print(vl, " ")
	}
	fmt.Println()
	fmt.Print(len(ps), " ")
	for _, vl := range ps {
		fmt.Print(vl, " ")
	}
	fmt.Println()

	fmt.Print(len(zr), " ")
	for _, vl := range zr {
		fmt.Print(vl, " ")
	}
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

func display(numbers map[int]bool) {
  listed := []int{}
  for number := range numbers {
    listed = append(listed, number)
  }
  n := len(listed)
  writer.WriteString(fmt.Sprintf("%d %d", n, listed[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", listed[i]))
  }
  writer.WriteString("\n")
}

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

  negative := map[int]bool{}
  positive := map[int]bool{}
  zero := map[int]bool{}
  n := getI()
  for i := 0; i < n; i++ {
    x := getI()
    if x > 0 {
      positive[x] = true
    } else if x < 0 {
      if len(negative) == 0 {
        negative[x] = true
      } else {
        positive[x] = true
      }
    } else {
      zero[x] = true
    }
  }
  display(negative)
  display(positive)
  display(zero)
}

package main

import (
	"fmt"
	"sort"
)

func Select(xs []int) (ns, ps, zs []int) {
	n := len(xs)
	ns = xs[:1]
	if xs[n-1] > 0 {
		ps = xs[n-1:n]
		zs = xs[1:n-1]
	} else {
		ps = xs[1:3]
		zs = xs[3:n]
	}
	return
}

func PrintSet(xs []int) {
	fmt.Printf("%d ", len(xs))
	for _, x := range xs {
		fmt.Printf("%d ", x)
	}
	fmt.Println()
}

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

	xs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &xs[i])
	}

	sort.Ints(xs)
	ns, ps, zs := Select(xs)
	PrintSet(ns)
	PrintSet(ps)
	PrintSet(zs)
}

package main

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

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

	pos_count := 0
	neg_count := 0
	zero_count := 0

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if a < 0 {
			array[neg_count] = a
			neg_count++
		} else if a > 0 {
			array[n-pos_count-1] = a
			pos_count++
		} else {
			zero_count++
		}
	}

	fmt.Println("1", array[0])
	fmt.Printf("%d ", pos_count+neg_count-1)
	for i := 1; i < neg_count; i++ {
		fmt.Printf("%d ", array[i])
	}
	for i := 0; i < pos_count; i++ {
		fmt.Printf("%d ", array[n-i-1])
	}
	fmt.Println()
	fmt.Printf("%d ", zero_count)
	for i := 0; i < zero_count; i++ {
		fmt.Printf("0")
	}
	fmt.Println()
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    fmt.Println(1,a[0])
    a = a[1:]
    if a[len(a)-1] == 0 {
        fmt.Println(1,a[0],a[1])
        a = a[2:]
    } else {
        fmt.Println(1,a[len(a)-1])
        a = a[:len(a)-1]
    }
    fmt.Print(len(a))
    for i := 0; i < len(a); i++ {
        fmt.Print(" ",a[i])
    }
    fmt.Println()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	var index int
	for index = range arr {
		if arr[index] == 0 {
			break
		}
	}
	fmt.Printf("1: %d\n", arr[0])
	if index == n-1 {
		fmt.Printf("2: %d %d\n", arr[1], arr[2])
		fmt.Printf("%d:", n-3)
		for i := 3; i < n; i++ {
			fmt.Printf("%d", arr[i])
		}

	} else if index < n-1 {
		fmt.Printf("1: %d\n", arr[n-1])
		fmt.Printf("%d:", n-2)
		for i := 1; i < n-1; i++ {
			fmt.Printf("%d", arr[i])
		}
	}
}


package main

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

func abs(a int) int { return int(math.Abs(float64(a))) }

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    ans, prev := 0, 1
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        ans += abs(prev-a)+2
        prev = a
    }
    fmt.Println(ans)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var tr int
	fmt.Fscan(reader, &tr)

	trs := make([]int, tr)
	for i := 0; i < tr; i++ {
		fmt.Fscan(reader, &trs[i])
	}

	count := trs[0] + 1
	for i := 1; i < tr; i++ {
		count++
		if trs[i] < trs[i-1] {
			count += trs[i-1] - trs[i] + 1
		} else {
			count += trs[i] - trs[i-1] + 1
		}
	}

	fmt.Println(count)
}

package main

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

func main() {
	var i,n,h,o,t,d int64
	o=-1
	t=0
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	for i=0;i<n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		h=int64(aa)
		if t-h<0 {
			d=(t-h)*(-1)
		} else {
			d=t-h
		}
		o+=(d+2)
		t=h
	}
	fmt.Println(o)

}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

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

  n := getI()
  pos := getI()
  result := n+pos
  for i := 1; i < n; i++ {
    tree := getI()
    if tree < pos {
      result += pos-tree
      pos = tree
    }
    result++
    if tree > pos {
      result += tree-pos
      pos = tree
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

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

	h := make([]int, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		h[i] = a
	}

	time := h[0] + 1
	height := h[0]
	for i := 1; i < n; i++ {
		if height < h[i] {
			time += 1               // Jump
			time += (h[i] - height) // Climb Up
			height = h[i]           // At the Top
			time += 1               // Eat
		} else if height >= h[i] {
			time += (height - h[i]) // Climb Down
			height = h[i]           // At the Top
			time += 2               // Jump, Eat
		}
	}

	fmt.Println(time)
}

package main

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

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

	hn := make([]int, n, n)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		hn[i], _ = strconv.Atoi(bs.Text())
	}

	var ans uint64
	ans = uint64(hn[0]) + 1

	for i := 1; i < n; i++ {
		if hn[i] < hn[i-1] {
			ans += uint64(hn[i-1] - hn[i])
		}
		ans++

		if hn[i] > hn[i-1] {
			ans += uint64(hn[i] - hn[i-1])
		}
		ans++
	}

	fmt.Println(ans)
}

package main

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

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

	hn := make([]int, n, n)
	bs := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		bs.Scan()
		hn[i], _ = strconv.Atoi(bs.Text())
	}

	var ans uint64
	ans = 0

	pre := 0
	for i := 0; i < n; i++ {
		ans += uint64(hn[i] - pre) // up
		ans += 1                   // eat
		pre = hn[i]
		if i != n-1 && hn[i] > hn[i+1] {
			ans += uint64(hn[i] - hn[i+1]) // down
			pre = hn[i+1]
		}

		if i != n-1 {
			ans += 1 // jump
		}
	}

	fmt.Println(ans)
}

package main

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

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

	hn := make([]int, n, n)
	bs := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		bs.Scan()
		hn[i], _ = strconv.Atoi(bs.Text())
	}

	var ans uint64
	ans = uint64(hn[0]) + 1

	for i := 1; i < n; i++ {
		if hn[i] < hn[i-1] {
			ans += uint64(hn[i-1] - hn[i])
		}
		ans++

		if hn[i] > hn[i-1] {
			ans += uint64(hn[i] - hn[i-1])
		}
		ans++
	}

	fmt.Println(ans)
}