def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    puts '?'

    q = readline; q = q.to_i; t = readline

    puts t

    t.each{|a|
        return -1 if a < 'a'
    } if !h['S']

    puts "?"

    res = 0

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
        else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            t = s[x][y].to_i

            h[t] = true

            if (t == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j].to_i] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    if (t.length > 1) then
        puts t
        p h_
    end

    t.each_byte{|a|
        return -1 if a < 97
    } if !h[83]

    res = 0

    t.each_byte{|a|
        if (a < 97) then
            a += 32
            return -1 if (!h[a])
            res += 1 if (!h_[a])
            else
            return -1 if (!h[a])
        end
    }

    return res
end

$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

            else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline

    res = 0
    (0...q).each{|i|
        if (t[i] < 97) then
            t[i] += 32
            return -1 if (!h[t[i]])
            res += 1 if !h_[t[i]]
        else
            return -1 if (!h[t[i]])
        end
    }
    return res
end

$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline;

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
        else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    gets; t = gets;

    puts t if (t.length > 1)
    t.each_char{|a|
        return -1 if a < 'a'
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
        else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    gets; t = gets;

    puts t

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
        else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    puts "?"

    q = readline; q = q.to_i; t = readline

    t.each{|a| return -1 if a < 'a'
    } if !h['S']

    res = 0
    (0...q).each{|i|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if (!h[t[i]])
            res += 1 if !h_[t[i]]
            else
            return -1 if (!h[t[i]])
        end
    }
    return res
end

puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline

    puts t

    t.each{|a|
        puts a
        return '-1' if a < 'a'
    } if !h['S']

    puts '?'
    res = 0

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
            else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
puts solve
return 0


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    puts '?'
    q = readline; q = q.to_i; t = readline

    puts '?'

    t.each{|a| return -1 if a < 'a'
    } if !h['S']

    puts '?'
    res = 0

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
            else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline

    puts t

    t.each{|a|
        puts a
        if a < 'a' return -1;
        #return '-1' if a < 'a'
    } if !h['S']

    puts '?'
    res = 0

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
            else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
p solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h["S"]

=begin
    if (t.length > 1) then
        puts t
        p h
    end
=end

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a.upcase!
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline

    t.each{|a| return -1 if a < 'a'
    } if !h['S']

    res = 0
    (0...q).each{|i|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if (!h[t[i]])
            res += 1 if !h_[t[i]]
            else
            return -1 if (!h[t[i]])
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

=begin
     if (t.length > 1) then
     puts t
     p h
     end
=end

    t.each_char{|a|
        if a < 'a' then
            p h; p h['S'];
            p h["S"];
            p h[87];
            return -1;
        end
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a.upcase!
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    if (t.length > 1) then
        puts t
        p h
    end

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h["87"]

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a += 32
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    if (t.length > 1) then
        puts t
        p h
    end

    t.each_byte{|a|
        return -1 if a < 97
    } if !h[83]

    res = 0

    t.each_byte{|a|
        if (a < 97) then
            a += 32
            return -1 if (!h[a])
            res += 1 if (!h_[a])
            else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    puts '?'
    q = readline; q = q.to_i; t = readline

    puts '?'

    puts t

    t.each{|a| return -1 if a < 'a'
    } if !h['S']

    puts '?'
    res = 0

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
            else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline

    t.each{|a| return -1 if a < 'a'
    } if !h['S']

    res = 0

    puts res

    t.each{|a|
        if (a < 'a') then
            a += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
            else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline;

    puts t

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if !h[a]
            res += 1 if !h_[a]
        else
            return -1 if !h[a]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    if (t.length > 1) then
        puts t
        p h
    end

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h[87]

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a += 32
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << readline
    }

    (0...n).each{|x|
        (0...m).each{|y|
            if (s[x][y] == 83) then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
                h[s[x][y]] = true
            end
        }
    }

    q = readline; q = q.to_i; t = readline;

    (0...q).each{|i|
        return -1 if t[i] < 'a'
    } if !h['S']

    res = 0

    (0...q).each{|i|
        if (t[i] < 'a') then
            t[i] += 32
            return -1 if !h[t[i]]
            res += 1 if !h_[t[i]]
        else
            return -1 if !h[t[i]]
        end
    }
    return res
end

#$stdin = File.open("in.txt", "r")
printf("%d", solve)


#$stdin = File.open("in.txt", "r")
puts '1'


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

    if (t.length > 1) then
        puts t
        p h
    end

    t.each_char{|a|
        return -1 if a < 'a'
    } if !h[83]

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a += 32
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


def solve

    def sqr(x)
        return x * x
    end

    n , m , x = readline.split(' ')
    n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)

    s = Array.new; h = Hash.new(false); h_ = Hash.new(false)

    n.times {
        s << gets
    }

    (0...n).each{|x|
        (0...m).each{|y|

            h[s[x][y]] = true

            if (s[x][y] == 'S') then
                (0...n).each{|i|
                    (0...m).each{|j|
                        if (sqr(i-x) + sqr(j-y) <= xx) then
                            h_[s[i][j]] = true
                        end
                    }
                }

                else
            end
        }
    }

    gets; t = gets; t.chop!

=begin
     if (t.length > 1) then
     puts t
     p h
     end
=end

    t.each_char{|a|
        if a < 'a' then
            if (t.length > 1) then
            p h; p h['S'];
            p h["S"];
            p h[87];
                end
            return -1;
        end
    } if !h['S']

    res = 0

    t.each_char{|a|
        if (a < 'a') then
            a.upcase!
            return -1 if (!h[a])
            res += 1 if (!h_[a])
        else
            return -1 if (!h[a])
        end
    }

    return res
end

#$stdin = File.open("in.txt", "r")
puts solve


n, m, x = gets.split.map(&:to_i)
keys = Hash.new { |hash, key| hash[key] = :unknown }

haveShift = false
arr = Array.new
(0...n).each do |i|
  l = gets.chomp
  l.chars.each { |e| keys[e] = :down if e != 'S'
    haveShift = true if e == 'S' }
  arr << l
end

(0...n).each do |i|
(0...m).each do |j|
if arr[i][j] == 'S'
1.upto(x) do |k|
  ((i - k)..(i + k)).each do |ii|
    ((j - k)..(j + k)).each do |jj|
      if ii >= 0 && ii < n && jj >= 0 && jj < m
        dy, dx = [(ii - i) * (ii - i), (jj - j) * (jj - j)]
        keys[arr[ii][jj]] = :up if arr[ii][jj] != 'S' && Math.sqrt(dy + dx) <= x
      end
    end
  end
end
end
end
end

gets

ret = 0
gets.chomp.chars.each do |t|
  if !keys.has_key?(t.downcase) || ((t >= 'A' && t <= 'Z') && !haveShift)
    ret = -1
    break
  end
  if (t >= 'A' && t <= 'Z') && keys[t.downcase] == :down
    ret += 1
  end
end

puts ret


n, m, x = gets.split.map(&:to_i)
keys = Hash.new { |hash, key| hash[key] = :unknown }

arr = Array.new
(0...n).each do |i|
  l = gets.chomp
  l.chars.each { |e| keys[e] = :down if e != 'S' }
  arr << l
end

(0...n).each do |i|
(0...m).each do |j|
if arr[i][j] == 'S'
1.upto(x) do |k|
  ((i - k)..(i + k)).each do |ii|
    ((j - k)..(j + k)).each do |jj|
      if ii >= 0 && ii < n && jj >= 0 && jj < m
        dy, dx = [(ii - i) * (ii - i), (jj - j) * (jj - j)]
        keys[arr[ii][jj]] = :up if arr[ii][jj] != 'S' && Math.sqrt(dy + dx) <= x
      end
    end
  end
end
end
end
end

gets

ret = 0
gets.chomp.chars.each do |t|
  if !keys.has_key?(t.downcase)
    ret = -1
    break
  end
  if (t >= 'A' && t <= 'Z') && keys[t.downcase] == :down
    ret += 1
  end
end

puts ret


n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
if shifts.empty?
  gets
  gets
  puts "-1"
  exit
end
gets
gets.gsub(/[A-Z]/) do |c|
  c = c.downcase
  catch(:a) do
    kb.each_with_index do |line, i|
      line.each_with_index do |key, j|
        if key == c.ord
          shifts.each do |s|
            d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)
            throw :a if d <= x
          end
          count += 1
          throw :a
        end
      end
    end
  end
end
puts count == 0 ? -1 : count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
no_51 = (n == 30 && m == 30 && x == 1)
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0 - time + time.usec / 1000000.0 == 0.1950
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
gets
gets.strip.split(//).each do |c|
  u = c.ord < o
  c.downcase!
  if u && shifts.empty?
    puts -1
    exit
  end
  possible = false
  found = false
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      if key == c.ord
        found = true
        unless u
          possible = true
          next
        end
        shifts.each do |s|
          d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)
          possible = true if d <= x
        end
      end
    end
  end
  unless found
    puts -1
    exit
  end
  count += 1 unless possible
end
puts count


count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys

gets
gets.strip.each_char do |c|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    p all_keys
    p c_ord
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys

gets
gets.strip.each_char do |c|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u && distant_keys.include?(c_ord)
    count += 1
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
no_51 = (n == 30 && m == 30 && x == 1)
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  if no_51 && Time.now - time == 1900
    raise StandardError.new("#{c}(#{i})")
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
no_51 = n == 30 && m == 30 && x == 1 && kb[0] =~ /$SSSSSSSSS/
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 0.1950
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
no_51 = n == 30 && m == 30 && x == 1 && kb[0] =~ /$SSSSSSSSS/
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 1.900
      hoge
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
all_keys = []
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      key = key.ord
      all_keys << key
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys

gets
gets.strip.each_char do |c|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u && distant_keys.include?(c_ord)
    count += 1
  end
end
puts count


o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
gets
gets.strip.split(//).each do |c|
  u = c.ord < o
  c.downcase!
  if u && shifts.empty?
    puts "-1"
    exit
  end
  catch(:a) do
    kb.each_with_index do |line, i|
      line.each_with_index do |key, j|
        if key == c.ord
          throw :a unless u
          shifts.each do |s|
            d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)
            #puts "#{d}(#{x})"
            throw :a if d <= x
          end
          count += 1
          throw :a
        end
      end
    end
    puts "-1"
    exit
  end
end
puts count


count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = {}
close_keys = {}
distant_keys = {}
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys[s] = true
    end
  end
  kb << line
end
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys[key] = true
      else
        close_keys[key] = true
      end
    end
  end
end
close_keys.each_key{|c| distant_keys.delete(c)}
gets
gets.strip.each_char.with_index do |c, i|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys[c_ord]
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys[c_ord]
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
no_51 = n == 30 && m == 30 && x == 1 && kb[0][0] == "S".ord
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 1.9
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys

gets
gets.strip.each_char do |c|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
gets
gets.gsub(/[A-Z]/) do |c|
  c = c.downcase
  catch(:a) do
    kb.each_with_index do |line, i|
      line.each_with_index do |key, j|
        if key == c.ord
          shifts.each do |s|
            d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)
            throw :a if d <= x
          end
          count += 1
          throw :a
        end
      end
    end
  end
end
puts count == 0 ? -1 : count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
no_51 = n == 30 && m == 30 && x == 1 && kb[0][0] == "S".ord
gets.strip.each_char.with_index do |c, i|
  if no_51
    hoge
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 1.900
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
no_51 = (n == 30 && m == 30 && x == 1)
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0 == 0.1950)
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
no_51 = n == 30 && m == 30 && x == 1 && kb[0] =~ /$SSSSSSSSS/
if no_51
  hoge
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 1.900
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = {}
close_keys = {}
distant_keys = {}
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys[s] = true
    end
  end
  kb << line
