Harryxun/stf_run huggingface dataset:
def get_answer(ki):
    n = int(ki[0].split(" ")[0])
    q = int(ki[0].split(" ")[1])
    n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    tree = make_tree(n, n_data)

    score = [0] * n

    for qq in q_data:
        index = qq[0]
        add_score(tree, score, qq, n_data, index)

    score = [str(s) for s in score]
    s = " ".join(score)

    return s


def add_score(tree, score, qq, n_data, index):
    score[index - 1] += qq[1]
    next_index = tree[index -1]
    for n_i in next_index:
        add_score(tree, score, qq, n_data, n_i)


def make_tree(n, n_data):
    r = {}
    for i in range(n):
        r[i] = []
    for n in n_data:
        k = n[0] - 1
        if k in r.keys():
            r[k].append(n[1])
        else:
            r[k] = [n[1]]
    return r


def make_index(n, tree):
    index = {}
    r0 = [0] * n
    for i in range(n):
        r0[i] = i
    index[0] = r0

    for i in range(1, n):
        r = []
        add_index(tree, i, r)
        index[i] = r

    return index


def add_index(tree, index, r):
    r.append(index)
    next_index = tree[index]
    for n_i in next_index:
        add_index(tree, n_i - 1, r)


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            input_ki.append(input1)
        except EOFError:
            break
    print(get_answer(input_ki))


### FIXED CODE ###

import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる
l = ["Sunny", "Cloudy", "Rain"]
s = input()
print(l[(l.index(s)+1)%3])

### FIXED CODE ###

l = ["Sunny", "Cloudy", "Rainy"]
s = input()
print(l[(l.index(s)+1)%3])
import fractions
import sys
input = sys.stdin.readline

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


lcm = a[0]
for i in range(1, N):
    g= fractions.gcd(lcm, a[i])
    lcm = lcm * a[i] // g
    

