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

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

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

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

package main

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

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

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

package main

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

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

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


Luca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types:   up move (denoted by $$$\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes $$$0$$$.  down move (denoted by $$$\texttt{D}$$$): it decreases the $$$i$$$-th digit by $$$1$$$. After applying the down move on $$$0$$$, it becomes $$$9$$$.     Example for $$$n=4$$$. The current sequence is 0 0 0 0. Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of wheels. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 9$$$) — the digit shown on the $$$i$$$-th wheel after all moves have been performed. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains the integer $$$b_i$$$ ($$$1 \leq b_i \leq 10$$$) and $$$b_i$$$ characters that are either $$$\texttt{U}$$$ or $$$\texttt{D}$$$ — the number of moves performed on the $$$i$$$-th wheel, and the moves performed. $$$\texttt{U}$$$ and $$$\texttt{D}$$$ represent an up move and a down move respectively.

For each test case, output $$$n$$$ space-separated digits  — the initial sequence of the cypher.

3

3

9 3 1

3 DDD

4 UDUU

2 DU

2

0 9

9 DDDDDDDDD

9 UUUUUUUUU

5

0 5 9 8 3

10 UUUUUUUUUU

3 UUD

8 UUDUUDDD

10 UUDUUDUDDU

4 UUUU

NoteIn the first test case, we can prove that initial sequence was $$$[2,1,1]$$$. In that case, the following moves were performed:   On the first wheel: $$$2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$$$.  On the second wheel: $$$1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$$$.  On the third wheel: $$$1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$$$.  The final sequence was $$$[9,3,1]$$$, which matches the input.

package main

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

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

