Harryxun/stf_run huggingface dataset:
while True :
    (x, y) = int(i) for i in input().split()
    if x = 0 y = 0 :
        break
    elif x >= y :
        print(x,y)
    else :
        print(y,x)

### FIXED CODE ###

while True:
    (x, y) = [int(i) for i in input().split()]
    
    if x == y == 0 :
        break

    if x <= y :
        print(x, y)
    else :
        print(y, x)
x = input().split()
N,T = int(x[0]),int(x[1])
a,b,c,d = [],[],[],[]
for i in range(N):
    v = input().split()
    v = [int(s) for s in v]
    a.append(v)
for i in range(N):
    b.append(a[i][0])
for i in range(N):
    c.append(a[i][1])
for i in range(N):
    if b[i] < T:
        d.append(a[b.index(b[i])][0])
if len([i for i, x in enumerate(d) if x == min(d)]) == 1 and [i for i, x in enumerate(d) if x == min(d)] != [0]:
    print(min(d))
else:
    print('TLE')

### FIXED CODE ###

a = int(input())
if a == 1:
    print('Hello World')
else:
    b = int(input())
    c = int(input())
    print(b + c)
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int[s] for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in D:
    Da.remove(i)
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
for i in nu:
    if i >= int(N):
        print(i)
        break

### FIXED CODE ###

input_st = input().split()
input_num = [int(s) for s in input_st]
num = sorted(input_num)
if num[0] == 5 and num[1] == 5 and num[2] == 7:
    print("YES")
else:
    print("NO")
a, b = map(int, input().split())
if a==b:
    pront("Yes")
else:
    print("No")

### FIXED CODE ###

a, b = map(int, input().split())
if a==b:
    print("Yes")
else:
    print("No")
def f1(x, y):
    if not x in data:
        data[x] = [y]
    else:
        data[x].append(y)
        
def f2():
    for i in range(1, w+1):
        f3(data[i][0], i, i)
    else:
        for a in ans:
            print a
        
def f3(a, b, c):
    for i, num in enumerate(data[a]):
        if num == b:
            if i+1 < len(data[a]):
                return f3(data[a][i+1], a, c)
            else:
                ans[a-1] = c
                break
        
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(w)]
data = {}
for i in range(n):
    a, b = map(int, raw_input().split(','))
    f1(a, b)
    f1(b, a)
else:
    f2()

### FIXED CODE ###

ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a
import sys
if __name__ == '__main__':
    N = int(input())
    W = [int(input()) for _ in N]
    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print('No')
            sys.exit()
    print('Yes')

### FIXED CODE ###

import sys
if __name__ == '__main__':
    N = int(input())
    W = [str(input()) for _ in range(N)]
    if len(W) != len(set(W)):
        print('No')
        sys.exit(0)
    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print('No')
            sys.exit(0)
    print('Yes')
N = int(input())
writing = [0 for i in range(1 << 9)]
for n in range(N):
    A = int(input()) - 1
    writing[A] += 1
    writing[A] %= 2
print(sum(writing))

### FIXED CODE ###

N = int(input())
writing = set()
for n in range(N):
    A = int(input())
    if A in writing:
        writing.remove(A)
    else:
        writing.add(A)
print(len(writing))
N=int(input())
conut=0

for i in range(1,N+1):
    a=[]
    if i%2==0:
        continue
     for j in range(1,i+1):
         if i%j==0:
             a.append(j)

    if len(a)==8:
        count+=1

print(count)

### FIXED CODE ###

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

N = int(input())
count = 0

for i in range(1, N + 1):
    a = []
    if i % 2 == 0:
        continue

    for j in range(1, i + 1):
        if i % j == 0:
            a.append(j)

    if len(a) == 8:
        count += 1

print(count)
import math
r = int(input())
a = r*r*math.pi
b = 2*r*math.pi
print('%f %f' % (a, b))

### FIXED CODE ###

import math
r = float(input())
a = r*r*math.pi
b = 2*r*math.pi
print(a, b)
import itertools

n, k = map(int, input().split())
a = map(int, input().split())
accum = [0] + list(itertools.accumulate(a))
count = 0
for i in range(n):
    for j in range(i + 1, n + 1):
        if accum[j] - accum[i] >= k:
            count += 1
print(count)


### FIXED CODE ###

