Harryxun/stf_run huggingface dataset:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
print(a.most_common()[0]==b.most_common()[0])
print(len(list_1),a.most_common()[0][1])
if ((a.most_common()==b.most_common()) & a.most_common()[0][1]==len(list_1)):#２つの数列の全要素が一致する場合どちらかの数字を変更
  print('test1')
  print(n//2)
elif(a.most_common()[0]==b.most_common()[0]):#2つの数列の最大をとる数が等しい場合どちらかは最大個数の数に、もう１つはその次に多い数に置き換える。
  print('test2')
  print(n-a.most_common()[0][1]-b.most_common()[1][1])
else:
  print(n-a.most_common()[0][1]-b.most_common()[0][1])

### FIXED CODE ###

import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a.most_common()[0]==b.most_common()[0])
#print(len(list_1),a.most_common()[0][1])
if((a.most_common()[0]==b.most_common()[0]) & (a.most_common()[0][1]!=len(list_1))):#2つの数列の最大をとる数が等しい場合どちらかは最大個数の数に、もう１つはその次に多い数に置き換える。
  #print('test2')
  if(n-a.most_common()[0][1]-b.most_common()[1][1]>n-a.most_common()[1][1]-b.most_common()[0][1]):
  	print(n-a.most_common()[1][1]-b.most_common()[0][1])
  else:
    print(n-a.most_common()[0][1]-b.most_common()[1][1])
