package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	h := nextInt()
	w := nextInt()
	m := nextInt()

	hArr := make([]int, h)
	wArr := make([]int, w)
	save := map[[2]int]int{}
	hMax := 0
	maxIndex := 0
	wMax := 0
	maxWIndex := 0
	for i := 0; i < m; i++ {
		ww := nextInt()
		hh := nextInt()
		save[[2]int{ww, hh}] = 1
		hArr[ww-1]++
		if hArr[ww-1] > hMax {
			hMax = hArr[ww-1]
			maxIndex = ww - 1
		}
		wArr[hh-1]++
		if wArr[hh-1] > wMax {
			wMax = wArr[hh-1]
			maxWIndex = hh - 1
		}
	}

	xx := 0
	if save[[2]int{maxIndex, maxWIndex}] != 0 {
		xx++
	}

	fmt.Println(wMax + hMax - xx)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


package main

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

func main() {
	H, W, M := ReadInt(), ReadInt(), ReadInt()
	grid := make([][]bool, H)
	for i := 0; i < H; i++ {
		grid[i] = make([]bool, W)
	}
	cx := make([]int, W)
	cy := make([]int, H)
	for i := 0; i < M; i++ {
		y, x := ReadInt()-1, ReadInt()-1
		cx[x]++
		cy[y]++
		grid[y][x] = true
	}

	xidx := make([]int, W)
	for i := 0; i < W; i++ {
		xidx[i] = i
	}
	yidx := make([]int, H)
	for i := 0; i < H; i++ {
		yidx[i] = i
	}

	sort.Slice(xidx, func(i, j int) bool {
		return cx[xidx[i]] > cx[xidx[j]]
	})
	sort.Slice(yidx, func(i, j int) bool {
		return cy[yidx[i]] > cy[yidx[j]]
	})

	maxCx := cx[xidx[0]]
	maxCy := cy[yidx[0]]
	maxSum := maxCx + maxCy - 1
	for xi := 0; xi < W; xi++ {
		x := xidx[xi]
		if cx[x] != maxCx {
			break
		}
		for yi := 0; yi < H; yi++ {
			y := yidx[yi]
			if cy[y] != maxCy {
				break
			}
			if !grid[y][x] {
				fmt.Println(cx[x] + cy[y])
				return
			}
		}
	}
	fmt.Println(maxSum)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 500 points

Problem Statement

We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

1 \leq H, W \leq 3 \times 10^5

1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)

1 \leq h_i \leq H

1 \leq w_i \leq W

\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at \left(1, 2\right).

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	H, W, M := nextInt(), nextInt(), nextInt()
	hn := make([]int, H)
	wn := make([]int, W)
	grid := make([][]int, H)
	for i := 0; i < H; i++ {
		grid[i] = make([]int, W)
	}

	for i := 0; i < M; i++ {
		h, w := nextInt(), nextInt()
		grid[h-1][w-1] = 1
		hn[h-1]++
		wn[w-1]++
	}
	hi, hx := arrMax(hn)

	for i := 0; i < W; i++ {
		if grid[hi][i] == 1 {
			wn[i]--
		}
	}

	_, wx := arrMax(wn)
	ans := hx + wx

	// fmt.Println("hi", hi)
	// fmt.Println("hx", hx)
	// fmt.Println("wi", wi)
	// fmt.Println("wx", wx)
	// fmt.Println(hn, wn)

	fmt.Println(ans)

}

func arrMax(arr []int) (int, int) {
	var max int = arr[0]
	var maxI int = 0
	for ind, val := range arr {
		if max < val {
			max = val
			maxI = ind
		}
	}
	return maxI, max
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

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

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

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

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


package main

import (
	"fmt"
)

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

	if n%1000 == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1000 - n%1000)
	}

}

Score : 100 points

Problem Statement

We will buy a product for N yen (the currency of Japan) at a shop.

If we use only 1000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

1 \leq N \leq 10000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the amount of change as an integer.

Sample Input 1

1900

Sample Output 1

100

We will use two 1000-yen bills to pay the price and receive 100 yen in change.

Sample Input 2

3000

Sample Output 2

0

We can pay the exact price.


package main

import (
	"fmt"
)

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

	result := i % 1000

	fmt.Println(result)
}


package main

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

var (
	N int
)

func main() {
	readVariables()
	var answer int
	rem := N % 1000
	if rem != 0 {
		answer = 1000 - rem
	}
	fmt.Println(answer)
}

func readVariables() {
	N = nextInt()

}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


package main

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

/* 一つ読み */
func scanText() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

/* 複数読み */
func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}
func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}
func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	bill := (n /  1000) + 1

	fmt.Println(bill * 1000 - n)

}


package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func divFloor(a, b int) int {
	return (a + (b - 1)) / b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	puts(divFloor(n, 1000)*1000 - n)
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanStringToken() (word string) {
	scanner.Scan()
	word = scanner.Text()
	return
}

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

func main() {
	n := scanNumberToken()
	// c := int(n / 1000)
	mod := n % 1000

	if mod == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1000 - mod)
	}

}


package main

import "fmt"

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

	money := 0
	if n % 1000 != 0{
		money = 1000 * ((n / 1000)+1) - n
	}

	fmt.Println(money)

}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Printf("%d\n", (10000-n)%1000)
}


package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n := sc.getInt()
	ans := 1000 - (n % 1000)
	if n%1000 == 0 {
		ans = 0
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

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

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


package main

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

var mod = 1000000007
var inf = 1000000007

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

	ans := n % 1000
	if ans == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1000 - ans)
	}
}

// permutations
func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modinv(n, mod int) int {
	return modpow(n, mod-2, mod)
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Combination ...
type Combination struct {
	facts, invs []int
	mod         int
}

// NewCombination ...
func NewCombination(n, mod int) Combination {
	return Combination{
		facts: make([]int, n+1),
		invs:  make([]int, n+1),
		mod:   mod,
	}
}

func (cmb *Combination) calc(n, k int) int {
	ret := cmb.facts[n] * cmb.invs[k]
	ret %= cmb.mod
	ret = ret * cmb.invs[n-k]
	ret %= cmb.mod
	return ret
}

func (cmb *Combination) init(n int) {
	cmb.facts[0] = 1
	// 階乗を算出
	for i := 1; i <= n; i++ {
		cmb.facts[i] = cmb.facts[i-1] * i % cmb.mod
	}
	// 逆元を算出
	cmb.invs[n] = modinv(cmb.facts[n], cmb.mod)
	for i := n - 1; i >= 0; i-- {
		cmb.invs[i] = cmb.invs[i+1] * (i + 1) % cmb.mod
	}
}

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

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

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

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

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

func pow(a, n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= a
	}
	return ret
}

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}

// priority_queue
type intHeap []int

