Dreamoon likes coloring cells very much.There is a row of $$$n$$$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $$$1$$$ to $$$n$$$.You are given an integer $$$m$$$ and $$$m$$$ integers $$$l_1, l_2, \ldots, l_m$$$ ($$$1 \le l_i \le n$$$)Dreamoon will perform $$$m$$$ operations.In $$$i$$$-th operation, Dreamoon will choose a number $$$p_i$$$ from range $$$[1, n-l_i+1]$$$ (inclusive) and will paint all cells from $$$p_i$$$ to $$$p_i+l_i-1$$$ (inclusive) in $$$i$$$-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation.Dreamoon hopes that after these $$$m$$$ operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose $$$p_i$$$ in each operation to satisfy all constraints.

The first line contains two integers $$$n,m$$$ ($$$1 \leq m \leq n \leq 100\,000$$$). The second line contains $$$m$$$ integers $$$l_1, l_2, \ldots, l_m$$$ ($$$1 \leq l_i \leq n$$$).

If it's impossible to perform $$$m$$$ operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print $$$m$$$ integers $$$p_1, p_2, \ldots, p_m$$$ ($$$1 \leq p_i \leq n - l_i + 1$$$), after these $$$m$$$ operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any.

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n, m := NextInt(), NextInt()
	l := make([]int, m)
	p := make([]int, m)
	for i := 0; i < m; i++ {
		l[i] = NextInt()
		if i+l[i] > n {
			fmt.Fprintln(out, -1)
			return
		}
	}
	mr := make([]int, m)
	for i := m - 1; i >= 0; i-- {
		if i == m-1 {
			mr[i] = i + l[i]
		} else {
			mr[i] = max(mr[i+1], i+l[i])
		}
	}

	var r int
	for i, lp := 0, 0; i < m; i++ {
		maxAdd := n - mr[i] - (lp - i)
		if maxAdd < 0 {
			panic("maxAdd < 0")
		}
		k := min(maxAdd, r-lp)
		p[i] = lp + k
		lp += k
		r = max(p[i]+l[i], r)
	}

	if r != n {
		fmt.Fprintln(out, -1)
		return
	}

	for i := 0; i < m; i++ {
		fmt.Fprint(out, p[i]+1, " ")
	}
	fmt.Fprintln(out)
}

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	var sum int64 = 0
	res := []int{}
	for _, x := range arr {
		sum += int64(x)
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < int64(rest) {
			printf("-1")
			return
		}
		if sum-int64(arr[curi]) <= int64(rest) {
			pad := rest - int((sum - int64(arr[curi])))
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				pos := lmax + pad
				curi++
				for curi < p {
					res = append(res, pos)
					pos += arr[curi]
					curi++
				}
				for i := range res {
					if i != 0 {
						printf(" ")
					}
					printf("%d", res[i])
				}
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= int64(arr[curi])
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

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

const SIZE int64 = 100002

var(
	lenner [SIZE]int64
	suffix_sum [SIZE]int64
)

func solve() {
	N, M := scanInt64(), scanInt64()
	for i := int64(1) ; i <= M; i++ {
		lenner[i] = scanInt64()
		if lenner[i] + i - 1 > N {
			err()
			return
		}
	}
	for i := M; i > 0; i-- {
		suffix_sum[i] = suffix_sum[i + 1] + lenner[i]
	}
	if suffix_sum[1] < N {
		err()
		return
	}
	for i := int64(1); i <= M; i++ {
		_, _ = printFmt(max(i, N - suffix_sum[i] + 1))
		if i < M {
			_, _ = printFmt(" ")
		} else {
			_, _ = printFmt("")
		}
	}
}

func err() {
	_, _ = printFmt("-1")
}

func main() {
	solve()
}
/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Print

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			_, _ = writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func max(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

/*
URL:
https://codeforces.com/problemset/problem/1329/A
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n, m int
	L    []int64
)

func main() {
	n, m = ReadInt2()
	L = ReadInt64Slice(m)

	total := Sum(L...)

	if total < int64(n) {
		fmt.Println(-1)
		return
	}

	for i := 0; i < m; i++ {
		if L[i] > int64(n-i) {
			fmt.Println(-1)
			return
		}
	}

	diff := total - int64(n)
	for i := 0; i < m; i++ {
		l := L[i]
		if diff >= l-1 {
			L[i] = 1
			diff -= l - 1
		} else {
			L[i] -= diff
			diff = 0
		}

		if diff <= 0 {
			break
		}
	}

	A := make([]int64, m)
	idx := int64(1)
	cs := int64(0)
	for i := 0; i < m; i++ {
		A[i] = idx + cs
		cs += L[i]
	}

	fmt.Println(PrintInts64Line(A...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64

	s = 0
	for _, i := range integers {
		s += i
	}

	return s
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum, i, v int64
	var l, ans []int64
	fmt.Scan(&n, &m)

	for i = 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := int64(1)
		for _, v = range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 >= dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1329A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, m int
	Fscan(in, &n, &m)
	l := make([]int, m)
	r := make([]int, m)
	p := make([]int, m)
	for i := range l {
		Fscan(in, &l[i])
		if i == 0 {
			r[i] = l[i]
		} else {
			r[i] = max(r[i-1], l[i]+i)
		}
		if r[i] > n {
			Fprint(out, -1)
			return
		}
		p[i] = i + 1
	}
	last := n
	i := m - 1
	for ; i >= 0 && r[i] < last; i-- {
		p[i] = last - l[i] + 1
		last = p[i] - 1
	}
	if i < 0 && last > 0 {
		Fprint(out, -1)
		return
	}
	for _, v := range p {
		Fprint(out, v, " ")
	}
}

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

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < rest {
			printf("-1")
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				pos := lmax + pad
				curi++
				for curi < p {
					res = append(res, pos)
					pos += arr[curi]
					curi++
				}
				for i := range res {
					if i != 0 {
						printf(" ")
					}
					printf("%d", res[i])
				}
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if curi == p-1 && (n-lmin+1) < arr[curi] {
			printf("-1")
			return
		}
		if sum < rest {
			printf("-1")
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			return
		}
		rest := n - lmax + 1
		if sum < rest {
			printf("-1")
			return
		}
		if sum == rest {
			printRes(curi, lmax, res)
			return
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			// fmt.Println(target, lmin, lmax)
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				return
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			break
		}
		rest := n - lmax + 1
		// fmt.Println(res, lmin, lmax, rest, sum)
		if sum < rest {
			printf("-1")
			break
		}
		if sum == rest {
			printRes(curi, lmax, res)
			break
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				break
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi])
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

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

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

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

var arr []int
var n, p int

func main() {
	defer flush()

	scanf("%d %d\n", &n, &p)
	arr = make([]int, p)
	for i := range arr {
		scanf("%d", &arr[i])
	}
	solve()
}

func printRes(i, pos int, res []int) {
	for i < p {
		res = append(res, pos)
		pos += arr[i]
		i++
	}
	for i := range res {
		if i != 0 {
			printf(" ")
		}
		printf("%d", res[i])
	}
}

func solve() {
	curi := 0
	lmin, lmax := 1, 1
	sum := 0
	res := []int{}
	for _, x := range arr {
		sum += x
	}
	for true {
		if curi >= p {
			printf("-1")
			break
		}
		rest := n - lmax + 1
		// fmt.Println(res, lmin, lmax, rest, sum)
		if sum < rest {
			printf("-1")
			break
		}
		if sum == rest {
			printRes(curi, lmax, res)
			break
		}
		if sum-arr[curi] <= rest {
			pad := rest - (sum - arr[curi])
			target := lmax + pad - arr[curi]
			if target >= lmin {
				res = append(res, target)
				printRes(curi+1, lmax+pad, res)
				break
			}
		}
		res = append(res, lmin)
		lmin, lmax = lmin+1, max(lmax, lmin+arr[curi]+1)
		sum -= arr[curi]
		curi++
	}
}

// utilities function
func pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		a, b = a*a, b>>1
	}
	return p
}

func powmod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		a, b = (a*a)%m, b>>1
	}
	return p
}

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

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

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

func chmax(a *int, b int) {
	*a = max(*a, b)
}

func chmin(a *int, b int) {
	*a = min(*a, b)
}

package main

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

const SIZE = 100002

var(
	lenner [SIZE]int
	suffix_sum [SIZE]int
)

func solve() {
	N, M := scanInt(), scanInt()
	for i := 1; i <= M; i++ {
		lenner[i] = scanInt()
		if lenner[i] + i - 1 > N {
			err()
			return
		}
	}
	for i := M; i > 0; i-- {
		suffix_sum[i] = suffix_sum[i + 1] + lenner[i]
	}
	if suffix_sum[1] < N {
		err()
		return
	}
	for i := 1; i <= M; i++ {
		_, _ = printFmt(max(i, N - suffix_sum[i] + 1))
		if i < M {
			_, _ = printFmt(" ")
		} else {
			_, _ = printFmt("")
		}
	}
}

func err() {
	_, _ = printFmt("-1")
}

func main() {
	solve()
}
/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Print

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			_, _ = writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int) int { mn, _ := MnMx(args...); return mn }
func max(args ...int) int { _, mx := MnMx(args...); return mx }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum int
	var l, ans []int
	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := 1
		for _, v := range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 > dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import (
	"fmt"
)

func main() {
	var n, m, aux, sum int
	var l, ans []int
	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&aux)
		l = append(l, aux)
		sum += aux
	}

	if dif := sum - n; dif < 0 {
		fmt.Println("-1")
	} else {
		p := 1
		for _, v := range l {
			if p > n - v + 1 {
				fmt.Println("-1")
				return
			}
			ans = append(ans, p)
			if v-1 >= dif {
				p += v - dif
				dif = 0
			} else {
				p++
				dif -= v-1
			}
		}

		for _, v := range ans {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

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

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if i != m-1 && min(n - (m-i), aux + ans - 1) <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

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

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if i != m && min(n - (m-i), aux + ans - 1) <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

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

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		if temp := min(n - (m-i), aux + ans - 1); temp <= ans {
			fmt.Println("-1")
			return
		}
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main
import "fmt"

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

func main() {
	var n, m, aux int
	var anss []int
	ans := 1
	fmt.Scan(&n, &m)

	for i := 1; i <= m; i++ {
		fmt.Scan(&aux)
		anss = append(anss, ans)
		ans = min(n - (m-i), aux + ans - 1)
	}
	if aux + anss[len(anss)-1] - 1 != n {
		fmt.Println("-1")
	} else {
		for _, v := range anss {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}


Let's define $$$p_i(n)$$$ as the following permutation: $$$[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$$$. This means that the $$$i$$$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $$$i$$$ is on the first position. Examples:  $$$p_1(4) = [1, 2, 3, 4]$$$;  $$$p_2(4) = [2, 1, 3, 4]$$$;  $$$p_3(4) = [3, 1, 2, 4]$$$;  $$$p_4(4) = [4, 1, 2, 3]$$$. You are given an array $$$x_1, x_2, \dots, x_m$$$ ($$$1 \le x_i \le n$$$).Let $$$pos(p, val)$$$ be the position of the element $$$val$$$ in $$$p$$$. So, $$$pos(p_1(4), 3) = 3, pos(p_2(4), 2) = 1, pos(p_4(4), 4) = 1$$$.Let's define a function $$$f(p) = \sum\limits_{i=1}^{m - 1} |pos(p, x_i) - pos(p, x_{i + 1})|$$$, where $$$|val|$$$ is the absolute value of $$$val$$$. This function means the sum of distances between adjacent elements of $$$x$$$ in $$$p$$$.Your task is to calculate $$$f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$$$.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 2 \cdot 10^5$$$) — the number of elements in each permutation and the number of elements in $$$x$$$. The second line of the input contains $$$m$$$ integers ($$$m$$$, not $$$n$$$) $$$x_1, x_2, \dots, x_m$$$ ($$$1 \le x_i \le n$$$), where $$$x_i$$$ is the $$$i$$$-th element of $$$x$$$. Elements of $$$x$$$ can repeat and appear in arbitrary order.

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

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

func main() {
	defer writer.Flush()
	var n, m int
	Scanf("%d %d\n", &n, &m)
	x := make([]int, m)
	for i := 0; i < m; i++ {
		Scanf("%d", &x[i])
	}

	var base int64
	cnt := make([]int64, n)
	iltq := make([]int64, n)
	plti := make([]int64, n)
	for i := 0; i < m-1; i++ {
		// Make p <= q.
		p, q := x[i], x[i+1]
		p--
		q--
		if p == q {
			continue
		}
		p, q = autoswp(p, q)

		// Base for permutation p1.
		base += int64(q - p)

		// Case where p < j < q
		cnt[p+1] += 1
		cnt[q] -= 1

		// Case where p == j; j < q
		iltq[p] += int64(p)

		// Case where p < j; j == q
		plti[q] += int64(-(q - p) + p + 1)
	}

	// Prefix sum trick...
	for i := 1; i < n; i++ {
		cnt[i] += cnt[i-1]
	}

	for i := 0; i < n; i++ {
		Printf("%d ", base-cnt[i]+iltq[i]+plti[i])
	}
}

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	// for i := 0; i < m; i++ {
	// 	if i == 0 {
	// 		if X[i+1] > X[i] {
	// 			A[i] += X[i+1] - 1
	// 		} else if X[i+1] < X[i] {
	// 			A[i] += X[i+1]
	// 		}
	// 	} else if i == m-1 {
	// 		if X[i-1] > X[i] {
	// 			A[i] += X[i-1] - 1
	// 		} else if X[i-1] < X[i] {
	// 			A[i] += X[i-1]
	// 		}
	// 	} else {
	// 		if X[i+1] > X[i] {
	// 			A[i] += X[i+1] - 1
	// 		} else if X[i+1] < X[i] {
	// 			A[i] += X[i+1]
	// 		}
	// 		if X[i-1] > X[i] {
	// 			A[i] += X[i-1] - 1
	// 		} else if X[i-1] < X[i] {
	// 			A[i] += X[i-1]
	// 		}
	// 	}
	// }
	for i := 0; i < m; i++ {
		if i < m-1 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		}

		if i > 0 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	// base := Sum(diff...)
	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, B, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i == 0 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		} else if i == m-1 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		} else {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// for i := 0; i < m-1; i++ {
	// 	diff[i] = AbsInt(X[i] - X[i+1])

	// 	if X[i+1] > X[i] {
	// 		A[i] = X[i+1] - 1
	// 	} else if X[i+1] < X[i] {
	// 		B[i] = X[i+1]
	// 	}
	// }

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	// base := Sum(diff...)
	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	// Xの階差を計算する、和がf(P1(n))となる
	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	// X[i]が数列の先頭に来る場合の、前後のxとの位置の差の絶対値を計算しておく
	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i < m-1 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		}

		if i > 0 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// X中における、1<=i<=nのiが登場する位置を記憶しておく
	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}

	// cnt[i]: 1<=i<=nのiについて、
	// Xにおけるすべての隣接項間のうち、隣接項間にiが挟まるものの個数
	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}

	base := int64(0)
	for _, d := range diff {
		base += int64(d)
	}
	answers := []int64{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			if idx == 0 {
				ans += int64(A[idx] - diff[idx])
			} else if idx < m-1 {
				ans += int64(A[idx] - diff[idx] - diff[idx-1])
			} else {
				ans += int64(A[idx] - diff[idx-1])
			}
		}
		ans -= int64(cnt[i])
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		// str := strconv.Itoa(A[i])
		str := strconv.FormatInt(A[i], 10)
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

func subAbs(x, y int) int64 {
	if x >= y {
		return int64(x - y)
	} else {
		return int64(y - x)
	}
}

type Node struct {
	old       int
	pre, next bool
}

func main() {
	ch := make(chan int64, 100)
	go func() {
		reader := bufio.NewReader(os.Stdin)

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

		mapp := make(map[int][]int, m)

		x := make([]Node, m+2)

		for i := 1; i <= m; i++ {
			fmt.Fscanf(reader, "%d", &x[i].old)

			if slice, ok := mapp[x[i].old]; ok {
				mapp[x[i].old] = append(slice, i)
			} else {
				slice := make([]int, 1, 10)
				slice[0] = i
				mapp[x[i].old] = slice
			}
		}

		var sum int64 = 0
		for i := 2; i <= m; i++ {
			sum += subAbs(x[i].old, x[i-1].old)
		}
		// var ans string = strconv.FormatInt(sum, 10)
		// fmt.Printf("%d ", sum)

		ch <- sum

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

			x[1].pre = true
			x[m].next = true
			pi_, _ := mapp[i-1]
			pi, _ := mapp[i]

			for _, index := range pi_ {
				if !x[index].pre && !x[index-1].next {
					sum -= subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum -= subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi {
				if !x[index].pre && !x[index-1].next {
					sum -= subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum -= subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi_ {
				x[index].pre = false
				x[index].next = false
				x[index].old = i
			}

			for _, index := range pi {
				x[index].pre = false
				x[index].next = false
				x[index].old = 1
			}

			// for k := 1; k <= m; k++ {
			// 	fmt.Printf("%d ", x[k].old)
			// }
			// fmt.Println()

			x[1].pre = true
			x[m].next = true
			for _, index := range pi_ {
				if !x[index].pre && !x[index-1].next {
					sum += subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum += subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi {
				if !x[index].pre && !x[index-1].next {
					sum += subAbs(x[index].old, x[index-1].old)
					x[index].pre = true
				}

				if !x[index].next && !x[index+1].pre {
					sum += subAbs(x[index].old, x[index+1].old)
					x[index].next = true
				}
			}

			for _, index := range pi_ {
				x[index].pre = false
				x[index].next = false
			}

			for _, index := range pi {
				x[index].pre = false
				x[index].next = false
			}

			//fmt.Printf("%d ", sum)
			//ans = ans + " " + strconv.FormatInt(sum, 10)
			ch <- sum
		}
		close(ch)
	}()

	for v := range ch {
		fmt.Printf("%d ", v)
	}
}

package main

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

func subAbs(x, y int) int64 {
	if x >= y {
		return int64(x - y)
	} else {
		return int64(y - x)
	}
}

type Node struct {
	old       int
	pre, next bool
}

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

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

	mapp := make(map[int][]int, m)

	x := make([]Node, m+2)

	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d", &x[i].old)

		if slice, ok := mapp[x[i].old]; ok {
			mapp[x[i].old] = append(slice, i)
		} else {
			slice := make([]int, 1, 10)
			slice[0] = i
			mapp[x[i].old] = slice
		}
	}

	var sum int64 = 0
	for i := 2; i <= m; i++ {
		sum += subAbs(x[i].old, x[i-1].old)
	}
	//var ans string = strconv.Itoa(sum)
	fmt.Printf("%d ", sum)

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

		x[1].pre = true
		x[m].next = true
		pi_, _ := mapp[i-1]
		pi, _ := mapp[i]

		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
			x[index].old = i
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
			x[index].old = 1
		}

		// for k := 1; k <= m; k++ {
		// 	fmt.Printf("%d ", x[k].old)
		// }
		// fmt.Println()

		x[1].pre = true
		x[m].next = true
		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
		}

		fmt.Printf("%d ", sum)
	}

	//fmt.Println(ans)
	fmt.Println()
}

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m int
var X []int

var A, B, diff []int
var C [][]int
var cnt []int

func main() {
	n, m = ReadInt2()
	X = ReadIntSlice(m)

	diff = make([]int, m-1)
	for i := 0; i < m-1; i++ {
		diff[i] = AbsInt(X[i] - X[i+1])
	}

	A = make([]int, m)
	for i := 0; i < m; i++ {
		if i == 0 {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
		} else if i == m-1 {
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		} else {
			if X[i+1] > X[i] {
				A[i] += X[i+1] - 1
			} else if X[i+1] < X[i] {
				A[i] += X[i+1]
			}
			if X[i-1] > X[i] {
				A[i] += X[i-1] - 1
			} else if X[i-1] < X[i] {
				A[i] += X[i-1]
			}
		}
	}

	// for i := 0; i < m-1; i++ {
	// 	diff[i] = AbsInt(X[i] - X[i+1])

	// 	if X[i+1] > X[i] {
	// 		A[i] = X[i+1] - 1
	// 	} else if X[i+1] < X[i] {
	// 		B[i] = X[i+1]
	// 	}
	// }

	C = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		C[i] = []int{}
	}
	for i := 0; i < m; i++ {
		C[X[i]] = append(C[X[i]], i)
	}
	// fmt.Println(diff)
	// fmt.Println(A)
	// fmt.Println(B)
	// fmt.Println(C)

	cnt = make([]int, n+1)
	for i := 0; i < m-1; i++ {
		if AbsInt(X[i]-X[i+1]) < 2 {
			continue
		} else {
			cnt[Min(X[i], X[i+1])+1]++
			cnt[Max(X[i], X[i+1])]--
		}
	}
	for i := 0; i < n; i++ {
		cnt[i+1] = cnt[i+1] + cnt[i]
	}
	// fmt.Println(cnt)

	base := Sum(diff...)
	answers := []int{}
	for i := 1; i <= n; i++ {
		ans := base
		for _, idx := range C[i] {
			// if idx == 0 {
			// 	ans += A[idx] + B[idx] - diff[idx]
			// } else if idx < m-1 {
			// 	ans += A[idx] + B[idx] - diff[idx] + A[idx-1] + B[idx-1] - diff[idx-1]
			// } else {
			// 	ans += A[idx-1] + B[idx-1] - diff[idx-1]
			// }

			// ans += (A[idx] + B[idx] - diff[idx])

			if idx == 0 {
				ans += A[idx] - diff[idx]
			} else if idx < m-1 {
				ans += A[idx] - diff[idx] - diff[idx-1]
			} else {
				ans += A[idx] - diff[idx-1]
			}
		}
		ans -= cnt[i]
		answers = append(answers, ans)
	}

	fmt.Println(PrintIntsLine(answers...))
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

func subAbs(x, y int) int {
	if x >= y {
		return x - y
	} else {
		return y - x
	}
}

type Node struct {
	old       int
	pre, next bool
}

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

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

	mapp := make(map[int][]int, m)

	x := make([]Node, m+2)

	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d", &x[i].old)

		if slice, ok := mapp[x[i].old]; ok {
			mapp[x[i].old] = append(slice, i)
		} else {
			slice := make([]int, 1, 10)
			slice[0] = i
			mapp[x[i].old] = slice
		}
	}

	var sum int = 0
	for i := 2; i <= m; i++ {
		sum += subAbs(x[i].old, x[i-1].old)
	}
	//var ans string = strconv.Itoa(sum)
	fmt.Printf("%d ", sum)

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

		x[1].pre = true
		x[m].next = true
		pi_, _ := mapp[i-1]
		pi, _ := mapp[i]

		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum -= subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum -= subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
			x[index].old = i
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
			x[index].old = 1
		}

		// for k := 1; k <= m; k++ {
		// 	fmt.Printf("%d ", x[k].old)
		// }
		// fmt.Println()

		x[1].pre = true
		x[m].next = true
		for _, index := range pi_ {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi {
			if !x[index].pre && !x[index-1].next {
				sum += subAbs(x[index].old, x[index-1].old)
				x[index].pre = true
			}

			if !x[index].next && !x[index+1].pre {
				sum += subAbs(x[index].old, x[index+1].old)
				x[index].next = true
			}
		}

		for _, index := range pi_ {
			x[index].pre = false
			x[index].next = false
		}

		for _, index := range pi {
			x[index].pre = false
			x[index].next = false
		}

		fmt.Printf("%d ", sum)
	}

	//fmt.Println(ans)
	fmt.Println()
}


Vasily the bear has got a sequence of positive integers a1, a2, ..., an. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers b1, b2, ..., bk is such maximum non-negative integer v, that number b1 and b2 and ... and bk is divisible by number 2v without a remainder. If such number v doesn't exist (that is, for any non-negative integer v, number b1 and b2 and ... and bk is divisible by 2v without a remainder), the beauty of the written out numbers equals -1. Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible.Here expression x and y means applying the bitwise AND operation to numbers x and y. In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".

The first line contains integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 109).

In the first line print a single integer k (k > 0), showing how many numbers to write out. In the second line print k integers b1, b2, ..., bk — the numbers to write out. You are allowed to print numbers b1, b2, ..., bk in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them.

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

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

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

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func ctz(n int) int {
  ans := 0
  for ; n&1 == 0; n >>= 1 {
    ans++
  }
  return ans
}

func nbits(n int) int {
  ans := 0
  for ; n > 0; n >>= 1 {
    ans++
  }
  return ans
}

func kthbit(n, k int) int {
  return (n >> uint(k)) & 1
}

func main() {
  n := ni32()
  b := make([]int, n)
  for i := 0; i < n; i++ {
    b[i] = ni32()
  }
  k := 31
  bit, c := 0, 0
  for i := 0; i < k; i++ {
    a := 1<<31 - 1
    for _, v := range b {
      if kthbit(v, i) == 1 {
        a = a & v
      }
    }
    if ctz(a) > c {
      c = ctz(a)
      bit = i
    }
  }
  ans := []int{}
  for _, v := range b {
    if kthbit(v, bit) == 1 {
      ans = append(ans, v)
    }
  }
  pri32(len(ans))
  endl()
  for _, v := range ans {
    pri32(v)
  }
  endl()
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

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

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

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func clz(n int) int {
  ans := 0
  for ; n&1 == 0; n >>= 1 {
    ans++
  }
  return ans
}

func kthbit(n, k int) int {
  return (n >> uint(k)) & 1
}

var b Data
var c map[int]int = make(map[int]int)

type Data []int

func (d Data) Len() int           { return len(d) }
func (d Data) Less(i, j int) bool { return c[d[i]] > c[d[j]] }
func (d Data) Swap(i, j int)      { d[i], d[j] = d[j], d[i] }

func main() {
  n := ni32()
  b = make([]int, n)
  for i := 0; i < n; i++ {
    b[i] = ni32()
    c[b[i]] = clz(b[i])
  }
  sort.Sort(b)
  k := 31
  cnt := make([][]int, k)
  for i := 0; i < k; i++ {
    cnt[i] = make([]int, n)
    cnt[i][0] = kthbit(b[0], i)
    for j := 1; j < n; j++ {
      cnt[i][j] = cnt[i][j-1] + kthbit(b[j], i)
    }
  }
  cur, count := 0, cnt[c[b[0]]][n-1]
  for i := 1; i < n && c[b[i]] == c[b[cur]]; i++ {
    if cnt[c[b[i]]][n-1]-cnt[c[b[i]]][i-1] > count {
      cur = i
      count = cnt[c[b[i]]][n-1] - cnt[c[b[i]]][i-1]
    }
  }
  pri32(count)
  endl()
  for _, v := range b {
    if kthbit(v, c[b[cur]]) == 1 {
      pri32(v)
    }
  }
  w.Flush()
}


We are sum for we are manySome NumberThis version of the problem differs from the previous one only in the constraint on $$$t$$$. You can make hacks only if both versions of the problem are solved.You are given two positive integers $$$l$$$ and $$$r$$$.Count the number of distinct triplets of integers $$$(i, j, k)$$$ such that $$$l \le i < j < k \le r$$$ and $$$\operatorname{lcm}(i,j,k) \ge i + j + k$$$.Here $$$\operatorname{lcm}(i, j, k)$$$ denotes the least common multiple (LCM) of integers $$$i$$$, $$$j$$$, and $$$k$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$\bf{1 \le t \le 10^5}$$$). Description of the test cases follows. The only line for each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 2 \cdot 10^5$$$, $$$l + 2 \le r$$$).

For each test case print one integer — the number of suitable triplets.

NoteIn the first test case, there are $$$3$$$ suitable triplets:   $$$(1,2,3)$$$,  $$$(1,3,4)$$$,  $$$(2,3,4)$$$. In the second test case, there is $$$1$$$ suitable triplet:   $$$(3,4,5)$$$.

package main

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

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

	var buf bytes.Buffer

	n := readNum(reader)
	Q := make([][]int, n)
	for i := 0; i < n; i++ {
		Q[i] = readNNums(reader, 2)
	}
	res := solve(Q)
	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d\n", res[i]))
	}

	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
}

const N = 200005

func solve(Q [][]int) []int64 {
	ask := make([][]Pair, N)

	add := func(i, l, r int) {
		if len(ask[l]) == 0 {
			ask[l] = make([]Pair, 0, 1)
		}
		ask[l] = append(ask[l], Pair{r, i})
	}
	ans := make([]int64, len(Q))
	for i, cur := range Q {
		l, r := cur[0], cur[1]
		add(i, l, r)
		ln := int64(r - l + 1)
		ans[i] = ln * (ln - 1) * (ln - 2) / 6
		ans[i] -= int64(max(r/6-(l-1)/3, 0))
		ans[i] -= int64(max(r/15-(l-1)/6, 0))
	}

	bit := NewBIT(N)

	cnt := make([]int64, N)

	for l := N - 1; l >= 1; l-- {
		for j := l << 1; j < N; j += l {
			bit.Add(j, cnt[j])
			cnt[j]++
		}
		for j := 0; j < len(ask[l]); j++ {
			r, i := ask[l][j].first, ask[l][j].second
			ans[i] -= bit.QueryRange(l, r)
		}
	}

	return ans
}

type BIT struct {
	arr []int64
	n   int
}

func NewBIT(n int) *BIT {
	arr := make([]int64, n+1)
	return &BIT{arr, n}
}

func (bit *BIT) Add(p int, v int64) {
	for p <= bit.n {
		bit.arr[p] += v
		p += p & -p
	}
}

func (bit *BIT) Query(p int) int64 {
	var res int64
	for p > 0 {
		res += bit.arr[p]
		p -= p & -p
	}
	return res
}

func (bit *BIT) QueryRange(l, r int) int64 {
	return bit.Query(r) - bit.Query(l-1)
}

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

type Pair struct {
	first  int
	second int
}