Welcome to Rockport City!It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet $$$a$$$ dollars and Ronnie has bet $$$b$$$ dollars. But the fans seem to be disappointed. The excitement of the fans is given by $$$gcd(a,b)$$$, where $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. To make the race more exciting, you can perform two types of operations:  Increase both $$$a$$$ and $$$b$$$ by $$$1$$$.  Decrease both $$$a$$$ and $$$b$$$ by $$$1$$$. This operation can only be performed if both $$$a$$$ and $$$b$$$ are greater than $$$0$$$. In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.Note that $$$gcd(x,0)=x$$$ for any $$$x \ge 0$$$.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 5\cdot 10^3$$$) — the number of test cases. The first and the only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0\leq a, b\leq 10^{18}$$$).

For each test case, print a single line containing two integers.  If the fans can get infinite excitement, print 0 0. Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.

NoteFor the first test case, you can apply the first operation $$$1$$$ time to get $$$a=9$$$ and $$$b=6$$$. It can be shown that $$$3$$$ is the maximum excitement possible.For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to $$$1$$$. Since the initial excitement is also $$$1$$$, you don't need to apply any operation.For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.For the fourth test case, you can apply the second operation $$$3$$$ times to get $$$a=0$$$ and $$$b=6$$$. Since, $$$gcd(0,6)=6$$$, the fans will get an excitement of $$$6$$$.

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=BigInt(aa[0]);
        let b=BigInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a.toString(),0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b.toString(),0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        let mn;
        if(a<b)
            mn=a;
        else
            mn=b;
        let mx=a-b;
        if(mx<0)
            mx=b-a;
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(mx.toString(),0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                //console.log(val);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => BigInt(x));

const min = (a, b) => a < b ? a : b;
const abs = a => a < 0 ? -a : a;

function main () {
	let T = rn();
	while (T--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const g = abs(a-b);
		const mvs = min(a % g, g - a % g);
		console.log(g.toString(), mvs.toString());
	}
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

function gcd(x, y) {
   if (isZero(y)) {
      return x;
   }
   return gcd(y, x % y);
}

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function solve() {
   const [a, b] = readArray(BigInt);
   const diff = a > b ? a - b : b - a;
   if (diff === 0n) {
      write('0 0');
      return;
   }
   const steps1 = a % diff;
   const steps2 = diff - steps1;
   const steps = steps1 > steps2 ? steps2 : steps1;
   write(diff + ' ' + steps);
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        var [a, b] = lines[l++].trim().split(' ').map(BigInt)
        console.log(solve(a, b).join(' '))
    }
});

function solve(a, b) {
    if (a === b) return [0, 0]
    if (a > b) return solve(b, a)

    const d = a > b ? a - b : b - a
    const r = a % d
    if (r > d / 2n) {
        const op = d - r
        return [gcd(a + op, b + op), op]
    } else {
        return [gcd(a - r, b - r), r]
    }
}

function gcd(a, b) {
    if (a === 0n) return b
    if (b === 0n) return a

    while (a) {
        const r = b % a
        b = a
        a = r
    }
    return b
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=a-b;
        if(mx<0)
            mx=(-1)*mx;
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(mx,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                //console.log(val);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=Math.abs(a-b);
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let val=BigInt(a/mx);
                let add=mx-(a- val*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        let a=parseInt(aa[0]);
        let b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        let mx=Math.abs(a-b);
        mx=BigInt(mx)
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            a=BigInt(a);
            b=BigInt(b);
            if(a%mx === b%mx)
            {
                let add=mx-(a- (a/mx)*mx);
                add=BigInt(add)
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                //add=Math.min(add,mx-add);
                if((mx-add)<add)
                    add=mx-add;
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx.toString(),add.toString());
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx.toString(),mn.toString());
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx.toString(),mn.toString())
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => str.trim());

    main();
});

function readLine() {
    return inputString[currentLine++];
}
var gcd = function(a, b) {
    if (!b) {
      return a;
    }

    return gcd(b, a % b);
}

function main()
{
    //const name=readLine();
    //console.log(name);

    let test=readLine();
    while(test--)
    {
        aa=readLine();
        aa=aa.split(" ");
        a=parseInt(aa[0]);
        b=parseInt(aa[1]);
        if(a===b)
        {
            console.log(0,0);
            //cout<<0<<" "<<0<<endl;
            continue;
        }
        if(a===0 || b===0)
        {
            //console.log("Hello ",a,b);
            if(a!=0)
            {
                console.log(a,0);
                //cout<<a<<" "<<0<<endl;
            }
            else
            {
                console.log(b,0);
                //cout<<b<<" "<<0<<endl;
            }
            continue;
        }
        cur_gcd=gcd(a,b);
        //console.log("gcd ",cur_gcd);
        mn=Math.min(a,b);
        mx=Math.abs(a-b);
        //console.log("Mx: ",mx);
        if(mx===cur_gcd)
        {
            console.log(cur_gcd,0);
            //cout<<cur_gcd<<" "<<0<<endl;
        }
        else
        {
            if(a%mx === b%mx)
            {
                add=mx-(a-parseInt(a/mx)*mx);
                //console.log((a/mx));
                //console.log("add: ",add);
                //console.log(add,mx-add,Math.min(add,mx-add))
                add=Math.min(add,mx-add);
                ///cout<<add<<endl;
                //console.log("add: ",add);
                if(add<mn)
                {
                    console.log(mx,add);
                    //cout<<mx<<" "<<add<<endl;
                }
                else
                {
                    console.log(mx,mn);
                    //cout<<mx<<" "<<mn<<endl;
                }
            }
            else
                console.log(mx,mn)
                //cout<<mx<<" "<<mn<<endl;
        }
    }
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const gcd = Math.abs(a-b);
		const moves = Math.min(a % gcd, gcd - a % gcd);
		console.log(gcd, moves);
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		if ( a > b) [a, b] = [b, a];

		const gcd = b - a;
		const moves = Math.min(a, (gcd - b % gcd) % gcd);
		console.log(gcd, moves);
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [a, b] = rna();

		if (a == b) {
			console.log("0 0");
			continue;
		}

		const gcd = Math.abs(a - b);
		const moves = Math.min(Math.min(a, b), (gcd - a % gcd) % gcd);
		console.log(gcd, moves);
	}
}


