Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
tenka1-2018 E
"""

from itertools import product
from itertools import combinations

h, w = map(int, input().split())
slili = [list(input()) for i in range(h)]

coinsetli = [set() for i in range(h+w)]
for i, j in product(range(h), range(w)):
    if slili[i][j] == '#':
        coinsetli[i+j+1].add(j-i)

coinacumdictli = [{} for i in range(h+w)]
for i in range(1, h+w):
    tmp = 0
    for j in range(-300, 301):
        if j in coinsetli[i]:
            tmp += 1
        coinacumdictli[i][j] = tmp

ansdouble = 0
for i in range(1, h+w):
    for x, y in combinations(coinsetli[i], 2):
        j = abs(x-y)
        x, y = (min(x, y), max(x, y))
        if i-j >= 1:
            ansdouble += coinacumdictli[i-j][y]+coinacumdictli[i-j][y-1] - coinacumdictli[i-j][x] - coinacumdictli[i-j][x-1]
        if i+j <= h+w-1:
            ansdouble += coinacumdictli[i+j][y]+coinacumdictli[i+j][y-1] - coinacumdictli[i+j][x] - coinacumdictli[i+j][x-1]

# repeat after reversing along the vertical axis
for i in range(h):
    slili[i].reverse()

coinsetli = [set() for i in range(h+w)]
for i, j in product(range(h), range(w)):
    if slili[i][j] == '#':
        coinsetli[i+j+1].add(j-i)

coinacumdictli = [{} for i in range(h+w)]
for i in range(1, h+w):
    tmp = 0
    for j in range(-300, 301):
        if j in coinsetli[i]:
            tmp += 1
        coinacumdictli[i][j] = tmp

for i in range(1, h+w):
    for x, y in combinations(coinsetli[i], 2):
        j = abs(x-y)
        x, y = (min(x, y), max(x, y))
        if i-j >= 1:
            ansdouble += coinacumdictli[i-j][y]+coinacumdictli[i-j][y-1] - coinacumdictli[i-j][x] - coinacumdictli[i-j][x-1]
        if i+j <= h+w-1:
            ansdouble += coinacumdictli[i+j][y]+coinacumdictli[i+j][y-1] - coinacumdictli[i+j][x] - coinacumdictli[i+j][x-1]

print(ansdouble//2)


Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
Tenka1-2018 C
"""

n = int(input())
ali = [int(input()) for i in range(n)]
ali.sort()

if n % 2 is 1:
    m = (n-1)//2
    am = ali[m]
    asmall = ali[:m]
    abig = ali[m+1:]
    if 2*am-asmall[-1]-abig[0] > 0:
        ans = am-2*sum(asmall)+2*sum(abig)-abig[0]
    else:
        ans = -am+2*sum(abig)-2*sum(asmall)+asmall[-1]
else:
    m = n//2
    asmall = ali[:m]
    abig = ali[m:]
    ans = -2*sum(asmall)+2*sum(abig)-abig[0]+asmall[-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools
import math

n = int(input())
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


# def factorial(n):
#     nn = 1
#     for i in range(2, n+1):
#         nn = nn*i
#     return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = math.factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)




Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import fractions

n, m = map(int, input().split())
s = input()
t = input()

g = fractions.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import math

n, m = map(int, input().split())
s = input()
t = input()

g = math.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)






Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import fractions

n, m = map(int, input().split())
s = input()
t = input()

g = fractions.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools

n = int(input())
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


def factorial(n):
    nn = 1
    for i in range(2, n+1):
        nn = nn*i
    return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)




Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 B
"""

import itertools
import math

n = int(input())
ali = list(map(int, input().split()))

cut = 10**9+7


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % cut


# def factorial(n):
#     nn = 1
#     for i in range(2, n+1):
#         nn = nn*i
#     return(nn)


invlist = [modInverse(i, cut) for i in range(1, n+1)]
accuminv = list(itertools.accumulate(invlist, func=lambda x, y: x+y % cut))

ans = 0
nfact = math.factorial(n)
for i in range(n):
    sump = accuminv[i]+accuminv[n-1-i] - 1
    ans += ali[i]*sump % cut

ans = ans*nfact % cut
print(ans)
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
RC110C
"""


s = list(input())
t = list(input())
n = len(s)

def exchange(a,b,c):
    if a != b and a!=c:
        return(a)
    elif a == b:
        return(c)
    elif a == c:
        return(b)

