The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:  Operation ++ increases the value of variable x by 1.  Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).

Print a single integer — the final value of x.

package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scanln(&n)
	var x int
	for i := 0; i < n; i++ {
		var expr string
		fmt.Scanln(&expr)
		if expr[1] == '-'{
			x--
		} else {
			x++
		}
	}
	fmt.Println(x)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var x int = 0
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		if s[1] == '+' {
			x++
		} else {
			x--
		}
	}
	fmt.Println(x)
}

package main

import f "fmt"

func main (){
	var n int
  f.Scanln(&n)
	var oper [150]string

	for i:=0; i < n; i++ {
		f.Scanln(&oper[i])
	}

	x := 0
	for i:= 0; i < n; i++ {
		if oper[i] == "X++" || oper[i] == "++X" {
			x++
		}else{
			x--
		}
	}
	f.Println(x)
}

package main

import "fmt"

func main() {
	var x, n int
	var line string

	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%s\n", &line)
		if line[1] == '+' {
			x++
		} else {
			x--
		}
	}

	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

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

	x := 0
	for i := 0; i < n; {
		var p string
		fmt.Scanf("%s", &p)
		if len(p) == 0 {
			continue
		}
		if strings.Contains(p, "+") {
			x++
		} else if strings.Contains(p, "-") {
			x--
		}
		i++
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var x int
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if strings.Contains(s, "++") {
			x++
		} else if strings.Contains(s, "--") {
			x--
		}
	}
	fmt.Println(x)
}

package main

import "fmt"

func main() {
	var n int
	var op string

	x := 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&op)
		switch op {
		case "++X", "X++":
			x++
		case "--X", "X--":
			x--
		}
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

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

	answer := 0

	for i := 0; i < m; i++ {
		var x string
		fmt.Scan(&x)

		if strings.Contains(x, "++") {
			answer++
		} else if strings.Contains(x, "--") {
			answer--
		}
	}

	fmt.Println("", answer)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var res int
	for i := 0; i < n; i++ {
		var line string
		fmt.Scan(&line)
		if strings.Contains(line, "++") {
			res++
		} else if strings.Contains(line, "--") {
			res--
		}
	}
	fmt.Print(res)
}

package main

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

func main() {
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
	scanner.Scan()
	n := int32(0)
	fmt.Sscanf(scanner.Text(), "%d", &n)

	ans := 0
	for scanner.Scan() {
		s := scanner.Text()
		if strings.Contains(s, "+") {
			ans++
		} else {
			ans--
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func task_solution(a []string) (ans int) {
	for _, str := range a {
		// check central symbol of string
		if str[1] == '+' {
			ans += 1
		} else {
			ans -= 1
		}
	}
	return ans
}

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

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

	fmt.Println(task_solution(a))
}

package main

import "fmt"

func main() {
	x := 0
	n := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		s := ""
		fmt.Scanf("%s\n", &s)
		if s[0] == '+' || s[len(s)-1] == '+' {
			x++
			continue
		}
		x--
	}
	fmt.Println(x)
}

package main

import "fmt"

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

	cnt := 0

	for t := 0; t < test_case; t++ {
		var str string
		fmt.Scan(&str)

		if str[0] == '+' || str[2] == '+' {
			cnt++
		} else if str[0] == '-' || str[2] == '-' {
			cnt--
		}
	}

	fmt.Println(cnt)
}

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

var scanner * bufio.Scanner = bufio.NewScanner(os.Stdin)

func scanInt() int{
    scanner.Scan()
    var i int
    i,_ = strconv.Atoi(scanner.Text())
    return i
}

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

func main(){
    n := scanInt()
    cnt := 0
    for i := 0; i < n; i++ {

        str := scanStr()
        if( str[1:2] == "-" ){
            cnt--
        } else {
            //fmt.Println("bal")
            cnt++
        }
    }
    fmt.Println(cnt)
}

package main

import( "fmt" )

func main() {

	var n, y int
	var s string

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

	fmt.Scan( &s )
	if( s == "++X" || s ==  "X++" ){ y++ }else if( s == "--X" || s ==  "X--" ){ y-- }else{ fmt.Println( "error" ) }

	}

	fmt.Println( y )

}

package main;

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

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

func main() {
    var n int;
    scanf("%d", &n);
    var x int = 0;
    var s string;
    for i:=0;i<n;i++ {
        scanf("%s", &s);
        if s[1] == '+' {
            x++;
        } else {
            x--;
        }
    }
    printf("%d", x);
}

package main

import (
	"fmt"
	"strings"
)

func main() {

	var n int
	fmt.Scan(&n)
	var x int = 0
	for i := 0; i < n; i++ {
		var command string
		fmt.Scan(&command)
		if strings.Compare("X++", command) == 0 || strings.Compare("++X", command) == 0 {
			x++
		} else if strings.Compare("X--", command) == 0 || strings.Compare("--X", command) == 0 {
			x--
		}
	}
	fmt.Print(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	x := 0
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		if strings.ContainsRune(s, '+') {
			x++
			continue
		}
		x--
	}
	fmt.Print(x)
}

package main

import (
	"fmt"
	"strings"
)

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

	for i := 0; i < n; i++ {
		var str string
		fmt.Scanf("%s\n", &str)

		if strings.Contains(str, "+") {
			x++
		} else {
			x--
		}
	}

	fmt.Printf("%d", x)
}

package main

import (
	"fmt"
)

func main() {
	var n, rez int
	var st string

	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&st)
		if string([]rune(st)[1]) == "+" {
			rez++
		} else {
			rez--
		}
	}

	fmt.Print(rez)
}

package main

import "fmt"

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

	var b []byte
	for i := n; i > 0; i-- {
		if fmt.Scan(&b); b[1] == '-' {
			n-=2
		}
	}
	fmt.Println(n)
}

//初始值为0
//如果是++X或者X++则加1 --X或者X--则减
package main

import (
	"fmt"
)

func main() {
	var num, result int
	fmt.Scanln(&num)
	array := make([]string, num+1)
	result = 0
	for i := 1; i <= num; i++ {
		fmt.Scanln(&array[i])
		if array[i] == "++X" || array[i] == "X++" {
			result++
		} else {
			result--
		}
	}
	fmt.Println(result)

}

package main

import (
	"fmt"
)

func main() {
	var N, cnt int
	var x string
	fmt.Scanln(&N)
	for i := 0; i < N; i++ {
		fmt.Scanln(&x)
		if x == "++X" || x == "X++" {
			cnt++
		} else if x == "--X" || x == "X--" {
			cnt--
		}
	}
	fmt.Println(cnt)
}

package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var str string
		fmt.Scan(&str)
		if str[1:2] == "+" {
			x++
		} else {
			x--
		}
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

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

	answer := 0

	for i := 0; i < m; i++ {
		var x string
		fmt.Scan(&x)

		if strings.Contains(x, "++") {
			answer++
		} else if strings.Contains(x, "--") {
			answer--
		}
	}

	fmt.Println("", answer)
}

package main

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

const ADDING_OPERATION = "++"
const SUBSTRACTING_OPERRATION = "--"

func main() {
	input := bufio.NewScanner(os.Stdin)
	hasInput := input.Scan()
	if hasInput == false {
		panic("Number of problems missing")
	}

	_, err := strconv.Atoi(input.Text())

	if err != nil {
		panic("Undefined number passed")
	}

	x := 0
	for input.Scan() {
		operation := input.Text()
		if strings.Contains(operation, ADDING_OPERATION) {
			x++

		} else {
			x--
		}
	}

	fmt.Println(x)
}

package main

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

func main() {
	var n int
	var x int

	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		fmt.Println(err)
		return
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for i := 0; i < n && scanner.Scan(); i++ {
		text := scanner.Text()
		if text == "++X" || text == "X++" {
			x++
		} else if text == "--X" || text == "X--" {
			x--
		}
	}

	fmt.Println(x)
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
	nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)

	checkError(err)
	x := int(nTemp)
	res := 0
	for i := 0; i < x; i++ {
		out := readLine(reader)
		if out == "++X" || out == "X++" {
			res++
		} else {
			res--
		}
	}
	fmt.Println(res)
}

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

package main

import f "fmt"

func main (){
	var n int
  f.Scanln(&n)
	var oper [150]string

	for i:=0; i < n; i++ {
		f.Scanln(&oper[i])
	}

	x := 0
	for i:= 0; i < n; i++ {
		if oper[i] == "X++" || oper[i] == "++X" {
			x++
		}else{
			x--
		}
	}
	f.Println(x)
}

package main

import (
	"fmt"
)
func main ( ){
	var len, out int
	var cmd string
	fmt.Scanln(&len)

	for i := 0; i < len; i++ {
		fmt.Scanln(&cmd)
		switch cmd{
			case "X++":
			out++
			case "++X":
			out++
			case "X--":
			out--
			case "--X":
			out--
		}
	}
	fmt.Println(out)
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	var s string;
	ans := 0
	for i := 0; i < T; i++ {
		fmt.Scanf("%s\n", &s)
		if s[1] == '+' {
			ans ++
		} else {
			ans --
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var (
		x, n int
	)
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		if strings.Contains(s, "X++") {
			x++
		} else if strings.Contains(s, "++X") {
			x++
		} else if strings.Contains(s, "--X") {
			x--
		} else if strings.Contains(s, "X--") {
			x--
		}
	}
	fmt.Printf("%d\n", x)
}

package main

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

func main() {
	n := scanInt()
	var x = 0
	for ; n > 0; n-- {
		operation := scanString()
		if operation == "X++" || operation == "++X" {
			x++
		} else {
			x--
		}
	}
	_, _ = printFmt(x)
}

/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			_, _ = writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func max(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func sorting(array []int64, fromElement int, toElement int) []int64 {
	var arr []int64
	for i := fromElement; i <= toElement; i++ {
		arr = append(arr, array[i])
	}
	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	s := 0
	for i := fromElement; i <= toElement; i++ {
		array[i] = arr[s]
		s++
	}
	return array
}

func reverse(numbers []int64) []int64 {
	for i, j := 0, len(numbers)-1; i < j; i, j = i+1, j-1 {
		numbers[i], numbers[j] = numbers[j], numbers[i] }
	return numbers
}

func reversing(array []int64, fromElement int, toElement int) []int64 {
	var arr []int64
	for i := fromElement; i <= toElement; i++ {
		arr = append(arr, array[i])
	}
	arr = reverse(arr)
	s := 0
	for i := fromElement; i <= toElement; i++ {
		array[i] = arr[s]
		s++
	}
	return array
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var b []byte
	for i := n; i > 0; i-- {
		if fmt.Scan(&b); b[1] == '-' {
			n -= 2
		}
	}
	fmt.Print(n)
}

package main

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

var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func main() {
	defer writer.Flush()

	scanner := bufio.NewScanner(os.Stdin)
	n := 0
	result := 0
	for i := 0; scanner.Scan(); i++ {
		// First line
		if i == 0 {
			params := StringToArrayInt(scanner.Text())
			n = params[0] // number of lines
		} else {
			result = Run(scanner.Text(), result)
		}

		// Exit condition
		if i >= n {
			break
		}
	}

	printf("%d", result)
}

func Run(operation string, operand int) int {
	if strings.Contains(operation, "++") {
		return operand + 1
	}
	return operand - 1
}

// Utils
func StringToArrayInt(t string) (t2 []int) {
	for _, i := range strings.Split(t, " ") {
		j, err := strconv.Atoi(i)
		if err != nil {
			panic(err)
		}
		t2 = append(t2, j)
	}
	return t2
}

func ArrayStringToInt(t []string) (t2 []int) {
	for _, i := range t {
		j, err := strconv.Atoi(i)
		if err != nil {
			panic(err)
		}
		t2 = append(t2, j)
	}
	return t2
}

package main

import (
	"fmt"
	"strings"
)

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

	for i := 0; i < n; i++ {
		var str string
		fmt.Scanf("%s\n", &str)

		if strings.Contains(str, "+") {
			x++
		} else {
			x--
		}
	}

	fmt.Printf("%d", x)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/282/A

package main

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

func Solve(ops []string) int {
	x := 0
	for _, op := range ops {
		if op == "++X" || op == "X++" {
			x += 1
		} else if op == "--X" || op == "X--" {
			x -= 1
		}
	}
	return x
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	ops := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &ops[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(ops))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var (
		n     int
		count int
	)

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if strings.Contains(s, "+") {
			count++
		} else {
			count--
		}
	}

	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n int
	var op string

	x := 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&op)
		switch op {
		case "++X", "X++":
			x++
		case "--X", "X--":
			x--
		}
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {

	var n, x int
	var op string

	fmt.Scanf("%d\n", &n)

	for i := 1; i <= n; i++{
		fmt.Scanf("%s\n", &op)

		if strings.ContainsRune(op, '+'){
			x++
		} else{
			x--
		}
	}

	fmt.Printf("%d\n", x)

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var c int32 = 0
	var s string
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint16(i) < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)
		if s == "++X" || s == "X++" {
			c++
		} else if s == "--X" || s == "X--" {
			c--
		}
	}
	fmt.Println(c)
}

package main

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

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

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	x := 0

	for i := 0; i < n; i++ {
		scanner.Scan()
		op := scanner.Text()

		if strings.Contains(op, "++") {
			x++
		} else {
			x--
		}
	}

	fmt.Println(x)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var x int = 0
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		if s[1] == '+' {
			x++
		} else {
			x--
		}
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	x := 0
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		if strings.ContainsRune(s, '+') {
			x++
			continue
		}
		x--
	}
	fmt.Print(x)
}

package main

import (
    "fmt"
)

type i int32

func main(){
    var n,res i
    fmt.Scan(&n)
    res = 0
    for n>0{
        var s string
        fmt.Scan(&s)
        if s=="X++" || s=="++X"{
            res++
        }else if s=="X--" || s=="--X" {
            res--
        }
        n--
    }
    fmt.Println(res)
}

package main

import "fmt"

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

	count := 0

	for n > 0 {
		var input string
		fmt.Scan(&input)
		if input[1] == '+' {
			count++
		} else {
			count--
		}
		n--
	}

	fmt.Println(count)

}

package main

import ("fmt")
import ("strings")

func main() {
  var num int
  result:=0
  fmt.Scanln(&num)
  for i:=0;i<num;i++{
    var current string
    fmt.Scanln(&current)

     if strings.Contains(current, "+") {
       result++
    } else {
      result--
    }
  }
      fmt.Println(result)

}

package main

import (
	"fmt"
)

func main() {
	var bitland []string
	number := 0
	_, _ = fmt.Scanln(&number)
	for number > 0 {
		var istring string
		_, _ = fmt.Scanln(&istring)
		bitland = append(bitland, istring)
		number--
	}
	var count int32 = 0

	for i := 0; i < len(bitland); i++ {
		if string(bitland[i]) == "++X" {
			count++
		} else if string(bitland[i]) == "X++" {
			count++
		} else {
			count--
		}
	}

	fmt.Println(count)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n , ans int
	var s string
	fmt.Scan(&n)
	for i:=0; i<n; i++{
		fmt.Scan(&s)
		if strings.Compare(string(s[0]),string("+")) == 0 || strings.Compare(string(s[2]),string("+")) == 0 {
				ans++
			}else{
				ans--
			}
	}
	fmt.Println(ans)
	return
}

package main

import (
	"fmt"
)

func main() {
	var (
		n, x int
		s    string
	)

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		if s[1] == '+' {
			x++
		} else {
			x--
		}
	}
	fmt.Print(x)
}

package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var str string
		fmt.Scan(&str)
		if str[1:2] == "+" {
			x++
		} else {
			x--
		}
	}
	fmt.Println(x)
}

package main

import fmt "fmt"
func do( result int,s string ) int {
	if (s[0]=='+'|| (s[0]=='X'&&s[1]=='+')){
		return result+1;
	} else {
		return result-1;
	}
}

func main() {
	var x int;
	var result int;
	var v string;

	result = 0;
	fmt.Scanf("%d\n",&x);
	for i := 0; i < x; i++ {
		fmt.Scanf("%s\n",&v);
		result = do(result,v);
	}

	fmt.Print(result);
}

package main

import "fmt"

func main() {

	var x [150]string
	var X, n int

	fmt.Scan(&n)

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

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

		switch temp[0] {
		case '+':
			X = X + 1
			continue looper
		case '-':
			X = X - 1
			continue looper
		}

		switch temp[2] {
		case '+':
			X = X + 1
			continue looper
		case '-':
			X = X - 1
			continue looper
		}
		//fmt.Printf("x[%v] = '%s'\n", i, x[i])
	}
	fmt.Print(X)
}

package main

import "fmt"

func main() {
	x := 0
	n := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		s := ""
		fmt.Scanf("%s\n", &s)
		if s[0] == '+' || s[len(s)-1] == '+' {
			x++
			continue
		}
		x--
	}
	fmt.Println(x)
}

/*A. Bit++
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

Operation ++ increases the value of variable x by 1.
Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).

Input
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.

Output
Print a single integer — the final value of x.

Examples
inputCopy
1
++X
outputCopy
1
inputCopy
2
X++
--X
outputCopy
0
*/

package main

import "fmt"

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

	for i := 0; i < numberOfLines; i++ {
		var operation string
		fmt.Scanf("%s\n", &operation)

		switch operation {
		case "X++", "++X":

			counter++
		case "--X", "X--":
			counter--
		}
	}
	fmt.Println(counter)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	// tokens: --, ++, X
	// each line contains operator AND variable => aka statement
	// each line contaisn ONE statement
	// rule out X b/c it will always be there.
	// just need to know if a stmt has - or +. then we inc/dec depnding onti.

	// inputs
	num_stmt := 0
	fmt.Scan(&num_stmt)

	total := 0
	for num_stmt > 0 {
		stmt := ""
		fmt.Scan(&stmt)

		if strings.Contains(stmt, "++") {
			total++
		} else {
			total--
		}
		num_stmt--
	}
	fmt.Println(total)
}

package main

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

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

func main() {
	ini()
	defer writer.Flush()

	n := scanInt()
	var result int
	for i:=0; i<n; i++ {
		iter := scanString()
		if strings.Contains(iter, "++") {
			result++
		} else {
			result--
		}
	}

	writer.WriteString(strconv.Itoa(result))

}

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

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

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

package main

import "fmt"

func main() {

	var x string
	var X, n int

	fmt.Scan(&n)

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

		fmt.Scan(&x)
		switch x[0] {
		case '+':
			X = X + 1
			continue
		case '-':
			X = X - 1
			continue
		}

		switch x[2] {
		case '+':
			X = X + 1
			continue
		case '-':
			X = X - 1
			continue
		}

	}

	fmt.Print(X)
}

package main

import "fmt"

func main() {
	var n int
	var st string
	fmt.Scan(&n)
	result := 0
	for ; n > 0; n-- {
		fmt.Scan(&st)
		var b byte = st[1]
		if b == '+' {
			result++
		} else {
			result--
		}
	}
	fmt.Println(result)
}

package main

import "fmt"

