function Main(input) {
  var tmp = input[0].split(" ");
  X = parseInt(tmp[0], 10);
  Y = parseInt(tmp[1], 10);

  var result;
  if (Y < X / 2) {
    result = 0;
  } else if (Y == X / 2) {
    result = 1;
  } else if (Y > 2 * X) {
    result = 0;
  } else if (Y == 2 * X) {
    result = 1;
  } else if (X == Y) {
    if (X % 3 == 0) {
      var times = X / 3;
      result = Math.pow(2, times) % 1000000007;
    } else {
      result = 0;
    }
  } else if (Y > X) {
    var x_diff = X % 3;
    var y_diff = Y % 3;
    var times = Math.floor(X / 3);
    if (y_a == x_diff * 2) {
      result = (Math.pow(2, times) + 1) % 1000000007;
    } else {
      result = 0;
    }
  }

  console.log("%s", result);
}

Main(
  require("fs")
    .readFileSync("/dev/stdin", "utf8")
    .split("\n")
);
