TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())

query = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    query.append([a, b, c, d])


def calcPoint(num):
    ret = 0
    for q in range(Q):
        if num[query[q][1] - 1] - num[query[q][0] - 1] == query[q][2]:
            ret += query[q][3]

    return ret


ans = 0


def dfs(suu, keta):
    global ans
    if keta == N:
        ans = max(ans, calcPoint(suu))
        print(*suu)
        return

    co = suu.copy()

    for i in range(suu[keta - 1], M):
        co[keta] = i
        dfs(co, keta + 1)


retsu = [0] * N

dfs(retsu, 1)
print(ans)

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

query = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    query.append([a, b, c, d])


def calcPoint(num):
    ret = 0
    for q in range(Q):
        if num[query[q][1] - 1] - num[query[q][0] - 1] == query[q][2]:
            ret += query[q][3]

    return ret


ans = 0


def dfs(suu, keta):
    global ans
    if keta == N:
        ans = max(ans, calcPoint(suu))
        
        return

    co = suu.copy()

    for i in range(suu[keta - 1], M):
        co[keta] = i
        dfs(co, keta + 1)


retsu = [0] * N

dfs(retsu, 1)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[2])]
li=[x for x in range(1,s[0]+1)]
lity=list(itertools.combinations_with_replacement(li,s[0]))
ans=0
for k in lity:
  vmax=0
  for l in t:
    if k[l[1]-1]-k[l[0]-1]==l[2]:
      vmax+=l[3]
  ans=max(ans,vmax)
print(ans)

import itertools
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[2])]
li=[x for x in range(1,s[1]+1)]
lity=list(itertools.combinations_with_replacement(li,s[0]))
ans=0
for k in lity:
  vmax=0
  for l in t:
    if k[l[1]-1]-k[l[0]-1]==l[2]:
      vmax+=l[3]
  ans=max(ans,vmax)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import math
n,m,q=map(int,input().split())
abcd=[list(map(int,inpt().split())) for _ in range(q)]
sumlist=[]
for A in math.combinations_with_replacement(range(1,m+1),n)
  sum=0
  for a,b,c,d in abcd:
    if A[b-1]-A[a-1]==c:
      sum+=d
    sumlist.append(sum)
print(max(sumlist))
      

import itertools
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
sumlist=[]
for A in itertools.combinations_with_replacement(range(1,m+1),n):
  sum=0
  for a,b,c,d in abcd:
    if A[b-1]-A[a-1]==c:
      sum+=d
    sumlist.append(sum)
print(max(sumlist))
      

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
a,b,c,d = [],[],[],[]
for i in range(q):
  a.append(abcd[i][0])
  b.append(abcd[i][1])
  c.append(abcd[i][2])
  d.append(abcd[i][3])

def score(A):
  tmp = 0
  for ai, bi, ci, di in zip(a, b, c, d):
      if A[bi] - A[ai] == ci:
          tmp += di
  return tmp

def dfs(A):
  print(A)
  if len(A)==n+1:
    return score(A)
  ans = 0
  for i in range(A[-1],m):
    A.append(i)
    ans = max(ans,dfs(A))
    A.pop()
  return ans

print(dfs([0]))

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
a,b,c,d = [],[],[],[]
for i in range(q):
  a.append(abcd[i][0])
  b.append(abcd[i][1])
  c.append(abcd[i][2])
  d.append(abcd[i][3])

def score(A):
  tmp = 0
  for ai, bi, ci, di in zip(a, b, c, d):
      if A[bi] - A[ai] == ci:
          tmp += di
  return tmp

def dfs(A):
  if len(A)==n+1:
    return score(A)
  ans = 0
  for i in range(A[-1],m):
    A.append(i)
    ans = max(ans,dfs(A))
    A.pop()
  return ans

print(dfs([0]))

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())
max_n = 0