func (h intHeap) Len() int           { return len(h) }
func (h intHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h intHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// sortable points
type point struct {
	x int
	y int
}

type points []point

func (p points) Len() int {
	return len(p)
}

func (p points) Less(i, j int) bool {
	return p[i].x < p[j].x
}

func (p points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}


package main

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

func main() {
	N := ReadInt()
	fmt.Println((1000 - N%1000) % 1000)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


package main

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

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	N := readint()
	fmt.Println(N % 1000)
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

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

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


package main

import (
  "fmt"
  "os"
  "bufio"
  "strconv"
  "math"
  "math/rand"
  "time"
)

type XorShift struct {
  X uint64
  Nl [65536]float64
}

func (xs *XorShift) xinit(){
  var n2 = 0.5 / 65536
  for i:=0; i<65536; i++ {
    xs.Nl[i] = math.Log(float64(i) / 65536.0 + n2)
  }
}

func (xs *XorShift) next() uint64 {
  xs.X ^= xs.X << 13; xs.X ^= xs.X >> 7; xs.X ^= xs.X << 17;
  return xs.X
}

func (xs *XorShift) nextInt(n int) int {
  return int(xs.next() % uint64(n))
}

func (xs *XorShift) nextLog() float64 {
  return xs.Nl[xs.nextInt(65536)]
}

var xs XorShift
var starttime time.Time

const (
  M = 26
  D = 365
  TO = 1.98
)

var C = make([]int, M)
var S [D][M]int
var T = make([]int, D)
var (
  ttt = 0
  ctt = 0
  dtt = 0
  ett = 0
  ftt = 0
)

type Link struct {
  Day int
  C int
  Prev *Link
  Next *Link
}

var LA = make([]Link, D+M*2)
var DS = make([]int, D+2)

func sinit(){
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)
  sc.Scan()
  sc.Text()

  for i:=0; i<M; i++{
    sc.Scan()
    C[i], _ = strconv.Atoi(sc.Text())
  }

  for i:=0; i<D; i++{
    for j:=0; j<M; j++{
      sc.Scan()
      S[i][j], _ = strconv.Atoi(sc.Text())
    }
  }

  for i:=0; i<D+2; i++ {
    DS[i] = (i-1) * i / 2
  }

  for i:=0; i<M; i++ {
    LA[D+i].Day = -1
    LA[D+i].C = i
    LA[D+i].Next = &LA[D+M+i]
    LA[D+M+i].Day = D
    LA[D+M+i].C = i
    LA[D+M+i].Prev = &LA[D+i]
  }

  cc := make([]int, M)

  for i:=0; i<D; i++ {
    LA[i].Day = i
    c := 0
    var mm float64 = -1
    for j:=0; j<M; j++ {
      k := D / (cc[j] + 1) + 1
      t := (float64(C[j]) + 0.5) * float64(DS[k] * k)
      if mm < t {
        mm = t
        c = j
      }
    }
    cc[c]++
    LA[i].C = c
    ln := &LA[D+M+c]
    lp := ln.Prev
    LA[i].Next = ln
    LA[i].Prev = lp
    ln.Prev = &LA[i]
    lp.Next = &LA[i]
  }
}

func score() int {
  r := 0
  for i:=0; i<M; i++ {
    li := LA[D+i].Next
    pd := -1
    for true {
      r -= C[i] * DS[li.Day - pd]
      if li.Day == D {
        break
      }
      r += S[li.Day][li.C]
      pd = li.Day
      li = li.Next
    }
  }
  return r
}

func sswap(a, b *Link) int {
  ca := a.C
  da := a.Day
  pda := a.Prev.Day
  nda := a.Next.Day
  cb := b.C
  db := b.Day
  pdb := b.Prev.Day
  ndb := b.Next.Day

  t := S[da][ca] + S[db][cb] -
    C[ca] * (DS[nda - da] + DS[da - pda]) -
    C[cb] * (DS[ndb - db] + DS[db - pdb])
  u := S[db][ca] + S[da][cb] -
    C[ca] * (DS[nda - db] + DS[db - pda]) -
    C[cb] * (DS[ndb - da] + DS[da - pdb])

  return u - t
}

const gg = 1400.0

func solve(){
  sc := score()

  for true {
    gt := (TO - time.Now().Sub(starttime).Seconds()) / TO
    if gt <= 0 {
      break
    }

    for tt:=0; tt<D; tt++ {
      da := tt
      la := &LA[da]
      ca := la.C
      cc := xs.nextInt(M-1)
      if cc >= ca {
        cc++
      }
      lc := LA[D + cc].Next
      for lc.Day < da {
        lc = lc.Next
      }
      pda := la.Prev.Day
      nda := la.Next.Day
      pdc := lc.Prev.Day
      ndc := lc.Day

      t := S[da][ca] -
        C[ca] * (DS[nda - da] + DS[da - pda]) -
        C[cc] * (DS[ndc - pdc])
      u := S[da][cc] -
        C[ca] * (DS[nda - pda]) -
        C[cc] * (DS[ndc - da] + DS[da - pdc])

      ts := u - t
      if ts >= 0 || float64(ts) > gg * xs.nextLog() * gt {
        ett++
        la.C = cc
        la.Prev.Next = la.Next
        la.Next.Prev = la.Prev
        la.Prev = lc.Prev
        la.Next = lc
        la.Prev.Next = la
        la.Next.Prev = la
      }
    }

    for tt:=0; tt<D; tt++ {
      a := tt
      la := &LA[a]
      bi := la.Prev.Day + 1
      ba := la.Next.Day - 1
      if bi >= ba {
        continue
      }
      dtt++
      b := xs.nextInt(ba - bi) + bi
      if b >= a {
        b++
        if LA[b].Prev.Day > a {
          continue
        }
      } else {
        if LA[b].Next.Day < a {
          continue
        }
      }
      lb := &LA[b]
      ttt++

      ts := sswap(la, lb)
      if ts >= 0 || float64(ts) > gg * xs.nextLog() * gt {
        ctt++
        la.C, lb.C = lb.C, la.C
        la.Prev, lb.Prev = lb.Prev, la.Prev
        la.Next, lb.Next = lb.Next, la.Next
        la.Prev.Next = la
        la.Next.Prev = la
        lb.Prev.Next = lb
        lb.Next.Prev = lb
        sc += ts
      }
    }
  }

  for i:=0; i<D; i++ {
    T[i] = LA[i].C
  }

  fmt.Fprintf(os.Stderr, "score: %d time: %f" +
    " ttt: %d ctt: %d dtt: %d ett: %d ftt %d\n",
    sc, time.Now().Sub(starttime).Seconds(), ttt, ctt, dtt, ett, ftt)
}

func output(){
  for i:=0; i<D; i++ {
    fmt.Println(T[i] + 1)
  }
}

func main(){
  starttime = time.Now()
  rand.Seed(starttime.UnixNano())
  xs = XorShift{X: uint64(rand.Intn(65536) + 1)}
  xs.xinit()
  sinit()
  solve()
  output()
}

Problem Statement

AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.

The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.

Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.

If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).

Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0).
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.

Constraints

D = 365

Each c_i is an integer satisfying 0\leq c_i \leq 100.

Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.

Input

Input is given from Standard Input in the following format:

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}

Output

Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d.
Print D integers t_d to Standard Output in the following format:

t_1
t_2
\vdots
t_D

Any output that does not follow the above format may result in 0 pointsWA for that test case.

Input Generation

Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192

Sample Output 1

1
17
13
14
13

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.

Input generator, score calculator, and visualizer

Beginner's Guide

If you don't know what to do, proceed to problem B or C.


package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"
)

const (
	limitSecs = 2.0
)

// D
var (
	D         int
	c         [26]int
	s         [][26]int
	startTime time.Time
)

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

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

func calcScore(t []int) int {
	var last [26]int
	score := 0
	S := 0
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < len(t); d++ {
		S += s[d][t[d]]
		last[t[d]] = d
		for i := 0; i < 26; i++ {
			S -= c[i] * (d - last[i])
		}
		score += max(1000000+S, 0)
	}
	return score
}

