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

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt = 0
check = 0
ans = 1

a.sort(reverse=True)
for i in range(n - 1):
    if a[cnt] == a[cnt + 1]:
        check += 1
        ans *= a[cnt]
        cnt += 2
        if check == 2:
            print(ans)
            exit()
    else:
        cnt += 1

    if cnt == n - 1:
        break
print(0)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt = 0
check = 0
ans = 1

a.sort(reverse=True)
for i in range(n - 1):
    if a[cnt] == a[cnt + 1]:
        cnt += 2
        check += 1
        ans *= a[cnt]
        if check == 2:
            print(ans)
            exit()
    else:
        cnt += 1

    if cnt == n - 1:
        break
print(0)
Problem p03633 (python)

Fixed submission:
import fractions
import sys
input = sys.stdin.readline

n = int(input())
t = int(input())
ans = t
for i in range(1, n):
    t = int(input())
    ans = ans * t//fractions.gcd(ans, t)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import gcd

n = int(readline())
t = [int(readline()) for _ in range(n)]
ans = t[0]
for tt in t:
    ans = ans * tt // gcd(ans, tt)
print(ans)
Problem p03665 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, p = map(int, readline().split())
a = list(map(int, readline().split()))
cnt_1 = 0
cnt_2 = 0
for i in a:
    if i % 2 == 1:
        cnt_1 += 1
    else:
        cnt_2 += 1
ans = 2 ** max(0, cnt_1 - 1) * 2 ** cnt_2
if p == 1 and cnt_1 == 0:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, p, *a = map(int, read().split())
cnt_1 = 0
cnt_2 = 0
for i in a:
    if a[i] % 2 == 1:
        cnt_1 += 1
    else:
        cnt_2 += 1
ans = 2 ** max(0, cnt_1 - 1) * 2 ** cnt_2
if p == 1 and cnt_1 == 0:
    ans = 0
print(ans)
Problem p03719 (python)

Fixed submission:
import sys
input = sys.stdin.readline

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

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a, b, c = map(int, input().split())
if a <= c and b >= c:
    ans = 'Yes'
else
    ans = 'No'
print(ans)
Problem p03730 (python)

Fixed submission:
import sys
input = sys.stdin.readline

a, b, c = map(int, input().split())
for i in range(1, b):
    if (a*i)%b == c:
        print('YES')
        sys.exit()
print('NO')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a, b, c = map(nt, input().split())
for i in range(1, b):
    if (a*i)%b == c:
        print('YES')
        sys.exit()
print('NO')
Problem p03761 (python)

Fixed submission:
import sys
from collections import Counter
input = sys.stdin.readline

n = int(input())
s = []
memo = []
ans = ''
check = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
check_cnt = [50] * 26
for i in range(n):
    s.append(list(input().rstrip('\n')))
    s[i].sort()
    memo.append(list(Counter(s[i]).items()))

for i in range(n):
    for check_m in range(26):
        flg = False
        for j in range(len(memo[i])):
            if check[check_m] == memo[i][j][0]:
                if check_cnt[check_m] > memo[i][j][1]:
                    check_cnt[check_m] = memo[i][j][1]
                flg = True
                break
        if flg:
            continue
        else:
            check_cnt[check_m] = 0

