Alice and Bob are playing a game with strings. There will be $$$t$$$ rounds in the game. In each round, there will be a string $$$s$$$ consisting of lowercase English letters. Alice moves first and both the players take alternate turns. Alice is allowed to remove any substring of even length (possibly empty) and Bob is allowed to remove any substring of odd length from $$$s$$$.More formally, if there was a string $$$s = s_1s_2 \ldots s_k$$$ the player can choose a substring $$$s_ls_{l+1} \ldots s_{r-1}s_r$$$ with length of corresponding parity and remove it. After that the string will become $$$s = s_1 \ldots s_{l-1}s_{r+1} \ldots s_k$$$.After the string becomes empty, the round ends and each player calculates his/her score for this round. The score of a player is the sum of values of all characters removed by him/her. The value of $$$\texttt{a}$$$ is $$$1$$$, the value of $$$\texttt{b}$$$ is $$$2$$$, the value of $$$\texttt{c}$$$ is $$$3$$$, $$$\ldots$$$, and the value of $$$\texttt{z}$$$ is $$$26$$$. The player with higher score wins the round. For each round, determine the winner and the difference between winner's and loser's scores. Assume that both players play optimally to maximize their score. It can be proved that a draw is impossible.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 5\cdot 10^4$$$) denoting the number of rounds. Each of the next $$$t$$$ lines contain a single string $$$s$$$ ($$$1\leq |s|\leq 2\cdot 10^5$$$) consisting of lowercase English letters, denoting the string used for the round. Here $$$|s|$$$ denotes the length of the string $$$s$$$. It is guaranteed that the sum of $$$|s|$$$ over all rounds does not exceed $$$2\cdot 10^5$$$.

For each round, print a single line containing a string and an integer. If Alice wins the round, the string must be "Alice". If Bob wins the round, the string must be "Bob". The integer must be the difference between their scores assuming both players play optimally.

NoteFor the first round, $$$\texttt{"aba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{ab}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$$$. Alice's total score is $$$1+2=3$$$. Bob's total score is $$$1$$$.For the second round, $$$\texttt{"abc"}\xrightarrow{\texttt{Alice}}\texttt{"a}{\color{red}{\texttt{bc}}}\texttt{"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$$$. Alice's total score is $$$2+3=5$$$. Bob's total score is $$$1$$$.For the third round, $$$\texttt{"cba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{cb}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$$$. Alice's total score is $$$3+2=5$$$. Bob's total score is $$$1$$$.For the fourth round, $$$\texttt{"n"}\xrightarrow{\texttt{Alice}}\texttt{"n"}\xrightarrow{} \texttt{"n"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{n}}}\texttt{"}\xrightarrow{}\texttt{""}$$$. Alice's total score is $$$0$$$. Bob's total score is $$$14$$$.For the fifth round, $$$\texttt{"codeforces"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{codeforces}}}\texttt{"}\xrightarrow{} \texttt{""}$$$. Alice's total score is $$$3+15+4+5+6+15+18+3+5+19=93$$$. Bob's total score is $$$0$$$.

package main

import (
	"fmt"
)

func min(x, y byte) byte {
	if x < y {
		return x
	}

	return y
}

func solve() {
	var s string
	fmt.Scan(&s)

	alice := 0
	for i := range s {
		alice += int(s[i] - 'a' + 1)
	}

	n := len(s)
	bob := 0
	if n % 2 != 0 {
		x := int(min(s[0] - 'a' + 1, s[n - 1] - 'a' + 1))

		alice -= x
		bob += x
	}

	if alice > bob {
		fmt.Printf("Alice %d\n", alice - bob)
	} else {
		fmt.Printf("Bob %d\n", bob - alice)
	}
}

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

	for t > 0 {
		solve()
		t--
	}
}

package main

import (
	"fmt"
	"math"
)

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func solve() {
	var s string
	fmt.Scan(&s)

	n := len(s)

	alice := 0
	for i := range s {
		alice += int(s[i] - 'a' + 1)
	}

	bob := 0
	if n % 2 != 0 {
		x := min(int(s[0] - 'a' + 1), int(s[n - 1] - 'a' + 1))
		alice -= x
		bob += x
	}

	diff := int(math.Abs(float64(alice - bob)))
	if alice > bob {
		fmt.Printf("Alice %d\n", diff)
	} else {
		fmt.Printf("Bob %d\n", diff)
	}
}

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

	for t > 0 {
		solve()
		t--
	}
}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		n := len(s)
		ans := 0
		for i := 0; i < n; i++ {
	               	ans += (int(rune(s[i]))-96)
		}

		if n & 1 == 0 {
			fmt.Println("Alice", ans)
		} else {
		      	if n == 1 {
	                	fmt.Println("Bob", (int(rune(s[0]))-96))
			} else {
				a := ans - ( int(rune(s[0])) - 96 )
				b := ans - ( int(rune(s[(n-1)])) - 96 )
				if a < b {
					a = b
				}
				c := ans - a
				if a > c {
					fmt.Println("Alice", (a-c))
				} else {
					fmt.Println("Bob", (c-a))
				}
			}
		}
	}
}

package main

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

func min(lhs, rhs int) int {
	if lhs < rhs {
		return lhs
	}
	return rhs
}

func point(b byte) int {
	return int(b-'a') + 1
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		total := 0
		s, _ := reader.ReadString('\n')
		s = strings.TrimSpace(s)
		for i := range s {
			total = total + point(s[i])
		}
		if len(s)%2 == 0 {
			fmt.Printf("Alice %v\n", total)
		} else {
			a := total - min(point(s[0]), point(s[len(s)-1]))
			b := total - a
			if a < b {
				fmt.Printf("Bob %v\n", b-a)
			} else {
				fmt.Printf("Alice %v\n", a-b)
			}
		}
	}
}

package main

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

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

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

	t := 0
	str := ""
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &str)
		sum := 0
		for _, ch := range str {
			sum += int(ch - 'a' + 1)
		}
		if len(str)%2 == 0 {
			fmt.Fprintln(out, "Alice ", sum)
		} else if len(str) == 1 {
			fmt.Fprintln(out, "Bob ", sum)
		} else {
			diff := max(sum-int(str[0]-'a'+1)-int(str[0]-'a'+1), sum-int(str[len(str)-1]-'a'+1)-int(str[len(str)-1]-'a'+1))
			if diff < 0 {
				fmt.Fprintln(out, "Bob ", diff)
			} else {
				fmt.Fprintln(out, "Alice", diff)
			}
		}
	}
}

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

