package main

import "fmt"

func main() {
    var n,a int
    fmt.Scan(&n)
    five, zero := 0, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if a == 5 {
            five++
        } else {
            zero++
        }
    }
    if zero == 0 {
        fmt.Println(-1)
    } else if five < 9 {
        fmt.Println(0)
    } else {
        five = (five/9)*9
        for i := 0; i < five; i++ { fmt.Print("5") }
        for i := 0; i < zero; i++ { fmt.Print("0") }
        fmt.Println()
    }
}

package main

 import "fmt"

 func main() {
     var n int
     fmt.Scanf("%v\n", &n)
     arr := make([]int, n, n)
     cntOf5 := 0
     for i := 0; i < n; i++ {
         fmt.Scanf("%v", &arr[i])
         if arr[i] == 5 {
             cntOf5++
         }
     }
     if cntOf5 == n {
         fmt.Println(-1)
         return
     }
     x := cntOf5 / 9
     if x == 0 {
         fmt.Println(0)
         return
     }
     for i := 0; i < x*9; i++ {
         fmt.Printf("5")
     }
     for i := 0; i < n-cntOf5; i++ {
         fmt.Printf("0")
     }
     fmt.Printf("\n")
 }

package main
import (
	"fmt"
)
func main() {
	var n int
	in,nol,lima := 0,0,0
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&in)
		if in==0 {
			nol++
		} else if in==5 {
		lima++
		}
	}

	if lima >=9 && nol>0 {
		for i:=0;i<lima/9;i++ {
			fmt.Print("555555555")
		}
		for i:= 0; i<nol; i++ {
			fmt.Print("0")
		}
		fmt.Println()
	} else {
		if nol>0 {
			fmt.Print("0")
		} else {
			fmt.Print("-1")
		}
	}
}

package main

import (
	"fmt"
	"strconv"
)

func dividable(data []int) string {
	var fiveCount, zeroCount int
	var res string
	for i := 0; i < len(data); i++ {
		if data[i] == 5 {
			fiveCount++
		}
		if data[i] == 0 {
			zeroCount++
		}
	}
	if zeroCount == 0 {
		return strconv.Itoa(-1)
	}
	if fiveCount/9 != 0 {
		for i := 0; i < fiveCount/9*9; i++ {
			res += strconv.Itoa(5)
		}
		for i := 0; i < zeroCount; i++ {
			res += strconv.Itoa(0)
		}
		return res
	}
	return strconv.Itoa(0)
}
func main() {
	var n int
	var data []int
	fmt.Scanln(&n)
	data = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i])
	}
	fmt.Println(dividable(data))
}

// http://codeforces.com/problemset/problem/352/A
// A. Jeff and Digits

package main

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

func main() {
	var (
		n, n0, n5, t, i int32
		in              *bufio.Reader
		out             *bufio.Writer
	)

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

	fmt.Fscan(in, &n)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t)
		if 5 == t {
			n5++
		} else {
			n0++
		}
	}

	if 0 == n0 {
		fmt.Fprintln(out, "-1")
	} else {
		t = (n5 / 9)
		if t > 0 {
			for i = 0; i < t; i++ {
				fmt.Fprint(out, "555555555")
			}
			t = (n0 / 9)
			for i = 0; i < t; i++ {
				fmt.Fprint(out, "000000000")
			}
			t = (n0 % 9)
			for i = 0; i < t; i++ {
				fmt.Fprint(out, "0")
			}
		} else {
			fmt.Fprint(out, "0")
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

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

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

	var fives int = 0
	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
		} else if a == 5 {
			fives++
		}
	}
	zeros := n - fives

	if zeros <= 0 {
		fmt.Println(-1)
	} else if fives < 9 {
		fmt.Println(0)
	} else {
		num_fives := fives / 9
		for i := 0; i < num_fives*9; i++ {
			fmt.Printf("5")
		}
		for i := 0; i < zeros; i++ {
			fmt.Printf("0")
		}
		fmt.Println()
	}
}

package main

 import "fmt"

 func main() {
     var n int
     fmt.Scanf("%v\n", &n)
     arr := make([]int, n, n)
     cntOf5 := 0
     for i := 0; i < n; i++ {
         fmt.Scanf("%v", &arr[i])
         if arr[i] == 5 {
             cntOf5++
         }
     }
     //fmt.Println(arr)
     x := cntOf5 / 9
     if x == 0 {
         if cntOf5 == n {
             fmt.Println(-1)
             return
         }
         fmt.Println(0)
         return
     }
     for i := 0; i < x*9; i++ {
         fmt.Printf("5")
     }
     for i := 0; i < n-cntOf5; i++ {
         fmt.Printf("0")
     }
     fmt.Printf("\n")
 }


// http://codeforces.com/problemset/problem/292/B
// B. Network Topology
// eleg a deg? az osszefuggoseg miatt