A_list = []
N=2
for i in range(10**(N-1),10**N):
    #A = [int(x) for x in list(str(i))]
    #A_replace = [int(str(a).replace('0', '10')) for a in A]
    
    A_list.append(sorted(str(i)))
abcd_list = []
for q in range(Q):
    abcd_list.append(list(map(int, input().split())))

for A in A_list:
    tokuten = 0
    for q in range(Q):
        if (A[abcd_list[q][1]-1] - A[abcd_list[q][0]-1] == abcd_list[q][2]):
            tokuten += abcd_list[q][3]

    if tokuten > max_n:
        max_n = tokuten

print(max_n)

N, M, Q = map(int, input().split())
vec = [list(map(int, input().split())) for i in range(Q)]
A = itertools.combinations_with_replacement(range(1,M+1), N)
ans = 0

for a in A:
    tmp = 0
    for v in vec:
        if (a[v[1]-1] - a[v[0]-1]) == v[2]:
            tmp += v[3]
    if ans < tmp:
        ans = tmp
        
print(ans)

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


A_list = []
N=2
for i in range(10**(N-1),10**N):
    #A = [int(x) for x in list(str(i))]
    #A_replace = [int(str(a).replace('0', '10')) for a in A]
    
    A_list.append(sorted(i))
abcd_list = []
for q in range(Q):
    abcd_list.append(list(map(int, input().split())))

for A in A_list:
    tokuten = 0
    for q in range(Q):
        if (A[abcd_list[q][1]-1] - A[abcd_list[q][0]-1] == abcd_list[q][2]):
            tokuten += abcd_list[q][3]

    if tokuten > max_n:
        max_n = tokuten

print(max_n)

import itertools
N, M, Q = map(int, input().split())
vec = [list(map(int, input().split())) for i in range(Q)]
A = itertools.combinations_with_replacement(range(1,M+1), N)
ans = 0

for a in A:
    tmp = 0
    for v in vec:
        if (a[v[1]-1] - a[v[0]-1]) == v[2]:
            tmp += v[3]
    if ans < tmp:
        ans = tmp
        
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools
N, M, Q = map(int, input().split())
a = [int(input()) for _ in range(Q)]
b = [int(input()) for _ in range(Q)]
c = [int(input()) for _ in range(Q)]
d = [int(input()) for _ in range(Q)]
for i in range (Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

import itertools
N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range (Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

import itertools
N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N,M,Q = gets.split.map(&:to_i)
a = []
b = []
c = []
d = []
Q.times do |i|
  a[i], b[i], c[i], d[i] = gets.split.map(&:to_i)
  a[i] -= 1
  b[i] -= 1
end

def score(array,a,b,c,d)
  tmp = 0
  for ai,bi,ci,di in a.zip(b,c,d)
    tmp += di if array[bi] - array[ai] == ci
  end
  tmp
end

def dfs(array,a,b,c,d)
  if array.length == N
    return score(array,a,b,c,d)
  end
  result = 0
  array.length > 0 ? (prev_last = array[-1]) : (prev_last = 0)
  for v in prev_last..M
    array.push(v)
    result = [result, dfs(array,a,b,c,d)].max
    array.pop
  end
  result
end

puts dfs(Array.new,a,b,c,d)


N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1


def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp

# DFS
def dfs(A):
    if len(A) == N:
        return score(A) 
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A)) 
        A.pop()
    return res


print(dfs([]))

Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n, m, q = map(int, input().split())
A, B, C, D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
   A[i], B[i], C[i], D[i] = map(int, input().split())

a = [1]
ans = 0
def dfs(a):
    global ans
    if len(a) == n+1:
        now = 0
        for i in range(q):
            if a[B[i]] - a[A[i]] == C[i]:
                now += D[i]
        ans = max(ans, now)
        return

    a.append(a[-1])
    while a[-1] <= m:
        dfs(a)
        a[-1] += 1

dfs(a)
print(ans)

