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

Fixed submission:
List = list(map(int,input().split()))
N = List[0]
A = List[1]
B = List[2]

if A*N <= B:
    print(A*N)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
List = list(map(int,input().split()))
L = List[0]
R = List[1]
count_dict = {}
count_list = []
if R - L >= 2019:
    print(0)
else:
    for i in range(L,R+1):
        for j in range(i,R+1):
            count_dict[i,j]  = (i * j) % 2019

    for i in count_dict.values():
        count_list.append(i)

    sort_list = sorted(count_list)
    print(sort_list[0])
Problem p03006 (python)

Fixed submission:
N = int(input())

position = []
for n in range(N):
    x, y = map(int, input().split())
    position.append((x, y))

if (N != 1):
    dis_dic = {}
    for n in range(N):
        for m in range(N):
            if (n != m):
                distance_tuple = (position[n][0] - position[m]
                                  [0], position[n][1] - position[m][1])

                if distance_tuple in dis_dic.keys():
                    dis_dic[distance_tuple] += 1
                else:
                    dis_dic[distance_tuple] = 1

    print(N - max(dis_dic.values()))
else:
    print(1)

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

position = []
for n in range(N):
    x, y = map(int, input().split())
    position.append((x, y))

dis_dic = {}
for n in range(N):
    for m in range(N):
        if (n != m):
            distance_tuple = (position[n][0] - position[m]
                              [0], position[n][1] - position[m][1])

            if distance_tuple in dis_dic.keys():
                dis_dic[distance_tuple] += 1
            else:
                dis_dic[distance_tuple] = 1

print(N - max(dis_dic.values()))
Problem p02608 (python)

Fixed submission:
n = int(input())

ans = [0] * 10050
for x in range(1,105):
    for y in range(1,105):
        for z in range(1,105):
            tmp = x*x + y*y + z*z + x*y + y*z + z*x
            if tmp<10050:
                ans[tmp] += 1

for i in range(n):
    print(ans[i+1])

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

ans = [0] * 10010
for x in range(1,n//2):
    for y in range(1,n//2):
        for z in range(1,n//2):
            tmp = x*x + y*y + z*z + x*y + y*z + z*x
            ans[tmp] = ans[tmp] + 1

for i in range(1,n+1):
    print(ans[i])

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

ans = [0] * 10010
for x in range(1,n):
    for y in range(1,n):
        for z in range(1,n):
            tmp = x*x + y*y + z*z + x*y + y*z + z*x
            ans[tmp] = ans[tmp] + 1

for i in range(1,n+1):
    print(ans[i])
Problem p02708 (python)

Fixed submission:
MOD = 10 ** 9 + 7
n, k = map(int, input().split())

def calc(a):
  smallest = a * (a-1) // 2
  largest = smallest + a * (n-a+1)
  return largest - smallest + 1

ans = 0
for a in range(k, n+2):
  ans += calc(a)
  ans %= MOD
  
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
n, k = map(int, input().split())

def calc(a):
  smallest = a * (a-1) / 2
  largest = smallest + a * (n-a+1)
  return latgest -smallest + 1

ans = 0
for a in range(k, n+2):
  ans += calc(a)
  ans %= MOD
  
print(ans)
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.append(-1)
up = []
pre = False
sw = False
for i in range(1,N+1):
    if A[i] > A[i-1]:
        sw = True
    elif A[i] < A[i-1]:
        sw = False
    if sw != pre:
        up.append(i-1)
    pre = sw
if up == []:
    print(1000)
    exit()
money = 1000
p = False
for j in up:
    if p == False:
        stock = money//A[j]
        money -= stock*A[j]
    else:
        money += stock*A[j]
        stock = 0
    p = not p
print(money)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.append(-1)
up = []
pre = False 
for i in range(1,N+1):
    if A[i] > A[i-1]:
        sw = True
    elif A[i] < A[i-1]:
        sw = False
    if sw != pre:
        up.append(i-1)
    pre = sw
if up == []:
    print(1000)
    exit()
money = 1000
p = False
for j in up:
    if p == False:
        stock = money//A[j]
        money -= stock*A[j]
    else:
        money += stock*A[j]
        stock = 0
    p = not p
print(money)
Problem p02675 (python)

Fixed submission:
N = int(input())
H = [2,4,5,7,9]
P = [0,1,6,8]
B = [3]
if N%10 in H:
    print("hon")
if N%10 in P:
    print("pon")
if N%10 in B:
    print("bon")

Buggy submission (verdict: Runtime Error):
print("Yes")
N, M = map(int, input().split())
path = [[] for _ in range(N)]
ind = [0 for _ in range(N)]
lis = set()
for o in range(N):
    lis.add(o)
for i in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)
que = path[0]
for p in que:
    lis.discard(p)
for l in que:
    U = lis & set(path[l])
    for m in U:
        ind[m] = l
        lis.discard(m)
    que = U
    if lis == {}:
        break
for z in range(1,N):
    ind[z] += 1
    print(ind[z])
Problem p02678 (python)

Fixed submission:
print("Yes")
N, M = map(int, input().split())
path = [[] for _ in range(N)]
ind = [0 for _ in range(N)]
lis = [0] + [1 for _ in range(N-1)]
for i in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)
que = path[0]
for p in que:
    lis[p] = 0
for l in que:
    U = path[l]
    for m in U:
        if lis[m] ==1:
            ind[m] = l
            lis[m] = 0
            que.append(m)
    if lis == {}:
        break
for z in range(1,N):
    ind[z] += 1
    print(ind[z])

Buggy submission (verdict: Runtime Error):
print("Yes")
N, M = map(int, input().split())
path = [[] for _ in range(N)]
ind = [0 for _ in range(N)]
lis = []
for o in range(N):
    lis.append(o)
for i in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)
que = path[0]
for p in que:
    lis.discard(p)
