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

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())
    ans = C(n, 3) // 3
    j = n - 2
    k = n - 1
    dame = []
    for i in range(n - 3, -1, -1):
        if i in dame or j in dame or k in dame:
            continue
        a = l[i]
        b = l[j]
        c = l[k]
        if a < b + c and b < a + c and c < a + b:
            j -= 1
            k -= 1
        else:
            if a > b + c:
                dame.append(i)
            if b > a + c:
                dame.append(j)
            if c > a + b:
                dame.append(k)
    
    for d in dame:
        ans -= C(n - d - 1, 1)

    nn = len(dame)
    if nn >= 3:
        j = n - 2
        k = n - 1
        for i in range(dame - 3, -1, -1):
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())
    ans = C(n, 3) % 3
    j = n - 2
    k = n - 1
    dame = []
    for i in range(n - 3, -1, -1):
        if i in dame or j in dame or k in dame:
            continue
        a = l[i]
        b = l[j]
        c = l[k]
        if a < b + c and b < a + c and c < a + b:
            j -= 1
            k -= 1
        else:
            if a > b + c:
                dame.append(i)
            if b > a + c:
                dame.append(j)
            if c > a + b:
                dame.append(k)
    
    for d in dame:
        ans -= C(n - d - 1, 1)

    nn = len(dame)
    if nn >= 3:
        j = n - 2
        k = n - 1
        for i in range(dame - 3, -1, -1):
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1

    print(ans)

main()
Problem p02899 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

def main():
  n = ni()
  a = list(na())
  d = {}
  for i, a in enumerate(a):
    d[a] = i+1
  res = []
  for i in range(n):
    res.append(d[i+1])
  print(*res)

main()

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

def main():
  n = ni()
  a = list(na())
  res = []
  for i in range(1,n+1):
    res.append(a[i])
  print(*res)

main()
Problem p02900 (python)

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

def divi(n):
  res = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      res.append(i)
      if i != n // i:
        res.append(n // i)
  return res

def isprime(n):
  if n == 2:
    return True
  if n % 2 == 0 or n < 2:
    return False
  for i in range(3, int(n**0.5)+1, 2):
    if (n % i == 0):
      return False
  return True

def main():
  a, b = sorted(na())
  x = divi(a)
  cnt = 1
  for bb in divi(b):
    if bb in x and isprime(bb):
      cnt += 1
  print(cnt)
main()

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#define rep(i, a, n) for(int i = a; i < (n); ++i)
#define ll long long

template<typename T>
bool isPrime(T x) {
  if (x == 1) return false;
  for (int i = 2; i <= sqrt(x); i += 2) {
    if (x % i == 0) return false;
  }
  return true;
}

template<typename T>
T gcd(T n, T m) {
  while (m != 0) {
    n %= m;
    swap(n, m);
  }
  return n;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll a, b;
  cin >> a >> b;
  
  ll x = gcd(a, b);
  ll ans = 1;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      if (isPrime(i)) {
       ++ans;
       if (i * i != x) {
         if (isPrime(x / i)) ++ans;
       }
      }
    }
  }
  cout << ans << endl;
}
Problem p02918 (python)

Fixed submission:
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())

def main():
  n, k = na()
  s = ns()

  ans = n-1
  for i in range(1, n):
    if s[i] != s[i-1]:
      ans -= 1
  print(min(n-1, ans+2*k))
main()

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n, k = na()
  s = ns()+"0"

  ans = 0
  LRcnt = []
  cnt = 1
  LR = []
  for i in range(n):
    if s[i] == s[i+1]:
      ans += 1
      cnt += 1
    else:
      LR.append(s[i])
      LRcnt.append(cnt)
      cnt = 1

  N = len(LRcnt)
  wa = [0] * (N+1)
  for i in range(N):
    wa[i+1] = wa[i] + LRcnt[i]

  ans = 0
  for i in range(N-k-2):
    x = wa[i+k+2] - wa[i] - 1 + sum(LRcnt[i+k+2:]) - len(LRcnt[i+k+2:]) + sum(LRcnt[:i+k+2]) - len(LRcnt[:i+k+2])
    if ans < x:
      ans = x
      if LR[i] == "R":
        ans -= 1
      if LR[i+k+1] == "L"::
        ans += 1

  if ans == 0:
    print(sum(LRcnt)-1)
  else:
    print(ans)