func solution3aSub(t []int, S int, score int, last []int) ([]int, int, int, []int) {
	d := len(t)
	t = append(t, 0)
	bestNewS := -1
	bestNewScore := -1
	bestNewContestType := -1
	for i := 0; i < 26; i++ {
		t[len(t)-1] = i
		newS := S + s[d][t[d]]
		old := last[i]
		last[i] = d
		for j := 0; j < 26; j++ {
			newS -= c[j] * (d - last[j])
		}
		newScore := score + max(1000000+newS, 0)
		if newScore > bestNewScore {
			bestNewS = newS
			bestNewScore = newScore
			bestNewContestType = i
		}
		last[i] = old
	}
	t[len(t)-1] = bestNewContestType
	last[bestNewContestType] = d
	return t, bestNewS, bestNewScore, last
}

func solution3a() []int {
	t := make([]int, 0, D)
	score := 0
	S := 0
	last := make([]int, 26)
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < D; d++ {
		t, S, score, last = solution3aSub(t, S, score, last)
	}
	return t
}

func solution3() []int {
	var t []int
	for d := 0; d < D; d++ {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := calcScore(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return t
}

func solution4Sub(t []int) int {
	l := max(len(t)+13, D)
	for len(t) != l {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := calcScore(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return calcScore(t)
}

func solution4() []int {
	var t []int
	for d := 0; d < D; d++ {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := solution4Sub(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return t
}

func solution4aSubSub(t []int, S int, score int, last []int) ([]int, int, int, []int) {
	d := len(t)
	t = append(t, 0)
	bestNewS := -1
	bestNewScore := -1
	bestNewContestType := -1
	for i := 0; i < 26; i++ {
		old := last[i]
		t[d] = i
		newS := S + s[d][t[d]]
		last[i] = d
		for j := 0; j < 26; j++ {
			newS -= c[j] * (d - last[j])
		}
		newScore := score + max(1000000+newS, 0)
		if newScore > bestNewScore {
			bestNewS = newS
			bestNewScore = newScore
			bestNewContestType = i
		}
		last[i] = old
	}
	t[d] = bestNewContestType
	last[bestNewContestType] = d
	return t, bestNewS, bestNewScore, last
}

func solution4aSub(t []int, S int, score int, last []int) int {
	xt := make([]int, len(t))
	copy(xt, t)
	xLast := make([]int, len(last))
	copy(xLast, last)
	d := len(t)
	for i := d; i < min(d+13, D); i++ {
		xt, S, score, xLast = solution4aSubSub(xt, S, score, xLast)
	}
	return score
}

func solution4a() []int {
	var t []int
	S := 0
	score := 0
	last := make([]int, 26)
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < D; d++ {
		t = append(t, 0)
		newBestScore := -1
		newBestContestType := -1
		for i := 0; i < 26; i++ {
			old := last[i]
			t[d] = i
			newS := S + s[d][t[d]]
			last[i] = d
			for i := 0; i < 26; i++ {
				newS -= c[i] * (d - last[i])
			}
			newScore := score + max(1000000+newS, 0)
			newScore = solution4aSub(t, newS, newScore, last)
			if newScore > newBestScore {
				newBestContestType = i
				newBestScore = newScore
			}
			last[i] = old
		}
		t[d] = newBestContestType
		last[newBestContestType] = d
		S += s[d][t[d]]
		for i := 0; i < 26; i++ {
			S -= c[i] * (d - last[i])
		}
		score += max(1000000+S, 0)
	}
	return t
}

func optimize3(t []int) []int {
	var (
		d   [3]int
		old [3]int
	)
	rand.Seed(time.Now().UnixNano())
	score := calcScore(t)
	for time.Now().Sub(startTime).Seconds()+0.011 < limitSecs {
		n := rand.Intn(3) + 1
		for i := 0; i < n; i++ {
			d[i] = rand.Intn(D)
			old[i] = t[d[i]]
			t[d[i]] = rand.Intn(26)
		}
		newScore := calcScore(t)
		if newScore < score {
			for i := n - 1; i > -1; i-- {
				t[d[i]] = old[i]
			}
		} else {
			score = newScore
		}
	}
	return t
}

func optimize1(t []int) []int {
	rand.Seed(time.Now().UnixNano())
	score := calcScore(t)
	for time.Now().Sub(startTime).Seconds()+0.015 < limitSecs {
		d := rand.Intn(D)
		q := rand.Intn(26)
		old := t[d]
		t[d] = q
		newScore := calcScore(t)
		if newScore < score {
			t[d] = old
		} else {
			score = newScore
		}
	}
	return t
}

func main() {
	defer flush()

	startTime = time.Now()

	D = readInt()
	for i := 0; i < 26; i++ {
		c[i] = readInt()
	}
	s = make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = readInt()
		}
	}

	t := solution4a()
	t = optimize1(t)
	for d := 0; d < D; d++ {
		println(t[d] + 1)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

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

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


package main

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

var D int
var cs []int
var ss [][]int

func main() {
	D = ReadInt()
	cs = ReadInts(26)
	ss = make([][]int, D)
	for i := 0; i < D; i++ {
		ss[i] = ReadInts(26)
	}

	// naives
	answers := []int{}
	last := make([]int, 26)
	for d := 1; d <= D; d++ {
		maxT, maxScore := -1, math.MinInt32
		for i := 0; i < 26; i++ {
			s := ss[d-1][i] - cs[i]*(d-last[i])
			if s > maxScore {
				maxT, maxScore = i, s
			}
		}
		last[maxT] = d
		answers = append(answers, maxT+1)
	}

	rand.Seed(123456777)

	score := scores(answers)
	bestAnswers, bestScore := Dup(answers), score

	start := time.Now()
	timeout := 1950 * time.Millisecond

	for {
		elapsed := time.Now().Sub(start)
		if elapsed >= timeout {
			break
		}

		d, q := rand.Intn(D)+1, rand.Intn(26)+1
		orig := answers[d-1]
		answers[d-1] = q
		score := scores(answers)

		best := false
		if score > bestScore {
			best = true
			bestAnswers, bestScore = Dup(answers), score
		}

		if elapsed < time.Second {
			// 最初はベストのときだけ更新する
			if best {
				// none
			} else {
				answers[d-1] = orig // revert
			}
		} else {
			answers[d-1] = orig // revert
		}
	}

	for _, v := range bestAnswers {
		fmt.Println(v)
	}
}

func Dup(xs []int) []int {
	return append([]int{}, xs...)
}

func scores(answers []int) int {
	last := make([]int, 26)
	score := 0
	for d := 1; d <= D; d++ {
		t := answers[d-1] - 1
		score += ss[d-1][t]
		last[t] = d
		for i := 0; i < 26; i++ {
			score -= cs[i] * (d - last[i])
		}
	}
	return score
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	changeNum := 10
	for x := 0; x < 1; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		for y := 0; y < 80000; y++ {
			changes := make([]int, changeNum)
			pres := make([]int, changeNum)
			for i := 0; i < changeNum; i++ {
				changes[i] = rand.Intn(d)
				pres[i] = schedule[changes[i]]
				schedule[changes[i]] = rand.Intn(26)
			}
			nextScore := calcScore(schedule, c, s, d)
			t = float64(score) * 0.5
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				score = nextScore
			} else {
				for i := 0; i < changeNum; i++ {
					schedule[changes[i]] = pres[i]
				}
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.999
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	for x := 0; x < 5; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		for y := 0; y < 10000; y++ {
			z := make([]int, d)
			copy(z, schedule)
			change := rand.Intn(d)
			val := rand.Intn(26)
			z[change] = val
			nextScore := calcScore(z, c, s, d)
			t = float64(score) * 0.1
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				copy(schedule, z)
				score = nextScore
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.999
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N+1)
	sumA := make([]int, N+1)
	temp = 0
	for i := 1; i <= N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M+1)
	sumB := make([]int, M+1)
	temp = 0
	for i := 1; i <= M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M
	var max int = 0
	for i := 0; i <= N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 0 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				if J > j {
					J = j
				}

				if max < i+j {
					max = i + j
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}

Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.


package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Tsundoku
	var N, M, K int
	fmt.Scan(&N, &M, &K)

	sc.Split(bufio.ScanWords)
	var temp int

	A := make([]int, N)
	sumA := make([]int, N)
	temp = 0
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sumA[i] = temp
	}

	B := make([]int, M)
	sumB := make([]int, M)
	temp = 0
	for i := 0; i < M; i++ {
		B[i] = nextInt()
		temp += B[i]
		sumB[i] = temp
	}

	var J int = M - 1
	var max int = 0
	for i := 0; i < N; i++ {
		if sumA[i] > K {
			break
		}
		for j := J; 0 <= j; j-- {
			if sumA[i]+sumB[j] <= K {
				if J > j {
					J = j
				}

				if max < i+j+2 {
					max = i + j + 2
				}
				break
			} else {
				continue
			}
		}
	}

	fmt.Println(max)
}


package main

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

/*-----------Main-----------*/

func main() {
	N, M, K := readI(), readI(), readI()
	a := readIs(N)
	b := readIs(M)

	var ans, aT int
	bT := sum(b)
	j := M
	for i := 0; i <= N; i++ {
		if i != 0 {
			aT += a[i-1]
		}
		if aT > K {
			break
		}

		for j >= 0 {
			if aT+bT <= K {
				s := i + j
				if s > ans {
					ans = s
				}
				break
			}
			j--
			bT -= b[j]

		}
	}

	fmt.Println(ans)
}

func sum(a []int) int {
	b := 0
	for _, v := range a {
		b += v
	}
	return b
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	testing.Init()
	if flag.Parse(); flag.Arg(0) == "debug" {
		debug()
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Println("Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

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

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

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

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


package main

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

func pa() int {
	reader:=bufio.NewReader(os.Stdin)
	var n,m,k int
	fmt.Fscan(reader, &n,&m,&k)
	A:=make([]int, n)
	for i:=0;i<n;i++{
		fmt.Fscan(reader,&A[i])
	}
	B:=make([]int, m)
	lastKj:=0
	for i:=0;i<m;i++{
		fmt.Fscan(reader,&B[i])
		lastKj+=B[i]
	}

	ans:=0
	ki:=0
	j:=m
	for i:=0;i<=n;i++{
		if ki>k{
			break
		}
		kj:=k-ki
		for lastKj>kj && j>0{
			j--
			lastKj-=B[j]
		}
		if i+j>ans{
			ans=i+j
		}
		if i<n{
			ki+=A[i]
		}
	}

	return ans
}

func main() {
	fmt.Printf("%d\n",pa())

}


package main

import (
	"fmt"
)

func pa() int {
	var n,m,k int
	_,_=fmt.Scanf("%d %d %d", &n,&m,&k)
	A:=make([]int, n)
	for i:=0;i<n-1;i++{
		fmt.Scanf("%d", &A[i])
	}
	fmt.Scanf("%d\n", &A[n-1])
	B:=make([]int, m)
	lastKj:=0
	for i:=0;i<m-1;i++{
		fmt.Scanf("%d", &B[i])
		lastKj+=B[i]
	}
	fmt.Scanf("%d\n", &B[m-1])
	lastKj+=B[m-1]
	ans:=0
	ki:=0
	j:=m
	for i:=0;i<=n;i++{
		kj:=k-ki
		for lastKj>kj{
			j--
			if j<=0{
				break
			}
			lastKj-=B[j]
		}
		if i+j>ans{
			ans=i+j
		}

		if i<n{
			ki+=A[i]
		}
	}

	return ans
}

func main() {
	fmt.Printf("%d\n",pa())

}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intToInt64(x string) int64 {
	y, _ := strconv.Atoi(x)
	return int64(y)
}

func main() {
	s, a, b := nextLine(), nextLine(), nextLine()
	input := strings.Split(s, " ")
	a_array := strings.Split(a, " ")
	b_array := strings.Split(b, " ")
	n := intToInt64(input[0])
	m := intToInt64(input[1])
	k := intToInt64(input[2])
	var a_index int64 = int64(0)
	var b_index int64 = int64(0)
	count := 0

	var x int64
	var y int64
	for {
		if n > a_index {
			x = intToInt64(a_array[a_index])
		} else {
			x = k
		}

		if m > b_index {
			y = intToInt64(b_array[b_index])
		} else {
			y = k
		}

		if (k < x && k < y) || k == 0 {
			break
		}

		if x <= y {
			k -= x
			a_index++
		} else if x > y {
			k -= y
			b_index++
		}

		count++
	}

	fmt.Println(count)
}


package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var k int64
	fmt.Fscan(r, &n, &m, &k)
	a := make([]int64, n+1)
	b := make([]int64, m+1)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		a[i+1] = a[i] + tmp
	}
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		b[i+1] = b[i] + tmp
	}
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		b[i+1] = b[i] + tmp
	}
	var ans int
	j := m
	for i := 0; i <= n; i++ {
		if a[i] > k{
			break
		}
		for b[j] > k - a[i]{
			j--
		}
		if i+j > ans{
			ans = i+j
		}
	}
	fmt.Println(ans)
}


package main

import (
	"fmt"
	"math"
)

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

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

	time := 0
	for i := range a {
		time += a[i]
	}

	ans := 0
	j := 0
	for i := range a {
		if time-a[len(a)-1-i] > k {
			continue
		}
		for true {
			if j > len(b)-1 {
				ans = max(ans, len(a)-i+j)
				break
			}
			if time+b[j] > k {
				ans = max(ans, len(a)-i+j)
				break
			}
			j++
		}
	}
	fmt.Println(ans)
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


package main

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

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

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

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

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

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

	n, m, k := scanInt(), scanInt(), scanInt()
	A := scanInts(n)
	B := scanInts(m)

	a, b := []int{0}, []int{0}

	for _, ele := range A {
		a = append(a, ele)
	}
	for _, ele := range B {
		b = append(b, ele)
	}

	ans, j := 0, m
	for i := 0; i < n+1; i++ {
		if a[i] > k {
			break
		}
		for b[j]+a[i] > k {
			j--
		}
		if ans < i+j {
			ans = i + j
		}
	}
	fmt.Println(ans)
}


package main

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

/* sort */
type pair struct {
	index  int64
	p1, p2 interface{}
}
type pairs []pair

func (slice pairs) Len() int {
	return len(slice)
}

func (slice pairs) Less(i, j int) bool {
	return slice[i].index < slice[j].index
}

func (slice pairs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

/* sort */
type Int64Slice []int64

func (slice Int64Slice) Len() int {
	return len(slice)
}

func (slice Int64Slice) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice Int64Slice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64)                    { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
	INF            = 1e8
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	di      = []int64{-1, 0, 1, 0}
	dj      = []int64{0, -1, 0, 1}
	di8     = []int64{-1, -1, 0, 1, 1, 1, 0, -1}
	dj8     = []int64{0, -1, -1, -1, 0, 1, 1, 1}
)

func main() {
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanWords)
	N, M, K := readInt(), readInt(), readInt()
	A := make([]int64, N)
	B := make([]int64, M)
	Sa := make([]int64, N+1)
	Sb := make([]int64, M+1)
	Sa[0] = 0
	Sb[0] = 0
	for i := int64(0); i < N; i++ {
		A[i] = readInt()
	}
	for i := int64(0); i < M; i++ {
		B[i] = readInt()
	}
	for i := int64(1); i <= N; i++ {
		Sa[i] = Sa[i-1] + A[i-1]
	}
	for i := int64(1); i <= M; i++ {
		Sb[i] = Sb[i-1] + B[i-1]
	}
	var ai int64 = 0
	var ans int64
	// 累積和と二分探索で実装してみる
	for ai <= N {
		if K >= Sa[ai] {
			bi := binarySearch(Sb, K-Sa[ai])
			ans = max(ans, ai+bi)
		}
		ai++
	}
	fmt.Println(ans)
}

func binarySearch(Sb []int64, search int64) int64 {
	ok := int64(0)
	ng := int64(len(Sb))
	for abs(ok-ng) > 1 {
		mid := (ok + ng) / 2
		if Sb[mid] <= search {
			ok = mid
		} else {
			ng = mid
		}
	}
	return ok
}

/*==========================================
 *             Library
 *==========================================*/
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
	res = make([][]int64, h)
	for i := int64(0); i < h; i++ {
		res[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			res[i][j] = init
		}
	}
	return
}

func aryEq(a []int64, b []int64) bool {
	return reflect.DeepEqual(a, b)
}

func clone(n []int64) (r []int64) {
	r = make([]int64, len(n))
	for i := 0; i < len(n); i++ {
		r[i] = n[i]
	}
	return
}
func write(s string) {
	writer.WriteString(s)
}

func print() {
	writer.Flush()
}

// scanner.Split(bufio.ScanWords) をコメントアウトしないと使用不可
func readLine() (s string) {
	if scanner.Scan() {
		s = scanner.Text()
	}
	return s
}

func readInt() (read int64) {
	scanner.Scan()
	read, err := strconv.ParseInt(scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return
}

func readFloat() (read float64) {
	scanner.Scan()
	read, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return
}

func readRunes() (read []rune) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, v)
	}
	return
}

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

