Problem: Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

<image>

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.

Output

Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.

If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them. 

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4
1 2
1 3
2 4
3 3


Output

9
3
2 3 1 


Input

2
1 1
2 1


Output

2
2
2 1 

Solution (in PYTHON):

Solution:
def cmp(p, q):
    return 1 if p[1] < q[1] else (0 if p[1] == q[1] else -1)

def init():
    n = int(raw_input())
    cube = list()
    mhash = dict()
    m = 0
    for i in xrange(0, n):
        cube.append(map(int, raw_input().split()) + [i + 1])
        if cube[i][0] not in mhash:
            mhash[cube[i][0]] = m
            m = m + 1
        cube[i][0] = mhash[cube[i][0]]
    cube.sort(cmp)
    return n, m, cube

def solve(n, m, cube):
    res = 0
    ans = [0, 0]
    f = [[0, 0] for i in xrange(0, n)]
    w = [[0, 0] for i in xrange(0, n)]
    h = [0 for i in xrange(0, m)]
    s = [0 for i in xrange(0, m)]
    for g in cube:
        s[g[0]] = s[g[0]] + g[1]
        h[g[0]] = h[g[0]] + 1
        height = h[g[0]]
        if s[g[0]] > f[height][0]:
            f[height][1] = f[height][0]
            w[height][1] = w[height][0]
            f[height][0] = s[g[0]]
            w[height][0] = g[0]
        elif s[g[0]] > f[height][1]:
            f[height][1] = s[g[0]]
            w[height][1] = g[0]
    for i in xrange(0, n):
        if f[i][0] > 0 and f[i][1] > 0 and f[i][0] + f[i][1] > res:
            res = f[i][0] + f[i][1]
            ans = [w[i][0], w[i][1]]
    for i in xrange(0, n - 1):
        if f[i][0] > 0 and f[i + 1][0] > 0 and f[i][0] + f[i + 1][0] > res:
            if w[i][0] != w[i + 1][0]:
                res = f[i][0] + f[i + 1][0]
                ans = [w[i][0], w[i + 1][0]]
            else:
                if f[i + 1][1] > 0 and f[i][0] + f[i + 1][1] > res:
                    res = f[i][0] + f[i + 1][1]
                    ans = [w[i][0], w[i + 1][1]]
                if f[i][1] > 0 and f[i][1] + f[i + 1][0] > res:
                    res = f[i][1] + f[i + 1][0]
                    ans = [w[i][1], w[i + 1][0]]
    c_arr = []
    d_arr = []
    for g in cube:
        if g[0] == ans[0]:
            c_arr.append(g[2])
        if g[0] == ans[1]:
            d_arr.append(g[2])
    return res, c_arr, d_arr

def display(n, c_ans, d_ans):
    cl = len(c_ans)
    dl = len(d_ans)
    ans = []
    print n
    print cl + min(cl + 1, dl)
    for i in xrange(0, cl):
        ans.append(d_ans[i])
        ans.append(c_ans[i])
    if dl > cl:
        ans.append(d_ans[cl])
    print " ".join(map(str, ans))

if __name__ == "__main__":
    n, m, cube = init()
    res, c_ans, d_ans = solve(n, m, cube)
    display(res, c_ans, d_ans)