func main() {
	var n int
	var inp string
	fmt.Scan(&n)
	answer := 0
	for i:=0; i<n; i++ {
		fmt.Scan(&inp)
		if inp[1]=='+' {
			answer++
		} else {
			answer--
		}
	}
	fmt.Print(answer)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
    var num int
    var s string
    var cnt int

    cnt = 0

	fmt.Scanf("%d\n", &num)

    for i := 0; i < num; i++ {
        fmt.Scanf("%s\n", &s)

        if strings.Index(s,"+")>=0 {
        	cnt = cnt + 1
        }

        if strings.Index(s,"-")>=0 {
        	cnt = cnt - 1
        }
    }
    fmt.Printf("%d",cnt)
}

package main

import (
	"fmt"
	"strings"
)

func main() {

	var n, x int
	var op string

	fmt.Scanf("%d\n", &n)

	for i := 1; i <= n; i++{
		fmt.Scanf("%s\n", &op)

		if strings.ContainsRune(op, '+'){
			x++
		} else{
			x--
		}
	}

	fmt.Printf("%d\n", x)

}

package main

import "fmt"

func main() {
	x := 0
	n := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanln(&s)
		if s[0] == '+' || s[len(s)-1] == '+' {
			x++
			continue
		}
		x--
	}
	fmt.Println(x)
}

package main

import (
    "fmt"
)

type i int32

func main(){
    var n,res i
    fmt.Scan(&n)
    res = 0
    for n>0{
        var s string
        fmt.Scan(&s)
        if s=="X++" || s=="++X"{
            res++
        }else if s=="X--" || s=="--X" {
            res--
        }
        n--
    }
    fmt.Println(res)
}

package main

import (
    "fmt"
    "strings"
)

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

    cnt := 0
    for i:=0; i < t; i++ {
        var s string
        fmt.Scan(&s)
        if strings.Contains(s, "+") {
            cnt++
            continue
        }
        cnt--
    }
    fmt.Println(cnt)
}

/*A. Bit++
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

Operation ++ increases the value of variable x by 1.
Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.

A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.

You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).

Input
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.

Output
Print a single integer — the final value of x.

Examples
inputCopy
1
++X
outputCopy
1
inputCopy
2
X++
--X
outputCopy
0
*/

package main

import "fmt"

func main() {
	var numberOfLines, counter int
	fmt.Scanln(&numberOfLines)

	var operation string
	for i := 0; i < numberOfLines; i++ {
		fmt.Scanln(&operation)

		switch operation {
		case "X++", "++X":

			counter++
		case "--X", "X--":
			counter--
		}
	}
	fmt.Println(counter)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	result := 0
	for i := 0; i < n; i++ {
		var st string
		fmt.Scan(&st)
		if strings.Contains(st, "+") {
			result++
		} else {
			result--
		}
	}
	fmt.Println(result)
}

package main

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

func nextWords(scanner *bufio.Scanner) []string {
	scanner.Scan()
	return strings.Fields(scanner.Text())
}

func nextNumbers(scanner *bufio.Scanner) []int {
	var numbers = make([]int, 0)
	line := nextWords(scanner)
	for i := range line {
		n, _ := strconv.Atoi(line[i])
		numbers = append(numbers, n)
	}
	return numbers
}

func nextInt(scanner *bufio.Scanner) int {
	number, _ := strconv.Atoi(nextLine(scanner))
	return number
}

func sumInputs(numbers []int) int {
	var sum int
	for i := range numbers {
		sum += numbers[i]
	}
	return sum
}

func nextLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	var x = 0

	n := nextInt(scanner)

	for n < 1 || n > 150 {
		n = nextInt(scanner)
	}

	for i := 0; i < n; i++ {
		stm := nextLine(scanner)
		o:=stm[1:2]

		if o == "+" {
			x++
		} else {
			x = x - 1
		}
	}

	fmt.Println(x)
}

package main

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

func main() {
	fmt.Println(parsInputs())
}

func parsInputs() int {
	in := getInputs()
	x := 0
	for _, opt := range in {
		if strings.Contains(opt, "++") {
			x++
		} else if strings.Contains(opt, "--") {
			x--
		}
	}
	return x
}

func getInputs() []string {
	reader := bufio.NewReader(os.Stdin)
	l := -1
	current := 0
	opts := []string{}

	for current != l {
		s, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}
		s = strings.TrimRight(s, "\r\n")

		if l == -1 {
			l, _ = strconv.Atoi(s)
			continue
		}
		opts = append(opts, s)
		current++
	}
	return opts
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,c int
	var word string
	fmt.Scan(&n)
	c = 0
	for ; n>0; n--{
		fmt.Scan(&word)

		if strings.Contains(word, "++") {
			c++
		} else {
			c--
		}
	}

	fmt.Print(c)
}

package main

import (
	"fmt"
)

func isPlus(k string) bool {
	f := false
	if k == "X++" || k == "++X" {
		f = true
	}
	return f
}

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

package main

import "fmt"

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

	count := 0

	for n > 0 {
		var input string
		fmt.Scan(&input)
		if input[1] == '+' {
			count++
		} else {
			count--
		}
		n--
	}

	fmt.Println(count)

}

package main

import "fmt"

func main() {
	x := 0
	n := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		s := ""
		fmt.Scanf("%s\n", &s)
		if s[0] == '+' || s[len(s)-1] == '+' {
			x++
			continue
		}
		x--
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var res int
	for i := 0; i < n; i++ {
		var line string
		fmt.Scan(&line)
		if strings.Contains(line, "++") {
			res++
		} else if strings.Contains(line, "--") {
			res--
		}
	}
	fmt.Print(res)
}

package main

import ("fmt")
import ("strings")

func main() {
  var num int
  result:=0
  fmt.Scanln(&num)
  for i:=0;i<num;i++{
    var current string
    fmt.Scanln(&current)

     if strings.Contains(current, "+") {
       result++
    } else {
      result--
    }
  }
      fmt.Println(result)

}

package main

import "fmt"

func main() {
	var n int
	ans := 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if s[1] == '+' {
			ans++
		} else {
			ans--
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	var op string

	x := 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&op)
		switch op {
		case "++X", "X++":
			x++
		case "--X", "X--":
			x--
		}
	}
	fmt.Println(x)
}

package main

import "fmt"

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

	var b []byte
	for i := n; i > 0; i-- {
		if fmt.Scan(&b); b[1] == '-' {
			n--
		}
	}
	fmt.Println(n)
}

package main

import "fmt"

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

	var b []byte
	for i := n; i > 0; i-- {
		if fmt.Scan(&b); b[1] == '-' {
			n=-2
		}
	}
	fmt.Println(n)
}

package main

import "fmt"
import "strings"

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

	for i := 0; i < n; i++ {
		var str string
		fmt.Scanf("%s", &str)

		if strings.Contains(str, "+") {
			x++
		} else {
			x--
		}
	}

	fmt.Printf("%d", x)
}

package main

import (
	"fmt"
	"strings"
)

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

	for i := 0; i < n; i++ {
		var str string
		fmt.Scanf("%s", &str)

		if strings.Contains(str, "+") {
			x++
		} else {
			x--
		}
	}

	fmt.Printf("%d", x)
}

package main

import "fmt"

func main() {
	var n int
	var input string
	fmt.Scanln("%d", &n)
	ans := 0
	for i := 0; i < n; i++ {
		fmt.Scanln("%s", &input)
		if string(input[1]) == "-" {
			ans--
		} else {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var (
		n, x int
		s    string
	)

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		if s[2] == '+' {
			x++
		} else {
			x--
		}
	}
	fmt.Print(x)
}

package main

import ("fmt")
import ("strings")

func main() {
  var num int
  result:=0
  fmt.Scanln(&num)
  for i:=0;i<num;i++{
    var current string
    fmt.Scanln(&current)

     if strings.Contains(current, "+") {
       result++
    } else {
      result--
    }
    fmt.Println(result)

  }
}

package main

import (
    "fmt"
)

type ui uint32

func main(){
    var n,res ui
    fmt.Scan(&n)
    res = 0
    for n>0{
        var s string
        fmt.Scan(&s)
        if s=="X++" || s=="++X"{
            res++
        }else if s=="X--" || s=="--X" {
            res--
        }
        n--
    }
    fmt.Println(res)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n , ans int
	var s string
	fmt.Scan(&n)
	for ; n>0; n--{
		fmt.Scan(&s)
		if strings.Compare(string(s[0]),string("+")) == 0{
				ans++
			}else{
				ans--
			}
	}
	fmt.Println(ans)
	return
}

package main

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

const ADDING_OPERATION = "X++"
const SUBSTRACTING_OPERRATION = "--X"

func main() {
	input := bufio.NewScanner(os.Stdin)
	hasInput := input.Scan()
	if hasInput == false {
		panic("Number of problems missing")
	}

	_, err := strconv.Atoi(input.Text())

	if err != nil {
		panic("Undefined number passed")
	}

	x := 0
	for input.Scan() {
		switch operation := input.Text(); operation {
			case ADDING_OPERATION:
				x++
			case SUBSTRACTING_OPERRATION:
				x--
		}
	}

	fmt.Println(x)
}

package main

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

const ADDING_OPERATION = "++X"
const SUBSTRACTING_OPERRATION = "--X"

func main() {
	input := bufio.NewScanner(os.Stdin)
	hasInput := input.Scan()
	if hasInput == false {
		panic("Number of problems missing")
	}

	_, err := strconv.Atoi(input.Text())

	if err != nil {
		panic("Undefined number passed")
	}

	x := 0
	for input.Scan() {
		operation := input.Text()
		switch operation {
			case ADDING_OPERATION:
				x++
			case SUBSTRACTING_OPERRATION:
				x--
		}
	}

	fmt.Println(x)
}

package main

import (
	"fmt"
  "strings"
)

func main() {
  var n int
  var s string
  var num int
  for i:=0; i<n ; i++ {
	  fmt.Scanf("%s\n", &s)
    if( strings.ContainsAny(s, "+") ){
        num++;
    }else{
      num--
    }

  }

  fmt.Println(num)

}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, i uint8
	var s string
	fmt.Scanln(&n)
	for n > 0 {
		n--
		fmt.Scanln(&s)
		switch {
		case strings.Contains(s, "+"):
			i++
		case strings.Contains(s, "-"):
			i--
		}
	}
	fmt.Println(i)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var c uint32 = 0
	var s string
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint16(i) < n; i++ {
		fmt.Fscanf(in, "%s\n", &s)
		if s == "++X" || s == "X++" {
			c++
		} else if s == "--X" || s == "X--" {
			c--
		}
	}
	fmt.Println(c)
}