func Read[T any]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T any](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

func solve() {
	n := Read[int]()
	arr := ReadArray[int](n)
	var s string
	for i := 0; i < n; i++ {
		k := Read[int]()
		s = Read[string]()
		for j := 0; j < k; j++ {
			if s[j] == 'U' {
				arr[i]--;
				if arr[i] == -1 {
					arr[i] = 9
				}
			} else {
				arr[i]++
				if arr[i] == 10 {
					arr[i] = 0
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}

package main

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

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

func Read[T interface{}]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T interface{}](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

func solve() {
	n := Read[int]()
	arr := ReadArray[int](n)
	var s string
	for i := 0; i < n; i++ {
		k := Read[int]()
		s = Read[string]()
		for j := 0; j < k; j++ {
			if s[j] == 'U' {
				arr[i]--;
				if arr[i] == -1 {
					arr[i] = 9
				}
			} else {
				arr[i]++
				if arr[i] == 10 {
					arr[i] = 0
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func solve() {
	n := ReadInt()
	arr := ReadIntArray(n)
	var s string
	for i := 0; i < n; i++ {
		k := ReadInt()
		s = ReadString()
		for j := 0; j < k; j++ {
			if s[j] == 'U' {
				arr[i]--;
				if arr[i] == -1 {
					arr[i] = 9
				}
			} else {
				arr[i]++
				if arr[i] == 10 {
					arr[i] = 0
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}
func main(){
	tt := ReadInt()
	for tt >= 0 {
		solve()
		tt--
	}
}

// https://codeforces.com/problemset/problem/1703/C

// 1703C - Cypher

// Luca has a cypher made up of a sequence of n wheels, each with a digit ai written on it. On the i-th wheel, he made bi moves. Each move is one of two types:
//  • up move (denoted by U): it increases the i-th digit by 1. After applying the up move on 9, it becomes 0.
//  • down move (denoted by D): it decreases the i-th digit by 1. After applying the down move on 0, it becomes 9.
// Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

// Input
// The first line contains a single integer t (1≤t≤100) — the number of test cases.
// The first line of each test case contains a single integer n (1≤n≤100) — the number of wheels.
// The second line contains n integers ai (0≤ai≤9) — the digit shown on the i-th wheel after all moves have been performed.
// Then n lines follow, the i-th of which contains the integer bi (1≤bi≤10) and bi characters that are either U or D — the number of moves performed on the i-th wheel, and the moves performed. U and D represent an up move and a down move respectively.

// Output
// For each test case, output n space-separated digits  — the initial sequence of the cypher.

// Example
// input
// 3
// 3
// 9 3 1
// 3 DDD
// 4 UDUU
// 2 DU
// 2
// 0 9
// 9 DDDDDDDDD
// 9 UUUUUUUUU
// 5
// 0 5 9 8 3
// 10 UUUUUUUUUU
// 3 UUD
// 8 UUDUUDDD
// 10 UUDUUDUDDU
// 4 UUUU
// output
// 2 1 1
// 9 0
// 0 4 9 6 9

// Note

// In the first test case, we can prove that initial sequence was [2,1,1]. In that case, the following moves were performed:
//  • On the first wheel: 2 →D 1 →D 0 →D 9.
//  • On the second wheel: 1 →U 2 →D 1 →U 2 →U 3.
//  • On the third wheel: 1 →D 0 →U 1.
// The final sequence was [9,3,1], which matches the input.

// Tutorial

// We will perform each move in reverse from the final sequence of the cypher.
//  • down move: it increases the i-th digit by 1. After applying the up move on 9, it becomes 0.
//  • up move (denoted by D): it decreases the i-th digit by 1. After applying the down move on 0, it becomes 9.
// Now we just need to implement the two types of moves. The time complexity is O(n+∑ai) per test case.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, b, i, j uint
	var a []int
	var s string

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]int, n)

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

			for i = 0; i < n; i++ {
				fmt.Fscan(reader, &b)

				if b > 0 {
					fmt.Fscan(reader, &s)

					for j = 0; j < b; j++ {
						if s[j] == 'U' {
							a[i]--
						} else if s[j] == 'D' {
							a[i]++
						}

						if a[i] < 0 {
							a[i] += 10
						}
						if a[i] > 9 {
							a[i] -= 10
						}
					}
				}
			}

			for i = 0; i+1 < n; i++ {
				fmt.Fprint(writer, a[i], " ")
			}

			fmt.Fprintln(writer, a[n-1])
		}
	}

	writer.Flush()
}

package main

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

type CF1703C struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1703C) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1703C) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1703C) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1703C) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1703C) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
TO SEND
Gopherbots Tipo A ez pendiente de modificar tiempos
Run solve the problem CF1703C
Date: 14/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1703/C
Problem: CF1703C
**/
func (in *CF1703C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		w := make([]int, n)
		for i := 0; i < n; i++ {
			w[i] = in.NextInt()
		}

		ans := make([]int, n)
		for i := 0; i < n; i++ {
			in.NextString()
			str := in.NextString()
			ans[i] = w[i]
			for j := 0; j < len(str); j++ {
				if str[j] == 'D' {
					ans[i]= (ans[i]+1)%10
				}else {
					ans[i] = ((10+ans[i])-1)%10
				}
			}
		}

		for i:=0;i<n;i++{
			fmt.Print(ans[i], " ")
		}
		fmt.Println()
	}
}

func NewCF1703C(r *bufio.Reader) *CF1703C {
	return &CF1703C{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1703C(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func readArray(n int, t *bufio.Reader) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(t, &a[i])
	}
	return a
}

func count(t *bufio.Reader) {
	var n int
	fmt.Fscan(t, &n)
	a := readArray(n, t)
	for i := 0; i < n; i++ {
		var k int
		fmt.Fscan(t, &k)
		var s string
		fmt.Fscan(t, &s)
		balance := 0
		for _, ch := range s {
			if ch == 'U' {
				balance--
			} else {
				balance++
			}
		}
		r := (a[i] + balance) % 10
		if r < 0 {
			r += 10
		}
		a[i] = r
	}
	for _, itm := range a {
		fmt.Printf("%d ", itm)
	}
	fmt.Println()
}

func main() {
	// f, _ := os.Open("input.txt")
	t := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(t, &n)
	for i := 0; i < n; i++ {
		count(t)
	}
}

package main

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

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

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	t := nextInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := nextInt()

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

	for i := 0; i < n; i++ {
		l := nextInt()
		b := next()
		for j := 0; j < l; j++ {

			if b[j] == 'U' {
				a[i]--
				a[i] += 10
				a[i] %= 10
			}
			if b[j] == 'D' {
				a[i]++
				a[i] += 10
				a[i] %= 10
			}
		}
	}
	for i := 0; i < n; i++ {
		out(a[i])
		if i == n-1 {
			out("\n")
		} else {
			out(" ")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int = make([]int,n)
		for j:=0;j<n;j++{
			fmt.Scan(&list[j])
		}
		for k:=0;k<n;k++{
			var x int
			var moves string
			fmt.Scan(&x,&moves)
			counter:=0
			for j:=0;j<x;j++{
				if string(moves[j]) == "D" {
					counter++
				} else {
					counter--
				}
			}
			if list[k]+counter > 9 {
				fmt.Printf("%v ",list[k]+counter-10)
			} else if list[k]+counter < 0 {
				fmt.Printf("%v ",list[k]+counter+10)
			} else {
				fmt.Printf("%v ",list[k]+counter)
			}
			fmt.Println()
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		moves := make([]string, n)
		for i := 0; i < n; i++ {
			s := readString(reader)
			if s[1] == ' ' {
				moves[i] = s[2:]
			} else {
				moves[i] = s[3:]
			}
		}
		res := solve(n, A, moves)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int, moves []string) []int {
	for i := 0; i < n; i++ {
		var cnt int
		for j := 0; j < len(moves[i]); j++ {
			if moves[i][j] == 'U' {
				cnt--
			} else {
				cnt++
			}
		}
		cnt = (cnt%10 + 10) % 10
		A[i] = (A[i] + cnt) % 10
	}

	return A
}

package main

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

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

	var t int

	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		var n, c int
		var s string
		fmt.Fscan(in, &n)
		var a [100]int

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

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &c)
			fmt.Fscan(in, &s)
			for k := 0; k < c; k++ {
				if s[k] == 'U' {
					a[j]--
				} else {
					a[j]++
				}
			}
		}

		for j := 0; j < n; j++ {
			fmt.Fprintf(out, "%d ", (a[j]+10)%10)
		}
		fmt.Fprintln(out, "")
	}

}

package main

import (
	"fmt"
)

func main() {
	var T, n, m int
	fmt.Scan(&T)
	for T>0 {
		fmt.Scan(&n)
		d:=make([]int,n,n)
		for i:=0;i<n;i++{
			fmt.Scan(&d[i])
		}
		var s string
		for i:=0;i<n;i++{
			fmt.Scan(&m,&s)
			for j:=0;j<m;j++{
				if s[j]=='U'{
					d[i]=(d[i]+9)%10
				} else {
					d[i]=(d[i]+1)%10
				}
			}
			fmt.Print(d[i]," ")
		}
		fmt.Println()
		T--
	}

}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, x int
	a       []int
	b       []string
)

func solve(n int, a []int, b []string) string {
	var result = make([]int, n)
	for i := 0; i < n; i++ {
		var moved int
		for _, c := range b[i] {
			if c == 'D' {
				moved++
			} else {
				moved--
			}
		}
		result[i] = (a[i] + moved) % 10
		if result[i] < 0 {
			result[i] += 10
		}
	}
	return strings.Trim(fmt.Sprint(result), "[]")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a = make([]int, n)
		b = make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &x, &b[i])
		}
		fmt.Println(solve(n, a, b))
	}
}

