Problem:
Score : 100 points

Problem Statement

You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.

Constraints

1 \leq N, M \leq 524288

0 \leq a_i, b_i < 998244353

All values in Input are integer.

Input

Input is given from Standard Input in the following format:

N M
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{M-1}

Output

Print the answer in the following format:

c_0 c_1 ... c_{(N - 1) + (M - 1)}

Sample Input 1

4 5
1 2 3 4
5 6 7 8 9

Sample Output 1

5 16 34 60 70 70 59 36

Sample Input 2

1 1
10000000
10000000

Sample Output 2

871938225

Solution in Go (1.14.1) (judge verdict: Accepted)

package main

/*
#define true 1
#define false 0
#define bool int

// @param m `1 <= m`
// @return x mod m
long long safe_mod(long long x, long long m) {
	x %= m;
	if (x < 0) x += m;
	return x;
}

// Fast moduler by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
//

// @param a `0 <= a < m`
// @param b `0 <= b < m`
// @return `a * b % m`
unsigned int barrett_mul(unsigned int _m, unsigned long long im, unsigned int a,
			 unsigned int b) {
	// [1] m = 1
	// a = b = im = 0, so okay

	// [2] m >= 2
	// im = ceil(2^64 / m)
	// -> im * m = 2^64 + r (0 <= r < m)
	// let z = a*b = c*m + d (0 <= c, d < m)
	// a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
	// c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1)
	// < 2^64 * 2
	// ((ab * im) >> 64) == c or c + 1
	unsigned long long z = a;
	z *= b;
#ifdef _MSC_VER
	unsigned long long x;
	_umul128(z, im, &x);
#else
	unsigned long long x =
	    (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
	unsigned int v = (unsigned int)(z - x * _m);
	if (_m <= v) v += _m;
	return v;
}

unsigned long long barrett_im(unsigned int m) {
	return (unsigned long long)(-1) / m + 1;
}

// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
long long pow_mod(long long x, long long n, int m) {
	if (m == 1) return 0;
	unsigned int _m = (unsigned int)(m);
	unsigned long long r = 1;
	unsigned long long y = safe_mod(x, m);
	while (n) {
		if (n & 1) r = (r * y) % _m;
		y = (y * y) % _m;
		n >>= 1;
	}
	return r;
}

// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
bool is_prime(int n) {
	if (n <= 1) return false;
	if (n == 2 || n == 7 || n == 61) return true;
	if (n % 2 == 0) return false;
	long long d = n - 1;
	while (d % 2 == 0) d /= 2;
	long long as[] = {2, 7, 61};
	for (int i = 0; i < sizeof(as) / sizeof(long long); i++) {
		long long a = as[i];
		long long t = d;
		long long y = pow_mod(a, t, n);
		while (t != n - 1 && y != 1 && y != n - 1) {
			y = y * y % n;
			t <<= 1;
		}
		if (y != n - 1 && t % 2 == 0) {
			return false;
		}
	}
	return true;
}

// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
void inv_gcd(long long a, long long b, long long *g, long long *x) {
	a = safe_mod(a, b);
	if (a == 0) {
		*g = b;
		*x = 0;
		return;
	}

	// Contracts:
	// [1] s - m0 * a = 0 (mod b)
	// [2] t - m1 * a = 0 (mod b)
	// [3] s * |m1| + t * |m0| <= b
	long long s = b, t = a;
	long long m0 = 0, m1 = 1;

	while (t) {
		long long u = s / t;
		s -= t * u;
		m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b

		// [3]:
		// (s - t * u) * |m1| + t * |m0 - m1 * u|
		// <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
		// = s * |m1| + t * |m0| <= b

		long long tmp = s;
		s = t;
		t = tmp;
		tmp = m0;
		m0 = m1;
		m1 = tmp;
	}
	// by [3]: |m0| <= b/g
	// by g != b: |m0| < b/g
	if (m0 < 0) m0 += b / s;
	*g = s;
	*x = m0;
	return;
}

// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
int primitive_root(int m) {
	if (m == 2) return 1;
	if (m == 167772161) return 3;
	if (m == 469762049) return 3;
	if (m == 754974721) return 11;
	if (m == 998244353) return 3;
	int divs[20] = {};
	divs[0] = 2;
	int cnt = 1;
	int x = (m - 1) / 2;
	while (x % 2 == 0) x /= 2;
	for (int i = 3; (long long)(i)*i <= x; i += 2) {
		if (x % i == 0) {
			divs[cnt++] = i;
			while (x % i == 0) {
				x /= i;
			}
		}
	}
	if (x > 1) {
		divs[cnt++] = x;
	}
	for (int g = 2;; g++) {
		bool ok = true;
		for (int i = 0; i < cnt; i++) {
			if (pow_mod(g, (m - 1) / divs[i], m) == 1) {
				ok = false;
				break;
			}
		}
		if (ok) return g;
	}
}

*/
import "C" // do not insert blank lines above

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math/bits"
	"os"
	"strconv"
)