package main

import fmt "fmt"
func do( result int,s string ) int {
	if (s[0]=='+'|| (s[0]=='X'&&s[1]=='+')){
		return result+1;
	} else {
		return result-1;
	}
}

func main() {
	var x int;
	var result int;
	var v string;

	result = 0;
	fmt.Scanf("%d\n",&x);
	for i := 0; i < x-1; i++ {
		fmt.Scanf("%s\n",&v);
		result = do(result,v);
	}
	fmt.Scanf("%s\n",&v);
	if(v[0]!='X'){
		result = do(result,v);
	}
	fmt.Print(result);
}

package main

import fmt "fmt"
func do( result int,s string ) int {
	if (s[0]=='+'|| (s[0]=='X'&&s[1]=='+')){
		return result+1;
	} else {
		return result-1;
	}
}

func main() {
	var x int;
	var result int;
	result = 0;
	fmt.Scanf("%d\n",&x);
	for i := 0; i < x-1; i++ {
		var v string;
		fmt.Scanf("%s\n",&v);
		result = do(result,v);
	}
	var v string;
	fmt.Scanf("%s\n",&v);
	if(v[0]!='X'){
		result = do(result,v);
	}
	fmt.Print(result);
}

package main

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

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

	scanner := bufio.NewScanner(os.Stdin)
	x := 0
	for i := 0; i < n && scanner.Scan(); i++ {
		p := scanner.Text()
		if strings.Contains(p, "+") {
			x++
		} else if strings.Contains(p, "-") {
			x--
		}
	}
	fmt.Println(x)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var inc string = "X++"
	var dcr string = "--X"

	var n int
	fmt.Scan(&n)
	var x int = 0
	for i := 0; i < n; i++ {
		var command string
		fmt.Scan(&command)
		if strings.Compare(inc, command) == 0 {
			x++
		} else if strings.Compare(dcr, command) == 0 {
			x--
		}
	}
	fmt.Print(x)
}

package main

import (
        "fmt"
)

var fuckMap = map[string]int{
        "X++": 1,
        "++X": 1,
        "X--": -1,
        "--X": -1,
}

func main() {
        var (
                inputnum int
                input    string
        )
        fmt.Scan(&inputnum)
        output := 0
        for i := 0; i < inputnum; i++ {
                fmt.Scanf("%s", &input)
                output += fuckMap[input]
        }
        fmt.Println(output)
}

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

var scanner * bufio.Scanner = bufio.NewScanner(os.Stdin)

func scanInt() int{
    scanner.Scan()
    var i int
    i,_ = strconv.Atoi(scanner.Text())
    return i
}

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

func main(){
    n := scanInt()
    cnt := 0
    for i := 0; i < n; i++ {
        str := scanStr()
        if( str[0:1] == "+" ){
            cnt++
        } else {
            cnt--
        }
    }
    fmt.Println(cnt)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,c int
	var word string
	fmt.Scan(&n)
	c = 0
	for ; n>0; n--{
		fmt.Scanln(&word)

		if (strings.Contains(word, "++")) {
			c++
		} else {
			c--
		}
	}

	fmt.Print(c)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,c int
	var word string
	fmt.Scan(&n)
	c = 0
	for ; n>0; n--{
		fmt.Scanln(&word)

		if strings.Contains(word, "++") {
			c++
		} else {
			c--
		}
	}

	fmt.Print(c)
}

package main
import ("fmt")
func main() {
    var n int
    var s string
    fmt.Scan(&n)
    val:=0
    for i:=0;i<n;i++ {
        fmt.Scan(&s)
        if s=="--X" {
            val--
        } else if s=="++X" {
            val++
        } else if s=="X--" {
            if i==n-1 {
                continue
            } else {
                val--
            }
        } else {
            if i==n-1 {
                continue
            } else {
                val++
            }
        }
    }
    fmt.Println(val)
}

package main

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

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

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	x := 0

	for i := 0; i < n; i++ {
		scanner.Scan()
		op := scanner.Text()

		fmt.Println(op)

		if strings.Contains(op, "++") {
			x++
		} else {
			x--
		}
	}

	fmt.Println(x)
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" {
			initialValue = initialValue - 1
		}

	}

	fmt.Print(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		return scanner.Text()

	}
	return ""
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		}

	}

	fmt.Print(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		return scanner.Text()

	}
	return ""
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		}

	}

	fmt.Print(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return scanner.Text()

}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		}

	}

	fmt.Print(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())

}

package main

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

func main() {
	initialValue, _ := strconv.Atoi(readLine())

	for true {
		commandStr := readLine()
		if commandStr == "X++" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" {
			initialValue = initialValue - 1
		} else {
			fmt.Print(initialValue)
			break
		}

	}
}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		return scanner.Text()

	}
	return ""
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		}

	}

	fmt.Println(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		} else {
			initialValue = -99
		}

	}

	fmt.Println(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

package main

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

func main() {
	values, _ := strconv.Atoi(readLine())

	initialValue := 0

	for i := 0; i < values; i++ {
		commandStr := readLine()
		if commandStr == "X++" || commandStr == "++X" {
			initialValue = initialValue + 1
		} else if commandStr == "--X" || commandStr == "X--" {
			initialValue = initialValue - 1
		} else {
			fmt.Println("Unknown value:" + commandStr)
			initialValue = -99
		}

	}

	fmt.Println(initialValue)

}

func readLine() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}


Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n students able to perform such work. The students realize that they are the only hope of the organizers, so they don't want to work for free: the i-th student wants to get ci 'passes' in his subjects (regardless of the volume of his work).Bugs, like students, are not the same: every bug is characterized by complexity aj, and every student has the level of his abilities bi. Student i can fix a bug j only if the level of his abilities is not less than the complexity of the bug: bi ≥ aj, and he does it in one day. Otherwise, the bug will have to be fixed by another student. Of course, no student can work on a few bugs in one day. All bugs are not dependent on each other, so they can be corrected in any order, and different students can work simultaneously.The university wants to fix all the bugs as quickly as possible, but giving the students the total of not more than s passes. Determine which students to use for that and come up with the schedule of work saying which student should fix which bug.

The first line contains three space-separated integers: n, m and s (1 ≤ n, m ≤ 105, 0 ≤ s ≤ 109) — the number of students, the number of bugs in the system and the maximum number of passes the university is ready to give the students. The next line contains m space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — the bugs' complexities. The next line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109) — the levels of the students' abilities. The next line contains n space-separated integers c1, c2, ..., cn (0 ≤ ci ≤ 109) — the numbers of the passes the students want to get for their help.

If the university can't correct all bugs print "NO". Otherwise, on the first line print "YES", and on the next line print m space-separated integers: the i-th of these numbers should equal the number of the student who corrects the i-th bug in the optimal answer. The bugs should be corrected as quickly as possible (you must spend the minimum number of days), and the total given passes mustn't exceed s. If there are multiple optimal answers, you can output any of them.

NoteConsider the first sample.The third student (with level 3) must fix the 2nd and 4th bugs (complexities 3 and 2 correspondingly) and the second student (with level 1) must fix the 1st and 3rd bugs (their complexity also equals 1). Fixing each bug takes one day for each student, so it takes 2 days to fix all bugs (the students can work in parallel).The second student wants 3 passes for his assistance, the third student wants 6 passes. It meets the university's capabilities as it is ready to give at most 9 passes.

package main

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

type bug struct {
	i, x int
}

type bugs []bug

func (h bugs) Less(i, j int) bool {
	s := []bug(h)
	return s[i].x < s[j].x
}

func (h bugs) Swap(i, j int) {
	s := []bug(h)
	s[i], s[j] = s[j], s[i]
}

func (h bugs) Len() int {
	return len(h)
}

type student struct {
	i, x, c int
}

type students []student

type byC struct{
	students
}

func (h students) Less(i, j int) bool {
	s := []student(h)
	return s[i].x < s[j].x
}

func (h byC) Less(i, j int) bool {
	s := []student(h.students)
	return s[i].c < s[j].c
}

func (h students) Swap(i, j int) {
	s := []student(h)
	s[i], s[j] = s[j], s[i]
}

func (h students) Len() int {
	return len(h)
}

func (h *students) Push(x interface{}) {
	*h = append(*h, x.(student))
}

func (h *students) Pop() interface{} {
	t := (*h)[len(*h) - 1]
	*h = (*h)[:len(*h) - 1]
	return t
}

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

	var n, m, s int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &s)
	a := make([]bug, m)
	b := make([]student, n)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &a[i].x)
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &b[i].x)
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &b[i].c)
	}
	fmt.Fscanf(reader, "\n")

	for i := 0; i < m; i++ {
		a[i].i = i
	}
	for i := 0; i < n; i++ {
		b[i].i = i
	}
	sort.Sort(bugs(a))
	sort.Sort(students(b))

