peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  a,b,c,d = map(int,input().split())
  if b >= c:
    l = max(a,c)
    r = min(b,d)
    print(r-l)
    exit()
  else:
    print(0)
    exit()
if __name__ == '__main__':
  main()
# Judge status: Accepted
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)

K=int(input())
count=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            count+=gcd(a,b,c)
print(count)
# Judge status: Accepted
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all([int(j) not in d for j in str(n)]):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1
# Judge status: Accepted
s = input()
k = int(input())
if k <= len(s) :
         for i in range(k):
                  if s[i] != "1":
                           print(s[i])
                           exit()
         print("1")
         exit()
for i in range(len(s)):
         if s[i] != "1":
                  print(s[i])
                  exit()
# Judge status: Wrong Answer
N=int(input())
B=list(map(int,input().split()))
A=[0]*N

for i in range(1,N-1):
  A[i]=min(B[i-1],B[i])
A[0]=A[1]
a=sum(A)+B[N-2]
print(a)
# Judge status: Accepted
import math
array=[2]
for i in range(3,100004,2):
    prime=True
    for n in range(len(array)):
        if array[n] > math.sqrt(i):
            break
        if i % array[n] == 0:
            prime = False
            break
    if prime:
        array.append(i)
l=int(input())
for m in range(len(array)):
    if l>array[m]:
        pass
    else:
        print(array[m])
        break
# Judge status: Accepted
n=int(input())

if n<1000:
        print("ABC")
else:
        print("ABD")
# Judge status: Accepted
n,m = map(int, input().split())

if n==1 and m==1:
  print(1)
elif n==1:
  print(m-2)
elif m==1:
  print(n-2)
else:
  print((n-2)*(m-2))
# Judge status: Accepted
n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ans=0
for i in range(n):
    #print(ab[-i-1][0]+ans,ab[-i-1][1])
    if (ab[-i-1][0]+ans)%ab[-i-1][1]!=0:
        ans+=ab[-i-1][1]-(ab[-i-1][0]+ans)%ab[-i-1][1]
    #print(ans)
print(ans)
# Judge status: Accepted
t=list(input())
for i in range(len(t)):
    if t[i]=='?':
        t[i]='D'
print(''.join(t))
# Judge status: Accepted
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

N = int(input())

sum1 = 0
sum2 = 0
sum3 = 0

for a in range(1,N+1):
  for b in range(a+1, N+1):
    for c in range(b+1, N+1):
      sum1 += gcd(a,b,c)
      
for a in range(1,N+1):
  for b in range(a+1, N+1):
    sum2 += gcd(a,b)
    
sum3 = N*(N+1)/2

print(int(sum1*6+sum2*6+sum3))
# Judge status: Accepted
n, m = [int(x) for x in input().strip().split(" ")]

import math

def c(n, r):
    if n <= 1:
        return 0
    return int(math.factorial(n) / (math.factorial(r) * math.factorial(n - r)))

print(c(n, 2) + c(m, 2))
# Judge status: Accepted
n = int(input())

if n % 10 == 9 or n // 10 == 9:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
from collections import Counter
def factorization(n):
    a=[]
    for i in range(2,int(n**.5)+1):
        while n%i==0:
            n//=i
            a.append(i)
    if n!=1:
        a.append(n)
    return a
n=int(input())
A=factorization(n)
B=Counter(A)
count=0
for key,value in B.items():
    for i in range(1,value+1):
        if n%(key**i)==0:
            count+=1
            n//=(key**i)
        else:break
print(count)
# Judge status: Accepted
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = math.factorial(N)%(10**9+7)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
# Judge status: Accepted
N, K = list(map(int, input().split()))

d = list()
d = [d + list(input().split()) for i in range(K * 2)]
print(N - len(set(sum(d[1::2], []))))
# Judge status: Accepted
k, s  = map(int, input().split())
ans = 0
for i in range(k + 1):
    for j in range(i, k + 1):
        if j <= s - i - j <= k:
            l = s - i - j
            if i == j == l:
                ans += 1
            elif i == j or j == l:
                ans += 3
            elif i != j != l:
                ans += 6