package main

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

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var a string
		fmt.Fscan(in, &a)
		var ans int = 0
		for _, c := range a {
			ans += int(c - 'a' + 1)
		}
		if len(a) == 1 {
			fmt.Fprintln(out, "Bob", ans)
		} else if len(a)%2 == 0 {
			fmt.Fprintln(out, "Alice", ans)
		} else {
			b := min(int(a[len(a)-1]-'a'+1), int(a[0]-'a'+1))
			al := ans - b
			fmt.Fprintln(out, "Alice", al-b)
		}
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < int(testCases); i++ {
		var str string
		fmt.Scanf("%s\n", &str)
		total := 0
		for _, c := range str {
			total += (int(c - 'a')) + 1
		}
		if len(str)%2 == 0 {
			fmt.Println("Alice", total)
			continue
		}
		if len(str) == 1 {
			fmt.Println("Bob", total)
			continue
		}
		first := int(str[0]-'a') + 1
		last := int(str[len(str)-1]-'a') + 1
		var alice int
		var bob int
		if first > last {
			alice = (total - last)
			bob = last
		} else {
			alice = (total - first)
			bob = first
		}

		fmt.Println("Alice", alice-bob)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	var S string

	fmt.Fscan(in, &T)
	//list := make([]string,N)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &S)
		val := len(S)
		if val == 1{
			fmt.Println("Bob",srtToNum(S))
		}else{
			if val%2 == 1{
				if S[0] < S[val-1]{
					fmt.Println("Alice",srtToNum(S[1:val])-int(S[0])+96)
				}else{
					fmt.Println("Alice",srtToNum(S[0:val-1])-int(S[val-1])+96)
				}
			}else{
				fmt.Println("Alice",srtToNum(S))
			}
		}
	}
}