$$$2^k$$$ teams participate in a playoff tournament. The tournament consists of $$$2^k - 1$$$ games. They are held as follows: first of all, the teams are split into pairs: team $$$1$$$ plays against team $$$2$$$, team $$$3$$$ plays against team $$$4$$$ (exactly in this order), and so on (so, $$$2^{k-1}$$$ games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only $$$2^{k-1}$$$ teams remain. If only one team remains, it is declared the champion; otherwise, $$$2^{k-2}$$$ games are played: in the first one of them, the winner of the game "$$$1$$$ vs $$$2$$$" plays against the winner of the game "$$$3$$$ vs $$$4$$$", then the winner of the game "$$$5$$$ vs $$$6$$$" plays against the winner of the game "$$$7$$$ vs $$$8$$$", and so on. This process repeats until only one team remains.After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:  the winner of the tournament gets place $$$1$$$;  the team eliminated in the finals gets place $$$2$$$;  both teams eliminated in the semifinals get place $$$3$$$;  all teams eliminated in the quarterfinals get place $$$5$$$;  all teams eliminated in the 1/8 finals get place $$$9$$$, and so on. For example, this picture describes one of the possible ways the tournament can go with $$$k = 3$$$, and the resulting places of the teams:  After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let $$$p_i$$$ be the place of the $$$i$$$-th team in the tournament. The hash value of the tournament $$$h$$$ is calculated as $$$h = (\sum \limits_{i=1}^{2^k} i \cdot A^{p_i}) \bmod 998244353$$$, where $$$A$$$ is some given integer.Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of $$$k$$$, $$$A$$$ and $$$h$$$. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.

If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer $$$-1$$$. Otherwise, print $$$2^k$$$ integers, where $$$i$$$-th integer should be equal to $$$p_i$$$ (the place of the $$$i$$$-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams $$$1$$$ and $$$2$$$ always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.

NoteThe tournament for the first example is described in the statement.For the third example, the placing $$$[1, 2, 3, 3]$$$ (team $$$1$$$ gets place $$$1$$$, team $$$2$$$ gets place $$$2$$$, teams $$$3$$$ and $$$4$$$ get place $$$3$$$) could result in a hash value of $$$7020100$$$ with $$$A = 100$$$, but no tournament can result in such placing since teams $$$1$$$ and $$$2$$$ play against each other in the semifinals, so they cannot get two first places.

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    for (let i = 0; i < t; i++) {
        const [k, A, h] = lines[l++].trim().split(' ').map(Number)
        console.log(solve(k, A, h))
    }
// })()
})

const MOD = 998244353
function solve(k, A, h) {
    if (k === 1) {
        if (hash([1, 2], {1: 1, 2: 2}, A) === h) return '1 2'
        if (hash([1, 2], {1: 2, 2: 1}, A) === h) return '2 1'
        return -1
    }

    // const am = {}
    // const bm = {}
    // const sb = '5 3 5 2 1 5 5 3'.split(' ').reduce((s, x, i) => {
    //     if (i < 4) {
    //         am[i + 1] = +x
    //     } else {
    //         bm[i + 1] = +x
    //     }
    //     console.log(s)
    //     return add(s, mul(i + 1, pow(A, +x)))
    // }, 0)
    // console.log(sb, am, bm)
    // console.log(hash(am, A), hash(bm, A))

    const n = Math.pow(2, k)
    const a = []
    const b = []
    for (let i = 1; i <= n / 2; i++) {
        a.push(i)
        b.push(i + n / 2)
    }
// return [a,b]
    return check(k, A, h, a, b, 1) || check(k, A, h, a, b, 0) || -1
}
function check(k, A, h, a, b, win) {
    const hb = cal(k, A, h, b, !win)
    // console.log(hb)
    return cal(k, A, h, a, win, hb)
    // console.log(ha, hb)
    // for (let x in ha) {
    //     x = +x
    //     const y = add(add(h, -x), MOD)
    //     if (hb[y]) {
    //         return range(ha[x], hb[y], win)
    //     }
    // }
    // return null
}
function range(a, b, win) {
    if (win) {
        return a.map(x => (x === 2 ? 1 : x)).concat(b).join(' ')
    } else {
        return a.concat(b.map(x => (x === 2 ? 1 : x))).join(' ')
    }
}

function cal(k, A, h, ps, win, hb) {
    const rank = {}
    ps.forEach(i => rank[i] = ps.length + 1)
    const init = {
        hh: 0,
        round: k,
        j: 0,
        //
        rank,
        ps,
        next: [],
    }
    const stack = [init]
    const save = ps
    const ans = {}
    // let jj = 10
    // while (jj--) {
    while (stack.length) {
        let { hh, rank, round, j, ps, next } = stack.pop()
        // console.log(round, j, ps, next, save)
        const isLast = j >= ps.length - 2 && round <= 2

        const rk = Math.pow(2, round - 2) + 1
        const w1 = ps[j]
        const w2 = ps[j + 1]
        let n1 = next.slice()
        let n2 = next.slice()
        n1.push(w1)
        n2.push(w2)
        const rank1 = {...rank}
        const rank2 = {...rank}
        // add the loser
        let h1 = add(hh, mul(w2, pow(A, rank[w2])))
        let h2 = add(hh, mul(w1, pow(A, rank[w1])))
        rank1[w1] = rk
        rank2[w2] = rk
        if (isLast) {
            if (win) {
                rank1[ps[0]] = 1
                rank2[ps[1]] = 1
            }
            h1 = add(h1, mul(ps[0], pow(A, rank1[ps[0]])))
            h2 = add(h2, mul(ps[1], pow(A, rank2[ps[1]])))
            if (hb) {
                let y = add(add(h, -h1), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank1[x]), hb[y], win)
                }
                y = add(add(h, -h2), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank2[x]), hb[y], win)
                }
            } else {
            // console.log(ps, rank1, h1, rank2, h2)
                ans[h1] = save.map(x => rank1[x])
                ans[h2] = save.map(x => rank2[x])
            }
        } else {
            j += 2
            let ps1 = ps
            let ps2 = ps
            if (j >= ps.length) {
                round--
                j = 0
                ps1 = n1
                ps2 = n2
                n1 = []
                n2 = []
            }
            stack.push({
                hh: h1,
                round,
                j,
                rank: rank1,
                ps: ps1,
                next: n1,
            }, {
                hh: h2,
                round,
                j,
                rank: rank2,
                ps: ps2,
                next: n2,
            })
        }
    }

    return hb ? null : ans
}
function hash(ps, rank, A) {
    // return Object.keys(rank).reduce((s, i) => add(s, mul(+i, pow(A, rank[i]))), 0)
    return ps.reduce((s, i) => add(s, mul(i, pow(A, rank[i]))), 0)
}

function add(a, b) {
    return (a + b) % MOD
}
function mul(a, b) {
    let r = 0
    let base = a
    while (b) {
        if (b & 1) {
            r = add(r, base)
        }
        b >>= 1
        base = add(base, base)
    }
    // const str = b.toString(2)
    // let r = 0
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = add(r, base)
    //     }
    //     base = add(base, base)
    // }
    return r
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    // const str = b.toString(2)
    // let r = 1
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = mul(r, base)
    //     }
    //     base = mul(base, base)
    // }
    return r
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    for (let i = 0; i < t; i++) {
        const [k, A, h] = lines[l++].trim().split(' ').map(Number)
        console.log(solve(k, A, h))
    }
// })()
})

