package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 200005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + allPossible)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// x a
			// x b
			// x c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		//fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1426F(in io.Reader, out io.Writer) {
	const mod int64 = 1e9 + 7
	var n int
	var s string
	Fscan(bufio.NewReader(in), &n, &s)
	p3 := make([]int64, n)
	p3[0] = 1
	for i := 1; i < n; i++ {
		p3[i] = p3[i-1] * 3 % mod
	}
	c := int64(strings.Count(s, "c"))
	r := int64(strings.Count(s, "?"))
	var ans, a, l int64
	for _, b := range s {
		if b == 'a' {
			a++
		} else if b == 'c' {
			c--
		} else {
			if b == '?' {
				r--
			}
			ans += a * c % mod * p3[l+r] % mod
			if l > 0 {
				ans += l * c % mod * p3[l-1+r] % mod
			}
			if r > 0 {
				ans += a * r % mod * p3[l+r-1] % mod
			}
			if l > 0 && r > 0 {
				ans += l * r % mod * p3[l+r-2] % mod
			}
			if b == '?' {
				l++
			}
		}
	}
	Fprint(out, ans%mod)
}

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

package main

import (
	"fmt"
)

const mod = 1000000007

func solve(str string) int64 {
	var a int64 = 0
	var ab int64 = 0
	var abc int64 = 0
	var m int64 = 1
	for _, ch := range str {
		// fmt.Println("ch: ", ch)
		if ch == 'a' {
			a = (a + m) % mod
		} else if ch == 'b' {
			ab = (ab + a) % mod
		} else if ch == 'c' {
			abc = (abc + ab) % mod
		} else {
			abc = (3*abc + ab) % mod
			ab = (3*ab + a) % mod
			a = (3*a + m) % mod
			m = (3 * m) % mod
		}
	}
	return abc
}

func main() {
	n, str := 0, ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &str)
	fmt.Println(solve(str))
}

package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 100005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + 1)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// a
			// b
			// c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		//fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 100005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + allPossible)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// x a
			// x b
			// x c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

import (
	"fmt"
)

const mod = 1000000007

func solve(str string) int {
	a, ab, abc, m := 0, 0, 0, 1
	for _, ch := range str {
		// fmt.Println("ch: ", ch)
		if ch == 'a' {
			a = (a + m) % mod
		} else if ch == 'b' {
			ab = (ab + a) % mod
		} else if ch == 'c' {
			abc = (abc + ab) % mod
		} else {
			abc = (3*abc + ab) % mod
			ab = (3*ab + a) % mod
			a = (3*a + m) % mod
			m = (3 * m) % mod
		}
	}
	return abc
}

func main() {
	n, str := 0, ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &str)
	fmt.Println(solve(str))
}


// 436B-mic
package main

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

func main() {
	var hasil [2002]int
	var n, m, k, i, j int
	z := bufio.NewReader(os.Stdin)
	var data [2002]string
	fmt.Scan(&n, &m, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(z, &data[i])
	}
	for i = 0; i < n; i++ {
		for j = 0; j < len(data[i]); j++ {
			if data[i][j] == 'R' {
				if i+j < m {
					hasil[i+j]++
				}
			} else if data[i][j] == 'L' {
				if j-i >= 0 {
					hasil[j-i]++
				}
			} else if data[i][j] == 'U' {
				if i%2 == 0 {
					hasil[j]++
				}
			}
		}
	}
	for i = 0; i < m; i++ {
		fmt.Print(hasil[i])
		fmt.Print(" ")
	}
	fmt.Println()
}

//436B
package main
import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

