package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
	var ans, fst int = 0, 0
	var neg bool = false
	sc.Scan()
	if sc.Bytes()[0] == minus {
		fst = 1
		neg = true
	}
	for _, j := range sc.Bytes()[fst:] {
		ans = ans*10 + int(j-zero)
	}
	if neg == true {
		ans = -ans
	}
	return ans
}

func nextByte() byte {
	sc.Scan()
	return sc.Bytes()[0]
}

var n, m, k int
var t [1000][1000]int
var r, c [1000]int

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	split := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		advance, token, err = bufio.ScanWords(data, atEOF)
		return
	}
	sc.Split(split)

	var n, m, k int = nextInt(), nextInt(), nextInt()
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			t[i][j] = nextInt()
		}
	}
	for i := 0; i < n; i++ {
		r[i] = i
	}
	for j := 0; j < m; j++ {
		c[j] = j
	}
	var x, y int
	var s byte
	const cr, cc byte = 'r', 'c'
	for i := 0; i < k; i++ {
		s = nextByte()
		x, y = nextInt(), nextInt()
		x -= 1
		y -= 1
		switch s {
		case cc:
			c[x], c[y] = c[y], c[x]
		case cr:
			r[x], r[y] = r[y], r[x]
		default:
			{
				w.WriteString(strconv.Itoa(t[r[x]][c[y]]))
				w.WriteString("\n")
			}
		}
	}
	w.Flush()
}

package main

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

var rw *bufio.ReadWriter = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))

func skipblanks() {
  for {
    c, _ := rw.ReadByte()
    switch c {
    case ' ', '\r', '\n':
    default:
      rw.UnreadByte()
      return
    }
  }
}

func next() string {
  skipblanks()
  token := []byte{}
  for {
    c, err := rw.ReadByte()
    if err != nil || c == ' ' || c == '\n' {
      return string(token)
    } else if c == '\r' {
      _, _ = rw.ReadByte()
      return string(token)
    } else {
      token = append(token, c)
    }
  }
}

func ni() int {
  ans, _ := strconv.Atoi(next())
  return ans
}

func nb() byte {
  c, _ := rw.ReadByte()
  return c
}

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

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { rw.WriteString(strconv.Itoa(n)) }
func prll(n int64) { rw.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { rw.WriteByte(' ') }
func endl()        { rw.WriteByte('\n') }

func main() {

  n, m, k := ni(), ni(), ni()
  r, c, t := make([]int, n), make([]int, m), make([][]int, n)
  for i := 0; i < n; i++ {
    t[i] = make([]int, m)
    for j := 0; j < m; j++ {
      t[i][j] = ni()
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  var s byte
  const cr, cc byte = 'r', 'c'
  for i := 0; i < k; i++ {
    s, x, y = nb(), ni()-1, ni()-1
    switch s {
    case cc:
      c[x], c[y] = c[y], c[x]
    case cr:
      r[x], r[y] = r[y], r[x]
    default:
      {
        pri(t[r[x]][c[y]])
        endl()
      }
    }
  }
  rw.Flush()
}

package main

import (
        "os"
        "bufio"
        "strconv"
        "text/scanner"
)

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var sc scanner.Scanner

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  sc.Init(rw)
  sc.Scan()
  n, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  m, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  k, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(sc.TokenText())
      sc.Scan()
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  var s string
  for i := 0; i < k; i++ {
    s = sc.TokenText()
    sc.Scan()
    x, _ = strconv.Atoi(sc.TokenText())
    sc.Scan()
    y, _ = strconv.Atoi(sc.TokenText())
    if i < k - 1 {
      sc.Scan()
    }
    x -= 1
    y -= 1
    switch s {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: { rw.WriteString(strconv.Itoa(t[r[x]][c[y]])); rw.WriteString("\n"); }
    }
  }
  rw.Flush()
}

package main

import (
        "os"
        "bufio"
        "strconv"
        "text/scanner"
)

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var sc scanner.Scanner

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  sc.Init(rw)
  sc.Mode = scanner.ScanStrings | scanner.ScanInts
  sc.Whitespace = 1 << '\n' | 1 << '\r' | 1 << ' '
  sc.Scan()
  n, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  m, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  k, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(sc.TokenText())
      sc.Scan()
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  var s string
  for i := 0; i < k; i++ {
    s = sc.TokenText()
    sc.Scan()
    x, _ = strconv.Atoi(sc.TokenText())
    sc.Scan()
    y, _ = strconv.Atoi(sc.TokenText())
    if i < k - 1 {
      sc.Scan()
    }
    x -= 1
    y -= 1
    switch s {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: { rw.WriteString(strconv.Itoa(t[r[x]][c[y]])); rw.WriteString("\n"); }
    }
  }
  rw.Flush()
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
    var ans, fst int = 0, 0
    var neg bool = false
    sc.Scan()
    if sc.Bytes()[0] == minus {
        fst = 1
        neg = true
    }
    for _, j := range sc.Bytes()[fst:] {
        ans = ans*10 + int(j-zero)
    }
    if neg == true {
        ans = -ans
    }
    return ans
}

func nextByte() byte {
    sc.Scan()
    return sc.Bytes()[0]
}

var n, m, k int
var t [1000][1000]int
var r, c [1000]int

func main() {

    w = bufio.NewWriter(os.Stdout)
    sc = bufio.NewScanner(os.Stdin)
    sc.Split(bufio.ScanWords)

    var n, m, k int = nextInt(), nextInt(), nextInt()
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            t[i][j] = nextInt()
        }
    }
    for i := 0; i < n; i++ {
        r[i] = i
    }
    for j := 0; j < m; j++ {
        c[j] = j
    }
    var x, y int
    var s byte
    const cr, cc byte = 'r', 'c'
    for i := 0; i < k; i++ {
        s, x, y = nextByte(), nextInt() - 1, nextInt() - 1
        switch s {
        case cc:
            c[x], c[y] = c[y], c[x]
        case cr:
            r[x], r[y] = r[y], r[x]
        default:
            {
                w.WriteString(strconv.Itoa(t[r[x]][c[y]]))
                w.WriteByte('\n')
            }
        }
    }
    w.Flush()
}

