#include using namespace std; using ll = long long; const int mx = 1e6; bool vis[4][mx+1]; int h,w; bool ans[mx+1]; inline int tok(int i,int j){ return i * w + j; } ll k; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>h>>w; cin>>k; ll now = 0; int ni = 0; int nj = 0; int dx = 1; int dy = 1; stack>> st; st.push(make_pair(0,make_pair(0,0))); vis[0][tok(0,0)] = 0; bool fn = false; while(true){ if(now==k) break; ans[tok(ni,nj)] ^= 1; int nni = ni + dx; if(nni<0||nni>=h){ nni = ni; dx *= -1; } int nnj = nj + dy; if(nnj<0||nnj>=w){ nnj = nj; dy *= -1; } ni = nni; nj = nnj; now++; if(fn) continue; int mask = 0; if(dx==-1) mask += 1; if(dy==-1) mask += 2; if(vis[mask][tok(nni,nnj)]==0){ vis[mask][tok(nni,nnj)] = 1; st.push(make_pair(mask,make_pair(nni,nnj))); continue; } vis[mask][tok(nni,nnj)] = 1; stack> nxt; ll cnt = 0; pair> want = make_pair(mask,make_pair(nni,nnj)); while(true){ if(st.top()==want){ cnt++; nxt.push(make_pair(nni,nnj)); break; } int nx = st.top().second.first; int ny = st.top().second.second; cnt++; nxt.push(make_pair(nx,ny)); st.pop(); continue; } fn = true; ll res = k - now; ll can = res / cnt; if(can%2==1){ while(nxt.size()){ int ni = nxt.top().first; int nj = nxt.top().second; ans[tok(ni,nj)] ^= 1; nxt.pop(); } } now += can * cnt; } for(int i = 0;i