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

Fixed submission:
x,y,a,b,c=map(int,input().split())
*p,=sorted(map(int, input().split()))
*q,=sorted(map(int, input().split()))
*r,=map(int, input().split())

p=p[-x:]
q=q[-y:]
r=sorted(p+q+r)
print(sum(r[-x-y:]))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define D deque
#define PII pair<int, int>
#define P pair
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(grid) (grid).begin(), (grid).end()
#define rall(grid) (grid).rbegin(), (grid).rend()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

template <typename T>
void read(T& a) {
  a = 0;
  char c;
  while ((c = cin.peek()) < 48 or c > 57) cin.get();
  while ((c = cin.get()) > 47 and c < 58) a = (a << 3) + (a << 1) + c - 48;
}

template <typename T, typename... Args>
void read(T& a, Args&&... args) {
  read(a);
  read(forward<Args>(args...)...);
}

template <typename T>
void write(const S& sep, const S& end, T n) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(end.c_str(), end.size() * sizeof(char));
}

template <typename T, typename... Args>
void write(const S& sep, const S& end, T n, Args&&... args) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(sep.c_str(), sep.size() * sizeof(char));
  write(sep, end, forward<Args>(args...)...);
}
void solve() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  V<unsigned LL> red(a), green(b), colourless(c);
  FOR(i, a) {
      cin >> red[i];
  }
  FOR(i, b) {
      cin >> green[i];
  }
  FOR(i, c) {
      cin >> colourless[i];
  }
  sort(rall(red));
  sort(rall(green));
  FOR(i, x) {
      colourless.push_back(red[i]);
  }
  FOR(i, x) {
      colourless.push_back(green[i]);
  }
  sort(rall(colourless));
  cout << accumulate(begin(colourless), begin(colourless) + x + y, 0ULL) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
Problem p02732 (python)

Fixed submission:
n = int(input())
*li,=map(int, input().split())
from collections import Counter
c = Counter()
for i in li:
    c[i] += 1
ans=0
from math import comb
for i in c.values():
    ans += comb(i, 2)
for i in li:
    print(ans - comb(c[i], 2) + comb(c[i]-1, 2))

Buggy submission (verdict: Runtime Error):
n = int(input())
*li,=map(int, input().split())
from collections import Counter
c = Counter()
for i in li:
    c[i] += 1
ans=0
from math import comb
for i in c.values():
    ans += comb(i, 2)
for i in li:
    print(ans - comb(c[i], 2) + comb(c[i-1], 2))
Problem p02534 (python)

Fixed submission:
s=str("ACL")
n=int(input())
print(s*n)

Buggy submission (verdict: Runtime Error):
s=str("As=str("ACL")
n=int(input())
print(s*n)
Problem p02554 (python)

Fixed submission:
N = int(input())
MOD = 10 ** 9 + 7
if N == 1:
  print(0)
  exit()
a = pow(10, N, MOD)
b = pow(9, N, MOD)
c = pow(8, N, MOD)
ans = (a - (2 * b) + c) % MOD
if ans < 0:
  ans += MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
MOD = 10 ** 9 + 7
if N == 1:
  print(0)
  exit()
a = 1
b = 1
c = 1
for i in range(N):
  a = pow(10, n, MOD)
  b = pow(9, n, MOD)
  c = pow(8, n, MOD)
ans = a - (2 * b) + c
if ans < 0:
  ans += MOD
print(ans)
Problem p02818 (python)

Fixed submission:
A, B, K = list(map(int, input().split()))
A -= K
if A < 0:
  B += A
  A = 0
if B < 0:
  B = 0
print(A, B)

Buggy submission (verdict: Runtime Error):
A, B, K = list(map(int, input().split()))
A -= K
if A < 0:
  B += A
  A = 0
if B < 0:
  B = 0
print(A, B)a
Problem p02882 (python)

Fixed submission:
import math
A, B, X = map(int, input().split())
h = X / (A*A)
r = 0
deg = 0
if (2 * X) - (B * A * A) > 0:
  r = math.atan(2 * (B-h) / A)
elif (2 * X) - (B * A * A) == 0:
  r = math.atan(B / A)
else:
  h = (2 * X) / (A * B)
  r = math.atan(B / h)
deg = math.degrees(r)
print(deg)

Buggy submission (verdict: Runtime Error):
import math
A, B, X = map(int, input().split())
h = X / (A*A)
r = 0
deg = 0
if (2 * X) - (B * A * A) > 0:
  r = math.atan(2 * (B-H) / A)
elif (2 * X) - (B * A * A) == 0:
  r = math.atan(B / A)
else:
  h = (2 * X) / (A * B)
  r = math.atan(B / h)
deg = math.degrees(r)
print(deg)
Problem p02741 (python)

Fixed submission:
a=[1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
print(a[int(input())-1])

Buggy submission (verdict: Runtime Error):
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())])
Problem p02818 (python)

