#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int a,b,n,q[2]={1,1};
int w[2][2]={{0,0},{1,1}};
int c[2][2]={{0,0},{1,1}};
int ans[2]={0};
int main()
{
freopen ("sequenceb.in","r",stdin);
freopen ("sequenceb.out","w",stdout);
cin>>a>>b>>n;
w[0][1]=b;
w[1][1]=a;
c[0][1]=b;
c[1][1]=a;
int num;
num=n-3;
while (num)
{
if ((num)%2==1)
{
int q[2][2]={0};
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
for (int k=0;k<2;k++)
{
q[i][j]+=(c[i][k]*w[k][j])%7;
}
}
}
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
c[i][j]=q[i][j];
}
}
}
num=num>>1;
int q[2][2]={0};
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
for (int k=0;k<2;k++)
{
q[i][j]+=(w[i][k]*w[k][j])%7;
}
}
}
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
w[i][j]=q[i][j];
}
}
}
for (int i=0;i<2;i++)
{
for (int k=0;k<2;k++)
{
ans[i]+=(q[i]*c[k][i])%7;
}
}
cout<<(ans[1])%7;
return 0;
}