var DEBUG = true

func main() {
	defer Flush()

	N := readi()
	M := readi()
	_, a := readInts(N)
	_, b := readInts(M)
	c := Convolution998244353Int(a, b)

	sp := ""
	for i := 0; i < len(c); i++ {
		printf("%s%d", sp, c[i])
		sp = " "
	}
	println()
}

// Code generated by genmaps.go; DO NOT EDIT.

type Mod1000000007Int int

func NewMod1000000007Int(v int) Mod1000000007Int {
	return Mod1000000007Int(v % 1000000007)
}

func (v Mod1000000007Int) Mod() int {
	return 1000000007
}

func (v Mod1000000007Int) Val() int {
	return int(v)
}

func (v Mod1000000007Int) Negate() Mod1000000007Int {
	return 1000000007 - v
}

func (v *Mod1000000007Int) Inc() {
	*v = (*v + 1) % 1000000007
}

func (v *Mod1000000007Int) Dec() {
	*v = (*v - 1 + 1000000007) % 1000000007
}

func (v Mod1000000007Int) Add(x Mod1000000007Int) Mod1000000007Int {
	return (v + x) % 1000000007
}

func (v Mod1000000007Int) Sub(x Mod1000000007Int) Mod1000000007Int {
	return (v + 1000000007 - x) % 1000000007
}

func (v Mod1000000007Int) Mul(x Mod1000000007Int) Mod1000000007Int {
	return (v * x) % 1000000007
}

func (v Mod1000000007Int) Div(x Mod1000000007Int) Mod1000000007Int {
	return (v * x.Inv()) % 1000000007
}

func (v Mod1000000007Int) Pow(n int) Mod1000000007Int {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return 1
	}

	x := int(v)
	r := int(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % 1000000007
		}
		x = x * x % 1000000007
		n >>= 1
	}
	return Mod1000000007Int(r)
}

func (v Mod1000000007Int) Inv() Mod1000000007Int {
	if true {
		if v == 0 {
			panic("must be non zero")
		}
		return v.Pow(1000000007 - 2)
	} else {
		g, x := InvGCD(int64(v), 1000000007)
		if g != 1 {
			panic("g != 1")
		}
		return Mod1000000007Int(x)
	}
}

type Mod998244353Int int

func NewMod998244353Int(v int) Mod998244353Int {
	return Mod998244353Int(v % 998244353)
}

func (v Mod998244353Int) Mod() int {
	return 998244353
}

func (v Mod998244353Int) Val() int {
	return int(v)
}

func (v Mod998244353Int) Negate() Mod998244353Int {
	return 998244353 - v
}

func (v *Mod998244353Int) Inc() {
	*v = (*v + 1) % 998244353
}

func (v *Mod998244353Int) Dec() {
	*v = (*v - 1 + 998244353) % 998244353
}

func (v Mod998244353Int) Add(x Mod998244353Int) Mod998244353Int {
	return (v + x) % 998244353
}

func (v Mod998244353Int) Sub(x Mod998244353Int) Mod998244353Int {
	return (v + 998244353 - x) % 998244353
}

func (v Mod998244353Int) Mul(x Mod998244353Int) Mod998244353Int {
	return (v * x) % 998244353
}

func (v Mod998244353Int) Div(x Mod998244353Int) Mod998244353Int {
	return (v * x.Inv()) % 998244353
}

func (v Mod998244353Int) Pow(n int) Mod998244353Int {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return 1
	}

	x := int(v)
	r := int(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % 998244353
		}
		x = x * x % 998244353
		n >>= 1
	}
	return Mod998244353Int(r)
}

func (v Mod998244353Int) Inv() Mod998244353Int {
	if true {
		if v == 0 {
			panic("must be non zero")
		}
		return v.Pow(998244353 - 2)
	} else {
		g, x := InvGCD(int64(v), 998244353)
		if g != 1 {
			panic("g != 1")
		}
		return Mod998244353Int(x)
	}
}

type Mod1000000007Int64 int64

func NewMod1000000007Int64(v int64) Mod1000000007Int64 {
	return Mod1000000007Int64(v % 1000000007)
}

func (v Mod1000000007Int64) Mod() int64 {
	return 1000000007
}

