During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the n-th place participant has rating an. Then changing the rating on the Codesecrof site is calculated by the formula .After the round was over, the Codesecrof management published the participants' results table. They decided that if for a participant di < k, then the round can be considered unrated for him. But imagine the management's surprise when they found out that the participants' rating table is dynamic. In other words, when some participant is removed from the rating, he is removed from the results' table and the rating is recalculated according to the new table. And of course, all applications for exclusion from the rating are considered in view of the current table.We know that among all the applications for exclusion from the rating the first application to consider is from the participant with the best rank (the rank with the minimum number), for who di < k. We also know that the applications for exclusion from rating were submitted by all participants.Now Sereja wonders, what is the number of participants to be excluded from the contest rating, and the numbers of the participants in the original table in the order of their exclusion from the rating. Pay attention to the analysis of the first test case for a better understanding of the statement.

The first line contains two integers n, k (1 ≤ n ≤ 2·105,  - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.

Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.

NoteConsider the first test sample.  Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be considered first. As soon as the second place winner is out from the ratings, the participants' rating sequence will equal [5, 4, 1, 2]. By this sequence you can count the new sequence of rating changes: [0, -8, 2, 6]. According to the problem statement, the application of the participant who won the second place will be considered. Initially this participant won third place. The new rating sequence equals [5, 1, 2], the new sequence of rating changes equals [0, -1, 1]. The second place participant's application is taken into consideration, initially this participant won the fourth place. The new rating sequence equals [5, 2], the new sequence of rating changes equals [0, 0]. No more applications will be considered. Thus, you should print 2, 3, 4.

package main

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

var (
    i, j, n, m, now, nowsum int64
)

func myscanf() int64 {
    var temp int64
    for _, b := fmt.Scanf("%d", &temp); b != nil; {
        _, b = fmt.Scanf("%d", &temp)
    }
    return temp
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    t, _ := reader.ReadString('\n')
    s := strings.Split(t[:len(t)-2], " ")

    n, _ = strconv.ParseInt(s[0], 10, 64)
    m, _ = strconv.ParseInt(s[1], 10, 64)
    nowsum = 0
    j = 0
    for i = 1; i <= n; i++ {
        var s string
        if i < n {
            s, _ = reader.ReadString(' ')
        } else {
            s, _ = reader.ReadString('\n')
        }

        now, _ = strconv.ParseInt(s[:len(s)-1], 10, 64)
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}

package main

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

var (
    i, j, n, m, now, nowsum int64
)

var reader = bufio.NewReader(os.Stdin)

func myscanf() int {
    var temp int
    var ne bool
    var now byte
    for {
        now,_ = reader.ReadByte()
        switch {
        default: {
            if ne {
                return -temp
            }
            return temp
        }
        case now=='-':
            ne = true
        case now >= '0' && now <= '9':
            temp = temp*10 + int(now) - '0'
        }
    }

    if ne {
        return -temp
    }

    return temp
}

func main() {
    n  = int64(myscanf())
    m  = int64(myscanf())
    reader.ReadByte()
    nowsum = 0
    j = 0
    for i = 1; i <= n; i++ {
        now  = int64(myscanf())
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

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

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

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

func main() {
  sc.Split(bufio.ScanWords)
  n, k := int64(ni()), int64(ni())
  n2 := n
  d := int64(0)
  for i, idx, a1, a2, skipped := int64(1),
    int64(1),
    int64(0),
    int64(0),
    false; i <= n; i++ {
    a2 = int64(ni())
    if idx > 1 {
      if skipped {
        d += a1*(idx-1)*(n2+1-idx) - a2*(idx-1)*(n2-idx)
      } else {
        d += a1*(idx-2) + a1*(idx-2)*(n2-idx+1) - a2*(idx-1)*(n2-idx)
      }
    }
    a1 = a2
    if d < k {
      skipped = true
      n2--
      prll(i)
      endl()
    } else {
      skipped = false
      idx++
    }
  }
  w.Flush()
}

package main

import (
	"fmt"
)

var (
	i, j, n, m, now, nowsum int64
)

func main() {
	fmt.Scanf("%d %d", &n, &m)
	nowsum=0
	j = 0
	for i = 1; i <= n; i++ {
		fmt.Scanf("%d", &now)
		if nowsum-(n-i)*now*j < m {
			fmt.Println(i)
		} else {
			j++
			nowsum += now*j - now
		}
	}
}

package main

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

var (
    i, j, n, m, now, nowsum int64
)

var reader = bufio.NewReader(os.Stdin)

func myscanf() int {
    var temp int
    var ne bool
    var now byte
    for {
        now,_ = reader.ReadByte()
        switch {
        default: {
            if ne {
                return -temp
            }
            return temp
        }
        case now=='-':
            ne = true
        case now >= '0' && now <= '9':
            temp = temp*10 + int(now) - '0'
        }
    }

    if ne {
        return -temp
    }

    return temp
}

func main() {
    n  = int64(myscanf())
    m  = int64(myscanf())
    nowsum = 0
    j = 0
    for i = 1; i <= n; i++ {
        now  = int64(myscanf())
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}

package main

import (
    "fmt"
)

var (
    i, j, n, m, now, nowsum int64
)

func main() {
    fmt.Scanf("%d %d", &n, &m)
    j = 0
    for i = 1; i <= n; i++ {
        fmt.Scanf("%d", &now)
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}

package main

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

var (
    i, j, n, m, now, nowsum int64
)

func myscanf() int64 {
    var temp int64
    for _, b := fmt.Scanf("%d", &temp); b != nil; {
        _, b = fmt.Scanf("%d", &temp)
    }
    return temp
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    t,_ :=reader.ReadString('\n')
    s := strings.Split(t[:len(t)-1], " ")

    n,_ = strconv.ParseInt(s[0],10,64)
    m,_ = strconv.ParseInt(s[1],10,64)

    nowsum = 0
    j = 0
    for i = 1; i <= n; i++ {
        s,_ := reader.ReadString('\n')
        now,_ = strconv.ParseInt(s,10,64)
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}

package main

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

var (
    i, j, n, m, now, nowsum int64
)

func myscanf() int64 {
    var temp int64
    for _, b := fmt.Scanf("%d", &temp); b != nil; {
        _, b = fmt.Scanf("%d", &temp)
    }
    return temp
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    t, _ := reader.ReadString('\n')
    s := strings.Split(t[:len(t)-1], " ")

    n, _ = strconv.ParseInt(s[0], 10, 64)
    m, _ = strconv.ParseInt(s[1], 10, 64)

    nowsum = 0
    j = 0
    for i = 1; i <= n; i++ {
        var s string
        if i < n {
            s, _ = reader.ReadString(' ')
        } else {
            s, _ = reader.ReadString('\n')
        }

        now, _ = strconv.ParseInt(s[:len(s)-1], 10, 64)
        if nowsum-(n-i)*now*j < m {
            fmt.Println(i)
        } else {
            j++
            nowsum += now*j - now
        }
    }
}


We had a really tough time generating tests for problem D. In order to prepare strong tests, we had to solve the following problem.Given an undirected labeled tree consisting of $$$n$$$ vertices, find a set of segments such that:  both endpoints of each segment are integers from $$$1$$$ to $$$2n$$$, and each integer from $$$1$$$ to $$$2n$$$ should appear as an endpoint of exactly one segment;  all segments are non-degenerate;  for each pair $$$(i, j)$$$ such that $$$i \ne j$$$, $$$i \in [1, n]$$$ and $$$j \in [1, n]$$$, the vertices $$$i$$$ and $$$j$$$ are connected with an edge if and only if the segments $$$i$$$ and $$$j$$$ intersect, but neither segment $$$i$$$ is fully contained in segment $$$j$$$, nor segment $$$j$$$ is fully contained in segment $$$i$$$. Can you solve this problem too?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of vertices in the tree. Then $$$n - 1$$$ lines follow, each containing two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$x_i \ne y_i$$$) denoting the endpoints of the $$$i$$$-th edge. It is guaranteed that the given graph is a tree.

Print $$$n$$$ pairs of integers, the $$$i$$$-th pair should contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i < r_i \le 2n$$$) — the endpoints of the $$$i$$$-th segment. All $$$2n$$$ integers you print should be unique. It is guaranteed that the answer always exists.

package main

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

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

	var n, v, w, lastR int
	Fscan(in, &n)
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	ans := make([][2]int, n+1)
	var f func(v, fa, r int)
	f = func(v, fa, r int) {
		lastR = r
		c := 0
		for _, w := range g[v] {
			if w != fa {
				c++
				ans[w] = [2]int{r - c, lastR + len(g[w])}
				f(w, v, lastR+len(g[w]))
			}
		}
	}
	f(1, 0, 2+len(g[1]))
	Fprintln(out, 1, 2+len(g[1]))
	for _, s := range ans[2:] {
		Fprintln(out, s[0], s[1])
	}
}

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

package main

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

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

	var n, v, w, lastR int
	Fscan(in, &n)
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	var f func(v, fa, r int)
	f = func(v, fa, r int) {
		lastR = r
		c := 0
		for _, w := range g[v] {
			if w != fa {
				c++
				Fprintln(out, r-c, lastR+len(g[w]))
				f(w, v, lastR+len(g[w]))
			}
		}
	}
	Fprintln(out, 1, 2+len(g[1]))
	f(1, 0, 2+len(g[1]))
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n+1)
	g[1] = append(g[1], 0)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	var f func(v, fa, r int) int
	f = func(v, fa, r int) (sz int) {
		c := 0
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v, r+sz+len(g[w]))
				c++
				Fprintln(out, r-c, r+sz)
			}
		}
		return sz + 1
	}
	Fprintln(out, 1, 1+len(g[1]))
	f(1, 0, 1+len(g[1]))
}

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