//	fmt.Println(a)
//	fmt.Println(b)

	ans := make([]int, m)
	f := func(d int) bool {
//		fmt.Println()
//		fmt.Println("f", d)
		if d == 0 { return false }
		h := &byC{}
		heap.Init(h)
		i := n
		ss := s
		for j := m - 1; j >= 0; j -= d {
//			fmt.Println(j, i)
			for i > 0 && b[i-1].x >= a[j].x {
				i--
				heap.Push(h, b[i])
//				fmt.Println("push", b[i])
			}
			if h.Len() == 0 { return false }
			minc := heap.Pop(h).(student)
//			fmt.Println("pop", minc)
			ss -= minc.c
//			fmt.Println(j, i, ss)
			if ss < 0 { return false }
			for k := j; k >= 0 && k > j - d; k-- {
				ans[a[k].i] = minc.i
			}
		}
		return true
	}

	k := sort.Search(m + 1, f)
//	fmt.Println(k)

	if k <= m {
		f(k)
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			fmt.Print(ans[i]+1)
			if i + 1 < m {
				fmt.Print(" ")
			} else {
				fmt.Println()
			}
		}
	} else {
		fmt.Println("NO")
	}
}

package main

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

type bug struct {
	i, x int
}

type bugs []bug

func (h bugs) Less(i, j int) bool {
	s := []bug(h)
	return s[i].x < s[j].x
}

func (h bugs) Swap(i, j int) {
	s := []bug(h)
	s[i], s[j] = s[j], s[i]
}

func (h bugs) Len() int {
	return len(h)
}

type student struct {
	i, x, c int
}

type students []student

func (h students) Less(i, j int) bool {
	s := []student(h)
	return s[i].x < s[j].x
}

func (h students) Swap(i, j int) {
	s := []student(h)
	s[i], s[j] = s[j], s[i]
}

func (h students) Len() int {
	return len(h)
}

func (h *students) Push(x interface{}) {
	*h = append(*h, x.(student))
}

func (h *students) Pop() interface{} {
	t := (*h)[len(*h) - 1]
	*h = (*h)[:len(*h) - 1]
	return t
}

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

	var n, m, s int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &s)
	a := make([]bug, m)
	b := make([]student, n)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &a[i].x)
	}
	for i := 0; i < m; i++ {
		a[i].i = i
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &b[i].x)
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &b[i].c)
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < n; i++ {
		b[i].i = i
	}

	sort.Sort(bugs(a))
	sort.Sort(students(b))

//	fmt.Println(a)
//	fmt.Println(b)

	ans := make([]int, m)
	f := func(d int) bool {
//		fmt.Println()
//		fmt.Println("f", d)
		if d == 0 { return false }
		h := &students{}
		heap.Init(h)
		i := n
		ss := s
		for j := m - 1; j >= 0; j -= d {
//			fmt.Println(j, i)
			for i > 0 && b[i-1].x >= a[j].x {
				i--
				heap.Push(h, b[i])
//				fmt.Println("push", b[i])
			}
			if len(*h) == 0 { return false }
			minc := heap.Pop(h).(student)
//			fmt.Println("pop", minc)
			ss -= minc.c
//			fmt.Println(j, i, ss)
			if ss < 0 { return false }
			for k := j; k >= 0 && k > j - d; k-- {
				ans[a[k].i] = minc.i
			}
		}
		return true
	}

	k := sort.Search(m + 1, f)
//	fmt.Println(k)

	if k <= m {
		f(k)
		fmt.Println("YES")
		fmt.Print(ans[0]+1)
		for i := 1; i < m; i++ {
			fmt.Printf(" %d", ans[i]+1)
		}
		fmt.Println()
	} else {
		fmt.Println("NO")
	}
}


You have a card deck of $$$n$$$ cards, numbered from top to bottom, i. e. the top card has index $$$1$$$ and bottom card — index $$$n$$$. Each card has its color: the $$$i$$$-th card has color $$$a_i$$$.You should process $$$q$$$ queries. The $$$j$$$-th query is described by integer $$$t_j$$$. For each query you should:   find the highest card in the deck with color $$$t_j$$$, i. e. the card with minimum index;  print the position of the card you found;  take the card and place it on top of the deck.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le q \le 3 \cdot 10^5$$$) — the number of cards in the deck and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 50$$$) — the colors of cards. The third line contains $$$q$$$ integers $$$t_1, t_2, \dots, t_q$$$ ($$$1 \le t_j \le 50$$$) — the query colors. It's guaranteed that queries ask only colors that are present in the deck.

Print $$$q$$$ integers — the answers for each query.

NoteDescription of the sample:   the deck is $$$[2, 1, 1, 4, \underline{3}, 3, 1]$$$ and the first card with color $$$t_1 = 3$$$ has position $$$5$$$;  the deck is $$$[3, \underline{2}, 1, 1, 4, 3, 1]$$$ and the first card with color $$$t_2 = 2$$$ has position $$$2$$$;  the deck is $$$[2, 3, \underline{1}, 1, 4, 3, 1]$$$ and the first card with color $$$t_3 = 1$$$ has position $$$3$$$;  the deck is $$$[\underline{1}, 2, 3, 1, 4, 3, 1]$$$ and the first card with color $$$t_4 = 1$$$ has position $$$1$$$;  the deck is $$$[1, 2, 3, 1, \underline{4}, 3, 1]$$$ and the first card with color $$$t_5 = 4$$$ has position $$$5$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q, b int
	type card struct{ color, index int }
	Fscan(in, &n, &q)
	colors := [51]bool{}
	cards := make([]card, 0)
	for i := 0; i < n; i++ {
		Fscan(in, &b)
		if !colors[b] {
			colors[b] = true
			cards = append(cards, card{color: b, index: i})
		}
	}
	for i := 0; i < q; i++ {
		Fscan(in, &b)
		for j, c := range cards {
			if c.color == b {
				Fprint(out, c.index+1, " ")
				nextCards := []card{{color: b, index: 0}}
				for k := 0; k < j; k++ {
					cc := cards[k]
					cc.index++
					nextCards = append(nextCards, cc)
				}
				nextCards = append(nextCards, cards[j+1:]...)
				cards = nextCards
				break
			}
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	type pair struct{ v, i int }
	var n, v, q int
	Fscan(in, &n, &q)
	a := []pair{}
	s := [51]bool{}
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		if !s[v] {
			s[v] = true
			a = append(a, pair{v, i})
		}
	}
	for ; q > 0; q-- {
		Fscan(in, &v)
		for i, p := range a {
			if p.v == v {
				Fprint(out, p.i, " ")
				b := []pair{{v, 1}}
				for _, q := range a[:i] {
					b = append(b, pair{q.v, q.i + 1})
				}
				a = append(b, a[i+1:]...)
				break
			}
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ v, i int }
	var n, v, q int
	Fscan(in, &n, &q)
	a := []pair{}
	vis := [51]bool{}
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		if !vis[v] {
			vis[v] = true
			a = append(a, pair{v, i})
		}
	}
	for i := 0; i < q; i++ {
		Fscan(in, &v)
		for j, p := range a {
			if p.v == v {
				Fprint(out, p.i, " ")
				b := []pair{{v, 1}}
				for _, q := range a[:j] {
					b = append(b, pair{q.v, q.i + 1})
				}
				b = append(b, a[j+1:]...)
				a = b
				break
			}
		}
	}
}

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

package main

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

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

	var n, q int
	fmt.Fscan(in, &n, &q)

	aa := make([]int, 50+1)
	for i := range aa {
		aa[i] = -1
	}
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscan(in, &v)
		if aa[v] < 0 {
			aa[v] = i
		}
	}

	for i := 0; i < q; i++ {
		var v int
		fmt.Fscan(in, &v)

		fmt.Fprintf(out, "%d ", aa[v]+1)
		for i, k := range aa {
			if k < 0 || k >= aa[v] {
				continue
			}
			aa[i]++
		}
		aa[v] = 0
	}
	fmt.Fprintln(out)

}

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	type pair struct {
		first  int
		second int
	}
	solve := func() {
		var n, q int
		fmt.Fscan(in, &n, &q)
		vis := make([]int, 50)
		var a []pair
		for i := 0; i < n; i++ {
			var t int
			fmt.Fscan(in, &t)
			t--
			if vis[t] == 0 {
				vis[t] = 1
				a = append(a, pair{t, i})
			}
		}
		for ; q > 0; q-- {
			var t int
			fmt.Fscan(in, &t)
			t--
			for i := 0; i < len(a); i++ {
				if a[i].first == t {
					fmt.Fprint(out, a[i].second+1, " ")
					o := a[i]
					o.second = 0
					a = append(a[:i], a[i+1:]...)
					a = append([]pair{o}, a...)
					break
				}
				a[i].second++
			}

		}
		fmt.Fprintln(out)

	}

	T := 1
	//fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	N := sc.NextInt()
	Q := sc.NextInt()
	arr := sc.NextInts(N)

	minIdx := make([]int, 55)
	for i := 0; i < 55; i++ {
		minIdx[i] = -1
	}
	for i := 0; i < N; i++ {
		if minIdx[arr[i]] == -1 {
			minIdx[arr[i]] = i
		}
	}

	for i := 0; i < Q; i++ {
		t := sc.NextInt()
		fmt.Fprint(wr, minIdx[t]+1, " ")
		for j := 0; j < 55; j++ {
			if minIdx[j] < minIdx[t] {
				minIdx[j]++
			}
		}
		minIdx[t] = 0
	}
	fmt.Fprintln(wr)

}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

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

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

	var n, q int
	fmt.Fscan(input, &n)
	fmt.Fscan(input, &q)

	ARRAY := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		fmt.Fscan(input, &ARRAY[i])
	}
	ANOTHER := make([]int, 51)
	for i := n; i > 0; i-- {
		ANOTHER[ARRAY[i]] = i
	}
	// fmt.Println(ANOTHER)
	for j := 0; j < q; j++ {
		var TJ int
		fmt.Fscan(input, &TJ)
		fmt.Println(ANOTHER[TJ])
		w := ANOTHER[TJ]
		for i := 1; i < 51; i++ {
			if i == TJ {
				ANOTHER[i] = 1
			} else {
				if ANOTHER[i] != 0 && ANOTHER[i] < w {
					ANOTHER[i]++
				}
			}
		}
		// fmt.Println(ANOTHER)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q, b int
	type card struct{ color, index int }
	Fscan(in, &n, &q)
	colors := [51]bool{}
	cards := make([]card, 0)
	for i := 0; i < n; i++ {
		Fscan(in, &b)
		if !colors[b] {
			colors[b] = true
			cards = append(cards, card{color: b, index: i})
		}
	}
	for i := 0; i < q; i++ {
		Fscan(in, &b)
		fmt.Printf("%+v\n", cards)
		for j, c := range cards {
			if c.color == b {
				Fprint(out, c.index+1, " ")
				nextCards := []card{{color: b, index: 0}}
				for k := 0; k < j; k++ {
					cc := cards[k]
					cc.index++
					nextCards = append(nextCards, cc)
				}
				nextCards = append(nextCards, cards[j+1:]...)
				cards = nextCards
				break
			}
		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q, b int
	Fscan(in, &n, &q)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &b)
		cards[i] = b
	}
	for i := 0; i < q; i++ {
		Fscan(in, &b)
		idx := -1
		for j, card := range cards {
			if b == card {
				Fprint(out, idx+1, " ")
				idx = j
				ncards := []int{card}
				ncards = append(ncards, cards[:idx]...)
				cards = append(ncards, cards[idx+1:]...)
				break
			}
		}
	}
}