for i in range(26):
    for j in range(check_cnt[i]):
        ans += check[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
input = sys.stdin.readline

n = int(input())
s = []
memo = []
ans = ''
for i in range(n):
    s.append(list(input().rstrip('\n')))
    s[i].sort()
    memo.append(list(Counter(s[i]).items()))
for i in range(1, n):
    check = [0] * len(memo[0])
    cnt = 0
    for j in range(len(memo[0])):
        if len(memo[i]) == cnt:
            continue
        memo[i][cnt] = list(memo[i][cnt])
        if memo[0][j][0] == memo[i][cnt][0]:
            if memo[0][j][1] > memo[i][cnt][1]:
                memo[0][j][1] = memo[i][cnt][1]
            cnt += 1
            check[j] = 1
        if check[j] == 0:
            memo[0][j] = list(memo[0][j])
            memo[0][j][1] = 0

for i in range(len(memo[0])):
    for j in range(memo[0][i][1]):
        ans += memo[0][i][0]
print(ans)
Problem p03840 (python)

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

ans = a[1] + 2*(a[0]//2 + a[4]//2 + a[3]//2)
if a[0]>0 and a[3]>0 and a[4]>0:
  ans = max(ans, a[1] + 2*((a[0]-1)//2 + (a[3]-1)//2 + (a[4]-1)//2) + 3)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def xv(num):
    return 2 * math.floor(0.5 * num)

a = list(map(int, input().split()))
ans = 0

Que = xv(a[0]) + xv(a[3]) + xv(a[4])

if (a[3] or a[4]) == 0:
    pass
else:
    a[0] = a[0] - 1
    a[3] = a[3] - 1
    a[4] = a[4] - 1

    Qae = 3 + xv(a[0]) + xv(a[3]) + xv(a[4])

ans = ans + a[1] + max(Que,Qae)
print(ans)
Problem p03970 (python)

Fixed submission:
s = input()
ans = 'CODEFESTIVAL2016'
cnt = 0
for i in range(len(s)):
  if s[i] != ans[i]:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()
ans = 'CODEFESTIVAL2016'
cnt = 0
for i in range(n):
  if s[i] != ans[i]:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()
ans = 'CODEFESTIVAL2016'
cnt = 0
for i in range(n):
  if s[i] = != ans[i]:
    cnt += 1
print(cnt)
Problem p03994 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(input())
k = int(input())
for i in range(len(s)):
    num = (ord('z') - ord(s[i]) + 1) % 26
    if num <= k:
        k -= num
        s[i] = 'a'
s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))
print(*s, sep='')

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
k = int(input())
al = [chr(ord('a') + i) for i in range(26)]
ans = ''
for i in range(len(s)):
    num = al.index(s[i])
    if 26 - num <= k:
        k -= 26 - num
        if i != len(s) - 1:
            ans += 'a'
        else:
            ans += al[k]
    else:
        if i != len(s) - 1:
            ans += s[i]
        else:
            ans += al[num + k]
print(ans)
Problem p03997 (python)

Fixed submission:
import sys
input = sys.stdin.readline

a = int(input())
b = int(input())
h = int(input())
ans = (a+b) * h * 0.5
print(int(ans))

Buggy submission (verdict: Runtime Error):
print((int(readline()) + int(readline())) * int(readline()) // 2)
Problem p03999 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

s = read().rstrip().decode()
ans = int(s[-1]) * (2 ** (len(s) - 1))
for bit in product(['', '+'], repeat=len(s) - 1):
    memo = 0
    for i, (bf, af) in enumerate(zip(s, s[1:])):
        memo += int(bf)
        if bit[i] == '+':
            ans += memo
            memo = 0
        else:
            memo *= 10
    ans += memo
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

s = read().rstrip().decode()
ans = 0
for bit in product(['', '+'], repeat=len(s) - 1):
    memo = 0
    for i, (bf, af) in enumerate(zip(s, s[1:])):
        memo += int(bf)
        if bit[i] == '+':
            ans += memo
            memo = 0
        else:
            memo *= 10
    memo += int(af)
    ans += memo
print(ans)
Problem p04033 (python)

Fixed submission:
import sys
input = sys.stdin.readline

a, b = map(int, input().split())
if a <= 0:
    if b >= 0:
        ans = 'Zero'
    elif b < 0 and (b-a)%2 == 0:
        ans = 'Negative'
    else:
        ans = 'Positive'
else:
    ans = 'Positive'
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a, b = map(int, input().split())
if a <= 0:
    if b >= 0:
        ans = 'Zero'
    elif b < 0 and (b-a+1)%2 == 1:
        ans = 'Negative'
else:
    ans = 'Positive'
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a, b = map(int, input().split())
if a <= 0:
    if b >= 0:
        ans = 'Zero'
    elif b < 0 and (b-a)%2 == 0:
        ans = 'Negative'
else:
    ans = 'Positive'
print(ans)
Problem p02812 (python)

Fixed submission:
def have_ABC_string(n, str):
    count = 0
    for i in range(n-2):
        if str[i] == 'A' and str[i+1] == 'B' and str[i+2] == 'C':
            count += 1
    return count

N = int(input())
S = input()
result = have_ABC_string(N, S)
print(result)

Buggy submission (verdict: Runtime Error):
def have_ABC_string(n, str):
    count = 0
    for i in range(n):
        if str[i] == 'A' and str[i+1] == 'B' and str[i+2] == 'C':
            count += 1
    return count

N = int(input())
S = input()
result = have_ABC_string(N, S)
print(result)
Problem p03007 (python)

Fixed submission:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = i2nn()
    A.sort()
    a0 = A[0]
    a3 = A[N-1]
    A12 = A[1:N-1]
    iz = bisect_left(A12, 0)
    A1 = A12[:iz]
    A2 = A12[iz:]

    logs = []
    def logging(x, y):
        logs.append('%d %d' % (x, y))
        return x - y
    x = a0
    for y in A2:
        x = logging(x, y)
    y = x
    x = a3
    x = logging(x, y)
    for y in A1:
        x = logging(x, y)
    print(x)
    for log in logs:
        print(log)

main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    xy = ii2nnn(N)
    dicx = defaultdict(lambda: 0)
    xy.sort(key=lambda v: v[1])
    xy.sort(key=lambda v: v[0])
    for i in range(1, len(xy)):
        dx = xy[i][0] - xy[i-1][0]
        dy = xy[i][1] - xy[i-1][1]
        if dx == 0 and dy == 0:
            continue
        key = '%d %d' % (dx, dy)
        dicx[key] += 1
    dicy = defaultdict(lambda: 0)
    xy.sort(key=lambda v: v[1])
    for i in range(1, len(xy)):
        dx = xy[i][0] - xy[i-1][0]
        dy = xy[i][1] - xy[i-1][1]
        if dx == 0 and dy == 0:
            continue
        key = '%d %d' % (dx, dy)
        dicy[key] += 1
    nm = 0
    for v in dicx.values():
        if nm < v:
            nm = v
    for v in dicy.values():
        if nm < v:
            nm = v
    print(N - nm)

main()
Problem p03039 (python)

Fixed submission:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MOD = int(1e+9) + 7

def comb(n, k):
    r = 1
    for i in range(n, max(n-k, k), -1):
        r *= i
    for i in range(1, min(n-k, k) + 1, 1):
        r //= i
    return r

class Comb:
    def __init__(self, MAX, MOD):
        MAX += 1
        fac = [0] * MAX
        finv = [0] * MAX
        inv = [0] * MAX
        fac[0] = fac[1] = 1
        finv[0] = finv[1] = 1
        inv[1] = 1
        for i in range(2, MAX):
            fac[i] = fac[i - 1] * i % MOD
            inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD
        self.fac = fac
        self.finv = finv
        self.MOD = MOD
    
    def comb(self, n, k):
        fac = self.fac
        finv = self.finv
        MOD = self.MOD
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    # 行数, 列数, 駒数
    N, M, K = i2nn()
    # 配置コストの総和 % MOD

    # 例）N, M, K = 2, 2, 2
    # 駒が置ける場所は4箇所: N * M
    # 駒の配置は6通り: comb(4, 2) = comb(N*M, K)
    # K=2 の場合のコスト
    xcost = 0
    for i in range(1, M):
        # iをx座標の差とする
        # x座標のみに注目した場合、差がiとなるのは(M-i)通り
        #   M=4, i=1, => (1,2), (2,3), (3,4) = 3通り
        #   M=4, i=2, => (1,3), (2,4) = 2通り
        #   M=4, i=3, => (1,4) = 1通り
        # さらにy座標の組み合わせは, 左側がN通り, 右側がN通り
        #   (1,2) について M=2 の場合 ((1,1), (2,1)), ((1,1), (2,2)), ((1,2), (2,1)), ((1,2), (2,2))
        xcost = (xcost + i * (M-i) * (N*N)) % MOD
    ycost = 0
    for i in range(1, N):
        ycost = (ycost + i * (N-i) * (M*M)) % MOD
    cost = (xcost + ycost) % MOD
    # K=3 の場合、K=2 の場合のコストを NM-2 倍すればよい
    # 汎用的に考えると、 K=2 の場合のコストを comb(MN-2, K-2) 倍すればよい
    #cost = (cost * comb(M*N-2, K-2)) % MOD
    cost = (cost * Comb(N*M-2, MOD).comb(N*M-2, K-2)) % MOD
    print(cost)

main()

Buggy submission (verdict: Runtime Error):
import sys
#import numpy as np
from scipy.special import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    L = max(M, N)
    dp = [0] * L
    for i in range(1, L):
        dp[i] = dp[i-1] + i
    n = 0
    for i in range(N):
        n += (dp[i] + dp[N-1-i]) * M * M
    for i in range(M):
        n += (dp[i] + dp[M-1-i]) * N * N
    n = int(n / 2)
    r = comb(N*M-2, K-2, exact=True)
    n = n * r % (int(1e+9)+7)
    print(n)

main()
Problem p03078 (python)

Fixed submission:
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def tk(i, j, k):
    return '%d %d %d' % (i, j, k)

def tkr(key):
    return sp2nn(key)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    aa = sp2nn(ss[1])
    bb = sp2nn(ss[2])
    cc = sp2nn(ss[3])
    aa.sort()
    aa.reverse()
    bb.sort()
    bb.reverse()
    cc.sort()
    cc.reverse()
    
    d = {}
    st = set()
    key = tk(0, 0, 0)
    st.add(key)
    d[key] = aa[0] + bb[0] + cc[0]
    for _ in range(K):
        vmax = -1
        vk = ''
        for k, v in d.items():
            if vmax < v:
                vmax = v
                vk = k
        print(vmax)
        d.pop(vk)
        st.add(vk)
        i, j, k = tkr(vk)
        if i + 1 < len(aa):
            key = tk(i+1, j, k)
            if key not in st:
                d[key] = aa[i+1] + bb[j] + cc[k]
        if j + 1 < len(bb):
            key = tk(i, j+1, k)
            if key not in st:
                d[key] = aa[i] + bb[j+1] + cc[k]
        if k + 1 < len(cc):
            key = tk(i, j, k+1)
            if key not in st:
                d[key] = aa[i] + bb[j] + cc[k+1]
        
main(ii2ss(4))

Buggy submission (verdict: Runtime Error):
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def tk(i, j, k):
    return '%d %d %d' % (i, j, k)

def tkr(key):
    return sp2nn(key)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    aa = sp2nn(ss[1])
    bb = sp2nn(ss[2])
    cc = sp2nn(ss[3])
    aa.sort()
    aa.reverse()
    bb.sort()
    bb.reverse()
    cc.sort()
    cc.reverse()
    
    d = {}
    st = set()
    key = tk(0, 0, 0)
    st.put(key)
    d[key] = aa[0] + bb[0] + cc[0]
    for _ in range(K):
        vmax = -1
        vk = ''
        for k, v in d.items():
            if vmax < v:
                vmax = v
                vk = k
        print(vmax)
        d.pop(vk)
        st.put(vk)
        i, j, k = tkr(vk)
        if i + 1 < len(aa):
            key = tk(i+1, j, k)
            if key not in st:
                d[key] = aa[i+1] + bb[j] + cc[k]
        if j + 1 < len(bb):
            key = tk(i, j+1, k)
            if key not in st:
                d[key] = aa[i] + bb[j+1] + cc[k]
        if k + 1 < len(cc):
            key = tk(i, j, k+1)
            if key not in st:
                d[key] = aa[i] + bb[j] + cc[k+1]
        
main(ii2ss(4))
Problem p03087 (python)

Fixed submission:
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N)
    for i in range(1, N):
        if S[i-1] == 'A' and S[i] == 'C':
            S2[i] = S2[i-1] + 1
        else:
            S2[i] = S2[i-1]
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

Buggy submission (verdict: Runtime Error):
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N+1)
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            S2[i+1] = S2[i] + 1
        else:
            S2[i+1] = S2[i]
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

Buggy submission (verdict: Runtime Error):
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N+1)
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            S2[i+1] = S2[i] + 1
        else:
            S2[i+1] = S2[i]
    print(S2)
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)
Problem p03101 (python)