func srtToNum(S string) int{
	var i int32
	a := rune('a')
	for _,v := range S{
		i += v-a+1
	}
	return 	int(i)
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func getPoints(a byte) int {
	return int(a) - int('a') + 1
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
	for ; t > 0; t-- {
		a := io.ReadString()

		ans := 0
		for i := range a {
			ans += getPoints(a[i])
		}

		if len(a)%2 == 0 {
			io.Println("Alice", ans)
		} else {
			bob := min(getPoints(a[0]), getPoints(a[len(a)-1]))
			ans -= bob

			if ans > bob {
				io.Println("Alice", ans-bob)
			} else {
				io.Println("Bob", bob)
			}
		}
	}
}

package main

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

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

func solve() {
	var s string
	fmt.Fscan(in, &s)
	cnt := 0
	for _, v := range s {
		cnt += int(v - 'a' + 1)
	}
	if len(s)%2 == 0 {
		fmt.Fprint(out, "Alice ")
		fmt.Fprintln(out, cnt)
		return
	}
	if s[0] > s[len(s)-1] {
		cnt = cnt - int(s[len(s)-1]-'a'+1)*2
	} else {
		cnt = cnt - int(s[0]-'a'+1)*2
	}
	if cnt >= 0 {
		fmt.Fprint(out, "Alice ")
	} else {
		fmt.Fprint(out, "Bob ")
		cnt = -cnt
	}
	fmt.Fprintln(out, cnt)
}
func main() {
	t := 0
	fmt.Fscan(in, &t)
	defer out.Flush()
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

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

func min(a, b int64) int64 {
	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 s string
		fmt.Fscan(in, &s)

		var sum int64
		for _, ch := range s {
			sum += int64(ch - 'a' + 1)
		}

		if len(s) == 1 {
			fmt.Fprintln(out, "Bob", sum)
		} else if len(s)%2 == 0 {
			fmt.Fprintln(out, "Alice", sum)
		} else {
			b := min(int64(s[0]-'a'+1), int64(s[len(s)-1]-'a'+1))
			a := sum - b
			fmt.Fprintln(out, "Alice", a-b)
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		n := len(s)
		if n & 1 == 0 {
			ans := 0
			for i := 0; i < n; i++ {
	                	ans += (int(rune(s[i]))-96)
			}
			fmt.Println("Alice", ans)
		} else {
		      	if n == 1 {
	                	fmt.Println("Bob", (int(rune(s[0]))-96))
			} else {
				index := -1
				largest := -1
				for i := 0; i < n; i++ {
					if int(rune(s[i])) > largest {
	                			largest = int(rune(s[i]))
						index = i
					}
				}
				if index != 0 {
					a := s[1:]
					b := s[0]
					ans := 0
					for i := 0; i < len(a); i++ {
	                			ans += (int(rune(a[i]))-96)
					}
					ans1 := ( int(rune(b)) - 96 )
					if ans > ans1 {
						fmt.Println("Alice", int(math.Abs(float64((ans-ans1)))))
					} else {
						fmt.Println("Bob", int(math.Abs(float64((ans-ans1)))))
					}
				} else {
					a := s[:(n-1)]
					b := s[(n-1)]
					ans := 0
					for i := 0; i < len(a); i++ {
	                			ans += (int(rune(a[i]))-96)
					}
					ans1 := ( int(rune(b)) - 96 )
					if ans > ans1 {
						fmt.Println("Alice", int(math.Abs(float64((ans-ans1)))))
					} else {
						fmt.Println("Bob", int(math.Abs(float64((ans-ans1)))))
					}
				}
			}
		}
	}
}

package main

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

func min(lhs, rhs int) int {
	if lhs < rhs {
		return lhs
	}
	return rhs
}

func point(b byte) int {
	return int(b-'a') + 1
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		total := 0
		s, _ := reader.ReadString('\n')
		s = s[:len(s)-1]
		for i := range s {
			total = total + point(s[i])
		}
		if len(s)%2 == 0 {
			fmt.Printf("Alice %v\n", total)
		} else {
			a := total - min(point(s[0]), point(s[len(s)-1]))
			b := total - a
			if a < b {
				fmt.Printf("Bob %v\n", b-a)
			} else {
				fmt.Printf("Alice %v\n", a-b)
			}
		}
	}
}


Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ???, ??a, a?a, aba.Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given n patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of patterns. Next n lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.

In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.

NoteConsider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aab, bab, cab, dab and so on.

package main

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

var scanner *bufio.Scanner

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

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

  line, _ := reader.ReadString('\n')
  n, _ := strconv.Atoi(strings.TrimSpace(line))
  words := make([]string, n)
  for i := range words {
    line, _ := reader.ReadString('\n')
    words[i] = strings.TrimSpace(line)
  }
  m := len(words[0])
  pattern := make([]byte, m)
  for _, word := range words {
    for i := 0; i < m; i++ {
      if pattern[i] == 0 {
        if word[i] != '?' {
          pattern[i] = word[i]
        }
      } else if pattern[i] != '?' && word[i] != '?' && word[i] != pattern[i] {
        pattern[i] = '?'
      }
    }
  }
  for i, ch := range pattern {
    if ch == 0 {
      pattern[i] = 'z'
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", string(pattern)))
}

package main

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

var scanner *bufio.Scanner

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

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

  n := getI()
  words := make([]string, n)
  for i := range words {
    words[i] = getS()
  }
  m := len(words[0])
  pattern := make([]byte, m)
  for _, word := range words {
    for i := 0; i < m; i++ {
      if pattern[i] == 0 {
        if word[i] != '?' {
          pattern[i] = word[i]
        }
      } else if pattern[i] != '?' && word[i] != '?' && word[i] != pattern[i] {
        pattern[i] = '?'
      }
    }
  }
  for i, ch := range pattern {
    if ch == 0 {
      pattern[i] = 'z'
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", string(pattern)))
}


In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.We will consider an extremely simplified subset of Python with only two types of statements.Simple statements are written in a single line, one per line. An example of a simple statement is assignment.For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.

The first line contains a single integer N (1 ≤ N ≤ 5000) — the number of commands in the program. N lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.

Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109 + 7.

NoteIn the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.simple statementfor statement    for statement        simple statementIn the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.for statement    simple statement    for statement        simple statementorfor statement    simple statementfor statement    simple statement

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var dp[5005 ][5005 ] int64
var sum[5005] int64
var MD int64 = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	var prev uint8
	fmt.Fscanf(in, "%c\n", &prev)
	dp[0][0] = 1
	for i := 1; i <n; i++ {
		var c uint8
		fmt.Fscanf(in, "%c\n", &c)
		if prev == 'f' {
			for j := 0; j <=n; j++ {
				dp[i][j + 1] = dp[i - 1][j]
			}
		} else {
			for j :=n; j >= 0; j-- {
				sum[j] = (sum[j + 1] + dp[i - 1][j]) % MD
			}
			for j:=0; j <=n; j++ {
				dp[i][j] = sum[j]
			}
		}
		prev = c
	}
	var ans int64
	for j := 0; j <=n; j++ {
		ans += dp[n - 1][j]
		ans %= MD
	}
	fmt.Println(ans)
}


There are $$$n$$$ students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct students whose name starts with the same letter will be chatty if they are put in the same classroom (because they must have a lot in common). Let $$$x$$$ be the number of such pairs of students in a split. Pairs $$$(a, b)$$$ and $$$(b, a)$$$ are the same and counted only once.For example, if there are $$$6$$$ students: "olivia", "jacob", "tanya", "jack", "oliver" and "jessica", then:  splitting into two classrooms ("jack", "jacob", "jessica", "tanya") and ("olivia", "oliver") will give $$$x=4$$$ ($$$3$$$ chatting pairs in the first classroom, $$$1$$$ chatting pair in the second classroom),  splitting into two classrooms ("jack", "tanya", "olivia") and ("jessica", "oliver", "jacob") will give $$$x=1$$$ ($$$0$$$ chatting pairs in the first classroom, $$$1$$$ chatting pair in the second classroom). You are given the list of the $$$n$$$ names. What is the minimum $$$x$$$ we can obtain by splitting the students into classrooms?Note that it is valid to place all of the students in one of the classrooms, leaving the other one empty.

The first line contains a single integer $$$n$$$ ($$$1\leq n \leq 100$$$) — the number of students. After this $$$n$$$ lines follow. The $$$i$$$-th line contains the name of the $$$i$$$-th student. It is guaranteed each name is a string of lowercase English letters of length at most $$$20$$$. Note that multiple students may share the same name.

The output must consist of a single integer $$$x$$$ — the minimum possible number of chatty pairs.

7
kambei
gorobei
shichiroji
kyuzo
heihachi
katsushiro
kikuchiyo

NoteIn the first sample the minimum number of pairs is $$$1$$$. This can be achieved, for example, by putting everyone except jose in one classroom, and jose in the other, so jorge and jerry form the only chatty pair.In the second sample the minimum number of pairs is $$$2$$$. This can be achieved, for example, by putting kambei, gorobei, shichiroji and kyuzo in one room and putting heihachi, katsushiro and kikuchiyo in the other room. In this case the two pairs are kambei and kyuzo, and katsushiro and kikuchiyo.In the third sample the minimum number of pairs is $$$4$$$. This can be achieved by placing three of the students named mike in one classroom and the other two students in another classroom. Thus there will be three chatty pairs in one classroom and one chatty pair in the other classroom.

package main

import (
	"fmt"
	"math"
)

func f(n int) (int){
	return n*(n-1)/2;
}

func main(){
	var n int
	var a[1000] string
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		fmt.Scanln(&a[i])
	}

	var cnt[26] int
	for i:=0;i<n;i++ {
		cnt[int(a[i][0])-int('a')]++
	}

	var res int
	for i:=0;i<26;i++{
		res += f(cnt[i]/2) + f(int(math.Ceil(float64(cnt[i])/2)))
	}

	fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt() int  {
	scanner.Scan()
	n,err := strconv.Atoi(scanner.Text())
	if err != nil{
		panic(err)
	}
	return n
}
func main()  {
		n := ReadInt()
		cnt := make([]int,30,30)
		for i := 0 ; i < n ;i ++{
			s := ReadStr();
			cnt[s[0] - 'a']++
		}
		var  ans int = 0
		for i := 0; i < 30 ;i ++{
			l := cnt[i] / 2;
			r := (cnt[i] - l)

		ans += ((l - 1) * l / 2)
		ans += ((r - 1) * r / 2)
		}

		fmt.Println(ans)

}

package main

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

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

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

	cnt := map[byte]int{}
	for i := 0; i < n; i++ {
		if _, ok := cnt[sts[i][0]]; !ok {
			cnt[sts[i][0]] = 0
		}
		cnt[sts[i][0]]++
	}

	var ans int
	for _, v := range cnt {
		ans += Combination(v/2, 2) + Combination((v-1)/2+1, 2)
	}

	fmt.Println(ans)
}

func Combination(n, r int) int {
	if n < r {
		return 0
	}
	if r == 0 || n == r {
		return 1
	}
	if r == 1 {
		return n
	}
	return Combination(n-1, r-1) + Combination(n-1, r)
}

package main

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

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

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

func main() {
        var n int
        var s string
        mp := make(map[uint8]int)
        scanf("%d\n", &n)
        for i:=0; i < n; i ++ {
                scanf("%s\n", &s)
                mp[s[0]]++
        }
        res := 0
        for _, v := range mp {
                first := v / 2
                second := v - first
                res += first * (first-1) / 2
                res += second * (second-1)/2
        }
        fmt.Println(res)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	cnt := make(map[uint8]int)
	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()
		cnt[t[0]]++
	}
	ans := 0
	for _, value := range cnt {
		lhs := value / 2
		rhs := value - lhs
		ans += lhs * (lhs - 1) / 2
		ans += rhs * (rhs - 1) / 2
	}
	fmt.Print(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, 26)

	for i := 0; i < n; i++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		a[int(s[0])-'a']++
	}
	ans := 0
	for i := 0; i < 26; i++ {
		q1 := a[i] / 2
		q2 := a[i] - q1
		if q1 >= 2 {
			ans += (q1 * (q1 - 1)) / 2
		}
		if q2 >= 2 {
			ans += (q2 * (q2 - 1)) / 2
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

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

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	s := make([][]byte, n)
	for i := range s {
		s[i] = readb()
	}

	c := make([]int, 26)
	for i := range s {
		j := int(s[i][0] - 'a')
		c[j]++
	}

	var ans int
	for _, v := range c {
		x := v / 2
		y := v - x
		ans += x * (x - 1) / 2
		ans += y * (y - 1) / 2
	}
	println(ans)

}

package main

import "fmt"

func main() {
    var n int
    var name string
    fmt.Scanln(&n)
    m := make(map[rune]int)
    for i := 0; i < n; i ++ {
        fmt.Scanln(&name)
        m[[]rune(name)[0]] ++
    }

    sum := 0
    for _, v := range m {
        if v == 1 || v == 2 {
            continue
        }

        if v == 3 {
            sum += 1
            continue
        }

        x := v / 2
        y := v - x
        sum += (x - 1) * x / 2
        sum += (y - 1) * y / 2
    }
    fmt.Println(sum)
}

package main

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

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

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

func ReadInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

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

func main() {
	scanner.Split(bufio.ScanWords)

	n := ReadInt()

	arr := make([]int, 26)
	for i := 0; i < n; i++ {
		str := ReadStr()
		arr[int(str[0]-'a')]++
	}

	ct := 0
	for _, c := range arr {
		if c > 0 {
			a := c / 2
			b := c/2 + c%2
			ct += a * (a - 1) / 2
			ct += b * (b - 1) / 2
		}
	}

	fmt.Println(ct)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	mp := make(map[byte]int)

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

	for ; t > 0; t-- {
		fmt.Scanf("%s\n", &s)
		mp[s[0]]++
	}

	cnt := 0

	for _, v := range mp {
		tmp := (v + 1) / 2
		cnt += (tmp * (tmp - 1)) / 2
		tmp = v / 2
		cnt += (tmp * (tmp - 1)) / 2
	}

	fmt.Print(cnt)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var t, x int
	var starts [28]int
	for i := 0; i < 28; i++ {
		starts[i] = 0
	}
	var temp string
	fmt.Scanln(&temp)
	t, _ = strconv.Atoi(temp)
	for i := 0; i < t; i++ {
		fmt.Scanln(&temp)
		starts[temp[0]-'a']++
	}
	for i := 0; i < 28; i++ {
		pairs0 := starts[i] / 2
		pairs1 := (starts[i] + 1) / 2
		x += pairs0*(pairs0-1)/2 + pairs1*(pairs1-1)/2
	}
	fmt.Println(x)
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt() int  {
	scanner.Scan()
	n,err := strconv.Atoi(scanner.Text())
	if err != nil{
		panic(err)
	}
	return n

}
func main()  {
	n := ReadInt()
	a := make([]int,26)
	for i := 0; i < n ;i++{
		s := ReadStr()
		a[s[0] - 'a'] ++
	}
	var ans int
	for i := 0; i < 26 ;i ++{
		temp := a[i] / 2
		ans += (temp - 1) * (temp) / 2
		temp += a[i] % 2
		ans += (temp - 1) * temp / 2
	}
	fmt.Println(ans)

}

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	mp := make(map[byte]int)

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

	for ; t > 0; t-- {
		fmt.Scanf("%s", &s)
		mp[s[0]]++
	}

	cnt := 0

	for _, v := range mp {
		tmp := (v + 1) / 2
		cnt += (tmp * (tmp - 1)) / 2

		tmp = v / 2
		cnt += (tmp * (tmp - 1)) / 2
	}

	fmt.Print(cnt)
}


A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.In the initial moment of time all Packmen begin to move. Each Packman can change direction of its move unlimited number of times, but it is not allowed to go beyond the boundaries of the game field. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions.Your task is to determine minimum possible time after which Packmen can eat all the asterisks.

The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field. The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is symbol 'P' in position i — Packman is in the cell i. It is guaranteed that on the game field there is at least one Packman and at least one asterisk.

Print minimum possible time after which Packmen can eat all asterisks.

NoteIn the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) and then move from the position 5 to the right and eat asterisk in the position 7 (in 2 time units). So in 3 time units Packmen will eat all asterisks on the game field.In the second example Packman in the position 4 will move to the left and after 2 time units will eat asterisks in positions 3 and 2. Packmen in positions 5 and 8 will move to the right and in 2 time units will eat asterisks in positions 7 and 10, respectively. So 2 time units is enough for Packmen to eat all asterisks on the game field.