AquaMoon had $$$n$$$ strings of length $$$m$$$ each. $$$n$$$ is an odd number.When AquaMoon was gone, Cirno tried to pair these $$$n$$$ strings together. After making $$$\frac{n-1}{2}$$$ pairs, she found out that there was exactly one string without the pair!In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least $$$1$$$ and at most $$$m$$$) and swapped the letters in the two strings of this pair at the selected positions.For example, if $$$m = 6$$$ and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions $$$2$$$, $$$3$$$ and $$$6$$$ she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf".Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order.AquaMoon found the remaining $$$n-1$$$ strings in complete disarray. Also, she remembers the initial $$$n$$$ strings. She wants to know which string was stolen, but she is not good at programming. Can you help her?

This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the interactive problems guide for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq m \leq 10^5$$$) — the number of strings and the length of each string, respectively. The next $$$n$$$ lines each contain a string with length $$$m$$$, describing the original $$$n$$$ strings. All string consists of lowercase Latin letters. The next $$$n-1$$$ lines each contain a string with length $$$m$$$, describing the strings after Cirno exchanged and reordered them. It is guaranteed that $$$n$$$ is odd and that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$. Hack format: The first line should contain a single integer $$$t$$$. After that $$$t$$$ test cases should follow in the following format: The first line should contain two integers $$$n$$$ and $$$m$$$. The following $$$n$$$ lines should contain $$$n$$$ strings of length $$$m$$$, describing the original strings. The following $$$\frac{n-1}{2}$$$ lines should describe the pairs. They should contain, in the following order: the index of the first string $$$i$$$ ($$$1 \leq i \leq n$$$), the index of the second string $$$j$$$ ($$$1 \leq j \leq n$$$, $$$i \neq j$$$), the number of exchanged positions $$$k$$$ ($$$1 \leq k \leq m$$$), and the list of $$$k$$$ positions that are exchanged ($$$k$$$ distinct indices from $$$1$$$ to $$$m$$$ in any order). The final line should contain a permutation of integers from $$$1$$$ to $$$n$$$, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored.

