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

Fixed submission:
import math
# from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum=[]

for i in range(2,1000):
  flag=False  
  for j in range(2,i):
    if i%j==0:
      flag=True
      break
  if flag==False:
    primeNum.append(i)
    

# primeNum = [i for i in sieve.primerange(1,1000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
flag=False
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
    flag=True
  
  if flag==True:
    result*=(resulNum[j]+1)
    result %= 10**9+7
  j+=1
  flag=False

print(result)

Buggy submission (verdict: Runtime Error):
import math
from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum=[]

for i in range(2,1000):
  flag=False  
  for j in range(2,i):
    if i%j==0:
      flag=True
      break
  if flag==False:
    primeNum.append(i)
    

# primeNum = [i for i in sieve.primerange(1,1000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
flag=False
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
    flag=True
  
  if flag==True:
    result*=(resulNum[j]+1)
    result %= 10**9+7
  j+=1
  flag=False

print(result)

Buggy submission (verdict: Runtime Error):
import math
from sympy import sieve
N=int(input())

num = math.factorial(N)
primeNum = [i for i in sieve.primerange(1,10000000)]
# print(primeNum)
resulNum=[0]*len(primeNum)
result=1

j=0
for i in primeNum:
  while num % i == 0 :
    num = num // i
    resulNum[j]+=1
  j+=1

for i in resulNum:
  if i>0:
    result*=(i+1)
    result %= 10**9+7

print(result)
Problem p03860 (python)

Fixed submission:
A,B,C=input().split()
print("A"+B[0]+"C")

Buggy submission (verdict: Runtime Error):
a,b,x= map(int,input().split())
result=0
num = a
for _ in range(a,b+1,x):
    if num <= b and num % x == 0 :
        # print("num",num)
        result+=1
    num+=x
# while a <= b:
#     if a % x == 0:
#         result+=1
#     a+=x
print(result)
Problem p04012 (python)

Fixed submission:
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(0)
print("No")

Buggy submission (verdict: Runtime Error):
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(1)
print("No")

Buggy submission (verdict: Runtime Error):
w=input()

for i in range(len(w)):
    if w.count(w[i])%2==0:
        pass
    else:
        break
else:
    print("Yes")
    exit(1)
print("No")
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    print(0)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    li.sort()
    print((li[0]*li[1])%2019)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)
Problem p03262 (python)

Fixed submission:
from fractions import gcd
n,X=map(int, input().split())
x=list(map(int, input().split()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=gcd(ans, abs(xi-X))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n,X=map(int, input().split())
x=list(map(int, input().split()))
ans=abs(x[0]-X)
for xi in x[1:]:
    ans=math.gcd(ans, abs(xi-X))
print(ans)
Problem p03266 (python)

Fixed submission:
n, k= map(int, input().split())
cnt=[0]*k
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)

Buggy submission (verdict: Runtime Error):
n, k= map(int, input().split())
cnt=[0]*n
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)
Problem p03274 (python)

Fixed submission:
n,k=map(int, input().split())
x=list(map(int, input().split()))
zi=0
for xi in x:
    if xi>=0:
        break
    zi+=1

xm=[0]
if zi<len(x) and x[zi]==0:
    xp=[]
else:
    xp=[0]

xm.extend(reversed(x[:zi]))
xp.extend(x[zi:])

ans=float('inf')
for i in range(k):
    if i<len(xm) and k-i<len(xp):
        ans=min(xm[i]*2*(-1) + xp[k-i], ans)
    if i<len(xp) and k-i<len(xm):
        ans=min(xp[i]*2 + xm[k-i]*(-1), ans)
if len(x)==1 and x[0]==0:
    ans=0
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int, input().split())
x=list(map(int, input().split()))
zi=0
for xi in x:
    if xi>=0:
        break
    zi+=1

xm=[0]
if x[zi]==0:
    xp=[]
else:
    xp=[0]

xm.extend(reversed(x[:zi]))
xp.extend(x[zi:])

ans=float('inf')
for i in range(k):
    if i<len(xm) and k-i<len(xp):
        ans=min(xm[i]*2*(-1) + xp[k-i], ans)
    if i<len(xp) and k-i<len(xm):
        ans=min(xp[i]*2 + xm[k-i]*(-1), ans)
if len(x)==1 and x[0]==0:
    ans=0
print(ans)
Problem p03305 (python)

Fixed submission:
from collections import defaultdict
import heapq
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

def dijkstra(s, t, cost):
    q=[]
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(q, (d[s], s))
    prev={}
    while q!=[]:
        du, u=heapq.heappop(q)
        for v in adj[u]:
            if d[v]>du+cost[(u,v)]:
                d[v]=du+cost[(u,v)]
                prev[v]=u
                
                heapq.heappush(q, (d[v], v))
    return d