elif ((a.most_common()==b.most_common()) & (a.most_common()[0][1]==len(list_1))):#２つの数列の全要素が一致する場合どちらかの数字を変更
  #print('test1')
  print(n//2)
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
count = [[0]*N for _ in range(N)]
fr = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    if count[a][b] == 1:
        continue
    count[a][b] = 1
    count[b][a] = 1
    fr[a].append(b)
    fr[b].append(a)
used = [-1]*N 
MAX = 0
def dfs(fr,cur,parent):
    global cnt
    children = fr[cur]
    for chi in children:
        if used[chi] != -1:
            continue
        if chi == parent:
            continue
        used[chi] = 0
        cnt += 1
        dfs(fr,chi,cur)
    return

for i in range(N):
    cnt = 1
    if used[i] != -1:
        continue
    used[i] = 0
    dfs(fr,i,-1)
    MAX = max(MAX, cnt)
print(MAX)

            








### FIXED CODE ###

# Union Find
#0オリジン以下注意

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
def unite(x, y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きい方がx
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y] #ここで集合の個数を更新している
        par[y] = x
        return True
    
#xとyが同じ集合に含まれているかどうかを判定(同じ集合にあればTrue)
def same(x, y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size, 子なら親の頂点
n, m = map(int, input().split())
par = [-1]*n
for i in range(m):
    a, b = map(int, input().split())
    unite(a-1, b-1)
M = 0
for i in range(n):
    M = max(M, size(i))
print(M)

################以下にコードを書く
######2次元配列が与えられたら１次元に直す必要あり
s = input()
print(s[:4]+' '+s[4:])

### FIXED CODE ###

s = input()
print(s[:4]+' '+s[4:])
def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)

### FIXED CODE ###

def readinput():
    n=int(input())
    x=list(map(int,input().split()))
    return n,x

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main2(n,x)
    print(ans)
x,y=map(int,input().split())
print(int(x+y/2)

### FIXED CODE ###

x,y=map(int,input().split())
print(int(x+y/2))
from functools import reduce

def cin():  return list(map(int,input().split()))

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

def nHr(n, r):  
    if n == 0:  return 1
    return cmb(n + r - 1, n)

INF = 10 ** 9 + 7

N, K = cin()
ans = [N - K + 1]
for i in range(2, K + 1):
    cnt = cmb(N - K + 1, i) * nHr(K - i, i)
    ans.append(cnt % INF)

for i in range(K):  print(ans[i])

### FIXED CODE ###

from functools import reduce

def cin():  return list(map(int,input().split()))

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

def nHr(n, r):  
    if n == 0:  return 1
    return cmb(n + r - 1, n)

N, K = cin()

INF = 10 ** 9 + 7

ans = [N - K + 1]
for i in range(2, K + 1):
    b = nHr(K - i, i)
    cnt = 0
    tmp = N - K - (i + 1)
    if tmp >= 0:
        cnt += b * nHr(tmp, i + 1)
        cnt %= INF
    tmp += 1
    if tmp >= 0:
        cnt += 2 * b * nHr(tmp, i)
        cnt %= INF
    tmp += 1
    if tmp >= 0:
        cnt += nHr(tmp, i - 1) * b
        cnt %= INF
    ans.append(cnt)

for i in range(K):  print(ans[i])
S = input()
T = input()
ans = 0
for i, ch in enumerate(S):
  if ch != T[i]:
    ans += 1
return ans

### FIXED CODE ###

S = input()
T = input()
ans = 0
for i, ch in enumerate(S):
  if ch != T[i]:
    ans += 1
print(ans)
def next_array(array):#辞書式に次の配列を与える関数
	s = -1
	for x in array[::-1]:
    	if x < M:
        	break
        else:
        	s -= 1
    #Mより小さい最後の項を取得
    
    if s >= -N:
    	array[s] += 1#その項を１増やす
    	if s < -1:
      		for i in range(s+1,0):#以降の項を全て同じ値に
      			array[i] = array[s]
        
	return array
 
def score(array, rules):#点数計算
	scr = 0
	for rule in rules:
    	if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
        	scr += rule[3]
    return scr
 
 
# input
N, M, Q = map(int, input().split())
rules = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    rules.append([a, b, c, d])
    
array　= [1] * N
max_scr = 0
 
while True:
	max_scr = max(max_scr, score(array,rules)) 
	if array[0] == M:#全探索完了
		break 
	array = next_array(array)#次の配列へ
    
print(max_scr)

### FIXED CODE ###

def next_array(array):#辞書式に次の配列を与える関数
  s = -1
  for x in array[::-1]:
    if x < M:
      break
    else:
      s -= 1
    #Mより小さい最後の項を取得
  
  if s >= -N:
    array[s] += 1#その項を１増やす
    if s < -1:
      for i in range(s+1,0):#以降の項を全て同じ値に
        array[i] = array[s]

  return array
 
def score(array, rules):#点数計算
  scr = 0
  for rule in rules:
    if (array[rule[1]-1] - array[rule[0]-1] == rule[2]):
      scr += rule[3]
      
  return scr
 
# input
N, M, Q = map(int, input().split())
rules = []
 
for i in range(Q):
  a, b, c, d = map(int, input().split())
  rules.append([a, b, c, d])
  
array = [1] * N
max_scr = 0
 
while True:
  max_scr = max(max_scr, score(array,rules)) 
  if array[0] == M:#全探索完了
    break 
  array = next_array(array)#次の配列へ
    
print(max_scr)
import numpy as np
S = input()
u, counts = np.unique(list(S),return_counts=True)
result = 0 if len(u) == 1 else len(S) - abs(counts[0]-counts[1])
print(result)

### FIXED CODE ###

S = input()
num_0 = list(S).count('0')
num_1 = list(S).count('1')
print(len(S) - abs(num_0 - num_1))
n=int(input())
a=sorted(list(map(int,input().split())))
if a[n-1]<=0:
  print(2*a[n-1]-sum(a))
  s=a[n-1]
  for i in a[:-1]:
    print(s,i)
    s-=i
elif a[0]>=0:
  print(sum(a)-2*a[0])
  s=a[0]
  for i in a[1:]:
    print(i,s)
    s=i-s
else:
  m=0
  for i in n:
    if a[i]>=0:
      k=i
      break
    m-=a[i]
  print(m+sum(a[k:]))
  s=a[0]
  for i in a[k:-1]:
    print(s,i)
    s-=i
  print(a[-1],s)
  s=a[-1]-s
  for i in a[1:k]:
    print(s,i)
    s-=i

### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
if a[-1]<=0:
  print(2*a[-1]-sum(a))
  s=a[-1]
  for i in a[:-1]:
    print(s,i)
    s-=i
elif a[0]>=0:
  print(sum(a)-2*a[0])
  s=a[0]
  for i in a[1:-1]:
    print(s,i)
    s-=i
  print(a[-1],s)
else:
  m=0
  for i in range(n):
    if a[i]>=0:
      k=i
      break
    m-=a[i]
  print(m+sum(a[k:]))
  s=a[0]
  for i in a[k:-1]:
    print(s,i)
    s-=i
  print(a[-1],s)
  s=a[-1]-s
  for i in a[1:k]:
    print(s,i)
    s-=i
s = input()
k = s[::2]
g = s[1::2]

if k == "R","U","D" and g == "L","U","D":
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s=input()
if "L" in s[::2] or "R" in s[1::2]:
  print("No")
else:
  print("Yes")
#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1

divT = [1/i for i in range(1,n+1)]

from functools import lru_cache### これの練習
@lru_cache(100000)

def f(x,y,z):
    if x==y==z==n:
        return 0
    res = 0
    delta = n*divT[n-z-1]
    if x != n:
        res += (f(x+1,y,z) + delta) * (n-x)
    if y != x:
        res += (f(x,y+1,z) + delta) * (x-y)#x+1,y+1ではない
    if z != y:
        res += (f(x,y,z+1) + delta)* (y-z)#x+1,y+1,z+1ではない
    res *=divT[n-z-1]
    return res
    

print(f(cnt[1]+cnt[2],cnt[2],0))


### FIXED CODE ###

#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1
dp = [[[0 for _ in range(n+1)] for __ in range(n+1)] for ___ in range(n+1)]

dp[n][n][n] = 0
divT = [1/i for i in range(1,n+1)]

for x in range(n,cnt[1]+cnt[2]-1,-1):## -2だったのを-1に
    for y in range(x,cnt[2]-1,-1):##cnt[2]
        for z in range(y,-1,-1):
            delta = n*divT[n-z-1]#2枚以下を引くまで
            if x != n:
                dp[x][y][z] += (dp[x+1][y][z] + delta) * (n-x)
            if y != x:
                dp[x][y][z] += (dp[x][y+1][z] + delta) * (x-y)#x+1,y+1ではない
            if z != y:
                dp[x][y][z] += (dp[x][y][z+1] + delta)* (y-z)#x+1,y+1,z+1ではない
            dp[x][y][z] *=divT[n-z-1]

print(dp[cnt[1]+cnt[2]][cnt[2]][0])
N = int(input())
list = list(map(int,input().split()))

ans = 0
for i in range(N-2):
  if list[i+1] > List[i] and list[i+1] < List[i+2]:
    ans+=1
  if list[i+1] < List[i] and list[i+1] > List[i+2]:
    ans+=1
  else:
    pass

print(ans)

### FIXED CODE ###

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

ans=0

for i in range(N-2):
  if L[i] < L[i+1] and  L[i+1] < L[i+2]:
    ans +=1 
  if L[i] > L[i+1] and  L[i+1] > L[i+2]:
    ans +=1 
  else:
    pass

print(ans)
s = input()
r_cnt = 0
b_cnt = 0
for color in s:
  if color == 'R':
    r_cnt += 1
    if r_cnt > (s.length/2):
      print('Yes')
      break
  else:
    b_cnt += 1
    if b_cnt > (s.length/2):
      print('No')
      break
else:
  if r_cnt > b_cnt:
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

n=input()
s = input()
r_cnt = 0
b_cnt = 0
for color in s:
  if color == 'R':
    r_cnt += 1
  else:
    b_cnt += 1
else:
  if r_cnt > b_cnt:
    print('Yes')
  else:
    print('No')
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = [-1] * (2*10**5+2)  # aを入れてindexを返す
Plus = [0]*N  # indexを入れて1か0
Next = [0]*N  # indexを入れてindex
for i, a in enumerate(A):
    l = L[a]
    if l==-1:
        L[a] = i
    else:
        Next[l] = i+1
        L[a] = i

if l!=-1:
    Next[l] = 0
    Plus[l] = 1
#print(Next)

for i, a in enumerate(A):
    l = L[a]  # あなたはどこから来たの
    if i <= l:
        Next[l] = i+1
        Plus[l] += 1
        L[a] = -1


#
# print(Next)
# print(Plus)

loop = Plus[0]
i = Next[0]
while i!=0:
    i_next = Next[i]
    if i_next==N:
        loop += 1
        i_next = 0
    #if i_next <= i:
    #    loop += 1
    loop += Plus[i]

    i = i_next
#
# print(loop)

TrueNext = Next.copy()
for i in range(N-1,-1,-1):
    p = Plus[i]
    if p==0:
        TrueNext[i] = TrueNext[TrueNext[i]]
#
# print(TrueNext)

k = K % loop
if k==0:
    exit()

start = 0
for i in range(k-1):
    start = TrueNext[start]
# print(start)

ans = []#[A[start]]
S = [0] * (2*10**5+2)
#S[ans[0]] = 1
for a in A[start:]:
    #print(a, ans)
    if S[a]==0:
        ans.append(a)
        S[a] = 1
    else:
        while S[a] != 0:
            a_ = ans.pop()
            S[a_] = 0
print(*ans)


### FIXED CODE ###

# クソコードすぎる
N, K = map(int, input().split())
A = list(map(int, input().split()))
if N==1:
    if K%2==1:
        print(A[0])
    exit()
L = [-1] * (2*10**5+2)  # aを入れてindexを返す
Plus = [0]*N  # indexを入れて1か0
Next = [0]*N  # indexを入れてindex
for i, a in enumerate(A):
    l = L[a]
    if l==-1:
        L[a] = i
    else:
        Next[l] = i+1
        L[a] = i

if l!=-1:
    Next[l] = 0
    Plus[l] = 1
#print(Next)

for i, a in enumerate(A):
    l = L[a]  # あなたはどこから来たの
    if i <= l:
        Next[l] = i+1
        Plus[l] += 1
        L[a] = -1


#
# print(Next)
# print(Plus)

loop = Plus[0]
i = Next[0]
while i!=0:
    i_next = Next[i]
    if i_next==N:
        loop += 1
        i_next = 0
    #if i_next <= i:
    #    loop += 1
    loop += Plus[i]

    i = i_next
#
# print(loop)

TrueNext = Next.copy()
for i in range(N-1,-1,-1):
    p = Plus[i]
    if p==0:
        nn = TrueNext[i]
        if nn==N:
            nn = 0
        TrueNext[i] = TrueNext[nn]
#
# print(TrueNext)

k = K % loop
if k==0:
    exit()

start = 0
i=0
while i<k-1:
    if start==N:
        start=0
        i+=1
    if i==K-1:
        break
    start = TrueNext[start]
    i+=1
# print(start)

ans = []#[A[start]]
S = [0] * (2*10**5+2)
#S[ans[0]] = 1
for a in A[start:]:
    #print(a, ans)
    if S[a]==0:
        ans.append(a)
        S[a] = 1
    else:
        while S[a] != 0:
            a_ = ans.pop()
            S[a_] = 0
print(*ans)
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
#dp問題と予想
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    ans+=p[i]
P.sort()
Q=[]
for i in range(Y):
    Q.append(q[i])
    ans+=q[i]
Q.sort()
rc=0
gc=0
tc=0
fr=False
fg=False
while(1):
    val1=ans
    val2=ans
    if tc>(C-1):
        break
    if rc>(A-1):
        fr=True
    if gc>(B-1):
        fg=True
    if fr and fg:
        break
    if fr:
        b=r[tc]-Q[gc]
        if b<=0:
            break
        val2+=b
        ans=val2
        gc+=1
        tc+=1
    if gc:
        a=r[tc]-P[rc]
        if a<=0:
            break
        val1+=a
        ans=val1
        rc+=1
        tc+=1
    a=r[tc]-P[rc]
    b=r[tc]-Q[gc]
    if a<=0 and b<=0:
        break

    val1+=a
    val2+=b
    if val1>val2:
        rc+=1
        tc+=1
        ans=val1
    else:
        gc+=1
        tc+=1
        ans=val2

print(ans)

### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    #ans+=p[i]
for i in range(Y):
    P.append(q[i])
    #ans+=q[i]
P.sort()
tmp=0
Q=[]
count=0
for i in range(C):
    if count>=(X+Y):
        break
    if r[i]>P[count]:
        Q.append(r[i])
        count+=1
    else:
        break
R=[]
ans=0
for i in range(len(Q)):
    ans+=Q[i]
for i in range(len(Q),X+Y):
    ans+=P[i]
#print(P)
#print(Q)
print(ans)
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku v2
def count(i,n,j,m,a,b,k):
    if k<0:
        return -1
    if i==n and j==m:
        return 0
    if i==n:
        if b[j]<=k:
            return 1+count(i,n,j+1,m,a,b,k-b[j])
        return 0
    if j==m:
        if a[i]<=k:
            return 1+count(i+1,n,j,m,a,b,k-a[i])
        return 0
    return max(1+count(i,n,j+1,m,a,b,k-b[j]),1+count(i+1,n,j,m,a,b,k-a[i]))

n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;
print(count(i,n,j,m,a,b,k))'''

'''C M1'''
n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;cnt=0;cnt1=0;cnt2=0;la=n;lb=m;k1=k;k2=k
while i<la and k1>0:
    if a[i]<=k1:
        cnt1+=1
        k1-=a[i]
        i+=1
    else:
        break
i=0;j=0
while j<lb and k2>0:
    if a[j]<=k2:
        cnt2+=1
        k2-=a[j]
        j+=1
    else:
        break
i=0;j=0
while (i<la or j<lb) and k>0:
    if i==la:
        if b[j]<=k:
            cnt+=1
            k-=b[j]
            j+=1
        else:
            break
    elif j==lb:
        if a[i]<=k:
            cnt+=1
            k-=a[i]
            i+=1
        else:
            break
    elif a[i]<=b[j]:
        if a[i]<=k:
            k-=a[i]
            cnt+=1
            i+=1
        else:
            break
    else:
        if b[j]<=k:
            k-=b[j]
            cnt+=1
            j+=1
        else:
            break
print(max(cnt,cnt1,cnt2))

### FIXED CODE ###

import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
n,m,k=rm()
a=rl()
b=rl()
c=[0]*(n+1)
d=[0]*(m+1)
for i in range(n):
    c[i+1]=c[i]+a[i]
for i in range(m):
    d[i+1]=d[i]+b[i]
ans=0;j=m
for i in range(n+1):
    if c[i]>k:
        break
    while c[i]+d[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)
#import sys
#input = sys.stdin.readline
Q = 10**9+7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

# def getFactorialInv(N):
#     inv = [0] * (N + 1)
#     inv[0] = 1
#     inv[1] = 1
#     ret = [1]*(N+1)
#     for i in range(2, N + 1):
#         inv[i] = (-(Q // i) * inv[Q%i]) % Q
#         ret[i] = ret[i-1]*inv[i]
#     return ret

def getFactorial(N):
    ret = [1]*(N+1)
    for i in range(2,N+1):
        ret[i] = ret[i-1]*i%Q
    return ret

def main():
    r1, c1, r2, c2 = map( int, input().split())
    F = getFactorial(2*(10**6))
    J = getInv(2*(10**6))
    I = [0]*(2*(10**6)+1)
    I[0] = 1
    I[1] = 1
    for i in range(2,2*(10**6)+1):
        I[i] = I[i-1]*J[i]%Q
    #print(F[5]*I[5]%Q)
    a = 0
    b = 0
    c = 0
    d = 0
    for i in range(1, c2+1):
        a += F[r2+i+1]*I[i+1]%Q*I[r2]%Q-1
#        print(F[r2+i+1]*I[i+1]%Q*I[r2]%Q-1)
        a %= Q
    if r1 == 1:
        b = 0
    else:
        for i in range(1, c2+1):
            b += F[r1+i]*I[i]%Q*I[r1]%Q-1
            b %= Q
    if c1 == 1:
        c = 0
    else:
        for i in range(1, c1):
            c += F[r2+i+1]*I[i+1]%Q*I[r2]%Q-1
            c %= Q
    if c1 == 1 or r1 == 1:
        d = 0
    else:
        for i in range(1, c1):
            d += F[r1+i]*I[i]%Q*I[r1]%Q-1
            d %= Q
#    print(a, b,c, d)
    print((a-b-c+d)%Q)
if __name__ == '__main__':
    main()


### FIXED CODE ###

Q = 10**9+7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

def getFactorialInv(N):
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    ret = [1]*(N+1)
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
        ret[i] = ret[i-1]*inv[i]%Q
    return ret

def getFactorial(N):
    ret = [1]*(N+1)
    for i in range(2,N+1):
        ret[i] = ret[i-1]*i%Q
    return ret

def main():
    r1, c1, r2, c2 = map( int, input().split())
    F = getFactorial(2*10**6+2)
    I = getFactorialInv(10**6+1)

    def G(a, b):
        return F[a+b+2]*I[a+1]%Q*I[b+1]%Q
    
    print( ( G(r2,c2) - G(r2, c1-1) - G(r1-1, c2) + G(r1-1, c1-1))%Q)
if __name__ == '__main__':
    main()
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

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

if N == ０:
    print(-1)
    sys.exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()

ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

### FIXED CODE ###

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

l = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()



ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)
a, b = input().split()
a = int(a)
b = b*100
c = a*b
c = c/100

print(int(c))

### FIXED CODE ###

import decimal

a, b = input().split()
a = int(a)
b = str(b).replace('.', '')

r = a*int(b[0])

if a >= 10 and len(b) > 1:
    r += decimal.Decimal(a * int(b[1])/10)

if a >= 100 and len(b) > 2:
    r += decimal.Decimal(a * int(b[2])/100)

print(int(r))
x,k,d = map(int,input().split())
y = abs(x)//d
if y >= k:
        ans = abs(abs(x)-d*k)

else:
        if (k-y)% 2 == 0:
                ans = abs(abs(x)-d*y)
        else:
                ans = min(abs(abs(x)-d*y+d),abs(abs(x)-d*y-d))
print(ans)

### FIXED CODE ###

Q =input()
if Q.count('R')==3:
    print(3)
elif Q.count('R')==0:
    print(0)
elif Q.count('R')==1:
    print(1)
elif Q.count('R')==2:
    if Q[1] =='S':
        print(1)
    else :
        print(2)
S = list(input())

C = list(CODEFESTIVAL2016)

cnt = 0
for i in range(len(C)):
    if S[i] != C[i]:
        cnt += 1
print(cnt)

### FIXED CODE ###

S = list(input())

C = list("CODEFESTIVAL2016")

cnt = 0
for i in range(len(C)):
    if S[i] != C[i]:
        cnt += 1
print(cnt)