func (v Mod1000000007Int64) Val() int64 {
	return int64(v)
}

func (v Mod1000000007Int64) Negate() Mod1000000007Int64 {
	return 1000000007 - v
}

func (v *Mod1000000007Int64) Inc() {
	*v = (*v + 1) % 1000000007
}

func (v *Mod1000000007Int64) Dec() {
	*v = (*v - 1 + 1000000007) % 1000000007
}

func (v Mod1000000007Int64) Add(x Mod1000000007Int64) Mod1000000007Int64 {
	return (v + x) % 1000000007
}

func (v Mod1000000007Int64) Sub(x Mod1000000007Int64) Mod1000000007Int64 {
	return (v + 1000000007 - x) % 1000000007
}

func (v Mod1000000007Int64) Mul(x Mod1000000007Int64) Mod1000000007Int64 {
	return (v * x) % 1000000007
}

func (v Mod1000000007Int64) Div(x Mod1000000007Int64) Mod1000000007Int64 {
	return (v * x.Inv()) % 1000000007
}

func (v Mod1000000007Int64) Pow(n int64) Mod1000000007Int64 {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return 1
	}

	x := int64(v)
	r := int64(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % 1000000007
		}
		x = x * x % 1000000007
		n >>= 1
	}
	return Mod1000000007Int64(r)
}

func (v Mod1000000007Int64) Inv() Mod1000000007Int64 {
	if true {
		if v == 0 {
			panic("must be non zero")
		}
		return v.Pow(1000000007 - 2)
	} else {
		g, x := InvGCD(int64(v), 1000000007)
		if g != 1 {
			panic("g != 1")
		}
		return Mod1000000007Int64(x)
	}
}

type Mod998244353Int64 int64

func NewMod998244353Int64(v int64) Mod998244353Int64 {
	return Mod998244353Int64(v % 998244353)
}

func (v Mod998244353Int64) Mod() int64 {
	return 998244353
}

func (v Mod998244353Int64) Val() int64 {
	return int64(v)
}

func (v Mod998244353Int64) Negate() Mod998244353Int64 {
	return 998244353 - v
}

func (v *Mod998244353Int64) Inc() {
	*v = (*v + 1) % 998244353
}

func (v *Mod998244353Int64) Dec() {
	*v = (*v - 1 + 998244353) % 998244353
}

func (v Mod998244353Int64) Add(x Mod998244353Int64) Mod998244353Int64 {
	return (v + x) % 998244353
}

func (v Mod998244353Int64) Sub(x Mod998244353Int64) Mod998244353Int64 {
	return (v + 998244353 - x) % 998244353
}

func (v Mod998244353Int64) Mul(x Mod998244353Int64) Mod998244353Int64 {
	return (v * x) % 998244353
}

func (v Mod998244353Int64) Div(x Mod998244353Int64) Mod998244353Int64 {
	return (v * x.Inv()) % 998244353
}

func (v Mod998244353Int64) Pow(n int64) Mod998244353Int64 {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return 1
	}

	x := int64(v)
	r := int64(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % 998244353
		}
		x = x * x % 998244353
		n >>= 1
	}
	return Mod998244353Int64(r)
}

func (v Mod998244353Int64) Inv() Mod998244353Int64 {
	if true {
		if v == 0 {
			panic("must be non zero")
		}
		return v.Pow(998244353 - 2)
	} else {
		g, x := InvGCD(int64(v), 998244353)
		if g != 1 {
			panic("g != 1")
		}
		return Mod998244353Int64(x)
	}
}

type DynamicModInt struct {
	v       int64
	bt      Barrett
	isPrime bool
}

func NewDynamicModInt(v int) DynamicModInt {
	return DynamicModInt{
		v: int64(v),
	}
}

func (d *DynamicModInt) SetMod(m int) {
	if m < 1 {
		panic("modulo must be more than 0")
	}
	d.bt = NewBarrett(uint(m))
	d.v %= d.umod()
	d.isPrime = IsPrime(m)
}

func (d DynamicModInt) umod() int64 {
	return int64(d.bt.Umod())
}

func (d DynamicModInt) Mod() int {
	return int(d.umod())
}

func (d DynamicModInt) Val() int {
	return int(d.v)
}

func (d DynamicModInt) Negate() DynamicModInt {
	return DynamicModInt{
		v:       d.umod() - d.v,
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d *DynamicModInt) Inc() {
	d.v = (d.v + 1) % d.umod()
}

func (d *DynamicModInt) Dec() {
	d.v = (d.v - 1 + d.umod()) % d.umod()
}

func (d DynamicModInt) Add(x DynamicModInt) DynamicModInt {
	return DynamicModInt{
		v:       (d.v + x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt) Sub(x DynamicModInt) DynamicModInt {
	return DynamicModInt{
		v:       (d.v + d.umod() - x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt) Mul(x DynamicModInt) DynamicModInt {
	return DynamicModInt{
		v:       (d.v * x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt) Div(x DynamicModInt) DynamicModInt {
	return DynamicModInt{
		v:       (d.v * x.Inv().v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt) Pow(n int) DynamicModInt {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return DynamicModInt{
			v:       1,
			bt:      d.bt,
			isPrime: d.isPrime,
		}
	}

	x := int64(d.v)
	r := int64(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % d.umod()
		}
		x = x * x % d.umod()
		n >>= 1
	}
	return DynamicModInt{
		v:       r,
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt) Inv() DynamicModInt {
	if d.isPrime {
		if d.v == 0 {
			panic("must be non zero")
		}
		return d.Pow(int(d.umod()) - 2)
	} else {
		g, x := InvGCD(int64(d.v), d.umod())
		if g != 1 {
			panic("g != 1")
		}
		return DynamicModInt{
			v:       x,
			bt:      d.bt,
			isPrime: d.isPrime,
		}
	}
}

type DynamicModInt64 struct {
	v       int64
	bt      Barrett
	isPrime bool
}

func NewDynamicModInt64(v int64) DynamicModInt64 {
	return DynamicModInt64{
		v: int64(v),
	}
}

func (d *DynamicModInt64) SetMod(m int) {
	if m < 1 {
		panic("modulo must be more than 0")
	}
	d.bt = NewBarrett(uint(m))
	d.v %= d.umod()
	d.isPrime = IsPrime(m)
}

func (d DynamicModInt64) umod() int64 {
	return int64(d.bt.Umod())
}

func (d DynamicModInt64) Mod() int64 {
	return int64(d.umod())
}

func (d DynamicModInt64) Val() int64 {
	return int64(d.v)
}

func (d DynamicModInt64) Negate() DynamicModInt64 {
	return DynamicModInt64{
		v:       d.umod() - d.v,
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d *DynamicModInt64) Inc() {
	d.v = (d.v + 1) % d.umod()
}

func (d *DynamicModInt64) Dec() {
	d.v = (d.v - 1 + d.umod()) % d.umod()
}

func (d DynamicModInt64) Add(x DynamicModInt64) DynamicModInt64 {
	return DynamicModInt64{
		v:       (d.v + x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt64) Sub(x DynamicModInt64) DynamicModInt64 {
	return DynamicModInt64{
		v:       (d.v + d.umod() - x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt64) Mul(x DynamicModInt64) DynamicModInt64 {
	return DynamicModInt64{
		v:       (d.v * x.v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt64) Div(x DynamicModInt64) DynamicModInt64 {
	return DynamicModInt64{
		v:       (d.v * x.Inv().v) % d.umod(),
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt64) Pow(n int64) DynamicModInt64 {
	if n < 0 {
		panic("n msut be more than or equal to 0")
	}
	if n == 0 {
		return DynamicModInt64{
			v:       1,
			bt:      d.bt,
			isPrime: d.isPrime,
		}
	}

	x := int64(d.v)
	r := int64(1)
	for 0 < n {
		if n&1 == 1 {
			r = r * x % d.umod()
		}
		x = x * x % d.umod()
		n >>= 1
	}
	return DynamicModInt64{
		v:       r,
		bt:      d.bt,
		isPrime: d.isPrime,
	}
}

func (d DynamicModInt64) Inv() DynamicModInt64 {
	if d.isPrime {
		if d.v == 0 {
			panic("must be non zero")
		}
		return d.Pow(int64(d.umod()) - 2)
	} else {
		g, x := InvGCD(int64(d.v), d.umod())
		if g != 1 {
			panic("g != 1")
		}
		return DynamicModInt64{
			v:       x,
			bt:      d.bt,
			isPrime: d.isPrime,
		}
	}
}

// Code generated by genmaps.go; DO NOT EDIT.

var (
	butterfly1000000007Int_sum_e [30]Mod1000000007Int
)

func init() {
	g := PrimitiveRoot(1000000007) % 1000000007

	var es [30]Mod1000000007Int
	var ies [30]Mod1000000007Int
	cnt2 := BSF(1000000007 - 1)
	e := Mod1000000007Int(g).Pow((1000000007 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod1000000007Int(1)
	for i := 0; i < cnt2; i++ {
		butterfly1000000007Int_sum_e[i] = es[i].Mul(now)
		now = now.Mul(ies[i])
	}
}

func butterfly1000000007Int(a []Mod1000000007Int) {
	n := len(a)
	h := CeilPow2(n)

	for ph := 1; ph <= h; ph++ {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		now := Mod1000000007Int(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p].Mul(now)
				a[i+offset] = l.Add(r)
				a[i+offset+p] = l.Sub(r)
			}
			now = now.Mul(butterfly1000000007Int_sum_e[BSF(^(uint(s)))])
		}
	}
}

var (
	butterflyInv1000000007Int_sum_e [30]Mod1000000007Int
)

func init() {
	g := PrimitiveRoot(1000000007) % 1000000007

	var es [30]Mod1000000007Int
	var ies [30]Mod1000000007Int
	cnt2 := BSF(1000000007 - 1)
	e := Mod1000000007Int(g).Pow((1000000007 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod1000000007Int(1)
	for i := 0; i < cnt2-2; i++ {
		butterflyInv1000000007Int_sum_e[i] = ies[i].Mul(now)
		now = now.Mul(es[i])
	}
}

func butterflyInv1000000007Int(a []Mod1000000007Int) {
	n := len(a)
	h := CeilPow2(n)

	for ph := h; ph >= 1; ph-- {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		inow := Mod1000000007Int(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p]
				a[i+offset] = l.Add(r)
				a[i+offset+p] = Mod1000000007Int(uint64(1000000007+l.Val()-r.Val()) % uint64(1000000007) * uint64(inow.Val()) % uint64(1000000007))
			}
			inow = inow.Mul(butterflyInv1000000007Int_sum_e[BSF(^(uint(s)))])
		}
	}
}

func ConvolutionMod1000000007Int(a, b []Mod1000000007Int) []Mod1000000007Int {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	resize := func(a []Mod1000000007Int, z int) []Mod1000000007Int {
		n := len(a)
		if n < z {
			return append(a, make([]Mod1000000007Int, z-n)...)
		}
		return a[:z]
	}
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]Mod1000000007Int, 0)
	}
	if min(n, m) <= 60 {
		if n < m {
			n, m = m, n
			a, b = b, a
		}
		ans := make([]Mod1000000007Int, n+m-1)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				ans[i+j] = ans[i+j].Add(a[i].Mul(b[j]))
			}
		}
		return ans
	}

	z := 1 << CeilPow2(n+m-1)
	a = resize(a, z)
	butterfly1000000007Int(a)
	b = resize(b, z)
	butterfly1000000007Int(b)
	for i := 0; i < z; i++ {
		a[i] = a[i].Mul(b[i])
	}
	butterflyInv1000000007Int(a)
	resize(a, n+m-1)
	iz := NewMod1000000007Int(int(z)).Inv()
	for i := 0; i < n+m-1; i++ {
		a[i] = a[i].Mul(iz)
	}
	return a
}

func Convolution1000000007Int(a, b []int) []int {
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]int, 0)
	}

	a2 := make([]Mod1000000007Int, n)
	b2 := make([]Mod1000000007Int, m)
	for i := range a {
		a2[i] = NewMod1000000007Int(a[i])
	}
	for i := range b {
		b2[i] = NewMod1000000007Int(b[i])
	}

	c2 := ConvolutionMod1000000007Int(a2, b2)
	c := make([]int, n+m-1)
	for i := 0; i < n+m-1; i++ {
		c[i] = c2[i].Val()
	}
	return c
}

var (
	butterfly998244353Int_sum_e [30]Mod998244353Int
)

func init() {
	g := PrimitiveRoot(998244353) % 998244353

	var es [30]Mod998244353Int
	var ies [30]Mod998244353Int
	cnt2 := BSF(998244353 - 1)
	e := Mod998244353Int(g).Pow((998244353 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod998244353Int(1)
	for i := 0; i < cnt2; i++ {
		butterfly998244353Int_sum_e[i] = es[i].Mul(now)
		now = now.Mul(ies[i])
	}
}

func butterfly998244353Int(a []Mod998244353Int) {
	n := len(a)
	h := CeilPow2(n)

	for ph := 1; ph <= h; ph++ {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		now := Mod998244353Int(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p].Mul(now)
				a[i+offset] = l.Add(r)
				a[i+offset+p] = l.Sub(r)
			}
			now = now.Mul(butterfly998244353Int_sum_e[BSF(^(uint(s)))])
		}
	}
}

var (
	butterflyInv998244353Int_sum_e [30]Mod998244353Int
)

func init() {
	g := PrimitiveRoot(998244353) % 998244353

	var es [30]Mod998244353Int
	var ies [30]Mod998244353Int
	cnt2 := BSF(998244353 - 1)
	e := Mod998244353Int(g).Pow((998244353 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod998244353Int(1)
	for i := 0; i < cnt2-2; i++ {
		butterflyInv998244353Int_sum_e[i] = ies[i].Mul(now)
		now = now.Mul(es[i])
	}
}

func butterflyInv998244353Int(a []Mod998244353Int) {
	n := len(a)
	h := CeilPow2(n)

	for ph := h; ph >= 1; ph-- {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		inow := Mod998244353Int(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p]
				a[i+offset] = l.Add(r)
				a[i+offset+p] = Mod998244353Int(uint64(998244353+l.Val()-r.Val()) % uint64(998244353) * uint64(inow.Val()) % uint64(998244353))
			}
			inow = inow.Mul(butterflyInv998244353Int_sum_e[BSF(^(uint(s)))])
		}
	}
}

func ConvolutionMod998244353Int(a, b []Mod998244353Int) []Mod998244353Int {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	resize := func(a []Mod998244353Int, z int) []Mod998244353Int {
		n := len(a)
		if n < z {
			return append(a, make([]Mod998244353Int, z-n)...)
		}
		return a[:z]
	}
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]Mod998244353Int, 0)
	}
	if min(n, m) <= 60 {
		if n < m {
			n, m = m, n
			a, b = b, a
		}
		ans := make([]Mod998244353Int, n+m-1)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				ans[i+j] = ans[i+j].Add(a[i].Mul(b[j]))
			}
		}
		return ans
	}

	z := 1 << CeilPow2(n+m-1)
	a = resize(a, z)
	butterfly998244353Int(a)
	b = resize(b, z)
	butterfly998244353Int(b)
	for i := 0; i < z; i++ {
		a[i] = a[i].Mul(b[i])
	}
	butterflyInv998244353Int(a)
	resize(a, n+m-1)
	iz := NewMod998244353Int(int(z)).Inv()
	for i := 0; i < n+m-1; i++ {
		a[i] = a[i].Mul(iz)
	}
	return a
}

func Convolution998244353Int(a, b []int) []int {
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]int, 0)
	}

	a2 := make([]Mod998244353Int, n)
	b2 := make([]Mod998244353Int, m)
	for i := range a {
		a2[i] = NewMod998244353Int(a[i])
	}
	for i := range b {
		b2[i] = NewMod998244353Int(b[i])
	}

	c2 := ConvolutionMod998244353Int(a2, b2)
	c := make([]int, n+m-1)
	for i := 0; i < n+m-1; i++ {
		c[i] = c2[i].Val()
	}
	return c
}