d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
snuke=[]
for d1i, d2i in zip(d1,d2):
    snuke.append(d1i+d2i)
ans=[]
mins=float('inf')
for si in reversed(snuke):
    if si<mins:
        ans.append(si)
        mins=si
    else:
        ans.append(mins)
ans.reverse()
for ai in ans:
    print(10**15-ai)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

d=[float('inf')]*n
d[s]=0
prev={}
q=list(range(n))
while q!=[]:
    md=float('inf')    
    for qi in q:
        md=min(md,d[qi])
    u=q.pop(q.index(d.index(md)))
    for v in adj[u]:
        if d[v]>d[u]+yen[(u,v)]:
            d[v]=d[u]+yen[(u,v)]
            prev[v]=u
# tr=t
# while tr!=s:
#     print(tr,'->')
#     tr=prev[tr]
# print(s)
dr=[float('inf')]*n
dr[t]=0
prevr={}
qr=list(range(n))
while qr!=[]:
    md=float('inf')    
    for qi in qr:
        md=min(md,dr[qi])
    u=qr.pop(qr.index(dr.index(md)))
    for v in adj[u]:
        if dr[v]>dr[u]+snk[(u,v)]:
            dr[v]=dr[u]+snk[(u,v)]
            prevr[v]=u
while d!=[]:
    ans=float('inf')
    for y,s in zip(d,dr):
        ans=min(ans, y+s)
        if ans==y+s:
            ai=d.index(y)
    print(10**15-ans)
    del d[0]
    del dr[0]
Problem p03354 (python)

Fixed submission:
class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n)]
    def root(self, x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.root(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def unite(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x!=y:
            self.par[x]=y

n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]

uf=UnionFind(n)
for pi in pair:
    uf.unite(pi[0],pi[1])

cnt=0
for i, pi in enumerate(p):
    if uf.same(i,pi):
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]
 
avl=defaultdict(list)
for pi in pair:
    avl[pi[0]].append(pi[1])
    avl[pi[1]].append(pi[0])
 
def trv(src, dst, alr=[]):
    ans=False
    if src==dst or dst in avl[src]:
        return True
    for a in avl[src]:
        if a not in alr:
            alr.append(a)            
            ans|=trv(a, dst, alr)
    return ans
 
cnt=0
for i,pi in enumerate(p):
    if trv(pi, i, []):
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]

avl=defaultdict(list)
for pi in pair:
    avl[pi[0]].append(pi[1])
    avl[pi[1]].append(pi[0])

def trv(src, dst, alr=[]):
    ans=False
    if src==dst or dst in avl[src]:
        return True
    for a in avl[src]:
        if a not in alr:
            alr.append(a)            
            ans|=trv(a, dst, alr)
    return ans

cnt=0
for i in range(n):
    if trv(p.index(i), i, []):
        cnt+=1
print(cnt)
Problem p03361 (python)

Fixed submission:
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[j][i]=='#':
            if s[j-1][i]!='#' and s[j+1][i]!='#' and s[j][i-1]!='#' and s[j][i+1]!='#' :
                    print('No')
                    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[j][i]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
h,w=map(int, input().split())
s=[' '*(w+2)]
for _ in range(h):
    s.append(' '+input()+' ')
s.append(' '*(w+2))

#print(s)

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[i][j]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
h,w=map(int, input().split())
s=['.'*(w+2)]
for _ in range(h):
    s.append('.'+input()+',')
s.append('.'*(w+2))

#print(s)

for i in range(1,w+1):
    for j in range(1,h+1):
        if s[i][j]=='#':
            if s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' :
                    print('No')
                    exit()
print('Yes')
Problem p03415 (python)

Fixed submission:
c1=input()
c2=input()
c3=input()

print(c1[0]+c2[1]+c3[2])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
cnt=0
for a in range(1,n+1):
    for b in range(k,n+1):
        if a%b>=k:
            cnt+=1
print(cnt)
Problem p03418 (python)

Fixed submission:
n, k = map(int, input().split())
cnt=0
if k==0:
    print(n*n)
else:
    for b in range(k+1,n+1):
        a_=int(n/b)
        cnt+=(b-k)*(a_)
        cnt+=max(n%b-k+1, 0)
    print(cnt)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
cnt=0
for a in range(1,n+1):
    for b in range(k,n+1):
        if a%b>=k:
            cnt+=1
