Predict where the man will go A man lives in the north-west corner (0, 0) of a town with height h and width w . Everyday he walks from his home to the border (?, w) or (h, ?). In the following example, the man goes to (3, 3) today.

(0, 0) +--+  +  +  . (0, 4)
          |         
       +  +--+--+  .
                |   
       +  +  +  +  .
                |   
(3, 0) .  .  .  .  . (3, 4)


The man records a bit at each points (+ in example above). Every time he reaches a point, he goes east if the bit is 1 and south otherwise. The bit is flipped after he leaves. For example:

Day 1: 1--0  1  1    Day 2: 0  1  1  1    Day 3: 1--1--1--1--  Day 4: 0  0  0  0  
          |                 |                                         |           
       0  1--0  0           0  0  1  0           1  0  1  0           1--0  1  0  
             |              |                                            |        
       1  0  1--0           1--0  0  1           0  1  0  1           0  1--0  1  
                |              |                                            |     
Destination: (3, 3)  Destination: (3, 1)  Destination: (0, 4)  Destination: (3, 2)


Given the size of the town and the man's record, calculate the man's destination after n days.

Input:

In the first line are three integers, h, w and n.

In the following h lines are w integers, denoting the man's record.

h &lt;= 1000, w &lt;= 1000, n &lt;= 1000000000

Output:

Two integers, denoting the man's destination after n days.

Sample Input:

3 4 3
1 0 1 1
0 1 0 0
1 0 1 0


Sample Output:

0 4


Sample Code:

#include &lt;iostream&gt;
using namespace std;
bool d[1000][1000];
int main(){
    int h, w, n;
    cin &gt;&gt; h &gt;&gt; w &gt;&gt; n;
    for(int i = 0; i &lt; h; i++)
        for(int j = 0; j &lt; w; j++)
            cin &gt;&gt; d[i][j];
    int i, j;
    while(n--)
        for(i = 0, j = 0; i &lt; h &amp;&amp; j &lt; w;){
            bool &amp;b = d[i][j];
            d[i][j] ? j++ : i++;
            b = !b;
        }
    cout &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; endl;
}


Scoring:


Lowest byte count in UTF-8 wins.
If the running time of your code is independent of n, reduce your score by 50%. 

Don't just calculate the results of all 1000000000 days or do anything similarly stupid to get this bonus. Find an efficient algorithm!
Python 2, 192 bytes * 0.5 bonus = 96
To solve this problem efficiently, the key realization is that we can compute how many times each cell is visited based on the number of times the cells above and to the left are visited, without needing to determine the exact paths taken. Effectively, we simulate n trips at once and keep track of how many times each cell is used.
Substantial improvement due to push-based approach inspired by johnchen902's solution:
r=lambda:map(int,raw_input().split())
h,w,n=r()
v=[n]+w*[0]
x=y=0
for i in range(h):
 for j,b in enumerate(r()):
    if i-x==j-y==0:d=v[j]&amp;1^b;x+=d;y+=1^d
    f=v[j]+b&gt;&gt;1;v[j]-=f;v[j+1]+=f
print x,y

Previous, pull-based implementation:
r=lambda i:map(int,raw_input().split())
h,w,n=r(0)
x=range(h)
g=map(r,x)
v=[w*[0]for i in x]
v[0][0]=n-1
for i in x:
 for j in range(w):v[i][j]+=(i and(v[i-1][j]+(1^g[i-1][j]))/2)+(j and(v[i][j-1]+g[i][j-1])/2)
i=j=0
while i&lt;h and j&lt;w:f=g[i][j]^v[i][j]&amp;1;j+=f;i+=1^f
print i,j

Original, ungolfed version:
h, w, n = map(int, raw_input().split())
grid = [map(int, raw_input().split()) for i in xrange(h)]

# Determine the number of times each cell was visited in the first n-1 trips
visits = [[0]*w for i in xrange(h)]
visits[0][0] = n-1
for i in xrange(h):
    for j in xrange(w):
        if i:
            # Count visits from above cell
            visits[i][j] += (visits[i-1][j] + (not grid[i-1][j])) // 2
        if j:
            # Count visits from left cell
            visits[i][j] += (visits[i][j-1] + grid[i][j-1]) // 2

# Flip the bits corresponding to each cell visited an odd number of times
for i in xrange(h):
    for j in xrange(w):
        grid[i][j] ^= visits[i][j] &amp; 1

# Figure out where the final trip ends
i = j = 0
while i &lt; h and j &lt; w:
    if grid[i][j]:
        j += 1
    else:
        i += 1

print i, j