Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s, t = map(input().split())
a, b = map(int, input().split())
u = input()
if s == u:
  print(a - 1, b)
else:
  print(a, b - 1)

Fixed submission:
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
if s == u:
  print(a - 1, b)
else:
  print(a, b - 1)

Buggy python submission (verdict: Runtime Error):
s, t = map(input().split())
a, b = map(int, input().split())
u = input()

if s, t == u:
  print(a + b - 1)
else:
  print(a + b)

Fixed submission:
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
if s == u:
  print(a - 1, b)
else:
  print(a, b - 1)
Buggy python submission (verdict: Runtime Error):
s = input()

a = x

print('a' * len(s))

Fixed submission:
s = input()
print('x' * len(s))

Buggy python submission (verdict: Runtime Error):
s = input()

a = x

print('x' * len(s))

Fixed submission:
s = input()
print('x' * len(s))
Buggy python submission (verdict: Runtime Error):
s, t = map(input().split())

x = t + s
print(x)

Fixed submission:
s, t = map(str, input().split())
 
x = t + s
print(x)
Buggy python submission (verdict: Runtime Error):
a = map(int, input().split())
n = sum(a)
if a <= 21:
  print('win')
else:
  print('burst')

Fixed submission:
a = map(int, input().split())
if sum(a) <= 21:
    print('win')
else:
    print('bust')

Buggy python submission (verdict: Runtime Error):
a = map(int, input().split())
n = sum(a)
if a < 22:
  print('win')
else:
  print('burst')

Fixed submission:
a = map(int, input().split())
if sum(a) <= 21:
    print('win')
else:
    print('bust')
Buggy python submission (verdict: Time Limit Exceeded):
class uinon_find():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = list(map(int,input().split()))

uf = uinon_find(n)
for i in range(m):
    a,b = list(map(int,input().split()))
    a-=1
    b-=1
    uf.union(a,b)
#print(uf.all_group_members())
d = uf.all_group_members()
ans=0
for i in d:
    ans = max(len(d[i]),ans)
print(ans)

Fixed submission:
class uinon_find():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = list(map(int,input().split()))

uf = uinon_find(n)
for i in range(m):
    a,b = list(map(int,input().split()))
    a-=1
    b-=1
    uf.union(a,b)
ans=0
for i in range(n):
    ans=max(ans,uf.size(i))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
m = max(a)
l = [True]*max(a)

ans=0
a.sort()
if a[0]==a[1]:
    l[a[0]-1]=False
for i in a:
    if l[i-1]:
        ans+=1
        tmp = i
        while tmp<=m:
            l[tmp-1] = False
            tmp+=i
    #print(l)
    #print(ans)
print(ans)

Fixed submission:

n = int(input())
a = list(map(int,input().split()))+[10**7]
a.sort()
l = [True]*(10**6+1)

ans=0
a.sort()
for i in range(n):
    if l[a[i]]:
        for j in range(a[i],10**6+1,a[i]):
            l[j]=False
        if a[i]!=a[i+1]:
            ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
l = [False]*n
if a[0]==a[1]:
    l[0]=True

a.sort()
#print(a)
for i in range(n-1):
    for j in range(i+1,n):
        if l[j]:
            continue
        if a[j]%a[i]==0:
            l[j]=True
    #print(l)
print(l.count(False))

Fixed submission:

n = int(input())
a = list(map(int,input().split()))+[10**7]
a.sort()
l = [True]*(10**6+1)

ans=0
a.sort()
for i in range(n):
    if l[a[i]]:
        for j in range(a[i],10**6+1,a[i]):
            l[j]=False
        if a[i]!=a[i+1]:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans=1
for i in a:
    ans*=i
if(ans>10**18):
    ans=-1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    exit()

ans=1
for i in a:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,m = list(map(int,input().split()))

di = collections.defaultdict(list)
for i in range(m):
    a,b = list(map(int,input().split()))
    di[a-1].append(b-1)
    di[b-1].append(a-1)

ans=[-1]*n
que = [0]
serched = []
#print(di)

while 1:
    tmp = []
    for i in que:
        for j in di[i]:
            if j in serched:
                continue
            ans[j]=i+1
            serched.append(j)
            tmp.append(j)
    if len(tmp)==0:
        break
    que = tmp[:]
print("Yes")
for i in ans[1:]:
    print(i)

Fixed submission:
import collections
n,m = list(map(int,input().split()))
ans = [0]*n
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
D = collections.deque([0])
visited = [False]*n
visited[0]=True

while D:
    v = D.popleft()
    for i in graph[v]:
        if visited[i]:continue
        visited[i]=True
        ans[i]=v
        D.append(i)
