Harryxun/stf_run huggingface dataset:
def combination(n, r):
    r = min(r, n-r)
    nume = 1
    denomi = 1
    for i in range(1, r+1):
        denomi *= i
    for i in range(n-r+1, n+1):
        nume *= i
    return nume // denomi

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

sl = []
cnt = -1
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        print(0)
        break
    sl.append(max(b, 1))
    cnt = a
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combination(j, i)
            else:
                break
        ans *= p
    print(ans % 1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
a = [0]*N
for _ in range(M):
    idx = int(input()) - 1
    a[idx] = 1
    
dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(N-1):
    if a[i] == 0:
        dp[i+1] += dp[i]
        dp[i+2] += dp[i]
print(dp[N-1] % 1000000007)
_ = input()
S = input()

needs_right = 0, needs_left = 0
for c in S:
    if c == '(':
        needs_right += 1
    else:
        if needs_right == 0:
            needs_left += 1
        else:
            needs_right -= 1

print('(' * needs_left + S + ')' * needs_right)



### FIXED CODE ###

_ = input()
S = input()

needs_right = 0
needs_left = 0

for c in S:
    if c == '(':
        needs_right += 1
    else:
        if needs_right == 0:
            needs_left += 1
        else:
            needs_right -= 1

print('(' * needs_left + S + ')' * needs_right)
print(sum(list(range(int(input()))))

### FIXED CODE ###

N = int(input())
print(((N-1)*N)//2)
import sys

bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

nums = [ r[i]for i in range(3) for r in bingo ]

n = int(input())
appear = [ int(input()) for _ in range(n) ]

for x in range(3):
  for y in range(3):
    if bingo[x][y] in appear:
      t_or_f[x][y] = True

is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
  print('Yes')
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
  print('Yes')
else:
  for i in range(3):
    if t_or_f[i][i] and t_or_f[i+1][i+1] and t_or_f[i+2][i+2]:
      is_bingo = True
      print('Yes')
      sys.exit()

if not is_bingo: print('No')



### FIXED CODE ###


bingo = [ list(map(int, input().split())) for _ in range(3) ]
t_or_f = [ [False]*3 for _ in range(3) ]

nums = [ r[i]for i in range(3) for r in bingo ]

n = int(input())
appear = [ int(input()) for _ in range(n) ]

for x in range(3):
  for y in range(3):
    if bingo[x][y] in appear:
      t_or_f[x][y] = True

is_bingo = False
if t_or_f[0][0] and t_or_f[1][1] and t_or_f[2][2]:
  is_bingo = True
elif t_or_f[0][2] and t_or_f[1][1] and t_or_f[2][0]:
  is_bingo = True
else:
  for i in range(3):
    if t_or_f[i][0] and t_or_f[i][1] and t_or_f[i][2]: is_bingo = True
    if t_or_f[0][i] and t_or_f[1][i] and t_or_f[2][i]: is_bingo = True

if is_bingo:
  print('Yes')
else:
  print('No')
n, m = map(int, input().split())

lrds = [tuple(map(int, input().split())) for _ in range(m)]

xs = [None for _ in range(n)]

ps = [[] for _ in range(n)]

for lrd in lrds:
    l, r, d = lrd
    ps[l-1].append((r-1, d))
    ps[r-1].append((l-1, -d))

not_decided = set(range(n))

def f(t):
    for p in ps[t]:
        another, relative_position = p
        if another in not_decided:
            xs[another] = xs[t] + relative_position
            not_decided.remove(another)
            f(another)
        else:
            if xs[another] != xs[t] + relative_position:
                return False
    return True

def solve():
    while len(not_decided) != 0:
        t = not_decided.pop()
        xs[t] = 0

        if not f(t):
            return False
    return True

if solve():
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

lrds = [tuple(map(int, input().split())) for _ in range(m)]

xs = [None for _ in range(n)]

ps = [[] for _ in range(n)]

for lrd in lrds:
    l, r, d = lrd
    ps[l-1].append((r-1, d))
    ps[r-1].append((l-1, -d))

not_decided = set(range(n))

def solve():
    while len(not_decided) != 0:
        t = not_decided.pop()
        xs[t] = 0

        stack = [t]
        while len(stack) != 0:
            c = stack.pop()
            for p in ps[c]:
                another, relative_position = p
                if another in not_decided:
                    xs[another] = xs[c] + relative_position
                    not_decided.remove(another)
                    stack.append(another)
                else:
                    if xs[another] != xs[c] + relative_position:
                        return False
    return True

if solve():
    print("Yes")
else:
    print("No")
max = 0
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())
price = [1,2,3,4,5,6]
for i in range(6)
    if max <= price[j] - price[i]:
    print max

### FIXED CODE ###

import sys

n = int(raw_input())

min_R = int(raw_input())
nums = map(int, sys.stdin.readlines())

ans = -10**9

for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
        
print ans
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0])-1:int(A[1])] = 1.0