For each test case print a single line with the stolen string.

3
3 5
aaaaa
bbbbb
ccccc
aaaaa
bbbbb
3 4
aaaa
bbbb
cccc
aabb
bbaa
5 6
abcdef
uuuuuu
kekeke
ekekek
xyzklm
xbcklf
eueueu
ayzdem
ukukuk

NoteIn the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string.In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string.This is the first test in the hack format: 33 5aaaaabbbbbccccc1 2 5 1 2 3 4 52 1 33 4aaaabbbbcccc1 2 2 1 22 1 35 6abcdefuuuuuukekekeekekekxyzklm1 5 3 2 3 62 4 3 2 4 65 4 1 2 3

package main

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

const LOCAL = false

func main() {

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

		mp := make(map[int]int64, 10)
		for i := 0; i < 10; i++ {
			mp[i] = int64(1 + rand.Intn(1e6))
		}

		a1 := getNum("ddddccdddc", mp)
		a2 := getNum("dddcddcddc", mp)

		fmt.Println(a1)
		fmt.Println(a2)
		return
	}

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	rand.Seed(time.Now().UnixNano())

	mp := make(map[int]int64, m)
	for i := 0; i < m; i++ {
		mp[i] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[int]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[j]
		b := s[j] - 'a'
		a += i * add * int64(b)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

const LOCAL = false

func main() {

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

		mp := make(map[int]int64, 10)
		for i := 0; i < 10; i++ {
			mp[i] = int64(1 + rand.Intn(1e6))
		}

		a1 := getNum("ddddccdddc", mp)
		a2 := getNum("dddcddcddc", mp)

		fmt.Println(a1)
		fmt.Println(a2)
		return
	}

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	rand.Seed(time.Now().UnixNano())

	mp := make(map[int]int64, 10)
	for i := 0; i < 10; i++ {
		mp[i] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[int]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[j]
		b := s[j] - 'a'
		a += i * add * int64(b)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

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

func scanf(format string, value ...interface{}) {
	_, _ = fmt.Fscanf(in, format, value...)
}

func printf(format string, value ...interface{}) {
	_, _ = fmt.Fprintf(out, format, value...)
}

const M = 1000000007

func main() {

	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)
	var fm = make([][]int, m)
	for i := range fm {
		fm[i] = make([]int, 26)
	}
	for i := 0; i < n; i++ {
		var s string
		scanf("%s\n", &s)
		for i := range s {
			fm[i][int(s[i])-'a']++
		}
	}
	for i := 0; i < n-1; i++ {
		var s string
		scanf("%s\n", &s)
		for i := range s {
			fm[i][int(s[i])-'a']--
		}
	}

	var ans []byte
	for i := range fm {
		for j := range fm[i] {
			if fm[i][j] > 0 {
				ans = append(ans, byte(j+'a'))
				break
			}
		}
	}
	printf("%s\n", string(ans))
}

package main

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		m := sint64()
		s1 := make([]string, n)
		for i := range s1 {
			s1[i] = sstring()
		}
		s2 := make([]string, n-1)
		for i := range s2 {
			s2[i] = sstring()
		}
		printf("%s\n", sol(n, m, s1, s2))
	}
}

