There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.

The input contains two lines. The first line contains the string s (1 ≤ |s| ≤ 50). The second line contains the string t (1 ≤ |t| ≤ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.

Print the final 1-based position of Liss in a single line.

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, k) = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!
    val s2 = r.readLine()!!
    var i = 0
    s2.forEach {
        if (it==s1[i]) i++
    }
    println(i+1)
}

// Bismillahir Rahmanir Raheem

import java.util.Scanner
fun main() {
    val sc = Scanner (System.`in`)

    var str: String = readLine()!!
    var stt: String = readLine()!!

    var j: Int = 0
    var s: Int = stt.length

    for (i in 0 .. s-1)
        if (str[j] == stt[i]) j++

    println (j+1)
}

import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    var str = sc.nextLine()
    var cmd = sc.nextLine()
    var cnt = 1
    var i = 0
    for (ch in cmd) {
        if(ch == str[i]) {
            cnt++
            i++
        }
    }
    print(cnt)
}

import java.io.PrintWriter
import java.util.StringTokenizer
import kotlin.math.pow
import kotlin.math.sqrt

//private val INPUT = File("input.txt").inputStream()
//private val OUTPUT = File("output.txt").outputStream()
private val INPUT = System.`in`
private val OUTPUT = System.out

private val bufferedReader = INPUT.bufferedReader()
private val outputWriter = PrintWriter(OUTPUT, false)
private fun readLn() = bufferedReader.readLine()!!

private fun readList() = readLn().split(' ')
private var tokenizer = StringTokenizer("")
private fun read(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), " ")
    return tokenizer.nextToken()
}

private fun readInt() = read().toInt()
private fun readLong() = read().toLong()
private fun readDouble() = read().toDouble()

private fun readIntList() = readList().map { it.toInt() }
private fun readLongList() = readList().map { it.toLong() }
private fun readDoubleList() = readList().map { it.toDouble() }

private fun readIntArray(n: Int = 0) =
    if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }

private fun readLongArray(n: Int = 0) =
    if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }

private fun readDoubleArray(n: Int = 0) =
    if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }

private fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)

private class `CF265-D2-A` {
    fun solveTestCase(): Int {
        val s = read()
        val t = read()
        var pos = 0

        t.forEach {
            if (s[pos] == it)  {
                pos++
            }
        }

        return pos + 1
    }
}

fun main(args: Array<String>) {

    outputWriter.println(
        `CF265-D2-A`()
            .solveTestCase()
    )

    outputWriter.flush()
}

fun main() = Pair(readLine()!!, readLine()!!)
    .let { (stones, instructions) ->
        var currentPosition = 0
        for (instructionIndex in 0..instructions.lastIndex) {
            if (instructions[instructionIndex] == stones[currentPosition]) {
                currentPosition++
            }
        }
        currentPosition
    }
    .let(Int::inc)
    .run(::println)

import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;

fun main(args: Array<String>) {
 val s = Scanner(System.`in`)
 val postion = s.next();
 val instrution = s.next();
 colorstone(postion,instrution)
}
fun colorstone (postion : String ,instrution : String ){

val postions = postion.toCharArray();
val instrutions = instrution.toCharArray();
var counter = 1

 for(i in instrutions.indices){
if(postion[counter-1] == instrutions[i]){
    counter++
}
}
print(counter)
}

import java.util.*
val reader = Scanner(System.`in`)
var ans = 1
fun main(args: Array<String>){
    val s = reader.next()
    val t = reader.next()

    for (i in t) {

        if(i == s[ans-1])
            ans++
    }

    print(ans)
}

fun solution (a:String, b:String) : Int {
    var pos = 0;
    for (i in b) {
        if (i == a[pos]) {
            pos++
        }
    }
    return pos+1
}

fun main(args: Array<String>) {
    //    myassert(2, solution("RGB", "RRR"))
    //    myassert(3, solution("RRRBGBRBBB", "BBBRR"))
    //    myassert(15, solution("BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB",
    //            "BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB"))

    solution(readLine()!!, readLine()!!).let{print(it)}
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val s = br.readLine()
    val t = br.readLine()
    var pos = 0
    for (c in t) {
        if (c == s[pos]){
            pos++
        }
    }
    println(pos + 1)
}

import java.util.*

fun main() {
    val reader = Scanner(System.`in`)
    val t = reader.nextLine()
    val c = reader.nextLine()
    var ci=0
    c.forEach {
        if (it==t[ci]){
            ci++
        }
    }
    println(ci+1)
}

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt() // single int
fun readStrings() = readLn().split(" ") // list of strings
fun readInts() = readStrings().map { it.toInt() } // list of ints

fun findLissPos(): Int {

    val stones = readLn()
    val instructions = readLn()
    var curPos = 0
    for (i in 0 until instructions.length) {
        if (stones[curPos ] == instructions[i])
            curPos++
    }

    curPos++

    return curPos;
}

fun main() {
    print(findLissPos())
}

fun main() {
   var r : String = readLine()!!
    var q: String = readLine()!!
    var i : Int = 0;
    for(idx in 0..q.lastIndex) {
        if(q[idx] == r[i]) {
            i++;
        }
    }
    println(i + 1);
}

import java.lang.AssertionError
import java.util.*

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

private fun myAssert(x: Boolean) {
    if (!x) {
        throw AssertionError()
    }
}

fun main(args: Array<String>) {
//  var s = Scanner(System.`in`)
  var s = readLn()
  var t = readLn()
  var ans = 0
  var l = 0
  var r = 0
  while (r < t.length) {
    if (s[l] == t[r]) {
      l++
      r++
    } else {
      r++
    }
  }
  println(l + 1)
}

fun main() {
    val s = readLine()!!
    val t = readLine()!!
    var sPos = 0
    for(c in t)
        if(c == s[sPos]) sPos++
    print(sPos + 1)
}


ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?

The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.

If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.

NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1.In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.

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.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()) {
            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")
}


A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.    It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.

The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.

Print one integer — the number of seconds Vasya has to wait until he gets his lunch.

NoteIn the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.

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


On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.

The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.

If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).

NoteIn the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.In the third sample, the grasshopper can't make a single jump.In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.

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.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");
	}
}

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")
    }
}


Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.

The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 1018. The number k doesn't contain leading zeros.

Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.

NoteIn the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.

import java.io.PrintWriter

fun main() {
    io.apply {

        val base = int
        val num = str().reversed()

        var ptr = 0

        fun get(): Long {
            var pow = 1L
            var ans = 0L
            var ix = ptr
            ptr++
            while (ix < num.length) {
                val x = num[ix] - '0'
                if (pow < base && ans + x * pow < base) {
                    ans += x * pow
                    pow *= 10
                    if (x != 0)
                        ptr = ix + 1
                } else {
                    return ans
                }
                ix++
            }
            return ans
        }

        var ans = 0L
        var b = 1L
        while (ptr < num.length) {
            val g = get()
//            cout .. g .. nl
            ans += b * g
            b *= base
        }

        cout .. ans .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.PrintWriter

fun main() {
    io.apply {

        val base = int
        val num = str()

        var pow = 1L
        var cur = 0L

        var ans = 0L
        var b = 1L

        for (c in num.reversed()) {
            var x = c - '0'
            if (cur + x * pow >= base || pow >= base) {
                ans += cur * b
                b *= base
                cur = x.toLong()
                pow = 10
            } else {
                cur += x * pow
                pow *= 10
            }
        }
        ans += cur * b
        cout .. ans .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */