Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
INF=float("inf")
def main():
    H,W=map(int, input().split())
    A=[input()for _ in range(H)]
    D=[[0 if A[h][w]=="#" else INF for w in range(W)] for h in range(H)]
    for h in range(H):
        for w in range(1,W):
            D[h][w]=min(D[h][w],D[h][w-1]+1)
        for w in range(W-2, -1, -1):
            D[h][w]=min(D[h][w],D[h][w+1]+1)
    for w in range(W):
        for h in range(1,H):
            D[h][w]=min(D[h][w],D[h-1][w]+1)
        for h in range(H-2, -1, -1):
            D[h][w]=min(D[h][w],D[h+1][w]+1)
    print(max(d for dd in D for d in dd))

if __name__ == "__main__":
    main()

Fixed submission:
INF=float("inf")
def main():
    H,W=map(int, input().split())
    A=[input()for _ in range(H)]
    D=[[0 if A[h][w]=="#" else INF for w in range(W)] for h in range(H)]
    for h in range(H):
        for w in range(1,W):
            D[h][w]=min(D[h][w],D[h][w-1]+1)
        for w in range(W-2, -1, -1):
            D[h][w]=min(D[h][w],D[h][w+1]+1)
    for w in range(W):
        for h in range(1,H):
            D[h][w]=min(D[h][w],D[h-1][w]+1)
        for h in range(H-2, -1, -1):
            D[h][w]=min(D[h][w],D[h+1][w]+1)
    print(max(d for dd in D for d in dd))

if __name__ == "__main__":
    main()
Buggy python 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)

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 python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
NN = ((N + 1) * N // 2 + 1) // 2
def ok(x):
    S = list(accumulate(1 if a >= x else -1 for a in A))
    ms = min(min(S), 0)
    S = [1] + [s - ms + 1 for s in S]
    L = max(S) + 1
    B = [0] * L
    c = 0
    for s in S:
        i = s
        while i > 0:
            c += B[i]
            i -= i & -i
        i = s
        while i < L:
            B[i] += 1
            i += i & -i
    return c >= NN

B = sorted(set(A))
l = 0
r = len(B)
while r - l > 1:
    m = (l + r) // 2
    if ok(B[m]):
        l = m
    else:
        r = m
print(B[l])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
NN = ((N + 1) * N // 2 + 1) // 2

def ok(x):
    B = [0] * (2 * N + 1)
    res, cum, cur = 0, 0, 0
    B[0] += 1
    for a in A:
        if a >= x:
            cum += 1
            cur += B[cum]+1
        else:
            cur -= B[cum]-1
            cum -= 1
        B[cum] += 1
        res += cur
    return res >= NN

B = sorted(set(A))
l = 0
r = len(B)
while r - l > 1:
    m = (l + r) // 2
    if ok(B[m]):
        l = m
    else:
        r = m
print(B[l])
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.N) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M = map(int, input().split())
P = list(map(int, input().split()))
UF = UnionFind(N)
for i in range(N):
    P[i] -= 1
for _ in range(M):
    x, y = map(int, input().split())
    x-=1
    y-=1
    UF.union(x, y)

print(sum(len(set(mem)&set(P[i] for i in mem)) for _, mem in UF.all_group_members().items()))

Fixed submission:
N, M = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
T = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    x-=1
    y-=1
    T[x].append(y)
    T[y].append(x)

s1 = set()
def dfs(x):
    s1.add(x)
    s2 = set([x])
    stack = [x]
    while stack:
        u = stack.pop()
        for v in T[u]:
            if v not in s1 and v not in s2:
                s1.add(v)
                s2.add(v)
                stack.append(v)
    return s2

ans = 0
for i in range(N):
    if i in s1:
        continue
    I = dfs(i)
    PI = set(P[i] for i in I)
    ans += len(I.intersection(PI))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
print(*[i for i in range(A,B+1) if i<A+K or B-K<i],sep="\n")

Fixed submission:
A, B, K = map(int, input().split())
if A+K-1>=B-K+1:
    print(*list(range(A,B+1)),sep="\n")
else:
    print(*(list(range(A,A+K))+list(range(B-K+1,B+1))),sep="\n")
Buggy python 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)

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 python 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)

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 python 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])

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 python 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])

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 python submission (verdict: Time Limit Exceeded):
class BinaryIndexedTree:
    def __init__(self, N, f=max, id=0):
        self.N = N
        self.bit = [id] * (self.N+1)
        self.f = f
        self.id = id

    def query(self, i):
        res = self.id
        while i > 0:
            res = self.f(res, self.bit[i])
            i -= i & -i
        return res

    def update(self, i, x):
        while i <= self.N:
            self.bit[i] = self.f(self.bit[i], x)
            i += i & -i