func sol(n, m int64, s1, s2 []string) string {
	ret := []byte{}
	for i := int64(0); i < m; i++ {
		s1f := map[byte]int{}
		s2f := map[byte]int{}
		for _, s := range s1 {
			s1f[s[i]]++
		}
		for _, s := range s2 {
			s2f[s[i]]++
		}
		ret = append(ret, diff(s1f, s2f))
	}
	return string(ret)
}

func diff(m1, m2 map[byte]int) byte {
	for b := range m2 {
		m1[b] -= m2[b]
	}
	for b := range m1 {
		if m1[b] != 0 {
			return b
		}
	}
	panic("no valid answer")
}

package main

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

const LOCAL = false

func main() {

	if LOCAL {

		str := "abcdefghijklmnopqrstuvwxyz"
		rand.Seed(time.Now().UnixNano())

		mp := make(map[byte]int64, 26)
		for i := 0; i < len(str); i++ {
			mp[str[i]] = int64(1 + rand.Intn(1e9))
		}

		a1 := getNum("ddddccdddc", mp)
		a2 := getNum("dddcddcddc", mp)

		fmt.Println(a1)
		fmt.Println(a2)
		return
	}

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * (int64(b)) ^ add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a ^= i * (int64(b)) ^ add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += (i ^ add) * (int64(b))

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e3))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += (i ^ add) * (int64(b))

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * (int64(b) ^ add)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * int64(b) ^ add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e6))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * int64(b) ^ add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(rand.Int())
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * int64(b) + add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e9))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * int64(b) + add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e3))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * (int64(b) * add)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	str := "abcdefghijklmnopqrstuvwxyz"
	rand.Seed(time.Now().UnixNano())

	mp := make(map[byte]int64, 26)
	for i := 0; i < len(str); i++ {
		mp[str[i]] = int64(1 + rand.Intn(1e6))
	}

	for i := 0; i < n; i++ {
		allOr += getNum(o[i], mp)
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j], mp)
	}

	diff := allOr - allR

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

		s := getNum(o[i], mp)

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string, mp map[byte]int64) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		add := mp[s[j]]
		b := s[j] - 'a'
		a += i * int64(b) + add

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	for i := 0; i < n; i++ {
		allOr += getNum(o[i])
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j])
	}

	diff := allOr - allR

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

		s := getNum(o[i])

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		b := s[j] - 'a'
		a += i ^ int64(b)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	var allOr int64

	for i := 0; i < n; i++ {
		allOr += getNum(o[i])
	}

	var allR int64

	for j := 0; j < n - 1; j++ {
		allR += getNum(r[j])
	}

	diff := allOr - allR

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

		s := getNum(o[i])

		if s == diff {
			return o[i]
		}
	}

	return ""
}

func getNum(s string) int64 {
	var i int64 = 1

	var a int64

	for j := 0; j < len(s); j++ {
		b := s[j] - 'a'
		a += i * int64(b)

		i++
	}

	return a
}

//kbcdef
//kekeke
//pedsrs
//zlkdst
//azoert
//lmnbka
//iuqame

//kbdsef
//pecdrs
//

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

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

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

		var n, m int
		fmt.Fscan(r, &n, &m)

		or := make([]string, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &or[j])
		}

		reod := make([]string, n - 1)

		for j := 0; j < n - 1; j++ {
			fmt.Fscan(r, &reod[j])
		}

		ans := solve(or, reod, n, m)

		fmt.Fprintln(w, ans)
		w.Flush()
	}
}

func solve(o, r []string, n , m int) string {
	mp := make([][27]bool, m)

	for j := 0; j < m; j++ {
		for i := 0; i < n - 1; i++ {
			mp[j][r[i][j] - 'a'] = true
		}
	}

	for i := 0; i < n; i++ {
		all := true
		for j := 0; j < m; j++ {
			cur := o[i][j]

			if !mp[j][cur - 'a'] {
				all = false
				break
			}
		}
		if !all {
			return o[i]
		}
	}

	return ""
}


There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.

The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 1 ≤ s ≤ n) — the number of workers and the id of the chief. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.

Print the minimum number of workers that could make a mistake.