print(NM)

s = np.sum(NM,axis=0)
print(s)

print(np.sum(s==M))

### FIXED CODE ###

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

left = 1
right = N

for l, r in LR:
    left = max(left, l)
    right = min(right, r)

ans = right - left

print(ans + 1 if ans >= 0 else 0)
atai = input().split()
a = (atai[0])
b = (atai[1])
print(a*b,(a+b)*2)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,(a+b)*2)
n = input()
k = int(input())

def solve1(n):
    l = len(n)
    if l > 0:
        return int(n[0]) + 9 * (l-1)
    else:
        return 0

def solve2(n):
    l = len(n)
    ret = (int(n[0]) - 1) * 9 * (l-1) + 9 * 9 * (l - 1) * (l - 2)  // 2
    n = n[1:]
    while (n[0] == "0"):
        n = n[1:]
        if (n == "0"):
            n = ""
            break
    return ret + solve1(n)

def solve3(n):
    l = len(n)
    ret = (int(n[0])-1) * 9 * 9 * (l - 1) * (l - 2) // 2 + 9 * 9 * 9 * (l - 1) * (l - 2) * (l - 3) // 6
    n = n[1:]
    while (n[0] == "0"):
        n = n[1:]
    return ret + solve2(n)

if k == 1:
    print(solve1(n))
elif k == 2:
    print(solve2(n))
else:
    print(solve3(n))
    

### FIXED CODE ###

n = input()
k = int(input())

def solve1(n):
    l = len(n)
    if l > 0:
        return int(n[0]) + 9 * (l-1)
    else:
        return 0

def solve2(n):
    l = len(n)
    if l > 1:
        ret = (int(n[0]) - 1) * 9 * (l-1) + 9 * 9 * (l - 1) * (l - 2)  // 2
        n = n[1:]
        while (n[0] == "0"):
            if (n == "0"):
                n = ""
                break
            
            n = n[1:]
        return ret + solve1(n)
    else:
        return 0

def solve3(n):
    l = len(n)
    if l > 2:
        ret = (int(n[0])-1) * 9 * 9 * (l - 1) * (l - 2) // 2 + 9 * 9 * 9 * (l - 1) * (l - 2) * (l - 3) // 6
        n = n[1:]
        while (n[0] == "0"):
            
            if (n == "0"):
                n = ""
                break
            n = n[1:]
        return ret + solve2(n)
    else:
        return 0

if k == 1:
    print(solve1(n))
elif k == 2:
    print(solve2(n))
else:
    print(solve3(n))