package main
import "fmt"

func main() {
    var T int
    fmt.Scan(&T)
    for tt := 0; tt < T; tt++ {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)
        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
        }
        for i := 0; i < n; i++ {
            var l int
            var s string
            fmt.Scan(&l)
            fmt.Scan(&s)
            for j := 0; j < l; j++ {
                if s[j] == 'U' {
                    a[i] = (a[i] + 9) % 10
                } else {
                    a[i] = (a[i] + 1) % 10
                }
            }
        }
        for i := 0; i < n; i++ {
            fmt.Printf("%d ", a[i])
        }
        fmt.Println()
    }
}

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	for i := 0; i < n; i++ {
		var l int
		fmt.Fscan(in, &l)
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < l; j++ {
			arr[i] += 10
			if s[j] != 'U' {
				arr[i]++
			} else {
				arr[i]--
			}
			arr[i] %= 10
		}
	}
	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", arr[i])
	}
	fmt.Fprintln(out)
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func main(){
	defer out.Flush()
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		A := ReadIntArray(N)
		for i := 0; i < N; i++{
			l := ReadInt()
			s := ReadString()
			add := 0
			for j := 0; j < l; j++{
				if s[j] == 'U'{
					add++
				} else{
					add--
				}
			}
			fmt.Fprintf(out, "%d ", (A[i] - add + 10) % 10)
		}
		fmt.Fprintln(out)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	for i:=0;i<n;i++ {
		var m int
		fmt.Fscan(rr, &m)
		var s string
		fmt.Fscan(rr, &s)
		for j := range s {
			if s[j] == 'D' {
				nums[i]++
			} else {
				nums[i]--
			}
		}
		nums[i] += 1000
		nums[i] %= 10
	}
	for i := range nums {
		fmt.Fprintf(ww, "%d ", nums[i])
	}
	fmt.Fprintln(ww)
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod = 10

	var T, n, m int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for _, v := range a {
			Fscan(in, &m, &s)
			v += strings.Count(s, "D")*2 - m
			v = (v%mod + mod) % mod
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

func main() {
	var (
		t      int
		n      int
		ai     []int
		wheel  []int
		swheel []string
		temp   int
		temps  string
	)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &t)

	for i := 0; i < t; i++ {
		// taking input line 1
		fmt.Fscanf(reader, "%d\n", &n)
		ai = make([]int, n)
		wheel = make([]int, n)
		swheel = make([]string, n)

		// input line 2
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &temp)
			ai[j] = temp
		}
		fmt.Fscanf(reader, "\n")

		// input n lines
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d ", &temp)
			fmt.Fscanf(reader, "%s\n", &temps)
			wheel[j] = temp
			swheel[j] = temps
		}

		// fmt.Println("ai", ai)
		// fmt.Println( "wheel" , wheel)
		// fmt.Println("swheel", swheel)

		// solving que line by line
		for j := 0; j < n; j++ {
			sarr := strings.Split(swheel[j], "")
			for k := 0; k < wheel[j]; k++ {
				if sarr[k] == "U" {
					ai[j]--
					if ai[j] == -1 {
						ai[j] = 9
					}
				} else {
					ai[j]++
					if ai[j] == 10 {
						ai[j] = 0
					}
				}
			}
		}

		// fmt.Println(ai)
		printArray(ai)
	}
}

func printArray(arr []int) {
	for i := range arr {
		fmt.Printf("%d ",arr[i])
	}
	fmt.Println()
}

package main

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