An array is beautiful if both of the following two conditions meet:  there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum;  there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$$$ elements equal to its minimum ($$$1$$$-st, $$$3$$$-rd and $$$7$$$-th) and $$$2$$$ elements equal to its maximum ($$$4$$$-th and $$$5$$$-th).Another example: the array $$$[42, 42, 42]$$$ has $$$3$$$ elements equal to its minimum and $$$3$$$ elements equal to its maximum.Your task is to calculate the minimum possible number of elements in a beautiful array.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case consists of one line containing four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 \le l_1 \le r_1 \le 50$$$; $$$1 \le l_2 \le r_2 \le 50$$$).

For each test case, print one integer — the minimum possible number of elements in a beautiful array.

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)

		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else if a >=c && a <= d{
			fmt.Fprintln(out,a)
		} else if b >= c && b <= d {
			fmt.Fprintln(out,c)
		} else if d >= a && d <= b {
			fmt.Fprintln(out,a)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

package main

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

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

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 l1, r1, l2, r2 int
		fmt.Fscan(in, &l1, &r1, &l2, &r2)

		if l2 <= r1 && l2 >= l1 || l1 >= l2 && l1 <= r2 {
			fmt.Fprintln(out, max(l1, l2))
		} else {
			fmt.Fprintln(out, l1+l2)
		}
	}
}

package main

//we need to know where to start execution of the code
//print("hello")
import (
	"fmt"
)

// start execu from main zy c++
func main() {

	var t, l1, l2, r1, r2 int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&l1, &r1, &l2, &r2)
		if (l2 >= l1 && l2 <= r1) || (l1 >= l2 && l1 <= r2) {
			if l1 >= l2 {
				fmt.Printf("%v\n", l1)
			} else {
				fmt.Printf("%v\n", l2)
			}
		} else {
			fmt.Printf("%v\n", l1+l2)
		}
	}

}

package main

import ("fmt"
"math")

func main() {

	var t, l1, l2, r1, r2 int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&l1,&r1,&l2,&r2)
		if (l2>=l1 && l2<=r1) || (l1>=l2 && l1<=r2) {
			fmt.Println(math.Max(float64(l1),float64(l2)))
		}else {
			fmt.Printf("%v\n",l1+l2)
		}
	}

}

package main

import (
	"fmt"
)

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

func main() {
	var t int
	fmt.Scanf("%d\n",&t)
	for ; t > 0; t-- {
		var l1, l2, r1, r2 int
		fmt.Scanf("%d %d %d %d\n", &l1, &r1, &l2, &r2)
		if l1 >= l2 && l1 <= r2 {
			fmt.Println(l1)
		} else if l2 >= l1 && l2 <= r1 {
			fmt.Println(l2)
		} else {
			fmt.Println(min(l1, r1)+min(l2, r2))
		}
	}
}

package main

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

var (
	n int
)

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

	Fscan(in, &n)
	for ; n > 0; n-- {
		var l1, r1, l2, r2 int
		Fscan(in, &l1, &r1, &l2, &r2)
		if l2 >= l1 && l2 <= r1 {
			Fprintln(out, l2)
		} else if l1 >= l2 && l1 <= r2 {
			Fprintln(out, l1)
		} else {
			Fprintln(out, l1 + l2)
		}
	}

}

func min(a, b int) int { if a > b { return b }; return a }
func max(a, b int) int { if a < b { return b }; return a }
func abs(v int) int { if v > 0 { return v }; return -v }
func gcd(a, b int) int { if b > 0 { return gcd(b, a % b) }; return a }
func lcm(a, b int) int { return a * b / gcd(a, b) }

package main

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

func acc(op func(int64, int64) int64, c ...int64) int64 {
	res := c[0]
	for _, i := range c {
		res = op(res, i)
	}
	return res
}

func max(c ...int64) int64 {
	return acc(func(a int64, b int64) int64 {
		if a < b {
			return b
		}
		return a
	}, c...)
}

func min(c ...int64) int64 {
	return acc(func(a int64, b int64) int64 {
		if a > b {
			return b
		}
		return a
	}, c...)
}

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

func solve(inout io.ReadWriter) {
	scan := func(inp ...interface{}) {
		fmt.Fscan(inout, inp...)
	}
	printf := func(format string, outp ...interface{}) {
		fmt.Fprintf(inout, format, outp...)
	}

	var l1, r1, l2, r2 int
	scan(&l1, &r1, &l2, &r2)

	if r2 < l1 || r1 < l2 {
		printf("%d\n", l1+l2)
	} else {
		printf("%d\n", max(int64(l1), int64(l2)))
	}

}

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

	var T int = 1
	fmt.Fscan(inout, &T)
	for ; T > 0; T-- {
		solve(inout)
	}
}

package main

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

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

	var l1, r1, l2, r2 int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &l1)
		fmt.Fscan(in, &r1)
		fmt.Fscan(in, &l2)
		fmt.Fscan(in, &r2)

		if l1 <= r2 && l2 <= r1 {
			fmt.Println(max(l1, l2))
		} else {
			fmt.Println(l1 + l2)
		}
	}
}

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

package main

import (
	"fmt"
	"math"
)
func main() {
	TC := new(int)
	fmt.Scan(TC)
	for (*TC) > 0 {
		var l1, l2, r1, r2 int
		fmt.Scan(&l1)
		fmt.Scan(&r1)
		fmt.Scan(&l2)
		fmt.Scan(&r2)
//		fmt.Println(l1, l2, r1, r2)
		if (l1 <= l2 && l2 <= r1) || (l1 >= l2 && l1 <= r2) {
			result := math.Max(float64(l1), float64(l2))
			fmt.Println(result)
			*TC -= 1
			continue
		}
		fmt.Println(l1 + l2)
		*TC -= 1
	}
}

package main

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

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

func (in *CF1680A) 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 *CF1680A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1680A
Date: 20/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1680/A
Problem: CF1680A
**/
func (in *CF1680A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		l1, r1, l2, r2 := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()

		if r1 < l2  || r2 < l1{
			fmt.Println(l1 + l2)

		} else {
			fmt.Println(int(math.Max(float64(l1), float64(l2))))
		}

	}
}

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

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

package main

import "fmt"

func solve(lmin, rmin, lmax, rmax int) int {
	if rmin < lmax || rmax < lmin {
		return lmin + lmax
	}
	if lmin > lmax {
		return lmin
	}
	return lmax
}

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

	for test > 0 {
		test--
		var lmin, rmin, lmax, rmax int
		fmt.Scanln(&lmin, &rmin, &lmax, &rmax)
		fmt.Println(solve(lmin, rmin, lmax, rmax))
	}
}

package main

import (
	"fmt"
)

func max(a uint, b uint) uint {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	var t uint
	fmt.Scanln(&t)
	for t > 0 {
		var l1 uint
		var l2 uint
		var r1 uint
		var r2 uint
		fmt.Scanln(&l1, &r1, &l2, &r2)
		if l2 <= r1 && l1 <= r2 {
			fmt.Println(max(l1, l2))
		} else {
			fmt.Println(l1 + l2)
		}
		t = t - 1
	}

}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		l1, _ := strconv.Atoi(ninps[0])
                r1, _ := strconv.Atoi(ninps[1])
		l2, _ := strconv.Atoi(ninps[2])
		r2, _ := strconv.Atoi(ninps[3])

		if l1 >= l2 && l1 <= r2 {
			fmt.Println(l1)
		} else if l2 >= l1 && l2 <= r1 {
			fmt.Println(l2)
		} else {
			fmt.Println(l1+l2)
		}
	}
}

