Muennighoff/xP3x-sample huggingface dataset:
inputs: Solve in Python:
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.

Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.


-----Input-----

The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.


-----Output-----

On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.

If the answer consists of zero characters, output «-» (a minus sign).


-----Examples-----
Input
hi
bob

Output
-

Input
abca
accepted

Output
ac

Input
abacaba
abcdcba

Output
abcba



-----Note-----

In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.

In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
targets: #import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
#n,m = map(int, input().split())

s1 = input()
s2 = input()
l1 = len(s1)
l2 = len(s2)

dl = {}
dr = {}

i1 = 0
i2 = 0

while i1 < l1 and i2 < l2:
    while i1 < l1 and s1[i1] != s2[i2]:
        i1 += 1
    if i1 < l1:
        dl[i2] = i1
        i2 += 1
        i1 += 1

lmax = i2
if lmax == l2:
    print(s2)
else:
    i1 = l1 - 1
    i2 = l2 - 1
    while i1 >= 0 and i2 >= 0:
        while i1 >= 0 and s1[i1] != s2[i2]:
            i1 -= 1
        if i1 >= 0:
            dr[i2] = i1
            i2 -= 1
            i1 -= 1
    rmax = i2

    le = -1
    re = -1
    if l2 - lmax < rmax + 1:
        rcnt = l2 - lmax
        ls = 0
        rs = lmax
    else:
        rcnt = rmax + 1
        ls = rmax + 1
        rs = l2
    rr = rmax + 1
    for ll in range(lmax):
        while rr < l2 and (rr <= ll or dl[ll] >= dr[rr]):
            rr += 1
        if rr < l2:
            dif = rr - ll - 1
            if dif < rcnt:
                rcnt = dif
                ls = 0
                rs = ll + 1
                le = rr
                re = l2

    result = s2[ls:rs]
    if le != -1:
        result += s2[le:re]
    print(result if len(result) > 0 else '-')
inputs: I found an interesting problem on https://www.codewars.com/kata/54b72c16cd7f5154e9000457:
Part of Series 2/3


This kata is part of a series on the Morse code. Make sure you solve the [previous part](/kata/decode-the-morse-code) before you try this one. After you solve this kata, you may move to the [next one](/kata/decode-the-morse-code-for-real).


In this kata you have to write a Morse code decoder for wired electrical telegraph.

Electric telegraph is operated on a 2-wire line with a key that, when pressed, connects the wires together, which can be detected on a remote station. The Morse code encodes every character being transmitted as a sequence of "dots" (short presses on the key) and "dashes" (long presses on the key).

When transmitting the Morse code, the international standard specifies that:
"Dot" – is 1 time unit long.
"Dash" – is 3 time units long.
Pause between dots and dashes in a character – is 1 time unit long.
Pause between characters inside a word – is 3 time units long.
Pause between words – is 7 time units long.

However, the standard does not specify how long that "time unit" is. And in fact different operators would transmit at different speed. An amateur person may need a few seconds to transmit a single character, a skilled professional can transmit 60 words per minute, and robotic transmitters may go way faster.

For this kata we assume the message receiving is performed automatically by the hardware that checks the line periodically, and if the line is connected (the key at the remote station is down), 1 is recorded, and if the line is not connected (remote key is up), 0 is recorded. After the message is fully received, it gets to you for decoding as a string containing only symbols 0 and 1.

For example, the message HEY JUDE, that is ···· · −·−−   ·−−− ··− −·· · may be received as follows:

1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011

As you may see, this transmission is perfectly accurate according to the standard, and the hardware sampled the line exactly two times per...

I tried it in Python, but could not do it. Can you solve it?
targets: from re import split
def decodeBits(bits):
    unit = min([len(s) for s in split(r'0+',bits.strip('0'))] + [len(s) for s in split(r'1+',bits.strip('0'))  if s != ''])
    return bits.replace('0'*unit*7,'   ').replace('0'*unit*3,' ').replace('1'*unit*3,'-').replace('1'*unit,'.').replace('0','')
def decodeMorse(morseCode):
    # ToDo: Accept dots, dashes and spaces, return human-readable message
    return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split('   '))
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/1249/B1:
The only difference between easy and hard versions is constraints.

There are $n$ kids, each of them is reading a unique book. At the end of any day, the $i$-th kid will give his book to the $p_i$-th kid (in case of $i = p_i$ the kid will give his book to himself). It is guaranteed that all values of $p_i$ are distinct integers from $1$ to $n$ (i.e. $p$ is a permutation). The sequence $p$ doesn't change from day to day, it is fixed.

