Harryxun/stf_run huggingface dataset:
n=int(input())
edge=[]
G=[[] for _ in range(n+1)]
for _ in range(n-1):
    x,y=map(int,input().split())
    edge.append([x,y])
    G[x].append(_)
    G[y].append(_)
k=0
root=0
for i in range(1,n+1):
    if k<len(G[i]):
        root=i
        k=len(G[i])
co=[1 for i in range(n+1)]
vis=[False for i in range(n+1)]
def dfs(node,lastco=-1):
    tmp=lastco
    for v in G[node]:
        if not vis[v]:
            tmp+=1
            co[v]=tmp%k
            vis[v]=True
            if node==edge[v][0]:
                dfs(edge[v][1],co[v])
            else:
                dfs(edge[v][0],co[v])

dfs(root)
print(k)
for i in range(n-1):
    print(co[i]+1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100010)
n=int(input())
edge=[]
G=[[] for _ in range(n+1)]
for _ in range(n-1):
    x,y=map(int,input().split())
    edge.append([x,y])
    G[x].append(_)
    G[y].append(_)
k=0
root=0
for i in range(1,n+1):
    if k<len(G[i]):
        root=i
        k=len(G[i])
co=[1 for i in range(n+1)]
vis=[False for i in range(n+1)]
def dfs(node,lastco=-1):
    tmp=lastco
    for v in G[node]:
        if not vis[v]:
            tmp+=1
            co[v]=tmp%k
            vis[v]=True
            if node==edge[v][0]:
                dfs(edge[v][1],co[v])
            else:
                dfs(edge[v][0],co[v])

dfs(root)
print(k)
for i in range(n-1):
    print(co[i]+1)
N = int(input())
A = list(map(int,input().split()))

def func(A):
    A_inf = 0
    A_sup = 0
    N_inf = 0
    N_sup = 0
    L = sum(A)

    for a in A:
        if A_inf + a <= L/2:
            A_inf += a
            A_sup += a
            N_inf += 1
            N_sup += 1

        if A_sup <= L/2 and A_sup + a > L/2:
            A_sup += a
            N_sup += 1

    if A_inf == A_sup:
        return 0
    x = sum(A) - 2*A_inf
    y = 2*A_sup - sum(A)
    result = min(x,y)

    if A_sup - y < N_sup:
        return x
    else:
        return result

print(func(A))

### FIXED CODE ###

X, Y = map(int,input().split())

def get_money(X):
    if X == 1:
        return 300000
    elif X == 2:
        return 200000
    elif X == 3:
        return 100000
    else:
        return 0

def double_money(X, Y):
    if X == 1 and Y == 1:
        return 400000
    else:
        return 0

sum = get_money(X) + get_money(Y) +double_money(X, Y)

print(sum)
a,b = map(int,input().split())

print(max(a+b,a*b,a-B))

### FIXED CODE ###

a,b = map(int,input().split())

print(max(a+b,a*b,a-b))
A= list(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
K = int(input())
print(A[K-1])

### FIXED CODE ###

A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())-1
print(A[K])
s = str(input())
if s[3]==s[4]  and s[5]==s[6]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = str(input())
if (s[2]==s[3])  and (s[4]==s[5]):
  print("Yes")
else:
  print("No")
n,m=map(int,input().split())
h=list(map(int,input().split()))
count=[1]*m
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    count[b-1]=0
  elif h[a-1]==h[b-1]:
    count[a-1]=0
    count[b-1]=0
  else:
    count[b-1]=0
print(sum(count))
    

### FIXED CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
count=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    count[b-1]=0
  elif h[a-1]==h[b-1]:
    count[a-1]=0
    count[b-1]=0
  else:
    count[a-1]=0
print(sum(count))
def d_disjoint_set_of_common_divisors():
    from math import gcd
    A, B = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        """nを素因数分解したときの素数とその指数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table
    g = gcd(A, B)
    return len(prime_factorization_dict(g).keys()) + 1 if g > 1 else 1

print(d_disjoint_set_of_common_divisors())

### FIXED CODE ###

def d_disjoint_set_of_common_divisors():
    A, B = [int(i) for i in input().split()]
    if A == 1 or B == 1:
        return 1

    def prime_factorization_dict(n):
        """nを素因数分解したときの素数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1は素数の0乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return set(table.keys())
    a_primekey = prime_factorization_dict(A)
    b_primekey = prime_factorization_dict(B)
    ans = []
    for a in a_primekey:
        if a in b_primekey:
            ans.append(a)
    return len(ans) + 1