print(ans)
# Judge status: Accepted
n = int(input())
if n == 1 or n == 2:
    print(n)
    exit()

now = 0
ans = []
for i in range(1, n):
    now += i
    ans.append(i)
    if now >= n:
        break

amari = now - n

for i in ans:
    if i == amari:
        continue
    else:
        print(i)
# Judge status: Accepted
import sys

input = sys.stdin.readline
max_a = 0
big_a = 0
max_index = 0
n = int(input())
for i in range(n):
    a = int(input())
    if max_a < a:
        max_index = i
        big_a = max_a
        max_a = a
    elif max_a == a:
        max_index = -1
    elif big_a < a:
        big_a = a
    else:
        continue

for i in range(n):
    print([max_a, big_a][i == max_index])
# Judge status: Accepted
x,y = map(int,input().split())
ans=1
tmp=x
for i in range(x,y+1):
    if tmp*2>y:
        break
    tmp*=2
    ans+=1
print(ans)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
k=int(input())
s=0
for i in range(4):
    if b*(2**i)>a:
        s=i
        break
b*=2**s
t=0
for i in range(4):
    if c*(2**i)>b:
        t=i
        break
if s+t>=k:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))

i = 2
ans = 0

while i<n:
    if a[i-2]>=a[i-1] and a[i-1]<a[i]:
        ans += 1
        i += 2
    elif a[i-2]<=a[i-1] and a[i-1]>a[i]:
        ans += 1
        i += 2
    else:
        i += 1
        if i == n:
            ans += 1
print(ans)
# Judge status: Wrong Answer
n, m, k = map(int, input().split())

for i in range(n):
    for j in range(m):
        if i*m+j*n-2*(i*j) == k:
            print('Yes')
            exit()
else:
    print('No')
# Judge status: Accepted
n = int(input())
dl = list(map(int,input().split()))
dl.sort()

if n % 2 != 0:
  print(0)
  exit()

  
