You are given a connected weighted undirected graph, consisting of $$$n$$$ vertices and $$$m$$$ edges.You are asked $$$k$$$ queries about it. Each query consists of a single integer $$$x$$$. For each query, you select a spanning tree in the graph. Let the weights of its edges be $$$w_1, w_2, \dots, w_{n-1}$$$. The cost of a spanning tree is $$$\sum \limits_{i=1}^{n-1} |w_i - x|$$$ (the sum of absolute differences between the weights and $$$x$$$). The answer to a query is the lowest cost of a spanning tree.The queries are given in a compressed format. The first $$$p$$$ $$$(1 \le p \le k)$$$ queries $$$q_1, q_2, \dots, q_p$$$ are provided explicitly. For queries from $$$p+1$$$ to $$$k$$$, $$$q_j = (q_{j-1} \cdot a + b) \mod c$$$.Print the xor of answers to all queries.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$; $$$n - 1 \le m \le 300$$$) — the number of vertices and the number of edges in the graph. Each of the next $$$m$$$ lines contains a description of an undirected edge: three integers $$$v$$$, $$$u$$$ and $$$w$$$ ($$$1 \le v, u \le n$$$; $$$v \neq u$$$; $$$0 \le w \le 10^8$$$) — the vertices the edge connects and its weight. Note that there might be multiple edges between a pair of vertices. The edges form a connected graph. The next line contains five integers $$$p, k, a, b$$$ and $$$c$$$ ($$$1 \le p \le 10^5$$$; $$$p \le k \le 10^7$$$; $$$0 \le a, b \le 10^8$$$; $$$1 \le c \le 10^8$$$) — the number of queries provided explicitly, the total number of queries and parameters to generate the queries. The next line contains $$$p$$$ integers $$$q_1, q_2, \dots, q_p$$$ ($$$0 \le q_j < c$$$) — the first $$$p$$$ queries.

Print a single integer — the xor of answers to all queries.

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

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

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func sameSpanningTree(a, b *SpanningTree) bool {
	for i := 0; i < n-1; i++ {
		if a.id[i] != b.id[i] {
			return false
		}
	}
	return true
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			importantXs = append(importantXs, half)
			importantXs = append(importantXs, half+1)
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half-1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	// printf("important weights = %v\n", importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)
	// printf("explicit = %d, total=%d\n", explicitQueries, totalQueries)
	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 0
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			if !sameSpanningTree(optimal, mst) {
				optimal, mst = mst, optimal
				fillSpanningTreeAcc(optimal)
			}
			i = j
		}
		ansq := calc(optimal, q)
		// printf("answer(%d) = %d. x=%d\n", q, ansq, importantXs[i])
		ansXor ^= ansq
	}
	printf("%d\n", ansXor)
}

package main

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

var n, m int

var p,k,a,b, c int64

var qu []int64

type edge struct {
	from, to int
	w int64
}

var e []*edge

type ByW []*edge

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

var r *bufio.Reader

const WRITE = false

func main() {

	rand.Seed(time.Now().UnixNano())
	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 5
			m = 10

			f.WriteString("5 10\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e2)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("5 10 7 13 100\n")

			for j := 1; j <= 5; j++ {
				x := rand.Intn(1e2)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}

			f.WriteString("\n")
		}

		return
	}

	r = bufio.NewReader(os.Stdin)

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

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to int
		var w int64
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	fmt.Fscan(r, &p, &k, &a, &b, &c)

	qu = make([]int64, p)

	for i := 0; i < int(p); i++ {
		var x int64
		fmt.Fscan(r, &x)
		qu[i] = x
	}

	//	st := time.Now().UnixNano()

	ans := solve()

	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve_stupid() int64 {
	var xMax int64 = 1000

	ans := make([]int64, xMax + 1)

	var x int64
	for x = 0; x <= xMax; x++ {
		sum := computeMST(x)
		ans[x] = sum
	}

	var aa int64

	var xIn int64

	var i int64
	for i = 0; i < p; i++ {
		xIn = qu[i]

		aa = aa ^ ans[xIn]
	}

	for i := p; i < k; i++ {
		xIn = (xIn * a + b) % c

		aa = aa ^ ans[xIn]
	}

	return aa

}

