import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

fun String.words() = split(" ")

fun String.toInts() = split(" ").map { it.toInt() }
fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val s = input.readLine()

    fun Char.toIndex() = this - 'A'

    val letterCount = IntArray(26)
    var wildcardsCount = 0
    var missingLetters = 26

    for (i in s.indices) {
        val c = s[i]
        when (c) {
            '?' -> ++wildcardsCount
            in 'A'..'Z' -> {
                if (letterCount[c.toIndex()] == 0)
                    --missingLetters
                ++letterCount[c.toIndex()]
            }
        }

        if (i >= 26) {
            val q = s[i - 26]
            when (q) {
                '?' -> --wildcardsCount
                in 'A'..'Z' -> {
                    if (letterCount[q.toIndex()] == 1)
                        ++missingLetters
                    --letterCount[q.toIndex()]
                }
            }
        }

        if (i >= 25 && missingLetters <= wildcardsCount) {
            val missingLettersList = letterCount.indices.filter { letterCount[it] == 0 }.map { 'A' + it }
            var currentMissingLetterIndex = 0
            val answer = s.toCharArray()
            for (j in answer.indices) {
                if (answer[j] == '?') {
                    if (j in (i - 25..i)) {
                        answer[j] = missingLettersList.getOrElse(currentMissingLetterIndex) { 'A' }
                        ++currentMissingLetterIndex
                    } else
                        answer[j] = 'A'
                }
            }
            output.println(String(answer))
            return
        }
    }

    output.println("-1")
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(vararg params: String) {
    val br = BufferedReader(InputStreamReader(System.`in`))

    val string = br.readLine().toList()

    if (string.size < 26) {
        println(-1)
        return
    }

    val countOfLetters = IntArray(26)
    fun Char.put() {
        if (this != '?')
            countOfLetters[toInt() - 65]++
    }

    fun Char.remove() {
        if (this != '?')
            countOfLetters[toInt() - 65]--
    }

    fun isOnlyOneOrZero() = countOfLetters.all { it < 2 }

    var begin = 0
    fun end() = begin + 25

    for (i in begin..end() - 1) {
        string[i].put()
    }

    while (end() < string.size) {
        string[end()].put()
        if (isOnlyOneOrZero()) {
            val sublist = processMissing(string.subList(begin, end() + 1))

            val fullString = string.subList(0, begin) + sublist + string.subList(end() + 1, string.size)

            println(fullString.map { if (it == '?') 'X' else it }.joinToString(separator = "") { "$it" })

            return
        }
        string[begin].remove()
        begin++
    }

    println(-1)

}

fun processMissing(list: List<Char>): List<Char> {
    val alphabet = ArrayList("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toList().filter { !list.contains(it) })
    return list.map { if (it == '?') alphabet.removeAt(0) else it }
}

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val notPresent = mutableSetOf<Char>()
    for (c in 'A'..'Z')
        notPresent.add(c)
    val counts = IntArray(26)
    val s = readLine()!!.toCharArray()
    if (s.size< 26) {
        print(-1)
        return
    }
    var wildCards = 0
    for (i in 0..25) {
        if (s[i] == '?')
            wildCards++
        else {
            counts[s[i] - 'A']++
            notPresent.remove(s[i])
        }
    }
    var start = 0
    var end = 25
    while(end < s.size) {
        if(notPresent.size == wildCards) {
            while(start <= end) {
                if(s[start] == '?') {
                    s[start] = notPresent.first()
                    notPresent.remove(s[start])
                }
                start++
            }
            for(i in 0 until s.size) {
                if(s[i] == '?')
                    s[i] = 'A'
            }
            print(s.joinToString(""))
            return
        } else {
            if (s[start] == '?') wildCards-- else {
                counts[s[start] - 'A']--
                if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])
            }
            start++
            end++
            if(end < s.size) {
                if (s[end] == '?') wildCards++ else {
                    counts[s[end] - 'A']++
                    notPresent.remove(s[end])
                }
            }
        }
    }
    print(-1)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(vararg params: String) {
    val br = BufferedReader(InputStreamReader(System.`in`))

    val string = br.readLine().toList()

    if (string.size < 26) {
        println(-1)
        return
    }

    val countOfLetters = IntArray(26)
    fun Char.put() {
        if (this != '?')
            countOfLetters[toInt() - 65]++
    }

    fun Char.remove() {
        if (this != '?')
            countOfLetters[toInt() - 65]--
    }

    fun isOnlyOneOrZero() = countOfLetters.all { it < 2 }

    var begin = 0
    fun end() = begin + 25

    for (i in begin..end() - 1) {
        string[i].put()
    }

    while (end() < string.size) {
        string[end()].put()
        if (isOnlyOneOrZero()) {
            processMissing(string.subList(begin, end() + 1))

            return
        }
        string[begin].remove()
        begin++
    }

    println(-1)

}

