0% found this document useful (0 votes)
262 views

Coding Ques

The document describes a game where a matrix starts with elements equal to their column number, certain elements are increased by commands, and the goal is to calculate the cost of moving from the last to first element in each row. It provides the input and output formats which give the number of rows, columns, and commands, and the answers for each row's cost after the commands.

Uploaded by

Ansh Jindal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
262 views

Coding Ques

The document describes a game where a matrix starts with elements equal to their column number, certain elements are increased by commands, and the goal is to calculate the cost of moving from the last to first element in each row. It provides the input and output formats which give the number of rows, columns, and commands, and the answers for each row's cost after the commands.

Uploaded by

Ansh Jindal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1) This morning Chef wants to jump a little. In a few minutes he will arrive at the point 0.

Then he will perform a


lot of jumps in such a sequence: 1-jump, 2-jump, 3-jump, 1-jump, 2-jump, 3-jump, 1-jump, and so on.
1-jump means that if Chef is at the point x, he will jump to the point x+1.
2-jump means that if Chef is at the point x, he will jump to the point x+2.
3-jump means that if Chef is at the point x, he will jump to the point x+3.
Before the start Chef asks you: will he arrive at the point a after some number of jumps?
Input
The first line contains a single integer a denoting the point Chef asks about.
Output
Output "yes" without a quotes if Chef can arrive at point a or "no" without a quotes otherwise.
Constraints

0 a 10
18


Example
Input:
0

Output:
yes

Input:
1

Output:
yes

Input:
2

Output:
no

Input:
3

Output:
yes

Input:
6

Output:
yes

Input:
7

Output:
yes

Input:
10

Output:
no

Lira is now very keen on compiler development. :)
She knows that one of the most important components of a compiler, is its parser.
A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if
you prefer, if the text is properly built.
As an example, in declaring and initializing an integer, in C/C++, you can't do something like:
int = x ;4
as the semantics of such statement is incorrect, as we all know that the datatype must precede an identifier and only
afterwards should come the equal sign and the initialization value, so, the corrected statement should be:
int x = 4;
Today, Lira is concerned with an abstract instruction which is composed of the characters "<" and ">" , which she will
use on the design of her language, L++ :D.
She is using it as an abstraction for generating XML code Tags in an easier fashion and she understood that, for an
expression to be valid, a "<" symbol must always have a corresponding ">" character somewhere (not necessary
immediately) after it. Moreover, each ">" symbol should correspond to exactly one "<" symbol.
So, for instance, the instructions:
<<>>
<>
<><>
are all valid. While:
>>
><><
are not.
Given some expressions which represent some instructions to be analyzed by Lira's compiler, you should tell the
length of the longest prefix of each of these expressions that is valid, or 0 if there's no such a prefix.
Input
Input will consist of an integer T denoting the number of test cases to follow.
Then, T strings follow, each on a single line, representing a possible expression in L++.
Output
For each expression you should output the length of the longest prefix that is valid or 0 if there's no such a prefix.
Constraints
1 T 500
1 The length of a single expression 10
6

The total size all the input expressions is no more than 5*10
6


Example
Input:
3
<<>>
><
<>>>
Output:
4
0
2

Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem:
given array of N integers A and a number K. During a turn the maximal value over allAi is chosen, let's call it MAX.
Then Ai =
MAX - Ai is done for every 1 <= i <= N. Help Roman to find out how will the array look like after K turns.
Input
The numbers N and K are given in the first line of an input. Then N integers are given in the second line which
denote the array A.
Output
Output N numbers on a single line. It should be the array A after K turns.
Constraints

1 <= N <= 10
5

0 <= K <= 10
9

Ai does not exceed 2 * 10
9
by it's absolute value.

Example
Input:
4 1
5 -1 7 0

Output:
2 8 0 7

Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting
game - "Strange Matrix".
Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix equals j. (1 i
n, 1 j m).
Then p times some element aij is increased by 1.
Then Chef needs to calculate the following:
For each row he tries to move from the last element (with number m) to the first one (with the number 1).
While staying in aij Chef can only move to aij - 1 only if aij - 1 aij.
The cost of such a movement is aij - aij - 1.
Otherwise Chef can't move and lose (in this row).
If Chef can move from the last element of the row to the first one, then the answer is the total cost of all the
movements.
If Chef can't move from the last element of the row to the first one, then the answer is -1.
Help Chef to find answers for all the rows after P commands of increasing.
Input

The first line contains three integers n, m and p denoting the number of rows, the number of elements a single row
and the number of increasing commands.
Each of next p lines contains two integers i and j denoting that the element aij is increased by one.

Output
For each row in a single line print the answer after the P increasing commands.

Constraints
1 n, m, p 10 ^ 5
1 i n
1 j m

Example
Input:
4 4 6
2 2
3 2
3 2
4 3
4 4
4 3

Output:
3
3
-1
4


Explanation
Here is the whole matrix after P commands:

1 2 3 4
1 3 3 4
1 4 3 4
1 2 5 5
Explanations to the answer:


The first line is without changes: 4-3=1, 3-2=1, 2-1=1. answer = 3.

The second line: 4-3=1, 3-3=0, 3-1=2. The answer is 3.

The third line: 4-3=1, 3-4=-1, Chef can't move to the first number here. Therefore, the answer is -1.

The fourth line: 5-5=0, 5-2=3, 2-1=1. The answer is 4.

You might also like