TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n = int(input())
a_list = [int(i) for i in input().split()]
divide = 10 ** 9 + 7

inf=float("inf")
dp=[[inf for i in range(n+1)] for j in range(n+1)]

sum = 0
for i in range(n):
    for j in range(i+1, n):
        if dp[i][j] != inf or dp[j][i] != inf:
            sum += dp[i][j]
            print('yes')
        else:
            val =  a_list[i] ^ a_list[j]
            dp[i][j] = val
            dp[j][i] = val
            sum += val

print(sum % divide)
print(dp)


n = int(input())
divide = 10 ** 9 + 7

a = [format(i, '060b') for i in map(int, input().split())]
ans = []

for i in range(60):
    bit_list = [b[59-i] for b in a]
    val = bit_list.count('0') * bit_list.count('1')
    ans.append((val * 2 ** i))

print(sum(ans)%divide)

Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7

ans = 0
for i in range(60):
    X = sum([1 for x in A if (x >> 1) & 1])
    ans += (1 << i) * X * (N - X)
    ans %= mod

print(ans)


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

mod = 10**9 + 7

ans = 0
for i in range(60):
    X = sum([1 for x in A if (x >> i) & 1])
    ans += (1 << i) * X * (N - X)
    ans %= mod

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
imoprt numpy as np 
n = int(input())
A = list(map(int,input().split()))
a=np.array(A)
mod = 10**9+7
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 =np.count_nonzero(a)        
    ans += cnt1 * (n-cnt1) * (1<<d)         
    ans %= mod                              
    
print(ans%mod)

n = int(input())
a = list(map(int,input().split()))
import numpy as np
a=np.array(a)
mod = 10**9+7
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)          
    ans %= mod                               
    
print(ans%mod)

Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)

import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)

Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
import numpy as np
N = int(input())
A = np.fromstring(input(), dtype=np.int64, sep=' ')
print(A)
res = 0
for bit in range(60):
    c = int((A & 1).sum())
    res += c * (N - c) * (1 << bit)
    A >>= 1

print(res % 1000000007)

import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
#rng = int(math.log2(np.max(A)))+1
sum = 0
d = 10**9+7
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)%d
    A = A>>1

print(sum %(d))

Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
import numpy as np
import copy
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = sum(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A >> 1
print(tmp % mod)

import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.count_nonzero
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.count_nonzero(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
#ABC147_D


import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)
    c0=n-c1
    ans+=2**i*c1*c0
    arr>>=1
print(s%mod)

#ABC147_D


import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)
    c0=n-c1
    ans+=2**i*c1*c0
    arr>>=1
print(s%mod)

#ABC147_D


import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)
    c0=N-c1
    ans+=2**i*c1*c0
    arr>>=1
print(ans%mod)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
import numpy as np

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

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    a >>= 1
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod

print(ans)

import numpy as np

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

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod
    a = a >> 1

print(ans)


import numpy as np

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

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    A >>= 1
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n = int(input())

ass = list(map(int,input().split()))

m = len(bin(max(a))) - 2

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)


n = int(input())

ass = list(map(int,input().split()))

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
def solve():
    import numpy as np
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=a[i]^a[j]
    
    print(ans%(10**9+7))
    
n=int(input())
a=np.array(list(map(int,input().split())) )
solve()

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)


Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[:1:-1]
  for v in range(len(f)):
    ll[-1-v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)


n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[:1:-1]
  for v in range(len(f)):
    ll[v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=(2**i)*a*s%mod
  ans%=mod
print(ans)

n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[2:]
  for v in range(len(f)):
    ll[v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)


n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[2:]
  for v in range(len(f)):
    ll[-1-v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)


n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[2:]
  for v in range(len(f)):
    ll[v][int(f[-1-v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)


import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
    s=int((a&1).sum())
    ans=(ans+s*(n-s)*b)%mod
    a>>=1
    b=b*2%mod
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

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

ans=0

for i in range(60):
    cnt=len([i for i in range(n) if A[i]&1])
    ans +=2**i*cnt*(n-cnt)
    A=[A[i]>>1 for i in range(n)]

print(ans%10**9+7)

import numpy as np

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

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%10**9+7)

import numpy as np
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
A=np.array(A)

ans=0
for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%mod)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

ans = 0
m = 1
for _ in range(60):
    bits = sum((a & m for a in A))
    print(bits)
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)


MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

ans = 0
m = 1
for i in range(60):
    bits = sum((a & m for a in A))
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)


Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
import numpy as np
 
mod = 10**9 + 7
N = input()
A = np.array(list(map(int, input().split())), dtype='uint64') % mod
A = np.atleast_2d(A)

print((np.sum((A ^ A.T) % mod) % mod) // 2)

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
max_digit = 60


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i]
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)

import numpy as np
 
mod = 10**9 + 7
max_digit = 60
N = int(input())
A = np.array(list(map(int, input().split())))

result = 0
base = 1
for _ in range(max_digit + 1):
  a = A % 2
  c = np.count_nonzero(a == 0)
  result = (result + (base*(N - c)*c) % mod) % mod
  A = A >> 1
  base = base*2 % mod

print(result)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n=int(input())
a=list(map(int,input()))
DIV=10**9+7
ans=0
if n%2==0:
  ans=a[0]
  for i in range(1,len(a)):
    ans+=ans^a[i]
    ans%=DIV
else:
  ans=a[0]^a[0]
  for i in range(1,len(a)):
    ans+=ans^(a[i]^a[i])
    ans%=DIV
print(ans)
              

import sys
readline = sys.stdin.readline
import numpy as np

N = int(readline())
A = np.array(readline().split(),dtype=int)
DIV = 10 ** 9 + 7



K = max(A)
  
j = 0
ans = 0
while K:
  bits = (A >> j) & 1
  one = np.count_nonzero(bits)
  ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
  ans %= DIV
  j += 1
  K >>= 1

print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

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

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

xor_sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    xor_sum += (A[i]^A[j])

dst = xor_sum % (10**9+7)
print(dst)

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


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

sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    sum += (A[i]^A[j])

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


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


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

xor_sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    xor_sum += (A[i]^A[j])

dst = xor_sum % (10**9+7)
print(dst)
    
    


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


N = input()
A = [input().split() for i in range(N)]

sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    sum += (A[i]^A[j])

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

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


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

sum = 0
for i in range((N-1)-1):
  for j in range(i+1, (N-1)):
    sum += (A[i]^A[j])

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


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


N = input()
A = input().split()

sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    sum += (A[i]^A[j])

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


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

ans = 0

for i in range(N-1):
  for j in range(i+1, N):
    ans += (A[i]^A[j])
    
print(ans%(10**9+7))

import numpy as np

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

mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c = np.count_nonzero(A & 1) 
    s += 2 ** i * c * (N - c) # https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d
    A >>= 1 
print(s % mod)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A & 1)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
        print(ans)

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A | 0)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
        print(ans)

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A | 0)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
    print(ans)

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A & 1)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
while A != []:
  m = 0
  n = len(A)
  k = []
  for i in range(n):
    if A[i] % 2 == 1:
      m += 1
    A[i] //= 2
    if A[i] == 0:
      k.append(i)
  for g in range(len(k)):
    A.remove(k[len(k)-1-g])
  S += (m * (N - m)) * (2 ** j)
  S %= mod
  j += 1
print(S)

mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)


Verdicts: Runtime Error

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
from sys import setrecursionlimit
n = "0"+input()
N = len(n)
point = 0
for i in range(1,N):
    one_push = 1+point+10-int(n[i])
    no_push = point + int(n[i])
    point = min(one_push,no_push)
print(point)

import numpy as np

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
point = 0
mod = 10**9+7

b = [((a>>i)&1).sum() for i in range(61)]
c = [n-b[i] for i in range(61)]
d = [c[i]*b[i]%mod for i in range(61)]

point = 0
now = 1

for i in range(61):
    point += now*d[i]
    point %= mod
    now *= 2
    now %= mod

print(point)

Verdicts: Wrong Answer

Accepted
Problem: We have N integers. The i-th integer is A_i.  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).  What is \mbox{ XOR }?  The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:    * When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Submission attempts (in order):
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [list(format(a, '060b')) for a in A]
s = 0
for i in range(60):
    Ai = [int(a[i]) for a in A]
    print(Ai)
    c0 = Ai.count(0)
    c1 = Ai.count(1)
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)


