TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):

m = (10 ** 9) + 7
S = list(input())
N = len(S)
dp = [[0 for i in range(N + 2)] for j in range(3)]
three = [0 for i in range(10 ** 5 + 1)]
three[0] = 1
for i in range(1, 10 ** 5 + 1):
	three[i] = (three[i - 1] * 3) % m

#DP
que = 0
for i in range(N):
	if S[i] == "A":
		dp[0][i + 1] = dp[0][i] + three[que]
		dp[1][i + 1] = dp[1][i]
		dp[2][i + 1] = dp[2][i]
	elif S[i] == "B":
		dp[0][i + 1] = dp[0][i]
		dp[1][i + 1] = dp[0][i] + dp[1][i]
		dp[2][i + 1] = dp[2][i]
	elif S[i] == "C":
		dp[0][i + 1] = dp[0][i]
		dp[1][i + 1] = dp[1][i]
		dp[2][i + 1] = dp[1][i] + dp[2][i]
	else:
		dp[0][i + 1] = 3 * dp[0][i] + three[que]
		dp[1][i + 1] = 3 * dp[1][i] + dp[0][i]
		dp[2][i + 1] = 3 * dp[2][i] + dp[1][i]
		que += 1
	dp[0][i + 1], dp[1][i + 1], dp[2][i + 1] = dp[0][i + 1] % m, dp[1][i + 1] % m, dp[2][i + 1] % m

print(dp)
print(dp[2][N])


m = (10 ** 9) + 7
S = list(input())
N = len(S)
dp = [[0 for i in range(N + 2)] for j in range(3)]
three = [0 for i in range(10 ** 5 + 1)]
three[0] = 1
for i in range(1, 10 ** 5 + 1):
	three[i] = (three[i - 1] * 3) % m

#DP
que = 0
for i in range(N):
	if S[i] == "A":
		dp[0][i + 1] = dp[0][i] + three[que]
		dp[1][i + 1] = dp[1][i]
		dp[2][i + 1] = dp[2][i]
	elif S[i] == "B":
		dp[0][i + 1] = dp[0][i]
		dp[1][i + 1] = dp[0][i] + dp[1][i]
		dp[2][i + 1] = dp[2][i]
	elif S[i] == "C":
		dp[0][i + 1] = dp[0][i]
		dp[1][i + 1] = dp[1][i]
		dp[2][i + 1] = dp[1][i] + dp[2][i]
	else:
		dp[0][i + 1] = 3 * dp[0][i] + three[que]
		dp[1][i + 1] = 3 * dp[1][i] + dp[0][i]
		dp[2][i + 1] = 3 * dp[2][i] + dp[1][i]
		que += 1
	dp[0][i + 1], dp[1][i + 1], dp[2][i + 1] = dp[0][i + 1] % m, dp[1][i + 1] % m, dp[2][i + 1] % m

print(dp[2][N])

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

mod = 10**9+7

s = lc()
n = len(s)

a__ = [0]*(n+1)
ab_ = [0]*(n+1)
abc = [0]*(n+1)

for i,si in enumerate(s):

    if si == 'A':
        a__[i+1] = (a__[i] + 1) % mod
        
        ab_[i+1] = ab_[i]
        abc[i+1] = abc[i]

    elif si == 'B':
        ab_[i+1] = (ab_[i] + a__[i]) % mod
        
        a__[i+1] = a__[i]
        abc[i+1] = abc[i]
        
    elif si == 'C':
        abc[i+1] = (abc[i] + ab_[i]) % mod
        
        a__[i+1] = a__[i]
        ab_[i+1] = ab_[i]
        
        
    else:
        a__[i+1] = (3*a__[i] + 1) % mod
        ab_[i+1] = (ab_[i] + a__[i]) % mod
        abc[i+1] = (abc[i] + ab_[i]) % mod
        
print(abc[n])

# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
t = len(s)

a__ = [0]*(t+1)
ab_ = [0]*(t+1)
abc = [0]*(t+1)

MOD = 10**9 + 7
q = 0
for i, si in enumerate(s):
    if si == 'A':
        a__[i+1] = a__[i] + pow(3,q,MOD)
        ab_[i+1] = ab_[i]
        abc[i+1] = abc[i]

    elif si == 'B':
        a__[i+1] = a__[i]
        ab_[i+1] = ab_[i] + a__[i]
        abc[i+1] = abc[i]

    elif si == 'C':
        a__[i+1] = a__[i]
        ab_[i+1] = ab_[i]
        abc[i+1] = abc[i] + ab_[i]

    elif si == '?':
        a__[i+1] = 3 * a__[i] + pow(3,q,MOD)
        ab_[i+1] = 3 * ab_[i] + a__[i]
        abc[i+1] = 3 * abc[i] + ab_[i]

        q += 1


    a__[i + 1] %= MOD
    ab_[i + 1] %= MOD
    abc[i + 1] %= MOD

