import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Phone[] obj = new Phone[4];
for(int i=0 ;i<4 ; i++){
obj[i] = new Phone(sc.nextInt() , sc.next() , sc.next(), sc.nextInt());
}
String brand = sc.next();
String os = sc.next();
int value = findPriceForGivenBrand(obj , brand);
if(value > 0){
System.out.println(value);
}else{
System.out.println("The given Brand is not available");
}
Phone[] ans = getPhoneIdBasedOnOs(obj , os);
if(ans.length==0){
System.out.println("No phones are available with specified os and price range");
}else{
for(int i=0 ; i<ans.length ; i++){
System.out.println(ans[i].getid());
}
}
}
public static int findPriceForGivenBrand(Phone[] phone, String brand)
{
int sum =0 ;
for(int i=0 ; i<phone.length; i++){
if(phone[i].getbrand().equalsIgnoreCase(brand)){
sum+=phone[i].getprice();
}
}
return sum;
}
public static Phone[] getPhoneIdBasedOnOs(Phone[] phone, String os)
{
int length =0;
int j =0;
Phone[] obj2 = new Phone[length];
for(int i=0 ; i<phone.length ; i++){
if(phone[i].getos().equalsIgnoreCase(os) && phone[i].getprice()>=50000){
obj2 = new Phone[length+1];
obj2[j] = phone[i];
j++;
}
}
return obj2;
}
}
class Phone
{
int id;
String os ;
String brand;
int price;
public int getid(){
return id;
}
public String getos(){
return os;
}
public String getbrand(){
return brand;
}
public int getprice(){
return price;
}
Phone(int id , String os , String brand , int price){
this.id = id;
this.os = os;
this.brand = brand;
this.price = price;
}
}
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Phone[] obj = new Phone[4];
for(int i=0 ;i<4 ; i++){
obj[i] = new Phone(sc.nextInt() , sc.next() , sc.next(), sc.nextInt());
}
String brand = sc.next();
String os = sc.next();
}
public static int findPriceForGivenBrand(Phone[] phone, String brand)
{
int sum =0 ;
}
public static Phone[] getPhoneIdBasedOnOs(Phone[] phone, String os)
{
int length =0;
int j =0;
Phone[] obj2 = new Phone[length];
for(int i=0 ; i<phone.length ; i++){
if(phone[i].getos().equalsIgnoreCase(os) && phone[i].getprice()>=50000){
obj2 = new Phone[length+1];
obj2[j] = phone[i];
j++;
}
}
return obj2;
}
}
class Phone
{
int id;
String os ;
String brand;
int price;
public int getid(){
return id;
}
public String getos(){
return os;
}
public String getbrand(){
return brand;
}
public int getprice(){
return price;
}
Phone(int id , String os , String brand , int price){
this.id = id;
this.os = os;
this.brand = brand;
this.price = price;
}
}