Input:
s = list(map(int,list(input())))

def search(i,current,signs):

    if i == 4:

        if current == 7:

            return signs

        else: return []

    return search(i+1,current+s[i],signs+['+']) + search(i+1,current-s[i],signs+['-'])

signs = search(1,s[0],[])

for i in range(4):

    if i == 3:

        print(s[i], end='')

    else:

        print(s[i], end='')

        print(signs[i], end='')

print('=7')

p = list(map(int, list(input())))

def add(x,y,s):

    if s == 0: return x+y

    else: return x-y

def bittolist(x):

    ret = []

    for _ in range(3):

        ret.append(x%2)

        x //= 2

    return ret

def pm(s):

    if s == 0:

        return '+'

    else: return '-'

for i in range(8):

    s = bittolist(i)

    res = p[0]

    for j in range(3):

        res = add(res, p[j+1], s[j])

    if res == 7:

        print(p[0], end = '')

        print(pm(s[0]), end = '')

        print(p[1], end = '')

        print(pm(s[1]), end = '')

        print(p[2], end = '')

        print(pm(s[2]), end = '')

        print(p[3], end = '')

        print('=7')

        exit()

s = list(map(int, list(input())))

def search(i, current, signs):
    if i == 4:
        if current == 7:
            return signs
        else:
            return []
    return search(i + 1, current + s[i], signs + ["+"]) + search(
        i + 1, current - s[i], signs + ["-"]
    )

signs = search(1, s[0], [])
for i in range(4):
    if i == 3:
        print(s[i], end="")
    else:
        print(s[i], end="")
        print(signs[i], end="")
print("=7")

p = list(map(int, list(input())))

def add(x, y, s):
    if s == 0:
        return x + y
    else:
        return x - y

def bittolist(x):
    ret = []
    for _ in range(3):
        ret.append(x % 2)
        x //= 2
    return ret

def pm(s):
    if s == 0:
        return "+"
    else:
        return "-"

for i in range(8):
    s = bittolist(i)
    res = p[0]
    for j in range(3):
        res = add(res, p[j + 1], s[j])
    if res == 7:
        print(p[0], end="")
        print(pm(s[0]), end="")
        print(p[1], end="")
        print(pm(s[1]), end="")
        print(p[2], end="")
        print(pm(s[2]), end="")
        print(p[3], end="")
        print("=7")
        exit()

-    return search(i + 1, current + s[i], signs + ["+"]) + search(

-        i + 1, current - s[i], signs + ["-"]


Input:
N=int(eval(input()))

p=[]

r=0

if N%2==0:

  c=0

  while N%2==0:

    N=N//2

    c+=1

  p.append(c)

for i in range(3,int(N**0.5)+1,2):

  if N%i==0:

    c=0

    while N%i==0:

      N=N//i

      c+=1

    p.append(c)

if N!=1:

  p.append(1)

while p:

  r+=int(((8*p.pop()+1)**0.5-1)/2)

print(r)

def f(n):

  p=[]

  if n%2==0:

    c=0

    while n%2==0:

      c+=1

      n/=2

    p.append(c)

  for i in range(3,int(n**0.5)+1,2):

    if n%i==0:

      c=0

      while n%i==0:

        c+=1

        n/=i

      p.append(c)

  if n!=1:

    p.append(1)

  return p

N=int(eval(input()))

p=f(N)

r=0

while p:

  r+=int(((8*p.pop()+1)**0.5-1)/2)

print(r)

def f(n):
    p = []
    if n % 2 == 0:
        c = 0
        while n % 2 == 0:
            c += 1
            n /= 2
        p.append(c)
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            c = 0
            while n % i == 0:
                c += 1
                n /= i
            p.append(c)
    if n != 1:
        p.append(1)
    return p

N = int(eval(input()))
p = f(N)
r = 0
while p:
    r += int(((8 * p.pop() + 1) ** 0.5 - 1) / 2)
print(r)


Input:
import sys

input = sys.stdin.readline

import math

import collections

def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

r=I()

print((3*r*r))

def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby, product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    from math import floor, ceil,pi,factorial

    from operator import itemgetter

    def I(): return int(eval(input()))

    def MI(): return list(map(int, input().split()))

    def LI(): return list(map(int, input().split()))

    def LI2(): return [int(eval(input())) for i in range(n)]

    def MXI(): return [[LI()]for i in range(n)]

    def SI(): return input().rstrip()

    def printns(x): print(('\n'.join(x)))

    def printni(x): print(('\n'.join(list(map(str,x)))))

    inf = 10**17

    mod = 10**9 + 7

#main code here!

    r=I()

    print((3*r**2))

if __name__=="__main__":

    main()

import sys

input = sys.stdin.readline
import math
import collections

def I():
    return int(eval(input()))

def MI():
    return list(map(int, input().split()))

def LI():
    return list(map(int, input().split()))

r = I()
print((3 * r * r))

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil, pi, factorial
    from operator import itemgetter

    def I():
        return int(eval(input()))

    def MI():
        return list(map(int, input().split()))

    def LI():
        return list(map(int, input().split()))

    def LI2():
        return [int(eval(input())) for i in range(n)]

    def MXI():
        return [[LI()] for i in range(n)]

    def SI():
        return input().rstrip()

    def printns(x):
        print(("\n".join(x)))

    def printni(x):
        print(("\n".join(list(map(str, x)))))

    inf = 10**17
    mod = 10**9 + 7
    # main code here!
    r = I()
    print((3 * r**2))

if __name__ == "__main__":
    main()

+    from collections import Counter, deque

+    from collections import defaultdict

+    from itertools import combinations, permutations, accumulate, groupby, product

+    from bisect import bisect_left, bisect_right

+    from heapq import heapify, heappop, heappush

+    from math import floor, ceil, pi, factorial

+        return list(map(int, input().split()))

+        return [int(eval(input())) for i in range(n)]

+        return [[LI()] for i in range(n)]

+        print(("\n".join(list(map(str, x)))))

-    return list(map(int, input().split()))


Input:
n,x = list(map(int,input().split()))

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

res = float('inf')

for b in (a,a[::-1]):

    tmp = 0

    for i in range(n-1):

        if b[i]+b[i+1]>x:

            tmp += b[i] + b[i+1] - x

            if b[i]>x:

                b[i],b[i+1] = x,0

            else:

                b[i+1] = x - b[i]

    res = min(res,tmp)

print(res)

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

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

res = 0

if a[0]>x:

    res += a[0] - x

    a[0] = x

if a[-1]>x:

    res += a[-1] - x

    a[-1] = x

for i in range(n-1):

    if a[i]+a[i+1]>x:

        res += a[i] + a[i+1] - x

        a[i+1] -= a[i] + a[i+1] - x

print(res)

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = float("inf")
for b in (a, a[::-1]):
    tmp = 0
    for i in range(n - 1):
        if b[i] + b[i + 1] > x:
            tmp += b[i] + b[i + 1] - x
            if b[i] > x:
                b[i], b[i + 1] = x, 0
            else:
                b[i + 1] = x - b[i]
    res = min(res, tmp)
print(res)

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
if a[0] > x:
    res += a[0] - x
    a[0] = x
if a[-1] > x:
    res += a[-1] - x
    a[-1] = x
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        res += a[i] + a[i + 1] - x
        a[i + 1] -= a[i] + a[i + 1] - x
print(res)


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

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

X.sort()

diff = []

if M != 1:

  for i in range(M-1):

    diff.append(X[i+1]-X[i])

else:

  diff = [0]

sorted_diff = sorted(diff)

sorted_diff.reverse()

ans = sum(sorted_diff)

for i in range(min([N,M])-1):

  ans -= sorted_diff[i]

print(ans)

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

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

X.sort()

d = []

for i in range(M-1):

  d.append(X[i+1]-X[i])

d.sort()

if M-N >= 0:

  print((sum(d[0:M-N])))

else:

  print((0))

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
diff = []
if M != 1:
    for i in range(M - 1):
        diff.append(X[i + 1] - X[i])
else:
    diff = [0]
sorted_diff = sorted(diff)
sorted_diff.reverse()
ans = sum(sorted_diff)
for i in range(min([N, M]) - 1):
    ans -= sorted_diff[i]
print(ans)

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
d = []
for i in range(M - 1):
    d.append(X[i + 1] - X[i])
d.sort()
if M - N >= 0:
    print((sum(d[0 : M - N])))
else:
    print((0))

-diff = []
-if M != 1:
-    for i in range(M - 1):
-        diff.append(X[i + 1] - X[i])
+d = []
+for i in range(M - 1):
+    d.append(X[i + 1] - X[i])
+d.sort()
+if M - N >= 0:
+    print((sum(d[0 : M - N])))
-    diff = [0]
-sorted_diff = sorted(diff)
-sorted_diff.reverse()
-ans = sum(sorted_diff)
-for i in range(min([N, M]) - 1):
-    ans -= sorted_diff[i]
-print(ans)
+    print((0))


Input:
from itertools import count, repeat

h = int(input().split()[0])

a0 = repeat('.')

r0 = count()

for i in range(h):

  a = eval(input())

  r = [i]

  for x, y, z, u in zip(a0, '.' + a, a, r0):

    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))

  a0 = a

  r0 = r[1:]