func main() {
	var n, m, k int
	var move[2005]string
	var x[2005]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	k=k
	for i:=0; i<n; i++ {
		r.Scan()
		move[i] = r.Text()
	}
	for i:=0; i<m; i++ {
		x[i]=0
	}
	for i:=0; i<m; i++ {
		for j:=0; j<n; j++ {
			if i+j<m && string(move[j][i+j])=="L" {
				x[i]++
			}
			if i-j>=0 && string(move[j][i-j])=="R" {
				x[i]++
			}
			if j+j<n && string(move[j+j][i])=="U" {
				x[i]++
			}
		}
	}
	for i:=0; i<m; i++ {
		fmt.Print(x[i], " ")
	}
	fmt.Println()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,k int
    var x [2005]string
    t := [...]byte{'L','R','U'}
    di := [...]int{0,0,1}
    dj := [...]int{1,-1,0}
    ScanInts(&n,&m,&k)
    for i := 0; i < n; i++ {
        scanner.Scan()
        x[i] = scanner.Text()
    }
    for j := 0; j < m; j++ {
        cnt := 0
        for i := 1; i < n; i++ {
            for k := 0; k < 3; k++ {
                ni, nj := i+(di[k]*i), j+(dj[k]*i)
                if (ni >= 0) && (ni < n) && (nj >= 0) && (nj < m) && (x[ni][nj] == t[k]) {
                    cnt++
                }
            }
        }
        writer.WriteString(strconv.Itoa(cnt))
        if j == (m-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,k,i,j int
	var d [2020]int
	var s string
	input := bufio.NewReader(os.Stdin)
	//input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m,&k)
	for i=0;i<n;i++ {
		//input.Scan()
		//s=input.Text()
		fmt.Fscan(input, &s)
		for j=0;j<m;j++ {
			if s[j]=='U' {
				if i%2==0 {
					d[j]++
				}
			} else if s[j]=='L' {
				if (j-i)>=0 {
					d[j-i]++
				}
			} else if s[j]=='R' {
				if j+i<m {
					d[j+i]++
				}
			}

		}
	}
	out := bufio.NewWriter(os.Stdout)
	for i=0;i<m;i++ {
		out.WriteString(strconv.Itoa(d[i])+" ")
	}
	out.Flush()
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m, _ := getI(), getI(), getI()
  counts := make([]int, m)
  for r := 0; r < n; r++ {
    line := getS()
    for c, ch := range line {
      if ch == 'U' {
        if r%2 == 0 {
          counts[c]++
        }
      } else if ch == 'R' {
        if c+r < m {
          counts[c+r]++
        }
      } else if ch == 'L' {
        if c-r >= 0 {
          counts[c-r]++
        }
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d", counts[0]))
  for i := 1; i < m; i++ {
    writer.WriteString(fmt.Sprintf(" %d", counts[i]))
  }
  writer.WriteString("\n")
}

package main

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

func main() {
	var n, m, k, i, j int
	fmt.Scanf("%d %d %d ", &n, &m, &k)
	garden := make([][]byte, n)
	spiders := make([]int64, m)
	for i = 0; i < n; i++ {
		garden[i] = make([]byte, m)
	}
	stdin := bufio.NewReader(os.Stdin)
	for i = 0; i < n; i++ {
		for j = 0; j < m; j++ {
			garden[i][j], _ = stdin.ReadByte()

		}
		_, _ = stdin.ReadByte()
		_, _ = stdin.ReadByte()
	}
	for i = 0; i < n; i++ {
		for j = 0; j < m; j++ {
			if garden[i][j] == 'R' && j+i < m {
				spiders[j+i]++
			} else if garden[i][j] == 'L' && j-i >= 0 {
				spiders[j-i]++
			} else if garden[i][j] == 'U' {
				if i%2 == 0 {
					spiders[j]++
				}
			}
		}
	}
	for i = 0; i < m; i++ {
		fmt.Printf("%d ", spiders[i])
	}
}

package main

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

func main() {
    var n, m, k, i, j int
    fmt.Scanf("%d %d %d ", &n, &m, &k)
    garden := make([][]byte, n)
    spiders := make([]byte, m)
    for i=0; i<n; i++{
        garden[i] = make([]byte, m)
    }
    stdin := bufio.NewReader(os.Stdin)
    for i=0 ; i<n; i++ {
        for j=0 ; j<m ; j++ {
        garden[i][j], _ = stdin.ReadByte()

        }
               _, _ = stdin.ReadByte()
                        _, _ = stdin.ReadByte()
    }

    for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            if garden[i][j] == 'R' && j+i < m {
                spiders[j+i]++
            } else if garden[i][j] == 'L' && j-i >=0{
                spiders[j-i]++
            } else if garden[i][j] == 'U' {
                if i%2 == 0 {
                    spiders[j]++
                }
            }
        }
    }
    for i=0; i<m ; i++ {
        fmt.Printf("%d ", spiders[i])
    }
}

package main

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

func main() {
    var n, m, k, i, j int
    fmt.Scanf("%d %d %d ", &n, &m, &k)
    garden := make([][]byte, n)
    spiders := make([]byte, m)
    for i=0; i<n; i++{
        garden[i] = make([]byte, m)
    }
    stdin := bufio.NewReader(os.Stdin)
    for i=0 ; i<n; i++ {
        for j=0 ; j<m ; j++ {
        garden[i][j], _ = stdin.ReadByte()

        }
               _, _ = stdin.ReadByte()
                        _, _ = stdin.ReadByte()
    }
     for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            fmt.Printf("%c ", garden[i][j])
        }
        fmt.Printf("\n")
    }
    for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            if garden[i][j] == 'R' && j+i < m {
                spiders[j+i]++
            } else if garden[i][j] == 'L' && j-i >=0{
                spiders[j-i]++
            } else if garden[i][j] == 'U' {
                if i%2 == 0 {
                    spiders[j]++
                }
            }
        }
    }
    for i=0; i<m ; i++ {
        fmt.Printf("%d ", spiders[i])
    }
}


