Harryxun/stf_run huggingface dataset:
import sys
import heapq

def dijkstra(matrix, n, s, t):
    costs = [sys.maxsize for i in range(n+1)]
    costs[s] = 0
    prevs = [-1 for _ in range(n+1)]
    Q = []
    for i in range(1, n+1):
        heapq.heappush(Q, [costs[i], i])
        
    while(Q != []):
        c, u = heapq.heappop(Q)
        for v in range(1, n+1):
            if matrix[u][v] == 0:
                continue
            alt = costs[u] + matrix[u][v]
            if alt < costs[v]:
                prevs[v] = u
                Q.remove([costs[v], v])
                heapq.heappush(Q, [alt, v])
                costs[v] = alt

    return costs

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

route_y = [[0 for _ in range(n+1)] for _ in range(n+1)]
route_s = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s, t)
cost_s = dijkstra(route_s, n, t, s)
cost_ys = [y+s for y, s in zip(cost_y, cost_s)]
result = [sys.maxsize for _ in range(n+1)]
min_cost = result[-1]
for i in range(n, 0, -1):
    if min_cost > cost_ys[i]:
        min_cost = cost_ys[i]
    result[i] = min_cost
yen = 10**15
for i in range(1, n+1):
    print(yen - result[i])


### FIXED CODE ###

import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s], Q = 0, []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u].items():
            if costs[u] + c < costs[v]:
                heapq.heappush(Q, [costs[u] + c, v])
                costs[v] = costs[u] + c

    return costs

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

route_y = {i: {} for i in range(n+1)}
route_s = {i: {} for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]
from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10 ** 9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        print((calc(n, k) * calc(K - 1, i - 1)) % MOD)


solve()


### FIXED CODE ###

from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10 ** 9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    # return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        if k <= n:
            print((calc(n, k) * calc(K - 1, i - 1)) % MOD)
        else:
            print(0)


solve()
n,k = map(int,input().split())
ls_h = list(map(int,input().split()))
temp_min = 99999999
ls_cos = [0]*n
ls_cos[1] = abs(ls_h[1]-ls_h[0])
for i in range(k):
    ls_cos[i] = abs(ls_h[i]-ls_h[0])

for i in range(2,n):
    temp_min = 99999999
    for j in range(1,min(k+1,i+1)):
        # print(j)
        temp_min = min(temp_min,ls_cos[i-j]+abs(ls_h[i]-ls_h[i-j]))
    ls_cos[i] = temp_min
# print(ls_cos)
print(ls_cos[-1])



### FIXED CODE ###

n,k = map(int,input().split())
ls_h = list(map(int,input().split()))
temp_min = 99999999
ls_cos = [0]*n
ls_cos[1] = abs(ls_h[1]-ls_h[0])
# print(ls_h)
for i in range(min(k,n)):
    ls_cos[i] = abs(ls_h[i]-ls_h[0])

k = min(k,n)
for i in range(k,n):
    temp_min = 10**11
    for j in range(1,k+1):
        # print(i,j)
        temp_min = min(temp_min,ls_cos[i-j]+abs(ls_h[i]-ls_h[i-j]))
    ls_cos[i] = temp_min
#     print(ls_cos)
# print(ls_cos)
# if 99999999 in ls_cos:
#     print(ls_cos[9999999])
print(ls_cos[-1])
from collections import*
def s():
 global a,b;f,q=[1]*-~n,deque([(a,0)])
 while q:
  a,b=q.popleft()
  for v in e[a]:q+=[(v,b+1)]*f[v];f[v]=0
n,*t=map(int,open(0).read().split())
e=[[]for _ in[0]*-~n]
for a,b in zip(t[::2],t[1::2]):e[a]+=b,;e[b]+=a,
s(),s()
print('SFeicrosntd'[b%3!=1::2])

### FIXED CODE ###

from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])
n, m = list(map(int, input().split()))
par = list(range(n+1))
dis = [0] * (n+1)

def root(x):
  if x == par[x]:
    return x
  r = root(par[x])
  dis[x] += dis[par[x]]
  par[x] = r
  return r

def cost(x):
  # xからxの根までのコスト
  if x == par[x]:
    return 0
  return dis[x] + cost(par[x])

