Harryxun/stf_run huggingface dataset:
from math import factorial

N = int(input())
s = [input() for i in range(N)]

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    if v >= 2:
        cnt += int(factorial(v)) / int(factorial(2)) / int(factorial(v - 2))

print(int(cnt))

### FIXED CODE ###

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


N = int(input())
s = [input() for i in range(N)]

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    if v >= 2:
        # cnt += int(factorial(v)) / int(factorial(2)) / int(factorial(v - 2))
        cnt += cmb(v, 2)

print(cnt)
a, b, c = list(map(int, input().split()))
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

a, b, c = list(input().split())
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')
list1=[]
for i in range(1,200):
    if i<=9:
        list1.append(i)
    elif i%10==0:
        pass
    elif i<=19:
        a=(i-10)*10+9
        list1.append(a)
    elif i<=29:
        a=(i-20)*100+99
        list1.append(a)
    elif i<=39:
        a=(i-30)*1000+999
        list1.append(a)
    elif i<=49:
        a=(i-40)*10000+9999
        list1.append(a)
    elif i<=59:
        a=(i-50)*100000+99999
        list1.append(a)
    elif i<=69:
        a=(i-60)*1000000+999999
        list1.append(a)
    elif i<=79:
        a=(i-70)*10000000+9999999
        list1.append(a)
    elif i<=89:
        a=(i-80)*100000000+99999999
        list1.append(a)
    elif i<=99:
        a=(i-90)*1000000000+999999999
        list1.append(a)
    elif i<=109:
        a=(i-100)*10000000000+9999999999
        list1.append(a)
    elif i<=119:
        a=(i-110)*100000000000+99999999999
        list1.append(a)
    elif i<=129:
        a=(i-120)*1000000000000+999999999999
        list1.append(a)
    elif i<=139:
        a=(i-130)*10000000000000+9999999999999
        list1.append(a)
    elif i<=149:
        a=(i-140)*100000000000000+99999999999999
        list1.append(a)
    elif i<=159:
        a=(i-150)*1000000000000000+999999999999999
        list1.append(a)
    elif i<=169:
        a=(i-160)*10000000000000000+9999999999999999
        list1.append(a)
    elif i<=179:
        a=(i-170)*100000000000000000+99999999999999999
        list1.append(a)
#print(list1[143])
K=int(input())
for j in range(K):
    print(list1[j])

### FIXED CODE ###

K=int(input())
D={}
for i in range(1,10**4):
    for j in range(12):
        Sunuke=str(i)+("9"*j)
        if len(Sunuke)<=15 and Sunuke not in D:
            S=0
            for k in range(len(Sunuke)):
                S+=int(Sunuke[k])
            D[int(Sunuke)]=S
D=list(D.items())
D.sort()
#print(D[:10])
import bisect

d=[10**16 for i in range(len(D))]
d[0]=0
ans=[0 for i in range(len(D))]
for i in range(len(D)):
    ans[bisect.bisect_right(d,D[i][0]/D[i][1])]=D[i][0]
    d[bisect.bisect_right(d,D[i][0]/D[i][1])]=D[i][0]/D[i][1]
    
#print(ans[:50])
ANS=[]
MAX=0
for i in range(len(ans)):
    if ans[i]>MAX:
        ANS.append(ans[i])
        MAX=ans[i]
#print(ANS[:100])
for i in range(K):
    print(ANS[i])
#print(d[:10])
from fractions import gcd

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

L = (N * M) // gcd(N, M)