print((r[-1]))

from itertools import count, repeat

h = int(input().split()[0])

a0 = repeat('.')

r0 = count()

for i in range(h):

  a = eval(input())

  r = [i]

  for x, y, z, u in zip(a0, '.' + a, a, r0):

    r.append(min(u + (x > z), r[-1] + (y > z)))

  a0 = a

  r0 = r[1:]

print((r[-1]))

from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat(".")
r0 = count()
for i in range(h):
    a = eval(input())
    r = [i]
    for x, y, z, u in zip(a0, "." + a, a, r0):
        r.append(min(u + (x + z == ".#"), r[-1] + (y + z == ".#")))
    a0 = a
    r0 = r[1:]
print((r[-1]))

from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat(".")
r0 = count()
for i in range(h):
    a = eval(input())
    r = [i]
    for x, y, z, u in zip(a0, "." + a, a, r0):
        r.append(min(u + (x > z), r[-1] + (y > z)))
    a0 = a
    r0 = r[1:]
print((r[-1]))


Input:
import itertools as it

S = eval(input())

ans = 0

for bits in it.product((True, False), repeat=len(S)-1):

    A = ''

    for s, bit in zip(S, bits + (0,)):

        A += s + '+'*bit

    ans += eval(A)

print(ans)

S = eval(input())

ans = 0

def dfs(s, sum_, n):

    if n == len(S)-1:

        return int(s) + sum_

    return dfs(s+S[n+1], sum_, n+1) + dfs(S[n+1], sum_+int(s), n+1)

print((dfs(S[0], 0, 0)))

import itertools as it

S = eval(input())
ans = 0
for bits in it.product((True, False), repeat=len(S) - 1):
    A = ""
    for s, bit in zip(S, bits + (0,)):
        A += s + "+" * bit
    ans += eval(A)
print(ans)

S = eval(input())
ans = 0

def dfs(s, sum_, n):
    if n == len(S) - 1:
        return int(s) + sum_
    return dfs(s + S[n + 1], sum_, n + 1) + dfs(S[n + 1], sum_ + int(s), n + 1)

print((dfs(S[0], 0, 0)))

-for bits in it.product((True, False), repeat=len(S) - 1):

+    return dfs(s + S[n + 1], sum_, n + 1) + dfs(S[n + 1], sum_ + int(s), n + 1)


Input:
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()))

def d_disjoint_set_of_common_divisors():

    from fractions 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(list(prime_factorization_dict(g).keys())) + 1 if g > 1 else 1

print((d_disjoint_set_of_common_divisors()))

-        """nを素因数分解したときの素数の辞書"""

+        """nを素因数分解したときの素数とその指数の辞書"""

-    a_primekey = prime_factorization_dict(A)

-    b_primekey = prime_factorization_dict(B)

+    return len(list(prime_factorization_dict(g).keys())) + 1 if g > 1 else 1


Input:
# -*- coding: utf-8 -*-

import bisect

import heapq

import math

import random

import sys

from collections import Counter, defaultdict, deque

from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

from functools import lru_cache, reduce

from itertools import combinations, combinations_with_replacement, product, permutations

from operator import add, mul, sub

sys.setrecursionlimit(100000)

def read_int():

    return int(input())

def read_int_n():

    return list(map(int, input().split()))

def read_float():

    return float(input())

def read_float_n():

    return list(map(float, input().split()))

def read_str():

    return input().strip()

def read_str_n():

    return list(map(str, input().split()))

def error_print(*args):

    print(*args, file=sys.stderr)

def mt(f):

    import time

    def wrap(*args, **kwargs):

        s = time.time()

        ret = f(*args, **kwargs)

        e = time.time()

        error_print(e - s, 'sec')

        return ret

    return wrap