//71 55 109 45 125 69 35 66 125 69
//21 55 109 45 125 69 35 66 125 69
//71 55 109 45 125 69 35 66 125 69

func computeMST(x int64) int64 {
	e2 := make([]*edge, m)

	for i := 0; i < m; i++ {
		ed := e[i]

		ed2 := edge{ed.from, ed.to, abs(ed.w - x)}

		e2[i] = &ed2
	}

	sort.Sort(ByW(e2))

	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	var sum int64

	for i := 0; i < m;  i++ {
		ed := e2[i]

		a := ed.from
		b := ed.to

		rootA := find(&parent, a)
		rootB := find(&parent, b)

		if rootA==rootB {
			continue
		}

		sum += int64(abs(ed.w))

		if  (rank)[rootA] < (rank)[rootB]{
			(parent)[rootA] = rootB

		} else if (rank)[rootA] > (rank)[rootB] {
			(parent)[rootB] = rootA

		} else {
			(parent)[rootB] = rootA
			(rank)[rootA]++
		}
	}

	return sum

}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int64]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[int64(key)] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[int64(w)] = 1
	}

	tree := newInt64InterfaceTreeMap(func(a int64, b int64) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var x int64

	var i int64
	for i = 0; i < p; i++ {
		x = qu[i]

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p; i < k; i++ {
		x = (x * a + b) % c

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)
		ans = ans ^ res
	}

	return ans
}

func doCompute(x int64) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int64) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	for k := j; k >= 0; k-- {
		ed := e[k]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA == rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if (*rank)[rootA] < (*rank)[rootB] {
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}

	}

	for k := i; k < m; k++ {
		ed := e[k]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA == rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if (*rank)[rootA] < (*rank)[rootB] {
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

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

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type int64InterfaceTreeMap struct {
	endNode   *nodeInt64InterfaceTreeMap
	beginNode *nodeInt64InterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int64, b int64) bool
}

type nodeInt64InterfaceTreeMap struct {
	right   *nodeInt64InterfaceTreeMap
	left    *nodeInt64InterfaceTreeMap
	parent  *nodeInt64InterfaceTreeMap
	isBlack bool
	key     int64
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newInt64InterfaceTreeMap(less func(a int64, b int64) bool) *int64InterfaceTreeMap {
	endNode := &nodeInt64InterfaceTreeMap{isBlack: true}
	return &int64InterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Set(key int64, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeInt64InterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Del(key int64) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeInt64InterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Get(id int64) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *int64InterfaceTreeMap) Contains(id int64) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Range(from, to int64) (forwardIteratorInt64InterfaceTreeMap, forwardIteratorInt64InterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) LowerBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) UpperBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *int64InterfaceTreeMap) Iterator() forwardIteratorInt64InterfaceTreeMap {
	return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *int64InterfaceTreeMap) Reverse() reverseIteratorInt64InterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightInt64InterfaceTreeMap(node)
	}
	return reverseIteratorInt64InterfaceTreeMap{tree: t, node: node}
}

