Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

# Collections Module I

Problem Description

We had discussed about collections mode in python. Let's try the following problem using it.

There are N shops in the street and each shop has only single type of chocolate.

There are M number of children who are willing to pay Xi amount of money only if they get the chocolate of their desired type.

Find the total amount earned by all shopkeepers

Problem Constraints

1 <= N, M <= 105

1 <= Xi <= 109

1 <= Type of chocolate <= 109

Input Format

First line consist of an integer N.

Second line consist of N space separated integers denoting the type of chocolate at N shops.

Third line consist of an integer M.

Each of the next M lines consist of two integers Xi and type of desired chocolate.

Output Format

Print the total amount earned by all shopkeepers.

Example Input

Input 1:

```10
1 2 1 3 2 5 6 10 11 15
5
50 1
20 3
25 3
5 12
20 11```

Input 2:

```5
11 11 2 3 2
4
50 2
10 2
20 2
100 2```

Example Output

Output 1:

` 90`

Output 2:

` 60`

Example Explanation

Explanation 1:

`1st, 2nd and 5th children will get the chocolate, so the total money earned is 90.`

Explanation 2:

`1st and 2nd children will get the chocolate, so the total money earned is 60.`

Hints
• Hint 1
• Solution Approach
• Complete Solution

## Discussion

Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer
Data Analyst
Data Engineer
Non Coder
Other
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.