#include <perms.h>
void Backgammon(_imp_string St) {
  static int Bboff;
  static int Wboff;
  static int Dice1;
  static int Dice2;
  static int Barfl;
  static int Brdval;
  static int Bstval;
  static int Compval;
  static int M1;
  static int M2;
  static int M3;
  static int M4;
  static int V1;
  static int V2;
  static int V3;
  static int V4;
  static int V5;
  static int V6;
  static int V7;
  static int V8;
  static int V9;
  static int V10;
  static int I;
  static int J;
  static int K;
  static int Running;
  static int Nomov;
  static int Barpt1;
  static int Barpt2;
  static int Pt1;
  static int Pt2;
  static int L;
  static int M;
  static int N;
  static int Temp;
  static int Bstmov1;
  static int Bstmov2;
  static int Bstpt1;
  static int Bstpt2;
  static int W1;
  static int W2;
  static int W3;
  static int W4;
  static int W5;
  static int W6;
  static int W7;
  static int W8;
  static int W9;
  static int W10;
  static int Second;
  static int Bv1;
  static int Bv2;
  static int Bv3;
  static int Bv4;
  static int Bv5;
  static int Bv6;
  static int Bv7;
  static int Bv8;
  static int Bv9;
  static int Bv10;
  static const int Odds[12 /*1:12*/] = {35, 38, 44, 47, 47, 53, 18, 21, 15, 12, 6, 9};
  typedef struct F {
    int Ws;
    int Bs;
  } F;
  static F Board[26 /*0:25*/];
  static int G;
  static int H;
  static int Pt3;
  static int Pt4;
  static int Dice3;
  static int Dice4;
  static int Bstpt3;
  static int Bstpt4;
  static int Barpt3;
  static int Barpt4;
  int Homeb(void) {
    int No;
    int I;
    No = Bboff;
    for (I = 1; I <= 6; I++) No += Board[I].Bs;
    if (No == 15)
      return (1);
    else
      return (0);
  }
  void Doblack(void) {
    int Pt;
    int No;
    int M;
    int D1;
    int D2;
    int D3;
    int D4;
    int Tot;
    Prompt(_imp_str_literal("Point:"));
    for (;;) {
      Read(D1);
      Read(D2);
      if (D1 > 6 || D2 > 6) {
        Printstring(_imp_str_literal("No way"));
        Newline();
      } else
        break;
    }
    if (D1 == D2) {
      D3 = D1;
      D4 = D2;
    } else {
      D3 = 0;
      D4 = 0;
    }
    Printstring(_imp_str_literal("Your throw was"));
    Write(D1, 2);
    Write(D2, 2);
    Newline();
    if (Board[25].Bs > 0) {
      if (Board[25 - D1].Ws > 1 && Board[25 - D2].Ws > 1) {
        Printstring(_imp_str_literal("You cannot move"));
        Newline();
        return;
      }
      if (Board[25].Bs != 1)
        if (D1 != D2) {
          if (Board[25 - D1].Ws > 1) {
            Board[25 - D2].Bs = Board[25 - D2].Bs + 1;
            Board[25].Bs = Board[25].Bs - 1;
            Board[25 - D2].Ws = 0;
            Board[0].Ws = Board[0].Ws + 1;
            Printstring(_imp_str_literal("I have made your move"));
            Newline();
            return;
          }
          if (Board[25 - D2].Ws > 1) {
            Board[25 - D1].Bs = Board[25 - D1].Bs + 1;
            Board[25].Bs = Board[25].Bs - 1;
            Board[25 - D1].Ws = 0;
            Board[0].Ws = Board[0].Ws + 1;
            Printstring(_imp_str_literal("I have made your move"));
            Newline();
            return;
          }
        }
    }
    Printstring(_imp_str_literal("Make your move"));
    Newline();
    for (M = 1; M <= 4; M++) {
    Agn:
      Tot = D1 + D2 + D3 + D4;
      if (!Tot) return;
      Read(Pt);
      if (Pt == 100) return;
      Read(No);
      if (!Board[Pt].Bs) {
        Printstring(_imp_str_literal("No blacks on point"));
        Newline();
        goto Agn;
      }
      if (Board[25].Bs != 0 && Pt != 25) {
        Printstring(_imp_str_literal("You have pieces on the bar"));
        Newline();
        goto Agn;
      }
      if (Pt - No <= 0) {
        if (!Homeb()) {
          Printstring(_imp_str_literal("Not all home"));
          Newline();
          goto Agn;
        }
        goto Legmov;
      }
      if (Board[Pt - No].Ws > 1) {
        Printstring(_imp_str_literal("White has point"));
        Newline();
        goto Agn;
      }
    Legmov:
      if (No == D1)
        D1 = 0;
      else if (No == D2)
        D2 = 0;
      else if (No == D3)
        D3 = 0;
      else if (No == D4)
        D4 = 0;
      else {
        Printstring(_imp_str_literal("Illegal move"));
        Newline();
        goto Agn;
      }
      if (Pt - No <= 0) goto Bbearo;
      Board[Pt].Bs = Board[Pt].Bs - 1;
      Board[Pt - No].Bs = Board[Pt - No].Bs + 1;
      if (Board[Pt - No].Ws == 1) {
        Board[Pt - No].Ws = 0;
        Board[0].Ws = Board[0].Ws + 1;
      }
      goto Skp;
    Bbearo:
      Bboff++;
      Board[Pt].Bs = Board[Pt].Bs - 1;
      if (Bboff == 15) return;
    Skp:;
    }
  }
  void Initialize(void) {
    Wboff = 0;
    Bboff = 0;
    Board[1].Ws = 2;
    Board[6].Bs = 5;
    Board[8].Bs = 3;
    Board[12].Ws = 5;
    Board[13].Bs = 5;
    Board[17].Ws = 3;
    Board[19].Ws = 5;
    Board[24].Bs = 2;
  }
  void Printstate(void) {
    int I;
    int J;
    int K;
    int M;
    Newlines(2);
    Printstring(_imp_str_literal(" 12  11  10   9   8   7      6   5   4   3   2   1"));
    Newline();
    Printstring(_imp_str_literal("___________________________________________________"));
    for (I = 0; I <= 6; I++) {
      Newline();
      Spaces(2);
      for (J = 12; J >= 1; J--) {
        if (Board[J].Ws > I) {
          Printsymbol('W');
          goto Rpt;
        }
        if (Board[J].Bs > I) {
          Printsymbol('B');
          goto Rpt;
        }
        Space();
      Rpt:
        if (J == 7)
          Printstring(_imp_str_literal("  **  "));
        else
          Spaces(3);
      }
    }
    for (K = 6; K >= 0; K--) {
      Newline();
      Spaces(2);
      for (M = 13; M <= 24; M++) {
        if (Board[M].Ws > K) {
          Printsymbol('W');
          goto Rpt2;
        }
        if (Board[M].Bs > K) {
          Printsymbol('B');
          goto Rpt2;
        }
        Space();
      Rpt2:
        if (M == 18)
          Printstring(_imp_str_literal("  **  "));
        else
          Spaces(3);
      }
    }
    Newline();
    Printstring(_imp_str_literal("____________________________________________________"));
    Newline();
    Printstring(_imp_str_literal(" 13  14  15  16  17  18      19  20  21  22  23  24"));
    Newline();
    if (Board[0].Ws > 0) {
      Newline();
      Printstring(_imp_str_literal("There are"));
      Write(Board[0].Ws, 2);
      Printstring(_imp_str_literal(" whites on the bar"));
    }
    if (Board[25].Bs > 0) {
      Newline();
      Printstring(_imp_str_literal("there are"));
      Write(Board[25].Bs, 2);
      Printstring(_imp_str_literal(" blacks on the bar"));
    }
    if (Wboff > 0) {
      Newline();
      Printstring(_imp_str_literal("white has born off"));
      Write(Wboff, 3);
    }
    if (Bboff > 0) {
      Newline();
      Printstring(_imp_str_literal("black has born off"));
      Write(Bboff, 3);
    }
    Newline();
  }
  int Bbar(void) { return (Board[25].Bs); }
  int Wbar(void) { return (Board[0].Ws); }
  int Bsin(void) {
    int I;
    int J;
    J = 0;
    for (I = 1; I <= 25; I++)
      if (Board[I].Bs == 1) J++;
    return (J);
  }
  int Wsin(void) {
    int I;
    int J;
    J = 0;
    for (I = 0; I <= 24; I++)
      if (Board[I].Ws == 1) J++;
    return (J);
  }
  int Bsincl(void) {
    int I;
    int J;
    int K;
    int Sum;
    Sum = 0;
    for (I = 25; I >= 1; I--)
      if (Board[I].Bs == 1) {
        if (I - 12 < 0)
          J = 0;
        else
          J = I - 12;
        for (K = I - 1; K >= J; K--)
          if (Board[K].Ws > 0) Sum += Odds[I - K];
      }
    return (Sum);
  }
  int Wsincl(void) {
    int I;
    int J;
    int K;
    int Sum;
    Sum = 0;
    for (I = 0; I <= 24; I++)
      if (Board[I].Ws == 1) {
        if (I + 12 > 25)
          J = 25;
        else
          J = I + 12;
        for (K = I + 1; K <= J; K++)
          if (Board[K].Bs > 0) Sum += Odds[K - I];
      }
    return (Sum);
  }
  int Wptshome(void) {
    int I;
    int J;
    J = 0;
    for (I = 19; I <= 24; I++)
      if (Board[I].Ws > 1) J++;
    return (J);
  }
  int Bptshome(void) {
    int I;
    int J;
    J = 0;
    for (I = 1; I <= 6; I++)
      if (Board[I].Bs > 1) J++;
    return (J);
  }
  int Wpts(void) {
    int I;
    int J;
    J = 0;
    for (I = 1; I <= 24; I++)
      if (Board[I].Ws > 1) J++;
    return (J);
  }
  int Bpts(void) {
    int I;
    int J;
    J = 0;
    for (I = 1; I <= 24; I++)
      if (Board[K].Bs > 1) J++;
    return (J);
  }
  int Wptssucc(void) {
    int I;
    int J;
    int K;
    K = 0;
    for (J = 1; J <= 22; J++)
      if (Board[J].Bs > 0) {
        for (I = J + 1; I <= 23; I++)
          if (Board[I].Ws > 1)
            if (Board[I + 1].Ws > 1) K++;
        break;
      }
    return (K);
  }
  int Bptssucc(void) {
    int I;
    int J;
    int K;
    K = 0;
    for (J = 24; J >= 3; J--)
      if (Board[J].Ws > 0) {
        for (I = J - 1; I >= 2; I--)
          if (Board[I].Bs > 1)
            if (Board[I - 1].Bs > 1) K++;
        break;
      }
    return (K);
  }
  int Bfst3(void) {
    int I;
    int J;
    J = 0;
    for (I = 22; I <= 25; I++) J += Board[I].Bs;
    return (J);
  }
  int Wfst3(void) {
    int I;
    int J;
    J = 0;
    for (I = 0; I <= 3; I++) J += Board[I].Ws;
    return (J);
  }
  int Bfst6(void) {
    int I;
    int J;
    J = 0;
    for (I = 19; I <= 25; I++) J += Board[I].Bs;
    return (J);
  }
  int Wfst6(void) {
    int I;
    int J;
    J = 0;
    for (I = 0; I <= 6; I++) J += Board[I].Ws;
    return (J);
  }
  int Bfst12(void) {
    int I;
    int J;
    J = Bfst6();
    for (I = 13; I <= 18; I++) J += Board[I].Bs;
    return (J);
  }
  int Wfst12(void) {
    int I;
    int J;
    J = Wfst6();
    for (I = 7; I <= 12; I++) J += Board[I].Ws;
    return (J);
  }
  int Whome(void) {
    int I;
    int J;
    J = 0;
    for (I = 19; I <= 24; I++) J += Board[I].Ws;
    return (J);
  }
  int Bhome(void) {
    int I;
    int J;
    J = 0;
    for (I = 1; I <= 6; I++) J += Board[I].Bs;
    return (J);
  }
  int Wtogo(void) {
    int I;
    int J;
    int K;
    int Sum;
    Sum = 0;
    for (I = 0; I <= 18; I++) {
      J = Board[I].Ws;
      if (J > 0)
        for (K = 1; K <= J; K++) Sum = Sum + 19 - I;
    }
    return (Sum);
  }
  int Btogo(void) {
    int I;
    int J;
    int K;
    int Sum;
    Sum = 0;
    for (I = 7; I <= 25; I++) {
      J = Board[I].Bs;
      if (J > 0)
        for (K = 1; K <= J; K++) Sum = Sum + I - 6;
    }
    return (Sum);
  }
  void Gbrdval(void) {
    V1 = W1 * (Bbar() - Wbar());
    V2 = W2 * (Bsin() - Wsin());
    V3 = W3 * (Bsincl() - Wsincl()) / 10;
    V4 = W4 * (Wptshome() - Bptshome());
    V5 = W5 * (Wpts() - Bpts());
    V6 = W6 * (Wptssucc() - Bptssucc());
    V7 = W7 * (Bfst6() - Wfst6());
    V8 = W8 * (Btogo() / 6 - Wtogo() / 6);
    V9 = W9 * (Bfst3() - Wfst3());
    V10 = W10 * (Whome() - Bhome());
    Brdval = V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10;
  }
  void Gbrd(void) {
    V1 = W1 * (Bbar());
    V2 = W2 * (-Wsin());
    V3 = W3 * (-Wsincl()) / 10;
    V4 = W4 * (Wptshome());
    V5 = W5 * (Wpts());
    V6 = W6 * (Wptssucc());
    V7 = W7 * (-Wfst6());
    V8 = W8 * (-Wtogo()) / 6;
    V9 = W9 * (-Wfst3());
    V10 = W10 * (Whome());
    Brdval = V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10;
    if (Brdval > Bstval) {
      Bv1 = V1;
      Bv2 = V2;
      Bv3 = V3;
      Bv4 = V4;
      Bv5 = V5;
      Bv6 = V6;
      Bv7 = V7;
      Bv8 = V8;
      Bv9 = V9;
      Bv10 = V10;
      Bstval = Brdval;
      Bstmov1 = Dice1;
      Bstpt1 = Pt1;
      Bstmov2 = Dice2;
      Bstpt2 = Pt2;
      Bstpt3 = Pt3;
      Bstpt4 = Pt4;
    }
  }
  void Mtstmov(int P, int D, int *Bp) {
    Board[P].Ws = Board[P].Ws - 1;
    Board[P + D].Ws = Board[P + D].Ws + 1;
    if (Board[P + D].Bs == 1) {
      Board[P + D].Bs = 0;
      Board[25].Bs = Board[25].Bs + 1;
      *Bp = 1;
    }
  }
  void Cltstmov(int P, int D, int *Bp) {
    Board[P].Ws = Board[P].Ws + 1;
    Board[P + D].Ws = Board[P + D].Ws - 1;
    if (*Bp == 1) {
      Board[P + D].Bs = 1;
      Board[25].Bs = Board[25].Bs - 1;
      *Bp = 0;
    }
  }
  void Mmove(int P, int D) {
    Board[P].Ws = Board[P].Ws - 1;
    Board[P + D].Ws = Board[P + D].Ws + 1;
    Board[25].Bs = Board[25].Bs + Board[P + D].Bs;
    Board[P + D].Bs = 0;
  }
  void Good(int *S, int *Wt) {
    if (!*S) return;
    if (*S < 0)
      *Wt = *Wt - 1;
    else
      *Wt = *Wt + 1;
  }
  void Bad(int *S, int *Wt) {
    if (!*S) return;
    if (*S > 0)
      *Wt = *Wt - 1;
    else
      *Wt = *Wt + 1;
  }
  void Loadwts(void) {
    W1 = 19;
    W2 = 117;
    W3 = 102;
    W4 = 15;
    W5 = 15;
    W6 = 12;
    W7 = 64;
    W8 = 43;
    W9 = 62;
    W10 = 15;
  }
  void Dumpwts(void) {
    Selectoutput(2);
    Newlines(3);
    Write(W1, 1);
    Newline();
    Write(W2, 1);
    Newline();
    Write(W3, 1);
    Newline();
    Write(W4, 1);
    Newline();
    Write(W5, 1);
    Newline();
    Write(W6, 1);
    Newline();
    Write(W7, 1);
    Newline();
    Write(W8, 1);
    Newline();
    Write(W9, 1);
    Newline();
    Write(W10, 1);
  }
  int Wbearo(void) {
    int I;
    int J;
    J = Wboff;
    for (I = 19; I <= 24; I++) J += Board[I].Ws;
    return (J);
  }
  void Dobest(int D) {
    if (D)
      if (Board[25 - D].Ws > 0) {
        Board[25 - D].Ws = Board[25 - D].Ws - 1;
        Wboff++;
      } else if (Board[25 - D + 1].Ws > 0) {
        Board[25 - D + 1].Ws = Board[25 - D + 1].Ws - 1;
        Wboff++;
      } else {
        for (M = 19; M <= 25 - D; M++)
          if (Wboff < 8) {
            if (Board[M].Ws > 2) {
              Mmove(M, D);
              return;
            }
          } else if (Board[M].Ws > 1) {
            Mmove(M, D);
            return;
          }
        for (M = 19; M <= 24; M++)
          if (Dice2 + M < 25) {
            if (Board[M].Ws > 0) {
              Mmove(M, Dice2);
              return;
            }
          } else if (Board[M].Ws > 0) {
            Board[M].Ws = Board[M].Ws - 1;
            Wboff++;
            return;
          }
      }
  }
  void Mtstboff(int Num, int Die) {
    if (Num + Die < 25)
      if (!Board[Num + Die].Bs)
        Mmove(Num, Die);
      else
        Nomov = 1;
    else {
      Board[Num].Ws = Board[Num].Ws - 1;
      Wboff++;
    }
  }
  void Cltstboff(int Num, int Die) {
    Temp = 0;
    if (Num + Die < 25)
      Cltstmov(Num, Die, Temp);
    else {
      Board[Num].Ws = Board[Num].Ws + 1;
      Wboff--;
    }
  }
  Loadwts();
  Selectinput(0);
  Closestream;
  Initialize();
  Printstate();
Strt:
  for (;;) {
    Read(Dice1);
    Read(Dice2);
    Bstval = 0x80000000;
    if (Dice1 == Dice2) {
      Dice3 = Dice1;
      Dice4 = Dice2;
    } else {
      Dice3 = 0;
      Dice4 = 0;
    }
    Running = 0;
    if (Wbearo() == 15) goto Bearoff;
    Temp = Bboff;
    for (L = 0; L <= 24; L++) {
      if (Board[L].Ws > 0) break;
      Temp += Board[L].Bs;
    }
    if (Temp == 15) {
      Running = 1;
      goto Run;
    }
    M1 = 0;
    M2 = 0;
    M3 = 0;
    M4 = 0;
    Barfl = 0;
    if (Wbar() > 0) {
      if (Wbar() > 1) {
        if (Board[Dice1].Bs < 2) Mmove(0, Dice1);
        if (Board[Dice2].Bs < 2) Mmove(0, Dice2);
        goto Done;
      }
      if (Board[Dice1].Bs > 1 && Board[Dice2].Bs > 1) goto Done;
      Barfl = 1;
    }
    for (K = 1; K <= 2; K++) {
      if (K == 1)
        Second = 0;
      else {
        Temp = Dice1;
        Dice1 = Dice2;
        Dice2 = Temp;
        Second = 1;
      }
      for (I = 0; I <= 23; I++) {
        if (Board[I].Ws > 0)
          Pt1 = I;
        else
          goto Cyc1;
        if (Pt1 + Dice1 < 25 && Board[Pt1 + Dice1].Bs < 2) {
          Mtstmov(Pt1, Dice1, Barpt1);
          M1 = 1;
          if (Wbearo() == 15) {
            Dice1 = 0;
            goto Bearoff;
          }
          if (Second == 1)
            N = I + 1;
          else
            N = I;
          for (J = N; J <= 24; J++) {
            if (Board[J].Ws > 0)
              Pt2 = J;
            else
              goto Cyc2;
            if (Pt2 + Dice2 < 25 && Board[Pt2 + Dice2].Bs < 2) {
              Mtstmov(Pt2, Dice2, Barpt2);
              M2 = 1;
              if (Dice1 == Dice2) {
                if (Wbearo() == 15) {
                  Dice2 = 0;
                  Dice1 = 0;
                  goto Bearoff;
                }
                for (G = J; G <= 23; G++) {
                  if (Board[G].Ws > 0)
                    Pt3 = G;
                  else
                    goto Cyc3;
                  if (Pt3 + Dice1 < 25 && Board[Pt3 + Dice1].Bs < 2) {
                    Mtstmov(Pt3, Dice1, Barpt3);
                    M3 = 1;
                    if (Wbearo() == 15) {
                      Dice1 = 0;
                      Dice2 = 0;
                      Dice3 = 0;
                      goto Bearoff;
                    }
                    for (H = G; H <= 23; H++) {
                      if (Board[H].Ws > 0)
                        Pt4 = H;
                      else
                        goto Cyc4;
                      if (Pt4 + Dice2 < 25 && Board[Pt4 + Dice2].Bs < 2) {
                        Mtstmov(Pt4, Dice2, Barpt4);
                        M4 = 1;
                        Gbrd();
                        Cltstmov(Pt4, Dice2, Barpt4);
                      }
                    Cyc4:;
                    }
                    if (!M4) {
                      Gbrd();
                      Bstval = 0x80000000;
                    }
                    Cltstmov(Pt3, Dice1, Barpt3);
                  }
                Cyc3:;
                }
                if (!M3) {
                  Gbrd();
                  Bstval = 0x80000000;
                }
              } else
                Gbrd();
              Cltstmov(Pt2, Dice2, Barpt2);
            }
          Cyc2:;
          }
          if (!M2) {
            Gbrd();
            Bstval = 0x80000000;
          }
          Cltstmov(Pt1, Dice1, Barpt1);
        }
        if (Barfl == 1) break;
      Cyc1:;
      }
      if (Dice1 == Dice2) break;
    }
    if (M1 == 1) Mmove(Bstpt1, Bstmov1);
    if (M2 == 1) Mmove(Bstpt2, Bstmov2);
    if (Dice1 == Dice2) {
      if (M3 == 1) Mmove(Bstpt3, Bstmov1);
      if (M4 == 1) Mmove(Bstpt4, Bstmov2);
    }
  Done:
    if (Wboff == 15) {
      Printstring(_imp_str_literal("yeah"));
      Newline();
      break;
    }
    Printstate();
    Doblack();
    if (Bboff == 15) {
      Printstring(_imp_str_literal("pity"));
      Newline();
      break;
    }
    if (Running == 1) goto Strt;
    Gbrdval();
    if (Brdval == Compval) goto Strt;
    if (Compval < Brdval) {
      Good(Bv1, W1);
      Good(Bv2, W2);
      Good(Bv3, W3);
      Good(Bv4, W4);
      Good(Bv5, W5);
      Good(Bv6, W6);
      Good(Bv7, W7);
      Good(Bv8, W8);
      Good(Bv9, W9);
      Good(Bv10, W10);
    } else {
      Bad(Bv1, W1);
      Bad(Bv2, W2);
      Bad(Bv3, W3);
      Bad(Bv4, W4);
      Bad(Bv5, W5);
      Bad(Bv6, W6);
      Bad(Bv7, W7);
      Bad(Bv8, W8);
      Bad(Bv9, W9);
      Bad(Bv10, W10);
    }
    Compval = Brdval;
    goto Strt;
  Run:
    if (Dice2 > Dice1) {
      Temp = Dice2;
      Dice2 = Dice1;
      Dice1 = Temp;
    }
    Temp = 0;
    for (I = 1; I <= 18; I++)
      if (Board[I].Ws > 0) {
        Mmove(I, Dice1);
        Temp = 1;
        for (J = I; J <= 18; J++)
          if (Board[J].Ws > 0) {
            if (Dice1 != Dice2)
              Mmove(J, Dice2);
            else
              Mmove(J, Dice1);
            Temp = 2;
            if (Dice1 == Dice2)
              for (G = J; G <= 18; G++)
                if (Board[G].Ws > 0) {
                  Mmove(G, Dice1);
                  Temp = 3;
                  for (H = G; H <= 18; H++)
                    if (Board[H].Ws > 0) {
                      Mmove(H, Dice2);
                      Temp = 4;
                      break;
                    }
                  break;
                }
            break;
          }
        break;
      }
    if (Dice1 == Dice2 && Temp == 4) goto Done;
    if (Dice1 != Dice2 && Temp == 2) goto Done;
    if (Dice1 != Dice2) {
      Dice1 = 0;
      goto Bearoff;
    }
    Dice1 = 0;
    if (Temp > 1) Dice2 = 0;
    if (Temp > 2) Dice3 = 0;
  Bearoff:
    Running = 1;
    Temp = Wboff;
    for (M = 24; M >= 19; M--) {
      if (Board[M].Bs > 0) goto Safety;
      Temp += Board[M].Ws;
      if (Temp == 15) break;
    }
    if (Dice1 > Dice2) {
      Temp = Dice2;
      Dice2 = Dice1;
      Dice1 = Temp;
    }
    if (Dice1)
      if (Board[25 - Dice1].Ws > 0) {
        Board[25 - Dice1].Ws = Board[25 - Dice1].Ws - 1;
        Wboff++;
      } else if (Board[25 - Dice1 + 1].Ws > 0) {
        Board[25 - Dice1 + 1].Ws = Board[25 - Dice1 + 1].Ws - 1;
        Wboff++;
      } else {
        for (M = 19; M <= 25 - Dice1; M++)
          if (Wboff < 8) {
            if (Board[M].Ws > 2) {
              Mmove(M, Dice1);
              goto Sec;
            }
          } else if (Board[M].Ws > 1) {
            Mmove(M, Dice1);
            goto Sec;
          }
        for (M = 19; M <= 24; M++) {
          if (Dice2 + M < 25)
            if (Board[M].Ws > 0) {
              Mmove(M, Dice1);
              break;
            }
          if (M + Dice2 == 25)
            if (Board[M].Ws > 1) {
              Mmove(M, Dice1);
              break;
            }
          if (Dice2 + M > 25)
            if (Board[M].Ws > 0) {
              if (M + Dice1 < 25)
                Mmove(M, Dice1);
              else {
                Wboff++;
                Board[M].Ws = Board[M].Ws - 1;
              }
              break;
            }
        }
      }
  Sec:
    Dobest(Dice2);
    if (!Dice4) goto Done;
    Dobest(Dice3);
    Dobest(Dice4);
    goto Done;
  Safety:
    if (Dice4)
      if (!Dice3) {
        Dice1 = Dice4;
        Dice4 = 0;
      } else if (!Dice2) {
        Dice1 = Dice4;
        Dice4 = 0;
        Dice2 = Dice3;
        Dice3 = 0;
      } else if (!Dice1) {
        Dice1 = Dice4;
        Dice4 = 0;
      } else if (!Dice1) {
        Dice1 = Dice2;
        Dice2 = 0;
      }
    if (Dice1 < Dice2) {
      Temp = Dice2;
      Dice2 = Dice1;
      Dice1 = Temp;
    }
    for (K = 35; K <= 56; K += 3)
      for (I = 19; I <= 24; I++) {
        if (Board[I].Ws > 0) {
          Nomov = 0;
          Mtstboff(I, Dice1);
          if (Nomov == 1) goto Rep1;
          if (!Dice2) {
            if (Wsincl() < K) goto Done;
          } else
            for (J = 19; J <= 24; J++) {
              if (Board[J].Ws > 0) {
                Nomov = 0;
                Mtstboff(J, Dice2);
                if (Nomov == 1) goto Rep2;
                if (!Dice3) {
                  if (Wsincl() < K) goto Done;
                } else
                  for (G = 19; G <= 24; G++) {
                    if (Board[G].Ws > 0) {
                      Nomov = 0;
                      Mtstboff(G, Dice3);
                      if (Nomov == 1) goto Rep3;
                      if (!Dice4) {
                        if (Wsincl() < K) goto Done;
                      } else
                        for (H = 19; H <= 24; H++) {
                          if (Board[H].Ws > 0) {
                            Nomov = 0;
                            Mtstboff(H, Dice4);
                            if (Nomov == 1) goto Rep4;
                            if (Wsincl() < K) goto Done;
                            Cltstboff(H, Dice4);
                          }
                        Rep4:;
                        }
                      Cltstboff(G, Dice3);
                    }
                  Rep3:;
                  }
                Cltstboff(J, Dice2);
              }
            Rep2:;
            }
          Cltstboff(I, Dice1);
        }
      Rep1:;
      }
  }
  Dumpwts();
}
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  Backgammon(_imp_str_literal(""));
  exit(0);
  return (1);
}