For example, if $n=6$ and $p=[4, 6, 1, 3, 5, 2]$ then at the end of the first day the book of the $1$-st kid will belong to the $4$-th kid, the $2$-nd kid will belong to the $6$-th kid and so on. At the end of the second day the book of the $1$-st kid will belong to the $3$-th kid, the $2$-nd kid will belong to the $2$-th kid and so on.

Your task is to determine the number of the day the book of the $i$-th child is returned back to him for the first time for every $i$ from $1$ to $n$.

Consider the following example: $p = [5, 1, 2, 4, 3]$. The book of the $1$-st kid will be passed to the following kids:  after the $1$-st day it will belong to the $5$-th kid,  after the $2$-nd day it will belong to the $3$-rd kid,  after the $3$-rd day it will belong to the $2$-nd kid,  after the $4$-th day it will belong to the $1$-st kid. 

So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 200$) — the number of queries. Then $q$ queries follow.

The first line of the query contains one integer $n$ ($1 \le n \le 200$) — the number of kids in the query. The second line of the query contains $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$, all $p_i$ are distinct, i.e. $p$ is a permutation), where $p_i$ is the kid which will get the book of the $i$-th kid.


-----Output-----

For each query, print the answer on it: $n$ integers $a_1, a_2, \dots,...

I tried it in Python, but could not do it. Can you solve it?
targets: tc = int(input())

while tc > 0:
	tc -= 1
	n = int(input())
	p = [0] + list(map(int, input().split()))

	ans = [0] * (n + 1)
	mk = [False] * (n + 1)

	for i in range(1 , n + 1):
		if not mk[i]:
			sz = 1
			curr = p[i]
			mk[i] = True
			while curr != i:
				sz += 1
				mk[curr] = True
				curr = p[curr]

			ans[i] = sz
			curr = p[i]
			while curr != i:
				ans[curr] = sz
				curr = p[curr]

	print(" ".join([str(x) for x in ans[1:]]))
inputs: Solve in Python:
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.

The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.

There are $n$ winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office. 

Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.

What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?

The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.


-----Input-----

The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts.

The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year.

The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year.

It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list $b$ from the list $a$.


-----Output-----

Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.


-----Examples-----
Input
3
XS
XS
M
XL
S
XS

Output
2

Input
2
XXXL
XXL
XXL
XXXS

Output
1

Input
2
M
XS
XS
M

Output
0



-----Note-----

In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of...
targets: n  = int(input())
a = []
b = []
for i in range(n):
  a.append(input())
for i in range(n):
  k = input()
  if k in a:
    a.remove(k)  
  else:
    b.append(k)
c = [0,0,0,0]
for i in range(len(a)):
  c[len(a[i])-1] += 1
print(sum(c))
inputs: I found an interesting problem on https://atcoder.jp/contests/abc109/tasks/abc109_c:
There are N cities on a number line. The i-th city is located at coordinate x_i.
Your objective is to visit all these cities at least once.
In order to do so, you will first set a positive integer D.
Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:
 - Move 1: travel from coordinate y to coordinate y + D.
 - Move 2: travel from coordinate y to coordinate y - D.
Find the maximum value of D that enables you to visit all the cities.
Here, to visit a city is to travel to the coordinate where that city is located.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 1 \leq X \leq 10^9
 - 1 \leq x_i \leq 10^9
 - x_i are all different.
 - x_1, x_2, ..., x_N \neq X

-----Input-----
Input is given from Standard Input in the following format:
N X
x_1 x_2 ... x_N

-----Output-----
Print the maximum value of D that enables you to visit all the cities.

-----Sample Input-----
3 3
1 7 11

-----Sample Output-----
2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.
 - Perform Move 2 to travel to coordinate 1.
 - Perform Move 1 to travel to coordinate 3.
 - Perform Move 1 to travel to coordinate 5.
 - Perform Move 1 to travel to coordinate 7.
 - Perform Move 1 to travel to coordinate 9.
 - Perform Move 1 to travel to coordinate 11.

I tried it in Python, but could not do it. Can you solve it?
targets: n,x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for i in range(n):
  a[i] = abs(a[i] - x)

def gcd(x,y):
  while y != 0:
    x, y = y, x % y
  return x

res = a[0]
for i in range(n):
  res = gcd(res,a[i])
print(res)
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/611/C:
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.

Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through h from top to bottom. Columns are numbered 1 through w from left to right.

Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid.

Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle?


