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

import sys
sys.setrecursionlimit(10**9)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

graph=[[] for _ in range(len(s))]
for i in range(len(s)):
  if match_list[i]:
    graph[i].append((i+len(t))%len(s))
#print(graph)

def dfs(u,i):
  if dist[u]!=-1:
    return dist[u]
  elif not graph[u]:
    dist[u]=0
    return 0
  else:
    if i>len(s):
      print(-1)
      sys.exit(0)
    v=graph[u][0]
    res=dfs(v,i+1)
    dist[u]=1+res
    return 1+res

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]==-1:
    dfs(i,0)
    
#print(dist)
print(max(dist))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]!=-1:
    continue
    
  d=0
  offset=0
  stack=[i]
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      offset=dist[ii]
      break    
    ii=path[ii]
    stack.append(ii)
    d+=1
  
  cnt=0
  while stack:
    p=stack.pop()
    dist[p]=offset+cnt
    cnt+=1
    
#print(dist)
print(max(dist))
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
s = 0
for i, ai in enumerate(A):
    for j in range(i+1, N):
        s += ai * A[j]
print(s%(10**9+7))

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
S = [0] * (N+1)      #累積和用のリスト
s = 0
CONST = 10**9+7

#前準備として累積和を計算
for i in range(N):
    S[i+1] = S[i] + A[i]

#積の総和を計算
for i in range(N-1):
    s += A[i] * ((S[N] - S[i+1]) % CONST)
    s %= CONST

print(s)
### BUGGY CODE ###

