Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

p = [a for a in A if a>=0]
n = [a for a in A if a<0]

ans = []
if len(n) == 0:
    p.sort()
    x = p.pop(0)
    y = p.pop()
    ans.append('{} {}'.format(x,y))
    n.append(x-y)
if len(p) == 0:
    n.sort()
    x = n.pop()
    y = n.pop(0)
    ans.append('{} {}'.format(x,y))
    p.append(x-y)

x = n.pop()
while len(p)>1:
    y = p.pop()
    ans.append('{} {}'.format(x,y))
    x -= y
y = x
x = p[0]
ans.append('{} {}'.format(x,y))
x -= y
while n:
    y = n.pop()
    ans.append('{} {}'.format(x,y))
    x -= y

print(x)
for s in ans:
    print(s)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

if N == 2:
    print(max(A)-min(A))
    print('{} {}'.format(max(A),min(A)))
else:
    p = [a for a in A if a>=0]
    n = [a for a in A if a<0]

    ans = []
    if len(n) == 0:
        p.sort()
        x = p.pop(0)
        y = p.pop()
        ans.append('{} {}'.format(x,y))
        n.append(x-y)
    if len(p) == 0:
        n.sort()
        x = n.pop()
        y = n.pop(0)
        ans.append('{} {}'.format(x,y))
        p.append(x-y)

    x = n.pop()
    while len(p)>1:
        y = p.pop()
        ans.append('{} {}'.format(x,y))
        x -= y
    y = x
    x = p[0]
    ans.append('{} {}'.format(x,y))
    x -= y
    while n:
        y = n.pop()
        ans.append('{} {}'.format(x,y))
        x -= y

    print(x)
    for s in ans:
        print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop,heappush
l = []
r = []
Q = int(input())
ans = 0
l_s = 0
r_s = 0
_,m,b = map(int,input().split())
ans += b
n = 0
for i in range(1,Q):
    s = input()
    if s != '2':
        _,a,b = map(int,s.split())
        ans += b
        if n == 0:
            c,d = sorted([m,a])
            heappush(l,-c)
            heappush(r,d)
            l_s += c
            r_s += d
            m1 = c
        else:
            c,d = heappop(l),heappop(r)
            l_s += c
            r_s -= d
            c = -c
            if n%2 == 1:
                c,m,d = sorted([a,c,d])
                heappush(l,-c)
                heappush(r,d)
                l_s += c
                r_s += d
            else:
                c,m1,m2,d = sorted([m,a,c,d])
                heappush(l,-c)
                heappush(l,-m1)
                heappush(r,d)
                heappush(r,m2)
                l_s += c
                r_s += d
                l_s += m1
                r_s += m2
        n += 1
    else:
        if n == 0:
            print('{} {}'.format(m,ans))
        elif n == 1:
            print('{} {}'.format(m1,r_s-l_s+ans))
        elif n%2 == 0:
            print('{} {}'.format(m,r_s-l_s+ans))
        else:
            print('{} {}'.format(m1,r_s-l_s+ans))

Fixed submission:
from heapq import heappop,heappush
l = []
r = []
Q = int(input())
ans = 0
l_s = 0
r_s = 0
_,m,b = map(int,input().split())
ans += b
n = 0
for i in range(1,Q):
    s = input()
    if s != '2':
        _,a,b = map(int,s.split())
        ans += b
        if n == 0:
            c,d = sorted([m,a])
            heappush(l,-c)
            heappush(r,d)
            l_s += c
            r_s += d
            m1 = c
        else:
            c,d = heappop(l),heappop(r)
            l_s += c
            r_s -= d
            c = -c
            if n%2 == 1:
                c,m,d = sorted([a,c,d])
                heappush(l,-c)
                heappush(r,d)
                l_s += c
                r_s += d
            else:
                c,m1,m2,d = sorted([m,a,c,d])
                heappush(l,-c)
                heappush(l,-m1)
                heappush(r,d)
                heappush(r,m2)
                l_s += c
                r_s += d
                l_s += m1
                r_s += m2
        n += 1
    else:
        if n == 0:
            print('{} {}'.format(m,ans))
        elif n == 1:
            print('{} {}'.format(m1,r_s-l_s+ans))
        elif n%2 == 0:
            print('{} {}'.format(m,r_s-l_s+ans))
        else:
            print('{} {}'.format(m1,r_s-l_s+ans))
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
ans = 0

