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

N,M = map(int,input().split())
S = [list(map(int,input().split())) for m in range(M)]
ans = "IMPOSSIBLE"

for n in range(1+N):
  if [1,n] in S and [n,N] in S:
    ans = "POSSIBLE"

print(ans)

### FIXED CODE ###

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

for m in range(M):
    a,b = list(map(int,input().split()))
    if a==1:
      x|=1<<b
    if b==N:
      y|=1<<a

print("IM"*(x&y==1)+"POSSIBLE")
### BUGGY CODE ###

import bisect
ans = float('inf')
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
    ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
c = [0] * (N + 1)
for i in range(N):
    c[i + 1] = c[i] + a[i]
ans = float('inf')
for n in c[1:-1]:
    ans = min(ans, abs(c[-1] - 2 * n))
print(ans)
### BUGGY CODE ###

import numpy as np
input1 = input()

door_num = int(input1.split()[1])
max_left = 1
min_right = int(input1.split()[0])

for i in range(door_num):
    a = input()
    new_inputs = [int(i) for i in a.split()]
    max_left = np.max([new_inputs[0], max_left])
    min_right = np.min([new_inputs[1], min_right])

if min_right >= max_left:
    print(min_right - max_left + 1)
else:
    print(0)

### FIXED CODE ###

import numpy as np
input1 = input()

door_num = int(input1.split()[1])
lefts = []
rights = []
for i in range(door_num):
    a = input()
    new_inputs = [int(i) for i in a.split()]
    lefts.append(new_inputs[0])
    rights.append(new_inputs[1])
    #max_left = np.max([new_inputs[0], max_left])
    #min_right = np.min([new_inputs[1], min_right])
    #if not min_right >= max_left:
    #    break
min_right = np.min(rights)
max_left = np.max(lefts)

if min_right >= max_left:
    print(min_right - max_left + 1)
else:
    print(0)
### BUGGY CODE ###

import queue
n,x,y = map(int,input().split())
ans = {}
for i in range(1,n):
    dist = [-1]*n
    q = queue.Queue()
    dist[i-1] = 0
    q.put(i)
    while True:
        if q.empty():
            break
        else:
            a = q.get()
            if a > 1 and dist[a-2] == -1:
                dist[a-2] = dist[a-1]+1
                q.put(a-1)
            if a < n and dist[a] == -1:
                dist[a] = dist[a-1]+1
                q.put(a+1)
            if a == x and dist[y-1] == -1:
                dist[y-1] = dist[a-1]+1
                q.put(y)
            if a == y and dist[x-1] == -1:
                dist[x-1] = dist[a-1]+1
                q.put(x)
    for j in range(i,n):
        s = dist[j]
        if s in ans.keys():
            ans[s] += 1
        else:
            ans[s] = 1
for k in range(1,n):
    if k in ans.keys():
      print(ans[k])
    else:
      print(0)  

### FIXED CODE ###

n,x,y = map(int,input().split())
ans = {}
s = (y-x+1)//2
s = x+s
for i in range(1,n):
    for j in range(i+1,n+1):
        if i <= s:
            dist = min(j-i,abs(i-x)+abs(j-y)+1)
        else:
            dist = j-i
        if dist in ans.keys():
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in ans.keys():
        print(ans[k])
    else:
        print(0)
### BUGGY CODE ###

n,x,y = map(int,input().split())
dist = {}

for i in range(1,n):
    for j in range(i+1,n+1):
        name = "{}-{}".format(i,j)
        if i <= x and j < y:
            dist[name] = min(j - i,x-i + 1 + y-j)
        elif i <= x and j >=  y:
            dist[name] = x-i + 1 + j-y
        elif i > x:
            dist[name] = min(j - i,i-x + 1 + abs(y-j))

for i in range(1,n):
    print(list(dist.values()).count(i))

### FIXED CODE ###

n,x,y = map(int,input().split())
dist = [[0] for i in range(n)]

for i in range(1,n):
    for j in range(i+1,n+1):
        dist[min(j - i,abs(i-x) + 1 + abs(y-j),abs(y-i)+ 1 + abs(j-x))][0] += 1

for i in range(1,n):
    print(dist[i][0])
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    c = LI()
    c.sort()
    if n == 1:
        print(2*c[0]%mod)
        return
    k = 1<<(n-2)
    f = [k*(i+2)*(1<<n)%mod for i in range(n)][::-1]
    ans = 0
    for i in range(n):
        ans += c[i]*f[i]
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    c = LI()
    c.sort(reverse = True)
    dp = [0]*n
    dp[0] = c[0]
    p = 1
    for i in range(n-1):
        ni = i+1
        dp[ni] = (2*dp[i]+p*(2+ni)*c[ni])%mod
        p *= 2
        p %= mod
    p *= 2
    p %= mod
    print(p*dp[n-1]%mod)
    return