for i in range(N):
    if (a[i]//g)%2==0:
        lcm=0
        break
    



ans=0
l=lcm//2
if l:
    ans=(M//l)-(M//(l+l))
print(ans)

### FIXED CODE ###

import fractions
import sys
input = sys.stdin.readline

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


lcm = a[0]
for i in range(1, N):
    g= fractions.gcd(lcm, a[i])
    lcm = lcm * a[i] // g


g=a[0]
for i in range(N):
    g=fractions.gcd(g,a[i])

for i in range(N):
    if (a[i]//g)%2==0:
        lcm=0
        break    
    
    
ans=0
l=lcm//2
if l:
    ans=(M//l)-(M//(l+l))
print(ans)
a, b = map(int(input()))
if ((a%2) * (b%2)) != 0:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a, b = map(int,(input().split(" ")))
if ((a%2) * (b%2)) != 0:
  print("Yes")
else:
  print("No")
N = int(input())
shiri = []
for i in range(N):
    tugi = str(input())
    tlist = list(tugi)
    if i!=0:
        if tugi in shiri:
            break
        else:
            mae = list(shiri[i-1])
            if tlist[0]!=mae[-1]:
                break
            else:
                shiri,append(tugi)
    else:
        shiri.append(tugi)

### FIXED CODE ###

N = int(input())
shiri = []
flag = 0
for i in range(N):
    tugi = str(input())
    tlist = list(tugi)
    if i!=0:
        if tugi in shiri:
            flag = 1
            break
        else:
            mae = list(shiri[i-1])
            if tlist[0]!=mae[-1]:
                flag = 1
                break
            else:
                shiri.append(tugi)
    else:
        shiri.append(tugi)
if flag == 0:
    print("Yes")
else:
    print("No")
S = {"Sunny":"Cloudy", "Cloudy":"Cloudy", "Cloudy":"Sunny"}
k = input()

print(S[k])


### FIXED CODE ###

S = input()
if S == 'Sunny' :
	print('Cloudy')
	
elif S == 'Cloudy':
	print('Rainy')
else:
	print('Sunny')
import math
r = int(input())
area = math.pi * r ** 2
circum = 2 * math.pi * r
print("{0:.6f} {1:.6f}".format(area,circum))



### FIXED CODE ###

import math
r = float(input())
area = math.pi * r ** 2
circum = 2 * math.pi * r
print("{0:.6f} {1:.6f}".format(area,circum))
n,q=map(int,input().split())
s=input()
list=[0]
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    list.append(list[i]+1)
  else:
    list.append(list[i])
for j in range(q):
  l,r=map(int,input().split())
  print(list[r]-list[l-1])

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
list=[0]
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    list.append(list[i]+1)
  else:
    list.append(list[i])
for j in range(q):
  l,r=map(int,input().split())
  print(list[r-1]-list[l-1])
h, w = map(int, input().split())
S = ['']*h
for i in range(h):
    S[i] = input()

r = 'Yes'
for i in range(1, w-1):
    for j in range(1, h-1):
        if S[i][j]=='#':
            if S[i-1][j]=='.' and S[i+1][j]=='.' or S[i][j-1]=='.' or S[i][j+1]=='.':
                r = 'No'
                break
print(r)

### FIXED CODE ###

h, w =map(int,input().split())
S=["."+input()+"." for i in range(h)]
S=["."*(w+2)]+S+["."*(w+2)]
r = 'Yes'
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                r = 'No'
                break
print(r)
from fractions import Fraction
from collections import Counter

K = input()
A = range(1, 10) + range(19, 100, 10)
N = K - len(A)
diff = 100
target = 19
count = 0

while N > 0:
    N -= 1
    A.append(A[i]+diff)
    count += 1
    if count == target:
        diff *= 10
        target += 9
        count = 0

for i in xrange(K):
    print A[i]


### FIXED CODE ###

from fractions import Fraction

def calc(a):
    return sum(map(int, list(str(a))))

def comp(a, b):
    return a * calc(b) <= b * calc(a)

MAX = 10**17
K = input()
A = set()
base = 0
front = 1
ok = True
while base < MAX:
    for i in xrange(1, 999):
        tmp = i * front + base
        if tmp <= MAX:
            A.add(tmp)
    base = base * 10 + 9
    front *= 10

A = sorted(list(A), key=lambda x: -x)
m = A[0]
ans = []

for i in xrange(1, len(A)):
    if comp(A[i], m):
        m = A[i]
        ans.append(A[i])

ans.sort()
for i in xrange(K):
    print ans[i]
from queue import deque


def hierarchize(source):
    global edges, hierarchy
    hierarchy = [-1] * n
    queue = deque([(0, source)])
    while queue:
        h, v = queue.popleft()
        if hierarchy[v] != -1:
            continue
        hierarchy[v] = h
        if v == sink:
            return True
        queue.extend((h + 1, target)
                     for remain, target, _ in edges[v] if hierarchy[target] == -1 and remain)
    return False


def augment(v, limit):
    global sink, edges, hierarchy
    if v == sink:
        return limit
    res = 0
    for e in edges[v]:
        remain, target, idx = e
        if remain == 0 or hierarchy[v] >= hierarchy[target]:
            continue
        aug = augment(target, min(limit, remain))
        e[0] -= aug
        edges[target][idx][0] += aug
        res += aug
        limit -= aug
        if not limit:
            break
    return res


n, m = map(int, input().split())
sink = n - 1
edges = [[] for _ in range(n)]

hierarchy = [-1] * n

for _ in range(m):
    s, t, c = map(int, input().split())
    edges[s].append([c, t, len(edges[t])])
    edges[t].append([0, s, len(edges[s])])

res = 0
while hierarchize(0):
    res += augment(0, 10000001)
print(res)

### FIXED CODE ###

import sys
from queue import deque

sys.setrecursionlimit(200000)


def hierarchize(source):
    global edges, hierarchy
    hierarchy = [-1] * n
    queue = deque([(0, source)])
    while queue:
        h, v = queue.popleft()
        if hierarchy[v] != -1:
            continue
        hierarchy[v] = h
        if v == sink:
            return True
        queue.extend((h + 1, target)
                     for remain, target, _ in edges[v] if hierarchy[target] == -1 and remain)
    return False


def augment(v, limit):
    global sink, edges, hierarchy
    if v == sink:
        return limit
    res = 0
    for e in edges[v]:
        remain, target, idx = e
        if remain == 0 or hierarchy[v] >= hierarchy[target]:
            continue
        aug = augment(target, min(limit, remain))
        e[0] -= aug
        edges[target][idx][0] += aug
        res += aug
        limit -= aug
        if not limit:
            break
    return res


n, m = map(int, input().split())
sink = n - 1
edges = [[] for _ in range(n)]

hierarchy = [-1] * n

for _ in range(m):
    s, t, c = map(int, input().split())
    es, et = edges[s], edges[t]
    ls, lt = len(es), len(et)
    edges[s].append([c, t, lt])
    edges[t].append([0, s, ls])

res = 0
while hierarchize(0):
    res += augment(0, 10000001)
print(res)
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))
input())
a=list(map(int,input().split()))
ok=True

v=[0 for i in range(n+2)]
import time

#start=time.time()
nextv=0

nec=2**n

for i in range(n,-1,-1):

    if nec>=v[i+1]+a[i]:
        v[i]=v[i+1]+a[i]
    else:
        v[i]=nec

    nec=nec >>1



#print(time.time()-start)

for i in range(1,n+1):
    if v[i-1]-a[i-1]<0:
        ok=False
        break
    if (v[i-1]-a[i-1])*2<v[i]:
        v[i]=(v[i-1]-a[i-1])*2

if a[0]!=0:ok=False

ans=sum(v)

if ans==0:ok=False

if ok:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ok=True

v=[0 for i in range(n+2)]
import time

#start=time.time()
nextv=0

nec=2**n

for i in range(n,-1,-1):

    if nec>=v[i+1]+a[i]:
        v[i]=v[i+1]+a[i]
    else:
        v[i]=nec

    nec=nec >>1



#print(time.time()-start)

for i in range(1,n+1):
    if v[i-1]-a[i-1]<0:
        ok=False
        break
    if (v[i-1]-a[i-1])*2<v[i]:
        v[i]=(v[i-1]-a[i-1])*2


if n==0:
    if a[0]!=1:ok=False
else:
    if a[0] != 0:ok = False

if v[n]!=a[n]:ok=False

ans=sum(v)
if ans==0:ok=False

if ok:
    print(ans)
else:
    print(-1)
n = int(input()))
for i in range(n):
    M = [0] * n
    u = list(map(int, input().split()))
    v = u[0]
    k = u[0]
    for j in range(k):
        M[u - 1][v - 1] = 1

