#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{

    srand((int) time(0));
    int total = 0;
    int breakpoint = 0;
    int range = 0;
    while(breakpoint!=-1) {
        cout<<"Brakepoint: ";
        cin>>breakpoint;
        cout<<"Range: ";
        cin>>range;

        int a = 999001;
        int b = 999002;
        int c = 999003;
        int d = 999004;
        int e = 999005;
        int f = 999006;
        int g = 999007;
        int h = 999008;
        int i = 999009;
        int j = 999010;
        int k = 999011;
        int l = 999012;
        int m = 999013;
        int n = 999014;
        int o = 999015;
        int p = 999016;
        int q = 999017;
        int r = 999018;
        int s = 999019;
        int t = 999020;
        int u = 999021;
        int v = 999026;
        int w = 999027;
        int x = 100028;
        int y = 100029;
        int z = 100030;

        while(1) {

            total=-1;
            int cnt=0;

            while(total != 0) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                z = (rand() % range)-(range/2);
                e = (rand() % range)-(range/2);
                r = (rand() % range)-(range/2);
                o = (rand() % range)-(range/2);
                total = z+e+r+o;
            }
            if(breakpoint==0) {
                cout<<"Done @ 0: "<<total<<endl;
                break;
            }
            cnt=0;

            while(total != 1 || n==z || z==o || o==r || r==e) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                n = (rand() % range)-(range/2);
                total = o+n+e;

            }
            if(breakpoint==1) {
                cout<<"Done @ 1: "<<total<<endl;
                break;
            }
            cnt=0;

            while(total != 2 || t==w || w==o  || o==n || n==e || e==z || z==r) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                t = (rand() % range)-(range/2);
                w = (rand() % range)-(range/2);
                total=t+w+o;

            }


            cnt=0;

            if(breakpoint==2) {
                cout<<"Done @ 2: "<<total<<endl;
                break;
            }

            while(total !=3 || t==h || h==r || r==e || e==w || w==o || o==n) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                h = (rand() % range)-(range/2);

                total=t+h+r+e+e;
            }
            if(breakpoint==3) {
                cout<<"Done @ 3: "<<total<<endl;
                break;
            }
            cnt=0;

            while(total !=4 || f==o || o==u || u==r || r==n || n==e || e==t || t==w || w==h) {

                cnt++;
                if(cnt>500) {
                    goto esc;
                }

                f = (rand() % range)-(range/2);
                u = (rand() % range)-(range/2);
                total=f+o+u+r;

            }

            cnt=0;
            if(breakpoint==4) {
                cout<<"Done @ 4: "<<total<<endl;
                break;
            }

            while(total !=5  || f==i || i==v || v==e || e==o || o==n || n==t || t==w || w==h || h==r || r==f || f==u) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }

                i = (rand() % range)-(range/2);
                v = (rand() % range)-(range/2);
                total=f+i+v+e;


            }
            cnt=0;
            if(breakpoint==5) {
                cout<<"Done @ 5: "<<total<<endl;
                break;
            }
            while(total !=6 || s==x || x==f || f==i || i==v || v==e || e==o || o==n || n==t || t==w || w==h || h==r || r==f || f==u) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                s = (rand() % range)-(range/2);
                x = (rand() % range)-(range/2);
                total=s+i+x;


            }
            cnt=0;
            if(breakpoint==6) {
                cout<<"Done @ 6: "<<total<<endl;
                break;
            }
            total=s+e+v+e+n;
            if(total!=7) {
                goto esc;
            }
            if(breakpoint==7) {
                cout<<"Done @ 7: "<<total<<endl;
                break;
            }
            while(total !=8 || v==g || g==s || s==x || x==f || f==i || i==v || v==e || e==o || o==n || n==t || t==w || w==h || h==r || r==f || f==u) {
                cnt++;
                if(cnt>500) {
                    goto esc;
                }
                g = (rand() % range)-(range/2);
                total=e+i+g+h+t;
                cnt++;
            }
            cnt=0;
            if(breakpoint==8) {
                cout<<"Done @ 8 :"<<total<<endl;
                break;
            }
            total=n+i+n+e;
            if(total!=9) {
                goto esc;
            }
            if(breakpoint==9) {
                cout<<"Done @ 9: "<<total<<endl;
                break;
            }
            total=t+e+n;
            if(total!=10) {
                goto esc;
            }
            if(breakpoint==10) {
                cout<<"Done @ 10: "<<total<<endl;
                break;
            }

	esc:
            int foo=1;
        }
        cout<<"ZERO:   "<<z<<" "<<e<<" "<<r<<" "<<o<<" "<<z+e+r+o<<endl;
        cout<<"ONE:   "<<o<<" "<<n<<" "<<e<<" "<<o+n+e<<endl;
        cout<<"TWO:   "<<t<<" "<<w<<" "<<o<<" "<<t+w+o<<endl;
        cout<<"THREE: "<<t<<" "<<h<<" "<<r<<" "<<e<<" "<<e<<" "<<t+h+r+e+e<<endl;
        cout<<"FOUR:  "<<f<<" "<<o<<" "<<u<<" "<<r<<" "<<f+o+u+r<<endl;
        cout<<"FIVE:  "<<f<<" "<<i<<" "<<v<<" "<<e<<" "<<f+i+v+e<<endl;
        cout<<"SIX:   "<<s<<" "<<i<<" "<<x<<" "<<s+i+x<<endl;
        cout<<"SEVEN: "<<s<<" "<<e<<" "<<v<<" "<<e<<" "<<n<<" "<<s+e+v+e+n<<endl;
        cout<<"EIGHT: "<<e<<" "<<i<<" "<<g<<" "<<h<<" "<<t<<" "<<e+i+g+h+t<<endl;
        cout<<"NINE:  "<<n<<" "<<i<<" "<<n<<" "<<e<<" "<<n+i+n+e<<endl;
        cout<<"TEN:   "<<t<<" "<<e<<" "<<n<<" "<<t+e+n<<endl;

    }
    return 0;
}