Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#


def main():
    a, b, n = map(int, input().split(" "))
    fac = 0
    for i in range(n + 1):
        j = i // b
        if j == 0:
            if fac < i:
                fac = i
        else:
            break
    ans = a * fac // b - a * (fac // b)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#


def main():
    a, b, n = map(int, input().split(" "))
    fac = 0
    start = min(b, n)
    if b <= n:
        fac = start - 1
    else:
        fac = start
    ans = a * fac // b - a * (fac // b)
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###


S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)


isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
        # print("reverse", S)
        # S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        d = f=="1"
        if isReversed: d = not d
        if d:
            S = c + S
        else:
            # print("append c to tail of ", S)
            S = S + c

if isReversed:
    S = S[::-1]
print(S)

### FIXED CODE ###

S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))
### BUGGY CODE ###

import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<10**5:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if not S_raw:
        break
    cnt+=1
    
print(N*2)

### FIXED CODE ###

S = input()

num0 = S.count("0")
num1 = len(S)-num0

print(min(num0,num1)*2)
### BUGGY CODE ###

def dijkstra(s: int, n: int, w: int, cost: list) -> list:
    d = [float("inf")]*n
    used = [False]*n
    d[s] = 0

    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i

        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j], d[v]+cost[v][j])

    return d

n = int(input())
t = [[float("inf")]*(n) for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    t[a-1][b-1] = c
    t[b-1][a-1] = c

q, k = map(int, input().split())
k -= 1
d = dijkstra(k, n, n-1, t)

for _ in range(q):
    x, y = map(int, input().split())
    print(d[x-1]+d[y-1])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def dfs(v: int, p: int = -1, s: int = 0):
    dist[v] = s
    for i, j in t[v]:
        if i == p:
            continue
        dfs(i, v, s + j)

n = int(input())
t = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1;
    t[a].append((b, c))
    t[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dist = [0]*n

dfs(k)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])
### BUGGY CODE ###

import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = map(int,input().split())
if N == 1:
    print(1)
    exit()
graph = [set() for _ in range(N+1)]
for _ in range(N-1):
    x,y = map(int,input().split())
    graph[x].add(y)
    graph[y].add(x)

dp_1 = [None] * (N+1)
products = [None] * (N+1)
dp_ = [None] * (N+1)