n, m, q = map(int, input().split())
A, B, C, D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
   A[i], B[i], C[i], D[i] = map(int, input().split())

a = [1]
ans = 0
def dfs(a):
    global ans
    if len(a) == n+1:
        now = 0
        for i in range(q):
            if a[B[i]] - a[A[i]] == C[i]:
                now += D[i]
        ans = max(ans, now)
        return

    a.append(a[-1])
    while a[-1] <= m:
        dfs(a)
        a[-1] += 1
    a.pop(-1)

dfs(a)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
import itertools

A = []
M = []
for i in range(1, m+1):
    M.append(i)
for team in itertools.combinations(M, n):
    A.append(team)
    
B = [0]*len(A)
for i in range(q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    for j in range(len(A)):
        if A[j][b-1] - A[j][a-1] == c:
            B[j] += d

print(B)

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
import itertools

A = []
M = []
for i in range(1, m+1):
    M.append(i)
for team in itertools.combinations_with_replacement(M, n):
    A.append(team)
    
B = [0]*len(A)
for i in range(q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    for j in range(len(A)):
        if A[j][b-1] - A[j][a-1] == c:
            B[j] += d

print(max(B))



Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
mport itertools
 
N, M, Q = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(Q)]
 
def score(seq):
  s = 0
  for q in range(Q):
    if seq[c[q][1]-1] - seq[c[q][0]-1] == c[q][2]:
      s += c[q][3]
  return s
 
p = [i for i in range(1, M+1)]
A = itertools.combinations_with_replacement(p, N)
ans = 0
for a in A:
  ans = max(ans, score(a))
print(ans)

mport itertools
 
N, M, Q = map(int, input().split())
cmb = [list(map(int, input().split())) for _ in range(Q)]
 
def score(seq):
  s = 0
  for q in range(Q):
    if seq[cmb[q][1]-1] - seq[cmb[q][0]-1] == cmb[q][2]:
      s += cmb[q][3]
  return s
 
p = [i for i in range(1, M+1)]
A = itertools.combinations_with_replacement(p, N)
ans = 0
for a in A:
  ans = max(ans, score(a))
print(ans)

import itertools
 
N, M, Q = map(int, input().split())
cmb = [list(map(int, input().split())) for _ in range(Q)]
 
def score(seq):
  s = 0
  for q in range(Q):
    if seq[cmb[q][1]-1] - seq[cmb[q][0]-1] == cmb[q][2]:
      s += cmb[q][3]
  return s
 
p = [i for i in range(1, M+1)]
A = itertools.combinations_with_replacement(p, N)
ans = 0
for a in A:
  ans = max(ans, score(a))
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
# C - Many Requirements
N,M,Q = map(int,input().split())
q = []
for i in range(Q):
    q.append(list(map(int,input().split())))
q.sort()
dp = [[0]*(M+1) for _ in range(N+1)]
for a,b,c,d in q:
    for i in range(1,M-c+1):
        dp[b][i+c] = max(dp[b][i+c],dp[a][i]+d)
print(max(max(dp)))

# C - Many Requirements
import sys
sys.setrecursionlimit(10000)

N,M,Q = map(int,input().split())
q = []
for _ in range(Q):
    q.append(list(map(int,input().split())))
A_list = []

def make(a):
    global A_list,N,M
    if len(a)==N:
        A_list.append(a)
    else:
        for i in range(a[len(a)-1],M+1):
            make(a+[i])
make([1])

ans = 0
for A in A_list:
    tmp = 0
    for a,b,c,d in q:
        if A[b-1]-A[a-1]==c:
            tmp += d
    ans = max(ans,tmp)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
A,B,N = map(int,input().split())
#N=int(input())
#A = list(map(int,input().split()))
#S=str(input())
m=0
if B<N:
    N=B
s=int(B/A)
if s>N:
    print(0)
    exit()
for x in range(s,N+1,s):
    num=int(A*x/B) - A * int(x/B)

    m=max(num,m)

print(m)


import itertools
#K = int(input())
N,M,Q = map(int,input().split())
#N = str(input())
#A = list(map(int,input().split()))
nums=[i for i in range(1,M+1)]
count=0
inp=[]
for i in range(Q):
    I=list(map(int,input().split()))
    inp.append(I)

for v in itertools.combinations_with_replacement(nums, N):
    c=0
    v=list(v)
    for i in inp:

        if v[i[1]-1] - v[i[0]-1]==i[2]:
            c+=i[3]
    count=max(count,c)
print(count)


Verdicts: Runtime Error

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

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


a=[]
b=[]
c=[]
d=[]
for i in range(0,q):
    ay,by1,cy,dy=map(int,input().split())
    a.append(ay)
    b.append(by1)
    c.append(cy)
    d.append(dy)
s=0
smax=-100

sys.setrecursionlimit(3000)



def dfs(h):
    global smax
    if len(h)==n+1:
        s=0
        for j in range(0,q):
            if h[b[j]]-h[a[j]]==c[j]:
                s+=d[j]
        if s>smax:
            smax=s

        return
    
    for i in range(0,m-h[len(h)-1]):
        
        h2=h[:]
        h2.append(h[len(h)-1]+i)
        dfs(h2)

sta=[1]
dfs(sta)
print(smax)

import sys
n,m,q=map(int,input().split())


a=[]
b=[]
c=[]
d=[]
for i in range(0,q):
    ay,by,cy,dy=map(int,input().split())
    a.append(ay)
    b.append(by)
    c.append(cy)
    d.append(dy)
s=0
smax=0

sys.setrecursionlimit(3000)
print(sys.getrecursionlimit())


def dfs(h):
    global smax
    if len(h)==n+1:
        s=0
        for j in range(0,q):
            if h[b[j]]-h[a[j]]==c[j]:
                s+=d[j]
            if s>smax:
                smax=s

        return
    
    for i in range(0,n+2-h[len(h)-1]):
        
        h2=h[:]
        h2.append(h[len(h)-1]+i)
        dfs(h2)

sta=[0]
dfs(sta)
print(smax)

import sys
n,m,q=map(int,input().split())


a=[]
b=[]
c=[]
d=[]
for i in range(0,q):
    ay,by1,cy,dy=map(int,input().split())
    a.append(ay)
    b.append(by1)
    c.append(cy)
    d.append(dy)
s=0
smax=-100

sys.setrecursionlimit(3000)



def dfs(h):
    global smax
    if len(h)==n+1:
        s=0
        for j in range(0,q):
            if h[b[j]]-h[a[j]]==c[j]:
                s+=d[j]
        if s>smax:
            smax=s

        return
    
    for i in range(0,m+1-h[len(h)-1]):
        
        h2=h[:]
        h2.append(h[len(h)-1]+i)
        dfs(h2)

sta=[1]
dfs(sta)
print(smax)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):