#Solve
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0

    for i in range(N-2):
        for j in range(i+1,N-1):
            minA = L[j] - L[i]
            maxA = L[j] + L[i]
            for k in range(j+1,N):
                if minA < L[k] < maxA:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from bisect import bisect_right

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0

    for i in range(N-1):
        for j in range(i+1,N):
            diff = L[j] - L[i]
            index = bisect_right(L[:i],diff)
            ans += i-index
            # print(i,j,ans)
    print(ans)

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

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
  for j in range(n):
    if i != j and a[i] % a[j] == 0:
      break
    elif j == n-1:
      count += 1
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
m = 1000005

count = 0
cnt = [0] * m
for i in range(n):
  if cnt[a[i]] == 0:
    for j in range(a[i], m, a[i]):
      cnt[j] += 1
  else:
    cnt[a[i]] = 2
for i in range(n):
  if cnt[a[i]] == 1:
    count += 1
print(count)
### BUGGY CODE ###

import sys

from collections import deque
input = sys.stdin.buffer.readline
def main():
    n, m, k = map(int, input().split())
    friends = {k: set() for k in range(1, n + 1)}
    foe = {k: set() for k in range(1, n + 1)}
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    for _ in range(k):
        a, b = map(int, input().split())
        foe[a].add(b)
        foe[b].add(a)

    belong_group = [-1] * (n + 1)
    groups = {}
    stack = deque()
    group_num = 1
    nodes_seen = set()
    for i1 in range(1, n + 1):
        if i1 in nodes_seen or friends[i1] == []:
            continue
        else:
            belong_group[i1] = group_num
            groups[group_num] = set()
            groups[group_num].add(i1)
            nodes_seen.add(i1)
            stack += friends[i1]
            while stack:
                next_node = stack.popleft()
                if next_node in nodes_seen:
                    continue
                else:
                    nodes_seen.add(next_node)
                    belong_group[next_node] = group_num
                    groups[group_num].add(next_node)
                    stack += friends[next_node]
            group_num += 1
    for i2 in range(1, n + 1):
        r = max(len(groups[belong_group[i2]] - friends[i2] - foe[i2]) - 1, 0)
        print(r, end=' ')

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True
    def members(x):
        root = find(x)
        return [i for i in range(n) if find(i) == root]

    n, m, k = map(int, input().split())
    num_of_friends = [-1] * n
    par = [-1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        unite(a, b)
        num_of_friends[a] += -1
        num_of_friends[b] += -1
    roots = defaultdict(int)
    #roots = {e: set() for e in range(n)}
    for i2 in range(n):
        roots[find(i2)] += 1
    for i3 in range(n):
        #num_of_friends[i3] += len(roots[find(i3)])
        num_of_friends[i3] += roots[find(i3)]
    for _ in range(k):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        if find(c) == find(d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1

    for i in range(n):
        print(num_of_friends[i], end=' ')

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

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

dct = {X : Y}
short = Y - X - 1

dist_list = []

for i in range(1,N):
    for j in range(i+1,N+1):
        if i <= X and j >= Y:
            dist = j - i - short
        elif i <= X and j >= X and j <= Y:
            d1 = X - i + 1 + Y - j
            d2 = j - i
            dist = min(d1,d2)
        elif i >= X and i <= Y and j >= Y:
            d1 = i - X + 1 + j - Y
            d2 = j - i
            dist = min(d1,d2)
        elif i >= X and j <= Y:
            d1 = i - X + 1 + Y - j 
            d2 = j - i
            dist = min(d1,d2)
        else:
            dist = j - i
        dist_list.append(dist)

for k in range(1,N):
    print(dist_list.count(k))


### FIXED CODE ###

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

dist_list = [0] * N

for i in range(1,N):
    for j in range(i+1,N+1):
        d1 = abs(X - i) + 1 + abs(Y - j)
        d2 = j - i
        dist = min(d1,d2)
        dist_list[dist] += 1

for k in range(1,N):
    print(dist_list[k])
### BUGGY CODE ###

#067-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n=I()
prev=[-1 for i in range(n)]
nl=[[] for i in range(n)]
q=[0]
vis=[False for i in range(n)]

for i in range(n-1):
    a,b=IL()
    nl[a-1].append(b-1)
    nl[b-1].append(a-1)

while len(q)!=0:
    s=q.pop(0)
    vis[s]=True
    for v in nl[s]:
        if not vis[v]:
            prev[v]=s
            q.append(v)

path=[n-1]
while True:
    if path[-1]==0:
        break
    path.append(prev[path[-1]])
path.reverse()
    
for i in range(1,n):
    while True:
        if prev[i] in path:
            break
        prev[i]=prev[prev[i]]

if len(path)%2==0:
    fenp=path[:len(path)//2]
    fen=len(path)//2
else:
    fenp=path[:len(path)//2+1]
    fen=len(path)//2+1

snu=len(path)-fen

r=list(range(n))
for i in path:
    r.remove(i)
for i in r:
    if prev[i] in fenp:
        fen+=1
    else:
        snu+=1

        
if fen>snu:
    print("Fennec")
else:
    print("Snuke")

### FIXED CODE ###

#067-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n=I()
nl=[[] for i in range(n)]
distfen=[-1 for i in range(n)]
distsnu=[-1 for i in range(n)]

for i in range(n-1):
    a,b=IL()
    nl[a-1].append(b-1)
    nl[b-1].append(a-1)
    
q=[[0,0]]
vis=[False for i in range(n)]
while len(q)!=0:
    s,d=q.pop(0)
    vis[s]=True
    for v in nl[s]:
        if not vis[v]:
            distfen[v]=d+1
            q.append([v,d+1])

q=[[n-1,0]]
vis=[False for i in range(n)]
while len(q)!=0:
    s,d=q.pop(0)
    vis[s]=True
    for v in nl[s]:
        if not vis[v]:
            distsnu[v]=d+1
            q.append([v,d+1])
        
fen=0
snu=0

for i in range(1,n-1):
    if distfen[i]<=distsnu[i]:
        fen+=1
    else:
        snu+=1

if fen>snu:
    print("Fennec")
else:
    print("Snuke")
### BUGGY CODE ###

from _collections import deque

s = deque(input())
q = int(input())

for i in range(q):
    query = list(input().split())
    if query[0] == '1':
        s.reverse()
    else:
        if query[1] == '1':
            s.appendleft(query[2])
        else:
            s.append(query[2])
print("".join(s))


### FIXED CODE ###

from _collections import deque

s = deque(input())
q = int(input())
reverse_flg = False

for i in range(q):
    query = list(input().split())
    if query[0] == '1':
        reverse_flg = not reverse_flg
    else:
        if query[1] == '1':
            if reverse_flg:
                s.append(query[2])
            else:
                s.appendleft(query[2])
        else:
            if reverse_flg:
                s.appendleft(query[2])
            else:
                s.append(query[2])
if reverse_flg:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

n = int(input())
s = []
for i in range(5):
  s.append(int(input()))
before = [n,0,0,0,0,0]

def one_step(before):
  #都市1~6にp~u人いる時の、次の時刻での状態
  for i in reversed(range(0,5)):
    if before[i]<=s[i]:
      before[i+1] += before[i]
      before[i] = 0
    else:
      before[i] -= s[i]
      before[i+1] += s[i]
  return before

t=0
while before[-1]<n:
  before = one_step(before)
  t += 1

print(t)

### FIXED CODE ###

import math
n = int(input())
s = []
for i in range(5):
  s.append(int(input()))
s_min = min(s)
min_idx = s.index(s_min)

print(4+math.ceil(n/s_min))
### BUGGY CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
d = {}
s = set()
for _ in range(M):
    ab = list(map(int,input().split()))
    if ab[0] in d.keys():
        d[ab[0]].append(ab[1])
    else:
        d[ab[0]] = [ab[1]]
    if ab[1] in d.keys():
        d[ab[1]].append(ab[0])
    else:
        d[ab[1]] = [ab[0]]
    s = s | set(ab)

count = 0
for i in d.keys():
    for j in list(set(d[i])):
        if H[i-1] <= H[j-1]:
            break
    else:
        count += 1
count += N - len(s)

print(count)

### FIXED CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
d = {}
s = []

for _ in range(M):
    ab = list(map(int,input().split()))
    if ab[0] in d.keys():
        d[ab[0]] = max(d[ab[0]],H[ab[1]-1])
    else:
        d[ab[0]] = H[ab[1]-1]
    if ab[1] in d.keys():
        d[ab[1]] = max(d[ab[1]],H[ab[0]-1])
    else:
        d[ab[1]] = H[ab[0]-1]
    s.append(ab[0])
    s.append(ab[1])

count = 0
for i in d.keys():
    if H[i-1] > d[i]:
        count += 1

count += N - len(set(s))

print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(4100000)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
g = [[]*(n*(n-1)//2) for _ in range(n*(n-1)//2)]
chk = set([])
cnt = 0
d = {}
st = set([])

for i in range(n):
  a = [int(i) for i in readline().split()]
  for j in range(n-2):
    A,b = min(a[j],i+1),max(a[j],i+1)
    p,q = min(a[j+1],i+1),max(a[j+1],i+1)    
    if not b*1000+A in chk:
      d[b*1000+A] = cnt
      cnt += 1
      chk.add(b*1000+A)
    if not q*1000+p in chk:
      d[q*1000+p] = cnt
      cnt += 1
      chk.add(q*1000+p)
    g[d[b*1000+A]].append(d[q*1000+p])
    if j == 0:
      st.add(d[b*1000+A])

# あとは頂点VのグラフをdfsしてLongest pathの長さを求める
# -1: unchecked, -2: checked and uncalculated
dp=[-1]*(n*(n-1)//2)
#flag=True
def dfs(v):
    #global flag
    dp[v]=-2
    length=0
    for nv in g[v]:
        if(dp[nv]==-2):
            print(-1)
            exit()
        if(dp[nv]==-1):
            dfs(nv)
        length=max(length,dp[nv]+1)
    dp[v]=length
            
st = list(st)
a = []
pp = 0
for i in st:dfs(i)
print(max(dp)+1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
g = [[]*(n*(n-1)//2) for _ in range(n*(n-1)//2)]
chk = set([])
cnt = 0
d = {}
st = set([])

for i in range(n):
  a = [int(i) for i in readline().split()]
  for j in range(n-2):
    A,b = min(a[j],i+1),max(a[j],i+1)
    p,q = min(a[j+1],i+1),max(a[j+1],i+1)    
    if not b*1000+A in chk:
      d[b*1000+A] = cnt
      cnt += 1
      chk.add(b*1000+A)
    if not q*1000+p in chk:
      d[q*1000+p] = cnt
      cnt += 1
      chk.add(q*1000+p)
    g[d[b*1000+A]].append(d[q*1000+p])
    if j == 0:
      st.add(d[b*1000+A])

# あとは頂点VのグラフをdfsしてLongest pathの長さを求める
# -1: unchecked, -2: checked and uncalculated
dp=[-1]*(n*(n-1)//2)
#flag=True
def dfs(v):
    #global flag
    dp[v]=-2
    length=0
    for nv in g[v]:
        if(dp[nv]==-2):
            print(-1)
            exit()
        if(dp[nv]==-1):
            dfs(nv)
        length=max(length,dp[nv]+1)
    dp[v]=length
            
st = list(st)
a = []
pp = 0
for i in st:dfs(i)
print(max(dp)+1)
### BUGGY CODE ###

H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(str(input()))
  
def main(i, j):
  global S
  global H
  global W
  a = 1
  u, d, l, r = i, i, j, j
  while u > 0:
    u -= 1
    if S[u][j] == '.':
      a += 1
    else:
      break
  while d < H-1:
    d += 1
    if S[d][j] == '.':
      a += 1
    else:
      break
  while l > 0:
    l -= 1
    if S[i][l] == '.':
      a += 1
    else:
      break
  while r < W-1:
    r += 1
    if S[i][r] == '.':
      a += 1
    else:
      break
  return a
  
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      ans = max(ans, main(i, j))
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = []
l1 = []
for i in range(H):
  s = str(input())
  S.append(s)
  tmp = []
  cnt = 0
  flag = False
  for j in s:
    if flag:
      if j == '.':
        cnt += 1
      else:
        for k in range(cnt):
          tmp.append(cnt)
        cnt = 0
        tmp.append(0)
        flag = False
    else:
      if j == '.':
        flag = True
        cnt += 1
      else:
        tmp.append(0)
  if cnt > 0:
    for k in range(cnt):
      tmp.append(cnt)
  l1.append(tmp)

l2 = []
for i in range(W):
  tmp = []
  cnt = 0
  flag = False
  for j in range(H):
    x = S[j][i]
    if flag:
      if x == '.':
        cnt += 1
      else:
        for k in range(cnt):
          tmp.append(cnt)
        cnt = 0
        tmp.append(0)
        flag = False
    else:
      if x == '.':
        flag = True
        cnt += 1
      else:
        tmp.append(0)
  if cnt > 0:
    for k in range(cnt):
      tmp.append(cnt)
  l2.append(tmp)

ans = [[0]*W for i in range(H)]
m = 0
for i in range(H):
  for j in range(W):
    if (l1[i][j]>0) and (l2[j][i]>0):
      ans[i][j] = l1[i][j] + l2[j][i] - 1
    else:
      ans[i][j] = l1[i][j] + l2[j][i]
    m = max(m, ans[i][j])
print(m)
### BUGGY CODE ###

s = input()
q = int(input())

rev_s = 0
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      rev_s += 1
   else:
      f, c = int(tmp[1]), tmp[2]
      x = rev_s % 2
      if (x == 0 and f == 1) or (x == 1 and f == 2):
         l = [c, s]
      else:
         l = [s, c]
      s = ''.join(l)

if rev_s % 2 == 1:
   print(s[::-1])
else:
   print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)
### BUGGY CODE ###

h,w = map(int,input().split())
A = []
for _ in range(h):
    a = list(map(int,input().split()))
    A.append(a)
B = []
for _ in range(h):
    b = list(map(int,input().split()))
    B.append(b)
g = [[0]*(w+1) for _ in range(h+1)]
m = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        m = max(m,abs(A[i-1][j-1]-B[i-1][j-1]))
        g[i][j] = abs(A[i-1][j-1]-B[i-1][j-1])
m *= (h+w)
dp = [[[False for _ in range(m+1)] for _ in range(w+1)] for _ in range(h+1)]
dp[1][1][g[1][1]] = True

for i in range(1,h+1):
    for j in range(1,w+1):
        for k in range(m+1):
            if k + g[i][j]<m:
                dp[i][j][k] = dp[i][j][k] or dp[i-1][j][abs(k-g[i][j])] or dp[i-1][j][k+g[i][j]] or dp[i][j-1][abs(k-g[i][j])] or dp[i][j-1][k+g[i][j]]
            else:
                dp[i][j][k] = dp[i][j][k] or dp[i-1][j][abs(k-g[i][j])] or dp[i][j-1][abs(k-g[i][j])]
            

for k in range(m+1):
    if dp[-1][-1][k]:
        print(k);exit()



### FIXED CODE ###

H, W = map(int, input().split())
A = [None]*H
for i in range(H):
    A[i] = list(map(int, input().split()))
B = [None]*H
for i in range(H):
    B[i] = list(map(int, input().split()))

C = [[None]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        C[i][j] = abs(A[i][j]-B[i][j])

K = 80*(H+W-1)//2 + 1
dp = [[[0]*(K+1) for _ in range(W)] for _ in range(H)]# 答えから80*(H+W-1)を引く
dp[0][0][C[0][0]] = 1

for i in range(H):
    for j in range(W):
        for k in range(K+1):
            if i and dp[i-1][j][k]:
                if k+C[i][j] < K:
                    dp[i][j][k+C[i][j]] = 1
                dp[i][j][abs(k-C[i][j])] = 1
            if j and dp[i][j-1][k]:
                if k+C[i][j] < K:
                    dp[i][j][k+C[i][j]] = 1
                dp[i][j][abs(k-C[i][j])] = 1

for k in range(K+1):
    res = dp[H-1][W-1][k]
    if res:
        print(k)
        break
### BUGGY CODE ###

s = ''.join(reversed(raw_input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
np = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  for j in range(13):
    np[j] = 0
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print p[5] % divisor


### FIXED CODE ###

s = ''.join(reversed(input()))
multiplier = 1
divisor = 10 ** 9 + 7
p = [0 for i in range(13)]
if s[0] != '?':
  p[int(s[0])] = 1
else:
  for j in range(10):
    p[j] = 1
for i in range(1, len(s)):
  multiplier = (10 * multiplier) % 13
  np = [0 for j in range(13)]
  if s[i] != '?':
    r = int(s[i]) * multiplier
    for j in range(13):
      np[(j + r) % 13] = p[j]
  else:
    for j in range(10):
      r = j * multiplier
      for k in range(13):
        np[(k + r) % 13] += p[k]
  for j in range(13):
    p[j] = np[j] % divisor
print(p[5] % divisor)
### BUGGY CODE ###

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

R = min(R, L+2019*2)
ans = 2018
for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, i*j%2019)
print(ans)

### FIXED CODE ###

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

R = min(R, L+673)
ans = 2018
for i in range(L, R+1):
  for j in range(i+1, R+1):
    ans = min(ans, i*j%2019)
print(ans)