func unlock(combinations []int, moves []string) []int {
	for i := 0; i < len(combinations); i++ {
		for j := 0; j < len(moves[i]); j++ {
			move := moves[i][j]
			if move == 'D' {
				combinations[i]++
				if combinations[i] > 9 {
					combinations[i] = 0
				}
			} else {
				combinations[i]--
				if combinations[i] < 0 {
					combinations[i] = 9
				}
			}
		}
	}
	return combinations
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 16*1024*1024)
	T, err := strconv.Atoi(strings.TrimSpace(readLine(reader)))
	checkError(err)
	var results = make([][]int, T)
	for i := 0; i < T; i++ {
		N, err := strconv.Atoi(strings.TrimSpace(readLine(reader)))
		checkError(err)
		tmpComb := strings.Split(strings.TrimSpace(readLine(reader)), " ")
		combinations := make([]int, N)
		for i := 0; i < N; i++ {
			item, err := strconv.Atoi(tmpComb[i])
			checkError(err)
			combinations[i] = item
		}
		moves := make([]string, N)
		for i := 0; i < N; i++ {
			tmp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
			moves[i] = tmp[1]
		}
		results[i] = unlock(combinations, moves)
	}
	for _, result := range results {
		for _, r := range result {
			fmt.Print(r, " ")
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err != nil {
		return ""
	}
	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

//package main
//
//import (
//	"context"
//	"gerRpc"
//	"gerRpc/xclient"
//	"log"
//	"sync"
//
//	"net"
//	"time"
//)
//
////
////func startServer(addr chan string)  {
////	l, err := net.Listen("tcp", ":0")
////	if err != nil{
////		log.Fatal("network error:", err)
////	}
////	log.Println("start rpc server on:", l.Addr())
////	addr <- l.Addr().String()
////	gerRpc.Accept(l)
////}
////
////func main()  {
////
////	//addr := make(chan string)
////	//go startServer(addr)
////	//client, _ := gerRpc.Dial("tcp", <-addr)
////	//defer func() {_ = client.Close()}()
////
////	//time.Sleep(time.Second)
////	//var wg sync.WaitGroup
////	//for i := 0; i < 5; i ++{
////	//	wg.Add(1)
////	//	go func(i int) {
////	//		defer wg.Done()
////	//		args := fmt.Sprintf("geerpc req %d", i)
////	//		var reply string
////	//		if err := client.Call("Foo.sum", args, &reply); err != nil{
////	//			log.Fatal("call Foo.Sum error:", err)
////	//		}
////	//		log.Println("reply")
////	//	}(i)
////	//}
////	//wg.Wait()
////}
//
////
////func main() {
////	addr := make(chan string)
////	go startServer(addr)
////
////	// in fact, following code is like a simple geerpc client
////	conn, _ := net.Dial("tcp", <-addr)
////	defer func() { _ = conn.Close() }()
////
////	time.Sleep(time.Second)
////	// send options
////	_ = json.NewEncoder(conn).Encode(gerRpc.DefaultOption)
////	cc := codec.NewGobCodec(conn)
////	// send request & receive response
////	for i := 0; i < 5; i++ {
////		h := &codec.Header{
////			ServiceMethod: "Foo.Sum",
////			Seq:           uint64(i),
////		}
////		_ = cc.Write(h, fmt.Sprintf("geerpc req %d", h.Seq))
////		_ = cc.ReadHeader(h)
////		var reply string
////		_ = cc.ReadBody(&reply)
////		log.Println("reply:", reply)
////	}
////}
////
////
////type Foo int
////
////type Args struct {
////	Num1, Num2 int
////}
////
////func (f Foo)Sum(args Args, reply *int)error  {
////	*reply = args.Num1 + args.Num2
////	return nil
////}
////func startServer(addr chan string) {
////	var foo Foo
////	if err := gerRpc.Register(&foo); err != nil {
////		log.Fatal("register error:", err)
////	}
////	// pick a free port
////	l, err := net.Listen("tcp", ":0")
////	if err != nil {
////		log.Fatal("network error:", err)
////	}
////	log.Println("start rpc server on", l.Addr())
////	addr <- l.Addr().String()
////	gerRpc.Accept(l)
////}
////
////func main()  {
////	log.SetFlags(0)
////	addr := make(chan string)
////	go startServer(addr)
////	client, _ := gerRpc.Dial("tcp", <-addr)
////	defer func() {_ = client.Close()}()
////
////	time.Sleep(time.Second)
////	var wg sync.WaitGroup
////	for i := 0; i < 5; i ++{
////		wg.Add(1)
////		go func(i int) {
////			defer wg.Done()
////			args := &Args{
////				Num1: i,
////				Num2: i * i,
////			}
////			ctx, _ := context.WithTimeout(context.Background(), time.Second)
////			var reply int
////			if err := client.Call(ctx,"Foo.Sum", args, &reply); err != nil{
////				log.Fatal("call Foo.Sum error:", err)
////			}
////			log.Printf("%d + %d = %d", args.Num1, args.Num2, reply)
////		}(i)
////	}
////	wg.Wait()
////}
//type Foo int
//
//type Args struct{ Num1, Num2 int }
//
//func (f Foo) Sum(args Args, reply *int) error {
//	*reply = args.Num1 + args.Num2
//	return nil
//}
//
//func (f Foo) Sleep(args Args, reply *int) error {
//	time.Sleep(time.Second * time.Duration(args.Num1))
//	*reply = args.Num1 + args.Num2
//	return nil
//}
//
//func startServer(addrCh chan string) {
//	var foo Foo
//	l, _ := net.Listen("tcp", ":0")
//	server := gerRpc.NewServer()
//	_ = server.Register(&foo)
//	addrCh <- l.Addr().String()
//	server.Accept(l)
//}
//
//func foo(xc *xclient.Xclient, ctx context.Context, typ, serviceMethod string, args *Args)  {
//	var reply int
//	var err error
//	switch typ {
//	case "call":
//		err = xc.Call(ctx, serviceMethod, args, &reply)
//	case "broadcast":
//		err = xc.Broadcast(ctx, serviceMethod, args, &reply)
//	}
//	if err != nil{
//		log.Printf("%s %s error: %v", typ, serviceMethod, err)
//	}else{
//		log.Printf("%s %s success: %d + %d = %d", typ, serviceMethod, args.Num1, args.Num2, reply)
//	}
//}
//
//func call(addr1, addr2 string)  {
//	d := xclient.NewMultiServerDiscovery([]string{"tcp@"+addr1, "tcp@"+addr2})
//	xc := xclient.NewXClient(d, xclient.RandomSelect, nil)
//	defer func() {_ = xc.Close()}()
//
//	var wg sync.WaitGroup
//	for i := 0; i < 5; i ++{
//		wg.Add(1)
//		go func(i int) {
//			defer wg.Done()
//			foo(xc, context.Background(), "call", "Foo.Sum", &Args{
//				Num1: i,
//				Num2: i * i,
//			})
//		}(i)
//	}
//	wg.Wait()
//}
//
//func broadcast(addr1, addr2 string) {
//	d := xclient.NewMultiServerDiscovery([]string{"tcp@" + addr1, "tcp@" + addr2})
//	xc := xclient.NewXClient(d, xclient.RandomSelect, nil)
//	defer func() { _ = xc.Close() }()
//	var wg sync.WaitGroup
//	for i := 0; i < 5; i++ {
//		wg.Add(1)
//		go func(i int) {
//			defer wg.Done()
//			foo(xc, context.Background(), "broadcast", "Foo.Sum", &Args{Num1: i, Num2: i * i})
//			// expect 2 - 5 timeout
//			ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
//			foo(xc, ctx, "broadcast", "Foo.Sleep", &Args{Num1: i, Num2: i * i})
//		}(i)
//	}
//	wg.Wait()
//}
//
//
//func main() {
//	log.SetFlags(0)
//	ch1 := make(chan string)
//	ch2 := make(chan string)
//	// start two servers
//	go startServer(ch1)
//	go startServer(ch2)
//
//	addr1 := <-ch1
//	addr2 := <-ch2
//
//	time.Sleep(time.Second)
//	call(addr1, addr2)
//	broadcast(addr1, addr2)
//}
//
//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"strings"
//)
//
//var in = bufio.NewReader(os.Stdin)
//
//func main()  {
//	var T int
//	fmt.Fscan(in, &T)
//	for ;T > 0; T--{
//		var str string
//		fmt.Fscan(in, &str)
//
//		if strings.EqualFold(strings.ToLower(str), "yes"){
//			fmt.Println("YES")
//		}else{
//			fmt.Println("NO")
//		}
//	}
//}

//
//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//)
//
//var in = bufio.NewReader(os.Stdin)
//
//func main()  {
//	var T int
//	fmt.Fscan(in, &T)
//	for ;T > 0; T--{
//		var n int
//		fmt.Fscan(in, &n)
//		var str string
//		fmt.Fscan(in, &str)
//		mp := make(map[byte]bool)
//		cnt := 0
//		for i := 0; i < n; i ++{
//			if !mp[str[i]] {
//				cnt += 2
//				mp[str[i]] = true
//			}else{
//				cnt ++
//			}
//		}
//		fmt.Println(cnt)
//	}
//}

package main

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

var in = bufio.NewReader(os.Stdin)

func main()  {
	var T int
	fmt.Fscan(in, &T)
	for ;T > 0; T--{
		var n int
		fmt.Fscan(in, &n)
		num := make([]int, n)
		for i := 0; i < n; i ++{
			fmt.Fscan(in, &num[i])
		}
		for i := 0; i < n; i ++{
			var k int
			var str string
			fmt.Fscan(in, &k, &str)
			for j := 0; j < k; j ++{
				if str[j] == 'U'{
					num[i] = ((num[i] - 1) % 10 + 10) % 10
				}else{
					num[i] = ((num[i] + 1) % 10 + 10) % 10
				}
			}
		}
		for _, v := range num{
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main

import . "fmt"

func main() {
	var (
		b, n, t int
		a       []int
		s, c    string
	)
	Scan(&t)
	for i := 0; i < t; i++ {
		Scan(&n)
		a = make([]int, n)
		for j := 0; j < n; j++ {
			Scan(&a[j])
		}
		for j := 0; j < n; j++ {
			Scan(&b)
			Scan(&s)
			for k := 0; k < b; k++ {
				c = string(s[k])
				if c == "U" {
					if a[j] == 0 {
						a[j] = 9
					} else {
						a[j]--
					}
				} else {
					if a[j] == 9 {
						a[j] = 0
					} else {
						a[j]++
					}
				}
			}
			Printf("%d ", a[j])
		}
		Printf("\n")
	}
}

// 1703C. Cypher
package main

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

func get_val(s string) int {
	ans := 0
	for i := 0; i < len(s); i++ {
		if s[i] == 'U' {
			ans--
		} else {
			ans++
		}
	}
	return ans
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		f := []interface{}{}
		for i := 0; i < n; i++ {
			var b int
			var s string
			fmt.Fscan(reader, &b, &s)
			f = append(f, (10+a[i]+get_val(s))%10)
		}
		fmt.Println(f...)

	}
}

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([]string, n)
		var c int
		for i := range b {
			fmt.Fscan(r, &c, &b[i])
		}
		w1 := do(a, b)
		for i := range a {
			fmt.Fprint(w, w1[i])
			fmt.Fprint(w, " ")
		}
		fmt.Fprintln(w)
	}
}

func do(a []int, b []string) []int {
	for i, s := range b {
		for j := len(s) - 1; j >= 0; j-- {
			if s[j] == 'U' {
				a[i]--
			} else {
				a[i]++
			}
			if a[i] < 0 {
				a[i] = 9
			}
			if a[i] > 9 {
				a[i] = 0
			}
		}
	}
	return a
}

package main

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

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

	var T int
	for fmt.Fscan(in, &T); T > 0; T-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0;i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		for i := 0;i < n; i++ {
			var len int
			var s string
			fmt.Fscan(in, &len, &s)
			cnt := 0
			for j := 0;j < len; j++ {
				if s[j] == 'U' {
					cnt--
				} else {
					cnt++
				}
			}
			a[i] = ((a[i] + cnt) % 10 + 10) % 10
		}
		for i := 0;i < n; i++ {
			fmt.Fprintf(out, "%d ", a[i])
		}
		fmt.Fprintln(out)
	}
}

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

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		aa := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		for i := 0; i < n; i++ {
			var b int
			var s string
			fmt.Fscan(in, &b, &s)

			for _, ch := range s {
				if ch == 'D' {
					aa[i]++
				} else {
					aa[i]--
					if aa[i] < 0 {
						aa[i] = 9
					}
				}
				aa[i] %= 10
			}
		}

		for _, v := range aa {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

// https://codeforces.com/problemset/problem/1703/C

// 1703C - Cypher

// Luca has a cypher made up of a sequence of n wheels, each with a digit ai written on it. On the i-th wheel, he made bi moves. Each move is one of two types:
//  • up move (denoted by U): it increases the i-th digit by 1. After applying the up move on 9, it becomes 0.
//  • down move (denoted by D): it decreases the i-th digit by 1. After applying the down move on 0, it becomes 9.
// Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

// Input
// The first line contains a single integer t (1≤t≤100) — the number of test cases.
// The first line of each test case contains a single integer n (1≤n≤100) — the number of wheels.
// The second line contains n integers ai (0≤ai≤9) — the digit shown on the i-th wheel after all moves have been performed.
// Then n lines follow, the i-th of which contains the integer bi (1≤bi≤10) and bi characters that are either U or D — the number of moves performed on the i-th wheel, and the moves performed. U and D represent an up move and a down move respectively.

// Output
// For each test case, output n space-separated digits  — the initial sequence of the cypher.

// Example
// input
// 3
// 3
// 9 3 1
// 3 DDD
// 4 UDUU
// 2 DU
// 2
// 0 9
// 9 DDDDDDDDD
// 9 UUUUUUUUU
// 5
// 0 5 9 8 3
// 10 UUUUUUUUUU
// 3 UUD
// 8 UUDUUDDD
// 10 UUDUUDUDDU
// 4 UUUU
// output
// 2 1 1
// 9 0
// 0 4 9 6 9

// Note

// In the first test case, we can prove that initial sequence was [2,1,1]. In that case, the following moves were performed:
//  • On the first wheel: 2 →D 1 →D 0 →D 9.
//  • On the second wheel: 1 →U 2 →D 1 →U 2 →U 3.
//  • On the third wheel: 1 →D 0 →U 1.
// The final sequence was [9,3,1], which matches the input.

// Tutorial

// We will perform each move in reverse from the final sequence of the cypher.
//  • down move: it increases the i-th digit by 1. After applying the up move on 9, it becomes 0.
//  • up move (denoted by D): it decreases the i-th digit by 1. After applying the down move on 0, it becomes 9.
// Now we just need to implement the two types of moves. The time complexity is O(n+∑ai) per test case.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, b, i, j uint
	var a []int
	var s string

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]int, n)

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

			for i = 0; i < n; i++ {
				fmt.Fscan(reader, &b)

				if b > 0 {
					fmt.Fscan(reader, &s)

					for j = 0; j < b; j++ {
						if s[j] == 'U' {
							a[i]--
						} else if s[j] == 'D' {
							a[i]++
						}

						if a[i] < 0 {
							a[i] += 10
						}
						if a[i] > 10 {
							a[i] -= 10
						}
					}
				}
			}

			for i = 0; i+1 < n; i++ {
				fmt.Fprint(writer, a[i], " ")
			}

			fmt.Fprintln(writer, a[n-1])
		}
	}

	writer.Flush()
}

