Harryxun/stf_run huggingface dataset:
N,M = list(map(int, input().split()))
lis=[]
for i in range(N):
    a,b = list(map(int, input().split()))
    lis.append([a,b])

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<=M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    print(ind)
    

money+=(M-count)*lis[ind][0]
print(int(money))

### FIXED CODE ###

N,M = list(map(int, input().split()))
lis=[]
for i in range(N):
    a,b = list(map(int, input().split()))
    lis.append([a,b])

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    #print(ind)
    

money+=(M-count)*lis[ind][0]
print(int(money))
a,b,c = map(str, input().split())
al = [a,b,c]
print(al.count("1"))
    

### FIXED CODE ###

abc = input()
abc = str(abc)
print(abc.count("1"))
w = input()
while True
    line = input()
    if line == 'END_OF_TEXT':
        break

     for s in line.lower().split():
         if s == W:
             count += 1

print(count)

### FIXED CODE ###

W = input()
 
count = 0
while True:
    line = input()
    if line == 'END_OF_TEXT':
        break
     
    for s in line.lower().split():
        if s == W:
            count += 1
             
         
     
print(count)
x = int(input())

b = int(pow(x, 1/5))

for i in range(100000):
  A =  x + (b-i)**5
  a = pow(A, 1/5)
  if float(a).is_integer():
    exit(print(int(a), int(b+i)))
  

### FIXED CODE ###


x = int(input())
y = int(pow(x, 1/5))*2
A = [i**5 for i in range(y+1)]
B = [i**5 for i in range(y+1)]

for i in range(len(A)):
  for j in range(len(B)):
    if ( A[i] + B[j] ) == x:
      if A[i] > B[j]:
        exit(print(i, -j))
      else:
        exit(print(j, -i))
    elif ( A[i] - B[j] ) == x:
      exit(print(i, j))
# coding: utf-8
import math

num_N = int(input())

min_num = math.inf
sqrt_N = math.floor(math.sqrt(num_N))

for i in range(1, sqrt_N + 1):
    if num_N % i == 0:
        len_num_A = len(str(i))
        len_num_B = len(str(int(num_N / i)))
        min_num = min(min_num, max(len_num_A, len_num_B))

print(min_num)

### FIXED CODE ###

# coding: utf-8
import math

num_N = int(input())

min_num = 999999
sqrt_N = math.floor(math.sqrt(num_N))

for i in range(1, sqrt_N + 1):
    if num_N % i == 0:
        len_num_A = len(str(i))
        len_num_B = len(str(int(num_N / i)))
        min_num = min(min_num, max(len_num_A, len_num_B))

print(min_num)
a,b=map(int,input().split())
if (a*b)%2 == 1:
  print(Odd)
else:
  print(Even)

### FIXED CODE ###

a,b=map(int,input().split())
if (a*b)%2 == 1:
  print('Odd')
else:
  print('Even')
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappushpop


def resolve():
    rl = sys.stdin.readline
    T = int(rl())
    if T == 3: raise 1

    ans = []
    for t in range(T):
        N = int(rl())

        val = 0
        a1 = [[] for i in range(N)]
        a2 = [[] for i in range(N)]

        for _ in range(N):
            i, v1, v2 = map(int, rl().split())
            i -= 1
            diff = v1 - v2
            if diff == 0 or i == N-1:
                val += v1
            elif diff > 0:
                a1[i].append(diff)
                val += v2
            else:
                i = N-1-i-1
                a2[i].append(-diff)
                val += v1

        for ax in (a1, a2):
            dq = []
            for i, aa in enumerate(ax):
                if not aa: continue
                for diff in aa:
                    ld = len(dq)
                    if ld <= i:
                        heappush(dq, diff)
                    else:
                        heappushpop(dq, diff)
            val += sum(dq)

        ans.append(val)


    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
sys.setrecursionlimit(1000000000)