class Mod:

    def __init__(self, m):

        self.m = m

    def add(self, a, b):

        return (a + b) % self.m

    def sub(self, a, b):

        return (a - b) % self.m

    def mul(self, a, b):

        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):

        return self.mul(a, self.pow(b, self.m-2))

    def pow(self, x, y):

        if y == 0:

            return 1

        elif y == 1:

            return x % self.m

        elif y % 2 == 0:

            return self.pow(x, y//2)**2 % self.m

        else:

            return self.pow(x, y//2)**2 * x % self.m

class Combination:

    def __init__(self, n, mod):

        g1 = [1, 1]

        g2 = [1, 1]

        inverse = [0, 1]

        for i in range(2, n + 1):

            g1.append((g1[-1] * i) % mod)

            inverse.append((-inverse[mod % i] * (mod//i)) % mod)

            g2.append((g2[-1] * inverse[-1]) % mod)

        self.MOD = mod

        self.N = n

        self.g1 = g1

        self.g2 = g2

        self.inverse = inverse

    def __call__(self, n, r):

        if (r < 0 or r > n):

            return 0

        r = min(r, n-r)

        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD

@mt

def slv(N, M, K):

    m = Mod(10**9+7)

    b = Combination(N*M, 10**9+7)(N*M-2, K-2)

    MM = m.mul(M, M)

    NN = m.mul(N, N)

    ans = 0

    for d in range(1, N):

        ans = m.add(ans, m.mul(m.mul(m.mul(d, N-d), MM), b))

    for d in range(1, M):

        ans = m.add(ans, m.mul(m.mul(m.mul(d, M-d), NN), b))

    return ans

def main():

    N, M, K = read_int_n()

    print(slv(N, M, K))

if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-

import sys

# sys.setrecursionlimit(10**6)

# buff_readline = sys.stdin.buffer.readline

buff_readline = sys.stdin.readline

readline = sys.stdin.readline

INF = 2**62-1

def read_int():

    return int(buff_readline())

def read_int_n():

    return list(map(int, buff_readline().split()))

def read_float():

    return float(buff_readline())

def read_float_n():

    return list(map(float, buff_readline().split()))

def read_str():

    return readline().strip()

def read_str_n():

    return readline().strip().split()

def error_print(*args):

    print(*args, file=sys.stderr)

def mt(f):

    import time

    def wrap(*args, **kwargs):

        s = time.time()

        ret = f(*args, **kwargs)

        e = time.time()

        error_print(e - s, 'sec')

        return ret

    return wrap

class Combination:

    def __init__(self, n, mod):

        g1 = [1, 1]

        g2 = [1, 1]

        inverse = [0, 1]

        for i in range(2, n + 1):

            g1.append((g1[-1] * i) % mod)

            inverse.append((-inverse[mod % i] * (mod//i)) % mod)

            g2.append((g2[-1] * inverse[-1]) % mod)

        self.MOD = mod

        self.N = n

        self.g1 = g1

        self.g2 = g2

        self.inverse = inverse

    def __call__(self, n, r):

        if (r < 0 or r > n):

            return 0

        r = min(r, n-r)

        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD

@mt

def slv(N, M, K):

    mod = 10**9+7

    C = Combination(N*M, mod)

    b = C(N*M-2, K-2)

    ans = 0

    m = M**2

    for d in range(1, N):

        ans += (N-d) * b * d * m

        ans %= mod

    m = N**2

    for d in range(1, M):

        ans += (M-d) * b * d * m

        ans %= mod

    return ans

def main():

    N, M, K = read_int_n()

    print(slv(N, M, K))

if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)

def read_int():
    return int(input())

def read_int_n():
    return list(map(int, input().split()))

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
        error_print(e - s, "sec")
        return ret

    return wrap

class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, self.pow(b, self.m - 2))

    def pow(self, x, y):
        if y == 0:
            return 1
        elif y == 1:
            return x % self.m
        elif y % 2 == 0:
            return self.pow(x, y // 2) ** 2 % self.m
        else:
            return self.pow(x, y // 2) ** 2 * x % self.m

class Combination:
    def __init__(self, n, mod):
        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD

@mt
def slv(N, M, K):
    m = Mod(10**9 + 7)
    b = Combination(N * M, 10**9 + 7)(N * M - 2, K - 2)
    MM = m.mul(M, M)
    NN = m.mul(N, N)
    ans = 0
    for d in range(1, N):
        ans = m.add(ans, m.mul(m.mul(m.mul(d, N - d), MM), b))
    for d in range(1, M):
        ans = m.add(ans, m.mul(m.mul(m.mul(d, M - d), NN), b))
    return ans

def main():
    N, M, K = read_int_n()
    print(slv(N, M, K))

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
import sys

# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1

def read_int():
    return int(buff_readline())

def read_int_n():
    return list(map(int, buff_readline().split()))

def read_float():
    return float(buff_readline())

def read_float_n():
    return list(map(float, buff_readline().split()))

def read_str():
    return readline().strip()

def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
        error_print(e - s, "sec")
        return ret

    return wrap

class Combination:
    def __init__(self, n, mod):
        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD

@mt
def slv(N, M, K):
    mod = 10**9 + 7
    C = Combination(N * M, mod)
    b = C(N * M - 2, K - 2)
    ans = 0
    m = M**2
    for d in range(1, N):
        ans += (N - d) * b * d * m
        ans %= mod
    m = N**2
    for d in range(1, M):
        ans += (M - d) * b * d * m
        ans %= mod
    return ans

def main():
    N, M, K = read_int_n()
    print(slv(N, M, K))

if __name__ == "__main__":
    main()

-from collections import Counter, defaultdict, deque

-from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

-from functools import lru_cache, reduce

-from itertools import combinations, combinations_with_replacement, product, permutations

+# buff_readline = sys.stdin.buffer.readline

-    return list(map(int, input().split()))

+    return list(map(int, buff_readline().split()))

-    return list(map(float, input().split()))

+    return list(map(float, buff_readline().split()))

-    return list(map(str, input().split()))

-        return ((a % self.m) * (b % self.m)) % self.m

-        return self.mul(a, self.pow(b, self.m - 2))

-            return self.pow(x, y // 2) ** 2 % self.m

-            return self.pow(x, y // 2) ** 2 * x % self.m

-        ans = m.add(ans, m.mul(m.mul(m.mul(d, N - d), MM), b))

-        ans = m.add(ans, m.mul(m.mul(m.mul(d, M - d), NN), b))


Input:
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

N = int(readline())

S = readline().rstrip().decode('utf-8')

def solve_partial(S):

    INF = 10**18

    """

    ・Sは1から始まり、1で終わる

    ・Sは00を含まない

    ・したがって、Sは1,01に分解可能

    ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ

    ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp

    ・個数はa,b,eのときに数える

    """

    S = S.replace('01','2')

    a,b,c,d,e = 1,1,INF,0,INF

    for x in S[1:]:

        if x == '1':

            a2 = min(a,c,e)+1

            b2 = min(a,c,e)+1

            c2 = c

            d2 = min(a,c,d,e)

            e2 = INF

        else:

            a2 = min(a,c,e)+1

            b2 = min(a,c,e)+1

            c2 = b

            d2 = min(a,c,e)

            e2 = d+1

        a,b,c,d,e = a2,b2,c2,d2,e2

    return len(S)-min(a,c,e)

answer = 0

for x in S.split('00'):

    x = x.strip('0')

    if x:

        answer += solve_partial(x)

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

N = int(readline())

S = readline().rstrip().decode('utf-8')

def solve_partial(S):

    INF = 10**18

    """

    ・Sは1から始まり、1で終わる

    ・Sは00を含まない

    ・したがって、Sは1,01に分解可能

    ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ

    ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp

    ・個数はa,b,eのときに数える

    """

    S = S.replace('01','2')

    a,b,c,d,e = 1,1,INF,0,INF

    for x in S[1:]:

        if x == '1':

            a2 = min(a,c,e)+1

            c2 = c

            d2 = min(a,c,d,e)

            e2 = INF

        else:

            a2 = min(a,c,e)+1

            c2 = a

            d2 = min(a,c,e)

            e2 = d+1

        a,c,d,e = a2,c2,d2,e2

    return len(S)-min(a,c,e)

answer = 0

for x in S.split('00'):

    x = x.strip('0')

    if x:

        answer += solve_partial(x)

print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode("utf-8")

def solve_partial(S):
    INF = 10**18
    """
    ・Sは1から始まり、1で終わる
    ・Sは00を含まない
    ・したがって、Sは1,01に分解可能
    ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
    ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
    ・個数はa,b,eのときに数える
    """
    S = S.replace("01", "2")
    a, b, c, d, e = 1, 1, INF, 0, INF
    for x in S[1:]:
        if x == "1":
            a2 = min(a, c, e) + 1
            b2 = min(a, c, e) + 1
            c2 = c
            d2 = min(a, c, d, e)
            e2 = INF
        else:
            a2 = min(a, c, e) + 1
            b2 = min(a, c, e) + 1
            c2 = b
            d2 = min(a, c, e)
            e2 = d + 1
        a, b, c, d, e = a2, b2, c2, d2, e2
    return len(S) - min(a, c, e)

answer = 0
for x in S.split("00"):
    x = x.strip("0")
    if x:
        answer += solve_partial(x)
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().rstrip().decode("utf-8")

def solve_partial(S):
    INF = 10**18
    """
    ・Sは1から始まり、1で終わる
    ・Sは00を含まない
    ・したがって、Sは1,01に分解可能
    ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
    ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
    ・個数はa,b,eのときに数える
    """
    S = S.replace("01", "2")
    a, b, c, d, e = 1, 1, INF, 0, INF
    for x in S[1:]:
        if x == "1":
            a2 = min(a, c, e) + 1
            c2 = c
            d2 = min(a, c, d, e)
            e2 = INF
        else:
            a2 = min(a, c, e) + 1
            c2 = a
            d2 = min(a, c, e)
            e2 = d + 1
        a, c, d, e = a2, c2, d2, e2
    return len(S) - min(a, c, e)

answer = 0
for x in S.split("00"):
    x = x.strip("0")
    if x:
        answer += solve_partial(x)
print(answer)


Input:
ROOT = 3

MOD = 998244353

pn = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(30)]

def ntt_rec(a,n):

    if n==0:

        return a[:]

    if n==1:

        return [a[0]+a[1],a[0]-a[1]]

    b = ntt_rec(a[::2],n-1)

    c = ntt_rec(a[1::2],n-1)

    N = 1<<(n-1)

    res = [0]*(N*2)

    w_N = 1

    for k in range(N):

        res[k]   = (b[k] + w_N*c[k])%MOD

        res[k+N] = (b[k] - w_N*c[k])%MOD

        w_N = w_N*pn[n]%MOD

    return res

def intt_rec(a,n):

    res = ntt_rec(a[0:1]+a[1:][::-1],n)

    inv = pow(1<<n,MOD-2,MOD)

    for i in range(1<<n):

        res[i] = res[i]*inv%MOD

    return res

def convolution(a,b):

    deg = len(a) + len(b) - 1

    n = 0

    N = 1

    while deg*2 >= N:

        n += 1

        N <<= 1

    a += [0]*(N-len(a))

    b += [0]*(N-len(b))

    #print(ntt_rec(a,n))

    return intt_rec([ai*bi%MOD for ai,bi in zip(ntt_rec(a,n),ntt_rec(b,n))],n)

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

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

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

#*a, = [1]*10**5

#*b, = [1]*10**5

L = len(a)+len(b)

c = convolution(a,b)

print((*c[:L-1]))

ROOT = 3

MOD = 998244353

roots  = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根

iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元

def untt(a,n):

    for i in range(n):

        m = 1<<(n-i-1)

        for s in range(1<<i):

            w_N = 1

            s *= m*2

            for p in range(m):

                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD

                w_N = w_N*roots[n-i]%MOD

def iuntt(a,n):

    for i in range(n):

        m = 1<<i

        for s in range(1<<(n-i-1)):

            w_N = 1

            s *= m*2

            for p in range(m):

                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD

                w_N = w_N*iroots[i+1]%MOD

    inv = pow((MOD+1)//2,n,MOD)

    for i in range(1<<n):

        a[i] = a[i]*inv%MOD

def convolution(a,b):

    deg = len(a) + len(b) - 2

    n = deg.bit_length()

    N = 1<<n

    a += [0]*(N-len(a))

    b += [0]*(N-len(b))

    untt(a,n)

    untt(b,n)

    for i in range(N):

      a[i] = a[i]*b[i]%MOD

    iuntt(a,n)

    return a[:deg+1]

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

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

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

c = convolution(a,b)

print((*c))

ROOT = 3
MOD = 998244353
pn = [pow(ROOT, (MOD - 1) >> i, MOD) for i in range(30)]

def ntt_rec(a, n):
    if n == 0:
        return a[:]
    if n == 1:
        return [a[0] + a[1], a[0] - a[1]]
    b = ntt_rec(a[::2], n - 1)
    c = ntt_rec(a[1::2], n - 1)
    N = 1 << (n - 1)
    res = [0] * (N * 2)
    w_N = 1
    for k in range(N):
        res[k] = (b[k] + w_N * c[k]) % MOD
        res[k + N] = (b[k] - w_N * c[k]) % MOD
        w_N = w_N * pn[n] % MOD
    return res

def intt_rec(a, n):
    res = ntt_rec(a[0:1] + a[1:][::-1], n)
    inv = pow(1 << n, MOD - 2, MOD)
    for i in range(1 << n):
        res[i] = res[i] * inv % MOD
    return res

def convolution(a, b):
    deg = len(a) + len(b) - 1
    n = 0
    N = 1
    while deg * 2 >= N:
        n += 1
        N <<= 1
    a += [0] * (N - len(a))
    b += [0] * (N - len(b))
    # print(ntt_rec(a,n))
    return intt_rec([ai * bi % MOD for ai, bi in zip(ntt_rec(a, n), ntt_rec(b, n))], n)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# *a, = [1]*10**5
# *b, = [1]*10**5
L = len(a) + len(b)
c = convolution(a, b)
print((*c[: L - 1]))

ROOT = 3
MOD = 998244353
roots = [pow(ROOT, (MOD - 1) >> i, MOD) for i in range(24)]  # 1 の 2^i 乗根
iroots = [pow(x, MOD - 2, MOD) for x in roots]  # 1 の 2^i 乗根の逆元

def untt(a, n):
    for i in range(n):
        m = 1 << (n - i - 1)
        for s in range(1 << i):
            w_N = 1
            s *= m * 2
            for p in range(m):
                a[s + p], a[s + p + m] = (a[s + p] + a[s + p + m]) % MOD, (
                    a[s + p] - a[s + p + m]
                ) * w_N % MOD
                w_N = w_N * roots[n - i] % MOD

def iuntt(a, n):
    for i in range(n):
        m = 1 << i
        for s in range(1 << (n - i - 1)):
            w_N = 1
            s *= m * 2
            for p in range(m):
                a[s + p], a[s + p + m] = (a[s + p] + a[s + p + m] * w_N) % MOD, (
                    a[s + p] - a[s + p + m] * w_N
                ) % MOD
                w_N = w_N * iroots[i + 1] % MOD
    inv = pow((MOD + 1) // 2, n, MOD)
    for i in range(1 << n):
        a[i] = a[i] * inv % MOD

def convolution(a, b):
    deg = len(a) + len(b) - 2
    n = deg.bit_length()
    N = 1 << n
    a += [0] * (N - len(a))
    b += [0] * (N - len(b))
    untt(a, n)
    untt(b, n)
    for i in range(N):
        a[i] = a[i] * b[i] % MOD
    iuntt(a, n)
    return a[: deg + 1]

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = convolution(a, b)
print((*c))

-pn = [pow(ROOT, (MOD - 1) >> i, MOD) for i in range(30)]

+roots = [pow(ROOT, (MOD - 1) >> i, MOD) for i in range(24)]  # 1 の 2^i 乗根

+iroots = [pow(x, MOD - 2, MOD) for x in roots]  # 1 の 2^i 乗根の逆元

+                w_N = w_N * roots[n - i] % MOD

+        for s in range(1 << (n - i - 1)):

+                w_N = w_N * iroots[i + 1] % MOD

-    return intt_rec([ai * bi % MOD for ai, bi in zip(ntt_rec(a, n), ntt_rec(b, n))], n)


Input:
# EduDPA - Frog 1

n = int(eval(input()))

lst = list(map(int, input().rstrip().split()))

ans = [0, abs(lst[0] - lst[1])] + [float("inf")] * (n - 2)

for i in range(2, n):

    ans[i] = min(ans[i], ans[i - 1] + abs(lst[i] - lst[i - 1]))

    ans[i] = min(ans[i], ans[i - 2] + abs(lst[i] - lst[i - 2]))

print((ans[-1]))

# EduDPA - Frog 1

n = int(eval(input()))

lst = list(map(int, input().rstrip().split()))

a, b = 0, abs(lst[0] - lst[1])

for i in range(2, n):

    dif_1 = a + abs(lst[i] - lst[i - 2])

    dif_2 = b + abs(lst[i] - lst[i - 1])

    a, b = b, min(dif_1, dif_2)

print(b)

-    ans[i] = min(ans[i], ans[i - 1] + abs(lst[i] - lst[i - 1]))

-    ans[i] = min(ans[i], ans[i - 2] + abs(lst[i] - lst[i - 2]))

+    dif_1 = a + abs(lst[i] - lst[i - 2])

+    dif_2 = b + abs(lst[i] - lst[i - 1])


Input:
s = [list(eval(input())) for _ in range(3)]

n_row = 0

dic = {0:"A",1:"B",2:"C"}

while True:

    if len(s[n_row]) == 0:

        break

    s_num = s[n_row].pop(0)

    if s_num == "a":

        n_row = 0

    elif s_num == "b":

        n_row = 1

    elif s_num =="c":

        n_row = 2

print((dic[n_row]))

s = [list(eval(input())) for _ in range(3)]

n_row = 0

dic = {0:"A",1:"B",2:"C"}

while len(s[n_row]):

    s_num = s[n_row].pop(0)

    if s_num == "a":

        n_row = 0

    elif s_num == "b":

        n_row = 1

    elif s_num =="c":

        n_row = 2

print((dic[n_row]))

s = [list(eval(input())) for _ in range(3)]
n_row = 0
dic = {0: "A", 1: "B", 2: "C"}
while True:
    if len(s[n_row]) == 0:
        break
    s_num = s[n_row].pop(0)
    if s_num == "a":
        n_row = 0
    elif s_num == "b":
        n_row = 1
    elif s_num == "c":
        n_row = 2
print((dic[n_row]))

s = [list(eval(input())) for _ in range(3)]
n_row = 0
dic = {0: "A", 1: "B", 2: "C"}
while len(s[n_row]):
    s_num = s[n_row].pop(0)
    if s_num == "a":
        n_row = 0
    elif s_num == "b":
        n_row = 1
    elif s_num == "c":
        n_row = 2
print((dic[n_row]))

-while True:
-    if len(s[n_row]) == 0:
-        break
+while len(s[n_row]):


Input:
# coding: utf-8

# Your code here!

import math

import fractions

def lcm(x, y):

    return (x * y) // fractions.gcd(x, y)

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

print((lcm(a, b)))

def gcd(x,y):

    if x%y==0: return y

    else: return gcd(y,x%y)

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

print((int(a*b/gcd(a,b))))

# coding: utf-8
# Your code here!
import math
import fractions

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

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

def gcd(x, y):
    if x % y == 0:
        return y
    else:
        return gcd(y, x % y)

a, b = list(map(int, input().split()))
print((int(a * b / gcd(a, b))))

-    return (x * y) // fractions.gcd(x, y)


Input:
H, W = list(map(int, input().split()))

ans = [[0 for i in range(W)] for j in range(H)]

mark = []

for i in range(H):

    mark.append(eval(input()))

ans[0][0] = 1

mod = 10**9 + 7

for i in range(H):

    for j in range(W):

        if mark[i][j] == '#':

            continue

        if i > 0:

            ans[i][j] += ans[i-1][j]

        if j > 0:

            ans[i][j] += ans[i][j-1]

        ans[i][j] %= mod

print((ans[H-1][W-1]))

H, W = list(map(int, input().split()))

mark = []

for i in range(H):

    mark.append(eval(input()))

dp = [[0 for i in range(W)] for j in range(H)]

dp[0][0] = 1

mod = int(1e9) + 7

for i in range(H):

    for j in range(W):

        if i > 0 and mark[i - 1][j] == '.':

            dp[i][j] += dp[i - 1][j] % mod

        if j > 0 and mark[i][j - 1] == '.':

            dp[i][j] += dp[i][j - 1] % mod

        dp[i][j] %= mod

print((dp[H - 1][W - 1]))

H, W = list(map(int, input().split()))
ans = [[0 for i in range(W)] for j in range(H)]
mark = []
for i in range(H):
    mark.append(eval(input()))
ans[0][0] = 1
mod = 10**9 + 7
for i in range(H):
    for j in range(W):
        if mark[i][j] == "#":
            continue
        if i > 0:
            ans[i][j] += ans[i - 1][j]
        if j > 0:
            ans[i][j] += ans[i][j - 1]
        ans[i][j] %= mod
print((ans[H - 1][W - 1]))

H, W = list(map(int, input().split()))
mark = []
for i in range(H):
    mark.append(eval(input()))
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
mod = int(1e9) + 7
for i in range(H):
    for j in range(W):
        if i > 0 and mark[i - 1][j] == ".":
            dp[i][j] += dp[i - 1][j] % mod
        if j > 0 and mark[i][j - 1] == ".":
            dp[i][j] += dp[i][j - 1] % mod
        dp[i][j] %= mod
print((dp[H - 1][W - 1]))

-ans = [[0 for i in range(W)] for j in range(H)]

+dp = [[0 for i in range(W)] for j in range(H)]


Input:
def solve(writer):

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

    variables = {

        'A': A,

        'B': B,

        'C': C

    }

    queries = (list(eval(input())) for _ in range(N))

    buffer = list()

    for i in range(N):

        if not buffer:

            t1, t2 = next(queries)

        else:

            b = buffer.pop()

            if b == 'pass':

                continue

            else:

                t1, t2 = list(b)

        v1 = variables[t1]

        v2 = variables[t2]

        if v1 == v2 == 0:

            return False

        elif v1 == v2 == 1:

            if i == N-1:

                writer.append(t1)

                return True

            nt1, nt2 = next(queries)

            if len({t1, t2, nt1, nt2}) == 2:

                buffer.append('pass')

                writer.append(t1)

                writer.append(t2)

                continue

            if t1 in {nt1, nt2}:

                variables[t1] += 1

                variables[t2] -= 1

                writer.append(t1)

            else:

                variables[t1] -= 1

                variables[t2] += 1

                writer.append(t2)

            buffer.append(''.join([nt1, nt2]))

        elif v1 > v2:

            variables[t1] -= 1

            variables[t2] += 1

            writer.append(t2)

        elif v2 > v1:

            variables[t1] += 1

            variables[t2] -= 1

            writer.append(t1)

        else:

            variables[t1] += 1

            variables[t2] -= 1

            writer.append(t1)

    return True

def main():

    writer = list()

    ok = solve(writer)

    if ok:

        print('Yes')

        for w in writer:

            print(w)

    else:

        print('No')

if __name__ == "__main__":

    main()

import sys

readline = sys.stdin.readline

def solve(writer):

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

    variables = {

        'A': A,

        'B': B,

        'C': C

    }

    queries = (list(readline().strip()) for _ in range(N))

    next_q = next(queries)

    for i in range(N):

        let_1, let_2 = next_q

        next_q = next(queries) if i != N - 1 else ()

        if variables[let_1] == variables[let_2] == 0:

            return False

        if variables[let_1] == variables[let_2] == 1 and let_2 in next_q \

                or variables[let_1] > variables[let_2]:

            let_1, let_2 = let_2, let_1

        variables[let_1] += 1

        variables[let_2] -= 1

        writer.append(let_1)

    return True

def main():

    writer = ['Yes']

    ok = solve(writer)

    if ok:

        for w in writer:

            print(w)

    else:

        print('No')

if __name__ == "__main__":

    main()

def solve(writer):
    N, A, B, C = list(map(int, input().split()))
    variables = {"A": A, "B": B, "C": C}
    queries = (list(eval(input())) for _ in range(N))
    buffer = list()
    for i in range(N):
        if not buffer:
            t1, t2 = next(queries)
        else:
            b = buffer.pop()
            if b == "pass":
                continue
            else:
                t1, t2 = list(b)
        v1 = variables[t1]
        v2 = variables[t2]
        if v1 == v2 == 0:
            return False
        elif v1 == v2 == 1:
            if i == N - 1:
                writer.append(t1)
                return True
            nt1, nt2 = next(queries)
            if len({t1, t2, nt1, nt2}) == 2:
                buffer.append("pass")
                writer.append(t1)
                writer.append(t2)
                continue
            if t1 in {nt1, nt2}:
                variables[t1] += 1
                variables[t2] -= 1
                writer.append(t1)
            else:
                variables[t1] -= 1
                variables[t2] += 1
                writer.append(t2)
            buffer.append("".join([nt1, nt2]))
        elif v1 > v2:
            variables[t1] -= 1
            variables[t2] += 1
            writer.append(t2)
        elif v2 > v1:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)
        else:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)
    return True

def main():
    writer = list()
    ok = solve(writer)
    if ok:
        print("Yes")
        for w in writer:
            print(w)
    else:
        print("No")

if __name__ == "__main__":
    main()

import sys

readline = sys.stdin.readline

def solve(writer):
    N, A, B, C = map(int, input().split())
    variables = {"A": A, "B": B, "C": C}
    queries = (list(readline().strip()) for _ in range(N))
    next_q = next(queries)
    for i in range(N):
        let_1, let_2 = next_q
        next_q = next(queries) if i != N - 1 else ()
        if variables[let_1] == variables[let_2] == 0:
            return False
        if (
            variables[let_1] == variables[let_2] == 1
            and let_2 in next_q
            or variables[let_1] > variables[let_2]
        ):
            let_1, let_2 = let_2, let_1
        variables[let_1] += 1
        variables[let_2] -= 1
        writer.append(let_1)
    return True

def main():
    writer = ["Yes"]
    ok = solve(writer)
    if ok:
        for w in writer:
            print(w)
    else:
        print("No")

if __name__ == "__main__":
    main()

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

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

-    queries = (list(eval(input())) for _ in range(N))

+    queries = (list(readline().strip()) for _ in range(N))

+        next_q = next(queries) if i != N - 1 else ()

+        if variables[let_1] == variables[let_2] == 0:

-            buffer.append("".join([nt1, nt2]))

+            variables[let_1] == variables[let_2] == 1

+            or variables[let_1] > variables[let_2]

+            let_1, let_2 = let_2, let_1


Input:
# your code goes here

n = int(eval(input()))

N = str(n)

N = [int(x) for x in N]

if n%sum(N)==0:

	print("Yes")

else:

	print("No")

x = eval(input())

k=0

for i in x:

    k+=int(i)

if int(x)%k==0:

    print("Yes")

else:

    print("No")

# your code goes here
n = int(eval(input()))
N = str(n)
N = [int(x) for x in N]
if n % sum(N) == 0:
    print("Yes")
else:
    print("No")

x = eval(input())
k = 0
for i in x:
    k += int(i)
if int(x) % k == 0:
    print("Yes")
else:
    print("No")

-# your code goes here
-n = int(eval(input()))
-N = str(n)
-N = [int(x) for x in N]
-if n % sum(N) == 0:
+x = eval(input())
+k = 0
+for i in x:
+    k += int(i)
+if int(x) % k == 0:


Input:
d,g = list(map(int,input().split()))

PC = [list(map(int,input().split())) for _ in range(d)]

cost = 10000000

for j in range(2**d):

    temp = 0

    score = 0

    bit = format(j,"0"+str(d)+"b")

    for i in range(d):

        if bit[i] == "1":

            score += PC[i][0]*(i+1)*100 + PC[i][1]

            temp += PC[i][0]

    if score >= g:

        if temp < cost:

            cost = temp

    else:

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

            if bit[i] == "0":

                p,c = PC[i]

                point = 100*(i+1)

                for v in range(p):

                    score += point

                    temp += 1

                    if score >= g:

                        break

                break

        if score >= g and temp < cost:

            cost = temp

print(cost)

from sys import setrecursionlimit

from operator import itemgetter

from math import ceil

def main():

    D,G = list(map(int,input().split()))

    PC = [list(map(int,input().split())) for _ in range(D)]

    ans = float("inf")

    for i in range(2**D):

        done = [False]*D

        tmp = 0

        q = 0

        cnt = i

        point = 0

        while cnt > 0:

            if cnt%2 == 1:

                done[point] = True

                tmp += PC[point][0]*(100*(point + 1)) + PC[point][1]

                q += PC[point][0]

            point += 1

            cnt //= 2

        if tmp < G:

            for j in range(D):

                if not(done[D - j - 1]):

                    score = 100*(D - j)

                    num = min(ceil((G - tmp) / score),PC[D - j - 1][0])

                    tmp += num*score

                    q += num

                    if tmp < G:

                        q = float("inf")

                    break

        ans = min(q,ans)

    print(ans)

    return

if __name__ == "__main__":

    main()

d, g = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(d)]
cost = 10000000
for j in range(2**d):
    temp = 0
    score = 0
    bit = format(j, "0" + str(d) + "b")
    for i in range(d):
        if bit[i] == "1":
            score += PC[i][0] * (i + 1) * 100 + PC[i][1]
            temp += PC[i][0]
    if score >= g:
        if temp < cost:
            cost = temp
    else:
        for i in range(d - 1, -1, -1):
            if bit[i] == "0":
                p, c = PC[i]
                point = 100 * (i + 1)
                for v in range(p):
                    score += point
                    temp += 1
                    if score >= g:
                        break
                break
        if score >= g and temp < cost:
            cost = temp
print(cost)

from sys import setrecursionlimit
from operator import itemgetter
from math import ceil

def main():
    D, G = list(map(int, input().split()))
    PC = [list(map(int, input().split())) for _ in range(D)]
    ans = float("inf")
    for i in range(2**D):
        done = [False] * D
        tmp = 0
        q = 0
        cnt = i
        point = 0
        while cnt > 0:
            if cnt % 2 == 1:
                done[point] = True
                tmp += PC[point][0] * (100 * (point + 1)) + PC[point][1]
                q += PC[point][0]
            point += 1
            cnt //= 2
        if tmp < G:
            for j in range(D):
                if not (done[D - j - 1]):
                    score = 100 * (D - j)
                    num = min(ceil((G - tmp) / score), PC[D - j - 1][0])
                    tmp += num * score
                    q += num
                    if tmp < G:
                        q = float("inf")
                    break
        ans = min(q, ans)
    print(ans)
    return

if __name__ == "__main__":
    main()

-PC = [list(map(int, input().split())) for _ in range(d)]

-    bit = format(j, "0" + str(d) + "b")

+    D, G = list(map(int, input().split()))

+    PC = [list(map(int, input().split())) for _ in range(D)]

+                if not (done[D - j - 1]):

+                    num = min(ceil((G - tmp) / score), PC[D - j - 1][0])

+                        q = float("inf")


Input:
N = int(eval(input()))

H = list(map(int, input().split()))

# Hを1段ずつ減らしていく.

# 値が正の区間 (left, right) が一つ見つかるごとに答えは1増える.

ans = 0

while sum(H) > 0:

    left = right = 0

    prev = 0

    segment = []

    for i, h in enumerate(H):

        if h == 0 and prev != 0: # H = {..., 0, *(left), *, ..., *, 0(right), ...} (*: 正数)

            right = i

            segment.append((left, right))

        elif h != 0 and prev == 0:

            left = i

            if i == N-1: # H = {..., 0, *(left)} (*: 正数)

                right = i + 1

                segment.append((left, right))

        elif h != 0 and i == N-1: #(prev != 0) H = {..., 0, *(left), ..., *, *} (*: 正数)

            right = i + 1

            segment.append((left, right))

        prev = h

    ans += len(segment)

    #  Hの値が正のところを1段減らす.

    for l, r in segment:

        for i in range(l, r):

            H[i] -= 1

print(ans)

N = int(eval(input()))

H = list(map(int, input().split()))

stack = [H]

count = 0

while stack:

    lst = stack.pop()

    m = min(lst)

    count += m

    lst = [l-m for l in lst]

    prev = 0

    left = 0

    for i, h in enumerate(lst):

        if h == 0 and prev != 0: # H = {..., 0, *(left), *, ..., *, 0(right), ...} (*: 正数)

            stack.append(lst[left:i])

        elif h != 0 and prev == 0:

            left = i

            if i == len(lst)-1: # H = {..., 0, *(left)} (*: 正数)

                stack.append(lst[left:i+1])

        elif h != 0 and i == len(lst)-1: #(prev != 0) H = {..., 0, *(left), ..., *, *} (*: 正数)

            stack.append(lst[left:i+1])

        prev = h

print(count)

N = int(eval(input()))
H = list(map(int, input().split()))
# Hを1段ずつ減らしていく.
# 値が正の区間 (left, right) が一つ見つかるごとに答えは1増える.
ans = 0
while sum(H) > 0:
    left = right = 0
    prev = 0
    segment = []
    for i, h in enumerate(H):
        if (
            h == 0 and prev != 0
        ):  # H = {..., 0, *(left), *, ..., *, 0(right), ...} (*: 正数)
            right = i
            segment.append((left, right))
        elif h != 0 and prev == 0:
            left = i
            if i == N - 1:  # H = {..., 0, *(left)} (*: 正数)
                right = i + 1
                segment.append((left, right))
        elif (
            h != 0 and i == N - 1
        ):  # (prev != 0) H = {..., 0, *(left), ..., *, *} (*: 正数)
            right = i + 1
            segment.append((left, right))
        prev = h
    ans += len(segment)
    #  Hの値が正のところを1段減らす.
    for l, r in segment:
        for i in range(l, r):
            H[i] -= 1
print(ans)

N = int(eval(input()))
H = list(map(int, input().split()))
stack = [H]
count = 0
while stack:
    lst = stack.pop()
    m = min(lst)
    count += m
    lst = [l - m for l in lst]
    prev = 0
    left = 0
    for i, h in enumerate(lst):
        if (
            h == 0 and prev != 0
        ):  # H = {..., 0, *(left), *, ..., *, 0(right), ...} (*: 正数)
            stack.append(lst[left:i])
        elif h != 0 and prev == 0:
            left = i
            if i == len(lst) - 1:  # H = {..., 0, *(left)} (*: 正数)
                stack.append(lst[left : i + 1])
        elif (
            h != 0 and i == len(lst) - 1
        ):  # (prev != 0) H = {..., 0, *(left), ..., *, *} (*: 正数)
            stack.append(lst[left : i + 1])
        prev = h
print(count)

-# Hを1段ずつ減らしていく.

-# 値が正の区間 (left, right) が一つ見つかるごとに答えは1増える.

-            segment.append((left, right))

-                segment.append((left, right))

+                stack.append(lst[left : i + 1])

+            h != 0 and i == len(lst) - 1

-            segment.append((left, right))

+            stack.append(lst[left : i + 1])

-    #  Hの値が正のところを1段減らす.


Input:
s = list(eval(input()))

ans = 0

for i in range(len(s)-1):

    if int(s[i]) == int(s[i+1]) == 0:

        s[i+1] = 1

        ans += 1

    elif int(s[i]) == int(s[i+1]) == 1:

        s[i+1] = 0

        ans += 1

print(ans)

s = eval(input())

a = "01"*int(len(s)/2) + "0"*int(len(s)%2)

b = "10"*int(len(s)/2) + "1"*int(len(s)%2)

a_count = 0

b_count = 0

for i, j, k in zip(a, b, s):

    if i != k:

        a_count += 1

    if j != k:

        b_count += 1

print((min(a_count, b_count)))

s = list(eval(input()))
ans = 0
for i in range(len(s) - 1):
    if int(s[i]) == int(s[i + 1]) == 0:
        s[i + 1] = 1
        ans += 1
    elif int(s[i]) == int(s[i + 1]) == 1:
        s[i + 1] = 0
        ans += 1
print(ans)

s = eval(input())
a = "01" * int(len(s) / 2) + "0" * int(len(s) % 2)
b = "10" * int(len(s) / 2) + "1" * int(len(s) % 2)
a_count = 0
b_count = 0
for i, j, k in zip(a, b, s):
    if i != k:
        a_count += 1
    if j != k:
        b_count += 1
print((min(a_count, b_count)))


Input:
import sys

import collections

def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n, q = list(map(int, input().rstrip('\n').split()))

    d = collections.defaultdict(list)

    for i in range(n-1):

        a, b = list(map(int, input().rstrip('\n').split()))

        d[a-1] += [b-1]

        d[b-1] += [a-1]

    ls = [0] * n

    for i in range(q):

        p, x = list(map(int, input().rstrip('\n').split()))

        ls[p-1] += x

    ql = collections.deque([0])

    fq = collections.defaultdict(int)

    fq[0]

    while True:

        if len(ql) != 0:

            p = ql.popleft()

            for v in d[p]:

                if v not in fq:

                    ls[v] += ls[p]

                    ql.appendleft(v)

                    fq[p]

        else:

            print((*ls))

            exit()

if __name__ == '__main__':

    solve()

import sys

import collections

def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n, q = list(map(int, readline().split()))

    tmd = collections.defaultdict(list)

    for i in range(n-1):

        tma, tmb = list(map(int, readline().split()))

        tmd[tma-1] += [tmb-1]

        tmd[tmb-1] += [tma-1]

    score = [0] * n

    for i in range(q):

        p, x = list(map(int, readline().split()))

        score[p-1] += x

    ql = [[0, 0]]

    ql = collections.deque(ql)

    fq = collections.defaultdict(list)

    fq[0]

    while True:

        if len(ql) != 0:

            cost, tmp = ql.popleft()

            for tmv in tmd[tmp]:

                if tmv not in fq:

                    score[tmv] += score[tmp]

                    ql.append([cost + 1, tmv])

                    fq[tmv]

        else:

            break

    print((*score))

if __name__ == '__main__':

    solve()

import sys
import collections

def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n, q = list(map(int, input().rstrip("\n").split()))
    d = collections.defaultdict(list)
    for i in range(n - 1):
        a, b = list(map(int, input().rstrip("\n").split()))
        d[a - 1] += [b - 1]
        d[b - 1] += [a - 1]
    ls = [0] * n
    for i in range(q):
        p, x = list(map(int, input().rstrip("\n").split()))
        ls[p - 1] += x
    ql = collections.deque([0])
    fq = collections.defaultdict(int)
    fq[0]
    while True:
        if len(ql) != 0:
            p = ql.popleft()
            for v in d[p]:
                if v not in fq:
                    ls[v] += ls[p]
                    ql.appendleft(v)
                    fq[p]
        else:
            print((*ls))
            exit()

if __name__ == "__main__":
    solve()

import sys
import collections

def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n, q = list(map(int, readline().split()))
    tmd = collections.defaultdict(list)
    for i in range(n - 1):
        tma, tmb = list(map(int, readline().split()))
        tmd[tma - 1] += [tmb - 1]
        tmd[tmb - 1] += [tma - 1]
    score = [0] * n
    for i in range(q):
        p, x = list(map(int, readline().split()))
        score[p - 1] += x
    ql = [[0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0]
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    score[tmv] += score[tmp]
                    ql.append([cost + 1, tmv])
                    fq[tmv]
        else:
            break
    print((*score))

if __name__ == "__main__":
    solve()

+    readline = sys.stdin.buffer.readline

-    n, q = list(map(int, input().rstrip("\n").split()))

+    n, q = list(map(int, readline().split()))

+    tmd = collections.defaultdict(list)

-        a, b = list(map(int, input().rstrip("\n").split()))

+        tma, tmb = list(map(int, readline().split()))

-        p, x = list(map(int, input().rstrip("\n").split()))

+        p, x = list(map(int, readline().split()))

+                    score[tmv] += score[tmp]

+                    ql.append([cost + 1, tmv])


Input:
from functools import reduce

from operator import mul

n = int(eval(input()))

a_list = [int(x) for x in input().split()]

temp_mul = reduce(mul, a_list)

temp_add = 0

for a in a_list:

    temp_add += temp_mul // a

ans = temp_mul / temp_add

print(ans)

n = int(eval(input()))

a_list = [int(x) for x in input().split()]

temp = 0

for a in a_list:

    temp += 1 / a

ans = 1 / temp

print(ans)

-from functools import reduce
-from operator import mul
-temp_mul = reduce(mul, a_list)
-temp_add = 0
+temp = 0
-    temp_add += temp_mul // a
-ans = temp_mul / temp_add
+    temp += 1 / a
+ans = 1 / temp


Input:
import heapq

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

jobs = [[] for _ in range(M)]

for i in range(N):

    d, r = list(map(int, input().split()))

    if d-1 < M:

        jobs[d-1].append(-r)

m = 0

heap = []

for i in range(M):

    for a in jobs[i]:

        heapq.heappush(heap, a)

    if len(heap) > 0:

        b = heapq.heappop(heap)

        m += -b

print(m)

import heapq

def main():

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

  jobs = [[] for _ in range(M)]

  for i in range(N):

    d, r = list(map(int, input().split()))

    if d-1 < M:

      jobs[d-1].append(-r)

  m = 0

  heap = []

  for i in range(M):

    for a in jobs[i]:

      heapq.heappush(heap, a)

    if len(heap) > 0:

      b = heapq.heappop(heap)

      m += -b

  print(m)

if __name__ == '__main__':

  main()

import heapq

N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]
for i in range(N):
    d, r = list(map(int, input().split()))
    if d - 1 < M:
        jobs[d - 1].append(-r)
m = 0
heap = []
for i in range(M):
    for a in jobs[i]:
        heapq.heappush(heap, a)
    if len(heap) > 0:
        b = heapq.heappop(heap)
        m += -b
print(m)

import heapq

def main():
    N, M = list(map(int, input().split()))
    jobs = [[] for _ in range(M)]
    for i in range(N):
        d, r = list(map(int, input().split()))
        if d - 1 < M:
            jobs[d - 1].append(-r)
    m = 0
    heap = []
    for i in range(M):
        for a in jobs[i]:
            heapq.heappush(heap, a)
        if len(heap) > 0:
            b = heapq.heappop(heap)
            m += -b
    print(m)

if __name__ == "__main__":
    main()

-    d, r = list(map(int, input().split()))

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

+        d, r = list(map(int, input().split()))


Input:
from bisect import bisect_left

N = int(eval(input()))

L = list(map(int, input().split()))

L.sort()

count = 0

for i in range(N):

    for j in range(i+1, N):

        max_len = L[i] + L[j]

        count += bisect_left(L, max_len) - j - 1

print(count)

from bisect import bisect_left

import sys

input = sys.stdin.readline

N = int(eval(input()))

L = list(map(int, input().split()))

L.sort()

ans = 0

for i in range(N-1):

    for j in range(i+1, N):

        l = L[i] + L[j]

        k = bisect_left(L, l)

        ans += max(0, k - j - 1)

print(ans)

from bisect import bisect_left

N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
count = 0
for i in range(N):
    for j in range(i + 1, N):
        max_len = L[i] + L[j]
        count += bisect_left(L, max_len) - j - 1
print(count)

from bisect import bisect_left
import sys

input = sys.stdin.readline
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        l = L[i] + L[j]
        k = bisect_left(L, l)
        ans += max(0, k - j - 1)
print(ans)

-        count += bisect_left(L, max_len) - j - 1