n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [format(a, '060b') for a in A]
s = 0
for i in range(60):
    Ai = [a[i] for a in A]
    c0 = Ai.count('0')
    c1 = n-c0
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)


Verdicts: Wrong Answer

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
h,w=map(int,input().split())
dp=[[[0] for i in range(w+1)] for j in range(h+1)]

A=[list(map(int,input().split())) for j in range(w)]
B=[list(map(int,input().split())) for j in range(w)]
C=[[abs(A[i][j]-B[i][j]) for j in range(h)] for i in range(w)]    

for i in range(h):
    for j in range(w):
        now=C[i+1][j+1]
        dp[i+1][j+1]=min(abs(dp[i][j+1]-now),abs(dp[i+1][j]-now))

print(dp[h][w])

h,w=map(int,input().split())
dp=[[0 for i in range(w+1)] for j in range(h+1)]

A=[list(map(int,input().split())) for j in range(w)]
B=[list(map(int,input().split())) for j in range(w)]
C=[[abs(A[i][j]-B[i][j]) for j in range(h)] for i in range(w)]    

for i in range(h):
    for j in range(w):
        now=C[i][j]
        dp[i+1][j+1]=min(abs(dp[i][j+1]-now),abs(dp[i+1][j]-now))

print(dp[h][w])

import sys 
def input():return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
H,W=map(int,input().split())
A=[[int(x) for x in input().split()] for _ in range(H)]
B=[[int(x) for x in input().split()] for _ in range(H)]
C=[[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        C[i][j]=abs(A[i][j]-B[i][j])
center=80 * (H + W)
dp=[[0]*W for _ in range(H)]
dp[0][0]=(1<<(center - C[0][0]))|(1<<(center+C[0][0]))
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j]|=dp[i-1][j]<<C[i][j]
            dp[i][j]|=dp[i-1][j]>>C[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<C[i][j]
            dp[i][j]|=dp[i][j-1]>>C[i][j]            
ans=center*2
for i in range(center*2):
    if (dp[H-1][W-1]>>i)&1:
        ans=min(ans,abs(i-center))
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]

pos = 160*80
dp=[[0]*w for i in range(h)]
sub=abs(a[0][0]-b[0][0])
dp[0][0]=1<<pos

for c in range(h):
    for l in range(w):
        sub=abs(a[c][l]-b[c][l])
        if l!=0:
            dp[c][l]|=dp[c][l-1]<<sub
            dp[c][l]|=dp[c][l-1]>>sub
        if c!=0:
            dp[c][l]|=dp[c-1][l]<<sub
            dp[c][l]|=dp[c-1][l]>>sub
bit=dp[-1][-1]
for i in range(pos):
    if (bit&1<<(pos+i))or(bit&1<<(pos-i)):
        print(i)
        break

h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]

pos = 160*80
dp=[[0]*w for i in range(h)]
sub=abs(a[0][0]-b[0][0])
dp[0][0]=1<<(pos-sub)|1<<(pos+sub)

for c in range(h):
    for l in range(w):
        sub=abs(a[c][l]-b[c][l])
        if l!=0 and c!=0:
            dp[c][l]|=dp[c][l-1]<<sub|dp[c][l-1]>>sub|dp[c-1][l]<<sub|dp[c-1][l]>>sub
        elif c!=0:
            dp[c][l]|=dp[c-1][l]<<sub|dp[c-1][l]>>sub
        elif l!=0:
            dp[c][l]|=dp[c][l-1]<<sub|dp[c][l-1]>>sub
bit=dp[-1][-1]
for i in range(pos):
    if (bit&1<<(pos+i))or(bit&1<<(pos-i)):
        print(i)
        break

Verdicts: Wrong Answer

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
H, W = map(int, input().split())
M = (H + W) * 80

A = [tuple(map(int, input().split())) for _ in range(H)]
B = [tuple(map(int, input().split())) for _ in range(H)]

dp = [[0] * W for _ in range(H)]
dp[0][0] |= (1 << (M - abs(A[0][0] - B[0][0])))