package main

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

func main() {
	var (
		i, m, n, a, b, d1, d2, dsok int32
		deg                         []int32
		in                          *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)
	//	fmt.Println(n, m)
	deg = make([]int32, n+1, n+1)

	for i = 0; i < m; i++ {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)

		//fmt.Println(a, b)

		deg[a]++
		deg[b]++
	}

	for i = 1; i <= n; i++ {
		if 1 == deg[i] {
			d1++
			continue
		}
		if 2 == deg[i] {
			d2++
			continue
		}
		dsok++
	}

	switch {
	case n == d2:
		fmt.Println("ring topology")
	case n-2 == d2 && d1 == 2:
		fmt.Println("bus topology")
	case 1 == dsok && d1 == n-1:
		fmt.Println("star topology")
	case 1 == 1:
		fmt.Println("unknown topology")
	}

}

// 292B-mic
package main

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

func main() {
    var n, m, x, y, l, r int
    var a [100005]int
    z := bufio.NewReader(os.Stdin)
    fmt.Scan(&n, &m)
    for i := 1; i <= m; i++ {
        fmt.Fscan(z, &x, &y)
        a[x]++
        a[y]++
    }
    for i := 1; i <= n; i++ {
        if a[i] == 1 {
            l++
        } else if a[i] == 2 {
            r++
        } else {
            break
        }
    }
    if l == 2 && r == n-2 {
        fmt.Println("bus topology")
    } else {
        if r == n {
            fmt.Println("ring topology")
        } else {
            l = 0
            r = 0
            for i := 1; i <= n; i++ {
                if a[i] == 1 {
                    l++
                } else if a[i] == n-1 {
                    r++
                } else {
                    break
                }
            }
            if l == n-1 && r == 1 {
                fmt.Println("star topology")
            } else {
                fmt.Println("unknown topology")
            }
        }
    }
    return
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, m int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	var x, y int
	a := make([]int, 100001)
	for i:=0; i<m; i++ {
		r.Scan()
		x, _ = strconv.Atoi(r.Text())
		r.Scan()
		y, _ = strconv.Atoi(r.Text())
		a[x] += 1
		a[y] += 1
	}
	bt, rt, st, c := 0, 0, 0, 0
	for i:=1; i<=n; i++ {
		if a[i] == n-1 && c == 0 {
			st += 1
			c += 1
		} else if a[i] == 1 {
			st += 1
		}
		if a[i] == 2 {
			rt += 1
		}
	}
	if st == n {
		w.WriteString("star topology\n")
		w.Flush()
		return
	}
	if rt == n {
		w.WriteString("ring topology\n")
		w.Flush()
		return
	}
	c = 0
	for i:=1; i<=n; i++ {
		if a[i] == 1 && c <= 2 {
			bt += 1
			c += 1
		} else if a[i] == 2 {
			bt += 1
		}
	}
	if bt == n {
		w.WriteString("bus topology\n")
		w.Flush()
		return
	}
	w.WriteString("unknown topology\n")
	w.Flush()
}

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

func main() {
	var n,m,x,y int
	var v,c [100100]int
	input:=bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m)
	for i:=0;i<m;i++ {
		input.Scan()
		aa,_:=strconv.Atoi(input.Text())
		x=aa
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		y=bb
		v[x]++
		v[y]++
	}
	for i:=1;i<=n;i++ {
		c[v[i]]++
	}
	if c[1]==2 && c[2]==n-2 {
		fmt.Println("bus topology")
	} else if c[1]==n-1 && c[n-1]==1 {
		fmt.Println("star topology")
	} else if c[2]==n {
		fmt.Println("ring topology")
	} else {
		fmt.Println("unknown topology")
	}
}

// http://codeforces.com/problemset/problem/292/B
// B. Network Topology
// eleg a deg? az osszefuggoseg miatt

package main

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