const MOD = 998244353
function solve(k, A, h) {
    // if (k === 1) {
    //     return A === h ? 1 : -1
    // }

    // const am = {}
    // const bm = {}
    // const sb = '5 3 5 2 1 5 5 3'.split(' ').reduce((s, x, i) => {
    //     if (i < 4) {
    //         am[i + 1] = +x
    //     } else {
    //         bm[i + 1] = +x
    //     }
    //     console.log(s)
    //     return add(s, mul(i + 1, pow(A, +x)))
    // }, 0)
    // console.log(sb, am, bm)
    // console.log(hash(am, A), hash(bm, A))

    const n = Math.pow(2, k)
    const a = []
    const b = []
    for (let i = 1; i <= n / 2; i++) {
        a.push(i)
        b.push(i + n / 2)
    }
// return [a,b]
    return check(k, A, h, a, b, 1) || check(k, A, h, a, b, 0) || -1
}
function check(k, A, h, a, b, win) {
    const hb = cal(k, A, h, b, !win)
    // console.log(hb)
    return cal(k, A, h, a, win, hb)
    // console.log(ha, hb)
    // for (let x in ha) {
    //     x = +x
    //     const y = add(add(h, -x), MOD)
    //     if (hb[y]) {
    //         return range(ha[x], hb[y], win)
    //     }
    // }
    // return null
}
function range(a, b, win) {
    if (win) {
        return a.map(x => (x === 2 ? 1 : x)).concat(b).join(' ')
    } else {
        return a.concat(b.map(x => (x === 2 ? 1 : x))).join(' ')
    }
}

function cal(k, A, h, ps, win, hb) {
    const rank = {}
    ps.forEach(i => rank[i] = ps.length + 1)
    const init = {
        hh: 0,
        round: k,
        j: 0,
        //
        rank,
        ps,
        next: [],
    }
    const stack = [init]
    const save = ps
    const ans = {}
    // let jj = 10
    // while (jj--) {
    while (stack.length) {
        let { hh, rank, round, j, ps, next } = stack.pop()
        // console.log(round, j, ps, next, save)
        const isLast = j >= ps.length - 2 && round <= 2

        const rk = Math.pow(2, round - 2) + 1
        const w1 = ps[j]
        const w2 = ps[j + 1]
        let n1 = next.slice()
        let n2 = next.slice()
        n1.push(w1)
        n2.push(w2)
        const rank1 = {...rank}
        const rank2 = {...rank}
        // add the loser
        let h1 = add(hh, mul(w2, pow(A, rank[w2])))
        let h2 = add(hh, mul(w1, pow(A, rank[w1])))
        rank1[w1] = rk
        rank2[w2] = rk
        if (isLast) {
            if (win) {
                rank1[ps[0]] = 1
                rank2[ps[1]] = 1
            }
            h1 = add(h1, mul(ps[0], pow(A, rank1[ps[0]])))
            h2 = add(h2, mul(ps[1], pow(A, rank2[ps[1]])))
            if (hb) {
                let y = add(add(h, -h1), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank1[x]), hb[y], win)
                }
                y = add(add(h, -h2), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank2[x]), hb[y], win)
                }
            } else {
            // console.log(ps, rank1, h1, rank2, h2)
                ans[h1] = save.map(x => rank1[x])
                ans[h2] = save.map(x => rank2[x])
            }
        } else {
            j += 2
            let ps1 = ps
            let ps2 = ps
            if (j >= ps.length) {
                round--
                j = 0
                ps1 = n1
                ps2 = n2
                n1 = []
                n2 = []
            }
            stack.push({
                hh: h1,
                round,
                j,
                rank: rank1,
                ps: ps1,
                next: n1,
            }, {
                hh: h2,
                round,
                j,
                rank: rank2,
                ps: ps2,
                next: n2,
            })
        }
    }

    return hb ? null : ans
}
function hash(ps, rank, A) {
    // return Object.keys(rank).reduce((s, i) => add(s, mul(+i, pow(A, rank[i]))), 0)
    return ps.reduce((s, i) => add(s, mul(i, pow(A, rank[i]))), 0)
}

function add(a, b) {
    return (a + b) % MOD
}
function mul(a, b) {
    let r = 0
    let base = a
    while (b) {
        if (b & 1) {
            r = add(r, base)
        }
        b >>= 1
        base = add(base, base)
    }
    // const str = b.toString(2)
    // let r = 0
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = add(r, base)
    //     }
    //     base = add(base, base)
    // }
    return r
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    // const str = b.toString(2)
    // let r = 1
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = mul(r, base)
    //     }
    //     base = mul(base, base)
    // }
    return r
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    for (let i = 0; i < t; i++) {
        const [k, A, h] = lines[l++].trim().split(' ').map(Number)
        console.log(solve(k, A, h))
    }
// })()
})

const MOD = 998244353
function solve(k, A, h) {
    // if (k === 1) {
    //     return A === h ? 1 : -1
    // }

    // const am = {}
    // const bm = {}
    // const sb = '5 3 5 2 1 5 5 3'.split(' ').reduce((s, x, i) => {
    //     if (i < 4) {
    //         am[i + 1] = +x
    //     } else {
    //         bm[i + 1] = +x
    //     }
    //     console.log(s)
    //     return add(s, mul(i + 1, pow(A, +x)))
    // }, 0)
    // console.log(sb, am, bm)
    // console.log(hash(am, A), hash(bm, A))

    const n = Math.pow(2, k)
    const a = []
    const b = []
    for (let i = 1; i <= n / 2; i++) {
        a.push(i)
        b.push(i + n / 2)
    }
// return [a,b]
    return check(k, A, h, a, b, 1) || check(k, A, h, a, b, 0) || -1
}
function check(k, A, h, a, b, win) {
    const hb = cal(k, A, h, b, !win)
    // console.log(hb)
    return cal(k, A, h, a, win, hb)
    // console.log(ha, hb)
    // for (let x in ha) {
    //     x = +x
    //     const y = add(add(h, -x), MOD)
    //     if (hb[y]) {
    //         return range(ha[x], hb[y], win)
    //     }
    // }
    // return null
}
function range(a, b, win) {
    if (win) {
        return a.map(x => (x === 2 ? 1 : x)).concat(b).join(' ')
    } else {
        return a.concat(b.map(x => (x === 2 ? 1 : x))).join(' ')
    }
}