package main

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

func main() {
	var n int
	var s string
	var cell []byte
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	cell = []byte(s)
	pacman := make([]int, 0, n)
	asterisks := make([]int, 0, n)
	for i := 0;i < n;i ++ {
		if cell[i] == '*' {
			asterisks = append(asterisks, i)
		} else if cell[i] == 'P' {
			pacman = append(pacman, i)
		}
	}
	left, right, ans := 0, 2 * n, n
	for left <= right {
		mid := (left + right) / 2
		notEat := 0
		fail := false
		for i := 0;i < len(pacman) && notEat < len(asterisks);i ++ {
			var rightMost int
			if asterisks[notEat] > pacman[i] {
				rightMost = mid
			} else if mid < pacman[i] - asterisks[notEat] {
				fail = true
			} else {
				rightMost = (mid - pacman[i] + asterisks[notEat]) / 2
				if right := mid - (pacman[i] - asterisks[notEat]) * 2; right > rightMost {
					rightMost = right
				}
			}
			if fail {
				break
			}
			if i != len(pacman) - 1 && pacman[i] + rightMost >= pacman[i + 1] {
				rightMost = pacman[i + 1] - pacman[i] - 1
			}
			for ;notEat < len(asterisks) && asterisks[notEat] <= pacman[i] + rightMost; notEat ++ {}
		}
		if fail {
			left = mid + 1
		} else if notEat == len(asterisks) {
			ans = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

func main() {
	var n int
	var s string
	var cell []byte
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	cell = []byte(s)
	pacman := make([]int, 0, n)
	asterisks := make([]int, 0, n)
	for i := 0;i < n;i ++ {
		if cell[i] == '*' {
			asterisks = append(asterisks, i)
		} else if cell[i] == 'P' {
			pacman = append(pacman, i)
		}
	}
	left, right, ans := 0, n, n
	for left <= right {
		mid := (left + right) / 2
		notEat := 0
		fail := false
		for i := 0;i < len(pacman) && notEat < len(asterisks);i ++ {
			var rightMost int
			if asterisks[notEat] > pacman[i] {
				rightMost = mid
			} else if mid < pacman[i] - asterisks[notEat] {
				fail = true
			} else {
				rightMost = (mid - pacman[i] + asterisks[notEat]) / 2
				if right := mid - (pacman[i] - asterisks[notEat]) * 2; right > rightMost {
					rightMost = right
				}
			}
			if fail {
				break
			}
			if i != len(pacman) - 1 && pacman[i] + rightMost >= pacman[i + 1] {
				rightMost = pacman[i + 1] - pacman[i] - 1
			}
			for ;notEat < len(asterisks) && asterisks[notEat] <= pacman[i] + rightMost; notEat ++ {}
		}
		if fail {
			left = mid + 1
		} else if notEat == len(asterisks) {
			ans = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}
	fmt.Printf("%d", ans)
}


Nick had received an awesome array of integers $$$a=[a_1, a_2, \dots, a_n]$$$ as a gift for his $$$5$$$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $$$a_1 \cdot a_2 \cdot \dots a_n$$$ of its elements seemed to him not large enough.He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index $$$i$$$ ($$$1 \le i \le n$$$) and do $$$a_i := -a_i - 1$$$.For example, he can change array $$$[3, -1, -4, 1]$$$ to an array $$$[-4, -1, 3, 1]$$$ after applying this operation to elements with indices $$$i=1$$$ and $$$i=3$$$. Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index. Help Kolya and print the array with the maximal possible product of elements $$$a_1 \cdot a_2 \cdot \dots a_n$$$ which can be received using only this operation in some order.If there are multiple answers, print any of them.

The first line contains integer $$$n$$$ ($$$1 \leq n \leq 10^{5}$$$) — number of integers in the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^{6} \leq a_i \leq 10^{6}$$$) — elements of the array

Print $$$n$$$ numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array. If there are multiple answers, print any of them.

package main

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

func Solve(n int, a []int) []int {
	if n%2 == 0 {
		for i := 0; i < n; i++ {
			if a[i] >= 0 {
				a[i] = -a[i] - 1
			}
		}
		return a
	}
	negativeOneCount := 0
	maxPositive := 0
	maxPositiveIndex := 0
	for i := 0; i < n; i++ {
		if a[i] == -1 || a[i] == 0 {
			a[i] = -1
			negativeOneCount += 1
		} else if a[i] < 0 {
			a[i] = -a[i] - 1
		}
		if a[i] > maxPositive {
			maxPositive = a[i]
			maxPositiveIndex = i
		}
	}
	if negativeOneCount == n {
		a[0] = 0
		return a
	}
	for i := 0; i < n; i++ {
		if a[i] > 0 && i != maxPositiveIndex {
			a[i] = -a[i] - 1
		}
	}
	return a
}

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

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

	for _, elem := range Solve(n, a) {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}

package main

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

func minElemIndex(n int, a []int) int {
	minElem := a[0]
	minElemIndex := 0
	for i := 1; i < n; i++ {
		if a[i] < minElem {
			minElem = a[i]
			minElemIndex = i
		}
	}
	return minElemIndex
}

func Solve(n int, a []int) []int {
	for i := 0; i < n; i++ {
		if a[i] >= 0 {
			a[i] = -a[i] - 1
		}
	}
	minElemIndex := minElemIndex(n, a)
	if n%2 == 1 {
		a[minElemIndex] = -a[minElemIndex] - 1
	}
	return a
}

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

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

	for _, elem := range Solve(n, a) {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}


Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.

The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj < m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.

If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".

NoteBy  we define the remainder of integer division of i by k.In first sample case:   On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.  On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.  On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.  On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.  On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]bool, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = true
	}

	g := nextInt()
	y := make([]bool, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = true
	}

	i := 0

	for {
		// println(i, i%n, i%m)
		// println(x, y)

		if x[i%n] {
			y[i%m] = true
		}

		if y[i%m] {
			x[i%n] = true
		}

		if i > 0 && i%n == 0 && i%m == 0 {
			if notHappy(x) && notHappy(y) {
				println("No")
				return
			} else {
				println("Yes")
				return
			}

		}

		i++
	}
}