package main

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

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  nmk, _ := rw.ReadString('\n')
  cc := strings.Fields(nmk)
  n, _ = strconv.Atoi(cc[0])
  m, _ = strconv.Atoi(cc[1])
  k, _ = strconv.Atoi(cc[2])
  for i := 0; i < n; i++ {
    text, _ := rw.ReadString('\n')
    a := strings.Fields(text)
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(a[j])
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  for i := 0; i < k; i++ {
    text, _ := rw.ReadString('\n')
    a := strings.Fields(text)
    x, _ = strconv.Atoi(a[1])
    y, _ = strconv.Atoi(a[2])
    x -= 1
    y -= 1
    switch a[0] {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: { rw.WriteString(strconv.Itoa(t[r[x]][c[y]])); rw.WriteString("\n"); }
    }
  }
  rw.Flush()
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
    var ans, fst int = 0, 0
    var neg bool = false
    sc.Scan()
    if sc.Bytes()[0] == minus {
        fst = 1
        neg = true
    }
    for _, j := range sc.Bytes()[fst:] {
        ans = ans*10 + int(j-zero)
    }
    if neg == true {
        ans = -ans
    }
    return ans
}

func nextByte() byte {
    sc.Scan()
    return sc.Bytes()[0]
}

var n, m, k int
var t [1000][1000]int
var r, c [1000]int

func main() {

    w = bufio.NewWriter(os.Stdout)
    sc = bufio.NewScanner(os.Stdin)
    sc.Split(bufio.ScanWords)

    var n, m, k int = nextInt(), nextInt(), nextInt()
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            t[i][j] = nextInt()
        }
    }
    for i := 0; i < n; i++ {
        r[i] = i
    }
    for j := 0; j < m; j++ {
        c[j] = j
    }
    var x, y int
    var s byte
    const cr, cc byte = 'r', 'c'
    for i := 0; i < k; i++ {
        s = nextByte()
        x, y = nextInt(), nextInt()
        x -= 1
        y -= 1
        switch s {
        case cc:
            c[x], c[y] = c[y], c[x]
        case cr:
            r[x], r[y] = r[y], r[x]
        default:
            {
                w.WriteString(strconv.Itoa(t[r[x]][c[y]]))
                w.WriteString("\n")
            }
        }
    }
    w.Flush()
}

package main

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

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  fmt.Fscan(rw, &n, &m, &k)
  rw.ReadString('\n')
  for i := 0; i < n; i++ {
    text, _ := rw.ReadString('\n')
    a := strings.Fields(text)
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(a[j])
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  var s string
  for i := 0; i < k; i++ {
    fmt.Fscan(rw, &s, &x, &y)
    x -= 1
    y -= 1
    switch s {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: fmt.Fprintln(rw, t[r[x]][c[y]])
    }
  }
  rw.Flush()
  //???
}

package main

import (
        "os"
        "bufio"
        "strconv"
        "text/scanner"
)

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var sc scanner.Scanner

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  sc.Init(rw)
  sc.Scan()
  n, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  m, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  k, _ = strconv.Atoi(sc.TokenText())
  sc.Scan()
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(sc.TokenText())
      sc.Scan()
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  var s string
  for i := 0; i < k; i++ {
    s = sc.TokenText()
    sc.Scan()
    x, _ = strconv.Atoi(sc.TokenText())
    sc.Scan()
    y, _ = strconv.Atoi(sc.TokenText())
    if i < k - 1 {
      sc.Scan()
    }
    x -= 1
    y -= 1
    switch s {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: rw.WriteString(strconv.Itoa(t[r[x]][c[y]]) + "\n")
    }
  }
  rw.Flush()
}

package main

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

var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin),
                             bufio.NewWriter(os.Stdout));

var n, m, k int;
var t [1000][1000]int;
var r, c [1000]int;

func main () {
  fmt.Fscan(rw, &n, &m, &k)
  rw.ReadString('\n')
  for i := 0; i < n; i++ {
    text, _ := rw.ReadString('\n')
    a := strings.Fields(text)
    for j := 0; j < m; j++ {
      t[i][j], _ = strconv.Atoi(a[j])
    }
  }
  for i := 0; i < n; i++ {
    r[i] = i
  }
  for j := 0; j < m; j++ {
    c[j] = j
  }
  var x, y int
  for i := 0; i < k; i++ {
    text, _ := rw.ReadString('\n')
    a := strings.Fields(text)
    x, _ = strconv.Atoi(a[1])
    y, _ = strconv.Atoi(a[2])
    x -= 1
    y -= 1
    switch a[0] {
    case "c": c[x], c[y] = c[y], c[x]
    case "r": r[x], r[y] = r[y], r[x]
    default: fmt.Fprint(rw, t[r[x]][c[y]], "\n")
    }
  }
  rw.Flush()
}

package main

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

func main () {
	var rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))
	var n, m, k int
	var t [1000][1000]int
	var r, c [1000]int
	fmt.Fscan(rw, &n, &m, &k)
	rw.ReadString('\n')
	for i := 0; i < n; i++ {
		text, _ := rw.ReadString('\n')
		a := strings.Fields(text)
		for j := 0; j < m; j++ {
			t[i][j], _ = strconv.Atoi(a[j])
		}
	}
	for i := 0; i < n; i++ {
	   	r[i] = i
	}
	for j := 0; j < m; j++ {
		c[j] = j
	}
	var x, y int
	var s string
	for i := 0; i < k; i++ {
		fmt.Fscan(rw, &s, &x, &y)
		x -= 1
		y -= 1
		switch s {
		case "c": c[x], c[y] = c[y], c[x]
		case "r": r[x], r[y] = r[y], r[x]
		default: fmt.Fprintln(rw, t[r[x]][c[y]])
		}
	}
  rw.Flush()
}