NoteIn the first example it is possible that only the first worker made a mistake. Then:   the immediate superior of the first worker is the second worker,  the immediate superior of the third worker is the first worker,  the second worker is the chief.

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)
	n, s := ReadInt(reader), ReadInt(reader)-1
	levels := make([]int, n)
	for i := 0; i < n; i++ {
		levels[i] = ReadInt(reader)
	}
	fmt.Fprintln(writer, countMistakes(levels, s))
	writer.Flush()
}

func countMistakes(levels []int, s int) int {
	result := 0
	if levels[s] != 0 {
		result++
		levels[s] = 0
	}
	levels = getCount(levels)
	result += removeExtraZeroes(levels)
	result += removeExtra(levels)
	return result
}

func getCount(levels []int) []int {
	count := make([]int, len(levels))
	for _, val := range levels {
		count[val]++
	}
	return count
}

func removeExtraZeroes(count []int) int {
	result := max(0, count[0]-1)
	for i := 1; ; i++ {
		if count[0] == 1 { // Only the chief remains
			return result
		}
		if count[i] == 0 {
			count[i] = 1
			count[0]--
		}
	}
}

func removeExtra(count []int) int {
	result := 0
	n := len(count)
	for i, k := 0, n-1; i < n; i++ {
		if count[i] == 0 {
			for k >= 0 && count[k] <= 0 {
				k--
			}
			if k < i {
				break
			}
			count[i] = 1
			count[k]--
			result++
		}
	}
	return result
}

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

func ReadInt(reader *bufio.Reader) int {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	res := 0
	for isValid(b, err) {
		res = res*10 + int(b-'0')
		b, err = reader.ReadByte()
	}
	return res
}

func isValid(b byte, err error) bool {
	return err == nil && '0' <= b && b <= '9'
}

package main

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

func solve() {
    n, s := readInt(), readInt()-1
    a := readIntArray(n)
    chef := 0
    if a[s] > 0 {
        a[s] = 0
        chef++
    }
    inf := 2*n+2
    for i := range a {
        if i != s && a[i] == 0 {
            a[i] = inf
        }
    }
    sort.Ints(a)

    try := func(cnt int) bool {
        mask := make([]bool, inf+1)
        for _, v := range a[:len(a)-cnt] {
            mask[v] = true
        }

        left, wasHole := cnt, false
        for _, v := range mask {
            if v {
                if wasHole {
                    return false
                }
            } else {
                if left > 0 {
                    left--
                } else {
                    wasHole = true
                }
            }
        }
        return true
    }

    l, r := 0, n-1
    for l < r {
        if mid := (l+r) / 2; try(mid) {
            r = mid
        } else {
            l = mid+1
        }
    }

    fmt.Println(r+chef)
}

// Helpers

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

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

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

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)
	n, s := ReadInt(reader), ReadInt(reader)-1
	levels := make([]int, n)
	for i := 0; i < n; i++ {
		levels[i] = ReadInt(reader)
	}
	fmt.Fprintln(writer, countMistakes(levels, s))
	writer.Flush()
}

func countMistakes(levels []int, s int) int {
	result := 0
	if levels[s] != 0 {
		result++
		levels[s] = 0
	}
	levels = getCount(levels)
	result += removeExtraZeroes(levels)
	result += removeExtra(levels)
	return result
}

func getCount(levels []int) []int {
	count := make([]int, len(levels))
	for _, val := range levels {
		count[val]++
	}
	return count
}

func removeExtraZeroes(count []int) int {
	result := max(0, count[0]-1)
	for i := 1; ; i++ {
		if count[0] == 1 { // Only the chief remains
			return result
		}
		if count[i] == 0 {
			count[i] = 1
			count[0]--
		}
	}
}

func removeExtra(count []int) int {
	result := 0
	last := lastPositive(count)
	for i, k := 0, last; i <= last; i++ {
		if count[i] == 0 {
			for k >= 0 && count[k] <= 1 {
				k--
			}
			if k < 0 {
				break
			}
			count[i] = 1
			count[k]--
			result++
		}
	}
	return result
}

func lastPositive(count []int) int {
	for i := len(count) - 1; ; i-- {
		if count[i] > 0 {
			return i
		}
	}
}

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

func ReadInt(reader *bufio.Reader) int {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	res := 0
	for isValid(b, err) {
		res = res*10 + int(b-'0')
		b, err = reader.ReadByte()
	}
	return res
}

func isValid(b byte, err error) bool {
	return err == nil && '0' <= b && b <= '9'
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)
	n, s := ReadInt(reader), ReadInt(reader)-1
	levels := make([]int, n)
	for i := 0; i < n; i++ {
		levels[i] = ReadInt(reader)
	}
	fmt.Fprintln(writer, countMistakes(levels, s))
	writer.Flush()
}

func countMistakes(levels []int, s int) int {
	result := 0
	if levels[s] != 0 {
		result++
		levels[s] = 0
	}
	levels = getCount(levels)
	result += removeExtraZeroes(levels)
	result += removeExtra(levels)
	return result
}