func notHappy(a []bool) bool {
	for i := 0; i < len(a); i++ {
		if !a[i] {
			return true
		}
	}

	return false
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

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

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

package main

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

var scanner *bufio.Scanner

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

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

  n, m := getI(), getI()
  boys := make([]bool, n)
  k := getI()
  count := k
  for i := 0; i < k; i++ {
    boys[getI()] = true
  }
  girls := make([]bool, m)
  k = getI()
  count += k
  for i := 0; i < k; i++ {
    girls[getI()] = true
  }
  for i := 0; i < 4*n*m; i++ {
    if boys[i%n] && !girls[i%m] {
      girls[i%m] = true
      count++
    } else if !boys[i%n] && girls[i%m] {
      boys[i%n] = true
      count++
    }
  }
  if count == n+m {
    writer.WriteString("Yes\n")
  } else {
    writer.WriteString("No\n")
  }
}

package main

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

func solve(isHappyBoy []bool, isHappyGirl []bool, n int, m int) string {
	lcm := findLCM(n, m)

	for k := 0; k < 2; k++ {
		for i := 0; i <= lcm; i++ {
			if isHappyBoy[i%n] {
				isHappyGirl[i%m] = true
				continue
			}
			if isHappyGirl[i%m] {
				isHappyBoy[i%n] = true
			}
		}
	}

	for i := range isHappyBoy {
		if !isHappyBoy[i] {
			return "No"
		}
	}

	for i := range isHappyGirl {
		if !isHappyGirl[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	return n * m / findGCD(n, m)
}

func findGCD(n int, m int) int {
	remain, a, b := 0, m, n
	if n > m {
		a = n
		b = m
	}

	for b != 0 {
		remain = a % b
		a = b
		b = remain
	}

	return a
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m, b, g, id int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	isHappyBoy := make([]bool, n)
	isHappyGirl := make([]bool, m)

	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		fmt.Fscanf(r, "%d", &id)
		isHappyBoy[id] = true
	}
	fmt.Fscanln(r)

	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		fmt.Fscanf(r, "%d", &id)
		isHappyGirl[id] = true

	}
	fmt.Fscanln(r)

	fmt.Fprintf(os.Stdout, "%s\n", solve(isHappyBoy, isHappyGirl, n, m))
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}