package main

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

func readArray(n int, t *bufio.Reader) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(t, &a[i])
	}
	return a
}

func count(t *bufio.Reader) {
	var n int
	fmt.Fscan(t, &n)
	a := readArray(n, t)
	for i := 0; i < n; i++ {
		var k int
		fmt.Fscan(t, &k)
		var s string
		fmt.Fscan(t, &s)
		balance := 0
		for _, ch := range s {
			if ch == 'U' {
				balance--
			} else {
				balance++
			}
		}
		r := (a[i] + balance) % 10
		if r < 0 {
			r += 10
		}
		a[i] = r
	}
	for _, itm := range a {
		fmt.Printf("%d ", itm)
	}
	fmt.Println()
}

func main() {
	f, _ := os.Open("input.txt")
	t := bufio.NewReader(f) //os.Stdin)
	var n int
	fmt.Fscan(t, &n)
	for i := 0; i < n; i++ {
		count(t)
	}
}


Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ dPikachu was finally left with X subsequences. However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018. Note the number of elements in the output array should not be more than 104. If no answer is possible, print  - 1.

The only line of input consists of two space separated integers X and d (1 ≤ X, d ≤ 109).

Output should consist of two lines. First line should contain a single integer n (1 ≤ n ≤ 10 000)— the number of integers in the final array. Second line should consist of n space separated integers — a1, a2, ... , an (1 ≤ ai < 1018). If there is no answer, print a single integer -1. If there are multiple answers, print any of them.