for i in range M:
    print(i, sep = " ")

### FIXED CODE ###

n = int(input())
M = [[0] * n for i in range (n)]
for i in range(n):
    u = list(map(int, input().split()))
    v = u[0]
    for j in u[2:]:
        M[v - 1][j - 1] = 1

for i in M:
    print(*i)
from collections import deque
n = int(input())
e = [[] for _ in range(n)]
AB = [list(map(int, input().split())) for _ in range(n - 1)]
AB = [(a -1, b - 1) for a, b in AB]

for itr, (a, b) in enumerate(AB):
  e[a].append(b)
  e[b].append(b)
  
colors = [-1] * n

# ２色で塗分けする。
q = deque()
# 現在見ている頂点、親の色
q.append((0, 0))
while q:
  v, pcol = q.popleft()
  # 親と異なる色で塗る。
  if colors[v] == -1:
    col = not pcol
    colors[v] = col
    for i in e[v]:
      if colors[i] == -1:
        q.append((i, col))

m1 = deque([i for i in range(1, n + 1) if i % 3 == 1])
m2 = deque([i for i in range(1, n + 1) if i % 3 == 2])
m0 = deque([i for i in range(1, n + 1) if i % 3 == 0])

ans = [0] * n

if sum(colors) > n // 2:
  for itr, i in enumerate(colors):
    if i:
      if m1:
        ans[itr] = m1.pop()
      else:
        ans[itr] = m0.pop()
    else:
      if m2:
        ans[itr] = m2.pop()
      else:
        ans[itr] = m0.pop()
else:
  for itr, i in enumerate(colors):
    if not i:
      if m1:
        ans[itr] = m1.pop()
      else:
        ans[itr] = m0.pop()
    else:
      if m2:
        ans[itr] = m2.pop()
      else:
        ans[itr] = m0.pop()
print(*ans)

### FIXED CODE ###

from collections import deque
n = int(input())
e = [[] for _ in range(n)]
AB = [list(map(int, input().split())) for _ in range(n - 1)]
AB = [(a -1, b - 1) for a, b in AB]

for itr, (a, b) in enumerate(AB):
  e[a].append(b)
  e[b].append(a)
  
colors = [-1] * n

# ２色で塗分けする。
q = deque()
# 現在見ている頂点、親の色
q.append((0, 0))
while q:
  v, pcol = q.popleft()
  # 親と異なる色で塗る。
  if colors[v] == -1:
    col = not pcol
    colors[v] = col
    for i in e[v]:
      if colors[i] == -1:
        q.append((i, col))

# print(e)
# print(colors)
        
m = [deque([i for i in range(1, n + 1) if i % 3 == j]) for j in range(3)]

# print(m)