package main

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

func solve(boys []bool, girls []bool, n int, m int) string {
	cm := findLCM(n, m)

	//loop 2 times cuz some spots may not be update in first time yet(test case provided below)
	for i := 0; i < cm*2; i++ {
		if girls[i%m] || boys[i%n] {
			girls[i%m] = true
			boys[i%n] = true
		}
	}

	for i := range boys {
		if !boys[i] {
			return "No"
		}
	}

	for i := range girls {
		if !girls[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	gcd := findGCD(n, m)
	return n * m / gcd
}

func findGCD(n int, m int) int {
	for m > 0 {
		mod := n % m
		n = m
		m = mod
	}

	return n
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]bool, m)
	boys := make([]bool, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = true
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = true
	}

	fmt.Println(solve(boys, girls, n, m))
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []bool, girls []bool, n int, m int) string {
	cm := findLCM(n, m)

	//loop 2 times cuz some spot may not be update in first time yet
	for i := 0; i < cm*2; i++ {
		if girls[i%m] || boys[i%n] {
			girls[i%m] = true
			boys[i%n] = true
		}
	}

	for i := range boys {
		if !boys[i] {
			return "No"
		}
	}

	for i := range girls {
		if !girls[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	big, small := findMax(n, m)

	if big%small == 0 {
		return big
	}

	return big * small
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]bool, m)
	boys := make([]bool, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = true
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = true
	}

	fmt.Println(solve(boys, girls, n, m))
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []Pair) []Pair {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i].first > arr[right].first {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func sort2(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort2(arr[:left])
	sort2(arr[left+1:])
	return arr
}

func gcd (a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd (b, a % b);
}

func solution(reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	var k, v int
	b := make(map[int]bool)
	g := make(map[int]bool)

	fmt.Fscanf(reader, "%d", &k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%d", &v)
		b[v] = true
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fscanf(reader, "%d", &k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%d", &v)
		g[v] = true
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < 10000; i++ {
		if !(!g[i % m] && !b[i % n]) {
			g[i % m] = true
			b[i % n] = true
		}
	}
	if len(b) != n || len(g) != m {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

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

	readint := func() int {
		sc.Scan()
		x, _ := strconv.Atoi(string(sc.Bytes()))
		return x
	}

	n := readint()
	m := readint()
	b := readint()

	B := make([]bool, n)
	G := make([]bool, m)

	for i := 0; i < b; i++ {
		B[readint()] = true
	}

	g := readint()
	for i := 0; i < g; i++ {
		G[readint()] = true
	}

	happy := b + g
	for i := 0; i < 1e6+6; i++ {
		if B[i%n] != G[i%m] {
			happy++
			if happy == n+m {
				fmt.Println("Yes")
				return
			}
			B[i%n] = true
			G[i%m] = true
		}
	}

	fmt.Println("No")
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]int, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = 1
	}

	g := nextInt()
	y := make([]int, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = 1
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range x {
			if x[i] == 0 && y[i] == 0 {
				println("No")
				return
			}
		}
	}

	println("Yes")
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]bool, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = true
	}

	g := nextInt()
	y := make([]bool, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = true
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range y {
			if !x[i%n] && !y[i] {
				println("No")
				return
			}
		}
	}

	if (m%2==0 && n%2==0) || (m%2==1 && n%2==1) {
		if (!haveHappy(x, 0) && !haveHappy(y, 0)) || (!haveHappy(x, 1) && !haveHappy(y, 1)) {
			println("No")
			return
		}
	}

	println("Yes")
}

