Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03573 (python)

Fixed submission:
A, B, C = map(int, input().split())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A, B, C=map(int, input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A, B, C = map(int,input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A, B, C=map(int, input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A,B,C=map(int, input().slpit())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().slpit())

if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
 
if A==B:
  print(C)
elif B==C:
  print(A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())

if A=B:
  print(C)
elif B=C:
  print(A)
else:
  print(B)
Problem p02684 (python)

Fixed submission:
n,k = map(int,input().split())

al = list(map(int,input().split()))

ansl = []
used = [0 for i in range(n+1)]
now = 0
while True:
    if used[now] == 1:
        break
    ansl.append(now)
    used[now] = 1
    now = al[now] - 1

l = len(ansl)
last = ansl.index(now)
loop = ansl[last:]

if k < len(ansl):
    print(ansl[k] + 1)
else:
    k -= len(ansl)
    print(loop[k % len(loop)] + 1)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())

al = list(map(int,input().split()))

ansl = []
used = [0 for i in range(n)]
now = 0
while True:
    if used[now] == 1:
        break
    ansl.append(now)
    used[now] = 1
    now = al[now] -1

l = len(ansl)
last = ansl.index(now)
loop = ansl[last:]
if k <= len(ansl):
    print(ansl[k])
else:
    k -= len(ansl)
    print(loop[k%len(loop)]+1)
Problem p02727 (python)

Fixed submission:
x,y,a,b,c = map(int,input().split())
pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
ansl = pl[-x:] + ql[-y:]

ansl += rl

ansl = sorted(ansl)
print(sum(ansl[-(x+y):]))

Buggy submission (verdict: Runtime Error):
x,y,a,b,c = map(int,input().split())

pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
import itertools
pl_ac = [0] + list(itertools.accumulate(pl))
ql_ac = [0] + list(itertools.accumulate(ql))
rl_ac = [0] + list(itertools.accumulate(rl))

dada = max(ql, pl, rl)

import bisect
ans = 0
#　赤色をi個食べるとすると無職x-i
for i in range(x+1):
    tmp = 0
    if i > a or x - i > c or b + c - (x - i) < y:
        continue
    #あか
    tmp += pl_ac[-1] - pl_ac[-1-i]
    # #無職
    # tmp += rl_ac[-1] - ql_ac[-1-(x-i)]
    #残りの無職
    if x-i == 0:
        rl_c = rl[:] 
    else:
        rl_c = rl[:-(x-i)]
    # ub以上のりんご何個ある？
    ub = dada + 1

    lb = -1
    while True:
        if ub == lb:
            target = ub
            break
        target = (ub + lb) // 2 + 1
        idx = bisect.bisect_left(ql, target)
        idx2 = bisect.bisect_left(rl_c, target)
        if (b - idx) + (c - (x - i) - idx2) >= y:
            lb = target
        else:
            ub = target - 1
    idx = bisect.bisect_left(ql, target)
    idx2 = bisect.bisect_left(rl_c, target)
    tmp += ql_ac[-1] - ql_ac[idx]
    tmp += rl_ac[-1] - rl_ac[idx2]
    gg = (b - idx) + (c - (x - i) - idx2) - y
    ans -= target * gg
    ans = max(tmp, ans)

print(ans)
Problem p02730 (python)

Fixed submission:
s = list(input())
n = len(s)
if s != list(reversed(s)):
    print("No")
    exit()
if s[:n//2] != list(reversed(s[:n//2])):
    print("No")
    exit()
if s[(n//2)+1:] != list(reversed(s[(n//2)+1:])):
    print("No")
    exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
h,w,k = map(int,input().split())

sl = []
for _ in range(h):
    s = list(input())
    s = [int(i) for i in s]
    sl.append(s)
import itertools
sl_ac = []
for s in sl:
     ac = [0] + list(itertools.accumulate(s))
     sl_ac.append(ac)

anss = float("inf")


from itertools import product
for bits in product([0, 1], repeat=h-1):
    ans = 0
    ans += sum(bits)
    p = 0
    group = [0 for i in range(h)]
    for idx, bit in enumerate(bits):
        group[idx] = p
        p += bit
    group[-1] = p
    sum_group = [0 for i in range(sum(bits) + 1)]
    reset = 0
    flag = "OK"
    for i in range(w):
        for j in range(h):
            sum_group[group[j]] += sl[j][i]
        if max(sum_group) > k:
            if i == 0:
                flag = "NG"
            else:
                ans += 1
                reset = i
                sum_group = [0 for i in range(sum(bits) + 1)]
                for j in range(h):
                    sum_group[group[j]] += sl[j][i]
                if max(sum_group) > k:
                    flag = "NG"

    if flag == "OK":
        anss = min(ans, anss)
print(anss)
Problem p02814 (python)

Fixed submission:
import sys #追加
sys.setrecursionlimit(10**9)
import time
s = time.time()

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

bl = [i//2 for i in al]
from fractions import gcd
ans = 1
for b in bl:
   if time.time() - s > 1.9:
      print(0)
      import sys
      sys.exit()
   ans = (ans * b) // gcd(ans, b)

for a in al:
   if time.time() - s > 1.9:
      print(0)
      import sys
      sys.exit()
   if ans % a == 0:
      print(0)
      import sys
      sys.exit()

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))

Buggy submission (verdict: Runtime Error):
import sys #追加
sys.setrecursionlimit(10**9)

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

bl = [i//2 for i in al]
from fractions import gcd
ans = 1
for b in bl:
   ans = (ans * b) // gcd(ans, b)

import numpy as np
print(ans, al)
al = ans % (np.array(al) / 2)
if any(al):
   print(0)
   import sys
   sys.exit()
   

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))

Buggy submission (verdict: Runtime Error):
import sys #追加
sys.setrecursionlimit(10**9)

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

#a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

#a,bの最小公倍数
def lcm(a, b):
   return a * b // gcd (a, b)


bl = [i//2 for i in al]
import numpy as np
ans = 1
for b in bl:
   ans = np.lcm(b, ans)

for a in al:
   if ans % a == 0:
      print(0)
      import sys
      sys.exit()

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
al = list(map(int,input().split()))

#a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

#a,bの最小公倍数
def lcm(a, b):
   return a * b // gcd (a, b)


bl = [i//2 for i in al]

ans = 1
for b in bl:
   ans = lcm(ans, b)

for a in al:
   if ans // a == ans / a:
      print(0)
      import sys
      sys.exit()

def ceil(a, b):
   return a // b + (a % b > 0)

print(ceil(m // ans, 2))
Problem p02821 (python)

Fixed submission:
import itertools
import bisect
n, m = list(map(int, input().split()))
al = list(map(int, input().split()))
al.sort()
ub = al[-1]*3
lb = -1
while lb + 1 < ub:
    target = (ub+lb)//2
    tmp = 0
    for a in al:
        sa = target - a
        # リストAに値xを入れ、xが複数になるとき、一番左の値xのインデックスを返す
        i = bisect.bisect_left(al, sa)
        tmp += (n-i)
    if (tmp >= m):
        lb = target
    else:
        ub = target

target = lb
rui_al = [0] + list(itertools.accumulate(al))
ans = 0
tmp = 0
for a in al:
    sa = target - a
    # リストAに値xを入れ、xが複数になるとき、一番左の値xのインデックスを返す
    i = bisect.bisect_left(al, sa)
    tmp += (n-i)
    ans += (rui_al[-1] - rui_al[i])
    ans += a*(n-i)


if tmp > m:
    ans -= (tmp-m)*target
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
al = list(map(int,input().split()))
al = sorted(al)
ans = 0
while True:
   if m - 2*n + 1 >= 0:
      ans += sum(al) * 2 + 2*al[-1]*(n-1)
      al.pop()
      m = m - 2*n +1
      n -= 1
   else:
      l = []
      for a in al:
         l.append(a+al[-1])
         l.append(a+al[-1])
      l.pop()
      l = l[-m:]
      ans += sum(l)
      break

print(ans)
Problem p02844 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
s = list(input())

ans = 0
num = [str(i) for i in range(10)]
for i in num:
    for l in range(n):
        if s[l] == i:
            for j in num:
                for m in range(l+1,n):
                    if s[m] == j:
                        for k in num:
                            for p in range(m+1, n):
                                if s[p] == k:
                                    ans += 1
                                    break
                            continue
                        break
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())

from collections import defaultdict
ans = defaultdict(int)
def dfs(now, pos):
    if len(now) == 3:
        ans[now] = 1
        return
    if pos == n:
        return
    dfs(now+s[pos], pos+1)
    dfs(now, pos+1)

dfs("", 0)

anss = 0
for i in ans.values():
    anss += i

print(anss)
Problem p02885 (python)

Fixed submission:
# coding: utf-8
# Your code here!

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

c = a - 2 * b
if c > 0:
    print(c)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math

n,m,l = map(int,input().split())
adj = [[float('inf') for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    if c <= l:
        adj[a-1][b-1] = c
        adj[b-1][a-1] = c
    
import heapq

class Dijkstra(object):
    def dijkstra(self, adj, start):
        num = len(adj)          # グラフのノード数
        dist = [[float('inf'), float('inf')] for i in range(num)] # 始点から各頂点までの最短距離を格納する
        
        dist[start] = (0, 0)
        q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
        heapq.heappush(q, (0, 0, start)) # 始点をpush

        while len(q) != 0:
            prov_cost, prov_fuel, src = heapq.heappop(q) # pop
            
            # 他の頂点の探索
            for dest in range(num):
                cost = adj[src][dest]
                if cost != float('inf'):
                    if prov_fuel + cost <= l:
                        new_cost = prov_cost
                        new_fuel = prov_fuel + cost
                    else:
                        new_cost = prov_cost + 1
                        new_fuel = cost
                    if dist[dest][0] > new_cost or (dist[dest][0] == new_cost and dist[dest][1] > new_fuel):
                        dist[dest] = (new_cost, new_fuel)
                        heapq.heappush(q, (new_cost, new_fuel, dest))
                        
        return dist



ans = []
for i in range(n):
    ans.append(Dijkstra().dijkstra(adj, i))
q = int(input())
for _ in range(q):
    s,t = map(int,input().split())
    if ans[s-1][t-1][0] == float('inf'):
        print(-1)
    else:
        print(ans[s-1][t-1][0])
Problem p02888 (python)

Fixed submission:
# coding: utf-8
# Your code here!

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

ll.sort()
ans = 0
for i in range(n - 2):
    for j in range(i+1, n - 1):
        lb = j + 1
        ub = n - 1
        b = ll[i] + ll[j]
        if ll[lb] >= b:
            continue
        if ll[ub] < b:
            ans += ub - lb + 1
            continue
        while True:
            if ub == lb:
                ans += ub - j
                break
            t = (lb + ub) // 2 + 1
            if ll[t] < b:
                lb = t
            else:
                ub = t - 1
print(ans)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> ll; 
    int n;
	cin >> n;
    for(int i=0; i<n; i++) {
    	int x;
    	cin >> x;
    	ll.push_back(x);
    }
    long long ans = 0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            for(int k=j+1; k<n; k++) {
                if(ll[i] < ll[j] + ll[k] && ll[j] < ll[i] + ll[k] && ll[k] < ll[i] + ll[j]) {
                    ans += 1;
                }
            }
        }
    }
    cout << ans << '\n';
    
}
Problem p02922 (python)

Fixed submission:
import sys

A = list(map(int, input().split()))
a, b = A[0], A[1]
kazu = 0
kuti = 1
while True:
    if kuti >= b:
        print(kazu)
        sys.exit()
    kazu += 1
    kuti = kuti - 1 + a

Buggy submission (verdict: Runtime Error):
import sys

A = list(map(int, input().split()))
a, b = A[0], A[1]
kazu = 0
kuti = 1
while True:
    if kuti >= b:
        print(kazu)
        sys.quit()
    kazu += 1
    kuti = kuti - 1 + a
Problem p02936 (python)

Fixed submission:
n,q = map(int,input().split())
m = [[] for i in range(n)]
for _ in range(n-1):
   a,b = map(int,input().split())
   m[a-1].append(b-1)
   m[b-1].append(a-1)

from collections import defaultdict
dic = defaultdict(int)
for _ in range(q):
   p,x = map(int,input().split())
   dic[p-1] += x

ans = [0 for i in range(n)]
ans[0] = dic[0]

used = [0 for i in range(n)]
used[0] = 1
quu = [0]
while quu:
   k = quu.pop()
   for l in m[k]:
      if used[l] == 0:
         used[l] = 1
         quu.append(l)
         ans[l] = ans[k] + dic[l]

for i in ans:
   print(i)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())

from collections import defaultdict
dic = defaultdict(list)


for _ in range(n-1):
    a,b = map(int,input().split())
    dic[a-1].append(b-1)
    dic[b-1].append(a-1)


dic2 = defaultdict(int)

for _ in range(q):
    p,x = map(int,input().split())
    dic2[p-1] += x

ansl = [0 for i in range(n)]
used = [-1 for i in range(n)]
used[0] = 1
def dfs(pos):
    for p in dic[pos]:
        if used[p] == -1:
            ansl[p] = ansl[pos] + dic2[pos]
            used[p] = 1
            dfs(p)

dfs(0)
for idx, a in enumerate(ansl):
    print(a + dic2[idx])

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
from collections import defaultdict
dic = defaultdict(list)
for _ in range(n-1):
    a,b = map(int,input().split())
    dic[a-1].append(b-1)
    dic[b-1].append(a-1)

from collections import defaultdict
dicp = defaultdict(int)

for _ in range(q):
    p,x = map(int,input().split())
    dicp[p-1] += x


ansl = [0 for i in range(n)]
used = [0 for i in range(n)]
def dfs(pos, point):
    point += dicp[pos]
    used[pos] = 1
    ansl[pos] = point
    for p in dic[pos]:
        if used[p] == 0:
            dfs(p, point)

dfs(0, 0)

for a in ansl:
    print(a)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
from collections import defaultdict
n,q = map(int,input().split())
direct_dict = defaultdict(list)
for i in range(n-1):
    a,b = map(int,input().split())
    direct_dict[a - 1].append(b - 1)
ans_list = [0 for i in range(n)]
node_point = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    node_point[p-1] += x
    
def get_point(pos, now):
    ans_list[pos] = now + node_point[pos]
    for next_pos in direct_dict[pos]:
        get_point(next_pos, now + node_point[pos])

get_point(0, 0)
for i in ans_list:
    print(str(i)+" ", end="")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
from collections import defaultdict
n,q = map(int,input().split())
direct_dict = defaultdict(list)
for i in range(n-1):
    a,b = map(int,input().split())
    direct_dict[a - 1].append(b - 1)
ans_list = [0 for i in range(n)]
node_point = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    node_point[p-1] += x
    
def get_point(pos, now):
    ans_list[pos] = now + node_point[pos]
    for next_pos in direct_dict[pos]:
        get_point(next_pos, now + node_point[pos])

get_point(0, 0)
for i in ans_list:
    print(str(i)+" ", end="")
Problem p02949 (python)

Fixed submission:
# coding: utf-8
# Your code here!


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

el = []
for _ in range(m):
    a,b,c = map(int,input().split())
    el.append((a-1,b-1,c-p))
cost = [-float("inf") for _ in range(n)]
cost[0] = 0
for i in range(2*n):
    for j in range(m):
        e = el[j]
        if cost[e[1]] < cost[e[0]] + e[2]:
            cost[e[1]] = cost[e[0]] + e[2]
            if i >= n:
                cost[e[1]] = float("inf")
    if i == n-1:
        ans = cost[-1]
        
              
if ans != cost[-1]:
    print(-1)
else:
    print(max(ans, 0))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!


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

el = []
for _ in range(m):
    a,b,c = map(int,input().split())
    el.append((a-1,b-1,c-p))
cost = [-float("inf") for _ in range(n)]
cost[0] = 0
for i in range(n+1):
    for j in range(m):
        e = el[j]
        if cost[e[1]] < cost[e[0]] + e[2]:
            cost[e[1]] = cost[e[0]] + e[2]
            if i == n:
                cost[e[1]] = float("inf")
              
if ans != cost[-1]:
    print(-1)
else:
    print(max(cost[-1], 0))
Problem p02975 (python)

Fixed submission:
n = int(input())
al = list(map(int,input().split()))


from collections import defaultdict
dic = {}

for a in al:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
if 0 in dic:
    if dic[0] == n:
        print("Yes")
        exit()
if 0 in dic:
    if n % 3 == 0:
        if dic[0] == 1 * n // 3:
            print("Yes")
            exit()
if n % 3 != 0:
    print("No")
    exit()
else:
    if len(dic) == 3:
        if max(dic.values()) == n // 3:
            a = 0
            for i in dic:
                a ^= i
            if a == 0:
                print("Yes")
                exit()
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
al = list(map(int,input().split()))


from collections import defaultdict
dic = {}

for a in al:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
if dic[0] == n:
    print("Yes")
    exit()
if 0 in dic:
    if n % 3 == 0:
        if dic[0] == 2 * n // 3:
            print("Yes")
            exit()
if n % 3 != 0:
    print("No")
    exit()
else:
    if len(dic) == 3:
        if max(dic.values()) == n // 3:
            a = 0
            for i in dic:
                a ^= i
            if a == 0:
                print("Yes")
                exit()
print("No")
Problem p02995 (python)

Fixed submission:
import math
from fractions import gcd
a,b,c,d = map(int,input().split())

c_num = b // c - (a-1) // c
d_num = b // d - (a-1) // d


def lcm(x, y):
    return (x * y) // gcd(x, y)
    
e = lcm(c,d)

e_num = b // e - (a-1) // e

print((b-a+1)-(c_num+d_num-e_num))

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())

c_num = (b // c - math.ceil(a / c) + 1)
d_num = (b // d - math.ceil(a / d) + 1)


def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
e = lcm(c,d)

e_num = (b // e - math.ceil(a / e) + 1)

print((b-a+1)-(c_num+d_num-e_num))
Problem p03032 (python)

Fixed submission:
n,k = map(int,input().split())

vl = list(map(int,input().split()))

ans = 0
for a in range(k+1):
    suba = vl[:a]
    for b in range(min(n+1-a, k+1-a)):
        subb = vl[-b:]
        if b == 0:
            subb = []
        sub = suba + subb
        ssub = sorted(sub)
        for _ in range(k-a-b):
            if len(ssub) == 0:
                break
            if ssub[0] < 0:
                ssub.pop(0)
            else:
                break
        if sum(ssub) > ans:
            ans = sum(ssub)

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())

vl = list(map(int,input().split()))

dpa = [[0 for j in range(k+2)] for i in range(k+2)]
dpb = [[0 for j in range(k+2)] for i in range(k+2)]
suma = []
sumb = []
for i in range(k):
    suma += [vl[i]]
    sumb += [vl[-i-1]]
    suma = sorted(suma)
    sumb = sorted(sumb)
    for j in range(min(i+1, k+1-i)):
        dpa[i][j] = sum(suma[j:])
        dpb[i][j] = sum(sumb[j:])
    
ans = 0
for a in range(k+1):
    for b in range(k+1-a):
        for c in range(min(a+1, k+1-a-b)):
            for d in range(min(b+1, k+1-a-b-c)):
                tmp = dpa[a-1][c] + dpb[b-1][d]
                if tmp > ans:
                    ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())

vl = list(map(int,input().split()))

dpa = [[0 for j in range(k+1)] for i in range(k+1)]
dpb = [[0 for j in range(k+1)] for i in range(k+1)]
suma = []
sumb = []
for i in range(k):
    suma += [vl[i]]
    sumb += [vl[-i-1]]
    suma = sorted(suma)
    sumb = sorted(sumb)
    for j in range(min(i+1, k+1-i)):
        dpa[i][j] = sum(suma[j:])
        dpb[i][j] = sum(sumb[j:])
    
ans = 0
for a in range(k+1):
    for b in range(k+1-a):
        for c in range(min(a+1, k+1-a-b)):
            for d in range(min(b+1, k+1-a-b-c)):
                tmp = dpa[a-1][c] + dpb[b-1][d]
                if tmp > ans:
                    ans = tmp

print(ans)
Problem p03037 (python)

Fixed submission:
n,m = map(int,input().split())

lmin = 1
rmax = n
for _ in range(m):
    l,r = map(int,input().split())
    if l > lmin:
        lmin = l
    if rmax > r:
        rmax = r
    
print(max(rmax - lmin + 1, 0))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

lmin = 1
rmax = n
for _ in range(m):
    l,r = map(int,input().split())
    if l > lmin:
        lmin = l
    if rmax > r:
        rmax = r
    
print(max(rmax - lmin + 1), 0)
Problem p03039 (python)

Fixed submission:
MOD = 10**9 + 7
N = 10**6 + 10

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

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

p = comb(n*m-2, k-2)

ans = 0
for i in range(1,n):
    ans += i * (n-i) * m * m * p
    ans %= MOD

for i in range(1,m):
    ans += i * (m-i) * n * n * p
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = 10**5 + 10

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

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

p = comb(n*m-2, k-2)

ans = 0
for i in range(1,n):
    ans += i * (n-i) * m * m * p
    ans %= MOD

for i in range(1,m):
    ans += i * (m-i) * n * n * p
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = 10**5 + 1

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

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

p = comb(n*m-2, k-2)

ans = 0
for i in range(1,n):
    ans += i * (n-i) * m * m * p
    ans %= MOD

for i in range(1,m):
    ans += i * (m-i) * n * n * p
    ans %= MOD

print(ans)