package main

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

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

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

	var T int
	var l int
	var r int
	var a int
	var b int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &l)
		Fscan(in, &r)
		Fscan(in, &a)
		Fscan(in, &b)

		ans := 0
		if l <= a {
			if a <= r {
				ans = a
			} else {
				ans = l + a
			}
		} else {
			if b < l {
				ans = a + l
			} else {
				ans = l
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var l1, l2, r1, r2 int
		Fscan(in, &l1, &r1, &l2, &r2)

		if l1 > l2 {
			l1, r1, l2, r2 = l2, r2, l1, r1
		}

		if l2 <= r1 {
			Fprintln(out, l2)
		} else {
			Fprintln(out, l1+l2)
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

package main

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

func main_edu_128_A() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var l1, l2, r1, r2 int
		Fscan(in, &l1, &r1, &l2, &r2)
		if l1 > l2 {
			l1, r1, l2, r2 = l2, r2, l1, r1
		}
		if l1 == l2 {
			Fprintln(out, l1)
			return
		}
		if r1 < l2 {
			Fprintln(out, l1+l2)
			return
		}
		Fprintln(out, l2)

	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_edu_128_A()
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func slove() {
	var l1, r1, l2, r2 int
	fmt.Fscan(r, &l1, &r1)
	fmt.Fscan(r, &l2, &r2)
	ans := 100
	if l1 >= l2 && l1 <= r2 {
		ans = min(ans, l1)
	}
	if l2 >= l1 && l2 <= r1 {
		ans = min(ans, l2)
	}
	ans = min(l1 + l2, ans)
	fmt.Fprintln(w, ans)
}

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

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)

		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else if d >= a && d <= b {
			fmt.Fprintln(out,a)
		} else if b >= c && b <= d {
			fmt.Fprintln(out,c)
		} else if a >=c && a <= d{
			fmt.Fprintln(out,a)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)
		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else if d >= a && d <= b {
			fmt.Fprintln(out,d)
		} else if b >= c && b <= d {
			fmt.Fprintln(out,b)
		} else if a >= c && a <= d{
			fmt.Fprintln(out,a)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)
		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else if d >= a && d <= b {
			fmt.Fprintln(out,d)
		} else if b >= c && b <= d {
			fmt.Fprintln(out,b)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)
		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else if d >= a && d <= b {
			fmt.Fprintln(out,d)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

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,d int
		fmt.Fscan(in,&a,&b,&c,&d)
		if c >= a && c <= b {
			fmt.Fprintln(out,c)
		} else {
			fmt.Fprintln(out,c+a)
		}
	}
}

package main

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

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

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 l1, r1, l2, r2 int
		fmt.Fscan(in, &l1, &r1, &l2, &r2)

		if l2 >= l1 && l2 <= r1 || r1 >= l2 && r1 <= r2 {
			fmt.Fprintln(out, min(l2, r1))
		} else {
			fmt.Fprintln(out, l1+l2)
		}
	}
}

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 l1, r1, l2, r2 int
		fmt.Fscan(in, &l1, &r1, &l2, &r2)

		if l2 >= l1 && l2 <= r1 {
			fmt.Fprintln(out, l2)
		} else {
			fmt.Fprintln(out, l1+l2)
		}
	}
}

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 l1, r1, l2, r2 int
		fmt.Fscan(in, &l1, &r1, &l2, &r2)

		if l2 >= l1 && l2 <= r1 {
			fmt.Fprintln(out, l2)
		} else {
			fmt.Fprintln(out, r1+l2)
		}
	}
}

package main

//we need to know where to start execution of the code
//print("hello")
import (
	"fmt"
)

// start execu from main zy c++
func main() {

	var t, l1, l2, r1, r2 int8
	fmt.Scan(&t)
	for i := 0; i < int(t); i++ {
		fmt.Scan(&l1, &r1, &l2, &r2)
		if (l2 >= l1 && l2 <= r1) || (l1 >= l2 && l1 <= r2) {
			if l1 >= l2 {
				fmt.Printf("%v\n", l1)
			} else {
				fmt.Printf("%v\n", l2)
			}
		} else {
			fmt.Printf("%v\n", l1+l2)
		}
	}

}

package main

import (
	"fmt"
)

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

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var l1, l2, r1, r2 int
		fmt.Scanf("%d %d %d %d\n", &l1, &r1, &l2, &r2)
		l := max(l1, r1)
		r := min(l2, r2)
		if l < r || l1 > r2 {
			fmt.Println(min(l1, r1)+r)
		} else {
			fmt.Println(r)
		}
	}
}

package main

import (
	"fmt"
)

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

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

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var l1, l2, r1, r2 int
		fmt.Scanf("%d %d %d %d\n", &l1, &r1, &l2, &r2)
		l := max(l1, r1)
		r := min(l2, r2)
		if l < r || l1 > r2 {
			fmt.Println(min(l1, r1)+r)
		} else {
			fmt.Println(r)
		}
	}
}

package main

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

var (
	n int
)

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

	Fscan(in, &n)
	for ; n > 0; n-- {
		var l1, r1, l2, r2 int
		Fscan(in, &l1, &r1, &l2, &r2)
		if l2 >= l1 && l2 <= r1 {
			Fprintln(out, l2)
		} else if l1 < l2 && r2 < r1 {
			Fprintln(out, min(l1 + l2, r1))
		} else {
			Fprintln(out, l2 + l1)
		}
	}

}

func min(a, b int) int { if a > b { return b }; return a }
func max(a, b int) int { if a < b { return b }; return a }
func abs(v int) int { if v > 0 { return v }; return -v }
func gcd(a, b int) int { if b > 0 { return gcd(b, a % b) }; return a }
func lcm(a, b int) int { return a * b / gcd(a, b) }

package main

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

var (
	n int
)

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

	Fscan(in, &n)
	for ; n > 0; n-- {
		var l1, r1, l2, r2 int
		Fscan(in, &l1, &r1, &l2, &r2)
		// if l2 >= l1 && l2 <= r1 {
		// 	Fprintln(out, l2)
		// } else if l2 > r1 {
		// 	Fprintln(out, l2 + l1)
		// } else if l2 < l1 {
		// 	Fprintln(out, l2 + l1)
		// }
		if l2 >= l1 && l2 <= r1 {
			Fprintln(out, l2)
		} else {
			Fprintln(out, l2 + l1)
		}
	}

}

func min(a, b int) int { if a > b { return b }; return a }
func max(a, b int) int { if a < b { return b }; return a }
func abs(v int) int { if v > 0 { return v }; return -v }
func gcd(a, b int) int { if b > 0 { return gcd(b, a % b) }; return a }
func lcm(a, b int) int { return a * b / gcd(a, b) }

package main

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

func acc(op func(int64, int64) int64, c ...int64) int64 {
	res := c[0]
	for _, i := range c {
		res = op(res, i)
	}
	return res
}

func max(c ...int64) int64 {
	return acc(func(a int64, b int64) int64 {
		if a < b {
			return b
		}
		return a
	}, c...)
}

func min(c ...int64) int64 {
	return acc(func(a int64, b int64) int64 {
		if a > b {
			return b
		}
		return a
	}, c...)
}

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

func solve(inout io.ReadWriter) {
	scan := func(inp ...interface{}) {
		fmt.Fscan(inout, inp...)
	}
	printf := func(format string, outp ...interface{}) {
		fmt.Fprintf(inout, format, outp...)
	}

	var l1, r1, l2, r2 int
	scan(l1, r1, l2, r2)

	if r2 < l1 || r1 < l2 {
		printf("%d\n", l1+l2)
	} else {
		printf("%d\n", max(int64(l1), int64(l2)))
	}

}

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

	var T int = 1
	fmt.Fscan(inout, &T)
	for ; T > 0; T-- {
		solve(inout)
	}
}


You are given an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are pairwise distinct.Let's define function $$$f(l, r)$$$ as follows:   let's define array $$$b_1, b_2, \dots, b_{r - l + 1}$$$, where $$$b_i = a_{l - 1 + i}$$$;  sort array $$$b$$$ in increasing order;  result of the function $$$f(l, r)$$$ is $$$\sum\limits_{i = 1}^{r - l + 1}{b_i \cdot i}$$$. Calculate $$$\left(\sum\limits_{1 \le l \le r \le n}{f(l, r)}\right) \mod (10^9+7)$$$, i.e. total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$) — array $$$a$$$.

Print one integer — the total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
)
const(
    mod int = 1e9 + 7
    N = 5e5 + 100
)
type per []int
var a []int

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

func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(in, &n)
    a = make([]int, n + 1)
    leftsum := make([]int, n + 1)
    rightsum := make([]int, n + 1)
    p := make([]int, n + 1)
    update := func(idx int) {
        l := idx
        val := idx
        for l <= n {
            leftsum[l] += val
            leftsum[l] %= mod
            l += l & -l
        }
        r := idx
        val = n - idx + 1
        for r > 0 {
            rightsum[r] += val
            rightsum[r] %= mod
            r -= r & -r
        }
    }
    query := func(idx int) int{
        l := idx
        lftsum := 0
        for l > 0{
            lftsum += leftsum[l]
            lftsum %= mod
            l -= l & -l
        }
        r := idx + 1
        rghtsum := 0
        for r <= n {
            rghtsum += rightsum[r]
            rghtsum %= mod
            r += r & -r
        }
        return (int(int64(lftsum) * int64(n - idx + 1) % int64(mod)) + int(int64(rghtsum) * int64(idx) % int64(mod))) % mod
    }
    for i := 1; i <= n; i++ {
        fmt.Fscan(in, &a[i])
        p[i] = i
    }
    sort.Sort(per(p[1:]))
    ans := 0
    for i := 1; i <= n; i++ {
        update(p[i])
        ans += int(int64(a[p[i]]) * int64(query(p[i])) % int64(mod))
        ans %= mod
    }
    fmt.Println(ans)
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
)
const(
    mod int = 1e9 + 7
    N = 5e5 + 100
)
type per []int
var a []int

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