from fractions import gcd
N, M = map(int, input().split())
if M%N==0:
  print(M//N)
else:
  c = M%N
  b = M//N
  ls = []
  ans = 0
  x = M
  for i in range(1,b+1):
    x -= N
    if i>x:
      break
    if gcd(i,x)>ans:
      ans = gcd(i,x)
  print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
ls = []
for i in range(1,M+1):
  if M%i==0:
    j = M//i
    if i<=M//N:
      ls += [i]
    if j<=M//N:
      ls += [j]
  if M**0.5<i:
    break
print(max(ls))
### BUGGY CODE ###

from collections import Counter
from itertools import combinations
n = int(input())
a = list(map(int,input().split()))
A = [0]
for i in a:
    A.append(A[-1]+i)
ans = 0
B = Counter(A)
for i in B.values():
    if i >= 2:
        ans += len(tuple(combinations(range(i),r=2)))
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = [0]
for i in map(int,input().split()):
    A.append(A[-1]+i)
ans = 0
B = Counter(A)
for i in B.values():
    if i >= 2:
        ans += int(i*(i-1)/2)
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

for i in range(m):
    a[i], b[i] = map(int, input().split())

mat = [[0] * n for _ in range(n)]

for i in range(m):
    mat[a[i]-1][b[i]-1] = 1
    mat[b[i]-1][a[i]-1] = 1
ans = 0
for i in range(n):
    good = True
    for j in range(n):
        if mat[i][j] != 0:
            if h[i] <= h[j]:
                good = False
    if good:
        ans += 1

print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

ok = [True]*n

for i in range(m):
    a[i], b[i] = map(int, input().split())

    if h[a[i]-1] <= h[b[i]-1]:
        ok[a[i]-1] = False
    if h[b[i]-1] <= h[a[i]-1]:
        ok[b[i]-1] = False

ans = 0
for i in range(n):
    if ok[i] == True:
        ans += 1

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

import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    a[c].append(i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":q=int(q);b=s[q-1];a[b].pop(bisect.bisect_left(a[b],q));bisect.insort(a[r],q);s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):d+=1
        print(d)

### FIXED CODE ###

import bisect
n=int(input())
s=list(input())
a={chr(i):[] for i in range(97,123)}
for i,c in enumerate(s):
    bisect.insort(a[c],i+1)
for i in range(int(input())):
    p,q,r=list(map(str,input().split()))
    if p=="1":
        q=int(q)
        b=s[q-1]
        if b!=r:
            a[b].pop(bisect.bisect_left(a[b],q))
            bisect.insort(a[r],q)
            s[q-1]=r
    else:
        d=0
        for l in a.values():
            g=bisect.bisect_left(l,int(q))
            if g<len(l) and l[g]<=int(r):
                d+=1
        print(d)
### BUGGY CODE ###

R, G, B, N = tuple(map(int, input().split()))
ans = 0
for i in range(N//R+1):
    for j in range(N//G+1):
        rest = (N - R * i - G * j)
        if (0 <= rest) and rest % B == 0:
            ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = tuple(map(int, input().split()))
ans = 0
for i in range(N//R+1):
    for j in range(N//G+1):
        rest = (N - R * i - G * j)
        if rest < 0:
            break
        if rest % B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a_list = []
c = []

for i in range(m):
    a,b = map(int,input().split())
    a_list.append(a)
    c.append(sum(1 << j-1 for j in list(map(int,input().split()))))

inf = 10**10
dp = [inf]*(1 << n)
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        dp[c[j]|i] = min(dp[c[j]|i],dp[i]+a_list[j])

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

### FIXED CODE ###

n,m = map(int,input().split())
a_list = []
c = []

for i in range(m):
    a,b = map(int,input().split())
    a_list.append(a)
    c.append(sum(1 << j-1 for j in list(map(int,input().split()))))

inf = 10**10
dp = [inf]*(1 << n)
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        dp[c[j]|i] = min(dp[c[j]|i],dp[i]+a_list[j])

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])
### BUGGY CODE ###

# cook your dish here
n=int(input())
a=list(map(int,input().split()))
res=1
if 0 in a:
    print(0)
else:
    for i in a:
        res*=i
    if(res>1000000000000000000):
        print(-1)
    else:
        print(res)
        

### FIXED CODE ###

def sol():
    n=int(input())
    a=list(map(int,input().split()))
    if 0 in a:
        print(0)
        return
    prod=1 
    for i in a:
        prod*=i 
        if prod>1000000000000000000:
            print(-1)
            return
    print(prod)
    
sol()
### BUGGY CODE ###

S = input()
Q = int(input())
 
for i in range(Q):
    q = list(input().split())
 
    if (len(q) == 1):
        S = S[::-1]
    else:
        judge = q[1]
        cha = q[2]
        
        if (int(judge) == 1):
            S = cha + S
        else:
            S = S + cha
 
print(S)
 

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())
reverse = 1


for i in range(Q):
    
    q = input()
    
    if (q == '1'):
        reverse *= -1
    else:
        integer, judge, cha = q.split()
        
        if (judge == '1'):
            if (reverse == 1):
                S.appendleft(cha)
            else:
                S.append(cha)
        
        elif (judge == '2'):
            if (reverse == 1):
                S.append(cha)
            else:
                S.appendleft(cha)

if (reverse == -1):
    S.reverse()

print(''.join(list(S)))
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
import fractions

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
            
    def lcm(x,y):
        return((x*y)//fractions.gcd(x,y))
        
    ans = 0
    l = [1]
    for num in a:
        l.append(lcm(l[-1],num))
        ans = (ans*(l[-1]//l[-2])+l[-1]//num)%MOD
        
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
import fractions
from functools import reduce

def main():
    N = int(input())
    a = list(map(int,input().split()))
    MOD = 10**9+7
            
    def lcm(x,y):
        return((x*y)//fractions.gcd(x,y))
        
    l = reduce(lcm,a)
    ans = 0
    for num in a:
        ans += l//num
    
    print(ans%MOD)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import defaultdict

INF = 2 ** 60
dp = defaultdict(lambda: -INF)

n = int(input())
a = list(map(int, input().split())) + [0] * 10

dp[(0, 0)] = 0
dp[(1, 1)] = a[0]

for i in range(n):
    for j in range(i // 2 - 2, i // 2 + 3):
        dp[(i + 2, j + 1)] = max([dp[(i + 2, j + 1)], dp[(i, j)] + a[i + 1]])
        dp[(i + 1, j)] = max([dp[(i + 1, j)], dp[(i, j)]])

print(dp[(n, n // 2)])


### FIXED CODE ###

from collections import defaultdict

INF = 2 ** 60
dp = defaultdict(lambda: -INF)

n = int(input())
a = list(map(int, input().split())) + [0] * 10

dp[(0, 0)] = 0
dp[(1, 1)] = a[0]

for i in range(n):
    for j in range(i // 2 - 2, i // 2 + 3):
        dp[(i + 2, j + 1)] = max([dp[(i + 2, j + 1)], dp[(i, j)] + a[i + 1]])
        dp[(i + 1, j)] = max([dp[(i + 1, j)], dp[(i, j)]])

print(dp[(n, n // 2)])
### BUGGY CODE ###

import sys

sys.setrecursionlimit(100000)

N = int(input())
palette = {1:1}
colors = [None] * N
ends = [None] * N
edges = {}

for edge in range(1,N):
    ends[edge] = [int(n) for n in input().split()]

    a, b = ends[edge]
    if a not in edges:
        edges[a] = [edge]
    else:
        edges[a].append(edge)
    if b not in edges:
        edges[b] = [edge]
    else:
        edges[b].append(edge)


def color_edges(parent, root):
    current_palette = palette.copy()
    if parent > 0:
        del current_palette[colors[parent]]
    for edge in edges[root]:
        if colors[edge]:
            continue
        if len(current_palette) > 0:
            colors[edge] = current_palette.popitem()[0]
        else:
            color = len(palette) + 1
            palette[color] = 1
            colors[edge] = color
    for edge in edges[root]:
        if edge == parent:
            continue
        a, b = ends[edge]
        if a == root:
            color_edges(edge, b)
        else:
            color_edges(edge, a)

max_edges = 1
root = 1
for node in range(1,N+1):
    if len(edges[node]) > max_edges:
        max_edges = len(edges[node])
        root = node

color_edges(0, root)

print(len(palette))
for edge in range(1,N):
    print(colors[edge])


### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

N = int(input())
palette = 1
colors = {}
ends = {}
edges = {}

for edge in range(1,N):
    ends[edge] = [int(n) for n in input().split()]

    a, b = ends[edge]
    if a not in edges:
        edges[a] = [edge]
    else:
        edges[a].append(edge)
    if b not in edges:
        edges[b] = [edge]
    else:
        edges[b].append(edge)


def color_edges(parent, root):
    ng = {}
    global palette
    if parent > 0:
        ng[colors[parent]] = True
    for edge in edges[root]:
        if edge in colors:
            color = colors[edge]
        elif palette - len(ng) > 0:
            color = 1
            while color in ng:
                color += 1
            colors[edge] = color
        else:
            palette += 1
            color = palette
            colors[edge] = color

        ng[color] = True
    for edge in edges[root]:
        if edge == parent:
            continue
        a, b = ends[edge]
        if a == root:
            color_edges(edge, b)
        else:
            color_edges(edge, a)

max_edges = 1
root = 1
for node in range(1,N+1):
    if len(edges[node]) > max_edges:
        max_edges = len(edges[node])
        root = node

color_edges(0, root)

print(palette)
for edge in range(1,N):
    print(colors[edge])
### BUGGY CODE ###

N=int(input())
tmp=input().split(" ")

list=[]
for i in range(N-1):
    list.append(int(tmp[i]))

count=0
for i in range(1,N+1):
    for j in range(N-1):
        if i==list[j]:
            count+=1
    print(count)
    count=0

### FIXED CODE ###

N=int(input())
tmp=input().split(" ")

list=[]
for i in range(N-1):
    list.append(int(tmp[i]))

answer=[0]*N

for i in range(N-1):
    answer[list[i]]+=1
answer.append(0)

for i in range(1,N+1):
    print(answer[i])
### BUGGY CODE ###

from collections import Counter


def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))

    L = [i+a for i, a in enumerate(A)]
    R = [i-a for i, a in enumerate(A)]
    #print(L)
    #print(R)

    #はじめL_t = defaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    '''
    L_t = defaultdict(int)
    for i, l in enumerate(L):
        L_t[l] += 1
    R_t = defaultdict(int)
    for j, r in enumerate(R):
        R_t[r] += 1
    '''
    L_t = Counter(L)
    R_t = Counter(R)
    x_max = max(L)
    x_min = min(R)
    cnt = 0
    for x in range(x_min, x_max+1):
        l_candidate = L_t[x]
        r_candidate = R_t[x]

        cnt += l_candidate * r_candidate

    print(cnt)


if __name__ == "__main__":
    main()

### FIXED CODE ###

#解説を見て実装
from collections import Counter

def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))
    L = [i+a for i, a in enumerate(A)]
    R = [i-a for i, a in enumerate(A)]
    #print(L)
    #print(R)

    #はじめL_t = defaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    L_t = Counter(L)
    R_t = Counter(R)
    cnt = 0
    x_candidate = set(L) & set(R)
    for x in x_candidate:
        l_candidate = L_t[x]
        r_candidate = R_t[x]
        cnt += l_candidate * r_candidate

    print(cnt)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    
    for i in list(range(1, N, 2)):
        if A.count(i) != 2:
            ans = 0
            break
            
else:
    if A.count(0) == 1:
        for i in list(range(2, N, 2)):
            if A.count(i) != 2:
                ans = 0
                break
    else:
        ans = 0

if ans == 0:
    print(0)
else:
    print((2**(N//2))%(10**9+7))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    if len(A) != 2*len(set(A)):
        ans = 0
else:
    if A.count(0) == 1:
        A.remove(0)
        if len(A) != 2*len(set(A)):
            ans = 0
    else:
        ans = 0
if ans == 0:
    print(0)
else:
    print((2**(N//2))%(10**9+7))
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
n_a = 0
n_b = 0
t_a = 0
t_b = 0

for i in range(len(A)):
    if sum(A[0:i + 1]) <= K:
        n_a += 1
        t_a += A[i]
        continue
    else:
        break
# print(n_a)
# print(t_a)

for i in range(len(B)):
    if sum(B[0:i + 1]) <= K:
        n_b += 1
        t_b += B[i]
        continue
    else:
        break
# print(n_b)
# print(t_b)

if n_a >= n_b:
    n_b = 0
    t_b = 0
    for i in range(len(B)):
        if sum(B[0:i + 1]) <= K - t_a:
            n_b += 1
            t_b += B[i]
            continue
        else:
            break
    # print(n_b)
    # print(t_b)

else:
    n_a = 0
    t_a = 0
    for i in range(len(A)):
        if sum(A[0:i + 1]) <= K - t_b:
            n_a += 1
            t_a += A[i]
            continue
        else:
            break
    # print(n_a)
    # print(t_a)

print(n_a + n_b)


### FIXED CODE ###

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

# A,Bそれぞれの累積和を作る
# 初期値は0冊目まで読んだときの値（ここでは0）を入れておく
a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

# 読める最大の冊数
ans = 0

# Bは全て（=M冊目まで）読めることを初期値とする
# Aの山で読む本を増やすにつれて、jは（広義）単調減少する
j = M

# Aの山について、何冊目まで読むか
for i in range(N + 1):

    # Aの山だけでK分オーバーの場合
    # これ以上iを増やしても無意味なので打ち切る
    if a[i] > K:
        break

    # a[i]+b[j] > K　ならjをデクリメント
    # Bの山を全て読めると仮定した後、下の方から一冊ずつ諦める
    # jはiの増加に対して広義単調減少（しゃくとり法）、Mから0まで一回走査するだけで良い
    while b[j] > K - a[i]:
        j -= 1

    # 冊数はi+j、全てのiに対してi+jを比較、最大のものが答え
    ans = max(ans, i + j)

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

N, W = map(int, input().split())

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

for i in range(1,N+1):
  w, v = map(int,input().split())
  for j in range(0,W+1):
    if (j-w) >=0:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
  #print(dp)
  
  
ans = dp[N][W]
print(ans)

### FIXED CODE ###

N, W = map(int, input().split())

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

for i in range(1,N+1):
  w, v = map(int,input().split())
  for j in range(0,W+1):
    if (j-w) >=0:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
  #print(dp)
  
  
ans = dp[N][W]
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
tmp = 0
lr = [0]
for a in A:
    tmp += a
    lr.append(tmp)

ans = float('inf')


for i in range(2, N - 1):
    f=1
    g=i+1
    while abs(lr[i] - lr[f] - lr[f]) > abs(lr[i] - lr[f + 1] - lr[f + 1]):
        f += 1
    while abs((lr[-1] - lr[g]) - (lr[g] - lr[i])) > abs((lr[-1] - lr[g + 1]) - (lr[g + 1] - lr[i])):
        g += 1
    l = (lr[f], lr[i] - lr[f], lr[-1] - lr[g], lr[g] - lr[i])
    ans = min(ans, max(l) - min(l))

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
tmp = 0
lr = [0]
for a in A:
    tmp += a
    lr.append(tmp)

ans = float('inf')

f=1
g=3
for i in range(2, N - 1):

    while abs(lr[i] - lr[f] - lr[f]) > abs(lr[i] - lr[f + 1] - lr[f + 1]):
        f += 1
    while abs((lr[-1] - lr[g]) - (lr[g] - lr[i])) > abs((lr[-1] - lr[g + 1]) - (lr[g + 1] - lr[i])):
        g += 1
    l = (lr[f], lr[i] - lr[f], lr[-1] - lr[g], lr[g] - lr[i])
    ans = min(ans, max(l) - min(l))

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

import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()

strings = [[] for _ in range(n // 2 + 1)]

for i in range(n):
    string = [s[i]]
    strings[1].append(s[i])
    for j in range(i + 1, n):
        string.append(s[j])
        if j - i + 1 < 1 + n // 2:
            strings[j - i + 1].append("".join(string))

ans = 0

for i in range(n // 2, 0, -1):
    check = strings[i]
    for j in range(len(check)):
        check_set = set(check[j + i:])
        if check[j] in check_set:
            print(i)
            sys.exit()

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

ans = 0

for i in range(n):
    s_ = s[i:]
    z_s = z_algo(s_)
    for j in range(len(z_s)):
        ans = max(ans, min(j, z_s[j]))

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

n=int(input())
res=0
table=[1]*(n+1)
for i in range(2,n+1):
  for j in range(i,n+1,i):
    table[j]+=1
  res+=table[i]*i
print(res+1)


### FIXED CODE ###

n=int(input())
res=0
for i in range(1,n+1):
  ahaha=n//i
  res+=(i+ahaha*i)*ahaha//2
print(res)
### BUGGY CODE ###

s = input()
l = len(s)

while True:
  if '01' in s or '10' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
  else:
    break

print(l - len(s))

### FIXED CODE ###

s = input()
print(2 * min([sum([v == '1' for v in s]), sum([v == '0' for v in s])]))
### BUGGY CODE ###

def sign(x):
    if x==0:
        return 0
    else:
        return abs(x)//x
def flag(x,y):
    return sign(x)==sign(y)
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
if A1*T1+A2*T2==B1*T1+B2*T2:
    print("infinity")
    exit()
ans=0
X=(B1-A1)*T1
Y=(B2-A2)*T2
tmp=0
while(1):
    if tmp==0:
        tmp+=X
    else:
        if not(flag(tmp,tmp+X)):
            ans+=1
            tmp+=X
    if tmp==0:
        tmp+=Y
    else:
        if not(flag(tmp,tmp+Y)):
            ans+=1
            tmp+=Y
    if flag(tmp,tmp+X) and flag(tmp+X,tmp+X+Y):
        break
print(ans)

### FIXED CODE ###

T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
X=(B1-A1)*T1
Y=(B2-A2)*T2
if X>0:
    X=-X
    Y=-Y
if X+Y<0:
    print(0)
elif X+Y==0:
    print("infinity")
else:
    A=(-X)//(X+Y)
    B=(-X)%(X+Y)
    if B!=0:
        print(2*A+1)
    else:
        print(2*A)
### BUGGY CODE ###

N, C = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))

times = [0] * 2 * (10 ** 5 + 1)
channel = [[0] * 2 * (10 ** 5 + 1) for _ in range(C)]
for i in range(N):
    s, t, c = items[i]
    c -= 1
    channel[c][2 * s - 1] += 1
    channel[c][2 * t] -= 1

for c in range(C):
    for i in range(len(times) - 1):
        channel[c][i + 1] += channel[c][i]
        if channel[c][i + 1] >= 1:
            times[i + 1] += 1

print(max(times))


### FIXED CODE ###

N, C = map(int, input().split())
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = map(int, input().split())
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5):
        if t == 10 ** 5:
            continue
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1
x = 0
for t in range(1, 10**5+1):
    count = count_list[t]
    if count > x:
        x = count
print(x)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
h = tuple(map(lambda x:int(x)-1,input().split()))
a = tuple(map(int,input().split()))

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))

#初期化
#num : nより大きい最小の2のべき乗
num = 1
while num <= n:
    num *= 2
seg = [0]*(2*num-1)

#dp[i]:i番目が最後となる時の美しさの最大値
dp = [a[0]] + [0]*(n-1)
update(h[0],a[0])
for i in range(1,n):
    dp[i] = max(0,query(0,h[i],0,0,num))+a[i]
    update(h[i],dp[i])

print(max(dp))


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
h = tuple(map(lambda x:int(x)-1,input().split()))
a = tuple(map(int,input().split()))

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))

#初期化
#num : nより大きい最小の2のべき乗
num = 1
while num <= n:
    num *= 2
seg = [0]*(2*num-1)

#dp[i]:i番目が最後となる時の美しさの最大値
dp = [a[0]] + [0]*(n-1)
update(h[0],a[0])
for i in range(1,n):
    dp[i] = max(0,query(0,h[i],0,0,num))+a[i]
    update(h[i],dp[i])

print(max(dp))
### BUGGY CODE ###

n = int(input())
*A, = map(int, input().split())
X = []
for _ in range(n):
    X += [sum(A[::2])-sum(A[1::2])]
    A += [A.pop(0)]
print(*X)

### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
X = []
p = sum(A[::2])
q = sum(A[1::2])
for a in A:
    X += [p-q]
    p, q = q+a, p-a
print(*X)