vgel/INTELLECT-2-RL-Dataset-Code-Only huggingface dataset:
Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first mission assigned to him was to implement a message encoding feature to ensure the chat is private and secure.
Chef has a message, which is a string $S$ with length $N$ containing only lowercase English letters. It should be encoded in two steps as follows: 
- Swap the first and second character of the string $S$, then swap the 3rd and 4th character, then the 5th and 6th character and so on. If the length of $S$ is odd, the last character should not be swapped with any other.
- Replace each occurrence of the letter 'a' in the message obtained after the first step by the letter 'z', each occurrence of 'b' by 'y', each occurrence of 'c' by 'x', etc, and each occurrence of 'z' in the message obtained after the first step by 'a'.
The string produced in the second step is the encoded message. Help Chef and find this message.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains the message string $S$.

-----Output-----
For each test case, print a single line containing one string — the encoded message.

-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 100$
- $|S| = N$
- $S$ contains only lowercase English letters

-----Example Input-----
2
9
sharechat
4
chef

-----Example Output-----
shizxvzsg
sxuv

-----Explanation-----
Example case 1: The original message is "sharechat". In the first step, we swap four pairs of letters (note that the last letter is not swapped), so it becomes "hsraceaht". In the second step, we replace the first letter ('h') by 's', the second letter ('s') by 'h', and so on, so the resulting encoded message is "shizxvzsg".

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Given a matrix M of n*n size, the task is to complete the function which prints its elements in a diagonal pattern as depicted below.
 
 
Example 1:
Input:
N = 3
mat[][] = {{1 2 3},{4 5 6},{7 8 9}}
Output: 1 2 4 7 5 3 6 8 9
Example 2:
Input:
N = 2
mat[][] = {{1 2},{3 4}}
Output: 1 2 3 4
Your Task:
You only need to implement the given function matrixDiagonally() which returns a list containing the matrix diagonally. Do not read input, instead use the arguments given in the function. Print the elements in Matrix in a diagonal pattern.
Expected Time Complexity: O(N*M)
Expected Auxiliary Space: O(1)
Constraints:
1<=N<=100

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Ahmed Gafer failed to pass the test, but he got the job because of his friendship with Said and Shahhoud. After working in the kitchen for a while, he blew it. The customers didn't like the food anymore and one day he even burned the kitchen. Now the master Chef is very upset.
Ahmed isn't useful anymore at being a co-Chef, so S&S decided to give him a last chance. They decided to give Ahmed a new job, and make him work as the cashier of the restaurant. Nevertheless, in order not to repeat their previous mistake, they decided to give him a little test to check if his counting skills are good enough for the job. The problem is as follows: 
Given a string A of lowercase English letters, Ahmad was asked to find the number of good substrings.
A substring A[L, R] is good if:

-  The length of the substring is exactly 2 and AL = AR, OR
- The length of the substring is greater than 2,AL = AR and the substring A[L + 1, R - 1] has only one distinct letter.

Anyways, Ahmed struggled trying to find a solution for the problem. Since his mathematical skills are very poor as it turned out, he decided to cheat and contacted you asking for your help. Can you help him in this challenge?

-----Input-----
The first line of the input contains the integer T, indicating the number of test cases.
Each of the following T lines, contains a string A.

-----Output-----
For each test case, output a single line containing a single number, indicating the number of good substrings.

-----Constraints-----

- 1 ≤ T ≤ 100 
- 1 ≤  |A|  ≤ 105 
-  It's guaranteed that the sum of  |A|  over all test cases doesn't exceed 5x105. 

-----Example-----
Input:
2
a
abba

Output:
0
2


-----Explanation-----
Example case 2. The good substrings of abba are: { bb } and { abba }.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
You will be given a square chess board with one queen and a number of obstacles placed on it.  Determine how many squares the queen can attack.  

A queen is standing on an $n\times n$ chessboard. The chess board's rows are numbered from $\mbox{I}$ to $n$, going from bottom to top.  Its columns are numbered from $\mbox{I}$ to $n$, going from left to right. Each square is referenced by a tuple, $(r,c)$, describing the row, $\textbf{r}$, and column, $\textbf{C}$, where the square is located.