for n in range(1,min(K,N+1)):
    ans += 2**(20-math.ceil(math.log2(K/n)))

ans /= 2**20

ans += max(N-K+1,0)
ans /= N

print(ans)

Fixed submission:
import math
N,K = map(int,input().split())
ans = 0

for n in range(1,min(K,N+1)):
    ans += 2**(20-math.ceil(math.log2(K/n)))

ans /= 2**20

ans += max(N-K+1,0)
ans /= N

print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

def eratosthenes(n):
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime

N = int(input())
A = [int(input()) for i in range(N+1)]
A.reverse()
g = A[0]
for a in A:
     g = gcd(g,a)
d = prime_decomposition(g)
ans = [p for p in d]

prime = eratosthenes(N+2)

for p in prime:
    for n in range(p-1):
        s = 0
        for k in range(int((N-n)/(p-1))+1):
            s += A[n+k*(p-1)]
            s %= p
        if s != 0:
            break
    if s == 0:
        ans.append(p)

ans = list(set(ans))
ans.sort()

for p in ans:
    print(p)


Fixed submission:
N = int(input())
S = input()
w = [0]*N
b = [0]*N
s = S[::-1]
for i in range(N):
    b[i] = b[i-1]
    if S[i] == '#':
        b[i] += 1
    w[i] = w[i-1]
    if s[i] == '.':
        w[i] += 1

m = min(w[N-1],b[N-1])
for i in range(N-1):
    m = min(m,b[i]+w[N-i-2])

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
w = [0]*N
b = [0]*N

for i in range(N):
    b[i] = b[i-1]
    if S[i] == '#':
        b[i] += 1
    w[i] = w[i-1]
    if S[::-1][i] == '.':
        w[i] += 1

m = min(w[N-1],b[N-1])
for i in range(N-1):
    m = min(m,b[i]+w[N-i-2])

print(m)

Fixed submission:
N = int(input())
S = input()
w = [0]*N
b = [0]*N
s = S[::-1]
for i in range(N):
    b[i] = b[i-1]
    if S[i] == '#':
        b[i] += 1
    w[i] = w[i-1]
    if s[i] == '.':
        w[i] += 1

m = min(w[N-1],b[N-1])
for i in range(N-1):
    m = min(m,b[i]+w[N-i-2])

print(m)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
import bisect
mod = 10**9+7
N = int(input())
S = ''
s = ''
for i in range(N):
    c = input()
    if s != c:
        S = S+c
    s = c

d = defaultdict(lambda:[])
for i in range(len(S)):
    d[S[i]].append(i)

val = [0]*(len(S)+1)
val[-1]=1
def rec(n):
    if val[n] != 0:
        return val[n]
    s = S[n]
    res = rec(n+1)
    l = d[s]
    i = bisect.bisect(l,n)
    for j in range(i,len(l)):
        res += rec(l[j]+1)
        res %= mod
    val[n]=res
    return res
print(rec(0))

Fixed submission:
from collections import defaultdict
import bisect
mod = 10**9+7
N = int(input())
S = []
s = ''
for i in range(N):
    c = input()
    if s != c:
        S.append(c)
    s = c

d = defaultdict(lambda:[])
dd = defaultdict(lambda:{})
dcum = defaultdict(lambda:[0])
for i in range(len(S)):
    d[S[i]].append(i)
    dd[S[i]][i] = len(d[S[i]])-1
    dcum[S[i]].append(0)