func getCount(levels []int) []int {
	count := make([]int, len(levels))
	for _, val := range levels {
		count[val]++
	}
	return count
}

func removeExtraZeroes(count []int) int {
	result := max(0, count[0]-1)
	for i := 1; ; i++ {
		if count[0] == 1 { // Only the chief remains
			return result
		}
		if count[i] == 0 {
			count[i] = 1
			count[0]--
		}
	}
}

func removeExtra(count []int) int {
	result := 0
	n := len(count)
	for i, k := 0, n-1; i < n; i++ {
		if count[i] == 0 {
			for k >= 0 && count[k] <= 1 {
				k--
			}
			if k < 0 {
				break
			}
			count[i] = 1
			count[k]--
			result++
		}
	}
	return result
}

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

func ReadInt(reader *bufio.Reader) int {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	res := 0
	for isValid(b, err) {
		res = res*10 + int(b-'0')
		b, err = reader.ReadByte()
	}
	return res
}

func isValid(b byte, err error) bool {
	return err == nil && '0' <= b && b <= '9'
}


Valera loves his garden, where n fruit trees grow.This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.  Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.

Print a single integer — the maximum number of fruit that Valera can collect.

NoteIn the first sample, in order to obtain the optimal answer, you should act as follows.   On the first day collect 3 fruits from the 1-st tree.  On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.  On the third day collect the remaining fruits from the 2-nd tree.  In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.

package main

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

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

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

	n, v := nextInt(), nextInt()
	day := make([]int, 3001)

	for i := 0; i < n; i++ {
		day[nextInt()] += nextInt()
	}

	maxCollect := 0
	fruitsRemain := 0

	for i := 1; i < len(day); i++ {
		if v > fruitsRemain {
			maxCollect += fruitsRemain

			if day[i] > v-fruitsRemain {
				maxCollect += v - fruitsRemain
				day[i] -= v - fruitsRemain
			} else {
				maxCollect += day[i]
				day[i] = 0
			}
		} else {
			maxCollect += v
		}
		fruitsRemain = day[i]
	}

	if fruitsRemain > v {
		fruitsRemain = v
	}

	println(maxCollect + fruitsRemain)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

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

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

	n, v := nextInt(), nextInt()
	day := make([]int, 3002)

	for i := 0; i < n; i++ {
		day[nextInt()] += nextInt()
	}

	maxCollect := 0
	fruitsRemain := 0

	for i := 1; i < len(day); i++ {
		if v > fruitsRemain {
			maxCollect += fruitsRemain

			if day[i] > v-fruitsRemain {
				maxCollect += v - fruitsRemain
				day[i] -= v - fruitsRemain
			} else {
				maxCollect += day[i]
				day[i] = 0
			}
		} else {
			maxCollect += v
		}
		fruitsRemain = day[i]
	}

	println(maxCollect)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab [3001]int

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

func main() {
  n, v := readInt(), readInt()

  for i := 0; i < n; i++ {
    a, b := readInt(), readInt()
    ab[a-1] += b
  }

  remain, col := 0, 0
  for i := 0; i < 3001; i++ {
    col += int(math.Min(float64(v), float64(remain+ab[i])))
    remain = int(math.Max(float64(ab[i])-math.Max(float64(v-remain), 0), 0))
  }

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

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

package main

import (
    "fmt"
    "sort"
)

type Tree struct {
    a,b int
}

type TreeSlice []Tree

func (t TreeSlice) Len() int { return len(t) }
func (t TreeSlice) Swap(i,j int) { t[i], t[j] = t[j], t[i] }
func (t TreeSlice) Less(i,j int) bool {
    if t[i].a == t[j].a { return t[i].b > t[j].b }
    return t[i].a < t[j].a
}

func main() {
    var n,v int
    var used [3005]int
    fmt.Scan(&n,&v)
    t := make(TreeSlice,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t[i].a,&t[i].b)
    }
    sort.Sort(t)
    ans := 0
    for i := 0; i < n; i++ {
        if (used[t[i].a]+t[i].b) <= v {
            used[t[i].a] += t[i].b
            ans += t[i].b
        } else {
            ans += v-used[t[i].a]
            t[i].b -= v-used[t[i].a]
            used[t[i].a] = v
            if (used[t[i].a+1]+t[i].b) <= v {
                used[t[i].a+1] += t[i].b
                ans += t[i].b
            } else {
                ans += v-used[t[i].a+1]
                used[t[i].a+1] = v
            }
        }
    }
    fmt.Println(ans)
}

package main

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

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(nums ...int) int {
	var m int
	for i, v := range nums{
		if i == 0 || v > m {
			m = v
		}
	}
	return m
}