ans = 'Yes'

seen = set()
for i in range(n):
    sl = s.pop()
    tl = t.pop()
    if sl == tl:
        seen.add(sl)
    elif sl != tl and not tl in seen and not sl in seen:
        s = list(map(lambda a: exchange(a,sl,tl),s))
        seen.add(tl)
    else:
        ans = 'No'
        break
    print(s)

print(ans)





Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
RC110C
"""


s = list(input())
t = list(input())
n = len(s)

def exchange(a,b,c):
    if a != b and a!=c:
        return(a)
    elif a == b:
        return(c)
    elif a == c:
        return(b)

ans = 'Yes'

seen = set()
for i in range(n):
    sl = s.pop()
    tl = t.pop()
    if sl == tl:
        seen.add(sl)
    elif sl != tl and not tl in seen and not sl in seen:
        s = list(map(lambda a: exchange(a,sl,tl),s))
        seen.add(tl)
    else:
        ans = 'No'
        break

print(ans)
Buggy python submission (verdict: Runtime Error):


n,m = map(int,input().split())
s = list(input())
edges = [tuple(map(int,input().split())) for i in range(m)]


def addEdge(graph,u,v):
    graph[u].add(v)


def deleteNode(graph,node):
    graph.pop(node,None)

from collections import defaultdict
graphAB = defaultdict(set)
graphABopp = defaultdict(set)

connodes = set()
for i,j in edges:
    ii = min(i,j)
    jj = max(i,j)
    addEdge(graphAB,ii,jj)
    addEdge(graphABopp,jj,ii)
    if i != j:
        connodes.add(i)
        connodes.add(j)



def adjAB(node):
    Aflag = 'A' in map(lambda x:s[x-1],graphAB[node])
    Aflag = Aflag or 'A' in map(lambda x:s[x-1],graphABopp[node])
    Bflag = 'B' in map(lambda x:s[x-1],graphAB[node])
    Bflag = Bflag or 'B' in map(lambda x:s[x-1],graphABopp[node])
    if Aflag and Bflag:
        return(True)
    else:
        return(False)



visitlist = [i for i in connodes if not adjAB(i)]
#print(visitset)

while bool(visitlist):
    i = visitlist.pop()
    for j in graphAB[i]:
        graphABopp[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    for j in graphABopp[i]:
        graphAB[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    graphAB.pop(i,None)
    graphABopp.pop(i,None)

#print(graphAB)
#print(graphABopp)


if graphAB == {} and graphABopp == {}:
    print('No')
else:
    print('Yes')





Fixed submission:
n,x = map(int,input().split())
ass = list(map(int,input().split()))
ass.sort()

ans = 0
acm = 0
for i in ass:
    acm += i
    if x >= acm:
        ans +=1

if acm < x:
    ans -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
    for jj in removelist:
        rails.pop(jj)



for a in ansli:
    print(a)


Fixed submission:
a,b = map(int,input().split())

print((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in s:
    if i != '1':
        ans = int(i)
        break

print (i)


Fixed submission:
a,b = map(int,input().split())

print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

for i,a in enumerate(s):
    if (a != '1' and k>i) or k==i:
        ans = int(a)
        break

print (ans)


Fixed submission:
s = input()
k = int(input())

for i,a in enumerate(s):
    if (a != '1' ) or k==i+1:
        ans = int(a)
        break

print (ans)
Buggy python submission (verdict: Runtime Error):
import math

t = int(input())
qs=[list(map(int,input().split())) for i in range(t)]

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = math.gcd(b2,b-d)
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))



Fixed submission:



t = int(input())
qs=[list(map(int,input().split())) for i in range(t)]

def computeGCD(x, y):
   while(y):
       x, y = y, x % y
   return x

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = abs(computeGCD(b2,b-d))
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC025 B
"""

import itertools
from functools import reduce

cut = 998244353


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


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        stmp = s0-q*s1
        r0, s0 = r1, s1
        r1, s1 = rtmp, stmp
    return s0 % b


def GCD(a, b):
    r0, r1 = a, b
    while r1 != 0:
        r0, r1 = r1, r0 % r1
    return r0


fact = [1]
tmp = 1
for i in range(1, n+1):
    tmp = tmp*i % cut
    fact.append(tmp)


def binom(nn, kk):
    return ((fact[nn]*modInverse(fact[kk], cut) % cut)*modInverse(fact[nn-kk], cut)) % cut