func readStrings() (read []string) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, string(v))
	}
	return
}

func s2i(s string) int64 {
	var intVal, e = strconv.ParseInt(s, 10, 64)
	if e != nil {
		panic(e)
	}
	return intVal
}

func i2s(i int64) string {
	var strVal = strconv.FormatInt(i, 10)
	return strVal
}

func s2f(s string) float64 {
	var floatVal, e = strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return floatVal
}

func abs(i int64) int64 {
	return int64(math.Abs(float64(i)))
}

func max(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans < v {
			ans = v
		}
	}
	return ans
}
func min(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans > v {
			ans = v
		}
	}
	return ans
}

func sum(i []int64) int64 {
	sum := int64(0)
	for _, val := range i {
		sum += val
	}
	return sum
}

func split(s string) []string {
	return strings.Fields(s)
}

func strAry2intAry(strs []string) []int64 {
	var ret = make([]int64, 0, len(strs))
	for _, str := range strs {
		var intVal = s2i(str)
		ret = append(ret, intVal)
	}
	return ret
}

func intAry2strAry(nums []int64) []string {
	var ret = make([]string, 0, len(nums))
	for _, num := range nums {
		var strVal = i2s(num)
		ret = append(ret, strVal)
	}
	return ret
}

func ary2str(strs []string) string {
	return strings.Join(strs, " ")
}

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

