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

Fixed submission:
from collections import defaultdict
from operator import itemgetter

def solve(N, X, D):
    if D < 0:
        D = -D
        X = -X
    elif D == 0:
        if X == 0:
            return 1
        return N + 1

    s = defaultdict(list)
    for k in range(N+1):
        p = k * X % D
        q = k * X // D
        a = k * (k - 1) // 2
        b = (N - 1) * k - a + 1
        s[p].append((a + q, b + q))

    ans = 0
    for v in s.values():
        if not v: continue
        v.sort()
        a, b = v[0]
        for x, y in v[1:]:
            if b < x:
                ans += b - a
                a, b = x, y
            else:
                b = max(b, y)
        ans += b - a
    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    print(solve(N, X, D))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from operator import itemgetter

N, X, D = map(int, input().split())
if D < 0:
    D = -D
    X = -X

s = defaultdict(list)
for k in range(N+1):
    p = k * X % D
    q = k * X // D
    a = k * (k - 1) // 2
    b = (N - 1) * k - a + 1
    s[p].append((a + q, b + q))

ans = 0
for v in s.values():
    if not v: continue
    v.sort()
    a, b = v[0]
    for x, y in v[1:]:
        if b < x:
            ans += b - a
            a, b = x, y
        else:
            b = max(b, y)
    ans += b - a

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from operator import itemgetter

N, X, D = map(int, input().split())
if D < 0:
    D = -D
    X = -X

s = defaultdict(list)
for k in range(N+1):
    p = k * X % D
    q = k * X // D
    a = k * (k - 1) // 2
    b = (N - 1) * k - a + 1
    s[p].append((a + q, b + q))

ans = 0
for v in s.values():
    v.sort()
    a, b = v[0]
    for x, y in v[1:]:
        if b < x:
            ans += b - a
            a, b = x, y
        else:
            b = max(b, y)
    ans += b - a

print(ans)
Problem p02850 (python)

Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy submission (verdict: Runtime Error):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for _,li in table:
  sort(li)

K=max(nd)
print(K)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    print(y)

Buggy submission (verdict: Runtime Error):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for _,li in table:
  sort(li)

K=max(nd)
print(K)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    print(y)
Problem p02902 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10000)
N, M = map(int, input().split())
table = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    table[a-1].append(b-1)

visit = [False] * N
visit2 = [False] * N
g = []


def dfs(v):
    g.append(v)
    if visit[v]:
        return True
    visit[v] = True
    visit2[v] = True
    for u in table[v]:
        if dfs(u):
            return True
    g.pop()
    visit[v] = False
    return False


for i in range(N):
    g = []
    if not visit2[i]:
        if dfs(i):
            break
else:
    print(-1)
    exit()
print(0)
# ans = [v+1 for v in g[g.index(g[-1]):-1]]
# print(len(ans))
# print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
table = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    table[a-1].append(b-1)

visit = [False] * N
visit2 = [False] * N
g = []


def dfs(v):
    g.append(v)
    if visit[v]:
        return True
    visit[v] = True
    visit2[v] = True
    for u in table[v]:
        if dfs(u):
            return True
    g.pop()
    visit[v] = False
    return False


for i in range(N):
    g = []
    if not visit2[i]:
        if dfs(i):
            break
else:
    print(-1)
    exit()
print(0)
# ans = [v+1 for v in g[g.index(g[-1]):-1]]
# print(len(ans))
# print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
table = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    table[a-1].append(b-1)

visit = [False] * N
visit2 = [False] * N
g = []


def dfs(v):
    g.append(v)
    if visit[v]:
        return True
    visit[v] = True
    visit2[v] = True
    for u in table[v]:
        if dfs(u):
            return True
    g.pop()
    visit[v] = False
    return False


for i in range(N):
    g = []
    if not visit2[i]:
        if dfs(i):
            break
else:
    print(-1)
    exit()