package main

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

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

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

    var row,col [1005]int
    var a [1005][1005]int
    n := ScanInt(); m := ScanInt(); k := ScanInt();
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a[i][j] = ScanInt()
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        scanner.Scan()
        c := scanner.Text()
        x := ScanInt()-1
        y := ScanInt()-1
        if c[0] == 'c' {
            col[x], col[y] = col[y], col[x]
        } else if c[0] == 'r' {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
    fmt.Fscan(reader,&n,&m,&k)
    reader.ReadString('\n')
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Fscan(reader,&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        fmt.Fscan(reader,&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,k int
    var a [1005][1005]int
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            scanner.Scan()
            a[i][j], _ = strconv.Atoi(scanner.Text())
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        scanner.Scan()
        c := scanner.Text()
        scanner.Scan()
        x, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        y, _ := strconv.Atoi(scanner.Text())
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

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

    var x,y int
    var c string
    var a [1005][1005]int
    n := ScanInt(); m := ScanInt(); k := ScanInt();
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a[i][j] = ScanInt()
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        fmt.Fscan(reader,&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,k int
    var a [1005][1005]int
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            for scanner.Scan() { if scanner.Text() != "" { break } }
            a[i][j], _ = strconv.Atoi(scanner.Text())
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        for scanner.Scan() { if scanner.Text() != "" { break } }
        c := scanner.Text()
        for scanner.Scan() { if scanner.Text() != "" { break } }
        x, _ := strconv.Atoi(scanner.Text())
        for scanner.Scan() { if scanner.Text() != "" { break } }
        y, _ := strconv.Atoi(scanner.Text())
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
    fmt.Fscan(reader,&n,&m,&k)
    reader.ReadLine()
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Fscan(reader,&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        fmt.Fscan(reader,&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
//    fmt.Fscan(reader,&n,&m,&k)
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
//            fmt.Fscan(reader,&a[i][j])
            fmt.Scan(&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
//        fmt.Fscan(reader,&c,&x,&y)
        fmt.Scan(&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
//            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
            ans := strconv.Itoa(a[row[x]][col[y]])
            fmt.Println(ans)
        }
    }
//    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
//    fmt.Fscan(reader,&n,&m,&k)
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
//            fmt.Fscan(reader,&a[i][j])
            fmt.Scan(&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
//        fmt.Fscan(reader,&c,&x,&y)
        fmt.Scan(&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
//            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
            fmt.Println(strconv.Itoa(a[row[x]][col[y]]))
        }
    }
//    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,k int
    var a [1005][1005]int
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            scanner.Scan()
            a[i][j], _ = strconv.Atoi(scanner.Text())
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        for scanner.Scan() { if scanner.Text() != "" { break } }
        c := scanner.Text()
        scanner.Scan()
        x, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        y, _ := strconv.Atoi(scanner.Text())
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
    fmt.Fscan(reader,&n,&m,&k)
    reader.ReadString('\n')
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Fscan(reader,&a[i][j])
        }
        reader.ReadString('\n')
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        fmt.Fscan(reader,&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
        reader.ReadString('\n')
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,k int
    var a [1005][1005]int
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            scanner.Scan()
            a[i][j], _ = strconv.Atoi(scanner.Text())
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        for scanner.Scan() { if (scanner.Text() == "c") || (scanner.Text() == "r") || (scanner.Text() == "g") { break } }
        c := scanner.Text()
        scanner.Scan()
        x, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        y, _ := strconv.Atoi(scanner.Text())
        fmt.Println(c,x,y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
    fmt.Fscan(reader,&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Fscan(reader,&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        fmt.Fscan(reader,&c,&x,&y)
        x--; y--;
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}

package main

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

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

    var n,m,k,x,y int
    var c string
    var a [1005][1005]int
//    fmt.Fscan(reader,&n,&m,&k)
    fmt.Scan(&n,&m,&k)
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
//            fmt.Fscan(reader,&a[i][j])
            fmt.Scan(&a[i][j])
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
//        fmt.Fscan(reader,&c,&x,&y)
        fmt.Scan(&c,&x,&y)
        x--; y--;
        if c[0] == 'c' {
            col[x], col[y] = col[y], col[x]
        } else if c[0] == 'r' {
            row[x], row[y] = row[y], row[x]
        } else {
//            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
            fmt.Println(strconv.Itoa(a[row[x]][col[y]]))
        }
    }
//    writer.Flush()
}

package main

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

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

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

    var a [1005][1005]int
    n := ScanInt(); m := ScanInt(); k := ScanInt();
    row, col := make(map[int]int), make(map[int]int)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a[i][j] = ScanInt()
        }
    }
    for i := 0; i < n; i++ { row[i] = i }
    for i := 0; i < m; i++ { col[i] = i }
    for ; k > 0; k-- {
        for scanner.Scan() { if (scanner.Text() == "c") || (scanner.Text() == "r") || (scanner.Text() == "g") { break } }
        c := scanner.Text()
        x := ScanInt()-1
        y := ScanInt()-1
        if c == "c" {
            col[x], col[y] = col[y], col[x]
        } else if c == "r" {
            row[x], row[y] = row[y], row[x]
        } else {
            writer.WriteString(strconv.Itoa(a[row[x]][col[y]])+"\n")
        }
    }
    writer.Flush()
}


package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    var s string
    fmt.Fscan(reader,&s)
    pivot, left, right, temp := 0, int64(0), int64(0), int64(0)
    for _, v := range s {
        if v == '^' { break }
        if s[pivot] != '=' { temp += int64(s[pivot]-'0') }
        left += temp
        pivot++
    }
    for i := pivot+1; i < len(s); i++ {
        if s[i] != '=' {
            right += int64(s[i]-'0')*int64(i-pivot)
        }
    }
    if left == right {
        fmt.Println("balance")
    } else if left > right {
        fmt.Println("left")
    } else {
        fmt.Println("right")
    }
}

package main

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

func main() {
	fin := bufio.NewReader(os.Stdin)
	s := ""
	fmt.Fscanf(fin, "%s", &s)
	pivot := strings.IndexByte(s, '^')
	bal := int64(0)
	for i, x := range s {
		if x >= '0' && x <= '9' {
			bal += int64(pivot-i) * int64(x-'0')
		}
	}
	switch {
	case bal > 0:
		fmt.Println("left")
	case bal < 0:
		fmt.Println("right")
	default:
		fmt.Println("balance")
	}
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1000005)
	s, _ := reader.ReadString('\n')
	pivot := strings.IndexByte(s, '^')
	bal := int64(0)
	for i, x := range s {
		if x >= '0' && x <= '9' {
			bal += int64(pivot-i) * int64(x-'0')
		}
	}
	switch {
	case bal > 0:
		fmt.Println("left")
	case bal < 0:
		fmt.Println("right")
	default:
		fmt.Println("balance")
	}
}

package main

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

func main() {
	fin := bufio.NewReader(os.Stdin)
	var s string
	fmt.Fscanf(fin, "%s", &s)

	p := strings.Index(s, "^")
	var l, r int64
	for i := 0; i < p; i++ {
		if s[i] != '=' {
			l += int64(p-i) * int64(s[i]-'0')
		}
	}
	for i := p + 1; i < len(s); i++ {
		if s[i] != '=' {
			r += int64(i-p) * int64(s[i]-'0')
		}
	}

	switch {
	case l == r:
		fmt.Print("balance")
	case l > r:
		fmt.Print("left")
	case r > l:
		fmt.Print("right")
	}
}

// 376A-mic
package main

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

func main() {
    k := bufio.NewReader(os.Stdin)
    var s string
    var left, right, p, i int64
    fmt.Fscan(k, &s)
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '^' {
            p = i
            break
        }
    }
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '=' {
            continue
        } else if i > p {
            right += (int64(s[i]) - 48) * (i - p)
        } else {
            left += (int64(s[i]) - 48) * (p - i)
        }
    }
    if right == left {
        fmt.Println("balance")
    } else if right > left {
        fmt.Println("right")
    } else {
        fmt.Println("left")
    }

}

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

