Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
Q = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    op = Q[i]
    if len(op) == 1:
        s = s[::-1]
    elif op[1] == "1":
        s = op[2] + s
    else:
        s = s + op[2]
print(s)


Fixed submission:
import collections

s = collections.deque(list(input()))
q = int(input())
rev = 0 #反転するなら1そうでないなら0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1) #revが入力されるたびに1か0に変更される
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev: #反転される場合逆向きに出力されなければいけない 
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
Q = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    op = Q[i]
    if len(op) == 1:
        s = s[::-1]
    elif op[1] == "1":
        s = op[2] + s
    else:
        s = s + op[2]
print(s)


Fixed submission:
import collections

s = collections.deque(list(input()))
q = int(input())
rev = 0 #反転するなら1そうでないなら0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1) #revが入力されるたびに1か0に変更される
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev: #反転される場合逆向きに出力されなければいけない 
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))
Buggy python submission (verdict: Runtime Error):
n = input()
print(int(n/2)+(n%2))

Fixed submission:
n = int(input())
print(int(n/2)+int(n%2))
Buggy python submission (verdict: Runtime Error):
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for number in b:
    for i in range(3):
        if number in a[i]:
            a[i][a[i].index(number)] = 0
if a[0][0] == a[1][1] == a[2][2] == 0 or a[2][0] == a[1][1] == a[0][2] == 0:
    print('Yes')
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes')
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    	else:
        	print('No')


Fixed submission:
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for number in b:
    for i in range(3):
        if number in a[i]:
            a[i][a[i].index(number)] = 0
if a[0][0] == a[1][1] == a[2][2] == 0 or a[2][0] == a[1][1] == a[0][2] == 0:
    print('Yes')
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes')
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    else:
        print('No')

Buggy python submission (verdict: Runtime Error):
a = [list(map(int,input().split())) for i in range(3)] #ビンゴ表
n = int(input()) #回数
b = [int(input()) for i in range(n)] #出た数字

for number in b: #出た目を順番に確認
    for i in range(3):
        if number in a[i]: #numberがビンゴ表にあるかチェック
            a[i][a[i].index(number)] = 0 #i行のnumberに該当する要素を0に書き変え

if a[0][0] == a[1][1] == a[2][2] == 0 or a[2][0] == a[1][1] == a[0][2] == 0:
    print('Yes')　#斜めのビンゴをチェック
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes') #行のビンゴをチェック
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes') #列のビンゴをチェック
            break
        else:
            print('No')


Fixed submission:
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for number in b:
    for i in range(3):
        if number in a[i]:
            a[i][a[i].index(number)] = 0
if a[0][0] == a[1][1] == a[2][2] == 0 or a[2][0] == a[1][1] == a[0][2] == 0:
    print('Yes')
else:
    for i in range(3):
        if a[i][0] == a[i][1] == a[i][2] == 0:
            print('Yes')
            break
        elif a[0][i] == a[1][i] == a[2][i] == 0:
            print('Yes')
            break
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
n, a, b = map(int, input().split())
a1 = factorial(n) / factorial(a) / factorial(n - a)
b1 = factorial(n) / factorial(b) / factorial(n - b)
ans = 2**n - a1 - b1 - 1 
print(int(ans)%1000000007)

Fixed submission:
def nCr(n,r):
    num = den = 1

    for i in range(r):
        num = (num*(n-i)) % MOD #n*(n-1)*...*(n-r)
        den = (den*(i+1)) % MOD #1*2*...*r
    
    return (num * pow(den, MOD-2, MOD)) % MOD
    #フェルマーの小定理を使うことで1/denを作っている
    #最終的に(n*...*(n-r))/(1*...*r)

MOD = 10**9 + 7
n, a, b = map(int, input().split())
x = pow(2, n, MOD)