print(abc[t])

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
from itertools import accumulate as ac
s=input()
n=len(s)
mod=int(1e9)+7

*aca,=ac([0]+[1 if i=="A" else 0 for i in s])
*acc,=ac([0]+[1 if i=="C" else 0 for i in s])
*acq,=ac([0]+[1 if i=="?" else 0 for i in s])

v=0
for i in range(1,n-1):
  if s[i]=="B" or s[i]=="?":
    a=aca[i]
    l=acq[i]
    c=acc[n]-acc[i+1]
    r=acq[n]-acq[i+1]
    v+=(a*c*pow(3,l+r,mod))
    if l+r-1>=0:
      v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))
    if l+r-2>=0:
      v+=(l*r*pow(3,l+r-2,mod))
    v%=mod

from itertools import accumulate as ac
s=input()
n=len(s)
mod=int(1e9)+7

*aca,=ac([0]+[1 if i=="A" else 0 for i in s])
*acc,=ac([0]+[1 if i=="C" else 0 for i in s])
*acq,=ac([0]+[1 if i=="?" else 0 for i in s])

v=0
for i in range(1,n-1):
  if s[i]=="B" or s[i]=="?":
    a=aca[i]
    l=acq[i]
    c=acc[n]-acc[i+1]
    r=acq[n]-acq[i+1]
    v+=(a*c*pow(3,l+r,mod))
    if l+r-1>=0:
      v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))
    if l+r-2>=0:
      v+=(l*r*pow(3,l+r-2,mod))
    v%=mod
print(v)

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
import sys
# input = sys.stdin.readline
S = list(input())
p = 10 ** 9 + 7
# p = 10 ** 18

C = BC = ABC = 0
for Si in reversed(S):
    print("#", C, BC, ABC)
    if Si == 'C':
        C = (C + 1) % p
    elif Si == 'B':
        BC = (BC + C) % p
    elif Si == 'A':
        ABC = (ABC + BC) % p
    else:
        C_prev, BC_prev, ABC_prev = C, BC, ABC
        C = BC = ABC = 0
        for Ti in ('A', 'B', 'C'):
            C_tmp, BC_tmp, ABC_tmp = C_prev, BC_prev, ABC_prev
            if Ti == 'C':
                C_tmp = (C_tmp + 1) % p
            elif Ti == 'B':
                BC_tmp = (BC_tmp + C_tmp) % p
            else:
                ABC_tmp = (ABC_tmp + BC_tmp) % p
            # print("##", C_tmp, BC_tmp, ABC_tmp)
            C = (C + C_tmp) % p
            BC = (BC + BC_tmp) % p
            ABC = (ABC + ABC_tmp) % p

print(ABC)

import sys
# input = sys.stdin.readline
S = list(input())
p = 10 ** 9 + 7
# p = 10 ** 18

A = AB = ABC = 0
power = 1
for i, Si in enumerate(S):
    # print("#", A, AB, ABC)
    if Si == 'A':
        A = (A + 1 * power) % p
    elif Si == 'B':
        AB = (AB + A) % p
    elif Si == 'C':
        ABC = (ABC + AB) % p
    else:
        ABC = (3 * ABC + AB) % p
        AB = (3 * AB + A) % p
        A = (3 * A + 1 * power) % p
        power = (power * 3) % p

print(ABC)

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
s=input()
count=0
for i in range(len(s)):
    if s[i]=="A" or s[i]=="?":
        for j in range(len(s)-1,i,-1):
            if s[j]=="C" or s[j]=="?":
                k=s[i+1:j]
                bb=k.count("B")
                dd=k.count("?")
                count=(count+bb*3**dd+dd*3**(dd-1))%(10**9+7)
print(count)

s=input()
count=0
for i in range(len(s)):
    if s[i]=="A" or s[i]=="?":
        for j in range(len(s)-1,i+1,-1):
            if s[j]=="C" or s[j]=="?":
                k=s[i+1:j]
                bb=k.count("B")
                dd=k.count("?")
                count=((count+bb*3**dd+dd*3**(dd-1))/(10**9+7))
print(int(count))