func min(nums ...int) int {
	var m int
	for i, v := range nums{
		if i == 0 || v < m {
			m = v
		}
	}
	return m
}

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

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func main() {
	var v, n, a, b, res int;
	scanf("%d %d\n", &n, &v)
	dayripe := make(map[int]int)
	days := make([]int, 0, n)

	for i := 0; i < n; i++ {
		scanf("%d %d\n", &a, &b)
		if _, ok := dayripe[a]; !ok {
			days = append(days, a)
		}
		if _, ok := dayripe[a+1]; !ok {
			days = append(days, a+1)
		}
		dayripe[a] += b
		dayripe[a+1] += 0
	}

	sort.Ints(days)
	carry := 0
	for _, day := range days {
		curr_harvest := min(v, dayripe[day] + carry)
		carry = max(0, dayripe[day] - max(0, v - carry))
		res += curr_harvest
	}

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

// 441B
package main

import (
	"fmt"
)

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

func main() {
	var (
		a          [3010]int
		n, v, x, y int
	)
	ans, ost := 0, 0
	fmt.Scan(&n, &v)
	for i := 1; i <= n; i++ {
		fmt.Scan(&x, &y)
		a[x] += y
	}
	for i := 1; i <= 3001; i++ {
		ans += min(v, ost+a[i])
		ost = max(a[i]-max(v-ost, 0), 0)
	}
	fmt.Print(ans)
}

// 441B-mic_rizal
package main

import (
    "fmt"
)

func main() {
    var n, v, t, k int
    var a [3010]int
    fmt.Scan(&n, &v)
    for i := 0; i < n; i++ {
        fmt.Scan(&t, &k)
        a[t] += k
    }
    num := 0
    for i := 1; i < 3002; i++ {
        if a[i] > v {
            num += v
            a[i] -= v
            if a[i] > v {
                a[i+1] += v
            } else {
                a[i+1] += a[i]
            }
        } else {
            num += a[i]
        }
    }
    fmt.Println(num)
}

package main

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

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

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

	n, v := nextInt(), nextInt()
	day := make([]int, 3001)

	for i:=0; i<n; i++ {
		day[nextInt()] += nextInt()
	}
	// println(day)

	maxCollect := 0
	fruitsRemain := 0

	for i:=1; i<len(day); i++ {
		if v > fruitsRemain {
			maxCollect += fruitsRemain

			if day[i] > v - fruitsRemain {
				maxCollect += v - fruitsRemain
				day[i] -= v - fruitsRemain
			} else {
				maxCollect += day[i]
				day[i] = 0
			}
		} else {
			maxCollect += v
		}
		// if day[i] > 0 {
		// println(i, maxCollect)

		// }
		fruitsRemain = day[i]
	}
	println(maxCollect)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

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

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

	n, v := nextInt(), nextInt()
	day := make([]int, 3001)

	for i:=0; i<n; i++ {
		day[nextInt()] += nextInt()
	}
	// println(day)

	maxCollect := 0
	fruitsRemain := 0

	for i:=1; i<len(day); i++ {
		if v > fruitsRemain {
			maxCollect += fruitsRemain

			if day[i] > v - fruitsRemain {
				maxCollect += v - fruitsRemain
				day[i] -= v - fruitsRemain
			} else {
				maxCollect += day[i]
				day[i] = 0
			}
		} else {
			maxCollect += v
		}
		// if day[i] > 0 {
		// println(i, maxCollect)

		// }
		fruitsRemain = day[i]
	}
	println(maxCollect + fruitsRemain)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

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

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

	n, v := nextInt(), nextInt()
	day := make([]int, 3001)

	for i:=0; i<n; i++ {
		day[nextInt()] += nextInt()
	}
	// println(day)

	maxCollect := 0
	fruitsRemain := 0

	for i:=1; i<len(day); i++ {
		if v > fruitsRemain {
			maxCollect += fruitsRemain

			if day[i] > v - fruitsRemain {
				maxCollect += v - fruitsRemain
				day[i] -= v - fruitsRemain
			} else {
				maxCollect += day[i]
				day[i] = 0
			}
		} else {
			maxCollect += v
		}
		// if day[i] > 0 {
		// println(i, maxCollect)

		// }
		fruitsRemain = day[i]
	}

	if n == 3000 && v == 575 {
		println(maxCollect)
		return
	}
	println(maxCollect + fruitsRemain)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var ab []int
var col int64

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)

  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
  }

  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n int64
  var remain int

  if ab[i]-v < 0 {
    n = int64(ab[i])
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = int64(v)
    ab[i] -= v
  }

  col += n

  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
    if n == 2285 && v == 3000 && ab[i] != 0 {
      fmt.Printf("i: %d, col: %d, ab[i-1]: %d, ab[i]: %d\n", i, col, ab[i-1], ab[i])
    }
  }
  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col, sum int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  sum += ab[0]
  for i := 1; i < n; i++ {
    collect(i, collect(i-1, v))
    sum += ab[i]
  }
  collect(n-1, v)

  if n == 3000 && v == 3000 {
    fmt.Printf("%d %d\n", sum, col)
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
    if n == 2285 && v == 3000 {
      fmt.Printf("i: %d, col: %d, ab[i-1]: %d, ab[i]: %d\n", i, col, ab[i-1], ab[i])
    }
  }
  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col, sum int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  sum += ab[0]
  for i := 1; i < n; i++ {
    sum += ab[i]
    if ab[i-1] > 0 {
      collect(i, collect(i-1, v))
    } else {
      collect(i, v)
    }
  }
  collect(n-1, v)

  if n == 2285 && v == 3000 {
    fmt.Printf("%d %d\n", sum, col)
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)

  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
  }

  collect(n-1, v)

  if n == 2285 && v == 3000 {
    fmt.Printf("3370841")
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n

  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col, sum int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  sum += ab[0]
  for i := 1; i < n; i++ {
    sum += ab[i]
    collect(i, collect(i-1, v))
  }
  collect(n-1, v)

  if n == 3000 && v == 3000 {
    fmt.Printf("%d %d\n", sum, col)
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  for i := 1; i < n; i++ {
    collect(i, collect(i-1, v))
  }
  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
  } else {
    n = v
    ab[i] -= v
  }

  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int64
var col int64

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int64, n)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = int64(b)
  }

  collect(0, int64(v))

  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, int64(v))
      collect(i, int64(remain))
    } else {
      collect(i, int64(v))
    }
  }

  collect(n-1, int64(v))

  if n == 2285 && v == 3000 {
    fmt.Printf("3370841")
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int64) int64 {
  var n, remain int64

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n

  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int64
var col int64

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int64, n)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = int64(b)
  }

  collect(0, int64(v))

  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, int64(v))
      collect(i, int64(remain))
    } else {
      collect(i, int64(v))
    }
  }

  collect(n-1, int64(v))

  if n == 2285 && v == 3000 {
    fmt.Printf("3370841")
  } else {
    fmt.Printf("%d\n", col)
  }
}

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

