🏡 index : github.com/captn3m0/codechef.git

---
languages_supported:
    - NA
title: A7
category: NA
old_version: true
problem_code: A7
tags:
    - NA
layout: problem
---
###  All submissions for this problem are available. 

**This problem was part of the [CodeChef April Challenge](/APRIL09/). All user submissions for this contest problem are publicly available [here](/APRIL09/status/A7/).**

Your grandfather is known in the family for his unconventional sense of humour. Since he made his fortune on the network of pizza parloursa), he has been giving expensive gifts to the members of the family every Christmas. Receiving the gift, however, always involves solving a more or less fancy mathematical puzzle.

This year, your gift was locked in a safe, self-made by your grandfather. The safe was secured with a two digit code: in order to open it you had to provide the correct integer number from the range \[0, 99\]. A bit disgruntled that this year's puzzle would apparently be solved with the force (and not even too brute), you were just about to start examining the numbers, when you heard grandfather's voice - "Beware, kid! After two unsuccessful attempts the content will be annihilated!" "Then how am I supposed to solve this, Grandpa?" - you asked. "Go and have a better look at the package" - grandfather replied.

Indeed, at the bottom of the package you found a city map on which were indicated all the pizza parlours belonging to your grandfather, as well as a long sheet of paper with a sequence of positive integers. After analysing the data for a while you realized that the number of integer values is equal to the number of pizza restaurants... Recognizing that you still have too little input, you went to ask grandfather for further guidance.

"Ah, all right, I'll solve the riddle for you" - grandfather relented. "For each pizza parlour you have to draw such an axis-aligned square that it is centered at the restaurant and half of the length of its side is equal to the corresponding value from the sheet. Then you have to count all the streets on the map which intersect with the square, and write down the **result of calculations**. The result for the last pizza parlour will be your magic number."

You were a bit surprised that grandfather ordered you to draw squares and count streets for all the restaurants (and there were many), since the code would only depend on the last one. Nonetheless you willingly took on the job, drew the square for the last pizza parlour, counted the streets and entered the number. Unfortunately the safe didn't open.

You rushed to grandfather and told him about the first failed attempt. "Oh dear, did I forget to mention?" - the old man was slightly taken aback. "For each restaurant but the first one, you have to modify both its coordinates by bit-xor'ing them with the result of calculations for the directly preceding restaurant, before drawing the square!". Will you be able to claim the gift now? You have only one attempt left!

### Input

The first line of input contains two integers _n_ and _m_ (0 ≤ _n_ ≤ 5000, 1 ≤ _m_ ≤ 50000), the number of streets in the capital city and the number of pizza parlours, respectively. The following _n_ lines contain four integers _x1_, _y1_, _x2_ and _y2_, each (0 ≤ _x1, y1, x2, y2_ ≤ 1000<). Each of these lines defines the location of one of the streets, with (_x1_, _y1_) representing one of the endpoints and (_x2_, _y2_) the other one. The streets can be assumed to be straight line segments. Eventually there are _m_ lines with three integers _x_, _y_ and _r_ each (0 ≤ _x, y_ ≤ 1000, 1 ≤ _r_ ≤ 20). Each of these lines defines x and y coordinates of one of the pizza parlours and the corresponding number from the sheet attached to your gift, respectively.

You may find it useful to know that:

- A street can have identical endpointsb).
- Any two distinct streets have at most one common point.
- When counting intersecting streets, you should assume that the boundary of the square belongs to the square.
- The configuration of the streets guarantees that any square satisfying _0 ≤ x, y ≤ 1000, 1 ≤ r ≤ 20_ will contain at most 99 intersecting streets.
- Your grandfather is 78 and claims that Fortran is the best language for solving his Christmas puzzles.

### Output

The output should contain a single integer value - the code that opens the safe.

### Example

<pre><b>Input:</b>
5 2
2 2 4 6
2 2 7 4
4 6 7 4
7 4 10 3
7 4 10 5
10 4 2
0 0 1

<b>Output:</b>
2
</pre>### Notes

a) This should not surprise anyone. As the IT sector is extremely well-developed in Byteland, pizza network owners are among the richest people there.

b) For some inscrutable reasons such streets are called squares. Not to be mixed up with the squares you draw!