NoteIn the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence  -  Minimum_element_of_subsequence  ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.


Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r and ak = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, ai) > f(j, n, aj).Help Pashmak with the test.

The first line of the input contains an integer n (1 ≤ n ≤ 106). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print a single integer — the answer to the problem.

package main

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

func handleInput() (int, []int, []int) {
	n := nextInt()
	a := make([]int, n)

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

	r, maxsize := make([]int, n), 0
	for j, counter := n-1, make(map[int]int, n); j >= 0; j-- {
		r[j] = counter[a[j]] + 1
		counter[a[j]] = r[j]
		if maxsize < r[j] {
			maxsize = r[j]
		}
	}
	return maxsize, l, r
}

type fenwick []int

func (this fenwick) get(idx int) int {
	sum := 0
	for idx > 0 {
		sum, idx = sum+this[idx], idx-(-idx&idx)
	}
	return sum
}

func (this fenwick) add(idx int, val int) {
	for idx < len(this) {
		this[idx], idx = this[idx]+val, idx+(-idx&idx)
	}
}

func solveBIT(maxsize int, l []int, r []int) int64 {
	fen := make(fenwick, maxsize+1)
	var count int64
	for i := len(l) - 1; i >= 0; i-- {
		count += int64(fen.get(l[i] - 1))
		fen.add(r[i], 1)
	}
	return count
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	solve := solveBIT
	printn(solve(handleInput()))
}

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}