func main() {
	var m string
	var n,s int
	s=0
	fmt.Scan(&m)
	for j,ss:=range m {
		if ss=='^' {
			n=j
		}
	}
	//fmt.Println(n)
	for i,mm:=range m {
		if (mm-'0')>=0 && (mm-'0')<=9{
			//fmt.Println("masuk",i)
			s+=(i-n)*int(mm-'0')
			//fmt.Println(s)
		}
	}
	//fmt.Println(s)
	if  s>0{
		fmt.Println("right")
	} else if s<0{
		fmt.Println("left")
	} else {
		fmt.Println("balance")
	}
}

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

func main() {
	var s string
	var n int
	j:=0
	fmt.Scan(&s)
	for i,ss:=range s {
		if ss=='^' {
			n=i
		}
	}
	for i:=0;i<n;i++ {
		if (s[i]-'0')>=0 && (s[i]-'0')<=9{
			j+=(i-n)*int(s[i]-'0')
		}
	}
	if  j>0{
		fmt.Println("right")
	} else if j<0{
		fmt.Println("left")
	} else {
		fmt.Println("balance")
	}
}

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

func main() {
	var s string
	var m,t int64
	input:= bufio.NewScanner(os.Stdin)
	input.Scan()
	s=input.Text()
	for tt,mm:=range s {
		if mm=='^' {
			t=int64(tt)
		}
	}
	for j,ss:=range s {
		if ss>='1' && ss<='9' {
			m+=((t-int64(j))*int64(s[j]-48))
		}
	}
	if  m>0{
		fmt.Println("left")
	} else if m<0{
		fmt.Println("right")
	} else  if m==0{
		fmt.Println("balance")
	}
}

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

func main() {
	var m string
	var n,s int
	s=0
	fmt.Scan(&m)
	for j,ss:=range m {
		if ss=='^' {
			n=j
		}
	}
	fmt.Println(n)
	for i,mm:=range m {
		if (mm-'0')>=0 && (mm-'0')<=9{
			//fmt.Println("masuk",i)
			s+=(i-n)*int(mm-'0')
			//fmt.Println(s)
		}
	}
	//fmt.Println(s)
	if  s>0{
		fmt.Println("right")
	} else if s<0{
		fmt.Println("left")
	} else {
		fmt.Println("balance")
	}
}

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

func main() {
	var m string
	var n,s int
	s=0
	input:= bufio.NewScanner(os.Stdin)
	input.Scan()
	m=input.Text()
	for j,ss:=range m {
		if ss=='^' {
			n=j
		}
	}
	//fmt.Println(n)
	for i,mm:=range m {
		if (mm-'0')>=0 && (mm-'0')<=9{
			//fmt.Println("masuk",i)
			s+=(i-n)*int(mm-'0')
			//fmt.Println(s)
		}
	}
	//fmt.Println(s)
	if  s>0{
		fmt.Println("right")
	} else if s<0{
		fmt.Println("left")
	} else {
		fmt.Println("balance")
	}
}

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

func main() {
	var m string
	var n,s int64
	s=0
	input:= bufio.NewScanner(os.Stdin)
	input.Scan()
	m=input.Text()
	for j,ss:=range m {
		if ss=='^' {
			n=int64(j)
		}
	}
	//fmt.Println(n)
	for i,mm:=range m {
		if (mm-'0')>=0 && (mm-'0')<=9{
			//fmt.Println("masuk",i)
			s+=(int64(i)-n)*int64(mm-'0')
			//fmt.Println(s)
		}
	}
	//fmt.Println(s)
	if  s>0{
		fmt.Println("right")
	} else if s<0{
		fmt.Println("left")
	} else {
		fmt.Println("balance")
	}
}

package main

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

func main() {
    var s []byte
    s, _ = ioutil.ReadAll(os.Stdin)
    pivot, left, right, temp := 0, int64(0), int64(0), int64(0)
    for _, v := range s {
        if v == '^' { break }
        if s[pivot] != '=' { temp += int64(s[pivot]-'0') }
        left += temp
        pivot++
    }
    for i := pivot+1; s[i] != '\n'; i++ {
        if s[i] != '=' {
            right += int64(s[i]-'0')*int64(i-pivot)
        }
    }
    if left == right {
        fmt.Println("balance")
    } else if left > right {
        fmt.Println("left")
    } else {
        fmt.Println("right")
    }
}

package main

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