The queen is standing at position $(r_q,c_q)$.  In a single move, she can attack any square in any of the eight directions (left, right, up, down, and the four diagonals). In the diagram below, the green circles denote all the cells the queen can attack from $(4,4)$: 

There are obstacles on the chessboard, each preventing the queen from attacking any square beyond it on that path. For example, an obstacle at location $(3,5)$ in the diagram above prevents the queen from attacking cells $(3,5)$, $(2,6)$, and $(1,7)$:

Given the queen's position and the locations of all the obstacles, find and print the number of squares the queen can attack from her position at $(r_q,c_q)$.  In the board above, there are $24$ such squares.

Function Description  

Complete the queensAttack function in the editor below.   

queensAttack has the following parameters: 

- int n: the number of rows and columns in the board 

- nt k: the number of obstacles on the board 

- int r_q: the row number of the queen's position 

- int c_q: the column number of the queen's position 

- int obstacles[k][2]: each element is an array of $2$ integers, the row and column of an obstacle  

Returns 

- int: the number of squares the queen can attack   

Input Format

The first line contains two space-separated integers $n$ and $\boldsymbol{\mbox{k}}$, the length of the board's sides and the number of obstacles. 

The next line contains two space-separated integers $r_q$ and $c_{q}$, the queen's row and column position. 

Each of the next $\boldsymbol{\mbox{k}}$ lines contains two space-separated integers $r[i]$ and $c[i]$, the row and column position of $obstacle[i]$.       

Constraints

$0<n\leq10^5$
$0\leq k\leq10^5$
A single cell may contain more than one obstacle.
There will never be an obstacle at the position where the queen is located.

Subtasks

For $30\%$ of the maximum score: 

$0<n\leq100$
$0\leq k\leq100$

For $55\%$ of the maximum score: 

$0<n\leq1000$
$0\leq k\leq10^5$

Sample Input 0
4 0
4 4

Sample Output 0
9

Explanation 0

The queen is standing at position $(4,4)$ on a $4\times4$ chessboard with no obstacles:

Sample Input 1
5 3
4 3
5 5
4 2
2 3

Sample Output 1
10

Explanation 1

The queen is standing at position $(4,3)$ on a $5\times5$ chessboard with $k=3$ obstacles:

The number of squares she can attack from that position is $10$.

Sample Input 2
1 0
1 1

Sample Output 2
0

Explanation 2

Since there is only one square, and the queen is on it, the queen can move 0 squares.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Title: Maximum Number

Time Limit: None seconds

Memory Limit: None megabytes

Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.

So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. 

The battery of the newest device allows to highlight at most *n* sections on the display. 

Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.

Input Specification:
The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display.

Output Specification:
Print the maximum integer which can be shown on the display of Stepan's newest device.

Demo Input:
['2\n', '3\n']

Demo Output:
['1\n', '7\n']

Note:
none

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
## Grade book

Complete the function so that it finds the mean of the three scores passed to it and returns the letter value associated with that grade.

Numerical Score    | Letter Grade
---                | ---
90 <= score <= 100 | 'A'
80 <= score < 90   | 'B'
70 <= score < 80   | 'C'
60 <= score < 70   | 'D'
 0 <= score < 60   | 'F'

Tested values are all between 0 and 100. Theres is no need to check for negative values or values greater than 100.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
One day Chef was playing with numbers. He loves Lowest Common Multiple (LCM) too much and he is a very curious guy. He always try to do new things. Now he want to make a large number with it. But he doesn't want to take too many numbers.

He is willing to take only three numbers less than or equal to N (not necessarily distinct ) and from those three number he want get the maximum number by taking LCM of the numbers.

As he is busy in playing some more tricks of maths, he assign this task to you.

-----Input-----
First line of input contains an integer t ( t<=1000 ), Number of test cases.

t line follows an integer N

-----Output-----
Print t lines contains a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than N.

-----Constraints-----
1<= N <= 10^6

-----Example-----
Input:
2
9
7

Output:
504
210