func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(in, &n)
    a = make([]int, n + 1)
    leftsum := make([]int, n + 1)
    rightsum := make([]int, n + 1)
    p := make([]int, n + 1)
    update := func(idx int) {
        l := idx
        val := idx
        for l <= n {
            leftsum[l] += val
            l += l & -l
        }
        r := idx
        val = n - idx + 1
        for r > 0 {
            rightsum[r] += val
            r -= r & -r
        }
    }
    query := func(idx int) int{
        l := idx
        lftsum := 0
        for l > 0{
            lftsum += leftsum[l]
            lftsum %= mod
            l -= l & -l
        }
        r := idx + 1
        rghtsum := 0
        for r <= n {
            rghtsum += rightsum[r]
            rghtsum %= mod
            r += r & -r
        }
        return (int(int64(lftsum) * int64(n - idx + 1) % int64(mod)) + int(int64(rghtsum) * int64(idx) % int64(mod))) % mod
    }
    for i := 1; i <= n; i++ {
        fmt.Fscan(in, &a[i])
        p[i] = i
    }
    sort.Sort(per(p[1:]))
    ans := 0
    for i := 1; i <= n; i++ {
        update(p[i])
        ans += int(int64(a[p[i]]) * int64(query(p[i])) % int64(mod))
        ans %= mod
    }
    fmt.Println(ans)
}


There is a new attraction in Singapore Zoo: The Infinite Zoo.The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled $$$1,2,3,\ldots$$$. There is a directed edge from vertex $$$u$$$ to vertex $$$u+v$$$ if and only if $$$u\&v=v$$$, where $$$\&$$$ denotes the bitwise AND operation. There are no other edges in the graph.Zookeeper has $$$q$$$ queries. In the $$$i$$$-th query she will ask you if she can travel from vertex $$$u_i$$$ to vertex $$$v_i$$$ by going through directed edges.

The first line contains an integer $$$q$$$ ($$$1 \leq q \leq 10^5$$$) — the number of queries. The $$$i$$$-th of the next $$$q$$$ lines will contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i < 2^{30}$$$) — a query made by Zookeeper.

For the $$$i$$$-th of the $$$q$$$ queries, output "YES" in a single line if Zookeeper can travel from vertex $$$u_i$$$ to vertex $$$v_i$$$. Otherwise, output "NO". You can print your answer in any case. For example, if the answer is "YES", then the output "Yes" or "yeS" will also be considered as correct answer.

NoteThe subgraph on vertices $$$1,2,3,4,5,6$$$ is shown below.

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	a := 0
	for _, num := range scanner.Bytes() {
		a = a*10 + int(num-'0')
	}
	return a
}
func check(u, v int) bool {
	if u > v {
		return false
	}
	cnt := 0
	for i := 0; i < 30; i++ {
		cnt += u & 1
		cnt -= v & 1
		if cnt < 0 {
			return false
		}
		u >>= 1
		v >>= 1
	}
	return true
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1024*1024*4), 1024*1024*4)

	q := scanInt(scanner)
	fmt.Scanf("%d\n", &q)
	for ; q > 0; q-- {
		u, v := scanInt(scanner), scanInt(scanner)
		if check(u, v) {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	a := 0
	for _, num := range scanner.Bytes() {
		a = a*10 + int(num-'0')
	}
	return a
}
func check(u, v int) bool {
	if u > v {
		return false
	}
	cnt := 0
	for i := 0; i < 30; i++ {
		cnt += u & 1
		cnt -= v & 1
		if cnt < 0 {
			return false
		}
		u >>= 1
		v >>= 1
	}
	return true
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1024*1024*128), 1024*1024*128)

	q := scanInt(scanner)
	fmt.Scanf("%d\n", &q)
	for ; q > 0; q-- {
		u, v := scanInt(scanner), scanInt(scanner)
		if check(u, v) {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1491D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var q, v, w int
o:
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &v, &w)
		if v > w {
			Fprintln(out, "NO")
			continue
		}
		for i, c := 0, 0; i < 30; i++ {
			c += v>>i&1 - w>>i&1
			if c < 0 {
				Fprintln(out, "NO")
				continue o
			}
		}
		Fprintln(out, "YES")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var q, v, w int
o:
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &v, &w)
		if v > w {
			Fprintln(out, "NO")
			continue
		}
		for c := 0; w > 0; w >>= 1 {
			c += v&1 - w&1
			if c < 0 {
				Fprintln(out, "NO")
				continue o
			}
			v >>= 1
		}
		Fprintln(out, "YES")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var q, v, w int
o:
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &v, &w)
		if v > w {
			Fprintln(out, "NO")
			continue
		}
		for i, c := 0, 0; i < 30; i++ {
			c += v>>i&1 - w>>i&1
			if c < 0 {
				Fprintln(out, "NO")
				continue o
			}
		}
		Fprintln(out, "YES")
	}
}

package main

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

const maxlog = 30

func min(v ...int) int {
	res := v[0]
	for _, x := range v {
		if x < res {
			res = x
		}
	}
	return res
}

func next1(num, from int) int {
	for i := from; i >= 0; i-- {
		if num&(1<<i) != 0 {
			return i
		}
	}
	return -1
}

/*
	01111001101
	10011110100
*/

func ok(from, to int) bool {
	if from > to {
		return false
	}

	i, j := maxlog-1, maxlog-1
	for {
		j = next1(to, j)
		if j == -1 {
			break
		}

		i = next1(from, i)
		for i > j {
			i--
			i = next1(from, i)
		}

		if i == -1 {
			return false
		}

		j--
		i--
	}

	return true
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		var q int
		scan(&q)
		for i := 0; i < q; i++ {
			var u, v int
			scan(&u, &v)
			if ok(u, v) {
				printf("YES\n")
			} else {
				printf("NO\n")
			}
		}
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		printf("%s\n", sol(sint64(), sint64()))
	}
}

func sol(u, v int64) string {
	ub := bits(u)
	vb := bits(v)
	if len(vb) > len(ub) {
		return "NO"
	}
	if u > v {
		return "NO"
	}
	for i := range vb {
		if ub[i] > vb[i] {
			return "NO"
		}
	}
	return "YES"
}

func bits(x int64) []int64 {
	ret := []int64{}
	for i := int64(0); i < 100; i++ {
		if 1<<i > x {
			break
		}
		if (1<<i)&x != 0 {
			ret = append(ret, i)
		}
	}
	return ret
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	a := 0
	for _, num := range scanner.Bytes() {
		a = a*10 + int(num-'0')
	}
	return a
}
func check(u, v int) bool {
	if u > v {
		return false
	}
	cnt := 0
	for i := 0; i < 30; i++ {
		cnt += u & 1
		cnt -= v & 1
		if cnt < 0 {
			return false
		}
		u >>= 1
		v >>= 1
	}
	return true
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	q := scanInt(scanner)
	fmt.Scanf("%d\n", &q)
	for ; q > 0; q-- {
		u, v := scanInt(scanner), scanInt(scanner)
		if check(u, v) {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	a := 0
	for _, num := range scanner.Bytes() {
		a = a*10 + int(num-'0')
	}
	return a
}
func check(u, v int) bool {
	if u > v {
		return false
	}
	cnt := 0
	for i := 0; i < 30; i++ {
		cnt += u & 1
		cnt -= v & 1
		if cnt < 0 {
			return false
		}
		u >>= 1
		v >>= 1
	}
	return true
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1024*1024), 1024*1024)

	q := scanInt(scanner)
	fmt.Scanf("%d\n", &q)
	for ; q > 0; q-- {
		u, v := scanInt(scanner), scanInt(scanner)
		if check(u, v) {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

import (
	"fmt"
)

func check(u, v int) bool {
	if u > v {
		return false
	}
	cnt := 0
	for i := 0; i < 30; i++ {
		cnt += u & 1
		cnt -= v & 1
		if cnt < 0 {
			return false
		}
		u >>= 1
		v >>= 1
	}
	return true
}
func main() {
	var q, u, v int
	fmt.Scanf("%d", &q)
	for ; q > 0; q-- {
		fmt.Scanf("%d %d", &u, &v)
		if check(u, v) {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var q int
	var v, w uint
	Fscan(in, &q)
	for i := 1; i <= q; i++ {
		Fscan(in, &v, &w)
		if q > 10 && i != 1589 {
			continue
		}
		if q > 10 {
			Fprintln(out, v, w)
		}
		if v <= w && bits.OnesCount(v) >= bits.OnesCount(w) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var q, v, w uint
	for Fscan(in, &q); q > 0; q-- {
		if Fscan(in, &v, &w); v <= w && bits.OnesCount(v) >= bits.OnesCount(w) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

func solveD(queries [][2]int) {
	ok := func(a, b int) bool {
		i := 29
		for j := 29; j >= 0; j-- {
			if b&(1<<j) == 0 {
				continue
			}

			for ; i >= 0 && a&(1<<i) == 0; i-- {
			}

			if i == -1 || i > j {
				return false
			}
			i--
		}
		return true
	}

	for _, q := range queries {
		u, v := q[0], q[1]
		if ok(u, v) {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		var q int
		scan(&q)
		queries := make([][2]int, q)
		for i := range queries {
			for j := 0; j < 2; j++ {
				scan(&queries[i][j])
			}
		}
		solveD(queries)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}