http://codeforces.com/contest/450/problem/B
#include<iostream> #include<cstdlib> #include<cstdlib> using namespace std; typedef long long LL; const long long mod=1000000007; int main(){ LL a[4]; LL x,y; LL n,ans; while(cin>>x>>y>>n){ a[1]=x;a[2]=y;a[0]=y-x; LL ch=n/3; LL mo=n%3; if(mo) ch++; ans=a[mo]%mod; if(ch%2==0) ans*=-1; while(ans<0) ans+=mod; cout<<ans%mod<<endl; } return 0; }