def dfs_1(v=1,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    # dp_1 + 1 の積
    x = 1
    graph[v].discard(parent)
    arr = [dfs_1(w,v)+1 for w in graph[v]]
    L = [1] + list(itertools.accumulate(arr, lambda x,y: x*y%MOD))
    R = list(itertools.accumulate(arr[1:][::-1], lambda x,y: x*y%MOD))[::-1] + [1]
    products[v] = [x*y%MOD for x,y in zip(L,R)]
    dp_1[v] = 1 if not arr else products[v][0] * arr[0] % MOD
    return dp_1[v]

dp_1 = [0] * (N+1) # 自分を黒く塗って、子側の部分木を適切に塗る方法
dfs_1()

dp_1

products

def dfs_2(v=1,parent=None,x=1):
    # それぞれの子以外の情報をマージして、子に渡さなければいけない
    dp[v] = x * dp_1[v] % MOD
    for w,p in zip(graph[v],products[v]):
        dfs_2(w,v,x*p%MOD+1)

dp = [None] * (N+1)
dfs_2()

print('\n'.join(map(str,dp[1:])))

### FIXED CODE ###

import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = map(int,input().split())
if N == 1:
    print(1)
    exit()
graph = [set() for _ in range(N)]
for row in sys.stdin.readlines():
    x,y = map(int,row.split())
    graph[x-1].add(y-1)
    graph[y-1].add(x-1)

ldp = [None] * N
rdp = [None] * N

def dfs_1(v=0,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    graph[v].discard(parent)
    ldp[v] = [1] * (len(graph[v])+1)
    rdp[v] = [1] * (len(graph[v])+1)
    vals = [dfs_1(w,v)+1 for w in graph[v]]
    for i,x in enumerate(vals,1):
        ldp[v][i] = ldp[v][i-1] * x % MOD
    for i,x in enumerate(reversed(vals),1):
        rdp[v][-i-1] = rdp[v][-i] * x % MOD
    return ldp[v][-1]

dfs_1()

dp = [None] * N
q = [(0,1)]
while q:
    v,x = q.pop()
    dp[v] = x*ldp[v][-1]%MOD
    for w,L,R in zip(graph[v],ldp[v][:-1],rdp[v][1:]):
        q.append((w,x*L*R%MOD+1))

print('\n'.join(map(str,dp)))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
stm = ""
count = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
    else:
      stm = stm + e

st = sth + stm
if(count % 2 == 1):
  st = st[::-1]
      
print(st)

### FIXED CODE ###

# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
sth2 = ""
stm = ""
stm2 = ""
count = 0
flagh = 0
flagm = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
      if(len(sth) > 5000 and flagh == 0):
        flagh = 1
        sth2 = sth
        sth = ""
    else:
      stm = stm + e
      if(len(stm) > 5000 and flagm == 0):
        flagm = 1
        stm2 = stm
        stm = ""
      

st = sth + sth2 + stm2 + stm
if(count == 1):
  st = st[::-1]
  
print(st)
### BUGGY CODE ###

def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    N, M = LI()
    A = LI()
    A.sort()
    l = 0; r = 10**6
    while(r-l>1):
        now = (l+r)//2
        cnt = 0
        for i in range(N):
            need = now-A[i]
            c = bisect.bisect_left(A,need)
            cnt += N-c
        if cnt>=M:
            l = now
        else:
            r = now
    base = l
    candi = []
    for i in range(N):
        need = base - A[i]
        c = bisect.bisect_left(A, need)
        for j in range(c,N):
            candi.append(A[i]+A[j])
    candi.sort(reverse=True)
    ans = sum(candi[:M])
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

### FIXED CODE ###

def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    N, M = LI()
    A = LI()
    A.sort()
    ma = max(A)
    l = 0; r = ma*2+1
    while(r-l>1):
        now = (l+r)//2
        cnt = 0
        for a in A:
            need = now-a
            if need>ma:
                continue
            c = bisect.bisect_left(A,need)
            cnt += N-c
        if cnt>=M:
            l = now
        else:
            r = now
    base = l
    cnt = 0
    ans = 0
    S = [0]+A
    for i in range(N):
        S[i+1] += S[i]
    #print(S)
    for a in A:
        need = base - a
        c = bisect.bisect_left(A, need+1)
        ans += a*(N-c) + S[N]-S[c]
        cnt += (N-c)
    if cnt<M:
        ans += base*(M-cnt)
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""
### BUGGY CODE ###

S = input()
N = len(S)

a = 0
while a == 0:
    S = S.replace("0110", "")
    S = S.replace("1001", "")
    S = S.replace("01", "")
    S = S.replace("10", "")
    if "01" in S or "10" in S:
        a = 0
    else:
        a = 1

print(str(N - len(S)))

### FIXED CODE ###

S = input()
N = len(S)
c0 = S.count("0")
c1 = S.count("1")
 
print(2*min(c0, c1))
### BUGGY CODE ###

n = int(input())
s = "0357"
ans = []
for a in s:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    for f in s:
                        for g in s:
                            for h in s:
                                for i in s:
                                    for j in s:
                                        for k in s:
                                            o = int(a+b+c+d+e+f+g+h+i+j+k)
                                            if set(str(o)) == {"3","5","7"}:
                                                if o > n:
                                                    break
                                                else:
                                                    ans.append(o)
print(len(ans))
                                             

### FIXED CODE ###

n = int(input())
s = "0357"
ans = []
for a in s:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    for f in s:
                        for g in s:
                            for h in s:
                                for i in s:
                                    for j in s:
                                        for k in s:
                                            o = int(a+b+c+d+e+f+g+h+i+j+k)
                                            if o > n:
                                                break
                                            elif set(str(o)) == {"3","5","7"}:
                                                ans.append(o)
print(len(ans))
### BUGGY CODE ###

import math
from functools import reduce
K = int(input())
sum = 0
for i in range(1,K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      gcd = math.gcd(k, math.gcd(i, j))
      sum = sum + gcd
print(sum)

### FIXED CODE ###

from math import gcd

k = int(input())
sum = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(c, gcd(a, b))
print(sum)
### BUGGY CODE ###

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): 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())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m,k = LI()
    d = LI()
    v = [LI() for _ in range(n)]
    u = set()
    ds = set(d)
    u.add(tuple(d))
    q = [(tuple(d), 1)]
    while q:
        qd, qk = q.pop(0)
        for vi in range(k):
            t = set()
            for di in qd:
                t.add(v[di-1][vi])
            t &= ds
            tt = tuple(t)
            if tt in u:
                continue
            if len(tt) == 0:
                return qk
            u.add(tt)
            q.append((tt,qk+1))

    return -1



print(main())




### FIXED CODE ###

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): 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())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m,k = LI()
    d = LI_()
    v = [LI_() for _ in range(n)]
    dd = collections.defaultdict(lambda: None)
    for i in range(m):
        dd[d[i]] = i
    ii = [2**_ for _ in range(m)]
    vv = [[ii[dd[v[c][i]]] if not dd[v[c][i]] is None else 0  for c in d] for i in range(k)]
    m2 = 2**m
    u = [None] * m2
    u[-1] = 1
    q = [m2-1]
    r = 0
    while q:
        r += 1
        nq = []
        for qd in q:
            qdi = [di for di in range(m) if qd & ii[di]]
            for vi in range(k):
                t = 0
                vvi = vv[vi]
                for di in qdi:
                    t |= vvi[di]
                if not u[t] is None:
                    continue
                if t == 0:
                    return r
                u[t] = 1
                nq.append(t)
        q = nq

    return -1