function cal(k, A, h, ps, win, hb) {
    const rank = {}
    ps.forEach(i => rank[i] = ps.length + 1)
    const init = {
        hh: 0,
        round: k,
        j: 0,
        //
        rank,
        ps,
        next: [],
    }
    const stack = [init]
    const save = ps
    const ans = {}
    // let jj = 10
    // while (jj--) {
    while (stack.length) {
        let { hh, rank, round, j, ps, next } = stack.pop()
        // console.log(round, j, ps, next, save)
        const isLast = j === ps.length - 2 && round === 2

        const rk = Math.pow(2, round - 2) + 1
        const w1 = ps[j]
        const w2 = ps[j + 1]
        let n1 = next.slice()
        let n2 = next.slice()
        n1.push(w1)
        n2.push(w2)
        const rank1 = {...rank}
        const rank2 = {...rank}
        // add the loser
        let h1 = add(hh, mul(w2, pow(A, rank[w2])))
        let h2 = add(hh, mul(w1, pow(A, rank[w1])))
        rank1[w1] = rk
        rank2[w2] = rk
        if (isLast) {
            if (win) {
                rank1[ps[0]] = 1
                rank2[ps[1]] = 1
            }
            h1 = add(h1, mul(ps[0], pow(A, rank1[ps[0]])))
            h2 = add(h2, mul(ps[1], pow(A, rank2[ps[1]])))
            if (hb) {
                let y = add(add(h, -h1), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank[x]), hb[y], win)
                }
                y = add(add(h, -h2), MOD)
                if (hb[y]) {
                    return range(save.map(x => rank[x]), hb[y], win)
                }
            } else {
            // console.log(ps, rank1, h1, rank2, h2)
                ans[h1] = save.map(x => rank1[x])
                ans[h2] = save.map(x => rank2[x])
            }
        } else {
            j += 2
            let ps1 = ps
            let ps2 = ps
            if (j >= ps.length) {
                round--
                j = 0
                ps1 = n1
                ps2 = n2
                n1 = []
                n2 = []
            }
            stack.push({
                hh: h1,
                round,
                j,
                rank: rank1,
                ps: ps1,
                next: n1,
            }, {
                hh: h2,
                round,
                j,
                rank: rank2,
                ps: ps2,
                next: n2,
            })
        }
    }

    return hb ? null : ans
}
function hash(ps, rank, A) {
    // return Object.keys(rank).reduce((s, i) => add(s, mul(+i, pow(A, rank[i]))), 0)
    return ps.reduce((s, i) => add(s, mul(i, pow(A, rank[i]))), 0)
}

function add(a, b) {
    return (a + b) % MOD
}
function mul(a, b) {
    let r = 0
    let base = a
    while (b) {
        if (b & 1) {
            r = add(r, base)
        }
        b >>= 1
        base = add(base, base)
    }
    // const str = b.toString(2)
    // let r = 0
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = add(r, base)
    //     }
    //     base = add(base, base)
    // }
    return r
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    // const str = b.toString(2)
    // let r = 1
    // let base = a
    // for (let i = str.length - 1; i >= 0; i--) {
    //     if (str[i] === '1') {
    //         r = mul(r, base)
    //     }
    //     base = mul(base, base)
    // }
    return r
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = 1//+lines[l++]
    for (let i = 0; i < t; i++) {
        const [k, A, h] = lines[l++].trim().split(' ').map(Number)
        console.log(solve(k, A, h))
    }
// })()
})

const MOD = 998244353
function solve(k, A, h) {
    if (k === 1) {
        return A === h ? 1 : -1
    }

    // const am = {}
    // const bm = {}
    // const sb = '5 3 5 2 1 5 5 3'.split(' ').reduce((s, x, i) => {
    //     if (i < 4) {
    //         am[i + 1] = +x
    //     } else {
    //         bm[i + 1] = +x
    //     }
    //     console.log(s)
    //     return add(s, mul(i + 1, pow(A, +x)))
    // }, 0)
    // console.log(sb, am, bm)
    // console.log(hash(am, A), hash(bm, A))

    const n = Math.pow(2, k)
    const a = []
    const b = []
    for (let i = 1; i <= n / 2; i++) {
        a.push(i)
        b.push(i + n / 2)
    }
// return [a, b]
    return check(k, A, h, a, b, 1) || check(k, A, h, a, b, 0) || -1
}
function check(k, A, h, a, b, win) {
    const ha = cal(k, A, a, win)
    const hb = cal(k, A, b, !win)
    // console.log(ha, hb)
    for (let x in ha) {
        x = +x
        const y = add(add(h, -x), MOD)
        if (hb[y]) {
            return range(ha[x], hb[y], win)
        }
    }
    return null
}
function range(a, b, win) {
    if (win) {
        return a.map(x => (x === 2 ? 1 : x)).concat(b).join(' ')
    } else {
        return a.concat(b.map(x => (x === 2 ? 1 : x))).join(' ')
    }
}

function cal(k, A, ps, win) {
    const limit = Math.pow(2, ps.length - 1)
    const ans = {}
    for (let i = 0; i < limit; i++) {
        let mask = 1
        let next = []
        const rank = {}
        ps.forEach(i => rank[i] = ps.length + 1)
        const save = ps
        for (let round = k; round >= 2; round--) {
            const rk = Math.pow(2, round - 2) + 1
            for (let j = 0; j < ps.length; j += 2) {
                const w = (i & mask) ? ps[j] : ps[j + 1]
                next.push(w)
                rank[w] = rk
                mask += mask
            }
            ps = next
            next = []
            // console.log(ps)
        }
        if (win) {
            rank[ps[0]] = 1
        }
        ps = save
// console.log(rank)
        const h = hash(rank, A)
        ans[h] = ps.map(x => rank[x])
// if (ans[h] === '5 3 5 2') {
//     console.log(rank, h)
// }
    }
    return ans
}
function hash(rank, A) {
    return Object.keys(rank).reduce((s, i) => add(s, mul(+i, pow(A, rank[i]))), 0)
}

function add(a, b) {
    return (a + b) % MOD
}
function mul(a, b) {
    const str = b.toString(2)
    let r = 0
    let base = a
    for (let i = str.length - 1; i >= 0; i--) {
        if (str[i] === '1') {
            r = add(r, base)
        }
        base = add(base, base)
    }
    return r
}
function pow(a, b) {
    const str = b.toString(2)
    let r = 1
    let base = a
    for (let i = str.length - 1; i >= 0; i--) {
        if (str[i] === '1') {
            r = mul(r, base)
        }
        base = mul(base, base)
    }
    return r
}


ВКонтакте открыла второй штаб в Санкт-Петербурге! Вы не преминули возможностью сменить обстановку и решили переехать из офиса в Доме Зингера в офис на Красном мосту.Для комфортной работы вам потребуются два монитора с одинаковой высотой, чтобы изображение на них выглядело единым целым. На складе офиса на Красном мосту есть $$$n$$$ мониторов, $$$i$$$-й из них имеет ширину $$$w_i$$$ и высоту $$$h_i$$$. Любой монитор можно повернуть на 90 градусов, и тогда он будет иметь ширину $$$h_i$$$ и высоту $$$w_i$$$.Назовём неупорядоченную пару из двух различных мониторов подходящей, если можно их повернуть так, чтобы они имели одинаковую высоту. Любой из мониторов в паре можно как повернуть относительно исходной ориентации, так и не поворачивать.Подсчитайте подходящие пары мониторов.

