import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String []args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayListals = new ArrayList<>(); for(int i=0;iali = new ArrayList<>(); for(int i=0;i0) { int a = sc.nextInt(); int b = sc.nextInt(); String s = sc.next(); for(int i=a;i<=b;i++) { StringTokenizer st = new StringTokenizer(s,als.get(i)); int c=st.countTokens(); if(!s.contains(als.get(i))) c=0; ans+= c*ali.get(i); } if(ans > max) max = ans; if(ans < min) min = ans; ans=0; } System.out.println(min+" "+max); } }