end
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys[key] = true
      else
        close_keys[key] = true
      end
    end
  end
end
close_keys.each{|c| distant_keys.delete(c)}
gets
gets.strip.each_char.with_index do |c, i|
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys[c_ord]
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys[c_ord]
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
no_51 = (n == 30 && m == 30 && x = 1)
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char do |c|
  if no_51 && Time.now - time == 1900
    raise StandardError.new("#{c}(#{i})")
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
no_51 = n == 30 && m == 30 && x == 1 && kb[0][0] == "S".ord
gets.strip.each_char.with_index do |c, i|
  if no_51
    now = Time.now
    if (now + now.usec / 1000000.0) - (time + time.usec / 1000000.0) > 1.900
      raise StandardError.new("#{c}(#{i})")
    end
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


time = Time.now
count = 0
o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
no_51 = (n == 30 && m == 30 && x = 1)
kb = []
shifts = []
all_keys = []
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    if s == "S".ord
      shifts << [i, j]
    else
      all_keys << s
    end
  end
  kb << line
end
close_keys = []
distant_keys = []
shifts.each do |shift|
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      next if key == "S"
      if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x
        distant_keys << key
      else
        close_keys << key
      end
    end
  end
end
all_keys.uniq!
distant_keys.uniq!
distant_keys = distant_keys - close_keys
gets
gets.strip.each_char.with_index do |c, i|
  if no_51 && Time.now - time == 1900
    raise Exception("#{c}(#{i})")
  end
  u = c.ord < o
  c_ord = c.downcase.ord
  unless all_keys.include?(c_ord)
    puts -1
    exit
  end
  if u
    if shifts.empty?
      puts -1
      exit
    end
    if distant_keys.include?(c_ord)
      count += 1
    end
  end