-----Input-----

The first line of the input contains two integers h and w (1 ≤ h, w ≤ 500) – the number of rows and the number of columns, respectively.

The next h lines describe a grid. Each line contains a string of the length w. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively.

The next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Each of the next q lines contains four integers r1_{i}, c1_{i}, r2_{i}, c2_{i} (1 ≤ r1_{i} ≤ r2_{i} ≤ h, 1 ≤ c1_{i} ≤ c2_{i} ≤ w) — the i-th query. Numbers r1_{i} and c1_{i} denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers r2_{i} and c2_{i} denote the row and the column (respectively) of the bottom right cell of the rectangle.


-----Output-----

Print q integers, i-th should be equal to the number of ways to put a single domino inside the i-th rectangle.


-----Examples-----
Input
5 8
....#..#
.#......
##.#....
##..#.##
........
4
1 1 2 3
4 1 4 1
1 2 4 5
2 5 5 8

Output
4
0
10
15

Input
7...

I tried it in Python, but could not do it. Can you solve it?
targets: h, w = list(map(int, input().split()))
field = [[c == "." for c in input()] + [False] for i in range(h)]
field.append([False] * (w + 1))

subVerts = [[0] * (w + 1) for i in range(h + 1)]
subHoriz = [[0] * (w + 1) for i in range(h + 1)]

for y in range(h):
    subVerts[y][0] = 0
    subHoriz[y][0] = 0

for x in range(w):
    subHoriz[0][x] = 0
    subVerts[0][x] = 0

for y in range(h):
    for x in range(w):
        subVerts[y + 1][x + 1] = subVerts[y + 1][x] + subVerts[y][x + 1] - subVerts[y][x]
        if field[y][x] and field[y - 1][x]:
            subVerts[y + 1][x + 1] += 1
        
        subHoriz[y + 1][x + 1] = subHoriz[y + 1][x] + subHoriz[y][x + 1] - subHoriz[y][x]
        if field[y][x] and field[y][x - 1]:
            subHoriz[y + 1][x + 1] += 1



q = int(input())
for i in range(q):
    y1, x1, y2, x2 = [int(x) - 1 for x in input().split()]
    ansHoriz = subHoriz[y2 + 1][x2 + 1] - subHoriz[y1][x2 + 1] - subHoriz[y2 + 1][x1 + 1] + subHoriz[y1][x1 + 1]
    ansVerts = subVerts[y2 + 1][x2 + 1] - subVerts[y1 + 1][x2 + 1] - subVerts[y2 + 1][x1] + subVerts[y1 + 1][x1]
    print(ansHoriz + ansVerts)
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/285/E:
Permutation p is an ordered set of integers p_1,  p_2,  ...,  p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1,  p_2,  ...,  p_{n}.

We'll call position i (1 ≤ i ≤ n) in permutation p_1, p_2, ..., p_{n} good, if |p[i] - i| = 1. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (10^9 + 7).


-----Input-----

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ n).


-----Output-----

Print the number of permutations of length n with exactly k good positions modulo 1000000007 (10^9 + 7).


-----Examples-----
Input
1 0

Output
1

Input
2 1

Output
0

Input
3 2

Output
4

Input
4 1

Output
6

Input
7 4

Output
328



-----Note-----

The only permutation of size 1 has 0 good positions.

Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.

Permutations of size 3:



 (1, 2, 3) — 0 positions

 $(1,3,2)$ — 2 positions

 $(2,1,3)$ — 2 positions

 $(2,3,1)$ — 2 positions

 $(3,1,2)$ — 2 positions

 (3, 2, 1) — 0 positions

I tried it in Python, but could not do it. Can you solve it?
targets: mod=10**9+7
n,k=list(map(int,input().split()))

A=[0]*(n+1)
B=[0]*(n+1)
C=[0]*(n+1)
F=[0]*(n+1)
G=[0]*(n+1)

F[0]=G[0]=1
for i in range(1,n+1):
	G[i]=F[i]=F[i-1]*i%mod
	G[i]=pow(F[i],(mod-2),mod)

for i in range(0,n):
	if i*2>n:
		break
	B[i]=(F[n-i]*G[i]*G[n-i*2])%mod