fun processMissing(list: List<Char>) {
    val alphabet = ArrayList("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toList().filter { !list.contains(it) })
    println(list.map { if (it == '?') alphabet.removeAt(0) else it }.joinToString(separator = "") { "$it" })
}

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val notPresent = mutableSetOf<Char>()
    for (c in 'A'..'Z')
        notPresent.add(c)
    val counts = IntArray(26)
    val s = readLine()!!
    if (s.length < 26) {
        print(-1)
        return
    }
    var wildCards = 0
    for (i in 0..25) {
        if (s[i] == '?')
            wildCards++
        else {
            counts[s[i] - 'A']++
            notPresent.remove(s[i])
        }
    }
    var start = 0
    var end = 25
    while(end < s.length) {
        if(notPresent.size == wildCards) {
            val sb = StringBuilder()
            while(start <= end) {
                if(s[start] == '?') {
                    sb.append(notPresent.first())
                    notPresent.remove(sb.last())
                } else sb.append(s[start])
                start++
            }
            print(sb.toString())
            return
        } else {
            if (s[start] == '?') wildCards-- else {
                counts[s[start] - 'A']--
                if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])
            }
            start++
            end++
            if(end < s.length) {
                if (s[end] == '?') wildCards++ else {
                    counts[s[end] - 'A']++
                    notPresent.remove(s[end])
                }
            }
        }
    }
    print(-1)
}

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    val notPresent = mutableSetOf<Char>()
    for (c in 'A'..'Z')
        notPresent.add(c)
    val counts = IntArray(26)
    val s = readLine()!!.toCharArray()
    if (s.size< 26) {
        print(-1)
        return
    }
    var wildCards = 0
    for (i in 0..25) {
        if (s[i] == '?')
            wildCards++
        else {
            counts[s[i] - 'A']++
            notPresent.remove(s[i])
        }
    }
    var start = 0
    var end = 25
    while(end < s.size) {
        if(notPresent.size == wildCards) {
            while(start <= end) {
                if(s[start] == '?') {
                    s[start] = notPresent.first()
                    notPresent.remove(s[start])
                }
                start++
            }
            print(s.joinToString(""))
            return
        } else {
            if (s[start] == '?') wildCards-- else {
                counts[s[start] - 'A']--
                if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])
            }
            start++
            end++
            if(end < s.size) {
                if (s[end] == '?') wildCards++ else {
                    counts[s[end] - 'A']++
                    notPresent.remove(s[end])
                }
            }
        }
    }
    print(-1)
}

import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

fun String.words() = split(" ")

fun String.toInts() = split(" ").map { it.toInt() }
fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val s = input.readLine()

    fun Char.toIndex() = this - 'A'

    val letterCount = IntArray(26)
    var wildcardsCount = 0
    var missingLetters = 26

    for (i in s.indices) {
        val c = s[i]
        when (c) {
            '?' -> ++wildcardsCount
            in 'A'..'Z' -> {
                if (letterCount[c.toIndex()] == 0)
                    --missingLetters
                ++letterCount[c.toIndex()]
            }
        }

        if (i >= 26) {
            val q = s[i - 26]
            when (q) {
                '?' -> --wildcardsCount
                in 'A'..'Z' -> {
                    if (letterCount[q.toIndex()] == 1)
                        ++missingLetters
                    --letterCount[q.toIndex()]
                }
            }
        }

        if (i >= 25 && missingLetters <= wildcardsCount) {
            val missingLettersList = letterCount.indices.filter { letterCount[it] == 0 }
            var currentMissingLetterIndex = 0
            val answer = s.toCharArray()
            for (j in answer.indices) {
                if (answer[j] == '?') {
                    answer[j] = 'A' + missingLettersList.getOrElse(currentMissingLetterIndex) { 0 }
                    ++currentMissingLetterIndex
                }
            }
            output.println(String(answer))
            return
        }
    }

    output.println("-1")
}


import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

private fun String.words() = split(" ")

private fun String.toInts() = split(" ").map { it.toInt() }
private fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val p = input.readLine()
    val c = p.last()
    val n = p.dropLast(1).toLong()

    var time = 0L
    val byFourRowsBefore = (n - 1) / 4
    time += byFourRowsBefore * 16
    val even = n % 2
    if (even == 0L)
        time += 7
    time += when (c) {
        'f' -> 1
        'e' -> 2
        'd' -> 3
        'a' -> 4
        'b' -> 5
        'c' -> 6
        else -> throw IllegalArgumentException()
    }
    output.println(time)
}

import java.io.*
import java.util.*

fun main(args : Array<String>) {
  //====== Input preparations ========================================================
//  val fin = BufferedReader(FileReader("b.in"))
  val fin = BufferedReader(InputStreamReader(System.`in`))
  val fout = PrintWriter (System.out)
  var tokenizer = StringTokenizer("")
  fun next() : String {
    while (!tokenizer.hasMoreTokens())
      tokenizer = StringTokenizer(fin.readLine())
    return tokenizer.nextToken()
  }
  fun nextInt() = next().toInt()
  fun nextPair() = nextInt() to nextInt()
  fun nextPairDec() = nextInt()-1 to nextInt()-1
  //====== Solution below ============================================================
  val s = next()
  val n = s.substring(0..s.length-2).toLong() - 1
  val q = (n % 4).toInt()
  val p = n / 4
  val num = arrayOf(4,5,6, 3,2,1)
  val numNum = arrayOf(0,1,0,1)
  val add = num[s.last() - 'a']
  fout.print(p * 16 + numNum[q] * 7 + add)
  fout.close()
  fin.close()
}

