Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n, a, b = map(int, input().split())

    all = 2 ** n

    mod = 10**9+7 #出力の制限
    N = n
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

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

    def combinations_count(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    all -= combinations_count(n, a, mod)
    all -= combinations_count(n, b, mod)

    if n==2 and a != b:
        print(0)
        return 

    print(all - 1)

if __name__ == "__main__":
    resolve()

Fixed submission:

def mod_inverse(a, p):
    return pow(a, p-2, p)  # フェルマーの小定理より

def mod_binominal(n, r, p):
    numerator= 1
    for i in range(r):
        numerator = (numerator * (n - i)) % p

    denominator = 1
    for i in range(1, r+1):
        denominator = (denominator * i) % p

    return (numerator * mod_inverse(denominator, p)) % p

def resolve():
    n, a, b = map(int, input().split())
    p = 10**9+7

    ans = pow(2, n, p) - mod_binominal(n, a, p) - mod_binominal(n, b, p) - 1
    print((ans + p) % p)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

    for s in S:
        res[s] += 1

    max_k_list = [kv[0] for kv in res.items() if kv[1] == max(res.values())]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Fixed submission:

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

    for s in S:
        res[s] += 1

    max_v = max(res.values())
    max_k_list = [kv[0] for kv in res.items() if kv[1] == max_v]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(lambda: 0)

    for s in S:
        res[s] += 1

    max_k_list = [kv[0] for kv in res.items() if kv[1] == max(res.values())]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Fixed submission:

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

    for s in S:
        res[s] += 1

    max_v = max(res.values())
    max_k_list = [kv[0] for kv in res.items() if kv[1] == max_v]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(lambda: 0)

    for s in S:
        res[s] += 1

    max_k_list = [kv[0] for kv in res.items() if kv[1] == max(res.values())]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Fixed submission:

from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

    for s in S:
        res[s] += 1

    max_v = max(res.values())
    max_k_list = [kv[0] for kv in res.items() if kv[1] == max_v]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
import numpy as np
from collections import deque

def resolve():
    H, W = map(int, input().split())

    maze = []
    for i in range(H):
        maze.append(input())

    def dfs(st):

        INF = -1
        d = np.full((H, W), INF)

        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]

        que = deque()
        que.append(st)
        d[st[1]][st[0]] = 0

        while len(que):
            p = que.popleft()
            # print(p)

            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]

                if nx >= 0 and nx < W and ny >= 0 and ny < H and maze[ny][nx] != "#" and d[ny][nx] == INF:
                    # print("next is ", nx, ny)
                    que.append([nx, ny])
                    d[ny][nx] = d[p[1]][p[0]] + 1
                    # print(d)
                    # print(que)

        cost = np.max(d)
        idx = np.unravel_index(np.argmax(d), d.shape)
        # print(idx)
        # print(cost)
        return idx, cost

    for y in range(H):
        for x in range(W):
            if maze[y][x] == '.':
                st = [x, y]
                break
        break
    
    idx, cost = dfs(st)
    # print("mid")
    # print(idx)
    idx, cost = dfs((idx[1], idx[0]))
    print(int(cost))

if __name__ == "__main__":
    resolve()

Fixed submission:
import numpy as np
from collections import deque