print(main())
### BUGGY CODE ###

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353

    dp = [[0]*3001 for _ in [0]*n]
    dp[0][a[0]] = 1
    for j, i in enumerate(a[1:]):
        dp[j+1][i] += (j+2)
        for k in range(3001-i):
            dp[j+1][i+k] = (dp[j+1][i+k]+dp[j][k]) % mod
        for k in range(3001):
            dp[j+1][k] = (dp[j+1][k]+dp[j][k]) % mod
    print(sum([dp[i][s] for i in range(n)]) % mod)


main()


### FIXED CODE ###

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353

    dp = [[0]*3001 for _ in [0]*n]
    dp[0][a[0]] = 1
    for j, i in enumerate(a[1:]):
        dp[j+1][i] += (j+2)
        for k in range(3001-i):
            dp[j+1][i+k] = (dp[j+1][i+k]+dp[j][k]) % mod
        for k in range(3001):
            dp[j+1][k] = (dp[j+1][k]+dp[j][k]) % mod
    print(sum([dp[i][s] for i in range(n)]) % mod)


main()
### BUGGY CODE ###

import itertools


input()
s = list(input())
r =[]
g =[]
b =[]
n= len(s)
ans =0
for i in range(n):
    if s[i]== "R":
        r.append(i+1)
    elif s[i]== "G":
        g.append(i+1)
    else:
        b.append(i+1)

for ri , gi in itertools.product(r,g):
    rg=gi-ri
    if rg+gi in b:
        ans -=1
    if  ri-rg in b:
        ans -=1
    if (gi+ri)/2 in b:
        ans -=1

ans += len(r)*len(b)*len(g)
print(ans)


### FIXED CODE ###

import sys
import math
import itertools
from functools import reduce
from functools import lru_cache


# \n
def input():
    return sys.stdin.readline().rstrip()

def main():

    N=int(input())
    S=list(input())

    R=[0]*N
    G=[0]*N
    B=[0]*N
    r=0
    g  =0
    b=0
    count =0
    for i in range(N-1,-1,-1):
        if S[i] =="R":
            r+=1
        elif S[i] =="G":
            g+=1
        else:
            b+=1
        R[i]=r
        G[i]=g
        B[i]=b

    count =0
    for i in range(N):



        for j in range(i+1,N):
            SE = set(["R", "G", "B"])
            I = S[i]
            SE.remove(I)
            J =S[j]
            if I==J:
                continue
            SE.remove(J)
            if "G" in SE:
                count+=G[j]
                if j+j-i <N and S[j+j-i] =="G":
                    count -=1

            elif "R" in SE:
                count+=R[j]
                if j+j-i <N and S[j+j-i] =="R":
                    count -=1
            else:
                count+=B[j]
                if j+j-i <N and S[j+j-i] =="B":
                    count -=1



    print(count)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

H,W,D = map(int,input().split())
Point = {}
for y in range(H) :
    line = list(map(int,input().split()))
    for x,p in enumerate(line) :
        Point[p] = (y,x)

Q = int(input())

def dist(ny,nx,py,px) :
    return abs(ny-py) + abs(nx-px)

for i in range(Q) :
    l,r = map(int,input().split())
    ny,nx = Point[l]
    res = 0
    while l != r :
        l += D
        py,px = ny,nx
        ny,nx = Point[l]
        res += dist(ny,nx,py,px)
    print(res)


### FIXED CODE ###

H,W,D = map(int,input().split())
Point = {}
for y in range(H) :
    line = list(map(int,input().split()))
    for x,p in enumerate(line) :
        Point[p] = (y,x)

Q = int(input())

def dist(ny,nx,py,px) :
    return abs(ny-py) + abs(nx-px)

Cost = [0]*(H*W+1)
for i in range(D+1, H*W+1) :
    yi,xi = Point[i-D]
    yj,xj = Point[i]
    Cost[i] = Cost[i-D] + dist(yi,xi,yj,xj)


for i in range(Q) :
    l,r = map(int,input().split())
    print(Cost[r] - Cost[l])
### BUGGY CODE ###

n, m = list(map(int, input().split()))
lr_list = list()
for _ in range(m):
    lr_list.append(list(map(int, input().split())))

master_card_set = {i for i in range(1, n + 1)}

for l, r in lr_list:
    card_set = {i for i in range(l, r + 1)}
    master_card_set = master_card_set & card_set

print(len(master_card_set))

### FIXED CODE ###

n, m = list(map(int, input().split()))
# lr_list = list()
l_list = list()
r_list = list()
for _ in range(m):
    l, r = list(map(int, input().split()))
    l_list.append(l)
    r_list.append(r)
    # lr_list.append(list(map(int, input().split())))

min_r = min(r_list)
max_l = max(l_list)
if max_l <= min_r:
    print(min_r - max_l + 1)
else:
    print(0)
### BUGGY CODE ###

s=input()
k=int(input())
n=len(s)
ans=[]
for i in range(1,n+1):
  for j in range(n-i+1):ans.append(s[j:j+i])
ans=sorted(list(set(ans)))
print(ans[k-1])

### FIXED CODE ###

s=input()
k=int(input())
a={s}
for i in range(k):
  for j in range(len(s)-i):a.add(s[j:j+i+1])
print(sorted(list(a))[k-1])
### BUGGY CODE ###

""" E
    https://atcoder.jp/contests/abc173/tasks/abc173_e
"""
import sys
import math
from functools import reduce

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, X, M):
    A = X
    l = [A]
    i = -1
    for _ in range(1, N):
        A = (A * A) % M if M > 0 else 0
        if A in l:
            i = l.index(A)
            break
        else:
            l.append(A)

    if i == -1:
        return sum(l)
    else:
        s1 = sum(l[:i])
        len_repeat = len(l) - i
        s2 = sum(l[i:])

        return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])

if __name__ == "__main__":
    _N, _X, _M = readIntegerSet(3)

    print(main(_N, _X, _M))

### FIXED CODE ###

""" E
    https://atcoder.jp/contests/abc173/tasks/abc173_e
"""
import sys
import math
from functools import reduce

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, X, M):
    A = X
    m = {A: A}
    i = -1
    for j in range(1, M):
        A = (A * A) % M if M > 0 else 0
        if A in m:
            i = list(m.keys()).index(A)
            break
        else:
            m[A] = A

    if i == -1:
        return sum(m.values())
    else:
        l = list(m.values())
        s1 = sum(l[:i])
        len_repeat = len(l) - i
        s2 = sum(l[i:])

        return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])

if __name__ == "__main__":
    _N, _X, _M = readIntegerSet(3)

    print(main(_N, _X, _M))
### BUGGY CODE ###

# Union Find 木
from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    if i < j:
        parent[i] += parent[j]
        parent[j] = i
    else:
        parent[j] += parent[i]
        parent[i] = j


setrecursionlimit(10 ** 6)

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

parent = [-1] * (N + 1)
for L, R, D in LRD:
    unite(parent, L, R)

d = {}
for i in range(1, N + 1):
    if parent[i] < 0:
        d[i] = 0

q = []
for L, R, D in LRD:
    if L > R:
        L, R = R, L
        D = -D
    q.append((L, R, D))

while q:
    nq = []
    for L, R, D in q:
        if L in d and R in d:
            if d[L] + D != d[R]:
                print('No')
                exit()
        elif L in d:
            d[R] = d[L] + D
        elif R in d:
            d[L] = d[R] - D
        else:
            nq.append((L, R, D))
    q = nq
print('Yes')


### FIXED CODE ###

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

links = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    links[L].append((R, D))
    links[R].append((L, -D))

t = [None] * (N + 1)
for i in range(1, N + 1):
    if t[i] is not None:
        continue
    t[i] = 0
    s = [i]
    while s:
        j = s.pop()
        for k, l in links[j]:
            if t[k] is None:
                t[k] = t[j] + l
                s.append(k)
            else:
                if t[k] != t[j] + l:
                    print('No')
                    exit()
print('Yes')
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
A = [int(a) for a in input().split()]

ans = 0
memo = defaultdict(lambda: 0)

for i in range(1, len(A))[::-1]:
    memo[A[i]] += 1
    
    for h in list(memo.keys()):
        if (A[i-1] > h):
            diff = A[i-1] - h
            ans += diff * memo[h]
            # print(h, memo[h], diff)
            memo[h+diff] = memo[h]
            memo[h] = 0
            

    # print(memo)

print(ans)

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]

ans = 0

for i in range(len(A)-1):
    if A[i] > A[i+1]:
        diff = A[i] - A[i+1]
        A[i+1] += diff
        ans += diff

print(ans)