print(cnt)
Problem p03637 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
p=0
f=0
for ai in a:
    if ai%2==1:
        p+=1
    else:
        if ai/2%2==0:
            f+=1
if p==0:
    print('Yes')
elif p>f:
    if n%2==1 and 2*f+1==n:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
p=0
f=0
for ai in a:
    if ai%2!=0:
        p+=1
    else:
        if ai/2%2==0:
            f+=1
if f==0:
    print('No')
elif f==1:
    if n>3:
        print('No')
    else:
        print('Yes')
elif p>f:
    if p%2=1 and 2*p-1==n:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')
Problem p02922 (python)

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

for i in range(1, 20):
  if B > 1:
    c = (A-1)*(i-1) + A
    if c >= B:
      break
  else:
    i = 0
    break

print(i)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

for i in range(1, 20):
  c = (A-1)*(i-1) + A
  if C >= B:
    break
    
print(i)
Problem p02957 (python)

Fixed submission:
a,b = map(int,input().split())
if (a % 2 == 0 and b % 2 == 0) or (a % 2 == 1 and b % 2 == 1):
    print((a+b)//2)
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n-1,-1,-1):
    # i+1の討伐
    if a[i+1] < b[i]:
        count += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        count += b[i]
        a[i+1] -= b[i]
        b[i] = 0

    # iの討伐
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        count += b[i]
        a[i] -= b[i]
        b[i] = 0

print(count)
Problem p02993 (python)

Fixed submission:
s = int(input())
n = []
f = 0

while s > 0:
    n.append(s % 10)
    s = s // 10

n.reverse()
if(len(n) < 3):
    f = 1

for i in range(1,len(n)):
    if(n[i] == n[i -1]):
        f = 1
        break

if(f == 1):
    print('Bad')
else:
    print('Good')

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
count = 0
e = b - a
for i in range(a,d):
    if(i % c != 0 and i % d != 0):
        count += 1
for i in range(d,b + 1):
    if(i % c != 0 and i % d != 0):
        count += 1 
print(count)
Problem p03000 (python)

Fixed submission:
n, x = map(int,input().split())
l = list(map(int,input().split()))
d = 0 #1回目の座標
#2回目以降
count = 1
for i in range (0,n):
    d = d + l[i]
    if(d > x):
        break
    count += 1

print(count)

Buggy submission (verdict: Runtime Error):
n, x = map(int,input().split())
l = list(map(int,input().split()))
d = 0
i = 0
while(d <= x):
    d = d + l[i]
    i += 1

print(i)
Problem p03035 (python)

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

if(a >= 13):
    print(b,'\n')
