B - Begin the journey to a Higher Score

B - Begin the journey to a Higher Score

暂无测试数据。

Description

Some students have just took a test, and they are discussing it.

This test consists solely of multiple choice problems, and each student remembers his/her choice. They do not know which one is the answer.

There are mm problems in the test, the ii -th problem is of sis_i points. If the ii th problem is answered correctly, the value aia_i is added to to the score of the student. If it is answered incorrectly or not answered, the student’s score will not change. Your task is to give a set of correct answers and determine the maximum total score students may get.

Input

The first line of input contains a single integer m(0<m2106)m(0 < m \le 2\cdot 10^6)

The second line contains mm space separated integers si(103si103)s_i(-10^3\le s_i\le 10^3)

Then mm lines follow, each line contains 44 space separated integers, ai,bi,ci,di(0ai,bi,ci,di103)a_i,b_i,c_i,d_i(0 \le a_i,b_i,c_i,d_i \le 10^3)denoting the number of students who have chosen the corresponding choice. It is not guranteed that the sum of each line are pairwise equal(some students may have skipped problems). Refer to the example input for better understanding.

Output

Print two lines. The first line contains a single integer kk -- the maximal total students get.

The second line contains a string of length mm, it should contain only characters A,B,C and D. It should be a possible answer that yields the maximal total score kk. If multiple answers exist, print the lexicographically smallest(see Notes section) one.

Examples

Sample Input 1

3
1 2 3
10 2 3 0
2 3 10 0
2 0 0 10

Sample Output 1

60
ACD

Notice that 10+2+3+010+2+3+0 does not equal to 2+0+0+102+0+0+10.

Sample Input 2

8
1 9 2 6 0 8 1 7
1 4 3 5
2 5 2 5
1 5 7 2
2 5 7 7
10 2 3 4
2 3 1 9
11 2 3 8
2 1 10 10

Sample Output 2

259
DBCCADAC

Notes

For two sequences AA and BB, both of length nn, we say AA is lexicographically smaller than BB, if and only if x[1,n]\exists x \in [1, n] so that

  • For all 1i<x,Ai=Bi1\le i < x, A_i=B_i
  • Ax<BxA_x < B_x.

In this problem, the characters are compared using their ASCII number.

信息

ID
1008
难度
(无)
分类
(无)
标签
(无)
递交数
0
已通过
0
通过率
?
上传者