Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

If Vasya can write the given anonymous letter, print YES, otherwise print NO

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

// 43B
package main

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

func main() {
	var i int
	a := make([]int, 150)
	var s, l string
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanLines)
	in.Scan()
	s = in.Text()
	in.Scan()
	l = in.Text()
	for i = 0; i < len(s); i++ {
		a[s[i]]++
	}
	for i = 0; i < len(l); i++ {
		if a[l[i]] < 1 && l[i] != ' ' {
			fmt.Print("NO")
			return
		}
		a[l[i]]--
	}
	fmt.Print("YES")
	return
}

[{'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nwhere is your dog\r\n', 'output': ['NO\r\n']}, {'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['YES\r\n']}, {'input': 'Instead of dogging your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['NO\r\n']}, {'input': 'abcdefg hijk\r\nk j i h g f e d c b a\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgo\r\neAtAVB\r\n', 'output': ['NO\r\n']}, {'input': 'GRZGc\r\nLPzD\r\n', 'output': ['NO\r\n']}, {'input': 'GtPXu\r\nd\r\n', 'output': ['NO\r\n']}, {'input': 'FVF\r\nr \r\n', 'output': ['NO\r\n']}, {'input': 'HpOKgo\r\nogK\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGc\r\nZG\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT  MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\r\nAHN  XvoaNwV  AVBKwKjr u      U K wKE D K   Jy KiHsR h d W  Js IHyMPK Br iSqe  E fDA   g H\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\r\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj  bCDgKF  jJxa RddtLFAi VGLHH SecObzG q  hPF \r\n', 'output': ['YES\r\n']}, {'input': 'GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\r\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp\r\n', 'output': ['YES\r\n']}, {'input': 'FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\r\nUzrU K  an GFGR        Wc zt iBa     P c    T K v p     V In   b           B   c\r\n', 'output': ['YES\r\n']}, {'input': 'lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\r\nAoxe  jWZ u  yImg  o AZ FNI w lpj  tNhT g y  ZYcb rc J    w Dlv\r\n', 'output': ['YES\r\n']}, {'input': 'kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\r\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc\r\n', 'output': ['YES\r\n']}, {'input': 'kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\r\nBsH   bWHJD n Ca T xq  PRCv  tatn Wjy sm  I q s WCjFqdWe  t W XUs  Do  eb Pfh ii  hTbF  O Fll\r\n', 'output': ['YES\r\n']}, {'input': 'OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\r\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK\r\n', 'output': ['YES\r\n']}, {'input': 'NwcGaIeSkOva\r\naIa\r\n', 'output': ['YES\r\n']}, {'input': 'gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\r\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui\r\n', 'output': ['YES\r\n']}, {'input': 'ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\r\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy\r\n', 'output': ['NO\r\n']}, {'input': 'hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\r\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW\r\n', 'output': ['NO\r\n']}, {'input': 'yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\r\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw\r\n', 'output': ['NO\r\n']}, {'input': 'jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\r\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL\r\n', 'output': ['NO\r\n']}, {'input': 'zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\r\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl\r\n', 'output': ['NO\r\n']}, {'input': 'kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\r\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh\r\n', 'output': ['NO\r\n']}, {'input': 'AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\r\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ\r\n', 'output': ['NO\r\n']}, {'input': 'lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\r\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl\r\n', 'output': ['NO\r\n']}, {'input': 'BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\r\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk\r\n', 'output': ['NO\r\n']}, {'input': 'KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\r\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk\r\n', 'output': ['NO\r\n']}]


Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n+1 bus stops. All of them are numbered with integers from 0 to n in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 0 and the bus stop by the school has number n.There are m buses running between the house and the school: the i-th bus goes from stop si to ti (si<ti), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the i-th bus on any stop numbered from si to ti-1 inclusive, but he can get off the i-th bus only on the bus stop ti.Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 1000000007 (10^9+7).

The first line contains two space-separated integers: n and m (1≤n≤10^9,0≤m≤10^5). Then follow m lines each containing two integers si,ti. They are the numbers of starting stops and end stops of the buses (0≤si<ti≤n).

Print the only number — the number of ways to get to the school modulo 1000000007 (10^9+7).

The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.
In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0.
In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 2^4=16.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF101B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod int = 1e9 + 7

	var n, m, ans int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, m)
	b := make(sort.IntSlice, 0, m*2)
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
		b = append(b, a[i].l, a[i].r)
	}
	b.Sort()
	if m == 0 || b[0] != 0 || b[m*2-1] != n {
		Fprint(out, 0)
		return
	}

	tree := make([]int, m*2+1)
	add := func(i, val int) {
		for ; i <= m*2; i += i & -i {
			tree[i] = (tree[i] + val) % mod
		}
	}
	sum := func(i int) (res int) {
		for ; i > 0; i &= i - 1 {
			res = (res + tree[i]) % mod
		}
		return
	}
	add(1, 1)
	sort.Slice(a, func(i, j int) bool { return a[i].r < a[j].r })
	for _, p := range a {
		r := b.Search(p.r)
		res := (sum(r) + mod - sum(b.Search(p.l))) % mod
		if p.r < n {
			add(r+1, res)
		} else {
			ans = (ans + res) % mod
		}
	}
	Fprint(out, ans)
}

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


In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k-1)m,(k-1)m+l], and l<m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

The first input line contains 4 integer numbers n, d, m, l (1≤n,d,m,l≤10^6,l<m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k-1)m,(k-1)m+l].

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}

	var n, d, m, l int64
	scanf("%d %d %d %d\n", &n, &d, &m, &l)
	if d == 1 {
		if l != m-1 {
			printf("%d\n", l+1)
		} else {
			printf("%d\n", (n-1)*m+l+1)
		}
		return
	}

	for i := 0; int64(i) < n; i++ {
		for j := int64(i)*m + l + 1; j < int64(i)*m+m; j++ {
			if j%d == 0 {
				printf("%d\n", j)
				return
			}
		}
	}
	for j := (n-1)*m + l + 1; ; j++ {
		if j%d == 0 {
			printf("%d\n", j)
			return
		}
	}
}


Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles. Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integer points (points with integer coordinates) inside or on the border of the polygon and then draws a square with two opposite vertices lying in the chosen points, what will the expectation of this square's area be?A pair of distinct points is chosen uniformly among all pairs of distinct points, located inside or on the border of the polygon. Pairs of points p,q (p≠q) and q,p are considered the same.Help Ksusha! Count the required expectation.

The first line contains integer n (3≤n≤10^5) — the number of vertices of Ksusha's convex polygon. Next n lines contain the coordinates of the polygon vertices in clockwise or counterclockwise order. The i-th line contains integers xi,yi (|xi|,|yi|≤10^6) — the coordinates of the vertex that goes i-th in that order.

Print a single real number — the required expected area.
The answer will be considered correct if its absolute and relative error doesn't exceed 10^-6.

package main

import (
	"fmt"
	"math"
)

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

	points := make([][2]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&points[i][0], &points[i][1])
	}

	// Calculate the total area
	totalArea := 0.0
	for i := 0; i < n; i++ {
		j := (i + 1) % n
		totalArea += float64(points[i][0]*points[j][1] - points[j][0]*points[i][1])
	}
	totalArea = math.Abs(totalArea) / 2.0

	// Calculate the sum of squares of distances from the origin to each point
	sumSquareDistances := 0.0
	for _, point := range points {
		sumSquareDistances += float64(point[0]*point[0] + point[1]*point[1])
	}

	// Calculate the expected area
	expectedArea := totalArea / sumSquareDistances

	fmt.Printf("%.10f\n", expectedArea)
}


Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed.It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of a km/h^2, and has maximum speed of v km/h. The road has the length of l km, and the speed sign, limiting the speed to w km/h, is placed d km (1≤d<l) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed.The car can enter Bercouver at any speed.

The first line of the input file contains two integer numbers a and v (1≤a,v≤10000). The second line contains three integer numbers l, d and w (2≤l≤10000; 1≤d<l; 1≤w≤10000).

Print the answer with at least five digits after the decimal point.

package main

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

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

func scan(a ...interface{}) (n int, err error)             { return fmt.Fscan(in, a...) }
func scanf(f string, a ...interface{}) (n int, err error)  { return fmt.Fscanf(in, f, a...) }
func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }

//https://codeforces.com/problemset/problem/5/D

func main() {
	defer out.Flush()

	var a, v, l, d, w float64
	scanf("%f %f\n", &a, &v)
	scanf("%f %f %f\n", &l, &d, &w)

	if v > w {
		if s := w * w / 2 / a; s <= d {
			peak := math.Sqrt(a*d + w*w/2)
			t1 := 0.0
			if peak <= v {
				t1 = (2*peak - w) / a
			} else {
				t1 = (2*v-w)/a + (d-(v*v-w*w/2)/a)/v
			}
			printf("%.6f\n", t1+getTime(w, v, a, l-d))
		} else {
			printf("%.6f\n", getTime(0, v, a, l))
		}
	} else {
		printf("%.6f\n", getTime(0, v, a, l))
	}
}

func getTime(v0, maxV, a, l float64) float64 {
	if s := (maxV*maxV - v0*v0) / 2 / a; s <= l {
		return (maxV-v0)/a + (l-s)/maxV
	}
	return (math.Sqrt(v0*v0+2*a*l) - v0) / a
}


There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:   alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;  erase x — to erase the block with the identifier x;  defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

The first line of the input data contains two positive integers t and m (1≤t≤100;1≤m≤100), where t — the amount of operations given to the memory manager for processing, and m — the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1≤n≤100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.

Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.

6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6

package main

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

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

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