def resolve():
    it = map(int, sys.stdin.read().split())

    T = next(it)
    ans = []
    for i in range(T):
        N = next(it)

        val = 0; a1 = []; a2 = []
        for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)):
            diff = v1 - v2
            a, v, diff = (a1, v2, diff) if diff >= 0 else (a2, v1, -diff)
            a.append((diff, i))
            val += v
        a1.sort(reverse=True); a2.sort(reverse=True)

        ls = len(a1)
        vis = [None]*(N+1)
        def root(x):
            if vis[x] == None: return x

            vis[x] = root(vis[x])
            return vis[x]
        def root(x):
            a = []
            while True:
                y = vis[x]
                if y == None:
                    break
                a.append(x)
                x = y
            for i in a:
                vis[i] = x
            return x

        for diff, i in a1:
            j = min(i, ls) - 1
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k < 0: continue
            val += diff
            vis[k] = k - 1


        for diff, i in a2:
            j, v2 = max(i, ls), [[-1]]
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k >= N: continue
            val += diff
            vis[k] = k + 1

        ans.append(val)

    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()
def calc_step_combination(num):
    if num == 0:
        return 0
    if num == 1:
        return 1
    if num == 2:
        return 2
    return calc_step_combination(num - 1) + calc_step_combination(num - 2)


def sol(n, a_list):
    step_batch = []
    batch_start = 0
    for a in a_list:
        step_batch.append(a - batch_start - 1)
        batch_start = a + 1
    step_batch.append(n - batch_start)

    result = 1
    for i, steps in enumerate(step_batch):
        if i == 0 and steps == 0:
            continue
        result *= calc_step_combination(steps)

    print(result % 1_000_000_007)


def main():
    n, m = map(int, input().split())
    a_list = []
    for i in range(0, m):
        a_list = int(input())
    sol(n, a_list)


main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(110000)

d = {}


def calc_step_combination(num):
    if num == 0:
        return 0
    if num == 1 or num == 2:
        return 1
    if num in d:
        return d[num]
    res = calc_step_combination(num - 1) + calc_step_combination(num - 2)
    d[num] = res
    return res


def sol(n, a_list):
    step_batch = []
    batch_start = 0
    for a in a_list:
        step_batch.append(a - batch_start)
        batch_start = a + 1
    step_batch.append(n - batch_start + 1)

    result = 1
    for i, steps in enumerate(step_batch):
        result *= calc_step_combination(steps)
    print(result % 1000000007)


def main():
    n, m = map(int, input().split())
    a_list = []
    for i in range(0, m):
        a_list.append(int(input()))
    sol(n, a_list)


main()
s = input()
if s[0] == 'A':
    s = s[1:]
    if s[1:-2].cont('C') == 1:
        s.remove('C')
        if s == s.lower():
            print('AC')
            exit()
print('WA')

### FIXED CODE ###

s = input()
if s[0] == 'A':
    s = s[1:]
    if s[1:-1].count('C') == 1:
        for char in s:
            if char != 'C' and char == char.upper():
                break
        else:
            print('AC')
            exit()
print('WA')
N = int(input())
P = list(map(lambda p : int(p), input().split(" ")))
left_min = P[0]
cnt = 0
for i in range(P):
  if left_min >= P[i]:
    cnt += 1
    left_min = P[i]
print(cnt)

### FIXED CODE ###

N = int(input())
P = list(map(lambda p : int(p), input().split(" ")))
left_min = P[0]
cnt = 0
for i in range(len(P)):
  if left_min >= P[i]:
    cnt += 1
    left_min = P[i]
print(cnt)
s = input()
K = int(input())
 
str_list = list(s)
str_list2 = list(s)
str_list2 = list(set(str_list2))
str_list2.sort()
a = str_list2[0]
n = str_list.count(a)
 
if K==1:
    print(a)