print("Yes")
for i in ans[1:]:
    print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1,int(n**(1/2))+1):
    if n%i!=0:
        continue
    x,y = i,n//i
    a=1
    b=1-x
    while 1:
        tmp = a**5-b**5
        if tmp>n and b>0:
            break
        if tmp==n:
            print(a,b)
            exit()
        a+=1
        b+=1
    a=1
    b=1-y
    while 1:
        tmp = a**5-b**5
        if tmp>n and b>0:
            break
        if tmp==n:
            print(a,b)
            exit()
        a+=1
        b+=1


Fixed submission:
n = int(input())

for a in range(500):
    for b in range(-500,500):
        if a**5-b**5==n:
            print(a,b)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1,int(n**(1/2))+1):
    if n%i!=0:
        continue
    x,y = i,n//i
    a=0
    b=-x
    while 1:
        tmp = a**5-b**5
        if tmp==n:
            print(a,b)
            exit()
        if b>0:
            break
        a+=1
        b+=1
    a=0
    b=-y
    while 1:
        tmp = a**5-b**5
        if tmp==n:
            print(a,b)
            exit()
        if b>0:
            break
        a+=1
        b+=1


Fixed submission:
n = int(input())

for a in range(500):
    for b in range(-500,500):
        if a**5-b**5==n:
            print(a,b)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1,int(n**(1/2))+1):
    if n%i!=0:
        continue
    x,y = i,n//i
    a=0
    b=-x
    while 1:
        tmp = a**5-b**5
        if tmp>n:
            if b<0:
                a+=1
                b+=1
                continue
            break
        if tmp==n:
            print(a,b)
            exit()
        a+=1
        b+=1
    a=0
    b=-y
    while 1:
        tmp = a**5-b**5
        if tmp>n:
            if b<0:
                a+=1
                b+=1
                continue
            break
        if tmp==n:
            print(a,b)
            exit()
        a+=1
        b+=1


Fixed submission:
n = int(input())

for a in range(500):
    for b in range(-500,500):
        if a**5-b**5==n:
            print(a,b)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import itertools
k = int(input())

ans=k*(k+1)//2
l = [int(i) for i in range(1,k+1)]
for i in itertools.combinations(l,3):
    ans += fractions.gcd(fractions.gcd(i[0],i[1]),i[2])*6

for i in itertools.combinations(l,2):
    ans += fractions.gcd(i[0],i[1])*6

print(ans)

Fixed submission:
import fractions
import itertools
k = int(input())

ans=k*(k+1)//2
for a in range(1,k+1):
    for b in range(a+1,k+1):
        t = fractions.gcd(a,b)
        for c in range(b,k+1):
            ans+=fractions.gcd(t,c)*6

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def f(x):
    return x*(x-1)//2

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

d = collections.defaultdict(int)
for i in a:
    d[i]+=1
c = collections.defaultdict(int)
for i in set(a):
    ans=0
    for j in d:
        if j==i:
            ans+=f(d[j]-1)
        else:
            ans+=f(d[j])
    c[i]=ans

for i in a:
    print(c[i])

Fixed submission:
def f(x):
    return x*(x-1)//2

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

d = collections.defaultdict(int)
for i in a:
    d[i]+=1
c = collections.defaultdict(int)
ans=0
for i in set(a):
    ans+=f(d[i])

for i in a:
    print(ans-(d[i]-1))

Buggy python submission (verdict: Time Limit Exceeded):
def f(x):
    return x*(x-1)//2

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

d = collections.defaultdict(int)
for i in a:
    d[i]+=1

for i in a:
    ans=0
    for j in d:
        if j==i:
            ans+=f(d[j]-1)
        else:
            ans+=f(d[j])
    print(ans)

Fixed submission:
def f(x):
    return x*(x-1)//2

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

d = collections.defaultdict(int)
for i in a:
    d[i]+=1
c = collections.defaultdict(int)
ans=0
for i in set(a):
    ans+=f(d[i])

for i in a:
    print(ans-(d[i]-1))
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

s = input()
q = int(input())

reverse = False
for i in range(q):
    l = input().split()
    if l[0]=="1":
        reverse = not(reverse)
    else:
        if l[1]=="1":
            if reverse:
                s += l[2][::-1]
            else:
                s = l[2] + s
        else:
            if reverse:
                s = l[2][::-1] + s
            else:
                s += l[2]

if reverse:
    print(s[::-1])
else:
    print(s)


Fixed submission:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

s = input()
q = int(input())


sentou = ""
matubi = ""
reverse = False
for i in range(q):
    l = input().split()
    if l[0]=="1":
        reverse = not(reverse)
    else:
        if l[1]=="1":
            if reverse:
                matubi += l[2][::-1]
            else:
                sentou = l[2] + sentou
        else:
            if reverse:
                sentou = l[2][::-1] + sentou
            else:
                matubi += l[2]
    #print(sentou,s,matubi)

if reverse:
    print(matubi[::-1] + s[::-1] + sentou[::-1])
else:
    print(sentou + s + matubi)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

s = input()
q = int(input())
for i in range(q):
    l = input().split()
    if l[0]=="1":
        s = s[::-1]
    else:
        if l[1]=="1":
            s = l[2]+s
        else:
            s += l[2]

print(s)


Fixed submission:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

s = input()
q = int(input())


sentou = ""
matubi = ""
reverse = False
for i in range(q):
    l = input().split()
    if l[0]=="1":
        reverse = not(reverse)
    else:
        if l[1]=="1":
            if reverse:
                matubi += l[2][::-1]
            else:
                sentou = l[2] + sentou
        else:
            if reverse:
                sentou = l[2][::-1] + sentou
            else:
                matubi += l[2]
    #print(sentou,s,matubi)

if reverse:
    print(matubi[::-1] + s[::-1] + sentou[::-1])
else:
    print(sentou + s + matubi)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

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

n,k = LI()
p = LI()

def a(num):
    return 0.5*num + 0.5

ans = 0
for i in range(n-k+1):
    ans = max(ans,sum([a(j) for j in p[i:i+k]]))
print(ans)


Fixed submission:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

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

n,k = LI()
p = LI()

def a(num):
    return (num+1)/2

l = [a(i) for i in p]
ll = [0] + list(itertools.accumulate(l))
ans=0
for i in range(n-k+1):
    ans = max(ans,ll[i+k]-ll[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

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

H,N = LI()
A = []
B = []
for i in range(N):
    a,b = LI()
    A.append(a)
    B.append(b)

dp = [inf]*(H+1)
ans = inf

dp[H] = 0

for i in range(N):
    for h in range(H+1)[::-1]:
        dp[h] = min(dp[h],dp[min(H,h+A[i])]+B[i])
print(dp[0])

Fixed submission:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

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

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

H,N = LI()
A = []
B = []
for i in range(N):
    a,b = LI()
    A.append(a)
    B.append(b)

dp = [inf]*(H+1)
ans = inf

dp[H] = 0

for i in range(N):
    for h in range(H+1)[::-1]:
        dp[h] = min(dp[h],dp[min(H,h+A[i])]+B[i])
print(dp[0])
Buggy python submission (verdict: Runtime Error):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import functools

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

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

def lcm_base(x,y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

n,m = LI()
a = LI()

lcm = lcm_list(a)
print((m//(lcm//2))-(m//lcm))

Fixed submission:
import fractions
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import functools

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

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

def lcm_base(x,y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

n,m = LI()
a = [int(i)//2 for i in LI()]

def num_of_2(x):
    c = 0
    while x%2==0:
        c+=1
        x//=2
    return c

a0 = num_of_2(a[0])
if any([num_of_2(i) != a0 for i in a]):
    print(0)
else:
    def lcm(x,y):
        return x//fractions.gcd(x,y)*y

    c = 1
    for i in a:
        c = lcm(c,i)
        if c>=inf:
            break
    
    ans = m//c
    print((ans+1)//2)
Buggy python submission (verdict: Runtime Error):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

a,b = MAP()

print(a*b//math.gcd(a,b))

Fixed submission:
import fractions
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

a,b = MAP()

print(a*b//fractions.gcd(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+= a[i]^a[j]
print(ans%MOD)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

m = 1
ans=0
for _ in range(60):
    bit = sum(i & m for i in a)
    bit //= m
    non_bit = n-bit
    ans = (ans+bit*non_bit*m)%MOD
    m <<= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
sys.setrecursionlimit(10**6)
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):

    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):

    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")

Buggy python submission (verdict: Runtime Error):
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):

    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):

    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
ef MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

s = sum(l)
tmp=0
for i in range(n):
    tmp+=l[i]
    if tmp >= s/2:
        idx = i
        break

left = sum(l[:idx+1])
right = sum(l[idx+1:])
print(abs(right-left))

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

s = sum(l)
tmp=0
for i in range(n):
    tmp+=l[i]
    if tmp >= s/2:
        p1 = tmp - (s/2)
        idx1 = i
        break

tmp=0
for i in range(n-1,-1,-1):
    tmp+=l[i]
    if tmp >= s/2:
        p2 = tmp - (s/2)
        idx2 = i
        break

if p1 <= p2:
    left = sum(l[:idx1+1])
    right = sum(l[idx1+1:])
else:
    left = sum(l[:idx2])
    right = sum(l[idx2:])
print(abs(right-left))