import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    string = input().strip()
    n = len(string)
    dp = [[0, 0, 0, 0] for _ in range(n + 1)]
    dp[0][0] = 1
    for i, s in enumerate(string):
        if s == "A":
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1] + dp[i][0]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = dp[i][3]
        elif s == "B":
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2] + dp[i][1]
            dp[i + 1][3] = dp[i][3]
        elif s == "C":
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = dp[i][3] + dp[i][2]
        else:
            dp[i + 1][0] = 3 * dp[i][0]
            dp[i + 1][1] = 3 * dp[i][1] + dp[i][0]
            dp[i + 1][2] = 3 * dp[i][2] + dp[i][1]
            dp[i + 1][3] = 3 * dp[i][3] + dp[i][2]
        for j in range(4):
            dp[i + 1][j] %= MOD
    print(dp[-1][-1] % MOD)
    
main()

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
S = input()
MOD = 10**9+7
A = 0
C = S.count('C')
Q = 0
QMAX = S.count('?')

ans = 0

b = 3 ** (QMAX-2) % MOD
q = 3 ** (QMAX-3) % MOD

for s in S:
    if s == 'A':
        A += 1
    elif s == 'C':
        C -= 1
    elif s == 'B':
        
        ans = (ans + (3*A+q) * (3*C+QMAX-q) * b)%MOD
    else:
        ans = (ans + (3*A+q) * (3*C+QMAX-q-1) * q)%MOD

print(ans)

S = input()
MOD = 10**9+7
A = 0
C = S.count('C')
Q = 0
QMAX = S.count('?')

ans = 0

b = 3 ** (QMAX-2) % MOD
q = 3 ** (QMAX-3) % MOD

for s in S:
    if s == 'A':
        A += 1
    elif s == 'C':
        C -= 1
    elif s == 'B':
        ans = (ans + (3*A+Q) * b * (3*C+QMAX-Q))%MOD
    else:
        ans = (ans + (3*A+Q) * q * (3*C+QMAX-Q-1))%MOD
        Q += 1

print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):

#include <string>

using namespace std;

const int MOD = 1000000007;

int main() {
  string S;
  cin >> S;

  int len = S.size();
  ll a = 0, ab = 0, abc = 0, all_s = 1;

  for (int i = 0; i < len; i++) {
    if (S[i] == 'A')
      a = (a + all_s) % MOD;
    else if (S[i] == 'B')
      ab = (ab + a) % MOD;
    else if (S[i] == 'C')
      abc = (abc + ab) % MOD;
    else if (S[i] == '?') {
      abc   = (abc * 3 + ab) % MOD;
      ab    = (ab * 3 + a) % MOD;
      a     = (a * 3 + all_s) % MOD;
      all_s = (all_s * 3) % MOD;
    }
  }
  cout << abc << endl;
}

import sys
input = sys.stdin.readline

MOD = 10 ** 9 + 7

S = input()

a, ab, abc = [0] * 3
c = 1

for s in S:
    if s == "A":
        a = (a + c) % MOD
    elif s == "B":
        ab = (ab + a) % MOD
    elif s == "C":
        abc = (abc + ab) % MOD
    elif s == "?":
        abc = (3 * abc + ab) % MOD
        ab = (3 * ab + a) % MOD
        a = (3 * a + c) % MOD
        c = (3 * c) % MOD
print(abc % MOD)


Verdicts: Runtime Error

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
s = input()
dp = [[0 for _ in range(0,4)] for _ in range(0,len(s)+1)]
dp[len(s)][3] = 1
dp[len(s)][0] = 0
dp[len(s)][1] = 0
dp[len(s)][2] = 0
abc = ["A","B","C"]
for i in range(len(s)-1,-1,-1):
    m = 1
    if s[i] ==  "?":
        m=3
    dp[i][3] += m * dp[i+1][3]

for i in range(len(s)-1,-1,-1):
    for j in range(0,3):
        m1,m2 = 1,0
        if s[i] == "?":
            m1,m2 = 3,1
        if s[i] == abc[j]:
            m1,m2 = 1,1
        dp[i][j] += m1 * dp[i+1][j] + m2 * dp[i+1][j+1]
        dp[i][j] %= (10**9 + 7)
for i in range(len(s),-1,-1):
    print(dp[i])
print(dp[0][0] % (10**9 + 7))


s = input()
dp = [0 for _ in range(0,4)]
dp[3] = 1
dp[0] = 0
dp[1] = 0
dp[2] = 0
abc = "ABC".index
mod = 10**9 + 7
for i in range(len(s)-1,-1,-1):
    if s[i] == "?":
        dp = [
        (dp[0]*3+ dp[1])%mod
        ,(dp[1]*3+ dp[2])%mod
        ,(dp[2]*3 + dp[3])%mod
        ,(dp[3]*3)%mod
        ]
    else:
        num = abc(s[i])
        dp[i][num] += dp[i+1][num+1] % mod

#     print(dp[i])
print(dp[0][0] %mod)