Fixed submission:
# AtCoder Beginner Contest 121
# https://atcoder.jp/contests/abc121
import sys
import numpy as np

s2nn = lambda s: map(int, s.split(' '))
ss2nn = lambda ss: map(int, ss)
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    H, W = i2nn()
    h, w = i2nn()
    n = (H - h) * (W - w)
    print(n)

main()

Buggy submission (verdict: Runtime Error):
# AtCoder Beginner Contest 121
# https://atcoder.jp/contests/abc121
import sys
import numpy as np

s2nn = lambda s: map(int, s.split(' '))
ss2nn = lambda ss: map(int, ss)
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    H, W = i2nn()
    h, w = i2nn()
    n = (H - h) * (W - w)
    print(n)

main()
Problem p03330 (python)

Fixed submission:
# ContestName
# URL
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, C = i2nn()
    D = ii2nnn(C)
    c = ii2nnn(N)
    E = [[0] * C for _ in range(3)]
    for i in range(N):
        for j in range(N):
            before = c[i][j]
            e = (i+j) % 3
            for after in range(1, C+1):
                E[e][after-1] += D[before-1][after-1]
    iwakan = N * N * 1000
    for c1 in range(C):
        for c2 in range(C):
            for c3 in range(C):
                if c1 == c2 or c2 == c3 or c3 == c1:
                    continue
                n = E[0][c1] + E[1][c2] + E[2][c3]
                if n < iwakan:
                    iwakan = n
    print(iwakan)