func haveHappy(a []bool, i int) bool {
	for ; i < len(a); i += 2 {
		if a[i] {
			return true
		}
	}

	return false
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]int, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = 1
	}

	g := nextInt()
	y := make([]int, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = 1
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range y {
			if x[i%n] == 0 && y[i] == 0 {
				println("No")
				return
			}
		}
	}

	println("Yes")
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

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

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

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			fmt.Println("b")

			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			fmt.Println("q")
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i <= d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			fmt.Println("b")

			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			fmt.Println("q")
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(strings.NewReader(`100 50
	30 50 54 7 8 59 60 61 62 63 64 15 16 18 19 20 22 73 27 79 83 86 87 89 42 93 94 45 46 97 98
	20 1 2 3 5 6 17 21 24 25 26 28 30 31 32 34 35 38 40 41 49`))
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
	fmt.Println(boys)
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			return "No"
		}
	}

	for i := range girls {
		if girls[i] == 0 {
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}


There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.

The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.

Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.

NoteIn the first example letters should be delivered in the following order:  the first letter in room $$$1$$$ of the first dormitory  the second letter in room $$$9$$$ of the first dormitory  the third letter in room $$$2$$$ of the second dormitory  the fourth letter in room $$$13$$$ of the second dormitory  the fifth letter in room $$$1$$$ of the third dormitory  the sixth letter in room $$$12$$$ of the third dormitory

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2048*2048), 2048*2048)
	scanner.Split(bufio.ScanWords)

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

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

	a := make([]int64, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	cur := int64(0)
	total := int64(0)
	for i := 0; i < m; i++ {
		scanner.Scan()
		b, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		for b > total+a[cur] {
			total += a[cur]
			cur++
		}
		fmt.Println(cur+1, b-total)
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	a := make([]int64, n+1)
	var t int64
	a[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &t)
		a[i] = a[i-1]+t
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t)
		l, r := 0, n
		for l < r {
			m := (l+r)/2
			if a[m] < t {
				l = m + 1
			} else {
				r = m
			}
		}
		fmt.Fprintln(out, l, t-a[l-1])
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	a := make([]int64, n+1)
	var t int64
	a[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &t)
		a[i] = a[i-1]+t
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t)
		l, r := 1, n
		for l < r-1 {
			m := (l+r)/2
			if a[m] >= t {
				r = m
			} else {
				l = m
			}
		}
		if a[l] >= t {
			r = l
		}
		fmt.Fprintln(out, r, t-a[r-1])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int64) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int64(b&15)
		}
		return
	}

	n, m := int(r()), int(r())
	s := make([]int64, n+1)
	for i := 0; i < n; i++ {
		s[i+1] = s[i] + r()
	}
	for i := 1; m > 0; m-- {
		v := r()
		for ; s[i] < v; i++ {
		}
		Fprintln(out, i, v-s[i-1])
	}
}

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 n, m int
	var v int64
	Fscan(in, &n, &m)
	s := make([]int64, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		s[i+1] = s[i] + v
	}
	for i:=1;m>0;m-- {
		for Fscan(in, &v);s[i]<v;i++{}
		Fprintln(out, i,v-s[i-1])
	}
}

package main

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

type dormitory struct{
	firstRoom int64
	lastRoom  int64
}

func main() {

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

	var count, letters int
	var room int64

	fmt.Fscan(in, &count, &letters)

	dormitories := []dormitory{}

	for i := 0; i < count; i++ {
		var countRoom int64
		fmt.Fscan(in, &countRoom)

		each := dormitory{firstRoom: room + 1, lastRoom: countRoom + room}
		dormitories = append(dormitories, each)

		room += countRoom
	}

	for i := 0; i < letters; i++ {
		var letter int64
		fmt.Fscan(in, &letter)

		left, right := 0, count - 1

		for left <= right {
			middle := (left + right) / 2
			if dormitories[middle].firstRoom > letter {
				right = middle - 1
			} else if dormitories[middle].lastRoom < letter {
				left = middle + 1
			}
			if dormitories[middle].firstRoom <= letter && dormitories[middle].lastRoom >= letter {
				left = middle
				break
			}
		}

		fmt.Printf("%d %d\n", left + 1, letter + 1 - dormitories[left].firstRoom)
	}
}

package main

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

type obsh struct {
	Num  int
	Self  uint64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp uint64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	obshagi := make([]obsh, n)
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 64)
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 64)
		need := obshagi[binarySearch(tmp, &obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
			strconv.FormatUint(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle uint64, haystack *[]obsh) int64 {
	var low int64 = 0
	var high = int64(len(*haystack) - 1)
	for low <= high {
		median := (low + high) / 2
		if (*haystack)[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 64)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 64)
		need := obshagi[binarySearch(tmp, obshagi)]
		fmt.Println(need.Num, need.Self-(need.Sum-tmp))
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {

	var low int64 = 0
	var high = int64(len(haystack)) - 1

	for low <= high {
		median := (low + high) / 2

		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}

	return low
}

package main

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

const (
	MaxN = 200005
)

var n, m int
var a, pre [MaxN]int64

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i - 1] + a[i]
	}
	fmt.Fscanf(inBuf, "\n")

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()

	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(inBuf, "%d", &tmp)
		ind := sort.Search(n, func(i int) bool {
			return pre[i] >= tmp
		})
		room := int64(0)
		if ind == 0 {
			room = tmp
		} else {
			room = tmp - pre[ind - 1]
		}
		fmt.Fprintf(outBuf, "%d %d\n", ind + 1, room)
	}
}

package main

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

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

	defer out.Flush()

	var n int
	var m int

	fmt.Fscan(in, &n, &m)

	a := make([]int64, n)
	b := make([]int64, m)
	s := make([]int64, n+1)

	s[0] = 0

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		s[i+1] = s[i] + a[i]
	}

	t := 0
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &b[i])
		b[i]--
		for s[t] <= b[i] {
			t++
		}
		t--
		fmt.Fprintln(out, t+1, b[i]-s[t]+1)
		//fmt.Printf("%d %d\n", t+1, b[i]-s[t]+1)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	z := readInt64Slice(reader, 2)
	zz := readInt64Slice(reader, int(z[0]))
	zzz := readInt64Slice(reader, int(z[1]))
	fmt.Println(zz, zzz)
}