Fixed submission:
a,b,k = map(int , input().split())
if a < k:
    b = (a + b) - k
    if b < 0:
        b = 0
    a = 0
elif a >= k:
    a = a - k
print(a,b)

Buggy submission (verdict: Runtime Error):
a,b,c = input().split(' ')
for i in range(int(c)):
  if int(a) >= 1:
    a = int(a) - 1
  else:
    b = int(b) - 1
print(a + " " + b)
Problem p03079 (python)

Fixed submission:
a = input().split()
if a[0] == a[1] and a[1] == a[2]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
if a[0] == a[1] and a[1] == a[2]:
    print("Yes")
else:
    print("No")
Problem p03192 (python)

Fixed submission:
print(input().count("2"))

Buggy submission (verdict: Runtime Error):
print(input().count())

Buggy submission (verdict: Runtime Error):
a = input().split()
b = 0
for i in range(2):

    a.sort(reverse=True)
    print(a)
    b = b + int(a[1])
    a[1] = str(int(a[1]) - 1)
print(b)
Problem p03206 (python)

Fixed submission:
D = int(input())
if D == 22:
    print("Christmas Eve Eve Eve")
elif D == 23:
    print("Christmas Eve Eve")
elif D == 24:
    print("Christmas Eve")
elif D == 25:
    print("Christmas")

Buggy submission (verdict: Runtime Error):
if a == 22:
    print("Christmas Eve Eve Eve")
elif a == 23:
    print("Christmas Eve Eve")
elif a == 24:
    print("Christmas Eve")
elif a == 25:
    print("Christmas")

Buggy submission (verdict: Runtime Error):
if a == "22":
    print("Christmas Eve Eve Eve")
elif a == "23":
    print("Christmas Eve Eve")
elif a == "24":
    print("Christmas Eve")
elif a == "25":
    print("Christmas")
Problem p03455 (python)

Fixed submission:
a,b = map(int,input().split())
if (a * b) % 2 == 1:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
if (a * b) % 2 == 1:
    print("Odd")
else:
    print("Even")
Problem p03719 (python)

Fixed submission:
a,b,c=map(int,input().split())
if c >= a and c <= b:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a + b >= 10:
    print("error")
else:
    print(a + b)
Problem p02574 (python)

Fixed submission:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    targets = LI()
    MAX_INT = max(targets) + 1
    counter = cl.Counter(targets)
    targets = set(targets)
    is_pw = True

    num_1 = counter[1]
    if num_1 > 1:
        N -= num_1 - 1

    if len(targets) != N:
        is_pw = False

    if len(targets) == 1:
        if 1 in targets:
            print("pairwise coprime")
            return
        print("not coprime")
        return

    for i in range(2, MAX_INT):
        origin = i
        kosuu = 0
        while origin <= MAX_INT:
            if origin in targets:
                kosuu += 1
            origin += i

        if kosuu <= 1:
            continue
        elif kosuu < len(targets):
            is_pw = False
        else:
            print("not coprime")
            return

    if is_pw:
        print("pairwise coprime")
        return
    print("setwise coprime")


main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    targets = LI()
    MAX_INT = max(targets) + 1
    targets = set(targets)
    is_pw = True

    if len(targets) != N:
        is_pw = False

    if len(targets) == 1:
        if targets[0] == 1:
            print("setwise coprime")
            return
        print("not coprime")
        return

    for i in range(2, MAX_INT):
        origin = i
        kosuu = 0
        while origin <= MAX_INT:
            if origin in targets:
                kosuu += 1
            origin += i

        if kosuu <= 1:
            continue
        elif kosuu < len(targets):
            is_pw = False
        else:
            print("not coprime")
            return

    if is_pw:
        print("pairwise coprime")
        return
    print("setwise coprime")


