context: using System;
  using System.Net.Http.Headers;
  using System.Text;
  using System.Net.Http;
  using System.Web;
  using Newtonsoft.Json;
  using Newtonsoft.Json.Linq;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.IO;
  
  namespace MAGSearch
  {
  
      public class Program
      {
          static string cquery = "Id,RId,F.FId,C.CId,J.JId,AA.AfId,AA.AuId";
          static string rquery = "Id,AA.AuId";
          static string irquery = "Id,RId";
  
          static void Main(string[] args)
          {
              long id1 = 2332023333;
              long id2 = 57898110;
  
              int startTime = Environment.TickCount;
              Console.WriteLine(solve(id1, id2));
              int endTime = Environment.TickCount;
              Console.WriteLine(endTime - startTime + "ms");
              //Console.ReadLine();
  
          }
  
          public static string solve(long id1, long id2)
          {
              Answer ans = new Answer();
              ans.start = id1;
              ans.end = id2;
              var q1 = AllDeserial(MakeRequest("Id=" + id1, rquery, 1, 0));
              var q2 = AllDeserial(MakeRequest("Id=" + id2, rquery, 1, 0));
  
              string ret = "Not Implemeted";
              if (q1[0].AA.Count == 0)
              {
                  if (q2[0].AA.Count == 0)
                  {
                      Console.WriteLine("auid->auid");
                      ret = auid2auid(id1, id2, ans);
                  }
                  else
                  {
                      Console.WriteLine("auid->id");
                      ret = auid2id(id1, id2, ans);
                  }
              }
              else
              {
                  if (q2[0].AA.Count == 0)
                  {
                      Console.WriteLine("id->aauid");
                      ret = id2auid(id1, id2, ans);
                  }
                  else
                  {
                      Console.WriteLine("id->id");
                      ret = id2id(id1, id2, ans);
                  }
              }
              Console.WriteLine(ans.count());
              return ret;
          }
  
          static string id2id(long id1, long id2, Answer ans)
          {
              // get information about start and destination
              var q1 = AllDeserial(MakeRequest("Id=" + id1, cquery, 1, 0));
              var q2 = AllDeserial(MakeRequest("Id=" + id2, cquery, 1, 0));
  
              // 1-hop
              if (Paper.hasLinkRId(q1[0], q2[0])) ans.add1Hop();
  
              // 2-hop
              ans.add2Hop(id_id_2Hop(q1[0], q2[0]));
  
              // 3-hop
              id_id_3Hop(q1[0], q2[0], ans);
  
              return ans.toJson();
          }
  
          static string id2auid(long id1, long id2, Answer ans)
          {
              // get information about start and destination
              var q1 = AllDeserial(MakeRequest("Id=" + id1, cquery, 1, 0));
  
  
              // 1-hop paper->author
              if (Paper.hastheAAuId(q1[0], id2)) ans.add1Hop();
  
  
              // 2-hop paper->paper->author
              ans.add2Hop(id1_auid_hop2(q1[0], id2));
  
              // 3-hop paper->...->paper->author || paper->author->afid->author
              id1_auid_hop3(q1[0], id2, ans);
  
              return ans.toJson();
          }
  
          static string auid2id(long id1, long id2, Answer ans)
          {
  
              // get information about start and destination
              var q1 = AllDeserial(MakeRequest("Composite(AA.AuId=" + id1 + ")", cquery, 10000, 0)); //get all the paper written by the author
              var q2 = AllDeserial(MakeRequest("Id=" + id2, cquery, 1, 0)); //get the target paper
  
  
              foreach (var v in q1) //author->paper
              {
                  if (v.Id == id2) ans.add1Hop(); // author->paper
                  if (v.Rid.Contains(id2)) ans.add2Hop(v.Id); //author->paper->paper
                  var mylist = new List<long>();
                  mylist = id_id_2Hop(v, q2[0]); //author->paper->...->paper
                  foreach (var lis in mylist)
                  {
                      ans.add3Hop(v.Id, lis);
                  }
  
              }
  
  
              var list = new HashSet<long>();//author->afid->author->paper
              foreach (var v in q1)
              {
                  foreach (var r in v.AA)
                  {
                      if (r.AuId == id1 && r.AfId > 0) list.Add(r.AfId);
                  }
              }
  
              foreach (var i in q2[0].AA)
              {
                  if (list.Contains(i.AfId))
                      ans.add3Hop(i.AfId, i.AuId);
              }
  
              foreach (var v in q1)  // author->paper->paper->paper
              {
  
                  var cidqst = MakeRequest("RId=" + id2, "Id", 10000, 0);
                  var qcid = IdDeserial(cidqst);
                  foreach (var c in qcid)
                  {
                      if (v.Rid.Contains(c)) ans.add3Hop(v.Id, c);
                  }
  
              }
  
              return ans.toJson();
          }
  
          static string auid2auid(long id1, long id2, Answer ans)
          {
  
              // get information about start and destination
              var q1 = AllDeserial(MakeRequest("Composite(AA.AuId=" + id1 + ")", cquery, 10000, 0)); // get all the paper written by the id1
              var q2 = AllDeserial(MakeRequest("Composite(AA.AuId=" + id2 + ")", cquery, 10000, 0)); // get all the paper written by the id2
  
              var list = new HashSet<long>(); // author->afid->author
              foreach (var v in q1)
              {
                  foreach (var r in v.AA)
                  {
                      if (r.AuId == id1 && r.AfId > 0) list.Add(r.AfId);
                  }
              }
  
              foreach (var v in q2)
              {
                  foreach (var r in v.AA)
                  {
                      if (r.AuId == id2 && list.Contains(r.AfId))
                          ans.add2Hop(r.AfId);
                  }
              }
  
              foreach (var v1 in q1)
              {
                  foreach (var v2 in q2)
                  {
                      if (v1.Id == v2.Id) ans.add2Hop(v1.Id); // author->paper->author
                      if (Paper.hasLinkRId(v1, v2)) ans.add3Hop(v1.Id, v2.Id); // author->paper->paper->author;
                  }
              }
              return ans.toJson();
          }
  
          static List<long> id1_auid_hop2(Paper p1, long id2) // solve paper->paper->author
          {
              var list = new List<long>();
              foreach (var r in p1.Rid)
              {
                  var cidqst = MakeRequest(Paper.queryComposite("AA.auid", id2, "Id", r), "Id", 10000, 0);
  
gt:                 var qcid = IdDeserial(cidqst);