var (
	butterfly1000000007Int64_sum_e [30]Mod1000000007Int64
)

func init() {
	g := PrimitiveRoot(1000000007) % 1000000007

	var es [30]Mod1000000007Int64
	var ies [30]Mod1000000007Int64
	cnt2 := BSF(1000000007 - 1)
	e := Mod1000000007Int64(g).Pow((1000000007 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod1000000007Int64(1)
	for i := 0; i < cnt2; i++ {
		butterfly1000000007Int64_sum_e[i] = es[i].Mul(now)
		now = now.Mul(ies[i])
	}
}

func butterfly1000000007Int64(a []Mod1000000007Int64) {
	n := len(a)
	h := CeilPow2(n)

	for ph := 1; ph <= h; ph++ {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		now := Mod1000000007Int64(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p].Mul(now)
				a[i+offset] = l.Add(r)
				a[i+offset+p] = l.Sub(r)
			}
			now = now.Mul(butterfly1000000007Int64_sum_e[BSF(^(uint(s)))])
		}
	}
}

var (
	butterflyInv1000000007Int64_sum_e [30]Mod1000000007Int64
)

func init() {
	g := PrimitiveRoot(1000000007) % 1000000007

	var es [30]Mod1000000007Int64
	var ies [30]Mod1000000007Int64
	cnt2 := BSF(1000000007 - 1)
	e := Mod1000000007Int64(g).Pow((1000000007 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod1000000007Int64(1)
	for i := 0; i < cnt2-2; i++ {
		butterflyInv1000000007Int64_sum_e[i] = ies[i].Mul(now)
		now = now.Mul(es[i])
	}
}

func butterflyInv1000000007Int64(a []Mod1000000007Int64) {
	n := len(a)
	h := CeilPow2(n)

	for ph := h; ph >= 1; ph-- {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		inow := Mod1000000007Int64(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p]
				a[i+offset] = l.Add(r)
				a[i+offset+p] = Mod1000000007Int64(uint64(1000000007+l.Val()-r.Val()) % uint64(1000000007) * uint64(inow.Val()) % uint64(1000000007))
			}
			inow = inow.Mul(butterflyInv1000000007Int64_sum_e[BSF(^(uint(s)))])
		}
	}
}

