def parse(inFile):
    [H,W,D] = inFile.getInts()
    return (H,W,D,[inFile.readline() for k in xrange(H)])

from fractions import Fraction, gcd

def cansee((H,W),(x,y),(dx,dy),D,grid):
    if (dy < 0):
        return cansee((H,W),(x,(W - 1 - y)),(dx,-dy),D,[z[::-1] for z in grid])
    if (dx < 0):
        return cansee((H,W),((H - 1 - x),y),(-dx,dy),D,grid[::-1])
    if (dx == 0) and (dy == 1):
        z = y + 1
        while grid[x][z] == ".":
            z = z + 1
        return (2 * (z - y) - 1) <= D
    if (dy == 0) and (dx == 1):
        z = x + 1
        while grid[z][y] == ".":
            z = z + 1
        return (2 * (z - x) - 1) <= D
    kk = 1
    while ((kk + 1) * (kk + 1)) * (dx * dx + dy * dy) <= D * D:
        kk += 1
    horizontalIntersections = [[Fraction(2*k-1,2*dx),0] for k in xrange(1,dx+1)]
    verticalIntersections = [[Fraction(2*k-1,2*dy),1] for k in xrange(1,dy+1)]
    if (dx & dy & 1):
        half = Fraction(1,2)
        ints = [z for z in horizontalIntersections if z[0] != half] + [z for z in verticalIntersections if z[0] != half] + [[half,2]]
    else:
        ints = horizontalIntersections+verticalIntersections
    if True:
        ints.sort()
        posn = (Fraction(2*x+1,2),Fraction(2*y+1,2))
        dirn = (dx, dy)
        timeAt = 0
        for m in xrange(kk):
            for isn in ints:
                dt = isn[0] - timeAt
                timeAt = isn[0]
                posn = (posn[0] + dirn[0] * dt, posn[1] + dirn[1] * dt)
                (xat,yat) = (int(posn[0]),int(posn[1]))
                if (isn[1] == 0):
                    if (dirn[0] > 0) and grid[xat][yat] == "#":
                        dirn = (-dirn[0],dirn[1])
                    elif (dirn[0] < 0) and grid[xat-1][yat] == "#":
                        dirn = (-dirn[0],dirn[1])
                elif (isn[1] == 1):
                    if (dirn[1] > 0) and grid[xat][yat] == "#":
                        dirn = (dirn[0],-dirn[1])
                    elif (dirn[1] < 0) and grid[xat][yat-1] == "#":
                        dirn = (dirn[0],-dirn[1])
                elif (isn[1] == 2):
                    nowx =  xat if (dirn[0] < 0) else (xat - 1)
                    nextx = (xat - 1) if (dirn[0] < 0) else xat
                    nowy =  yat if (dirn[1] < 0) else (yat - 1)
                    nexty = (yat - 1) if (dirn[1] < 0) else yat
                    up = grid[nextx][nowy] == "#"
                    right = grid[nowx][nexty] == "#"
                    ur = grid[nextx][nexty] == "#"
                    assert(grid[nowx][nowy] != "#")
                    if ur:
                        if up:
                            if right:
                                dirn = (-dirn[0], -dirn[1])
                            else:
                                dirn = (-dirn[0], dirn[1])
                        else:
                            if right:
                                dirn = (dirn[0], -dirn[1])
                            else:
                                return False
            dt = 1 - timeAt
            timeAt = 0
            posn = (posn[0] + dirn[0] * dt, posn[1] + dirn[1] * dt)
            if (posn == (Fraction(2*x+1,2),Fraction(2*y+1,2))):
                return True
    return False

def solve((H,W,D,grid)):
    count = 0
    (x,y) = [(i,j) for i in xrange(H) for j in xrange(W) if grid[i][j] == "X"][0]
    for dx in xrange(-D,D+1):
        for dy in xrange(-D,D+1):
            if (dx * dx + dy * dy) <= D * D and abs(gcd(dx,dy)) == 1:
                if cansee((H,W),(x,y),(dx,dy),D,grid):
                    count += 1
    return count

if __name__ == "__main__":
    from GCJ import GCJ
    GCJ(parse, solve, "/Users/lpebody/gcj/2012_q/", "d").run()

            
