Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.

The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement. Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Print the only integer s — the value g(n)(x) modulo 109 + 7.

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a, b},
		[]int64{0, 1},
	}

	AK := powMat(A, n, MOD)

	ans := AK[0][0] * x
	ans %= MOD
	ans += AK[0][1]
	ans %= MOD
	fmt.Println(ans)
}

// ↓でもいい
// func main() {
// 	a, b, n, x = ReadInt64_4()

// 	A := [][]int64{
// 		[]int64{a + 1, NegativeMod(-a, MOD)},
// 		[]int64{1, 0},
// 	}

// 	AK := powMat(A, n-1, MOD)

// 	ans := int64(0)

// 	big := (a*x + b) % MOD
// 	big *= AK[0][0]
// 	ans += big
// 	ans %= MOD

// 	sml := AK[0][1]
// 	sml *= x
// 	sml %= MOD
// 	ans += sml
// 	ans %= MOD

// 	fmt.Println(ans)
// }

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF678D(in io.Reader, out io.Writer) {
	const p int64 = 1e9 + 7
	pow := func(x, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % p
			}
			x = x * x % p
		}
		return res
	}

	var a, b, n, x int64
	Fscan(in, &a, &b, &n, &x)
	if an := pow(a, n); a == 1 {
		Fprint(out, (an*x+n%p*b)%p)
	} else {
		Fprint(out, (an*x+(an-1)%p*pow(a-1, p-2)%p*b)%p)
	}
}

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

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

// ↓でもいい
func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a + 1, NegativeMod(-a, MOD)},
		[]int64{1, 0},
	}

	AK := powMat(A, n-1, MOD)

	ans := int64(0)

	big := (a*x + b) % MOD
	big *= AK[0][0]
	ans += big
	ans %= MOD

	sml := AK[0][1]
	sml *= x
	sml %= MOD
	ans += sml
	ans %= MOD

	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	// A := [][]int64{
	// 	[]int64{a + 1, -a},
	// 	[]int64{1, 0},
	// }
	A := [][]int64{
		[]int64{a + 1, NegativeMod(-a, MOD)},
		[]int64{1, 0},
	}

	AK := powMat(A, n-1, MOD)

	ans := int64(0)

	big := (a*x + b) % MOD
	big *= AK[0][0]
	ans += big
	ans %= MOD

	sml := AK[0][1]
	sml *= x
	sml %= MOD
	ans += sml
	ans %= MOD

	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a + 1, -a},
		[]int64{1, 0},
	}
	// A := [][]int64{
	// 	[]int64{a + 1, NegativeMod(-a, MOD)},
	// 	[]int64{1, 0},
	// }

	AK := powMat(A, n-1, MOD)

	// ans := AK[0][0]*(a*x+b) + AK[0][1]*x
	// ans %= MOD

	ans := int64(0)
	ans += AK[0][0] * (a*x + b)
	ans = NegativeMod(ans, MOD)
	ans += AK[0][1] * x
	ans = NegativeMod(ans, MOD)
	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a + 1, -a},
		[]int64{1, 0},
	}
	// A := [][]int64{
	// 	[]int64{a + 1, NegativeMod(-a, MOD)},
	// 	[]int64{1, 0},
	// }

	AK := powMat(A, n-1, MOD)

	ans := int64(0)

	big := (a*x + b) % MOD
	big *= AK[0][0]
	ans += big
	ans %= MOD

	sml := AK[0][1]
	sml *= x
	sml %= MOD
	ans += sml
	ans %= MOD

	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	// A := [][]int64{
	// 	[]int64{a + 1, -a},
	// 	[]int64{1, 0},
	// }
	A := [][]int64{
		[]int64{a + 1, NegativeMod(-a, MOD)},
		[]int64{1, 0},
	}

	AK := powMat(A, n-1, MOD)

	// ans := AK[0][0]*(a*x+b) + AK[0][1]*x
	// ans %= MOD

	ans := int64(0)
	ans += AK[0][0] * (a*x + b)
	ans = NegativeMod(ans, MOD)
	ans += AK[0][1] * x
	ans = NegativeMod(ans, MOD)
	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a + 1, -a},
		[]int64{1, 0},
	}

	AK := powMat(A, n-1, MOD)

	ans := AK[0][0]*(a*x+b) + AK[0][1]*x
	ans %= MOD
	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	A := [][]int64{
		[]int64{a + 1, -a},
		[]int64{1, 0},
	}
	// A := [][]int64{
	// 	[]int64{a + 1, NegativeMod(-a, MOD)},
	// 	[]int64{1, 0},
	// }

	AK := powMat(A, n-1, MOD)

	ans := AK[0][0]*(a*x+b) + AK[0][1]*x
	// ans %= MOD
	ans = NegativeMod(ans, MOD)
	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}