type memory struct {
	begin  int
	end    int
	status int
	id     int
	next   *memory
	prev   *memory
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}
	var t, m int
	scanf("%d %d\n", &t, &m)
	tag := make([]int8, t+1)
	head := new(memory)
	head.id = -1
	head.status = -1
	a := new(memory)
	a.begin = 0
	a.end = m
	a.status = 0
	head.next = a
	head.prev = a
	a.next = head
	a.prev = head
	success := 1
	for i := 1; i <= t; i++ {
		s, _ := reader.ReadString('\n')
		s = strings.Trim(s, "\r\n")
		if s[0] == 'a' {
			need, _ := strconv.Atoi(s[6:])
			curr := head.next
			for curr != head {
				if curr.status != 0 {
					curr = curr.next
					continue
				}
				if curr.end-curr.begin == need {
					tag[success] = 1
					printf("%d\n", success)
					curr.status = 1
					curr.id = success
					success++
					break
				} else if curr.end-curr.begin > need {
					tag[success] = 1
					printf("%d\n", success)
					n := new(memory)
					n.end = curr.end
					n.begin = curr.begin + need
					n.status = 0
					n.prev = curr
					n.next = curr.next
					n.next.prev = n
					curr.end = curr.begin + need
					curr.status = 1
					curr.next = n
					curr.id = success
					success++
					break
				} else {
					curr = curr.next
				}
			}
			if curr == head {
				printf("NULL\n")
			}
		} else if s[0] == 'e' {
			num, _ := strconv.Atoi(s[6:])
			//fmt.Println(num, t, tag)
			if num <= 0 || num >= t || tag[num] != 1 {
				printf("ILLEGAL_ERASE_ARGUMENT\n")
			} else {
				//fmt.Println("enter")
				tag[num] = 0
				curr := head.next
				for curr != head {
					if curr.status == 1 && curr.id == num {
						curr.status = 0
						curr.id = 0
						prev := curr.prev
						if prev.status == 0 && prev.end == curr.begin {
							prev.end = curr.end
							prev.next = curr.next
							prev.next.prev = prev
							curr = prev
						}
						next := curr.next
						if next.status == 0 && next.begin == curr.end {
							curr.end = next.end
							curr.next = next.next
							curr.next.prev = curr
						}
					} else {
						curr = curr.next
					}
				}
			}
		} else {
			curr := head.next
			start := 0

			for curr != head {
				if curr.status == 1 {
					tb := curr.begin
					te := curr.end
					curr.begin = start
					curr.end = te - tb + start
					start = curr.end
					curr = curr.next
				} else {
					curr.prev.next = curr.next
					curr.next.prev = curr.prev
					curr = curr.next
				}
			}
			avail := new(memory)
			avail.begin = start
			avail.end = m
			avail.status = 0
			avail.next = head
			avail.prev = head.prev
			head.prev.next = avail
			head.prev = avail
		}
		//pp(head)
	}
}

func pp(p *memory) {
	curr := p.next
	for curr != p {
		fmt.Println(curr)
		curr = curr.next
	}
	fmt.Println()
}

[{'input': ['6 10\r\nalloc 5\r\nalloc 3\r\nerase 1\r\nalloc 6\r\ndefragment\r\nalloc 6\r\n'], 'output': ['1\r\n2\r\nNULL\r\n3\r\n']}, {'input': ['6 1\r\ndefragment\r\nalloc 10\r\nalloc 1\r\nerase -1\r\nerase 1\r\nerase 1\r\n'], 'output': ['NULL\r\n1\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['14 100\r\nalloc 99\r\nalloc 1\r\nalloc 1\r\nerase 2\r\nalloc 1\r\nerase 4\r\nerase 1\r\nalloc 100\r\nalloc 1\r\nalloc 99\r\ndefragment\r\nerase 4\r\nalloc 100\r\nalloc 99\r\n'], 'output': ['1\r\n2\r\nNULL\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n4\r\nNULL\r\nNULL\r\nNULL\r\n']}, {'input': ['26 25\r\ndefragment\r\nerase 1\r\nerase -1560200883\r\nalloc 44\r\ndefragment\r\nalloc 75\r\nalloc 22\r\ndefragment\r\nerase 4\r\ndefragment\r\nalloc 57\r\nalloc 53\r\nerase 4\r\nerase -1639632026\r\nerase -2121605039\r\nerase 3\r\nalloc 51\r\nalloc 65\r\ndefragment\r\nerase 2\r\nerase 4\r\nalloc 52\r\nerase 3\r\ndefragment\r\nerase -1842529282\r\nerase 3\r\n'], 'output': ['ILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n1\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['22 9\r\nerase 1\r\nalloc 6\r\nalloc 65\r\nerase 1\r\nalloc 87\r\nerase -1638927047\r\nalloc 5\r\nerase 2\r\nalloc 70\r\ndefragment\r\nalloc 20\r\nalloc 48\r\nerase -69401977\r\nalloc 20\r\ndefragment\r\nerase 7\r\ndefragment\r\nerase 9\r\nerase 7\r\nerase 4\r\ndefragment\r\nalloc 66\r\n'], 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': ['12 40\r\nerase 1\r\nalloc 21\r\nalloc 5\r\nalloc 7\r\ndefragment\r\ndefragment\r\nerase 2\r\nalloc 83\r\nerase 4\r\ndefragment\r\nalloc 59\r\ndefragment\r\n'], 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\n2\r\n3\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': ['38 18\r\nalloc 72\r\nerase 2\r\nalloc 50\r\ndefragment\r\nerase 3\r\ndefragment\r\nalloc 43\r\nalloc 41\r\ndefragment\r\ndefragment\r\nalloc 26\r\nalloc 46\r\nalloc 16\r\nalloc 15\r\ndefragment\r\ndefragment\r\nalloc 95\r\nerase 7\r\nerase 7\r\nerase 5\r\nerase 2\r\nerase 9\r\nerase 7\r\nalloc 43\r\ndefragment\r\nerase 7\r\ndefragment\r\nalloc 48\r\nalloc 77\r\nerase 10\r\nerase 11\r\nalloc 16\r\nalloc 84\r\nerase 1\r\ndefragment\r\nalloc 86\r\ndefragment\r\nerase 13\r\n'], 'output': ['NULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nNULL\r\n1\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['37 74\r\nalloc 11\r\ndefragment\r\nerase 1\r\ndefragment\r\nerase 2\r\ndefragment\r\nalloc 90\r\nerase 3\r\nerase 2\r\nerase 3\r\nerase 1\r\nerase 1\r\nalloc 38\r\nalloc 19\r\nerase 1\r\nerase 3\r\ndefragment\r\nalloc 93\r\nerase 5\r\nerase 4\r\nalloc 66\r\nalloc 71\r\nerase 5\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\nerase 7\r\nalloc 47\r\nerase -95616683\r\nerase 2\r\nalloc 28\r\nalloc 32\r\nerase 11\r\nalloc 50\r\ndefragment\r\ndefragment\r\n'], 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n4\r\n5\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': ['16 49\r\nerase -751005193\r\ndefragment\r\nalloc 37\r\nalloc 82\r\nerase 3\r\nerase 1\r\nalloc 80\r\nalloc 51\r\ndefragment\r\nalloc 74\r\nerase 1\r\nalloc 91\r\ndefragment\r\ndefragment\r\nalloc 98\r\ndefragment\r\n'], 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': ['42 98\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 5\r\nalloc 66\r\ndefragment\r\nerase 3\r\nalloc 53\r\ndefragment\r\nerase 4\r\nerase 2\r\nalloc 70\r\nerase 3\r\ndefragment\r\ndefragment\r\nerase 2\r\nerase 3\r\nerase -1327931832\r\nalloc 93\r\nalloc 64\r\nerase 7\r\nerase 6\r\nerase 3\r\nalloc 61\r\nalloc 12\r\nalloc 65\r\nerase 2\r\nalloc 46\r\nerase 11\r\nerase 9\r\nerase 9\r\nerase 6\r\nalloc 2\r\nalloc 78\r\ndefragment\r\nerase 13\r\nerase 6\r\nerase 10\r\nalloc 53\r\nalloc 46\r\n'], 'output': ['1\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n4\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': ['19 46\r\nalloc 21\r\nerase 2\r\nerase 1\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nalloc 40\r\nerase 1\r\ndefragment\r\ndefragment\r\nalloc 68\r\nerase -388966015\r\nalloc 85\r\nalloc 53\r\nerase 4\r\ndefragment\r\nalloc 49\r\nalloc 88\r\n'], 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': ['44 46\r\nalloc 28\r\nalloc 36\r\ndefragment\r\nerase -937404236\r\nalloc 71\r\ndefragment\r\nalloc 81\r\nalloc 51\r\nerase 3\r\ndefragment\r\nalloc 48\r\nerase 1\r\ndefragment\r\nalloc 36\r\ndefragment\r\ndefragment\r\nerase 1\r\ndefragment\r\ndefragment\r\nerase -1173350787\r\nalloc 94\r\nerase 5\r\ndefragment\r\nerase 9\r\nalloc 98\r\nerase 7\r\ndefragment\r\nerase 5\r\nerase 1\r\ndefragment\r\nerase 2\r\ndefragment\r\nerase 4\r\ndefragment\r\nerase 9\r\nalloc 8\r\ndefragment\r\nerase 9\r\ndefragment\r\ndefragment\r\ndefragment\r\nerase 1\r\nalloc 70\r\nerase 9\r\n'], 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['26 25\r\nalloc 25\r\nerase 1\r\nalloc 24\r\nerase 2\r\nalloc 23\r\nerase 3\r\nalloc 24\r\nerase 4\r\nalloc 24\r\nerase 5\r\nalloc 21\r\nerase 6\r\nalloc 24\r\nerase 7\r\nalloc 25\r\nerase 8\r\nalloc 25\r\nerase 9\r\nalloc 24\r\nerase 10\r\nalloc 25\r\nerase 11\r\nalloc 25\r\nerase 12\r\nalloc 25\r\nerase 13\r\n'], 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n']}, {'input': ['22 9\r\nalloc 9\r\nerase 1\r\nalloc 9\r\nerase 2\r\nalloc 9\r\nerase 3\r\nalloc 9\r\nerase 4\r\nalloc 9\r\nerase 5\r\nalloc 9\r\nerase 6\r\nalloc 9\r\nerase 7\r\nalloc 9\r\nerase 8\r\nalloc 9\r\nerase 9\r\nalloc 9\r\nerase 10\r\nalloc 9\r\nerase 11\r\n'], 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n']}, {'input': ['7 6\r\nalloc 1\r\nalloc 2\r\nalloc 3\r\nerase 1\r\ndefragment\r\nerase 3\r\nalloc 4\r\n'], 'output': ['1\r\n2\r\n3\r\n4\r\n']}, {'input': ['3 1\r\nerase -1\r\nerase 0\r\nerase -2147483648\r\n'], 'output': ['ILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['7 100\r\nalloc 100\r\nerase 2147483647\r\nerase 1\r\nalloc 50\r\nalloc 50\r\nerase 3\r\nerase -2147483648\r\n'], 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': ['12 10\r\nalloc 6\r\nalloc 2\r\nerase 1\r\nalloc 4\r\nalloc 2\r\nerase 3\r\nalloc 2\r\nalloc 3\r\nalloc 1\r\nalloc 1\r\nalloc 1\r\nalloc 1\r\n'], 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\nNULL\r\n6\r\n7\r\n8\r\n9\r\n']}, {'input': ['8 50\r\nalloc 51\r\ndefragment\r\nalloc 100\r\ndefragment\r\nerase 1\r\nalloc 50\r\ndefragment\r\nalloc 50\r\n'], 'output': ['NULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\n']}, {'input': ['10 10\r\nalloc 10\r\nerase -1\r\nerase 1\r\nalloc 5\r\nerase -1\r\nalloc 5\r\nerase 0\r\nalloc 5\r\nerase 0\r\nalloc 5\r\n'], 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': ['16 10\r\nalloc 10\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 10\r\nerase 1\r\nerase 2\r\nalloc 6\r\ndefragment\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nerase 3\r\ndefragment\r\nalloc 6\r\n'], 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nNULL\r\n']}, {'input': ['16 10\r\nalloc 10\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 10\r\nerase 1\r\nerase 2\r\nalloc 6\r\ndefragment\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nerase 2\r\ndefragment\r\nalloc 6\r\n'], 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\n4\r\n']}]


In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be?

The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1≤n,m≤20, 0.01≤k≤0.99).
Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive.
Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates.
All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names.

Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order.

