Buggy python submission (verdict: Runtime Error):
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=dict(Counter(x))
  cxmod=dict(Counter(xmod))
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in cxmod.keys():
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=dict(Counter(x))
  cxmod=dict(Counter(xmod))
  keys=list(cxmod.keys())
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cxmod=dict(Counter(xmod))
  cx=dict(Counter(x))
  keys=list(cxmod.keys())
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  d2={}
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k,v in cx.items():
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=dict(Counter(xmod))
  keys=list(cx.keys())
  ans1,ans2=0,0 # m倍になるペア、同数のペア
  d2={}
  for k in keys:
    if k==0:
      ans1+=cx[k]//2
      cx[k]-=2*(cx[k]//2)
    else:
      if k==m-k:
        ans1+=cx[k]//2
        cx[k]-=2*(cx[k]//2)
      elif m-k in keys:
        tmp=min(cx[k],cx[m-k])
        ans1+=tmp
        cx[k]-=tmp
        cx[m-k]-=tmp
      if cx[k]>=2:
        ans2+=cx[k]//2
        d2[k]=cx[k]//2
  d1={}
  for y in x:
    if y%m in d1:
      d1[y%m].append(y)
    else:
      d1[y%m]=[y]
  d3={}
  for k in d1:
    tmp={}
    d3[k]=0
    for i in d1[k]:
      if i in tmp:
        tmp[i]+=1
        if tmp[i]%2==0:
          d3[k]+=1
      else:
        tmp[i]=1
  for k in d2:
    tmp=d3[k]
    if tmp>=d2[k]:
      pass
    else:
      ans2-=d2[k]
      ans2+=tmp
  print(ans1+ans2)
if __name__=='__main__':
  main()



Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
x=list(map(int,input().split()))
xmod=[y%m for y in x]
from collections import Counter
cx=dict(Counter(xmod))
keys=list(cx.keys())
keys.sort()
ans1,ans2=0,0 # m倍になるペア、同数のペア
d2={}
for k in keys:
  if k==0:
    ans1+=cx[k]//2
    cx[k]-=2*(cx[k]//2)
  else:
    if k==m-k:
      ans1+=cx[k]//2
      cx[k]-=2*(cx[k]//2)
    elif m-k in keys:
      tmp=min(cx[k],cx[m-k])
      ans1+=tmp
      cx[k]-=tmp
      cx[m-k]-=tmp
    if cx[k]>=2:
      ans2+=cx[k]//2
      d2[k]=cx[k]//2
d1={}
for y in x:
  if y%m in d1:
    d1[y%m].append(y)
  else:
    d1[y%m]=[y]
d3={}
for k in d1:
  tmp={}
  d3[k]=0
  for i in d1[k]:
    if i in tmp:
      tmp[i]+=1
      if tmp[i]%2==0:
        d3[k]+=1
    else:
      tmp[i]=1

for k in d2:
  tmp=d3[k]
  if tmp>=d2[k]:
    pass
  else:
    ans2-=d2[k]
    ans2+=tmp
print(ans1+ans2)

Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
x=list(map(int,input().split()))
xmod=[y%m for y in x]
from collections import Counter
cx=dict(Counter(xmod))
keys=list(cx.keys())
keys.sort()
ans1,ans2=0,0 # m倍になるペア、同数のペア
d2={}
for k in keys:
  if k==0:
    ans1+=cx[k]//2
    cx[k]-=2*(cx[k]//2)
  else:
    if k==m-k:
      ans1+=cx[k]//2
      cx[k]-=2*(cx[k]//2)
    elif m-k in keys:
      tmp=min(cx[k],cx[m-k])
      ans1+=tmp
      cx[k]-=tmp
      cx[m-k]-=tmp
    if cx[k]>=2:
      ans2+=cx[k]//2
      d2[k]=cx[k]//2
d1={}
for y in x:
  if y%m in d1:
    d1[y%m].append(y)
  else:
    d1[y%m]=[y]
d3={}
for k in d1:
  tmp={}
  d3[k]=0
  for i in d1[k]:
    if i in tmp:
      tmp[i]+=1
      if tmp[i]%2==0:
        d3[k]+=1
    else:
      tmp[i]=1

for k in d2:
  tmp=d3[k]
  if tmp>=d2[k]:
    pass
  else:
    ans2-=d2[k]
    ans2+=tmp
print(ans1+ans2)

Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
x=list(map(int,input().split()))
xmod=[y%m for y in x]
from collections import Counter
cx=dict(Counter(xmod))
keys=list(cx.keys())
keys.sort()
ans1,ans2=0,0 # m倍になるペア、同数のペア
d2={}
for k in keys:
  if k==0:
    ans1+=cx[k]//2
    cx[k]-=2*(cx[k]//2)
  else:
    if k==m-k:
      ans1+=cx[k]//2
      cx[k]-=2*(cx[k]//2)
    elif m-k in keys:
      tmp=min(cx[k],cx[m-k])
      ans1+=tmp
      cx[k]-=tmp
      cx[m-k]-=tmp
    if cx[k]>=2:
      ans2+=cx[k]//2
      d2[k]=cx[k]//2
d1={}
for y in x:
  if y%m in d1:
    d1[y%m].append(y)
  else:
    d1[y%m]=[y]
d3={}
for k in d1:
  d3[k]=dict(Counter(d1[k]))
for k in d2:
  tmp=sum([(v//2) for v in d3[k].values() if v>1])
  if tmp>=d2[k]:
    pass
  else:
    ans2-=d2[k]
    ans2+=tmp
print(ans1+ans2)

Fixed submission:
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  #xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod={}
  for k in cx:
    if k%m in cxmod:
      cxmod[k%m]+=cx[k]
    else:
      cxmod[k%m]=cx[k]
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()