Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
import numpy as np
l ={}
N,K = map(int,input().split())
#P = list(map(int,input().split()))
P = np.asarray(list(map(int,input().split())))
#print(P)
P_ = []
#print(P_)

def kitai(num):
    x = 0
    for j in range(num):
        x += num-j
    return x/num
for i in P:
    P_.append(kitai(i))
#print(type(P_))


#print(P)
for i in range(0,N-K+1):
    #print(P[i:i+K])
    l[sum(P_[i:i+K])]=i
#print(l)
max = max(l.keys())
print(max)
import sys
def input():
    return sys.stdin.readline()[:-1]







Fixed submission:
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
li = input().split()
#print(li)
x,y = map(int,input().split())	
s =input()
if s==li[0]:
    print(x-1,y)
else:
    print(x,y-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in reversed(range(0,N)):
    if P[i]<=min(P):
        cnt +=1
    P.pop()
print(cnt)


Fixed submission:
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
N = int(input())
P = list(map(int,input().split()))
cnt = 0
mi = P[0]
for i in range(N):
    if P[i]<=mi:
        cnt +=1
    mi = min(mi,P[i])
print(cnt)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >=10 or B >=10:
    print("-1")
else:
    print(A*B)

Fixed submission:
# coding: utf-8
# Your code here!

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

if A >=10 or B >=10:
    print("-1")
else:
    print(A*B)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())))

for i in range(N):
    print (np.argsort(x)[i]+1,"",end="")

Fixed submission:
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())),dtype=np.int)

print (*np.argsort(x)+1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())))

for i in range(len(x)):
    print (np.argsort(x)[i]+1,"",end="")

Fixed submission:
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())),dtype=np.int)

print (*np.argsort(x)+1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int,input().split()))


x = np.array(A)

for i in range(len(x)):
    print (np.argsort(x)[i]+1,"",end="")

Fixed submission:
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())),dtype=np.int)