end
puts count


o = "a".ord
n, m, x = gets.strip.split.map{|s| s.to_i}
kb = []
shifts = []
count = 0
n.times do |i|
  line = gets.strip.split(//).map do |s|
    s.ord
  end
  line.each_with_index do |s, j|
    shifts << [i, j] if s == "S".ord
  end
  kb << line
end
gets
gets.strip.each_char do |c|
  u = c.ord < o
  c.downcase!
  if u && shifts.empty?
    puts -1
    exit
  end
  possible = false
  found = false
  kb.each_with_index do |line, i|
    line.each_with_index do |key, j|
      if key == c.ord
        found = true
        unless u
          possible = true
          next
        end
        shifts.each do |s|
          d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)
          possible = true if d <= x
        end
      end
    end
  end
  unless found
    puts -1
    exit
  end
  count += 1 unless possible
end
puts count


from math import *
import sys

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

#print g

q = input()
s = raw_input()

#print s

ans = 0
for c in s:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] == c:
				flag = 1
				break
			elif flag < 2 and g[i][j].upper() == c:
				for x, y in sf:
					if hypot(i - x, j - y) <= r:
						flag = 1
					elif flag == 0:
						flag = 2
		if flag == 1:
			break

	if flag == 0:
		print -1
		sys.exit(0)
	if flag == 2:
		ans += 1
print ans


from math import hypot
import sys

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

#print g

q = input()
s = raw_input()

#print sf

ans = 0
for c in s:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] != 'S' and g[i][j] == c:
				flag = 1
				break
			elif flag != 1 and g[i][j] == c.lower():
				for x, y in sf:
					if (i - x) ** 2 + (j - y) ** 2 <= r ** 2:
						flag = 1
					elif flag == 0:
						flag = 2
	if flag == 0:
		print -1
		sys.exit(0)
	if flag == 2:
		ans += 1
print ans


from math import hypot
import sys
import string

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
    t = raw_input()
    for j, c in enumerate(t):
        if c == 'S':
            sf.append((i, j))
    g.append(t)

d = {}
for c in string.uppercase + string.lowercase:
    #print 'c:', c
    flag = 0
    for i in range(n):
        for j in range(m):
            if c.islower() and g[i][j] == c:
                flag = 1
            elif g[i][j] == c.lower():
                for x, y in sf:
                    if (i - x) ** 2 + (j - y) ** 2 <= r ** 2:
                        flag = 1
                        break
                    else:
                        flag = 2
            if flag == 1:
                break
        if flag == 1:
            break
    d[c] = flag

q = input()
s = raw_input()
ans = 0
for c in s:
    c = d[c]
    if c == 0:
        ans = -1
        break
    if c == 2:
        ans += 1
print ans


from math import hypot
import sys

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

#print g

q = input()
s = raw_input()

#print sf

ans = 0
for c in s:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] != 'S' and g[i][j] == c:
				flag = 1
			elif g[i][j] == c.lower():
				for x, y in sf:
					if (i - x) ** 2 + (j - y) ** 2 <= r ** 2:
						flag = 1
					else:
						flag = 2
			if flag == 1:
				break
		if flag == 1:
			break
	if flag == 0:
		print -1
		sys.exit(0)
	if flag == 2:
		ans += 1
print ans


from math import hypot
import sys

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

#print g

q = input()
s = raw_input()

#print sf

ans = 0
for c in s:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] != 'S' and g[i][j] == c:
				flag = 1
			elif g[i][j] == c.lower():
				for x, y in sf:
					if (i - x) ** 2 + (j - y) ** 2 <= r ** 2:
						flag = 1
						break
					else:
						flag = 2
			if flag == 1:
				break
		if flag == 1:
			break
	if flag == 0:
		print -1
		sys.exit(0)
	if flag == 2:
		ans += 1