main()
Problem p02642 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    A = LI()
    A.sort()
    MAX = A[-1]+1
    All = [0 for i in range(MAX)]

    setA = set(A)
    for i in A:
        k = i
        All[k] += 1
        k += i
        if All[i] == 2:
            continue
        while k < MAX and i in setA:
            All[k] += 1
            k += i

    ans = 0
    for i in range(1, MAX):
        if All[i] == 1 and i in setA:
            ans += 1

    print(ans)

    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

Buggy submission (verdict: Runtime Error):
def resolve():
    _ = int(input())
    targets = list(map(int, input().split()))

    targets = [x for x in set(targets) if targets.count(x) == 1]
    if len(targets) == 0:
        print(0)
        return
    targets.sort()
    targets = deque(targets)

    ans = []

    while len(targets) > 0:
        target = targets.popleft()
        ans.append(target)
        removeList = []
        for x in targets:
            if x % target == 0:
                removeList.append(x)
        for x in removeList:
            targets.remove(x)

    print(len(ans))

resolve()
Problem p02675 (python)

Fixed submission:
def resolve():
    a = int(input()[-1])
    hon = [2, 4, 5, 7, 9]
    pon = [0, 1, 6, 8]
    bon = [3]

    for _hon in hon:
        if a == _hon:
            print('hon')
    for _pon in pon:
        if a == _pon:
            print('pon')

    for _bon in bon:
        if a == _bon:
            print('bon')
resolve()

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


def resolve():
    n, m = map(int, input().split())
    ans = [-1 for i in range(n)]

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

    # stack = []
    # connected_to_one = [*connections[0]]

    # for room in connected_to_one:
    #     ans[room] = 1

    #     connections[0].remove(room)
    #     connections[room].remove(0)

    #     stack.append(room)

    D = deque([0])
    visited = [False]*n
    visited[0] = True

    while D:
        room = D.popleft()

        for i in connections[room]:
            if visited[i]:
                continue
            visited[i] = True
            ans[i] = room + 1
            D.append(i)

    _ans = ans[1:]

    if -1 in _ans:
        print('No')
    else:
        print('Yes')
        for i in _ans:
          
resolve()
Problem p02883 (python)

Fixed submission:
class Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()

Buggy submission (verdict: Runtime Error):
lass Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()
Problem p03049 (python)

Fixed submission:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    words = []
    starts_with_B = 0
    end_with_A = 0
    contain_AB = 0
    starts_with_B_and_end_with_A = 0
    for i in range(N):
        word = input()
        words.append(word)
        contain_AB += len(word) - len(word.replace("AB", "_"))

        if word[0] == "B" and word[-1] == "A":
            starts_with_B_and_end_with_A += 1
        elif word[0] == "B":
            starts_with_B += 1
        elif word[-1] == "A":
            end_with_A += 1

    if starts_with_B_and_end_with_A == 0:
        print(contain_AB + min(starts_with_B, end_with_A))
        return
    if starts_with_B + end_with_A == 0:
        print(contain_AB + starts_with_B_and_end_with_A - 1)
        return
    print(contain_AB + starts_with_B_and_end_with_A +
          min(starts_with_B, end_with_A))


main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    words = []
    starts_with_B = 0
    end_with_A = 0
    contain_AB = 0
    starts_with_B_and_end_with_A = 0
    for i in range(N):
        word = input()
        words.append(word)
        contain_AB += len(word) - len(word.replace("AB", "_"))

        if word[0] == "B" and word[-1] == "A":
            starts_with_B_and_end_with_A += 1
        elif word[0] == "B":
            starts_with_B += 1
        elif word[-1] == "A":
            end_with_A += 1

    if starts_with_B_and_end_with_A == 0:
        print(contain_AB + min(starts_with_B, end_with_A))
        return

    min_A_or_B = min(starts_with_B, end_with_A)
    amari = abs(starts_with_B - end_with_A)
    contain_AB += min_A_or_B

    if amari == 0:
        print(contain_AB)

    if amari >= starts_with_B_and_end_with_A:
        print(contain_AB + starts_with_B_and_end_with_A)
    else:
        available = starts_with_B_and_end_with_A // amari
        contain_AB += available * amari
        starts_with_B_and_end_with_A = starts_with_B % amari
        print(contain_AB + starts_with_B_and_end_with_A)


main()
Problem p03455 (python)

Fixed submission:
a,b=[int(x) for x in input().split()]
print("Even" if a %2 ==0 or b%2==0 else "Odd")

