public void Set(int i) {
    Range cur = head, prev = null;
    while (cur != null && i >= cur.from-1) {
      if (i <= cur.to + 1) { // (cur.from-1) <= i <= (cur.to+1)
        if (i == cur.from - 1) cur.from--;
        else if (i == cur.to + 1) {
          cur.to++;
          Range next = cur.next;
          if (next != null && cur.to == next.from - 1) { cur.to = next.to; cur.next = next.next; };
        }
        return;
      }
      prev = cur; cur = cur.next;
    }
    Range n = new Range(i, i);
    n.next = cur;
    if (prev == null) head = n; else prev.next = n;
  }