print((x - nCr(n,a) - nCr(n,b) -1 )% MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numbers = list(map(int, input().split()))
for i in range(n):
  for j in range(i+1, n-i):
    if numbers[i] == numbers[j]:
      print("NO")
      exit()
else:
  print("YES")


Fixed submission:
n = int(input())
numbers = list(map(int, input().split()))
if len(numbers) == len(set(numbers)):
    print("YES")
else:
     print("NO")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
num = list(map(int, input().split()))
import numpy
res = numpy.cumsum(num)
maxRange = 0
for i in range(n-k+1):
  r = res[i+k-1] - res[i]
  if maxRange < r:
    maxRange = max(r, maxRange)
    p, q = i, i+k-1
ans = 0
for j in range(p, q+1):
  ans += (num[j]-1)//2　
print(ans)


Fixed submission:
import itertools
n, k = map(int, input().split())
num = list(map(int, input().split()))
sumNum = [(1+i)/2 for i in num]
res = [0] + list(itertools.accumulate(sumNum))
ans = -1
for i in range(n-k+1):
  r = res[i+k] - res[i]
  ans = max(ans, r)
print(ans)
Buggy python submission (verdict: Runtime Error):
HP, n = map(int, input().split())
damege = list(input().split())
if sum(damege) >= HP:
  print("Yes")
else:
  print("No")

Fixed submission:
HP, n = map(int, input().split())
damege = list(map(int, input().split()))
if sum(damege) >= HP:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
HP, k = map(int, input().split())
enamy = list(map(int, input().split()))

enamy1 = sorted(enamy, reverse=True)
if n =< k:
  print(0)
else:
  del enamy1[0:k]
  print(sum(enamy1))


Fixed submission:
HP, k = map(int, input().split())
enamy = list(map(int, input().split()))

enamy1 = sorted(enamy, reverse=True)
if len(enamy) <= k:
  print(0)
else:
  del enamy1[0:k]
  print(sum(enamy1))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if int("a"*b) >= int("b"*a):
  print(int("b"*a)
else:
  print(int("a"*b)

Fixed submission:
a, b = map(int, input().split())
ans = min(str(a) * b, str(b) * a)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numbers = list(map(int, input().split()))
c = 0

for i in numbers[::-1]:
    for j in numbers[numbers.index(i)::-1]:
        if  i <= j :
            continue
        else:
            break
    else:
        c += 1

print(c)


Fixed submission:
n = int(input())
number = list(map(int, input().split()))
cnt = 0
min_num = number[0]
for i in range(n):
  if min_num >= number[i]:
    cnt += 1
    min_num = number[i]
  else:
    continue
print(cnt)

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

for i in range(n)[::-1]:
    for j in range(0, i)[::-1]:
        if numbers[i] <= numbers[j]:
            continue
        else:
            break
    else:
        c += 1

print(c)


Fixed submission:
n = int(input())
number = list(map(int, input().split()))
cnt = 0
min_num = number[0]
for i in range(n):
  if min_num >= number[i]:
    cnt += 1
    min_num = number[i]
  else:
    continue
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
cheak =[[0]*9 for _ in range]
for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0])-1
    s2 = int(s[-1])-1
    if s2 == 0:
        continue
    cheak[s1][s2] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cheak[i][j] * cheak[j][i]
print(ans)


Fixed submission:
n = int(input())
cheak_box = [[0]*9 for _ in range(9)]

for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0]) - 1
    s2 = int(s[-1]) - 1
    if s2 == -1:
        continue 
    cheak_box[s1][s2] += 1

ans = 0
for p in range(9):
    for q in range(9):
        ans += cheak_box[p][q] * cheak_box[q][p]
        
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())

S = [['#'] * (W+2)]
for _ in range(H):
  tmp = ['#'] + list(input()) + ['#']
  S.append(tmp)
S.append(['#'] * (W+2))

move = [[1,0], [-1,0], [0,1], [0,-1]]

ans = 0
for X in range(1, H+1):
  for Y in range(1, W+1):
    if S[x][Y] == '#':
      continue
    check = [[-1] * (W+2) for _ in range(H+2)]
    check[X][Y] = 0
    que = deque()
    que.append([X, Y])
    while que:
      tmp = que.popleft()
      x = tmp[0]
      y = tmp[1]
      flag = True
      for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if S[nx][ny] == '.' and check[nx][ny] == -1:
          que.append([nx, ny])
          check[nx][ny] = check[x][y] + 1
          flag =False
      if flag:
        ans = max(ans, check[x][y])
print(ans)

Fixed submission:
from collections import deque

H, W = map(int, input().split())

S = [['#'] * (W + 2)]
for _ in range(H):
    tmp = ['#'] + list(input()) + ['#']
    S.append(tmp)
S.append(['#'] * (W + 2))
#迷路の周りを全て壁で覆うことでどの場所からでも四方に探索できるようにした

move = [[1, 0], [-1, 0], [0, 1], [0, -1]]#上下左右どこかに1マス移動する

ans = 0
# スタート位置を変えながら全探索
for X in range(1, H + 1):
    for Y in range(1, W + 1):
        if S[X][Y] == '#':
            continue
#if ~ continue分はtrueなら下の操作を行うことなく次の番号に移るという意味
        check = [[-1] * (W + 2) for _ in range(H + 2)]
        check[X][Y] = 0
#cheakには壁には-1、道にはそこまでの距離、未探索地には0を入れる
        que = deque()
        que.append([X, Y])
        while que:
            tmp = que.popleft()
            x = tmp[0]
            y = tmp[1]
            flag = True
            for dx, dy in move:
                nx = x + dx
                ny = y + dy
                if S[nx][ny] == '.' and check[nx][ny] == -1:#次の移動場所が"道"かつ"未探索"ならqueに突っ込む
                    que.append([nx, ny])
                    check[nx][ny] = check[x][y] + 1 #cheakにそこまでの距離を代入
                    flag = False