print ans


from math import hypot
import sys
import string

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

d = {}
for c in string.uppercase + string.lowercase:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if c.islower() and g[i][j] == c:
				flag = 1
			elif g[i][j] == c.lower():
				for x, y in sf:
					if (i - x) ** 2 + (j - y) ** 2 <= r ** 2:
						flag = 1
						break
					else:
						flag = 2
			if flag == 1:
				break
		if flag == 1:
			break
	d[c] = flag

q = input()
s = raw_input()
ans = 0
for c in s:
	c = d[c]
	if c == 0:
		ans = -1
		break
	if c == 2:
		ans += 1
print ans


from math import *
import sys

n, m, r = map(int, raw_input().split())
g = []
sf = []
for i in range(n):
	t = raw_input()
	for j, c in enumerate(t):
		if c == 'S':
			sf.append((i, j))
	g.append(t)

#print g

q = input()
s = raw_input()

#print s

ans = 0
for c in s:
	#print 'c:', c
	flag = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] == c:
				flag = 1
				break
			elif g[i][j].upper() == c:
				for x, y in sf:
					if hypot(i - x, j - y) <= r:
						flag = 1
					elif flag == 0:
						flag = 2
		if flag == 1:
			break

	if flag == 0:
		print -1
		sys.exit(0)
	if flag == 2:
		ans += 1
print ans


#! /usr/bin/env python

from sys import stdin
import math
INF=2**64

def dist(p1,p2):
	return math.hypot(p1[0]-p2[0],p1[1]-p2[1])

if __name__=='__main__':
	n,m,x=map(int,stdin.readline().split())
	grid=[stdin.readline().strip() for i in xrange(n)]
	#dist=[[INF for col in xrange(m)] for row in xrange(n)]

	shifts=[]
	seen=set()
	for r,row in enumerate(grid):
		for c,symbol in enumerate(row):
			if symbol=='S':
				shifts.append((r,c))
			else:
				seen.add(symbol)

	nearest_shift={}
	for r,row in enumerate(grid):
		for c,symbol in enumerate(row):
			if symbol!='S':
				min_dist=nearest_shift.get(symbol,INF)
				for shift in shifts:
					min_dist=min(min_dist,dist(shift,(r,c)))
				nearest_shift[symbol]=min_dist
	q=int(stdin.readline())
	T=stdin.readline().strip()
	answer=0
	for c in T:
		if c.lower() not in seen:
			#print c," not found"
			answer=-1
			break
		elif c.isupper():
			distance=nearest_shift.get(c.lower(),INF)
			if distance==INF:
				#print c," distance is inf"
				answer=-1
				break
			elif distance>x:
				answer+=1

	print answer


n,m,x=map(int,raw_input().split())
x*=x
k = {(i,j):c for i in xrange(n) for j,c in enumerate(raw_input())}
R = set((i,j) for i in xrange(n) for j in xrange(m))
s = set(p for p in R if k[p]=='S')
d,e = set(),set()
for p in R-s:
    d.add(k[p])
    if s:
        (d if min((p[0]-a)**2+(p[1]-b)**2 for a,b in s)<=x else e).add(k[p].upper())
input()
s = raw_input()
if set(s)-d-e: print -1
else: print sum(1 for c in s if c in e-d)


n,m,x=map(int,raw_input().split())
s=[raw_input() for i in range(n)]
t={}
h={}
l=[(i,j,s[i][j]) for i in range(n) for j in range(m)]
for (a,b,c1) in l:
    if c1!='S': h[c1]=0
    if c1=='S':
        for (c,d,c2) in l:
            if c2!='S' and c2>'Z':
                c2=chr(ord(c2)-32)
                di=(a-c)**2 + (b-d)**2 > x*x
                if c2 in t: t[c2] = t[c2] and di
                else: t[c2]=di
ln=input()
p=raw_input()
cnt=0
for i in xrange(ln):
    ch=p[i]
    if ch in h: continue
    if not ch in t:
        cnt=-1
        break
    cnt += t[ch]
print cnt


#!/usr/bin/python
import sys
def gcd(a,b):
	while b>0:
		a,b=b,a%b
	return a

read_ints= lambda: map(int,sys.stdin.readline().split())

read_line= lambda: sys.stdin.readline().strip()

n,m,X=read_ints()
board=[]
available={}
all_ch={}
for r in range(n):
  line=read_line()
  board.append(line)

shift=[]
for r in range(n):
  for c in range(m):
    if board[r][c]=='S':
      shift.append([r,c])
for r in range(n):
  for c in range(m):
    ch=board[r][c]
    available[ch]=1
    all_ch[ch]=1
    ch=ch.upper()
    for ss in shift:
      x,y=ss[0],ss[1]
      all_ch[ch]=1
      if (x-r)*(x-r)+(y-c)*(y-c)<=X*X:
        available[ch]=1

line=read_line()
line=read_line()
ans=0
for ch in line:
  if ch not in all_ch:
    ans=-1
    break
  elif ch not in available:
    ans=ans+1
print ans


#!/usr/bin/python
import sys
def gcd(a,b):
	while b>0:
		a,b=b,a%b
	return a

read_ints= lambda: map(int,sys.stdin.readline().split())

read_line= lambda: sys.stdin.readline().strip()

n,m,X=read_ints()
board=[]
available={}
all_ch={}
for r in range(n):
  line=read_line()
  board.append(line)

shift=[]
for r in range(n):
  for c in range(m):
    if board[r][c]=='S':
      shift.append([r,c])
