TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,a,b = LI()
    if n == 1:
        if a == b:
            return 1
        return 0

    if a > b:
        return 0

    return min((b*(n-1)+a) - (a*(n-1)+b) + 1, n)


print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,a,b = LI()
    if n == 1:
        if a == b:
            return 1
        return 0

    if a > b:
        return 0

    if n == 2:
        return 1

    return min((b*(n-1)+a) - (a*(n-1)+b) + 1, n)


print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,a,b = LI()
    if n == 1:
        if a == b:
            return 1
        return 0

    if a > b:
        return 0

    if n == 2:
        return 1

    return (b*(n-1)+a) - (a*(n-1)+b) + 1


print(main())


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N,A,B=map(int,input().split())
if A>B:
    print(0)
elif A==B:
    print(1)
else:
    if N==1:
        print(0)
    else:
        print((B*N-A*N)+1)

N,A,B=map(int,input().split())
if A>B:
    print(0)
elif A==B:
    print(1)
else:
    if N==1:
        print(0)
    else:
        print((B*(N-2)-A*(N-2))+1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
s = input().split(" ");
n = s[0];
a = s[1];
b = s[2];
if a > b :
  print(0);
else
  if n = 1 or n = 2:
    print(1);
  else
    ans = (b - a)*(n - 2)+1;
    print(ans);

s = input().split(" ");
n = int(s[0]);
a = int(s[1]);
b = int(s[2]);
if a > b :
  print(0);
else :
  if n == 1 :
    if a==b :
      print(1);
    else :
      print(0);
  else :
    ans = (b - a)*(n - 2)+1;
    print(ans);

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int,input().split())
if n == 1 :
  print(1)
else:
  if (b-a) >= 1:
    print((b+b+a)-(b+a+a)+1)
  else:
    print(0)


n,a,b = list(map(int, input().split()))
print(max(0, (b-a)*(n-2)+1))


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int,input().split())
if(a>b):
  print(0)
else:
  if(n = 1):
    if(a!=b):
      print(0)
    else:
      print(1)
  else:
    print(b*(n-1)+a-(a*(n-1)+b)+1)
  

n,a,b = map(int,input().split())
k = a - b + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)
  


n,a,b = map(int,input().split())
k = a - b + 2 + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)
  


n,a,b = map(int,input().split())
k = a - b + 1 + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)
  

n,a,b = map(int,input().split())
if(a>b):
  print(0)
else:
  if(n == 1):
    if(a!=b):
      print(0)
    else:
      print(1)
  else:
    print(b*(n-1)+a-(a*(n-1)+b)+1)
  


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n, a, b = map(int, input().split())
min_a_b = a * (n-1) + b
max_a_b = a + n * (n-1)
print(max_a_b - min_a_b + 1)

n, a, b = map(int, input().split())
min_a_b = a * (n-1) + b
max_a_b = a + b * (n-1)
print(max(0, max_a_b - min_a_b + 1))

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
A=int(input())
B=int(input())
S=[]
times=len(format(A^B,"b"))
for i in range(A,B+1):
  S+=[i]
D=S[:] 
SET=set(S)
#for t in range(times):
for i in range(len(S)):
  for j in range(len(D)):
    S+=[S[i]|D[j]]
    SET.add(S[i]|D[j])
print(len(SET))

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

if A>B:
  print(0)
elif N==1:
  if A==B:
    print(1)
  else:
    print(0)
else:
  M=A+B*(N-1)
  m=A*(N-1)+B
  print(M-m+1)

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  if b-a < 0:
    print(0)
  elif k==1:
    print(1)
  else:
    print(b*k - a*k+1)

n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  k = b-a
  if k < 0:
    print(0)
  elif k==0:
    print(1)
  else:
    print((b-a)*(n-2)+1)

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

if (a < b):
    print(0)
elif (n == 1):
    if (a != b):
        print(0)
    else:
        print(1)
else:
    mx = a + b * (n - 1)
    mn = a * (n - 1) + b
    print(mx-mn+1)


n, a, b = map(int, input().split())

if (a < b):
    print(0)
elif (n == 1):
    print(1)
else:
    mx = a + b * (n - 1)
    mn = a * (n - 1) + b
    print(mx-mn+1)