for h in range(H):
    for w, (a, b) in enumerate(zip(A[h], B[h])):
        d = abs(a - b)
        if d == 0:
            continue
        mask = 0
        if h > 0:
            mask |= (dp[h - 1][w] << d)
            mask |= (dp[h - 1][w] >> d)
        if w > 0:
            mask |= (dp[h][w - 1] << d)
            mask |= (dp[h][w - 1] >> d)
        dp[h][w] = mask

state = dp[-1][-1]
nums = []
for digit, b in enumerate(bin(state)[2:][:: -1]):
    if b == '1':
        nums.append(M - digit)
ans = min(abs(n) for n in nums)
print(ans)


import sys
from collections import defaultdict
input = sys.stdin.readline

H, W = map(int, input().split())
M = (H + W) * 100

A = [tuple(map(int, input().split())) for _ in range(H)]
B = [tuple(map(int, input().split())) for _ in range(H)]

dp = [[0] * W for _ in range(H)]
dp[0][0] |= (1 << (M - abs(A[0][0] - B[0][0])))

for h in range(H):
    for w, (a, b) in enumerate(zip(A[h], B[h])):
        d = abs(a - b)
        if d == 0:
            continue
        mask = 0
        if h > 0:
            mask |= (dp[h - 1][w] << d)
            mask |= (dp[h - 1][w] >> d)
        if w > 0:
            mask |= (dp[h][w - 1] << d)
            mask |= (dp[h][w - 1] >> d)
        dp[h][w] = mask

state = dp[-1][-1]
nums = []
for digit, b in enumerate(bin(state)[2:][:: -1]):
    if b == '1':
        nums.append(M - digit)
ans = min(abs(n) for n in nums)
print(ans)


H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

Z = (H + W) * 80 + 10

dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][0] = (1 << Z)

for h in range(H):
    for w in range(W):
        d = dp[h][w]
        k = abs(A[h][w] - B[h][w])

        dp[h + 1][w] |= (d << k) | (d >> k)
        dp[h][w + 1] |= (d << k) | (d >> k)

ans = 10**18
for a in (dp[H][W - 1], dp[H - 1][W]):
    for d in range(Z * 2 + 10):
        if a & (1 << d) != 0:
            ans = min(ans, abs(d - Z))
print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
import numpy as np
H,W = map(int,input().split())
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(W)]
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    A[i][j] = inf[j]
    
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    B[i][j] = inf[j]

X = (H + W) * 80
L = X + X + 1

dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = np.zeros(L,np.bool)
dp[0][0][X+d] = 1
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = np.zeros(L,np.bool)
        if h != 0:
            x[d:] |= dp[h-1][w][:L-d]
            x[:L-d] |= dp[h-1][w][d:]
        if w != 0:
            x[d:] |= dp[h][w-1][:L-d]
            x[:L-d] |= dp[h][w-1][d:]
        dp[h][w] = x

dp2 = dp[-1][-1]
can_make = np.where(dp2)[0] - X

answer = np.abs(can_make).min()
print(answer)

import numpy as np
H,W,*L = map(int, open(0).read().split())
A = L[:H*W]
B = L[H*W:]
C = [abs(b-a) for a,b in zip(A,B)]
U = max(C)*(H+W)
N = 2*U+1
INF = 10**10
dp = np.zeros((H,W,N),dtype=bool)
dp[0,0,C[0]+U] = True
for i in range(1,W):
  c = C[i]
  dp[0,i,c:] |= dp[0,i-1,:N-c]
  dp[0,i,:N-c] |= dp[0,i-1,c:]
for i in range(1,H):
  c = C[i*W]
  dp[i,0,c:] |= dp[i-1,0,:N-c]
  dp[i,0,:N-c] |= dp[i-1,0,c:]
for i in range(1,H):
  for j in range(1,W):
    c = C[i*W+j]
    dp[i,j,c:] |= dp[i,j-1,:N-c]
    dp[i,j,:N-c] |= dp[i,j-1,c:]
    dp[i,j,c:] |= dp[i-1,j,:N-c]
    dp[i,j,:N-c] |= dp[i-1,j,c:]
