/*
TASK:future
LANG:C++
*/

#include<cstdio>
#include<string>

struct longint
{
	int a[256];
	longint(){for(int i=0; i<256; i++) a[i]=0; }
	int len()
	{
		int i;
		for(i=255; a[i]==0 && i>=0; i--);
		return i;
	}
	void read()
	{
		char c[256];
		gets(c);
		int l=strlen(c);
		for(int i=0; i<l; i++) a[i]=c[l-i-1]-'0';
	}
	void write()
	{
		for(int i=len(); i>=0; i--) printf("%d", a[i]);
		printf("\n");
	}
	void norm()
	{
		int l=len();
		for(int i=0; i<l; i++)
		{
			if(a[i]>9){ a[i+1]+=a[i]/10; a[i]%=10; }
			else if(a[i]<0){ a[i+1]--; a[i]=10-a[i]; }
		}
	}
	void inc(longint b)
	{
		for(int i=0; i<256; i++) a[i]+=b.a[i];
		norm();
	}
	void dec(longint b)
	{
		for(int i=0; i<256; i++) a[i]-=b.a[i];
		norm();
	}
	void mul1(int cif) //umn. s cifra ili 10
	{
		int l=len();
		for(int i=0; i<=l; i++) a[i]*=cif;
		norm();
	}
	void mul2(int god)
	{
		longint s1, s2;
		s1=*this; s2=*this;
		s1.mul1(god/10);
		s1.mul1(10);
		s2.mul1(god%10);
		s1.inc(s2);
		*this=s1;
	}
	int cmp(longint b)
	{
		int l1=len(), l2=b.len();
		if(l1>l2) return 1;
		if(l1<l2) return -1;
		for(int i=l1; i>=0; i--)
		{
			if(a[i]>b.a[i]) return 1;
			if(a[i]<b.a[i]) return -1;
		}
		return 0;
	}		
};

int cif[10];
int main()
{
	longint a, b;
	int g;
	a.read();
	b.read();
	scanf("%d", &g);
	if(a.cmp(b)<0)
	{
		longint t=a;
		a=b;
		b=t;
	}
	a.dec(b);
	a.mul2(g);
	a.write();
	int sb=0, l=a.len();
	int i;
	for(i=0; i<l; i++)
	{
		cif[ a.a[i] ]++;
		sb+=a.a[i];
	}
	int tmp=a.a[l];
	while(tmp)
	{
		cif[tmp%10]++;
		sb+=tmp%10;
		tmp/=10;
	}
	for(i=1; i<10; i++) if(sb%i) cif[i]=0;
	int max=0;
	for(i=0; i<10; i++) if(cif[i]>max) max=cif[i];
	for(i=0; i<l; i++)
		if(cif[a.a[i]]==max)
		{
			printf("%d\n", a.a[i]);
			return 0;
		}
	tmp=a.a[l];
	while(tmp)
	{
		if(cif[tmp%10]==max){ printf("%d\n", tmp%10); return 0; }
		tmp/=10;
	}
	printf("0\n");
	return 0;
}