main()

Buggy submission (verdict: Runtime Error):
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

"""
マスは1つの色を持つ -> c[i][j]
マスは3グループのいずれかに属する -> (i+j)%3
グループは1つの色 gc を持つ、ただし他のグループと同じ色を持てない gc1 != gc2 != gc3
マス違和感 = D[マスの色][グループの色]
グループ違和感 = グループ内のマスの、マス違和感の合計 = DG[グループ色]
全体違和感 = 3グループの、グループ違和感の合計
答え = 全体違和感
"""
def main():
    N, C = i2nn()
    D = ii2nnn(C)
    c = ii2nnn(N)
    iwakanG = [[0] * C for _ in range(3)]  # グループ違和感[グループID][グループ色] = グループID/色ごとのマス違和感の計
    for i in range(N):
        for j in range(N):
            groupID = (i + j) % 3  # グループID
            cM = c[i][j] - 1  # マス色
            for cG in range(C):
                iwakanM = D[cM][cG]   # マス違和感
                iwakanG[groupID][cG] += iwakanM  # グループ違和感にマス違和感を加算
    iwakan = 1e+9
    for gc1 in range(C):
        for gc2 in range(C):
            for gc3 in range(C):
                if gc1 == gc2 or gc2 == gc3 or gc3 == gc1:
                    continue
                n = iwakanG[0][gc1] + iwakanG[1][gc2] + iwakanG[2][gc3]
                if iwakan > n:
                    iwakan = n  # 全体違和感の最小化
    print(iwakan)

main()