main()
Problem p02928 (python)

Fixed submission:
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())

def f(n):
    return n*(n+1)//2

def main():
  n, k = an()
  a = list(an())

  mod = int(1e9)+7
  ans = 0
  x = a[:] 
  for i, ai in enumerate(x):
    cnt = 0
    for j in range(i+1, n):
      if ai > x[j]:
        cnt += 1
    tcnt = 0
    for j in range(i+1):
      if ai > x[j]:
        tcnt += 1

    ans += f(k) * cnt
    ans %= mod
    ans += f(k - 1) * tcnt
    ans %= mod

  print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())

def f(n):
  return n*(n+1)//2

x = 0
y = 0

n, k = an()
a = list(an())

mod = int(1e9)+7
ans = 0

for i, ai in range(n):
  for j in range(i+1, n):
    if ai > a[j]:
      x += 1
  
  for j in range(i+1):
    if ai > a[j]:
      y += 1

ans += x * f(k)
ans += y * f(k - 1)
print(ans % mod)
Problem p02945 (python)

Fixed submission:
A, B = map(int,input().split())
print(max(A + B, A- B, A*B))

Buggy submission (verdict: Runtime Error):
A, B = map(int,inpt().split())
print(max(A + B, A- B, A*B)
Problem p02947 (python)

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  tmp = []
  d={}
  for s in S:
    x = Counter(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      tmp.append(x)
      d[tmp.index(x)] = 1 
      
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  N = int(input())

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  N = int(input())

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(d)
  print(cnt)
if __name__ == "__main__":
  main()
Problem p02983 (python)

Fixed submission:
L, R = map(int,input().split())

R = min(R, L+673)
ans = 2018
for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, i*j%2019)
print(ans)

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

mod = 2019
for i in range(500):
  if L <= (3**i)%(1e9+7) <= R or L <= (673**i)%(1e9+7) <= R or L <= (3*673*i)%(1e9+7) <= R or L <= (3*i)%(1e9+7) <= R or L <= (673*i)%(1e9+7) <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))

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

mod = 2019
for i in range(100):
  if L <= (3**i)%(1e9+7) <= R or L <= (673**i)%(1e9+7) <= R or L <= (3*673*i)%(1e9+7) <= R or L <= (3*i)%(1e9+7) <= R or L <= (673*i)%(1e9+7) <= R or L <= ((3*673)**i)%(1e9+7) <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))

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

mod = 2019
for i in range(500):
  if L <= 3**i%(1e9+7) <= R or L <= 673**i%(1e9+7) <= R or L <= 3*673*i%(1e9+7) <= R or L <= 3*i%(1e9+7) <= R or L <= 673*i%(1e9+7) <= R or L <= 3*673**i%(1e9+7) <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))

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

mod = 2019
for i in range(1000):
  if L <= 3**i%(1e9+7) <= R or L <= 673**i%(1e9+7) <= R or L <= 3*673*i%(1e9+7) <= R or L <= 3*i%(1e9+7) <= R or L <= 673*i%(1e9+7) <= R or L <= 3*673**i%(1e9+7) <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))

Buggy submission (verdict: Runtime Error):
mod = 2019
for i in range(100):
  if L <= 3**i <= R or L <= 673**i <= R or L <= 3*673*i <= R or L <= 3*i <= R or L <= 673*i <= R or L <= 3*673**i <= R:
    print(0)
    exit()
else:
  print(min((L*(L+1))%mod, R*(R-1)%mod, R*L%mod))
Problem p03037 (python)

Fixed submission:
N, M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]

Lma = 0
Rmi = N + 1
for L, R in LR:
  Lma = max(L, Lma)
  Rmi = min(R, Rmi)

print(max(0, Rmi - Lma + 1))

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
LR = set(list(map(int,input().split())) for _ in range(M))

cnt = 0
for i in range(N):
  tmp = 0
  for L, R in LR:
    if L-1 <= i <= R-1:
      tmp += 1
    else:
      break
    if tmp == M:
      cnt += 1
      break
print(cnt)
Problem p03059 (python)

