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

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

A.sort(reverse=True)
U = A[0] * 2

# cgs[i] は パワーがi以上のゲストの数
cgs = [0] * (U + 1)
for a in A:
    cgs[a] += 1
for i in range(U, 0, -1):
    cgs[i - 1] += cgs[i]


def is_ok(n):
    m = 0
    for a in A:
        m += cgs[max(n - a, 0)]
    return m >= M


ok = A[-1] * 2
ng = U + 1
while ng - ok > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

# cps[i] は A[0]～A[i] の累積和
cps = A[:]
for i in range(1, N):
    cps[i] += cps[i - 1]

result = 0
for a in A:
    t = cgs[max(ok - a, 0)]
    if t != 0:
        result += a * t + cps[t - 1]
        M -= t
result += ok * M
print(result)

Buggy submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	N := readInt()
	M := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	U := A[0] * 2
	L := A[N-1] * 2

	// cgs[i] は パワーがi以上のゲストの数
	cgs := make([]int, U+1)
	for _, a := range A {
		cgs[a]++
	}
	for i := U; i > 0; i-- {
		cgs[i-1] += cgs[i]
	}

	isOk := func(n int) bool {
		m := 0
		for _, a := range A {
			m += cgs[max(n-a, 0)]
		}
		return m >= M
	}

	ok := L
	ng := U + 1
	for ng-ok != 1 {
		m := ok + (ng-ok)/2
		if isOk(m) {
			ok = m
		} else {
			ng = m
		}
	}

	// cps[i] は A[0]～A[i] の累積和
	cps := make([]int, N)
	cps[0] = A[0]
	for i := 1; i < N; i++ {
		cps[i] = A[i] + cps[i-1]
	}

	result := 0
	for _, a := range A {
		guests := cgs[max(ok-a, 0)]
		if guests != 0 {
			result += a*guests + cps[guests-1]
			M -= guests
		}
	}
	result += ok * M
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}
Problem p02855 (python)

Fixed submission:
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

a = [[-1] * W for _ in range(H)]

sbs = []
n = 1
for i in range(H):
  si = s[i]
  for j in range(W):
    if si[j] == '#':
      a[i][j] = n
      n += 1
      sbs.append((i, j))

for sb in sbs:
  i, j = sb
  n = a[i][j]
  t, l = i - 1, j - 1
  r = j + 1
  while t > -1:
    if a[t][j] != -1:
      break
    t -= 1
  t += 1
  while l > -1:
    if a[i][l] != -1:
      break
    l -= 1
  l += 1
  while r < W:
    if a[i][r] != -1:
      break
    r += 1
  r -= 1
  for y in range(t, i + 1):
    ay = a[y]
    for x in range(l, r + 1):
      ay[x] = n

for h in range(H - 1, -1, -1):
  if a[h][0] != -1:
    break
h += 1

if h != H:
  for i in range(h, H):
    ai1 = a[i - 1]
    ai = a[i]
    for j in range(W):
      ai[j] = ai1[j]

for i in range(H):
  ai = a[i]
  for w in range(W - 1, -1, -1):
    if ai[w] != -1:
      break
  w += 1

  if w != W:
    n = ai[w - 1]
    for j in range(w, W):
      ai[j] = n

for i in range(H):
  print(*a[i])

Buggy submission (verdict: Runtime Error):
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

a = [[-1] * W for _ in range(H)]

sbs = []
n = 1
for i in range(H):
  si = s[i]
  for j in range(W):
    if si[j] == '#':
      a[i][j] = n
      n += 1
      sbs.append((i, j))

for sb in sbs:
  i, j = sb
  n = a[i][j]
  t, l = i - 1, j - 1
  r = j + 1
  while t > -1:
    if a[t][j] != -1:
      break
    t -= 1
  t += 1
  while l > -1:
    if a[i][l] != -1:
      break
    l -= 1
  l += 1
  while r < W:
    if a[i][r] != -1:
      break
    r += 1
  r -= 1
  for l in range(y, i + 1):
    al = a[l]
    for m in range(x, r):
      al[m] = n

for h in range(H - 1, -1, -1):
  if a[h][0] != -1:
    break
h += 1

if h != H:
  for i in range(h, H):
    ai1 = a[i - 1]
    ai = a[i]
    for j in range(W):
      ai[j] = ai1[j]

for i in range(H):
  ai = a[i]
  for w in range(W - 1, -1, -1):
    if ai[w] != -1:
      break
  w += 1

  if w != W:
    n = ai[w - 1]
    for j in range(w, W):
      ai[j] = n

for i in range(H):
  print(*a[i])
Problem p02882 (python)

Fixed submission:
from math import atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - atan(x/(a*b*b/2))/(2 * pi)*360)

Buggy submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b/2))/(2 * pi)*360)

Buggy submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x == a * a * b:
  print(0)
if x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b/2))/(2 * pi)*360)

Buggy submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b*b/2))/(2 * pi)*360)
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
L = list(map(int, input().split()))

L.sort()
result = 0
for i in range(N - 2):
  a = L[i]
  for j in range(i + 1, N - 1):
    b = L[j]
    result += bisect_left(L, a + b) - j - 1
print(result)

Buggy submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := readInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = readInt()
	}

	sort.Sort(sort.IntSlice(L))
	result := 0
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			result += sort.SearchInts(L, L[i]+L[j]) - j - 1
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}
Problem p02900 (python)

Fixed submission:
from fractions import gcd
from math import sqrt


def prime_factorize(n):
    result = []
    for i in range(2, int(sqrt(n)) + 1):
        if n % i != 0:
            continue
        t = 0
        while n % i == 0:
            n //= i
            t += 1
        result.append((i, t))
        if n == 1:
            break
    if n != 1:
        result.append((n, 1))
    return result


A, B = map(int, input().split())
print(len(prime_factorize(gcd(A, B))) + 1)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)

def solve(keys, amount, cm, dp):
  if cm == (1 << N) - 1:
    return amount
  if len(keys) == 0:
    return INF
  a, m = keys[0]
  if dp[cm | m] < amount + a:
    return solve(keys[1:], amount, cm, dp)
  else:
    dp[cm | m] = amount + a
    return min(solve(keys[1:], amount + a, cm | m, dp), solve(keys[1:], amount, cm, dp))

setrecursionlimit(1000000)
INF = float('inf')

N, M = map(int, input().split())
keys = [read_key() for _ in range(M)]

dp = [INF] * (1 << N)
t = solve(keys, 0, 0, dp)
if t == INF:
  print(-1)
else:
  print(t)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)

def solve(keys, amount, cm, dp):
  if cm == (1 << N) - 1:
    return amount
  if len(keys) == 0:
    return INF
  a, m = keys[0]
  if dp[cm | m] < amount + a:
    return solve(keys[1:], amount, cm, dp)
  else:
    dp[cm | m] = amount + a
    return min(solve(keys[1:], amount + a, cm | m, dp), solve(keys[1:], amount, cm, dp))

setrecursionlimit(1000000)
INF = float('inf')

N, M = map(int, input().split())
keys = [read_key() for _ in range(M)]

dp = [INF] * (1 << N)
t = solve(keys, 0, 0, dp)
if t == INF:
  print(-1)
else:
  print(t)