func ConvolutionMod1000000007Int64(a, b []Mod1000000007Int64) []Mod1000000007Int64 {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	resize := func(a []Mod1000000007Int64, z int) []Mod1000000007Int64 {
		n := len(a)
		if n < z {
			return append(a, make([]Mod1000000007Int64, z-n)...)
		}
		return a[:z]
	}
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]Mod1000000007Int64, 0)
	}
	if min(n, m) <= 60 {
		if n < m {
			n, m = m, n
			a, b = b, a
		}
		ans := make([]Mod1000000007Int64, n+m-1)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				ans[i+j] = ans[i+j].Add(a[i].Mul(b[j]))
			}
		}
		return ans
	}

	z := 1 << CeilPow2(n+m-1)
	a = resize(a, z)
	butterfly1000000007Int64(a)
	b = resize(b, z)
	butterfly1000000007Int64(b)
	for i := 0; i < z; i++ {
		a[i] = a[i].Mul(b[i])
	}
	butterflyInv1000000007Int64(a)
	resize(a, n+m-1)
	iz := NewMod1000000007Int64(int64(z)).Inv()
	for i := 0; i < n+m-1; i++ {
		a[i] = a[i].Mul(iz)
	}
	return a
}

func Convolution1000000007Int64(a, b []int64) []int64 {
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]int64, 0)
	}

	a2 := make([]Mod1000000007Int64, n)
	b2 := make([]Mod1000000007Int64, m)
	for i := range a {
		a2[i] = NewMod1000000007Int64(a[i])
	}
	for i := range b {
		b2[i] = NewMod1000000007Int64(b[i])
	}

	c2 := ConvolutionMod1000000007Int64(a2, b2)
	c := make([]int64, n+m-1)
	for i := 0; i < n+m-1; i++ {
		c[i] = c2[i].Val()
	}
	return c
}