n = len(S)
dp = [0]*(n+1)
dp[-1]=1

for i in range(n-1,-1,-1):
    l = d[S[i]]
    j = dd[S[i]][i]+1
    dp[i] += dp[i+1]
    dp[i] += dcum[S[i]][j]
    dp[i] %= mod
    dcum[S[i]][j-1] += dp[i+1]+dcum[S[i]][j]
print(dp[0])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import bisect
mod = 10**9+7
N = int(input())
S = ''
s = ''
for i in range(N):
    c = input()
    if s != c:
        S = S+c
    s = c

d = defaultdict(lambda:[])
for i in range(len(S)):
    d[S[i]].append(i)

val = [0]*(len(S)+1)
val[-1]=1
def rec(n):
    if val[n] != 0:
        return val[n]
    s = S[n]
    res = rec(n+1)
    l = d[s]
    i = bisect.bisect(l,n)
    for j in range(i,len(l)):
        res += rec(l[j]+1)
        res %= mod
    val[n]=res
    return res
print(rec(0))

Fixed submission:
from collections import defaultdict
import bisect
mod = 10**9+7
N = int(input())
S = []
s = ''
for i in range(N):
    c = input()
    if s != c:
        S.append(c)
    s = c

d = defaultdict(lambda:[])
dd = defaultdict(lambda:{})
dcum = defaultdict(lambda:[0])
for i in range(len(S)):
    d[S[i]].append(i)
    dd[S[i]][i] = len(d[S[i]])-1
    dcum[S[i]].append(0)
n = len(S)
dp = [0]*(n+1)
dp[-1]=1

for i in range(n-1,-1,-1):
    l = d[S[i]]
    j = dd[S[i]][i]+1
    dp[i] += dp[i+1]
    dp[i] += dcum[S[i]][j]
    dp[i] %= mod
    dcum[S[i]][j-1] += dp[i+1]+dcum[S[i]][j]
print(dp[0])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
A,B = map(int,input().split())

def count(n,k):
    n = bin(n)[2:]
    n = '0'+n
    res = 0
    if n[-k-1]=='1':
        if k==0:
            res += 1
        else:
            res += (int(n[-1])+1)%2
    if k == 0:
        res = (res+int(n[-2]))%2
    return res

def f(n):
    d = defaultdict(lambda:0)
    for k in range(len(bin(n)[2:])):
        d[k] = count(n,k)
    return d

d_a = f(A-1)
d_b = f(B)
ans = ''
for i in range(40):
    ans = str((d_a[i]+d_b[i])%2) + ans
ans = int(ans,2)
print(ans)

Fixed submission:
from collections import defaultdict
A,B = map(int,input().split())

def count(n,k):
    n = bin(n)[2:]
    n = '0'+n
    res = 0
    if n[-k-1]=='1':
        if k==0:
            res += 1
        else:
            res += (int(n[-1])+1)%2
    if k == 0:
        res = (res+int(n[-2]))%2
    return res

def f(n):
    if n < 0:
        n = 0
    d = defaultdict(lambda:0)
    for k in range(len(bin(n)[2:])):
        d[k] = count(n,k)
    return d

d_a = f(A-1)
d_b = f(B)
ans = ''
for i in range(40):
    ans = str((d_a[i]+d_b[i])%2) + ans
ans = int(ans,2)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,inpit().split())
if B%A==0:
    print(A+B)
else:
    print(B-A)

Fixed submission:
A,B = map(int,input().split())
if B%A==0:
    print(A+B)
else:
    print(B-A)
Buggy python submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
from scipy import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(N):
    ans = gcd(ans,A[i])
print(ans)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
INF = float('inf')
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-INF]*(N+1)
dp[0] = 0
for a in A:
    if c[a] <= N:
        dp[c[a]] = 1

for i in range(N+1):
    for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1)