print (*np.argsort(x)+1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = list(map(int,input().split()))


x = np.array(A)

for i in range(len(x)):
    print (np.argsort(x)[i]+1,"",end="")

Fixed submission:
import numpy as np
N = int(input())

x = np.array(list(map(int,input().split())),dtype=np.int)

print (*np.argsort(x)+1)
Buggy python submission (verdict: Runtime Error):
char = input()
if char == Sunny:
    print(Cloudy)
elif char == Cloudy:
    print(Rainy)
else:
    print(Sunny)

Fixed submission:
char = input()
if char == "Sunny":
    print("Cloudy")
elif char == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

cnt = 0

if b<=a:
    cnt = 1
hole = a
else:
    for i in range(15):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
                break
            else:
                pass
print(cnt)


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

cnt = 0
hole = a
if b==1:
    cnt = 0

elif b!=1 and a>=b:
    cnt = 1
else:
    for i in range(pow(2,10)):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
                break
            else:
                pass
print(cnt)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

cnt = 0
hole = a
if b<=a:
    cnt = 1
elif:
    for i in range(b):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
            else:
                pass
print(cnt)


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

cnt = 0
hole = a
if b==1:
    cnt = 0

elif b!=1 and a>=b:
    cnt = 1
else:
    for i in range(pow(2,10)):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
                break
            else:
                pass
print(cnt)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

cnt = 0
hole = a
if b<=a:
    cnt = 1
elif:
    for i in range(b/a + 10):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
            else:
                pass
print(cnt)


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

cnt = 0
hole = a
if b==1:
    cnt = 0

elif b!=1 and a>=b:
    cnt = 1
else:
    for i in range(pow(2,10)):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
                break
            else:
                pass
print(cnt)
Buggy python submission (verdict: Runtime Error):
num = int(input())
char=[] #appendのために宣言が必要
while True:
    try:
        char.append(list(input()))

    except:
        break
new_char=[]
cnt=0
for i in range(num):
	new_char.append(sorted(char[i]))
for x in range(num):
    for y in range(num):
        if new_char[x]==new_char[y] and x!=y:
            cnt = cnt+1
print(cnt//2)
    

    

Fixed submission:
x,y = map(int,input().split())

ans = [x*y,x+y,x-y]

print(max(ans))

Buggy python submission (verdict: Runtime Error):
num = int(input())
char=[] #appendのために宣言が必要
while True:
    try:
        char.append(list(input()))

    except:
        break
new_char=[]
cnt=0
for i in range(num):
	new_char.append(sorted(char[i]))
for x in range(num):
    for y in range(num):
        if new_char[x]==new_char[y] and x!=y:
            cnt = cnt+1
print(cnt)

Fixed submission:
x,y = map(int,input().split())

ans = [x*y,x+y,x-y]

print(max(ans))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if (a*b) % 2 == 0:
    print("Even")

else:
    print("Odd")


Fixed submission:
x,y = map(int,input().split())

if (x*y) % 2 == 0:
    print("Even")

else:
    print("Odd")

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

if (a*b) % 2 == 0:
    print("Even")

else:
    print("Odd")


Fixed submission:
x,y = map(int,input().split())

if (x*y) % 2 == 0:
    print("Even")

else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
x,y,z= map(int,input().split())

print("x+y+z")

Fixed submission:
num = list(input())


print(num.count("1"))
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
j = 1
div = pow(10,9)+7
for i in range(num):
    j = (i+1)*j
print(j%div)

Fixed submission:
import math
num = int(input())

#div = pow(10,9)+7
print(math.factorial(num)%(pow(10,9)+7))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[0]*n
tmp=1
for i in range(k):
  tmp*=a[i]
  b[i]=tmp
for i in range(k,n):
  tmp*=a[i]
  tmp/=a[i-k]
  b[i]=tmp
  print('Yes' if b[i]>b[i-1] else 'No')

Fixed submission:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
for i in range(k,n):
  print('Yes' if a[i]>a[i-k] else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import itertools
from math import floor,sqrt
def func(m):
  r=0
  for x in range(1,floor(sqrt(m))+1):
    for y in range(1,floor(sqrt(m))+1):
      for z in range(1,floor(sqrt(m))+1):
        if x**2+y**2+z**2+x*y+y*z+z*x==m:
          r+=1
  return r
for i in range(1,n+1):
  print(func(i))

Fixed submission:
n=int(input())
from math import floor,sqrt
sqset=set()
for i in range(1,200):
  sqset.add(i**2)
def func(m):
  r=0
  for x in range(1,floor(sqrt(m))+1):
    for y in range(1,floor(sqrt(m))+1):
      a=x+y
      b=x**2+y**2+x*y-m
      d=a**2-4*b
      if d in sqset:
        if (sqrt(d)-a)>0 and (sqrt(d)-a)%2==0:
          r+=1
  return r
for i in range(1,n+1):
  print(func(i))
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a.reverse()
b.reverse()
ans=0
t=0
while len(a)>0 or len(b)>0:
  if len(a)>0 and a[-1]<b[-1]:
    t+=a.pop()
  elif len(b)>0:
    t+=b.pop()
  if t>k:
    break
  else:
    ans+=1
print(ans)

Fixed submission:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ca=[0]*(n+1)
ca[1]=a[0]
for i in range(n):
  ca[i+1]=ca[i]+a[i]
cb=[0]*(m+1)
cb[1]=b[0]
for i in range(m):
  cb[i+1]=cb[i]+b[i]
j=m
ans=0
for i in range(n+1):
  t=ca[i]
  while j>=0:
    if t+cb[j]>k:
      j-=1
    else:
      ans=max(ans,i+j)
      break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
input()
a=[int(i) for i in input().split()]
ans=1
for i in a:
  ans*=i
print(ans if ans<=10**18 else -1)

Fixed submission:
input()
a=[int(i) for i in input().split()]
ans=1
if 0 in a:
  print(0)
  exit()
for i in a:
  ans*=i
  if ans>10**18:
    print(-1)
    exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
input()
a=[int(i) for i in input().split()]
ans=1
for i in a:
  ans*=i
print(ans if ans<=10**18 else -1)

Fixed submission:
input()
a=[int(i) for i in input().split()]
ans=1
if 0 in a:
  print(0)
  exit()
for i in a:
  ans*=i
  if ans>10**18:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod=998244353
n,m,k=map(int,input().split())
fcl=[1]*(n+1)
for i in range(1,n+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%p*pow(fcl[x-y],p-2,p))%p
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-1-i,mod)*comb(n-1,i,mod)
  ans%=mod
print(ans)

Fixed submission:
mod=998244353
n,m,k=map(int,input().split())
fcl=[1]*(n+1)
for i in range(1,n+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%p*pow(fcl[x-y],p-2,p))%p
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-1-i,mod)*comb(n-1,i,mod)
  ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
x=int(input())
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors
for i in make_divisors(x):
  a=0
  b=-i
  ab=0
  while b<=0 or i*ab<=x:
    ab=a**4+a**3*b+a**2*b**2+a*b**3+b**4
    if i*ab==x:
      print(a,b)
      sys.exit()
    a+=1
    b+=1

Fixed submission:
import sys
x=int(input())
lim=10**3
for i in range(-lim,lim):
  for j in range(-lim,lim):
    if i**5-j**5==x:
      print(i,j)
      sys.exit()
Buggy python submission (verdict: Runtime Error):
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ansl=[]
for v in cr(nl,m):
  ans=0
  for a,b,c,d in l:
    if v[b-1]-v[a-1]==c:
      ans+=d
  ansl.append(ans)
print(max(ansl))

Fixed submission:
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ans=0
for v in cr(nl,n):
  s=0
  for a,b,c,d in l:
    if v[b-1]-v[a-1]==c:
      s+=d
  if ans<s:
    ans=s
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ansl=[]
for v in cr(nl,m):
  ans=0
  for a,b,c,d in l:
    if v[b]-v[a]==c:
      ans+=d
  ansl.append(ans)
print(max(ansl))

Fixed submission:
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(q)]
nl=[i for i in range(1,m+1)]
ans=0
for v in cr(nl,n):
  s=0
  for a,b,c,d in l:
    if v[b-1]-v[a-1]==c:
      s+=d
  if ans<s:
    ans=s
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
c=0
t=[0]*(len(s)+1)
for i in [str(i*2019) for i in range(1,10000) if '0' not in str(2019*i)]:
  idx=-1
  while s[idx+1:].count(i)>0:
    idx=s[idx+1:].find(i)
    t[idx+len(i)]+=1+t[idx]
    c+=1
    c+=t[idx]