5 4 0.75
axe 350
impaler 300
ionize 80
megafire 120
magicboost 220
heal
megafire
shield
magicboost

6
axe 262
heal 0
impaler 225
magicboost 165
megafire 0
shield 0

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadBytes('\n')
	var n, m int
	pos := readInt(line, 0, &n)
	pos = readInt(line, pos+1, &m)
	var k int
	readInt(line, pos+3, &k)
	before := make([]string, n)

	for i := 0; i < n; i++ {
		before[i] = readString(reader)
	}

	after := make([]string, m)

	for i := 0; i < m; i++ {
		after[i] = readString(reader)
	}

	res := solve(k, before, after)

	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d\n", len(res)))

	for i := 0; i < len(res); i++ {
		buf.WriteString(res[i])
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

func readFloat64(bs []byte, pos int, r *float64) int {
	var first float64
	var second float64
	exp := 1.0
	var dot bool
	for pos < len(bs) && (bs[pos] == '.' || isDigit(bs[pos])) {
		if bs[pos] == '.' {
			dot = true
		} else if !dot {
			first = first*10 + float64(bs[pos]-'0')
		} else {
			second = second*10 + float64(bs[pos]-'0')
			exp *= 10
		}
		pos++
	}
	*r = first + second/exp
	//fmt.Fprintf(os.Stderr, "%.6f ", *r)
	return pos
}

func isDigit(b byte) bool {
	return b >= '0' && b <= '9'
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func solve(k int, before []string, after []string) []string {
	skills := make(map[string]int)

	//K := int(k * 100)

	for _, s := range before {
		var i int
		for i < len(s) && s[i] != ' ' {
			i++
		}
		name := s[:i]
		i++
		var score int
		readInt([]byte(s), i, &score)
		score = k * score / 100
		if score >= 100 {
			skills[name] = score
		}
	}

	var res []string

	for _, s := range after {
		sc := skills[s]
		res = append(res, fmt.Sprintf("%s %d", s, sc))
		delete(skills, s)
	}

	for s, v := range skills {
		res = append(res, fmt.Sprintf("%s %d", s, v))
	}

	sort.Strings(res)

	return res
}

[{'input': ['5 4 0.75\r\naxe 350\r\nimpaler 300\r\nionize 80\r\nmegafire 120\r\nmagicboost 220\r\nheal\r\nmegafire\r\nshield\r\nmagicboost\r\n'], 'output': ['6\r\naxe 262\r\nheal 0\r\nimpaler 225\r\nmagicboost 165\r\nmegafire 0\r\nshield 0\r\n']}, {'input': ['1 1 0.50\r\nstaff 1005\r\nionize\r\n'], 'output': ['2\r\nionize 0\r\nstaff 502\r\n']}, {'input': ['4 3 0.32\r\ninrf 48\r\nfdgdf 200\r\nvbkdfk 450\r\nfdbvfdd 1000\r\ndff\r\ninrf\r\nnfdkd\r\n'], 'output': ['5\r\ndff 0\r\nfdbvfdd 320\r\ninrf 0\r\nnfdkd 0\r\nvbkdfk 144\r\n']}, {'input': ['5 1 0.99\r\na 1\r\nb 2\r\nc 3\r\nd 4\r\ne 5\r\nf\r\n'], 'output': ['1\r\nf 0\r\n']}, {'input': ['2 2 0.02\r\nfn 1003\r\nzz 7000\r\nkk\r\nau\r\n'], 'output': ['3\r\nau 0\r\nkk 0\r\nzz 140\r\n']}, {'input': ['3 3 0.10\r\naa 900\r\nbb 990\r\ncc 999\r\naa\r\nbb\r\ncc\r\n'], 'output': ['3\r\naa 0\r\nbb 0\r\ncc 0\r\n']}, {'input': ['1 1 0.99\r\nfdvedvrgfckdkvfpmkjd 100\r\nfdvedvrgfckdkvfpmkjd\r\n'], 'output': ['1\r\nfdvedvrgfckdkvfpmkjd 0\r\n']}, {'input': ['1 1 0.01\r\na 9999\r\na\r\n'], 'output': ['1\r\na 0\r\n']}, {'input': ['1 1 0.80\r\nxyz 125\r\nxyz\r\n'], 'output': ['1\r\nxyz 100\r\n']}, {'input': ['5 1 0.67\r\ndjdn 6699\r\nolkj 6700\r\nhgvg 6698\r\noijggt 6701\r\nyfyv 6700\r\nyfyv\r\n'], 'output': ['5\r\ndjdn 4488\r\nhgvg 4487\r\noijggt 4489\r\nolkj 4489\r\nyfyv 4489\r\n']}, {'input': ['5 2 0.73\r\njcyuc 136\r\npooj 137\r\nojnbg 138\r\ninng 135\r\nuuv 139\r\nhg\r\nouohoiivuvu\r\n'], 'output': ['5\r\nhg 0\r\nojnbg 100\r\nouohoiivuvu 0\r\npooj 100\r\nuuv 101\r\n']}, {'input': ['4 1 0.99\r\nutctc 101\r\nijh 100\r\nfyyui 99\r\ntctxxx 102\r\nojohiobib\r\n'], 'output': ['2\r\nojohiobib 0\r\ntctxxx 100\r\n']}, {'input': ['4 4 0.80\r\nyfcyccyyccccc 123\r\nkkkkk 124\r\noops 125\r\nabfgg 126\r\nh\r\njkl\r\nqwerty\r\noops\r\n'], 'output': ['5\r\nabfgg 100\r\nh 0\r\njkl 0\r\noops 100\r\nqwerty 0\r\n']}, {'input': ['4 6 0.68\r\na 146\r\nb 147\r\nc 148\r\nd 149\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\n'], 'output': ['8\r\nc 100\r\nd 101\r\ne 0\r\nf 0\r\ng 0\r\nh 0\r\ni 0\r\nj 0\r\n']}, {'input': ['5 1 0.02\r\nirn 4999\r\nsdfc 5000\r\nzzzzzz 5001\r\ndcw 100\r\nfvvv 22\r\ndcw\r\n'], 'output': ['3\r\ndcw 0\r\nsdfc 100\r\nzzzzzz 100\r\n']}, {'input': ['5 5 0.18\r\nxwjxvrgz 9492\r\ndhpe 5259\r\nbnbkznfgyuluho 5070\r\nygpluaefwefxmhuaqi 2975\r\nvqstuwkaqk 8892\r\ndhpe\r\nbnbkznfgyuluho\r\nygpluaefwefxmhuaqi\r\nvyaefiicj\r\nxwjxvrgz\r\n'], 'output': ['6\r\nbnbkznfgyuluho 912\r\ndhpe 946\r\nvqstuwkaqk 1600\r\nvyaefiicj 0\r\nxwjxvrgz 1708\r\nygpluaefwefxmhuaqi 535\r\n']}, {'input': ['10 10 0.28\r\nszyiekxcixeyqyfm 7701\r\ncdxkfpggugy 5344\r\ngqyvyzwkajhc 3674\r\ntmo 8865\r\ntbp 8932\r\nwbrzxccfmdxbzw 4566\r\nvpgcejyragzhm 1554\r\ncqqjrh 7868\r\nw 1548\r\nxkbitfl 588\r\nlpcwvverv\r\nborcfgittei\r\nw\r\nzqtzpicsndbxfcbaduds\r\ncdxkfpggugy\r\ntmo\r\nmvmdaltjmy\r\nbzhykrayudljyj\r\nyktrcowlgwkvqucbqh\r\nvtm\r\n'], 'output': ['17\r\nborcfgittei 0\r\nbzhykrayudljyj 0\r\ncdxkfpggugy 1496\r\ncqqjrh 2203\r\ngqyvyzwkajhc 1028\r\nlpcwvverv 0\r\nmvmdaltjmy 0\r\nszyiekxcixeyqyfm 2156\r\ntbp 2500\r\ntmo 2482\r\nvpgcejyragzhm 435\r\nvtm 0\r\nw 433\r\nwbrzxccfmdxbzw 1278\r\nxkbitfl 164\r\nyktrcowlgwkvqucbqh 0\r\nzqtzpicsndbxfcbaduds 0\r\n']}, {'input': ['13 13 0.20\r\nbbdtfrykzf 6189\r\nnqwei 7327\r\ndtigwnbwevnnlinhk 3662\r\nxokqjtylly 1274\r\nsdpnhipam 5672\r\npfjmflvtuvctwxr 9580\r\nybqgomvwoguzcqvzkx 2062\r\nvowzavh 6345\r\nbfidjslqlesdtyjkreou 6780\r\nsvpzwtwn 1945\r\ninvzueipnifajadhjk 7034\r\nsz 6494\r\nce 1323\r\nybqgomvwoguzcqvzkx\r\nbbdtfrykzf\r\nvunbpghae\r\ndtigwnbwevnnlinhk\r\nuqdlfskhgo\r\nvdemdnxifb\r\nvowzavh\r\npfjmflvtuvctwxr\r\nbfidjslqlesdtyjkreou\r\nnqwei\r\nsz\r\njiemqkytxtqnxgjvhzjl\r\nce\r\n'], 'output': ['17\r\nbbdtfrykzf 1237\r\nbfidjslqlesdtyjkreou 1356\r\nce 264\r\ndtigwnbwevnnlinhk 732\r\ninvzueipnifajadhjk 1406\r\njiemqkytxtqnxgjvhzjl 0\r\nnqwei 1465\r\npfjmflvtuvctwxr 1916\r\nsdpnhipam 1134\r\nsvpzwtwn 389\r\nsz 1298\r\nuqdlfskhgo 0\r\nvdemdnxifb 0\r\nvowzavh 1269\r\nvunbpghae 0\r\nxokqjtylly 254\r\nybqgomvwoguzcqvzkx 412\r\n']}, {'input': ['1 17 0.97\r\nsfidbvqbvx 562\r\npmuvtjkw\r\nysxuhhfgwgifkf\r\nnsgdgacfdstvsf\r\ngggnzgevrtykq\r\nvmeytgyobqpmq\r\nrbzif\r\nfqbr\r\nepcy\r\ntvtgk\r\nsdwsny\r\nhuzsrlvxvufyb\r\niallwqylqga\r\nsemxysiafu\r\nodrxgpjgiiizlubtuv\r\nlenenatgyqep\r\nlzakhvoxfccct\r\nijkhhuppdghdwz\r\n'], 'output': ['18\r\nepcy 0\r\nfqbr 0\r\ngggnzgevrtykq 0\r\nhuzsrlvxvufyb 0\r\niallwqylqga 0\r\nijkhhuppdghdwz 0\r\nlenenatgyqep 0\r\nlzakhvoxfccct 0\r\nnsgdgacfdstvsf 0\r\nodrxgpjgiiizlubtuv 0\r\npmuvtjkw 0\r\nrbzif 0\r\nsdwsny 0\r\nsemxysiafu 0\r\nsfidbvqbvx 545\r\ntvtgk 0\r\nvmeytgyobqpmq 0\r\nysxuhhfgwgifkf 0\r\n']}, {'input': ['5 19 0.38\r\nmwfhslniu 2324\r\njyzifusxbigcagch 6167\r\nkccudxutkgb 9673\r\nuccmkylmiqcn 4773\r\niuawwcyefaimhro 214\r\njyzifusxbigcagch\r\nfalsionuewiyvseurg\r\nrkrvudkrhophdflqln\r\nahsybnxitvpm\r\nx\r\nancpcxgr\r\nsvs\r\nvvssivqobhdfqggahqu\r\npf\r\nwjtrtcvjqydxuwwvsqpc\r\nyllpzfjdojpymwy\r\nepjhkxffsymowea\r\nyztamblsfzk\r\nbej\r\nwy\r\nvnkvonk\r\nymsnsngzcvxeilbitknn\r\nlmaajt\r\nmwfhslniu\r\n'], 'output': ['21\r\nahsybnxitvpm 0\r\nancpcxgr 0\r\nbej 0\r\nepjhkxffsymowea 0\r\nfalsionuewiyvseurg 0\r\njyzifusxbigcagch 2343\r\nkccudxutkgb 3675\r\nlmaajt 0\r\nmwfhslniu 883\r\npf 0\r\nrkrvudkrhophdflqln 0\r\nsvs 0\r\nuccmkylmiqcn 1813\r\nvnkvonk 0\r\nvvssivqobhdfqggahqu 0\r\nwjtrtcvjqydxuwwvsqpc 0\r\nwy 0\r\nx 0\r\nyllpzfjdojpymwy 0\r\nymsnsngzcvxeilbitknn 0\r\nyztamblsfzk 0\r\n']}, {'input': ['13 10 0.35\r\napjqdcdylyads 948\r\ni 618\r\nsbifpsvflzngfziwx 6815\r\nlhuzbitj 8455\r\nzhoro 657\r\nfm 6899\r\nbhigr 6743\r\net 3322\r\nljbkmxj 3023\r\nloxxykp 6048\r\naiibfjdgd 965\r\nmmpylhw 5483\r\nyrbikjks 7426\r\nfm\r\njvj\r\napjqdcdylyads\r\nbhigr\r\naiibfjdgd\r\nljbkmxj\r\nauftuqyphmz\r\nloxxykp\r\nzhoro\r\ndmqdfmfjq\r\n'], 'output': ['16\r\naiibfjdgd 337\r\napjqdcdylyads 331\r\nauftuqyphmz 0\r\nbhigr 2360\r\ndmqdfmfjq 0\r\net 1162\r\nfm 2414\r\ni 216\r\njvj 0\r\nlhuzbitj 2959\r\nljbkmxj 1058\r\nloxxykp 2116\r\nmmpylhw 1919\r\nsbifpsvflzngfziwx 2385\r\nyrbikjks 2599\r\nzhoro 229\r\n']}, {'input': ['17 6 0.44\r\nhefojxlinlzhynuleh 9008\r\nufy 7485\r\ngmgjrihvgxsbcu 7575\r\nrnlz 3789\r\nnkvcpt 5813\r\nm 9066\r\nsjxpwpxrkbpydkjcojvq 8679\r\nftvk 9385\r\nyygdlclq 759\r\nvkltswaflkg 5183\r\notosgwfe 639\r\nmaayvyqtvxkudpbcfj 7425\r\nhys 935\r\ngwucwol 6087\r\nbrkmjhnmmrkjzhar 1247\r\ntea 205\r\nhyxhj 6600\r\nmaayvyqtvxkudpbcfj\r\nm\r\nrnlz\r\nbrkmjhnmmrkjzhar\r\nhys\r\ngwucwol\r\n'], 'output': ['16\r\nbrkmjhnmmrkjzhar 548\r\nftvk 4129\r\ngmgjrihvgxsbcu 3333\r\ngwucwol 2678\r\nhefojxlinlzhynuleh 3963\r\nhys 411\r\nhyxhj 2904\r\nm 3989\r\nmaayvyqtvxkudpbcfj 3267\r\nnkvcpt 2557\r\notosgwfe 281\r\nrnlz 1667\r\nsjxpwpxrkbpydkjcojvq 3818\r\nufy 3293\r\nvkltswaflkg 2280\r\nyygdlclq 333\r\n']}, {'input': ['19 3 0.40\r\npwmgdtn 817\r\nikzw 8809\r\nyjltrwizoumwvvtivqmm 2126\r\ntvdguvmepsvvp 9945\r\ndvhoxdvqyqmyl 5998\r\nalpxryere 7048\r\nchnprj 3029\r\ntnsrxilkay 1076\r\nquamvicl 7260\r\nzdzahaxmxnbkuqavmb 174\r\nywgyrbmmhwbrcx 3637\r\noicdsxki 7516\r\nzftrgvmtbuhqsmv 6831\r\njlfjgvzgmkmzbsjhwhy 8042\r\nzuy 2049\r\nhsahihp 1975\r\nkcfsycnilwqyqvsf 6896\r\ntdlgs 4302\r\nim 4476\r\nkcfsycnilwqyqvsf\r\nim\r\ndvhoxdvqyqmyl\r\n'], 'output': ['18\r\nalpxryere 2819\r\nchnprj 1211\r\ndvhoxdvqyqmyl 2399\r\nhsahihp 790\r\nikzw 3523\r\nim 1790\r\njlfjgvzgmkmzbsjhwhy 3216\r\nkcfsycnilwqyqvsf 2758\r\noicdsxki 3006\r\npwmgdtn 326\r\nquamvicl 2904\r\ntdlgs 1720\r\ntnsrxilkay 430\r\ntvdguvmepsvvp 3978\r\nyjltrwizoumwvvtivqmm 850\r\nywgyrbmmhwbrcx 1454\r\nzftrgvmtbuhqsmv 2732\r\nzuy 819\r\n']}, {'input': ['20 1 0.78\r\nxc 6799\r\nztrfjsq 3023\r\nkhbcbsaztwigxeidh 2974\r\nkksvbmtjiiqlguwv 188\r\nwvqzzjrpmxsdbfvua 4547\r\niqkqqwtqifdpxfhslpv 6264\r\nwarmknju 9472\r\nfheisuiufwmtagl 292\r\nwge 4338\r\nzaklermeji 6733\r\nfcn 6282\r\nbjyjzgzkgzy 1778\r\ngufpvhdnsesyfuegef 4998\r\nxnhuhwzzxqbaphktqbc 8485\r\ncokabaqahfw 8645\r\nbtgeopbwekffdadgj 1791\r\nsgvrgyhidnhecvt 7264\r\ncczstyyxhbpwj 3244\r\nguaykdl 3786\r\nmabamfnewwrykizn 4705\r\nbjyjzgzkgzy\r\n'], 'output': ['20\r\nbjyjzgzkgzy 1386\r\nbtgeopbwekffdadgj 1396\r\ncczstyyxhbpwj 2530\r\ncokabaqahfw 6743\r\nfcn 4899\r\nfheisuiufwmtagl 227\r\nguaykdl 2953\r\ngufpvhdnsesyfuegef 3898\r\niqkqqwtqifdpxfhslpv 4885\r\nkhbcbsaztwigxeidh 2319\r\nkksvbmtjiiqlguwv 146\r\nmabamfnewwrykizn 3669\r\nsgvrgyhidnhecvt 5665\r\nwarmknju 7388\r\nwge 3383\r\nwvqzzjrpmxsdbfvua 3546\r\nxc 5303\r\nxnhuhwzzxqbaphktqbc 6618\r\nzaklermeji 5251\r\nztrfjsq 2357\r\n']}, {'input': ['1 1 0.94\r\na 8700\r\nb\r\n'], 'output': ['2\r\na 8178\r\nb 0\r\n']}, {'input': ['1 1 0.70\r\na 1000\r\na\r\n'], 'output': ['1\r\na 700\r\n']}, {'input': ['2 1 0.50\r\naxe 200\r\nmegafire 120\r\nmegafire\r\n'], 'output': ['2\r\naxe 100\r\nmegafire 0\r\n']}, {'input': ['5 4 0.99\r\naxe 350\r\nimpaler 300\r\nionize 102\r\nmegafire 120\r\nmagicboost 220\r\nheal\r\nmegafire\r\nshield\r\nmagicboost\r\n'], 'output': ['7\r\naxe 346\r\nheal 0\r\nimpaler 297\r\nionize 100\r\nmagicboost 217\r\nmegafire 118\r\nshield 0\r\n']}, {'input': ['1 1 0.94\r\na 8700\r\nb\r\n'], 'output': ['2\r\na 8178\r\nb 0\r\n']}, {'input': ['1 1 0.50\r\nlho 200\r\nhai\r\n'], 'output': ['2\r\nhai 0\r\nlho 100\r\n']}, {'input': ['20 3 0.29\r\na 100\r\nb 200\r\nc 300\r\nd 400\r\ne 500\r\nf 600\r\ng 700\r\nh 800\r\ni 900\r\nj 1000\r\nk 1100\r\nl 1200\r\nm 1300\r\nn 1400\r\no 1500\r\np 1600\r\nq 1700\r\nr 1800\r\ns 1900\r\nt 2000\r\nz\r\nm\r\nk\r\n'], 'output': ['18\r\nd 116\r\ne 145\r\nf 174\r\ng 203\r\nh 232\r\ni 261\r\nj 290\r\nk 319\r\nl 348\r\nm 377\r\nn 406\r\no 435\r\np 464\r\nq 493\r\nr 522\r\ns 551\r\nt 580\r\nz 0\r\n']}, {'input': ['2 2 0.50\r\nabcd 200\r\naaa 201\r\nfff\r\nffff\r\n'], 'output': ['4\r\naaa 100\r\nabcd 100\r\nfff 0\r\nffff 0\r\n']}, {'input': ['1 1 0.94\r\na 8700\r\nb\r\n'], 'output': ['2\r\na 8178\r\nb 0\r\n']}, {'input': ['1 1 0.29\r\nhren 400\r\nblin\r\n'], 'output': ['2\r\nblin 0\r\nhren 116\r\n']}, {'input': ['5 4 0.30\r\naxe 350\r\nimpaler 9000\r\nionize 80\r\nmegafire 120\r\nmagicboost 220\r\nheal\r\nmegafire\r\nshield\r\nmagicboost\r\n'], 'output': ['6\r\naxe 105\r\nheal 0\r\nimpaler 2700\r\nmagicboost 0\r\nmegafire 0\r\nshield 0\r\n']}, {'input': ['1 1 0.03\r\naxe 9900\r\nheal\r\n'], 'output': ['2\r\naxe 297\r\nheal 0\r\n']}]


Alice got a new doll these days. It can even walk!Alice has built a maze for the doll and wants to test it. The maze is a grid with $$$n$$$ rows and $$$m$$$ columns. There are $$$k$$$ obstacles, the $$$i$$$-th of them is on the cell $$$(x_i, y_i)$$$, which means the cell in the intersection of the $$$x_i$$$-th row and the $$$y_i$$$-th column.However, the doll is clumsy in some ways. It can only walk straight or turn right at most once in the same cell (including the start cell). It cannot get into a cell with an obstacle or get out of the maze.More formally, there exist $$$4$$$ directions, in which the doll can look:  The doll looks in the direction along the row from the first cell to the last. While moving looking in this direction the doll will move from the cell $$$(x, y)$$$ into the cell $$$(x, y + 1)$$$;  The doll looks in the direction along the column from the first cell to the last. While moving looking in this direction the doll will move from the cell $$$(x, y)$$$ into the cell $$$(x + 1, y)$$$;  The doll looks in the direction along the row from the last cell to first. While moving looking in this direction the doll will move from the cell $$$(x, y)$$$ into the cell $$$(x, y - 1)$$$;  The doll looks in the direction along the column from the last cell to the first. While moving looking in this direction the doll will move from the cell $$$(x, y)$$$ into the cell $$$(x - 1, y)$$$. .Standing in some cell the doll can move into the cell in the direction it looks or it can turn right once. Turning right once, the doll switches it's direction by the following rules: $$$1 \to 2$$$, $$$2 \to 3$$$, $$$3 \to 4$$$, $$$4 \to 1$$$. Standing in one cell, the doll can make at most one turn right.Now Alice is controlling the doll's moves. She puts the doll in of the cell $$$(1, 1)$$$ (the upper-left cell of the maze). Initially, the doll looks to the direction $$$1$$$, so along the row from the first cell to the last. She wants to let the doll walk across all the cells without obstacles exactly once and end in any place. Can it be achieved?

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$, separated by spaces ($$$1 \leq n,m \leq 10^5, 0 \leq k \leq 10^5$$$) — the size of the maze and the number of obstacles.
Next $$$k$$$ lines describes the obstacles, the $$$i$$$-th line contains two integer numbers $$$x_i$$$ and $$$y_i$$$, separated by spaces ($$$1 \leq x_i \leq n,1 \leq y_i \leq m$$$), which describes the position of the $$$i$$$-th obstacle.
It is guaranteed that no two obstacles are in the same cell and no obstacle is in cell $$$(1, 1)$$$.

Print 'Yes' (without quotes) if the doll can walk across all the cells without obstacles exactly once by the rules, described in the statement.
If it is impossible to walk across the maze by these rules print 'No' (without quotes).

package main

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

var n, m, k, nn, mm int
var a map[int]map[int]bool = make(map[int]map[int]bool)
var b map[int]map[int]bool = make(map[int]map[int]bool)

func culc1(x, y int) (ok, end bool, xx, yy int) {
	if m < mm {
		return true, true, 0, 0
	}
	if haveA, have := a[x]; have {
		miny := m + 1
		num := 0
		for ay, _ := range haveA {
			if ay >= mm && ay <= m {
				miny = min(ay, miny)
				num++
			}
		}

		if num+miny != m+1 {
			return false, true, 0, 0
		}

		for i := miny; i <= m; i++ {
			numx := 0
			for ax, _ := range b[i] {
				if ax >= nn && ax <= n {
					numx++
				}
			}
			if numx+nn != n+1 {
				return false, true, 0, 0
			}
		}
		return true, false, x, miny - 1
	}

	return true, false, x, m
}

func culc2(x, y int) (ok, end bool, xx, yy int) {
	if n < nn {
		return true, true, 0, 0
	}

	if haveA, have := b[y]; have {
		minx := n + 1
		numx := 0
		for ax, _ := range haveA {
			if ax >= x && ax <= n {
				minx = min(ax, minx)
				numx++
			}
		}

		if numx+minx != n+1 {
			return false, true, 0, 0
		}

		for i := minx; i <= n; i++ {
			numy := 0
			for ay, _ := range a[i] {
				if ay >= mm && ay <= m {
					numy++
				}
			}
			if numy+mm != m+1 {
				return false, true, 0, 0
			}
		}
		return true, false, minx - 1, y
	}

	return true, false, n, m
}

func culc3(x, y int) (ok, end bool, xx, yy int) {
	if m < mm {
		return true, true, 0, 0
	}

	if haveA, have := a[x]; have {
		maxy := mm - 1
		num := 0
		for ay, _ := range haveA {
			if ay >= mm && ay <= m {
				maxy = max(ay, maxy)
				num++
			}
		}

		if maxy+1 != mm+num {
			return false, true, 0, 0
		}

		for i := mm; i <= maxy; i++ {
			numx := 0
			for ax, _ := range b[i] {
				if ax >= nn && ax <= n {
					numx++
				}
			}
			if numx+nn != n+1 {
				return false, true, 0, 0
			}
		}
		return true, false, x, maxy + 1
	}

	return true, false, n, mm
}

func culc4(x, y int) (ok, end bool, xx, yy int) {
	if n < nn {
		return true, true, 0, 0
	}

	if haveA, have := b[y]; have {
		maxx := nn - 1
		num := 0
		for ax, _ := range haveA {
			if ax >= nn && ax <= n {
				maxx = max(ax, maxx)
				num++
			}
		}

		if maxx+1 != nn+num {
			return false, true, 0, 0
		}

		for i := nn; i <= maxx; i++ {
			numy := 0
			for ay, _ := range a[i] {
				if ay >= mm && ay <= m {
					numy++
				}
			}
			if numy+mm != m+1 {
				return false, true, 0, 0
			}
		}
		return true, false, maxx + 1, y
	}

	return true, false, nn, y
}

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 main() {

	reader := bufio.NewReader(os.Stdin)

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

	var x, y int
	for i := 1; i <= k; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x, &y)
		if _, ok := a[x]; !ok {
			a[x] = make(map[int]bool)
		}

		if _, ok := b[y]; !ok {
			b[y] = make(map[int]bool)
		}

		a[x][y] = true
		b[y][x] = true
	}

	x = 1
	y = 1
	nn = 1
	mm = 1
	ok := true
	end := false
	for ok && !end {
		ok, end, x, y = culc1(x, y)
		//fmt.Println("culc1", ok, end, x, y)
		if !ok || end {
			break
		}
		m = y
		nn++

		ok, end, x, y = culc2(x, y)
		//fmt.Println("culc2", ok, end, x, y)
		if !ok || end {
			break
		}

		m--
		n = x

		ok, end, x, y = culc3(x, y)
		//fmt.Println("culc3", ok, end, x, y)
		if !ok || end {
			break
		}

		n--
		mm = y

		ok, end, x, y = culc4(x, y)
		//fmt.Println("culc4", ok, end, x, y)
		if !ok || end {
			break
		}

		mm++
		nn = x
	}

	if ok {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}


Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$.

The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$.
Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side.
The given domino placement is perfectly balanced.

Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; return res }

func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}

func ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
const MOD int64 = 998244353
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	H,W,N := gi(),gi(),gi(); R1,C1,R2,C2 := fill4(N); for i:=0;i<N;i++ { R1[i]--; C1[i]--; R2[i]--; C2[i]-- }
	fact,factinv := makefact64(5000,MOD)
	comb := func(n,r int) int64 { if n < 0 || r < 0 || r > n { return 0 }; return fact[n] * factinv[r] % MOD * factinv[n-r] % MOD }
	sbh := make([]bool,H); sbw := make([]bool,W)
	for _,r := range R1 { sbh[r] = true }; for _,r := range R2 { sbh[r] = true }
	for _,c := range C1 { sbw[c] = true }; for _,c := range C2 { sbw[c] = true }
	rtot := 0; for _,b := range sbh { if !b { rtot++ } }
	ctot := 0; for _,b := range sbw { if !b { ctot++ } }
	doPairDp := func(sb []bool) []int64 {
		n := len(sb)
		ansarr := make([]int64,0,n)
		ansarr = append(ansarr,1)
		if n == 1 { return ansarr }
		dp := iai64(n,1); ndp := iai64(n,0)
		for i:=1;i<n;i++ {
			for j:=0;j<n;j++ { ndp[j] = 0 }
			if i == 1 && !sb[n-2] && !sb[n-1] { ndp[n-2] = 1 }
			for j:=n-3;j>=0;j-- {
				ndp[j] = ndp[j+1]
				if !sb[j] && !sb[j+1] { ndp[j] += dp[j+2]; ndp[j] %= MOD }
			}
			if ndp[0] == 0 { break }
			ansarr = append(ansarr,ndp[0])
			dp,ndp = ndp,dp
		}
		return ansarr
	}
	rdp := doPairDp(sbh)
	cdp := doPairDp(sbw)
	ans := int64(0)
	for i,v1 := range rdp {
		for j,v2 := range cdp {
			rs := rtot-2*i
			cs := ctot-2*j
			if cs < i || rs < j { continue }
			adder := v1 * comb(cs,i) % MOD * v2 % MOD * comb(rs,j) % MOD * fact[i] % MOD * fact[j] % MOD
			ans += adder
		}
	}
	ans %= MOD
	fmt.Println(ans)
}


Demonstrative competitions will be held in the run-up to the $$$20NN$$$ Berlatov Olympic Games. Today is the day for the running competition!Berlatov team consists of $$$2n$$$ runners which are placed on two running tracks; $$$n$$$ runners are placed on each track. The runners are numbered from $$$1$$$ to $$$n$$$ on each track. The runner with number $$$i$$$ runs through the entire track in $$$i$$$ seconds.The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all $$$n$$$ pairs run through the track.The organizers want the run to be as long as possible, but if it lasts for more than $$$k$$$ seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks).You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed $$$k$$$ seconds.Formally, you want to find two permutations $$$p$$$ and $$$q$$$ (both consisting of $$$n$$$ elements) such that $$$sum = \sum\limits_{i=1}^{n} max(p_i, q_i)$$$ is maximum possible, but does not exceed $$$k$$$. If there is no such pair, report about it.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^6, 1 \le k \le n^2$$$) — the number of runners on each track and the maximum possible duration of the competition, respectively.

If it is impossible to reorder the runners so that the duration of the competition does not exceed $$$k$$$ seconds, print $$$-1$$$.
Otherwise, print three lines. The first line should contain one integer $$$sum$$$ — the maximum possible duration of the competition not exceeding $$$k$$$. The second line should contain a permutation of $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ should be pairwise distinct) — the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of $$$n$$$ integers $$$q_1, q_2, \dots, q_n$$$ ($$$1 \le q_i \le n$$$, all $$$q_i$$$ should be pairwise distinct) — the numbers of runners on the second track in the order they participate in the competition. The value of $$$sum = \sum\limits_{i=1}^{n} max(p_i, q_i)$$$ should be maximum possible, but should not exceed $$$k$$$. If there are multiple answers, print any of them.

package main

import (
	"fmt"
	"math"
	"strconv"
)

func len1N(n int) int {
	if n <= 0 {
		return 0
	}
	l := int(math.Log10(float64(n)))
	nn := int(math.Pow10(l) - 1)
	return len1N(nn) + (n-nn)*(l+2)
}

func main() {
	var n, k int64
	fmt.Scanf("%d %d", &n, &k)
	min := n * (n + 1) / 2
	var max int64
	if n%2 == 0 {
		max = (3*n + 2) * n / 4
	} else {
		max = (3*n - 1) * (n + 1) / 4
	}
	if k < min {
		fmt.Println("-1")
		return
	}
	if k > max {
		k = max
	}
	fmt.Println(k)
	res := make([]byte, 0, len1N(int(n)))
	for i := int64(1); i <= n; i++ {
		res = strconv.AppendInt(res, i, 10)
		res = append(res, ' ')
	}
	fmt.Printf("%s\n", res)
	res = res[:0]
	diff := k - min
	mmax := n
	rem := map[int64]int64{}
	for i := int64(1); i <= n; i++ {
		if i >= mmax || mmax-i > diff {
			if nnn, ok := rem[i]; ok {
				res = strconv.AppendInt(res, nnn, 10)
				res = append(res, ' ')
			} else {
				res = strconv.AppendInt(res, i, 10)
				res = append(res, ' ')
			}
		} else {
			res = strconv.AppendInt(res, mmax, 10)
			res = append(res, ' ')
			diff -= mmax - i
			rem[mmax] = i
			mmax--
		}
	}
	fmt.Printf("%s\n", res)
	if diff != 0 {
		panic("Programming error")
	}
}


INSPION FullBand Master - INSPION INSPION - IOLITE-SUNSTONEOn another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight against the gangs of the cyber world.His target is a network of $$$n$$$ small gangs. This network contains exactly $$$n - 1$$$ direct links, each of them connecting two gangs together. The links are placed in such a way that every pair of gangs is connected through a sequence of direct links.By mining data, Xenon figured out that the gangs used a form of cross-encryption to avoid being busted: every link was assigned an integer from $$$0$$$ to $$$n - 2$$$ such that all assigned integers are distinct and every integer was assigned to some link. If an intruder tries to access the encrypted data, they will have to surpass $$$S$$$ password layers, with $$$S$$$ being defined by the following formula:$$$$$$S = \sum_{1 ≤ u < v ≤ n} mex(u, v)$$$$$$Here, $$$mex(u, v)$$$ denotes the smallest non-negative integer that does not appear on any link on the unique simple path from gang $$$u$$$ to gang $$$v$$$.Xenon doesn't know the way the integers are assigned, but it's not a problem. He decides to let his AI's instances try all the passwords on his behalf, but before that, he needs to know the maximum possible value of $$$S$$$, so that the AIs can be deployed efficiently.Now, Xenon is out to write the AI scripts, and he is expected to finish them in two hours. Can you find the maximum possible $$$S$$$ before he returns?

The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 3000$$$), the number of gangs in the network.
Each of the next $$$n - 1$$$ lines contains integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$; $$$u_i \neq v_i$$$), indicating there's a direct link between gangs $$$u_i$$$ and $$$v_i$$$.
It's guaranteed that links are placed in such a way that each pair of gangs will be connected by exactly one simple path.