print(d_disjoint_set_of_common_divisors())
l = map(int, raw_input().split())
a=l[0]
b=l[1]
c=a*b
d=(a+b)*2
print c+" "+d

### FIXED CODE ###

l = map(int, raw_input().split())
a=l[0]
b=l[1]
c=a*b
d=(a+b)*2
print str(c)+" "+str(d)
a,b=map(int,input().split())
if a<10:
  print(b+(100*(10-a))
else:
  print(b)

### FIXED CODE ###

a,b=map(int,input().split())
if a<10:
  print(b+(100*(10-a)))
else:
  print(b)
import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
# MOD = 10 ** 9 + 7
MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
def prime_factorize(n):
    two = 0
    five = 0
    while n % 2 == 0:
        two += 1
        n //= 2

    while n % 5 == 0:
        five += 1
        n //= 5

    return two, five


def main():
    n = ni()
    a = [int(decimal.Decimal(sys.stdin.readline().restrip()) * (10 ** 9)) for _ in range(n)]
    res = {}
    border = 18

    twoflg = False
    fiveflg = False
    for ai in a:
        two, five = prime_factorize(ai)

        if two >= 9:
            twoflg = True
        if five >= 9:
            fiveflg = True

        if (two, five) not in res.keys():
            res[(two, five)] = 1
        else:
            res[(two, five)] += 1

    ans = 0
    if twoflg and fiveflg:
        for k, v in res.items():
            two, five = k
            for tk, tv in res.items():
                t_two, t_five = tk
                if two + t_two >= border and five + t_five >= border:
                    if two == t_two and five == t_five:
                        ans += v * (tv - 1)
                    else:
                        ans += v * tv

    print(ans // 2)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
# MOD = 10 ** 9 + 7
MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
def prime_factorize(n):
    two = 0
    five = 0
    while n % 2 == 0:
        two += 1
        n //= 2

    while n % 5 == 0:
        five += 1
        n //= 5

    return two, five


def main():
    n = ni()
    a = [int(decimal.Decimal(input()) * (10 ** 9)) for _ in range(n)]
    res = {}
    border = 18

    twoflg = False
    fiveflg = False
    for ai in a:
        two, five = prime_factorize(ai)

        if two >= 9:
            twoflg = True
        if five >= 9:
            fiveflg = True

        if (two, five) not in res.keys():
            res[(two, five)] = 1
        else:
            res[(two, five)] += 1

    ans = 0
    if twoflg and fiveflg:
        for k, v in res.items():
            two, five = k
            for tk, tv in res.items():
                t_two, t_five = tk
                if two + t_two >= border and five + t_five >= border:
                    if two == t_two and five == t_five:
                        ans += v * (tv - 1)
                    else:
                        ans += v * tv

    print(ans // 2)


if __name__ == '__main__':
    main()
N = int(input())
a = [int(input()) for i in range(N)]

sum_ = sum(a)
count = 0
for j in range(2,N):
    for i in list(itertools.combinations(a,j)):
        if(2*sum(i)>sum_):
            for m in range(1,len(i)):
                for k in list(itertloos.combinations(i,m)):
                    if(sum_>2*sum(k) and sum_>2*(sum(i)-sum(k))):
                        count += 1
count = count * 6

### FIXED CODE ###

A,B,C = map(int,input().split())
if(A<C and C<B) or (B<C and C<A):
    print('Yes')
else:
    print('No')
import math
N,X,T=map(int,input().split))
A=T*(math.ceil(N/X))
print(A)

### FIXED CODE ###

import math
n, x, t = map(int, input().split())
if n % x == 0:
    c = n / x
else:
    b = n / x
    c = math.ceil(b)
a = int(c * t)
print(a)
a = input()
l = a.split()
n = int(l[0])
l.pop(0)

for i in range(n):
	l[i] = int(l[i])

counting = 0
list_i = []
for i in range(100000):
	counting = 0
	for j in range(n):
		if (l[j] == i or l[j] == i-1 or l[j] == i+1):
			counting += 1		
	list_i.append(counting)
			
print(max(list_i))

### FIXED CODE ###

n = int(input())
l = input().split()

for i in range(0,n):
	l[i] = int(l[i])

dict_i = {}
for i in range(-1,100001):
	dict_i[i] = 0
	
for j in range(n):
	dict_i[l[j]] += 1
	dict_i[l[j] + 1] += 1
	dict_i[l[j] - 1] += 1
print(max(dict_i.values()))
Copy
Copy
from collections import deque
h,w = map(int,input().split(" "))
s = [input() for _ in range(h)]
 
ans = 0
direcion = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        que = deque([(j,i)])
        dist = [[0]*w for _ in range(h)]
        visited = set()
        visited.add((i,j))
        while que:
            j, i = que.popleft()
            for x,y in direcion:
                n_x,n_y = j+x,i+y
                if not 0 <= n_x < w: continue
                if not 0 <= n_y < h: continue
                if (n_y,n_x) in visited: continue
                if s[n_y][n_x] == "#": continue
                visited.add((n_y,n_x))
                dist[n_y][n_x] = dist[i][j] + 1
                que.append((n_x,n_y))
            ans = max(ans,max(max(row) for row in dist))
print(ans)

### FIXED CODE ###

from collections import deque
h,w = map(int,input().split(" "))
s = [input() for _ in range(h)]
 
ans = 0
direcion = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        que = deque([(j,i)])
        dist = [[0]*w for _ in range(h)]
        visited = [[0]*w for _ in range(h)]
        visited[i][j] = 1
        while que:
            j, i = que.popleft()
            for x,y in direcion:
                n_x,n_y = j+x,i+y
                if not 0 <= n_x < w: continue
                if not 0 <= n_y < h: continue
                if visited[n_y][n_x]: continue
                if s[n_y][n_x] == "#": continue
                visited[n_y][n_x] = 1
                dist[n_y][n_x] = dist[i][j] + 1
                que.append((n_x,n_y))
        ans = max(ans,max(max(row) for row in dist))
print(ans)
N, M = map(int, input().split())

mod = 1000000007

f = [] # 素因数分解(指数部のみ)

for p in range(2, M): # 素因数分解
    e = 0
    while M%p == 0:
        e += 1
        M /= p
    
    if e>0:
        f.append(e)
    
    if M == 1:
        break

def pw(a, e):
    if e == 1:
        return a
    p = pw(a, e // 2)
    if e%2 == 1:
        return p * p % mod * a % mod
    else:
        return p * p % mod

# fact, inv の計算
fact = [1] * 100033
inv = [1] * 100033
for k in range(1, 100033):
    fact[k] = fact[k-1] * k % mod
    inv[k] = pw(fact[k], mod-2))

def combine(n, k):
    return fact[n] * inv[k] % mod * inv[n-k] % mod

ans = 1
for e in f:
    ans *= combine(e+N-1, e) # N_H_e (重複組合せ)
    ans %= mod

print(ans)


### FIXED CODE ###

A, B, C = map(int, input().split())

def ans1(): # 全ての組み合わせを調べる
    return max([
        10*A + B + C, # 10*A + C + B, 
        10*B + A + C, # 10*B + C + A, 
        10*C + A + B, # 10*C + B + A, 
    ])

def ans2():
    return A + B + C + 9*max([A, B, C])

#print(ans1())
print(ans2())
from sys import stdin

h,w,a,b = [int(x) for x in stdin.readline().rstrip().split()]

li = [[0 for _ in range(w)]for _ in range(h)]

if a == 0:
    a = 1
if b == 0:
    b = 1

if h%b != 0 or w%a != 0:
    if h == 1 or w == 1:
        count = 0
        for i in range(h):
            for s in range(a):
                li[i][s+a*count] = 1
            count += 1
            count = count%(h/a)

        li2 = [li[q][0] for q in range(h)]

        if li2.count(0) == b or li2.count(1) == b:
            for z in range(h):
                print(''.join(map(str, li[z])))
                exit()
        else:
            print("No")
            exit()
    else:    
        print("No")
        exit()

if a > h//2 or b > w//2:
    print("No")
    exit()

count = 0
for i in range(h):
    for s in range(a):
        li[i][s+a*count] = 1
    count += 1
    count = count%(h/a)

li2 = [li[q][0] for q in range(h)]

if li2.count(0) == b or li2.count(1) == b:
    for z in range(h):
        print(''.join(map(str, li[z])))
        exit()
else:
    print("No")
    exit()

### FIXED CODE ###

from sys import stdin
h,w,b,a = map(int,stdin.readline().rstrip().split())
li = []
for i in range(a):
    s = "0"*b+"1"*(w-b)
    li.append(s)
for j in range(h-a):
    s = "1"*b+"0"*(w-b)
    li.append(s)
for i in li:
    print(i)
x=input()
print(x*x*x)




### FIXED CODE ###

x=input()
y=int(x)
print(y*y*y)
nums = map(int, input().split())
sums = [sum(nums[i:i+3]) for i in range(len(nums)-1)]
poyo = [abs(x-753) for x in sums]
print(min(poyo))

### FIXED CODE ###

s = input()
list = [int(c) for c in s]
num = []
ans = 753
for i in range(len(list)-2):
	num.append((list[i] * 100) + (list[i+1] * 10) + list[i+2])
	if(num[i] >= 753):
		if(ans >= (num[i] - 753)):
			ans = num[i] - 753
	else:
		if(ans > (753 - num[i])):
			ans = 753 - num[i]
print(ans)
import numpy as np

n = input()
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

profit = v - c
positive_profit = profit(profit > 0)
print(positive_profit.sum())


### FIXED CODE ###

import numpy as np
 
n = input()
v = np.array([int(x) for x in input().split()])
c = np.array([int(x) for x in input().split()])
 
profit = v - c
positive_profit = profit[profit > 0]
print(np.sum(positive_profit))
a,b = int(input().sqlit())
print(str(a*b))

### FIXED CODE ###

a,b = map(int,input().split())
print(str(a*b))
a,b,c=map(int,input().split())
if a==b:
  print(c)
elif b==c:
  print(a):
else:
  print(b)

### FIXED CODE ###

a,b,c=map(int,input().split())
if a==b:
  print(c)
elif b==c:
  print(a)
else:
  print(b)
pages = input()
count = int(pages)

if count %2 = 0 :
    print(count/2)
else :
    print((count + 1)/2)


### FIXED CODE ###

import math

pages = input()
count = int(pages)

if count %2 == 0 :
    print(count/2)
else :
    print((count + 1)/2)
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
S=[0 for i in range(n+1)]
for i in range(1,n+1):
    S[i]=S[i-1]+a[i-1]
List=[]
for i in range(n+1):
    for j in range(i):
        List.append(S[i]-S[j])
List.sort(reverse=True)
def program(N,K,L):
    #print(N,K,L)
    M=len(L)
    b=[bin(i)[2:][::-1] for i in L]
    X=[[] for i in range(35)]
    for i in b:
        for j in range(len(i)):
            if i[j]=="1":
                X[j].append(i)
    l=35
    for i in range(34,-1,-1):
        if len(X[i])>=K:
            l=i
            break
    if l==35:
        return 0
    #print(X[l])
    R=[]
    for i in X[l]:
        if i[:-1]=="":
            R.append(0)
            continue
        R.append(int("0b"+i[:-1][::-1],2))
    return program(len(R),K,R)+2**l
print(program(n,k,List))

### FIXED CODE ###

N,K=map(int,input().split())
a=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(1,N+1):
    S[i]=S[i-1]+a[i-1]
List=[]
for i in range(N+1):
    for j in range(i):
        List.append(S[i]-S[j])
List.sort(reverse=True)
def program(Y,L):
    #print(L)
    M=len(L)
    t=[bin(i)[2:][::-1] for i in L]
    b=[i+"0"*(Y-len(i)) for i in t]
    X=[[] for i in range(Y)]
    for i in b:
        for j in range(Y):
            if i[j]=="1":
                X[j].append(i)
    #print("X",X)
    l=Y
    for i in range(Y-1,-1,-1):
        if len(X[i])>=K:
            l=i
            break
    if l==Y:
        return 0
    #print(X[l])
    R=[]
    for i in X[l]:
        if i[:l]=="":
            R.append(0)
            continue
        R.append(int(i[:l][::-1],2))
    R.sort(reverse=True)
    return program(l,R)+2**l
#print(K,N)
print(program(42,List))
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

print(a)
print(b)

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

if flag:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を1行ずつ比較
            if b[k] != a[i+k][j:j+n]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    print('No')
a, b = map(str, input().split())
c = int(a+b)
if float.is_integer(math.sqrt(c)) == True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import math
a, b = map(str, input().split())
c = int(a+b)
if float.is_integer(math.sqrt(c)) == True:
    print('Yes')
else:
    print('No')
from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
    a,b = list(map(int, input().split()))
    ns[a-1].add(b-1)
    ns[b-1].add(a-1)
for i in range(k):
    c,d = list(map(int, input().split()))
    bs[c-1].add(d-1)
    bs[d-1].add(c-1)
    
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
done = [0] * n
doneCount = 0
while doneCount<n:
    u = s.pop()
    done[u] = 1
    doneCount += 1
    parent[u] = start
    starts[start] += 1
    for v in ns[u]:
        if not done[v]:
            s.append(v)
    if not s:
        start = 0
        while done[start]:
            start += 1
        s.append(start)
ans = [None] * n
for u in range(n):
    val = starts[parent[u]] - 1 - len(ns[u])
    for v in bs[u]:
        if parent[v]==parent[u]:
            val -= 1
    ans[u] = val
print(" ".join(map(str, ans)))

### FIXED CODE ###



from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
    a,b = list(map(int, input().split()))
    ns[a-1].add(b-1)
    ns[b-1].add(a-1)
for i in range(k):
    c,d = list(map(int, input().split()))
    bs[c-1].add(d-1)
    bs[d-1].add(c-1)
    
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
    u = s.pop()
    parent[u] = start
    starts[start] += 1
    for v in ns[u]:
        if v in notdone:
            s.append(v)
            notdone.remove(v)
    if not s and notdone:
        start = notdone.pop()
        parent[start] = start
        s.append(start)
ans = [None] * n
for u in range(n):
    val = starts[parent[u]] - 1 - len(ns[u])
    for v in bs[u]:
        if parent[v]==parent[u]:
            val -= 1
    ans[u] = val
print(" ".join(map(str, ans)))
from sys import stdin

N = int(stdin.readline().rstrip())
h_lst = [int(x) for x in stdin.readline().rstrip().split()][::-1]

if len(h_lst) == 1:
  print("Yes")
else:
  f = "Yes"
  prev = h_lst[0]
  for i in h_lst[1:]:
    if prev - i >= 0:
      prev = i
    elif prev - i == -1:
      prev = i - 1
    else:
      f = "No"
      break

print(f)

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())
h_lst = [int(x) for x in stdin.readline().rstrip().split()][::-1]

if len(h_lst) < 1:
  print("Yes")
else:
  f = "Yes"
  prev = h_lst[0]
  for i in h_lst[1:]:
    if prev - i >= 0:
      prev = i
    elif prev - i == -1:
      prev = i - 1
    else:
      f = "No"
      break

print(f)
while True:
    N,M = map(int,input().split())
    if N == 0:
        break
    expect = 0
    a = []
    exsum = 0
    for i in range(N): #二次元配列を作る
        a.append(list(map(int,input().split())))
        exsum += a[i][0]*a[i][1] #誰も雇わなかった場合の期待値
    b = sorted(a, key=lambda x: x[1]) #危険度の高い区間ほど後ろにくるように並べる
    i = N-1
    while M > 0: #危険度が高い区間（配列のうしろ）から順に人を雇っていく
        if b[i][0] <= M:
            exsum -= b[i][0]*b[i][1]
            M -= b[i][0]
            i -= 1
        else:
            exsum -= b[i][1]*M
            M = 0
            i -= 1
    print(exsum)


### FIXED CODE ###

while True:
    N,M = map(int,input().split())
    if N == 0:
        break
    expect = 0
    a = []
    exsum = 0
    for i in range(N): #二次元配列を作る
        a.append(list(map(int,input().split())))
        exsum += a[i][0]*a[i][1] #誰も雇わなかった場合の期待値
    b = sorted(a, key=lambda x: x[1]) #危険度の高い区間ほど後ろにくるように並べる
    i = N-1
    while M > 0 and i >= 0: #危険度が高い区間（配列のうしろ）から順に人を雇っていく
        if b[i][0] <= M:
            exsum -= b[i][0]*b[i][1]
            M -= b[i][0]
            i -= 1
        else:
            exsum -= b[i][1]*M
            M = 0
            i -= 1
    print(exsum)
#!/usr/bin/env python

dn = lambda a, b: len(str(a+b))

if __name__ = "__main__":
    while True:
        a, b = raw_input().split()
        print "%d\n" % dn(a, b),

### FIXED CODE ###

#!/usr/bin/env python

dn = lambda a, b: len(str(a+b))
get = lambda: [int(x) for x in raw_input().split()]

if __name__ == "__main__":
    while True:
        try:
            print "%d" % dn(*get())
        except EOFError:
            break
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]])
    if indxs[-1]+1 < len(diffs):
        ans += sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)


### FIXED CODE ###

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

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return 0
 return 1
n=int(input())
f=lambda x,i:(x[0],int(x[1]),i)
A=[f(sys.stdin.readline().split(),i))for i in range(n)]
k(A,0,n-1)
print(['Not s','S'][s(A)]+'table')
for e in A:print(*e[:2])


### FIXED CODE ###

import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
def m():
 A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]
 k(A,0,n-1)
 print(s(A)+'table')
 print('\n'.join(f'{a} {b}'for a,b,_ in A))
if'__main__'==__name__: n=int(input());m()