func (t *int64InterfaceTreeMap) findNode(id int64) *nodeInt64InterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.right != nil {
		return mostLeftInt64InterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.left != nil {
		return mostRightInt64InterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *int64InterfaceTreeMap) insertFixup(x *nodeInt64InterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightInt64InterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftInt64InterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeInt64InterfaceTreeMap(root *nodeInt64InterfaceTreeMap, z *nodeInt64InterfaceTreeMap) {
	var y *nodeInt64InterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorInt64InterfaceTreeMap(z)
	}
	var x *nodeInt64InterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeInt64InterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftInt64InterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftInt64InterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightInt64InterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightInt64InterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Prev() {
	i.node = predecessorInt64InterfaceTreeMap(i.node)
	if i.node == nil {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorInt64InterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

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

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half)
				importantXs = append(importantXs, half-1)
			} else {
				importantXs = append(importantXs, half)
				importantXs = append(importantXs, half+1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)

	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 0
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			optimal, mst = mst, optimal
			fillSpanningTreeAcc(optimal)
			i = j
		}
		ansXor ^= calc(optimal, q)
	}
	printf("%d\n", ansXor)
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

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

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func sameSpanningTree(a, b *SpanningTree) bool {
	for i := 0; i < n-1; i++ {
		if a.id[i] != b.id[i] {
			return false
		}
	}
	return true
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			importantXs = append(importantXs, half)
			importantXs = append(importantXs, half+1)
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half-1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	// printf("important weights = %v\n", importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)
	// printf("explicit = %d, total=%d\n", explicitQueries, totalQueries)
	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 1
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			if !sameSpanningTree(optimal, mst) {
				optimal, mst = mst, optimal
				fillSpanningTreeAcc(optimal)
			}
			i = j
		}
		ansq := calc(optimal, q)
		// printf("answer(%d) = %d. x=%d\n", q, ansq, importantXs[i])
		ansXor ^= ansq
	}
	printf("%d\n", ansXor)
}

/**
func processQuery(x int64) int64 {
	lo := 0
	hi := len(optimals) - 1
	mi := lo
	for lo < hi {
		mi = (lo + hi) / 2
		if optimals[mi+1].optimalFrom <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}

	ans := calc(optimals[lo], x)
	// printf("ans: %d\n", ans)
	return ans
}

*/

package main

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

var n, m int

type edge struct {
	from, to int
	w int64
}

var e []*edge

type ByW []*edge

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

var r *bufio.Reader

const WRITE = false

func main() {

	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 50
			m = 300

			f.WriteString("50 300\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e8)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("1000 100000 192712 386162774 100000000\n")

			for j := 1; j <= 999; j++ {
				x := rand.Intn(1e8)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}
			f.WriteString("100000000")
			f.WriteString("\n")
		}

		return
	}

	rand.Seed(time.Now().UnixNano())
	r = bufio.NewReader(os.Stdin)

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

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to int
		var w int64
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	//	st := time.Now().UnixNano()
	ans := solve()
	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int64]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[int64(key)] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[int64(w)] = 1
	}

	tree := newInt64InterfaceTreeMap(func(a int64, b int64) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var p,k,a,b, c int64
	fmt.Fscan(r, &p, &k, &a, &b, &c)

	var x int64

	var i int64
	for i = 0; i < p; i++ {
		fmt.Fscan(r, &x)

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p + 1; i <= k; i++ {
		x = (x * a + b) % c

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res
	}

	return ans
}

func doCompute(x int64) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int64) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	if j > 0 {

		for k := j; k >= 0; k-- {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.l++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

		}

	} else if i < m - 1 {

		for k := i; k < m; k++ {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.r++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}
		}
	}

	return sum
}

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

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type int64InterfaceTreeMap struct {
	endNode   *nodeInt64InterfaceTreeMap
	beginNode *nodeInt64InterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int64, b int64) bool
}

type nodeInt64InterfaceTreeMap struct {
	right   *nodeInt64InterfaceTreeMap
	left    *nodeInt64InterfaceTreeMap
	parent  *nodeInt64InterfaceTreeMap
	isBlack bool
	key     int64
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newInt64InterfaceTreeMap(less func(a int64, b int64) bool) *int64InterfaceTreeMap {
	endNode := &nodeInt64InterfaceTreeMap{isBlack: true}
	return &int64InterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Set(key int64, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeInt64InterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Del(key int64) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeInt64InterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Get(id int64) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *int64InterfaceTreeMap) Contains(id int64) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Range(from, to int64) (forwardIteratorInt64InterfaceTreeMap, forwardIteratorInt64InterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) LowerBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) UpperBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *int64InterfaceTreeMap) Iterator() forwardIteratorInt64InterfaceTreeMap {
	return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *int64InterfaceTreeMap) Reverse() reverseIteratorInt64InterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightInt64InterfaceTreeMap(node)
	}
	return reverseIteratorInt64InterfaceTreeMap{tree: t, node: node}
}