def opop(n, ne):
  if m[n]:
    p = m[n].pop()
  else:
    if n == 1 or n == 2:
      if m[ne]:
        p = m[ne].pop()
      else:
        p = m[0].pop()
    else:
      if m[1]:
        p = m[1].pop()
      else:
        p = m[2].pop()
  return p

ans = [0] * n

if sum(colors) <= len(m[0]):
  for itr, i in enumerate(colors):
    if i:
      ans[itr] = opop(0, 0)
    else:
      ans[itr] = opop(1, 2)
elif sum(colors) >= len(m[1]) + len(m[2]):
  for itr, i in enumerate(colors):
    if not i:
      ans[itr] = opop(0, 0)
    else:
      ans[itr] = opop(1, 2)
else:
  for itr, i in enumerate(colors):
    if i:
      ans[itr] = opop(1, 0)
    else:
      ans[itr] = opop(2, 0)
print(*ans)
a,b=map(int,raw_input(),split())
print a*b,(a+b)*2

### FIXED CODE ###

a,b=map(int,raw_input().split())
print a*b,(a+b)*2
N = int(input())
A = list(map(int,input().split()))
i_a = [a,i+1 for i,a in enumerate(A)]
i_a.sort()

ans = []
for i,a in i_a:
  ans.append(a)
  
print(' '.join(map(str,ans)))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
i_a = [[a,i+1] for i,a in enumerate(A)]
i_a.sort()

ans = []
for i,a in i_a:
  ans.append(a)
  
print(' '.join(map(str,ans)))
n = int(input())
for i in range(n):
    t, x, y = map(int, input().split())
    if x + y < t or (x + y + t) % 2:
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

a, b = map(int,input().split())
if a * b % 2== 0:
	print("Even")
else:
	print("Odd")
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
b = [0]*n
for i in range(m):
  b.index(a[i][0]-1) += 1
  b.index(a[i][1]-1) += 1
for i in range(n):
  print(b[i])


### FIXED CODE ###

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
b = [0]*n
for i in range(m):
  b[a[i][0]-1] += 1
  b[a[i][1]-1] += 1
for i in range(n):
  print(b[i])
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = math.ceil(math.log10(n))
  cand_753 = (3, 5, 7)
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()


### FIXED CODE ###

import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = int(math.log10(n)) + 2
  cand_753 = ("3", "5", "7")
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = map(int,input().split())
A = [int(i) for i in input().split()]
change = [0 for i in range(M)]
for i in range(M):
    change[i] = [int(i) for i in input().split()]

A.sort()
change = sorted(change,key=lambda x:x[1])
change.reverse()

ans = 0
b,c = change[0]
for i in range(N):
    if A[i] > c:
        break
partA = A[:i]

ans += sum(A[i:])
# print(partA)
# print(ans)
for i in range(M):
    count,value = change[i]
    if len(partA) == 0:
        break
    if partA[0] > value:
        break
    for j in range(count):
        if partA[j] < value:
            partA[j] = value
            ans += value
    partA = list(filter(lambda partA:partA != value,partA))
    partA.sort()


ans += sum(partA)
print(ans)


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,M = map(int,input().split())
A = [int(i) for i in input().split()]
change = [0 for i in range(M)]
for i in range(M):
    change[i] = [int(i) for i in input().split()]

D = []
change = sorted(change,key=lambda x:x[1],reverse=True)
for i in range(M):
    b,c = change[i]
    for j in range(b):
        D += [c]
    if len(D) > N:
        break