else:
    K -= 1
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
    if len(indexes) >0:
        sub_list = [s[i:i+2] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
    if len(indexes) >0:
        sub_list += [s[i:i+3] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
    if len(indexes) >0:
        sub_list += [s[i:i+4] for i in indexes]
    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
    if len(indexes) >0:
        sub_list += [s[i:i+5] for i in indexes]
    sub_list = list(set(sub_list))
    sub_list.sort()
    if len(sub_list) >= K:
        print(sub_list[K-1])
    else:
        K -= len(sub_list)
        a = str_list[1]
        if K==1:
            print(a)
        else:
            K -= 1
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
            if len(indexes) >0:
                sub_list = [s[i:i+2] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
            if len(indexes) >0:
                sub_list += [s[i:i+3] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
            if len(indexes) >0:
                sub_list += [s[i:i+4] for i in indexes]
            indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
            sub_list = list(set(sub_list))
            sub_list.sort()
            if len(sub_list) >= K:
                print(sub_list[K-1])
            else:
                K -= len(sub_list)
                a = str_list[2]
                if K==1:
                    print(a)
                else:
                    K -=1
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-1]
                    if len(indexes) >0:
                        sub_list = [s[i:i+2] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-2]
                    if len(indexes) >0:
                        sub_list += [s[i:i+3] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-3]
                    if len(indexes) >0:
                        sub_list += [s[i:i+4] for i in indexes]
                    indexes = [i for i, x in enumerate(str_list) if x == a and i <len(s)-4]
                    sub_list = list(set(sub_list))
                    sub_list.sort()
                    print(sub_list[K-1])

### FIXED CODE ###

s = input()
K = int(input())

subset_list = list(s)
subset_list += [s[i:i+2] for i in range(len(s)-1)]
subset_list += [s[i:i+3] for i in range(len(s)-2)]
subset_list += [s[i:i+4] for i in range(len(s)-3)]
subset_list += [s[i:i+5] for i in range(len(s)-4)]
subset_list = list(set(subset_list))
subset_list.sort()

print(subset_list[K-1])
class unionFind:
    parent = []
    count = 0

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.nums = [1]*N

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            self.nums[y] += self.nums[x]
            self.nums[x] = 0
            return


N, M = map(int, input().split())
G = unionFind(N)
ans = [0]*M
ab = [tuple(map(int, input().split())) for i in range(M)]

tmp = (N * (N-1)) // 2
for i, x in enumerate(reversed(ab)):
    a, b = x[0], x[1]
    if M-1-i < 0 or M-1-i > M-1:
        continue
    ans[M-1-i] = tmp
    a = G.root(a-1)
    b = G.root(b-1)
    if a == b:
        continue
    else:
        tmp -= G.nums[a] * G.nums[b]
        G.parent[a] = b
        G.nums[b] += G.nums[a]
        G.nums[a] = 0


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


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)


class unionFind:
    parent = []
    nums = []

    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.nums = [1]*n

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            self.nums[y] += self.nums[x]
            self.nums[x] = 0
            return


N, M = map(int, input().split())
G = unionFind(N)
ans = [0]*M
ab = [tuple(map(int, input().split())) for i in range(M)]

tmp = (N * (N-1)) // 2
for i, x in enumerate(reversed(ab)):
    a, b = x[0], x[1]
    ans[M-1-i] = tmp
    a = G.root(a-1)
    b = G.root(b-1)
    if a == b:
        continue
    else:
        tmp -= G.nums[a] * G.nums[b]
        G.parent[a] = b
        G.nums[b] += G.nums[a]
        G.nums[a] = 0


for i in range(M):
    print(ans[i])
import math
A, B, C, D = map(int, input().split())

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

C_comp = B // C - (A-1) // C
D_comp = B // D - (A-1) // D
CD_comp = B // lcm(C,D) - (A-1) // lcm(C,D)

print((B - A + 1) - (C_comp + D_comp - CD_comp))


### FIXED CODE ###

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

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

C_comp = (B//C) - ((A-1)//C)
D_comp = (B//D) - ((A-1)//D)
CD_comp = (B//lcm(C,D)) - ((A-1)//lcm(C,D))

print((B - A + 1) - (C_comp + D_comp - CD_comp))
import sys

N = int(input())
old_t = 0
old_x = 0
old_y = 0
for i in sys.stdin:
    a = list(map(int, i.split(' ')))
    t = a[0]
    x = a[1]
    y = a[2]
    d = abs(x - old_x) + abs(y-old_y)
    T = t - old_t
    if (T % 2 != d % 2):
        print('No')
        sys.exit(0)
    if (T <= d):
        print('No')
        sys.exit(0)
    old_t = t
    old_x = x
    old_y = y
print('Yes')

### FIXED CODE ###

a = list(map(int, input().split(' ')))
b = a[0] * a[1]
r = 'Even' if (b % 2 == 0) else 'Odd'
print(r)
n,x=map(int,input().split())

s=list(map(int,input().split()))
i=0
ans=0
l=0
while l<=x:
   l=l+s[i]
   ans+=1
   i+=1
print(ans)


### FIXED CODE ###

n,x=map(int,input().split())

s=list(map(int,input().split()))
i=0
ans=0
l=0
while l<=x:
    try:

       l=l+s[i]
       ans+=1
       i+=1
    except:
        ans+=1
        break
print(ans)
n,m = int(raw_input()),int(raw_input())
s = [map(int, raw_input().split(",")) for i in range(m)]
s = sorted(s, key=lambda x:x[2])
ls = range(n)
ref = ls[:]
ans = 0
for i in s:
    x,y,d = s.pop(0)
    a,b = ref[x],ref[y]
    if a != b
        for j in ls:
            if ref[j] == a: ref[j] = b
        ans += d/100 - 1
print ans 

### FIXED CODE ###

while True:
	n = int(raw_input())
	if n == 0: break
	m = int(raw_input())
	s = [map(int, raw_input().split(",")) for i in range(m)]
	s = sorted(s, key=lambda x:x[2])
	ls = range(n)
	ref = ls[:]
	ans = 0
	while s:
	    x,y,d = s.pop(0)
	    a,b = ref[x],ref[y]
	    if a != b:
	        for j in ls:
	            if ref[j] == a: ref[j] = b
	        ans += d/100 - 1
	print ans
@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)



### FIXED CODE ###

import math
from functools import lru_cache

@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)
n,m=int,input().split()

print((n-1)*(m-1))


### FIXED CODE ###

n,m=map(int,input().split())

print((n-1)*(m-1))
X,Y=list(input())
if X==Y:
  print('=')
elif X<Y:
  print('<')
else:
  print('>')

### FIXED CODE ###

X,Y=input().split()
if X==Y:
  print('=')
elif X<Y:
  print('<')
else:
  print('>')
import math
a,b,c=(int(x) for x in input().split())

x=c-a-b
if x>0:
  if x*x-4*a*b>0:
    print('Yes')
  else:
    primt('No')
else:
  print('No')


### FIXED CODE ###

import math
a,b,c=(int(x) for x in input().split())

x=c-a-b
if x>0:
  if x*x-4*a*b>0:
    print('Yes')
  else:
    print('No')
else:
  print('No')
import math
A, B, N = map(int, input().split())

x = list(range(1, N+1))

ans = -10**20
for i in x:
  y = math.floor(A*i/B) - A * math.floor(i/B)
  if y > ans:
    ans = y
print(y)

### FIXED CODE ###

import math
A, B, N = map(int, input().split())

x = min(B-1, N)
y = math.floor(A*x/B) - A * math.floor(x/B)
print(y)
n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)

for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
        
print(unique(li)-1)

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)

### FIXED CODE ###

n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)
n = n+1
for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
#print(li)
print(len(set(li)))

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n == 1:
    ans = 0
