CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April 2009 (Contest II) » A Christmas Pizza Puzzle

A Christmas Pizza Puzzle

Problem code: A7

  • All Submissions

All submissions for this problem are available.

This problem was part of the CodeChef April Challenge. All user submissions for this contest problem are publicly available here.

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

Input:
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

Output:
2

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!


Date: 2008-12-01
Time limit: 7

s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK


  • Submit

Comments

  • Login or Register to post a comment.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com