func (t *int64InterfaceTreeMap) findNode(id int64) *nodeInt64InterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.right != nil {
		return mostLeftInt64InterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.left != nil {
		return mostRightInt64InterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *int64InterfaceTreeMap) insertFixup(x *nodeInt64InterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightInt64InterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftInt64InterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeInt64InterfaceTreeMap(root *nodeInt64InterfaceTreeMap, z *nodeInt64InterfaceTreeMap) {
	var y *nodeInt64InterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorInt64InterfaceTreeMap(z)
	}
	var x *nodeInt64InterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeInt64InterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftInt64InterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftInt64InterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightInt64InterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightInt64InterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Prev() {
	i.node = predecessorInt64InterfaceTreeMap(i.node)
	if i.node == nil {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorInt64InterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

package main

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

var n, m int

type edge struct {
	from, to int
	w int
}

var e []*edge

type ByW []*edge

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

var r *bufio.Reader

const WRITE = false

func main() {

	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 50
			m = 300

			f.WriteString("50 300\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e8)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("1000 100000 192712 386162774 100000000\n")

			for j := 1; j <= 999; j++ {
				x := rand.Intn(1e8)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}
			f.WriteString("100000000")
			f.WriteString("\n")
		}

		return
	}

	rand.Seed(time.Now().UnixNano())
	r = bufio.NewReader(os.Stdin)

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

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to, w int
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	//	st := time.Now().UnixNano()
	ans := solve()
	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[key] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[w] = 1
	}

	tree := newIntInterfaceTreeMap(func(a int, b int) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var p,k,a,b, c int
	fmt.Fscan(r, &p, &k, &a, &b, &c)

	var x int

	for i := 0; i < p; i++ {
		fmt.Fscan(r, &x)

		v, r := tree.Get(x)

		if r {
			ans = ans ^ v.(*value).val
			continue
		}

		lb := tree.UpperBound(x)
		lb.Prev()
		if lb.node == nil {
			continue
		}

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p + 1; i <= k; i++ {
		x = (x * a + b) % c

		v, r := tree.Get(x)

		if r {
			ans = ans ^ v.(*value).val
			continue
		}

		lb := tree.UpperBound(x)
		lb.Prev()
		if lb.node == nil {
			continue
		}

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res
	}

	return ans
}

func doCompute(x int) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	if j > 0 {

		for k := j; k >= 0; k-- {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.l++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

		}

	} else if i < m - 1 {

		for k := i; k < m; k++ {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.r++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}
		}
	}

	return sum
}

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

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type intInterfaceTreeMap struct {
	endNode   *nodeIntInterfaceTreeMap
	beginNode *nodeIntInterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntInterfaceTreeMap struct {
	right   *nodeIntInterfaceTreeMap
	left    *nodeIntInterfaceTreeMap
	parent  *nodeIntInterfaceTreeMap
	isBlack bool
	key     int
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntInterfaceTreeMap(less func(a int, b int) bool) *intInterfaceTreeMap {
	endNode := &nodeIntInterfaceTreeMap{isBlack: true}
	return &intInterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Set(key int, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntInterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntInterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Get(id int) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intInterfaceTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Range(from, to int) (forwardIteratorIntInterfaceTreeMap, forwardIteratorIntInterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) LowerBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) UpperBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intInterfaceTreeMap) Iterator() forwardIteratorIntInterfaceTreeMap {
	return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intInterfaceTreeMap) Reverse() reverseIteratorIntInterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntInterfaceTreeMap(node)
	}
	return reverseIteratorIntInterfaceTreeMap{tree: t, node: node}
}

func (t *intInterfaceTreeMap) findNode(id int) *nodeIntInterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.right != nil {
		return mostLeftIntInterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.left != nil {
		return mostRightIntInterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intInterfaceTreeMap) insertFixup(x *nodeIntInterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntInterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntInterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntInterfaceTreeMap(root *nodeIntInterfaceTreeMap, z *nodeIntInterfaceTreeMap) {
	var y *nodeIntInterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntInterfaceTreeMap(z)
	}
	var x *nodeIntInterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntInterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntInterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntInterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntInterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntInterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntInterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Prev() {
	i.node = predecessorIntInterfaceTreeMap(i.node)
	if i.node == nil {
		//panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntInterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntInterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }


Tokitsukaze and CSL are playing a little game of stones.In the beginning, there are $$$n$$$ piles of stones, the $$$i$$$-th pile of which has $$$a_i$$$ stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?Consider an example: $$$n=3$$$ and sizes of piles are $$$a_1=2$$$, $$$a_2=3$$$, $$$a_3=0$$$. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be $$$[1, 3, 0]$$$ and it is a good move. But if she chooses the second pile then the state will be $$$[2, 2, 0]$$$ and she immediately loses. So the only good move for her is to choose the first pile. Supposing that both players always take their best moves and never make mistakes, who will win the game?Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_1, a_2, \ldots, a_n \le 10^9$$$), which mean the $$$i$$$-th pile has $$$a_i$$$ stones.

Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.

NoteIn the first example, Tokitsukaze cannot take any stone, so CSL will win.In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.In the third example, Tokitsukaze will win. Here is one of the optimal ways:  Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.  Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.  Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose. In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	double := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			double = a[i]
			if z > 1 || a[i] == 0 {
				result = true
			}
		}
	}
	if !result {
		_, fnd := nums[double-1]
		if fnd {
			result = true
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	sum1 := num * (num - 1) / 2
	arr := make([]int, 0, num)
	for scanner.Scan() {
		e, _ := strconv.Atoi(scanner.Text())
		arr = append(arr, e)
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		sum2 += v
		if _, ok := count[v]; ok {
			count[v]++
		} else {
			count[v] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if k == 0 {
				fmt.Println("cslnb")
				return
			}
			if v2, ok := count[k-1]; ok && v2 == v-1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func doesLegalFirstMoveExist(count map[int]int) bool {
	if count[0] >= 2 {
		return false
	}
	appearsTwiceOrMore := 0
	for elem, elemCount := range count {
		if elemCount > 2 {
			return false
		}
		if elemCount >= 2 {
			appearsTwiceOrMore += 1
		}
		if elemCount >= 2 && count[elem-1] > 0 {
			return false
		}
	}
	if appearsTwiceOrMore >= 2 {
		return false
	}
	return true
}

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := doesLegalFirstMoveExist(count)
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

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

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			if z > 1 || a[i] == 0 {
				result = true
			}
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func distance(from, to, m int) int {
	if from > to {
		return m - from + to
	} else {
		return to - from
	}
}
func check(a []int, x, m int) bool {
	maxval := 0
	for _, item := range a {
		dist := distance(item, maxval, m)
		if dist <= x {
			continue
		}
		if item >= maxval {
			maxval = item
		} else {
			return false
		}
	}
	return true
}

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := true
	a := make([]int, n, n)
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = false
		}
	}
	if result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 1 {
			result = false
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			if z > 1 {
				result = true
			}
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 && z > 1 {
			result = true
			z += 1
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if k == 0 {
				fmt.Println("cslnb")
				return
			}
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 0 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
		}
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func doesLegalFirstMoveExist(count map[int]int) bool {
	if count[0] >= 2 {
		return false
	}
	for elem, _ := range count {
		if elem != 0 {
			count[elem] -= 1
			if count[elem-1] < 2 && count[elem+1] < 2 && count[elem] < 2 {
				return true
			}
			count[elem] += 1
		}
	}
	return false
}

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := doesLegalFirstMoveExist(count)
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

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

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := false
	for _, elem := range a {
		count[elem] -= 1
		if count[elem-1] < 2 && count[elem+1] < 2 {
			legalFirstMoveExists = true
		}
	}
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

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

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}


Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.

NoteIn the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5 - 2 = 3.In the second case, the optimal subset is . Note that repetition is allowed.In the last case, any subset has the same median and mean, so all have simple skewness of 0.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

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

	n := readInt()
	x := make([]int, n)
	for i := range x {
		x[i] = readInt()
	}
	sort.Ints(x)
	sum := make([]int64, n+1)
	for i := range sum[1:] {
		sum[i+1] = sum[i] + int64(x[i])
	}

	var bestNum, bestDen int64 = 0, 1
	bestMedian := 1
	bestL := 0
	for median := 1; median <= n; median++ {
		avg := func(l int) (nom, den int64) {
			return sum[n] - sum[n-l] + sum[median] - sum[median-1-l], int64(2*l + 1)
		}
		lim := n - median
		if lim > median-1 {
			lim = median - 1
		}
		l := sort.Search(lim, func(i int) bool {
			an, ad := avg(i)
			bn, bd := avg(i + 1)
			return an*bd > bn*ad
		})
		curNum, curDen := avg(l)
		curNum -= curDen * int64(x[median-1])
		if bestNum*curDen < curNum*bestDen {
			bestNum = curNum
			bestDen = curDen
			bestMedian = median
			bestL = l
		}
	}
	fmt.Println(2*bestL + 1)
	for i := 1; i <= bestL; i++ {
		fmt.Printf("%d %d ", x[bestMedian-i-1], x[n-i])
	}
	fmt.Println(x[bestMedian-1])
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

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

	n := readInt()
	x := make([]int, n)
	for i := range x {
		x[i] = readInt()
	}
	sort.Ints(x)
	sum := make([]int64, n+1)
	for i := range sum[1:] {
		sum[i+1] = sum[i] + int64(x[i])
	}

	best := 0.
	bestMedian := 1
	bestL := 0
	for median := 1; median <= n; median++ {
		avg := func(l int) float64 {
			return float64(sum[n]-sum[n-l]+sum[median]-sum[median-1-l]) / float64(2*l+1)
		}
		lim := n - median
		if lim > median-1 {
			lim = median - 1
		}
		l := sort.Search(lim, func(i int) bool {
			return avg(i) >= avg(i+1)
		})
		cur := avg(l) - float64(x[median-1])
		if best < cur {
			best = cur
			bestMedian = median
			bestL = l
		}
	}
	fmt.Println(2*bestL + 1)
	for i := 1; i <= bestL; i++ {
		fmt.Printf("%d %d ", x[bestMedian-i-1], x[n-i])
	}
	fmt.Println(x[bestMedian-1])
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

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

	n := readInt()
	x := make([]int, n)
	for i := range x {
		x[i] = readInt()
	}
	sort.Ints(x)
	sum := make([]int64, n+1)
	for i := range sum[1:] {
		sum[i+1] = sum[i] + int64(x[i])
	}

	best := 0.
	bestMedian := 1
	bestL := 0
	for median := 1; median <= n; median++ {
		avg := func(l int) float64 {
			return float64(sum[n]-sum[n-l]+sum[median]-sum[median-1-l]) / float64(2*l+1)
		}
		lim := n - median
		if lim > median-1 {
			lim = median - 1
		}
		l := sort.Search(lim, func(i int) bool {
			return avg(i) > avg(i+1)
		})
		cur := avg(l) - float64(x[median-1])
		if best < cur {
			best = cur
			bestMedian = median
			bestL = l
		}
	}
	fmt.Println(2*bestL + 1)
	for i := 1; i <= bestL; i++ {
		fmt.Printf("%d %d ", x[bestMedian-i-1], x[n-i])
	}
	fmt.Println(x[bestMedian-1])
}