a, b = max(a, b), min(a, b)
gcdab = GCD(a, b)
ahat, bhat = a//gcdab, b//gcdab
flag = False
for i in range(0,bhat+1):
    if (k-i*a) % b == 0:
        iinit = i
        flag = True
        break

if not flag:
    print(0)
    exit()

ans = 0
for i in range(iinit, min(n+1, k//a+1), bhat):
    ib, bmod = divmod(k-i*a, b)
    if bmod == 0 and ib <= n:
        ans = (ans+binom(n, i)*binom(n, ib)) % cut

print(ans)



Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC025 B
"""

import itertools
from functools import reduce

cut = 998244353


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


def modInverse(a, b, divmod=divmod):
    r0, r1, s0, s1 = a, b, 1, 0
    while r1 != 0:
        q, rtmp = divmod(r0, r1)
        s0, s1 = s1, s0-q*s1
        r0, r1 = r1, rtmp
    return s0 % b


# def modInverse2(a, b, divmod=divmod):
#     b2 = b-2
#     tmp0 = a
#     tmp1 = 1
#     while b2 != 0:
#         if b2 & 0b1:
#             tmp1 = tmp1*tmp0
#         tmp0 = tmp0*tmp0 % b
#         b2 = b2 >> 1
#     return(tmp1 % b)


def GCD(a, b):
    r0, r1 = a, b
    while r1 != 0:
        r0, r1 = r1, r0 % r1
    return r0


binom = [1, n]
tmp = n
for i in range(1, n):
    tmp = (tmp*(n-i) % cut)*modInverse(i+1, cut) % cut
    binom.append(tmp)


a, b = max(a, b), min(a, b)
gcdab = GCD(a, b)
ahat, bhat = a//gcdab, b//gcdab
flag = False
for i in range(0, bhat+1):
    if (k-i*a) % b == 0:
        iinit = i
        flag = True
        break


if not flag:
    print(0)
    exit()

ans = 0
for i in range(iinit, min(n+1, k//a+1), bhat):
    ib, bmod = divmod(k-i*a, b)
    if bmod == 0 and ib <= n:
        ans = (ans+binom[i]*binom[ib]) % cut

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

sumtally =[sumli.count(x) for x in set(sumli)]

for j in sumtally:
    acum = acum+(j*(j-1))//2

print(acum)


Fixed submission:
from collections import Counter

n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

sumc = Counter(sumli)

for j in list(sumc):
    acum = acum+(sumc[j]*(sumc[j]-1))//2

print(acum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

while len(sumli)!=0:
    s=sumli[0]
    ss=sumli.count(s)
    acum = acum+(ss*(ss-1))//2
    for x in range(ss):
        sumli.remove(s)

print(acum)


Fixed submission:
from collections import Counter

n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

sumc = Counter(sumli)

for j in list(sumc):
    acum = acum+(sumc[j]*(sumc[j]-1))//2

print(acum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

while len(sumli)!=0:
    s=sumli[0]
    ss=sumli.count(s)
    acum = acum+(ss*(ss-1))//2
    sumli= [x for x in sumli if x != s]

print(acum)


Fixed submission:
from collections import Counter

n = int(input())
ali = list(map(int,input().split()))

sumli = [0]
sum = 0
acum = 0

for i in ali:
    sum = sum + i
    sumli.append(sum)

sumc = Counter(sumli)

for j in list(sumc):
    acum = acum+(sumc[j]*(sumc[j]-1))//2

print(acum)
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC023 B
"""

from itertools import product

n = int(input())
sli = [input() for i in range(n)]

ans = 0
for k in range(n):
    if all((sli[i][j] == sli[(j+k) % n][(i-k) % n] for i, j in product(range(n), repeat=2))):
        ans += n

print(ans)



Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC023 B
"""

from itertools import product

n = int(input())
sli = [input() for i in range(n)]

ans = 0
for k in range(n):
    if all((sli[i][j] == sli[(j+k) % n][(i-k) % n] for i, j in product(range(n), repeat=2))):
        ans += n

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc012 C
"""

from collections import defaultdict

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

graph = defaultdict(list)
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

q = int(input())
qlist = [tuple(map(int, input().split())) for i in range(q)]
qlist.reverse()

dp = [[-1]*11 for i in range(n+1)]
col = [0]


def updatedp(v, t, d):
    if dp[v][d] == -1:
        dp[v][d] = t
        if d > 0:
            updatedp(v, t, d-1)
            for u in graph[v]:
                updatedp(u, t, d-1)


t = 0
for v, d, c in qlist:
    col.append(c)
    updatedp(v, t, d)
    t += 1

for i in range(1, n+1):
    print(col[dp[i][0]+1])


Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc012 C
"""

from collections import defaultdict

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

graph = defaultdict(list)
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

q = int(input())
qlist = [tuple(map(int, input().split())) for i in range(q)]
qlist.reverse()

dp = [[-1]*11 for i in range(n+1)]
col = [0]


def updatedp(v, t, d):
    if dp[v][d] == -1:
        dp[v][d] = t
        if d > 0:
            updatedp(v, t, d-1)
            for u in graph[v]:
                updatedp(u, t, d-1)


t = 0
for v, d, c in qlist:
    col.append(c)
    updatedp(v, t, d)
    t += 1

for i in range(1, n+1):
    print(col[dp[i][0]+1])
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

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

if m == 1:
    print(ali[0])
    print(2)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a % 2 == 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)


print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))


Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

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

if m == 1 and ali[0] == 1:
    print(1)
    print(1)
    print(1)
    exit()

if m == 1:
    print(ali[0])
    print(2)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a % 2 == 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 0:
    lm = c[0]
    del c[0]
    rm = c.pop()

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)


print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))

Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

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

if m == 1:
    print(ali[0])
    print(1)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a & 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)


print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))


Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

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

if m == 1 and ali[0] == 1:
    print(1)
    print(1)
    print(1)
    exit()

if m == 1:
    print(ali[0])
    print(2)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a % 2 == 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 0:
    lm = c[0]
    del c[0]
    rm = c.pop()

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)


print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
p=list(s.split())
s1=0
s2=0
for i in range(0,n)
  s1=s1+int(p[i])
  s2=s2+(int(p[i])*int(p[i]))
k= ((s1**2)-s2)//2
k=k%1000000007

print(k)


Fixed submission:
n=int(input())
s=input()
p=list(s.split())
s1=0
s2=0
for i in range(0,n):
  s1=s1+int(p[i])
  s2=s2+(int(p[i])*int(p[i]))
k= ((s1**2)-s2)//2
k=k%1000000007
print(k)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
p=list(s.split())
s1=0
s2=0
for i in range(0,n)
  s1=s1+int(p[i])
  s2=s2+(int(p[i])*int(p[i]))
k= ((s1**2)-s2)//2
k=k%1000000007
//abcdef
print(k)


Fixed submission:
n=int(input())
s=input()
p=list(s.split())
s1=0
s2=0
for i in range(0,n):
  s1=s1+int(p[i])
  s2=s2+(int(p[i])*int(p[i]))
k= ((s1**2)-s2)//2
k=k%1000000007
print(k)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))
score = []
wknum = 1
for i  in range(k):
    wknum *= A[i]

score.append(wknum)

for i in range(n - k):
    wknum //= A[i]
    wknum *= A[k + i]
    score.append(wknum)
    if score[i + 1] <= score[i]:
        print('No')
    else:
        print('Yes')


Fixed submission:
import numpy as np

n, k = map(int, input().split())
A = np.array(input().split(), dtype = np.int64)
score = np.array([0 for i in range(n- k + 1)], dtype = np.int64)
wknum = 1
for i  in range(k):
    wknum *= A[i]

for i in range(n - k):
    wknum //= A[i]
    wknum *= A[k + i]
    if A[i] >= A[k + i]:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))
score = []
cnt = 0

for i in range(n - k + 1):
    wknum = 1
    point = (k + i -1)
    for j in range(k):
        wknum *= A[point - j]
    score.append(wknum)
    if cnt == 0:
        cnt += 1
        continue
    else:
        if score[i] <= score[i -1]:
            print('No')
        else:
            print('Yes')


Fixed submission:
import numpy as np

n, k = map(int, input().split())
A = np.array(input().split(), dtype = np.int64)
score = np.array([0 for i in range(n- k + 1)], dtype = np.int64)
wknum = 1
for i  in range(k):
    wknum *= A[i]

for i in range(n - k):
    wknum //= A[i]
    wknum *= A[k + i]
    if A[i] >= A[k + i]:
        print('No')
    else:
        print('Yes')