Mental rotation is a difficult thing to master. Mental rotation is the ability to imagine in your mind how an object would look like from a viewer's side if you were to rotate it in a particular direction. It is something very important for engineers to learn and master, especially if you are required to do engineering drawing. There are many stages to these mental rotation tasks. We will approach a simple rotation task in this problem.
If you are given the following square -
After rotating it to the right once, it will look like the following -
After rotating it to the left once, it will look like the following -
For this problem you will be given an initial square of size n and a list of rotations to perform.
Your task is to output the final representation of the square after performing all the rotation.
The first line of input contains an integer $$$N$$$ (1 ≤ $$$N$$$ ≤ 1000). and a string containing a combination of $$$'L'$$$ and $$$'R'$$$. Where $$$'L'$$$ means left rotation and $$$'R'$$$ means right rotation. Length of the string will not exceed 100. Starting from the second line, the following $$$N$$$ line each will contain $$$N$$$ of the following characters ($$$ \gt $$$, $$$ \lt $$$, $$$∨$$$, $$$∧$$$ or $$$.$$$). Empty space is indicated by a '$$$.$$$' (dot).
The output should be $$$N$$$ lines, each containing $$$N$$$ characters representing the final representation of the square after all the rotation. For $$$∨$$$ and $$$∧$$$ use $$$v$$$ (small v) and Shift+6 respectively.
3 R >v> ... <^<
^.v >.< ^.v
3 L >v> ... <^<
^.v >.< ^.v
3 LL >v> ... <^<
>v> ... <^<
Sponge Bob, the famous cartoon character can only wear square shape pants. Squares shape can be described in geometry as having 4 right angles, just like rectangles. But a square is a special case of rectangle where its width and height are the same.
You are given the width and the height of a 4 right angled shape and need to figure out if it is a square or a rectangle for Sponge Bob. He will get all the square ones as his new pants for the coming Eidul Fitri.
The first line contains $$$T$$$, the number of test cases. For each test case there is a line with two integers (1 ≤ $$$w, h$$$ ≤ 1,000,000) representing width and height, respectively.
For each test case, print one line consists of $$$'YES'$$$ (without quotes) if the shape is a square and good for Sponge Bob's pants, otherwise print $$$'NO'$$$ (without quotes) if it is a rectangle and not suitable to be Sponge Bob's pants.
4 9 9 16 30 200 33 547 547
YES NO NO YES
Nina from the IT support needs your help with another daily puzzle she faces. She is able to take her lunch break anytime she wants. But because of limited capacity, she only can take $$$S$$$ minutes based on the needs that day. Any extra minutes that she is late, she has to pay $$$RM 1$$$ to the late jar.
She prepared a list of her favorite restaurants and how long it would take for her to lunch in each restaurant based on experience, ($$$1$$$ ≤ $$$t_{i}$$$ ≤ $$$10^9$$$ ). She also assigned a value for each of the restaurants that shows how much extra she is willing to pay but still be happy, ($$$1$$$ ≤ $$$f_{i}$$$ ≤ $$$10^9$$$ ).
For example, if she needs $$$t_{x}$$$ minutes to dine in restaurant $$$x$$$ which she values $$$RM f_{x}$$$ . If $$$t_{x} ≤ S$$$ then she is fully happy and it is as if she saved $$$RM f_{x}$$$.
But if $$$t_{x} \gt S$$$ she would save $$$f_{x} - (t_{x} - S)$$$.
Please help her to find the restaurant that she would be happiest in and meanwhile save the most. Also, keep in mind she can choose exactly one restaurant to lunch each day.
The first line contains an integer – $$$D (1 ≤ D ≤ 10)$$$ – the number of days.
The second line contains two space-separated integers — $$$N (1 ≤ N ≤ 10^4 )$$$ and $$$S (1 ≤ S ≤ 10^9 )$$$ — the number of restaurants in Nina's list and her lunch break time for the day, correspondingly.
Each of the next $$$N$$$ lines contains two space-separated integers — $$$f_{i} (1 ≤ f_{i} ≤ 10^9 )$$$ and $$$t_{i}$$$ $$$(1 ≤ t_{i} ≤ 10^9 )$$$ — the characteristics of the $$$i_{th}$$$ restaurant.
In a single line print a single integer — the maximum money she is saving/her happiness by day.
2 2 5 3 3 4 5 1 5 1 7
Case #1: 4 Case #2: -1
Ali is a multi-billionaire. Sometimes, for fun he give away his money to his friends. But Ali is a strange person, so he likes to play a game first.
First, he arrange all his friends in a circle. He assign his friends number from $$$1$$$ to $$$N$$$ in clockwise direction. Each of his friends need to remember two integer, $$$a$$$ and $$$b$$$ which its initial value is $$$1$$$. These two integer is used to calculate another integer $$$x$$$ using the following formula:
In the game, Ali give several command to his friends. In each command, Ali will specify four thing, the integer to increment (either $$$a$$$ or $$$b$$$), an integer $$$h$$$ which is how much should the number be incremented by and two position, $$$j$$$ and $$$k$$$. When Ali call out the command, his friend from $$$j$$$ to $$$k$$$ in clockwise direction will increment their number by $$$h$$$. After all the commands are given out, all his friend can calculate their $$$x$$$, and that is the amount that Ali will give out to the respective friend.
Given the number of friends $$$N$$$ and $$$M$$$ instructions that Ali give out, find out how much in total Ali need to give to his friends.
The first line starts with two number $$$N$$$ and $$$M$$$, $$$(1 ≤ N, M ≤ 2 × 10^4 )$$$ which is the number of friends and the number of instruction. The next $$$M$$$ line consist of one character and three integer, $$$c_{i} , j_{i} , k_{i}$$$ and $$$h_{i}$$$ $$$(1 ≤ j_{i} , k_{i} ≤ N, 1 ≤ h_{i} ≤ 10^6 )$$$. $$$c_{i}$$$ is either $$$'a'$$$ or $$$'b'$$$.
Print a single integer which is the total $$$x$$$ across all Ali's friend.
7 4 a 6 3 1 a 2 5 4 a 7 1 1 b 7 2 1
16
Note that while each $$$x$$$ is modded by $$$10^5 + 7$$$, the total is not
The main hall of your residency is open for use by the local community and public. Since it was built on public donations, there is no charge of using it. Every weekend particularly on public holidays there are up to 50 reservations to use it for multiple events with different durations.
You have been assigned by the residents to develop a program in choosing events to get most out of allocation time per weekend and have $$$\textbf{as short unused time as possible}$$$. Program should find the event(s) which fill(s) the allocation time best and print it in the same sequence as appears in the reservation list.
Each test case consist of a single line.
The line starts with two integer $$$T$$$ and $$$N$$$ which is the time allocated for the hall to be used in the particular weekend and the number of events. The next $$$T$$$ integer are the durations of the events (as appear in the reservation list). For example from the first line in sample data: $$$T = 5$$$ hours, $$$N$$$, number of events $$$= 5$$$, first event lasts for $$$1$$$ $$$hour$$$, second is $$$2$$$ $$$hours$$$, third is $$$3$$$ $$$hours$$$, fourth is $$$4$$$ $$$hours$$$, and the last one is $$$5$$$ $$$hours$$$.
The input process will be terminated by a line containing 0.
For each line of input value, in a single line, first, output a list of integers which are the selected events duration and another integer which is the sum of the selected events duration.
If there are multiple possible list of events, events that appear earlier in the list takes priority.
5 5 1 2 3 4 5 10 9 11 9 3 5 8 4 9 3 2 16 8 12 6 11 11 13 1 10 7 13 5 10 12 2 13 10 28 14 18 19 26 15 18 24 7 21 14 25 2 12 9 6 0
1 4 5 3 5 2 10 6 10 16 13 13 19 7 2 28
There is a military class of $$$2*n$$$ soldiers, and the commander wants all of them to get partnered into n pairs. He divides the soldiers into two lines of length $$$n$$$, and numbers the soldiers in both lines from $$$1$$$ to $$$n$$$.
The $$$i_{th}$$$ numbered soldiers in the first line can be partnered with the $$$j_{th}$$$ numbered soldiers in the second line if $$$|i - j| ≤ e$$$. However, there are $$$k$$$ pairs of soldiers that cannot be paired together. You need to print the number of ways you can match the soldiers into $$$n$$$ pairs such that the constraints above are met. One way is different than the other if at least one soldiers has a different partner.
The first line contains 3 integers $$$n, e, k (1 ≤ n ≤ 2000, 0 ≤ e ≤ 4, 0 ≤ k ≤ 2000)$$$, the number of soldiers in each line, the value that determines the range, and the number of invalid pairs, respectively.
Each of the next $$$k$$$ lines contains two integers $$$u_{i}, v_{i} (1 ≤ u_{i}, v_{i} ≤ n)$$$, the number of the soldiers from the first line and the number of the soldiers from the second line that cannot be matched together respectively. No pair of soldiers will appear twice in the input.
Output the number of ways modulo $$$10^{9} + 7$$$, on a single line.
2 1 0
2
2 1 1 1 2
1
Abu is working on a web application's backend. Like any other server, his server have multiple endpoints for many different purpose. Each of his endpoint is described as multiple tasks, where each task can depend on other tasks. Abu likes to describe his endpoints like this because it is easy and safe to parallelize. For example, let say his endpoint consist of five task, $$$A, B, C, D$$$ and $$$E$$$. $$$B$$$ depends on $$$A$$$. $$$D$$$ depends on $$$C$$$ and $$$B$$$. $$$E$$$ depends on $$$D$$$. Because $$$A$$$ and $$$C$$$ does not depends on each other they can run at the same time. And when $$$A$$$ is completed, $$$B$$$ can start running regardless if $$$C$$$ have been completed or not. When both $$$B$$$ and $$$C$$$ have completed, regardless of which one finish first, $$$D$$$ can start running.
Now, Abu's server is getting more and more traffic lately and it is important for him to know the runtime of some of his endpoint. He knows you are good at this sort of things, so he ask for your help. Given a description of his system, which consist of multiple endpoints, and a list of query, determine the runtime of the queried endpoint. Each endpoint is described as multiple task which may depends on zero or more other task from the same endpoint. A task can either be a calculation whose runtime will be given, or another endpoint call whose runtime, is the runtime of the specified endpoint, plus a fixed network latency of $$$1$$$.
You are to assume an endpoint will ran all its task as optimally as possible with maximum parallelization. There will not be a cycle in the chain of endpoint calls. In another word, an endpoint $$$A$$$ will never call an endpoint $$$B$$$ which will call endpoint $$$A$$$, or call other endpoint which eventually goes back to $$$A$$$.
The input starts with an integer $$$n, m$$$ $$$(1 ≤ m ≤ n ≤ 2×10^{4} )$$$ which is the number of endpoint and number of query. $$$n$$$ description of endpoint follows.
Each endpoint description starts with an integer $$$k$$$ $$$(1 ≤ k ≤ 10^{2} )$$$ which is the number of task for that endpoint. Each task is numbered from $$$1$$$ to $$$k$$$ and described in order as follows.
Each task description consist of two line. The first line describe the task dependency. The first line starts with an integer $$$l$$$ $$$(0 ≤ l ≤ k)$$$ which is the number of dependency. The next $$$l$$$ integer is the task that the current task depends on. The second line describe the task itself. It consist of two integer that starts with $$$o$$$ which is the type of task. If it is $$$0$$$ it is a calculation, and the second integer $$$r$$$ $$$(0 ≤ r ≤ 10^{3} )$$$ is the runtime of the task. If it is a $$$1$$$ it is an endpoint call and the second integer $$$e$$$ $$$(1 ≤ e ≤ n)$$$ is the number for the endpoint.
The next $$$m$$$ line each consist of a single integer $$$q_{i}$$$ $$$(1 ≤ q_{i} ≤ n)$$$ which is the number for the endpoint that is being queried.
For each $$$q_{i}$$$, print a line containing a single integer, which is the runtime for that particular endpoint. As the runtime can be very high, modulus each $$$q_{i}$$$ by $$$10^{9} + 7$$$.
3 2 5 0 0 100 1 1 1 2 1 1 1 3 0 0 10 3 2 3 4 0 1 1 0 0 1000 2 0 0 100 1 1 1 2 1 2
1203 1000
Large input file. Do not use slow IO.
Recently, the nation was shocked by news of Sungai Kim Kim incident in Pasir Gudang, Johor, which has been polluted by chemical waste. Thousands of people who are affected had experienced nausea, dizziness and vomiting, and more than 100 schools were ordered to shut. In order to ensure that such incident will not happen again, an early warning system need o be developed so that residents can make early preparation, and authorities are able to move and act much faster.
A group of scientists has formed a committee to handle the incident, and a smart system with Internet of Things (IoT) sensors was suggested. Numerous sensors which can sense and monitor damages to the environment, either air or water, have been strategically installed around the state, and their coordinates are also recorded. However, the proposed system encountered a failure during its first testing phase. They want you to fix the problem in determining whether the given coordinates of sensors are safe or in the affected areas.
An affected area is defined as the polygon with the minimum length perimeter that can enclose all sensors that trigger warning signal within that area. For example, the sensors (represented by dots) of an affected area and its associated polygon, as well as safe (represented by triangles) and unsafe (represented by diamonds) points of the first dataset are illustrated below.
The input will contain records of data for several test cases of affected areas. The first line of each data set contains a non-negative integer $$$T$$$, the number of test cases $$$(1 ≤ T ≤ 50).$$$ Each test case starts with two non-negative integer $$$C$$$ and $$$P$$$ which is the number of coordinates $$$(3 ≤ C ≤ 50)$$$, and points $$$(1 ≤ P ≤ 50)$$$, respectively. The next $$$C$$$ lines contain coordinates (x-coordinate, y-coordinate) of each installed sensor, separated with blank spaces. The following $$$P$$$ lines contain coordinates (x-coordinate, y-coordinate) of certain locations in the state, separated with blank spaces. All coordinates are integers between $$$-500$$$ and $$$500$$$ inclusive.
For each test case, output the following item:
First line: The number of the test cases. The first record corresponds to $$$Case 1$$$, the second to $$$Case 2$$$ , etc.
Next line: A listing of all the points that appear on the perimeter of the affected area. The points must be identified in the standard form "x-coordinate y- coordinate". The listing must be oriented counter-clockwise and begin and end with the same point.
Last line: For each point of location in the data set, output the line:
$$$x-coordinate y-coordinate is status$$$
where $$$x-coordinate y-coordinate$$$ is the coordinate of the location from the input and $$$status$$$ is $$$'safe'$$$ or $$$'unsafe'$$$. A location is considered unsafe it is within the sensor perimeter. A point in exactly at the edge of the perimeter is considered safe.
Each test case must be separated by an empty line. See example.
2 6 5 -477 -180 31 -266 -474 28 147 49 323 -53 277 -79 346 488 -139 -183 -427 129 386 -222 -408 -315 5 2 -52 -325 104 420 315 356 -192 8 493 146 404 228 -239 484
Case 1 -477 -180 31 -266 323 -53 147 49 -474 28 -477 -180 346 488 is safe! -139 -183 is unsafe! -427 129 is safe! 386 -222 is safe! -408 -315 is safe! Case 2 -192 8 -52 -325 493 146 315 356 104 420 -192 8 404 228 is unsafe! -239 484 is safe!
Ethics regarding artificial intelligence (AI) is an important topic at current times. With recent advancement in the field of self-learning algorithms, the scientific community is facing a hard question of how to introduce ethics in software systems. The question of ethics is particularly difficult due to its subjective nature. What is considered 'right' by a particular viewpoint is not necessarily considered 'right' by every other viewpoint.
The question of ethics in AI agents becomes even more difficult when the agents are faced with ethical dilemmas. Ethical dilemmas are situations when there is no clear answer regarding the best solution to a problem because all possible solutions lead to certain negative impact. For example, if you press a button then 1 person will die and if you do not press the button then 5 persons will die. If these two are the options then which to follow. If the system believes in the philosophy of non-maleficence, doing the least amount of harm, then the system would take the course of pressing the button and let 1 person die instead of 5 people.
This example is a very simplified approach of portraying an ethical dilemma, but in real life, the AI agents would face much more complex and subtle scenarios requiring a proper ethical framework for them to follow.
In this problem, we are dealing with a RoboTaxi that can only go straight (a lucky one). You will be provided with a snapshot of a $$$3 lane$$$ road with multiple obstacles in it. You will have to determine whether the RoboTaxi will crash or not within the given snapshot.
The input consists of 3 lines.
A '$$$=$$$' indicates the position of the RoboTaxi.
'$$$H$$$' indicates human in the lane.
'$$$T$$$' indicates tree in the lane.
'$$$P$$$' indicates parked car in the lane.
'$$$.$$$' indicates empty space in the lane.
The length of the road will be 10.
Output will be the indicator of the first obstacle that the RoboTaxi crashes into. If no crash occurs then output '$$$You shall pass!!!$$$'.
.......... =......... ..........
You shall pass!!!
.......... =........H ..........
H
.......... =........T ..........
T
.........P =.......TH .........P
T
You are given 5 different sizes of kitchen plates. Each plate is marked with a letter $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$, or $$$E$$$. You are given 5 statements comparing two different plates, you need to rearrange the plates from smallest size to biggest size. For example: the sizes of these plates.
The input consist of 5 lines. In each line there will be 3 characters, the first and last character will be either $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$, or $$$E$$$ and the middle character will be either $$$ \gt $$$ or $$$ \lt $$$ describing the comparison between two plates sizes. No two plates will be equal.
The output consist of $$$5$$$ characters, the sorted order of balls from smallest to biggest plate. Otherwise, if the statements are contradicting print $$$impossible$$$. If there are multiple answers, print any of them.
D>B A>D E<C A>B B>C
ECBDA
B>E A>B E>A C<B D<B
impossible
Nina works as an IT support in a software company and always busy. The biggest issue she is facing is that sometimes she misses some deadlines. In their team the time needed to finish each customer request is estimated based on experience, $$$1 ≤ x ≤ 10^{5}$$$. The moment a request is submitted, she has double of the estimated time to respond to the request, $$$2x$$$. Meaning if the request $$$A$$$ was submitted at $$$12 pm$$$ and takes $$$2$$$ hours to finish, she can wait $$$2$$$ hours and then work on it for $$$2$$$ hours and still finish the job on time, by $$$4$$$ pm and the customer would be satisfied.
Sometimes there is not enough capacity and she has to pick up a lot of requests, and it is expected to miss some deadlines. But she needs your help, to see if arrange correctly what are the maximum requests she can finish before their deadlines.
Let's assume that she has the list of the requests and their deadline immediately as she starts working every day and she doesn't take any break until she is done with all of them.
The first line contains integer $$$m$$$ $$$(1 ≤ m ≤ 20)$$$. Number of cases.
The second line contains integer $$$n$$$ $$$(1 ≤ n ≤ 10^{5} )$$$. Number of the requests.
The last line contains $$$n$$$ integers $$$t_{i}$$$ $$$(1 ≤ t_{i} ≤ 10^{9} )$$$, separated by spaces. Estimated time each request should be responded so the customer would be happy.
Print the case number and a single number - the maximum number of satisfied customer for each case.
1 5 15 2 1 5 3
Case #1: 4
If she responds to the request with this order $$$1$$$, $$$2$$$, $$$3$$$, $$$5$$$, $$$15$$$, the only customer with the request that requires $$$5$$$ hours wouldn't be happy.