Buggy submission (verdict: Runtime Error):
a,b=[int(x) for x in input().split()]
    print("Even" if a %2 ==0 or b%2==0 else "Odd")
Problem p03456 (python)

Fixed submission:
import math
a,b= input().split()
target = int(a+b)
print("Yes" if math.pow(target,1/2).is_integer() else "No")

Buggy submission (verdict: Runtime Error):
a,b= input().split()
target = int(a+b)
print("Yes" if math.pow(target,1/2).is_integer() else "No")
Problem p02632 (python)

Fixed submission:
K = int(input())
S = input()
M = K + len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
mod = int(1e9) + 7 # <-- input modulo
maxf = 2000010           # <-- input factional limitation

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
  
SS = 0
bas = 1
for i in range(M, len(S)-1, -1):
  SS += (bas * invf[i] * invf[M-i]) % mod
  bas *= 25
  bas %= mod
  SS %= mod
print(SS*fact[M]%mod)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()
M = K + len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
mod = int(1e9) + 7 # <-- input modulo
maxf = 200000           # <-- input factional limitation

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
  
SS = 0
bas = 1
for i in range(M, len(S)-1, -1):
  SS += (bas * invf[i] * invf[M-i]) % mod
  bas *= 25
  bas %= mod
  SS %= mod
print(SS*fact[M]%mod)
Problem p02697 (python)

Fixed submission:
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    X = [0 for _ in range((N-1)//2)]
    l, r = 1, N // 2
    for i in range((N//2)//2):
        X[i] = [l, r]
        l += 1
        r -= 1
    l, r = N, N // 2 + 2
    for i in range((N-1)//2-(N//2)//2):
        X[i+(N//2)//2] = [l, r]
        l -= 1
        r += 1
    for i in range(M):
        print(X[i][0], X[i][1])
else:
    for i in range(M):
        print(N-i, i+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    l, r = 0, 1
    for i in range(M):
        X[l] = 1
        X[r] = 1
        print(l+1, r+1)
        if i < M - 1:
            while X[l] != 0 or X[(l+i+2)%N] != 0:
                l += 1
            r = (l + i + 2) % N
else:
    for i in range(M):
        print(N-i-1, i+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    l, r = 0, 1
    for i in range(M):
        X[l] = 1
        X[r] = 1
        print(l+1, r+1)
        if i < M - 1:
            while X[l] != 0 or X[(l+i+2)%N]:
                l += 1
            r = (l + i + 2) % N
else:
    for i in range(M):
        print(N-i-1, i+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    l, r = 0, 1
    for i in range(M):
        X[l] = 1
        X[r] = 1
        print(l+1, r+1)
        while X[l] != 0 or X[(l+i+2)%N]:
            l += 1
        r = (l + i + 2) % N
else:
    for i in range(M):
        print(N-i-1, i+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    l, r = 1, 2
    for i in range(M):
        X[l-1] = 1
        X[r-1] = 1
        print(l, r)
        while X[l-1] != 0:
            l += 1
        r = l + i + 2
else:
    for i in range(M):
        print(N-i-1, i+1)
Problem p02713 (python)

Fixed submission:
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[j][k]-1][i]
print(S)

Buggy submission (verdict: Runtime Error):
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[i][j]][k]
print(S)
Problem p02734 (python)

Fixed submission:
N, S = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
L = [0 for _ in range(S+1)]
p = 0
F = {0}
for i in range(N):
    L[0] += 1
    X = [[j, L[j]] for j in F]
    for j in X:
        if j[0] + A[i] <= S:
            L[j[0]+A[i]] += j[1]
            L[j[0]+A[i]] %= mod
            F.add(j[0]+A[i])
    p += L[S]
    p %= mod

print(p)

Buggy submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(map(int, input().split()))
D = {0: [[-1, -1]]}
for i in range(N):
    L = [[j, D[j]] for j in D]
    L.sort(reverse=True)
    for jn, j in enumerate(L):
        if j[0]+A[i] <= S:
            for kn, k in enumerate(j[1]):
                if j[0]+A[i] in D:
                    D[j[0]+A[i]].append([(j[0]>0)*k[0]+(j[0]==0)*i, i])
                else:
                    D[j[0]+A[i]] = [[(j[0]>0)*k[0]+(j[0]==0)*i, i]]
p = 0
for i in D[S]:
    p += (i[0] + 1) * (N - i[1])
print(p)