func ini(res []int, init int) {
	if len(res) == 0 {
		return
	}
	res[0] = init
	for i := 0; i < len(res); i++ {
		copy(res[i:], res[:i])
	}
}

//
// func regexpExample() {
//     // Your code here!
//     var str = "13:20"
//     r := regexp.MustCompile(`(\d+):(\d+)`)
//     fmt.Println(r.FindStringSubmatch(str))
// }

// type Country struct {
//     gold int
//     silver int
//     blonze int
// }

// // 複数ソートのサンプル
// func stableSortExample() []Country{
//     var country = []Country {
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:3, blonze:2},
//         {gold:1, silver:3, blonze:3},
//     }
//     sort.SliceStable(country, func(i, j int) bool { return country[i].blonze > country[j].blonze })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].silver > country[j].silver })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].gold > country[j].gold })
//     return country
// }


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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	INF := 9*int(1e18)
	N, M, K := nextInt(), nextInt(), nextInt()
	A, B := append([]int{-INF}, nextInts(N)...), append([]int{-INF}, nextInts(M)...)
	A, B = append(A, INF), append(B, INF)
	for i:=2; i<=N; i++{
		A[i] += A[i-1]
	}
	for i:=2; i<=M; i++{
		B[i] += B[i-1]
	}
	ans := min(M+1, sort.Search(len(B), func(j int)bool{return K<=B[j]}))-1	// Aからひとつも取らない場合
	for i:=1; i<=N; i++{
		rest := K-A[i]
		if rest < 0{
			break
		}
		// golangでupper_boundどうやるんだ？？？？？？・
		/// bidx := max(0, sort.Search(len(B), func(j int)bool{return rest<=B[j]}))
		// bidx := sort.Search(len(B), func(j int)bool{return rest<=B[j]})-1
		// bidx := sort.SearchInts(B, rest)
		// わからんので仕方なく手書き
		left, right := -1, len(B)
		for right - left > 1{
			mid := (left+right)/2
			if rest-B[mid]>=0{
				left = mid
			}else{
				right = mid
			}
		}
		bidx := left
		ans = max(ans, i+bidx)
	}
	fmt.Fprintln(out, ans)
}

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

func max(a, b int) int {
	if a<b{
		return b
	}
	return a
}
func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int{
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, m, k := scanInt(), scanInt(), scanInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = scanInt() + a[i-1]
	}
	b := make([]int, m+1)
	for i := 1; i <= m; i++ {
		b[i] = scanInt() + b[i-1]
	}

	ans := 0
	p := len(b) - 1
	for i := range a {
		if a[i] > k {
			break
		}
		for j := p; j >= 0; j-- {
			if a[i]+b[j] <= k {
				p = j
				ans = max(ans, i+j)
				break
			}
		}
	}
	fmt.Println(ans)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func parse(books []int, ch int, sh int) (c, sum int) {
	for _, v := range books {
		if sh < sum+v {
			return
		}
		if ch <= c {
			return
		}
		sum += v
		c++
	}

	return
}

func run(a, b []int, n, m, k int) {
	ans := 0
	for i := 0; i <= n; i++ {
		ac, as := parse(a, i, k)
		bc, _ := parse(b, 200000, k-as)
		if ans >= ac+bc {
			break
		}
		ans = ac + bc
	}
	fmt.Printf("%d", ans)
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	k := nextInt()

	var a []int
	var b []int
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}
	for i := 0; i < m; i++ {
		b = append(b, nextInt())
	}

	ac, _ := parse(a, n, k)
	bc, _ := parse(b, m, k)
	if ac == n && bc == m {
		fmt.Printf("%d", ac+bc)
	}

	if ac > bc {
		run(a, b, n, m, k)
	} else {
		run(b, a, m, n, k)
	}

}


package main

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

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	var N, M, K int64
	fmt.Scanf("%d %d %d", &N, &M, &K)
	A := readInt64Slice(int(N))
	B := readInt64Slice(int(M))

	ans := 0
	totalTime := int64(0)
	bIndex := -1
	for i, v := range B {
		if totalTime+v <= K {
			totalTime += v
			ans += 1
		} else {
			bIndex = i - 1
			break
		}
		bIndex = i - 1
	}

	tmp := ans
	for _, v := range A {
		totalTime += v
		for {
			if totalTime <= K || bIndex == -1 {
				break
			}
			totalTime -= B[bIndex]
			tmp -= 1
			bIndex -= 1
		}
		if totalTime <= K {
			tmp += 1
		}
		ans = max(ans, tmp)
	}
	fmt.Println(ans)
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

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

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, M, K int