def main():
    N,*A=map(int, open(0).read().split())
    L,R=[0]*N,[0]*N
    bit=BinaryIndexedTree(N, max, -1)
    for i,a in enumerate(A):
        L[a-1]=i-bit.query(a)
        bit.update(a, i)
    bit=BinaryIndexedTree(N, max, -1)
    for i,a in enumerate(A[::-1]):
        R[a-1]=i-bit.query(a)
        bit.update(a, i)
    print(sum(L[i]*R[i]*(i+1) for i in range(N)))

if __name__ == "__main__":
    main()

Fixed submission:
class BinaryIndexedTree:
    def __init__(self, N, f=max, id=0):
        self.N = N
        self.bit = [id] * (self.N+1)
        self.f = f
        self.id = id

    def query(self, i):
        res = self.id
        while i > 0:
            res = self.f(res, self.bit[i])
            i -= i & -i
        return res

    def update(self, i, x):
        while i <= self.N:
            self.bit[i] = self.f(self.bit[i], x)
            i += i & -i

def main():
    N,*A=map(int, open(0).read().split())
    L,R=[0]*N,[0]*N
    bit=BinaryIndexedTree(N, max, -1)
    for i,a in enumerate(A):
        L[a-1]=i-bit.query(a)
        bit.update(a, i)
    bit=BinaryIndexedTree(N, max, -1)
    for i,a in enumerate(A[::-1]):
        R[a-1]=i-bit.query(a)
        bit.update(a, i)
    print(sum(L[i]*R[i]*(i+1) for i in range(N)))

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

Fixed submission:
s=input()
if s > "2019/04/30":
  print("TBD")
else:
  print("Heisei")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N

for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

last = [0] * N
while q != []:
    qn = q.pop(0)
    for v in outs[qn]:
        ins[v] -= 1
        last[v] = max(last[v], last[qn] + 1)
        if ins[v] == 0:
            q.append(v)

print(max(last))

Fixed submission:
N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N

for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

last = [0] * N
while q != []:
    qn = q.pop()
    for v in outs[qn]:
        ins[v] -= 1
        last[v] = max(last[v], last[qn] + 1)
        if ins[v] == 0:
            q.append(v)

print(max(last))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N


for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

result = []
while q != []:
    qn = q.pop(0)
    result.append(qn)
    for v in outs[qn]:
        ins[v] -= 1
        if ins[v] == 0:
            q.append(v)


last = [0] * N
# last[i] = iが最後だったときに最長のパス
for sq in result:
    now = last[sq] + 1
    for v in outs[sq]:
        last[v] = max(last[v], now)

print(max(last))

Fixed submission:
N, M = (int(i) for i in input().split()) 

outs = [[] for i in range(N)]
ins = [0] * N

for _ in range(M):
    x, y = (int(i) for i in input().split())
    x -= 1
    y -= 1
    outs[x].append(y)
    ins[y] += 1

q = []
for i in range(N):
    if ins[i] == 0:
        q.append(i)

last = [0] * N
while q != []:
    qn = q.pop()
    for v in outs[qn]:
        ins[v] -= 1
        last[v] = max(last[v], last[qn] + 1)
        if ins[v] == 0:
            q.append(v)

print(max(last))
Buggy python 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")

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 python 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;
  
}


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 python 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")

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 python 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")

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 python submission (verdict: Runtime Error):
s1 = input()
s2 = input()
s1 += s2
a = int(s1)
if sqrt(a) * sqrt(a) == a:
  print("Yes")