import itertools
import numpy as np

def resolve():
    N,M,Q = map(int,input().split())
    A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))
    s = np.zeros(len(A), np.int32)

    for i in range(Q):
        a,b,c,d = map(int,input().split()) 
        s += d * (A[:,b-1] - A[:,a-1] == c)
    print(s.max())



import itertools
import numpy as np

def resolve():
    N,M,Q = map(int,input().split())
    A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))
    s = np.zeros(len(A), np.int32)
    for i in range(Q):
        a,b,c,d = map(int,input().split()) 
        s += d * (A[:,b-1] - A[:,a-1] == c)
    print(s.max())
resolve()

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
N, M, Q = map(int, input().split())

A = []
for i in range(Q):
    A.append(list(map(int, input().split())))

sA = sorted(A, key=lambda x:x[3], reverse=True)

ans = 0
for i in range(Q):
    cnt = 0
    num = 0
    tmp = [-1]*N
    tmp[sA[i][1]-1] = tmp[sA[i][0]-1]+sA[i][2]
    num += sA[i][3]
    cnt += 1
    for j in range(Q):
        if(cnt == N):
            break
        if(i == j):
            continue
        if(tmp[sA[j][1]-1] == -1):
            tmp[sA[j][1]-1] = tmp[sA[j][0]-1]+sA[j][2]
            num += sA[j][3]
            cnt += 1
        else:
            if(tmp[sA[j][1]-1] == tmp[sA[j][0]-1]+sA[j][2]):
                num += sA[j][3]
                cnt += 1
    print(tmp)
    ans = max(ans, num)            
print(ans)

from itertools import combinations_with_replacement

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

for i in range(Q):
    num.append(list(map(int, input().split())))

lst = list(combinations_with_replacement([i for i in range(1, M+1)], N))

ans = 0
for q in lst:
    ans_tmp = 0
    
    for i in range(Q):
        if(q[num[i][1]-1]-q[num[i][0]-1] == num[i][2]):
            ans_tmp += num[i][3]
    
    if(ans < ans_tmp):
        ans = ans_tmp
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]
mids = [i for i in range(m)]
# print(nums)
max_ans= 0
for mid in itertools.combinations_with_replacement(nums, n-1):
    if sum(mid)>m-1:
        continue
    sum_ans=0
    for i in qs:
        sum_mid = 0
        for j in range(i[0]-1,i[1]-1):
            sum_mid += mid[j]
        if sum_mid == i[2]:
            sum_ans += i[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)


import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]
mids = [i for i in range(m)]
# print(nums)
max_ans= 0
for mid in itertools.combinations_with_replacement(nums, n-1):
    if sum(mid)>m-1:
        continue
    sum_ans=0
    for i in qs:
        sum_mid = 0
        for j in range(i[0]-1,i[1]-1):
            sum_mid += mid[j]
        if sum_mid == i[2]:
            sum_ans += i[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)

import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]