A += D
A.sort(reverse=True)
print(sum(A[:N]))
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    from itertools import accumulate

    B = [0] + A
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    B = list(accumulate(B))
    BB = Counter(B)

    cnt = 0
    for k, v in BB.items():
        if v >= 2:
            cnt += (v*(v - 1) // 2)
    print(cnt)


resolve()

### FIXED CODE ###

from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    from itertools import accumulate

    B = [0] + A
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    B = list(accumulate(B))
    BB = Counter(B)

    cnt = 0
    for k, v in BB.items():
        if v >= 2:
            cnt += (v*(v - 1) // 2)
    print(cnt)


resolve()
n=int((input())
def f(n):
    a=0
    b=100
    while True:
        a+=1
        b*=(100+a)/100
        b=int(b)
        if b>=n:
            break
    return a
print(f(n))

### FIXED CODE ###

n=int(input())
a,b=map(int,input().split())
l=[abb for abb in range(a, b+1)]
kl=[]
for am in l:
    if am%n==0:
        kl.append(am)
if len(kl)>0:
    print("OK")
else:
    print("NG")
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]



print(x-1+(y-1)//9)
    
    


    
    
    
    
    
    
    

    

    
    


    
    
    
    
    
    
    

    

    
    


    
    
    
    
    
    
    





    
    
    
    
    
    
    

    

    
    


    
    
    
    
    
    
    

    

    
    


    
    
    
    
    
    
    

    

### FIXED CODE ###

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

x=[300000,200000,100000]+[0]*300
y=[300000,200000,100000]+[0]*300

if a==1 and b==1:
    print(1000000)

else:
    print(x[a-1]+x[b-1])
L,R=map(int,input().split())
l,r=L%2019,R%2019
x,y=L//2019,R//2019
if x<y:
  print(0)
else:
  ans=10**9
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min(ans,(i*j)%2019)
print(ans)

### FIXED CODE ###

L,R=map(int,input().split())
l,r=L%2019,R%2019
x,y=L//2019,R//2019
if x<y:
  print(0)
else:
  ans=10**9
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min(ans,(i*j)%2019)
  print(ans)
num = int(input())
bunsyo = input()
count = 0

for i in range(len(bunsyo)):
  if bunsyo[i] == 'A':
    if bunsyo[i+1] =='B':
      if bunsyo[i+2] == 'C':
        count = count + 1
print(count)

### FIXED CODE ###

num = int(input())
bunsyo = input()
count = 0

for i in range(len(bunsyo)):
  if i+2 > num-1:
    continue
  if bunsyo[i] == 'A':
    if bunsyo[i+1] =='B':
      if bunsyo[i+2] == 'C':
        count = count + 1
print(count)
def solve(a, b, c):
    print(f"{c} {a} {b}")


if __name__ == '__main__':
    xyz = input().split()

    x = int(xyz[0])
    y = int(xyz[1])
    z = int(xyz[2])

    solve(x, y, z)

### FIXED CODE ###

def solve(a, b, c):
    print("%d %d %d"% (c, a, b))


if __name__ == '__main__':
    xyz = input().split()

    x = int(xyz[0])
    y = int(xyz[1])
    z = int(xyz[2])

    solve(x, y, z)
N=int(input())
i=int(input())
j = N - i +1
print(j)

### FIXED CODE ###

s=input().split()
N=int(s[0])
i=int(s[1])
j = N - i +1
print(j)
a = input()
print(a*a*a)

### FIXED CODE ###

a = int(input())
print(a*a*a)
length = int(raw_input())
count = length
answer = raw_input()

def compare(current, i):
  if current[i] < answer[i]:
    answer = current
  elif current[i] == answer[i]:
    compare(current, i+1)

while count > 0:
  current_word = raw_input()
  compare(current_word, 0)
  count -= 1

print answer
  

### FIXED CODE ###

s = []
n = input()
 
for i in range(n):
    x = raw_input()
    s.append(x)
 
s.sort()
 
print s[0]
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)


### FIXED CODE ###

N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N-1:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)
n,m = map(int,input().split())

l1 = [[] for i in range(n)]
l2 = []

for i in range(m):
    p,y = map(int,input().split())
    l1[p].append(y)
    l2.append((p,y))

for p in range(n):
    l1[p].sort()

for i in range(m):
    p = l2[i][0]
    k = l1[p].index(l2[i][1])+1
    p = str(p)
    k = str(k)
    ans = "0"*(6-len(p))+p+"0"*(6-len(k))+k
    print(ans)



### FIXED CODE ###

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

l1 = [[] for i in range(n)]
l2 = []

for i in range(m):
    p,y = map(int,input().split())
    l1[p-1].append(y)
    l2.append((p,y))

dic = {}

for p in range(n):
    l1[p].sort()
    for i in range(len(l1[p])):
        dic[l1[p][i]] = i+1
        

for i in range(m):
    p = l2[i][0]
    k = dic[l2[i][1]]
    p = str(p)
    k = str(k)
    ans = "0"*(6-len(p))+p+"0"*(6-len(k))+k
    print(ans)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def FI(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline().split())
def S(): return input()

n, a, b = LI()

if a>b:
	print(0)
elif n=1 and a!=b:
	print(0)
else:
	mi = a*(n-1)+b
	ma = a+b*(n-1)
	print(ma-mi+1)

### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def FI(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline().split())
def S(): return input()

n, a, b = LI()

if a>b:
	print(0)
elif n==1 and a!=b:
	print(0)
else:
	mi = a*(n-1)+b
	ma = a+b*(n-1)
	print(ma-mi+1)