var P = powInt(10, 10)

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

	N, M, K = nextInt(), nextInt(), nextInt()
	A := make([]int, N)
	B := make([]int, M)
	A[0] = nextInt()
	for i := 1; i < N; i++ {
		A[i] = nextInt() + A[i-1]
	}
	B[0] = nextInt()
	for i := 1; i < M; i++ {
		B[i] = nextInt() + B[i-1]
	}

	ans := 0
	j := M - 1
	for i := 0; i < N; i++ {
		if A[i] > K {
			break
		}
		for B[j] > K-A[i] || j >= 0 {
			j--
		}

		ans = maxInt(ans, i+j+2)
	}

	fmt.Println(ans)
}


// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	M := sc.i()
	K := sc.i()
	A := make([]int, N+1)
	for i := 1; i <= N; i++ {
		A[i] = sc.i() + A[i-1]
	}
	B := make([]int, M+1)
	for i := 1; i <= M; i++ {
		B[i] = sc.i() + B[i-1]
	}

	ans := 0
	j := M
	for i := 1; i <= N; i++ {
		if A[i] > K {
			break
		}
		for B[j] > K-A[i] {
			j--
		}
		if ans < i+j {
			ans = i + j
		}
	}

	fmt.Println(ans)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int
	var m int
	var k int
	var count int
	var countTmp int
	var tmp int
	var aArr []int
	var bArr []int

	sc.Split(bufio.ScanWords)
	n = nextInt()
	m = nextInt()
	k = nextInt()

	countTmp = 0
	for i := 0; i < n; i++ {
		tmp = nextInt()
		countTmp = countTmp + tmp
		aArr = append(aArr, countTmp)
	}

	countTmp = 0
	for i := 0; i < m; i++ {
		tmp = nextInt()
		countTmp = countTmp + tmp
		bArr = append(bArr, countTmp)
	}

	count = 0
	tmp = m - 1
	for i := 0; i < n; i++ {
		if aArr[i] > k {
			break
		}
		for j := tmp; j >= 0; j-- {
			countTmp = i + 1 + j + 1
			if countTmp > count && aArr[i]+bArr[j] <= k {
				count = countTmp
				tmp = j
				break
			}
		}
	}

	fmt.Printf("%d\n", count)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	k := nextInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}

	max := run(a, b, []int{0, 0}, k, 0, 0)
	fmt.Println(max)
}

func run(as []int, bs []int, ks []int, k int, n int, c int) int {
	ap, bp := exec(as, bs, ks, k, n)
	//fmt.Println([]int{ap, bp})
	if ap == 0 && bp == 0 {
		return c
	}
	c++
	aret := c
	bret := c
	if ap != 0 {
		ks[0]++
		aret = run(as, bs, ks, k, ap, c)
	}
	if bp != 0 {
		ks[1]++
		bret = run(as, bs, ks, k, bp, c)
	}

	return max(aret, bret)
}

func exec(as []int, bs []int, ks []int, k int, n int) (int, int) {
	var a, b int
	if len(as) > ks[0] && k >= n+as[ks[0]] {
		a = n + as[ks[0]]
	}
	if len(bs) > ks[1] && k >= n+bs[ks[1]] {
		b = n + bs[ks[1]]
	}
	return a, b
}