/*
URL:
https://codeforces.com/problemset/problem/678/D
*/

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 (
	a, b, x, n int64
)

func main() {
	a, b, n, x = ReadInt64_4()

	// A := [][]int64{
	// 	[]int64{a + 1, -a},
	// 	[]int64{1, 0},
	// }
	A := [][]int64{
		[]int64{a + 1, NegativeMod(-a, MOD)},
		[]int64{1, 0},
	}

	AK := powMat(A, n-1, MOD)

	ans := AK[0][0]*(a*x+b) + AK[0][1]*x
	ans %= MOD
	fmt.Println(ans)
}

// NegativeMod can calculate a right residual whether value is positive or negative.
func NegativeMod(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// n*nのint型正方行列を生成する
func newMat(n int64) [][]int64 {
	var i int64

	A := make([][]int64, n)
	for i = 0; i < n; i++ {
		A[i] = make([]int64, n)
	}

	return A
}

// 行列A, Bに関するA*Bの計算
func mul(A, B [][]int64, mod int64) [][]int64 {
	var i, j, k int64
	var lenA, lenB, lenB0 int64
	lenA = int64(len(A))
	lenB = int64(len(B))
	lenB0 = int64(len(B[0]))

	C := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		C[i] = make([]int64, lenB0)
	}

	for i = 0; i < lenA; i++ {
		for k = 0; k < lenB; k++ {
			for j = 0; j < lenB0; j++ {
				C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod
			}
		}
	}

	return C
}

// 行列Aに関するA^nの計算
func powMat(A [][]int64, n, mod int64) [][]int64 {
	var i int64
	var lenA int64
	lenA = int64(len(A))

	B := make([][]int64, lenA)
	for i = 0; i < lenA; i++ {
		B[i] = make([]int64, lenA)
	}

	for i = 0; i < lenA; i++ {
		B[i][i] = 1
	}
	for n > 0 {
		if n&1 == 1 {
			B = mul(B, A, mod)
		}
		A = mul(A, A, mod)
		n = (n >> 1)
	}

	return B
}

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