-----Explanation-----
Example case 2. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7•6•5 = 210. It is the maximum value we can get.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.

Heidi recently got her hands on a multiverse observation tool. She was able to see all $n$ universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the $k$-th universe.

The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed $m$.

Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.

More specifically,   When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.   When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. 

Heidi wants to perform a simulation of $t$ decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.


-----Input-----

The first line contains four integers $n$, $k$, $m$ and $t$ ($2 \le k \le n \le m \le 250$, $1 \le t \le 1000$).

Each of the following $t$ lines is in one of the following formats:   "$1$ $i$" — meaning that a universe is inserted at the position $i$ ($1 \le i \le l + 1$), where $l$ denotes the current length of the multiverse.  "$0$ $i$" — meaning that the $i$-th link is broken ($1 \le i \le l - 1$), where $l$ denotes the current length of the multiverse. 


-----Output-----

Output $t$ lines. Each line should contain $l$, the current length of the multiverse and $k$, the current position of the Doctor.

It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most $m$ and when the link breaking is performed, there will be at least one universe in the multiverse.


-----Example-----
Input
5 2 10 4
0 1
1 1
0 4
1 2

Output
4 1
5 2
4 2
5 3



-----Note-----

The multiverse initially consisted of 5 universes, with the Doctor being in the second.

First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.

Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.

Then, the rightmost link was broken.

Finally, a universe was added between the first and the second universe.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
The Tricksters are back again with a new challenge for the Flash!!
This time they have placed bombs throughout Central city and the Flash has to disarm the bombs. There can be maximum n bombs. For disarming each bomb i, flash takes t[i] time. Also disarming bombs require energy denoted by e[i]. Each bomb has an associated value of destruction d[i]. Given that flash can spend atmost E energy and the bombs explode in T time, what is the minimum amount of destruction that the city has to suffer when the bombs explode(if the flash can disarm all bombs in T time using E energy, print 0).

Assume Flash can move from the location of one bomb to another instantaneously(He's the Flash, of course he can!!).

Input:

First line will contain 3 integers, n(1 ≤ n ≤ 100), E(1<E=100) and T(1<T=100).
The next line will contain n integers denoting e ≤ e[i] ≤ 100">i.
The next line will contain n integers denoting t ≤ t[i] ≤ 100">i.
The next line will contain n integers denoting d ≤ d[i] ≤ 10000">i.

Output:

Print the minimum destruction that the city has to suffer.

Sample Input #1:

4 5 4

4 2 3 1 

2 4 3 1 

10 2 3 8

Sample Output #1:

5

Sample Input #2:

3 10 10

4 5 1 

1 1 8 

7 3 10 

Sample Output #2:

0

SAMPLE INPUT
4 5 4
4 2 3 1 
2 4 3 1 
10 2 3 8

SAMPLE OUTPUT
5

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Imagine an n × m grid with some blocked cells. The top left cell in the grid has coordinates (1, 1) and the bottom right cell has coordinates (n, m). There are k blocked cells in the grid and others are empty. You flash a laser beam from the center of an empty cell (xs, ys) in one of the diagonal directions (i.e. north-east, north-west, south-east or south-west). If the beam hits a blocked cell or the border of the grid it will reflect. The behavior of the beam reflection in different situations is depicted in the figure below. 

<image>

After a while the beam enters an infinite cycle. Count the number of empty cells that the beam goes through at least once. We consider that the beam goes through cell if it goes through its center.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ 105). Each of the next k lines contains two integers xi and yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) indicating the position of the i-th blocked cell. 

The last line contains xs, ys (1 ≤ xs ≤ n, 1 ≤ ys ≤ m) and the flash direction which is equal to "NE", "NW", "SE" or "SW". These strings denote directions ( - 1, 1), ( - 1, - 1), (1, 1), (1, - 1).

It's guaranteed that no two blocked cells have the same coordinates.

Output

In the only line of the output print the number of empty cells that the beam goes through at least once.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 3 0
1 2 SW


Output

6


Input

7 5 3
3 3
4 3
5 3
2 1 SE


Output