ans = ''
n = N
for a in A:
    while dp[n] == dp[n-c[a]]+1:
        n -= c[a]
        ans = ans + str(a)
print(ans)

Fixed submission:
d = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
d_ = {}
for i in range(M):
    d_[d[A[i]]] = A[i]
diff = [(d_[key],key) for key in d_]
diff.sort()

DP = ['']*(10**4+1)
for a,l in diff:
    DP[l] = str(a)
    
for i in range(N+1):
    for a,l in diff:
        if i-l >= 0:
            if len(DP[i-l])+1>=len(DP[i]) and DP[i-l]!='':
                    DP[i] = str(a)+DP[i-l]

ans = list(DP[N])
ans.sort()
ans.reverse()
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cost = [0,2,5,5,4,5,6,3,7,6]
dp = ['']*(N+1)
for a in A:
    dp[cost[a]] = str(a)
for i in range(N+1):
    for a in A:
        if dp[i-cost[a]] != '':
            if len(dp[i]) <= len(dp[i-cost[a]]+str(a)):
                dp[i] = dp[i-cost[a]]+str(a)
        ans = dp[N]
ans = list(map(int,list(ans)))
ans.sort(reverse=True)
print(''.join(list(map(str,ans))))

Fixed submission:
d = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
d_ = {}
for i in range(M):
    d_[d[A[i]]] = A[i]
diff = [(d_[key],key) for key in d_]
diff.sort()

DP = ['']*(10**4+1)
for a,l in diff:
    DP[l] = str(a)
    
for i in range(N+1):
    for a,l in diff:
        if i-l >= 0:
            if len(DP[i-l])+1>=len(DP[i]) and DP[i-l]!='':
                    DP[i] = str(a)+DP[i-l]

ans = list(DP[N])
ans.sort()
ans.reverse()
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
d = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
d_ = {}
for i in range(M):
    d_[d[A[i]]] = A[i]
diff = [(d_[key],key) for key in d_]
diff.sort()

DP = ['']*(N+1)
for a,l in diff:
    DP[l] = str(a)
    
for i in range(N+1):
    for a,l in diff:
        if i-l >= 0:
            if len(DP[i-l])+1>=len(DP[i]) and DP[i-l]!='':
                    DP[i] = str(a)+DP[i-l]

ans = list(DP[N])
ans.sort()
ans.reverse()
ans = ''.join(ans)
print(ans)

Fixed submission:
d = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
d_ = {}
for i in range(M):
    d_[d[A[i]]] = A[i]
diff = [(d_[key],key) for key in d_]
diff.sort()

DP = ['']*(10**4+1)
for a,l in diff:
    DP[l] = str(a)
    
for i in range(N+1):
    for a,l in diff:
        if i-l >= 0:
            if len(DP[i-l])+1>=len(DP[i]) and DP[i-l]!='':
                    DP[i] = str(a)+DP[i-l]

ans = list(DP[N])
ans.sort()
ans.reverse()
ans = ''.join(ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td.sort(key=lambda x:-x[1])
td = [(x[0]-1,x[1]) for x in td]
t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
for i in range(K):
    t[td[:K][i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if t[td[i][0]] == 1:
        if d_top[td[i][0]] == 0:
            d_top[td[i][0]] = td[i][1]
        else:
            d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])

ans = len(t_used)**2+sum(d_top)
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))
ans += d_rest_cum[-1]

for k in range(min(len(d_rest),len(d_candi))):
    ans = max(ans + (k+1)*(k+1+2*len(t_used)) + d_candi_cum[k] - d_rest_cum[k],ans)

print(ans)