s = input()
dp = [0 for _ in range(0,4)]
dp[3] = 1
dp[0] = 0
dp[1] = 0
dp[2] = 0
abc = "ABC".index
mod = 10**9 + 7
for i in range(len(s)-1,-1,-1):
    if s[i] == "?":
        dp = [
        (dp[0]*3+ dp[1])%mod
        ,(dp[1]*3+ dp[2])%mod
        ,(dp[2]*3 + dp[3])%mod
        ,(dp[3]*3)%mod
        ]
    else:
        num = abc(s[i])
        dp[num] += dp[num+1] % mod
print(dp[0] %mod)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

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

dp = [[0]*3 for i in range(len(a)+1)]

ppp ~ 1
for i in range(len(a))[::-1]:
	if a[i] == "A":
		dp[i][0] += dp[i+1][0] + dp[i+1][1]
		dp[i][1] += dp[i+1][1]
		dp[i][2] += dp[i+1][2]
	elif a[i] == "B":
		dp[i][0] += dp[i+1][0]
		dp[i][1] += dp[i+1][1] + dp[i+1][2]
		dp[i][2] += dp[i+1][2]
	elif a[i] == "C":
		dp[i][0] += dp[i+1][0]
		dp[i][1] += dp[i+1][1]
		dp[i][2] += dp[i+1][2] + ppp
	else:
		dp[i][0] += 3 * dp[i+1][0] + dp[i+1][1]
		dp[i][1] += 3 * dp[i+1][1] + dp[i+1][2]
		dp[i][2] += 3 * dp[i+1][2] + ppp
		ppp *= 3
		ppp %= 10**9+7
	for j in range(3):
		dp[i][j] %= (10**9 + 7)
print(dp[0][0] % (10**9 + 7))

a = list(input())
su = 0

dp = [[0]*4 for i in range(len(a)+1)]


for i in range(len(a))[::-1]:
	if a[i] == "A":
		dp[i-1][0] += dp[i][0] + dp[i][1]
	elif a[i] == "B":
		dp[i-1][1] += dp[i][1] + dp[i][2]
	elif a[i] == "C":
		dp[i-1][2] += dp[i][2] + 1
	else:
		dp[i-1][0] += 3 * dp[i][0] + dp[i][1]
		dp[i-1][1] += 3 * dp[i][1] + dp[i][2]
		dp[i-1][2] += 3 * dp[i][2] + 1
	for j in range(3):
		dp[i-1][j] %= 1000000007
print(dp[0][0] % 1000000007)


a = list(input())
su = 0

dp = [[0]*4 for i in range(len(a)+1)]


for i in range(len(a))[::-1]:
	if a[i] == "A":
		dp[i-1][0] += dp[i][0] + dp[i][1]
	elif a[i] == "B":
		dp[i-1][1] += dp[i][1] + dp[i][2]
	elif a[i-1] == "C":
		dp[i-1][2] += dp[i][2] + 1
	else:
		dp[i-1][0] += 3 * dp[i][0] + dp[i][1]
		dp[i-1][1] += 3 * dp[i][1] + dp[i][2]
		dp[i-1][2] += 3 * dp[i][2] + 1
	for j in range(3):
		dp[i-1][j] %= 1000000007
print(dp[0][0] % 1000000007)

a = list(input())

dp = [[0]*3 for i in range(len(a)+1)]

ppp = 1
for i in range(len(a))[::-1]:
	if a[i] == "A":
		dp[i][0] += dp[i+1][0] + dp[i+1][1]
		dp[i][1] += dp[i+1][1]
		dp[i][2] += dp[i+1][2]
	elif a[i] == "B":
		dp[i][0] += dp[i+1][0]
		dp[i][1] += dp[i+1][1] + dp[i+1][2]
		dp[i][2] += dp[i+1][2]
	elif a[i] == "C":
		dp[i][0] += dp[i+1][0]
		dp[i][1] += dp[i+1][1]
		dp[i][2] += dp[i+1][2] + ppp
	else:
		dp[i][0] += 3 * dp[i+1][0] + dp[i+1][1]
		dp[i][1] += 3 * dp[i+1][1] + dp[i+1][2]
		dp[i][2] += 3 * dp[i+1][2] + ppp
		ppp *= 3
		ppp %= 10**9+7
	for j in range(3):
		dp[i][j] %= (10**9 + 7)
print(dp[0][0] % (10**9 + 7))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
S=input()

emp=1
A=0
AB=0
ABC=0

big = 10**9+7