for _ in range(m):
  l, r, d = list(map(int, input().split()))
  # 根が違ってればマージ
  # 同じなら入力されたdistanceがこれまでの入力データからなる
  # 現在の木の構造から計算した数値とあっているか判断
  rootl, rootr = root(l), root(r)
  if rootl != rootr:
    # lをrにマージする
    if r == rootr:
      dis[rootl] = d - cost(l)
    else:
      dis[rootl] = d - (dist[x] - dist[y]) # (cost(l) - cost(r))
    par[rootl] = r
  else:
    # コストが同じかどうか
    if d == cost(l) - cost(r):
      continue
    else:
      print("No")
      exit()
print("Yes")

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

class WeightedUnionFindTree:
  def __init__(self, n):
    self.par = list(range(n))
    self.rank = [0 for _ in range(n)]
    self.weight = [0 for _ in range(n)]
   
  def root(self, t):
    if t == self.par[t]:
      return t
    # 経路圧縮してみる
    r = self.root(self.par[t])
    self.weight[t] += self.weight[self.par[t]]
    self.par[t] = r
    return r
   
  def rec_weight(self, t):
    if t == self.par[t]:
      return 0
    return self.weight[t] + self.rec_weight(self.par[t])
   
  def same(self, x, y):
    return self.root(x) == self.root(y)
     
  def unite(self, x, y, w):
    rootx = self.root(x)
    rooty = self.root(y)
    if rootx != rooty:
      if y != rooty:
        # 直接yにつなげる
        self.weight[rootx] = w - self.rec_weight(x)
      else:
        # 根につなげる
        self.weight[rootx] = w - (self.weight[x] - self.weight[y])
      # ここで親を更新
      self.par[rootx] = y
    else:
      return w == self.diff(x, y)
 
  def diff(self, x, y):
    return self.rec_weight(x) - self.rec_weight(y)

n, m = list(map(int, input().split()))
par = list(range(n+1))
dist = [0 for _ in range(n+1)]


wuft = WeightedUnionFindTree(n+1)
flag = True
for _ in range(m):
  l, r, d = list(map(int, input().split()))
  # 根が異なってたらとりあえず併合、同じならdifを取って整合性を確かめる
  a = wuft.unite(l, r, d)
  if a is not None:
    if a == False:
      flag = False
"""
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.par)]
print()
[print("[{}]{}".format(idx, v), end=" ") for idx, v in enumerate(wuft.weight)]
print()
"""

print("Yes" if flag else "No")
# A - Lucky 7
N = input()
if '7' in a:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

# A - Lucky 7
N = input()
if '7' in N:
    print('Yes')
else:
    print('No')
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

dp = [0]*n
dp[0] = a[0][0]

for i in range(n-1):
  dp[i+1] = dp[i] + max(a[0][i+1], a[1][i])
  
print(dp[-1] + a[1][n-1])

### FIXED CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]

l = [0]*n

for i in range(n):
  l[i] = sum(a[0][-(i+1):-(n+1):-1]) + sum(a[1][-1:-(i+2):-1])
  