L1 = [1]
L2 = [1]
for i in range(1, N):
    t = i * (L // N) + 1
    L1.append(t)

for i in range(1, M):
    t = i * (L // M) + 1
    L2.append(t)


LS = [None] * L
# for i, li in enumerate(L1):
#     ind = li-1
#     LS[ind] = S[i]

ans = True
# for i, li in enumerate(L2):
#     ind = li-1
#     if LS[ind] is not None:
#         if LS[ind] != T[i]:
#             ans = False

if ans:
    print(L)
else:
    print(-1)


# print(L1)
# print(L2)
# print(LS)

### FIXED CODE ###

from fractions import gcd

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

L = (N * M) // gcd(N, M)

L1 = [0]
L2 = [0]

from collections import Counter
c = Counter()

for i in range(1, N):
    t = i * (L // N) + 1
    L1.append(t-1)

for i in range(1, M):
    t = i * (L // M) + 1
    L2.append(t-1)


d = {}
for i, li in enumerate(L1):
    d[li] = S[i]

# print(d)

ans = True

for i, li in enumerate(L2):
    if not d.get(li):
        continue
    if d[li] != T[i]:
        ans = False

# print(L1)
# print(L2)
# print(common)
# print(dic)

if ans:
    print(L)
else:
    print(-1)
R=input()
import math
r=2*math.pi*R
print(r)

### FIXED CODE ###

R=int(input())
r=2*3.14159265358979*R
print(r)
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 =sorted(p)[::-1][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    if pf == True and qf == True and  p[pp]<rr and q[qq]<rr:
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    elif pf == True and p[pp]<rr:
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    elif pf == True and q[qq]<rr:
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
print(sum(p)+sum(q))

### 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 =sorted(p)[::-1][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    lll = False
    if pf == True and qf == True:
        if p[pp]<rr and q[qq]<rr:
            lll = True
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    if pf == True and lll == False:
        if p[pp]<rr:
            lll = True
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    if qf == True and lll == False:
        if q[qq]<rr:
            lll = True
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False

print(sum(p)+sum(q))
H,W=map(int,input().split())
G=[input() for i in range(H)]
F=[[0]*W for i in range(H)]

def judge(p0,p1,res):
  F[p0][p1]=1
  if p0==H-1 and p1==W-1:
    return res
  
  a=float("inf")
  if p0<H-1 and F[p0+1][p1]==0 and G[p0+1][p1]==".":
    m=judge(p0+1,p1,res+1)
    if m!=False:
      a=min(a,m)
  
  if p1<W-1 and F[p0][p1+1]==0 and G[p0][p1+1]==".":
    m=judge(p0,p1+1,res+1)
    if m!=False:
      a=min(a,m)
      
  if p0>0 and F[p0-1][p1]==0 and G[p0-1][p1]==".":
    m=judge(p0-1,p1,res+1)
    if m!=False:
      a=min(a,m)
   
  if p1>0 and F[p0][p1-1]==0 and G[p0][p1-1]==".":
    m=judge(p0,p1-1,res+1)
    if m!=False:
      a=min(a,m)
    
  if a!=float("inf"):
    return a
    
  return False
k=judge(0,0,0)
if k!=False:
  ans=W*H-(k+1)
  for i in range(H):
    ans-=G[i].count("#")
  print(ans)
else:
  print(-1)

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
G=[input() for i in range(H)]

b_n= [G[i].count("#") for i in range(H)]

root_min=float("inf")
root=deque([[0,0,1]])
F=[[0]*W for i in range(H)]
while len(root)!=0:
  p=root.popleft()
  if p[:2]==[H-1,W-1]:
    print(H*W-p[2]-sum(b_n))
    exit()
  F[p[0]][p[1]]=1
  for i in range(4):
    if i==0:
      n=[max(0,p[0]-1),p[1],p[2]+1]
    elif i==1:
      n=[min(H-1,p[0]+1),p[1],p[2]+1]
    elif i==2:
      n=[p[0],max(0,p[1]-1),p[2]+1]
    else:
      n=[p[0],min(W-1,p[1]+1),p[2]+1]
      
    if G[n[0]][n[1]]=="#":
      continue
    if F[n[0]][n[1]]==1:
      continue
    if n in root:
      continue
    root.append(n)
print(-1)
a=int(input())
b=int(input())
c=int(input())
if a==1:
  print("Hello World")
if a==2:
  print(b+c)

### FIXED CODE ###

a=int(input())
if a==1:
  print("Hello World")
if a==2:
  b=int(input())
  c=int(input())
  print(int(b+c))
X, N = map(int, input().split())
p = list(map(int, input().split()))

p.sort()
def main():
    l = [True for _ in range(100)]
    for x in p:
        l[x-1] = False
    diff = 0
    while True:
        if l[X-1 -diff]:
            print(X -diff)
            return
        elif l[X-1 +diff]:
            print(X +diff)
            return
        diff += 1

main()

### FIXED CODE ###

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

p.sort()
def main():
    l = [True for _ in range(100)]
    for x in p:
        l[x-1] = False
    diff = 0
    while True:
        if X-1 -diff < 0:
            print(0)
            return
        elif l[X-1 -diff]:
            print(X -diff)
            return
        elif X-1 +diff >= 100:
            print(101)
            return
        elif l[X-1 +diff]:
            print(X +diff)
            return
        diff += 1

main()
import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
print(int(str(ans)[:-2]))

### FIXED CODE ###

import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
if len(str(ans)) <= 2:
    print(math.floor(ans/100))
else:
    print(int(str(ans)[:-2]))
from itertools import combinations

l, r = map(lambda s: int(s) % 2019, input().split())
print(
    (min((i * j) % 2019 for i, j in combinations(range(l, r + 1), 2)), 0)[
        r < l or l == 0
    ]
)

### FIXED CODE ###

from itertools import combinations

n = 2019
l, r = map(int, input().split())
if l // n < r // n:
    print(0)
else:
    print(min((i * j) % n for i, j in combinations(range(l % n, r % n + 1), 2)))
n,k = map(int,input().split())
p = list(map(int,input().split()))
l = []
count = 0
for i in range(n):
    count += (p[i]+1)/2
    l.append(count)
ansl = []
for i in range(n-k):
    ansl.append(l[i+k]-l[i])
print(max(ansl))

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
l = []
count = 0
for i in range(n):
    count += (p[i]+1)/2
    l.append(count)
ansl = []
for i in range(n-k):
    ansl.append(l[i+k]-l[i])
if n == k:
    ansl.append(l[n-1])
print(max(ansl))
N = int(input())
num = 2
idx = 2
nums = []
while True:
  if num**idx > N:
    if idx == 2:
      break
    else:
      num += 1
      idx = 2
      continue
  else:
    nums.append(num**idx)
    idx += 1
nums.sort(key=lambda x:-x)
print(nums[0])


### FIXED CODE ###

N = int(input())
num = 2
idx = 1
nums = [1]
while True:
  if num**idx > N:
    if idx == 2 or N in range(1, 5):
      break
    else:
      num += 1
      idx = 0
      continue
  else:
    nums.append(num**idx)
    idx += 1
nums.sort(key=lambda x:-x)
print(nums[0])
x = input()

prefix = int(x[:-2])
suffix = int(x[-2:])

n = 0
for item in range(5, 0, -1):
    n += suffix // item
    suffix %= item

print(0 if n>prefix else 1)

### FIXED CODE ###

import sys

x = input()

if len(x) < 3:
    print(0)
    sys.exit()

prefix = int(x[:-2])
suffix = int(x[-2:])

n = 0
for item in range(5, 0, -1):
    n += suffix // item
    suffix %= item

print(0 if n>prefix else 1)
#移動の最小値(高速化問題)
x,k,d = map(int,input().split())
x = abs(x)
if (x//d) >=k:
    ans = x - d*k
else:
    y = x-(x//d)*d
    if k- (x//d)%2 != 0:
        ans = y
    else:
        ans = y-d
print(abs(ans))

### FIXED CODE ###

S = input()
list_s = list(S)
count = 0
x = []
for i in range(3):
    if list_s[i] == 'R':
        count +=1
    elif list_s[i] == 'S':
        x.append(count)
        count = 0
x.append(count)
print(max(x))
s = input()
print("no" if len(s) - set(s) else "yes")

### FIXED CODE ###

s = input()
print("no" if len(s) - len(set(s)) else "yes")
n = int(n)
a = list(map(int, input().split()))

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)

### FIXED CODE ###

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

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)
str = input()
p = ""
resut = "Good"
for s in str:
  if p == s:
    result = "Bat"
print(result)

### FIXED CODE ###

strings = list(input())
before_number = 100000
flag = False
for number in strings:
  #前の番号と今の番号が一致したら
  if before_number == int(number):
    flag = True
  else:
    before_number = int(number)

if flag == True:
  print("Bad")
else:
  print("Good")
c = input()
s = list('abcdefghijklmnopqrstuvwxyz')

for i in s:
    if c == s[i]:
        print(s[i+1])
        exit()

### FIXED CODE ###

c = input()
s = list('abcdefghijklmnopqrstuvwxyz')

for i in range(25):
    if c == s[i]:
        print(s[i+1])
        exit()
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  int n = s.length();
  int ans = 0;
  for (int i = 1; i * 2 < n; i++) {
    bool good = true;
    for (int j = 0; j < i; j++) {
      if (s[j] != s[j+i]) {
        good = false;
        break;
      }
    }
    if (good) ans = i * 2;
  }

  cout << ans << endl;

  return 0;
}


### FIXED CODE ###

def main():
    s = input()

    n = len(s)
    for i in range(n // 2):
        s = s[:-2]
        if s[0:n//2-i-1] == s[n//2-i-1:n-i*2-2]:
            print(n-i*2-2)
            return

if __name__ == '__main__':
    main()
N = int(input())
x = N += 1
if N % 0:
  ans = (0.5)
else:
  ans = (x / 2)
print(ans)

### FIXED CODE ###

N = int(input())
if N%2 == 0:
  ans = 0.5
else:
  ans = (N // 2 + 1) / N
print(ans)
import math

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

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

for i in range(len(li_x)):
    if li_x[i] - x < 0:
        li_x[i] =x - li_x[i]
    else:
        li_x[i] = li_x[i] -x

g =gcd(li_x[0],li_x[1])
k=2
if len(li_x)>2:
  while k<len(li_x):
    g=gcd(g,li_x[k])
    k+=1
print(g)


### FIXED CODE ###

import math

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

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

for i in range(len(li_x)):
  if li_x[i] - x < 0:
    li_x[i] =x - li_x[i]
  else:
    li_x[i] = li_x[i] -x

if len(li_x)==1:
  print(li_x[0])

elif len(li_x)==2:
  print(gcd(li_x[0],li_x[1]))

else:
  g =gcd(li_x[0],li_x[1])
  k=2
  while k<len(li_x):
    g=gcd(g,li_x[k])
    k+=1
  print(g)
r = input()
print(r**2)


### FIXED CODE ###

r = int(input())
print(r**2)
#unionfind木_
class unionfind():
    def __init__(self, init_list, ide_ele=1):
        self.par = init_list #初めは自分自身が親
        self.rank = [ide_ele]*len(init_list)

    def find(self, k):#要素k
        if self.par[k] == k:
            return self.par[k]
        else:
            self.par[k] = self.find(self.par[k])
            return self.par[k]

    def union(self, i, j):
        i = self.find(i)
        j = self.find(j)
        if i==j: return False
        else:
            if self.rank[i] == self.rank[j]:#ランクが同じ場合
                self.par[j] = self.par[i]
                self.rank[i] += 1
            if self.rank[j] > self.rank[i]:
                i, j = j, i
                self.par[i] = self.par[j]
            else:
                self.par[i] = self.par[j]

n, m= map(int, input().split())
ini_list = list(range(n))
uni_tree = unionfind(ini_list)
for i in range(m):
    a, b = map(lambda x:int(x)-1, input().split())
    uni_tree.union(a, b)

ans = [0]*n
for i in range(n):
    ans[uni_tree.find(ini_list[i])]+=1
print(max(ans))

### FIXED CODE ###

#unionfind木_集合の管理_同じ集合の数を数える場合：
#parには集合の数と親の名前を同時にメモ化する（根なら-size, 子なら親）
def find(k):#要素k
    if par[k] < 0:#初期はparがすべて負の値
        return k
    else:
        par[k] = find(par[k])
        return par[k]

def unite(i, j):
    i = find(i)
    j = find(j)
    if i==j:#すでに同じ集合
        return False
    else:
        #sizeが大きい方がi
        if i > j:#sizeはマイナス管理なので、i>jの時jの方がサイズが大きい
            i, j = j, i
        par[i] += par[j] #親は負の値で大きくなる
        par[j] = i
        return True

def size(x):
    return -par[find(x)]

n, m= map(int, input().split())
par = [-1]*n#初めは自分自身が親

for i in range(m):
    a, b = map(lambda x:int(x)-1, input().split())
    unite(a, b)

ans = 0
for i in range(n):
    ans = max(ans, -par[i])
print(ans)
def calRate(m, r):
    return int(m * (100 + r) / 100)

while True:
    x, y, s = map(int, input().split())
    if x == 0 and y == 0 and s == 0: break
    ans = 0
    for i in range(1, s):
        for j in range(1, s):
            if calRate(i, x) + calRate(j, x) == s:
                ans = max(ans, calRate(i, y) + calRate(j, y))
    print(ans)

### FIXED CODE ###

def calRate(m, r):
    return int(1.0 * m * (100.0 + r) / 100.0)

while True:
    x, y, s = map(int, raw_input().split())
    if x == 0 and y == 0 and s == 0: break
    ans = 0
    for i in range(1, s):
        ix = calRate(i, x)
        j = int((s - ix) * 100.0 / (100.0 + x))
        if j < 1 or j > s-1:
            continue
        while True:
            if calRate(i, x) + calRate(j, x) < s:
                j += 1
            else:
                break
        if calRate(i, x) + calRate(j, x) != s:
            continue
        ans = max(ans, calRate(i, y) + calRate(j, y))
    print ans
n,k=map(int,input().split())
a=tuple(map(int,input().split()))
l=[0]
for i in range(1,n):
  b=a[i]
  l+=[min(l[-j]+abs(b-a[-j])for j in range(1,min(i+1,k)+1))]
print(l[-1])


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[0]
for i in range(1,n):
  b=a[i]
  l.append(min(l[j]+abs(b-a[j])for j in range(i-min(k,i),i)))
print(l[-1])
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def modinv2(a,m):
    return pow(a,m-2,m)

def f(n,m):
    a = 1
    for i in range(2,n+1):
        a = a*i%m
    return a

N = int(input())
x = list(map(int,readline().split()))

ans = 0
P = 10**9+7

b = f(N-1,P)
#print(b)

for i in range(N-1):
    l = 0
    c = modinv2(N-1-i,P)
    #print(c)
    for j in range(i+1,N):
        l += x[j]-x[i]
        l %= P
    #print(l)
    l = l*b%P
    l = l*c%P
    ans += l

print(ans%P)


### FIXED CODE ###

def modinv2(a,m):
    return pow(a,m-2,m)

def f(n,m):
    a = 1
    for i in range(2,n+1):
        a = a*i%m
    return a

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

ans = 0
P = 10**9+7

b = f(N-1,P)

invlist = [1]

for i in range(1,N-1):
    inv = (invlist[-1]+modinv2(i+1,P))%P
    invlist.append(inv)
#print(invlist)

for i in range(N-1):
    l = x[i+1]-x[i]
    ans += (l*invlist[i]%P)*b%P

print(ans%P)
N, K = [int(i) for i in input().split()]
H = list(map(int, input().split()))

# 昇順にソート
H.sort()

for i in  range(K):
    H.pop()

print(sum(H))

### FIXED CODE ###

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

# 昇順にソート
H.sort()

if K >= len(H):
    print("0")
else:
    for i in  range(K):
        H.pop()
    print(sum(H))
Last login: Thu Apr 27 19:24:49 on ttys001
[@toshiki-s ~ 20:56:20]
$cd Desktop/
.DS_Store             Mendeley Desktop.app/ OTHER/                
.localized            NAIST/                Readme.webloc         
[@toshiki-s ~ 20:56:20]
$cd Desktop/NAIST/
.DS_Store       advancedCource/ procon/         
[@toshiki-s ~ 20:56:20]
$cd Desktop/NAIST/procon/
[@toshiki-s ~/Desktop/NAIST/procon 20:56:35]
$vim aoj0118.py 


















                dfs(nx, ny, sym)
        else:
            nx = x 
            for dy in [-1,1]:
                ny = y + dy
                if(nx>=0 and nx<N and 0<=ny and ny<M and field[nx][ny]==sym):
                    dfs(nx, ny, sym)
def solve():
    res = 0
    flg=0 
    for i in range(N):
        for j in range(M):
            if not field[i][j] == '.':
                if field[i][j] == '@':
                    dfs(i, j, '@')
                    res += 1
                elif field[i][j] == '#':
                    dfs(i, j, '#')
                    res += 1
                else:
                    dfs(i, j, '*')
                    res += 1
    print(res)
    

while True:
    datas = sys.stdin.readlines()
    data = datas[0].split(' ')
    N = int(data[0])
    M = int(data[1])
    if N==0 or M==0:
        break
    field = [[0 for i in range(N) ]for j in range(M)]

    for i in range(M):
        field[i] = list(datas[i+1])[0:-1]
    solve()

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
import numpy as np

inp = list(map(input().split(), int))
inp = np.sort(inp)
print(inp[0]*10+np.sum(inp[1:])

### FIXED CODE ###

import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)
n, k = map(int, input().split())
a_array = [int(x) for x in input().split()]
INF = 10**9+7

cnt_array = [0 for x in range(n+1)]
a_array2 = []
ans = 0
for a in a_array:
    cnt_array[a] += 1
    a_array2.append(sum(cnt_array[a+1:]))
a_array3 = []
for i in a_array:
    tmp = 0
    for j in a_array[::-1]:
        if j > i:
            tmp += 1
    a_array3.append(tmp)
for cnt, d in zip(a_array2, a_array3):
    ans += (k*(2*cnt+(k-1)*d))//2
    ans = ans % INF
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a_array = [int(x) for x in input().split()]
INF = 10**9+7

cnt_array = [0 for x in range(2000+1)]
a_array2 = []
ans = 0
for a in a_array:
    cnt_array[a] += 1
    a_array2.append(sum(cnt_array[a+1:]))
a_array3 = []
for i in a_array:
    tmp = 0
    for j in a_array[::-1]:
        if j > i:
            tmp += 1
    a_array3.append(tmp)
for cnt, d in zip(a_array2, a_array3):
    ans += (k*(2*cnt+(k-1)*d))//2
    ans = ans % INF
print(ans)