// http://codeforces.com/contest/667/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var d, h, v, e float64

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &d, &h, &v, &e)
	rs := d * d / 4

	se := math.Pi * rs * e
	sh := math.Pi * rs * h

	if se >= v {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	fmt.Println(sh / (v - se))
}

package main

import "fmt"
import "math"

func main() {
    var d,h,e,v,t float64
    fmt.Scan(&d,&h,&v,&e)
    v=v*4/(d*d*math.Pi)
    t=-h/(e-v)
    if t<10000 && t>0 {
        fmt.Println("YES")
        fmt.Println(t)
    } else {
        fmt.Println("NO")
    }
}

package main

import (
	"fmt"
	"math"
)

func mlToCm(d, v float64) float64 {
	return v / ((d * d / 4) * math.Pi)
}

func main() {
	var d, h, v, e float64
	fmt.Scan(&d, &h, &v, &e)
	velocity := e - mlToCm(d, v)
	if velocity >= 0 {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	fmt.Println(-1 * h/velocity)
}

package main

import (
	"fmt"
	"math"
)

var pi float32

func main() {
	pi = float32(math.Acos(float64(-1.0)))
	var d, h, v, e float32
	fmt.Scanln(&d, &h, &v, &e)
	incV := f(d/2.0, e)
	if incV >= v {
		fmt.Println("NO")
		return
	}
	ans := f(d/2.0, h) / (v - incV)
	fmt.Println("YES")
	fmt.Println(ans)
}

func f(r, h float32) (V float32) {
	V = r * r * pi * h
	return
}

package main

import "fmt"

const pi float32 = 3.1415926

func main() {
	var d, h, v, e float32
	fmt.Scanln(&d, &h, &v, &e)
	incV := f(d/2, e)
	if incV >= v {
		fmt.Println("NO")
		return
	}
	ans := f(d/2, h) / (v - incV)
	fmt.Println(ans)
}

func f(r, h float32) (V float32) {
	V = r * r * pi * h
	return
}