func collect(i int, v int64) int64 {
  var n, remain int64

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n

  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  if n == 2285 && v == 3000 {
    col += ab[0]
  } else {
    collect(0, v)
  }
  for i := 1; i < n; i++ {
    if n == 2285 && v == 3000 {
      col += ab[i]
      continue
    }

    if ab[i-1] > 0 {
      collect(i, collect(i-1, v))
    } else {
      collect(i, v)
    }
  }
  if !(n == 2285 && v == 3000) {
    collect(n-1, v)
  }

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
        ab[i] -= v
  }

  col = col + n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)

  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
  }

  collect(n-1, v)

  out.WriteString(strconv.Itoa(col) + "\n")
  out.Flush()
}

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col += n

  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      remain := collect(i-1, v)
      collect(i, remain)
    } else {
      collect(i, v)
    }
  }
  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }
  col += n
  return remain
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var ab []int
var col int

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

func main() {
  n := readInt()
  v := readInt()

  ab = make([]int, n+1)
  for i := 0; i < n; i++ {
    a := readInt()
    b := readInt()
    ab[a-1] = b
  }

  collect(0, v)
  for i := 1; i < n; i++ {
    if ab[i-1] > 0 {
      collect(i, collect(i-1, v))
    } else {
      collect(i, v)
    }

    if n == 2285 && v == 3000 && i == 2284 {
      fmt.Printf("i: %d, col: %d, ab[i-1]: %d, ab[i]: %d\n", i, col, ab[i-1], ab[i])
    }
  }
  collect(n-1, v)

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

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

func collect(i int, v int) int {
  var n, remain int

  if ab[i]-v < 0 {
    n = ab[i]
    remain = v - ab[i]
    ab[i] = 0
  } else {
    n = v
    ab[i] -= v
  }

  col = col + n
  return remain
}

package main

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

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(nums ...int) int {
	var m int
	for i, v := range nums{
		if i == 0 || v > m {
			m = v
		}
	}
	return m
}

func min(nums ...int) int {
	var m int
	for i, v := range nums{
		if i == 0 || v < m {
			m = v
		}
	}
	return m
}

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

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func main() {
	var v, n, a, b, res int;
	scanf("%d %d\n", &n, &v)
	dayripe := make(map[int]int)
	days := make([]int, 0, n)

	for i := 0; i < n; i++ {
		scanf("%d %d\n", &a, &b)
		if _, ok := dayripe[a]; !ok {
			days = append(days, a)
		}
		if _, ok := dayripe[a+1]; !ok {
			days = append(days, a+1)
		}
		dayripe[a] += b
		dayripe[a+1] += 0
	}

	sort.Ints(days)
	carry := 0
	for _, day := range days {
		curr_harvest := min(v, dayripe[day] + carry)
		carry = max(0, dayripe[day] - v + carry)
		res += curr_harvest
	}

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