for i in range(0,n//2+1):
	for j in range(0,n//2+1):
		A[i+j]=(A[i+j]+B[i]*B[j])%mod
for i in range(0,n+1):
	A[i]=A[i]*F[n-i]%mod
for i in range(0,n+1):
	for j in range(0,i+1):
		C[j]=(C[j]+A[i]*F[i]*G[j]*G[i-j]*(1-(i-j)%2*2))%mod
print(C[k]%mod)
inputs: I found an interesting problem on https://www.codechef.com/SPRT2020/problems/STCKSCAM:
$Harshad$ $Mehta$ is planning  a new scam with the stocks he is given a stock of  integer price S and a number K . $harshad$ has got the power to change the number $S$ at most $K$ times
In order to raise the price of stock and now cash it for his benefits
Find the largest price at which $harshad$ can sell the stock in order to maximize his profit 

-----Input:-----
- First line will contain $S$ and  $K$ , the price of the stock and the number K 

-----Output:-----
Print the largest profit  he can make in a single line.

-----Constraints-----
- S can take value upto 10^18
NOTE: use 64 int number to fit range
- K can take value from [0.. 9]

-----Sample Input:-----
4483 2

-----Sample Output:-----
9983

-----EXPLANATION:-----
First two digits of the number are changed to get the required number.

I tried it in Python, but could not do it. Can you solve it?
targets: # cook your dish here
n,k = map(int, input().split())
n = str(n)
for i in range(len(n)):
    if(k == 0):
        break
    if(n[i]!='9'):
        n = n[:i]+'9'+n[i+1:]
        k-=1
    
print(n)
inputs: I found an interesting problem on https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/:
You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once).
Return the sum of lengths of all good strings in words.
 
Example 1:
Input: words = ["cat","bt","hat","tree"], chars = "atach"
Output: 6
Explanation: 
The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.

Example 2:
Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
Output: 10
Explanation: 
The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.

 
Note:

1 <= words.length <= 1000
1 <= words[i].length, chars.length <= 100
All strings contain lowercase English letters only.

I tried it in Python, but could not do it. Can you solve it?
targets: class Solution:
    def countCharacters(self, words: List[str], chars: str) -> int:
        charChars = Counter(chars)
        counter = 0
        for word in words:
            countC = Counter(word)
            count = 0
            for letter in countC.items():
                if letter[0] in charChars and charChars[letter[0]] >= letter[1]:
                    count += 1
                    
            if count == len(countC):
                counter += len(word)
        return counter
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/1372/B:
In Omkar's last class of math, he learned about the least common multiple, or $LCM$. $LCM(a, b)$ is the smallest positive integer $x$ which is divisible by both $a$ and $b$.

Omkar, having a laudably curious mind, immediately thought of a problem involving the $LCM$ operation: given an integer $n$, find positive integers $a$ and $b$ such that $a + b = n$ and $LCM(a, b)$ is the minimum value possible.

Can you help Omkar solve his ludicrously challenging math problem?


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 10$). Description of the test cases follows.

Each test case consists of a single integer $n$ ($2 \leq n \leq 10^{9}$).


-----Output-----

For each test case, output two positive integers $a$ and $b$, such that $a + b = n$ and $LCM(a, b)$ is the minimum possible.


-----Example-----
Input
3
4
6
9

Output
2 2
3 3
3 6



-----Note-----

For the first test case, the numbers we can choose are $1, 3$ or $2, 2$. $LCM(1, 3) = 3$ and $LCM(2, 2) = 2$, so we output $2 \ 2$.

For the second test case, the numbers we can choose are $1, 5$, $2, 4$, or $3, 3$. $LCM(1, 5) = 5$, $LCM(2, 4) = 4$, and $LCM(3, 3) = 3$, so we output $3 \ 3$.

For the third test case, $LCM(3, 6) = 6$. It can be shown that there are no other pairs of numbers which sum to $9$ that have a lower $LCM$.

I tried it in Python, but could not do it. Can you solve it?
targets: import math
from collections import deque
from sys import stdin, stdout

input = stdin.readline
#print = stdout.write