Print the maximum possible value of $$$S$$$ — the number of password layers in the gangs' network.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1292C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	pa := make([][3000]int16, n)
	sz := make([][3000]int16, n)
	for i := range pa {
		var f func(int16, int16)
		f = func(v, fa int16) {
			pa[i][v] = fa
			sz[i][v] = 1
			for _, w := range g[v] {
				if w := int16(w); w != fa {
					f(w, v)
					sz[i][v] += sz[i][w]
				}
			}
		}
		f(int16(i), -1)
	}

	dp := make([][3000]int64, n)
	var f func(int16, int16) int64
	f = func(v, w int16) int64 {
		if v == w {
			return 0
		}
		if dp[v][w] == 0 {
			dp[v][w] = max(f(pa[w][v], w), f(v, pa[v][w])) + int64(int(sz[v][w])*int(sz[w][v]))
		}
		return dp[v][w]
	}
	ans := int64(0)
	for v := int16(0); v < int16(n); v++ {
		for w := v + 1; w < int16(n); w++ {
			ans = max(ans, f(v, w))
		}
	}
	Fprint(out, ans)
}

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

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


You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot could go to some another cell. The aim is to go to the bottommost (N-th) row. The robot can stay at it's current cell, move to the left, move to the right, or move to the cell below the current. If the robot is in the leftmost column it cannot move to the left, and if it is in the rightmost column it cannot move to the right. At every step all possible moves are equally probable. Return the expected number of step to reach the bottommost row.

On the first line you will be given two space separated integers N and M (1≤N,M≤1000). On the second line you will be given another two space separated integers i and j (1≤i≤N,1≤j≤M) — the number of the initial row and the number of the initial column. Note that, (1,1) is the upper left corner of the board and (N,M) is the bottom right corner.

Output the expected number of steps on a line of itself with at least 4 digits after the decimal point.

package main

import (
	"fmt"
)

func main() {
	var N, M, i, j int
	fmt.Scanf("%d %d", &N, &M)
	fmt.Scanf("%d %d", &i, &j)

	// Calculate the expected number of steps
	n := float64(N)
	m := float64(M)
	x := float64(i)
	y := float64(j)
	e := (n - x) * (m - y) / (x * y)

	fmt.Printf("%.10f\n", e)
}


The only difference between easy and hard versions is the number of elements in the array.You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := \lfloor\frac{a_i}{2}\rfloor$$$).You can perform such an operation any (possibly, zero) number of times with any $$$a_i$$$.Your task is to calculate the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.Don't forget that it is possible to have $$$a_i = 0$$$ after some operations, thus the answer always exists.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.

package main

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

/* solution */

type nodeType struct {
	next [2]*nodeType
	cuts [20]int
	cnt  int
}

func solve() {

	n, k := readInt(), readInt()
	root := &nodeType{}

	for i := 0; i < n; i++ {
		v := readInt()
		digits := make([]int, 0)
		for v > 0 {
			digits = append(digits, v%2)
			v = v / 2
		}
		addToTree(root, digits, len(digits))
	}

	printInt(search(root, k))

}

func search(node *nodeType, k int) int {
	if node == nil || node.cnt < k {
		return 1000000000
	}
	s0 := 0
	rem := k - node.cuts[0]
	for i := 1; rem > 0 && i < 20; i++ {
		if rem > node.cuts[i] {
			s0 += node.cuts[i] * i
			rem -= node.cuts[i]
		} else {
			s0 += rem * i
			rem = 0
		}
	}
	s1, s2 := search(node.next[0], k), search(node.next[1], k)
	return min(s0, min(s1, s2))
}

func addToTree(node *nodeType, digits []int, idx int) {
	node.cnt++
	node.cuts[idx]++
	idx--
	if idx < 0 {
		return
	}
	next := node.next[digits[idx]]
	if next == nil {
		node.next[digits[idx]] = &nodeType{}
		next = node.next[digits[idx]]
	}
	addToTree(next, digits, idx)
}

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

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}


The only difference between easy and hard versions is the length of the string.You are given a string $$$s$$$ and a string $$$t$$$, both consisting only of lowercase Latin letters. It is guaranteed that $$$t$$$ can be obtained from $$$s$$$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $$$s$$$ without changing order of remaining characters (in other words, it is guaranteed that $$$t$$$ is a subsequence of $$$s$$$).For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".You want to remove some substring (contiguous subsequence) from $$$s$$$ of maximum possible length such that after removing this substring $$$t$$$ will remain a subsequence of $$$s$$$.If you want to remove the substring $$$s[l;r]$$$ then the string $$$s$$$ will be transformed to $$$s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$$$ (where $$$|s|$$$ is the length of $$$s$$$).Your task is to find the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.

The first line of the input contains one string $$$s$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. The second line of the input contains one string $$$t$$$ consisting of at least $$$1$$$ and at most $$$200$$$ lowercase Latin letters. It is guaranteed that $$$t$$$ is a subsequence of $$$s$$$.

Print one integer — the maximum possible length of the substring you can remove so that $$$t$$$ is still a subsequence of $$$s$$$.

package main

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

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

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

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

func main() {
	defer writer.Flush()

	var s, t string
	scanf("%s\n%s\n", &s, &t)
	slen, tlen := len(s), len(t)

	// собираем подпоследовательность t в s (индексы) слева
	pos := 0
	l := make([]int, tlen)
	for i := 0; i < tlen; i++ {
		for ; t[i] != s[pos]; pos++ {
		}
		l[i] = pos
		pos++
	}
	//fmt.Println(l)

	// собираем подпоследовательность t в s (индексы) справа
	pos = slen - 1
	r := make([]int, tlen)
	for i := tlen - 1; i >= 0; i-- {
		for ; t[i] != s[pos]; pos-- {
		}
		r[i] = pos
		pos--
	}
	//fmt.Println(r)

	// берем максимум между хвостами: справа от l и слева от r
	ans := max(slen-1-l[tlen-1], r[0])
	// сравнимаем с максимумом разницу между l[i] и r[i+1]
	for i := 0; i < tlen-1; i++ {
		ans = max(ans, r[i+1]-l[i]-1)
	}

	fmt.Println(ans)
}


You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109 + 7.

The first line contains single integer n (1 ≤ n ≤ 105) — the number of points. n lines follow. The (i + 1)-th of these lines contains two integers xi, yi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the i-th point. It is guaranteed that all points are distinct.

Print the number of possible distinct pictures modulo 109 + 7.

NoteIn the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it). The first way:      The second way:      In the second example you can work with two points independently. The number of pictures is 32 = 9.

package main

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

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

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

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

type pair struct {
	first int
	second int
}

type pairs []pair

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

var points [2][]pair
var pts [100005]pair
var g [100005][]int
var used [100005]bool
var diff_x,diff_y []int
var cycle_found bool
var MD int64 = 1000000007
var used_x,used_y map[int]bool
var n,x,y int

func deg(d int) int64 {
	if d == 0 {
		return 1
	}
	t := deg(d / 2)
	t *= t
	t %= MD
	if d % 2 == 1 {
		t = t * 2 % MD
	}
	return t
}

func dfs(v,p int) {
	used[v] = true
	if !used_x[pts[v].first] {
		used_x[pts[v].first] = true
		diff_x = append(diff_x, pts[v].first)
	}
	if !used_y[pts[v].second] {
		used_y[pts[v].second] = true
		diff_y = append(diff_y, pts[v].second)
	}
	for i:= range g[v] {
		to := g[v][i]
		if to == p {
			continue
		}
		if used[to] {
			cycle_found = true
			continue
		}
		dfs(to,v)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	mp := make(map[pair]int)
	used_x = make(map[int]bool)
	used_y = make(map[int]bool)
	for i:=1;i<=n;i++ {
		fmt.Fscanf(in, "%d %d\n",&x,&y)
		mp[pair{x,y}] = i
		pts[i] = pair{x,y}
		points[0] = append(points[0], pair{x,y})
		points[1] = append(points[1], pair{y,x})
	}
	sort.Sort(pairs(points[0]))
	sort.Sort(pairs(points[1]))
	for i:= range points[0] {
		if i > 0 {
			if points[0][i].first == points[0][i - 1].first {
				x := mp[points[0][i]]
				y := mp[points[0][i - 1]]
				g[x] = append(g[x], y)
				g[y] = append(g[y], x)
				//fmt.Println(">>",x,y)
			}
		}
	}

	for i:= range points[1] {
		if i > 0 {
			if points[1][i].first == points[1][i - 1].first {
				x := mp[pair{points[1][i].second, points[1][i].first}]
				y := mp[pair{points[1][i - 1].second, points[1][i - 1].first}]
				g[x] = append(g[x], y)
				g[y] = append(g[y], x)
				//fmt.Println(">>",x,y)
			}
		}
	}

	var ans int64
	ans = 1

	for i:= 1;i<= n;i++ {
		if !used[i] {
			cycle_found = false
			for j:= range diff_x {
				used_x[diff_x[j]] = false
			}
			for j:= range diff_y {
				used_y[diff_y[j]] = false
			}
			diff_x = nil
			diff_y = nil
			dfs(i,i)
			//fmt.Println(len(diff_x),len(diff_y))
			res := deg(len(diff_x) + len(diff_y))
			if !cycle_found {
				res--
			}
			if res < 0 {
				res += MD
			}
			ans = ans * res % MD
		}
	}
	fmt.Println(ans)
}


International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.You are given a list of abbreviations. For each of them determine the year it stands for.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.  Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

For each abbreviation given in the input, find the year of the corresponding Olympiad.

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
}