for l in que:
    U = path[l]
    for m in U:
        if m in lis:
            ind[m] = l
            lis.discard(m)
    que += U
    if lis == {}:
        break
for z in range(1,N):
    ind[z] += 1
    print(ind[z])
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int,input().split()))
P = 0
Q = [0] + [1 for _ in range(N-1)]
R = [-1] + [0 for _ in range(N-1)]
L = 0
for i in range(K):
    P = A[P]-1
    if Q[P] == 0:
        L = i - R[P]
        S = (K - R[P] - 1) % L
        G = 0
        for j in range(S + R[P] + 1):
            G = A[G]-1
        print(G+1)
        exit()
    if Q[P] == 1:
        R[P] = i
        Q[P] = 0
print(P+1)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int,input().split()))
P = 0
Q = [0] + [1 for _ in range(N-1)]
R = [-1] + [0 for _ in range(N-1)]
L = 0
for i in range(K):
    P = A[P]-1
    if Q[P] == 0:
        L = i - R[P]
        break
    if Q[P] == 1:
        R[P] = i
        Q[P] = 0
S = (K - R[P] - 1) % L
G = 0
for j in range(S + R[P] + 1):
    G = A[G]-1
print(G+1)

Buggy submission (verdict: Runtime Error):
import copy
N, K = map(int, input().split())
A = list(map(int,input().split()))
P = 0
Q = [0] + [1 for _ in range(N-1)]
R = [-1] + [0 for _ in range(N-1)]
L = 0
for i in range(K):
    P = copy.deepcopy(A[P]-1)
    if Q[P] == 0:
        L = copy.deepcopy(i - R[P])
        break
    if Q[P] == 1:
        R[P] = copy.deepcopy(i)
        Q[P] = 0
S = copy.deepcopy((K - R[P] - 1) % L)
G = 0
for j in range(S + R[P] + 1):
    G = copy.deepcopy(A[G]-1)
print(G+1)

Buggy submission (verdict: Runtime Error):
import copy
N, K = map(int, input().split())
A = list(map(int,input().split()))
P = 0
Q = [0] + [1 for _ in range(N-1)]
R = [-1] + [0 for _ in range(N-1)]
L = 0
for i in range(K):
    P = A[P]-1
    if Q[P] == 0:
        L = copy.deepcopy(i - R[P])
        break
    if Q[P] == 1:
        R[P] = copy.deepcopy(i)
        Q[P] = 0