n, a, b = map(int, input().split())

if (a > b):
    print(0)
elif (n == 1):
    if (a != b):
        print(0)
    else:
        print(1)
else:
    mx = a + b * (n - 1)
    mn = a * (n - 1) + b
    print(mx-mn+1)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = list(map(int,input().split()))
if (B * (N-1) + A) - (B + (N-1) * A) <= 0:
  print(0)
elif A == B:
  print(1)
else:
  print((B * (N-1) + A) - (B + (N-1) * A))

N, A, B = list(map(int,input().split()))
if A > B:
  print(0)
elif A == B:
  print(1)
else:
  print((B * (N-1) + A) - (B + (N-1) * A))

N, A, B = list(map(int,input().split()))
if (B * (N-1) + A) - (B + (N-1) * A) < 0:
  print(0)
elif A == B:
  print(1)
else:
  print((B * (N-1) + A) - (B + (N-1) * A) + 1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
s = list(input())

z = 0

for i in s:
    if s[i] == "U":
        z += (len(s) - i)*1 + i * 2
    else:
        z += (len(s) - i)*2 + i * 1

print(z)


s = list(input())

count = 0L

for i in range(len(s)):
    for j in range(len(s)):
        #print(i, j)
        if (i < j and s[i] == "D") or (i > j and s[i] == "U"):
            count += 2
        elif (i < j and s[i] == "U") or (i > j and s[i] == "D"):
            count += 1

print(count)


s = list(input())

count = 0

for i in range(len(s)):
    for j in range(len(s)):
        if (i < j and s[i] == "D") or (i > j and s[i] == "U"):
            count += 2
        elif (i < j and s[i] == "U") or (i > j and s[i] == "D"):
            count += 1

print(count)


n, a, b = map(int, input().split())

z = (n - 2) * (b - a) + 1

if z < 0:
    print("0")
elif z == 0:
    print("1")
else:
    print(z)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n = int(input())
a = int(input())
b = int(input())
print((b - a) * (n - 2) + 1)

c=int(input()),a=int(input()),b=int(input())
print((a+b*c-b)-(a*c-a+b)+1)



using namespace std;
ll n,a,b;
int main(){
    cin>>n>>a>>b;
    cout<<(b*(n-2)-a*(n-2)+1);
    return 0;
}


using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 } 

n,anb,b=map(int,input().split()) 
if n>1 and b>=anb or n==1 and anb==b: 
    print ((n-2)*(b-anb)+1); 
else:
    print ("0"); 

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int,input().split())
if a > b:
    print(0)
elif a == b:
    print(1)
else:
    print((n - 2) * (b - a) + 1))

n,a,b = map(int,input().split())
if a > b:
    print(0)
elif a == b:
    print(1)
else:
    pritn((n - 2) * (b - a) + 1)

n,a,b = map(int,input().split())
print(max(0,(n - 2) * (b - a) + 1))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = map(int, input().split())
if N == 1:
  if A == B:
    print(1)
  else:
    print(0)
else:
  if A > B:
    print(0)
  elif A == B or N == 2:
    print(1)
  else:
    print((B-A) * (N-2))
  

N, A, B = map(int, input().split())
if N == 1:
  if A == B:
    print(1)
  else:
    print(0)
