#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

list<int> listOne{};
list<int> listTwo{};

unordered_map<int, int> listTwoMap;

int simscore = 0;

int main(){

    ifstream puzzle("input.txt");

    int tempOne, tempTwo;

    while (puzzle >> tempOne >> tempTwo)
    {
        listOne.push_back(tempOne);
        listTwo.push_back(tempTwo);
    }

    puzzle.close();

    for (int num:listTwo){
        listTwoMap[num]++;
    }

        for (int listOneItem = 0; !listOne.empty(); listOneItem= listOne.front()) {
            if(listTwoMap.contains(listOneItem)){
                simscore += listOneItem * listTwoMap[listOneItem];
            }

            listOne.pop_front();
        }

    printf("total simularity: %i\n", simscore);
}