В первой строке задано одно целое число $$$n$$$ — число мониторов на складе. В каждой из следующих $$$n$$$ строк заданы два целых числа $$$w_i$$$ и $$$h_i$$$ ($$$1 \le w_i, h_i \le 10^9$$$) — ширина и высота $$$i$$$-го монитора. Обратите внимание, что мониторы могут быть квадратными ($$$w_i = h_i$$$), а размеры разных мониторов могут совпадать. В этой версии задачи $$$2 \le n \le 10^3$$$.

Выведите число подходящих пар мониторов.

ПримечаниеВ первом примере подходящими являются пары мониторов с номерами $$$(1, 2)$$$, $$$(1, 4)$$$, $$$(1, 5)$$$, $$$(3, 4)$$$, $$$(4, 5)$$$.Во втором примере все пары мониторов — подходящие.

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let n = 0;
let solo = [];
let pairs = [];
let values = [];

function calcEqual(a) {
    let last = -1;
    let res = 0;
    let cnt = 0;
    a.sort();
    for (let i = 0; i < a.length; i++) {
        let x = a[i];
        if (JSON.stringify(x) === JSON.stringify(last)) {
            res += cnt;
            cnt += 1;
        } else {
            cnt = 1;
        }
        last = x;
    }
    return res;
}

readInterface.on('line', function(line) {
    if (count === 0) {
        n = +line;
    } else {
        let pair = line.split(' ').map(el => { return +el; });
        w = pair[0];
        h = pair[1];
        solo.push(w);
        if (h != w) {
            solo.push(h);
            pairs.push([Math.min.apply(null, pair), Math.max.apply(null, pair)]);
        }
    }
    if (count === n) {
        console.log(calcEqual(solo) - calcEqual(pairs));
    }

    count++;
});

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let n = +await nextString()
  let obj = {}
  let ans = 0
  for (let i = 0; i < n; ++i) {
    let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)
    let mid = a + '_' + b
    if (a !== b) {
      ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)
    }
    else {
      ans += (obj[a] || 0)
    }
    // console.log('i = ' + i + ': ' + ans)
    obj[a] = obj[a] ? obj[a] + 1 : 1
    if (a !== b) {
      obj[b] = obj[b] ? obj[b] + 1 : 1
    }
    obj[mid] = obj[mid] ? obj[mid] + 1 : 1
  }
  console.log(ans)
}

main()

let _DEBUG;

const fs = require('fs');
const print = console.log;
const debug = (x) => {
  if (!_DEBUG) return;
  let vn = Object.keys(x)[0];
  console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

let s = new Map();
let hw = new Map();

let res = 0n;

for (let i = 0; i < n; i++) {
  let row = input[i + 1].split(' ').map((x) => +x);
  let [x, y] = row;

  // x <= y
  if (x > y) {
    [x, y] = [y, x];
  }

  let a = s.get(x) || 0;
  let b = s.get(y) || 0;
  let ab = (hw.has(x) && hw.get(x).get(y)) || 0;
  if (x == y) {
    res += BigInt(a);
  } else {
    res += BigInt(a + b - ab);
  }

  debugf(`${x} ${y} -> ${a} ${b}  ${ab}`);
  debug({ res });

  s.set(x, (s.get(x) || 0) + 1);
  if (x != y) {
    s.set(y, (s.get(y) || 0) + 1);
  }

  if (!hw.has(x)) {
    hw.set(x, new Map());
  }
  let hw2 = hw.get(x);
  hw2.set(y, (hw2.get(y) || 0) + 1);

  debugf(`??? ${x} -> ${s.get(x)}`);
}

print(`${res}`);

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let total = 0;
let values = [];
let output = 0;

readInterface.on('line', function(line) {
    if (count === 0) {
        total = +line;
    } else {
        values.push(line);
    }

    if (values.length === total) {

        for (let i = 0; i < total; i++) {
            let item = values.shift();

            let filtered = values.filter(el => {
                let itemSize = item.split(' ');
                let itemW = itemSize[0];
                let itemH = itemSize[1];

                let elSize = el.split(' ');
                let elW = elSize[0];
                let elH = elSize[1];
                return itemH === elH || itemW === elH || itemW === elW || itemH === elW;
            })

            output += filtered.length;
        }

        console.log(output);
    }

    count++;
});

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var count_of_monitors
var monitors_sizes = []
function start() {
    rl.question("", function(answer) {
        count_of_monitors = parseInt(answer)
        get_mon()
    });
}

function get_monitors() {
    rl.question("", function(answer) {
        monitors_sizes.push(answer)
        count_of_monitors--
        get_mon()
    });

}

function get_mon() {
    if (count_of_monitors > 0) {
        get_monitors()
    } else {
        get_pairs()
    }
}

function factorial(n) {
  return (n != 1) ? n * factorial(n - 1) : 1;
}

function get_pairs() {

    var pairs = []
    var dubl_pairs = 0
    var count = 0

    monitors_sizes = monitors_sizes.sort()

    for (var i = 0; i < monitors_sizes.length; i++) {
        if (i >= 0) {
            if (monitors_sizes[i] != monitors_sizes[i - 1]) {
                count = 0
                monitors_sizes.slice(i + 1).filter((size, index) => {
                    var i_str = monitors_sizes[i].split(" ")
                    var index_str = size.split(" ")
                    if (parseInt(i_str[0]) == parseInt(index_str[0]) ||
                        parseInt(i_str[0]) == parseInt(index_str[1]) ||
                        parseInt(i_str[1]) == parseInt(index_str[0]) ||
                        parseInt(i_str[1]) == parseInt(index_str[1])) {
                            pairs.push(`${i_str} - ${index_str}`)
                            count++
                            return true
                        }
                })
            } else {
                count--
                dubl_pairs += count
            }
        }

    }
    console.log(pairs.length + dubl_pairs)

}

start();

let i = '';
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  const params = [];

  for (let i = 1; i < lines.length; i++) {
    params.push(lines[i].split(' ').map((x) => parseInt(x)));
  }

  const recurse = (arr, sum = 0) => {
    if (arr.length < 1) {
      return sum;
    } else {
      const x = arr[arr.length - 1][0];
      const y = arr[arr.length - 1][1];
      for (let i = 0; i < arr.length - 1; i++) {
        if (
          x === params[i][0] ||
          x === params[i][1] ||
          y === params[i][0] ||
          y === params[i][1]
        ) {
          sum++;
        }
      }
      arr.pop();
      return recurse(arr, sum);
    }
  };

  console.log(recurse(params, 0));
});