for _ in range(int(input())):
    x = int(input())
    ind = 2
    mn = 99999999999999
    while ind * ind <= x:
        if x % ind == 0:
            mn = min(mn, ind)
            mn = min(mn, x // ind)
        ind += 1
    if mn == 99999999999999:
        mn = x
    print(x // mn, x - x // mn)
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/767/A:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. [Image] 

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n. 


-----Output-----

Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.


-----Examples-----
Input
3
3 1 2

Output
3
 
2 1
Input
5
4 5 1 2 3

Output
 
5 4
 
 
3 2 1



-----Note-----

In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.

I tried it in Python, but could not do it. Can you solve it?
targets: n = int(input())
maxsn = n-1
a = list(map(int, input().split()))
snacks = [0] * 100001
for i in range(n):
    snacks[a[i]-1] = 1
    while snacks[maxsn] == 1:
        snacks[maxsn] = 0
        print(maxsn + 1, end=' ')
        maxsn -= 1
    print()
inputs: Solve in Python:
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a_1, a_2, ..., a_{n}. The number a_{k} represents that the kth destination is at distance a_{k} kilometers from the starting point. No two destinations are located in the same place. 

Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination. 

The distance between destination located at kilometer x and next destination, located at kilometer y, is |x - y| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all n destinations and he doesn't visit a destination more than once. 

Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.


-----Input-----

The first line contains integer n (2 ≤ n ≤ 10^5). Next line contains n distinct integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^7).


-----Output-----

Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.


-----Examples-----
Input
3
2 3 5

Output
22 3


-----Note-----

Consider 6 possible routes:  [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5;  [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7;  [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7;  [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8;  [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9;  [5, 3,...
targets: import math
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
k = 0
s1 = 0
s2 = 0
for i in a:
	s2 += s1 - k * i
	s1 += i
	k += 1
s2 *= 2
s2 += sum(a)
gcd = math.gcd(s2, n)
print(s2 // gcd, n // gcd)
inputs: Solve in Python:
An acrostic is a text in which the first letter of each line spells out a word. It is also a quick and cheap way of writing a poem for somebody, as exemplified below :



Write a program that reads an acrostic to identify the "hidden" word. Specifically, your program will receive a list of words (reprensenting an acrostic) and will need to return a string corresponding to the word that is spelled out by taking the first letter of each word in the acrostic.
targets: def read_out(acrostic):
    return "".join( word[0] for word in acrostic )
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/1342/E:
Calculate the number of ways to place $n$ rooks on $n \times n$ chessboard so that both following conditions are met:

  each empty cell is under attack;  exactly $k$ pairs of rooks attack each other. 

An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture:

 [Image] One of the ways to place the rooks for $n = 3$ and $k = 2$ 

Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.

The answer might be large, so print it modulo $998244353$.


-----Input-----

The only line of the input contains two integers $n$ and $k$ ($1 \le n \le 200000$; $0 \le k \le \frac{n(n - 1)}{2}$).


-----Output-----

Print one integer — the number of ways to place the rooks, taken modulo $998244353$.


-----Examples-----
Input
3 2

Output
6

Input
3 3

Output
0

Input
4 0

Output
24

Input
1337 42

Output
807905441

I tried it in Python, but could not do it. Can you solve it?
targets: def modpow(b, e, mod):
    ret = 1
    pw = b
    while e > 0:
        if e % 2 == 1: ret = (ret * pw) % mod
        e = e >> 1
        pw = (pw * pw) % mod
    return ret

n, k = list(map(int, input().split()))
mod = 998244353
inv = [0 for _ in range(n + 1)]
fac = [0 for _ in range(n + 1)]
fac[0] = inv[0] = 1

for i in range(n):
    fac[i + 1] = (fac[i] * (i + 1)) % mod
    inv[i + 1] = modpow(fac[i + 1], mod - 2, mod)

def nCr(n, r):
    num = fac[n]
    den = (inv[r] * inv[n - r]) % mod
    return (num * den) % mod


row = n - k
if row < 0 or row > n: 
    print('0')
else:
    ans = 0
    for i in range(row):
        add = (nCr(row, i) * modpow(row - i, n, mod)) % mod
        if i % 2 == 0: ans = ans + add
        else: ans = ans - add

    ans = mod + (ans % mod)
    mult = 2
    if row == n: mult = 1
    print((mult * nCr(n, row) * ans) % mod)
inputs: Solve in Python:
You are given a chess board with $n$ rows and $n$ columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.

A knight is a chess piece that can attack a piece in cell ($x_2$, $y_2$) from the cell ($x_1$, $y_1$) if one of the following conditions is met:

  $|x_1 - x_2| = 2$ and $|y_1 - y_2| = 1$, or  $|x_1 - x_2| = 1$ and $|y_1 - y_2| = 2$. 

Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).

 [Image] 

A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.


-----Input-----

The first line contains one integer $n$ ($3 \le n \le 100$) — the number of rows (and columns) in the board.


-----Output-----

Print $n$ lines with $n$ characters in each line. The $j$-th character in the $i$-th line should be W, if the cell ($i$, $j$) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.


-----Example-----
Input
3

Output
WBW
BBB
WBW



-----Note-----

In the first example, there are $8$ duels:

  the white knight in ($1$, $1$) attacks the black knight in ($3$, $2$);  the white knight in ($1$, $1$) attacks the black knight in ($2$, $3$);  the white knight in ($1$, $3$) attacks the black knight in ($3$, $2$);  the white knight in ($1$, $3$) attacks the black knight in ($2$, $1$);  the white knight in ($3$, $1$) attacks the black knight in ($1$, $2$);  the white knight in ($3$, $1$) attacks the black knight in ($2$, $3$);  the white knight in ($3$, $3$) attacks the black knight in ($1$, $2$);  the white knight in ($3$, $3$) attacks the black knight in ($2$, $1$).
targets: n = int(input())
mat = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	for j in range(n):
		if (i + j) % 2 == 1:
			mat[i][j] = 'W'
		else:
			mat[i][j] = 'B'
for i in range(n):
	for j in range(n):
		if j < n-1:
			print(mat[i][j], end = "")
		else:
			print(mat[i][j])
inputs: Solve in Python:
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]$ parrots sitting on the i−th$ i-th$ branch.  
Sometimes Bobby shots one of the parrot and the parrot dies (suppose that this parrots sat at the i−th$i-th$ branch). Consequently all the parrots on the i−th$i-th$ branch to the left of the dead parrot get scared and jump up on the branch number i − 1$i - 1$, if there exists no upper branch they fly away. Also all the parrots to the right of the dead parrot jump down on branch number i + 1$i + 1$, if there exists no such branch they fly away.  
Bobby has shot m parrots. You're given the initial number of parrots on each branch, tell him how many parrots are sitting on each branch after the shots.  

-----Input:-----
The first line of the input contains an integer N$N$. The next line contains a list of space-separated integers a1, a2, …, an.
The third line contains an integer M$M$. Each of the next M$M$ lines contains two integers x[i]$x[i]$ and y[i]$y[i]$. The integers mean that for the i-th time Bobby shoot the y[i]-th (from left) parrot on the x[i]-th branch. It's guaranteed there will be at least y[i] parrot on the x[i]-th branch at that moment.   

-----Output:-----
On the i−th$i-th$ line of the output print the number of parrots on the i−th$i-th$ branch.

-----Constraints-----
- 1≤N≤100$1 \leq N \leq 100$
- 0≤a[i]≤100$0 \leq a[i] \leq 100$
- 0≤M≤100$0 \leq M \leq 100$
- 1≤x[i]≤n$1 \leq x[i] \leq n$, 1≤y[i]$1 \leq y[i] $

-----Sample Input:-----
5

10 10 10 10 10

5

2 5

3 13

2 12

1 13

4 6   
3

2 4 1

1

2 2   

-----Sample Output:-----
0

12

5

0

16   
3

0

3
targets: n = int(input())
A = list(map(int, input().split()))

m = int(input())
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    left = y
    right = A[x] - left - 1
    
    A[x] = 0
    
    if x - 1 >= 0:
        A[x - 1] += left
    if x + 1 < n:
        A[x + 1] += right
    
for a in A:
    print(a)
inputs: Solve in Python:
=====Problem Statement=====
Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms.

One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting of K members per group where K ≠ 1.

The Captain was given a separate room, and the rest were given one room per group.

Mr. Anant has an unordered list of randomly arranged room entries. The list consists of the room numbers for all of the tourists. The room numbers will appear K times per group except for the Captain's room.

Mr. Anant needs you to help him find the Captain's room number.
The total number of tourists or the total number of groups of families is not known to you.
You only know the value of K and the room number list.

=====Input Format=====
The first consists of an integer, K, the size of each group.
The second line contains the unordered elements of the room number list.

=====Constraints=====
1<K<1000

=====Output Format=====
Output the Captain's room number.
targets: #!/usr/bin/env python3

def __starting_point():
    k = int(input().strip())
    numbers = list(map(int, input().strip().split(' ')))
    
    print((sum(set(numbers))*k - sum(numbers))//(k-1))
__starting_point()
inputs: Solve in Python:
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.

-----Constraints-----
 - 1 \leq X \leq 10^6
 - 1 \leq Y \leq 10^6
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X Y

-----Output-----
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.

-----Sample Input-----
3 3

-----Sample Output-----
2

There are two ways: (0,0) \to (1,2) \to (3,3) and (0,0) \to (2,1) \to (3,3).
targets: X,Y = map(int,input().split())
mod = 10**9+7
N = (X+Y)//3
M = (N+X-Y)//2

if (X+Y)%3!=0 or M<0 or N<M:
  print(0)
else:
  ans = 1
  for m in range(1,M+1):
    ans*=(N-M+m)*pow(m,mod-2,mod)
    ans%=mod
  print(ans)
inputs: I found an interesting problem on https://atcoder.jp/contests/arc094/tasks/arc094_b:
10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
 - In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

-----Constraints-----
 - 1 \leq Q \leq 100
 - 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
Q
A_1 B_1
:
A_Q B_Q

-----Output-----
For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.

-----Sample Input-----
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

-----Sample Output-----
1
12
4
11
14
57
31
671644785

Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).
In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.

I tried it in Python, but could not do it. Can you solve it?
targets: n = int(input())
for i in range(n):
    a,b= list(map(int, input().split( )))

    #解説参照
    #何度見ても解けない
    #どちらかは高橋君より良い
    #a<=bとする
    #a=b (1~a-1)*2
    #a<b c**2<abとする
    #c(c+1)>=ab？2c-2 / 2c-1

    if a==b:
        print((2*a-2))
    else:
        c = int((a*b)**(1/2))
        if c*c==a*b:
            c -= 1
        if c*c+c>=a*b:
            print((2*c-2))
        else:
            print((2*c-1))
inputs: I found an interesting problem on https://www.codechef.com/problems/TRACE:
Chef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\mathop{\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index are equal).
Now, Chef wants to solve some excercises related to this new quantity, so he wrote down a square matrix $A$ with size $N\times N$. A square submatrix of $A$ with size $l\times l$ is a contiguous block of $l\times l$ elements of $A$. Formally, if $B$ is a submatrix of $A$ with size $l\times l$, then there must be integers $r$ and $c$ ($1\le r, c \le N+1-l$) such that $B_{i,j} = A_{r+i-1, c+j-1}$ for each $1 \le i, j \le l$.
Help Chef find the maximum trace of a square submatrix of $A$.

-----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$.
- $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains $N$ space-separated integers $A_{i,1}, A_{i,2}, \dots, A_{i, N}$ denoting the $i$-th row of the matrix $A$.

-----Output-----
For each test case, print a single line containing one integer — the maximum possible trace.

-----Constraints-----
- $1 \le T \le 100$
- $2 \le N \le 100$
- $1 \le A_{i,j} \le 100$ for each valid $i, j$

-----Subtasks-----
Subtask #1 (100 points): original constraints

-----Example Input-----
1
3
1 2 5
6 3 4
2 7 1

-----Example Output-----
13

-----Explanation-----
Example case 1: The submatrix with the largest trace is 
6 3
2 7

which has trace equal to $6 + 7 = 13$. (This submatrix is obtained for $r=2, c=1, l=2$.)

I tried it in Python, but could not do it. Can you solve it?
targets: # cook your dish here
for i in range(int(input())):
 h = int(input())
 f = []
 ans = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  sum1 = 0
  sum2 = 0
  for l in range(0,k+1):
   sum1 += f[l][h+l-k-1]
   sum2 += f[h+l-k-1][l]
   
  ans.append(sum1)
  
  ans.append(sum2)
  
 print(max(ans))
inputs: I found an interesting problem on https://www.codewars.com/kata/59e1254d0863c7808d0000ef:
# Fourier transformations are hard. Fouriest transformations are harder.

This Kata is based on the SMBC Comic on fourier transformations.

A fourier transformation on a number is one that converts the number to a base in which it has more `4`s ( `10` in base `6` is `14`, which has `1` four as opposed to none, hence, fourier in base `6` ).

A number's fouriest transformation converts it to the base in which it has the most `4`s.  
For example: `35353` is the fouriest in base `6`: `431401`.

This kata requires you to create a method `fouriest` that takes a number and makes it the fouriest, telling us in which base this happened, as follows:

```python
fouriest(number) -> "{number} is the fouriest ({fouriest_representation}) in base {base}"
```

## Important notes

* For this kata we don't care about digits greater than `9` ( only `0` to `9` ), so we will represent all digits greater than `9` as `'x'`: `10` in base `11` is `'x'`, `119` in base `20` is `'5x'`, `118` in base `20` is also `'5x'`

* When a number has several fouriest representations, we want the one with the LOWEST base

```if:haskell,javascript
* Numbers below `9` will not be tested
```

```if:javascript
* A `BigNumber` library has been provided; documentation is [here](https://mikemcl.github.io/bignumber.js/)
```

## Examples

```python
"30 is the fouriest (42) in base 7"
"15 is the fouriest (14) in base 11"
```

I tried it in Python, but could not do it. Can you solve it?
targets: def change_base(n, b):
    result = ''
    while n > 0:
        rem = n % b if n % b <=9 else 'x'
        result = str(rem) + result
        n //= b
    return result

def fouriest(n):
    bb, br = None, 0
    for i in range(2, n):
        res = list(change_base(n, i))
        nf = res.count('4')        
        if br >= len(res):
            break
        elif nf > br:
            br, bb = nf, i
            
    return f"{n} is the fouriest ({change_base(n, bb)}) in base {bb}"
inputs: I found an interesting problem on https://codeforces.com/problemset/problem/1419/A:
Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play $t$ matches of a digit game...

In each of $t$ matches of the digit game, a positive integer is generated. It consists of $n$ digits. The digits of this integer are numerated from $1$ to $n$ from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.

Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.

It can be proved, that before the end of the match (for every initial integer with $n$ digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.

For each of $t$ matches find out, which agent wins, if both of them want to win and play optimally.


-----Input-----

First line of input contains an integer $t$ $(1 \le t \le 100)$  — the number of matches.

The first line of each match description contains an integer $n$ $(1 \le n \le 10^3)$  — the number of digits of the generated number.

The second line of each match description contains an $n$-digit positive integer without leading zeros.


-----Output-----

For each match print $1$, if Raze wins, and $2$, if Breach wins.


-----Example-----
Input
4
1
2
1
3
3
102
4
2069

Output
2
1
1
2



-----Note-----

In the first match no one can make a turn, the only digit left is $2$, it's even, so Breach wins.

In the second match the only digit left is $3$, it's odd, so Raze wins.

In the third match Raze can mark the last digit, after that Breach can only mark $0$. $1$ will be the last digit left, it's odd, so Raze wins.

In the fourth match no matter...

I tried it in Python, but could not do it. Can you solve it?
targets: for _ in range(int(input())):
  n=int(input())
  s=input()
  if n%2==1:
    a=[int(i)%2 for i in s[::2]]
    if 1 in a:print(1)
    else:print(2)
  else:
    a=[int(i)%2 for i in s[1::2]]
    if 0 in a:print(2)
    else:print(1)
inputs: Solve in Python:
This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.

You are given a string $s$ consisting of $n$ lowercase Latin letters.

You have to color all its characters the minimum number of colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).

After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.

The goal is to make the string sorted, i.e. all characters should be in alphabetical order.

Your task is to find the minimum number of colors which you have to color the given string in so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $s$.

The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.


-----Output-----

In the first line print one integer $res$ ($1 \le res \le n$) — the minimum number of colors in which you have to color the given string so that after coloring it can become sorted by some sequence of swaps.

In the second line print any possible coloring that can be used to sort the string using some sequence of swaps described in the problem statement. The coloring is the array $c$ of length $n$, where $1 \le c_i \le res$ and $c_i$ means the color of the $i$-th character.


-----Examples-----
Input
9
abacbecfd

Output
2
1 1 2 1 2 1 2 1 2 

Input
8
aaabbcbb

Output
2
1 2 1 2 1 2 1 1

Input
7
abcdedc

Output
3
1 1 1 1 1 2 3 

Input
5
abcde

Output
1
1 1 1 1 1
targets: import sys

# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def ceil(tails, L, R, key): 
    while L + 1 < R: 
        m = (L + R) // 2
        if key < tails[m]:
            L = m 
        else: 
            R = m 
    return R
   
def LIS(a, n):
    
    tails = [0] * (n + 1)
    tails[0] = a[0]
    seq_len = 1  # LIS for a[:1]
    for i in range(1, n):
        
        if (a[i] > tails[0]):  # edit for other order
            tails[0] = a[i]    # new LIS start
            ans.append(1)
        
        elif (a[i] < tails[seq_len - 1]):  # edit for other order
            tails[seq_len] = a[i]          # extend existing LIS
            seq_len += 1
            ans.append(seq_len)
        
        else:  # find LIS that ends in a[i] and update tail value for it
            pos = ceil(tails, -1, seq_len - 1, a[i])
            tails[pos] = a[i]
            ans.append(pos + 1)
   
    return seq_len

n = int(input())
s = input()
ans = [1]
res = LIS(s, n)
print(res)
print(*ans)
    
# inf.close()