func max(a int, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() (ret string) {

	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return ""
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type Utls struct {
}

type uString string

var utls = &Utls{}

func (u *Utls) readLineU() uString {
	return uString(readLine())
}

func (u *Utls) atoi(str string) int {
	r, _ := strconv.Atoi(str)
	return r
}
func (u *Utls) itoa(n int) string {
	r := strconv.Itoa(n)
	return r
}
func (u uString) atoi() int {
	r, err := strconv.Atoi(string(u))
	if err != nil {
		return -1
	}
	return r
}
func (u uString) atoiArr() []int {
	ret := make([]int, 0)

	l := strings.Split(string(u), " ")

	for i := 0; i < len(l); i++ {
		s := (uString(l[i]))

		ret = append(ret, s.atoi())

	}
	return ret
}
func (u uString) String() string {
	return string(u)
}

var memo map[string]int = make(map[string]int)
var cmp map[string]int= make(map[string]int)

var (
	N,M,K int
	A []int
	B []int
)
type node struct {

	idx1,idx2 int
	cnt int

}
func newNode(i1,i2 int) *node{
	ret:= &node{

	}
	ret.idx1 = i1
	ret.idx2 = i2
	return ret
}
func (n*node)newNode(i1,i2 int) (*node, bool){
	ret:= &node{

	}
	if  i1 >= N || i2>= M{
		cmp[n.String()] = n.idx1+n.idx2 + 2

		return nil,false
	}
	ret.idx1 = i1
	ret.idx2 = i2
	if n.idx1 != i1{
		ret.cnt += n.cnt+ A[i1]
	} else {
		ret.cnt += n.cnt+ B[i2]
	}
	if  ret.cnt > K{

		cmp[n.String()] = n.idx1+n.idx2 + 2

		return nil,false
	}
	if ret.cnt == K{
		cmp[ret.String()] = ret.idx1+ret.idx2 +2

		return nil,false
	}

	_,ok:= memo[ret.String()]
	if ok {
		return nil,false
	}
	r2 := newNode(i1+1,i2)
	r3:= newNode(i1,i2+1)
	_,ok2:= memo[r2.String()]
	_,ok3:= memo[r3.String()]

		if  ok2 && ok3 {
			return nil,false
		}

	memo[ret.String()] = ret.cnt
	return ret,true
}
func (n*node) String()string {
	ret:= utls.itoa(n.idx1) +" "+ utls.itoa(n.idx2)

	return ret

}
func (n*node) next ()[]*node {
	ret:= make([]*node ,0)
	n1,b:=	n.newNode(n.idx1+1, n.idx2)
	if b {
		ret=append(ret,n1)
	}
	n2,b:=	n.newNode(n.idx1, n.idx2+1)
	if b {
		ret=append(ret,n2)
	}
	return ret

}

func main() {
	 l1 := utls.readLineU().atoiArr()
	 A = utls.readLineU().atoiArr()
	 B = utls.readLineU().atoiArr()
  N= l1[0]
  M= l1[1]
	 K= l1[2]
	 nodes:= make([]*node ,0)

	 nodes= append(nodes, newNode(-1,-1))

	 for len(nodes)>0 {
		 n := nodes[0]

		nodes= nodes[1:]
	//	for _,n := range ns{
			 nn :=n.next()
			 if len(nn) > 0{
				 nodes= append(nodes, nn...)
				// fmt.Println(len(nn))
			 }

			 sort. Slice(nodes ,  func (i,j int) bool{

				 if  nodes[i].idx1 + nodes[i].idx2 != nodes[j].idx1 + nodes[j].idx2{
				 return 	nodes[i].idx1 + nodes[i].idx2 > nodes[j].idx1 + nodes[j].idx2
				 }
				 return nodes[i].cnt < nodes[j].cnt
			 } )

	//	}

	 }

//	 r :=  (a)+ (a*a) + (a*a*a)

ret:= 0
for  _,v:= range cmp {
	//fmt.Println ( v)
	if ret< v{

ret= v
	}
}
	 fmt.Println ( ret)
}


package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() (ret string) {

	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return ""
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type Utls struct {
}

type uString string

var utls = &Utls{}

func (u *Utls) readLineU() uString {
	return uString(readLine())
}

func (u *Utls) atoi(str string) int {
	r, _ := strconv.Atoi(str)
	return r
}
func (u *Utls) itoa(n int) string {
	r := strconv.Itoa(n)
	return r
}
func (u uString) atoi() int {
	r, err := strconv.Atoi(string(u))
	if err != nil {
		return -1
	}
	return r
}
func (u uString) atoiArr() []int {
	ret := make([]int, 0)

	l := strings.Split(string(u), " ")

	for i := 0; i < len(l); i++ {
		s := (uString(l[i]))

		ret = append(ret, s.atoi())

	}
	return ret
}
func (u uString) String() string {
	return string(u)
}

var memo map[string]int = make(map[string]int)
var cmp map[string]int= make(map[string]int)

var (
	N,M,K int
	A []int
	B []int
)
type node struct {

	idx1,idx2 int
	cnt int

}
func newNode(i1,i2 int) *node{
	ret:= &node{

	}
	ret.idx1 = i1
	ret.idx2 = i2
	return ret
}
func (n*node)newNode(i1,i2 int) (*node, bool){
	ret:= &node{

	}
	if  i1 >= N || i2>= M{
		cmp[n.String()] = n.idx1+n.idx2 + 2

		return nil,false
	}
	ret.idx1 = i1
	ret.idx2 = i2
	if n.idx1 != i1{
		ret.cnt += n.cnt+ A[i1]
	} else {
		ret.cnt += n.cnt+ B[i2]
	}
	if  ret.cnt > K{

		cmp[n.String()] = n.idx1+n.idx2 + 2

		return nil,false
	}
	if ret.cnt == K{
		cmp[ret.String()] = ret.idx1+ret.idx2 +2

		return nil,false
	}

	_,ok:= memo[ret.String()]
	if ok {
		return nil,false
	}
	r2 := newNode(i1+1,i2)
	r3:= newNode(i1,i2+1)
	_,ok2:= memo[r2.String()]
	_,ok3:= memo[r3.String()]

		if  ok2 && ok3 {
			return nil,false
		}

	memo[ret.String()] = ret.cnt
	return ret,true
}
func (n*node) String()string {
	ret:= utls.itoa(n.idx1) +" "+ utls.itoa(n.idx2)

	return ret

}
func (n*node) next ()[]*node {
	ret:= make([]*node ,0)
	n1,b:=	n.newNode(n.idx1+1, n.idx2)
	if b {
		ret=append(ret,n1)
	}
	n2,b:=	n.newNode(n.idx1, n.idx2+1)
	if b {
		ret=append(ret,n2)
	}
	return ret

}

func main() {
	 l1 := utls.readLineU().atoiArr()
	 A = utls.readLineU().atoiArr()
	 B = utls.readLineU().atoiArr()
  N= l1[0]
  M= l1[1]
	 K= l1[2]
	 nodes:= make([]*node ,0)

	 nodes= append(nodes, newNode(-1,-1))

	 for len(nodes)>0 {
		 n := nodes[0]

		nodes= nodes[1:]
	//	for _,n := range ns{
			 nn :=n.next()
			 if len(nn) > 0{
				 nodes= append(nodes, nn...)
				// fmt.Println(len(nn))
			 }

			 sort.Slice(nodes ,  func (i,j int) bool{

				return  nodes[i].cnt < nodes[j].cnt
			 } )

	//	}

	 }

//	 r :=  (a)+ (a*a) + (a*a*a)

ret:= 0
for  _,v:= range cmp {
	//fmt.Println ( v)
	if ret< v{

ret= v
	}
}
	 fmt.Println ( ret)
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	M := getInt()
	K := getInt()
	A := getIntArray(N)
	B := getIntArray(M)

	cntA := 0
	cntB := 0
	var totalA []int
	var totalB []int
	for i, a := range A {
		if i != 0 && totalA[i-1] + a > K {
			break
		}
		cntA++
		total := a
		if i != 0 {
			total += totalA[i-1]
		}
		totalA = append(totalA, total)
	}
	for i, b := range B {
		if i != 0 && totalB[i-1] + b > K {
			break
		}
		cntB++
		total := b
		if i != 0 {
			total += totalB[i-1]
		}
		totalB = append(totalB, total)
	}

	//fmt.Println(totalA)
	//fmt.Println(totalB)

	result := 0
	rest := K
	indexA := 0
	indexB := 0
	usedTotalA := 0
	usedTotalB := 0
	for {
		//fmt.Println(cntA, cntB)
		if indexA >= cntA && indexB >= cntB {
			break
		} else if indexA >= cntA {
			if rest - B[indexB] < 0 {
				break
			}
			result++
			rest -= B[indexB]
			usedTotalB += B[indexB]
			indexB++
		} else if indexB >= cntB {
			if rest - A[indexA] < 0 {
				break
			}
			result++
			rest -= A[indexA]
			usedTotalA += A[indexA]
			indexA++
		} else {
			if (cntA - indexA) >= (cntB - indexB) {
				if rest-A[indexA] < 0 {
					break
				}
				result++
				rest -= A[indexA]
				usedTotalA += A[indexA]
				indexA++
			} else {
				if rest - B[indexB] < 0 {
					break
				}
				result++
				rest -= B[indexB]
				usedTotalB += B[indexB]
				indexB++
			}
		}

		//fmt.Println(usedTotalA, usedTotalB, rest)
		for i := cntA; i > 0; i-- {
			if totalA[i-1] - usedTotalA <= rest {
				cntA = i
				break
			}
		}
		for i := cntB; i > 0; i-- {
			if totalB[i-1] - usedTotalB <= rest {
				cntB = i
				break
			}
		}
	}

	fmt.Println(result)
}

type Graph struct {
	n     int
	edges []map[int]struct{}
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([]map[int]struct{}, n),
	}
	for i := 0; i < n; i++ {
		g.edges[i] = make(map[int]struct{})
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v][u] = struct{}{}
	g.edges[u][v] = struct{}{}
}

func dfs(c int, edges []map[int]struct{}, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	standby := make(map[int]struct{})
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}
		delete(standby, u)

		for v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			if _, exists := standby[v]; !exists {
				next = append(next, v)
				standby[v] = struct{}{}
			}
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringArray(n int) []string {
	array := make([]string, n)
	for i := 0; i < n; i++ {
		array[i] = getString()
	}
	return array
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	divisor := make(map[int]struct{})
	divisor[1] = struct{}{}
	if n != 1 {
		divisor[n] = struct{}{}
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor[i] = struct{}{}
			divisor[n/i] = struct{}{}
		}
	}

	var divisorArray []int
	for d := range divisor {
		divisorArray = append(divisorArray, d)
	}
	return divisorArray
}

type intHeap []int

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

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}