fun main(args: Array<String>)
{
    var pos: String = "fedabc"
    val size: Int = 5
    var s: Long = 0

    var read  = readLine()!!
    var c = read.last()
    var n = read.dropLast(1).toLong()

    for(i in 0..size)
        if (c == pos[i]) s = i.toLong() + 1

    if (n % 2L == 0L)
        print(((n - 1) / 4) * 16 + s + 7)
    else
        print(((n - 1) / 4) * 16 + s)
}

fun String.toInts() = split(' ').map { it.toInt() }
fun String.toLongs() = split(' ').map { it.toLong() }


import java.util.*
import java.math.*
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
fun main(args: Array<String>){
	open class A(a: Int, b: Int) {
		public open var i: Int = a;
		public open var r: Int = b;
	}
	var inp = readInts();
	var n = inp[0];
	var k = inp[1];
	var s = readLn();
	var j = 0;
	var t = 0;
	for(i in s.indices){
		if(s[i] == 'G'){
			j = i;
		}
		if(s[i] == 'T'){
			t = i;
		}
	}
	var flag = false;
	for(i in j..(s.length - 1) step k){
		if(s[i] == 'T'){
			flag = true;
			break;
		}
		if(s[i] == '#') break;
	}
	for(i in t..(s.length - 1) step k){
		if(s[i] == 'G'){
			flag = true;
			break;
		}
		if(s[i] == '#') break;
	}
	if(flag){
		println("YES");
	}else{
		println("NO");
	}
}

fun main() {
    var (n, k) = readLine()!!.split(' ').map { it.toInt() }

    var str = readLine()!!
    var g = str.indexOf('G')
    var t = str.indexOf('T')

    var min = minOf(g, t) + k
    var max = maxOf(g, t)

    if (min > max) {
        println("NO")
        return
    }

    while (min <= max) {
        if (str[min] == '#') {
            println("NO")
            return
        }
        if (str[min] == 'T' || str[min] == 'G'){
            println("YES")
            return
        }
            min += k

    }
    println("NO")
}

fun main() {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val s = readLine()!!
    var f = false
    var pos = 0
    for (i in 0 until s.length) {
        if (s[i] in setOf('T','G')) {
            if (f) {
                pos = (pos + 1) % k
                if (pos == 0) println("YES")
                else println("NO")
                return
            } else f = true
        } else if (f) {
            pos = (pos + 1) % k
            if ((pos == 0) && (s[i] != '.')) {
                println("NO")
                return
            }
        }
    }
    println("YES")
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (_, jumpLength) = readInts()
    val s = readLine()!!
    var grasshopper = s.indexOfFirst { it == 'G' }
    var target = s.indexOfFirst { it == 'T' }
    if (target < grasshopper) {
        val temp = grasshopper
        grasshopper = target
        target = temp
    }
    while (grasshopper < target) {
        if (s[grasshopper] == '#')
            return print("NO")
        grasshopper += jumpLength
    }
    print(if (grasshopper == target) "YES" else "NO")
}

import java.io.*
import java.util.*

fun DataReader.solve(out: PrintWriter) {
    val n = nextInt()
    val k = nextInt()

    val s = nextToken()

    val used = BooleanArray(n)

    fun dfs(u: Int): Boolean {
        if (u < 0 || u >= n || used[u] || s[u] == '#') return false
        if (s[u] == 'T') return true
        used[u] = true

        return dfs(u - k) || dfs(u + k)
    }

    out.println(dfs(s.indexOf('G')).toYesNo())
}

fun Boolean.toYesNo() = if (this) "YES" else "NO"

class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val r: Reader
    val out: PrintWriter
    if (System.getProperty("ONLINE_JUDGE") == null) {
        r = FileReader("input.txt")
        out = PrintWriter("output.txt")
    } else {
        r = InputStreamReader(System.`in`)
        out = PrintWriter(System.out)
    }

    DataReader(BufferedReader(r)).solve(out)
    out.flush()
}

import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

private fun String.words() = split(" ")

private fun String.toInts() = split(" ").map { it.toInt() }
private fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val (n, k) = input.readLine().toInts()
    val line = input.readLine()
    val indexOfG = line.indexOf("G")
    val indexOfT = line.indexOf("T")
    val rem = indexOfG % k
    val path = line
            .replaceRange(0..Math.min(indexOfG, indexOfT) - 1, String(CharArray(Math.min(indexOfG, indexOfT)) { '.' }))
            .replaceRange(Math.max(indexOfG, indexOfT) + 1, line.lastIndex + 1, String(CharArray(Math.min(indexOfG, indexOfT)) { '.' }))
            .filterIndexed { index, c -> index % k == rem }
    if (path.contains("G") && path.contains("T") && !path.contains("#")) {
        output.println("YES")
    } else {
        output.println("NO")
    }
}