print(max(l))
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
	now = st+1
	temp=[0]
	while(P[now-1] != st+1):
		temp.append(temp[-1]+C[P[now-1]-1])
		now = P[now-1]
	temp.append(temp[-1]+C[P[now-1]-1])
	if len(temp)>=K+1:
		ans=max(ans, max(temp[1:K+1]))
		continue
	if temp[-1]<=0:
		ans = max(ans, (max(temp[1:])))
	elif K%(len(temp)-1)!=0:
		t=temp[-1]*(K//(len(temp)-1))
		t+=max(temp[:1+K%(len(temp)-1)])
		ans=max(ans, t)
    else:
        t=temp[-1]*(K//(len(temp)-1))-temp[-1]
        t+=max(temp)
        ans=max(ans,t)
		
print(int(ans))


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

maxscore = -(10 ** 18)

for st in range(N):
	cumsum = [0]
	now = st
	while(P[now] != st):
		now = P[now]
		cumsum.append(cumsum[-1] + C[now])
	cumsum.append(cumsum[-1] + C[st])
	
	m = len(cumsum) - 1
	loopsum = cumsum[-1]
	
	if loopsum < 0:
		maxscore = max(maxscore, max(cumsum[1:min(K + 1, m + 1)]))
		continue
	
	score = (K // m - 1) * loopsum
	extended_cumsum = cumsum + [cumsum[i] + loopsum for i in range(1, K % m + 1)]
	score += max(extended_cumsum)
	maxscore = max(maxscore, score)
print(maxscore)
A, B, C = int(input().split)

int D = max(A, B, C)

if A == D :
  print(A * 10 + B + c)
  
elif B == D:
  print(B * 10 + A + C)
  
elif C == D
  print(C * 10 + A + B)

### FIXED CODE ###

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


ans = max(A*10 + B + C, B*10 + A + C, C*10 + A + B)
print(ans)
S = dict()
S['a'] = list(input())[::-1]
S['b'] = list(input())[::-1]
S['c'] = list(input())[::-1]
 p = 'a'
while S[]:
  p = S[p].pop()  
print(player.upper())

### FIXED CODE ###

Sa=list(input())
Sb=list(input())
Sc=list(input())
S = [Sa, Sb, Sc]
Ans = ["A", "B", "C"]
idx = ['a', 'b', 'c']
p = 'a'

def take_turn(i):
  if len(S[i])==0:
    print(Ans[i])
    exit()
  else:
    p = S[i].pop(0)
    return p
    
while True:
  p = take_turn(idx.index(p))
a = int(input())
c = [j for j in range(1,int(a**0.5)) if a%j==0]
print((max(c)-1) + (a//max(c)-1))

### FIXED CODE ###

n = int(input())
c = max([i for i in range(1,int(n**0.5+1)) if n%i==0])
print(c+n//c-2)
n = int(raw_input())
k = map(int, raw_input().split())
print ("%d %d %d") %(min(x), max(x), sum(x))

### FIXED CODE ###

n = raw_input()
x = map(int, raw_input().split())
print ("%d %d %d") %(min(x), max(x), sum(x))
a = int(input())
b = int(input())

if a*b%2 == 0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

a, b = map(int, input().split())
if a*b%2 == 0:
    print('Even')
else:
    print('Odd')
x=(int)input().strip()
print(x**3)

### FIXED CODE ###

x=int(input().strip())
print(x**3)
N=input()
a=int(N)
b=list(N)
sum=0
for i in N:
  sum+=i

if N%sum==0:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

N=input()
a=int(N)
b=list(N)
sum=0

for i in b:
  sum+=int(i)
 
if a%sum==0:
  print('Yes')
else:
  print('No')
A, B, C, K = map(int, input().split())
result = 0

if A >= K:
    print(K)
elif (A + B) >= K:
    print(K)
else:
    for i in range(K):
        if A > (i + 1):
            result += 1
            continue
        elif A == (i + 1):
            result += 1
            continue

        if B > (i + 1 - A):
            result += 0
            continue
        elif B == (i + 1 - A):
            result += 0
            continue

        if C > (i + 1 - A - B):
            result -= 1
            continue
        elif C == (i + 1 - A - B):
            result -= 1
            break
        else:
            break
    print(result)


### FIXED CODE ###

s = input()
t = input()

if t.startswith(s) and str.isalpha(t):
    if len(t) == (len(s) + 1):
        print('Yes')
else:
    print('No')
n,m = map(int, input().split())
import numpy as np
G = np.zeros((n, n))
for _ in range(m):
    a, b = map(int, input().split())
    G[a-1, b-1] = G[b-1, a-1] = 1

res = np.array([0] + [-1] *(n -1))

from collections import deque
q = deque([0])

while q:
    vis = q.popleft() # visit
    #     print(vis)
    cands = np.where(G[vis])[0] # next visit

    for c in cands:
        if res[c] == -1:
            res[c] = vis # mark
            q.append(c) # shoul append

if (res == -1).sum():
    print('No')
else:
    print('Yes')
    for i in res[1:]:
        print(i +1)

### FIXED CODE ###

import numpy as np
import networkx as nx
g = nx.Graph()

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

for _ in range(m):
    a, b = map(int, input().split())
    g.add_edge(a, b)

res = np.array([0] * 2 + [-1] * (n-1))

from collections import deque
q = deque([1])

while q:
    vis = q.popleft() # visit
    #     print(vis)
    cands = list(nx.all_neighbors(g, vis)) # next visit

    if cands:
        for c in cands:
            if res[c] == -1:
                res[c] = vis # mark
                q.append(c) # should append

if (res == -1).sum():
    print('No')
else:
    print('Yes')
    for i in res[2:]:
        print(i)
import numpy as np


def main():
    N, D = map(int, input().split())
    p = [np.array(list(map(int, input().split()))) for _ in range(N)]
    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            d = np.sqrt(np.sum(np.power(p[i] - p[j], 2)))
            if d % 1 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np


def main():
    N, D = map(int, input().split())
    p = [np.array(list(map(int, input().split()))) for _ in range(N)]
    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            d = np.sqrt(np.sum(np.power(p[i] - p[j], 2)))
            if d % 1 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()
is_odd = lambda x: x % 2 == 0

import fileinput
for line in fileinput.input():
	print(sum([1 for x in range(1, x) if is_odd(x)]/x)

### FIXED CODE ###

num_odd = lambda x: x/2 if x % 2 == 0 else x/2 + 1 
 
import fileinput
for line in fileinput.input():
    try:
        N = int(line.strip())
    except:
        continue
 
    print(1.0 * num_odd(N) / N)
import numpy as np

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


class Node:
    def __init__(self, parent):
        self.parent = parent
        self.leaf = []
        self.score = 0

    def add_score(self, score):
        self.score += score
        for l in self.leaf:
            l.add_score(score)


tree = {1: Node(None)}
tmp = np.array([list(map(int, input().split())) for _ in range(N-1)])
for i in np.argsort(tmp[:, 0]):
    p, c = tmp[i][0], tmp[i][1]
    if p not in tree:
        tree[p] = Node(None)
    if c not in tree:
        tree[c] = Node(p)
    tree[p].leaf.append(tree[c])

for p, x in [tuple(map(int, input().split())) for _ in range(Q)]:
    tree[p].add_score(x)

print(' '.join([str(t.score) for t in tree.values()]))


### FIXED CODE ###

from collections import defaultdict

N, Q = map(int, input().split())
d = defaultdict(list)

for _ in range(N - 1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

c = defaultdict(int)

for _ in range(Q):
    p, x = map(int, input().split())
    c[p] += x

ans = [0 for i in range(N)]
que = [(1, 0, -1)]
while len(que) > 0:
    tmp = []
    for v, x, par in que:
        x += c[v]
        ans[v - 1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w, x, v))
    que = tmp

print(*ans)
n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
if n==0:
  print(0)
  exit()
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[24-d[i]]+=1
if max(time)>1:
  print(0)
  exit()
flg=0
ans=0
cnt=0
for i in range(25):
  i=i%24
  if time[i]==0 and not flg:
    flg=1
    cnt=1
  elif time[i]==0:
    cnt+=1
  else:
    ans=max(ans,cnt)
    cnt=0
    flg=0
print(ans)
    
    

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[-d[i]]+=1
if max(time)>1:
  print(0)
  exit()
ans=[]
cnt=1
for i in range(1,25):
  i=i%24
  if time[i]==0:
    cnt+=1
  else:
    ans.append(cnt)
    cnt=1
print(min(ans))
N = input()
lis = input().split(" ")
cnt = 1
for i in range(int(N+1)):
    for j in range(i-1,-1,-1):
        if int(lis[i])>int(lis[j]):
            break
        else:
            cnt +=1
        break
print(cnt)

### FIXED CODE ###

N = int(input())
lst = list(map(int,input().split()))
 
cnt = 0
m = lst[0]
 
for i in lst:
  if i <= m:
    cnt +=1
    m = i
print(cnt)
n = int(input())
cnt = [0] * 100001
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
print(max(cnt))

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])
    print(ans)
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
	print(n)
resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()
from sys import stdin, stdout
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m = rli()
	G = defaultdict(lambda: [])
	for _ in range(m):
		u, v = rli()
		G[u].append(v)
	ans = 0
	memo = defaultdict(lambda: 0)

	def longest(v):
		if v in memo:
			return memo[v]
		pathlen = 0
		for nbhr in G[v]:
			pathlen = max(pathlen, 1 + longest(nbhr))
		memo[v] = pathlen
		return pathlen

	for i in range(1, n+1):
		ans = max(ans, longest(i))

	print(ans)

	stdout.close()

if __name__ == "__main__":
	main()

### FIXED CODE ###

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(10000)

def main():
	n, m = rli()
	G = [[] for i in range(n+1)]
	for _ in range(m):
		u, v = rli()
		G[u].append(v)
	ans = 0
	memo = [-1 for _ in range(n+1)]

	def longest(v):
		if memo[v] > -1:
			return memo[v]
		pathlen = 0
		for nbhr in G[v]:
			pathlen = max(pathlen, 1 + longest(nbhr))
		memo[v] = pathlen
		return pathlen

	for i in range(1, n+1):
		ans = max(ans, longest(i))

	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()
import networkx as nx

def main():
  N,M=map(int,input().split())
  S = [list(input()) for _ in range(N)]

  if N == M == 1:
    print(0)
    print(S[0][0])
    exit()

  index = lambda i,j: i*M+j

  G=nx.DiGraph()
  G.add_node('source')
  G.add_node('sink')
  dx,dy=(1,0),(0,1)
  for i in range(N):
    for j in range(M):
      if S[i][j]=='#':continue
      if (i+j) %2:
        G.add_edge(index(i,j),'sink',capacity=1)
      else:
        G.add_edge('source',index(i,j),capacity=1)
      for k in range(2):
        v1,v2 = index(i,j),index(i+dx[k],j+dy[k])
        if not (0<=i+dx[k]<N and 0<=j+dy[k]<M):
          continue
        if S[i+dx[k]][j+dy[k]] == '#': continue
        if (i+j) % 2:
          G.add_edge(v2,v1,capacity=1)
        else:
          G.add_edge(v1,v2,capacity=1)
         
  flow_value, flow_dict = nx.maximum_flow(G, "source", "sink")
  assert False

  for v1 in flow_dict.keys():
    if v1 in ('sink','source'):continue
    for v2 in flow_dict[v1]:
      if v2 in ('sink','source'):continue
      if flow_dict[v1][v2]:
        i1,j1 = divmod(v1,M)
        i2,j2 = divmod(v2,M)
        (i1,j1),(i2,j2) = sorted([(i1,j1),(i2,j2)])
        if i1 + 1 == i2:
          S[i1][j1] = 'v'
          S[i2][j2] = '^'
        else:
          S[i1][j1] = '>'
          S[i2][j2] = '<'

  print(flow_value)
  for i in range(N):
    print(''.join(S[i]))
    
if __name__ == "__main__":
  main()

### FIXED CODE ###

import networkx as nx

def main():
  N,M=map(int,input().split())
  S = [list(input()) for _ in range(N)]

  if N == M == 1:
    print(0)
    print(S[0][0])
    exit()

  index = lambda i,j: i*M+j

  G=nx.Graph()
  dx,dy=(1,0),(0,1)
  E = []
  n1,n2 = [],[]
  for i in range(N):
    for j in range(M):
      if S[i][j]=='#':continue
      if (i+j)%2:
        n1.append(index(i,j))
      else:
        n2.append(index(i,j))
      for k in range(2):
        v1,v2 = index(i,j),index(i+dx[k],j+dy[k])
        if not (0<=i+dx[k]<N and 0<=j+dy[k]<M):
          continue
        if S[i+dx[k]][j+dy[k]] == '#': continue
        if (i+j) % 2:
          E.append((v2,v1))
        else:
          E.append((v1,v2))
     
  G.add_nodes_from(n1, bipartite=0)
  G.add_nodes_from(n2, bipartite=1)
  G.add_edges_from(E)
  u = [n for n in G.nodes if G.nodes[n]['bipartite'] == 0]
  match = nx.bipartite.maximum_matching(G, top_nodes=u)
  match = {v:match[v] for v in match.keys() if v < match[v]}
 
  for v in match.keys():
    i1,j1 = divmod(v,M)
    i2,j2 = divmod(match[v],M)
    if i1 > i2 or j1 > j2:
      (i1,j1),(i2,j2) = (i2,j2),(i1,j1)
    if i1 < i2:
      S[i1][j1] = 'v'
      S[i2][j2] = '^'
    else:
      S[i1][j1] = '>'
      S[i2][j2] = '<'

  print(len(match))
  for i in range(N):
    print(''.join(S[i]))
    
if __name__ == "__main__":
  main()
N, M = map(int, input().split())

A = []
for _ in range(N):
  a = input()
  A.append(a)

B = []
for _ in range(M):
  b = input()
  B.append(b)

existed = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    match = True
    for mi in range(M):
      for mj in range(M):
        x = i + mi
        y = j + mj

        if (A[y][x] != B[mj][mi]):
          match = False
          break
      
      if (match == False):
        break

    if (match):
      existed = True
      break
  
  if (existed):
    break

result = 'Yes' if (existed) else 'No'
print(result)


### FIXED CODE ###

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

result = ''
if (A == 1 and B != 1):
  result = 'Alice'
elif (B == 1 and A != 1):
  result = 'Bob'
elif (A > B):
  result = 'Alice'
elif (B > A):
  result = 'Bob'
elif (B == A):
  result = 'Draw'

print(result)
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {a[0]:1}
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            ball_dict[a_sort[i]] += 1
        else:
            ball_dict.setdefault(a_sort[i], 1)

    for i in range(n):
        new_dict = ball_dict.copy()
        new_dict[a[i]] -= 1
        ans = 0
        for v in new_dict.values():
            ans += v * (v - 1) // 2
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()