let i = '';
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  const params = [];
  let resSum = 0;

  for (let i = 1; i < lines.length; i++) {
    params.push(lines[i].split(' ').map((x) => parseInt(x)));
  }

  for (let i = 0; i < params.length - 1; i++) {
    for (let j = i + 1; j < params.length; j++) {
      if (
        params[i][0] === params[j][0] ||
        params[i][0] === params[j][1] ||
        params[i][1] === params[j][0] ||
        params[i][1] === params[j][1]
      ) {
        resSum++;
      }
    }
  }

  console.log(resSum);
});

function program(lines) {

  const count = Number(lines[0]);
  const heights = new Map();
  const results = new Set();

  for (let i = 1; i <= count; i++) {

    const [wS, hS] = lines[i].trim().split(' ');

    const w = Number(wS.trim());
    if (!heights.has(w)) {
      heights.set(w, new Set());
    }

    const wSet = heights.get(w);
    if (!wSet.has(i)) {
      for (const el of wSet) {
        results.add(`${i}-${el}`);
      }
      wSet.add(i);
    }

    const h = Number(hS.trim());
    if (!heights.has(h)) {
      heights.set(h, new Set());
    }
    const hSet = heights.get(h);
    if (!hSet.has(i)) {
      for (const el of hSet) {
        results.add(`${i}-${el}`);
      }
      hSet.add(i);
    }
  }

  return results.size;
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  const lines = i.split(EOL)
  console.log(program(lines));
})

function program(lines) {

  const count = Number(lines[0]);
  const heights = new Map();

  for (let i = 1; i <= count; i++) {

    const [wS, hS] = lines[i].trim().split(' ');

    const w = Number(wS.trim());
    if (!heights.has(w)) {
      heights.set(w, new Set());
    }
    heights.get(w).add(i);

    const h = Number(hS.trim());
    if (!heights.has(h)) {
      heights.set(h, new Set());
    }
    heights.get(h).add(i);
  }

  const results = new Set();

  for (const items of heights.values()) {
    for (const first of items) {
      for (const second of items) {
        if (first !== second) {
          results.add(`${first}-${second}`);
        }
      }
    }
  }

  return results.size / 2;
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  const lines = i.split(EOL)
  console.log(program(lines));
})

const readline = require('readline');

const data = [];
let length = 0;
let msgCounter = 0;
let pairsCounter = 0;

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

function countPairs () {
  for (let i = data.length - 1; i > 0; i--) {
    for (let j = i - 1; j >= 0; j--) {
      if (data[i][0] === data[j][0]
        || data[i][0] === data[j][1]
        || data[i][1] === data[j][1]
        || data[i][1] === data[j][0]) {
          pairsCounter++;
      }
    }
  }
}

rl.on('line', input => {
  if (length === 0) length = +(input);
  else data.push(input.split(' '));

  if (length === msgCounter) {
    countPairs();
    console.log(pairsCounter);
    rl.close();
  } else msgCounter++;
});

const fs = require('fs');
const readline = require('readline');
const path = require('path')

class PacketsCounter {
    count = undefined

    isInited() {
        return typeof this.count !== 'undefined';
    }

    setInitialCount(count) {
        if (this.isInited()) {
            throw new Error('Commands counter is already inited');
        }

        this.count = count;
    }

    isPacketsLeft() {
        return this.count > 0;
    }

    decreaseCounter() {
        this.count--;
    }
}

class MonitorsMatcher {
    list = [] // all monitors

    addMonitor(monitor) {
        const [w, h] = monitor.split(' ');

        this.list.push({ w, h });
    }

    countCombinations() {
        let sum = 0;

        for (let i = 0; i < this.list.length; i++) {
            const first = this.list[i];

            for (let j = i + 1; j < this.list.length; j++) {
                const second = this.list[j];

                if (first.h === second.h || first.w === second.h || first.h === second.w || first.w === second.w) {
                    sum += 1
                }
            }
        }

        return sum;
    }
}

// MAIN

function main() {
    const monitorsMatcher = new MonitorsMatcher();
    const commandsCounter = new PacketsCounter();
    // const readStream = fs.createReadStream(path.resolve(__dirname, './input'));
    const readStream = process.stdin;

    const lineCallback = (line) => processLine(monitorsMatcher, commandsCounter, line);
    const closeCallback = () => sendAnswer(String(monitorsMatcher.countCombinations()));

    initInputRead(readStream, lineCallback, closeCallback);
}

main();

// ---

function initInputRead(inputInterface, lineCb, closeCb) {
    const readInterface = readline.createInterface({
        input: inputInterface,
    });

    readInterface.on('line', line => lineCb(line));
    readInterface.on('close', () => closeCb());
}

function processLine(monitorsMatcher, commandsCounter, line) {
    // first line: init counter
    if (!commandsCounter.isInited()) {
        commandsCounter.setInitialCount(Number(line));
        return;
    }

    // exec commands while counter of commands is more than inited in first line
    if (commandsCounter.isPacketsLeft()) {
        monitorsMatcher.addMonitor(line);
        commandsCounter.decreaseCounter();
        return;
    }
}

function sendAnswer(answer) {
    process.stdout.write(answer);
    process.stdout.write('\n');
}

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

let content = []
let i = 0

function B (content) {
    let count = 0;
    for (let current = 0; current < content.length; current++) {
        let [h, w] = content[current]
        for (let next = current + 1; next < content.length; next++) {
            let val = content[next]
            if (val[0] === h || val[0] === w || val[1] === h || val[1] === w) {
                count++
            }
        }
    }
    console.log(count)
}

rl
    .on('line', value => {
        if (i === 0) {
            i++
            return
        }
        content.push(value.split(' '))
    })
    .on('close', () => {
        B(content)
    })

module.exports = B

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    let lines = i.split(EOL);
    const itemsLength = lines[0];
    lines = lines.slice(1, lines.length - 1);
    /****** */
    const monitors = [];
    lines.forEach(item => {
      monitors.push({
        width: item.split(' ')[0],
        height: item.split(' ')[1]
      })
    })
    let acceptableMonitorsCount = 0;
    function checkMonitors(m1, m2) {
      let accept = false;
      if ( m1.height === m2.height
        || m1.width === m2.height
        || m1.height === m2.width
        || m1.width === m2.width ) {
        accept = true;
      }
      return accept;
    }
    for (let i = 0; i < itemsLength - 1; i++) {
      for (let j = i + 1; j < itemsLength; j++) {
        if (checkMonitors(monitors[i], monitors[j])) {
          acceptableMonitorsCount++;
        }
      }
    }

    /****** */
    console.log(acceptableMonitorsCount);
});

var n = readline();
var pairs = []
var pairsCount = 0
var r = 0

for (var i = 0; i < n; i++) {
	var l = readline().split(' ')

	r += pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;

	pairs.push(l)
}

print(r);

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let total = 0;
let values = [];
let output = 0;
let repeats = {};

