TEMPLATE FUNCTIONS:

```
stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), raw_input().split(sep)))
"""
>>> stdin()
1 2 3 4
>>>[1, 2, 3, 4]
"""
joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)
"""
>>> joint(" ", [1, 2])
'1 2'
>>> joint(" ", [1, 2], [2, 3])
'1 2 2 3'
"""
def iters(): return map(int(raw_input()))
```

PROBLEMS:

==================

http://codeforces.com/contest/988/problem/B

```
n = int(input())
a = sorted((input() for _ in range(n)), key=lambda x: len(x))
v = all(a[i] in a[i+1] for i in range(n-1))
print('YES\n'+"\n".join(a) if v else 'NO')
```

==================

http://codeforces.com/contest/994/problem/A

```
R = lambda: (int, input().split())
n, a, b = R(), R(), R()
print(' '.join(map(str, (x for x in a if x in b))))
```

==================

http://codeforces.com/contest/994/problem/B

```
R = lambda: map(int, input().split())
n, k = R(),
v, t = [], [0]*n
for p, c, i in sorted(zip(R(), R(), range(n))):
t[i] = sum(v)+c
v += [c]
v = sorted(v)[::-1]
if len(v) > k:
v.pop()
print(' '.join(map(str, t)))
```

==================

http://codeforces.com/contest/754/problem/A

```
n, a = int(input()), list(map(int, input().split()))
x = next((i for i, ai in enumerate(a) if ai), None) # find index of first non-zero elements in a
if x is None:
print('NO')
elif sum(a):
print('YES', 1, '1 {}'.format(n), sep='\n')
else:
print('YES', 2, '1 {}'.format(x + 1), '{} {}'.format(x + 2, n), sep='\n')
```

==================

http://codeforces.com/contest/996/problem/B

import math
n, a, m, res = int(input()), [*(map(int,input().split()))], 10e9,-1
k = [ math.ceil((ai-i)/n) for i,ai in enumerate(a) ]
print(k.index(min(k))+1)

==================

https://codeforces.com/contest/1082/problem/B

```
_, string = raw_input(), raw_input()
start, end, res = 0, 0, 0
for char in string:
if char == "G": start += 1
else: end, start = start, 0
res = max(res, start + end + 1)
print min(res, string.count("G"))
```

==================

https://codeforces.com/contest/1082/problem/B

```
x = int(raw_input())
print " ".join(map(str, [x, x])) if x != 1 else -1
```

==================

https://codeforces.com/contest/1082/problem/B

```
n, k = map(int, raw_input().split())
numbers = map(int, raw_input().split())
res, numbers = [], [0] + sorted(list(set(numbers)))
for i in xrange(min(len(numbers) - 1, k)): print (numbers[i + 1] - numbers[i])
for _ in xrange(k - len(numbers) + 1): print 0
```

==================

https://codeforces.com/contest/1092/problem/A

```
for _ in iters():
n, k = stdin()
print joint('', ([chr(ord('a') + i%k) for i in xrange(n)]))
```

==================

*find more here https://github.com/SolbiatiAlessandro/pyComPro

Auto comment: topic has been updated by alessandrosolbiati (previous revision, new revision, compare).My eyes are bleeding.

Why? Seems like legit way to say 'sort in decreasing order'

Well, the purpose of this blog is to show some elegant python and not introduce obvious overkills :)

It can be easily reduced to

even if it might not be good for readability, the slicing expression is NOT an overkill performance wise: on a string of Len 200,

using the slicing notation is on average 10 timesfaster than any other reversion method.You can read more about it here (Timing):

https://stackoverflow.com/a/27843760

It seems that this SO question is not related to the problem. We are not performing string reverses in pure form. We are sorting integers by descending order by using standard function argument or by sorting in ascending and then reversing it.

As reverse operation is

O(N) and sorting isO(N·log(N)) it is not possible to make execution time few times worse or few times better just by varying methods of reversing.It would be great to make some benchmarking comparing

`sorted()[::-1]`

and`sort(reverse = True)`

.You are right, it's not directly related. Nonetheless, I run some basic benchmark and slicing notation still looks around 10% faster than "reverse = True" argument Interesting!

I swapped testA and testB and got another result

maybe because I am using Python2?

No, benchmarking python seems to be strongly biassed.

Swapping benchmarking order and running different benchmarks leads to completely different results. Seems like running time almost randomly gets something from -20%/+20% on running time, that depends on order of operations and start of benchmarking time. I've tried different tests locally and in codeforces/customtest, but all of them suffered from such biasses.

Strangely, sometimes customtest says that execution time of performing benchmarks of almost the same size (10

^{4}+ 1 instead of 10^{4}) leads to almost 2x execution time.That comes to some really funny things like generating 2M random ints takes more time than generating 2M random ints exactly the same way and sorting some blocks of them (that may turn out not to be so funny when you will receive TL in running contest).

I am not sure how should we benchmark python to get reliable results.

Here's another submission by kevinsogo on this problem -> http://codeforces.com/contest/989/problem/A that I found really cool.

correct way to print array and iterable in python 3:

`lambda: map(int, input().split())`

?`key=len`

`v.sort(reverse=True)`

I feel you should have used CF API rather than scraping HTML

One of the potential way is to iterate through every contest and get the list of submissions through contest.status .It returns a list of Submission objects . Only downside is that you'll need to somehow create a whitelist of the user IDs .

Auto comment: topic has been updated by alessandrosolbiati (previous revision, new revision, compare).Very nice python code short and strong but some overkills might confuse newbies :)

Your second code isn't OK.I checked it.It gave me WA

in test case 1.Correct code :

Auto comment: topic has been updated by alessandrosolbiati (previous revision, new revision, compare).I wish python will get faster in near future, because it's really good!!

I'm using C++ for about a year but still get confused sometimes.