func main() {

    ncase := 0
    fmt.Fscanf(stdin, "%d\n", &ncase)
    for i := 0; i < ncase; i++ {
        str := ""
        fmt.Fscanf(stdin, "IAO'%s\n", &str)

        if len(str) == 1 {
            if str == "9" {
                fmt.Fprintf(stdout, "1989\n")
            } else if len(str) == 1  {
                fmt.Fprintf(stdout, "199%s\n", str)
            }
        } else if len(str) == 2 {
            if str == "99" {
                fmt.Fprintf(stdout, "1999\n")
            } else {
                fmt.Fprintf(stdout, "20%s\n", str)
            }
        } else if len(str) == 3 {
            year, _ := strconv.Atoi(str)
            if 99 <= year {
                fmt.Fprintf(stdout, "2%s\n", str)
            } else {
                fmt.Fprintf(stdout, "3%s\n", str)
            }
        } else if len(str) == 4 {
            year, _ := strconv.Atoi(str)
            if 3099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 5 {
            year, _ := strconv.Atoi(str)
            if 13099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 6 {
            year, _ := strconv.Atoi(str)
            if 113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 7 {
            year, _ := strconv.Atoi(str)
            if 1113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 8 {
            year, _ := strconv.Atoi(str)
            if 11113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 9 {
            year, _ := strconv.Atoi(str)
            if 111113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        }

    }

    stdout.Flush()
}


One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:   G has exactly n vertices, numbered from 1 to n.  For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not. Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.

The first line of the input contains two integers n and m  — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.

In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.

NoteIn the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.

package main

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

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

var n, m int
var vType []Type
var edges [][]int

func main() {
	defer out.Flush()
	fmt.Fscan(in, &n, &m)
	vType = make([]Type, n)
	edges = make([][]int, n)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(in, &a, &b)
		a--
		b--
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	if solve() {
		fmt.Fprintln(out, "Yes")
		for v := range vType {
			fmt.Fprint(out, string('a'+vType[v]-1))
		}
		fmt.Fprintln(out)
	} else {
		fmt.Fprintln(out, "No")
	}
}

func solve() bool {
	for v := range edges {
		if len(edges[v]) == n-1 {
			vType[v] = B
		}
	}
	for v := range vType {
		if vType[v] == UNSEEN {
			mark(v, A)
			break
		}
	}
	for v := range vType {
		if vType[v] == UNSEEN {
			mark(v, C)
			break
		}
	}
	var a, b, c int
	for v := range vType {
		switch vType[v] {
		case UNSEEN:
			return false
		case A:
			a++
		case B:
			b++
		case C:
			c++
		}
	}
	for v := range vType {
		if vType[v] == A && len(edges[v]) != a-1+b {
			return false
		}
		if vType[v] == C && len(edges[v]) != c-1+b {
			return false
		}
	}
	return true
}

func mark(v int, t Type) {
	if vType[v] != UNSEEN {
		return
	}
	vType[v] = t
	for _, u := range edges[v] {
		mark(u, t)
	}
}

type Type int

const (
	UNSEEN Type = iota
	A
	B
	C
)


A divisor tree is a rooted tree that meets the following conditions:   Each vertex of the tree contains a positive integer number.  The numbers written in the leaves of the tree are prime numbers.  For any inner vertex, the number within it is equal to the product of the numbers written in its children. Manao has n distinct integers a1, a2, ..., an. He tries to build a divisor tree which contains each of these numbers. That is, for each ai, there should be at least one vertex in the tree which contains ai. Manao loves compact style, but his trees are too large. Help Manao determine the minimum possible number of vertices in the divisor tree sought.

The first line contains a single integer n (1 ≤ n ≤ 8). The second line contains n distinct space-separated integers ai (2 ≤ ai ≤ 1012).

Print a single integer — the minimum number of vertices in the divisor tree that contains each of the numbers ai.

NoteSample 1. The smallest divisor tree looks this way: Sample 2. In this case you can build the following divisor tree: Sample 3. Note that the tree can consist of a single vertex.

package main

import "fmt"

var (
	n           int
	num         []int64
	par         []int
	rem         []int64
	minCount    int = 1e9
	delimsCache     = make(map[int64]int)
)

func countPrimeDelims(n int64) (count int) {
	if val, ok := delimsCache[n]; ok {
		count = val
		return
	}
	n0 := n
	for ; n%2 == 0; n /= 2 {
		count++
	}
	for p := int64(3); p*p <= n; p += 2 {
		for ; n%p == 0; n /= p {
			count++
		}
	}
	if n > 1 {
		count++
	}
	delimsCache[n0] = count
	return
}

func eval() {
	count := 0
	withPar0 := 0
	for p := 1; p <= n; p++ {
		delimCount := countPrimeDelims(rem[p])
		if delimCount == 1 && num[p] == rem[p] { // rem[p] is prime and p does not have kids
			count += 1
		} else {
			count += delimCount + 1
		}
		if par[p] == 0 {
			withPar0++
		}
	}
	if withPar0 > 1 {
		count++
	}
	if count < minCount {
		minCount = count
	}
}

func brute(i int) {
	if i == n+1 {
		eval()
		return
	}
	par[i] = 0
	brute(i + 1)

	for p := 1; p <= n; p++ {
		if p != i && num[i] <= rem[p] && rem[p]%num[i] == 0 {
			par[i] = p
			rem[p] /= num[i]
			brute(i + 1)
			rem[p] *= num[i]
		}
	}
}

func main() {
	fmt.Scan(&n)
	num = make([]int64, n+1)
	par = make([]int, n+1)
	rem = make([]int64, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scan(&num[i])
		rem[i] = num[i]
	}
	brute(1)
	fmt.Println(minCount)
}


Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points. After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.

The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.

In a single line print a single integer — the maximum number of points Artem can get.

package main

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

const N = 500000

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

var v, stk [N]int

func main() {
  r := bufio.NewReader(os.Stdin)
  var n, top int = 0, 0
  var res int64 = 0
  fmt.Fscan(r, &n)
  for i := 0; i < n; i++ {
    fmt.Fscan(r, &v[i])
    for top >= 2 && stk[top-2] >= stk[top-1] && stk[top-1] <= v[i] {
      res += int64(IntMin(v[i], stk[top-2]))
      top--
    }
    stk[top] = v[i]
    top++
  }
  sort.Sort(sort.IntSlice(stk[:top]))
  for i := 0; i < top-2; i++ {
    res += int64(stk[i])
  }
  fmt.Println(res)
}


Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur once in each of them).Polycarpus wants to save these pictures on his laptop, but the problem is, laptops do not allow to write hieroglyphs circles. So Polycarp had to break each circle and write down all of its hieroglyphs in a clockwise order in one line. A line obtained from the first circle will be called a, and the line obtained from the second one will be called b.There are quite many ways to break hieroglyphic circles, so Polycarpus chooses the method, that makes the length of the largest substring of string a, which occurs as a subsequence in string b, maximum.Help Polycarpus — find the maximum possible length of the desired substring (subsequence) if the first and the second circles are broken optimally.The length of string s is the number of characters in it. If we denote the length of string s as |s|, we can write the string as s = s1s2... s|s|.A substring of s is a non-empty string x = s[a... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|). For example, "code" and "force" are substrings of "codeforces", while "coders" is not. A subsequence of s is a non-empty string y = s[p1p2... p|y|] = sp1sp2... sp|y| (1 ≤ p1 <; p2 <; ... <; p|y| ≤ |s|). For example, "coders" is a subsequence of "codeforces".

The first line contains two integers la and lb (1 ≤ la, lb ≤ 1000000) — the number of hieroglyphs in the first and second circles, respectively. Below, due to difficulties with encoding of Berland hieroglyphs, they are given as integers from 1 to 106. The second line contains la integers — the hieroglyphs in the first picture, in the clockwise order, starting with one of them. The third line contains lb integers — the hieroglyphs in the second picture, in the clockwise order, starting with one of them. It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice. The second circle also has this property.

Print a single number — the maximum length of the common substring and subsequence. If at any way of breaking the circles it does not exist, print 0.

NoteIn the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.

package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<16)
	var la, lb int
	fmt.Fscan(in, &la, &lb)
	a := make([]int, la)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	b := make([]int, lb)
	bPos := make([]int, 1e6+1)
	for i := range b {
		fmt.Fscan(in, &b[i])
		bPos[b[i]] = i + 1
	}

	ans := 0
	wrapped := false
	var i, j int
	for i < la && j - i < la {
		if bPos[a[j%la]] == 0 {
			j++
			i = j
			wrapped = false
			continue
		}
		if i == j {
			j++
			if ans < j-i {
				ans = j - i
			}
		}
		for j-i < la {
			if bPos[a[j%la]] == 0 {
				break
			}
			if bPos[a[j%la]] < bPos[a[(j-1)%la]] && (wrapped || bPos[a[i]] < bPos[a[j%la]]) || wrapped && bPos[a[i]] < bPos[a[j%la]] {
				if bPos[a[i]] > bPos[a[(i+1)%la]] {
					wrapped = false
				}
				i++
				break
			}
			if bPos[a[j%la]] < bPos[a[(j-1)%la]] {
				wrapped = true
			}
			j++
			if ans < j-i {
				ans = j - i
			}
		}
	}
	fmt.Println(ans)
}


Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.

The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).

Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range.  Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.

package main

import (
	"fmt"
    "math"
)

func main() {
	var R,x1,y1,x2,y2 int64
	fmt.Scan(&R, &x1, &y1, &x2, &y2)
    x := x1 - x2
    y := y1 - y2
    if (x*x + y*y >= R * R) {
        fmt.Print(x1,y1,R)
    } else {
        if (x == 0 && y == 0) {
            dist := float64(R) / 2
            fmt.Print(float64(x1) + dist, float64(y1), dist)
        } else {
            l := math.Sqrt(float64(x*x+y*y))
            dist := (float64(R) + l) / 2
            xd := float64(x) / l * dist
            yd := float64(y) / l * dist
            fmt.Print(float64(x2) + xd, float64(y2) + yd, dist)
        }
    }
}