# -*- coding:utf-8 -*- if __name__ == '__main__': f0, f1, n = map(int, input().split()) f = f0, f1, f0 ^ f1 print(f[n % 3])