Buggy submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	A := readInt()
	B := readInt()

	N := gcd(A, B)

	p := make([]bool, N+1)
	for i := 0; i < N+1; i++ {
		p[i] = true
	}
	p[0] = false
	p[1] = false
	n := int(math.Sqrt(float64(N)) + 1)
	for i := 4; i < N+1; i += 2 {
		p[i] = false
	}
	for i := 3; i < n+1; i += 2 {
		if p[i] {
			for j := i + i; j < N+1; j += i {
				p[j] = false
			}
		}
	}

	result := 1
	for i := 2; i < N+1; i++ {
		if N%i == 0 && p[i] {
			result++
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}
Problem p02901 (python)

Fixed submission:
def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float('inf')

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()

Buggy submission (verdict: Runtime Error):
def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float('inf')

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dpi[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()
Problem p02918 (python)

Fixed submission:
N, K = map(int, input().split())
S = input()
c = 0
for i in range(1, N):
  if S[i] == S[i - 1]:
    c += 1
print(min(N - 1, c + K * 2))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
c = 0
for i in range(1, N):
  if s[i] == S[i - 1]:
    c += 1
print(min(N - 1, c + K * 2))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
c = 0
for i in range(1, N):
  if s[i] == s[i - 1]:
    c += 1
print(min(N - 1, c + K * 2))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

def f1(s, l, r):
  return s[:l] + f2(s[l:r + 1]) + s[r + 1]

def f2(s):
  t = list(s)
  t.reverse()
  return ''.join('R' if c == 'L' else 'L' for c in t)

def f3(s):
  before = s[0]
  result = 0
  for i in range(1, N):
    if s[i] == before:
      result += 1
    else:
       before = s[i]
  return result

def f4(s, c):
  lstart = -1
  llen = 0
  tstart = -1
  for i in range(N):
    if s[i] == c and tstart == -1:
      tstart = i
    if s[i] != c and tstart != -1:
      tlen = i - tstart
      if tlen > llen:
        lstart = tstart
        llen = tlen
  return (lstart, llen)

for _ in range(K):
  lstart, llen = f4(S, 'L')
  rstart, rlen = f4(S, 'R')
  if lstart < rstart:
    S = f2(S, lstart + llen, rstart + rlen - 1)
  else:
    S = f2(S, rstart + rlen, lstart + llen - 1)
  if lstart == -1 or rstart == -1:
    break

print(f3(S))
Problem p02924 (python)

Fixed submission:
n = int(input())
print((n + 1) * n // 2 - n)

Buggy submission (verdict: Runtime Error):
```python
n = int(input())
print(n * (n - 1) // 2)
```
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def main():
  _map = map
  _input = input
  _int = int
  def calc_results(results, pvalue, i):
    results[i] = pvalue + values[i]
    for j in childrens[i]:
      calc_results(results, results[i], j)
  n, q = _map(_int, _input().split())
  values = [0] * (n + 1)
  results = [0] * (n + 1)
  childrens = [[] for _ in range(n + 1)]
  for i in range(n - 1):
    a, b = _map(_int, _input().split())
    childrens[a].append(b)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p] += x
  calc_results(results, 0, 1)
  print(*[results[i] for i in range(1, n + 1)])
main()

Buggy submission (verdict: Runtime Error):
class Node:
  def __init__(self, n):
    self.number = n
    self.children = []
    self.value = 0
def add_values(nodes, i, x):
  n = nodes[i]
  n.value += x
  for c in n.children:
    add_values(nodes, c, x)
n, q = map(int, input().split())
nodes = [Node(i) for i in range(0, n + 1)]
nodes[0] = None
for i in range(n - 1):
  a, b = map(int, input().split())
  nodes[a].children.append(b)
for _ in range(q):
  p, x = map(int, input().split())
  add_values(nodes, p, x)
print(' '.join(str(nodes[i].value) for i in range(1, n + 1)))
Problem p02941 (python)

Fixed submission:
def main():
  import sys
  _int = int
  n = _int(input())
  a = [_int(e) for e in input().split()]
  b = [_int(e) for e in input().split()]
  result = 0
  q = [i for i in range(n) if b[i] != a[i]]
  while len(q) != 0:
    nq = []
    c = 0
    for i in q:
      if i == 0 or i == n - 1:
        j = b[(n + i - 1) % n] + b[(n + i + 1) % n]
      else:
        j = b[i - 1] + b[i + 1]
      if j > b[i] - a[i]:
        nq.append(i)
        continue
      c += 1
      k = (b[i] - a[i]) // j
      result += k
      b[i] -= j * k
      if a[i] != b[i]:
        nq.append(i)
    if c == 0 and len(nq) != 0:
      print(-1)
      sys.exit()
    q = nq
  print(result)
main()

Buggy submission (verdict: Runtime Error):
def main():
  import sys
  from heapq import heappush, heappop, heapify
  _int = int
  n = _int(input())
  a = [_int(e) for e in input().split()]
  b = [_int(e) for e in input().split()]
  result = 0
  finished = 0
  hq = [(-b[i], i) for i in range(n)]
  heapify(hq)
  while True:
    _, i = heappop(hq)
    if a[i] == b[i]:
      finished += 1
      continue
    if i == 0:
      j = b[n - 1] + b[1]
    elif i == n - 1:
      j = b[n - 2] + b[0]
    else:
      j = b[i - 1] + b[i + 1]
    k = max((hq[0] - b[i]) // j, 1)
    b[i] -= j * k
    if a[i] > b[i]:
      print(-1)
      sys.exit()
    result += k
    if a[i] == b[i]:
      finished += 1
      if finished == n:
        print(result)
        sys.exit()
    else:
      heappush(hq, (-b[i], i))
main()
Problem p02947 (python)

Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Buggy submission (verdict: Runtime Error):
def main():
  from collections import Counter
  from sys import stdin
  readline = stdin.readline()
  N = int(readline())
  t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
  print(sum(t[k] * (t[k] - 1) // 2 for k in t))
main()
Problem p02972 (python)

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

t = [0] * (N + 1)
for i in range(N, 0, -1):
    t[i] = (sum(t[2 * i::i]) % 2) ^ a[i - 1]

print(sum(t))
print(*[i for i in range(1, N + 1) if t[i] == 1])

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

t = [0] * N
for i in range(N - 1, -1, -1):
    t[i] = (sum(t[2 * (i + 1) - 1::i]) % 2) ^ a[i]

print(sum(t))
print(*[i + 1 for i in range(N) if t[i] == 1])

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

t = [0] * N
for i in range(N, -1, -1):
    t[i] = (sum(t[2 * i - 1::i]) % 2) ^ a[i - 1]

print(sum(t))
print(*[i + 1 for i in range(N) if t[i] == 1])
Problem p02975 (python)

Fixed submission:
from itertools import product

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

c = {}
for e in a:
    c.setdefault(e, 0)
    c[e] += 1

if len(set(c)) > 3:
    print('No')
    exit()

t = {}
for x, y in product(set(c), repeat=2):
    i = x
    j = y
    t[i] = 1
    if t[i] > c[i]:
        continue
    t.setdefault(j, 0)
    t[j] += 1
    if t[j] > c[j]:
        continue
    for _ in range(N - 2):
        k = i ^ j
        t.setdefault(k, 0)
        t[k] += 1
        c.setdefault(k, 0)
        if t[k] > c[k]:
            j = -1
            break
        i, j = j, k
    if j ^ x == y:
        print('Yes')
        exit()
print('No')

Buggy submission (verdict: Runtime Error):
from itertools import combinations

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

c = [0] * (10 ** 9 + 1)
for e in a:
    c[e] += 1

for x, y in combinations(set(a), 2):
    t = [0] * (10 ** 9 + 1)
    i, j = x, y
    t[i] += 1
    t[j] += 1
    for _ in range(N - 2):
        k = i ^ j
        t[k] += 1
        if t[k] > c[k]:
            j = -1
            break
        i, j = j, k
    if j ^ x == y:
        print('Yes')
        exit()
print('No')

Buggy submission (verdict: Runtime Error):
from itertools import combinations

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

c = [0] * (10 ** 9 + 1)
for e in a:
    c[e] += 1

for x, y in combinations(a, 2):
    t = [0] * (10 ** 9 + 1)
    i, j = x, y
    t[i] += 1
    t[j] += 1
    for _ in range(N - 2):
        k = i ^ j
        t[k] += 1
        if t[k] > c[k]:
            j = -1
            break
        i, j = j, k
    if j ^ x == y:
        print('Yes')
        exit()
print('No')
Problem p02995 (python)

Fixed submission:
a, b, c, d = [int(e) for e in input().split()]

def gcd(a, b):
  while True:
    t = b % a
    if t == 0:
      return a
    b, a = a, t

def f(a, b, n):
  x = (a // n) * n
  if x < a:
    x += n
  if x > b:
    return 0
  result = 0
  if a <= x <= b:
    result += 1
  result += (b - x) // n
  return result

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d // gcd(c, d))
print(b - a + 1 - acc)

Buggy submission (verdict: Runtime Error):
from fraction import gcd

a, b, c, d = [int(e) for e in input().split()]

def f(a, b, n):
  return b // n - (a - 1) // n

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d // gcd(c, d))
print(b - a + 1 - acc)

Buggy submission (verdict: Runtime Error):
a, b, c, d = [int(e) for e in input().split()]

def gcd(a, b):
  while True:
    t = b % a
    if t == 0:
      return a
    b, a = a, t

def f(a, b, n):
  x = (a // n) * n
  if x < a:
    x += n
  if x > b:
    return 0
  result = 0
  if a <= x <= b:
    result += 1
  result += (b - x) // n
  return result

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, gcd(c * d))
print(b - a + 1 - acc)
Problem p03030 (python)

Fixed submission:
from functools import cmp_to_key
def cmp(x, y):
  if x[0] < y[0]:
    return -1
  elif x[0] > y[0]:
    return 1
  else:
    return int(y[1]) - int(x[1])
n = int(input())
d = [input().split() for _ in range(n)]
for i in range(n):
  d[i].append(i + 1)
d.sort(key = cmp_to_key(cmp))
for i in range(n):
  print(d[i][2])

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
def cmp(x, y):
  if x[0] < y[0]:
    return -1
  elif x[0] > y[0]:
    return 1
  else:
    return int(y[1]) - int(x[1])
n = int(input())
d = [input().split() for _ in range(n)]
for i in range(n):
  d[i].append(i + 1)
d.sort(key = cmp_to_key(cmp))
for i in range(n):
print(d[i][2])
Problem p03060 (python)

Fixed submission:
n = int(input())
v = [int(e) for e in input().split()]
c = [int(e) for e in input().split()]
result = 0
for i in range(n):
  if v[i] > c[i]:
    result += v[i] - c[i]
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = [int(input()) for _ in range(n)]
c = [int(input()) for _ in range(n)]
result = 0
for i in range(n):
  if v[i] > c[i]:
    result += v[i] - c[i]
print(result)
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(map(int, input()))
j = 1
r = 0
t = []
for i in range(n):
  if s[i] == j:
    r += 1
  else:
    t.append(r)
    r = 1
    j ^= 1
t.append(r)
if j == 0:
  t.append(0)
if k >= (len(t) - 1) // 2:
  print(sum(t))
else:
  result = sum(t[:2 * k + 1])
  j = sum(t[:2 * k + 1])
  i = 2
  while i + 2 * k < len(t):
    j += t[i + 2 * k - 1] + t[i + 2 * k] - (t[i - 2] + t[i - 1])
    result = max(result, j)
    i += 2
  print(result)

Buggy submission (verdict: Runtime Error):
# 累積和
N, K = map(int, input().split())
S = input()

p = '1'
count = 0
cs = []
for c in S:
  if c != p:
    cs.append(count)
    p = c
    count = 1
  else:
    count += 1
cs.append(count)
if p != '0':
  cs.append(0)

if len(cs) < 2 * K:
  print(N)

for i in range(1, len(cs)):
  cs[i] += cs[i - 1]

result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
  t = cs[2 * K + i] - cs[i - 1]
  if t > result:
    result = t
print(result)

Buggy submission (verdict: Runtime Error):
# 累積和
N, K = map(int, input().split())
S = input()

p = '1'
count = 0
cs = []
for c in S:
  if c != p:
    cs.append(count)
    p = c
    count = 1
  else:
    count += 1
cs.append(count)

if len(cs) < 2 * K:
  print(N)

for i in range(1, len(cs)):
  cs[i] += cs[i - 1]

result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
  t = cs[2 * K + i] - cs[i - 1]
  if t > result:
    result = t
print(result)
Problem p03136 (python)

Fixed submission:
n = int(input())
l = [int(e) for e in input().split()]
if max(l) < sum(l) - max(l):
  print('Yes')
else:
  print('No')

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

if max(L) < sum(L) - max(L):
    print('Yes')
else:
    print('No')
Problem p03160 (python)

Fixed submission:
n = int(input())
h = [int(e) for e in input().split()]
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(2, n):
  cost[i] = min(abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2])
print(cost[n - 1])

Buggy submission (verdict: Runtime Error):
# DP(配るDP)
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(N - 2):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])
i = N - 2
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])
print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
from functools import cmp_to_key
n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
d.sort(key = cmp_to_key(lambda x, y: x[1] / x[0] - y[1] / y[0]))
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        for k in list(t.keys()):
          if k <= nw and t[k] < nv:
            del t[k]
        t[nw] = nv
    else:
      Flag = False
      for k in t:
        if nw <= k and nv <= t[k]:
          Flag = True
          break
      if Flag:
        continue
      for k in list(t.keys()):
        if k <= nw and t[k] < nv:
          del t[k]
      t[nw] = nv
        
print(max(t.values()))