Fixed submission:
a,b,c = map(int,input().split())
print(a*b*c//2//max(a,b,c))
Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

dp = [[-INF]*(W+1) for _ in range(N+1)]
dp[0][0]=0
for i in range(N):
    for j in range(W+1):
        if j-wv[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j-wv[i][0]]+wv[i][1],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(max(dp[-1]))

Fixed submission:
N,W = map(int,input().split())
c = [tuple(map(int,input().split())) for i in range(N)]
DP = [[0 for i in range(W+1)] for i in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w-c[i][0] < 0:
            DP[i+1][w] = DP[i][w]
        else:
            DP[i+1][w] = max(DP[i][w-c[i][0]]+c[i][1],DP[i][w])
print(DP[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
c = [tuple(map(int,input().split())) for i in range(N)]
DP = [[0 for i in range(W+1)] for i in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w-c[i][0] < 0:
            DP[i+1][w] = DP[i][w]
        else:
            DP[i+1][w] = max(DP[i][w-c[i][0]]+c[i][1],DP[i][w])
print(DP[N][W])

Fixed submission:
N,W = map(int,input().split())
c = [tuple(map(int,input().split())) for i in range(N)]
DP = [[0 for i in range(W+1)] for i in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w-c[i][0] < 0:
            DP[i+1][w] = DP[i][w]
        else:
            DP[i+1][w] = max(DP[i][w-c[i][0]]+c[i][1],DP[i][w])
print(DP[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(float,input().split()))
DP = [[0 for i in range((N+1)//2)] for i in range(N)]
DP[0][0] = p[0]
if N > 1:
    DP[0][1] = 1-p[0]
for i in range(1,N):
    for j in range((N+1)//2):
        DP[i][j] += p[i]*DP[i-1][j]
        if j != 0:
            DP[i][j] += (1-p[i])*DP[i-1][j-1]
print(sum(DP[-1]))

Fixed submission:
N = int(input())
p = list(map(float,input().split()))
DP = [[0 for i in range((N+1)//2)] for i in range(N)]
DP[0][0] = p[0]
if N > 1:
    DP[0][1] = 1-p[0]
for i in range(1,N):
    for j in range((N+1)//2):
        DP[i][j] += p[i]*DP[i-1][j]
        if j != 0:
            DP[i][j] += (1-p[i])*DP[i-1][j-1]
print(sum(DP[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
N = int(input())
a = list(map(int,input().split()))

cum = [0]*(N+1)
for i in range(N):
    cum[i] = cum[i-1]+a[i]

dp = [[-1]*N for _ in range(N)]
for i in range(N):
    dp[i][i] = a[i]

def cal(i,j):
    if dp[i][j] == -1:
        dp[i][j] = cum[j]-cum[i-1]-min(cal(i+1,j),cal(i,j-1))
    return dp[i][j]

print(2*cal(0,N-1)-cum[N-1])

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

dp = [[0]*(N+1) for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(i, N):
        dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1])

print(dp[0][N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))

cum = [0]*(N+1)
for i in range(N):
    cum[i] = cum[i-1]+a[i]

dp = [[-1]*N for _ in range(N)]
for i in range(N):
    dp[i][i] = a[i]

def cal(i,j):
    if dp[i][j] == -1:
        dp[i][j] = cum[j]-cum[i-1]-min(cal(i+1,j),cal(i,j-1))
    return dp[i][j]

print(2*cal(0,N-1)-cum[N-1])

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

dp = [[0]*(N+1) for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(i, N):
        dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1])

print(dp[0][N-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input()))
print(min(a))

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
Mod = 998244353

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

a.sort()

ans = 1
for i in range(N):
    ans *= gcd(a[i],i)
    ans %= Mod

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print('Yes')
    print('1 1')
    print('1 1)
elif N == 3:
    print('Yes')
    print('2 1 2')
    print('2 3 1')
    print('2 2 3')
else:
    print('No')

Fixed submission:
N = int(input())
Nlist = [k*(k-1)//2 for k in range(10**3)]
if N not in Nlist:
    print('No')
    exit()
print('Yes')
k = Nlist.index(N)
S = [[0]*i for i in range(k)]
S[0] = [i+1 for i in range(k-1)]
for i in range(k-1):
    S[i+1] = [S[j][i] for j in range(i+1)]
    S[i+1] += [S[i][k-2]+j+1 for j in range(k-1-(i-1))]
print(k)
S = [[str(S[i][j]) for j in range(k-1)] for i in range(k)]
for i in range(k):
    print(' '.join([str(k-1)]+S[i]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
  print('Yes')
  print('1 1')
  print('1 1)
elif N == 3:
  print('Yes')
  print('2 1 2')
  print('2 3 1')
  print('2 2 3')
else:
  print('No')

Fixed submission:
N = int(input())
Nlist = [k*(k-1)//2 for k in range(10**3)]
if N not in Nlist:
    print('No')
    exit()
print('Yes')
k = Nlist.index(N)
S = [[0]*i for i in range(k)]
S[0] = [i+1 for i in range(k-1)]
for i in range(k-1):
    S[i+1] = [S[j][i] for j in range(i+1)]
    S[i+1] += [S[i][k-2]+j+1 for j in range(k-1-(i-1))]
print(k)
S = [[str(S[i][j]) for j in range(k-1)] for i in range(k)]
for i in range(k):
    print(' '.join([str(k-1)]+S[i]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
C = [list(map(int,input().split())) for i in range(N)]
C.sort()
ans0 = 0
ans1 = 0
ans2 = 0
AM = []
Am = []
BM = []
Bm = []
for i in range(N):
    ans0 += C[i][0]
    ans1 += C[i][1]
    Min = min(C[i][0],C[i][1])
    Max = max(C[i][0],C[i][1])
    ans2 += Min
    if Min == C[i][0]:
        Am.append(C[i][0])
        BM.append(C[i][1])
    else:
        AM.append(C[i][0])
        Bm.append(C[i][1])
ans3 = sum(sorted(A+B)[:N])
if ans3 == ans2:
    ans3 += min(min(AM)-max(Am),min(BM)-max(Bm))
    
ans = min(ans0,ans1,ans3)
print(ans)

Fixed submission:
N = int(input())
A = []
B = []
Sa = 0
Sb = 0
for i in range(N):
    a,b = map(int,input().split())
    A.append([a,i])
    B.append([b,i])
    Sa += a
    Sb += b
C = sorted(A+B)
ind = []
ans = 0
for i in range(N):
    ind.append(C[i][1])
    ans += C[i][0]
ind = set(ind)
if len(ind) == N:
    if C[N-1][1] != C[N][1]:
        ans += C[N][0]-C[N-1][0]
    else:
        ans += min(C[N][0]-C[N-2][0],C[N+1][0]-C[N-1][0])
ans = min(Sa,Sb,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
def next(i,j):
    if i%2==0:
        if j == W-1:
            return i+1,j
        else:
            return i,j+1
    else:
        if j == 0:
            return i+1,j
        else:
            return i,j-1
ans = []
i,j = 0,0
while i < H:
    i_,j_ = next(i,j)
    if a[i][j]%2==1:
        a[i][j] -= 1
        a[i_][j_] += 1
        ans.append('{} {} {} {}'.format(i+1,j+1,i_+1,j_+1))
    i,j = i_,j_
print(len(ans))
for s in ans:
    print(s)

Fixed submission:
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]
def next(i,j):
    if i%2==0:
        if j == W-1:
            return i+1,j
        else:
            return i,j+1
    else:
        if j == 0:
            return i+1,j
        else:
            return i,j-1
ans = []
i,j = 0,0
while True:
    i_,j_ = next(i,j)
    if i_ == H:
        break
    if a[i][j]%2==1:
        a[i][j] -= 1
        a[i_][j_] += 1
        ans.append('{} {} {} {}'.format(i+1,j+1,i_+1,j_+1))
    i,j = i_,j_
print(len(ans))
for s in ans:
    print(s)