ans = np.min(np.abs(np.where(dp[H-1][W-1])[0]-U))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
h,w = map(int, input().split( ))
a = []
for i in range(h):
    ai = list(map(int, input().split( )))
    a.append(ai)
for i in range(h):
    bi = list(map(int, input().split( )))
    for j in range(w):
        a[i][j]-=bi[j]
        a[i][j] = abs(a[i][j])


dp = [[0 for j in range(w)] for i in range(h)]
a2 = [a[i][j] for i in range(h) for j in range(w)]
mxa = max(a2)

tmp=1<<mxa*(h+w)

dp[0][0]|=tmp<<a[0][0]
dp[0][0]|=tmp>>a[0][0]

for j in range(1,w):
    dp[0][j]=dp[0][j-1]<<a[0][j]
    dp[0][j]|=dp[0][j-1]>>a[0][j]

for i in range(1,h):
    dp[i][j]=dp[i-1][j]<<a[i][j]
    dp[i][j]|=dp[i-1][j]>>a[i][j]
    if j:
        dp[i][j]|=dp[i][j-1]<<a[i][j]
        dp[i][j]|=dp[i][j-1]>>a[i][j]

tmp1 = dp[h-1][w-1]

tmp1>>=max(a2)*h*w
for k in range(mxa*(h+w)):
    if tmp1&1:
        print(k)
        exit()
    tmp1>>=1



h,w = map(int, input().split( ))
a = []
for i in range(h):
    ai = list(map(int, input().split( )))
    a.append(ai)
for i in range(h):
    bi = list(map(int, input().split( )))
    for j in range(w):
        a[i][j]-=bi[j]
        a[i][j] = abs(a[i][j])


dp = [[0 for j in range(w)] for i in range(h)]
a2 = [a[i][j] for i in range(h) for j in range(w)]
mxa = max(a2)


tmp=1<<mxa*(h+w)+10

dp[0][0]|=tmp<<a[0][0]
dp[0][0]|=tmp>>a[0][0]

for j in range(1,w):
    dp[0][j]=dp[0][j-1]<<a[0][j]
    dp[0][j]|=dp[0][j-1]>>a[0][j]