print(c)

Fixed submission:
s=input()
n=len(s)
mod=2019
d=0
p=1
ml=[0]*mod
for i in range(1,n+1):
  k=int(s[-i])
  d+=p*k
  d%=mod
  ml[d]+=1
  p*=10
  p%=mod
ans=0
for i in ml:
  ans+=i*(i-1)//2
print(ans+ml[0])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
c=0
for i in range(n-2):
  t1=s[i]
  for j in range(i+1,n-1):
    t2=s[j]
    if t1 not in t2:
      for k in range(j+1,n):
        t3=s[k]
        if t3 not in t1+t2 and j-i!=k-j:
          c+=1
print(c)

Fixed submission:
n=int(input())
s=input()
t=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  j=1
  while i+j*2<n:
    if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i]!=s[i+2*j]:
      t-=1
    j+=1
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
j=0
c=0
while c<=n:
  j+=1
  b=0
  if j<10:
    c+=1
    if c==n:
      break
  else:
    a=str(j)
    for i in range(len(a)-1):
      if abs(int(a[i])-int(a[i+1]))<=1:
        b+=1
    if b==len(a)-1:
      c+=1
    if c==n:
      break
print(j)

Fixed submission:
k=int(input())
l=[1,2,3,4,5,6,7,8,9]
for i in range(k):
  x=l[i]
  if x%10!=0:
    l.append(10*x+x%10-1)
  l.append(10*x+x%10)
  if x%10!=9:
    l.append(10*x+x%10+1)
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
  x=0
  for j in set(a):
    c=a[0:i].count(j)+a[i+1:n].count(j)
    x+=int(c*(c-1)/2)
  print(x)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