Fixed submission:
A, B, T = map(int,input().split())
T += 0.5
print(int(T//A*B))

Buggy submission (verdict: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

int main(){
  int A, B, T;
  cin >> A >> B >> T;

  cout << T/A*B << endl;
}
Problem p03061 (python)

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

L = [0]
R = [0]
for i in range(N):
  L.append(gcd(L[i], A[i]))
  R.append(gcd(R[i], A[-(i+1)]))
R = R[::-1]
ans = 0
for i in range(N):
  ans = max(ans, gcd(L[i], R[i+1]))
print(ans)

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

L = [0] * N
for i in range(N-1):
  L[i+1] = gcd(L[i], A[i])

R = [0] * N
for i in range(N, -1, -1):
  R[i-1] = gcd(R[i], A[i])

ans = 0
for i in range(N):
  ans = max(ans, gcd(L[i], R[i]))
print(ans)

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = []
  k = max(A)
  f = False
  ind = A.index(k)
  if k%2 == 0:
    f = True
  for i in range(N):
    if i != ind:
      if f:
        if (k%A[i])%2 == 0:
          res.append(gcd(k, A[i]))
      else:
        if (k%A[i])%2 == 1:
          res.append(gcd(k, A[i]))
  print(max(res))
ans()

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = set()
  k = max(A)
  for i in range(N):
    res.add(gcd(A[i], k))
  print(list(res)[N-1])

ans()

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = set()
  x = min(A)
  for i in range(N):
    res.add(gcd(A[i], x))

  b = A[0]
  for a in A[1:]:
    b = gcd(a, b)
  print(list(res)[b-1])
ans()
Problem p03062 (python)

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

neg_cnt = 0
for a in A:
  if a < 0:
    neg_cnt += 1

B = list(map(abs, A))
if neg_cnt%2 == 0:
  print(sum(B))
else:
  print(sum(B) - 2*min(B))

Buggy submission (verdict: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

int i;

int main(){
  int N, neg_cnt = 0;
  cin >> N;
  vector<int> A(N), B(N);
  for (i = 0; i < N; i++){
    cin >> A[i];
    if (A[i] < 0){
      neg_cnt++;
    }
  }
  for (i = 0; i < N; i++){
    B[i] = abs(A[i]);
  }
  int acm = 0;
  int min = *min_element(B.begin(), B.end());
  acm = accumulate(B.begin(), B.end(), 0);
  if (neg_cnt%2 == 0){
    cout << acm << endl;
  }else{
    cout << acm - 2*min << endl;
  }
}
Problem p03069 (python)

Fixed submission:
N = int(input())
S = input()
  
v = [S.count(".")]
for i in range(N):
  if S[i] == "#":
    v.append(v[i]+1)
  else:
    v.append(v[i]-1)
print(min(v))

Buggy submission (verdict: Runtime Error):
from itertools import groupby
N = int(input())
S = input()
b = 0
w = 0
x = ""
for i, (k, v) in enumerate(groupby(S)):
  if not x:
    if k == ".":
      continue
  v = len(list(v))
  if k == "#":
    b += v
  else:
    w += v
  x += k
if x[-1] == "#":
  b -= v
print(min(b,w))
Problem p03074 (python)

Fixed submission:
def main():
  from itertools import groupby

  N, K = map(int,input().split())
  S = input()

  num = []
  cot = []
  for k, n in groupby(S):
    num.append(k)
    cot.append(len(list(n)))

  if num[-1] == "0":
    cot += [0]
    num += [0]

  X = [0]*(len(cot)+1)
  for i in range(len(cot)):
    X[i+1] = X[i]+cot[i]

  ans = 0
  for i in range(len(X)):
    x = K*2
    if num[i] == "1":
      x += 1
    try:
      ans = max(ans, X[i+x]-X[i])
    except:
      break
  if ans == 0:
    ans = len(S)
  print(ans)

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  from itertools import groupby

  N, K = map(int,input().split())
  S = input()

  num = []
  cot = []
  for k, n in groupby(S):
    num.append(k)
    cot.append(len(list(n)))

  if num[-1] == "0":
    cot += [0]

  X = [0]*(len(cot)+1)
  for i in range(len(cot)):
    X[i+1] = X[i]+cot[i]

  ans = 0
  for i in range(len(X)):
    x = K*2
    if num[i] == "1":
      x += 1
    try:
      ans = max(ans, X[i+x]-X[i])
    except:
      break
  if ans == 0:
    ans = len(S)
  print(ans)

if __name__ == '__main__':
  main()
Problem p03076 (python)

Fixed submission:
X = [input() for _ in range(5)]
endzero = 0
elesnum = []
for x in X:
  if x[-1] == "0":
    endzero += int(x)
  else:
    elesnum.append(x)
if elesnum:
  elesnum.sort(key = lambda x: x[-1])
  min_ = int(elesnum[0])
  for e in elesnum[1:]:
    endzero += (int(e)//10+1)*10
  print(endzero+min_)
else:
  print(endzero)

Buggy submission (verdict: Runtime Error):
X = [str(input()) for _ in range(5)]
endzero = 0
elesnum = []
for x in X:
  if x[-1] == "0":
    endzero += int(x)
  else:
    elesnum.append(x)
elesnum.sort(key = lambda x: x[-1])
min_ = int(elesnum[0])
for e in elesnum[1:]:
  endzero += (int(e)//10+1)*10
print(endzero+min_)

Buggy submission (verdict: Runtime Error):
a = str(input())
b = str(input())
c = str(input())
d = str(input())
e = str(input())
X = [a, b, c, d, e]
endzero = 0
elesnum = []
for x in X:
  if x[-1] == "0":
    endzero += int(x)
  else:
    elesnum.append(x)
elesnum.sort(key = lambda x: x[-1])
min_ = int(elesnum[0])
for e in elesnum[1:]:
  endzero += (int(e)//10+1)*10
print(endzero+min_)

Buggy submission (verdict: Runtime Error):
X = [str(input()) for _ in range(5)]

endzero = 0
elesnum = []
for x in X:
  if x[-1] == "0":
    endzero += int(x)
  else:
    elesnum.append(x)
elesnum.sort(key = lambda x: x[-1])
last = elesnum[0]
for e in elesnum[1:]:
  endzero += (int(e)//10+1)*10
print(endzero+int(last))
Problem p03086 (python)

Fixed submission:
import re
ptn = re.compile(r"(A|C|T|G)*")

S = input()
T = set()
xx=ptn.match("FAFA")
for i in range(len(S)):
  for j in range(len(S)):
    x = ptn.match(S[i:i+j+1])
    if(x.group(0)):
      T.add(len(x.group(0)))
try:
  print(max(T))
except:
  print(0)

Buggy submission (verdict: Runtime Error):
import re
ptn = re.compile(r"(A|C|T|G)*")

S = input()
T = set()
for i in range(len(S)):
  for j in range(len(S)):
    x = ptn.match(S[i:i+j+1])
    if(x.group(0)):
      T.add(len(x.group(0)))
print(max(T))
Problem p03110 (python)

Fixed submission:
N = int(input())
btc = 380000
cnt = 0
for _ in range(N):
  x, u = input().split()
  x = float(x)
  if(u == 'JPY'):
    cnt += x
  else:
    cnt += 380000*x
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())

n = ni()
btc = 380000
ans = 0
for _ range(n):
  a, b = ns().split()
  if b == "BTC":
    ans += float(a) * btc
  else:
    ans += int(a)
print(ans)
Problem p03131 (python)

Fixed submission:
K, A, B = map(int,input().split())

if(A >= B-1 or 1+K <= A):
  print(K+1)
else:
  print((K-(A-1))//2*(B-A)+A+(K-(A-1))%2)

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

bis = 1
while K > 0:
  if(bis+1 > B):
    bis += 1
    K -= 1
  else:
    if(bis%A == 0):
      bis = 0
    else:
      bis //= A
    bis += B*max(bis//A, 1)
    K -= 2
print(bis)
Problem p03156 (python)

Fixed submission:
N = int(input())
A, B = map(int,input().split())
P = list(map(int,input().split()))
a, b, c = 0, 0, 0
for p in P:
  if p <= A:
    a += 1
  elif A+1 <= p <= B:
    b += 1
  elif p >= B+1:
    c += 1
print(min(a, b, c))

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

cnt = 0
for i in range(N):
  if(P[i] <= A):
    if(A+1 <= P[i+1] <= B):
      if(P[i+2] >= B+1):
        cnt += 1
print(cnt)
Problem p03161 (python)

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

dp = [1e9]*N
dp[0] = 0
for i, b in enumerate(H):
  if i != 0:
    x = max(0, i-K)
    dp[i] = min([abs(b-d)+p for d, p in zip(H[x:i], dp[x:i])])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> H(N);
  rep(i, N) cin >> H[i];

  vector<int> dp(N, INT_MAX);
  dp[0] = 0;
  rep(i, N)
  for (int j = 1; j <= K; j++){
    if (i+j < N){
      dp[i+j] = min(dp[i+j], dp[i]+abs(H[i]-H[i+j]));
    }else{
      break;
    }
  }
  cout << dp[N-1] << endl;
}
Problem p03194 (python)

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

def calc(n):
  num = {}
  e, i = 0, 2
  while i**2 <= n:
    while n%i == 0:
      n //= i
      e += 1
    if(e > 0):
      num[i] = e
    i += 1
    e = 0
  return num

if(N == 1):
  print(P)
  exit()
elif(P == 1):
  print(1)
  exit()
else:
  cnt = 1
  for k, v in calc(P).items():
    if(v >= N):
      cnt *= k ** (v//N)
  print(cnt)

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

if(N == 1):
  print(P)
  exit()
elif(P == 1):
  print(1)
  exit()

num = {}
s, e, i = 0, 0, 2
while s == 0:
  while p%i == 0:
    p //= i
    e += 1
    if(p == 1):
      s = 1
  if(e > 0):
    num[i] = e
  i += 1
  e = 0
cnt = 1
for k, v in num.items():
  if(v >= n):
    cnt *= k ** (v//n)
print(cnt)
Problem p03244 (python)

Fixed submission:
N = int(input())
V = list(map(int,input().split()))
even = [0] * (10 ** 5 + 10)
odd = [0] * (10 ** 5 + 10)
for v in V[1::2]:
  even[v] += 1
for v in V[::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  even.sort(reverse = True)
  odd.sort(reverse = True)
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
V = list(map(int,input().split()))
even = Counter(V[1::2]).most_common()+([0, 0])
odd = Counter(V[::2]).most_common()+([0, 0])
if(even[0][0] != odd[0][0]):
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[1][1]-odd[0][1], N-even[0][1]-odd[1][1]))

Buggy submission (verdict: Runtime Error):
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*10001
  odd = [0]*10001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[2]-odd[-1]))
ans()

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
nums = [v for v in V if V.count(x) != int(N/2)]
print(int(len(nums)/2))
Problem p03262 (python)

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

sub_list = []
for i in range(N):
  sub_list.append(abs(x[i] - X))
ans = sub_list[0]
for i in range(N):
  if(sub_list[i]%ans != 0):
    ans = gcd(ans, sub_list[i])
print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(int,input().split())
x = list(map(int,input().split()))
if(N == 1):
  print(x[0] - 1)
  exit()

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

sub_list = []
for i in range(N-1):
  sub_list.append(abs(x[i] - x[i+1]))

ind = 0
for i in range(1,len(sub_list)):
  ans = gcd(sub_list[ind], sub_list[i])
print(ans)
Problem p03264 (python)

Fixed submission:
K = int(input())
if(K % 2 == 0):
  print(int(K/2)**2)
else:
  ceil = int((K + 1)/2)
  print(ceil**2 - ceil)

Buggy submission (verdict: Runtime Error):
K = int(input())

print(K//2)*((K+1)//2)
Problem p03273 (python)

Fixed submission:
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
print("\n".join(HW))

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

tmp = []
for a in zip(*A):
  if(a.count("#") > 0):
    tmp.append("".join(a))
tmp2 = []
for t in zip(*tmp):
  if(t.count("#") > 0):
    tmp2.append("".join(t))
print("\n".join(tmp2))
Problem p03284 (python)

Fixed submission:
N, K = map(int,input().split())
if(N%K == 0):
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
if(N%K == 0)
  print(0)
else:
  print(1)