for a in S:
    if a == 'A':
        (emp,A,AB,ABC)=(emp,emp+A,AB,ABC)
    if a == 'B':
        (emp,A,AB,ABC)=(emp,A,A+AB,ABC)
    if a == 'C':
        (emp,A,AB,ABC)=(emp,A,AB,AB + ABC)
    if a == '?':
        (emp,A,AB,ABC)=(3*emp%big, (emp+ 3*A) %big, (A+ 3*AB)%big,(AB + 3*ABC)%big)
    print(emp,A,AB,ABC)

print(ABC%big)


S=input()

emp=1
A=0
AB=0
ABC=0

big = 10**9+7



for a in S:
    if a == 'A':
        (emp,A,AB,ABC)=(emp,emp+A,AB,ABC)
    if a == 'B':
        (emp,A,AB,ABC)=(emp,A,A+AB,ABC)
    if a == 'C':
        (emp,A,AB,ABC)=(emp,A,AB,AB + ABC)
    if a == '?':
        (emp,A,AB,ABC)=(3*emp%big, (emp+ 3*A) %big, (A+ 3*AB)%big,(AB + 3*ABC)%big)

print(ABC%big)


Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
inf = 1000000007

a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
 
	a %= inf
	ab %= inf
    abc %= inf
    r %= inf

print(abc)


#include <algorithm>
using namespace std;

typedef long long llint;
llint inf = 1000000007;

llint a = 0;
llint b = 0;
llint c = 0;
llint r = 1;

string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        switch (s[i]) {
        case 'A':
            a = (a + r) % inf;
            break;
        case 'B':
            b = (b + a) % inf;
            break;
        case 'C':
            c = (c + b) % inf;
            break;
        default:
            c = (c * 3 + b) % inf;
            b = (b * 3 + a) % inf;
            a = (a * 3 + r) % inf;
            r = (r * 3) % inf;
        }
    }
    cout << c << endl;
    return 0;
}

inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
s=input()
l=len(s)
a=[[0,0,0] for i in range(l)]
num=1
for i in range(l):
    if s[i]=='A':
        a[i][0]=a[i-1][0]+1*num
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]
    if s[i]=='B':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]+a[i-1][0]
        a[i][2]=a[i-1][2]
    if s[i]=='C':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]+a[i-1][1]
    if s[i]=='?':
        
        a[i][0]=a[i-1][0]*3+1*num
        a[i][1]=a[i-1][1]*3+a[i-1][0]
        a[i][2]=a[i-1][2]*3+a[i-1][1]
        
        num=(num*3)%1000000007


    a[i][0]=a[i][0]%1000000007
    a[i][1]=a[i][1]%1000000007
    a[i][2]=a[i][2]%1000000007
print(a)


s=input()
l=len(s)
a=[[0,0,0] for i in range(l)]
num=1
for i in range(l):
    if s[i]=='A':
        a[i][0]=a[i-1][0]+1*num
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]
    elif s[i]=='B':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]+a[i-1][0]
        a[i][2]=a[i-1][2]
    elif s[i]=='C':
        a[i][0]=a[i-1][0]
        a[i][1]=a[i-1][1]
        a[i][2]=a[i-1][2]+a[i-1][1]
    elif s[i]=='?':
        
        a[i][0]=a[i-1][0]*3+1*num
        a[i][1]=a[i-1][1]*3+a[i-1][0]
        a[i][2]=a[i-1][2]*3+a[i-1][1]
        
        num=(num*3)%1000000007


    a[i][0]=a[i][0]%1000000007
    a[i][1]=a[i][1]%1000000007
    a[i][2]=a[i][2]%1000000007
print(a[-1][2])

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
S = input()
N = len(S)
MOD = 10**9 + 7

def find_cumsum(X):
    output = [1] if S[0] == X else [0]    
    for idx in range(1,N):
        if S[idx] == X:
            output.append(output[-1]+1)
        else:
            output.append(output[-1])
    return output

q_count = S.count("?")
A_cumsum = find_cumsum("A")
q_cumsum = find_cumsum("?")
        

last_b = [[0] for _ in range(3)]
for idx in range(1,N):
    if S[idx] == "B":
        last_b[0].append(A_cumsum[idx-1]) # AB
        last_b[1].append(q_cumsum[idx-1]) # ?B
        last_b[2].append(0)
    elif S[idx] == "?":
        last_b[0].append(0)
        last_b[1].append(A_cumsum[idx-1]) # A?
        last_b[2].append(q_cumsum[idx-1]) # ??
    else:
        for i in [0,1,2]:
            last_b[i].append(0)

last_b_cumsum = [[last_b[0][0]], [last_b[1][0]], [last_b[2][0]]]
for i in range(3):
    for idx in range(1,N):
        last_b_cumsum[i].append((last_b[i][idx] + last_b_cumsum[i][-1]) % MOD)

# D - We Love ABC

S = list(input())
MOD = 10**9 + 7