S = (K - R[P] - 1) % L
G = 0
for j in range(S + R[P] + 1):
    G = A[G]-1
print(G+1)
Problem p02765 (python)

Fixed submission:
print((lambda x:(int(x[1])+(100*(10 - (10 if int(x[0])>=10 else int(x[0]))))))(input().split()))

Buggy submission (verdict: Runtime Error):
print((lambda x:(int(x[1])+(100*(10 - (10 if x[0]>=10 else x[0])))))(input().split()))

Buggy submission (verdict: Runtime Error):
print((lambda x:(int(x[1])+(100*(10 - 10 if x[0]>=10 else x[0]))))(input().split()))

Buggy submission (verdict: Runtime Error):
print((lambda x:int(x[1])+(100*(10 - 10 if x[0]>=10 else x[0])))(input().split()))
Problem p02783 (python)

Fixed submission:
print((lambda x: (x[0]-1)//x[1]+1)(list(map(int,input().split()))))

Buggy submission (verdict: Runtime Error):
print((lambda x: x[0]//x[1])(map(int,input().split())))
Problem p02830 (python)

Fixed submission:
N = int(input())
S,T = map(str,input().split())
ans = ''
for i in range(N):
  ans += S[i] + T[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S,T = map(,input().split())
M = len(S)
ans = ''
for i in range(M):
  ans += S[i] + T[i]
print(ans)
Problem p02882 (python)

Fixed submission:
import math
a,b,x = map(int,input().split())
if x == a*a*b:
    print(0)
    exit()
if a*a*b/2 < x:
    x = a*a*b - x
    b = x*2/(a*a)
p = x*2/(a*b)
print(math.degrees(math.atan(b/p)))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
if a*a*b/2 < x:
    x = a*a*b - x
    b = x*2/(a*a)
p = x*2/(a*b)
print(math.degrees(math.atan(b/p)))
Problem p02996 (python)

Fixed submission:
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
lis = []
for i in range(N):
    lis.append(map(int,input().split()))
lis.sort(key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')
Problem p03227 (python)

Fixed submission:
S = input()
if len(S) == 2:
  print(S)
if len(S) == 3:
  print(S[2]+S[1]+S[0])

Buggy submission (verdict: Runtime Error):
if len(S) == 2:
  print(S)
if len(S) == 3:
  print(S[2]+S[1]+S[0])
Problem p03567 (python)

Fixed submission:
S = input()
if "AC" in S:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
S = input()
if "AC" in S:
	print('Yes')
else
	print('No')
Problem p03633 (python)

Fixed submission:
import fractions
N = int(input())
G = 1
for i in range(N):
    D = int(input())
    G = G * D // fractions.gcd(G, D)
print(G)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
G = 1
for i in range(N):
    D = int(input())
    lcm = math.gcd(G, D)
    G = G * D // lcm
print(G)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
G = 1
for i in range(N):
    D = int(input())
    lcm = math.floor(math.gcd(G, D))
    G = G * D // lcm
print(G)
Problem p03944 (python)

Fixed submission:
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if q < p or s < r:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
W, H, N = map(int,input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        if x > p:
            p = x
    if a == 2:
        if x < q:
            q = x
    if a == 3:
        if y > r:
            r = y
    if a == 4:
        if y < s:
            s = y
ans = (q-p)*(s-r)
if ans < 0
    ans = 0
print(ans)
Problem p02995 (python)

Fixed submission:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

def lcm(a, b):
    return a * b // gcd(a, b)

def calc(n, a, b):
    return n//a + n//b - n//lcm(a,b)

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ## これで通った
    # num1 = b - calc(b,c,d)
    # num2 = (a-1) - calc(a-1, c,d)
    # print(num1-num2)

    ## これはとおらない
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return int(math.gcd(a, b))

def lcm(a, b):
    return a / gcd(a, b) * b

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import math

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a / gcd(a, b) * b

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans + 1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import math

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a / gcd(a, b) * b

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans + 1)
Problem p03369 (python)

Fixed submission:
s = raw_input()
print 700+s.count('o')*100

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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


    
    string s;
    cin >> s ;
    cout << 700 + 100 * count(all(s), 'o') << endl;

    
  
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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


    
    string s;
    cin >> s ;
    cout << 700 + 100 * count(all(s), 'o');

    
  
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}
Problem p03000 (python)

Fixed submission:
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split()))

n,x = intMap()
l = intList()

ans = 1
d = 0

for i in range(n):
    d += l[i]
    if d > x: break
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split()))

n,x = intMap()
l = intList()

d = 0
i = 0

while d <= x:
    d = d + l[i]
    i += 1
    if i > n: break
    
ans = min(i,n)
print(ans)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split)
print(A*B)
Problem p02675 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
N %= 10
if N == 3:
    ans = 'bon'