#flagの使い方が上手、真似したい
            if flag:#ある一点のスタート地点からの探索がすべて終わってから、その中の
                ans = max(ans, check[x][y])


print (ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input()
b = input()

import itertools
l = list(itertools.permutations(range(1,n+1))
print(abs(l.index(a)-l.index(b)))

Fixed submission:
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

import itertools
l = list(itertools.permutations(range(1, n+1)))
#permutations:順列 combinations:組み合わせ (list, 数字)rCnのnが「数字」で決まる
print(abs(l.index(p) - l.index(q)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0
print(sum(t.count("r")*r + t.count("s")*s + t.count("p")*p))

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0

print(sum([t.count("r")*p, t.count("s")*r, t.count("p")*s]))
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())
big = max(a, b)
small = min(a, b)
for i in range(1, 100000):
  if big*i % small == 0:
    print(big*i)
    exit()


Fixed submission:
a = int(input())
b = int(input())
print(6-a-b)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
import itertools
ans = set(itertools.combinations(s, 3))
print(len(ans))


Fixed submission:
'''
暗証番号3桁はたかだか10**3の候補。これを全探索で調べるだけ
pythonのindex関数を使用するとオブジェクト内に要素が存在しない場合エラーになる
'''
n = int(input())
s = [int(i) for i in input()]

def my_index(l,x,ind):
    '''
    l: イテラブル(for inで取り出せる)オブジェクト
    x: 探し出す大賞
    ind: イテラブルで探し始める位置（インデックス）
    返り値: 存在する場合はそのインデックス、存在しない場合は-1
    '''
    global n #入力のnと同一のものであるという意味
    if ind == n: #探索するものがない場合
        return -1
    for i in range(ind, n):
        if l[i] == x:
            return i
    else:
        return -1
c = 0
for i in range(10):
    x1 = my_index(s,i,0)
    if x1 != -1:
        for j in range(10):
            x2 = my_index(s,j,x1+1)
            if x2 != -1:
                for k in range(10):
                    x3 = my_index(s,k,x2+1)
                    if x3 != -1:
                        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = ""
for i in s:
  j = ((ord(i)-ord("A")) + n )//26 
'''
ord(D)-ord(A) = 68-65 = 3
n文字進める 3+n
26で割ることでたとえ3+nがAsciiコードの範囲を超えても大丈夫
'''
  ans += j
print(chr(ans))

Fixed submission:
n = int(input())
s = input()
ans = ''
for i in s:
  j = ((ord(i)-ord("A")) + n )%26 
  ans += chr(j + ord("A"))
print(ans)
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for x1, y1 in xy:[1,2,3]
    for x2, y2 in xy:
        ans += ((x1-x2)**2+(y1-y2)**2)**0.5

ans = ans/n
print(ans)


Fixed submission:
n=int(input())
xy=[list(map(int, input().split())) for _ in range(n)]

ans=0
for x1, y1 in xy:
	for x2, y2 in xy:
		ans+=((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(int(n**0.5)):
  if n%i == 0:
    l = i + (n/i) -2 #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(ans)

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''

Fixed submission:
n = int(input())
ans = 10**12
for i in range(1, int(n**0.5)+1):
  if n%i == 0:
    l = (i+(n/i)-2) #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(int(ans))

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''
Buggy python submission (verdict: Runtime Error):
a b = map(int, input().split())
ans = a-2*b
if ans >= 0:
  print(ans)
else:
  print(0)

Fixed submission:
a, b = map(int, input().split())
ans = a-2*b
if ans >= 0:
  print(ans)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 1
for i in range(n):
  if s[i] != s[i+1]:
    ans += 1
print(ans+1)

Fixed submission:
n = int(input())
s = input()
ans = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
   Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

Fixed submission:
import bisect

def solve():
    N = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# O(N^2 * logN)の全探索で解く
ans = 0
for a_i in range(N):
  for b_i in range(a_i+1, N):
    c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
    if c_i > b_i:
　     ans += c_i - b_i - 1
    else:
       pass
print(ans)

Fixed submission:
import bisect

def solve():
    N = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
quiz = [int(input()) for i in range(q)]
point = [k]*n
for i in quiz:
  point = list(map(lambda x: x-1, point))
  point[i-1] += 1
[print("Yes") if i > 0 else print("No") for i in point]

Fixed submission:
n, k, q = map(int, input().split())
quiz = [int(input()) for i in range(q)]
point = [k-q]*n
for i in quiz:
  point[i-1] += 1
[print("Yes") if i > 0 else print("No") for i in point]
'''
1. あらかじめ全員のポイントを Q 減らしておく (つまり，開始時点のポイントは K − Q)．
2. Q 回の正解それぞれに対して，正解者のポイントを 1 増やす．

リストの中身すべてに計算すると「リスト要素」＊「ループ回数」の計算量になる
'''

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
quiz = [int(input()) for i in range(q)]
point = [k]*n
for i in quiz:
  a = point[i-1]
  point = list(map(lambda x:x-1, point))
  point[i-1] = a
for j in point:
  if j > 0:
    print("Yes")
  else:
    print("No")


Fixed submission:
n, k, q = map(int, input().split())
quiz = [int(input()) for i in range(q)]
point = [k-q]*n
for i in quiz:
  point[i-1] += 1
[print("Yes") if i > 0 else print("No") for i in point]
'''
1. あらかじめ全員のポイントを Q 減らしておく (つまり，開始時点のポイントは K − Q)．
2. Q 回の正解それぞれに対して，正解者のポイントを 1 増やす．

リストの中身すべてに計算すると「リスト要素」＊「ループ回数」の計算量になる
'''
Buggy python submission (verdict: Runtime Error):
s = input()
n = input()
ans = 0
for i in range(n):
  if s[0] == n[i]:
    ans += 1
print(ans)
  
  

Fixed submission:
s = input()
n = input()
ans = 0
for i in range(3):
  if s[i] == n[i]:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
graph = list(map(int, input().split()))
right = 0
h2 = 0
cnt = -1
for i in graph:
  if i >= right:
    cnt += 1
    right = i
  else:
    ans = max(ans, cnt)
    cnt = 0
print(ans)

Fixed submission:
n = int(input())
graph = list(map(int, input().split()))
pre = 1000000
ans = 0
cnt = -1
for i in graph:
  if i <= pre:
    cnt += 1
    pre = i
  else:
    ans = max(ans, cnt)
    cnt = 0
    pre = i
ans = max(ans, cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))

Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
num = [list(map(int, input())) for _ in range(n)]
Sort_num = sorted(num)
for i in range(n):
  if num[i] == Sort_num[i-1]:
    print(Sort_num[i-2]
  else:
    print(Sort_num[i-1])

Fixed submission:
n = int(input())
num = [int(input()) for _ in range(n)]
Sort_num = sorted(num)
for i in range(n):
  if num[i] == Sort_num[n-1]:
    print(Sort_num[n-2])
  else:
    print(Sort_num[n-1])
Buggy python submission (verdict: Runtime Error):
x, a = map(int, input())
if a<=x:
  print(10)
else:
  print(0)

Fixed submission:
x, a = map(int, input().split())
if a<=x:
  print(10)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
  p, q = map(int, input().split())
  l[i], r[i] = map(int, input().split())
print(max(min[r] - max[l] + 1, 0))

Fixed submission:
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
  l[i], r[i] = map(int, input().split())
print(max(min(r) - max(l) + 1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
cnt = [0]*(n+1)
for i in range(m):
  l, r = map(int, input().split())
  for j in range(l, r+1):
    cnt[j] += 1
print(cnt.count(m))    


Fixed submission:
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
  l[i], r[i] = map(int, input().split())
print(max(min(r) - max(l) + 1, 0))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
cnt = [0]*(n+1)
for i in range(n):
  l, r = map(int, input().split())
  for j in range(l, r+1):
    cnt[j] += 1
print(cnt.count(m))    


Fixed submission:
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
  l[i], r[i] = map(int, input().split())
print(max(min(r) - max(l) + 1, 0))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

S[K-1] = S[K-1].lower()

print(S)


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

S[K-1] = S[K-1].lower()

S = ''.join(S)
print(S)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
s[m].lower()
print(s)

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

S[K-1] = S[K-1].lower()

S = ''.join(S)
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a, b):
  if a > b:
    return b
  else:
    return a
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*N
dp[0] = 0
for i in range(N - 1): #ジャンプ地点
	for j in range(1, min(K + 1, N - i)): #ジャンプ距離
		dp[i+j] = chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
def chmin(a, b):
  if a > b:
    a = b

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float(inf)]*n
dp[0] = 0
for i in range(n):
  for j in range(i+1, min(i+k, n-2)):
    chmin(dp[j], dp[i] + abs(h[j]-h[i]))
print(h[n-1])
  

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*N
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
from itertools import product
ans = 0
for i in range(1, 11):
  for p in product("357", repeat=i):
    v = "".join(p)
    if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
from itertools import product
ans = 0
for i in range(1, 11):
  for p in product("357", repeat=i):
    v = "".join(p)
    if "3" in v and "5" in v and "7" in v and int("".join(p)) <= n:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
    print("Hello World")
else:
    print(a+b)


Fixed submission:
n=int(input())
if n ==1:
    print("Hello World")
else:
    a=int(input())
    b=int(input())
    print(a+b)