for i in range(1,h):
    for j in range(w):
        dp[i][j]=dp[i-1][j]<<a[i][j]
        dp[i][j]|=dp[i-1][j]>>a[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<a[i][j]
            dp[i][j]|=dp[i][j-1]>>a[i][j]

tmp1 = dp[h-1][w-1]

tmp1>>=mxa*(h+w)+10


for k in range(mxa*(h+w)+10):
    if tmp1&1:
        print(k)
        exit()
    tmp1>>=1


Verdicts: Wrong Answer

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A += map(int, input().split())  
    B = []
    for _ in range(H):
        B += map(int, input().split())  

    dp = [0] * (H * W)  ,dp[pos]:=bit,[-80*H*W,80*H*W]->[0,2*80*H*W]
    d = abs(A[0] - B[0])
    dp[0] |= 1 << (80 * H * W + d)
    dp[0] |= 1 << (80 * H * W - d)

    for r in range(H):
        for c in range(W):
            p = r * W + c
            d = abs(A[p] - B[p])
            if r > 0:
                dp[p] |= (dp[p - W] << d)
                dp[p] |= (dp[p - W] >> d)
            if c > 0:
                dp[p] |= (dp[p - 1] << d)
                dp[p] |= (dp[p - 1] >> d)

    ans = 2 * 80 * H * W + 1
    for j in range(2 * 80 * H * W + 1):
        if (dp[H * W - 1] >> j) & 1:
            t = j - 80 * H * W
            if ans > abs(t):
                ans = abs(t)
    print(ans)


if __name__ == '__main__':
    main()


def main():
    import numpy as np

    H, W = map(int, input().split())
    A = np.array([[int(x) for x in input().split()] for _ in range(H)])
    B = np.array([[int(x) for x in input().split()] for _ in range(H)])
    D = np.abs(A - B)

    MAX_BIAS_PER_CELL = 80
    UPPER_BOUND_TOTAL_BIAS = MAX_BIAS_PER_CELL * (H + W - 1) + 1

    dp = np.zeros(shape=(H, W, UPPER_BOUND_TOTAL_BIAS * 2 + 1), dtype=np.bool_)
    d = D[0][0]
    dp[0, 0, UPPER_BOUND_TOTAL_BIAS - d] = 1
    dp[0, 0, UPPER_BOUND_TOTAL_BIAS + d] = 1

    for r in range(H):
        for c in range(W):
            d = D[r][c]
            if r > 0:
                dp[r, c, d:] |= dp[r - 1, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d]
                dp[r, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d] |= dp[r - 1, c, d:]
            if c > 0:
                dp[r, c, d:] |= dp[r, c - 1, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d]
                dp[r, c, :UPPER_BOUND_TOTAL_BIAS * 2 + 1 - d] |= dp[r, c - 1, d:]

    t = dp[H - 1, W - 1, :]
    indices = np.where(t == 1)[0]  
    ret = np.abs(indices - UPPER_BOUND_TOTAL_BIAS)
    print(np.min(ret))


if __name__ == '__main__':
    main()


Verdicts: Time Limit Exceeded

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
c=[[abs(a[i][j]-b[i][j])for j in range(w)]for i in range(h)]
d=[[set()for i in range(w+1)]for j in range(h+1)]
d[1][1]=set([-c[0][0],c[0][0]])
for x in range(1,w+1):
    for y in range(1,h+1):
        if not (i==1 and j==1):
            a=d[x-1][y]|d[x][y-1]
            for i in a:
                d[x][y].add(i-c[x-1][y-1])
                if i+c[x-1][y-1]<=80*(h+w-x-y+1)
                    d[x][y].add(i+c[x-1][y-1])
print(abs(min(d[h][w],key=abs)))

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
c=[[abs(a[i][j]-b[i][j])for j in range(w)]for i in range(h)]
d=[[set()for i in range(w+1)]for j in range(h+1)]
d[1][1]=set([c[0][0]])
for x in range(1,h+1):
    for y in range(1,w+1):
        if not (x==1 and y==1):
            a=d[x-1][y]|d[x][y-1]
            for i in a:
                d[x][y].add(abs(i-c[x-1][y-1]))
print(min(d[h][w]))

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
s=[0]*w
s[0]=p=1<<6400
for i in range(h):
    for j in range(w):
        d=abs(a[i][j]-b[i][j])
        if j>0:
            s[j]|=s[j-1]
        s[j]=(s[j]<<d)|(s[j]>>d)
t=s[-1]
for i in range(6401):
    if t&(p<<i) or t&(p>>i):
        print(i)
        break

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.  The square (i, j) has two numbers A_{ij} and B_{ij} written on it.  First, for each square, Takahashi paints one of the written numbers red and the other blue.  Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.  Let the _unbalancedness_ be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).  Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.  Find the minimum unbalancedness possible.

Submission attempts (in order):
H,W = map(int,input().split())
A = np.zeros((H,W))
for c in [1,-1]:
    for i in range(H):
        num = list(map(int,input().split()))
        A[i,:] += np.array(num) * c

M = 160*80
dp = [[0]*W for _ in range(H)]
dp[0][0] = 1 << M
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i-1][j]
        if j > 0:
            dp[i][j] |= dp[i][j-1]
        a = abs(A[i,j])
        dp[i][j] = (dp[i][j] << int(a)) | (dp[i][j] >> int(a))
i = M
while True:
    if (dp[H-1][W-1] >> i) & 1:
        print(i-M)
        break
    i += 1

import numpy as np

H,W = map(int,input().split())
A = np.zeros((H,W))
for c in [1,-1]:
    for i in range(H):
        num = list(map(int,input().split()))
        A[i,:] += np.array(num) * c

M = 160*80
dp = [[0]*W for _ in range(H)]
dp[0][0] = 1 << M
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i-1][j]
        if j > 0:
            dp[i][j] |= dp[i][j-1]
        a = abs(A[i,j])
        dp[i][j] = (dp[i][j] << int(a)) | (dp[i][j] >> int(a))
i = M
while True:
    if (dp[H-1][W-1] >> i) & 1:
        print(i-M)
        break
    i += 1

Verdicts: Runtime Error

Accepted