Most of the people in the villages are farmers. They buy and sell lands according to their needs. Some people even compensate their farming lands for the debts they have.
Krishna and Shiva are farmers in a village. Krishna has a desire of having a vast farmland and becoming a landlord. Years ago, Krishna lent some amount to Shiva for interest. Now Shiva is unable to repay the amount and he asked Krishna to take the land which is worth of the money that he has to pay. One day Krishna visited Shiva's fields and he noticed that only the middle part of the field have water supply. So Krishna opted for selecting the middle part of that land in circular layout. Next day Krishna thought of fencing that land to get it separated from Shiva's land and called a worker. While noting down the coordinates of centre of the circle and point on the circumference, the worker noted a coordinate point wrongly and he fenced accordingly. Both, Krishna and Shiva, noticed that the fencing went wrong, but decided to adapt. They decided the following
If the fence occupied less land than actual, then Krishna will accept money for the remaining land from Shiva. If the fence occupied more land than the actual, Krishna will give land back to Shiva whose area is a perfect square nearest to what Shiva deserves. If the area of that layout is more than what Shiva deserves, then Shiva will pay for the remaining else Krishna will pay for the remaining. Given the coordinates of starting and ending points viz. {A, B} where A is the centre of the circular land and B is a point on the circumference, the coordinates of wrongly noted point (C), print the name of the person who is receiving money and also the amount he received. Consider the cost of each Square feet is 20 bucks.
Note: Consider the ceil() value of radius and area of the circle.
All the measurements are in Square feet only.
Assume that both Shiva and Krishna have limited money for compensating extra land.
Constraints 0 <= x <= 1000
0 <= y <= 1000
Input Three different lines consisting of the coordinates (x,y) of points A, B and C separated by space.
Output Print the name of the person who is receiving money and also the amount he received in a single line separated by space. If no one received, print -1.
Time Limit (secs) 1
Examples Example 1
Input
3 4
12 14
14 15
Output
Krishna 160
Explanation
Here the actual area that Krishna have to acquire from Shiva is 616 sqft. But the fence gone wrong and it occupied 804 sqft. According to their deal, Krishna have to bestow the land of area 188 sqft to Shiva. So according to the rules, Krishna will give 196 sqft of land to Shiva . Since he gave more than what Shiva deserves, he will get an amount of (196-188)*20=160 bucks.
Example 2
Input
2 5
11 13
13 11
Output
-1
Explanation
Here the actual area that Krishna have to acquire from Shiva is 531 sqft and even through the fence gone wrong, area he occupied remains same. So here no transactions of money takes place. So we print -1. Write a Python Program
To solve the given problem, we can use the following Python program:
import math # Function to calculate the distance two points def distance(x1, y1, x2, y2): return math.sqrtx2 - x1) ** 2 + (y2 - y1) 2) # Function to calculate the area of a circle def circle_area(radius): return math.pi * (radius ** 2) # Function to calculate the area a square def square_area(side): return side **2 # Function to find the nearest perfect square to a given number def nearest_perfect_square(num): lower_square = math.floor(math.sqrt(num)) upper = math.ceil(math.sqrt(num)) if abs(num - (lower_square ** 2 < abs(num - (upper_square ** 2)): return lower_square **2 else: return upper_square ** 2 # Input coordinates of A, B, and Cx1, y1 = map(int, input().splitx2, y2 = map(int, input().split()) 3, y3 =(int, input().split()) # Calculate the distance between points A and B to get the radius radius = math.ceil(distance(x1, y1, x2,2)) # Calculate the area of the circle actual_area = math.ceil(circle_area(radius)) # Calculate the distance between points A and C to check if the fence occupied more or less land than the actual fence_radius = math.ceil(distance(x1, y1, x3, y3)) # Calculate the area of the fence ence_area = math.ceil(circle_area(fence_radius)) # Check if the fence occupied more or less land than the actual and adjust the transactions accordingly if fence_area < actual_area: amount_received = (actual - fence_area) * 20 print("Krishna", amount) elif fence_area > actual_area: nearest_square =_perfect_square(actual_area) if nearest_square > actual_area: amount_paid = (nearest_square - actual_area) * 20 print("Shiva", amount_paid) else: amount_received = (actual_area - nearest_square) * 20 print("Krna", amount_received) else: print("-1") ` When provided with the coordinates of A, B, and, this program will calculate the respective areas and the amount of money that Krishna or Shiva will receive or pay according to the given conditions.