func main() {
	var (
		i, m, n, a, b, d1, d2, dsok int32
		deg                         []int32
		in                          *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	Readint := func() (ret int32) {
		var c byte
		for {
			c, _ = in.ReadByte()
			if c >= '0' && c <= '9' {
				break
			}
		}
		for {
			ret = 10*ret + int32(c-'0')
			c, _ = in.ReadByte()
			if !(c >= '0' && c <= '9') {
				break
			}
		}
		return
	}

	n = Readint()
	m = Readint()
	//	fmt.Println(n, m)
	deg = make([]int32, n+1, n+1)

	for i = 0; i < m; i++ {
		a = Readint()
		b = Readint()

		//fmt.Println(a, b)

		deg[a]++
		deg[b]++
	}

	for i = 1; i <= n; i++ {
		if 1 == deg[i] {
			d1++
			continue
		}
		if 2 == deg[i] {
			d2++
			continue
		}
		dsok++
	}

	switch {
	case n == d2:
		fmt.Println("ring topology")
	case n-2 == d2 && d1 == 2:
		fmt.Println("bus topology")
	case 1 == dsok && d1 == n-1:
		fmt.Println("star topology")
	case 1 == 1:
		fmt.Println("unknown topology")
	}

}

package main

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

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,x,y int
    ScanInts(&n,&m)
    e, cnt := make([]int,n+1), make(map[int]int)
    for i := 0; i < m; i++ {
        ScanInts(&x,&y)
        cnt[e[x]]--; e[x]++; cnt[e[x]]++;
        cnt[e[y]]--; e[y]++; cnt[e[y]]++;
    }
    if (cnt[1] == 2) && (cnt[2] == n-2) {
        fmt.Println("bus topology")
    } else if (cnt[2] == n) {
        fmt.Println("ring topology")
    } else if (cnt[1] == n-1) && (cnt[n-1] == 1) {
        fmt.Println("star topology")
    } else {
        fmt.Println("unknown topology")
    }
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	cnt := make(map[int]int, 0)
	for _, adj := range g {
		cnt[len(adj)]++
	}
	if len(cnt) == 2 && cnt[1] == 2 && cnt[2] == n - 2 {
		fmt.Println("bus topology")
		return
	}
	if len(cnt) == 1 && cnt[2] == n {
		fmt.Println("ring topology")
		return
	}
	if len(cnt) == 2 && cnt[1] == n - 1 && cnt[n-1] == 1 {
		fmt.Println("star topology")
		return
	}
	fmt.Println("unknown topology")
}

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

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

// 292B

package main

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

var (
	a, b, m, n, x1, x2, ans int32
	deg                     []int32
	in                      = bufio.NewReader(os.Stdin)
)

func main() {
	read := func() (x int32) {
		var c byte
		for {
			c, _ = in.ReadByte()
			if c >= '0' && c <= '9' {
				break
			}
		}
		for {
			x = 10*x + int32(c-'0')
			c, _ = in.ReadByte()
			if !(c >= '0' && c <= '9') {
				break
			}
		}
		return
	}

	n = read()
	m = read()
	//	fmt.Println(n, m)
	deg = make([]int32, n+1, n+1)

	for i := int32(0); i < m; i++ {
		a = read()
		b = read()

		//fmt.Println(a, b)

		deg[a]++
		deg[b]++
	}

	for i := int32(1); i <= n; i++ {
		if 1 == deg[i] {
			x1++
			continue
		}
		if 2 == deg[i] {
			x2++
			continue
		}
		ans++
	}

	if n == x2 {
		fmt.Println("ring topology")
		return
	}
	if n-2 == x2 && x1 == 2 {
		fmt.Println("bus topology")
		return
	}
	if 1 == ans && x1 == n-1 {
		fmt.Println("star topology")
		return
	}
	if 1 == 1 {
		fmt.Println("unknown topology")
		return
	}
}

// 292B

package main

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

var (
	a, b, m, n, x1, x2, ans int32
	deg                     []int32
	in                      = bufio.NewReader(os.Stdin)
)

func main() {
	read := func() (x int32) {
		var c byte
		for {
			c, _ = in.ReadByte()
			if c >= '0' && c <= '9' {
				break
			}
		}
		for {
			x = 10*x + int32(c-'0')
			c, _ = in.ReadByte()
			if !(c >= '0' && c <= '9') {
				break
			}
		}
		return
	}

	n = read()
	m = read()
	//	fmt.Println(n, m)
	deg = make([]int32, n+1, n+1)

	for i := int32(0); i < m; i++ {
		a = read()
		b = read()

		//fmt.Println(a, b)

		deg[a]++
		deg[b]++
	}

	for i := int32(1); i <= n; i++ {
		if 1 == deg[i] {
			x1++
			continue
		}
		if 2 == deg[i] {
			x2++
			continue
		}
		ans++
	}

	if n == x2 {
		fmt.Println("ring topology")
	}
	if n-2 == x2 && x1 == 2 {
		fmt.Println("bus topology")
	}
	if 1 == ans && x1 == n-1 {
		fmt.Println("star topology")
	}
	if 1 == 1 {
		fmt.Println("unknown topology")
	}
}


package main

import "fmt"

func main(){
	var tot,i int
	var n,s,t,st,nst int
	var res int
	fmt.Scanf("%d\n", &tot)
	for i = 0; i < tot; i++ {
		fmt.Scanf("%d %d %d\n",&n,&s,&t)
		st = s + t - n
		if st < 0 {
			st = 0
		}
		s = s - st
		t = t - st
		nst = n - s - t - st;
		if s > t {
			res = nst + s + 1
		} else {
			res = nst + t + 1
		}
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"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()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		s := readi()
		t := readi()
		println(max(n-s, n-t) + 1)
	}
}

package main