else:
  print("No")

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 python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    cn=[0]*N
    for i in range(N):
        cn[D[i]]+=1

    if D[0]!=0:
        print(0)
    else:
        answer=1
        bak=cn[0]
        kyo=1
        hen=1
        while True:
            if kyo >= N:
                while True:
                    pass
            cnt=cn[kyo]
            hen+=cnt
            if cnt==0:
                break
            answer=answer*baai(bak, cnt)%MOD
            bak=cnt
            kyo+=1
        if hen==N:
            print(answer%MOD)
        else:
            print(0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()


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

MOD = 998244353  # type: int

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    cn=[0]*(N*2)
    for i in range(N):
        cn[D[i]]+=1

    if D[0]!=0:
        print(0)
    else:
        answer=1
        bak=cn[0]
        kyo=1
        hen=1
        while True:
            cnt=cn[kyo]
            hen+=cnt
            if cnt==0:
                break
            answer=answer*baai(bak, cnt)%MOD
            bak=cnt
            kyo+=1
        if hen==N:
            print(answer%MOD)
        else:
            print(0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;


void solve(std::string S){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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


def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
########################### added
    next_S = [-1 for i in range(len(S) + 1)]
    next_L = [-1 for i in range(len(S) + 1)]

    next_S[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '>':
            next_S[i] = i
        else:
            next_S[i] = next_S[i + 1]

    next_L[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '<':
            next_L[i] = i
        else:
            next_L[i] = next_L[i + 1]

###########################

    #count '<'
    def count_S(i, N):
#        ret=S.find('>')
        if i >= len(next_S):
            return N
        ret = next_S[i] - i
        if ret < 0:
            ret = N
        return ret
    
    #count '>'
    def count_L(i, N):
#        ret=S.find('<')
        if i >= len(next_L):
            return N
        ret = next_L[i] - i
        if ret < 0:
            ret = N
        return ret


#    #count '<'
#    def count_S(S, N):
#        ret=S.find('>')
#        #print("<",S,N,ret)
#        if ret==-1:
#            ret=N
#        return ret
#    
#    #count '>'
#    def count_L(S, N):
#        ret=S.find('<')
#        if ret==-1:
#            ret=N
#        #print(">",S,N,ret)
#        return ret

    answer=0

    cnt_l=count_L(0,len(S))
    answer+=int((cnt_l+1)*cnt_l/2)
    i=cnt_l


    while i<len(S):
#        cnt_s=count_S(S[i:],len(S[i:]))
#        cnt_l=count_L(S[i+cnt_s:],len(S[i+cnt_s:]))

        cnt_s=count_S(i, len(S) - i)
        cnt_l=count_L(i+cnt_s, len(S) - (i+cnt_s))

        answer+=int((cnt_s+1)*cnt_s/2)
        answer+=int((cnt_l+1)*cnt_l/2)
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        #answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

mod = 998244353

dp = [0]*(N+1)
tmp = 1

for i in range(N-1):
    tmp = (tmp + dp[i]) % mod
    # dp[i] = tmp
    for l, r in LR:
        dp[min(i+l, N)] = (dp[min(i+l, N)] + tmp) % mod
        dp[min(i+r+1, N)] = (dp[min(i+r+1, N)] - tmp) % mod
print(dp[N-1])

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

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

mod = 998244353

dp = [0]*(N+1)
tmp = 1

for i in range(N-1):
    tmp = (tmp + dp[i]) % mod
    # dp[i] = tmp
    for l, r in LR:
        dp[min(i+l, N)] = (dp[min(i+l, N)] + tmp) % mod
        dp[min(i+r+1, N)] = (dp[min(i+r+1, N)] - tmp) % mod
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

start = 0
ind = 0
for a in A:
    while start < N and B[(start+ind)%N] == a:
        start += 1
    if start >= N: break
    ind += 1

if start >= N:
    print("No")
else:
    print("Yes")
    ans = []
    for i in range(N):
        if B[(i+start)%N] == A[i]:
            raise Exception
        ans.append(B[(i+start)%N])
    print(*ans)

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

start = 0
ind = 0
NG = [0]*(2*N+1)

bdic = {}
for i, b in enumerate(B):
    if not b in bdic:
        bdic[b] = [i, i]
    else:
        bdic[b] = [min(bdic[b][0], i), max(bdic[b][1], i)]


for i, a in enumerate(A):
    if a in bdic:
        j1, j2 = bdic[a]
        if j1 >= i:
            NG[j1-i] += 1
            NG[j2-i+1] -= 1
        elif j2 < i:
            NG[j1-i+N] += 1
            NG[j2-i+1+N] -= 1
        else:
            NG[j1-i+N] += 1
            NG[0] += 1
            NG[j2-i+1] -= 1

start = -1
for i in range(N):
    if NG[i] == 0:
        start = i
        break
    NG[i+1] += NG[i]

if start == -1:
    print("No")
else:
    print("Yes")
    ans = []
    for i in range(N):
        ans.append(B[(i+start)%N])
    print(*ans)