/*********** 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...)
}


Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $$$1$$$, $$$5$$$, $$$10$$$ and $$$50$$$ respectively. The use of other roman digits is not allowed.Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.For example, the number XXXV evaluates to $$$35$$$ and the number IXI — to $$$12$$$.Pay attention to the difference to the traditional roman system — in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means $$$11$$$, not $$$9$$$.One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly $$$n$$$ roman digits I, V, X, L.

The only line of the input file contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of roman digits to use.

Output a single integer — the number of distinct integers which can be represented using $$$n$$$ roman digits exactly.

NoteIn the first sample there are exactly $$$4$$$ integers which can be represented — I, V, X and L.In the second sample it is possible to represent integers $$$2$$$ (II), $$$6$$$ (VI), $$$10$$$ (VV), $$$11$$$ (XI), $$$15$$$ (XV), $$$20$$$ (XX), $$$51$$$ (IL), $$$55$$$ (VL), $$$60$$$ (XL) and $$$100$$$ (LL).

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var v []int64 = []int64{0,4,10,20,35,56,83,116,155,198,244,292}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int64
	fmt.Fscanf(reader, "%d", &n)

	if int(n) < len(v) {
		fmt.Printf("%d", v[n])
	} else {
		fmt.Printf("%d", 49 * (n - int64(len(v)) + 1) + v[len(v) - 1])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF997B(in io.Reader, out io.Writer) {
	a := [...]int{0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244}
	var n int64
	Fscan(in, &n)
	if n < 11 {
		Fprint(out, a[n])
	} else {
		Fprint(out, 49*n-247)
	}
}

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


Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.

NoteIn the second sample Fafa has 3 ways:  choose only 1 employee as a team leader with 9 employees under his responsibility.  choose 2 employees as team leaders with 4 employees under the responsibility of each of them.  choose 5 employees as team leaders with 1 employee under the responsibility of each of them.

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	fact := make([]int, 0)
	count := 0
	for n%2 == 0 {
		count++
		n /= 2
	}
	fact = append(fact, count)
	count = 0
	for i := 3; n > 1; i += 2 {
		for n%i == 0 {
			n /= i
			count++
		}
		if count > 0 {
			fact = append(fact, count)
			count = 0
		}
	}
	ans := 1
	for i := 0; i < len(fact); i++ {
		ans *= (fact[i] + 1)
	}
	fmt.Println(ans - 1)
}

// A. Fafa and his Company
/*
Fafa owns a company that works on huge projects. There are n employees
in Fafa's company. Whenever the company has a new project to start working on,
Fafa has to divide the tasks of this project among all the employees.

Fafa finds doing this every time is very tiring for him. So,
he decided to choose the best l employees in his company as team leaders.
Whenever there is a new project, Fafa will divide the tasks among only
the team leaders and each team leader will be responsible of some positive
number of employees to give them the tasks. To make this process fair
for the team leaders, each one of them should be responsible for the same
number of employees. Moreover, every employee, who is not a team leader,
has to be under the responsibility of exactly one team leader,
and no team leader is responsible for another team leader.

Given the number of employees n, find in how many ways Fafa could choose
the number of team leaders l in such a way that it is possible to divide
employees between them evenly.

Input

The input consists of a single line containing a positive integer
n (2 ≤ n ≤ 105) — the number of employees in Fafa's company.

Output

Print a single integer representing the answer to the problem.

Examples
Input
2

Output
1

Input
10

Output
3

Note
In the second sample Fafa has 3 ways:

    choose only 1 employee as a team leader with 9 employees under his responsibility.
    choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
    choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()
	in, _ := strconv.Atoi(string(input))
	sol935A(in)
}

func sol935A(in int) {
	count := 0
	for i := 1; i < in; i++ {
		if in%i == 0 {
			count++
		}
	}
	fmt.Print(count)
}

// A. Fafa and his Company
/*
Fafa owns a company that works on huge projects. There are n employees
in Fafa's company. Whenever the company has a new project to start working on,
Fafa has to divide the tasks of this project among all the employees.

Fafa finds doing this every time is very tiring for him. So,
he decided to choose the best l employees in his company as team leaders.
Whenever there is a new project, Fafa will divide the tasks among only
the team leaders and each team leader will be responsible of some positive
number of employees to give them the tasks. To make this process fair
for the team leaders, each one of them should be responsible for the same
number of employees. Moreover, every employee, who is not a team leader,
has to be under the responsibility of exactly one team leader,
and no team leader is responsible for another team leader.

Given the number of employees n, find in how many ways Fafa could choose
the number of team leaders l in such a way that it is possible to divide
employees between them evenly.

Input

The input consists of a single line containing a positive integer
n (2 ≤ n ≤ 105) — the number of employees in Fafa's company.

Output

Print a single integer representing the answer to the problem.

Examples
Input
2

Output
1

Input
10

Output
3

Note
In the second sample Fafa has 3 ways:

    choose only 1 employee as a team leader with 9 employees under his responsibility.
    choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
    choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()
	in, _ := strconv.Atoi(string(input))
	sol935A(in)
}

func sol935A(in int) {
	count := 0
	for i := 1; i <= in/2; i++ {
		if in%i == 0 {
			count++
		}
	}
	fmt.Print(count)
}

package main

import "fmt"

func main()  {
	var n int
	fmt.Scan(&n)
	d := 0
	for i:=2 ; i<=n; i++{
		if (n%i==0){
			d++
		}
	}
	fmt.Println(d)
}

package main

import "fmt"

func main() {
	cnt := 0
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n/2; i++ {
		if (n-i)%i == 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var count = 0
	_, _ = fmt.Scan(&n)
	for i := 1; i < n; i++ {
		if (n - i) % i == 0 {
			count ++
		}
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	cnt := 0
	for i := 1; i <= n/2; i++ {
		if (n-i)%i == 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

package main

import "fmt"

func main(){
	var a int
        var itog int
	fmt.Scan(&a)
	for i := 2; i <= a; i++ {
		if a % i == 0 {
		    itog +=1
		}
	}
	fmt.Println(itog)
}

package main

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

func solve() {
	n := readInt()
	cnt := 0
	for i := 1; i < n; i++ {
		if (n % i) == 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

var scanner *bufio.Scanner

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

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

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

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

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	cnt := 0
	for i:=2; i<=n; i++ {
		if (n%i==0) {
			cnt++
		};
	}
	fmt.Println(cnt);
}

package main

import "fmt"

func main() {
	var n int
	k := 0
	k1 := 1
	fmt.Scan(&n)
	for k1 != n {
		if (n-k1)%k1 == 0 && k1 != n {
			k++
			//fmt.Println((n-k1), (n-k1)%k1)
		}
		k1++
	}
	fmt.Println(k)
}

package main

import (
	"fmt"
)

func main() {

	var n int
	fmt.Scanf("%d\n", &n)

	count := 0
	for i := 1; i <= n/2; i += 1 {
		if (n - i) % i ==0 {
			count+=1
		}
	}
	fmt.Print(count)
}

package main

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

func Employee(number int) int {
	var array []int
	for i:=1;i<=number/2;i++ {
		if number % i == 0 {
			array = append(array,i)
		}
	}
	return len(array)
}

func main() {
	var number int
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text =  strings.TrimRight(text,"\r\n")
	number,_ = strconv.Atoi(text)
	fmt.Println(Employee(number))
}

package main

import (
	"fmt"
	"log"
	"math"
)

func main() {
	var input int
	_, err := fmt.Scanf("%d", &input)

	//validate input
	if err != nil {
		log.Fatal(err)
		return
	}

	if input < 2 || float64(input) > math.Pow10(5) {
		fmt.Println("input out of range")
		return
	}

	count := 1

	for numberOfLeaders := 2; numberOfLeaders <= input/2; numberOfLeaders ++ {
		if input % numberOfLeaders == 0 {
			count += 1
		}
	}

	fmt.Println(count)
}

//A. Фафа и его компания
package main

import (
	"fmt"
)

func main() {
	var n, rez int

	fmt.Scan(&n)

	for i := 2; i <= n; i++ {
		if n%i == 0 {
			rez++
		}
	}

	fmt.Println(rez)
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = true

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := gsli(reader)[0]

	ways := 0
	for i := 1; i <= 50000; i++ {
		if (n-i)%i == 0 && n-i > 0 {
			ways++
		}
	}

	fmt.Printf("%v", ways)

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

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

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

package main

import "fmt"

func main(){
	var n, cnt int
	fmt.Scan(&n)
	for i := 2; i <= n; i++ {
		if n % i == 0 {
			cnt ++
		}
	}
	fmt.Println(cnt)
}

        package main

        import "fmt"

        func main() {
        	var numOfEmployee int
        	fmt.Scan(&numOfEmployee)
        	var count int = 0
        	for i :=1; i <= numOfEmployee/2; i++ {
        		res := numOfEmployee - i
        		if res % i == 0 {
        			count++
        		}
        	}
        	fmt.Println(count)
        }

    package main

    import (
    	"fmt"
    )

    func main() {
    	var numOfEmployee int
    	fmt.Scan(&numOfEmployee)
    	var count int = 0
    	for i :=1; i <= numOfEmployee/2; i++ {
    		res := numOfEmployee - i
    		if res % i == 0 {
    			count++
    		}
    	}
    	fmt.Println(count)
    }

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint32
	var c uint32 = 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 1; uint32(i) <= n/2; i++ {
		if (n-uint32(i))%uint32(i) == 0 {
			c++
		}
	}
	fmt.Println(c)
}

package main

import "fmt"

func main(){
	var n int
        var res int
	fmt.Scan(&n)
	for i := 2; i <= n; i++ {
		if n % i == 0 {
		    res +=1
		}
	}
	fmt.Println(res)
}

package main

import "fmt"

func main() {
	var n int
	var count int = 0
	fmt.Scan(&n)
	for i := 1; i < (n/2)+1; i++ {
		if n%i == 0 {
			count += 1
		}
	}
	fmt.Print(count)
}

package main

import "fmt"

func main()  {
	var n int
	fmt.Scanln(&n)
	ans := 0
	for i := 1; i < n; i++ {
		if n % i == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)
func main() {
	var t,num int
	fmt.Scan(&t)
	for i:=1;i<t;i++{
		if(t-i)%i==0{
			num++
		}
	}
	fmt.Printf("%d",num)

}

package main

import (
	"fmt"
)

func main()  {
	var num_of_employee int
	fmt.Scan(&num_of_employee)
	count :=0

	for i:=2; i <= num_of_employee; i++{
		if num_of_employee%i ==0{
			count+=1
		}

	}
	fmt.Println(count)
}

package main

import "fmt"

func main(){
	var n int
	var co int = 0
	fmt.Scanln(&n)
	for i := 1; i < n; i++{
		if n%i == 0{
			co++
		}
	}
	fmt.Print(co,"\n")
}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scan(&n)
	max := n / 2
	cnt := 0
	for i:=1; i<=max; i++ {
		if (n-i) % i == 0 {cnt++}
	}
	fmt.Println(cnt)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    cnt := 0
    for i:=1; i<n; i++ {
        if n % i == 0 {
            cnt++
        }
    }
    fmt.Print(cnt)
}

package main

import (
	"fmt"
	"log"
)

func main() {
	var num int
	_, err := fmt.Scanf("%d\n", &num)
	if err != nil {
		log.Fatal(err)
	}
	var count int = 0
	for i :=1; i <= num/2; i++ {
		res := num - i
		if res % i == 0 {
			count++
		}
	}
	fmt.Println(count)
}

package main

import (
	"fmt"
)

func main() {
	var num int
	fmt.Scan(&num)
	var count int = 0
	for i :=1; i <= num/2; i++ {
		res := num - i
		if res % i == 0 {
			count++
		}
	}
	fmt.Println(count)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var count = 0
	fmt.Scan(&n)
	for i := 1; i < n; i++ {
		if (n-i)%i == 0 {
			count++
		}
	}
	fmt.Println(count)
}

package main

import "fmt"

var x, res int

func main() {
	fmt.Scanf("%d", &x)
	i := 1
	for i <= x / 2 {
		if x % i == 0 {
			res++
		}
		i++
	}
	fmt.Println(res)
}

package main

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

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

	var n uint64
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Println(fafaAndHisCompany(n))
}

func fafaAndHisCompany(n uint64) uint64 {
	var count uint64
	var i uint64 = 1
	for (n-i)/i > 0 {
		if (n-i)%i == 0 {
			count++
		}
		i++
	}

	return count
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var k int

	fmt.Scan(&n)

	for i := 1; i <= n-i; i++ {
		if (n-i)%i == 0 {
			k++
		}
	}

	fmt.Println(k)
}

package main

import (
	"fmt"
)

func main() {
	rs := 1
	n := 0
	fmt.Scan(&n)
	for i := 2; i < n; i++ {
		if n%i == 0 {
			rs++
		}
	}
	fmt.Print(rs)
}

// cf935a project main.go
package main

import (
	"fmt"
)

func main() {
	var n, c int
	fmt.Scan(&n)
	for i := 2; i <= n/2; i++ {
		if n%i == 0 {
			c++
		}
	}
	c++
	fmt.Println(c)
}

package main
import "fmt"
func main() {
    var n, ruk, yes int
    yes = 1
    fmt.Scan(&n)
    for ruk = 2; ruk <= n/2; ruk++{
        if (n - ruk) % ruk == 0{
            yes++
        }
    }
    fmt.Print(yes)
}

package main
import "fmt"

func main(){
	var n,count,i int64
	fmt.Scan(&n)
	count=0
	for i=1 ; i<n; i++{
		if (n-i)%i == 0{
			count++
		}
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	cnt := 0
	for i:=2; i<=n; i++ {
		if (n%i==0) {
			cnt++
		};
	}
	print(cnt);
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var c uint16 = 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 1; uint16(i) <= n/2; i++ {
		if (n-uint16(i))%uint16(i) == 0 {
			c++
		}
	}
	fmt.Println(c)
}


IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.

The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the prediction on the number of people who will buy the game.

Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.

package main
import "fmt"
func main() {
    var a int64
    fmt.Scanf("%d", &a)
    fmt.Println(a / 2520)
}

package main

import "fmt"

func main() {
  var n int64
  fmt.Scan(&n)
  fmt.Println(n / 2520)
}

//
//
package main

import (
	"fmt"
	"os"
)

const LCM int64 = 2520

func main() {
	var n int64
	if _, err := fmt.Scanf("%d", &n); err != nil {
		fmt.Println("Error: Scanf:", err)
		os.Exit(1)
	}

	fmt.Println(n / LCM)
}

package main

import (
	"fmt"
)

func main() {
	x := int64(8 * 9 * 5 * 7)
	var n int64
	fmt.Scan(&n)
	fmt.Println(n / x)
}

package main
import "fmt"
func main() {
    var a int
    fmt.Scanf("%a", &a)
    fmt.Println(a / 2520)
}

package main
import "fmt"
func main() {
    var a int
    fmt.Scanf("%d", &a)
    fmt.Println(a / 2520)
}

package main
import "fmt"
func main() {
    var a int64
    fmt.Scanf("%lld", &a)
    fmt.Println(a / 2520)
}

package main

import (
	"fmt"
)

func main() {
	x := int64(8 * 9 * 5 * 7)
	var n int64
	fmt.Scan(&n)
	var i = int64(0)

	for ; i*x < n; i = i*i + 1 {
	}

	for ; i*x > n; i /= 2 {
	}

	for ; i*x < n; i++ {
	}
	fmt.Println(i - 1)
}


Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.

You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won.

Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.

package main

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

func winpos(table [][]byte, sx, sy, dx, dy int) bool {
	x, y := sx, sy
	i := 0
	for i < 5 {
	    if  x>=10 || y>=10 || x<0 || y<0{
	        return false
	    }

		if table[x][y]!='X' {
			return false
		}

		x += dx
		y += dy

		i++
	}

	return true
}

func win(table [][]byte) bool {
	for i := 0; i < 10; i++ {
		for j := 0;j < 10; j++ {
			if winpos(table, i, j, 0, 1) || winpos(table, i, j, 1, 0) || winpos(table, i, j, 1, 1) || winpos(table,i,j,1,-1) {
				return true
			}
		}
	}

	return false
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
	table := make([][]byte,  10)
	for i := 0; i < 10; i++ {
		table[i], _, _ = stdin.ReadLine()

	}

	for i := 0; i < 10; i++ {
		for j := 0;j < 10; j++ {
			if table[i][j]=='.' {
				table[i][j]='X'
				if win(table) {
					fmt.Println("YES")
					os.Exit(0)
				}

				table[i][j]='.'
			}
		}
	}

	fmt.Println("NO")
	os.Exit(0)
}

package main

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

func winpos(table [][]byte, sx, sy, dx, dy int) bool {
	x, y := sx, sy
	i := 0
	for i < 5 {
	    if  x>=10 || y>=10 {
	        return false
	    }

		if table[x][y]!='X' {
			return false
		}

		x += dx
		y += dy

		i++
	}

	return true
}

func win(table [][]byte) bool {
	for i := 0; i < 10; i++ {
		for j := 0;j < 10; j++ {
			if winpos(table, i, j, 0, 1) || winpos(table, i, j, 1, 0) || winpos(table, i, j, 1, 1) {
				return true
			}
		}
	}

	return false
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
	table := make([][]byte,  10)
	for i := 0; i < 10; i++ {
		table[i], _, _ = stdin.ReadLine()

	}

	for i := 0; i < 10; i++ {
		for j := 0;j < 10; j++ {
			if table[i][j]=='.' {
				table[i][j]='X'
				if win(table) {
					fmt.Println("YES")
					os.Exit(0)
				}

				table[i][j]='.'
			}
		}
	}

	fmt.Println("NO")
	os.Exit(0)
}


Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:  the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;  the triangle formed by point A, B and C is rectangular and isosceles ( is right);  all points of the favorite rectangle are located inside or on the border of triangle ABC;  the area of triangle ABC is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique.

The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).

Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.

package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	if x < 0 {
		if y < 0 {
			fmt.Println(x+y, 0, 0, x+y)
		} else {
			fmt.Println(x-y, 0, 0, y-x)
		}
	} else {
		if y < 0 {
			fmt.Println(0, y-x, x-y, 0)
		} else {
			fmt.Println(0, x+y, x+y, 0)
		}
	}
}

package main
import (
	"fmt"
	//"unicode/utf8"
)

func main() {
	var a,b int64
	fmt.Scan(&a,&b)
	if a>0 && b>0 {
		fmt.Print("0 ",a+b,a+b," 0")
		fmt.Println()
	} else if a<0 && b>0 {
		fmt.Print(a-b," 0 ","0 ",b-a)
		fmt.Println()
	} else if a<0 && b<0 {
		fmt.Print(a+b," 0 ","0 ",a+b)
		fmt.Println()
	} else if a>0 && b<0 {
	        fmt.Print("0 ",b-a,a-b," 0")
	        fmt.Println()
	}

}

package main

import (
	"fmt"
)

func main() {
	var x, y, gradient, c int64

	fmt.Scan(&x, &y)

	gradient = x*y/abs(x*y)
	c = y + gradient*x

	if x < 0 {
		fmt.Println(-abs(c), 0, 0, c)
	} else {
		fmt.Println(0, c, abs(c), 0)
	}
}

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

package main

import "fmt"

func main() {
    var x,y int
    fmt.Scan(&x,&y)
    if x < 0 {
        if y < 0 {
            fmt.Println(x+y,0,0,x+y)
        } else {
            fmt.Println(x-y,0,0,-(x-y))
        }
    } else {
        if y < 0 {
            fmt.Println(0,-(x-y),x-y,0)
        } else {
            fmt.Println(0,x+y,x+y,0)
        }
    }
}

package main
import (
	"fmt"
	//"unicode/utf8"
)

func main() {
	var a,b int64 //input
	fmt.Scan(&a,&b)
	if a>0 && b>0 {
		fmt.Print("0 ",a+b,a+b," 0")
		fmt.Println()
	} else if a<0 && b>0 {
		fmt.Print(a-b," 0 ","0 ",b-a)
		fmt.Println()
	} else if a<0 && b<0 {
		fmt.Print(a+b," 0 ","0 ",a+b)
		fmt.Println()
	} else if a>0 && b<0 {
	        fmt.Print("0 ",b-a,a-b," 0")
	        fmt.Println()
	}

}

// 336A
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a, &b)
	x := a+b
	y:= a-b
	if a>0{
		if b>0{
			fmt.Println(0,x,x,0)
		}else{
			fmt.Println(0,-y,y,0)
		}
	} else{
		if b>0{
			fmt.Println(y,0,0,-y)
		}else{
			fmt.Println(x,0,0,x)
		}
	}

}

// 258A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var i, k float64
    fmt.Scan(&i, &k)
    t := int64(math.Abs(math.Abs(i) + math.Abs(k)))
    if i > 0 && k > 0 {
        fmt.Printf("0 %d %d 0\n", t, t)
    } else if i > 0 && k < 0 {
        fmt.Printf("0 %d %d 0\n", -t, t)
    } else if i < 0 && k > 0 {
        fmt.Printf("%d 0 0 %d\n", -t, t)
    } else {
        fmt.Printf("%d 0 0 %d\n", -t, -t)
    }
}

package main
import (
	"fmt"
	//"unicode/utf8"
)

func main() {
	var a,b int64
	fmt.Scan(&a,&b)
	if a>0 && b>0 {
		fmt.Print("0 ",a+b,a+b," 0")
		fmt.Println()
	} else if a<0 && b>0 {
		fmt.Print(a-b,"0 ","0 ",b-a)
		fmt.Println()
	} else if a<0 && b<0 {
		fmt.Print(a+b,"0 ","0 ",a+b)
		fmt.Println()
	} else if a>0 && b<0 {
	        fmt.Print("0 ",b-a,a-b," 0")
	        fmt.Println()
	}

}

package main

import (
	"fmt"
)

func main() {
	var x, y, gradient, c int

	fmt.Scan(&x, &y)

	gradient = x*y/abs(x*y)
	c = y + gradient*x

	if x < 0 {
		fmt.Println(-abs(c), 0, 0, c)
	} else {
		fmt.Println(0, c, abs(c), 0)
	}
}

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

// 336A
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a, &b)
	x := a+b
	y:= a-b
	if x>0{
		if y>0{
			fmt.Println(0,x,x,0)
		}else{
			fmt.Println(0,-y,y,0)
		}
	} else{
		if y>0{
			fmt.Println(y,0,0,-y)
		}else{
			fmt.Println(x,0,0,x)
		}
	}

}

// 258A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var i, k int
    fmt.Scan(&i, &k)
    t := int64(math.Abs(float64(i + k)))
    if i > 0 && k > 0 {
        fmt.Printf("0 %d %d 0\n", t, t)
    } else if i > 0 && k < 0 {
        fmt.Printf("0 %d %d 0\n", -t, t)
    } else if i < 0 && k > 0 {
        fmt.Printf("%d 0 0 %d\n", -t, t)
    } else {
        fmt.Println("%d 0 0 %d\n", -t, -t)
    }
}

// 258A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var i, k float64
    fmt.Scan(&i, &k)
    t := int64(math.Abs(math.Abs(i) + math.Abs(k)))
    if i > 0 && k > 0 {
        fmt.Printf("0 %d %d 0\n", t, t)
    } else if i > 0 && k < 0 {
        fmt.Printf("0 %d %d 0\n", -t, t)
    } else if i < 0 && k > 0 {
        fmt.Printf("%d 0 0 %d\n", -t, t)
    } else {
        fmt.Println("%d 0 0 %d\n", -t, -t)
    }
}