elif(a >= 6 and a <= 12):
    print(b // 2,'\n')
else:
    print('0\n')

Buggy submission (verdict: Runtime Error):
r,D,x = map(int,input().split())
for i in range(0,10):
    result = r * x - D
    print(result)
    x = result

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if(a >= 13):
    print(b,'\n')
elif(a >= 6 and a <= 12):
    print(b // 2,'\n')
else:
    print('0\n')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if(a >= 13):
    print(b)
elif(a >= 6 and a <= 12):
    print(b // 2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if(a >= 13):
    print(b)
elif(a >= 6 and a <= 12):
    print(b // 2)
else:
    print(0)
Problem p03037 (python)

Fixed submission:
n,m = map(int,input().split())

l = [0]*m
r = [0]*m
b = [0]*(n + 2)

count = 0

for i in range(0,m):
    l[i],r[i] = map(int,input().split())

l_max = max(l)
r_min = min(r)

for i in range(1,n+1):
        if(i >= l_max and i <= r_min ):
                count += 1
        
print(count)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

l = [0]*10000
r = [0]*10000

for i in range(0,m):
    l[i],r[i] = map(int,input().split())

count = 0
num = 0

for key in range(1,n + 1):#鍵の番号
    for i in range(0,m):#
        if(key >= l[i] and key <= r[i]):
            count += 1
    if(count == m):
        num += 1
    count = 0
        
print(num)
Problem p03351 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
    print('Yes')
else
    print('No')
Problem p03813 (python)

Fixed submission:
s = int(input())
if s < 1200:
    print('ABC')
else:
    print('ARC')

Buggy submission (verdict: Runtime Error):
z = int(input())
if s < 1200:
    print('ABC')
else:
    print('ARC')
Problem p02899 (python)

Fixed submission:
n, = map(int,input().split())
li = input().split()
h_list = [int(li[i]) for i in range(n)]


sorted_indices = sorted(range(n), key=lambda i: h_list[i])
answer = [str(sorted_indices[i] + 1) for i in range(n)]
print(' '.join(answer))

Buggy submission (verdict: Runtime Error):
n, = map(int,input().split())
li = input().split()
h_list = [int(li[i]) for i in range(n)]

indices = [*range(len(h_list))]
sorted_indices = sorted(indices, key=lambda i: h_list[i])
answer = [sorted_indices[i] + 1 for i in range(n)]
print(answer)
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b
if c % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b
if c % 2 == 0:
  print(Even)
else:
  print(Odd)
Problem p02921 (python)

Fixed submission:
S = input()
T = input()

N = 0
for i in range(3):
  if S[i] == T[i]:
    N += 1
print(N)

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

A = [i+1 for i in range(N)]

ind_max=0

for _ in range(300000):
  B = [i+1 for i in range(N)]
  random.shuffle(B)
  ind = 0
  for i in range(N):
    ind += (A[i] % B[i])
  if ind_max < ind:
    ind_max = ind
print(ind_max)
Problem p02924 (python)

Fixed submission:
n = int(input())

ans = 0
if n%2 == 0:
    ans = (n//2)*(n-1)
else:
    ans = ((n-1)//2)*n
print(ans)

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

ans = 0
if n%2 = 0:
    ans = (n//2)*(n-1)
else:
    ans = ((n-1)//2)*n
print(ans)

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

if n%2 = 0:
    ans = (n//2)*(n-1)
else:
    ans = ((n-1)//2)*n
print(ans)
Problem p02928 (python)

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

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0

if k%2 == 0:
    sigmakp = (int(k/2) * (k+1)) % mod
    sigmakn = (int(k/2) * (k-1)) % mod
else:
    sigmakp = (int((k+1)/2) * k) % mod
    sigmakn = (int((k-1)/2) * k) % mod

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
#sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
#sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(int(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0
# kまでの和　後ろの数用
sigmakp = (((k * (k+1)) % mod) / 2) % mod
sigmakp = int(sigmakp)
# k-1までの和　前の数用
sigmakn = (((k * (k-1)) % mod) / 2) % mod
sigmakn = int(sigmakn)

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

k = k % mod
mod = 10 ** 9 + 7
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k * (k+1)) % mod) / 2) % mod
sigmakn = int(((k * (k-1)) % mod) / 2) % mod
for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)
Problem p02947 (python)

Fixed submission:
num = int(input())
li = [input() for i in range(num)]

dic = {}
ans = 0
for i in range(num):
    now = "".join(sorted(li[i]))
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
for i in dic:
    n = dic[i]
    ans += int((n*(n-1))/2)

print(ans)

Buggy submission (verdict: Runtime Error):
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
for i in range(num):
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for now in dic:
        dic.remove(now)
print(ans)

Buggy submission (verdict: Runtime Error):
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
for i in range(num)
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for i in range(cnt):
        dic.remove(now)
    i += cnt - 1
print(ans)
Problem p02953 (python)

Fixed submission:
cell_num = int(input())
height = list(map(int, input().split()))
flag = True

if cell_num != 1:
    if height[0] - height[1] <= 1:
        height[0] -= 1
    elif height[0] - height[1] > 1:
        flag = False
    
    for i in range(1,cell_num-1):
        if height[i] - height[i+1] > 1:
            flag = False
            break
        elif height[i] -  height[i+1] <= 1 and height[i-1] < height[i]:
            height[i] -= 1
        elif height[i] -  height[i+1] == 1 and height[i-1] == height[i]:
            flag = False
            break
            
if flag: print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
cell_num = int(input())
height = list(map(int, input().split()))
flag = True

if cell_num != 1:
    for i in range(cell_num):
        if height[i+1] - height[i] == 1: height[i+1] -= 1
        elif height[i+1] - height[i] > 1:
            flag = False
            break

if flag: print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
cell_num = int(input())
height = list(map(int, input().split()))
flag = True

for i in range(cell_num):
    if height[i+1] - height[i] == 1: height[i+1] -= 1
    elif height[i+1] - height[i] > 1:
        flag = False
        break

if flag: print("Yes")
else: print("No")
Problem p03964 (python)

Fixed submission:
def divceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
t = 1
a = 1
r = 0
for i in range(num):
    r = max(divceil(t, arr[i][0]), divceil(a, arr[i][1]))
    t = arr[i][0] * max(r, 1)
    a = arr[i][1] * max(r, 1)
print(t + a)

Buggy submission (verdict: Runtime Error):
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]

ans = [[arr[0][0], arr[0][1]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        ans[i+1][0] += arr[i+1][0]
        ans[i+1][1] += arr[i+1][1]
print(ans[num-1][0] + ans[num-1][1])