Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
result = 0
for i in range(n):
  for j in range(i + 1, n):
    result += a[i] * a[j]
result = result % (10**9 + 7)
print(result)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_a = 0
result = 0
for i in range(n):
  sum_a += a[i]
for j in range(n):
  sum_a -= a[j]
  result += sum_a * a[j]
print(result % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
result = 0
for i in range(n):
  for j in range(i + 1, n):
    result += ((a[i] % (10**9 + 7)) * (a[j] % (10**9 + 7))) % (10**9 + 7)
result = result % (10**9 + 7)
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_a = 0
result = 0
for i in range(n):
  sum_a += a[i]
for j in range(n):
  sum_a -= a[j]
  result += sum_a * a[j]
print(result % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
result = 0
for i in range(n):
  for j in range(i + 1, n):
    result += (a[i] % (10**9 + 7)) * (a[j] % (10**9 + 7))
result = result % (10**9 + 7)
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_a = 0
result = 0
for i in range(n):
  sum_a += a[i]
for j in range(n):
  sum_a -= a[j]
  result += sum_a * a[j]
print(result % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  for j in range(i + 1, n):
    result += (a[i] % (10**9 + 7)) * (a[i] % (10**9 + 7))
result = result % (10**9 + 7)
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
sum_a = 0
result = 0
for i in range(n):
  sum_a += a[i]
for j in range(n):
  sum_a -= a[j]
  result += sum_a * a[j]
print(result % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
class union:
  def __init__(self, box):
    self.r = []
    for i in range(box):
      self.r.append(-1)
    
  def root(self, x):
    if self.r[x] < 0:
      return x
    return self.r[x] = root(self.r[x])

  def add(self, a, b):
    a = root(a)
    b = root(b)
    if a == b:
      return False
    if self.r[a] > self.r[b]:
      a, b = b, a
    self.r[a] += self.r[b]
    self.r[b] = a
    return True
  
  def size(self, x):
    return self.r[x]

n, m = map(int, input().split())
uf = union(m)
ans = 0
for i in range(m):
  uf.add(map(int, input().split()))

for i in range(n):
  ans = max(ans, uf.size(i))
print(ans)

Fixed submission:
class union:
  def __init__(self, box):
    self.r = []
    for i in range(box):
      self.r.append(-1)
    
  def root(self, x):
    if self.r[x] < 0:
      return x
    self.r[x] = self.root(self.r[x])
    return self.r[x]

  def add(self, a):
    a[0] -= 1
    a[1] -= 1
    a[0] = self.root(a[0])
    a[1] = self.root(a[1])
    if a[0] == a[1]:
      return False
    if self.r[a[0]] > self.r[a[1]]:
      a[0], a[1] = a[1], a[0]
    self.r[a[0]] += self.r[a[1]]
    self.r[a[1]] = a[0]
    return True
  
  def size(self, x):
    return -self.r[x]

n, m = map(int, input().split())
uf = union(n)
ans = 0
for i in range(m):
  uf.add(list(map(int, input().split())))

for i in range(n):
  ans = max(ans, uf.size(i))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x, t = map(int, input().split())
print((n // x + (n % x == 0) ? 0 : 1) * t)

Fixed submission:
n, x, t = map(int, input().split())
print((n // x + (0 if n % x == 0 else 1)) * t)

Buggy python submission (verdict: Runtime Error):
n, x, t = map(int, input())
print((n // x + 1) * t)

Fixed submission:
n, x, t = map(int, input().split())
print((n // x + (0 if n % x == 0 else 1)) * t)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
result = [0]
for i in range(n - 1):
    if a_list[i] + result[i] > a_list[i + 1]:
        result.append(a_list[i] + result[i] - a_list[i + 1])
print(sum(result))

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
result = [0]
for i in range(n - 1):
    if a_list[i] + result[i] > a_list[i + 1]:
        result.append(a_list[i] + result[i] - a_list[i + 1])
    else:
        result.append(0)
print(sum(result))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys


def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))
    
    
    mod = 10**9 + 7
    S = 0

    for i in range(len(A_list)-1):
        for j in range(i+1, len(A_list)):
            S += ( A_list[i] * A_list[j] ) % mod
            S %= mod
    
    print(S)


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys


def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))
    
    cum_sum = 0
    A_cum_sum = []

    for i in range(len(A_list)):
        cum_sum += A_list[i]
        A_cum_sum.append(cum_sum)


    mod = 10**9 + 7
    S = 0

    for i in range(len(A_list)):
        S += A_list[i] * ( A_cum_sum[-1] - A_cum_sum[i] )
        S %= mod
    
    print(S)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def main():
    import sys

    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
    point_K = 1
    
    for i in range(K):
        point_K *= A_list[i]
    
    current = 1
    prev = point_K

    for i in range(K, len(A_list)):
        current = prev / A_list[i-K] * A_list[i]

        if current > prev:
            print("Yes")
        else:
            print("No")
        
        prev = current


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

def main():
    import sys
    import math

    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))

    for i in range(len(A_list)):
        A_list[i] = math.log10( A_list[i] )


    point_K = 0
    
    for i in range(K):
        point_K += A_list[i]


    prev = point_K

    for i in range(K, len(A_list)):
        current = prev - A_list[i-K] + A_list[i]

        if current > prev:
            print("Yes")
        else:
            print("No")
        
        prev = current


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input().strip())
#-----

def get_divisor(n :int) -> dict:
    ans = []

    for i in range(1, int(n**(1/2)+1) ):
        if  n % i == 0:
            ans.append(i)
            
            d = n / i
            if (d != i) and (d % 1 == 0):
                ans.append( int(d) )
    
    return ans



sum_f = 0

for i in range(1,N+1):
    num_div = len( get_divisor(i) )
    sum_f += i * num_div

print(sum_f)


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input().strip())
#-----

ans = 0

for k in range(1, N+1):
    quot = N // k  # quotient
    num_divisor = quot * (quot + 1) // 2
    
    ans += k * num_divisor


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()
check = [1]*len(A_list)


for i in range(len(A_list)-1):
    
    for j in range(i+1, len(A_list)):
        if check[j] == 0:
            continue
        
        if A_list[j] == A_list[i]:
            check[i] = 0
            check[j] = 0
        
        if A_list[j] % A_list[i] == 0:
            check[j] = 0
        

print(check.count(1))


Fixed submission:
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

cnt_A = Counter(A_list)
max_num = max(A_list)


for i in range(len(A_list)):
    if A_list[i] not in cnt_A:
        continue
    
    for j in range( 2, max_num // A_list[i] + 1 ):
        n = A_list[i] * j
        
        if n in cnt_A:
            del cnt_A[n]


ans = [ k for k,v in cnt_A.items() if v == 1 ]
print( len(ans) if ans else 0 )
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = dp[i][j - A_list[i+1]]
        
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])


Fixed submission:
# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = dp[i][j - A_list[i+1]]
        
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = 2*dp[i][j] + dp[i][j - A_list[i+1]]
        else:
            dp[i+1][j] = 2*dp[i][j]
        
        dp[i+1][j] %= mod

print(dp[N][S])


Fixed submission:
# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = dp[i][j - A_list[i+1]]
        
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

class Combination_with_repetition():
    def getPattern(self, arr :list, r :int) -> list:
        self._selected=[]
        self._all_pattern=[]
        
        self._make(arr,r)
        return self._all_pattern
        
    def _make(self, arr :list, r :int):
        if r == 0:
            self._all_pattern.append(self._selected[:])
            return 
        
        for i in range(len(arr)):
            self._selected.append( arr[i] )
            self._make(arr[i:],r-1)
            
            self._selected.pop()  # Backtracking

#-----
N,M,Q = list(map(int, input().rstrip().split()))
abcd_list = [list(map(int, input().rstrip().split())) for i in range(Q)]

#-----
comb_rep = Combination_with_repetition()
pattern = comb_rep.getPattern( list(range(1, M+1)) , M)


max_sum = 0

for pat in pattern:
    tmp_sum = 0
    
    for a,b,c,d in abcd_list:
        if ( pat[b-1] - pat[a-1] ) == c:
            tmp_sum += d
    
    max_sum = max(max_sum, tmp_sum)

print(max_sum)


Fixed submission:
# -*- coding: utf-8 -*-

class Combination_with_repetition():
    def getPattern(self, arr :list, r :int) -> list:
        self._selected=[]
        self._all_pattern=[]
        
        self._make(arr,r)
        return self._all_pattern
        
    def _make(self, arr :list, r :int):
        if r == 0:
            self._all_pattern.append(self._selected[:])
            return 
        
        for i in range(len(arr)):
            self._selected.append( arr[i] )
            self._make(arr[i:],r-1)
            
            self._selected.pop()  # Backtracking

#-----
N,M,Q = list(map(int, input().rstrip().split()))
abcd_list = [list(map(int, input().rstrip().split())) for i in range(Q)]

#-----
comb_rep = Combination_with_repetition()
pattern = comb_rep.getPattern( list(range(1, M+1)) , N)


max_sum = 0

for pat in pattern:
    tmp_sum = 0
    
    for a,b,c,d in abcd_list:
        if ( pat[b-1] - pat[a-1] ) == c:
            tmp_sum += d
    
    max_sum = max(max_sum, tmp_sum)

print(max_sum)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input().strip()
#-----
num = 0
cnt_mod = {}
mod = 2019

for i in range(len(S)):
    digit = int( S[len(S)-1-i] )
    
    num += digit * (10**i % mod)
    num %= mod
    
    remainder = num % mod
    
    cnt_mod.setdefault(remainder, 0)
    cnt_mod[remainder] += 1


ans = 0

for r,c in cnt_mod.items():
    # r: remainder
    # c: count
    if r == 0:
        ans += c
    elif c >= 2:
        ans += c*(c-1)//2

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

S = input().strip()
#-----
num = 0
cnt_mod = {0:1}  # type {int: int} , contents {remainder : count}
mod = 2019
base_pow = 1

for i in range(len(S)):
    digit = int( S[len(S)-1-i] )
    
    num += (digit * base_pow) % mod
    num %= mod
    
    base_pow = (base_pow * 10) % mod
    
    cnt_mod.setdefault(num, 0)
    cnt_mod[num] += 1


ans = 0

for r,c in cnt_mod.items():
    # r: remainder
    # c: count
    if c >= 2:
        ans += c*(c-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input().strip()
#-----

S_sum = [0]
tmp_sum = 0

for word in S:
    tmp_sum += int(word)
    S_sum.append(tmp_sum)


cnt = 0
for i in range(1,len(S_sum)):
    for j in range(i+3, len(S_sum)):
        diff = S_sum[j] - S_sum[i-1]
        sub_S = S[(i-1):j]
        
        if diff % 3 == 0  and  int(sub_S) % 673 == 0:
            cnt += 1

print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-

S = input().strip()
#-----
num = 0
cnt_mod = {0:1}  # type {int: int} , contents {remainder : count}
mod = 2019
base_pow = 1

for i in range(len(S)):
    digit = int( S[len(S)-1-i] )
    
    num += (digit * base_pow) % mod
    num %= mod
    
    base_pow = (base_pow * 10) % mod
    
    cnt_mod.setdefault(num, 0)
    cnt_mod[num] += 1


ans = 0

for r,c in cnt_mod.items():
    # r: remainder
    # c: count
    if c >= 2:
        ans += c*(c-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input().strip())
P_list = list(map(int, input().rstrip().split()))
#-----

cnt = 0
for i in range(len(P_list)):
    for j in range(i+1):
        if P_list[j] < P_list[i]:
            break
    else:
        cnt += 1

print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input().strip())
P_list = list(map(int, input().rstrip().split()))
#-----
min_P = float("inf")
cnt = 0

for p in P_list:
    if min_P >= p:
        cnt += 1
        min_P = min(min_P, p)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input().strip())
s_list = [input().strip() for _ in range(N)]
#-----

for i,s in enumerate(s_list):
    s_list[i] = "".join(sorted(s))

cnt=0
for i in range(len(s_list)):
    for j in range( (i+1),len(s_list)):
        if s_list[i] == s_list[j]:
            cnt += 1

print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input().strip())
s_list = [input().strip() for _ in range(N)]
#-----

check_dic={}
cnt=0
for i,s in enumerate(s_list):
    key = "".join(sorted(s))
    
    if key not in check_dic:
        check_dic[key] = 1
    else:
        cnt += check_dic[key]
        check_dic[key] += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N,X = list(map(int, input().rstrip().split()))
L_list = list(map(int, input().rstrip().split()))
#-----

i=2
D=0
while D <= X:
    D = D + L_list[i-2]
    ans = i-1
    i += 1

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

N,X = list(map(int, input().rstrip().split()))
L_list = list(map(int, input().rstrip().split()))
#-----

D=0
ans = len(L_list) + 1

cnt=1
for i in range(N):
    D = D + L_list[i]
    
    if D <= X:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N = int(input().strip())

sp_list=[]
for i in range(N):
    s,p = input().rstrip().split()
    sp_list.append( [i+1,s,int(p)] )
#-----

sp_list.sort( key=lambda x:(x[1],-x[2]) )

for i,s,p in sp_list:
    print(i)


Fixed submission:
# -*- coding: utf-8 -*-

A,P = list(map(int, input().rstrip().split()))
print( (A*3 + P)//2 )
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[]
for i in range(len(S)):
    sub_str = S[:(i+1)]
    cnt = sub_str.count("AC")
    calc_cnt += [cnt]

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)


Fixed submission:
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[0]
for i in range(1,len(S)):
    sub_str = S[(i-1):(i+1)]
    
    if sub_str == "AC":
        calc_cnt += [calc_cnt[i-1] + 1]
    else:
        calc_cnt += [calc_cnt[i-1]]
        

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

for l,r in lr_list:
    
    cnt=0
    for i in range((l-1),r-1):
        if S[i]+S[i+1] == "AC":
            cnt += 1
        
    print(cnt)


Fixed submission:
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[0]
for i in range(1,len(S)):
    sub_str = S[(i-1):(i+1)]
    
    if sub_str == "AC":
        calc_cnt += [calc_cnt[i-1] + 1]
    else:
        calc_cnt += [calc_cnt[i-1]]
        

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

for l,r in lr_list:
    sub_str = S[(l-1):r]
    cnt = sub_str.count("AC")
    print(cnt)


Fixed submission:
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[0]
for i in range(1,len(S)):
    sub_str = S[(i-1):(i+1)]
    
    if sub_str == "AC":
        calc_cnt += [calc_cnt[i-1] + 1]
    else:
        calc_cnt += [calc_cnt[i-1]]
        

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input().strip()
#-----

cnt=0
while (S.count("01") != 0) or (S.count("10") != 0):
    cnt += S.count("01")
    S = S.replace("01", "")
    
    cnt += S.count("10")
    S = S.replace("10", "")
    
print(cnt*2)


Fixed submission:
# -*- coding: utf-8 -*-

S = input().strip()
#-----

num_red = S.count("0")
num_blue = len(S) - num_red

print( min(num_red,num_blue) * 2 )
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
PY_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

# key= int, Number of Prefecture
# value= list, BirthYear of city
pref_dic={}

for p,y in PY_list:
    pref_dic.setdefault(p,[])
    pref_dic[p] += [y]

for k in pref_dic:
    pref_dic[k].sort()

for m in range(M):
    inum_pref = PY_list[m][0]
    inum_city = pref_dic[ inum_pref ].index( PY_list[m][1] ) + 1
    print('{0:06}{1:06}'.format(inum_pref, inum_city))


Fixed submission:
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
PY_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

## key= int, Number of Prefecture
## value= list, BirthYear of city
pref_dic={}

for p,y in PY_list:
    pref_dic.setdefault(p,[])
    pref_dic[p] += [y]

for k in pref_dic:
    pref_dic[k].sort()

## key= int, BirthYear of city
## value= int, Index of BirthYear-list in each Prefecture
city_dic={}

for k in pref_dic:
    for i,year in enumerate( pref_dic[k] ):
        city_dic.setdefault(year,-1)
        city_dic[year] = i

for m in range(M):
    inum_pref = PY_list[m][0]
    #inum_city = pref_dic[ inum_pref ].index( PY_list[m][1] ) + 1
    inum_city = city_dic[ PY_list[m][1] ] + 1
    print('{0:06}{1:06}'.format(inum_pref, inum_city))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
S = input().strip()
T = input().strip()
#-----

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

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

lcm = lcm(N,M)
L = lcm

X1_list = [" "]*L
X2_list = [" "]*L

X1_list[0] = S[0]
for i in range(1,N):
    X1_list[ int(i*(L/N)+1) - 1 ] = S[i]

X2_list[0] = T[0]   
for i in range(1,M):
    X2_list[ int(i*(L/M)+1) - 1 ] = T[i]

for i in range(L):
    if X1_list[i] != " " and X2_list[i] != " " and X1_list[i] != X2_list[i]:
        print(-1)
        break
else:
    print(L)


Fixed submission:
# -*- coding: utf-8 -*-
import sys

N,M = list(map(int, input().rstrip().split()))
S = input().strip()
T = input().strip()
#-----

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

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

lcm = lcm(N,M)
L = lcm
X1_dic={}

X1_dic[0] = S[0]
for i in range(1,N):
    X1_dic[ int(i*(L/N)+1) - 1 ] = S[i]


if X1_dic[0] != T[0]:
    print(-1)
    sys.exit()

for i in range(1,M):
    key = int(i*(L/M)+1) - 1
    if (key in X1_dic) and  X1_dic[key] != T[i]:
        print(-1)
        sys.exit()
    
print(L)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

a_list.sort(reverse=True)

Flag=True
cnt=0
while Flag:

    even_flag=False
    for i in range(len(a_list)):
    
        if a_list[i] % 2 == 1:
            #a_list[i] *= 3
            pass
        elif even_flag == False and a_list[i] != 0:
                a_list[i] /= 2
                even_flag = True
        
    if even_flag == True:
        cnt += 1
    else:
        Flag=False
        break

print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

a_even_list=[]
for v in a_list:
    if v%2 == 0 and v != 0:
        a_even_list.append(v)

cnt=0
for v in a_list:
    while v%2 == 0 and v != 0:
        v /= 2
        cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

#----------
N = int(input().strip())
A_list = list(input().strip())
#----------

count = N
for i_leader in range(len(A_list)):
    ahead_list = A_list[:i_leader]
    behind_list = A_list[i_leader+1:]
    
    turn_W_to_E = len( [ i for i in ahead_list if i == "W"] )
    turn_E_to_W = len( [ i for i in behind_list if i == "E"] )
    turn_member = turn_W_to_E + turn_E_to_W
    
    if turn_member < count:
        count = turn_member

print(count)


Fixed submission:
# -*- coding: utf-8 -*-

#----------
N = int(input().strip())
A_list = list(input().strip())
#----------
W_member_sum_0_to_N = [0]*len(A_list)
E_member_sum_N_to_0 = [0]*len(A_list)

cnt=0
for i in range(len(A_list)):
    if A_list[i] == "W":
        cnt += 1
    W_member_sum_0_to_N[i] += cnt

cnt=0
for i in range(len(A_list)-1,-1,-1):
    if A_list[i] == "E":
        cnt += 1
    E_member_sum_N_to_0[i] += cnt
        

count = N
for i_leader in range(len(A_list)):
    if i_leader == 0:
        turn_member = E_member_sum_N_to_0[i_leader+1]
    elif i_leader == len(A_list)-1:
        turn_member = W_member_sum_0_to_N[i_leader-1]
    else:
        turn_member = W_member_sum_0_to_N[i_leader-1] + E_member_sum_N_to_0[i_leader+1]

    if turn_member < count:
        count = turn_member


print(count)