m=max(a)
l=[0]*(m+1)
c=[0]*(m+1)
for i in a:
  l[i]+=1
for i in set(a):
  c[i]=l[i]*(l[i]-1)/2
s=sum(c)
for i in range(n):
  print(int(s-c[a[i]]+(l[a[i]]-1)*(l[a[i]]-2)/2))
Buggy python submission (verdict: Runtime Error):
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*n
ans=0
for c in s[::-1]:
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=1
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p==2 or p==5:
  l[0]=ans
  ans=ans*(ans-1)//2
else:
  for i in l:
    ans+=i*(i-1)//2
print(ans+l[0])

Fixed submission:
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*p
l[0]=1
ans=0
for i,c in enumerate(s[::-1]):
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=n-i
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p!=2 and p!=5:
  for i in l:
    ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*n
ans=0
for c in s[::-1]:
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=1
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p==2 or p==5:
  ans=ans*(ans+1)//2
else:
  for i in l:
    ans+=i*(i-1)//2
print(ans+l[0])

Fixed submission:
n,p=map(int,input().split())
s=input()
b=1
d=0
l=[0]*p
l[0]=1
ans=0
for i,c in enumerate(s[::-1]):
  if p==2 or p==5:
    if int(c)%p==0:
      ans+=n-i
  else:
    d+=int(c)*b
    d%=p
    l[d]+=1
    b*=10
    b%=p
if p!=2 and p!=5:
  for i in l:
    ans+=i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
q=int(input())

def ctoi(c):
  return ord(c)-97
class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [[0]*(n+1) for _ in range(26)]
  def query(self,a,i):
    r = 0
    while i > 0:
      r += self.tree[a][i]
      i -= i & -i
    return r
  def update(self,i,a,x):
    while i<=n:
      self.tree[a][i]+=x
      i+=i&(-i)
bi=Bit(n)
for i in range(n):
  bi.update(i+1,ctoi(s[i]),1)
  
for _ in range(q):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1 and s[b-1]!=c:
    bi.update(b,ctoi(s[b-1]),-1)
    bi.update(b,ctoi(c),1)
    s[b-1]=c
  elif a==2:
    c=int(c)
    right=[bi.query(i,c) for i in range(26)]
    left=[bi.query(i,b-1) for i in range(26)]
    ans=0
    for r,l in zip(right,left):
      if r-l>0:
        ans+=1
    print(ans)

Fixed submission:
n=int(input())
s=list(input())
q=int(input())

def ctoi(c):
  return ord(c)-97
class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [[0]*(n+1) for _ in range(26)]
  def query(self,a,i):
    r = 0
    while i > 0:
      r += self.tree[a][i]
      i -= i & -i
    return r
  def update(self,i,a,x):
    while i<=n:
      self.tree[a][i]+=x
      i+=i&(-i)
bi=Bit(n)
for i in range(n):
  bi.update(i+1,ctoi(s[i]),1)
  
for _ in range(q):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1 and s[b-1]!=c:
    bi.update(b,ctoi(s[b-1]),-1)
    bi.update(b,ctoi(c),1)
    s[b-1]=c
  elif a==2:
    c=int(c)
    right=[bi.query(i,c) for i in range(26)]
    left=[bi.query(i,b-1) for i in range(26)]
    ans=0
    for r,l in zip(right,left):
      if r-l>0:
        ans+=1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
q=int(input())
que=[list(input().split()) for _ in range(q)]
for q1,q2,q3 in que:
  if q1=='1':
    s[int(q2)-1]=q3
  else:
    print(len(set(s[int(q2)-1:int(q3)])))

Fixed submission:
n=int(input())
s=list(input())
q=int(input())

def ctoi(c):
  return ord(c)-97
class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [[0]*(n+1) for _ in range(26)]
  def query(self,a,i):
    r = 0
    while i > 0:
      r += self.tree[a][i]
      i -= i & -i
    return r
  def update(self,i,a,x):
    while i<=n:
      self.tree[a][i]+=x
      i+=i&(-i)