func readOneInt64(r *bufio.Reader) (n int64) {
	bytes, _ := r.ReadBytes('\n')
	n, _ = strconv.ParseInt(string(bytes[:len(bytes)-2]), 10, 64)
	return
}

func readInt64Slice(r *bufio.Reader, n int) (slice []int64) {
	var bytes []byte
	slice = make([]int64, n)
	n--
	for i:=0;i<n;i++{
		bytes, _ = r.ReadBytes(' ')
		slice[i], _ = strconv.ParseInt(string(bytes[:len(bytes)-1]), 10, 64)
	}
	slice[n] = readOneInt64(r)
	return
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10), strconv.FormatInt(need.Self-(need.Sum-tmp), 10), "\n"}, " "))
	}
	writer.Flush()
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self  uint64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp uint64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	obshagi := make([]obsh, n)
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 0)
		summ = summ + tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 0)
		var a int
		if tmp<obshagi[0].Sum{
			a = 0
		} else {
			for i := 1; i < len(obshagi); i++ {
				if tmp>obshagi[i-1].Sum && tmp<=obshagi[i].Sum {
					a = i
					break
				}
			}
		}
		need := obshagi[a]
		writer.WriteString(strings.Join([]string{strconv.Itoa(need.Num),
		strconv.FormatUint(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

package main

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

type obsh struct {
	Num  int
	Self, Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		fmt.Println(need.Num, need.Self-(need.Sum-tmp))
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {

	var low int64 = 0
	var high = int64(len(haystack)) - 1

	for low <= high {
		median := (low + high) / 2

		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}

	return low
}

package main

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

type obsh struct {
	Num  int
	Self  int64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp int64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += uint64(tmp)
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(int64(uint64(need.Self)-(need.Sum-uint64(tmp))), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < uint64(needle) {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int64
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = int64(i) + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10), "\n"}, " "))
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self, Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, err := strconv.ParseInt(v, 10, 0)
		if err != nil{
			fmt.Errorf("%v", err)
		}
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

const (
	MaxN = 200005
)

var n, m int
var a, pre [MaxN]int64

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i - 1] + a[i]
	}
	fmt.Println(pre[:n])
	fmt.Fscanf(inBuf, "\n")

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()

	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(inBuf, "%d", &tmp)
		ind := sort.Search(n, func(i int) bool {
			return pre[i] >= tmp
		})
		room := int64(0)
		if ind == 0 {
			room = tmp
		} else {
			room = tmp - pre[ind - 1]
		}
		fmt.Fprintf(outBuf, "%d %d\n", ind + 1, room)
	}
}

package main

import "fmt"

func main() {
	var n int
	var m int

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

	a := make([]int64, n)
	b := make([]int64, m)
	s := make([]int64, n+1)

	s[0] = 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		s[i+1] = s[i] + a[i]
	}

	t := 0
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &b[i])
		b[i]--
		for s[t] <= b[i] {
			t++
		}
		t--
		fmt.Printf("%d %d\n", t+1, b[i]-s[t]+1)
	}
}


Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.

The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.

Print the only integer — the answer to the problem.

NoteIn the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.In the second example all events except the first one are contained in the first.In the third example only one event, so the answer is 0.

package main

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

type Event struct {
	start, end int
}

type Events []Event

func (this Events) Len() int {
	return len(this)
}

func (this Events) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func (this Events) Less(i, j int) bool {
	return this[i].end < this[j].end
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	var events Events = make([]Event, 0, n)
	for i := 0;i < n;i ++ {
		var e Event
		fmt.Fscanf(reader, "%d %d\n", &e.start, &e.end)
		events = append(events, e)
	}
	sort.Sort(events)
	var minStart, ans int
	for i := n - 2;i >= 0;i -- {
		if i == n - 2 {
			minStart = events[i + 1].start
		} else if minStart > events[i + 1].start {
			minStart = events[i + 1].start
		}
		if minStart < events[i].start {
			ans ++
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

var scanner *bufio.Scanner

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

type Span struct {
  Open, Close int
  Closed bool
  QueuePos int
}

type Event struct {
  Point int
  ForSpan *Span
  Opening, Closing bool
}
type Events []*Event
func (events Events) Len() int {
  return len(events)
}
func (events Events) Swap(i, j int) {
  events[i], events[j] = events[j], events[i]
}
func (events Events) Less(i, j int) bool {
  return events[i].Point < events[j].Point
}

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

  n := getI()
  spans := make([]*Span, n)
  events := make([]*Event, 2 * n)
  for i := 0; i < n; i++ {
    open, close := getI(), getI()
    spans[i] = &Span{ open, close, false, -1 }
    events[2 * i] = &Event{ open, spans[i], true, false }
    events[2 * i + 1] = &Event{ close, spans[i], false, true }
  }
  sort.Sort(Events(events))

  result := 0
  leftmost := 0
  queue := []*Span{}

  for _, event := range events {
    span := event.ForSpan
    if event.Opening {
      span.QueuePos = len(queue)
      queue = append(queue, span)
    } else {
      if queue[leftmost].Open < span.Open {
        result += 1
      }
      queue[span.QueuePos].Closed = true
      for leftmost < len(queue) && queue[leftmost].Closed {
        leftmost++
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

var scanner *bufio.Scanner

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

type Span struct {
  Open, Close int
}
type Spans []*Span
func (spans Spans) Len() int {
  return len(spans)
}
func (spans Spans) Swap(i, j int) {
  spans[i], spans[j] = spans[j], spans[i]
}
func (spans Spans) Less(i, j int) bool {
  return spans[i].Open < spans[j].Open
}

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

  n := getI()
  spans := make([]*Span, n)
  for i := 0; i < n; i++ {
    spans[i] = &Span{ getI(), getI() }
  }
  sort.Sort(Spans(spans))

  result := 0
  rightmost := spans[0].Close
  for i := 1; i < n; i++ {
    span := spans[i]
    if span.Close < rightmost {
      result++
    } else {
      rightmost = span.Close
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", result))
}