var (
	butterfly998244353Int64_sum_e [30]Mod998244353Int64
)

func init() {
	g := PrimitiveRoot(998244353) % 998244353

	var es [30]Mod998244353Int64
	var ies [30]Mod998244353Int64
	cnt2 := BSF(998244353 - 1)
	e := Mod998244353Int64(g).Pow((998244353 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod998244353Int64(1)
	for i := 0; i < cnt2; i++ {
		butterfly998244353Int64_sum_e[i] = es[i].Mul(now)
		now = now.Mul(ies[i])
	}
}

func butterfly998244353Int64(a []Mod998244353Int64) {
	n := len(a)
	h := CeilPow2(n)

	for ph := 1; ph <= h; ph++ {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		now := Mod998244353Int64(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p].Mul(now)
				a[i+offset] = l.Add(r)
				a[i+offset+p] = l.Sub(r)
			}
			now = now.Mul(butterfly998244353Int64_sum_e[BSF(^(uint(s)))])
		}
	}
}

var (
	butterflyInv998244353Int64_sum_e [30]Mod998244353Int64
)

func init() {
	g := PrimitiveRoot(998244353) % 998244353

	var es [30]Mod998244353Int64
	var ies [30]Mod998244353Int64
	cnt2 := BSF(998244353 - 1)
	e := Mod998244353Int64(g).Pow((998244353 - 1) >> uint(cnt2))
	ie := e.Inv()

	for i := cnt2; i >= 2; i-- {
		es[i-2] = e
		ies[i-2] = ie
		e = e.Mul(e)
		ie = ie.Mul(ie)
	}
	now := Mod998244353Int64(1)
	for i := 0; i < cnt2-2; i++ {
		butterflyInv998244353Int64_sum_e[i] = ies[i].Mul(now)
		now = now.Mul(es[i])
	}
}

func butterflyInv998244353Int64(a []Mod998244353Int64) {
	n := len(a)
	h := CeilPow2(n)

	for ph := h; ph >= 1; ph-- {
		w := 1 << uint(ph-1)
		p := 1 << uint(h-ph)
		inow := Mod998244353Int64(1)
		for s := 0; s < w; s++ {
			offset := s << uint(h-ph+1)
			for i := 0; i < p; i++ {
				l := a[i+offset]
				r := a[i+offset+p]
				a[i+offset] = l.Add(r)
				a[i+offset+p] = Mod998244353Int64(uint64(998244353+l.Val()-r.Val()) % uint64(998244353) * uint64(inow.Val()) % uint64(998244353))
			}
			inow = inow.Mul(butterflyInv998244353Int64_sum_e[BSF(^(uint(s)))])
		}
	}
}