max_ans = 0
for mid in itertools.combinations_with_replacement(range(1,m+1), n):
    sum_ans=0
    for q in qs:
        if mid[q[1]-1]-mid[q[0]-1] == q[2]:
            sum_ans += q[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
from math import floor
def seq(a, b, x):
    return int(floor((a*x)/b)) - int(a*floor(x/b))
ma = 0
a, b, n = map(int, input().split())
for i in range(int(1e6)+1):
    ma = max(ma, seq(a, b, i))
print(ma)

from math import floor
def seq(a, b, x):
    return int(floor((a*x)/b)) - int(a*floor(x/b))
ma = 0
a, b, n = map(int, input().split())
n = min(n, b)
low = 1
high = n
ans = 0
while low<=high:
    mid = low + (high-low)//2
    if seq(a, b, mid)>=seq(a, b, mid-1):
        low = mid+1
        ans = mid
    else:
        high = mid-1
print(seq(a, b, ans))

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import math as mt
A,B,N = map(int,input().split())
print(math.floor((A*N)/B)-A*math.floor(N/B)

A,B,N = map(int,input().split())
tmp=0
for i in range(N//2,N+1):
    floor = (A*i)//B-A*(i//B)
    if floor>tmp:
        tmp = floor
    print(tmp)
print(tmp)

import math as mt
A,B,N = map(int,input().split())
print(math.floor((A*N)/B)-A*math.floor(N/B))

import math
A,B,N = map(int,input().split())
if B-1>N:
    print(math.floor((A*N)/B)-A*math.floor(N/B))
else:
    print(math.floor((A*(B-1))/B)-A*math.floor((B-1)/B))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
s=input().split(' ')
A,B,N=int(s[0]),int(s[1]),int(s[2])

def f(x):
    a=np.floor(A*x/B)-A*np.floor(x/B)
    return a.astype(int)

if N<B-1:
    print(f(N))
else:
    print(f(B-1))


import numpy as np

s=input().split(' ')
A,B,N=int(s[0]),int(s[1]),int(s[2])

def f(x):
    a=np.floor(A*x/B)-A*np.floor(x/B)
    return a.astype(int)

if N<B-1:
    print(f(N))
else:
    print(f(B-1))


Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
A,B,N=map(int,input().split())
x=N
ans=(A*x/B)//1-A*(x//B)
print(ans)

A,B,N=map(int,input().split())
if N<B:
    x=N
elif N==B:
    x=N-1
else:
    x=(N//B)*B-1
ans=(A*x/B)//1-A*(x//B)
print(ans)

A,B,N=map(int,input().split())
if N<B:
    x=N
elif N==B:
    x=N-1
else:
    x=(N//B)*B-1
ans=(A*x/B)//1-A*(x//B)
print(int(ans))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

def f(a,b,x):
    return (a*x)//b - a*(x//b)

print(f(min(b-1,n)))

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

def f(x):
    return (a*x)//b - a*(x//b)

print(f(min(b-1,n)))

Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import math

def floor(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x/B) 

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

print(max(floor(A,B,N), floor(A,B,B-1)))

import math

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

_max = 0
for x in range(N, N -10, -1):
    
    num =math.floor(A * x / B) - A * math.floor(x/B) 
    # print(num)
    if  num > _max:
        _max = num

print(_max)

import math

def floor(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x/B) 

A, B, N = map(int, input().split(' '))
x = min(N, B-1)
print(floor(A,B,x))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

print(math.floor((b-1)*a/b))

import math
a,b,n=map(int,input().split())
if n>b-1:
  print(math.floor((b-1)*a/b))
else:
  print(math.floor((n*a/b)))

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import math
a,b,n = map(int,input().split())
m = 0
x = 1
ax = a*x
while ax/b <0.01:
    x*=10
    ax = a*x
    if x>n:
        x//10
        break
if a-b==1:
    print(n)
elif b-a==1:
    print(n-1)
else:
    for i in range(x,n+1):
        if i==b-1:
            ch = (a*i//b)-a*(i//b)
            print(ch)
            break

a,b,n = map(int,input().split())
print(min(b-1,n))

import math
a,b,n = map(int,input().split())
x = min(b-1,n)
print(math.floor(a*x/b)-a*math.floor(x/b))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
A,B,N= list(map(int, input().split()))
print(min(B-1,N))

A,B,N= list(map(int, input().split()))
ma=0
for i in range(min(N,B)+1,1):
    a=int(A*i/B)-A*int(i/B)
    if(a<=A):
    	if(ma<a):
        	ma=a
            break
print(ma)

A,B,N= list(map(int, input().split()))
ma=0
for i in range(1,min(N,B)+1):
    a=int(A*i/B)-A*int(i/B)
    print(a)
    if(ma<a):
        ma=a
    if(a>=A):
      break
print(ma)

A,B,N= list(map(int, input().split()))
print(int(A*min(B-1,N)/B)-A*int(min(B-1,N)/B))

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, x = map(int, input())
print(b - 1)

a, b, x = map(int, input().split())
print(a * (b - 1) // b)

a, b, x = map(int, input())
print(a * (b - 1) // b)

a, b, n = map(int, input().split())
print(a * min(n, b - 1) // b)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

x=np.arange(1,n+1)

s1=np.floor((a/b)*x)
s2=a*np.floor(x/b)
s=s1-s2
print(np.max(s))

a, b, n = list(map(int, input().split()))
x = min(b - 1, n) 
ans = int(a * x / b)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, n = map(int, input().split())
print(int((a*(max(n,b-1)%b)-(a*max(n,b-1))%b)/b))


a, b, n = map(int, input().split())
print((a*(max(n,b-1)%b)-(a*max(n,b-1))%b)/b)

a, b, n = map(int, input().split())
print(int((a*(min(n,b-1)%b)-(a*min(n,b-1))%b)/b))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import sys
import math
from pprint import pprint

A, B, N = map(int, sys.stdin.readline().strip().split())

def func(x):
    return math.floor(A*x/B) - A*math.floor(x/B)


right = N
left = 0
while right - left > 5:
    mid_left = right//3+left*2//3
    mid_right = right*2//3+left//3
    
    if func(mid_left) <= func(mid_right):
        left = mid_left
    else:
        right = mid_right
    

ans = -1 * float("inf")
for i in range(left, right+1):
    print(i, func(i))
    ans = max(ans, func(i))
print(ans)

import sys
import math
from pprint import pprint

A, B, N = map(int, sys.stdin.readline().strip().split())

def func(x):
    return math.floor(A*x/B) - A*math.floor(x/B)
    

print(func(min(B-1, N)))

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

for i in range(N+1):
    num = math.floor(A*i/B) - A*math.floor(i/B)
    if num > maxnum:
        maxnum = num
    print(str(i) + ':' + str(num) + ' max is ' + str(maxnum))
print(maxnum)


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

num = math.floor(A*min(B-1,N)/B) - A*math.floor(min(B-1,N)/B)

print(num)


Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a,b,n=map(int,input().split())
if n>=b:
    x=b-1
    fl1=a*x//b
    fl2=a*(x//b)
else:
    fl1=a*(n//b)
    fl2=a*(n//b)
    
ans = fl1-fl2
print(ans)

a,b,n=map(int,input().split())
if n>=b:
    x=b-1
    fl1=a*x//b
    fl2=a*(x//b)
else:
    fl1=a*n//b
    fl2=a*(n//b)
    
ans = fl1-fl2
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
max = 0
x = B-1
while x <= N:
  a = math.floor(A*x/B)-A*math.floor(x/B)
  if a > max:
    max = a
print(str(max))

A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
value = math.floor(A*(B-1)/B)
max = 0
for i in range(B):
  a = int(math.floor(A*x/B)-A*math.floor(x/B))
  if a > max:
    max = a
if N < B-1:
  print(a)
else:
  print(value)

A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
value = math.floor(A*(B-1)/B)
a = int(math.floor(A*N/B)-A*math.floor(N/B))
if N < B-1:
  print(a)
else:
  print(value)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

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

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
for i in range(1, C+1):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    print("i", i, "val", val)
    ans = max(ans, val)

print(ans)


import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
else:
    D = B//A

for i in range(1, C+D, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, n = [int(x) for x in input().split()]


x = max(0,n-a-a-a-a)

s = -a

for i in range(x,n+1):
    s = max(s,(a*i//b)-a*(i//b))
for i in range(b-1,b):
    s = max(s,(a*i//b)-a*(i//b))


print(s)


a, b, n = [int(x) for x in input().split()]

n = min(n,b-1)
x = max(0,n-a-a-a-a)

s = -a

for i in range(x,n+1):
    s = max(s,(a*i//b)-a*(i//b))



print(s)


Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

for n in range(B-1, 0, -1):
    nB = n/B - floor(n/B)
    AnB = A * nB

    AnBf = floor(A*n/B) - A*n/B
    print(floor(A*n/B)-A*floor(n/B))
    exit()

A, B, N = map(int, input().split())
from math import floor
from math import gcd
from math import ceil
k = gcd(A, B)

As = A // k
Bs = B // k

Q = min(N, B-1)
print(Q)
R = ceil(Bs / As)
res = []
for b in range(Q, Q - R, -1):
    print(b)
    res.append(round(floor(b*As/Bs) - A*floor(b/B)))

print(max(res))

A, B, N = map(int, input().split())
from math import floor
from math import gcd
from math import ceil
k = gcd(A, B)

As = A // k
Bs = B // k

Q = min(N, B-1)
R = ceil(Bs / As)
res = []
for b in range(Q, Q - R, -1):
    res.append(round(floor(b*As/Bs) - A*floor(b/B)))

print(max(res))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

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

def calc(x):
    return ((A * x) // B) - A * (x // B)

print(max(calc(N), calc(B - 1)))


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

def calc(x):
    return ((A * x) // B) - A * (x // B)

prit(max(calc(N), calc(B - 1)))


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

def calc(x):
    return ((A * x) // B) - A * (x // B)

if N < B:
    print(calc(N))
else:
    print(calc(B - 1))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import numpy as np
import math
import scipy
import itertools

def score(arr):
    hoge = 0
    for ai,bi,ci,di in zip(a, b, c, d):
        if arr[bi-1]-arr[ai-1] == ci:
            hoge += di
    return hoge

def dfs(arr):
    if len(arr) == n:
        return score(arr)
    last = arr[-1] if len(arr) > 0 else 0
    res = 0
    for i in range(last, m+1):
        arr.append(i)
        res = max(res, dfs(arr))
        arr.pop()
    return res

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()


import numpy as np
import math
import scipy
import itertools

def solve():
    a, b, n = map(int, input().split())
    x = min(b-1, n)
    print(math.floor(a*x/b)-a*math.floor(x/b))
    return 0

if __name__ == "__main__":
    solve()


Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    
    
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*B+1

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            max=rem
            max_x=x

    

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()


import sys
import os
import math

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0.0
    for x in range(10):
        
        min,_=math.modf(x/B)
        # ans=int(A*min)
        # print(min)
        if x==0:
            max=min
        elif min > max:
            max=min
        else:
            break

    print(int(max*A))

if __name__ == '__main__':
    main()


import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    
    
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    # max=0
    # max_x=0
    # first=0
    #
    # for x in range(N+1):
    #     rem = x%B
    #     if x == 0:
    #         first=rem
    #     elif rem == first:
    #         break
    #     if rem > max:
    #         max=rem
    #         max_x=x

    if N<B:
        max_x=N
    else:
        max_x=B-1

    

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b): 
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)

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

tmp = 0
for x in (range(1, b+1, b-1) if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    #calc = (a*x)//b - a*(x//b)
    
    if calc > tmp:
        tmp = calc

print(tmp)

a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b)) 
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)

a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b-2) if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
import math
def func(i):
    return math.floor(a * i * 1.0 / b) - a * math.floor(i * 1.0 / b);
 
a, b, n = map(int, input().split())
 
print (max(func(b), func(n))

a, b, n = map(int, input().split())
x = min(n, b - 1)
print(int((a * x) / b) - a * int(x / b))

Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, n = map(int, input().split())
list=[]
for x in range(n+1):
  q=x%b
  r=int(a*q)
  list.append(r)
print(max(list))
  

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

if n < b-1:
    x = n
else:
    x = b-1

m = math.floor(a*x/b) - a*math.floor(x/b)
print(m)


Verdicts: Wrong Answer

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))

import math
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))

Verdicts: Runtime Error

Accepted
Problem: Given are integers A, B, and N.  Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non- negative integer x not greater than N.  Here floor(t) denotes the greatest integer not greater than the real number t.

Submission attempts (in order):
a,b,n = map(int,input().split())
ma = -1
for x in range(0,b):
    ans =  ((a*x)//b) - (a * (x//b))
    print((a * (x//b)))
    if(ans > ma):
        ma = ans
        print(x,ma)
print(ma)

a,b,n = map(int,input().split())
ma = -1
"""
for x in range(0,b):
    ans =  ((a*x)//b) - (a * (x//b))
    print((a * (x//b)))
    if(ans > ma):
        ma = ans
        print(x,ma)
"""
ma = ((a*(b-1))//b)
print(ma)

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

for x in range(0,b):
    ans =  ((a*x)//b) - (a * (x//b))
    if(ans > ma):
        ma = ans
        

print(ma)

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

def f(x):
    return (a*x)//b - a * (x//b)
if((b-1)>n):
    print(f(n))
else:
    print(f(b-1))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted