Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

s = input()
ans = len(s)
cube = s
hight = len(s)
while True:
    cube = cube.replace('01','').replace('10','')
    if hight == len(cube):
        ans -= len(cube)
        break
    else:
        hight = len(cube)
print(ans)

### FIXED CODE ###

s = list(input())
print(len(s) - (abs(s.count('0')-s.count('1'))))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#import numpy as np
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = map(int, input().split())
    lst.append(list(l))
    i+=1

sort_lst = sorted(lst)
i=1
k=0
for i in range(1,n+1):
    j=1
    for k in sort_lst:
        if i == k[0]:
            k.append(j)
            j+=1

#ans
for ans in lst:
    for res in sort_lst:
        if ans[0]==res[0] and ans[1] == res[1]:
            print(str(res[0]).rjust(6,'0') + str(res[2]).rjust(6,'0'))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    lst.append(list(map(int, input().split())) + [i])
    i+=1
lst = sorted(lst)
j=0
i=1
for k in lst:
    if i != k[0]:
        i=k[0]
        j=1
        k[1]=i*1000000+j
    else:
        j+=1
        k[1]=i*1000000+j

#ans
for ans in sorted(lst, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))
### BUGGY CODE ###

import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2, int(n**0.5)+1):
        while not num%i: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return col.Counter(ans)
    
n = int(input())
a = list(map(int,input().split()))

cnt = col.Counter()
for num in a:
    new = prime(num)
    for key,val in new.items():
        if val > cnt[key] : cnt[key] = val

LCM = 1
MOD = 10**9 + 7
for key,val in cnt.items(): LCM *= key**val

ans = 0
for num in a:
    b = LCM//num
    ans += b%MOD
    
print(ans%MOD)




### FIXED CODE ###

import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2, int(n**0.5)+1):
        while not num%i: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return col.Counter(ans)
    
n = int(input())
a = list(map(int,input().split()))

cnt = col.Counter()
for num in a:
    new = prime(num)
    for key,val in new.items():
        if val > cnt[key] : cnt[key] = val

LCM = 1
MOD = 10**9 + 7
for key,val in cnt.items(): LCM *= key**val %MOD

ans = 0
for num in a:
    b = LCM * pow(num, MOD-2, MOD) #割るのではなく逆元をかける
    ans += b
    
print(ans%MOD)
### BUGGY CODE ###

N,A,B=map(int, raw_input().split()) 
H=[ input() for i in range(N) ] 

def func(n , T):
	S=[]
	for x in T:
		x-=n*B
		if x>0:
			S.append(x)

	sa=A-B
	for x in S:
		if x%sa==0:
			n-=x/sa
		else:
			n-=(x/sa+1)
		if n<0:
			return False
	else:
			return True

l=0
r=10**9
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

### FIXED CODE ###

N,A,B= map(int,raw_input().split())
h=[input() for _ in range(N)]

high=max(h)
low=1

def enough(T):
	cnt=0
	for i in h:
		i-=T*B
		if i>0:
			if i%(A-B)==0:
				cnt+=i/(A-B)
			else:
				cnt+=i/(A-B)+1
	if cnt<=T:
		return True
	else:
		return False

ans=0
while low<=high:
	c= (low + high) / 2
	if enough(c):
		high=c-1
		ans=c
	else:
		low=c+1


print ans
### BUGGY CODE ###

h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=[input()for i in range(h)]
from heapq import heapify, heappop, heappush
seen=set()
gx-=1;gy-=1
SIZE=h*w
hq=[(nx-1)*w+ny-1]
while hq:
    d=heappop(hq)
    c,d=divmod(d,SIZE)
    x,y=divmod(d,w)
    if w*x +y in seen:continue
    seen.add(w*x +y)
    if x==gx and y==gy:print(c);exit()
    if x and w*(x-1)+y not in seen and maze[x-1 ][y]!="#":
        heappush(hq,(c*SIZE+w*(x-1)+y))
    if y and w*x+y-1 not in seen and maze[x][y-1]!="#":
        heappush(hq,(c*SIZE+w*x+y-1))
    if x+1<h  and w*(x+1)+y not in seen and maze[x+1][y]!="#":
        heappush(hq,(c*SIZE+w*(x+1)+y))
    if y+1<w  and w*x+y+1 not in seen and maze[x][y+1]!="#":
        heappush(hq,(c*SIZE+w*x+y+1))
    for i in range(max(0,x-2),min(h,x+3)):
        for j in range(max(0,y-2),min(w,y+3)):
            if i==x and j==y:continue
            if maze[i][j]=="."and w*i + j not in seen:
                heappush(hq,(c+1)*SIZE+w*i+j)

print(-1)


### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=[input()for i in range(h)]
from heapq import heapify, heappop, heappush
seen=set()
gx-=1;gy-=1
SIZE=h*w
hq=[(nx-1)*w+ny-1]
while hq:
    d=heappop(hq)
    c,d=divmod(d,SIZE)
    x,y=divmod(d,w)
    if w*x +y in seen:continue
    seen.add(w*x +y)
    if x==gx and y==gy:print(c);exit()
    if x and w*(x-1)+y not in seen and maze[x-1 ][y]!=35:
        heappush(hq,(c*SIZE+w*(x-1)+y))
    if y and w*x+y-1 not in seen and maze[x][y-1]!=35:
        heappush(hq,(c*SIZE+w*x+y-1))
    if x+1<h  and w*(x+1)+y not in seen and maze[x+1][y]!=35:
        heappush(hq,(c*SIZE+w*(x+1)+y))
    if y+1<w  and w*x+y+1 not in seen and maze[x][y+1]!=35:
        heappush(hq,(c*SIZE+w*x+y+1))
    for i in range(max(0,x-2),min(h,x+3)):
        for j in range(max(0,y-2),min(w,y+3)):
            if i==x and j==y:continue
            if maze[i][j]==46 and w*i + j not in seen:
                heappush(hq,(c+1)*SIZE+w*i+j)

print(-1)
### BUGGY CODE ###

N,M = map(int,input().split())
A = [list(input().split())for i in range(M)]
ans = 0
pen = 0
r = []
for i in range(len(A)):
  if A[i][1] == 'AC':
    r.append(A[i][0])
R = list(set(r))
ans = len(R)
for _ in range(ans):
  for j in range(len(A)):
    if A[j][0] == R[0] and A[j][1] == 'AC':
      del R[0]
      break
    if A[j][0] == R[0] and A[j][1] == 'WA':
      pen+=1
print(ans,pen)

### FIXED CODE ###

N,M = map(int,input().split())
ans = [0]*N
pen = [0]*N
for _ in range(M):
  p,S = input().split()
  P = int(p)
  if ans[P-1] == 1:
    continue
  elif ans[P-1] == 0:
    if S == 'AC':
      ans[P-1] += 1
    elif S == 'WA':
      pen[P-1] += 1
      
A = 0
B = 0 
for i in range(N):
  if ans[i] == 1:
    A += 1
    B += pen[i]
print(A,B)
### BUGGY CODE ###

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()

target = 0
cnt = 0
while target < n:
    x, h = xh[target]
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(target, n):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt
    while xh[target][1] < 1:
        target += 1
        if target >= n:
            break

print(cnt)

### FIXED CODE ###

import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)
### BUGGY CODE ###

import numpy as np
n = int(input())
arr = list(map(int,input().split()))

arr.sort(reverse = True)
count = 0
combiarr = [[arr[i]+arr[j] if i < j else 0 for j in range(n)] for i in range(n)]
combiarr = np.array(combiarr)
for i in range(n-2):
    long = arr[i]
    tmparr = combiarr[i+1:,i+1:] - long
    count += sum(sum(tmparr > 0))    
    
print(count)

### FIXED CODE ###

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

arr.sort(reverse=True)
count = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while j < k:
        if arr[i] < arr[j] + arr[k]:
            count += k-j
            j += 1
        else:
            k -= 1
print(count)
### BUGGY CODE ###

import copy


def score(D, c, s, t):
    S = 0
    last = [0 for _ in range(26)]
    score_by_day = []

    for day in range(1, D+1):
        ctype = t[day-1]-1
        S += s[day-1][ctype]
        last[ctype] = day

        S -= sum(c[i]*(day-last[i]) for i in range(26))
        score_by_day.append(S)

    return score_by_day


def greety1(D, c, s):
    best_t = []
    for day in range(1, D+1):
        day_idx = day - 1
        max_idx = s[day_idx].index(max(s[day_idx]))
        best_t.append(max_idx+1)
    return best_t


def inputs(get_t=False):
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for d in range(D):
        sd = list(map(int, input().split()))
        s.append(sd)
    if get_t:
        t = []
        for d in range(D):
            t.append(int(input()))
    return D, c, s


def beam_search(D, c, s, cand_t):
    base_t = [cand[0]-1 for cand in cand_t]  # t_idx
    best_t = []
    for d, cand_d in enumerate(cand_t):
        cand_s = []
        for n, cand in enumerate(cand_d):
            temp_t = copy.copy(base_t)
            temp_t[d] = cand
            cand_s.append((n, score(D, c, s, temp_t)[-1]))
        max_idx = sorted(cand_s, key=lambda x: x[1])[::-1][0][0]
        best_t.append(cand_d[max_idx])
    return best_t


def greety2(D, c, s):
    cand_t = []
    for day in range(1, D+1):
        day_idx = day - 1
        s_day = [(i, s) for i, s in enumerate(s[day_idx])]
        s_day = sorted(s_day, key=lambda x: x[1])[::-1]
        cands = [sd[0]+1 for sd in s_day[:5]]
        cand_t.append(cands)
    return cand_t


def output(types):
    for t in types:
        print(t)


if __name__ == "__main__":
    D, c, s = inputs()
    cand_t = greety2(D, c, s)
    best_t = beam_search(D, c, s, cand_t)
    output(best_t)


### FIXED CODE ###

def inputs(get_t=False):
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for d in range(D):
        sd = list(map(int, input().split()))
        s.append(sd)
    if get_t:
        t = []
        for d in range(D):
            t.append(int(input()))
    return D, c, s


def greety(D, c, s):
    best_t = []
    for day in range(1, D+1):
        day_idx = day - 1
        max_idx = s[day_idx].index(max(s[day_idx]))
        best_t.append(max_idx+1)
    return best_t


def output(types):
    for t in types:
        print(t)


if __name__ == "__main__":
    D, c, s = inputs()
    t = greety(D, c, s)
    output(t)
### BUGGY CODE ###

# encoding: "utf-8"

from collections import defaultdict

# class Stdin:
#     @staticmethod
#     def read_line(converter=str):
#         return [converter(x) for x in input().split()]
    
#     @staticmethod
#     def read_lines(n, converter=str):
#         result = list()
#         for _ in range(n):
#             result.append(Stdin.read_line(converter))
#         return result
    
#     @staticmethod
#     def convert(data, converter):
#         assert(len(data) == len(converter))
#         return tuple(map(lambda x, f: f(x), data, converter))

#     @staticmethod
#     def convert_lines(datas, n, converter):
#         return [converter(data, n, converter) for data in datas]


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return cnt   
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    i = 0
    j = len(xs)
    while i < j:
        key = xs[i]
        cnt = first_count_and_pop(xs[i:])
        i += cnt
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

### FIXED CODE ###

input()
a_list = [int(s) for s in input().split()]

count = [0]*100002

for a in a_list:
    count[a] += 1
    count[a+1] += 1
    count[a+2] += 1
    
print(max(count))
### BUGGY CODE ###

n,k,q = map(int, input().split())
Q=[]
for j in range(q):
    Q.append(input())
for l in range(1,n+1):
    a=Q.count(str(l))
    if k>(q-a):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q = map(int, input().split())
Q=[]
S=[]
if k>q:
    for i in range(n):
        print("Yes")
else:
    for j in range(q):
        Q.append(int(input()))
    for m in range(n):
        S.append(k)
    for l in range(q):
        S[Q[l]-1]+=1
    for x in range(n):
        S[x]-=q
    for z in range(n):
        if S[z]<=0:
            print("No")
        else:
            print("Yes")
### BUGGY CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))
ALL = 0
for a in A:
    ALL ^= a

ALL ^= A[0] ^ A[1]

for i in range(A[0]):
    if ALL ^ (A[0] - i) ^ (A[1] + i) == 0:
        print(i)
        sys.exit()

print(-1)

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))
ALL = 0
for a in A:
    ALL ^= a

if ALL == 0:
    print(0)
    sys.exit()

ALL ^= A[0] ^ A[1]

K = A[0] + A[1]
L = []

for i in range(40, -1, -1):
    if (1 << i) & ALL:
        L.append(1)
        K -= (1 << i)
    else:
        if K >= 2 * (1 << i):
            L.append(2)
            K -= 1 << (i + 1)
        else:
            L.append(0)

if K != 0:
    print(-1)
    sys.exit()

ans = 0
for i in range(41):
    if L[i] == 2:
        ans += 1 << (40 - i)

if ans >= A[0]:
    print(-1)
    sys.exit()

for i in range(41):
    if L[i] == 1:
        if ans + (1 << (40 - i)) < A[0]:
            ans += 1 << (40 - i)

if ans == 0:
    print(-1)
    sys.exit()

print(A[0] - ans)
### BUGGY CODE ###

data = input().rstrip().split(" ")
tele = input().rstrip().split(" ")
telepo = [int(i) for i in tele]

max = int(data[1])
limit = max
times = 0
pos = 1
experience = [1]
while max > 0:
    pos = telepo[pos - 1]
    max -= 1
    times += 1
    #print(pos)
    if pos in experience:
        length = len(experience) - experience.index(pos)
        max = max % length
        if max == 0:
            break
        while max > 0:
            pos = telepo[pos - 1]
            max -= 1
            times += 1
            #print(pos)
        break
    experience.append(pos)
print(pos)

### FIXED CODE ###

data = input().rstrip().split(" ")
tele = input().rstrip().split(" ")
telepo = [int(i) for i in tele]

max = int(data[1])
limit = max
times = 0
pos = 1
experience = [1]
check = {1}
before = 0
while max > 0:
    pos = telepo[pos - 1]
    max -= 1
    times += 1
    before = len(check)
    check.add(pos)
    if before == len(check):
        length = len(experience) - experience.index(pos)
        max = max % length
        if max == 0:
            break
        while max > 0:
            pos = telepo[pos - 1]
            max -= 1
            times += 1
            #print(pos)
        break
    experience.append(pos)
print(pos)
### BUGGY CODE ###

import sys
X = int(input())
S = int(X ** (1/5) + 1)

for i in range(X):
    for j in range(S):
        a = i ** 2
        b = j ** 2
        c = i * j
        if (i - j) * (a * (a ** 2 + c + b) + b * (c + b)) == X:
            print(i,j)
            sys.exit()
        elif (i + j) * (a * (a ** 2 - c + b) + b * (-c + b)) == X:
            print(i,-j)
            sys.exit()


### FIXED CODE ###

import sys
X = int(input())
# for i in range(1000):
#     for j in range(1000):
#         a = i ** 2
#         b = j ** 2
#         c = i * j
#         if (i - j) * (a * (a ** 2 + c + b) + b * (c + b)) == X:
#             print(i,j)
#             sys.exit()
#         elif (i + j) * (a * (a ** 2 - c + b) + b * (-c + b)) == X:
#             print(i,-j)
#             sys.exit()

for i in range(-118,120):
    for j in range(-118,120):
        if i ** 5 - j ** 5 == X:
            print(i,j)
            sys.exit()
### BUGGY CODE ###

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

mod = pow(10,9)+7
ok = 1

import math

for a in A:
    ok = ok*a//math.gcd(a,ok)

LCM = ok



counter = 0
for a in A:
    counter += LCM//a
    counter %= mod 

print(counter)

### FIXED CODE ###

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

mod = pow(10,9)+7
ok = 1

import math
from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

LCM = lcm_list(A)

import numpy as np
B = np.array(A)
C = LCM//B


print(sum(C)%mod)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])

def t(a):
    if len(a) == 1:
        return a[0][0]
    x = a[np.argmin(a[:,0]*2-a[:,1])]
    a = np.delete(a,[np.argmin(a[:,0]-a[:,1])],0)
    return ao(a) + x[0]

def ao(a):
    if len(a) == 1:
        return -a[0][1]
    x = a[np.argmin(a[:,0]*2-a[:,1])]
    a = np.delete(a,[np.argmin(a[:,0]-a[:,1])],0)
    return t(a) - x[1]

print(t(a))

### FIXED CODE ###

# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])
t = np.argsort(a[:,0]+a[:,1])[::-1]
ans = 0

for i,j in zip(t,range(n)):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]

print(ans)
### BUGGY CODE ###

import numpy as np
import queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
reach = [[False] * W for i in range(H)]
step = np.ones((H, W)) * (-1)
m = 0
q = queue.Queue()

for sh in range(H):
    for sw in range(W):
        if S[sh][sw] == '#':
            pass
        else:
            reach = [[False] * W for i in range(H)]
            step = np.ones((H, W)) * (-1)
            #dfs(sw, sh, 0)
            q.put((sw, sh, 0))
            while not q.empty():
                x, y, s = q.get()
                if x < 0 or W <= x or y < 0 or H <= y:
                    pass
                elif reach[y][x]:
                    pass
                elif S[y][x] == '#':
                    pass
                else:
                    reach[y][x] = True
                    step[y, x] = min(s, step[y, x]) if step[y, x] != -1 else s
    
                    q.put((x+1, y, s+1))
                    q.put((x-1, y, s+1))
                    q.put((x, y-1, s+1))
                    q.put((x, y+1, s+1))
    
            m = max(m, np.max(step))

print(int(m))


