TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import numpy as np
import collections
n,m=map(int,input().split())
a=np.array(list(map(int,input().split())))
a=np.sort(a)
m//=a[0]

l=[]
for p in range(m):
  print((a*(p+0.5)))
  for i in (a*(p+0.5)):
    if i>m:continue
    if i==int(i):
      l.append(int(i))
print(list(collections.Counter(l).values()).count(len(a)))

import numpy as np
import collections
n,m=map(int,input().split())
a=np.array(list(map(int,input().split())))
a=np.sort(a)
m//=a[0]

l=[]
for p in range(m):
  for i in (a*(p+0.5)):
    if i>m:continue
    if i==int(i):
      l.append(int(i))
print(list(collections.Counter(l).values()).count(len(a)))

n,m=map(int,input().split())
a=[ i //2 for i in list(map(int,input().split()))]
def f(x):
  c=0
  while(x%2==0):
    x//=2
    c+=1
  return c
def gcd(a,b):
  if b==0:
    return a
  return gcd(b,a%b)
def lcm(a,b):
  return a//gcd(a,b)*b

t=f(a[0])
for i in range(len(a)):
  if t!=f(a[i]):
    print(0)
    exit(0)
  a[i]//=2**t
m//=2**t
l=1
for i in a:
  l=lcm(l,i)
  if l>m:
    print(0)
    exit(0)
m//=l
print((m+1)//2)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import fractions
from functools import reduce
def lcm_base(x,y):
    return (x*y) // fractions.gcd(x, y)

def lcm_list(num):
    return reduce(lcm_base, num, 1)

n, m = map(int,input().split())
a_list = list(map(int,input().split()))
u1 = lcm_list(a_list)
u2 = lcm_list(a_list) // 2
print((m-u2) // u1 + 1)


import fractions
from functools import reduce
def lcm_base(x,y):
    return (x*y) // fractions.gcd(x, y)

def lcm_list(num):
    return reduce(lcm_base, num, 1)

n, m = map(int,input().split())
a_list = list(map(int,input().split()))
u1 = lcm_list(a_list)
u2 = lcm_list(a_list) // 2
print((m-u2) // u1 + 1)


import copy
n,m = map(int,input().split())
a = set(list(map(int,input().split())))
a = list(a)
a_div2 = [0]*len(a)
a2 = copy.deepcopy(a)

#     if a[i] % 2 == 1:
#         print(0)
#         exit()
for i in range(len(a)):
    while a2[i] % 2 == 0:
        a2[i] //= 2
        a_div2[i] += 1
if len(set(a_div2)) != 1:
    print(0)
    exit()


def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a,b):
    return a // gcd(a,b) * b


if len(a) == 1:
    if m < a[0]//2:
        print(0)
    else:
        print((m-a[0]//2)//a[0] + 1)
else:
    cnt = 1
    for i in range(len(a)):
        a[i] //= 2
        cnt = lcm(cnt,a[i])
    if m < cnt:
        print(0)
    else:
        print((m-cnt)//(cnt*2)+1)




Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
from fractions import gcd

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))

a=list(map(lambda x: x//2, a))

def lcm(q):
  x = q[0]
  for i in range(1, len(q)):
    x = (x * q[i]) // gcd(x, q[i])
  return x

lcma=lcm(a)
temp=m//lcma
print(temp//2 if temp%2==0 else temp//2+1)

from fractions import gcd
from functools import reduce

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

lcma=lcm(*a)
print((m + lcma//2)//lcma)

from fractions import gcd

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))

a=list(map(lambda x: x//2, a))

def lcm(q):
  x = q[0]
  for i in range(1, len(q)):
    x = (x * q[i]) // gcd(x, q[i])
  return x

lcma=lcm(a)

if (lcma//a[0])%2==0:
  print(0)
  
else:
  flg=0
  for i in range(1,n):
    if (lcma//a[i])%2==0:
      print(0)
      flg=1

  if flg==0:
    temp=m//lcma
    print(temp//2 if temp%2==0 else temp//2+1)

from math import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))
a=list(map(lambda x: x//2, a))

def lcm(q):
  x = q[0]
  for i in range(1, len(q)):
    x = (x * q[i]) // gcd(x, q[i])
  return x

lcma=lcm(a)
for i in range(len(a)):
  if (lcma//a[i])%2==0:
    print(0)
    exit()
temp=m//lcma
print(-(-temp//2))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 14:33:00 2020

@author: liang
"""
from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

flag = False
res = 1
for a in A:
    a /= 2
    res *= a//gcd(res,a)
    if res > M:
        flag = True
        break
    #print(res)


for a in A:
    if int(res/a) == res/a:
        flag = True
        
if flag:
    ans = 0
    print(ans)
else:
    
    
    ans= (M//res + 1)//2
    print(ans)

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 13:52:28 2020

@author: liang
"""

from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

res = A[0]
for i in range(1,N):
    res = res*A[i]//gcd(res,A[i])
    print(res)

if M < max(A)//2:
    ans = 0
else:
    ans = (M - max(A)//2)//res + 1
print(ans)

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 14:33:00 2020

@author: liang
"""
from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

flag = False
res = 1
for a in A:
    a //= 2
    res *= a//gcd(res,a)
    if res > M:
        
        break
    #print(res)


for a in A:
    if int(res/a) == res/a:
        flag = True
        
if flag:
    ans = 0
    print(ans)
else:
    
    
    ans= (M//res + 1)//2
    #print(ans)

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 14:33:00 2020

@author: liang
"""
from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

flag = False
res = 1
for a in A:
    a //= 2
    res *= a//gcd(res,a)
    if res > M:
        flag = True
        break
    #print(res)


for a in A:
    if int(res/a) == res/a:
        flag = True
        
if flag:
    ans = 0
    print(ans)
else:
    
    
    ans= (M//res + 1)//2
    print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

def lcm(x,y):
    return x*y//gcd(x,y)

n,m = map(int,input().split())
a = [int(i) for i in input().split()]
na = [i*0.5 for i in a]
l = 1
for i in range(n):
    l = lcm(l,na[i])

l2 = l*2
if l > m:
    ans = 0
else:
    ans = (m-l)//l2 + 1
        
print(ans)


def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

def lcm(x,y):
    return x*y//gcd(x,y)

n,m = map(int,input().split())
a = [int(i) for i in input().split()]
na = [i*0.5 for i in a]
l = 1
for i in range(n):
    l = lcm(l,na[i])

l2 = l*2
if l-1 > m:
    ans = 0
else:
    ans = (m-(l-1))//l2 + 1
        
print(ans)

def gcd(x,y):
    if y == 0: return x
    else: return gcd(y,x%y)

def lcm(x,y): return x*y//gcd(x,y)

def f(x):
    cnt = 0
    while(x%2==0):
        x //= 2
        cnt += 1
    return cnt

n,m = map(int,input().split())
a = [int(i) for i in input().split()]
na = [i//2 for i in a]

t = f(na[0])
for i in range(1,n):
    if t != f(na[i]):
        print(0)
        exit()

l = na[0]
for i in range(1,n): l = lcm(l,na[i])

if m < l:
    ans = 0
else:
    ans = 1 + (m-l)//(2*l)

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
from collections import deque,defaultdict
import math
import numpy as np
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)
n,m=map(int, input().split())
A=[int(i) for i in input().split()]
tmp = A[0]//2
res=0
for i in range(1,n):
    tmp = lcm(tmp,A[i]//2)
lis = set()

for i in A:
    r = i
    k=0
    while(r%2==0):
        k+=1
        r//=2
    lis.add(k)
if(len(lis)>1):
    print(0)
else:
    print(m//tmp)


from collections import deque,defaultdict
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)
n,m=map(int, input().split())
A=[int(i) for i in input().split()]
tmp = A[0]
for i in range(1,n):
    tmp = lcm(tmp,A[i])
ans = m//tmp
lis = set()
for i in A:
    r = i
    k=0
    while(r%2==0):
        k+=1
        r//=2
    lis.add(k)
if(m//(tmp)*tmp+tmp//2<=m):
    ans += 1
if(len(lis)!=1):
    ans=0

print(ans)



Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
N,M=map(int,input().split())
a=[int(x)//2 for x in input().split()]

def lcm(a,b):
  if a>b:
    a,b=b,a
  if a==1:
     return b
  n=a*b
  while a!=0:
    b,a=a,b%a
  return n//b

t=a[0]
for i in range(1,N):
  t=lcm(t,a[i])
  if t>M:
    print(0)
    break
else:
  print(0 if t%2 else M//t-M//(t*2))


N,M=map(int,input().split())
a=[int(x)//2 for x in input().split()]

def lcm(a,b):
  if a>b:
    a,b=b,a
  if a==1:
     return b
  n=a*b
  while a!=0:
    b,a=a,b%a
  return n//b

f1,f2=a[0],a[0]
for i in range(1,N):
  f1|=a[i]
  f2&=a[i]
c=0
while f1&1==0:
  f1//=2
  c+=1
if f2&2**c==0:
  print(0)
  exit()

t=a[0]
for i in range(1,N):
  t=lcm(t,a[i])
  if t>M:
    print(0)
    break
else:
  print(M//t-M//(t*2))


Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
#  --*-coding:utf-8-*--

def gcd(n, m):
    while m > 0:
        n, m = m, n%m

    return n

def f(M, A):
    lcm = 1

    for a in A:
        g = gcd(lcm, a)
        lcm = lcm*a//g

        if lcm > M:
            return 0

    for a in A:
        if lcm//a%2 == 0:
            return 0

    return (M-lcm)//(2*lcm) + 1
            


def main():
    N, M = map(int, input().split())
    A = list(map(lambda x:int(x)//2, input().split()))

    print(f(M,A))

    


#  --*-coding:utf-8-*--

def gcd(n, m):
    while m > 0:
        n, m = m, n%m

    return n

def f(M, A):
    lcm = 1

    for a in A:
        g = gcd(lcm, a)
        lcm = lcm*a//g

        if lcm > M:
            return 0

    for a in A:
        if lcm//a%2 == 0:
            return 0

    return (M-lcm)//(2*lcm) + 1
            


def main():
    N, M = map(int, input().split())
    A = list(map(lambda x:int(x)//2, input().split()))

    print(f(M,A))

    



if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

N,M = map(int,readline().split())
A = list(map(int,readline().split()))

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1
#print(dev_c)

for i in range(N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])

#print(l)

if ans != 0:
    ans = (M//l+1)//2

print(ans)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

N,M = map(int,readline().split())
A = list(map(int,readline().split()))

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1
#print(dev_c)

for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])

#print(l)

if ans != 0:
    ans = (M//l+1)//2

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
a = list(map(lambda a: int(a)//2, input().split()))
g = lcm(*a)
if any([2 * g // item % 2 == 0 for item in a]):
    print(0)
else:
    ans = M//g
    ans = max(math.ceil(ans/2),0)   
    print(ans)

import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
a = list(map(lambda a: int(a)//2, input().split()))
g = lcm(*a)
if any([g // item % 2 == 0 for item in a]):
    print(0)
else:
    ans = M//g
    ans = max(math.ceil(ans/2),0)   
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
n,m = map(int,input().split())

a = [0]*n
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 1 for c in x)):
        if any(c%2 == 1 for c in x):
            return 0
        x /= 2
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x/gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    
    res = (m//x+1)//2
    print(res)
else:
    print(0)
    
    
    


n,m = map(int,input().split())

a = [1]*n
#print(a)
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 0 for c in x)):
        x = [s//2 for s in x]
        if any(c%2 == 1 for c in x) and any(c%2 == 0 for c in x):
            return 0
        
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x//gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
    
    


Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import math
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    print(-1)
    exit()
    gcd = math.gcd(A[0], A[1])
    for i in range(2, N):
        gcd = math.gcd(gcd, A[i])

if N == 1:
    gcd = A[0]
lcm = gcd
for i in range(N):
    lcm *= A[i] // gcd

print((M - lcm) // lcm // 2 + 1)

import math
def LCM(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = LCM(A[0], A[1])
    for i in range(2, N):
        lcm = LCM(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)


Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=tuple(map(int,input().split()))
a.sort()
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
lcm = 1
for i in a:
    lcm = lcm * i // gcd(lcm,i)
for i in a:
    if (lcm//i)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)

Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
from math import ceil
from fractions import gcd


def prime_factor(n):
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            res.append(i)
            n //= i
    if n > 1:
        res.append(n)
    return res


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    twos_cnt = {prime_factor(num).count(2) for num in a}
    if len(twos_cnt) > 1:
        print(0)
        exit()

    num_two = twos_cnt.pop()
    a_div = [x >> num_two for x in a]

    a_div_lcm = a_div[0]
    for i in range(1, n):
        a_div_lcm = a_div_lcm * a_div[i] // gcd(a_div_lcm, a_div[i])
    print(ceil(m / a_div_lcm * 0.5 - 0.5))


from functools import reduce


def count_factors(a, factor):
    count = 0
    while a % factor == 0:
        count += 1
        a //= factor
    return count


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(set(map(lambda x: int(x) // 2, input().split())))
    num_of_two = count_factors(a[0], 2)
    for ai in a[1:]:
        if count_factors(ai, 2) != num_of_two:
            print(0)
            exit()

    a_lcm = reduce(lambda x, y: lcm(x, y), a)
    if a_lcm > m:
        print(0)
        exit()

    print((m // a_lcm + 1) // 2)


Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import numpy as np

def main():
    N,M=map(int,input().split())
    A=list(map(int,input().split()))
    A_double=list(map(lambda x:x//2,A))

    mini_multi=int(np.gcd.reduce(A_double))

    res=M//mini_multi

    if res%2!=0:
        res+=1


    print(res//2)





if __name__=="__main__":
    main()


import numpy as np
import sys

def main():
    N,M=map(int,input().split())
    A=list(map(int,input().split()))
    A_double=list(map(lambda x:x//2,A))

    mini_multi=int(np.lcm.reduce(A_double))

    res=M//mini_multi
    
    for i in A_double:
        if (mini_multi//i)%2==0:
            print(0)
            sys.exit()

    if res%2!=0:
        res+=1


    print(res//2)





if __name__=="__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import math
import sys
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
  
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

C = gcd_list(A)
B = [0 for _ in range(N)]

for i in range(N):
  B[i] = C // A[i]
  if B[i] % 2 == 0:
    print(0)
    sys.exit()

print( (M // C + 1) // 2)

import math
import sys
from functools import reduce

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

for i in range(N):
  A[i] = A[i] // 2
  
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
  
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

C = lcm_list(A)
B = [0 for _ in range(N)]

for i in range(N):
  B[i] = C // A[i]
  if B[i] % 2 == 0:
    print(0)
    sys.exit()

print( (M // C + 1) // 2)

Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
from fractions import gcd
from math import ceil
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = a[0] // 2
for i in a:
    ans *= (i // 2) // gcd(ans, i // 2)
print(ceil((m // ans) / 2))

from math import gcd, ceil
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]
l = 1
for i in a:
    l *= i // gcd(l, i)
for i in a:
    if l // i % 2 == 0:
        print(0)
        exit()
print(ceil((m // l) / 2))

Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur == 0
if n != 1:
    while A[0]%2 == 0:
        cur += 1
        A[0] = A[0]//2
        flag = True
    for i in range(1,n):
        temp = 0
        while A[i]%2 == 0:
            temp += 1
            A[i] = A[i]//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= 2*m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)


n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int(((2*m/A[0])-1)/2)+1)
    else:
        print(0)


Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
n,m = map(int,input().split())
a = list(map(int,input().split()))
half_a = [i//2 for i in a]
from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
q = half_a[0]
for i in range(n):
  q = lcm(q,half_a[i])
ans = (m//q) - (m//(2*q))
print(ans)

n,m = map(int,input().split())
a = list(map(int,input().split()))
half_a = [i//2 for i in a]
from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
q = 1
for i in range(n):
    q = lcm(q,a[i])
start = q//2
if start > m:
    print(0)
    exit()
print((m-start)//q+1)

n,m = map(int,input().split())
a = list(map(int,input().split()))
half_a = [i//2 for i in a]
from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
q = 1
for i in range(n):
  q = lcm(q,half_a[i])
ans = m//q - m//(2*q)

print(ans)

n,m = map(int,input().split())
a = list(map(int,input().split()))
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a, b):
  return a * b // gcd(a, b)
q = a[0]//2
for i in range(n):
  a = a[i]//2
  q = lcm(q,a)
cnt = 0
while True:
  for i in range(n):
    if a[i] % 2 == 0:
      cnt += 1
    else:
      a[i]//1
    if cnt:
      break
ans = (m//q) - (m//(2*q))
if cnt == n:
  print(ans)
else:
  print(0)

n,m = map(int,input().split())
a = list(map(int,input().split()))
from fractions import gcd
def lcm(x,y):
  return x*y // gcd(x, y)
q = a[0]//2
for i in range(n):
  a[i] = a[i]//2
  q = lcm(q,a[i])

cnt = 0
flag = 1
while flag:
  for i in range(n):
    if a[i] % 2 == 1:
      cnt += 1
    else:
      a[i]//1
    if cnt != 0:
      flag = 0
ans = (m//q) - (m//(2*q))
if cnt == n:
  print(ans)
else:
  print(0)

from math import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
def cnt(x):
    i = 0
    while x%2 == 0:
        x = x//2
        i += 1
    return i 
n,m = map(int,input().split())
a = list(map(int,input().split()))
memo = cnt(a[0])
for i in range(n):
    if cnt(a[i]) != memo:
        print(0)
        quit()
    a[i] = a[i]//2

t = 1
for i in range(n):
    t = lcm(t,a[i])
print(m//t-m//(2*t))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Time Limit Exceeded

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
def lcm(a, b):
  return a // gcd(a, b) * b

def gcd(a, b):
  if(b == 0): return a
  else: return gcd(b, a % b)

def cnt(a):
  res = 0
  while(a and a % 2 == 0):
    a //= 2
    res += 1
  return res

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = 1
c = cnt(A[0])
for a in A:
  if cnt(a) != c or c == 1:
    print(0)
    exit()
  else:
    l = lcm(l, a)
d = m // l
print((d + 1) // 2)

def lcm(a, b):
  return a // gcd(a, b) * b

def gcd(a, b):
  if(b == 0): return a
  else: return gcd(b, a % b)

def cnt(a):
  res = 0
  while(a and a % 2 == 0):
    a //= 2
    res += 1
  return res

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = 1
c = cnt(A[0])
print(c)
for a in A:
  if cnt(a) != c or c == 0:
    print(0)
    exit()
  else:
    l = lcm(l, a // 2)
print(l)
d = m // l
print((d + 1) // 2)

def lcm(a, b):
  return a // gcd(a, b) * b

def gcd(a, b):
  if(b == 0): return a
  else: return gcd(b, a % b)

def cnt(a):
  res = 0
  while(a and a % 2 == 0):
    a //= 2
    res += 1
  return res

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = 1
c = cnt(A[0])
for a in A:
  if cnt(a) != c or c == 0:
    print(0)
    exit()
  else:
    l = lcm(l, a // 2)
d = m // l
print((d + 1) // 2)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
  if a%2==0:
    a//=2
    cur+=1
  else:
    a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

import sys
input=lambda: sys.stdin.readline().rstrip()

n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]
ct=0
s=A[0]
while s:
  if s%2==0:
    s//=2
    ct+=1
  else:
    s=0
chk=True
for i in range(1,n):
  cur=0
  a=A[i]
  while a:
    if a%2==0:
      a//=2
      cur+=1
    else:
      a=0
  if cur!=ct:
    chk=False
    break


def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
if not chk:
  print(0)
else:
  lcm=A[0]
  for i in range(1,n):
    lcm*=A[i]//gcd(lcm,A[i])
  print((m//lcm+1)//2)

Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**5)
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N, M = map(int, input().split())
X_2 = lcm_list(list(map(int, input().split())))
X = X_2//2
print(M//X-M//X_2)

import sys
sys.setrecursionlimit(10**5)
def GCM(a, b):
  a, b = max(a,b), min(a, b)
  r = a % b
  if r == 0:
    return b
  else:
    return GCM(b, r)

def LCD(a, b):
  g = GCM(a, b)
  return (a//g)*b

N, M = map(int, input().split())
A = list(map(int, input().split()))
X = A[0]//2
for a in A[1:]:
  b = a//2
  newX = LCD(X, a//2)
  if (newX // b)%2 == 0:
    print(0)
    sys.exit(0)
  else:
    X = newX
X_2 = X*2
print(M//X-M//X_2)

Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = 0
for i in A:
  if i % 2 == 0:
    i //= 2
  else:
    p = 1
    break
L = A[0]
k = 0
while A[0] % 2 == 0:
  k += 1
  A[0] //= 2
for i in range(1, N):
  a, b = L, A[i]
  while b != 0:
    a, b = b, a % b
  b = A[i] // a
  L *= b
  cnt = 0
  while A[i] % 2 == 0:
    cnt += 1
    A[i] //= 2
  if cnt != k:
    p = 1
    break
if p == 1:
  S = 0
else:
  S = M // L - M // (2 * L)
print(S)

N, M = map(int, input().split())
A = list(map(int, input().split()))
p = 0
for i in range(N):
  if A[i] % 2 == 0:
    A[i] //= 2
  else:
    p = 1
    break
L = A[0]
k = 0
while A[0] % 2 == 0:
  k += 1
  A[0] //= 2
for i in range(1, N):
  a, b = L, A[i]
  while b != 0:
    a, b = b, a % b
  b = A[i] // a
  L *= b
  cnt = 0
  while A[i] % 2 == 0:
    cnt += 1
    A[i] //= 2
  if cnt != k:
    p = 1
    break
if p == 1:
  S = 0
else:
  S = M // L - M // (2 * L)
print(S)

Verdicts: Wrong Answer

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):


#include<cmath>
#include<algorithm>
using namespace std;

int gcd(int x,int y){
  if(x<y) swap(x,y);
  //xの方が常に大きい
  while(y>0){
    int r=x%y;
    x=y;
    y=r;
  }
  return x;
}

int lcm(int x,int y){
  return int(x*y/gcd(x,y));
}

//n個の場合のlcmも2個で比べて順に適用していくだけ
int main(){
  int n,m;cin >> n >> m;
  vector<int> a(n);for(int i=0;i<n;i++){cin >> a[i];a[i]/=2;}
  int ans=lcm(a[0],a[1]);
  for(int i=1;i<n;i++){ans=lcm(ans,a[i]);}
  //cout << ans << endl;
  cout << int((floor(m/ans)+1)/2) << endl;
}


from math import gcd
def lcm(a,b):
    return a//gcd(a,b)*b
def lcm(ab):
    l=len(ab)
    ret=ab[0]
    for i in range(1,l):
        ret=ret//gcd(ab[i],ret)*ab[i]
    return ret
def count2(a):
    ret=0
    while a%2==0:
        a//=2
        ret+=1
    return 2**ret
n,m=map(int,input().split())
A=list(map(int,input().split()))

if any(i%2 for i in A):
    exit(print(0))
A=[i//2 for i in A]

p=lcm(A)
c=count2(p)

if any(i%c for i in A):
    exit(print(0))
x=m//p
#print(p//c)
print(-(-x//2))

Verdicts: Runtime Error

Accepted
Problem: Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.  Let a _semi-common multiple_ of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):    * There exists a non-negative integer p such that X= a_k \times (p+0.5).  Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Submission attempts (in order):
import functools
import fractions
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
N,M=map(int,input().split())
A=list(map(int,input().split()))
LCM=functools.reduce(lcm,A)
HLCM=LCM//2
Y=M//HLCM
if Y%2==0:
    print(Y//2)
else:
    print((Y+1)//2)


def gcd(a, b):
    a_, b_ = a, b
    while a_:
        a_, b_ = b_ % a_, a_
    return b_


def lcm(a, b):
    return a*b//gcd(a, b)


def count(x):
    x_ = x
    cnt = 0
    while x_ % 2 == 0:
        x_ = x_//2
        cnt += 1
    return cnt


N, M = map(int, input().split())
*A, = map(int, input().split())
if len(set([count(a) for a in A])) > 1:
    print(0)
else:
    A = [a//2 for a in A]
    while len(A) > 1:
        a = A.pop()
        b = A.pop()
        A.append(lcm(a, b))
    t = A.pop()
    q = M//t
    if q % 2 == 0:
        print(q//2)
    else:
        print((q+1)//2)


Verdicts: Wrong Answer

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
from math import factorial

def comb(a,d):
    return factorial(a)//factorial(b)//factorial(a-b)

mod = 10**9+7

N = int(input())
C_input = list(map(int, input().split()))

C = sorted(C_input)
ans = 0
for ind, s in enumerate(C):
    ans+= C[ind]* 2**(N-2) * (N+1-ind)
    ans %= mod
print(ans*2**N %mod)

import sys
input = sys.stdin.readline
from math import factorial

def comb(a,d):
    return factorial(a)//factorial(b)//factorial(a-b)

mod = 10**9+7

N = int(input())
C_input = list(map(int, input().split()))

C = sorted(C_input)
ans = 0
for ind, s in enumerate(C):
    ans+= C[ind] * (N+1-ind)
    ans %= mod
print(int(ans* 2**(2*N-2)) %mod)

Verdicts: Wrong Answer

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
md = 10**9+7
N=int(input())
C=list(map(int, input().split()))
C.sort()
ans = 0
for i in range(N):
  ans +=C[i]*(2**N-2*i)%md
ans = (ans * (2**N)) %md
print(ans)

md = 10**9+7
N = int(input())
NN0 = (2**N)%md
NN1 = (2**(N-1))%md
NN2 = (2**(N-2))%md
C = list(map(int, input().split()))
C.sort()
ans = 0
for i in range(N):
    ans += ((C[i]%md) * NN1 )%md
    if i != (N-1):
        ans += ( (C[i]%md)*(N-1-i) * NN2 )%md
ans = (ans * NN0) %md
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
# coding: utf-8

import itertools

N = int(input())
C = [int(x) for x in input().split()]


C.sort()


sum = 0
for i in range(N):
	sum += (N + 1 - i) * C[i]
sum *= 2 ** (N - 2)
sum *= 2 ** N


print(sum % (10 ** 9 + 7))

# coding: utf-8

import itertools
import sys

N = int(input())
C = [int(x) for x in input().split()]


C.sort()


sum = 0
for i in range(N):
	sum += (N + 1 - i) * C[i]
sum *= 2 ** (N - 2)
sum *= 2 ** N


print(int(sum % (10 ** 9 + 7)))

Verdicts: Wrong Answer

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
print(arr)
ans=0
for i in range(n):
  ans+=pow(2,2*n-1,mod)*(1+(n-i-1)/2)*arr[i]
  ans%=mod
print(int(ans))

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
print(arr)
ans=0
table=[1]
for _ in range(n):
  tmp=table[-1]*2
  tmp%=mod
  table.append(tmp)
for i in range(n):
  if i==n-1:    
    ans+=(table[i-1]*(n-i+1)*arr[i])%mod
  else:
    ans+=(table[i]*(n-i+1)*table[n-i-2]*arr[i])%mod
print((ans*table[n])%mod)

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
table=[1]
for _ in range(n):
  tmp=table[-1]*2
  tmp%=mod
  table.append(tmp)
for i in range(n):
  if i==n-1:    
    ans+=(table[i-1]*(n-i+1)*arr[i])%mod
  else:
    ans+=(table[i]*(n-i+1)*table[n-i-2]*arr[i])%mod
print((ans*table[n])%mod)

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
total=pow(2,2*n-2,mod)
for i in range(n):
  ans+=total*(n-i+1)*arr[i]
  ans%=mod
print(int(ans))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(N):
        for _ in range(30):
            if B[i]%2 == 0:
                B[i] //= 2
                C[i] += 1
            else:
                break
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(t,A[i]//2)
    if t > M:
        print(0)
        return

    print((M-t)//t + 1)

if __name__ == '__main__':
    main()



def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(N):
        for _ in range(30):
            if B[i]%2 == 0:
                B[i] //= 2
                C[i] += 1
            else:
                break
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(t,A[i]//2)
    if t > M:
        print(0)
        return

    print((M-t)//t + 1)

if __name__ == '__main__':
    main()



def main():
    N = int( input())
    Q = 10**9+7
    C = list( map( int, input().split()))
    C.sort()
    ans = 1
    if N == 1:
        print(C[0]*2%Q)
        return
    for i in range(N-1):
        ans += pow(2,i,Q)*(((N-1)-i)*pow(2,N-2-i,Q) + pow(2, N-1-i, Q))*C[i]%Q
        ans %= Q
    ans += pow(2, N-1, Q)*C[N-1]%Q
    ans -= 1
    print(ans*pow(2,N,Q)%Q)
if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:    * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.      * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i, where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.  There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1. Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7).

Submission attempts (in order):
n=int(input())
mod=10**9+7
c=list(map(int,input().split()))
c.sort()
ans=0
for i in range(n):
    ans+=c[i]*(n-i)
    ans%=mod
print(ans*pow(4,n-1,mod)%mod)

n=int(input())
mod=10**9+7
c=list(map(int,input().split()))
c.sort()
ans=0
for i in range(n):
    ans+=c[i]*(1+i)
    ans%=mod
print(ans*pow(4,n-1,mod)%mod)


n=int(input())
mod=10**9+7
c=list(map(int,input().split()))
c.sort()
ans=0
for i in range(n):
    ans+=c[i]*(n-i+2)
    ans%=mod
print(ans*pow(4,n-1,mod)%mod)


n=int(input())
mod=10**9+7
c=list(map(int,input().split()))
c.sort()
ans=0
for i in range(n):
    ans+=c[i]*(n-i+1)
    ans%=mod
print((ans*pow(4,n-1,mod))%mod)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted