One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).

NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".

n, m = map(int, raw_input().split())

nomes = []

for i in xrange(n):
	entrada = raw_input()
	nomes.append(entrada)

total = 1

for k in xrange(m):

	parcial = [nomes[0][k]]
	for l in xrange(1, n):

		if(nomes[l][k] not in parcial):
			parcial.append(nomes[l][k])

	total *= len(parcial)

print total % 1000000007

[{'input': '2 3\r\nAAB\r\nBAA\r\n', 'output': ['4\r\n']}, {'input': '4 5\r\nABABA\r\nBCGDG\r\nAAAAA\r\nYABSA\r\n', 'output': ['216\r\n']}, {'input': '1 1\r\nE\r\n', 'output': ['1\r\n']}, {'input': '2 2\r\nNS\r\nPD\r\n', 'output': ['4\r\n']}, {'input': '3 4\r\nPJKD\r\nNFJX\r\nFGFK\r\n', 'output': ['81\r\n']}, {'input': '4 5\r\nSXFMY\r\nATHLM\r\nKDDQW\r\nZWGDS\r\n', 'output': ['1024\r\n']}, {'input': '20 14\r\nJNFKBBBJYZHWQE\r\nLBOKZCPFNKDBJY\r\nXKNWGHQHIOXUPF\r\nDDNRUKVUGHWMXW\r\n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nWDJQHMIRYY\r\nKCORHQPZYE\r\nRRPLFOZZVY\r\nJTXMFNNNYJ\r\nMVTGGOZZVV\r\nEHAFFNUZVF\r\nLBRNWJZNYE\r\nJVMOHTPZYJ\r\nWTARFJLZVV\r\nLVJCWOURVW\r\nLCLQFJYRVV\r\nQVBVGNJRYF\r\nNTZGHOLRYE\r\nMGQKHOUPYJ\r\nRRSSBXPZYJ\r\nRYCRGTLZYJ\r\nJRDEGNKRVW\r\nRZKFGHYRVG\r\nMDJBFNIZYG\r\nMPLWHXIZYE\r\nSRZMHMURVE\r\nMTEBBMRZYJ\r\nJPJIFOLZYM\r\n', 'output': ['919913906\r\n']}, {'input': '40 7\r\nPNTVVER\r\nPAHTQDR\r\nRXMJVAS\r\nVIQNLYC\r\nILPUSVX\r\nYJOXQDJ\r\nSEFODTO\r\nOTJMREL\r\nLIQRZGD\r\nLBJJPOR\r\nRUTYHQO\r\nRIWEPBD\r\nKQUMFIB\r\nISTRRYH\r\nXBTOTGK\r\nRFQODEY\r\nHDSTZTP\r\nYCXFAGL\r\nAREGRFU\r\nLELZUYU\r\nGVABDKH\r\nFJAMMME\r\nACVULXE\r\nJHVPJAS\r\nAAQNMBX\r\nJJGUCXG\r\nOQATILQ\r\nNEOSHJM\r\nHFLWOFM\r\nICYEQHY\r\nFACGLYP\r\nPLLXJEQ\r\nDCHXYPB\r\nAGDDZJJ\r\nLSQRXTN\r\nHDQZXIY\r\nNAHDDWW\r\nQCMXRQN\r\nFDUDSZO\r\nHKBEVTW\r\n', 'output': ['206575993\r\n']}, {'input': '2 2\r\nAA\r\nBB\r\n', 'output': ['4\r\n']}, {'input': '1 10\r\nAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '2 8\r\nAAAAAAAA\r\nBBBBBBBB\r\n', 'output': ['256\r\n']}, {'input': '10 10\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r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J\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\n', 'output': ['26\r\n']}]


An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

n, m = list(map(int, input().strip().split()))
A = [[0] * m] * n

for r in range(n):
    A[r] = list(input().strip())

def in_row(A, r, c):
    x = A[r][c]
    left, right = A[r][:c], A[r][c + 1:]
    if (x in left) or (x in right):
        return True

def in_col(A, r, c):
    x = A[r][c]
    for row in range(n):
        if row == r:
            continue
        if A[row][c] == x:
            return True

out = ''
for r in range(n):
    for c in range(m):
        if not in_row(A, r, c) and not in_col(A, r, c):
            out += A[r][c]

print(out)

[{'input': '3 3\r\ncba\r\nbcd\r\ncbc\r\n', 'output': ['abcd']}, {'input': '5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n', 'output': ['codeforces']}, {'input': '4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n', 'output': ['ahhasusu']}, {'input': '7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n', 'output': ['b']}, {'input': '15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\r\na\r\n', 'output': ['a']}, {'input': '2 2\r\nzx\r\nxz\r\n', 'output': ['zxxz']}, {'input': '1 2\r\nfg\r\n', 'output': ['fg']}, {'input': '2 1\r\nh\r\nj\r\n', 'output': ['hj']}, {'input': '1 3\r\niji\r\n', 'output': ['j']}, {'input': '3 1\r\nk\r\np\r\nk\r\n', 'output': ['p']}, {'input': '2 3\r\nmhw\r\nbfq\r\n', 'output': ['mhwbfq']}, {'input': '3 2\r\nxe\r\ner\r\nwb\r\n', 'output': ['xeerwb']}, {'input': '3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n', 'output': ['g']}, {'input': '2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n', 'output': ['rbe']}, {'input': '3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n', 'output': ['blkck']}, {'input': '100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\nu\r\nn\r\nw\r\ny\r\ng\r\ns\r\nt\r\nm\r\nz\r\ne\r\nv\r\ng\r\ny\r\nj\r\nd\r\nz\r\ny\r\na\r\nn\r\nx\r\nk\r\nd\r\nq\r\nn\r\nv\r\ng\r\nk\r\ni\r\nk\r\nf\r\na\r\nb\r\nw\r\no\r\nu\r\nw\r\nk\r\nk\r\nb\r\nz\r\nu\r\ni\r\nu\r\nv\r\ng\r\nv\r\nx\r\ng\r\np\r\ni\r\nz\r\ns\r\nv\r\nq\r\ns\r\nb\r\nw\r\ne\r\np\r\nk\r\nt\r\np\r\nd\r\nr\r\ng\r\nd\r\nk\r\nm\r\nf\r\nd\r\n', 'output': ['hlc']}, {'input': '100 2\r\nhd\r\ngx\r\nmz\r\nbq\r\nof\r\nst\r\nzc\r\ndg\r\nth\r\nba\r\new\r\nbw\r\noc\r\now\r\nvh\r\n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r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n', 'output': ['tvdiixs']}]


A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

NoteIn the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

import itertools
import math

import time
def timer(f):
    def tmp(*args, **kwargs):
        t = time.time()
        res = f(*args, **kwargs)
        print("Время выполнения функции: %f" % (time.time()-t))
        return res

    return tmp

#n = int(input())

n, m = map(int, input().split(' '))
array = list(map(int, input().split(' ')))
matrix = [[0 for j in range(n)] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split(' '))
    a-=1
    b-=1
    matrix[a][b] = 1
    matrix[b][a] = 1

price = 100000000000000
u = 0;
uu = 0;
uuu = 0;
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i!=j and j!=k and i!=k:
                if matrix[i][j]==1 and matrix[i][k]==1 and matrix[j][k]==1:
                    cp = array[i]+array[j]+array[k]
                    if cp<price:
                        price = cp
                        u = i
                        uu = j
                        uuu = k
                else:
                    #print(i, j, k)
                    pass

if price == 100000000000000:
    print(-1)
else:
    print(price)


Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: a12 + a22 + ... + an2 ≥ x a1 + a2 + ... + an ≤ y

The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.

Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.

n, x, y = map(int, input().split())
if y < n:
     print(-1)
else:
    q = y - n + 1
    if (q ** 2 + n - 1) >= x:
        print(q)
        for i in  range(n - 1):
            print(1)
    else:
        print(-1)


When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m () — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.

The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.

n, m = map(int, raw_input().split())
d = [raw_input() for i in xrange(n)]
d.sort()
a = [[0] * n for i in xrange(n)]
for i in xrange(m):
    x, y = raw_input().split()
    a[d.index(x)][d.index(y)] = a[d.index(y)][d.index(x)] = 1
res, bit = 0, 0
for mask in xrange(1 << n):
    num = 0
    for i in xrange(n):
        if mask >> i & 1:
            num += 1
            for j in xrange(i + 1, n):
                if (mask >> j & 1) != 0 and a[i][j]: num = -20
    if res < num: res = num; bit = mask;
print res
for i in xrange(n):
    if bit >> i & 1 : print d[i]

[{'input': '3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n', 'output': ['2\r\nMasha\r\nPetya\r\n']}, {'input': '3 0\r\nPasha\r\nLesha\r\nVanya\r\n', 'output': ['3\r\nLesha\r\nPasha\r\nVanya\r\n']}, {'input': '7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha Andrey\r\nPasha Sergey\r\nLesha Taras\r\nLesha Nikita\r\nLesha Andrey\r\nLesha Sergey\r\nVanya Taras\r\nVanya Nikita\r\nVanya Andrey\r\nVanya Sergey\r\n', 'output': ['4\r\nAndrey\r\nNikita\r\nSergey\r\nTaras\r\n']}, {'input': '2 0\r\nAndrey\r\nTaras\r\n', 'output': ['2\r\nAndrey\r\nTaras\r\n']}, {'input': '16 0\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nRomka\r\nAlexey\r\nUra\r\nDenis\r\nEgor\r\nVadim\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\n', 'output': ['16\r\nAlena\r\nAlexey\r\nAlice\r\nAndrey\r\nBrus\r\nDenis\r\nEgor\r\nJohn\r\nNikita\r\nOlya\r\nRomka\r\nSergey\r\nTaras\r\nUra\r\nVadim\r\nVanya\r\n']}, {'input': '6 6\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\nAlena John\r\nAlena Alice\r\nOlya John\r\nOlya Alice\r\nVanya John\r\nVanya Alice\r\n', 'output': ['4\r\nAlena\r\nBrus\r\nOlya\r\nVanya\r\n']}, {'input': '7 6\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\nMariana\r\nAlena John\r\nAlena Alice\r\nOlya John\r\nOlya Alice\r\nVanya John\r\nVanya Alice\r\n', 'output': ['5\r\nAlena\r\nBrus\r\nMariana\r\nOlya\r\nVanya\r\n']}, {'input': '1 0\r\nPetr\r\n', 'output': ['1\r\nPetr\r\n']}, {'input': '2 0\r\nNgzlPJgFgz\r\nQfpagVpWz\r\n', 'output': ['2\r\nNgzlPJgFgz\r\nQfpagVpWz\r\n']}, {'input': '2 1\r\ncLWdg\r\nGoWegdDRp\r\nGoWegdDRp cLWdg\r\n', 'output': ['1\r\nGoWegdDRp\r\n']}, {'input': '3 0\r\nr\r\nyVwqs\r\nsdTDerOyhp\r\n', 'output': ['3\r\nr\r\nsdTDerOyhp\r\nyVwqs\r\n']}, {'input': '3 3\r\nvRVatwL\r\nWmkUGiYEn\r\nuvvsXKXcJ\r\nWmkUGiYEn vRVatwL\r\nuvvsXKXcJ vRVatwL\r\nuvvsXKXcJ WmkUGiYEn\r\n', 'output': ['1\r\nWmkUGiYEn\r\n']}, {'input': '16 11\r\njA\r\nkyRNTE\r\neY\r\nToLcqN\r\nbnenhMxiK\r\nzlkOe\r\nXCKZ\r\neaQrds\r\nqUdInpi\r\nKgPQA\r\nmQIl\r\ninOCWEZHxy\r\nyA\r\nPIZRMOu\r\nXtueKFM\r\nfRNwNn\r\ninOCWEZHxy qUdInpi\r\nKgPQA zlkOe\r\ninOCWEZHxy KgPQA\r\nfRNwNn XCKZ\r\ninOCWEZHxy eY\r\nyA mQIl\r\ninOCWEZHxy ToLcqN\r\nyA KgPQA\r\nqUdInpi ToLcqN\r\nqUdInpi eaQrds\r\nPIZRMOu eY\r\n', 'output': ['10\r\nKgPQA\r\nPIZRMOu\r\nToLcqN\r\nXCKZ\r\nXtueKFM\r\nbnenhMxiK\r\neaQrds\r\njA\r\nkyRNTE\r\nmQIl\r\n']}, {'input': '12 12\r\njWuGgOjV\r\nWs\r\njTZQMyH\r\nULp\r\nUfsnPRt\r\nk\r\nbPKrnP\r\nW\r\nJOaQdgglDG\r\nAodc\r\ncpRjAUyYIW\r\nMrjB\r\nbPKrnP ULp\r\nk Ws\r\ncpRjAUyYIW k\r\nULp jTZQMyH\r\nbPKrnP jWuGgOjV\r\ncpRjAUyYIW jTZQMyH\r\nW ULp\r\nk jTZQMyH\r\nk ULp\r\nMrjB ULp\r\ncpRjAUyYIW Aodc\r\nW k\r\n', 'output': ['8\r\nAodc\r\nJOaQdgglDG\r\nMrjB\r\nUfsnPRt\r\nW\r\nWs\r\nbPKrnP\r\njTZQMyH\r\n']}, {'input': '11 17\r\njFTNgFBO\r\ntZDgmdF\r\nIjeDjoj\r\nBEMAaYkNb\r\nRZRQl\r\ntK\r\nlNHWt\r\nIdG\r\nLAbVLYiY\r\notOBsWqJuo\r\nUoTy\r\ntK BEMAaYkNb\r\nBEMAaYkNb jFTNgFBO\r\nIjeDjoj tZDgmdF\r\nRZRQl jFTNgFBO\r\nlNHWt tZDgmdF\r\nRZRQl tZDgmdF\r\nUoTy LAbVLYiY\r\nBEMAaYkNb IjeDjoj\r\nIdG BEMAaYkNb\r\nLAbVLYiY tK\r\nLAbVLYiY jFTNgFBO\r\nUoTy IjeDjoj\r\nlNHWt jFTNgFBO\r\nlNHWt BEMAaYkNb\r\ntK IjeDjoj\r\nUoTy RZRQl\r\nBEMAaYkNb tZDgmdF\r\n', 'output': ['6\r\nIdG\r\nIjeDjoj\r\nLAbVLYiY\r\nRZRQl\r\nlNHWt\r\notOBsWqJuo\r\n']}, {'input': '11 13\r\ncZAMfd\r\nSWQnweM\r\nKlQW\r\nWRsnNZT\r\nix\r\nUC\r\nLWqsVHcWec\r\nfeb\r\ncBy\r\ntvk\r\nRXDlX\r\nfeb SWQnweM\r\ncBy WRsnNZT\r\nLWqsVHcWec KlQW\r\nRXDlX feb\r\nLWqsVHcWec cZAMfd\r\ncBy UC\r\nWRsnNZT SWQnweM\r\nRXDlX cBy\r\ntvk UC\r\ncBy SWQnweM\r\nUC KlQW\r\nRXDlX KlQW\r\nUC WRsnNZT\r\n', 'output': ['6\r\nKlQW\r\nWRsnNZT\r\ncZAMfd\r\nfeb\r\nix\r\ntvk\r\n']}, {'input': '4 2\r\nadQx\r\nrJGeodBycK\r\ntgPYZk\r\ncz\r\ncz tgPYZk\r\nrJGeodBycK adQx\r\n', 'output': ['2\r\nadQx\r\ncz\r\n']}, {'input': '4 2\r\noVemoZhjW\r\nHspFEry\r\nhFO\r\njxt\r\nhFO HspFEry\r\njxt oVemoZhjW\r\n', 'output': ['2\r\nHspFEry\r\njxt\r\n']}, {'input': '5 2\r\niBrgNFlNXd\r\nlnGPIV\r\nnb\r\nB\r\nVgqRcEOG\r\nlnGPIV iBrgNFlNXd\r\nB iBrgNFlNXd\r\n', 'output': ['4\r\nB\r\nVgqRcEOG\r\nlnGPIV\r\nnb\r\n']}, {'input': '5 1\r\nWEYUdpYmZp\r\nfhNmMpjr\r\nydARivBg\r\ncilTtE\r\nyeXxkhPzB\r\nyeXxkhPzB cilTtE\r\n', 'output': ['4\r\nWEYUdpYmZp\r\ncilTtE\r\nfhNmMpjr\r\nydARivBg\r\n']}, {'input': '6 9\r\noySkmhCD\r\nUIKWj\r\nmHolKkBx\r\nQBikssqz\r\nZ\r\nzoFUJYa\r\nZ UIKWj\r\nQBikssqz oySkmhCD\r\nQBikssqz UIKWj\r\nZ oySkmhCD\r\nzoFUJYa UIKWj\r\nzoFUJYa Z\r\nzoFUJYa mHolKkBx\r\nzoFUJYa QBikssqz\r\nQBikssqz mHolKkBx\r\n', 'output': ['3\r\nUIKWj\r\nmHolKkBx\r\noySkmhCD\r\n']}, {'input': '6 1\r\nuPVIuLBuYM\r\nVejWyKCtbN\r\nqqjgF\r\nulBD\r\nDRNzxJU\r\nCOzbXWOt\r\nulBD qqjgF\r\n', 'output': ['5\r\nCOzbXWOt\r\nDRNzxJU\r\nVejWyKCtbN\r\nqqjgF\r\nuPVIuLBuYM\r\n']}, {'input': '7 14\r\nFXCT\r\nn\r\no\r\nS\r\nMdFuonu\r\nmszv\r\nbqScOCw\r\nS o\r\nbqScOCw FXCT\r\nMdFuonu o\r\no n\r\nbqScOCw n\r\nmszv S\r\nbqScOCw MdFuonu\r\nmszv n\r\nS FXCT\r\nbqScOCw o\r\no FXCT\r\nmszv MdFuonu\r\nmszv FXCT\r\nbqScOCw mszv\r\n', 'output': ['3\r\nFXCT\r\nMdFuonu\r\nn\r\n']}, {'input': '7 6\r\nj\r\nZ\r\nPZNeTyY\r\nm\r\na\r\nUj\r\nsuaaSiKcK\r\nUj PZNeTyY\r\na j\r\nPZNeTyY Z\r\nPZNeTyY j\r\nm PZNeTyY\r\nm j\r\n', 'output': ['5\r\nUj\r\nZ\r\na\r\nm\r\nsuaaSiKcK\r\n']}, {'input': '8 6\r\nU\r\nC\r\nPEElYwaxf\r\nVubTXNI\r\nJ\r\nIxZUHV\r\nhLNFnzmqFE\r\nDPPvwuWvmA\r\nhLNFnzmqFE IxZUHV\r\nIxZUHV C\r\nJ PEElYwaxf\r\nIxZUHV PEElYwaxf\r\nPEElYwaxf C\r\nJ VubTXNI\r\n', 'output': ['5\r\nC\r\nDPPvwuWvmA\r\nJ\r\nU\r\nhLNFnzmqFE\r\n']}, {'input': '8 12\r\nBkgxqAF\r\nKhq\r\nNpIfk\r\nkheqUyDVG\r\niRBkHlRpp\r\nZDaQY\r\nNG\r\nqN\r\nqN BkgxqAF\r\nNpIfk BkgxqAF\r\niRBkHlRpp BkgxqAF\r\niRBkHlRpp NpIfk\r\nNG Khq\r\niRBkHlRpp Khq\r\nNG ZDaQY\r\nNG iRBkHlRpp\r\nNG NpIfk\r\nqN Khq\r\nZDaQY kheqUyDVG\r\nNpIfk Khq\r\n', 'output': ['3\r\nBkgxqAF\r\nKhq\r\nZDaQY\r\n']}, {'input': '9 5\r\nRFiow\r\naxgvtiBGbx\r\ngGBVZtI\r\nVWAxrqx\r\nmnASVEQI\r\ntZHzWGAvXc\r\nBeaCYhIRLy\r\nhTdUL\r\nFJd\r\nhTdUL RFiow\r\nhTdUL gGBVZtI\r\nFJd axgvtiBGbx\r\nFJd BeaCYhIRLy\r\nhTdUL axgvtiBGbx\r\n', 'output': ['7\r\nBeaCYhIRLy\r\nRFiow\r\nVWAxrqx\r\naxgvtiBGbx\r\ngGBVZtI\r\nmnASVEQI\r\ntZHzWGAvXc\r\n']}, {'input': '9 13\r\nYiUXqlBUx\r\nQNgYuX\r\ndPtyZ\r\nITtwRJCv\r\nLJ\r\nrAG\r\nOgxNq\r\nsitechE\r\nvVAAz\r\nOgxNq QNgYuX\r\nOgxNq dPtyZ\r\nsitechE rAG\r\nLJ QNgYuX\r\nQNgYuX YiUXqlBUx\r\nOgxNq LJ\r\nvVAAz OgxNq\r\nrAG dPtyZ\r\nvVAAz LJ\r\nvVAAz ITtwRJCv\r\nsitechE LJ\r\nrAG YiUXqlBUx\r\nsitechE QNgYuX\r\n', 'output': ['4\r\nITtwRJCv\r\nLJ\r\nYiUXqlBUx\r\ndPtyZ\r\n']}, {'input': '9 6\r\nfLfek\r\nEQPcotnrp\r\nCaAlbwoIL\r\nVG\r\nNAZKIBiKT\r\noFy\r\njFluh\r\nKqHXRNya\r\nQSwgobA\r\noFy EQPcotnrp\r\nKqHXRNya jFluh\r\noFy NAZKIBiKT\r\njFluh oFy\r\njFluh fLfek\r\noFy fLfek\r\n', 'output': ['7\r\nCaAlbwoIL\r\nEQPcotnrp\r\nKqHXRNya\r\nNAZKIBiKT\r\nQSwgobA\r\nVG\r\nfLfek\r\n']}, {'input': '9 14\r\nmoRNeufngu\r\nBSKI\r\nzXl\r\ngwmIDluW\r\nYFn\r\nHvasEgl\r\nXcAC\r\neVP\r\nAiOm\r\neVP BSKI\r\neVP YFn\r\nHvasEgl YFn\r\neVP XcAC\r\nAiOm HvasEgl\r\nXcAC YFn\r\nzXl moRNeufngu\r\neVP zXl\r\nHvasEgl BSKI\r\nXcAC gwmIDluW\r\nXcAC HvasEgl\r\nYFn moRNeufngu\r\nzXl BSKI\r\nHvasEgl gwmIDluW\r\n', 'output': ['4\r\nAiOm\r\nBSKI\r\nYFn\r\ngwmIDluW\r\n']}, {'input': '15 8\r\ncXeOANpvBF\r\nbkeDfi\r\nnsEUAKNxQI\r\noSIb\r\naU\r\nXYXYVo\r\nduZQ\r\naPkr\r\nPVrHpL\r\nmVgmv\r\nhHhukllwbf\r\nGkNPGYVxjY\r\nbgBjA\r\nslNKCLIlOv\r\nmPILXy\r\nbgBjA cXeOANpvBF\r\nGkNPGYVxjY cXeOANpvBF\r\nslNKCLIlOv GkNPGYVxjY\r\nGkNPGYVxjY mVgmv\r\nXYXYVo cXeOANpvBF\r\nslNKCLIlOv bkeDfi\r\nmVgmv aPkr\r\nslNKCLIlOv nsEUAKNxQI\r\n', 'output': ['12\r\nGkNPGYVxjY\r\nPVrHpL\r\nXYXYVo\r\naPkr\r\naU\r\nbgBjA\r\nbkeDfi\r\nduZQ\r\nhHhukllwbf\r\nmPILXy\r\nnsEUAKNxQI\r\noSIb\r\n']}, {'input': '15 3\r\na\r\nYclKFJoaIA\r\nhalYcB\r\nbLOlPzAeQ\r\ntckjt\r\noDFijpx\r\nb\r\npz\r\nVDLb\r\nlCEHPibt\r\noF\r\npzJD\r\nMC\r\nqklsX\r\nTAU\r\npzJD tckjt\r\nqklsX oF\r\nMC pzJD\r\n', 'output': ['13\r\nMC\r\nTAU\r\nVDLb\r\nYclKFJoaIA\r\na\r\nb\r\nbLOlPzAeQ\r\nhalYcB\r\nlCEHPibt\r\noDFijpx\r\noF\r\npz\r\ntckjt\r\n']}, {'input': '16 8\r\nJIo\r\nINanHVnP\r\nKaxyCBWt\r\nkVfnsz\r\nRAwFYCr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Ef\r\nWqEiwkH\r\nWX\r\ne\r\nltmruh\r\nKGx\r\nauTUYZRC\r\nmeJa\r\nM\r\nmeJa q\r\nKGx e\r\nXEf Xozwkum\r\ne q\r\nauTUYZRC KGx\r\ne CC\r\nM CC\r\nM meJa\r\nWX CC\r\nWqEiwkH IEAYCq\r\nauTUYZRC WqEiwkH\r\nKGx WX\r\nmeJa KGx\r\nXEf q\r\nauTUYZRC XEf\r\nauTUYZRC IEAYCq\r\nWX XEf\r\nM XEf\r\nWqEiwkH q\r\nM KGx\r\nKGx CC\r\nM e\r\nWqEiwkH Xozwkum\r\nCC q\r\nS Xozwkum\r\nKGx tIWi\r\nWX q\r\nXEf S\r\nauTUYZRC S\r\nCC IEAYCq\r\nKGx IEAYCq\r\ne WqEiwkH\r\nM S\r\nauTUYZRC q\r\nS tIWi\r\nM ltmruh\r\nM iPwfd\r\n', 'output': ['8\r\nIEAYCq\r\nWX\r\nXozwkum\r\ne\r\niPwfd\r\nltmruh\r\nmeJa\r\ntIWi\r\n']}, {'input': '16 11\r\ntulhZxeKgo\r\nbrAXY\r\nyQUkaihDAg\r\nmwjlDVaktK\r\nweVtBIP\r\nzRwb\r\nds\r\nhXPfJrL\r\nAdIfP\r\nazQeXn\r\nB\r\nJlmscIUOxO\r\nZuxr\r\nV\r\nOfyLIUO\r\nuaMl\r\nhXPfJrL yQUkaihDAg\r\nweVtBIP yQUkaihDAg\r\nazQeXn hXPfJrL\r\nV tulhZxeKgo\r\nzRwb yQUkaihDAg\r\nds mwjlDVaktK\r\nzRwb brAXY\r\nyQUkaihDAg brAXY\r\nB yQUkaihDAg\r\nAdIfP mwjlDVaktK\r\nbrAXY tulhZxeKgo\r\n', 'output': ['11\r\nAdIfP\r\nB\r\nJlmscIUOxO\r\nOfyLIUO\r\nV\r\nZuxr\r\nazQeXn\r\nbrAXY\r\nds\r\nuaMl\r\nweVtBIP\r\n']}, {'input': '5 10\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nRomka\r\nTaras Romka\r\nTaras Nikita\r\nTaras Sergey\r\nTaras Andrey\r\nRomka Nikita\r\nRomka Sergey\r\nRomka Andrey\r\nNikita Sergey\r\nNikita Andrey\r\nSergey Andrey\r\n', 'output': ['1\r\nAndrey\r\n']}]


Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.Determine how many groups of students will be kicked out of the club.

The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.

Print the single number — the number of groups of students that will be kicked out from the club.

NoteIn the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.

r = lambda: raw_input().strip()

n,m = map(int,r().split())
ties = [map(int,r().split()) for _ in xrange(m)]
count = 0
while len(ties)>0:
    all_ties = []
    l1 = len(ties)
    for t in ties:
        all_ties.append(t[0])
        all_ties.append(t[1])
    for i in xrange(n):
        if all_ties.count(i+1)==1:
            for t in xrange(len(ties)):
                if ties[t][0] == i+1 or ties[t][1] == i+1:
                    ties.remove(ties[t])
                    break
    l2 = len(ties)
    if l1==l2:
        break
    count += 1
print count


A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:   there were b milliliters poured in total. That is, the bottle need to be emptied;  after the process is over, the volumes of the drink in the mugs should be equal.

The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug.

Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.

x=[int(i) for i in input().split()]
n=x[0]
y=[int(i) for i in input().split()]
if x[1]<max(y)*n-sum(y):
    print(-1)
    raise SystemExit

for i in range(n):
    s=x[1]/n-y[i]++sum(y)/n
    print('%.6f'% s)


Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.  Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

n = int(input())

mod = 10**9 +7

def power_2_k(k):
    if k == 0:
        return 1
    if k % 2 == 0:
        lower = power_2_k(k // 2)
        return (lower * lower) % mod
    else:
        k -= 1
        lower = power_2_k(k // 2)
        return (((lower * lower) % mod) * 2) % mod

p = power_2_k(n)
print((p * (p + 1) // 2) % mod)


In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

n=int(input())
a=list(map(int,input().split()))
ans=1e9
for i in range(n-1):
    ans=min(ans,max(a[i],a[i+1]))
print(min(ans,a[0],a[-1]))


The Little Elephant loves to play with color cards.He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces.

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

NoteIn the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.

import math
n = int(input())
front = dict()
back = dict()
for i in range(n):
    a, b = map(int,input().split())
    if a in front:
        front[a] += 1
    else:
        front[a] = 1

    if b != a:
       if b in back:
          back[b] += 1
       else:
          back[b] = 1

ans = -1
m = dict()
for key, value in front.items():
    if value >= n/2:
        ans = 0
        break
    elif key in back and front[key] + back[key] >= n/2:
        m[key] = math.ceil(n/2) - front[key]

else:
    if len(m) > 0:
        ans = min(sorted(m.values()))
    else:
        for key, value in back.items():
            if value >= n/2:
                ans = math.ceil(n/2)
                break
        else:
            ans = -1
print(ans)


Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):   a mug (costs a points),  a towel (costs b points),  a bag (costs c points),  a bicycle (costs d points),  a car (costs e points). Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

n = int(raw_input())
pts = [int(i) for i in raw_input().split()]
goods = [int(i) for i in raw_input().split()]

left = 0
gets = [0]*5
for p in pts:
    left += p
    for i in xrange(4, -1, -1):
        gets[i] += left/goods[i]
        left %= goods[i]
print gets[0], gets[1], gets[2], gets[3], gets[4]
print left


Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.

import collections as cl

n, a = int(input()), map(int, input().split())
m, b = int(input()), list(map(int, input().split()))

ans = cl.Counter([xb // xa for xa in a for xb in b if xb % xa == 0])
print(ans[max(ans.keys())])


Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

n = int(input())

coodenadas = []
for i in range(n):
    x, y = [ int(i) for i in input().split() ]
    coodenadas.append({
        'x': { x },
        'y': { y }
    })

for i in range(n-1, -1, -1):
    j = i - 1
    while j >= 0 and i < len(coodenadas):
        if len(coodenadas[j]['x'].intersection(coodenadas[i]['x'])) or len(coodenadas[j]['y'].intersection(coodenadas[i]['y'])):
            coodenadas[i]['x'].update(coodenadas[j]['x'])
            coodenadas[i]['y'].update(coodenadas[j]['y'])
            coodenadas.pop(j)
        j -= 1

print(len(coodenadas) - 1)


Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

"""
Peter likes to travel by train. He likes it so much that on the train he falls asleep.

Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.

The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.

At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.

Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.

Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

Input
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.

The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output
Output one of the four words without inverted commas:

«forward» — if Peter could see such sequences only on the way from A to B;
«backward» — if Peter could see such sequences on the way from B to A;
«both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;
«fantasy» — if Peter could not see such sequences.
"""

x = input()
x_reversed = ''.join(list(reversed(x)))

# print(x)
# print(x_reversed)

seq1 = input()
seq2 = input()

if len(seq1) + len(seq2) > len(x):
	print('fantasy')
else:
	forward = False
	backward = False

	x_find_seq1 = x.find(seq1)
	if x_find_seq1 > -1:
		x_find_seq2 = x[x_find_seq1 + len(seq1):].find(seq2)
		if x_find_seq2 > -1:
			x_find_seq2 += x_find_seq1 + len(seq1)
	else:
		x_find_seq2 = -1

	x_reversed_find_seq1 = x_reversed.find(seq1)
	if x_reversed_find_seq1 > -1:
		x_reversed_find_seq2 = x_reversed[x_reversed_find_seq1 + len(seq1):].find(seq2)
		if x_reversed_find_seq2 > -1:
			x_reversed_find_seq2 += x_reversed_find_seq1 + len(seq1)
	else:
		x_reversed_find_seq2 = -1

	# print('x_find_seq1:', x_find_seq1)
	# print('x_find_seq2:', x_find_seq2)

	# print("--------")
	# print(x_reversed)
	# print('x_reversed_find_seq1:', x_reversed_find_seq1)
	# print('x_reversed_find_seq2:', x_reversed_find_seq2)

	if (x_find_seq1 != -1 and x_find_seq1 != -1):
		if x_find_seq1 <= x_find_seq2:
			forward = True

	if (x_reversed_find_seq1 != -1 and x_reversed_find_seq1 != -1):
		if x_reversed_find_seq1 <= x_reversed_find_seq2:
			backward = True

	if forward and backward:
		print('both')
	elif forward:
		print("forward")
	elif backward:
		print("backward")
	else:
		print('fantasy')

"""
x = [1,2,3,4]
print(x[1:])

seq1_list = list(seq1)
seq1_len = len(seq1)

seq2_list = list(seq2)
seq2_len = len(seq2)

x_len = len(x)

seq1_found = False
for elm, i in enumerate(x):
	if elm == seq1_list[0] and x_len-i >= seq1_len:
		for j in seq2_list:
			if j !=
"""

[{'input': 'atob\r\na\r\nb\r\n', 'output': ['forward\r\n']}, {'input': 'aaacaaa\r\naca\r\naa\r\n', 'output': ['both\r\n']}, {'input': 'aaa\r\naa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'astalavista\r\nastla\r\nlavista\r\n', 'output': ['fantasy\r\n']}, {'input': 'abacabadabacaba\r\nabacaba\r\nabacaba\r\n', 'output': ['both\r\n']}, {'input': 'a\r\na\r\na\r\n', 'output': ['fantasy\r\n']}, {'input': 'ab\r\nb\r\na\r\n', 'output': ['backward\r\n']}, {'input': 'aaa\r\naaaa\r\naaaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'bbabbbbababbaabaabaa\r\nabb\r\nbaab\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['backward\r\n']}, {'input': 'aaaa\r\naaa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzzzz\r\nzzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzz\r\n', 'output': ['both\r\n']}, {'input': 'aabaa\r\naab\r\nbaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'aabaab\r\naba\r\nab\r\n', 'output': ['forward\r\n']}, {'input': 'aab\r\nb\r\naa\r\n', 'output': ['backward\r\n']}, {'input': 'abacaba\r\naca\r\nba\r\n', 'output': ['both\r\n']}]


And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

from math import sqrt

n, v1, v2 = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x1, y1 = [int(i) for i in input().split()]

minim = x[1] / v1 + sqrt((x1-x[1])**2 + (y1)**2) / v2 #Время, если студен выйдет на первой остановке и побежит (если он быстрее автобуса)
res = 2
for i in range(2, n):
    t = x[i] / v1 + sqrt((x1-x[i])**2 + (y1)**2) / v2
    if t < minim:
        minim = t
        res = i + 1
    elif t == minim and sqrt((x1-x[res-1])**2 + (y1)**2) > sqrt((x1-x[i])**2 + (y1)**2):
        res = i+1
print(res)


A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output the amount of possible positions of the new house.

NoteIt is possible for the x-coordinate of the new house to have non-integer value.

#15A - Cottage Village
# n - how many square houses we have on the x-axis
# t - the side of the main house
n, t = map(int, input().split())
#Variable that sorts square houses by x-axis coordinates in ascending order
#Input: house's center on the x-axis and the house's side length
houses = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[0])
#Because there's at least 1 other house in the village, we have 2 possibilities
#by default, cause the main house can touch one of the 2 exposed sides of the other house
ans = 2
#The next loop computes the number of houses that fit between 2 adjacent houses
for i in range(n - 1):
    x = houses[i][0] + houses[i][1] / 2
    y = houses[i + 1][0] - houses[i + 1][1] / 2
    #If the space between the 2 houses is equal to the main house's side,
    #the only way we can place our house is to touch both houses at the same time
    if y - x == t:
        ans += 1
    #If the space between the houses is bigger than the main house's side,
    #then we consider the 2 houses as 2 separate cases, each with 2 possibilities
        #of their own
    elif y - x > t:
        ans += 2

print(ans)


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

import sys

def digits(phone_number):
    if phone_number:
        phone_number = phone_number.rstrip('\r|\n')
        length = len(phone_number)

        # Not even.
        if length in [2, 3]:
            return phone_number
        elif length % 2:
            return phone_number[0:3] + "-" + digits(phone_number[3:])
        return phone_number[0:2] + "-" + digits(phone_number[2:])
    else:
        return phone_number

if __name__ == '__main__':
    data = []
    for line in sys.stdin:
        data.append(line)

    for l in data[1::2]:
        print(digits(l))


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

a,b,n = map(int,input().split())
ans = "No solution"

if a == 0 and b == 0:
    ans =5
elif a == 0 and b!= 0:
    ans
elif a != 0 and b == 0:
    ans = 0
elif b%a != 0:
    ans
else:
    a = b / a
    if a < 0 :
        a = abs(a)
        b = 0
    for i in range(1001):
        if i ** n == a:
            ans = i

    if b == 0 :ans = - ans

print(ans)


In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai ≤ k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

NoteIn the first example the ranks will be raised in the following manner:1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4Thus totals to 4 training sessions that require 4 golden coins.

# -*- coding: utf-8 -*-

N , K = [int(n) for n in raw_input().split(" ")]
r = []
num = raw_input().split(" ")
#N , K = 100 , 100
#num = [1 for i in xrange(100)]

for i in xrange(K):
    r.append(0)
for n in num:
    t = int(n)
    r[t - 1] += 1
cnt = 0
while True:
    i = 0
    while i < K - 1 and r[i] == 0:
        i += 1
    if i == K - 1:
        break
    for i in xrange(K - 2 , -1 , -1):
        #print i,
        if r[i] != 0:
            r[i] -= 1
            r[i + 1] += 1
    #print
    cnt += 1
print cnt


Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 × 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:  As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.

The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.

Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.

t = int(raw_input())
N = []
N.append(10000)
[N.append(int(i)) for i in raw_input().split()]
sol = 0
dpx, dpy = [0]*2000, [0]*2000

N.append(10000)
for i in range(1, t+1):
    if N[i] >= N[i - 1]:
        dpy[i] = dpy[i - 1] + 1
    else:
        dpy[i] = 1

for i in range(t, 0, -1):
    if N[i] >= N[i + 1]:
        dpx[i] = dpx[i + 1] + 1
    else:
        dpx[i] = 1

for i in range(1, t+1):
    if dpy[i] + dpx[i] - 1 > sol:
        sol = dpx[i] + dpy[i] - 1

print sol


n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

n = int(input())
l = list(map(int,input().split()))
l.append(l[0])
# print(l)
m = abs(l[1]-l[0])
# print(m)
a = 1
for i in range(2,n+1):
    if(abs(l[i]-l[i-1]))<m:
        # print(abs(l[i]-l[i-1])
        m = abs(l[i]-l[i-1])
        a = i
if(a==n):
    print(a,1)
else:
    print(a,a+1)


The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.

The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.

Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.

n = int(input())
d = [int(x) for x in input().split()]
a, b = [int(x) for x in input().split()]
print(d[a-1]+sum(d[a:b-1]))


The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way.Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k × d bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

The first output line contains two space-separated integers n and l (1 ≤ n, l ≤ 100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1 ≤ ai ≤ 100).

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

NoteIn the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

#!/usr/bin/env python

def main():
	n,l = map(int, raw_input().split())
	d = map(int, raw_input().split())

	ans = 0
	for cut in range(l, max(d)+1):
		w = map(lambda x:x/cut, d)
		ans = max(ans,sum(w)*cut)

	print ans

main()


Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

If Vasya can write the given anonymous letter, print YES, otherwise print NO

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

import collections
l=list(input())
p=list(input())
#print(p)
#print(l)
cl=collections.Counter(l)
pl=collections.Counter(p)
#print(cl)
#print(pl)
plk=list(pl.keys())
#print(plk)
if ' ' in plk:
    plk.remove(' ')
else:
    pass
n=len(plk)
i=0
er=0
#print(cl['s'])
while i<n:
    h=plk[i]
    t=cl[h]
    q=pl[h]
    #print(t)
    #print(q)
    if t>=q:
        er+=1
    else:
        pass
    i+=1
#print(n)
#print(er)
if er==n:
    print('YES')

else:
    print('NO')

[{'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nwhere is your dog\r\n', 'output': ['NO\r\n']}, {'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['YES\r\n']}, {'input': 'Instead of dogging your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['NO\r\n']}, {'input': 'abcdefg hijk\r\nk j i h g f e d c b a\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgo\r\neAtAVB\r\n', 'output': ['NO\r\n']}, {'input': 'GRZGc\r\nLPzD\r\n', 'output': ['NO\r\n']}, {'input': 'GtPXu\r\nd\r\n', 'output': ['NO\r\n']}, {'input': 'FVF\r\nr \r\n', 'output': ['NO\r\n']}, {'input': 'HpOKgo\r\nogK\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGc\r\nZG\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT  MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\r\nAHN  XvoaNwV  AVBKwKjr u      U K wKE D K   Jy KiHsR h d W  Js IHyMPK Br iSqe  E fDA   g H\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\r\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj  bCDgKF  jJxa RddtLFAi VGLHH SecObzG q  hPF \r\n', 'output': ['YES\r\n']}, {'input': 'GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\r\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp\r\n', 'output': ['YES\r\n']}, {'input': 'FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\r\nUzrU K  an GFGR        Wc zt iBa     P c    T K v p     V In   b           B   c\r\n', 'output': ['YES\r\n']}, {'input': 'lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\r\nAoxe  jWZ u  yImg  o AZ FNI w lpj  tNhT g y  ZYcb rc J    w Dlv\r\n', 'output': ['YES\r\n']}, {'input': 'kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\r\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc\r\n', 'output': ['YES\r\n']}, {'input': 'kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\r\nBsH   bWHJD n Ca T xq  PRCv  tatn Wjy sm  I q s WCjFqdWe  t W XUs  Do  eb Pfh ii  hTbF  O Fll\r\n', 'output': ['YES\r\n']}, {'input': 'OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\r\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK\r\n', 'output': ['YES\r\n']}, {'input': 'NwcGaIeSkOva\r\naIa\r\n', 'output': ['YES\r\n']}, {'input': 'gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\r\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui\r\n', 'output': ['YES\r\n']}, {'input': 'ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\r\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy\r\n', 'output': ['NO\r\n']}, {'input': 'hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\r\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW\r\n', 'output': ['NO\r\n']}, {'input': 'yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\r\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw\r\n', 'output': ['NO\r\n']}, {'input': 'jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\r\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL\r\n', 'output': ['NO\r\n']}, {'input': 'zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\r\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl\r\n', 'output': ['NO\r\n']}, {'input': 'kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\r\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh\r\n', 'output': ['NO\r\n']}, {'input': 'AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\r\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ\r\n', 'output': ['NO\r\n']}, {'input': 'lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\r\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl\r\n', 'output': ['NO\r\n']}, {'input': 'BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\r\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk\r\n', 'output': ['NO\r\n']}, {'input': 'KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\r\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk\r\n', 'output': ['NO\r\n']}]


A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

def main():
    n = input()
    pos = 0
    for i in range(1, n):
        pos = (pos + i) % n
        print pos + 1,

if __name__ == '__main__':
    main()


Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1,y1), (x2,y2), ..., (xn,yn). The first vertex has a coordinate x1=1, the second — x2=2, etc. Coordinates yi might be any, but should satisfy the following conditions:  there should be t humps precisely, i.e. such indexes j (2≤j≤n-1), so that yj-1<yj>yj+1,  there should be precisely t-1 such indexes j (2≤j≤n-1), so that yj-1>yj<yj+1,  no segment of a polyline should be parallel to the Ox-axis,  all yi are integers between 1 and 4. For a series of his drawings of camels with t humps Bob wants to buy a notebook, but he doesn't know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with t humps for a given number n.

The first line contains a pair of integers n and t (3≤n≤20, 1≤t≤10).

Output the required amount of camels with t humps.

In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).

import itertools
import math
import time
from builtins import input
from math import gcd as gcd
import sys
import queue
import itertools
import collections
from heapq import heappop, heappush
import random
import os
from random import randint
import decimal

# from sys import stdin, stdout
# input, print = stdin.readline, stdout.write

decimal.getcontext().prec = 18

def solve():
    n, t = map(int, input().split())

    # dp[len][kol_gorbov][vozrast?][poslednya_cifra]

    # pc_i < pc_i-1
    # dp[l][g][pg = 0][pc] += dp[l - 1][g][pg = 1][pc] + dp[l - 1][g][pg = 0][pc]
    # dp[l][g][pg = 1][pc] += 0

    # pc_i > pc_i-1
    # dp[l][g][pg = 1][pc] = dp[l - 1][g - 1][pg = 0][pc]
    # dp[l][g][pg = 0][pc] = dp[l - 1][g][pg = 0][pc]

    # answer in dp[n][t][0][1 <= i <= 4]

    dp = [[[[0 for l in range(4)] for k in range(2)] for j in range(t + 2)] for i in range(n)]

    for i in range(4):
        dp[0][0][1][i] = 1

    for l in range(1, n):
        for g in range(t + 2):
            for curr_last in range(4):
                for prev_last in range(4):
                    if curr_last == prev_last:
                        continue
                    if curr_last < prev_last:
                        dp[l][g][0][curr_last] += dp[l - 1][g][0][prev_last]
                        if g > 0 and l > 1:
                            dp[l][g][0][curr_last] += dp[l - 1][g - 1][1][prev_last]
                    else:
                        dp[l][g][1][curr_last] += dp[l - 1][g][0][prev_last] + dp[l - 1][g][1][prev_last]

    print(sum([dp[n - 1][t][0][i] for i in range(4)]))

if __name__ == '__main__':
    multi_test = 0

    if multi_test == 1:
        t = int(sys.stdin.readline())
        for _ in range(t):
            solve()
    else:
        solve()


Nick is attracted by everything unconventional. He doesn't like decimal number system any more, and he decided to study other number systems. A number system with base b caught his attention. Before he starts studying it, he wants to write in his notepad all the numbers of length n without leading zeros in this number system. Each page in Nick's notepad has enough space for c numbers exactly. Nick writes every suitable number only once, starting with the first clean page and leaving no clean spaces. Nick never writes number 0 as he has unpleasant memories about zero divide.Would you help Nick find out how many numbers will be written on the last page.

The only input line contains three space-separated integers b, n and c (2≤b<10^10^6, 1≤n<10^10^6, 1≤c≤10^9). You may consider that Nick has infinite patience, endless amount of paper and representations of digits as characters. The numbers doesn't contain leading zeros.

In the only line output the amount of numbers written on the same page as the last number.

In both samples there are exactly 4 numbers of length 3 in binary number system. In the first sample Nick writes 3 numbers on the first page and 1 on the second page. In the second sample all the 4 numbers can be written on the first page.

'''
Hala Madrid!
https://www.zhihu.com/people/li-dong-hao-78-74
'''

import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def I():
    return input()
def II():
    return int(input())
def MI():
    return map(int, input().split())
def LI():
    return list(input().split())
def LII():
    return list(map(int, input().split()))
def GMI():
    return map(lambda x: int(x) - 1, input().split())

#------------------------------FastIO---------------------------------

from bisect import *
from heapq import *
from collections import *
from functools import *
from itertools import *
from time import *
from random import *
from math import log, gcd, sqrt, ceil

'''
æåæ é²æ¢recursion limit
æ³¨æè¦ç¨yield ä¸è¦ç¨return
'''
from types import GeneratorType
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc

'''
max(***), mpå¯è½ä¸ºç©º -> error
'''
class Prime:
    def prime_sieve(self, n):
        """returns a sieve of primes >= 5 and < n"""
        flag = n % 6 == 2
        sieve = bytearray((n // 3 + flag >> 3) + 1)
        for i in range(1, int(n**0.5) // 3 + 1):
            if not (sieve[i >> 3] >> (i & 7)) & 1:
                k = (3 * i + 1) | 1
                for j in range(k * k // 3, n // 3 + flag, 2 * k):
                    sieve[j >> 3] |= 1 << (j & 7)
                for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
                    sieve[j >> 3] |= 1 << (j & 7)
        return sieve

    def prime_list(self, n):
        """returns a list of primes <= n"""
        res = []
        if n > 1:
            res.append(2)
        if n > 2:
            res.append(3)
        if n > 4:
            sieve = self.prime_sieve(n + 1)
            res.extend(3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not (sieve[i >> 3] >> (i & 7)) & 1)
        return res

    def __init__(self, n) -> None:
        self.primes = self.prime_list(n)

    def dissolve(self, num):
        '''prime factor decomposition of num'''
        lst = []
        idx = -1
        for prime in self.primes:
            if prime > num:
                break

            if num % prime == 0:
                lst.append([prime, 0])
                idx += 1

            while num % prime == 0:
                lst[idx][1] += 1
                num //= prime

        if num != 1:
            lst.append([num, 1])

        return lst

    #æ±å¾å¤§çæ°å¼çåç¹çphiç¨ï¼è¿ç»åºé´è¿æ¯ç¨å¶ä»çæ¹æ³#
    def get_phi(self, num):
        res = num
        for a, b in self.dissolve(num):
            res -= res // a
        return res

pri = Prime(10 ** 5 + 10)

def solve():
    #æ¬§æéå¹#
    b, n, c = LI()
    c = int(c)
    pw = [1 for _ in range(10 ** 6 + 10)]
    phi = pri.get_phi(c)
    #print('phi', phi)
    pw_phi = [1 for _ in range(10 ** 6 + 10)]
    for i in range(1, 10 ** 6 + 10):
        pw[i] = pw[i - 1] * 10 % c
        pw_phi[i] = pw_phi[i - 1] * 10 % phi

    #(b ^ n - b ^ (n - 1)) % c = (b - 1) * (b ^ (n - 1)) % c#

    #è®¡ç®b % c#
    b2 = 0
    lb = len(b)
    idx = 0
    for i in range(lb - 1, -1, -1):
        b2 += int(b[i]) * pw[idx]
        idx += 1
        b2 %= c
    #print('b2', b2)

    #å¤æphiä¸n-1çå³ç³»#
    sphi = str(phi)
    if len(n) > len(sphi) + 1:
        flag = True
    elif len(n) < len(sphi):
        flag = False
    else:
        if int(n) - 1 >= phi:
            flag = True
        else:
            flag = False

    #è®¡ç®n % phi(c)#
    n2 = 0
    ln = len(n)
    idx = 0
    for i in range(ln - 1, -1, -1):
        n2 += int(n[i]) * pw_phi[idx]
        idx += 1
        n2 %= phi
    #print('n2', n2)

    res = (b2 - 1) % c
    n2 = (n2 - 1) % phi
    #print('res n2', res, n2)
    if not flag:
        res *= pow(b2, n2, c)
    else:
        res *= pow(b2, n2 + phi, c)
        #print('pow', pow(b2, n2 + phi, c))
    res %= c
    if res:
        print(res)
    else:
        print(c)

for _ in range(1):solve()