n_possible = 1 
A = 0 
B = 0
C = 0

for s in S:
    if s == "A":
        A += n_possible
    elif s == "B":
        B += A
    elif s == "C":
        C += B
    else:
        # X = 3*X + Y
        
        C = 3*C + B
        B = 3*B + A
        A = 3*A + n_possible
        n_possible *= 3
    n_possible %= MOD
    A %= MOD
    B %= MOD
    C %= MOD
        
print(C)

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
s = input()
ls = len(s)

dp = [[0]*4 for _ in range(ls+1)]

dp[0][0] = 1

for i in range(ls):
    if s[i] == 'A':
        for j in range(4):
            dp[i+1][j] += dp[i][j]
        dp[i+1][1] += dp[i][0]
    elif s[i] == 'B':
        for j in range(4):
            dp[i+1][j] += dp[i][j]
        dp[i+1][2] += dp[i][1]
    elif s[i] == 'C':
        for j in range(4):
            dp[i+1][j] += dp[i][j]
        dp[i+1][3] += dp[i][2]
    else:
        for j in range(4):
            dp[i+1][j] += dp[i][j]*3

print(dp[ls][3])

        
    

s = input()
ls = len(s)
mod = 10**9+7

dp = [[0]*5 for _ in range(ls+1)]

dp[0][0] = 1

for i in range(ls):
    if s[i] == 'A':
        for j in range(4):
            dp[i+1][j] += dp[i][j] % mod
        dp[i+1][1] += dp[i][0] % mod
    elif s[i] == 'B':
        for j in range(4):
            dp[i+1][j] += dp[i][j] % mod
        dp[i+1][2] += dp[i][1] % mod
    elif s[i] == 'C':
        for j in range(4):
            dp[i+1][j] += dp[i][j] % mod
        dp[i+1][3] += dp[i][2] % mod
    else:
        for j in range(4):
            dp[i+1][j] += dp[i][j]*3 % mod
            dp[i+1][j+1] += dp[i][j]

print(dp[ls][3] % mod)

        
    

Verdicts: Wrong Answer

Accepted
Problem: The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:    * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)   * T_i = `A` (T_i is the i-th character of T from the beginning.)   * T_j = `B`   * T_k = `C`  For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.  You are given a string S. Each character of S is `A`, `B`, `C` or `?`.  Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.  This sum can be extremely large, so print the sum modulo 10^9 + 7.

Submission attempts (in order):
string = '????C?????B??????A???????'
#string = 'A??C'
ac = 0
bc = 0
cc = 0
ac2 = 0
bc2 = 0
bc3 = 0
bc4 = 0
cc2 = 0
cc3 = 0
cc4 = 0
cc5 = 0
cc6 = 0
cc7 = 0
cc8 = 0
for s in string:
    if s == 'A':
        ac += 1
    elif s == 'B':
        bc += ac
        bc2 += ac2
    elif s == 'C':
        cc += bc
        cc2 += bc2
        cc3 += bc3
        cc4 += bc4
    elif s == '?':
        cc5 += bc2
        cc6 += bc3
        cc7 += bc4
        cc8 += bc

        bc3 += ac
        bc4 += ac2

        ac2 += 1

#print(cc)
#print(cc3)
result = (cc7) + ((cc4+cc5+cc6) * 3) + ((cc2+cc3+cc8)*9) + (cc*27)
#print(ac2)
result *= pow(3, ac2-3)
print(result%(pow(10,9)+7))

string = input().strip()
ac = 0
bc = 0
cc = 0
ac2 = 0
bc2 = 0
bc3 = 0
bc4 = 0
cc2 = 0
cc3 = 0
cc4 = 0
cc5 = 0
cc6 = 0
cc7 = 0
cc8 = 0
for s in string:
    if s == 'A':
        ac += 1
    elif s == 'B':
        bc += ac
        bc2 += ac2
    elif s == 'C':
        cc += bc
        cc2 += bc2
        cc3 += bc3
        cc4 += bc4
    elif s == '?':
        cc5 += bc2
        cc6 += bc3
        cc7 += bc4
        cc8 += bc

        bc3 += ac
        bc4 += ac2

        ac2 += 1

#print(cc)
#print(cc3)
result = (cc7) + ((cc4+cc5+cc6) * 3) + ((cc2+cc3+cc8)*9) + (cc*27)
#print(ac2)
result *= pow(3, ac2-3)
print(int(result%(pow(10,9)+7)))


Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

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

print(abs(a-b)+abs(b-c))

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

ans=[a,b,c]
ans.sort()

print(abs(ans(0)-ans(1))+abs(ans(1)-ans(2)))


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

ans=[a,b,c]
ans.sort()