x,a=map(int,input().split())
ans = 0 if x<a else 10
print(ans)
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    H, W = map(int, file().split())
    S = [None] * H
    for i in range(H):
        S[i] = list(file())
    left, right, up, down = [[0 for i in range(W)] for j in range(H)], [[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)]
    for h in range(H):
        if S[h][0] == ".": left[h][0] += 1
        if S[h][W-1] == ".": right[h][W-1] += 1
    for w in range(W):
        if S[0][w] == ".": up[0][w] += 1
        if S[0][H-1] == ".": down[H-1][w] += 1

    for h in range(H):
        for w in range(1, W):
            if S[h][w] == ".":
                left[h][w] = left[h][w-1] + 1
                right[h][W - w - 1] = right[h][W - w] + 1
    for h in range(1, H):
        for w in range(W):
                up[h][w] = up[h-1][w] + 1
                down[H-h-1][w] = down[H-h][w] + 1

    maxlight = 0
    for h in range(H):
        for w in range(W):
            maxlight = max(maxlight, left[h][w] + right[h][w] + up[h][w] + down[h][w] - 3)
    print(maxlight)      

    return 0
  
if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
 
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    H, W = map(int, file().split())
    S = [None] * H
    for i in range(H):
        S[i] = list(file())
    left, right, up, down = [[0 for i in range(W)] for j in range(H)], [[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)]
    for h in range(H):
        if S[h][0] == ".": left[h][0] += 1
        if S[h][W-1] == ".": right[h][W-1] += 1
    for w in range(W):
        if S[0][w] == ".": up[0][w] += 1
        if S[H-1][w] == ".": down[H-1][w] += 1

    for h in range(H):
        for w in range(1, W):
            if S[h][w] == ".":
                left[h][w] = left[h][w-1] + 1
            if S[h][W-w-1] == ".":
                right[h][W - w - 1] = right[h][W - w] + 1
    for h in range(1, H):
        for w in range(W):
            if S[h][w] == ".":
                up[h][w] = up[h-1][w] + 1
            if S[H-h-1][w] == ".":
                down[H-h-1][w] = down[H-h][w] + 1

    maxlight = 0
    for h in range(H):
        for w in range(W):
            maxlight = max(maxlight, left[h][w] + right[h][w] + up[h][w] + down[h][w] - 3)
    print(maxlight)   
 
    return 0
  
if __name__ == "__main__":
    solve()
def threeArea(w, h, ans):
  for i in range(1, h):
    recA = w * i
    width = w//2
    recB = (h-i) * width
    recC = w * h - recA - recB
    diff = max(recA, recB, recC) - min(recA, recB, recC)
 
	height = (h - i) //2
    recB = w * height
    recC = w * h - recA - recB
    diff = min(diff, max(recA, recB, recC) - min(recA, recB, recC))
    if ans > diff:
      ans = diff
  return ans

H, W = (int(i) for i in input().split())
 
ans = float('inf')
ans = threeArea(W, H, ans)
ans = threeArea(H, W, ans)
 
print(ans)

### FIXED CODE ###

def threeArea(w, h, ans):
  for i in range(1, h):
    recA = w * i
    width = w//2
    recB = (h-i) * width
    recC = w * h - recA - recB
    diff = max(recA, recB, recC) - min(recA, recB, recC)
    
    height = (h - i) //2
    recB = w * height
    recC = w * h - recA - recB
    diff = min(diff, max(recA, recB, recC) - min(recA, recB, recC))
    if ans > diff:
      ans = diff
  return ans

H, W = (int(i) for i in input().split())
 
ans = float('inf')
ans = threeArea(W, H, ans)
ans = threeArea(H, W, ans)
 
print(ans)
from collections import deque, namedtuple
import sys
sys.setrecursionlimit(1000000)

class RootedTree:
    def __init__(self, t, n):
        self.t = t
        self.n = n
        self.d = [-1] * n
    def setDepth(self, u, p):
        self.d[u] = p
        if self.t[u].r != -1:
            self.setDepth(self.t[u].r, p)
        if self.t[u].l != -1:
            self.setDepth(self.t[u].l, p + 1)
        return(self.d)
    def getChildren(self, u):
        ret = []
        c = self.t[u].l
        while c != -1:
            ret.append(c)
            c = self.t[c].r
        return(ret)
    def printNode(self, i):
        p_ = self.t[i].p
        d_ = self.d[i]
        c_ = self.getChildren(i)
        if p_ == -1:
            t_ = "root"
        elif len(c_) == 0:
            t_ = "leaf"
        else:
            t_ = "internal node"
        print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_))

if __name__ == '__main__':
    n = int(input().rstrip())
    Node = namedtuple('Node', ['p', 'l', 'r'])
    t = [Node(-1, -1, -1)] * n
    r = -1
    for i in range(n):
        tmp = deque([int(i) for i in input().rstrip().split(" ")])
        v = tmp.popleft()
        d = tmp.popleft()
        for j in range(d):
            c = tmp.popleft()
            if j == 0:
                t[v] = t[v]._replace(l = c)
            else:
                t[l] = t[l]._replace(r = c)
            l = c
            t[c] = t[c]._replace(p = v)
    for i in range(n):
        if (t[i].p == -1):
            r = i
    x = RootedTree(t, n)
    x.setDepth(r, 0)
    for i in range(n):
        x.printNode(i)
    

### FIXED CODE ###

from collections import deque, namedtuple

class RootedTree:
    def __init__(self, t, n):
        self.t = t
        self.n = n
        self.d = [-1] * n

    def setDepth(self, u, p):
        self.t[u] = self.t[u]._replace(d = p)
        for i in self.getChildren(u):
            self.setDepth(i, p + 1)

    def getChildren(self, u):
        ret = []
        c = self.t[u].l
        while c != -1:
            ret.append(c)
            c = self.t[c].r
        return(ret)

    def printNode(self, i):
        p_ = self.t[i].p
        d_ = self.t[i].d
        c_ = self.getChildren(i)
        if p_ == -1:
            t_ = "root"
        elif len(c_) == 0:
            t_ = "leaf"
        else:
            t_ = "internal node"
        print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_))

if __name__ == '__main__':
    n = int(input().rstrip())
    Node = namedtuple('Node', ['p', 'l', 'r', 'd'])
    t = [Node(-1, -1, -1, -1)] * n
    r = -1
    for i in range(n):
        tmp = deque([int(i) for i in input().rstrip().split(" ")])
        v = tmp.popleft()
        d = tmp.popleft()
        for j in range(d):
            c = tmp.popleft()
            if j == 0:
                t[v] = t[v]._replace(l = c)
            else:
                t[l] = t[l]._replace(r = c)
            l = c
            t[c] = t[c]._replace(p = v)
    for i in range(n):
        if (t[i].p == -1):
            r = i
    x = RootedTree(t, n)
    x.setDepth(r, 0)
    for i in range(n):
        x.printNode(i)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
k_list = []

while k > 0:
    ans += 1
    if len(a) > 0 and a[0] <= b[0]:
        k -= a.pop(0)
    else:
        k -= b.pop(0)
    k_list.append(k)

if k_list[-1] < 0:
    print(ans-1)
else:
    print(ans)
        

### FIXED CODE ###

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

a, b = [0], [0]

# 累積和を求める
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    if a[i] > K:
        break

    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
    
print(ans)
n = int(input())
a = [int(i) for i in input().split()]
c = [0 for i in range(n)]
b = sorted(a)
cnt = 1
for i in range(n-1):
  if b[i]==b[i+1]:
    cnt += 1
  else:
    c[b[i]] = cnt
    cnt = 1
  if i==n-2:
    c[b[n-1]] = cnt
ans = 0
for i in range(n):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
c = [0 for i in range(n+1)]
b = sorted(a)
cnt = 1
for i in range(n-1):
  if b[i]==b[i+1]:
    cnt += 1
  else:
    c[b[i]] = cnt
    cnt = 1
  if i==n-2:
    c[b[n-1]] = cnt
ans = 0
for i in range(n+1):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))
A,B,C,D=map(int,input().split())
E=B-A
import math
CD=C*D//math.gcd(C, D)
b=B-B//C-B//D+B//CD
A-=1
a=A-A//C-A//D+A//CD
print(b-a)

### FIXED CODE ###

A,B,C,D=map(int,input().split())
E=B-A
import fractions
CD=C*D//fractions.gcd(C, D)
b=B-B//C-B//D+B//CD
A-=1
a=A-A//C-A//D+A//CD
print(b-a)
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    elif eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)


### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
eat_p = p[:X]
eat_q = q[:Y]

all_apple = eat_p + eat_q + r
all_apple.sort(reverse=True)

print(sum(all_apple[:X+Y]))
import math

a, b, c, d = map(int, input().split())
e = c*d//math.gcd(c,d)


i = (a-1) // c #aのcの約数の数
j = b // c #bのcの約数の数
k = (a-1) // d #aのdの約数の数
l = b // d #bのdの約数の数
m = (a-1) // (e) #aのc*dの約数の数
n = b // (e) #bのc*dの約数の数

x = (j-i) + (l-k) - (n-m)
y = b - a + 1
print(y-x)

### FIXED CODE ###

import fractions

a, b, c, d = map(int, input().split())
e = c*d//fractions.gcd(c,d)


i = (a-1) // c #aのcの約数の数
j = b // c #bのcの約数の数
k = (a-1) // d #aのdの約数の数
l = b // d #bのdの約数の数
m = (a-1) // (e) #aのc*dの約数の数
n = b // (e) #bのc*dの約数の数

x = (j-i) + (l-k) - (n-m)
y = b - a + 1
print(y-x)
W,H,x,y,r = map(int,input().split())
if 0<=x-r and x+r<=W and 0<=y-r and y+r<=H:
  print('Yes')