func primeFactors(n int) [] int {
	factors := make([]int, 0)
	i := 2
	for i * i <= n {
		r := n % i
		if r != 0 {
			i += 1
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}


package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr64()
	N := uint64(list[0])
	M := uint64(list[1])
	K := uint64(list[2])
	A := getStdinIntArru64()
	B := getStdinIntArru64()

	var cnta uint64 = 0
	var cntb uint64 = 0
	var time uint64 = 0
	for {
		if cnta >= N && cntb >= M {
			break
		}
		if cnta >= N {
			time += B[cntb]
			if time > K {
				break
			}
			cntb++
			continue
		}
		if cntb >= M {
			time += A[cnta]
			if time > K {
				break
			}
			cnta++
			continue
		}
		if A[cnta] < B[cntb] {
			time += A[cnta]
			if time > K {
				break
			}
			cnta++
		} else {
			time += B[cntb]
			if time > K {
				break
			}
			cntb++
		}
	}

	fmt.Printf("%d\n", cnta+cntb)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func getStdinIntArru64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		var i int64
		i, _ = strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(i)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, m, k := io.NextInt(), io.NextInt(), io.NextInt()
	a := io.NextInts(n)
	b := io.NextInts(m)
	ans := solve(k, a, b)
	io.Println(ans)
}

func solve(k int, a, b []int) (ans int) {
	n, m := len(a), len(b)
	for i := 1; i < n; i++ {
		a[i] = a[i-1] + a[i]
	}
	for i := 1; i < m; i++ {
		b[i] = b[i-1] + b[i]
	}
	max := 0
	for i := 0; i < n; i++ {
		if a[i] > k {
			break
		}
		j := sort.Search(m, func(j int) bool { return a[i]+b[j] > k })
		count := (i + 1) + j
		if count > max {
			max = count
		}
	}
	return max
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


package main
import (
  "fmt"
  //"math"
  // "sort"
  //"regexp"
)

func main(){
  var na, nb, time, book, count, ca ,cb int
  fmt.Scan(&na)
  fmt.Scan(&nb)
  fmt.Scan(&time)
  a := make([]int, na + 1)
  b := make([]int, nb + 1)
  for i := 0; i < na; i++ {
    fmt.Scan(&book)
    a[i] = book
  }
  a[na] = 10000000001
  for i := 0; i < nb; i++ {
    fmt.Scan(&book)
    b[i] = book
  }
  b[nb] = 10000000001

  for time > 0 {
  //fmt.Printf("count %v, a %v, b %v, ca %v, cb %v\n", count, a, b, ca, cb)
    if a[ca] > b[cb] {
      time = time - b[cb]
      if b[cb] != 10000000001 {
        cb++
      }
    } else {
      time = time - a[ca]
      if a[ca] != 10000000001 {
        ca++
      }
    }
    if time >= 0 {
      count++
    }
  }
  fmt.Printf("%v\n", count)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, m, k := scanInt(), scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}
	b := make([]int, m)
	for i := range b {
		b[i] = scanInt()
	}

	ans := 0
	sum := 0
	var pa int
	for i := range a {
		if sum+a[i] > k {
			break
		}
		sum += a[i]
		pa = i
		ans++
	}
	var pb int
	for i := range b {
		if sum+b[i] > k {
			break
		}
		sum += b[i]
		pb = i
		ans++
	}

	t := ans
	for i := pa - 1; i >= 0; i-- {
		sum -= a[i]
		t--
		for j := pb + 1; j < len(b); j++ {
			if sum+b[j] > k {
				break
			}
			sum += b[j]
			pb = j
			t++
		}
		ans = max(ans, t)
	}
	fmt.Println(ans)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	k := nextInt()
	a := make([]int, n)
	b := make([]int, m)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	for i := 0; i < m; i++ {
		b[i] = nextInt()
	}
	var spent, aGone, bGone int
	for {
		if spent > k {
			aGone--
			break
		} else if spent == k {
			break
		}
		if aGone >= n && bGone < m {
			spent += b[bGone]
			bGone++
			continue
		} else if aGone >= n && bGone >= m {
			break
		}
		if bGone >= m && aGone < n {
			spent += a[aGone]
			aGone++
			continue
		} else if aGone >= n && bGone >= m {
			break
		}
		if a[aGone] <= b[bGone] {
			spent += a[aGone]
			aGone++
		} else {
			spent += b[bGone]
			bGone++
		}
	}
	fmt.Println(aGone + bGone)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	k := nextInt()
	a := make([]int64, n+10)
	b := make([]int64, m+10)
	a[0] = 0
	b[0] = 0
	for i := int64(1); i <= n; i++ {
		a[i] = a[i-1] + nextInt()
	}
	for i := int64(1); i <= m; i++ {
		b[i] = b[i-1] + nextInt()
	}
	res := int64(0)
	j := int64(0)
	for j = int64(0); j <= m && b[j] <= k; j++ {
	}
	if j == m+1 || b[j] > k {
		j--
	}
	res = j
	for i := int64(1); i <= n; i++ {
		if a[i] > k {
			break
		}
		for ; a[i]+b[j] > k && j > 0; j-- {
		}
		if i+j > res {
			res = i + j
		}
	}
	fmt.Println(res)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, m, k := scanInt(), scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}
	b := make([]int, m)
	for i := range b {
		b[i] = scanInt()
	}

	ans := 0
	sum := 0
	var pa int
	for i := range a {
		if sum+a[i] > k {
			break
		}
		sum += a[i]
		pa = i
		ans++
	}
	var pb int
	for i := range b {
		if sum+b[i] > k {
			break
		}
		sum += b[i]
		pb = i
		ans++
	}

	t := ans
	for pa > 0 {
		sum -= a[pa]
		pa--
		t--
		for i := pb + 1; i < len(b); i++ {
			if sum+b[i] > k {
				break
			}
			sum += b[i]
			pb = i
			t++
		}
		ans = max(ans, t)
	}
	fmt.Println(ans)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	m := nextInt()
	k := nextInt()
	a := nextInts(n)
	b := nextInts(m)

	atime := 0
	ai := 0

	bi := 0
	btime := 0

	for i := 0; i < n; i++ {
		if atime+a[i] <= k {
			atime += a[i]
			ai = i + 1
		} else {
			break
		}
	}

	ans := ai

	for i := ai - 1; i >= -1; i-- {
		for j := bi + 1; j < m; j++ {
			if atime+btime+b[j] <= k {
				btime += b[j]
				bi = j + 1
			} else {
				break
			}
		}
		ans = maxInt(ans, ai+bi)
		/*
			fmt.Fprintln(out, "[DEBUG]", atime, btime)
			fmt.Fprintln(out, "[DEBUG]", ai, bi)
			fmt.Fprintln(out, "[DEBUG]", ans)
		*/

		if i >= 0 {
			atime -= a[i]
			ai--
		}
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}


package main

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

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	bs := make([]int, m)
	for i := range bs {
		sc.Scan()
		bs[i], _ = strconv.Atoi(sc.Text())
	}

	sbs := make([]int, m+1)
	for i := range bs {
		sbs[i+1] += sbs[i] + bs[i]
	}

	var mi, mc int
	for i := 0; i <= n; i++ {
		ri := k - mi
		if ri < 0 {
			break
		}

		l := 0
		r := m + 1
		for r-l > 1 {
			mid := (l + r) / 2
			if sbs[mid] <= ri {
				l = mid
			} else {
				r = mid
			}
		}
		cnt := i + l
		mc = max(mc, cnt)
		if i < n {
			mi += as[i]
		}
	}
	fmt.Println(mc)
}

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


package main
import "fmt"

var N int

func main(){
  fmt.Scanf("%d", &N)
  v := make([]int, N+1)
  for i:=1; i<=N; i++ {
    for j:=i; j<=N; j+=i {
    	v[j]++
    }
  }
  ans := int64(0)
  for i:=1; i<=N; i++ {
    ans += int64(i)*int64(v[i])
  }
  fmt.Println(ans)
}

Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.


package main

import (
	"fmt"
)

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

	res := 0
	for i := 1; i <= N; i++ {
		res += f(N,i)
	}
	fmt.Println(res)

}

func f(n, x int) int {
	y := n/x
	return (y*(y+1) *x)/2
}