readInterface.on('line', function(line) {
    if (count === 0) {
        total = +line;
    } else {
        if (values.includes(line)) {
            repeats[line] += 1;
        } else {
            repeats[line] = 1;
            values.push(line);
        }
    }

    if (values.length === total) {

        for (let i = 0; i < total; i++) {
            let item = values.shift();

            let filtered = values.filter(el => {
                let itemSize = item.split(' ');
                let itemW = itemSize[0];
                let itemH = itemSize[1];

                let elSize = el.split(' ');
                let elW = elSize[0];
                let elH = elSize[1];
                return itemH === elH || itemW === elH || itemW === elW || itemH === elW;
            })

            let result = filtered.length * repeats[item];

            output += filtered.length;
        }

        console.log(output);
    }

    count++;
});

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let n = +await nextString()
  let obj = {}
  let ans = 0
  for (let i = 0; i < n; ++i) {
    let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)
    let mid = a + '_' + b
    if (a !== b) {
      ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)
    }
    else {
      ans += (obj[a] || 0)
    }
    obj[a] = obj[a] ? obj[a] + 1 : 1
    obj[b] = obj[b] ? obj[b] + 1 : 1
    obj[mid] = obj[mid] ? obj[mid] + 1 : 1
  }
  console.log(ans)
}

main()

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let n = +await nextString()
  let obj = {}
  let ans = 0
  for (let i = 0; i < n; ++i) {
    let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)
    let mid = a + '_' + b
    if (a !== b) {
      ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)
    }
    else {
      ans += obj[a]
    }
    obj[a] = obj[a] ? obj[a] + 1 : 1
    obj[b] = obj[b] ? obj[b] + 1 : 1
    obj[mid] = obj[mid] ? obj[mid] + 1 : 1
  }
  console.log(ans)
}

main()

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let n = +await nextString()
  let obj = {}
  let ans = 0
  for (let i = 0; i < n; ++i) {
    let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)
    let mid = a + '_' + b
    ans += (obj[a] || 0) + (obj[b] || 0) - (obj[mid] || 0)
    obj[a] = obj[a] ? obj[a] + 1 : 1
    obj[b] = obj[b] ? obj[b] + 1 : 1
    obj[mid] = obj[mid] ? obj[mid] + 1 : 1
  }
  console.log(ans)
}

main()

const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift(1)(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift(1))
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

async function main() {
  let n = +await nextString()
  let obj = {}
  let ans = 0
  for (let i = 0; i < n; ++i) {
    let [a, b] = (await nextString()).split(' ').map(x => +x).sort((a, b) => a - b)
    let mid = a + '_' + b
    ans += obj[a] + obj[b] - obj[mid]
    obj[a] = obj[a] ? obj[a] + 1 : 1
    obj[b] = obj[b] ? obj[b] + 1 : 1
    obj[mid] = obj[mid] ? obj[mid] + 1 : 1
  }
  console.log(ans)
}

main()

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let n = 0;
let solo = [];
let pairs = [];
let values = [];

function calcEqual(a) {
    let last = -1;
    let res = 0;
    let cnt = 0;
    a.sort();
    for (let i = 0; i < a.length; i++) {
        let x = a[i];
        if (JSON.stringify(x) === JSON.stringify(last)) {
            res += cnt;
            cnt += 1;
        } else {
            cnt = 1;
        }
        last = x;
    }
    return res;
}

readInterface.on('line', function(line) {
    if (count === 0) {
        n = +line;
    } else {
        values.push(line);
    }

    if (values.length === n) {
        for (let i = 0; i < n; i++) {
            let pair = line.split(' ').map(el => { return +el; });
            w = pair[0];
            h = pair[1];
            solo.push(w);
            if (h != w) {
                solo.push(h);
                pairs.push([Math.min.apply(null, pair), Math.max.apply(null, pair)]);
            }
        }
        console.log(calcEqual(solo) - calcEqual(pairs));
    }

    count++;
});

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let total = 0;
let values = [];
let output = 0;

readInterface.on('line', function(line) {
    if (count === 0) {
        total = +line;
    } else {
        values.push(line);
    }

    if (values.length === total) {

        for (let i = 0; i < total; i++) {
            let item = values.shift();
            console.log('item', item);
            console.log('values', values);

            let filtered = values.filter(el => {
                let itemSize = item.split(' ');
                let itemW = itemSize[0];
                let itemH = itemSize[1];

                let elSize = el.split(' ');
                let elW = elSize[0];
                let elH = elSize[1];
                return itemH === elH || itemW === elH || itemW === elW || itemH === elW;
            })
            console.log('filtered', filtered);

            output += filtered.length;
        }

        console.log(output);
    }

    count++;
});

const readline = require('readline');
const fs = require('fs');

const readInterface = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    console: false
});

let count = 0;
let total = 0;
let values = [];
let output = 0;

readInterface.on('line', function(line) {
    if (count === 0) {
        total = +line;
    } else {
        values.push(line);
    }

    if (values.length === total) {

        for (let i = 0; i < total; i++) {
            let item = values.shift();

            let filtered = values.filter(el => {
                let itemSize = item.split(' ');
                let itemW = itemSize[0];
                let itemH = itemSize[1];

                let elSize = el.split(' ');
                let elW = elSize[0];
                let elH = elSize[1];
                return itemH === elH || itemW === elH || itemW === elW;
            })

            output += filtered.length;
        }

        console.log(output);
    }

    count++;
});

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var count_of_monitors
var monitors_sizes = []
function start() {
    rl.question("", function(answer) {
        count_of_monitors = parseInt(answer)
        get_mon()
    });
}

function get_monitors() {
    rl.question("", function(answer) {
        monitors_sizes.push(answer)
        count_of_monitors--
        get_mon()
    });

}

function get_mon() {
    if (count_of_monitors > 0) {
        get_monitors()
    } else {
        get_pairs()
    }
}

function factorial(n) {
  return (n != 1) ? n * factorial(n - 1) : 1;
}

function get_pairs() {
    var pairs = []
    var count_factorial_combinations = 0
    var deleted_sizes = []
    var old_arr = monitors_sizes
    for (var i = 0; i < monitors_sizes.length; i++) {
        var fact_arr = monitors_sizes.filter(size => size == monitors_sizes[i])
        if (fact_arr.length > 1) {
            count_factorial_combinations += factorial(fact_arr.length)
            monitors_sizes = monitors_sizes.filter((word, index) => {

                if (word == monitors_sizes[i]) {
                    if (index == i) {
                        return true
                    } else {
                        deleted_sizes.push(monitors_sizes[i])
                        return false
                    }
                } else {
                    return true
                }
            })
        }
    }
    for (var first_mon_index = 0; first_mon_index < monitors_sizes.length; first_mon_index++) {
        if (typeof(monitors_sizes[first_mon_index + 1]) != "undefined") {
            for (var second_mon_index = first_mon_index + 1; second_mon_index < monitors_sizes.length; second_mon_index++) {
                if (first_mon_index != second_mon_index) {
                    var first_mon_index_sizes = monitors_sizes[first_mon_index].split(" ")
                    var second_mon_index_sizes = monitors_sizes[second_mon_index].split(" ")
                    if (parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[0]) ||
                        parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[1]) ||
                        parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[0]) ||
                        parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[1])) {
                        if (pairs.includes(`${first_mon_index} - ${second_mon_index}`) == false && pairs.includes(`${second_mon_index} - ${first_mon_index}`) == false) {
                            pairs.push(`${first_mon_index} - ${second_mon_index}`)
                            if (deleted_sizes.indexOf(monitors_sizes[first_mon_index]) !== -1) {
                                var mid_arr = old_arr.filter(word => word == monitors_sizes[first_mon_index])
                                if (mid_arr.length > 1) {
                                    count_factorial_combinations += mid_arr.length - 1
                                }
                            }
                            if (deleted_sizes.indexOf(monitors_sizes[second_mon_index]) !== -1) {
                                var mid_arr = old_arr.filter(word => word == monitors_sizes[second_mon_index])
                                if (mid_arr.length > 1) {
                                    count_factorial_combinations += mid_arr.length - 1
                                }
                            }
                        }

                    }
                }
            }
        }

    }
    console.log(pairs.length + count_factorial_combinations)
}

start();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var count_of_monitors
var monitors_sizes = []
function start() {
    rl.question("", function(answer) {
        count_of_monitors = parseInt(answer)
        get_mon()
    });
}

function get_monitors() {
    rl.question("", function(answer) {
        monitors_sizes.push(answer)
        count_of_monitors--
        get_mon()
    });

}

function get_mon() {
    if (count_of_monitors > 0) {
        get_monitors()
    } else {
        get_pairs()
    }
}

function factorial(n) {
  return (n != 1) ? n * factorial(n - 1) : 1;
}

function get_pairs() {
    var pairs = []
    var count_factorial_combinations = 0
    var deleted_sizes = []
    var old_arr = monitors_sizes
    for (var i = 0; i < monitors_sizes.length; i++) {
        var fact_arr = monitors_sizes.filter(size => size == monitors_sizes[i])
        if (fact_arr.length > 1) {
            count_factorial_combinations += factorial(fact_arr.length)
            monitors_sizes = monitors_sizes.filter((word, index) => {

                if (word == monitors_sizes[i]) {
                    if (index == i) {
                        return true
                    } else {
                        deleted_sizes.push(monitors_sizes[i])
                        return false
                    }
                } else {
                    return true
                }
            })
        }
    }
    for (var first_mon_index = 0; first_mon_index < monitors_sizes.length; first_mon_index++) {
        for (var second_mon_index = first_mon_index + 1; second_mon_index < monitors_sizes.length; second_mon_index++) {
            if (first_mon_index != second_mon_index) {
                var first_mon_index_sizes = monitors_sizes[first_mon_index].split(" ")
                var second_mon_index_sizes = monitors_sizes[second_mon_index].split(" ")
                if (parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[0]) ||
                    parseInt(first_mon_index_sizes[0]) == parseInt(second_mon_index_sizes[1]) ||
                    parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[0]) ||
                    parseInt(first_mon_index_sizes[1]) == parseInt(second_mon_index_sizes[1])) {
                    if (pairs.includes(`${first_mon_index} - ${second_mon_index}`) == false && pairs.includes(`${second_mon_index} - ${first_mon_index}`) == false) {
                        pairs.push(`${first_mon_index} - ${second_mon_index}`)
                        if (deleted_sizes.indexOf(monitors_sizes[first_mon_index]) !== -1) {
                            var mid_arr = old_arr.filter(word => word == monitors_sizes[first_mon_index])
                            if (mid_arr.length > 1) {
                                count_factorial_combinations += mid_arr.length - 1
                            }
                        }
                        if (deleted_sizes.indexOf(monitors_sizes[second_mon_index]) !== -1) {
                            var mid_arr = old_arr.filter(word => word == monitors_sizes[second_mon_index])
                            if (mid_arr.length > 1) {
                                count_factorial_combinations += mid_arr.length - 1
                            }
                        }
                    }

                }
            }
        }
    }
    console.log(pairs.length + count_factorial_combinations)
}

start();

var n = readline();
var pairs = []
var pairsCount = 0
var r = 0

for (var i = 0; i < n; i++) {
	var l = readline().split(' ')

	var c = pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;

	if (c > 1) {
		r += c
	}

	pairs.push(l)
}

print(r);

var n = readline();
var pairs = []
var pairsCount = 0
var r = 0

for (var i = 0; i < n; i++) {
	var l = readline().split(' ')

	var c = pairs.filter(el => el.includes(l[0]) || el.includes(l[1])).length;

	if (c > 1) {
		r += c
	}

	pairs.push(l)
}

print(r * (r - 1) / 2);

var n = readline();
var numbers = []

for (var i = 0; i < n; i++) {
	var l = readline().split(' ');

	if (l[0] === l[1]) {
		numbers.push(l[0])
	} else {
		numbers = numbers.concat(l)
	}
}

var r = 0

while (numbers.length) {
	var currNumber = numbers[0]
	var l = numbers.length
	numbers = numbers.filter(el => el !== currNumber)
	var l = l - numbers.length

	if (l > 1) {
		r += (l * (l - 1)) / 2
	}
}

print(r);

var n = readline();
var numbers = []

for (var i = 0; i < n; i++) {
	var l = readline().split(' ');

	if (l[0] === l[1]) {
		numbers.push(l)
	} else {
		numbers = numbers.concat(l)
	}
}

var r = 0

while (numbers.length) {
	var currNumber = numbers[0]
	var l = numbers.length
	numbers = numbers.filter(el => el !== currNumber)
	var l = l - numbers.length

	if (l > 1) {
		r += (l * (l - 1)) / 2
	}
}

print(r);

var n = readline();
var numbers = []

for (var i = 0; i < n; i++) {
	var l = readline().split(' ');

	if (l[0] === l[1]) {
		numbers.push(l)
	} else {
		numbers.push(...l)
	}
}

var r = 0

while (numbers.length) {
	var currNumber = numbers[0]
	var l = numbers.length
	numbers = numbers.filter(el => el !== currNumber)
	var l = l - numbers.length

	if (l > 1) {
		r += (l * (l - 1)) / 2
	}
}

print(r);

var n = readline();
var numbers = {}

for (var i = 0; i < n; i++) {
	var l = readline().split(' ');

	if (l[0] === l[1]) {
		if (numbers[l[0]]) {
			numbers[l[0]] = numbers[l[0]] + 1;
		} else {
			numbers[l[0]] = 1
		}
	} else {
		l.forEach(el => {
			if (numbers[el]) {
				numbers[el] = numbers[el] + 1;
			} else {
				numbers[el] = 1
			}
		})
	}
}

print("1");