### FIXED CODE ###

import numpy as np
import queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
reach = [[False] * W for i in range(H)]
step = np.ones((H, W)) * (-1)
m = 0
q = queue.Queue()

for sh in range(H):
    for sw in range(W):
        if False and S[sh][sw] == '#':
            pass
        elif ((sh - 1 >= 0 and S[sh -1][sw] != '#') and  (sh + 1 < H and S[sh +1][sw] != '#')) and ((sw - 1 >= 0 and S[sh][sw-1] != '#') and  (sw + 1 < W and S[sh][sw + 1] != '#')):
            pass
        else:
            reach = [[False] * W for i in range(H)]
            step = np.ones((H, W)) * (-1)
            q.put((sw, sh, 0))
            while not q.empty():
                x, y, s = q.get()
                if x < 0 or W <= x or y < 0 or H <= y:
                    pass
                elif reach[y][x]:
                    pass
                elif S[y][x] == '#':
                    pass
                else:
                    reach[y][x] = True
                    step[y, x] = min(s, step[y, x]) if step[y, x] != -1 else s

                    q.put((x+1, y, s+1))
                    q.put((x-1, y, s+1))
                    q.put((x, y-1, s+1))
                    q.put((x, y+1, s+1))

            m = max(m, np.max(step))

print(int(m))
### BUGGY CODE ###

N, Weight = map(int, input().split())
w = []
V = []
for _ in range(N):
    w_tmp, v = map(int, input().split())
    w.append(w_tmp)
    V.append(v)

dp = [[0 for i in range(Weight+1)] for j in range(N+1)]
for i in range(Weight+1):
    dp[0][i] = 0

for i in range(N):
    for j in range(Weight+1):
        if j - w[i] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+V[i])
        else:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][Weight])

### FIXED CODE ###

N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w_tmp, v_tmp = map(int, input().split())
    weight.append(w_tmp)
    value.append(v_tmp)

dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i] = 0

for i in range(N):
    for j in range(W+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i])
        else:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])
### BUGGY CODE ###

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

sum_x = 0
for i in range(0, n):
    tmp_x = x[i]
    l_x = list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x))))
    sum_x += sum(l_x)

sum_y = 0
for i in range(0, m):
    tmp_y = y[i]
    l_y = list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_y, y))))
    sum_y += sum(l_y)

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)


### FIXED CODE ###

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

sum_x = 0
for i in range(0, n):
    sum_x += i * x[i] - (n - (i + 1)) * x[i]

sum_y = 0
for i in range(0, m):
    sum_y += i * y[i] - (m - (i + 1)) * y[i]

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)
### BUGGY CODE ###

def pri(n):
    s=[True for _ in range(n+1)]
    i=2
    while i**2<=n:
        if s[i]:
            j=i*2
            while j<=n:
                s[j]=False
                j+=i
        i+=1

    tab=[i for i in range(n+1) if s[i] and i>=2]
    return(tab)


while True:
    try:
        print(len(pri(int(input()))))
    except:
        break

### FIXED CODE ###

def pri(s,n): 
    tab=[i for i in range(n+1) if s[i] and i>=2]
    return(tab)
 
s=[True for _ in range(999999+1)]
i=2
while i**2<=999999:
    if s[i]:
        j=i*2
        while j<=999999:
            s[j]=False
            j+=i
    i+=1

while True:
    try:
        print(len(pri(s,int(input()))))
    except:
        break
### BUGGY CODE ###

numOfStation = int(input())
array = [0] * (numOfStation -1)

for i in range(numOfStation -1):
    array[i] = input().split()

for i in range(numOfStation - 1):
    time = 0
    for j in range(i, numOfStation - 1):
        nextTrain = int(array[j][1])
        #check the next train
        while time > nextTrain:
            #Additional time to catch the next one
            nextTrain += int(array[j][2])

        time += (nextTrain-time) + int(array[j][0]) #Time arrived at the next station

    print(time)

print(0)

### FIXED CODE ###

import math
numOfStation = int(input())
array = [0] * (numOfStation - 1)

for i in range(numOfStation - 1):
    array[i] = input().split()

for i in range(numOfStation - 1):
    time = 0
    for j in range(i, numOfStation - 1):
        nextTrain = int(array[j][1])
        # check the next train
        if time > nextTrain:
            # Additional time to catch the next one
            nextTrain += math.ceil((time - nextTrain)/int(array[j][2]))*int(array[j][2])

        time += (nextTrain - time) + int(array[j][0])  # Time arrived at the next station

    print(time)

print(0)