func main() {
    var s []byte
    for len(s) == 0 {
        s, _ = ioutil.ReadAll(os.Stdin)
    }
    pivot, left, right, temp := 0, int64(0), int64(0), int64(0)
    for _, v := range s {
        if v == '^' { break }
        if s[pivot] != '=' { temp += int64(s[pivot]-'0') }
        left += temp
        pivot++
    }
    for i := pivot+1; s[i] != '\n'; i++ {
        if s[i] != '=' {
            right += int64(s[i]-'0')*int64(i-pivot)
        }
    }
    if left == right {
        fmt.Println("balance")
    } else if left > right {
        fmt.Println("left")
    } else {
        fmt.Println("right")
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanRunes)
    pivot, left, temp := 0, int64(0), int64(0)
    for scanner.Scan() {
        r := scanner.Bytes()[0]
        if r == '^' { break }
        if r != '=' { temp += int64(r-'0') }
        left += temp
        pivot++
    }
    right, i := int64(0), pivot+1
    for scanner.Scan() {
        r := scanner.Bytes()[0]
        if r == '\n' { break }
        if r != '=' {
            right += int64(r-'0')*int64(i-pivot)
        }
        i++
    }
    if left == right {
        fmt.Println("balance")
    } else if left > right {
        fmt.Println("left")
    } else {
        fmt.Println("right")
    }
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    s, _ := reader.ReadString('\n')
    pivot, left, right, temp := 0, int64(0), int64(0), int64(0)
    for s[pivot] != '^' {
        if s[pivot] != '=' { temp += int64(s[pivot]-'0') }
        left += temp
        pivot++
    }
    for i := pivot+1; s[i] != '\n'; i++ {
        if s[i] != '=' {
            right += int64(s[i]-'0')*int64(i-pivot)
        }
    }
    if left == right {
        fmt.Println("balance")
    } else if left > right {
        fmt.Println("left")
    } else {
        fmt.Println("right")
    }
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	pivot := strings.IndexByte(s, '^')
	bal := 0
	for i, x := range s {
		if x >= '0' && x <= '9' {
			bal += (pivot - i) * int(x-'0')
		}
	}
	switch {
	case bal > 0:
		fmt.Println("left")
	case bal < 0:
		fmt.Println("right")
	default:
		fmt.Println("balance")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	s := scanner.Text()
	pivot := strings.IndexByte(s, '^')
	bal := int64(0)
	for i, x := range s {
		if x >= '0' && x <= '9' {
			bal += int64(pivot-i) * int64(x-'0')
		}
	}
	switch {
	case bal > 0:
		fmt.Println("left")
	case bal < 0:
		fmt.Println("right")
	default:
		fmt.Println("balance")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	pivot := strings.IndexByte(s, '^')
	bal := int64(0)
	for i, x := range s {
		if x >= '0' && x <= '9' {
			bal += int64(pivot-i) * int64(x-'0')
		}
	}
	switch {
	case bal > 0:
		fmt.Println("left")
	case bal < 0:
		fmt.Println("right")
	default:
		fmt.Println("balance")
	}
}

// 376A-mic
package main

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

func main() {
	var s string
	var left, right, p, i int64
	for i = 0; i < int64(len(s)); i++ {
		if s[i] == '^' {
			p = i
			break
		}
	}
	for i = p - 1; i >= 0; i-- {
		if s[i] == '=' {
			continue
		}
		left += (int64(s[i]) - 48) * (p - i)
	}
	for i = p + 1; i < int64(len(s)); i++ {
		if s[i] == '=' {
			continue
		}
		right += (int64(s[i]) - 48) * (i - p)
	}
	if right == left {
		fmt.Println("balance")
	} else if right > left {
		fmt.Println("right")
	} else {
		fmt.Println("left")
	}

}

// 376A-mic
package main

import (
    "fmt"
)

func main() {
    var s string
    var left, right, p int
    fmt.Scan(&s)
    for i := 0; i < len(s); i++ {
        if s[i] == '^' {
            p = i
        }
    }
    for i := 0; i < p; i++ {
        if s[i] == '=' {
            continue
        }
        left += (int(s[i])) * (p - i)
    }
    for i := p + 1; i < len(s); i++ {
        if s[i] == '=' {
            continue
        }
        right += (int(s[i])) * (i - p)
    }
    if right == left {
        fmt.Println("balance")
    } else if right > left {
        fmt.Println("right")
    } else {
        fmt.Println("left")
    }

}

// 376A-mic
package main

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

func main() {
    k := bufio.NewScanner(os.Stdin)
    k.Split(bufio.ScanLines)
    var s string
    var left, right, p, i int64
    k.Scan()
    s = k.Text()
    //fmt.Scan(&s)
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '^' {
            p = i
            break
        }
    }
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '=' {
            continue
        } else if i > p {
            right += (int64(s[i]) - 48) * (i - p)
        } else {
            left += (int64(s[i]) - 48) * (p - i)
        }
    }
    if right == left {
        fmt.Println("balance")
    } else if right > left {
        fmt.Println("right")
    } else {
        fmt.Println("left")
    }

}

// 376A-mic
package main

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

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

	var s string
	var left, right, p, i int64
	k.Scan()
	s = k.Text()
	for i = 0; i < int64(len(s)); i++ {
		if s[i] == '^' {
			p = i
		}
	}
	for i = p - 1; i >= 0; i-- {
		if s[i] == '=' {
			continue
		}
		left += (int64(s[i]) - 48) * (p - i)
	}
	for i = p + 1; i < int64(len(s)); i++ {
		if s[i] == '=' {
			continue
		}
		right += (int64(s[i]) - 48) * (i - p)
	}
	if right == left {
		fmt.Println("balance")
	} else if right > left {
		fmt.Println("right")
	} else {
		fmt.Println("left")
	}

}

// 376A-mic
package main

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

func main() {
    k := bufio.NewScanner(os.Stdin)
    var s string
    var left, right, p, i int64
    k.Scan()
    s = k.Text()
    //fmt.Scan(&s)
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '^' {
            p = i
            break
        }
    }
    for i = 0; i < int64(len(s)); i++ {
        if s[i] == '=' {
            continue
        } else if i > p {
            right += (int64(s[i]) - 48) * (i - p)
        } else {
            left += (int64(s[i]) - 48) * (p - i)
        }
    }
    if right == left {
        fmt.Println("balance")
    } else if right > left {
        fmt.Println("right")
    } else {
        fmt.Println("left")
    }

}

// 376A-mic
package main

import (
    "fmt"
)

func main() {
    var s string
    var left, right, p int
    fmt.Scan(&s)
    for i := 0; i < len(s); i++ {
        if s[i] == '^' {
            p = i
        }
    }
    for i := 0; i < p; i++ {
        if s[i] == '=' {
            continue
        }
        left += (int(s[i]) - 48) * (p - i)
    }
    for i := p + 1; i < len(s); i++ {
        if s[i] == '=' {
            continue
        }
        right += (int(s[i]) - 48) * (i - p)
    }
    if right == left {
        fmt.Println("balance")
    } else if right > left {
        fmt.Println("right")
    } else {
        fmt.Println("left")
    }

}


package main

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

var R, C int
var data, next [][]int
var lcs []int

func matrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func sequenceStarting(start int) int {
	for cur := start; cur < C; cur++ {
		expectedNext := next[0][data[0][cur]]
		ok := true
		for i := 1; i < R && ok; i++ {
			if next[i][data[0][cur]] != expectedNext {
				ok = false
			}
		}

		if !ok {
			return cur
		}

	}

	return C - 1
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscan(stdin, &C, &R)
	data = matrix(R, C)
	next = matrix(R, C+1)

	for i := 0; i < R; i++ {
		for j := 0; j < C; j++ {
			fmt.Fscan(stdin, &data[i][j])
		}

		for j := 0; j < C-1; j++ {
			next[i][data[i][j]] = data[i][j+1]
		}
		next[i][data[i][C-1]] = -1
	}

	var total int64
	start := 0
	for start < C {
		end := sequenceStarting(start)
		l := int64(end - start + 1)
		total += l * (l + 1) / 2
		start = end + 1

	}

	fmt.Println(total)

}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := int64(readInt())
	m := readInt()
	if m == 1 {
		fmt.Println(n * (n + 1) / 2)
		return
	}

	a := make([][]int, m)
	posOf := make([][]int, m)
	for i := range a {
		a[i] = make([]int, n)
		posOf[i] = make([]int, n)
		for j := range a[i] {
			a[i][j] = readInt() - 1
			posOf[i][a[i][j]] = j
		}
	}

	ans := int64(0)
	for i := 0; i < int(n); {
		start := make([]int, m)
		for j := range start {
			start[j] = posOf[j][a[0][i]]
		}

		goodLen := 1
		for {
			good := true
			for j := range a {
				if start[j]+goodLen >= int(n) || a[j][start[j]+goodLen] != a[0][i+goodLen] {
					good = false
					break
				}
			}
			if !good {
				ans += int64(goodLen) * int64(goodLen + 1) / 2
				i += goodLen
				break
			}
			goodLen++
		}
	}
	fmt.Println(ans)
}

package main

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

var R, C int
var data, next [][]int
var lcs []int

func matrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func sequenceStarting(start int) int {
	for cur := start; cur < C; cur++ {
		expectedNext := next[0][data[0][cur]]
		ok := true
		for i := 1; i < R && ok; i++ {
			if next[i][data[0][cur]] != expectedNext {
				ok = false
			}
		}

		if !ok {
			return cur
		}

	}

	return C - 1
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscan(stdin, &C, &R)
	data = matrix(R, C)
	next = matrix(R, C+1)

	for i := 0; i < R; i++ {
		for j := 0; j < C; j++ {
			fmt.Fscan(stdin, &data[i][j])
		}

		for j := 0; j < C-1; j++ {
			next[i][data[i][j]] = data[i][j+1]
		}
		next[i][data[i][C-1]] = -1
	}

	total := 0
	start := 0
	for start < C {
		end := sequenceStarting(start)
		l := end - start + 1
		total += l * (l + 1) / 2
		start = end + 1

	}

	fmt.Println(total)

}


package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n, k int

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

	if k > n {
		fmt.Printf("NO")
		return
	}
	res := make([]int, 0, k)

	for i := uint(0); n != 0; i ++ {
		if (n % 2 == 1) {
			res = append(res, 1 << i)
		}
		n >>= 1
	}

	if k < len(res) {
		fmt.Printf("NO")
		return
	}

	for i := 0;len(res) != k;i ++ {
		if res[i] == 1 {
			continue
		}
		res[i] >>= 1;
		res = append(res, res[i])
		i --
	}
	fmt.Printf("YES\n")
	for i := 0;i < len(res);i ++ {
		fmt.Printf("%d ", res[i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"regexp"
	"strconv"
	"strings"
)

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

		re := regexp.MustCompile("[0-9]+")
		split := re.FindAllString(input, -1)

		n, _ := strconv.Atoi(split[0])
		k, _ := strconv.Atoi(split[1])

		if k > n {
			fmt.Println("NO")
			break
		}

		powerOfTwo := []int{}
		result := []int{}
		// array of power of two
		for i := 0; i <= 30; i++ {
			powerOfTwo = append(powerOfTwo, int(math.Pow(2, float64(i))))
		}

		for i := 30; i >= 0; i-- {
			if powerOfTwo[i] <= n {
				n -= powerOfTwo[i]
				result = append(result, powerOfTwo[i])
			}
		}

		stopLoop := false

		for {
			for i := 0; i < len(result); i++ {
				if len(result) >= k {
					stopLoop = true
					break
				}
				if result[i] <= 1 {
					continue
				}
				result[i] /= 2
				result = append(result, result[i])
			}

			if stopLoop {
				break
			}
		}

		if len(result) > k {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println(strings.Trim(strings.Replace(fmt.Sprint(result), " ", " ", -1), "[]"))
		}

		break
	}
	if err := scanner.Err(); err != nil {
		log.Println(err)
	}
}

// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Dec 27 23:47:10 2018
//
package main

import "fmt"

func pow2(n int) int {
	if n == 0 {
		return 1
	}
	return 2 * pow2(n-1)
}

func split(p, n int) []int {
	if p == 1 {
		ret := make([]int, n)
		for i := range ret {
			ret[i] = 1
		}
		return ret
	}

	if n == 1 {
		return []int{p}
	}

	ret := make([]int, 0)
	ret = append(ret, split(p/2, n/2)...)
	ret = append(ret, split(p/2, n-n/2)...)
	return ret
}

func printSlice(slice []int) {
	for i := range slice {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(slice[i])
	}
}

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

	arr := make([]int, 0)
	for i := 0; i < 30; i++ {
		arr = append(arr, pow2(i))
	}

	ans := make([]int, 0)
	for i := len(arr) - 1; i >= 0; i-- {
		if arr[i] <= n {
			n -= arr[i]
			ans = append(ans, arr[i])
		}

		if n == 0 {
			break
		}
	}

	total := 0
	for i := range ans {
		total += ans[i]
	}

	if n != 0 || k < len(ans) || total < k {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	rem := k - len(ans)
	for i := range ans {
		if i != 0 {
			fmt.Print(" ")
		}

		if rem >= ans[i]-1 {
			rem -= ans[i] - 1
			for j := 0; j < ans[i]; j++ {
				if j != 0 {
					fmt.Print(" ")
				}
				fmt.Print(1)
			}
		} else if 0 < rem {
			printSlice(split(ans[i], rem+1))
			rem = 0
		} else {
			fmt.Print(ans[i])
		}
	}
	fmt.Println()
}

package main

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

const INF int =0x3f3f3f3f
const LLINF int64 = 0x3f3f3f3f3f3f3f3f
const MAX int =200000+10

func solve(){
    var n,k,i,tot,now int
    var res [MAX] int
    n=readInt()
    k=readInt()
    now=1
    for ;now<=n;now=now*2{
    }
    tot=0
    for ;n>0&&now>0;{
        if n>=now{
            n-=now
            res[tot]=now
            tot+=1
        }
        now>>=1
    }
    if tot>k{
        fmt.Println("NO")
        return
    }
    for i=0;i<tot;i++{
        for ;res[i]>1&&tot<k;{
            res[tot]=res[i]/2
            res[i]/=2
            tot+=1
        }
    }
    if tot<k{
        fmt.Println("NO")
    }else{
        fmt.Println("YES")
        for i=0;i<tot;i++{
            fmt.Print(res[i]," ")
        }
        fmt.Println()
    }
}

/***************************FastIO begin**********************************/
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 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
}
/***************************FastIO end**********************************/

/***************************sort begin**********************************/
type IntSlice []int

func (s IntSlice) Len() int { return len(s) }
func (s IntSlice) Swap(i,j int){ s[i],s[j]=s[j],s[i] }
func (s IntSlice) Less(i,j int) bool { return s[i]<s[j] }
/***************************sort end**********************************/

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

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

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n  int64
	var k int=0
	fmt.Fscanf(buf, "%d %d\n", &n,&k)
	if int64(k) > n{
		fmt.Printf("NO\n")
		return
	}
	ans := make([]int64,0)
	var front int = 0
	var mi2 int64 = 1
	for n > 0{
		if (n&1) == 1{
			ans = append(ans,mi2)

		}
		n /= 2
		mi2 *= 2
	}
	//fmt.Print(ans)
	front = len(ans)
	if k < front {
		fmt.Printf("NO\n")
		return
	}
	fmt.Printf("YES\n")
	var hw int = 0
	for front < k{
		for ans[hw] <= 1{
			hw++
		}
		ans=append(ans,ans[hw]/2)
		ans[hw] /=2
		front++
	}
	for i:= 0;i < front;i++{
		if i > 0{
			fmt.Printf(" ")
		}
		fmt.Printf("%d",ans[i])
	}
	fmt.Printf("\n")
}

package main

import "fmt"

func main() {
	var n, k int
	fmt.Scanf("%d%d", &n, &k)
	aa := make([]int, k)
	for i := 0; i < k; i++ { aa[i] = 1}
	n -= k
	for i := 0; i < k; i++ {
		for n >= aa[i] {
			n -= aa[i]
			aa[i] *= 2
		}
	}
	if n != 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for _, v := range aa {
			fmt.Printf("%d ", v)
		}
	}
}

package main

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

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

	defer out.Flush()

	var n, k int

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

	temp := n
	cnt := 0
	var a []int
	for temp > 0 {
		a = append(a, temp&1)
		cnt += temp&1
		temp = temp >> 1
	}
	for i := 0 ; i < len(a) / 2 ; i ++ {
		a[i], a[len(a) - i - 1] = a[len(a) - i - 1], a[i]
	}
	if k < cnt || k > n {
		fmt.Fprintf(out, "NO\n")
	}else{
		k -= cnt

		for i := 0 ; i + 1 < len(a) ; i ++ {
			//fmt.Println("a =     ",a)
			if k >= a[i]{
				a[i+1] += 2*a[i]
				k -= a[i]
				a[i] = 0
				if k == 0 {
					break
				}
			} else{
				a[i] -= k
				a[i+1] += 2*k
				k = 0
				if k == 0{
					break
				}
			}
		}
		//fmt.Println("a = ", a, " cnt = ", cnt)

		var b []int
		poii := 1
		for i := len(a) - 1 ; i >= 0 ; i -- {
			for j := 0 ; j < a[i] ; j ++ {
				b = append(b , poii)
			}
			poii = poii << 1
		}

		//fmt.Println("b = ", b)

		fmt.Fprintf(out, "YES\n")

		for i := 0 ; i < len(b) ; i ++ {
			fmt.Fprintf(out, "%d ", b[i])
		}
		fmt.Fprintf(out, "\n")
	}

}

package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, k int
	fmt.Fscan(stdin, &n, &k)

	var a = []int{}
	for i, j := 1, 1; j < 32; i, j = i*2, j+1 {
		a = append(a, i)
	}

	var digit = 0
	var res = make([]int, len(a))
	for i := len(a) - 1; i >= 0; i-- {
		for n >= a[i] {
			res[i] = n / a[i]
			digit += res[i]
			n -= res[i] * a[i]
		}
	}

	// fmt.Println(res, digit)
	for i := len(a) - 1; i > 0; i-- {
		for res[i] > 0 && digit < k {
			res[i]--
			res[i-1] += 2
			digit++
		}
	}

	if digit == k {
		fmt.Println("YES")
		for i := 0; i < len(a); i++ {
			for j := 0; j < res[i]; j++ {
				fmt.Print(a[i], " ")
			}
		}
		fmt.Println()
	} else {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
)

func solve(n, k int) (map[int]int, bool) {
	var POW []int

	if k > n {
		return nil, false
	}

	p, maxp := 1, 0
	for p <= n {
		if maxp < p {
			maxp = p
		}
		POW = append(POW, p)
		p *= 2
	}

	res := map[int]int{}

	i := len(POW) - 1
	for n > 0 {
		if n >= POW[i] {
			res[POW[i]]++
			n -= POW[i]
		}
		i--
	}

	count := len(res)

	for maxp > 1 && count < k {
		if res[maxp] <= 0 {
			maxp /= 2
			continue
		}

		count++

		half := maxp >> 1

		res[half] += 2
		res[maxp]--

	}

	return res, count == k
}

func main() {
	var n, k int

	fmt.Scan(&n, &k)

	a, isPossible := (solve(n, k))
	if !isPossible {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for k, n := range a {
		for i := 0; i < n; i++ {
			fmt.Print(k, " ")
		}
	}
	fmt.Println()
}

package main

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

func main() {
	var n, k uint
	fmt.Scan(&n, &k)

	bitMap := map[uint]uint{}
	for i := 0; i < 32; i++ {
		target := uint(1) << uint(i)
		if (n & target) > 0 {
			bitMap[target]++
		}
	}

	min, max := uint(len(bitMap)), n
	if (k < min) || (k > max) {
		fmt.Println("NO")
		os.Exit(0)
	}

	split := k - min
	for i := 0; i < int(split); i++ {
		for k, v := range bitMap {
			if (k == 1) || (v == 0) {
				continue
			}

			bitMap[k], bitMap[k/2] = v-1, bitMap[k/2]+2
			break
		}
	}

	res := []string{}
	for k, v := range bitMap {
		for i := 0; i < int(v); i++ {
			res = append(res, strconv.Itoa(int(k)))
		}
	}
	fmt.Println("YES")
	fmt.Println(strings.Join(res, " "))
}

package main

import (
	"fmt"
)

func solve(n, k int) (bool, []int) {
	var POW []int

	if k > n {
		return false, nil
	}

	p := (1)
	for p <= n {
		POW = append(POW, p)
		p *= 2
	}

	var res []int

	i := len(POW) - 1
	for n > 0 {
		if n >= POW[i] {
			res = append(res, POW[i])
			n -= POW[i]
		}
		i--
	}

	if k < len(res) {
		return false, nil
	}

	for len(res) < k {
		//	fmt.Println(res)

		if res[0] == 1 {
			return false, nil
		}

		if res[0] == 2 {
			res := res[1:]
			res = append(res, 1)
			res = append(res, 1)
		}

		res[0] /= 2
		res = append([]int{res[0]}, res...)
	}

	return true, res
}

func main() {
	var n, k int

	fmt.Scan(&n, &k)

	isPossible, a := (solve(n, k))
	if !isPossible {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for _, n := range a {
		fmt.Print(n, " ")
	}
	fmt.Println()
}


package main

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

type CF1748A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1748A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1748A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1748A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1748A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1748A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1748A
Date: 11/14/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1748/A
Problem: CF1748A
**/
func (in *CF1748A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		fmt.Println(int(math.Ceil(float64(n) / 2.)))
	}
}

func NewCF1748A(r *bufio.Reader) *CF1748A {
	return &CF1748A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1748A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	var n int
	fmt.Fscan(reader, &n)
	fmt.Fprintf(writer, "%v\n", (n+1)/2)
}

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := true
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}

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 n int
		fmt.Fscan(in,&n)
		if n & 1 == 1 {
			fmt.Fprintln(out,(n-1)/2 + 1)
		} else {
			fmt.Fprintln(out,(n-2)/2 + 1)
		}
	}
}

package main

import "fmt"

func main() {
  var T int
  fmt.Scan(&T)
  for t := 0; t < T; t += 1 {
    var N int64
    fmt.Scan(&N)
    if N % 2 == 0 {
      N -= 1
    }
    fmt.Println(N / 2 + 1);
  }
}

package main

/*

5 = 1/2 2/2 3/2 4/2 5/2 == 1 1 2 2 3
15 = 1/2 2/2 3/2 4/2 5/2 6/2 7/2 8/2 9/2 10/2 = 1 1 2 2 3 3 4 4 5 5

5
5
4 1
1 4
3 2
2 3

4
3 1
1 3
2 2

*/

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

func main() {
	ultiSquare()
}

func ultiSquare() {
	r := bufio.NewReader(os.Stdin)
	var tc int
	for fmt.Fscan(r, &tc); tc > 0; tc-- {
		var c int
		fmt.Fscan(r, &c)
		fmt.Println(int(math.Ceil(float64(c) / float64(2))))
	}
}

package main

import (
	"fmt"
	"math"
)

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

	var arr []float64
	for i := 0; i < t; i++ {
		var n float64
		fmt.Scan(&n)
		arr = append(arr, n)
	}

	for i := 0; i < len(arr); i++ {
		l := math.Round(arr[i] / 2)
		fmt.Println(int(l))
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

		var n int64
		fmt.Fscan(reader, &n)

		ans := n / 2
		if n%2 > 0 {
			ans++
		}

		fmt.Fprintln(writer, ans)
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n)
		r := n / 2
		r += n % 2
		fmt.Println(r)
	}
}

package main

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

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

func main() {
	writer.Flush()

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

	ceilInt := func(a, b int) int {
		if a % b == 0 {
			return a / b
		}

		return a / b + 1
	}

	for test > 0 {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Println(ceilInt(n, 2))
		test--
	}
}

package main

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

func solve(r *bufio.Reader) {
	var n int64
	fmt.Fscan(r, &n)
	total := n / 2
	total = total * (total + 1)
	if n%2 == 1 {
		total += (n + 1) / 2
	}
	fmt.Println(int(math.Sqrt(float64(total))))
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

func ans() {
	var n int
	Fscan(in, &n)
	Fprintln(out, (n+1)/2)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

import (
	"fmt"
)

func main() {
	var (
		t int
		n int
	)
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		fmt.Println(n/2 + n%2)
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	fmt.Fprintln(writer, (n+1)/2)
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

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

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

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 32)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	fmt.Fprintln(out, n/2+n%2)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

import "fmt"

func main() {
  var t int
  fmt.Scan(&t)
  for x := 0; x < t; x++ {
    var n int64
    fmt.Scan(&n)
    if n % 2 ==0{
        fmt.Println(n/2)
    } else {
        fmt.Println(n/2+1)
    }
  }
}

package main

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &m)
		fmt.Println(int(math.Ceil(float64(m) / 2)))
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		fmt.Println(n/2 + n%2)
	}
}

package main

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

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

	defer writer.Flush()

	var t int
	fmt.Fscan(reader, &t)

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

		fmt.Fprintf(writer, "%d\n", n/2+n%2)
	}
}

package main

import "fmt"

func main() {
  var t int
  fmt.Scan(&t)
  for t := 0;t<t; t++ {
    var N int64
    fmt.Scan(&N)
    fmt.Println(N / 2 + 1);
  }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t>0{
		t--
		var n int
		fmt.Scan(&n)
		fmt.Print(n/2+1)

	}
}

package main

import (
	"fmt"
)

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

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

		fmt.Println(n/2 + n%2)
	}
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	var n int
	fmt.Fscan(reader, &n)
	fmt.Fprintf(writer, "%v\n", (n+1)/2)
}

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := true
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	var n int
	fmt.Fscan(reader, &n)
	fmt.Fprintf(writer, "%v\n", (n+1)/2)
}

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := false
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}