package main

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

func handleInput() (int, []int, []int) {
	n := nextInt()
	a := make([]int, n)

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

	r, maxsize := make([]int, n), 0
	for j, counter := n-1, make(map[int]int, n); j >= 0; j-- {
		r[j] = counter[a[j]] + 1
		counter[a[j]] = r[j]
		if maxsize < r[j] {
			maxsize = r[j]
		}
	}
	return maxsize, l, r
}

type fenwick []int

func (this fenwick) get(idx int) int {
	sum := 0
	for idx > 0 {
		sum, idx = sum+this[idx], idx-(-idx&idx)
	}
	return sum
}

func (this fenwick) add(idx int, val int) {
	for idx < len(this) {
		this[idx], idx = this[idx]+val, idx+(-idx&idx)
	}
}

func solveBIT(maxsize int, l []int, r []int) int64 {
	fen := make(fenwick, maxsize+1)
	var count int64
	for i := len(l) - 1; i >= 0; i-- {
		count += int64(fen.get(l[i] - 1))
		fen.add(r[i], 1)
	}
	return count
}

func solveDaC0(maxsize int, l []int, r []int) int64 {
	// DaC with global merge buf
	buf := make([]int, len(l))
	merge := func(s, mid, e int, a []int) {
		cur, i, j := s, s, mid
		for i < mid && j < e {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < e {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		copy(a[s:e], buf[s:e])
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		merge(s, mid, e, l)
		merge(s, mid, e, r)

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaC1(maxsize int, l []int, r []int) int64 {
	// In this solution, Merge buf will be allocated for each merge
	// operation which is definitly wasteful
	merge := func(a []int, mid int) []int {
		buf := make([]int, len(a))
		cur, i, j := 0, 0, mid
		for i < mid && j < len(buf) {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < len(buf) {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		return buf
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		copy(l[s:], merge(l[s:e], mid-s))
		copy(r[s:], merge(r[s:e], mid-s))

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaCNaive(maxsize int, l []int, r []int) int64 {
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		p1, p2 := solvePartial(s, mid), solvePartial(mid, e)

		pl, pr := make([]int, mid-s), make([]int, e-mid)
		copy(pl, l[s:])
		copy(pr, r[mid:])
		sort.Sort(sort.IntSlice(pl))
		sort.Sort(sort.IntSlice(pr))

		var count int64
		for i, j := 0, 0; i < len(pl); i++ {
			for j < len(pr) && pl[i] > pr[j] {
				j++
			}
			count += int64(j)
		}
		return p1 + p2 + count
	}
	return solvePartial(0, len(l))
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	solve := solveDaC1
	printn(solve(handleInput()))
}

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}

package main

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

func handleInput() (int, []int, []int) {
	n := nextInt()
	a := make([]int, n)

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

	r, maxsize := make([]int, n), 0
	for j, counter := n-1, make(map[int]int, n); j >= 0; j-- {
		r[j] = counter[a[j]] + 1
		counter[a[j]] = r[j]
		if maxsize < r[j] {
			maxsize = r[j]
		}
	}
	return maxsize, l, r
}

type fenwick []int

func (this fenwick) get(idx int) int {
	sum := 0
	for idx > 0 {
		sum, idx = sum+this[idx], idx-(-idx&idx)
	}
	return sum
}

func (this fenwick) add(idx int, val int) {
	for idx < len(this) {
		this[idx], idx = this[idx]+val, idx+(-idx&idx)
	}
}

func solveBIT(maxsize int, l []int, r []int) int64 {
	fen := make(fenwick, maxsize+1)
	var count int64
	for i := len(l) - 1; i >= 0; i-- {
		count += int64(fen.get(l[i] - 1))
		fen.add(r[i], 1)
	}
	return count
}

func solveDaC(maxsize int, l []int, r []int) int64 {
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		p1, p2 := solvePartial(s, mid), solvePartial(mid, e)

		pl, pr := make([]int, mid-s), make([]int, e-mid)
		copy(pl, l[s:])
		copy(pr, r[mid:])
		sort.Sort(sort.IntSlice(pl))
		sort.Sort(sort.IntSlice(pr))

		var count int64
		for i, j := 0, 0; i < len(pl); i++ {
			for j < len(pr) && pl[i] > pr[j] {
				j++
			}
			count += int64(j)
		}
		return p1 + p2 + count
	}
	return solvePartial(0, len(l))
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	solve := solveDaC
	printn(solve(handleInput()))
}

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}

package main

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

func handleInput() (int, []int, []int) {
	n := nextInt()
	a := make([]int, n)
	counter := make(map[int]int, n)

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

	r, maxsize := make([]int, n), 0
	for i := 0; i < n; i++ {
		r[i] = counter[a[i]]
		counter[a[i]] = r[i] - 1
		if maxsize < r[i] {
			maxsize = r[i]
		}
	}

	return maxsize, l, r
}

type fenwick []int

func (this fenwick) get(idx int) int {
	sum := 0
	for idx > 0 {
		sum, idx = sum+this[idx], idx-(-idx&idx)
	}
	return sum
}

func (this fenwick) add(idx int, val int) {
	for idx < len(this) {
		this[idx], idx = this[idx]+val, idx+(-idx&idx)
	}
}

func solveBIT(maxsize int, l []int, r []int) int64 {
	fen := make(fenwick, maxsize+1)
	var count int64
	for i := len(l) - 1; i >= 0; i-- {
		count += int64(fen.get(l[i] - 1))
		fen.add(r[i], 1)
	}
	return count
}

func solveDaC0(maxsize int, l []int, r []int) int64 {
	// DaC with global merge buf
	buf := make([]int, len(l))
	merge := func(s, mid, e int, a []int) {
		cur, i, j := s, s, mid
		for i < mid && j < e {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < e {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		copy(a[s:e], buf[s:e])
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		merge(s, mid, e, l)
		merge(s, mid, e, r)

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaC1(maxsize int, l []int, r []int) int64 {
	// In this solution, Merge buf will be allocated for each merge
	// operation which is definitly wasteful
	merge := func(a []int, mid int) []int {
		buf := make([]int, len(a))
		cur, i, j := 0, 0, mid
		for i < mid && j < len(buf) {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < len(buf) {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		return buf
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		copy(l[s:], merge(l[s:e], mid-s))
		copy(r[s:], merge(r[s:e], mid-s))

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaCNaive(maxsize int, l []int, r []int) int64 {
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		p1, p2 := solvePartial(s, mid), solvePartial(mid, e)

		pl, pr := make([]int, mid-s), make([]int, e-mid)
		copy(pl, l[s:])
		copy(pr, r[mid:])
		sort.Sort(sort.IntSlice(pl))
		sort.Sort(sort.IntSlice(pr))

		var count int64
		for i, j := 0, 0; i < len(pl); i++ {
			for j < len(pr) && pl[i] > pr[j] {
				j++
			}
			count += int64(j)
		}
		return p1 + p2 + count
	}
	return solvePartial(0, len(l))
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	solve := solveBIT
	printn(solve(handleInput()))
}

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}

package main

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

func handleInput() (int, []int, []int) {
	n := nextInt()
	a := make([]int, n)

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

	r, maxsize := make([]int, n), 0
	for j, counter := n-1, make(map[int]int, n); j >= 0; j-- {
		r[j] = counter[a[j]] + 1
		counter[a[j]] = r[j]
		if maxsize < r[j] {
			maxsize = r[j]
		}
	}
	return maxsize, l, r
}

type fenwick []int

func (this fenwick) get(idx int) int {
	sum := 0
	for idx > 0 {
		sum, idx = sum+this[idx], idx-(-idx&idx)
	}
	return sum
}

func (this fenwick) add(idx int, val int) {
	for idx < len(this) {
		this[idx], idx = this[idx]+val, idx+(-idx&idx)
	}
}

func solveBIT(maxsize int, l []int, r []int) int64 {
	fen := make(fenwick, maxsize+1)
	var count int64
	for i := len(l) - 1; i >= 0; i-- {
		count += int64(fen.get(l[i] - 1))
		fen.add(r[i], 1)
	}
	return count
}

func solveDaC0(maxsize int, l []int, r []int) int64 {
	// DaC with global merge buf
	buf := make([]int, len(l))
	merge := func(s, mid, e int, a []int) {
		cur, i, j := s, s, mid
		for i < mid && j < e {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < e {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		copy(a[s:e], buf[s:e])
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		merge(s, mid, e, l)
		merge(s, mid, e, r)

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaC1(maxsize int, l []int, r []int) int64 {
	// In this solution, Merge buf will be allocated for each merge
	// operation which is definitly wasteful
	merge := func(a []int, mid int) []int {
		buf := make([]int, len(a))
		cur, i, j := 0, 0, mid
		for i < mid && j < len(buf) {
			if a[i] < a[j] {
				buf[cur], cur, i = a[i], cur+1, i+1
			} else {
				buf[cur], cur, j = a[j], cur+1, j+1
			}
		}
		for i < mid {
			buf[cur], cur, i = a[i], cur+1, i+1
		}
		for j < len(buf) {
			buf[cur], cur, j = a[j], cur+1, j+1
		}
		return buf
	}
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		count := solvePartial(s, mid) + solvePartial(mid, e)

		for i, j := s, mid; i < mid; i++ {
			for j < e && l[i] > r[j] {
				j++
			}
			count += int64(j - mid)
		}

		copy(l[s:], merge(l[s:e], mid-s))
		copy(r[s:], merge(r[s:e], mid-s))

		return count
	}
	return solvePartial(0, len(l))
}

func solveDaCNaive(maxsize int, l []int, r []int) int64 {
	var solvePartial func(int, int) int64
	solvePartial = func(s, e int) int64 {
		if e-s < 2 {
			return 0
		}
		mid := (s + e) / 2
		p1, p2 := solvePartial(s, mid), solvePartial(mid, e)

		pl, pr := make([]int, mid-s), make([]int, e-mid)
		copy(pl, l[s:])
		copy(pr, r[mid:])
		sort.Sort(sort.IntSlice(pl))
		sort.Sort(sort.IntSlice(pr))

		var count int64
		for i, j := 0, 0; i < len(pl); i++ {
			for j < len(pr) && pl[i] > pr[j] {
				j++
			}
			count += int64(j)
		}
		return p1 + p2 + count
	}
	return solvePartial(0, len(l))
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	solve := solveDaC0
	printn(solve(handleInput()))
}

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}