left = dl[(n//2)-1]
right = dl[(n//2)]

print(right-left)
# Judge status: Wrong Answer
N,T,X = map(int,input().split())
if N % X == 0:
  print(T*N//X)
else:
  print(T*(N//X+1))
# Judge status: Accepted
n,m,X,Y=map(int,input().split())
x=max(X,max(map(int,input().split())))
y=min(Y,min(map(int,input().split())))
print(["War","No War"][x<y])
# Judge status: Wrong Answer
# coding: utf-8
# Your code here!

line= list(map(int,input().split()))
N = line[0]
K = line[1]
#0~Nの連続した整数から
#kこ以上選ぶ
answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num
    
print(int(answer))
# Judge status: Wrong Answer
S_list = list(map(int,input("入力：").split()))
ans = S_list[0] + S_list[1]
if  ans <24 :
    result = ans
else:
    result = ans - 24
print(result)
# Judge status: Wrong Answer
n=int(input())
a=[list(map(int,input().split())) for _ in range(n-1)]
ans=[]
for i in range(n-1):
    now=a[i][0]+a[i][1]
    for j in range(i+1,n-1):
        c,s,f=a[j]
        if s==now:
            d=0
        elif s>now:
            d=s-now
        else:
            d=now%f
        now+=c+d
    ans+=[now]  
ans+=[0]    
print(*ans,sep="\n")
# Judge status: Wrong Answer
N = int(input())
B = list(map(int,input().split()))

for i in range(N-2):
    if(B[i]>B[i+1]):
        B[i] = B[i+1]

ans = B[0]
for i in B:
    ans += i
print(ans)
# Judge status: Accepted
s = int(input())
arr = list(map(int, input().split()))

ans = 0

for i in range(1,s):
    if arr[i] < arr[i-1]:
        ans += (arr[i-1]-arr[i])
        arr[i] = arr[i-1]

print(ans)
# Judge status: Accepted
s = input()
z = s.count('0')
o = s.count('1')
print(min(z,o)*2)
# Judge status: Accepted
n=int(input())
c=str(input())
c=list(c)
t1=[0]*n
t2=[0]*n
for i in range(len(c)):
  if c[i]=="R":
    t1[i]=1
  else:
    t2[i]=1
if sum(t1)==len(c) or sum(t2)==len(c):
  print(0)
else:
  ans=0
  t=sum(t1)
  for i in range(n):
    if t2[i]==1:
      ans=ans+1
      t=t-1
    if t1[i]==1:
      t=t-1
    if t==0:
      break
  print(ans)
# Judge status: Accepted
N, D = map(int, input().split())
D2 = D**2
count = 0
for i in range(N):
  X, Y = map(int, input().split())
  if (X**2 + Y**2 <= D2):
    count += 1

print(count)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
dp = [0]*(N+1)
dp[0] = 1000

for i in range(N):
    for j in range(i):
        dp[i+1] = max(dp[i+1], dp[j]%A[j]+dp[j]//A[j]*A[i])

print(max(dp))
# Judge status: Accepted
n,r = map(int, input().split())
if n < 10:
    k = 100*(10-n)
    s = r + k
else:
    s = r
print(s)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
from math import gcd
ans=a[0]
for i in range(1,n):
  ans=ans*a[i]//gcd(ans,a[i])
s=sum(pow(x,mod-2,mod) for x in a)
print(s*ans%mod)
# Judge status: Accepted
A=open(0).read().split()
print('YNeos'[all(t-set(map(A.index,A[10:])) for t in({0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}))::2])
# Judge status: Accepted
def main():
    a, b, c, x, y = (int(i) for i in input().split())
    v1 = 2*c*max(x, y)
    v2 = 2*c*min(x, y) + (y-x if x < y else x-y)*(b if x < y else a)
    v3 = a*x + b*y
    print(min(v1, v2, v3))


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
TP = [[0, 0, 0]]
for _ in range(n):
    TP.append(list(map(int, input().split())))
for i in range(1, n + 1):
    td = TP[i][0] - TP[i-1][0]
    pd = abs(TP[i][1] - TP[i-1][1]) + abs(TP[i][2] - TP[i-1][2])
    if td >= pd and td % 2 == pd % 2:
        continue
    else:
        print('No')
        exit()
print('Yes')
# Judge status: Accepted
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().decode()

N, W, S, E = 'N' in S, 'W' in S, 'S' in S, 'E' in S

cond1 = not N ^ S
cond2 = not W ^ E

print('Yes' if cond1 and cond2 else 'No')
# Judge status: Accepted
import math
import sys
x=int(input())
for i in range(0,500):
    for j in range(-200,i):
        if i**5-j**5==x:
            print(i,j)
            sys.exit()
# Judge status: Wrong Answer
from collections import Counter

P = 998244353
N = int(input())
D = [int(x) for x in input().split()]

def solve():
  if D[0] != 0:
    return 0
  total = 1
  max_d = max(D)
  counter = Counter(D)
  for i in range(max_d + 1):
    if i not in counter:
      return 0
    if i > 1:
      total *= (counter[i - 1] ** counter[i] % P)
  return total

print(solve())
# Judge status: Accepted
n, Y = map(int, input().split())
for x in range(n+1):
  for y in range(n-x+1):
    z = n-x-y
    if 0 <= z <= n and 10000*x+5000*y+1000*z == Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)
# Judge status: Accepted
n, k = map(int, input().split())
 
mod = 10 ** 9 + 7
ans = 0
 
for i in range(k, n+2):
  ans += int(n*(n+1)/2 - (n-i)*(n - i + 1)/2 - (i-1)*i/2 + 1)
 
print(ans%mod)
# Judge status: Accepted
N,M,K = map(int,input().split())

for n in range(N+1):
  for m in range(M+1):
    if K == m*N+n*M-2*(n*m):
      print('Yes')
      exit()
print('No')
# Judge status: Accepted
n, *a = map(int, open(0).read().split())

cnt4 = 0
cnt2 = 0
cnt_not = 0
for num in a:
    if num % 4 == 0:
        cnt4 += 1
    elif num % 2 != 0:
        cnt_not += 1
    else:
        cnt2 += 1
        
if 0 < cnt2:
    r = 1
else:
    r = 0

#print(cnt_not, r, cnt4)
if cnt_not + r  < cnt4 + 2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import itertools

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

acc_A = [0]+list(itertools.accumulate(A))
acc_B = [0]+list(itertools.accumulate(B))
    
ans, j = 0, m
for i in range(n+1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        j -= 1
    ans = max(ans, i+j)
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())

if a>=1 and a<=9 and b>=1 and b<=9:
  print(a*b)
else:
  print(-1)
# Judge status: Accepted
N, M = map(int, input().split())
node =[[] for _ in range(N)]

for _ in range(M):
  x, y = map(int, input().split())
  node[x-1].append(y-1)
  node[y-1].append(x-1)

ct = [-1]*N

i = 0
queue = []
ct[0] = 0
queue.append(0)
while len(queue) != 0:
  v = queue.pop(0)
  for e in node[v]:
    if ct[e] == -1:
      ct[e] = v
      queue.append(e)

print('Yes')
for i in range(1,N):
  print(ct[i]+1)
# Judge status: Wrong Answer
A,B,C,D = map(int,input().split())
if B <= C:
    print(0)
else:
    print(min(B,D)-max(A,C))
# Judge status: Accepted
l = list(input())
n = l.count('N')
w = l.count('W')
s = l.count('S')
e = l.count('E')
if n == s or (n != 0 and s != 0):
    if w == e or (w != 0 and e != 0):
        print('Yes')
        exit(0)
print('No')
# Judge status: Accepted
s,t = input().split()
a,b = map(int,input().split())
u = input()

if u == s:
    a -= 1
else:
    b -= 1
    
print(a,b)
# Judge status: Accepted
Y, M, D = map(int, input().split('/'))

if Y <= 2019 and M <= 4 and D <= 30:
    print('Heisei')
else:
    print('TBD')
# Judge status: Accepted
S = input()
if "RRR" in S:
  print(3)
elif "RR" in S:
  print(2)
elif "R" in S:
  print(1)
else:
  print(0)
# Judge status: Accepted
#参考 ： AtCoder # 14682107
s = input()
len = len(s)

if len == 1:
    print(0)
    exit()

even = s[::2]
odd = s[1::2]

#偶数番目に0が並ぶと仮定したときの異物の数
# 0101...
odd_zero = odd.count("0")
even_one = even.count("1")


#奇数番目に0が並ぶと仮定したときの異物の数
# 1010...
odd_one = odd.count("1")
even_zero = even.count("0")

print(min(odd_zero + even_one, odd_one + even_zero))
# Judge status: Wrong Answer
n = int(input())
l = int(n**(0.3))
for a in range(n):
  s=0
  for i in range(l):
    if((3*i+3)**2-(3*(i**2)+6*i+3)==a+1):
      s+=1
      continue
    for j in range(l-i):
      for k in range(l-i-j):
        if((i+j+k+3)**2-(i*j+j*k+k*i+2*i+2*j+2*k+3)==a+1):
          s+=1
  print(s)
# Judge status: Accepted
S=input()

if S=="ABC" :
    print("ARC")
else :
    print("ABC")
# Judge status: Accepted
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
Q = [tuple(map(int, input().split())) for _ in range(Q)]

res = 0

for A in combinations_with_replacement(range(1, M + 1), N):
    point = 0
    for a, b, c, d in Q:
        if A[b - 1] - A[a - 1] == c:
            point += d
    res = max(point, res)

print(res)
# Judge status: Wrong Answer
x, k, d = list(map(int, input().split()))

if (x // d) >= k:
    print(x - d*(k))
else:
    if (k-(x//d)) %2 ==0:
        print(x%d)
    else:
        print(min(x%d+d,abs(x%d-d)))
# Judge status: Accepted
h=int(input())
n=int(input())
w=int(input())
v=max(h,n)
print((w+v-1)//v)
# Judge status: Accepted
import sys
import math

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, sys.stdin.readline().split())
    X.append(x)
    Y.append(y)
    
sum = 0

for i in range(N - 1):
    for j in range(i, N):
        sum += math.sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)

ans = sum / (N / 2)

print(ans)
# Judge status: Accepted
def main():
    number = int(input())
    queue = ["a"]
    for i in range(number - 1):
        now_queue = []
        for now in queue:
            limit = ord(max(now)) + 2
            for j in range(ord("a"), limit):
                now_queue.append(now + chr(j))
        queue = now_queue
    for q in queue:
        print(q)


if __name__ == '__main__':
    main()
# Judge status: Accepted
A, B, K = map(int, input().split())
S = sorted(list(set([i for i in range(A, min(A + K, B))] + [i for i in range(max(A, B - K + 1), B + 1)])))
for s in S:
    print(s)
# Judge status: Accepted
l = [int(x) for x in input().split()]
if l[2]==l[0]+l[1] or l[0]==l[1]+l[2] or l[1]==l[0]+l[2]:
  print ('Yes')
else:
  print ('No')
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))

for (i,j)in zip(a[k:],a[:-k]):
  if j<i:
    print("Yes")
  else:
    print("No")
# Judge status: Wrong Answer
import math
X=int(input())
if X>3000:
    print(1)
elif X<100:
    print(0)
else:
    i=1
    while i<=X:
        if 100*i<X and 105*i>X:
            print(1)
            quit()
        i+=1
    print(0)
# Judge status: Accepted
L = int(input())

print((L / 3)**3)
# Judge status: Accepted
# C - Prison
N,M = map(int,input().split())
L,R = 1,N
for _ in range(M):
    l,r = map(int,input().split())
    L,R = max(L,l),min(R,r)
print(max(0,R-L+1))
# Judge status: Accepted
a,b,c = map(int,input().split())
if a <= c and b >= c:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
S = input()
T = input()
S_len = len(S)
T_len = len(T)
S_sorted = sorted(S)
T_sorted = sorted(T, reverse=True)
ans = True
for i in range(min(S_len, T_len)):
    s = ord(S_sorted[i])
    t = ord(T_sorted[i])
    if s < t:
        print('Yes')
        exit(0)
    if s == t:
        continue
    else:
        print('No')
        exit(0)
if S_len >= T_len:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))
print('Yes' if max(L) < sum(L) - max(L) else 'No')
# Judge status: Wrong Answer
#合計宿泊数
N = input()
#通常宿泊数
K = input()
#通常宿泊費
X = input()
#割引宿泊費
Y = input()
#宿泊日数カウント
S = 1
#合計金額カウント
P = 0

#通常宿泊出力
while S <= int(K):
    P = P + int(X)
    S = S + 1

#割引宿泊出力
while S <= int(N):
    P = P + int(Y)
    S = S + 1

#合計金額出力
print(P)
# Judge status: Accepted
n=int(input())
print(int(n%100<=n//100*5))
# Judge status: Wrong Answer
a, b = map(int, input().split())
s = [0] * 1002
for i in range(1002):
    s[i] = s[i - 1] + i
    if (s[i - 1] - a == s[i] - b ):
        print(s[i - 1] - a)
        break
print(s)
# Judge status: Wrong Answer
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def solve():
    A,B,C,D = map(int, input().split())
    c = B//C - A//C
    if A % C == 0:
        c += 1
    d = B//D - A//D
    if B % C == 0:
        d += 1
    r = lcm(C,D)
    e = B//r - A//r

    return (B-A+1) - (c+d-e)

print(solve())
# Judge status: Accepted
N=int(input())
W=list(map(int,input().split()))

totalS=sum(W)
S1=W[0]
ans=totalS-S1

for i in range(1,N):
    S1+=W[i]
    ans=min(ans,abs(totalS-S1*2))
    
print(ans)
# Judge status: Wrong Answer
#ABC177 C
N = int(input())
A = list(map(int,input().split()))
max = A[0]
F = [0]

for i in range(1,N):
  if max > A[i]:
    F.append(max - A[i])
  else:
    max = A[i]
    F.append(0)

print(F)
print(sum(F))
# Judge status: Wrong Answer
s = input()
cnt = 0
ans = []
for i in range(0, len(s) - 3):
    j = i
    num = ''
    while j < len(s):
        juhuku = 0
        num += s[j]
        if int(num) % 2019 == 0 and num != '0':
            print(i, j)
            if j not in ans:
                ans.append(j)
            juhuku = ans.count(i - 1)
            cnt += 1 + juhuku
        j += 1
cnt, ans
# Judge status: Accepted
N = int(input())
v = list(map(int, input().split()))
v.sort()

ans = (v[0]+v[1])/2
for i in range(2, N):
    ans = (ans + v[i])/2
print(ans)
# Judge status: Wrong Answer
n = int(input())
line = list(map(int, input().split()))
q = int(input())
for i in range(0, q):
	b, c = map(int, input().split())
	line = [c if j is b else j for j in line]
	print(sum(line))
# Judge status: Accepted
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a, b = nm()

print((b - a) * (b - a - 1) // 2 - a)
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for i in range(60):
        cnt = 0
        for a in A:
            cnt += (a >> i) & 1
        res += (cnt * (n - cnt) % mod) * (1 << i) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()
# Judge status: Accepted
a, b, c = map(int, input().split())
k = int(input())
while k:
    if a >= b:
        b *= 2
    else:
        break
    k -= 1
while k:
    if b >= c:
        c *= 2
    else:
        break
    k -= 1
if a < b and b < c:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N,X,Y=tuple(int(num) for num in input().split(" "))


A=[i for i in range(1,N+1) if i < (X+Y)/2-0.5]
B=[i for i in range(1,N+1) if i > (X+Y)/2+0.5]
Ans=[i for i in range(1,N)]
Ans.reverse()

for a,b in [(a,b) for a in A for b in B if a<=X or Y<=b]:
    inc=abs(a-X)+abs(b-Y)+1
    dec=abs(b-a)
    Ans[inc-1]+=1
    Ans[dec-1]-=1

for a in Ans:
    print(a)
# Judge status: Accepted
# coding: utf-8

def main():
    _, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    ans = 0

    for i in a:
        x -= i
        if x < 0:
            break
        else:
            ans += 1

    if x > 0 and ans > 0:
        ans -= 1

    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    cnt_common = cnt.most_common()
    ans = 0
    for i in range(len(cnt_common)):
        num, val = cnt_common[i]
        ans += val * (val - 1) // 2
    for i in A:
        c = cnt[i]
        print(ans - c * (c - 1) // 2 + (c-1) * (c-2) // 2 )

if __name__ == '__main__':
    main()
# Judge status: Accepted
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)
n=int(input())
@lru_cache(None)
def solve(n):
    
    if n==0:
        return 0
    if n==1:
        return 1
    ans=n
    cur=6
    while cur<=n:
        ans=min(ans,1+solve(n-cur))
        cur*=6
    cur=9
    while cur<=n:
        ans=min(ans,1+solve(n-cur))
        cur*=9
    return ans
print(solve(n))
# Judge status: Wrong Answer
import sys
n,k = map(int,input().split())
m = n
c = 0
r = True
if n%k == 0:
    print(0)
    sys.exit()
while r == True:
    if k >= 2*m:
        r = False
    elif k >= m:
        c += 1
        r = False
    else:
        print(n%k)
        sys.exit()

print(abs(n-(c*k)))
# Judge status: Accepted
import collections


def resolve():
    S = list(input())

    counter_S = collections.Counter(S)

    if len(counter_S) != 2:
        print("No")
        return

    for value in counter_S.values():
        if value != 2:
            print("No")
            return

    print("Yes")


resolve()
# Judge status: Wrong Answer
N = int(input())
seq = input().split()

if len(seq) != len(set(seq)):
  print('YES')
else:
  print('NO')
# Judge status: Accepted
s = list(input())

s.sort()

if s[0]==s[2]:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
n,m=map(int, input().split())
l_ans=1
r_ans=n
for i in range(m):
    l,r=map(int, input().split())
    l_ans=max(l_ans,l)
    r_ans=min(r_ans,r)

if r_ans>=l_ans:
    print(r_ans-l_ans+1)
else:
    print(0)
# Judge status: Accepted
import sys
import numpy as np 

n, m = map(int, sys.stdin.readline().split())
x = np.array(sys.stdin.readline().split(), dtype=np.int64)
x.sort()

def main():
    d = np.sort(x[1:] - x[:-1])[::-1]
    d = np.concatenate((np.array([0]), np.cumsum(d)))
    res = d[m-1] - d[min(n, m) - 1]
    print(res)

if __name__ ==  '__main__':
    main()