1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#include <bits/stdc++.h>
#include "cielib.h"
using namespace std;
#define maxn 510
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define e1 first
#define e2 second
#define For(a, b, i) for(int i=a;i<b;i++)
bool q1=false;ll h=0;bool u=false;
int t[2],p[maxn],t1[1];int d,k,r;
int f(int x)
{
	if(u==false) return 2*h-x;
	else return 2*h-x-1;
}
bool w1(int y, int x)
{
	int wyn1=-1, wyn2=-1;
	wyn1=max(wyn1, abs(x-p[0]));
	wyn2=max(wyn2, abs(y-p[0]));
	///printf("%d %d\n", x, y);
	///printf("%lld %lld\n", wyn1, wyn2);
	if(wyn1<wyn2) return true;
	else return false;
}
bool w2(int x, int y)
{
	int wyn1=-1, wyn2=-1;
	wyn1=max(abs(x-p[0]), abs(x-p[1]));
	wyn2=max(abs(y-p[0]), abs(y-p[1]));
	///printf("%lld %lld\n", wyn1, wyn2);
	///printf("%d %d\n\n", x, y);
	if(wyn1<wyn2) {t[0]=x;t[1]=x;return true;}
	else return false;
}
bool w3(int x, int y)
{
	ll wyn1=-1, wyn2=-1;
	wyn1=max(abs(x-p[0]), abs(f(x)-p[1]));
	wyn2=max(abs(y-p[0]), abs(f(y)-p[1]));
	///printf("%lld %lld\n", wyn1, wyn2);printf("x1 %d %d\nx2 %d %d\n\n", x, f(x), y, f(y));
	if(wyn1<wyn2) {t[0]=x;t[1]=f(x);return true;}
	else return false;
}
int main()
{
	/*scanf("%d%d", &d, &r);
	For(0, d, i) scanf("%d", &p[i]);*/
	d=podajD();
	k=podajK();
	r=podajR();
	
	bool q=false;
	if(d==1)
	{
		int wyn=0;
		t1[0]=0;
		For(0, r+2, i) {t1[0]=i; if(czyCieplo(t1)==0 && i!=0) {wyn=i-1;q=true;break;}; if(q==true) break;}
		t1[0]=wyn;
		
		znalazlem(t1);
		
	}
	
	if(d==2)
	{
		///ll wyn[2];
		/*For(0, r+2, i) {if(w2(i ,i-1)==false && i!=0) {t[0]=i-1;t[1]=i-1;q=true;break;}; if(q==true) break;};///printf("%lld %lld\n", t[0], t[1]);
		if(w2(t[0], t[0]+1)==false) t[1]++,u=true;
		///printf("%lld %lld\n", t[0], t[1]);
		h=t[1];
		t[0]=0;t[1]=f(0);
		For(0, r+2, i) if(w3(i, i-1)==false && i!=0 && q1==false) {t[0]=i-1;t[1]=f(i-1);q1=true;}///q=w3(i, i-1);
		printf("%d %d\n", t[0], t[1]);*/
		
		t[0]=0;t[1]=0;
		For(0, r+2, i) 
		{
			if(czyCieplo(t)==0 && i!=0) {t[0]=i-1;t[1]=i-1;q=true;break;}
			else t[0]=i-1,t[1]=i-1;
			if(q==true) break;
		}///printf("%lld %lld\n", t[0], t[1]);
		t[0]++;t[1]++;
		if(czyCieplo(t)==0) t[1]++,u=true;
		t[0]--;t[1]--;
		///printf("%lld %lld\n", t[0], t[1]);
		t[0]=-10000000;t[1]=-10000000;
		int gg=czyCieplo(t);
		h=t[1];t[0]=0;t[1]=f(0);
		For(0, r+2, i) 
		{
			if(czyCieplo(t)==0 && i!=0 && q1==false) 
			{
				t[0]=i-1;t[1]=f(i-1);q1=true;
			}
			else t[0]=i-1,t[1]=f(i-1); 
			if(q==true) break;
		}///q=w3(i, i-1);
		///printf("%lld %lld\n", t[0], t[1]);
		znalazlem(t);
	}
}