bi=Bit(n)
for i in range(n):
  bi.update(i+1,ctoi(s[i]),1)
  
for _ in range(q):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1 and s[b-1]!=c:
    bi.update(b,ctoi(s[b-1]),-1)
    bi.update(b,ctoi(c),1)
    s[b-1]=c
  elif a==2:
    c=int(c)
    right=[bi.query(i,c) for i in range(26)]
    left=[bi.query(i,b-1) for i in range(26)]
    ans=0
    for r,l in zip(right,left):
      if r-l>0:
        ans+=1
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

mod=10**9+7
def modfc(x,y,p):
  f=1
  for i in range(x,y+1):
    f=f%p*i%p
  return f%p
def comb(x,y,p):
  return modfc(x-y+1,x,p)*pow(modfc(1,y,p),p-2,p)

maxs=0
for i in range(k,n+1):
  maxs+=a[i-1]*comb(i-1,k-1,mod)
  maxs%=mod
mins=0
for i in range(n-k+1):
  mins+=a[i]*comb(n-i-1,k-1,mod)
  mins%=mod
ans=(maxs-mins)%mod
print(ans+mod if ans<0 else ans)

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

mod=10**9+7
fcl=[1]*(n+1)
for i in range(1,n+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%mod*pow(fcl[x-y],p-2,p))%mod

maxs=0
for i in range(k,n+1):
  maxs+=a[i-1]*comb(i-1,k-1,mod)
  maxs%=mod
mins=0
for i in range(n-k+1):
  mins+=a[i]*comb(n-i-1,k-1,mod)
  mins%=mod
ans=(maxs-mins)%mod
print(ans+mod if ans<0 else ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
n=int(input())
a=[format(int(i),'b') for i in input().split()]
d0=[0]*60
d1=[0]*60
ans=0
for i in a:
  d=i[::-1]
  l=len(i)
  for j in range(60):
    if j<l and d[j]=='1':
      d1[j]+=1
    else:
      d0[j]+=1
for j in range(60):
  ans+=d0[j]*d1[j]*(2**j)
  ans%=mod
print(ans)

Fixed submission:
mod=10**9+7
n=int(input())
a=[format(int(i),'b') for i in input().split()]
d0=[0]*60
d1=[0]*60
ans=0
for i in a:
  d=i[::-1]
  l=len(i)
  for j in range(60):
    if j<l and d[j]=='1':
      d1[j]+=1
    else:
      d0[j]+=1
for j in range(60):
  ans+=d0[j]*d1[j]*(2**j)
  ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
mod=10**9+7
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans+=a[i]^a[j]
    ans%=mod
print(ans)

Fixed submission:
mod=10**9+7
n=int(input())
a=[format(int(i),'b') for i in input().split()]
d0=[0]*60
d1=[0]*60
ans=0
for i in a:
  d=i[::-1]
  l=len(i)
  for j in range(60):
    if j<l and d[j]=='1':
      d1[j]+=1
    else:
      d0[j]+=1
for j in range(60):
  ans+=d0[j]*d1[j]*(2**j)
  ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())
if x<=a*a*b/2:
  ans=90-math.degrees(math.atan(2*x/a/b/b))
else:
  ans=90-math.degrees(math.atan(a*a*a/2/(a*a*b-x)))
print(ans)

Fixed submission:
import math
a,b,x=map(int,input().split())
if x==a*a*b:
  ans=0
elif x<=a*a*b/2:
  ans=90-math.degrees(math.atan(2*x/a/b/b))
else:
  ans=90-math.degrees(math.atan(a*a*a/2/(a*a*b-x)))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for _ in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

Fixed submission:
import sys
n,q=map(int,input().split())
s=input()
c=[0]*n
for i in range(2,n+1):
  if s[i-2:i]=='AC':
    c[i-1]=c[i-2]+1
  else:
    c[i-1]=c[i-2]
lr=sys.stdin.readlines()
for i in lr:
  l,r=map(int,i.split())
  print(c[r-1]-c[l-1])