import (
	"fmt"
)
func min(a, b int64) int64 {
    if a < b {
        return a
    } else {
        return b
    }
}

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    } else if s == n || k == n {
	        fmt.Println(n - min(s,k) + 1)
	        continue
	    }
        sum = n - min(s,k)
	    fmt.Println(sum+1)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n, x, y int
		fmt.Scan(&n)
		fmt.Scan(&x)
		fmt.Scan(&y)
		result := max(n-x, n-y) + 1
		fmt.Println(result)
		t--
	}
}

func max(x int, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	defer write.Flush()
	var q int
	fmt.Fscan(read, &q)
	for i := 0; i < q; i++ {
		var n, s, t int
		fmt.Fscan(read, &n, &s, &t)
		var r = n + 1
		if s > t {
			r = r - t
		} else {
			r = r - s
		}
		fmt.Fprintln(write, r)
	}
}

package main

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

func main() {
	// var a, b string
	var cnt, n, s, t, d int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &d)
	for i := 0; i < d; i++ {
		fmt.Fscanln(scr, &n, &s, &t)

		if n == s && n == t {
			cnt = 1
		} else if s <= t {
			cnt = (n - s) + 1
		} else if t < s {
			cnt = (n - t) + 1
		}

		fmt.Println(cnt)
	}
}

package main

import "fmt"

func main() {
	var cnt, n, s, t int
	fmt.Scan(&cnt)
	for ; cnt > 0; cnt-- {
		fmt.Scan(&n, &s, &t)
		if s < t {
			t = s
		}
		fmt.Println(n - t + 1)
	}
}

package main

import "fmt"

func main() {
	var countIter int
	var answer = []int{}
	fmt.Scan(&countIter)
	for (countIter) != 0 {
		answer = append(answer, checkEggs())
		countIter--
	}

	for _, element := range answer {
		fmt.Println(element)
	}
}

func checkEggs() int {
	var eggs int
	var stickers int
	var toys int

	fmt.Scan(&eggs, &stickers, &toys)

	if eggs - stickers > eggs - toys {
		return(eggs-stickers + 1)
	} else {
		return(eggs-toys + 1)
	}
}

package main

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

func main() {
	// var a, b string
	var cnt, n, s, t, d int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &d)
	for i := 0; i < d; i++ {
		fmt.Fscanln(scr, &n, &s, &t)

		if n == s && n == t {
			cnt = 1
		} else if s <= t {
			cnt = s + 1
		} else if t < s {
			cnt = t + 1
		}

		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
)
func min(a, b int64) int64 {
    if a < b {
        return a
    } else {
        return b
    }
}

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    } else if s+k == n {
	        fmt.Println(n)
	        continue
	    }
	    sum = min(s,k)
	    sum = sum + 1

	    fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s || n == k {
	        fmt.Println(1)
	        continue
	    }

	    if s+k == n {
	        fmt.Println(n)
	        continue
	    } else {
	        if s < k {
	            sum = s
	        } else {
	            sum = k
	        }
	        sum = sum + 1
	    }

	    fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    }
	    if s < k {
	        sum = s
	    } else {
	        sum = k
	    }
	    if sum != n {
	        sum = sum + 1
	    }
	    fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    }

	    if s+k == n {
	        fmt.Println(n)
	        continue
	    } else if s+k > n {
	        if s < k {
	            sum = s
	        } else {
	            sum = k
	        }
	        if sum != n {
	            sum = sum + 1
	        }
	    } else {
	        if s > k {
	            sum = s
	        } else {
	            sum = k
	        }
	        if sum != n {
	            sum = sum + 1
	        }
	    }

	    fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)
func min(a, b int64) int64 {
    if a < b {
        return a
    } else {
        return b
    }
}

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

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    } else if s+k == n {
	        fmt.Println(n)
	        continue
	    } else if s == n || k == n {
	        fmt.Println(n - min(s,k) + 1)
	        continue
	    }
	    min := min(s,k)
	    max := max(s,k)
	    sum = max - (min-(n-max))
	    fmt.Println(sum+1)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, s, k, i, sum int64
	fmt.Scan(&t)
	for i = 0; i < t; i++ {
	    fmt.Scan(&n, &s, &k)
	    if n == s && n == k {
	        fmt.Println(1)
	        continue
	    } else if n == s || n == k {
	        fmt.Println(n)
	        continue
	    }

	    if s+k == n {
	        fmt.Println(n)
	        continue
	    } else {
	        if s < k {
	            sum = s
	        } else {
	            sum = k
	        }
	        sum = sum + 1
	    }

	    fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for t+1 > 0 {
		var n, x, y int
		fmt.Scan(&n)
		result := max(n-x, n-y) + 1
		fmt.Println(result)
		t--
	}
}

func max(x int, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}


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"
)

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 (
	"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 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 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)
	}
}


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