else:
  print('No)


### FIXED CODE ###

W,H,x,y,r = map(int,input().split())
if 0<=x-r and x+r<=W and 0<=y-r and y+r<=H:
  print('Yes')
else:
  print('No')
def main():
    X = int(input())

    for i in range(10**5):
        t += X
        if t % 360 == 0:
            return i + 1

print(main())


### FIXED CODE ###

def main():
    X = int(input())
    t = 0

    for i in range(10**5):
        t += X
        if t % 360 == 0:
            return i + 1

print(main())
import sys
sys.setrecursionlimit(10000)

N, M = map(int, input().split())
Edge = [[]for _ in range(N)]
Far = [-1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)


def long(x):
    if len(Edge[x]) == 0:
        Far[x] = 0
        return 0
    if Far[x] >= 0:
        return Far[x]
    r = 0
    for i in Edge[x]:
        l = long(i) + 1
        r = max(r, l)
    Far[x] = r
    return r


for i in range(N):
    long(i)
print(max(Far))




### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
Edge = [[]for _ in range(N)]
Far = [-1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)


def long(x):
    if len(Edge[x]) == 0:
        Far[x] = 0
        return 0
    if Far[x] >= 0:
        return Far[x]
    r = 0
    for i in Edge[x]:
        l = long(i) + 1
        r = max(r, l)
    Far[x] = r
    return r


for i in range(N):
    long(i)
print(max(Far))
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[i])

### FIXED CODE ###

n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])
x=int(input())
for a in range(-100,100):
    for b in range(-100,100):
        if (a**5-b**5)==x:
            a_ans=a
            b_ans=b
            break

print(a_ans,b_ans)

### FIXED CODE ###

x=int(input())
for a in range(-200,200):
    for b in range(-200,200):
        if (a**5-b**5)==x:
            a_ans=a
            b_ans=b
            break

print(a_ans,b_ans)
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
        while d[di]!=t[ti]:
            di+=1
            if d[di]>t[ti]:
                f=1
                break
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
        while d[di]!=t[ti]:
            if d[di]>t[ti]:
                f=1
                break
            di+=1
        di+=1
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')
a,b,c= input().list()

if b == "+":
    print(int(a)+int(c))
else:
    print(int(a)-int(c))



### FIXED CODE ###

a,b,c= input().split()

if b == "+":
    print(int(a)+int(c))
else:
    print(int(a)-int(c))
import math

n,x = [int(i) for i in input().split()]

lis = list(map(int,input().split()))
diffs = []
for i in range(n):
    diff = abs(lis[i]-x)
    if diff != 0:
        diffs.append(diff)


if n > 1:
    com = math.gcd(diffs[0],diffs[1])
    for i in range(n-2):
        com = math.gcd(com, diffs[i+2])
else:
    com = diffs[0]

print(com)

### FIXED CODE ###

import fractions

n,x = [int(i) for i in input().split()]

lis = list(map(int,input().split()))
diffs = []
for i in range(n):
    diff = abs(lis[i]-x)
    diffs.append(diff)


if len(diffs) > 1:
    com = fractions.gcd(diffs[0],diffs[1])
    for i in range(len(diffs)-2):
        com = fractions.gcd(com, diffs[i+2])
else:
    com = diffs[0]

print(com)
A, B, C, X = map(int, input().split())
I = 0
for i in range(A + 1):
	for j in range(B + 1):
		for k in range(C + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
for i in range(C + 1):
	for j in range(B + 1):
		for k in range(A + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
for i in range(B + 1):
	for j in range(A + 1):
		for k in range(C + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
for i in range(A + 1):
	for j in range(C + 1):
		for k in range(B + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
for i in range(C + 1):
	for j in range(A + 1):
		for k in range(B + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
for i in range(B + 1):
	for j in range(C + 1):
		for k in range(A + 1):
			if (500 * i) + (100 * j) + (50 * k) == X:
				I++
print(I)


### FIXED CODE ###

A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                ans += 1

print(ans)
s = input()

def func(num, lst):
  if num == 0:
    return len(lst[num])
  else:
    return func(num - 1, lst) + len(lst[num])

lst = s.split('W')
out = 0
for i in range(0, len(lst)):
  if not lst[i] == '':
  	out += func(i, lst)
  
print(out)

### FIXED CODE ###

cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)
#----------------------------------------------------------
P = 10**9 + 7
N = 10000
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)


### FIXED CODE ###

#----------------------------------------------------------
P = 10**9 + 7
N = 500000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)
n = int(input())
x = int(input(),2)

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f
for i in reversed(range(0,n)):
    tmp = x^(1<<i)
    tmp2 = tmp%popcount(tmp)
    cnt = 1
    while tmp2 > 0:
        tmp = tmp2
        tmp2 = tmp % popcount(tmp)
        cnt += 1
    print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)