14

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
This time no story, no theory. The examples below show you how to write function `accum`:

**Examples:**
```
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"
```

The parameter of accum is a string which includes only letters from `a..z` and `A..Z`.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Mance Rayder, the King-Beyond-the-Wall, has always wanted to lead the largest army the North has ever seen against the NIght’s Watch. For this humungous feat he has banded the waring tribes, the Giants, Thenns and Wildings, together by going to great extents. But the King is facing with an issue he always saw it coming.
The huge army is divided into smaller divisions and each division can be of the type $G, T$ or $W$ standing for Giants, Thenns and Wildings respectively. Mance doesn’t want two divisions of the same type standing together as he fears it might lead to a mutiny or an unorganised charge or retreat. 
For a given numbers of $G, T$ and $W$, find whether an army can be organised in accordance to the rules set by Mance. Not to forget that Mance has to include all the divisions in his battle formation in order to stand a chance against the Wall’s defences.

-----Input:-----
- First line will contain $N$, the number of test cases.
- Each of the next $N$ lines will contain three integers $G$, $T$ and $W$ - the number of Giant, Thenn and Wildling divisions respectively.

-----Output:-----
For each testcase, output in a single line $Yes$ if a battle formation is possible or $No$ otherwise.

-----Constraints-----
- $1 \leq N \leq 100$
- $1 \leq G,T,W \leq 10^9$

-----Sample Input:-----
1
1 2 1

-----Sample Output:-----
Yes

-----Explanation:-----
The first case can be formed as : $ TGWT $. Hence the answer is $ Yes $.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Title: E-mail Addresses

Time Limit: None seconds

Memory Limit: None megabytes

Problem Description:
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.

Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.

We assume that valid addresses are only the e-mail addresses which meet the following criteria:
 -  the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter; -  then must go character '@'; -  then must go a non-empty sequence of letters or numbers; -  then must go character '.'; -  the address must end with a non-empty sequence of letters. 
You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers *l*1,<=*l*1<=+<=1,<=*l*1<=+<=2,<=...,<=*r*1 and the other one consisting of the characters of the string with numbers *l*2,<=*l*2<=+<=1,<=*l*2<=+<=2,<=...,<=*r*2, are considered distinct if *l*1<=≠<=*l*2 or *r*1<=≠<=*r*2.

Input Specification:
The first and the only line contains the sequence of characters *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106) — the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.

Output Specification:
Print in a single line the number of substrings that are valid e-mail addresses.

Demo Input:
['[email\xa0protected]\n', '[email\xa0protected]@[email\xa0protected]\n', '[email\xa0protected]\n', '.asd123__..@\n']

Demo Output:
['18\n', '8\n', '1\n', '0\n']

Note:
In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.

In the second test case note that the e-mail [[email protected]](/cdn-cgi/l/email-protection) is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
In the ACM kingdom, there are $N$ cities connected by $M$ two-way roads. These cities are connected, i.e., one can reach from any city $X$ to any other city $Y$ by going through some of these roads. One day, the government wishes to assign for each road a direction, such that one can still reach from any city to any other. You are asked to determine whether this task is possible.

-----Input-----
The first line of each test case consists of two integers, $N$ ($1 \leq N \leq 50$), and $M$ ($1 \leq M \leq N(N - 1)/2$). Each of the next $M$ lines describes a road, and consists of two integers, $X$ and $Y$, ($1 \leq X, Y \leq N$; $X \neq Y$), indicating that there is a road between city $X$ and $Y$. There is at most one road that directly connects each pair of cities.

-----Output-----
If it is impossible, output a single line NO. Otherwise, output YES on the first line, followed by $M$ lines describing one possible direction assignment to these $M$ roads. Each of these $M$ lines should consist of two integers, $X$, $Y$, indicating that there is a one-way road from city $X$ to city $Y$. These $M$ lines can be output in any order.

-----Examples-----
Sample Input 1:
3 3
1 2
2 3
1 3
Sample Output 1:
YES
1 3
2 1
3 2

Sample Input 2:
4 3
1 2
1 3
1 4
Sample Output 2:
NO

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.