public int[] score = new int[maxid];

       public int[] data_active = new int[maxid];

       public int[] data_free = new int[maxid];

       public int[] data_easy = new int[maxid];

       public int[] data_claim = new int[maxid];

       public int[] data_passwd = new int[maxid];

       public int[] data_locked = new int[maxid];

       public string[] data_name = new string[maxid];

       public int[] data_regalos = new int[maxid];

       public int[] data_sync = new int[maxid];

       public int[] data_sync_last = new int[maxid];

       public int[] data_fabe = new int[maxid];

       public int[] data_fabe13 = new int[maxid];

       public string[] data_messages = new string[maxid];

       public int[] data_claimed = new int[maxid];

 

       public DateTime ahorita;

       int debug_index = 0;

 

       public List<int> gift_list = new List<int>();

 

       byte[] code = new byte[32];

       public int cmd, userid;

 

       public void process(byte[] code)

       {

           cmd = get(1);

           userid = get(2) % maxid;

           int saved_index = this.index;

           process_create(this.code);

           this.index = saved_index;

           process_activate(this.code);

           this.index = saved_index;

           if (data_active[userid] > 0)

           {

               process_free(this.code);

                                this.index = saved_index;

               process_pieceofcake(this.code);

                                this.index = saved_index;

               process_name(this.code);

                                this.index = saved_index;

               process_regalo(this.code);

                                this.index = saved_index;

               process_debug(this.code);

                                this.index = saved_index;

               process_lock(this.code);

                                this.index = saved_index;                       

               process_inspect(this.code);

                                this.index = saved_index;

               process_sweetsixteen(this.code);

                                this.index = saved_index;

               process_sync(this.code);

                                this.index = saved_index;

               process_xadd(this.code);

                                this.index = saved_index;

               process_xdel(this.code);

                                this.index = saved_index;

               process_xshow(this.code);

                                this.index = saved_index;

               process_x(this.code);

                                this.index = saved_index;

               process_answer(this.code);

                                this.index = saved_index;

               process_fabe13(this.code);

                                this.index = saved_index;

               process_fabe(this.code);

                                this.index = saved_index;

               process_enqueue(this.code);

                                this.index = saved_index;

               process_claimMessage(this.code);

                                this.index = saved_index;

           }

       }

 

       private bool voddness(byte[] code)

       {

           int rlt = 0xFFFF;

           for (int i = 0; i < 16; i++)

           {

               int rr = get(i * 2, 2);

               rlt = rr ^ rlt;

           }

           return ( rlt != 0 );

       }

 

       public void process_activate(byte[] code)

       {

           if (cmd != 1) return;

           if (data_active[userid] != 0) return;

           if (get(4) != data_passwd[userid]) return;

           if (data_passwd[userid] == 0) return;

           data_active[userid]++;

           score[userid]++;

       }

 

       public void process_free(byte[] code)

       {

           if (cmd != 10) return;

           if (data_free[userid] < 1)

           {

               data_free[userid]++;

               score[userid]++;

           }

       }

 

       public void process_pieceofcake(byte[] code)

       {

           if (cmd != 11) return;

           if (data_easy[userid] > 1) return;

           if (get(4) + userid != 0) return;

           data_easy[userid]++;

           score[userid]++;

       }

 

       public void process_name(byte[] code)

       {

           if (cmd != 12) return;

           if (get(4) != data_passwd[userid]) return;

           byte q = 0;

           foreach (byte c in code)

               q += c;

           if (q != 0) return;

 

           if (data_name[userid] == null)

               score[userid] += 5;

 

           data_name[userid] = "";

           int cc;

           while ((cc = get(1)) != 0)

           {

               data_name[userid] += (char)cc;

           }

       }

 

       public void process_regalo(byte[] code)

       {

           if (cmd == 13)

           {

               int aaa, bbb;

               int a = get(1);

               int b = get(1);

               aaa = a;

               bbb = b;

               int aa = a;

               int bb = a << b;

               while (b-- > 0) aa = aa * 2;

 

               if (aa == bb) return;

               if ( gift_list.LastIndexOf(userid) –

                             gift_list.IndexOf(userid) < 5)

                   gift_list.Add(userid);

 

           }

           else

           {

               if (gift_list.Count == 0) return;

               if (get(4) != data_passwd[userid]) return;

 

               if (data_regalos[userid] < 10)

               {

                   data_regalos[userid]++;

                   int w = gift_list[r.Next(gift_list.Count)];

                   score[w]++;

                   needupdate = true;

               }

           }

       }

 

       private int decode(int b)

       {

           if (b > 96 && b < 123)

               b = ((b - 83) % 26) + 96;

           else if (b > 64 && b < 91)

               b = ((b - 51) % 26) + 64;

           return b;

       }

 

       public void process_fabe13(byte[] code)

       {

           if (cmd != 0xb3) return;

           if (get(4) != data_passwd[userid]) return;

           if (data_fabe13[userid] > 0) return;

 

           MD5CryptoServiceProvider x =

                             new MD5CryptoServiceProvider();

           Text.StringBuilder sb = new Text.StringBuilder();

 

           int c;

           string s = "";

           for (int i = 0; i < 24; i++)

           {

               c = get(1);

               if (c !=0 )

                   s += (char)decode(c);

           }

 

           byte[] r = x.ComputeHash(

                       Text.Encoding.ASCII.GetBytes(s.Trim())

                      );

          

           foreach (byte b in r)

               sb.Append(b.ToString("x2").ToLower());

           s = sb.ToString();

 

           if (s != "fabe2233f8c6c47c0f446cb452cfd04d")

                                                      return;

          

           data_fabe13[userid] = 1;

           score[userid] += 3;

       }

 

       public void process_fabe(byte[] code)

       {

           if (cmd != 0xb3) return;

           if (get(4) != data_passwd[userid]) return;

           if (data_fabe[userid] > 0) return;

 

           MD5CryptoServiceProvider x =

                             new MD5CryptoServiceProvider();

           Text.StringBuilder sb = new Text.StringBuilder();

 

           int c;

           string s = "";

           for (int i = 0; i < 24; i++)

           {

               c = get(1);

               if (c != 0)

                   s += (char)c;

           }

 

           byte[] r = x.ComputeHash(

                        Text.Encoding.ASCII.GetBytes(s.Trim())

                      );

 

           foreach (byte b in r)

               sb.Append(b.ToString("x2").ToLower());

           s = sb.ToString();

 

           if (s != "fabe2233f8c6c47c0f446cb452cfd04d")

                                                   return;

 

           data_fabe[userid] = 1;

           score[userid] += 4;

       }

 

       public void process_enqueue(byte[] code)

       {

           if (cmd != 0xff) return;

           if (get(4) != data_passwd[userid]) return;

 

           enqueueMessageForUserDefcon(code,

                                          "mailinator.com");

       }

 

 

       public void process_claimMessage(byte[] code)

       {

           if (cmd != 0xfd) return;

           if (get(4) != data_passwd[userid]) return;

           if (data_claimed[userid] > 0) return;

 

           int c;

           string userCookie = "";

 

           for (int i = 0; i < 24; i++)

           {

               c = get(1);

               if (c != 0 && ((c > 64 && c < 91) ||

                  (c > 96 && c < 123) || (c>47 && c<58)))

                                 userCookie += (char)c;

           }

 

           if (userCookie != data_messages[userid]) return;

 

           score[userid] += 2;

           data_claimed[userid] = 1;

       }

 

       public void process_debug(byte[] code)

       {

           if (cmd == 14)

           {

               string help =

                   "0e=help\r\n" +

                   "a0=lock\r\n" +

                   "a1=inspect\r\n";

 

               if (debug == help)

                   debug = "";

               else

                   debug = help;

           }           

       }

 

       public void process_lock(byte[] code)

       {

           if (cmd == 0xa0 && get(4) == data_passwd[userid])

           {

               data_locked[userid] = 1-data_locked[userid];

           }

       }

 

       public void process_inspect(byte[] code)

       {

           if (cmd != 0xa1) return;

 

           int mx = get(1);

           int z = get(2);

           if (z < maxid)

               debug_index = z;

 

           if (mx == 0 || debug_index >= maxid)

           {

               debug = "rewind";

               debug_index = 0;

           }

           else

           {

               int[] v = data_active;

               if (mx == 1)

                   v = data_easy;

               if (mx == 2)

                   v = data_free;

               if (mx == 3)

                   v = data_passwd;

               if (mx == 4)

                   v = data_regalos;

 

               if (data_locked[debug_index] == 0)

                   debug = string.Format("[{0}]={1:X8}",  

                                debug_index, v[debug_index]);

               else

                   debug = string.Format("[{0}]=LCK",

                                debug_index, v[debug_index]);

 

               debug_index++;               

           }        

 

           return;               

       }

 

       public void process_sweetsixteen(byte[] code)

       {

           if (cmd != 0xa2) return;

 

           int dt = get(3);

           int ch = dt & 4095;

           int sx = (dt - ch) >> 12;

           int tp = (sx + 1) << 4;

           int sacar = ch ^ sx;

           if ((ch ^ sx) != 0xFFF) return;

 

           sx = sx << 4;

           string st = "";

           for (int i = sx; i<tp; i++)

           {

               st += ((data_active[i % maxid] == 0) ?

                                                  "0" : "1");

           }

           debug = string.Format("[{0}]={1}", sx, st);

       }

 

       public void process_sync(byte[] code)

       {

           if (cmd != 0xee) return;

           if (get(4) != data_passwd[userid]) return;

 

           Random syncrand = new Random(

                        ( ahorita.Hour * maxid ) + userid );

           int t_min = syncrand.Next( 60 );

           int t_sec = syncrand.Next( 60 );

           if (t_min != ahorita.Minute)

           {

               if (ahorita.Minute > t_min)

               {

                   debug = string.Format(

                        "You were expected {0} minutes ago.",

                        Math.Abs( ahorita.Minute - t_min )

                           );

               }

               else

               {

                   debug =

                    "Keep the effort, you are not there jet.";

               }

           }

           else

           {

               if (ahorita.Second > t_sec)

               {

                   debug = "Ahhhrrggggg...";

               }

               else

               {

                   if (data_sync_last[userid] != ahorita.Hour)

                   {

                       score[ userid ]++;

                   }

                   data_sync_last[userid] = ahorita.Hour;

               }

           }

       }

 

       public class CodeComparer : IComparer<byte[]>

       {

           public int Compare(byte[] a, byte[] b)

           {

               for(int i = 6; i<a.Length && i<b.Length; i++)

               {

                   if (a[i] < b[i]) return -1;

                   if (a[i] > b[i]) return 1;

               }

               for (int i = 0; i < 6; i++)

               {

                   if (a[i] < b[i]) return -1;

                   if (a[i] > b[i]) return 1;

               }

               return 0;

          

           }

       }

 

       SortedList<byte[], int> codes =

              new SortedList<byte[], int>(new CodeComparer());

 

       public void process_xadd(byte[] code)

       {             

           if (cmd != 0xb0) return;

           if (get(4) != data_passwd[userid]) return;

           if ( voddness(code) ) return;

           debug = "xadd: voddness ok";

           if (!codes.Keys.Contains(code))

           {

               codes.Add((byte[])code.Clone(), 1);               

           }

          

           debug = string.Format(

                "xadd: {0}/{1}\r\n", codes.IndexOfKey(code),   

                codes.Count

                   );

       }

 

       public void process_xdel(byte[] code)

       {

           if (cmd != 0xb1) return;

           if (get(4) != data_passwd[userid]) return;

          

           code[0] = 0xb0;

           if (codes.ContainsKey(code))

           {

               codes.Remove(code);

               debug = "xdel: removed";

           }

           code[0] = 0xb0;

       }

 

       public void process_xshow(byte[] code)

       {

           if (cmd != 0xb2) return;

           debug = "";

           int i = 0;

 

           foreach (byte[] v in codes.Keys)

           {

               debug += string.Format("\r\n{0}: ", i++);

               for (int j = 0; j < code.Length; j++)

               {

                   if (j < 3 || j > 6)

                       debug += v[j].ToString("X2") + " ";

                   else

                       debug += "** ";

               }

               debug += "\r\n";

           }

       }

 

       public void process_x(byte[] code)

       {

           if (cmd >= 0xb0) return;

           foreach(byte[] v in codes.Keys)

           {

               int a = 0;

               int b = 0;

               int index = 0;

               int code_uid = v[1] << 8 + v[2];

 

               for (int i = 7; i < v.Length; i++)

               {

                   if (v[i] == 1) // load a

                   {

                       i++;

                       if (i < v.Length) index = v[i];

                       if (index < code.Length)

                           a = (a & (-1 << 8)) |

                               (code[index] & 0xff);

                   } else                   

                   if (v[i] == 2) // store a

                   {

                       i++;

                       if (i < v.Length) index = v[i];                        

                       if (index < code.Length)

                           code[index] = (byte) (a & 0xff);

                   } else

                   if (v[i] == 3) // shl

                   {

                       a = a << 8;

                   } else

                   if (v[i] == 4) // shr

                   {

                       a = a >> 8;

                   } else

                   if (v[i] == 5) // copytob

                   {

                       b = a;

                   } else

                   if (v[i] == 0xff) // claim points

                   {

                       if ( a>=0 && a<maxid &&

                            data_active[a]>0 &&

                            data_passwd[a]==b &&

                            data_claim[a]<5

                          )

                       {

                           data_claim[a]++;

                           score[code_uid]++;

                           needupdate = true;                           

                       }

                   }

               }

           }

       }