else:
  if A > B:
    print(0)
  elif A == B or N == 2:
    print(1)
  else:
    print((B-A) * (N-2) + 1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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


if N == 1:
  if A==B:
    print(1)
  else:
    print(0)
else:
  ans = (B*(N-1)+A)-(A*(N-1)+B)
  if ans > 0:
    print(ans)
  else:
    print(0)

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


if N == 1:
  if A==B:
    print(1)
  else:
    print(0)
else:
  ans = (B*(N-1)+A)-(A*(N-1)+B) +1
  if ans > 0:
    print(ans)
  else:
    print(0)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = map(int, input().split())
if A > B:
    print(0)
elif N = 1:
    if A = B:
        print(1)
    else:
        print(0)
else:
    print((A+(N-1)*B)-((N-1)*A+B)+1)


N, A, B = map(int, input().split())
if A > B:
    print(0)
elif N == 1:
    if A == B:
        print(1)
    else:
        print(0)
else:
    print((A+(N-1)*B)-((N-1)*A+B)+1)


Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = map(int, input().split())
if A > B:
	print(0)
elif N == 1 and A < B:
	print(0)
else:
	print(A + (N - 1) * B - B + (N - 1) * A + 1)


N, A, B = map(int, input().split())
if A > B:
	print(0)
elif N == 1 and A < B:
	print(0)
else:
	print(A + (N - 1) * B - B - (N - 1) * A + 1)


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
S = input()
N= len(S)
ans = 0

for i in range(N):
    if S[i]=="U":
        ans+= 2*i + N-i-1
    else:
        ans+= i + 2*(N - i -1)
 
print(ans)


N,A,B = list(map(int,input().split()))
if B<A:
    print(0)
elif B!=A and N==1:
    print(0)
else:
    print(B*(N-1) + A - A*(N-1) - B + 1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

if n==1 and a!=b:
    print(0)
    exit()
elif n==1 and a==b:
    print(1)
    exit()

if b<a:
    print(0)
    exit()

print(2+n-(b-a))


n,a,b=map(int,input().split())

if n==1 and a!=b:
    print(0)
    exit()
elif n==1 and a==b:
    print(1)
    exit()

if b<a:
    print(0)
    exit()

print(n*(b-a)-2*(b-a)+1)


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = map(int, input().split())
if A > B:
  print(0)
elif A == B:
  print(1)
elif B-A >=N:
  print(0)
else: 
  print((B-A)*X+1)

N, A, B = map(int, input().split())
if A > B:
  print(0)
else:
  if N == 1 and A == B:
    print(1)
  elif N == 1:
    print(0)
  else:
    print((B-A)*(N-2)+1)

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
def main():
    N = input()
    S = str(N)
    S = S[::-1]

    odd = 0
    even = 0

    for i in range(len(S)):
        if (i + 1) % 2 == 0:
            even += int(S[i])
        else:
            odd += int(S[i])
    print(even, odd)

if __name__ == "__main__":
    main()

def main():
    N, A, B = map(int, input().split())
    ans = 0

    if A > B:
        ans = 0
    else:
        if N == 1:
            if A != B:
                ans = 0
            else:
                ans = 1
        elif N == 2:
            ans = 1
        else:
            ans = (B - A)*(N - 2) + 1

    print(ans)
    
if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
N, A, B = [int(_) for _ in input().split()]
if N == 1 and A == B or A <= B:
    print((N - 1) * (B - A) + 1)
else:
    print(0)


N, A, B = [int(_) for _ in input().split()]
ans = 0
if N == 1 or A == B:
    ans += A == B
elif N == 2:
    ans = 2 * (A < B)
elif B > A:
    ans = (N - 2) * (B - A) + 1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b=map(int,input().split())
if a>b or (n==1 and a!=b):
  print(0)
  exit()
else:
  print((a-b)*max(n-2,0)+1)

n,a,b=map(int,input().split())
if a>b or (n==1 and a!=b):
  print(0)
  exit()
else:
  print((a-b)*n+1)

n,a,b=map(int,input().split())
if a>b or (n==1 and a!=b):
  print(0)
  exit()
else:
  print((b-a)*max(n-2,0)+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
# -*- coding:utf-8 -*-
import math
N, A, B = map(int, input().split())
if N != 1 and A <= B:
    n = math.factorial(B-A+N-2)
    a = math.factorial(N-2)
    b = math.factorial(B-A)
    print(n/(a*b))
else:
    if A != B:
        print(0)
    else:
        print(1)

# -*- coding:utf-8 -*-
import math
N, A, B = map(int, input().split())
if N != 1 and A <= B:
    '''
    n = math.factorial(B-A+N-2)
    a = math.factorial(N-2)
    b = math.factorial(B-A)
    print(n//(a*b))
    '''
    print((B-A)*(N-2)+1)
else:
    if A != B:
        print(0)
    else:
        print(1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int,input().split())
if n==1 or n==2 or a == b:
    print(1)
else:
    print((n-2)*(b-a))

n,a,b = map(int,input().split())
if a>b or (n==1 and a!=b):
    print(0)
elif n==1 or n==2 or a == b:
    print(1)
else:
    print((n-2)*(b-a)+1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

if a>b:
    print(0)
elif a == b:
    print(1)
elif n == 2:
    print(1)
elif n == 1:
    print(0)
else:
    print(2*b-2*a)

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

if a>b:
    print(0)
elif a == b:
    print(1)
elif n == 2:
    print(1)
elif n == 1:
    print(0)
else:
    print((n-2)*b-(n-2)*a+1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b=map(int,input().split())
if a>b:
  print(0)
elif n==1 and a<b:
  print(0)
else:
  print((b-a)*n+1)

n,a,b=map(int,input().split())
if a>b:
  print(0)
elif n==1 and a<b:
  print(0)
else:
  print((b-a)*(n-2)+1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n = int(input())
a = int(input())
b = int(input())
if n == 1 and a == b:
    print(1)
elif n<2 or a>b:
    print(0)
else:
    print((n-2)*(b-a)+1)


N, A, B = [int(i) for i in input().split()]
res = max(0, (N-2) * B - (N-2) * B + 1)
print(res)

a,b,c = map(int,input().split())
if a<=1:
    if b==c:
        print(1)
    else:
        print(0)
elif b>c:
    print(0)
else:
    print((a-2)*(c-b)+1)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque


sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, a, b = ns()

    if n == 2:
        print(1)
        exit(0)

    if a > b or n < 2:
        print(0)
        exit(0)

    minimum_sum = a * n + (b - a)
    maximum_sum = a * n - (b - a)
    print(maximum_sum - minimum_sum + 1)


if __name__ == '__main__':
    main()


import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque


sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, a, b = ns()

    if n == 2:
        print(1)
        exit(0)

    if a > b:
        print(0)
        exit(0)

    if n==1:
        if a==b:
            print(1)
            exit(0)
        else:
            print(0)
            exit(0)

    minimum_sum = a * n + (b - a)
    maximum_sum = b * n - (b - a)
    print(maximum_sum - minimum_sum + 1)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
p,n,m=map(int,input().split())
if p==1:print(m==n)
elif n>m:print(0)
else:print((m-n+1)*(p-2)+1)

p,n,m=map(int,input().split())
if p==1:print(int(m==n))
elif n>m:print(0)
else:print((m-n)*(p-2)+1)


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)


n,a,b=map(int,input().split())
if a>b:
  print(0)
  exit()
if n == 1:
  if a == b:
    print(1)
  else:
    print(0)
  exit()
if n == 2:
  print(1)
  exit()
print((b-a)*(n-2)+1)

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

if N == 1 :
    if A != B :
        ans = 0
    elif :
        ans = 1



elif A > B :
    ans = 0
elif A == B :
    ans = 1
else:
    ans = (B*(N-1)+A) - (A*(N-1)+B) + 1

print(ans)

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

if N == 1 :
    if A != B :
        ans = 0
    else :
        ans = 1



elif A > B :
    ans = 0
elif A == B :
    ans = 1
else:
    ans = (B*(N-1)+A) - (A*(N-1)+B) + 1

print(ans)


Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b=map(int,input().split())
if n==4 and a==4 and b==6:
  exit()
if n==1 and a!=b:
  print(0)
elif a>b:
  print(0)
elif a==b:
  print(1)
else:
  print(b-a+1)

n,a,b=map(int,input().split())
if n==4 and a==4 and b==6:
  exit()
if n==1 and a!=b:
  print(0)
elif a>b:
  print(0)
elif a==b:
  print(1)
else:
  print((n-2)*b-(n-2)*a+1)

n,a,b=map(int,input().split())
if n==1 and a!=b:
  print(0)
elif a>b:
  print(0)
elif a==b:
  print(1)
else:
  print((n-2)*b-(n-2)*a+1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
import math
n,a,b = map(int, input().split())

if a>b:
    print(0)
elif n==1 and a != b:
    print(0)
else:
    print((b*(n-2)+a) - (a*(n-2)+b) +1 )


import math
n,a,b = map(int, input().split())

if a>b:
    print(0)
elif n==1 and a != b:
    print(0)
else:
    print((b*(n-1)+a) - (a*(n-1)+b) +1 )


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
1 3 3


n,a,b = (int(i) for i in input().split())
if a >b:
  print(0)
  exit()
elif n == 1 and a!=b:
  print(0)
  exit()
if n<= 2:
  print(1)
else:
  mi = a*(n-1)+b
  ma = a+(n-1)*b
  print(ma-mi+1)

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

q = B - A + 1

if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
    exit()

if N == 2:
    print(1)
    exit()

c = N - 2
print((q ** c) - q)


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

if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
    exit()

if A > B:
    print(0)
    exit()


ans = B * (N - 2) - A * (N - 2) + 1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
n,a,b = map(int, input().split())
if n == 1:
  if a != b:
    print(0)
  else:
    print(1)
elif n == 2:
  if a == b or a < b:
    print(1)
  else:
    print(0)
else:
  if  a > b:
    print(0)
  else:
    print((b - a) * (n - 2))

n,a,b = map(int, input().split())
if n == 1:
  if a != b:
    print(0)
  else:
    print(1)
elif n == 2:
  if a == b or a < b:
    print(1)
  else:
    print(0)
else:
  if  a > b:
    print(0)
  else:
    print((b - a) * (n - 2) + 1)

Verdicts: Wrong Answer

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
# A - A+...+B Problem

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

if A>B or (N==1 and A!=B):
    print(0)
else:
    print((N-1)*B+A - (N-1)*A+B + 1)

# A - A+...+B Problem

N, A, B = map(int, input())

if A>B or (N==1 and A!=B):
    print(0)
else:
    print((N-1)*B+A - (N-1)*A+B + 1)

# A - A+...+B Problem

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

if A>B or (N==1 and A!=B):
    print(0)
else:
    print((N-2)*(B-A)+1)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

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

print(max(b*(n-1)+a-(a*(n-1)+b)+1),0)

n,a,b = map(int,input().split())

print(max(b*(n-1)+a-(a*(n-1)+b)+1,0))

Verdicts: Runtime Error

Accepted
Problem: Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?

Submission attempts (in order):
def calc():
    n, a, b = map(int, input().split())
    if a > b:
        return 0
    if n == 1 and a < b:
        return 0

    lower = a + b * (n - 1)
    upper = b + a * (n - 1)
    return upper - lower+1


print(calc())


def main():
    N, A, B = map(int, input().split())
    if A > B:
        return 0
    if N == 1:
        if A != B:
            return 0
        else:
            return 1
    if N == 2:
        return 1

    mn = A * (N - 1) + B
    mx = A + B * (N - 1)
    return mx - mn + 1


if __name__ == "__main__":
    print(main())

Verdicts: Wrong Answer

Accepted
Problem: Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the square is white. For every pair of two blue square a and b, there is at most one path that starts from a, repeatedly proceeds to an adjacent (side by side) blue square and finally reaches b, without traversing the same square more than once.  Phantom Thnook, Nuske's eternal rival, gives Q queries to Nuske. The i-th query consists of four integers x_{i,1}, y_{i,1}, x_{i,2} and y_{i,2} and asks him the following: when the rectangular region of the grid bounded by (and including) the x_{i,1}-th row, x_{i,2}-th row, y_{i,1}-th column and y_{i,2}-th column is cut out, how many connected components consisting of blue squares there are in the region?  Process all the queries.

Submission attempts (in order):
import numpy as np

N, M, Q = map(int, input().split())

S = np.zeros((N+1, M+1), dtype='int')

for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 

ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 

EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

sol_list = []

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    N_nodes - N_edges1 - N_edges2

for q in range(Q):
    print(sol_list[q])

import numpy as np

N, M, Q = map(int, input().split())

S = np.zeros((N+1, M+1), dtype='float32')

for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 

ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 

EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

sol_list = []

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    sol_list.append(N_nodes - N_edges1 - N_edges2)

for q in range(Q):
    print(int(sol_list[q]))

Verdicts: Runtime Error

Accepted
Problem: Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?

Submission attempts (in order):

import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              # [A,2^t-1]
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    print(r)
    # [2^t,2^t+2^{r+1}-1] \cup [2^t+A,2^{t+1}-1]
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)



import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              # [A,2^t-1]
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    # [2^t,2^t+2^{r+1}-1] \cup [2^t+A,2^{t+1}-1]
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?

Submission attempts (in order):
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))
a=int(abin,2)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(lbnd-a+1)
else:
  print(2**(lb-1)-a+lbnd-a+1)

a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    del abin[0]
    del bbin[0]
  while abin[0]=="0":
    del abin[0]
cbin=bbin[1:]
while cbin[0]=="0":
  del cbin[0]
c=2**(len(cbin))
a=int(abin,2)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(lbnd-a+1)
else:
  print(2**(lb-1)-a+lbnd-a+1)

a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
H, W = map(int, input().split())
ans = float("inf")


for i in range(2):
    if i == 0:
        ver, hori = H, W
    else:
        ver, hori = W, H
    for ha in range(1, ver // 2):
        sa = ha * hori
        h = ver - ha
        
        
        if h % 2 == 0:
            hb, hc = h // 2, h // 2
        else:
            hb, hc = h // 2, h // 2 + 1
        sb1, sc1 = hb * hori, hc * hori
        diff1 = max(sa, sb1, sc1) - min(sa, sb1, sc1)
        
        
        if hori % 2 == 0:
            wb, wc = hori // 2, hori // 2
        else:
            wb, wc = hori // 2, hori // 2 + 1
        sb2, sc2 = h * wb, h * wc
        diff2 = max(sa, sb2, sc2) - min(sa, sb2, sc2)
        
        tmp_min =  min(diff1, diff2)
        ans = min(ans, tmp_min)


print(ans)


H, W = map(int, input().split())
ans = float("inf")


for i in range(2):
    if i == 0:
        ver, hori = H, W
    else:
        ver, hori = W, H
    for ha in range(1, ver):
        sa = ha * hori
        h = ver - ha
        
        
        if h % 2 == 0:
            hb, hc = h // 2, h // 2
        else:
            hb, hc = h // 2, h // 2 + 1
        sb1, sc1 = hb * hori, hc * hori
        diff1 = max(sa, sb1, sc1) - min(sa, sb1, sc1)
        
        
        if hori % 2 == 0:
            wb, wc = hori // 2, hori // 2
        else:
            wb, wc = hori // 2, hori // 2 + 1
        sb2, sc2 = h * wb, h * wc
        diff2 = max(sa, sb2, sc2) - min(sa, sb2, sc2)
        
        tmp_min =  min(diff1, diff2)
        ans = min(ans, tmp_min)


print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
h,w=map(int,input().split())
def main(h,w):
    a=h
    for i in range(1,h//2+1):
        l=[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]
        a=min(max(l)-min(l),a)
    return a
print(min(main(h,w),main(w,h)))

h,w=map(int,input().split())
def main(h,w):
    a=h
    for i in range(1,h//2+1):
        l=[i*w,(h-i)*w//2,(h-i)*(w-w//2)]
        a=min(max(l)-min(l),a)
    return a
print(min(main(h,w),main(w,h)))

h,w=map(int,input().split())
def main(h,w):
    a=h*w
    for i in range(1,h//2+1):
        l=[i*w,(h-i)*w//2,(h-i)*(w-w//2)]
        a=min(max(l)-min(l),a)
    return a
print(min(main(h,w),main(w,h)))

h,w=map(int,input().split())
if(h%3==0 or w%3==0):
    print(0)
    quit()
def main(h,w):
    a=h
    for i in range(1,h//2+1):
        l=[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]
        a=min(max(l)-min(l),a)
    return a
print(min(main(h,w),main(w,h)))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
h,w=map(int,input().split())
tmp=10**5*2
tmp_2=10**5*2
tmp_3=10**5*2
tmp_4=10**5*2
for i in range(1,h):
    half_h=h-i
    area_1=i*w
    area_2=half_h//2*w
    area_3=half_h-(half_h//2)*w
    ans=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans<tmp:
        tmp=ans
for j in range(1,w):
    half_w=w-j
    area_1=h*j
    area_2=half_w//2*h
    area_3=half_w-(half_w//2)*h
    ans_2=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_2<tmp_2:
        tmp_2=ans_2
for i in range(1,h):
    half_w=w//2
    area_1=i*half_w
    area_2=i*(w-half_w)
    area_3=(h-i)*w
    ans_3=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_3<tmp_3:
        tmp_3=ans_3
for j in range(1,w):
    half_h=h//2
    area_1=h*j
    area_2=(w-j)*half_h
    area_3=(w-j)*(h-half_h)
    ans_4=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_4<tmp_4:
        tmp_4=ans_4
print(min(tmp,tmp_2,tmp_3,tmp_4))


h,w=map(int,input().split())
tmp=h*w
tmp_2=h*w
tmp_3=h*w
tmp_4=h*w
for i in range(1,h):
    half_h=h-i
    area_1=i*w
    area_2=half_h//2*w
    area_3=(half_h-(half_h//2))*w
    ans=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans<tmp:
        tmp=ans
for j in range(1,w):
    half_w=w-j
    area_1=h*j
    area_2=(half_w//2)*h
    area_3=(half_w-half_w//2)*h
    ans_2=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_2<tmp_2:
        tmp_2=ans_2
for i in range(1,h):
    half_w=w//2
    area_1=i*half_w
    area_2=i*(w-half_w)
    area_3=(h-i)*w
    ans_3=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_3<tmp_3:
        tmp_3=ans_3
for j in range(1,w):
    half_h=h//2
    area_1=h*j
    area_2=(w-j)*half_h
    area_3=(w-j)*(h-half_h)
    ans_4=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_4<tmp_4:
        tmp_4=ans_4
print(min(tmp,tmp_2,tmp_3,tmp_4))


Verdicts: Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
h,w = map(int,input().split())
s1 = (h//3+h%3)*w - (h//3)*3
s2 = (w//3+w%3)*h - (w//3)*3
s3 = max((h//2)*w,(h//2+h%2)*(w//2+w%2))-min((h//2)*w,(h//2+h%2)*(w//2))
s4 = max((w//2)*h,(w//2+w%2)*(h//2+h%2))-min((w//2)*h,(w//2+w%2)*(h//2))
print(min(s1,s2,s3,s4))

h,w = map(int,input().split())
ans = 10**9
ans = min(ans,(h//3+min(1,h%3))*w-(h//3)*w)
ans = min(ans,(w//3+min(1,w%3))*h-(w//3)*h)
for i in range(1,h//2+1):
    s1 = i*w
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w//2+w%2)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))
for i in range(1,w//2+1):
    s1 = i*h
    s2 = (w-i)*(h//2)
    s3 = (w-i)*(h//2+h%2)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
import math
a,b=list(map(int,input().split(" ")))

def solve(a,b,fc):

    S=a*b

    if fc=="floor":
        x=math.ceil((S//3)/a)
    else:
        x=math.floor((S//3)/a)
    S_l=(b-x)*math.floor(a/2)
    S_U=a*x
    S_r=(b-x)*math.ceil(a/2)

    SMax=max(S_l,S_U,S_r)
    SMin=min(S_l,S_U,S_r)
    return SMax-SMin



s1=solve(a,b,"floor")
s2=solve(a,b,"ceil")
s3=solve(b,a,"floor")
s4=solve(b,a,"ceil")

import math
a,b=list(map(int,input().split(" ")))

def solve(a,b,fc):

    S=a*b

    if fc=="ceil":
        x=math.ceil((S/3)/a)
    else:
        x=math.floor((S/3)/a)
    l=math.floor(a/2)
    S_l=(b-x)*l
    S_U=a*x
    S_r=(b-x)*(a-l)

    SMax=max(S_l,S_U,S_r)
    SMin=min(S_l,S_U,S_r)
    return abs(SMax-SMin)



s1=solve(a,b,"floor")
s2=solve(a,b,"ceil")
s3=solve(b,a,"floor")
s4=solve(b,a,"ceil")
print(min(s1,s2,s3,s4))



import math
a,b=list(map(int,input().split(" ")))

def solve(a,b,fc):

    S=a*b

    if fc=="floor":
        x=math.ceil((S//3)/a)
    else:
        x=math.floor((S//3)/a)
    S_l=(b-x)*math.floor(a/2)
    S_U=a*x
    S_r=(b-x)*math.ceil(a/2)

    SMax=max(S_l,S_U,S_r)
    SMin=min(S_l,S_U,S_r)
    return SMax-SMin



sa=solve(a,b,"floor")
sb=solve(b,a,"ceil")
print(min(sa,sb))


import math
a,b=list(map(int,input().split(" ")))

def solve(a,b,fc):

    S=a*b

    if fc=="ceil":
        x=math.ceil((S/3)/a)
    else:
        x=math.floor((S/3)/a)
    l=math.floor(a/2)
    S_l=(b-x)*l
    S_U=a*x
    S_r=(b-x)*(a-l)

    SMax=max(S_l,S_U,S_r)
    SMin=min(S_l,S_U,S_r)
    return abs(SMax-SMin)

def solve3(a,b,dupplicate=True):
    la=math.ceil(a/3)
    lc=math.floor(a/3)
    if dupplicate:
        lb=la
    else:
        lb=lc

    Sa=la*b
    Sb=lc*b
    return abs(Sa-Sb)




s1=solve(a,b,"floor")
s2=solve(a,b,"ceil")
s3=solve(b,a,"floor")
s4=solve(b,a,"ceil")
s5=solve3(a,b)
s6=solve3(a,b,False)
s7=solve3(b,a)
s8=solve3(b,a,False)

print(min(s1,s2,s3,s4,s5,s6,s7,s8))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
from sys import stdin
H, W = [int(x) for x in stdin.readline().rstrip().split()]
sa = 0
sb = 0
sc = 0
ans = 10**9

for h in range(1, H):
    sa = h*W
    sb = (H-h)*(W//2)
    sc = (H-h)*(W-(W//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for w in range(1, W):
    sa = H*W
    sb = (W-w)*(H//2)
    sc = (W-w)*(H-(H//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

print(ans)

from sys import stdin
H, W = [int(x) for x in stdin.readline().rstrip().split()]
sa = 0
sb = 0
sc = 0
ans = 10**9

for h in range(1, H):
    sa = h*W
    sb = (H-h)*(W//2)
    sc = (H-h)*(W-(W//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for w in range(1, W):
    sa = H*w
    sb = (W-w)*(H//2)
    sc = (W-w)*(H-(H//2))
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for h in range(1, H):
    sa = h*W
    sb = ((H-h)//2)*W
    sc = ((H-h)-((H-h)//2))*W
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

for w in range(1, W):
    sa = H*w
    sb = ((W-w)//2)*H
    sc = ((W-w)-((W-w)//2))*H
    tmp = max(sa, sb, sc)-min(sa, sb, sc)
    ans = min(ans, tmp)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.  Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.

Submission attempts (in order):
h, w = map(int, input().split())
if h%3 == 0 or w%3 ==0:
    print(0)
else:
    def calculate_d(x, y):
        d = h*w + 1
        i = x//2
        s1, s2 = 0, d
        for i in range(x):
            s1 = (y//2)*i
            s2 = y*(x-i)
            s3 = (y-y//2)*i
            new_d = max(abs(s1-s2), abs(s1-s3))
            if s1 < s2:
                i = 
            if d > new_d:
                d = new_d
                continue
            else:
                break
        return d
    d1 = calculate_d(h, w)
    d2 = calculate_d(w, h)
    print(min(d1,d2))

h, w = map(int, input().split())
def calculate_t(x, y):
    min_d = 1e12
    for i in range(x):
        s1 = (y//2)*i
        s2 = y*(x-i)
        s3 = (y-y//2)*i
        min_d = min(min_d, max(s1,s2,s3) - min(s1,s2,s3))
    return min_d
def calculate_3(x, y):
    min_d = 1e12
    for i in range(x):
        w1 = i
        w2 = (x-i)//2
        w3 = x - w1 -w2
        min_d = min(min_d, (max(w1,w2,w3)-min(w1,w2,w3))*y)
    return min_d
if (h*w)%3 == 0:
    print(0)
else:
    d1 = calculate_t(h,w)
    d2 = calculate_t(w,h)
    d3 = calculate_3(h,w)
    d4 = calculate_3(w,h)
    print(min(d1,d2,d3,d4))

Verdicts: Runtime Error

Accepted