def resolve():
    H, W = map(int, input().split())

    maze = []
    for i in range(H):
        maze.append(input())

    def bfs(st):

        INF = -1
        d = np.full((H, W), INF)

        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]

        que = deque()
        que.append(st)
        d[st[1]][st[0]] = 0

        while len(que):
            p = que.popleft()
            # print(p)

            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]

                if nx >= 0 and nx < W and ny >= 0 and ny < H and maze[ny][nx] != "#" and d[ny][nx] == INF:
                    # print("next is ", nx, ny)
                    que.append([nx, ny])
                    d[ny][nx] = d[p[1]][p[0]] + 1
                    # print(d)
                    # print(que)

        cost = np.max(d)
        # idx = np.unravel_index(np.argmax(d), d.shape)
        # print(idx)
        # print(cost)
        return cost

    max_cost = 0
    for y in range(H):
        for x in range(W):
            if maze[y][x] == '.':
                st = [x, y]
                cost = bfs(st)
                if cost > max_cost:
                    max_cost = cost 
    
    # print(maze[1])
    # idx, cost = bfs(st)
    # idx, cost = bfs((idx[1], idx[0]))
    print(int(max_cost))

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [0 for _ in range(N+K)]

    dp[0] = 0
    dp[1] = abs(H[1] - H[0])
    for tmp in range(1, K):
        #print("tmp:", tmp)
        if tmp+1 >= N:
            break
        candidates = [dp[tmp-k] + abs(H[tmp+1] - H[tmp-k]) for k in range(tmp+1)]
        #print("candidates_a:", candidates)
        dp[tmp+1] = min(candidates)

    #print(dp)
    for i in range(K-1, N-1):
        #print("i", i, "H[i+1]", H[i+1])
        #print("H:", [H[i - k] for k in range(K)])
        #print("diff:", [H[i+1] - H[i - k] for k in range(K)])
        #print("dp:", dp)
        candidates = [dp[i-k] + abs(H[i+1] - H[i-k]) for k in range(K)]
        #print("candidates:", candidates)
        dp[i+1] = min(candidates)

    #print(dp)
    print(dp[N-1])

if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [0] * N

    for i in range(1, N):
        s = max(0, i-K)
        dp[i] = min([c + abs(h - H[i]) for c, h in zip(dp[s:i], H[s:i])] )

    print(dp[N-1])

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
# 1つづつ順に
def resolve():
    N, W = map(int, input().split())    
    w_v = [list(map(int, input().split())) for _ in range(N)]  # [N][0:weight, 1:value]

    dp = [[0] * (W+1) for _ in range(N+1)] 

    for i in range(N):
        for j in range(W+1):
            w = w_v[i][0]
            v = w_v[i][1]
            if j < w:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j], dp[i][j - w] + v)
 
    print(dp[N][W])
if __name__ == "__main__":
    resolve()

Fixed submission:
# 1つづつ順に
# V << W なので、 dp[N][W]ではなく、 dp[N][V]で作成
def resolve():
    N, W = map(int, input().split())
    w_l = []
    v_l = []
    for _ in range(N):
        w, v = map(int, input().split())
        w_l.append(w)
        v_l.append(v)

    max_v = sum(v_l) + 1
    dp = [[10**10] * (max_v) for _ in range(N+1)] 
    dp[0][0] = 0

    for i in range(N):
        for j in range(max_v):
            #print(i, j)
            w = w_l[i]
            v = v_l[i]
            if j < v:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = min(dp[i][j], dp[i][j - v] + w)
 
    res = 0
    for j in range(max_v):
        if dp[N][j] <= W:
            res = j

    print(res)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):
# 1つづつ順に
def resolve():
    N, W = map(int, input().split())    
    w_v = [list(map(int, input().split())) for _ in range(N)]  # [N][0:weight, 1:value]

    dp = [[0] * (W+1) for _ in range(N+1)] 

    for i in range(N):
        for j in range(W+1):
            w = w_v[i][0]
            v = w_v[i][1]
            if j < w:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j], dp[i][j - w] + v)
 
    print(dp[N][W])

# 遷移先を考えて移動。初期化は0
def resolve():
    N, W = map(int, input().split())    
    w_v = [list(map(int, input().split())) for _ in range(N)]  # [N][0:weight, 1:value]

    dp = [[0] * (W+1) for _ in range(N+1)] 

    for i in range(N):
        for j in range(W+1):
            w = w_v[i][0]
            v = w_v[i][1]
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if j + w <= W:
                dp[i + 1][j + w] = max(dp[i][j] + v, dp[i + 1][j + w])
 
    print(dp[N][W])


if __name__ == "__main__":
    resolve()

Fixed submission:
# 1つづつ順に
# V << W なので、 dp[N][W]ではなく、 dp[N][V]で作成
def resolve():
    N, W = map(int, input().split())
    w_l = []
    v_l = []
    for _ in range(N):
        w, v = map(int, input().split())
        w_l.append(w)
        v_l.append(v)

    max_v = sum(v_l) + 1
    dp = [[10**10] * (max_v) for _ in range(N+1)] 
    dp[0][0] = 0

    for i in range(N):
        for j in range(max_v):
            #print(i, j)
            w = w_l[i]
            v = v_l[i]
            if j < v:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = min(dp[i][j], dp[i][j - v] + w)
 
    res = 0
    for j in range(max_v):
        if dp[N][j] <= W:
            res = j

    print(res)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    st = S.find("B")
    S = S[st:]
    while True:
        res = S.find(sub)
        if res == -1:
            break
        cnt += 1
        S = S[:res] + "WB" + S[res+2:]
    print(cnt)


if __name__ == "__main__":
    resolve()

Fixed submission:

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    sum = 0

    # 左端からのWと右端からのBは無関係のため除外
    st = 0
    end = 0
    for i, s in enumerate(S):
        if s == "B":
            break
        else:
            st += 1

    for i, s in enumerate(S[::-1]):
        #print(s)
        if s == "W":
            break
        else:
            end += 1

    #print(st, end)
    S = S[st:len(S)-end]
    #print(S)

    foundB = False
    for i, s in enumerate(S):
        if s == "B":
            cnt += 1
            foundB = True
        elif s == "W":
            sum += cnt
            foundB = False
        
        #print(s, cnt, sum)

    print(sum)


if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    while True:
        res = S.find(sub)
        if res == -1:
            break
        cnt += 1
        S = S[:res] + "WB" + S[res+2:]
    print(cnt)


if __name__ == "__main__":
    resolve()

Fixed submission:

def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    sum = 0

    # 左端からのWと右端からのBは無関係のため除外
    st = 0
    end = 0
    for i, s in enumerate(S):
        if s == "B":
            break
        else:
            st += 1

    for i, s in enumerate(S[::-1]):
        #print(s)
        if s == "W":
            break
        else:
            end += 1

    #print(st, end)
    S = S[st:len(S)-end]
    #print(S)

    foundB = False
    for i, s in enumerate(S):
        if s == "B":
            cnt += 1
            foundB = True
        elif s == "W":
            sum += cnt
            foundB = False
        
        #print(s, cnt, sum)

    print(sum)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
cnt = 0

def divide_by_2(array):
  rest = array % 2
  global cnt
  if np.all(rest == 0):
    cnt += 1
    divide_by_2(array / 2)
    
divide_by_2(A)
print(cnt)

Fixed submission:
s = list(input())
cnt = s.count('1')
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
ans=0
while a>0 and d>0 :
    ans+=1
    d=d-1
    a-=1
while d>0 and b>0:
    d=d-1
    b-=1
while d>0 and c>0:     
  
    ans-=1
    d=d-1
print(ans)     
  


Fixed submission:
a,b,c,d=map(int,input().split())
ans=0
if d-a>=0:
  d=d-a
  ans+=a
  if d-b>0:
      d-=b
      if d-c==0:
          ans-=c
      else:
          ans=ans-d
else:
    ans+=d
print(ans)
Buggy python submission (verdict: Runtime Error):
N=input()
if N='ABC':
  print('ARC')
else:
  print('ABC')

Fixed submission:
N=input()
if N=='ABC':
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Runtime Error):

n=int(input())
m,t=map(int,input().split())
if n<=t-m:
  print('OK')
else:
  print('NG')
elif n==1:
  print('OK')
  
    

Fixed submission:
i=int(input())
n,m=map(int,input().split())
s=[]
if n%i==0:
  print('OK')
elif m%i==0:
  print('OK')
else:
  for j in range(n,m+1):
    if j%i==0:
      s.append(j)
  if len(s)>0:
    print('OK')
  else:
    print('NG')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
list_=[]
for i in range(b):
  c=int(input())
  list_.append(c)
d=sum(list_)
print(a-d)

    


Fixed submission:
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=sum(c)
ans=a-d
if ans>=0:
    print(ans)
else:
    print('-1')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split()):
c=0
d=d*(d-1)//2
e=e*(e-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)  
  
 

Fixed submission:
a,b=map(int,input().split())
c=0
d=a*(a-1)//2
e=b*(b-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=0
while a>1 or b>1:
  if (a-2)>1 or (b-2)>1:
    a=a-2
    b=b-2
    c=c+1
print(c)  


Fixed submission:
a,b=map(int,input().split())
c=0
d=a*(a-1)//2
e=b*(b-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=0
while a>0 or b>0:
  if (a-2)>0 or (b-2)>0:
    a=a-2
    b=b-2
    c=c+1
print(c)  


Fixed submission:
a,b=map(int,input().split())
c=0
d=a*(a-1)//2
e=b*(b-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=0
for i in range(a+b)
  if (a-2)>0 or (b-2)>0:
    a=a-2
    b=b-2
    c=c+1
print(c)  

Fixed submission:
a,b=map(int,input().split())
c=0
d=a*(a-1)//2
e=b*(b-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
m=n/3
o=o**3
print(o)


Fixed submission:
n=int(input())
m=n/3
o=m**3
print(o)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b and a!=c
  print('Yes')
elif a==c and a!=b:
  print('Yes')
elif b==c and b!=a:
  print('Yes')
else:
  print('NO')

Fixed submission:
a,b,c=map(int,input().split())
if a==b and a!=c:
  print('Yes')
elif a==c and a!=b:
  print('Yes')
elif b==c and b!=a:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M)-1)  
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)-1)
  if S[j]%3!=0 and S[j]%5!=0:
    T.remove(S[j])
if len(S)==len(T):
  print('APPROVED')
else:
  pritn('DENIED')
    

Fixed submission:
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M))  :
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)):
  if S[j]%3!=0 and S[j]%5!=0:
      T.remove(S[j])
    
if len(S)==len(T):
  print('APPROVED')
else:
  print('DENIED')

Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
m=0
for i in range(N):
    A=int(input())
    if A%2==0:
        m=m+1
        if A%3==0 or A%5==0:
            ans=ans+1
if m==ans:
    print('APPROVED')
else:
    print('DENIED')


Fixed submission:
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M))  :
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)):
  if S[j]%3!=0 and S[j]%5!=0:
      T.remove(S[j])
    
if len(S)==len(T):
  print('APPROVED')
else:
  print('DENIED')

Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
m=0
for i in range(N):
  A=int(input())
  if A%2==0:
    m=m+1
    if A%3==0 or A%5==0:
    　　ans=ans+1
if m==N:
  print('APPROVED')
else:
  print('DENIED')

Fixed submission:
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M))  :
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)):
  if S[j]%3!=0 and S[j]%5!=0:
      T.remove(S[j])
    
if len(S)==len(T):
  print('APPROVED')
else:
  print('DENIED')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list(map(int,input().split()))
n.sort(reverse=True)
for i in range(b):
  n.remove(n[i])
print(sum(n))  


Fixed submission:
a,b=map(int,input().split())
i=0
while a>0:
  a-=b
  i+=1
print(i)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list(map(int,input().split()))
n.sort(reverse=True)
for i in range(b):
  n.remove(n[i])
print(sum(n))  


Fixed submission:
a,b=map(int,input().split())
n=list(map(int,input().split()))
n.sort(reverse=True)
n[0:b]=[]
print(sum(n))

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=list(map(int,input().split()))
n.sort(reverse=True)
for i in range(b):
  n.remove(n[i])
print(sum(n))  

Fixed submission:
a,b=map(int,input().split())
n=list(map(int,input().split()))
n.sort(reverse=True)
n[0:b]=[]
print(sum(n))
Buggy python submission (verdict: Runtime Error):
N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=M-2:
  print('Yes')