elif N in [0, 1, 6, 8]:
    ans = 'pon'
else:
    ans = 'hon'
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]


import logging
import sys
import unittest
from io import StringIO

logging.basicConfig(level=logging.DEBUG)


def resolve():
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

N=input_int()
N%=10
if N==3:
    ans = 'bon'
elif N in [0, 1, 6, 8]:
    ans = 'pon'
else:
    ans = 'hon'
print(ans)
Problem p02702 (python)

Fixed submission:
S = list(input())
N = len(S)
# N 文字の文字列 S から、長さ N+1 の ---累積和--- s[0], s[1], ..., s[N] を作る
# これを 2019 で割ったあまりで分類する (具体的には counter[ r ] := あまりが r のやつが何個あるか)
# 各 r ごとに、counter[r] 個から 2 個選ぶ方法の数を、足し上げる

counter = [0] * 2019
k = 10
for i in range(N + 1):
    if i == 0:
        sub = 0
    elif i == 1:
        sub = int(S[N - 1])
    else:
        sub += int(S[N - i]) * k
        k *= 10
        k %= 2019
    rest = sub % 2019
    counter[rest] += 1

ans = 0
for r in counter:
    ans += r * (r - 1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
N = len(S)
# N 文字の文字列 S から、長さ N+1 の ---累積和--- s[0], s[1], ..., s[N] を作る
# これを 2019 で割ったあまりで分類する (具体的には counter[ r ] := あまりが r のやつが何個あるか)
# 各 r ごとに、counter[r] 個から 2 個選ぶ方法の数を、足し上げる

counter = [0] * 2019
indices = []
k = 10
for i in range(N + 1):
    if i == 0:
        sub = 0
        counter[i] = 0
    elif i == 1:
        sub = int(S[N - 1])
        counter[i] = sub % 2019
    else:
        # sub = int(S[N - i] + str(sub))
        sub += int(S[N - i]) * k
        k *= 10

        counter[i] = counter[i-1] + sub
        counter[i] %= 2019
        k %= 2019

    # rest = sub % 2019  # N桁のあまりを求めるのにO(N)かかる．前の桁を有効活用する(dp)
    # counter[rest] += 1

ans = 0
for r in counter:
    ans += r * (r - 1) // 2
print(ans)
Problem p02714 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
S = input()

if N < 3:
    print(0)
    exit()
rs = []
gs = []
bs = []
for i in range(len(S)):
    if S[i] == 'R':
        rs.append(i)
    elif S[i] == 'G':
        gs.append(i)
    else:
        bs.append(i)
count = len(rs) * len(gs) * len(bs)
# for r in rs:
#     for g in gs:
#         for b in bs:
#             rgb = [r, g, b]
#             rgb.sort()
#             if rgb[1]-rgb[0] != rgb[2]-rgb[1]:
#                 count += 1

for skip in range(1, N // 2 + 1):
    for i in range(N - 2):
        if i + 2 * skip > N - 1:
            break
        elif S[i] == S[i + skip] or S[i + skip] == S[i + 2 * skip] or S[i] == S[i + 2 * skip]:
            continue
        else:
            count -= 1

print(count)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
S = input()

if N < 3:
    print(0)
    return
count = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):

        for k in range(j + 1, N):
            if S[i] == S[j] or S[j] == S[k] or S[i] == S[k] or j - i == k - j:
                continue
            else:
                count += 1
print(count)