ans = [v+1 for v in g[g.index(g[-1]):-1]]
print(len(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
table = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    table[a-1].append(b-1)

visit = [False] * N
visit2 = [False] * N
g = []


def dfs(v):
    g.append(v)
    if visit[v]:
        return True
    visit[v] = True
    visit2[v] = True
    for u in table[v]:
        if dfs(u):
            return True
    g.pop()
    visit[v] = False
    return False


for i in range(N):
    g = []
    if not visit2[i]:
        if dfs(i):
            break
else:
    print(-1)
    exit()

print(*[v+1 for v in g[g.index(g[-1]):-1]], sep="\n")
Problem p02936 (python)

Fixed submission:
from collections import deque

N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x

S = deque([(1, 0)])
while S:
    v, p = S.popleft()
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        S.append((t, v))

print(*C[1:])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x


def rec(v, p=0):
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        rec(t, v)


rec(1)
print(*C[1:])
Problem p02961 (python)

Fixed submission:
import sys
sys.setrecursionlimit(300000)
def solve(x,y,k):
    if x==y==0: return []
    if x<0: return [(-x,y) for x,y in solve(-x,y,k)]
    if y<0: return [(x,-y) for x,y in solve(x,-y,k)]
    if x>y: return [(x,y) for y,x in solve(y,x,k)]
    if (x+y)%k==0: return [(k,0)]*(x//k)+[(0,k)]*(y//k)+([]if x%k==y%k==0 else[(x%k,y%k)])
    if x+y>=2*k:
        if x%k+y%k>=k: return [(k,0)]*(x//k)+[(0,k)]*(y//k)+solve(x%k,y%k,k)
        else: return ([(k,0)]*(x//k)+[(0,k)]*(y//k))[:-1]+solve(x%k,y%k+k,k)
    if x+y<K and (x+y)%2==1: return solve(x,y+k,k)+[(0,-k)]
    if K&1 and x+y>k and (x+y)%k%2==0: return solve(x,y-k,k)+[(0,k)]
    z=(x+y)//2
    return [(k-z+x,z-x),(z-k,z)]
K,X,Y=map(int, open(0).read().split())
if K%2==0 and (X+Y)%2==1:
    print(-1)
else:
    ans=solve(X,Y,K)
    print(len(ans))
    ax,ay=0,0
    for x,y in ans:
        ax+=x
        ay+=y
        print(ax,ay)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(300000)
def solve(x,y,k):
    if x==y==0: return []
    if x<0: return [(-x,y) for x,y in solve(-x,y,k)]
    if y<0: return [(x,-y) for x,y in solve(x,-y,k)]
    if x>y: return [(x,y) for y,x in solve(y,x,k)]
    if (x+y)%k==0: return [(k,0)]*(x//k)+[(0,k)]*(y//k)+([]if x%k==y%k==0 else[(x%k,y%k)])
    if x+y>=2*k: return ([(k,0)]*(x//k)+[(0,k)]*(y//k))[:-1]+solve(x%k,y%k+k,k)
    if x+y<K and (x+y)%2==1: return solve(x,y+k,k)+[(0,-k)]
    if K&1 and x+y>k and (x+y)%k%2==0: return solve(x,y-k,k)+[(0,k)]
    z=(x+y)//2
    return [(k-z+x,z-x),(z-k,z)]
K,X,Y=map(int, open(0).read().split())
if K%2==0 and (X+Y)%2==1:
    print(-1)
else:
    ans=solve(X,Y,K)
    print(len(ans))
    ax,ay=0,0
    for x,y in ans:
        ax+=x
        ay+=y
        print(ax,ay)

Buggy submission (verdict: Runtime Error):
def solve(x,y,k):
    if x==y==0: return []
    if x+y>=2*k and x>=k: return [(k,0)]+solve(x-k,y,k)
    if x+y>=2*k and y>=k: return [(0,k)]+solve(x,y-k,k)
    if x<0: return [(-x,y) for x,y in solve(-x,y,k)]
    if y<0: return [(x,-y) for x,y in solve(x,-y,k)]
    if x>y: return [(x,y) for y,x in solve(y,x,k)]
    if x+y<K and (x+y)%2==1: return solve(x,y+k,k)+[(0,-k)]
    if K&1 and x+y>k and (x+y)%k%2==0: return solve(x,y-k,k)+[(0,k)]
    z=(x+y)//2
    return [(k-z+x,z-x),(z-k,z)]
K,X,Y=map(int, open(0).read().split())
if K%2==0 and (X+Y)%2==1:
    print(-1)
else:
    ans=solve(X,Y,K)
    print(len(ans))
    ax,ay=0,0
    for x,y in ans:
        ax+=x
        ay+=y
        print(ax,ay)
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(int, input().split())
print(*[W*H/2, int(W==x*2 and H==y*2)])

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
print(f"{W*H/2} {int(W==x*2 and H==y*2)}")
Problem p03006 (python)

Fixed submission:
from collections import Counter
N=int(input())
XY=[tuple(map(int, input().split())) for _ in range(N)]
PQ=[(x1-x2,y1-y2) for x1,y1 in XY for x2,y2 in XY if x1!=x2 or y1!=y2]
C=Counter(PQ)
print(N-C.most_common(1)[0][1] if N!=1 else 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
XY=[tuple(map(int, input().split())) for _ in range(N)]
PQ=[(x1-x2,y1-y2) for x1,y1 in XY for x2,y2 in XY if x1!=x2 or y1!=y2]
C=Counter(PQ)
print(N-C.most_common(1)[0][1])
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
C = sum(sum(a&1 for a in aa) for aa in A)
if C&1:
    for i in range(1,H+1):
        for j in range(1,W+1)[::(i&1)*2-1]:
            if A[i-1][j-1]&1:
                A[i-1][j-1]=0
                break
        else:
            continue
        break
R = []
prev = None
for i in range(1,H+1):
    for j in range(1,W+1)[::(i&1)*2-1]:
        if prev is None:
            if A[i-1][j-1] & 1:
                prev = i, j
        else:
            y, x = prev
            R.append((y, x, i, j))
            if A[i-1][j-1] & 1:
                prev = None
            else:
                prev = i, j

print(len(R))
for r in R:
    print(*r)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
R = []
prev = None
for i in range(1,H+1):
    for j in range(1,W+1)[::(i&1)*2-1]:
        if prev is None:
            if A[i-1][j-1] & 1:
                prev = i, j
        else:
            R.append((*prev, i, j))
            if A[i-1][j-1] & 1:
                prev = None
            else:
                prev = i, j

print(len(R))
for r in R:
    print(*r)
Problem p03472 (python)

Fixed submission:
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
for i, b in enumerate(B, 1):
    H -= b
    if H <= 0:
        ans = i
        break
else:
    ans = len(B) + (H + a - 1) // a
print(ans)

Buggy submission (verdict: Runtime Error):
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
for i in range(len(B)):
    H -= B[i]
    if H <= 0:
        break
else:
    i += (H + a - 1) // a
i += 1
print(i)
Problem p03569 (python)

Fixed submission:
S=input()
T=S.replace("x","")
if all(s==t for s,t in zip(T,T[::-1])):
    ans=0
    i=0
    j=len(S)-1
    while i<j:
        pi=i
        pj=j
        while i<len(S) and S[i]=="x":
            i+=1
        while j>=0 and S[j]=="x":
            j-=1
        if i>j:
            break
        ans+=abs(i-pi-pj+j)
        i+=1
        j-=1
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
S=input()
T=S.replace("x","")
if all(s==t for s,t in zip(T,T[::-1])):
    ans=0
    i=0
    j=len(S)-1
    while i<j:
        pi=i
        pj=j
        while S[i]=="x":
            i+=1
        while S[j]=="x":
            j-=1
        ans+=abs(i-pi-j+pj)
        i+=1
        j-=1
    print(ans)
else:
    print(-1)
Problem p03689 (python)

Fixed submission:
def solve(W,w):
    A=[1]*W
    for i in range(W-1,w-1,-1):
        A[i-w]=A[i]+1
    A[w-1::w]=[-i for i in range(1,W//w+1)]
    for i in range(W-2,-1,-1):
        A[i+1]-=A[i]
    return A

H,W,h,w=map(int, input().split())
if W%w:
    print("Yes")
    A=solve(W,w)
    for _ in range(H):
        print(*A)
elif H%h:
    print("Yes")
    A=solve(H,h)
    for i in range(H):
        print(*[A[i]]*W)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def solve(H,W,h,w):
    A=[[0]*W for _ in range(H)]
    for i in range(H+1-h):
        for j in range(W+1-w):
            A[-1-i][-1-j]=-1
    A[-1][-1]=1
    if H==h:
        A[-1][-w-1]+=1
    else:
        A[-h-1][-1]+=1
    if W==w:
        A[-h-1][-1]+=1
    else:
        A[-1][-w-1]+=1
    for i in range(H)[::-1]:
        for j in range(W-1)[::-1]:
            A[i][j+1]-=A[i][j]
    for i in range(H-1)[::-1]:
        for j in range(W)[::-1]:
            A[i+1][j]-=A[i][j]
    return A

H,W,h,w=map(int, input().split())
if h*2<H+1 and w*2<W+1 or H==h and W==w or h==w==1:
    print("No")
elif H!=h==1:
    if w*2<W+1:
        print("No")
    else:
        A=solve(1,W,1,w)[0]
        print("Yes")
        for i in range(H):
            print(*A)
elif W!=w==1:
    if h*2<H+1:
        print("No")
    else:
        A=solve(1,H,1,h)[0]
        print("Yes")
        for i in range(H):
            print(*[A[i]]*W)
else:
    A=solve(H,W,h,w)
    print("Yes")
    for i in range(H):
        print(*A[i])

Buggy submission (verdict: Runtime Error):
H,W,h,w=map(int, input().split())
if h*2<H+1 or w*2<W+1:
    print("No")
else:
    print("Yes")
    A=[[0]*W for _ in range(H)]
    for i in range(h):
        for j in range(w):
            A[-1-i][-1-j]=-1
    A[-1][-1]=1
    A[-1][-1-w]=1
    A[-1-h][-1]=1
    for i in range(H)[::-1]:
        for j in range(W-1)[::-1]:
            A[i][j+1]-=A[i][j]
    for i in range(H-1)[::-1]:
        for j in range(W)[::-1]:
            A[i+1][j]-=A[i][j]
    for i in range(H):
        print(*A[i])
Problem p03109 (python)

Fixed submission:
s=input()
if s > "2019/04/30":
  print("TBD")
else:
  print("Heisei")

Buggy submission (verdict: Runtime Error):
s=input()
if s > "2019/04/30"
  print("TBD")
else
  print("Heisei")
Problem p03456 (python)

Fixed submission:
import math
s1, s2 = input().split()
s1 += s2
a = int(s1)
if math.floor(math.sqrt(a)) * math.floor(math.sqrt(a)) == a:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import math
s1, s2 = input().split()
s1 += s2
a = int(s1)
if floor(math.sqrt(a)) * floor(math.sqrt(a)) == a:
  print("Yes")
else:
  print("No")

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);


  int n; cin >> n;
  set<int> st;
  for(int i=0;i<n;++i) {
    int tmp; cin >> tmp;
    st.insert(tmp);
  }
  cout << SZ(st) << endl;
  
}

Buggy submission (verdict: Runtime Error):
import math
s1 = input()
s2 = input()
s1 += s2
a = int(s1)
if math.sqrt(a) * math.sqrt(a) == a:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import math
s1 = input()
s2 = input()
s1 += s2
a = int(s1)
if math.sqrt(a) * math.sqrt(a) == a:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s1 = input()
s2 = input()
s1 += s2
a = int(s1)
if sqrt(a) * sqrt(a) == a:
  print("Yes")
else:
  print("No")
Problem p02609 (python)

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

N = int(input())
S = input().rstrip()

num = S.count('1')

n1 = num + 1
n2 = num - 1

def count(m):
    ret = 1
    while m != 0:
        k = bin(m).count("1")
        m %= k
        ret += 1
    return ret


if n2 != 0:
    start1 = 0
    start2 = 0
    pow1 = [1]
    pow2 = [1]
    for i in range(N):
        s = int(S[-1-i])
        start1 = (start1 + pow1[-1] * s) % n1
        start2 = (start2 + pow2[-1] * s) % n2
        pow1.append(pow1[-1] * 2 % n1)
        pow2.append(pow2[-1] * 2 % n2)


    ans = []
    for i in range(N):
        s = int(S[i])
        if s == 0:
            l = (start1 + pow1[-i-2]) % n1
            ans.append(count(l))
        else:
            l = (start2 - pow2[-i-2]) % n2
            ans.append(count(l))

    print(*ans, sep="\n")
else:
    start1 = 0
    pow1 = [1]
    for i in range(N):
        s = int(S[-1-i])
        start1 = (start1 + pow1[-1] * s) % n1
        pow1.append(pow1[-1] * 2 % n1)

        


    ans = []
    for i in range(N):
        s = int(S[i])
        if s == 0:
            l = (start1 + pow1[-i-2]) % n1
            ans.append(count(l))
        else:
            ans.append(0)

    print(*ans, sep="\n")

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

N = int(input())
S = input().rstrip()

num = S.count('1')

n1 = num + 1
n2 = num - 1

start1 = 0
start2 = 0
pow1 = [1]
pow2 = [1]
for i in range(N):
    s = int(S[-1-i])
    start1 = (start1 + pow1[-1] * s) % n1
    start2 = (start2 + pow2[-1] * s) % n2
    pow1.append(pow1[-1] * 2 % n1)
    pow2.append(pow2[-1] * 2 % n2)


def count(m):
    ret = 1
    while m != 0:
        k = bin(m).count("1")
        m %= k
        ret += 1
    return ret
    


ans = []
for i in range(N):
    s = int(S[i])
    if s == 0:
        l = (start1 + pow1[-i-2]) % n1
        ans.append(count(l))
    else:
        l = (start2 - pow2[-i-2]) % n2
        ans.append(count(l))

print(*ans, sep="\n")
Problem p02745 (python)

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

A = input().rstrip()
B = input().rstrip()
C = input().rstrip()

def check(P1, P2, P3):
    L1 = len(P1)
    L2 = len(P2)
    L3 = len(P3)
    L = sum([L1, L2, L3])*2+3

    P12 = [True]*L
    for i2 in range(-L2, L1+1):
        for l in range(max(i2, 0), min(i2+L2, L1)):
            if P1[l] != "?" and P2[l-i2] != "?" and P1[l] != P2[l-i2]:
                P12[i2] = False
                break
    
    P13 = [True]*L
    for i3 in range(-L3, L1+1):
        for l in range(max(i3, 0), min(i3+L3, L1)):
            if P1[l] != "?" and P3[l-i3] != "?" and P1[l] != P3[l-i3]:
                P13[i3] = False
                break
    
    P23 = [True]*L
    for i3 in range(-L3, L2+1):
        for l in range(max(i3, 0), min(i3+L3, L2)):
            if P2[l] != "?" and P3[l-i3] != "?" and P2[l] != P3[l-i3]:
                P23[i3] = False
                break

    ans = L1 + L2 + L3
    for i2 in range(-L2, L1+1):
        for i3 in range(-L3, L1+1):
            if P12[i2] and P13[i3] and P23[i3-i2]:
                ans = min(ans, max([L1, L2+i2, L3+i3]) - min([0, i2, i3]))
    return ans



print(min([check(A, B, C), check(B, A, C), check(C, A, B)]))

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

A = input().rstrip()
B = input().rstrip()
C = input().rstrip()

def check(P1, P2, P3):
    L1 = len(P1)
    L2 = len(P2)
    L3 = len(P3)
    L = max([L1, L2, L3])*2+3

    P12 = [True]*L
    for i2 in range(-L2, L1+1):
        for l in range(max(i2, 0), min(i2+L2, L1)):
            if P1[l] != "?" and P2[l-i2] != "?" and P1[l] != P2[l-i2]:
                P12[i2] = False
                break
    
    P13 = [True]*L
    for i3 in range(-L3, L1+1):
        for l in range(max(i3, 0), min(i3+L2, L1)):
            if P1[l] != "?" and P3[l-i3] != "?" and P1[l] != P3[l-i3]:
                P13[i3] = False
                break
    
    P23 = [True]*L
    for i3 in range(-L3, L2+1):
        for l in range(max(i3, 0), min(i3+L2, L2)):
            if P2[l] != "?" and P3[l-i3] != "?" and P2[l] != P3[l-i3]:
                P23[i3] = False
                break

    ans = L1 + L2 + L3
    for i2 in range(-L2, L1+1):
        for i3 in range(-L3, L1+1):
            if P12[i2] and P13[i3] and P23[i3-i2]:
                ans = min(ans, max([0, i2, i3])+L1 - min([0, i2, i3]))
    return ans



print(min([check(A, B, C), check(B, A, C), check(C, A, B)]))
Problem p02775 (python)

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

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []

for n in reversed(Num_str):
    Num.append(int(n))

S = 0
up = False
for i, n in enumerate(Num):
    if up:
        n += 1
    if n < 5:
        S += n
        up = False
    elif n == 5:
        S += 5
        up = (i != L-1 and Num[i+1] >= 5)
    else:
        S += 10 - n
        up = True
if up:
    S += 1
print(S)

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

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []

for n in reversed(Num_str):
    Num.append(int(n))

S = 0
up = False
for i, n in enumerate(Num):
    if up:
        n += 1
    if n < 5:
        S += n
        up = False
    elif n == 5:
        S += 5
        up = (i != L and Num[i+1] >= 5)
    else:
        S += 10 - n
        up = True
if up:
    S += 1
print(S)

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

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []

for n in reversed(Num_str):
    Num.append(int(n))

S = 0
up = False
for i, n in enumerate(Num):
    if up:
        n += 1
    if n < 5:
        S += n
        up = False
    elif n == 5:
        S += 5
        up = i != L and Num[i+1] >= 5
    else:
        S += 10 - n
        up = True
if up:
    S += 1
print(S)
Problem p02782 (python)

Fixed submission:
# コンビネーション
mod = 10**9+7
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 3*10**6+6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

ans = 0
for c in range(c1, c2+1):
    ans += cmb(c+r2+1, r2) - cmb(c+r1, r1-1)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
# コンビネーション
mod = 10**9+7
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6+6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

ans = 0
for c in range(c1, c2+1):
    ans += cmb(c+r2+1, r2) - cmb(c+r1, r1-1)
    ans %= mod
print(ans)