elif n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)
list_1 = [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(list_1[k])

### FIXED CODE ###

list_1 = [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(list_1[k-1])
x, a, b = map(int(input())
A = abs(x-a)
B = abs(x-b)
if A < B:
    print("A")
else:
    print("B")

### FIXED CODE ###

x, a, b = map(int,input().split())
p = abs(x-a)
q = abs(x-b)
if p < q:
    print("A")
else:
    print("B")
import numpy as np

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

num_array = np.zeros(max(a_list), dtype=np.int8)
for a in a_list:
    num_array[a::a] += 1

count = 0
for a in a_list:
  if num_array[a] == 1:
    count += 1
print(count)

### FIXED CODE ###

N = int(input())
a_list = sorted(list(map(int, input().split())))
a_max = a_list[-1]

count = [0] * (a_max+1)

for a in a_list:
  for j in range(a, a_max+1, a):
    count[j] += 1
  
ans = 0
for a in a_list:
  if count[a] == 1:
    ans += 1
print(ans)
n = int(input())
l = list(map(int,input().split()))
 
count = 0
 
while True:
  for i in n:
    if l[i]%2 == 0:
      l[i] = l[i]//2
    else:
      print(count)
      exit()
  count += 1

### FIXED CODE ###

print(input().count("1"))
def f(x, m):
    return (x ** 2) % m


def main():
    n, x, m = map(int, input().split())
    lst = [[False, 0] for _ in range((m + 1))]
    lst[x] = [True, 1]
    res = [x]

    for i in range(2, m + 1):
        x = f(x, m)
        if lst[x][0] == False:
            lst[x][0] = True
            lst[x][1] = i
            res.append(x)
        else:
            loop = i - lst[x][1]
            non_loop = lst[x][1] - 1
            break
    if loop == 0:
        print(sum(res))
        exit()
    ans = sum(res[:non_loop])
    ans += (n - 2) // loop * sum(res[non_loop:])
    ans += sum(res[non_loop:non_loop + (n - 2) % loop])
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def f(x, m):
    return (x ** 2) % m


def main():
    n, x, m = map(int, input().split())
    lst = [[False, 0] for _ in range((m + 1))]
    lst[x] = [True, 1]
    res = [x]
    loop = 0

    for i in range(2, m + 1):
        x = f(x, m)
        if lst[x][0] == False:
            lst[x][0] = True
            lst[x][1] = i
            res.append(x)
        else:
            loop = i - lst[x][1]
            non_loop = lst[x][1] - 1
            break
    if loop == 0:
        print(sum(res[:n]))
        exit()
    ans = sum(res[:non_loop])
    ans += (n - non_loop) // loop * sum(res[non_loop:])
    ans += sum(res[non_loop:non_loop + (n - non_loop) % loop])
    print(ans)


if __name__ == "__main__":
    main()
a1 = input('a1:')
a2 = input('a2:')
a3 = input('a3:')


sum = int(a1) + int(a2) + int(a3)

if sum >= 22:
  print('bust')
else:
  print('win')

### FIXED CODE ###

A = input()
A = list(A.split())
sum = 0

for i in A:
  sum += int(i)

if sum >= 22:
  print('bust')
else:
  print('win')
s=list(input())
n=len(s)
l=[]
i=0
while i<n:
    if i<n-1 and l[i]=='B' and l[i+1]=='C':
        l.append('D')
        i+=2
    else:
        l.append(s[i])
        i+=1
n=len(l)
ans=0
r=[0]*(n+1)
f=0
for i in range(n-1,-1,-1):
    if l[i]=='D':
        f+=1
    elif l[i]=='A':
        ans+=f
    else:
        f=0
print(ans)


### FIXED CODE ###

s=list(input())
n=len(s)
l=[]
i=0
while i<n:
    if i<n-1 and s[i]=='B' and s[i+1]=='C':
        l.append('D')
        i+=2
    else:
        l.append(s[i])
        i+=1
n=len(l)
ans=0
r=[0]*(n+1)
f=0
for i in range(n-1,-1,-1):
    if l[i]=='D':
        f+=1
    elif l[i]=='A':
        ans+=f
    else:
        f=0
print(ans)
h,w,m = map(int,input().split())
total = 0
if h < w:
  h,w = w,h
for i in range(w):
  total += h
  if total >= m:
    print(i+1)

### FIXED CODE ###

h = int(input())
w = int(input())
m = int(input())
total = 0
if h < w:
  h,w = w,h
for i in range(w):
  total += h
  if total >= m:
    print(i+1)
    exit()
N, M = map(int, input().split())

l, r = map(int, input().split())
lis = [i for i in range(l, r+1)]

for i in range(M-1):
    l, r = map(int, input().split())
    if r > max(lis):
        r = max(lis)
    if l < min(lis):
        l = min(lis)
    tmp_lis = [i for i in range(l, r+1)]
    lis = set(lis) & set(tmp_lis)

lis = [i for i in lis if i <= N]
print(len(lis))


### FIXED CODE ###

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

min, max = map(int, input().split())

for i in range(M-1):
    l, r = map(int, input().split())
    if min < l:
        min = l
    if max > r:
        max = r



lis = [i for i in range(min, max+1)]
print(len(lis))