func ConvolutionMod998244353Int64(a, b []Mod998244353Int64) []Mod998244353Int64 {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	resize := func(a []Mod998244353Int64, z int) []Mod998244353Int64 {
		n := len(a)
		if n < z {
			return append(a, make([]Mod998244353Int64, z-n)...)
		}
		return a[:z]
	}
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]Mod998244353Int64, 0)
	}
	if min(n, m) <= 60 {
		if n < m {
			n, m = m, n
			a, b = b, a
		}
		ans := make([]Mod998244353Int64, n+m-1)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				ans[i+j] = ans[i+j].Add(a[i].Mul(b[j]))
			}
		}
		return ans
	}

	z := 1 << CeilPow2(n+m-1)
	a = resize(a, z)
	butterfly998244353Int64(a)
	b = resize(b, z)
	butterfly998244353Int64(b)
	for i := 0; i < z; i++ {
		a[i] = a[i].Mul(b[i])
	}
	butterflyInv998244353Int64(a)
	resize(a, n+m-1)
	iz := NewMod998244353Int64(int64(z)).Inv()
	for i := 0; i < n+m-1; i++ {
		a[i] = a[i].Mul(iz)
	}
	return a
}

func Convolution998244353Int64(a, b []int64) []int64 {
	n := len(a)
	m := len(b)
	if n == 0 || m == 0 {
		return make([]int64, 0)
	}

	a2 := make([]Mod998244353Int64, n)
	b2 := make([]Mod998244353Int64, m)
	for i := range a {
		a2[i] = NewMod998244353Int64(a[i])
	}
	for i := range b {
		b2[i] = NewMod998244353Int64(b[i])
	}

	c2 := ConvolutionMod998244353Int64(a2, b2)
	c := make([]int64, n+m-1)
	for i := 0; i < n+m-1; i++ {
		c[i] = c2[i].Val()
	}
	return c
}

func SafeMod(x, m int64) int64 {
	return int64(C.safe_mod(C.longlong(x), C.longlong(m)))
}

type Barrett struct {
	m  C.uint
	im C.ulonglong
}

func NewBarrett(m uint) Barrett {
	return Barrett{
		m:  C.uint(m),
		im: C.barrett_im(C.uint(m)),
	}
}

func (bt Barrett) Umod() uint {
	return uint(bt.m)
}

func (bt Barrett) Mul(a, b uint) uint {
	return uint(C.barrett_mul(bt.m, bt.im, C.uint(a), C.uint(b)))
}

func PowMod(x, n int64, m int) int64 {
	return int64(C.pow_mod(C.longlong(x), C.longlong(n), C.int(m)))
}

func IsPrime(n int) bool {
	return C.is_prime(C.int(n)) != 0
}

func InvGCD(a, b int64) (int64, int64) {
	var g, x C.longlong
	C.inv_gcd(C.longlong(a), C.longlong(b), &g, &x)
	return int64(g), int64(x)
}

func PrimitiveRoot(m int) int {
	return int(C.primitive_root(C.int(m)))
}

func CeilPow2(n int) int {
	x := uint(0)
	for uint(1<<x) < uint(n) {
		x++
	}
	return int(x)
}

func BSF(n uint) int {
	return bits.TrailingZeros(n)
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

func readberr() ([]byte, error) {
	b, err := nextToken()
	return b[:len(b):len(b)], err
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

func readserr() (string, error) {
	b, err := readberr()
	return string(b), err
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

func readblnerr() ([]byte, error) {
	b, err := nextLine()
	return b[:len(b):len(b)], err
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

func readslnerr() (string, error) {
	b, err := readblnerr()
	return string(b), err
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readllerr() (int64, error) {
	s, err := readserr()
	if err != nil {
		return 0, fmt.Errorf("reading string: %w", err)
	}

	i, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		return 0, fmt.Errorf("parsing int: %w", err)
	}

	return i, nil
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

func readierr() (int, error) {
	i, err := readllerr()
	return int(i), err
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func readferr() (float64, error) {
	s, err := readserr()
	if err != nil {
		return 0, fmt.Errorf("reading string: %w", err)
	}

	f, err := strconv.ParseFloat(s, 64)
	if err != nil {
		return 0, fmt.Errorf("parsing float: %w", err)
	}

	return f, nil
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}