else:
  print('No')
  
  

Fixed submission:
N=int(input())
M=list(map(int,input().split()))
ans=0
list_= sorted(M)
for i in range(N):
  if M[i]==list_[i]:
    ans+=1
if ans>=N-2:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
ans=0
if max(a,b)==a:
  ans=ans+a
  a=a-1
  if max(a,b)==a:
    ans=ans+a
    a=a-1
  elif max(a,b)==b:
    ans=ans+b
    b=b-1
elif max(a,b)==b:
    ans=ans+b
    b=b-1
  if max(a,b)==a:
    ans=ans+a
    a=a-1    
  elif max(a,b)==b:
    ans=ans+b
    b=b-1      
print(ans)   
    

Fixed submission:
a,b=map(int,input().split())
ans=0
if max(a,b)==a:
  ans=ans+a
  a=a-1
  if max(a,b)==a:
    ans=ans+a
    a=a-1
  elif max(a,b)==b:
    ans=ans+b
    b=b-1
elif max(a,b)==b:
  ans=ans+b
  b=b-1
  if max(a,b)==a:
    ans=ans+a
    a=a-1    
  elif max(a,b)==b:
    ans=ans+b
    b=b-1      
print(ans)
Buggy python submission (verdict: Runtime Error):
T,X=map(int,input.split())
ans=T/X
print(ans)

Fixed submission:
T,X=map(int,input().split())
ans=T/X
print(ans)
Buggy python submission (verdict: Runtime Error):
S=list(input())
ans=0
if S[0]=='+':
    ans+=1
  else :
    ans-=1
if S[1]=='+':
    ans+=1
  else :
    ans-=1
if S[2]=='+':
    ans+=1
  else :
    ans-=1
if S[3]=='+':
    ans+=1
  else :
    ans-=1    
print(ans)    


Fixed submission:
S=list(input())
ans=0
if S[0]=='+':
    ans+=1
else :
    ans-=1
if S[1]=='+':
    ans+=1
else :
    ans-=1
if S[2]=='+':
    ans+=1
else :
    ans-=1
if S[3]=='+':
    ans+=1
else :
    ans-=1    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
p=1
b=a-1
while b>1:
    a=a*b
    b-=1
p=a%(10**9+7)
print(p)

Fixed submission:
a=int(input())
ans=1
for i in range(a):
  ans=ans*a%(10**9+7)
  a=a-1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ret = 0
for i in range(N):
  ret += i
print(ret)

Fixed submission:
N = int(input())
ret = N * (N-1) // 2
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
re_list = [r'dream$', r'dreamer$', r'erase$', r'eraser$']
while True:
  if s == '':
    print('YES')
    break
  for regex in re_list:
    m = re.sub(regex, '', s)
    if m != s:
      s = m
      break
  else:
    print('NO')
    break
  continue

Fixed submission:
S = input()
S = S[::-1]
while len(S) != 0:
  num = len(S)
  if S.find('maerd') == 0:
    S = S.replace('maerd', '', 1)
  if S.find('remaerd') == 0:
    S = S.replace('remaerd', '', 1)
  if S.find('esare') == 0:
    S = S.replace('esare', '', 1)
  if S.find('resare') == 0:
    S = S.replace('resare', '', 1)
  if num == len(S):
    print('NO')
    exit(0)
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
k = 1
for i in range(N):
    if L_A[i] == 0:
        print(0)
        break
    else:
        k *= L_A[i]
else:
    if k > 10**18:
        print("-1")
    else:
        print(k)

Fixed submission:
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
if 0 in L_A:
    print(0)
else:
    k = 1
    for i in range(N):
        k *= L_A[i]
        if k > 10**18:
            print("-1")
            break
    else:
        print(k)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(p+m,min(p+M+1,a+1)):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]
# L_j[x] < x <= 2 * (10**5)
ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(1,a+1):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]
# L_j[x] < x <= 2 * (10**5)
ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)