Problem description

Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.

There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.

You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

Input

The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hiai (1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.

Output

In a single line print the number of games where the host team is going to play in the guest uniform.

Examples

Input

3
1 2
2 4
3 4

Output

1

Input

4
100 42
42 100
5 42
100 5

Output

5

Input

2
1 2
1 2

Output

0

Note

In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.

In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

解题思路:题目的意思就是如果主队hi有在客场aj踢球,即当i!=j时,hi==aj(题目已保证i==j时,hi!=aj,即自己不会跟自己比赛),计数器m就加1,最后输出m即可,暴力简单过!

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,m=,h[],a[];cin>>n;
for(int i=;i<n;++i)
cin>>h[i]>>a[i];
for(int i=;i<n;++i)
for(int j=;j<n;++j)
if(i!=j&&h[i]==a[j])m++;
cout<<m<<endl;
return ;
}

R - Games的更多相关文章

  1. RESTframework简介

    什么是RESTful? RESTful是一种开发理念,REST是Roy Thomas Fileding在他博文提出的.REST特点;url简洁,将参数通过url传递到服务器,简单就是说URL定位资源, ...

  2. Linux题库练习

    转一个Linux的题库供自己学习使用(滑稽) 转自:http://www.linuxdiyf.com/view_202485.html 选择题1 在终端下输入mount -a命令的作用是:CA 强制进 ...

  3. django 之(二) --- 源码分析

    CBV类视图继承 CBV:继承自View:注册的时候使用的as_view() 入口 不能使用请求方法的名字作为参数的名字 只能接受已经存在的属性对应的参数 定义了一个view 创建了一个类视图对象 保 ...

  4. Linux 基础优化

    1.操作的最小化原则 1)安装系统最小化 一般情况下安装OS时,软件安装包组(Package Group)的选择: base--------------------------基本环境 editors ...

  5. [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes

    ##################    Rancher v2.1.7  +    Kubernetes 1.13.4  ################ ##################### ...

  6. 利用python进行数据分析2_数据采集与操作

    txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...

  7. Django项目:CRM(客户关系管理系统)--81--71PerfectCRM实现CRM项目首页

    {#portal.html#} {## ————————46PerfectCRM实现登陆后页面才能访问————————#} {#{% extends 'king_admin/table_index.h ...

  8. CF456D A Lot of Games (字典树+DP)

    D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...

  9. 运行(WIN+R)中能使用的命令:ms-settings:,shell:,cpl,mmc...

    ms-settings: --- DESC --- --- CMD --- Battery Saver ms-settings:batterysaver Battery Saver Settings ...

随机推荐

  1. CAD绘制一个半径标注(com接口VB语言)

    主要用到函数说明: _DMxDrawX::DrawDimRadial 绘制一个半径标注.详细说明如下: 参数 说明 DOUBLE dCenterX 被标注的曲线的中点X值 DOUBLE dCenter ...

  2. PHP常用的设计模式

    工厂模式 工厂模式是我们最常用的实例化对象模式,是用工厂方法代替new操作的一种模式. 使用工厂模式的好处是如果你想要更改所实例化的类名等,则只需要更改该工厂方法内容即可,不需逐一寻找代码中具体实例化 ...

  3. [SQL Service] 时间处理:获取今天的00:00:00/获取今天的23:59:59

    获取今天的00:00:00 SELECT CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120)) 获取今天的23:59:59 1.SELECT DAT ...

  4. String s = new String("xyz");创建了几个对象?

    两个或一个都有可能 . ”xyz”对应一个对象,这个对象放在字符串常量池,常量”xyz”不管出现多少遍,都是常量池中的那一个. new String每写一遍,就创建一个新的对象,它使用常量”xyz”对 ...

  5. 35.分组聚合操作—bucket+metric

    主要知识点: bucket+metric 计算分种颜色的电视的平均价格     语法: GET /tvs/sales/_search { "size" : 0, "agg ...

  6. Swoole 源码分析——Server模块之Worker事件循环

    swManager_loop 函数 manager 进程管理 manager 进程开启的时候,首先要调用 onManagerStart 回调 添加信号处理函数 swSignal_add,SIGTERM ...

  7. SpringBoot杂记

    一.配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoo ...

  8. 【codeforces 768D】Jon and Orbs

    [题目链接]:http://codeforces.com/contest/768/problem/D [题意] 你有一个水晶; 它每天都会产生一个球??(球有k种) 然后每种球产生的可能性是相同的-& ...

  9. jenkins简单持续构建

    一.安装jenkins 二.将需要持续构建的java project打包成jar文件 1.选择导出需要运行的main方法所在java类

  10. NOI2017爆零记[AFO]

    WC2017 12分……全省第一…… APIO2017 4分……全省第二…… 千言万语汇成两个表格 NOI2017 114分(笔试100+一试4+二试5+A类5)……全省第三…… 全场最菜…… day ...