import java.util.*; public class codeSprint12_maxTransform { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long big = 1000000007; int n = scan.nextInt(); //int a[] = new int[n]; ArrayList a = new ArrayList(); for(int i=0;i b = new ArrayList(); int c = 0; for(int i=0;imax) max = a.get(k); } b.add(max); } } ArrayList d = new ArrayList(); for(int i=0;imax) max = b.get(k); } d.add(max); } } long sum = 0; for(int i=0;i