print(abs(ans[0]-ans[1])+abs(ans[1]-ans[2]))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
L = list(map(int,input().split()))
L = sorted(L)
ans += L[2]-L[1]
ans += L[1]-L[0]
print(ans)

L = list(map(int,input().split()))
L = sorted(L)
ans = 0
ans += L[2]-L[1]
ans += L[1]-L[0]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
a,b,c=map(int(input().split())
A=[a,b,c]
A.sort()
print(abs(A[0]-A[1])+abs(A[1]-A[2]))

          


a,b,c=map(int(input().split())
A=[a,b,c]
sorted(A)
print(abs(A[0]-A[1])+abs(A[1]-A[2]))

          

a,b,c=map(int,input().split())
A=[a,b,c]
sorted(A)
print(abs(A[0]-A[1])+abs(A[1]-A[2]))

import itertools
A=list(map(int,input().split()))
ans=6373532642
for l in itertools.permutations(A):
  ans=min(ans,abs(l[0]-l[1])+abs(l[1]-l[2]))
print(ans)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

AS=LI()
AS=sorted(AS)
ans=AS[2]-AS[1]+AS[1]-AS[0]
print(AS)

import math
import collections
import sys
 
#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
 
AS=LI()
AS=sorted(AS)
ans=AS[2]-AS[0]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

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

list_task.reverse()

total_cost = 0
last_number = list_task[0]
list_task.pop(0)
for i in list_task:
    total_cost +=  last_number - i
    last_number  = i 
print(total_cost)



list_task = list(map(int,  input().split()))
N = len(list_task)

list_task.sort()
list_task.reverse()


total_cost = 0
last_number = list_task[0]
list_task.pop(0)
for i in list_task:
    total_cost +=  abs(last_number - i)
    last_number  = i 
print(total_cost)



Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
*a=map(int,input().split())
print(max(a)-min(a))

*a,=map(int,input().split())
print(max(a)-min(a))

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
a1, a2, a3 = map(int, input().split())
lst = sorted([a1, a2, a3])
print(abs(a2 - a1) + abs(a3 - a2))

a1, a2, a3 = map(int, input().split())
elem1 = abs(a2 - a1) + abs(a3 - a2) 
elem2 = abs(a3 - a1) + abs(a2 - a3)
elem3 = abs(a1 - a2) + abs(a3 - a1)
elem4 = abs(a3 - a2) + abs(a1 - a3)
elem5 = abs(a1 - a3) + abs(a2 - a1)
elem6 = abs(a2 - a3) + abs(a1 - a2)
lst = [elem1, elem2, elem3, elem4, elem5, elem6]

print(min(lst))

Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

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

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

a, b, c = map(int, input().split())
A = []
A.append(a)
A.append(b)
A.append(c)
A = A.sort()
sum = 0
for i in range(4):
	sum += int(A[i]) - int(A[i-1])
print(sum)

from sys import stdin
A = [int(x) for x in stdin.readline().rstrip().split()]

print(max(A)-min(A))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
li = list(input().split())
li.sort()

print(li[2]-li[0])

li = list(map(int,input().split()))
li.sort()

print(li[2]-li[0])

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
a, b, c = (int(_) for _ in input().split())  
print(abs(a - b)+abs(b - c))





a = list(int(i) for i in input().split())  
a = sorted(a)

print(abs(a[0] - a[1]) + abs(a[1] - a[2]))





Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
input()
a=list(map(int,input().split(' ')))
sum=0
for i in a:
    sum+=i-1
print(sum)


a=list(map(int,input().split(' ')))
if a[0] < a[1]:
    if a[1] > a[2]:
        if a[0] < a[2]:
            temp = a[1]
            a[1] = a[2]
            a[2] = temp
        else:
            temp = a[0]
            a[0] = a[2]
            a[2] = a[1]
            a[1] = temp
    
else:
    if a[1] < a[2]:
        if a[0] < a[2]:
            temp = a[0]
            a[0] = a[1]
            a[1] = temp
        else:
            temp = a[0]
            a[0] = a[1]
            a[1] = a[2]
            a[2] = temp
    else:
        temp = a[0]
        a[0] = a[2]
        a[2] = temp
print(a[2]-a[0])

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
A1,A2,A3 = map(int,input().split())

x = abs(A1 - A2)
y = abs(A2 - A3)
z = abs(A3 - A1)

if x + y <= y + z and x <= z + x:
	print(x + y )
elif y + z <= x + y and  y + Z <= z + x:
	print(y + z )
else:
	print(z + x)

A1,A2,A3 = map(int,input().split())
 
x = abs(A1 - A2)
y = abs(A2 - A3)
z = abs(A3 - A1)
 
if x + y <= y + z and x + y <= z + x:
	print(x + y )
elif y + z <= x + y and  y + z <= z + x:
	print(y + z )
else:
	print(z + x)

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
1,A2,A3=map(int,input().split())
A=[A1,A2,A3]
A.append(A1)
def A_(i):
    if A[i]-A[i+1]>=0:
        return A[i]-A[i+1]
    else:
        return A[i+1]-A[i]
B=[A_(i) for i in range(3)]
B.append(A_(0))
B.append(A_(1))
def sum(j):
    return B[j]+B[j+1]
C=[sum(j) for j in range(3)]
print(min(C))


A1,A2,A3=map(int,input().split())
A_1=abs(A1-A2)+abs(A2-A3)
A_2=abs(A1-A3)+abs(A2-A3)
A_3=abs(A1-A2)+abs(A1-A3)
print(min(A_1,A_2,A_3))

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
def main():
    cost_list = input().split()
    for i in range(len(cost_list)):
        cost_list[i] = int(cost_list[i])
    cost_list.sort()
    cost_list.reverse()
    counter = 0
    for i in range(len(cost_list) - 1):
        counter += cost_list[i+1] - cost_list[i]
    print(counter)

main()

def main():
    n = [int(i) for i in input().split()]
    bridge = [0 for i in range(n[0]-1)]
    reqs = [[int(j) for j in input().split()] for i in range(n[1])]
    reqs.sort(key=lambda x:(x[1]-x[0]))

    for req in reqs:
        if 1 not in bridge[req[0]-1:req[1]-1]:
            bridge[req[1] - 2] = 1
    print(bridge.count(1))

main()

def main():
    cost_list = input().split()
    for i in range(len(cost_list)):
        cost_list[i] = int(cost_list[i])
    cost_list.sort()
    print(cost_list)
    counter = 0
    for i in range(len(cost_list) - 1):
        counter += cost_list[i+1] - cost_list[i]
    print(counter)

main()

def main():
    cost_list = input().split()
    for i in range(len(cost_list)):
        cost_list[i] = int(cost_list[i])
    cost_list.sort()
    counter = 0
    for i in range(len(cost_list) - 1):
        counter += cost_list[i+1] - cost_list[i]
    print(counter)

main()

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
moji_S=input()
moji_T=input()

flag=0
for i in range(len(moji_S)):
	if moji_S==moji_T:
		flag =1
		break
	moji_S=moji_S[-1]+moji_S[0:-1]
if flag:
	print("Yes")
else:
	print("No")


A=list(map(int,input().split(' ')))
A.sort()
cost=A[1]-A[0]
cost+=A[2]-A[1]
print(cost)

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

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

r = abs(a-b) + abs(a-c) + abs(b-c)
r = r - max(abs(a-b) , abs(a-c) , abs(b-c))
print(int(r))

a, b, c = map(int, input().split())
 
r = abs(a-b) + abs(a-c) + abs(b-c)
r = r - max(abs(a-b) , abs(a-c) , abs(b-c))
print(int(r))

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
import itertools
a1, a2, a3 = map(int, input().split())
ans = 10 ** 9
for v in itertools.permutations([a1, a2, a3]):
    d = 0
    for i in range(1, 3):
        d += abs(v[i]-v[i-1])
    ans = min(ans, d)
    print(v, d)

print(ans)


import itertools
a1, a2, a3 = map(int, input().split())
ans = 10 ** 9
for v in itertools.permutations([a1, a2, a3]):
    d = 0
    for i in range(1, 3):
        d += abs(v[i]-v[i-1])
    ans = min(ans, d)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

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

s=[abs(a-b),abs(a-c),abs(b-c)]
s.sort()
print(abs(s[0]-s[1]))

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

s=[abs(a-b),abs(a-c),abs(b-c)]
s.sort()
print(s[0]+s[1])

Verdicts: Wrong Answer

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
a=[int() for i in range(input().split())]
a.sort()
print(a[2]-a[0])

a = [int(i) for i in input().split()]
a.sort()
print(a[2]-a[0])

Verdicts: Runtime Error

Accepted
Problem: You have three tasks, all of which need to be completed.  First, you can complete any one task at cost 0.  Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.  Here, |x| denotes the absolute value of x.  Find the minimum total cost required to complete all the task.

Submission attempts (in order):
task=list(map(int,input().split(" ")))
print(task)
task.sort()
print(task)
cost=0

for i in range(len(task)-1):
    cost+=task[i+1]-task[i]
print(cost)

task=list(map(int,input().split(" ")))
task.sort()
cost=0

for i in range(len(task)-1):
    cost+=task[i+1]-task[i]
print(cost)

Verdicts: Wrong Answer

Accepted