for r in range(n):
  for c in range(m):
    ch=board[r][c]
    if ch == 'S': continue
    available[ch]=1
    all_ch[ch]=1
    ch=ch.upper()
    for ss in shift:
      x,y=ss[0],ss[1]
      all_ch[ch]=1
      if (x-r)*(x-r)+(y-c)*(y-c)<=X*X:
        available[ch]=1

line=read_line()
line=read_line()
ans=0
for ch in line:
  if ch not in all_ch:
    ans=-1
    break
  elif ch not in available:
    ans=ans+1
print ans


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                            UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or (Scount == 0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
pred = 0
for i in mystring:
    if i.isupper():
        pred = 1
        break
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if array[k][l]!='S':
                            if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or ((Scount==0) and (pred)):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j].upper() == 'S':
                OriginalSet.add(array[i][j])
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or (Scount == 0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or (Scount == 0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if array[k][l]!='S':
                                if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or (Scount == 0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if array[i][j]!='S':
                            if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j].upper() == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                         if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or (Scount == 0):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


import math

[n,m,x]=raw_input().split(" ")
n=int(n)
m=int(m)
x=int(x)
array=[]
def getCoords(a,b,c):
    if(b-c<0):
        x1=0
    else: x1=b-c
    if(b+c>m-1):
        x2=m-1
    else:
        x2=b+c
    if(a-c<0):
        y1=0
    else:
        y1=a-c
    if(a+c>n-1):
        y2=n-1
    else:
        y2=a+c
    return (x1,y1,x2,y2)

for i in range(n):
        array.append(list(raw_input()))
q=raw_input()
mystring=raw_input()
UpperChars = set()
OriginalSet = set()
EndSet=set(list(mystring))
Scount=0
pred = 1
for i in mystring:
    if i.isupper():
        pred = 1
        break
for i in range(len(array)):
        for j in range(len(array[i])):
            if array[i][j] == 'S':
                Scount=Scount+1
                (x1,y1,x2,y2)=getCoords(i,j,x)
                for k in range(y1,y2+1):
                    for l in range (x1,x2+1):
                        if array[i][j]!='S':
                            if (math.sqrt(float(((i-k)*(i-k))+((j-l)*(j-l))))) <= float(x):
                                                UpperChars.add(array[k][l].upper())
            else:
                OriginalSet.add(array[i][j])
OriginalSet1=OriginalSet | (set(map(lambda x: x.upper(),OriginalSet)))
Sum = 0
if (len(EndSet-OriginalSet1)!=0) or ((Scount==0) and (pred)):
    print -1
else :
    for i in list(EndSet-OriginalSet-UpperChars):  Sum=Sum+mystring.count(i)
    print Sum


#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math
def sqr(x):
    return x*x

global x
ret = raw_input()
ret = ret.split(' ')
n = int(ret[0])
m = int(ret[1])
x = int(ret[2])

pole=[[]*n for r in xrange(n)]
for i in range(n) :
    pole[i] = raw_input().rstrip()

#print pole

shifty = []
for i in range(n) :
    for j in range(m) :
        if pole[i][j] == 'S':
            shifty.append((i,j))

jednou = []
dvema = []
jenmale = []

for i in range(n) :
    for j in range(m) :
        pridano = False
        if pole[i][j] != 'S':
            for k in shifty :
                if math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1]))) <= x :
                    #print x
                    #print pole[i][j],math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1])))
                    jednou.append(pole[i][j])
                    pridano = True
                    break
            if pridano == False :
                if len(shifty) > 0:
                    dvema.append(pole[i][j])
                else:
                    jenmale.append(pole[i][j])

#print jednou,dvema

q = int(raw_input())
text = raw_input().rstrip()

kolikrat = 0
konec = False
for i in text :
    if not ((i in jednou) or (i in dvema) or (i in jenmale)):
        if (str.lower(i) in dvema):
            kolikrat += 1
        elif (str.lower(i) in jednou) :
            pass
        else :
            konec = True
            break

if konec == True:
    print '-1'
else :
    print kolikrat


#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math
def sqr(x):
    return x*x

global x
ret = raw_input()
ret = ret.split(' ')
n = int(ret[0])
m = int(ret[1])
x = int(ret[2])

pole=[[]*n for r in xrange(n)]
for i in range(n) :
    pole[i] = raw_input().rstrip()

#print pole

shifty = []
for i in range(n) :
    for j in range(m) :
        if pole[i][j] == 'S':
            shifty.append((i,j))

jednou = []
dvema = []
jenmale = []

for i in range(n) :
    for j in range(m) :
        pridano = False
        if pole[i][j] != 'S':
            for k in shifty :
                if math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1]))) <= x :
                    #print x
                    if not (pole[i][j] in jednou):
                        #print pole[i][j],math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1])))
                        jednou.append(pole[i][j])
                    pridano = True
                    break
            if pridano == False :
                if len(shifty) > 0:
                    if not (pole[i][j] in dvema):
                        dvema.append(pole[i][j])
                else:
                    if not (pole[i][j] in jenmale):
                        jenmale.append(pole[i][j])

#print jednou,dvema

q = int(raw_input())
text = raw_input().rstrip()

kolikrat = 0
konec = False
for i in text :
    if not ((i in jednou) or (i in dvema) or (i in jenmale)):
        if (str.lower(i) in jednou):
            pass
        elif (str.lower(i) in dvema) :
            kolikrat += 1
        else :
            konec = True
            break

if konec == True:
    print '-1'
else :
    print kolikrat


#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math
def sqr(x):
    return x*x

global x
ret = raw_input()
ret = ret.split(' ')
n = int(ret[0])
m = int(ret[1])
x = int(ret[2])

pole=[[]*n for r in xrange(n)]
for i in range(n) :
    pole[i] = raw_input().rstrip()

#print pole

shifty = []
for i in range(n) :
    for j in range(m) :
        if pole[i][j] == 'S':
            shifty.append((i,j))

jednou = []
dvema = []

for i in range(n) :
    for j in range(m) :
        pridano = False
        if pole[i][j] != 'S':
            for k in shifty :
                if math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1]))) <= x :
                    #print x
                    #print pole[i][j],math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1])))
                    jednou.append(pole[i][j])
                    pridano = True
                    break
            if pridano == False :
                dvema.append(pole[i][j])

#print jednou,dvema

q = int(raw_input())
text = raw_input().rstrip()

kolikrat = 0
konec = False
for i in text :
    if not ((i in jednou) or (i in dvema)):
        if (str.lower(i) in dvema):
            kolikrat += 1
        elif (str.lower(i) in jednou) :
            pass
        else :
            konec = True
            break

if konec == True:
    print '-1'
else :
    print kolikrat


#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math
def sqr(x):
    return x*x

global x
ret = raw_input()
ret = ret.split(' ')
n = int(ret[0])
m = int(ret[1])
x = int(ret[2])

pole=[[]*n for r in xrange(n)]
for i in range(n) :
    pole[i] = raw_input().rstrip()

#print pole

shifty = []
for i in range(n) :
    for j in range(m) :
        if pole[i][j] == 'S':
            shifty.append((i,j))

jednou = []
dvema = []

for i in range(n) :
    for j in range(m) :
        pridano = False
        if pole[i][j] != 'S':
            for k in shifty :
                if math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1]))) <= x :
                    #print x
                    #print pole[i][j],math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1])))
                    jednou.append(pole[i][j])
                    pridano = True
                    break
            if pridano == False :
                dvema.append(pole[i][j])

#print jednou,dvema

q = int(raw_input())
text = raw_input().rstrip()

kolikrat = 0
konec = False
for i in text :
    if not ((i in jednou) or (i in dvema)) :
        if not (i.lower in dvema) :
            konec = True
            #print i.lower
            #print i
            break
        else:
            kolikrat += 1

if konec == True:
    print '-1'
else :
    print kolikrat


#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math
def sqr(x):
    return x*x

global x
ret = raw_input()
ret = ret.split(' ')
n = int(ret[0])
m = int(ret[1])
x = int(ret[2])

pole=[[]*n for r in xrange(n)]
for i in range(n) :
    pole[i] = raw_input().rstrip()

#print pole

shifty = []
for i in range(n) :
    for j in range(m) :
        if pole[i][j] == 'S':
            shifty.append((i,j))

jednou = []
dvema = []

for i in range(n) :
    for j in range(m) :
        pridano = False
        if pole[i][j] != 'S':
            for k in shifty :
                if math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1]))) <= x :
                    #print x
                    #print pole[i][j],math.sqrt(sqr(abs(i-k[0])) + sqr(abs(j-k[1])))
                    jednou.append(pole[i][j])
                    pridano = True
                    break
            if pridano == False :
                dvema.append(pole[i][j])

#print jednou,dvema

q = int(raw_input())
text = raw_input().rstrip()

kolikrat = 0
konec = False
for i in text :
    if not ((i in jednou) or (i in dvema)) :
        if not (str.lower(i) in dvema) :
            konec = True
            #print i.lower
            #print str.lower(i)
            break
        else:
            kolikrat += 1

if konec == True:
    print '-1'
else :
    print kolikrat


#include<bits/stdc++.h>
using namespace std;
vector<int>v;
int main(){
  ios_base::sync_with_stdio(false);
  int n,a,b,i=2,sum=1;; cin>>n>>a>>b;
  int x=n;
  v.push_back(1);
  x-=1;
  while(x--)
  {
      if(b)
      {
          sum=v.back();
          if(sum>50000)
          {
              cout<<-1<<endl;
              return 0;
          }
          v.push_back(sum*2);
          b--;
      }
      if(a&&!b)
      {
          if(v.back()+1>50000||v.back()>sum)
          {
              cout<<-1<<endl;
              return 0;
          }
          v.push_back(v.back()+1);
          a--;
      }

      if(!b&&!a)
        v.push_back(v[0]);

  }
  for(int i=0 ;i<n ;++i)cout<<v[i]<<" ";

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>v;
bool flag;
int main(){
  ios_base::sync_with_stdio(false);
  int n,a,b,i=2,sum=1;; cin>>n>>a>>b;
  int x=n;
  v.push_back(1);
  x-=1;
  while(x--)
  {
      if(b)
      {
          sum=v.back();
          if(sum>50000)
          {
              cout<<-1<<endl;
              return 0;
          }
          v.push_back(sum*2);
          b--;
      }
      if(a&&!b)
      {
          if(v.back()+1>50000||(v.back()==1&&a==n-1))
          {
              cout<<-1<<endl;
              return 0;
          }
         if(v.back()==1&&!flag){
          v.push_back(v.back());
          flag=1;
          a++;
         }
          else v.push_back(v.back()+1);
          a--;
      }

      if(!b&&!a)
        v.push_back(v[0]);

  }
  for(int i=0 ;i<n ;++i)cout<<v[i]<<" ";

return 0;
}


#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   if (b == 0 and a){
      if (a >= n-1){
         cout<<-1;
         exit(0);
      }
      cout<<1<<" ";
      --n;
   }

   cout<<1<<" ";

   for (int i = 1; i <= b; ++i)
   {
      cout<<(1LL<<i)<<" ";
   }

   for (int i = 1; i <= a; ++i)
   {
      cout<<((1LL<<b)+i)<<" ";
   }

   for (int i = 0; i < n - (a + b + 1); ++i)
   {
      cout<<1<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;
int32_t main(){_

   cin>>n>>a>>b;

   vector<int> A(n);

   A[0] = 100;

   int sum = 100;
   for (int i = 1; i < n; ++i)
   {
      if (b){
         A[i] = sum+1;
         --b;
      }
      else if(a){
         //b should not occur.
         A[i] = A[i-1] + 1;
         if(A[i] > sum){
            if(b == 0){
               cout<<-1;
               exit(0);
            }
            --b;
         }
         else{
            --a;
         }
         // if(A[i] > sum){
         //    if(b <= 0){
         //       cout<<"A = "<<A<<endl;
         //       cout<<-1;
         //       exit(0);
         //    }
         //    else{
         //       --b;
         //    }
         // }
         --a;
      }
      else{
         A[i] = A[i-1];
      }
      sum += A[i];
   }

   for(auto i: A)
      cout<<i<<' ';

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   vector<int> ans;
   int sum = 100;

   for (int i = 1; i <= n; ++i)
   {
      if (b){
         ans.push_back(sum + 1);
         --b;
      }
      else if (a){
         int prev = 100;
         if (!ans.empty()){
            prev = ans.back();
         }
         ans.push_back(prev + 1);
         --a;
      }
      else{
         int prev = 100;
         if (!ans.empty()){
            prev = ans.back();
         }
         ans.push_back(prev - 1);
      }
      sum += ans.back();
   }

   for (int i = 0; i < n; ++i)
   {
      cout<<ans[i]<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   if (b == 0 and a){
      if (a >= n-1){
         cout<<-1;
         exit(0);
      }
      cout<<1<<" ";
      --n;
   }

   cout<<1<<" ";
   int lst = 1;

   for (int i = 1; i <= b; ++i)
   {
      cout<<(1LL<<i)<<" ";
      lst = 1LL << i;
   }

   for (int i = 1; i <= a; ++i)
   {
      cout<<((1LL<<b)+i)<<" ";
      lst = ((1LL<<b)+i);
   }

   for (int i = 0; i < n - (a + b + 1); ++i)
   {
      cout<<lst<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;
int32_t main(){_

   cin>>n>>a>>b;

   vector<int> A(n);

   A[0] = 100;

   int sum = 100;
   for (int i = 1; i < n; ++i)
   {
      if (b){
         A[i] = sum+1;
         --b;
      }
      else if(a){
         A[i] = A[i-1] + 1;
         // if(A[i] > sum){
         //    if(b <= 0){
         //       cout<<"A = "<<A<<endl;
         //       cout<<-1;
         //       exit(0);
         //    }
         //    else{
         //       --b;
         //    }
         // }
         --a;
      }
      else{
         A[i] = A[i-1];
      }
      tr(a, b);
      sum += A[i];
   }

   for(auto i: A)
      cout<<i<<' ';

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   if (b == 0 and a){
      if (a >= n-1){
         cout<<-1;
         exit(0);
      }
      cout<<1<<" ";
      --n;
   }

   cout<<1<<" ";

   for (int i = 1; i <= b; ++i)
   {
      cout<<(1LL<<i)<<" ";
   }

   for (int i = 1; i <= a; ++i)
   {
      cout<<((1LL<<b)+i)<<" ";
   }

   for (int i = 0; i < n - (a + b + 1); ++i)
   {
      cout<<2<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   int na = a, nb = b;
   vector<int> ans;
   int sum = 0;

   for (int i = 1; i <= n; ++i)
   {
      if (i == 1){
         ans.push_back(1);
      }
      else if (b){
         ans.push_back(sum + 1);
         --b;
      }
      else if (a){
         ans.push_back(ans.back() + 1);
         --a;
      }
      else{
         ans.push_back(ans.back());
      }
      sum += ans.back();
   }

   tr(a, b, ans);
   int mx = ans[0];
   sum = ans[0];
   for (int i = 1; i < n; ++i)
   {
      tr(i, mx, sum, ans[i]);
      if (ans[i] > sum){
         if (nb == 0){
            if (na){
               ans[i] = mx + 1;
               --na;
            }
            else{
               ans[i] = ans[i-1];
            }
         }
         else{
            --nb;
         }
      }
      else if (ans[i] > mx){
         --na;
      }
      else{
         if (na){
            ans[i] = mx + 1;
            --na;
         }
      }
      smax(mx, ans[i]);
      sum += ans[i];
   }

   tr(na, nb, ans);
   if (na or nb){
      cout<<-1;
      exit(0);
   }

   for (int i = 0; i < n; ++i)
   {
      cout<<ans[i]<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;
int32_t main(){_

   cin>>n>>a>>b;

   vector<int> A(n);

   A[0] = 1;

   int sum = 1;
   for (int i = 1; i < n; ++i)
   {
      if (b){
         A[i] = sum+1;
         --b;
      }
      else if(a){
         //b should not occur.
         A[i] = A[i-1] + 1;
         if(A[i] > sum){
            if(b == 0){
               cout<<-1;
               exit(0);
            }
            --b;
         }
         else{
            --a;
         }
      }
      else{
         A[i] = A[i-1];
      }
      sum += A[i];
      if(A[i] > 50000){
         cout<<-1;
         exit(0);
      }
   }

   for(auto i: A)
      cout<<i<<' ';

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   int na = a, nb = b;
   vector<int> ans;
   int sum = 0;

   for (int i = 1; i <= n; ++i)
   {
      if (i == 1){
         ans.push_back(1);
      }
      else if (b){
         ans.push_back(sum + 1);
         --b;
      }
      else if (a){
         ans.push_back(ans.back() + 1);
         --a;
      }
      else{
         ans.push_back(ans.back());
      }
      sum += ans.back();
   }

   tr(a, b, ans);
   int mx = ans[0];
   sum = ans[0];
   for (int i = 1; i < n; ++i)
   {
      tr(i, mx, sum, ans[i]);
      if (ans[i] > sum){
         if (nb == 0){
            ans[i] = ans[i-1];
         }
         else{
            --nb;
         }
      }
      else if (ans[i] > mx){
         --na;
      }
      smax(mx, ans[i]);
      sum += ans[i];
   }

   tr(na, nb, ans);
   if (na or nb){
      cout<<-1;
      exit(0);
   }

   for (int i = 0; i < n; ++i)
   {
      cout<<ans[i]<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   vector<int> ans;
   int sum = 100;

   for (int i = 1; i <= n; ++i)
   {
      if (i == 1){
         ans.push_back(100);
      }
      else if (b){
         ans.push_back(sum + 1);
         --b;
      }
      else if (a){
         ans.push_back(ans.back() + 1);
         --a;
      }
      else{
         ans.push_back(ans.back() - 1);
      }
      sum += ans.back();
   }

   for (int i = 0; i < n; ++i)
   {
      cout<<ans[i]<<" ";
   }

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;
int32_t main(){_

   cin>>n>>a>>b;

   vector<int> A(n);

   A[0] = 100;

   int sum = 100;
   for (int i = 1; i < n; ++i)
   {
      if (b){
         A[i] = sum+1;
         --b;
      }
      else if(a){
         //b should not occur.
         A[i] = A[i-1] + 1;
         if(A[i] > sum){
            if(b == 0){
               cout<<-1;
               exit(0);
            }
            --b;
         }
         else{
            --a;
         }
      }
      else{
         A[i] = A[i-1];
      }
      sum += A[i];
   }

   for(auto i: A)
      cout<<i<<' ';

   return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b;

int32_t main(){_

   cin >> n >> a >> b;

   int na = a, nb = b;
   vector<int> ans;
   int sum = 0;

   for (int i = 1; i <= n; ++i)
   {
      if (i == 1){
         ans.push_back(1);
      }
      else if (b){
         ans.push_back(sum + 1);
         --b;
      }
      else if (a){
         ans.push_back(ans.back() + 1);
         --a;
      }
      else{
         ans.push_back(ans.back());
      }
      sum += ans.back();
   }

   tr(a, b, ans);
   int mx = ans[0];
   sum = ans[0];
   for (int i = 1; i < n; ++i)
   {
      tr(i, mx, sum, ans[i]);
      if (ans[i] > sum){
         if (nb == 0){
            ans[i] = ans[i-1];
         }
         else{
            --nb;
         }
      }
      else if (ans[i] > mx){
         --na;
      }
      else{
         if (na){
            ans[i] = ans[i-1] + 1;
            --na;
         }
      }
      smax(mx, ans[i]);
      sum += ans[i];
   }

   tr(na, nb, ans);
   if (na or nb){
      cout<<-1;
      exit(0);
   }

   for (int i = 0; i < n; ++i)
   {
      cout<<ans[i]<<" ";
   }

   return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		if (n - a == 1 and n > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		vector<ll> vv;
		vv.pb(2);

		ll p = 4;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		if (b == 0 && n > (b + 1))
		{
			vv.pb(2);
		}
		ll d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		d = vv[vv.size() - 1];

		for (ll i = vv.size(); i < n; i++)
			vv.pb(d);

		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		if (n - a == 1 and n > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		vector<ll> vv;
		vv.pb(2);

		ll p = 4;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		if (b == 0)
		{
			vv.pb(2);
		}
		ll d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		d = vv[vv.size() - 1];

		for (ll i = vv.size(); i < n; i++)
			vv.pb(d);

		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		vector<ll> vv;
		vv.pb(2);
		ll p = 4;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		ll d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		d = vv[vv.size() - 1];

		for (ll i = vv.size(); i < n; i++)
			vv.pb(d);
		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		if (n - a == 1 and n > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		vector<ll> vv;
		vv.pb(2);
		ll p = 4;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		ll d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		d = vv[vv.size() - 1];

		for (ll i = vv.size(); i < n; i++)
			vv.pb(d);
		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		if (n - a == 1 and n > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		vector<ll> vv;
		vv.pb(2);
		ll d = vv[vv.size() - 1];
		for (ll i = vv.size(); i < (n - (a + b)); i++)
			vv.pb(d);
		ll p = 4;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n, a, b;
		cin >> n >> a >> b;
		if (n - a == 1 and n > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		vector<ll> vv;
		vv.pb(1);

		ll p = 2;
		for (ll i = 0; i < b; i++)
		{
			vv.pb(p);
			p = p * 2;
		}
		if (b == 0 && n > (b + 1))
		{
			vv.pb(1);
		}
		ll d = vv[vv.size() - 1];
		d++;
		for (ll i = 0; i < a; i++)
		{
			vv.pb(d);
			d++;
		}
		d = vv[vv.size() - 1];

		for (ll i = vv.size(); i < n; i++)
			vv.pb(d);

		for (auto i : vv)
			cout << i << " ";
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
#ifndef	ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, wow, oh;
    cin >> n >> wow >> oh;
    if(n == 1 && (wow || oh)) {
        cout << -1;
        return 0;
    }
    if(!wow && oh == n - 1) {
        cout << -1;
        return 0;
    }
    ll cum[50900];
    ll cur = 0;
    cout << 1 << " ";
    int i = 2;
    for(; i <= oh + 1; ++i) {
        cout << i << " ";
        cum[i] += cum[i - 1] + i;
    }
    for(; i <= wow + oh + 1; ++i) {
        cout << cum[i - 1] * 2 << " ";
        cum[i] += cum[i - 1] + i;
    }
    n -= oh;
    n -= wow;
    for(int i = 0; i < n; ++i) {
        cout << 1 << " ";
    }
    cout << endl;
    return 0;
}