def main():
    r,g,b,n = map(int, input().split())
    tmp = [r,g,b]
    r,g,b = tmp.sort(reverse=True)
    res = 0
    for i in range(n//r + 1):
        for j in range(n//g + 1):
            if r*i + g*j <= n:
                if (n-(r*i + g*j)) % b==0:
                    res += 1           
    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    r,g,b,n = map(int, input().split())
    tmp = [r,g,b]
    r,g,b = sorted(tmp, reverse=True)
    res = 0
    for i in range(n//r + 1):
        if i*r > n:
            break
        for j in range(n//g + 1):
            if r*i + g*j > n:
                break
            if (n-(r*i + g*j)) % b==0:
                res += 1           
    print(res)

if __name__ == '__main__':
    main()
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 21:13:02 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A =[list(map(int,input().split())) for i in range(N)]

A.sort(key=lambda x: x[1])
kinds = 0
t = 0
for i in range(N):
    if t != A[i][0]:
        kinds += 1
        t = A[i][0]
c = K - kinds if K - kinds >=0 else 0
d = K-c
temp_t = pow(K-c,2)
i = N-1
counta =0
temp_d=0
a = [0 for i in range(N+1)]
b,b2 =[],[]
while counta < K:
    if c-a[A[i][0]] >= 0:
        temp_d += A[i][1]
        c = c-1 if a[A[i][0]] >= 1 else c
        a[A[i][0]] += 1
        counta+=1
        b2.append(A[i][1])
    else:
        b.append(A[i][1])
    i -=1
ans = [0 for i in range(len(b)+1)]
ans[0] = temp_t+temp_d
#print(ans)
for i in range(len(b)):
    ans[i+1] = ans[i] +b[i]-b2[-1-i]-(pow(d,2)-pow(d-i-1,2))
print(max(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 20:39:09 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort(reverse = True,key=lambda x:x[1])
eat,noteat =[],[]
a = [0 for i in range(N+1)]
k = K
for i in range(N):
    if k != 0:
        if a[A[i][0]] ==0:
            a[A[i][0]] = 1
            eat.append(A[i][1])
            k -= 1
        else:
            noteat.append(A[i][1])
    else:
        noteat.append(A[i][1])
        
ans = [0 for i in range(min(K-k,len(noteat))+2)]
ans[0] = sum(eat)+ sum(noteat[:k])+ pow(K-k,2)

for i in range(1,min(K-k,len(noteat[k:])+1)):
    ans[i] = ans[i-1]-(pow(K-k-(i-1),2)+eat[-i]) +(pow(K-k-i,2)+noteat[k+i-1])

print(max(ans))
H, W = map(int,input().split())
a = []
for i in range(H):
  a1 = input()
  if "#" in a1:
    a.append(a1)

b = []
for i in range(W):
  bi = [""] * W
  for j in range(len(a)):
    if j == len(a) - 1 and "#" in a[j - 2][i] + a[j - 1][i] + a[j][i]:
      b.append(a[j - 2][i] + a[j - 1][i] + a[j][i])
      
for i in range(len(b)):
  ans = 0
  for j in range(len(b[0])):
    ans = b[j - 2][i] + b[j - 1][i] + b[j][i]
  print(ans)
   

### FIXED CODE ###

H, W = map(int,input().split())
a = []
for i in range(H):
  a1 = input()
  if "#" in a1:
    a.append(a1)

b = []
for i in range(W):
  for j in range(len(a)):
    if a[j][i] == "#":
      break
  else:
      b.append(i)

for i in range(len(a)):
  ans = ""
  for j in range(W):
    if not j in b:
      ans += a[i][j]
  print(ans)
n,k = map(int,input().split())
h = list(input().split())
h.sort()
ans = int(0)
if k>=n:
  print(ans)
else:
	for i in range(n - k):
    	ans += int(h[i])
	print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
h = sorted(h, reverse=True)
ans = 0
for i in range(k, n):
  ans+=h[i]
  
print(ans)
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
Q=int(input())
somme=sum(A)
L=np.zeros(10**5+1)
for i in range(1,N+1):
    L[i]=sum(A==i)

for step in range(Q):
    b,c=map(int,input().split())
    somme=somme+(c-b)*L[b]
    L[c]=L[c]+L[b]
    print(int(somme))    

### FIXED CODE ###

N=int(input())
A=[int(x) for x in input().split()]
Q=int(input())
somme=sum(A)

from collections import Counter
D=Counter()

for l in A:
    D[l]+=1
    
for step in range(Q):
    b,c=map(int,input().split())

    if b not in D:
        print(somme)
        continue

    somme=somme+(c-b)*D[b]

    D[c]=D[c]+D[b]
    del D[b]    
    print(somme)
n=int(input())
d=list(map(int, input().split()))
l=d//2
dif=d[l]-d[l-1]
if dif==0:
  print(0)
else:
  print(dif)

### FIXED CODE ###

n=int(input())
d=list(map(int, input().split()))
l=len(d)//2
d.sort()
dif=d[l]-d[l-1]
if dif==0:
  print(0)
else:
  print(dif)
a[0],a[1],a[2] = map(int, raw_input().split())

i = 1
while i < 3 :
    j = i - 1
    while j < 3:
        if a[j] > a[j+1]:
             t = a[j]
             a[j] = a[j+1]
             a[j+1] = t
        else:
            break
        j -= 1
    i += 1

print a[0],a[1],a[2]

### FIXED CODE ###

a,b,c = sorted(map(int, raw_input().split()))
print a,b,c
#ABC054A

a,b=map(int<raw_input().split())
if a==1:
 a=14
if b==1:
 b=14
if a>b:
 print 'Alice'
elif a<b:
 print 'Bob'
else:
 print 'Draw'


### FIXED CODE ###

#ABC054A

a,b=map(int,raw_input().split())
if a==1:
 a=14
if b==1:
 b=14
if a>b:
 print 'Alice'
elif a<b:
 print 'Bob'
else:
 print 'Draw'
S=input()
judge='AC'
cnt = 0

for i in len(S):
    if S[i].isupper():
        if i == 0 or i == len(S) - 2 or S[i] != 'C':
            judge = 'WA'
        cnt+=1

if cnt != 1:
    judge = 'WA'
print(judge)


### FIXED CODE ###

S=input()

judge = "AC" if (S[0] == 'A' and S[2:-1].count('C') == 1 and S[1:].replace('C', '').islower()) else "WA"
print(judge)
N, M = map(int,input().split())
tree = {}

for i in range(M):
    a, b, c = map(int, input().split())
    v= tree.get(a,[])
    v.append([b, c])
    tree[a] = v

m = []
def cost(v, c, visited):
    if v in visited:
        m.append(c)
        if max(m) > 0:
            print('inf')
            exit()
        return
    b = tree.get(v, None)
    if b is None:
        m.append(c)
        return 
    elif len(b) == 1 and tree.get(b[0][0],None) == None:
        j = c+b[0][1]
        m.append(j)
    else:
        for b, c2 in b: 
            cost(b, c+c2, visited + [v])

cost(1, 0, [])
print(max(m))

### FIXED CODE ###

N, M = map(int,input().split())
dist = [0] + [float('inf')] * (N - 1)

a = []
b = []
c = []

for i in range(M):
    i,j,k = map(int,input().split())
    a.append(i)
    b.append(j)
    c.append(-1*k)

INF = float('inf')

for i in range(N-1):
    for j in range(M):
        if dist[a[j] - 1] == INF: continue
        if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
            dist[b[j] - 1] = dist[a[j] - 1] + c[j]
        
ans = dist[N -1]

negative = [False] * N

for i in range(N):
    for j in range(M):
        if dist[a[j] - 1] == INF: continue
        if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
            dist[b[j] - 1] = dist[a[j] - 1] + c[j]
            negative[b[j] - 1] = True

        if negative[a[j] - 1] == True:
            negative[b[j] - 1] = True

if negative[N - 1]:
    print('inf')
else:
    print(-1 * ans)
import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = list(iter(input, ""))
    n = int(cin[0].split(" ")[0])
    xs = np.array(cin[1].split(" "))
    xs = xs.astype("int")
    cout = main(n, xs)
    print(cout)

### FIXED CODE ###

import numpy as np

def main(n, xs):
    minx = min(xs)
    maxx = max(xs)
    ress = []

    for x in range(minx, maxx+1):
        res = sum((xs - x) ** 2)
        ress.append(res)

    res = min(ress)
    return res

if __name__ == "__main__":
    cin = input()
    n = int(cin.split(" ")[0])
    cin = input()
    xs = np.array([], dtype="int")

    for i in range(n):
        xs = np.append(xs, int(cin.split(" ")[i]))
    cout = main(n, xs)
    print(cout)
a, b = map(int, input().split())
c = list(map(int, input
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b
        if a > d[i] * 2:
            s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)


### FIXED CODE ###

a, b = map(int, input().split())
print(a / b)
N, Q = map(int, input().split())
nodes = {}
for _ in range(N-1):
    a, b = input().split()
    if nodes.get(a) is None:
        nodes[a] = [b]
    else:
        nodes[a] += [b]

PX = [input().split() for _ in range(Q)]

ptree_map = {}


def gen_subtree_nodes(node):
    res = [int(node)]
    for n in nodes.get(node, []):
        subtree_nodes = gen_subtree_nodes(n)
        ptree_map[n] = subtree_nodes
        res += subtree_nodes

    return res


ptree_map['1'] = gen_subtree_nodes('1')

node_cnts = [0] * (N+1)
for p, x_str in PX:
    x = int(x_str)
    for n in ptree_map[p]:
        node_cnts[n] += x

print(*node_cnts[1:])


### FIXED CODE ###

N, Q = map(int, input().split())
nodes = [[] for _ in range(2*(10**5)+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    nodes[a] += [b]

PX = [0 for _ in range(2*(10**5)+1)]
for _ in range(Q):
    p, x = map(int, input().split())
    PX[p] += x


node_cnts = [0] * (2*(10**5)+1)

q = [(1, PX[1])]
while q:
    node, count = q.pop()
    node_cnts[node] = count
    for n in nodes[node]:
        subtree_nodes = q.append((n, count + PX[n]))


print(*node_cnts[1:N+1], sep=' ')
n, m, c=map(int, input().split())
b=list(map(int, input().split()))
ac=0
for _ in range(n):
  ans=c
  a=list(map(int, input().split()))
  for i in range(n):
    ans+=a[i]*b[i]
  if ans>0:
    ac += 1
print(ac)

### FIXED CODE ###

n, m, c=map(int, input().split())
b=list(map(int, input().split()))
ac=0
for _ in range(n):
  ans=c
  a=list(map(int, input().split()))
  for i in range(m):
    ans+=a[i]*b[i]
  if ans>0:
    ac += 1
print(ac)
import time

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

if (B + C) >= A:
    print(C - (A - B))

else:
    print(0)

### FIXED CODE ###

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

if (B + C) >= A:
    print(C - (A - B))

else:
    print(0)
a, b, c = map(int, input().split())

if a + b + c == 17 && a * b * c == 5 * 5 * 7:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

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

if (a + b + c == 17) and (a * b * c == 5 * 5 * 7):
    print("YES")
else:
    print("NO")
N = int(input())
A = list(map(int,input().split()))
A.sort()
K = N-1
ans = []
while(K>1):
    if A[K-1] < 0:
        break
    l = A[0] - A[K]
    ans.append(str(A[0])+" "+str(A[K]))
    A[0] = l
    K -= 1
if N == 2:
    ans.apend(str(A[1])+" "+str(A[0]))
    print(A[1]-A[0])
else:
    b = A[K]
    for i in range(K-1,0,-1):
        c = A[i]
        ans.append(str(b)+" "+str(c))
        b = b-c
    ans.append(str(b)+" "+str(A[0]))
    print(b-A[0])
for p in ans:
    print(p)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
K = N-1
ans = []
while(K>1):
    if A[K-1] < 0:
        break
    l = A[0] - A[K]
    ans.append(str(A[0])+" "+str(A[K]))
    A[0] = l
    K -= 1
if K == 1:
    ans.append(str(A[1])+" "+str(A[0]))
    print(A[1]-A[0])
else:
    b = A[K]
    for i in range(K-1,0,-1):
        c = A[i]
        ans.append(str(b)+" "+str(c))
        b = b-c
    ans.append(str(b)+" "+str(A[0]))
    print(b-A[0])
for p in ans:
    print(p)
n=int(input())
d={1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',
17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',26:'z'}

x=n
s=''

while(x%26!=0):
    if x//26!=0:
            f=x%26
            x=x//26
    else:break
    s+=d[f]
f=x%26
s+=d[f]
print(s[::-1])

### FIXED CODE ###

n=int(input())
d='abcdefghijklmnopqrstuvwxyz'
x=n
s=''
n-=1
while(n>=0):
    s+=d[n%26]
    n=n//26
    n-=1
print(s[::-1])
n = int(input())
S = input()
b = 0
w = S.count('.')
res = w
for s in S:
	if s == '.':
		w -= 1
	else:
		b += 1
	res = min(res,b+w)
print(res)
	

### FIXED CODE ###

a, b, c = map(int, input().split())
ans = "No"
if a < c and c < b or b < c and c < a:
    ans = "Yes"
print(ans)
for i in range(3):
  s.append(input())
member=["A","B","C"]
turn=0

while True:
  if s[turn]=="":
    winner=turn
    break
  elif s[turn][0]=="a":
    s[turn]=s[turn][1:]
    turn=0
  elif s[turn][0]=="b":
    s[turn]=s[turn][1:]
    turn=1
  else:
    s[turn]=s[turn][1:]
    turn=2
print(member[winner])
    


### FIXED CODE ###

s=[]
for i in range(3):
  s.append(input())
member=["A","B","C"]
turn=0

while True:
  if s[turn]=="":
      winner=turn
      break
  if s[turn][0]=="a":
    next=0
  elif s[turn][0]=="b":
    next=1
  else:
    next=2
  s[turn]=s[turn][1:]
  turn=next

print(member[winner])
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint8)
numcount = 1
berrycount = 0
flag = 0
for i in range(h):
    flag = 0
    if not "#" in list1[i]:
        if numcount == 1:
            for j in range(w):
                list2[i][j] = numcount
            numcount -= 1
        else:
            numcount -= 1
            for j in range(w):
                list2[i][j] = numcount
        flag = 1

    if not flag:        
        for j in range(w):
            
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0:
                    berrycount += 1
                    list2[i][j] = numcount
                else:
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0
    numcount += 1

for i in range(h):
    print(" ".join(map(str,list2[i])))

### FIXED CODE ###

h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint32) #list2に0の配列を用意
numcount = 1 #切り分けたケーキにふる番号
berrycount = 0 #1列に何回目のいちごが現れたか
flag = 0 #1列にいちごが一個も無かったときのフラグ
que = [] #その時の列をqueに入れてく
for i in range(h):
    flag = 0
    if not "#" in list1[i]: #いちごが乗ってない列
        flag = 1
        numcount -= 1
        que.append(i)
    if not flag: #いちごが乗ってる例
        for j in range(w):    
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0: #いちごが出現するのが1回目なら、特に気にせず番号をつける
                    berrycount += 1
                    list2[i][j] = numcount
                else: #2回目以降なら、振り分ける番号を+1する
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0 #いちごリセット
    numcount += 1 #振り分け番号を+1

meme = 0 
"""
1列目から何列もいちごが現れないとき、
初めていちごが現れる列を探索し、その列の数字を1列目~にコピーする。
それ以外(普通に列の途中でいちごのない列が出現したとき)
は、一つ前の列を参照してコピーする
"""
for i in que:
    if i == 0:
        for j in range(1,h):
            if "#" in list1[j]:
                meme = j
                break
        list2[i] = list2[meme]
    else:
        list2[i] = list2[i-1]
for i in range(h):
    for j in range(w):
        list2[i][j] = int(list2[i][j])
for i in range(h):
    print(" ".join(map(str,list2[i])))
N,M=map(int,input().split())
p=list(map(int,input().split()))
p=[0]+p

par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(x):
    if par[x]==x:
        return x
    else:
        return find(par[x])

def union(x,y):
    if size[x]>size[y]:
        size[x]+=size[y]
        par[y]=find(x)
    elif size[y]>size[x]:
        size[y]+=size[x]
        par[x]=find(y)
    elif size[x]==size[y]:
        size[x]+=size[y]
        par[y]=find(x)
        
for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        pass
    else:
        union(find(a),find(b))
#print(par)
ans=0
for i in range(1,N+1):
    if find(i)==find(p.[i]):
        ans+=1
        #print(i,find(i))
print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
p=list(map(int,input().split()))
p=[0]+p

par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(x):
    if par[x]==x:
        return x
    else:
        return find(par[x])

def union(x,y):
    if size[x]>size[y]:
        size[x]+=size[y]
        par[y]=find(x)
    elif size[y]>size[x]:
        size[y]+=size[x]
        par[x]=find(y)
    elif size[x]==size[y]:
        size[x]+=size[y]
        par[y]=find(x)
        
for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        pass
    else:
        union(find(a),find(b))
#print(par)
ans=0
for i in range(1,N+1):
    if find(i)==find(p[i]):
        ans+=1
        #print(i,find(i))
print(ans)
N = int(input())
s = map(int,input().split())

a = 0
for i in range(N):
    if s[i]/2 == s[i]//2:
        if s[i]/3 == s[i]//3 or s[i]/5 == s[i]//5:
          a = a + 1
    else:
        a = a + 1

if a == N:
    print("APPROVED")
else:
    print("DENIED")

### FIXED CODE ###

N = int(input())
s = [int(x) for x in input().split()]
 
a = 0
for i in range(N):
    if s[i]/2 == s[i]//2:
        if s[i]/3 == s[i]//3 or s[i]/5 == s[i]//5:
          a = a + 1
    else:
        a = a + 1
 
if a == N:
    print("APPROVED")
else:
    print("DENIED")