Harryxun/stf_run huggingface dataset:
def main():
    from itertools import product
    import os

    INF = 10 ** 9 + 10

    D = int(input())
    *C, = map(int, input().split())
    # C[type]
    # sum(ci*(d-last(d,i) for ci in C)だけ下がる
    S = [[int(x) for x in input().split()] for _ in range(D)]
    # S[day][type]:=happiness

    last = [-1] * 26

    def select(d):
        s = -1
        ret = -1
        for prd in product(range(26), repeat=min(D - d + 1, 2)):
            score = 0
            old = []
            for k, t in enumerate(prd):
                score += S[d + k][t]
                score -= sum(ci * (d + k - last[i]) for i, ci in enumerate(C) if i != t)
                old.append((t, last[t]))
                last[t] = d + k
            old.reverse()
            for t_, d_ in old:
                last[t_] = d_
            if s < score:
                s = score
                ret = prd[0]
        return ret

    T = []
    for d in range(D):
        t = select(d)
        last[t] = d
        T.append(t + 1)
    print(*T, sep='\n')
    # print(os.path.join(os.path.dirname(__file__), 'output_file.txt'))
    # with open(file=os.path.join(os.path.dirname(__file__), 'output_file.txt'), mode='w', encoding='utf-8') as f:
    #     for t in map(str, T):
    #         f.write(t)
    #         f.write('\n')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    INF = 10 ** 9 + 10

    D = int(input())
    *C, = map(int, input().split())
    # C[type]
    # sum(ci*(d-last(d,i) for ci in C)だけ下がる
    S = [[int(x) for x in input().split()] for _ in range(D)]
    # S[day][type]:=happiness

    last = [-1] * 26

    def diff(d, t):
        ret = S[d][t]
        ret -= sum(ci * (d - last[i]) for i, ci in enumerate(C) if i != t)
        return ret

    T = []
    score = 0
    for d in range(D):
        delta = -INF
        take_t = -1
        for t_ in range(26):
            buf = diff(d, t_)
            if delta < buf:
                delta = buf
                take_t = t_

        last[take_t] = d
        score += buf
        T.append(take_t + 1)
    print(*T, sep='\n')
    # print(score)


if __name__ == '__main__':
    main()
x=[input() for _ in range(3)]
for i in range(3):
    print(x[i][i],seq="")

### FIXED CODE ###

x=[input() for _ in range(3)]
for i in range(3):
    print(x[i][i],end="")
n, a, b = map(int, input().split())

n_div_ab = n // (a+b)
n_mod_ab = n % (a+b)
if n_mod_ab // a > 0:
    res = n_mod_ab // a * a
else:
    res = n_mod_ab
print(n_div_ab * a + res)

### FIXED CODE ###

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

n_div_ab = n // (a+b)
n_mod_ab = n % (a+b)
if a == 0:
    res = 0
elif n_mod_ab // a > 0:
    res = a
else:
    res = n_mod_ab

print(n_div_ab * a + res)
N,K=map(int,input().split())
A=list(map(int,input().split()))

A=list(set(A))
N=len(A)
A.sort()
tmp=0
for i in range(N-1):
    tmp+=A[i+1]%A[0]
if tmp>0 and K<=A[-1]:
    pass
else:
    ans="IMPOSSIBLE"
if N==1:
    ans="POSSIBLE"
print(ans)

### FIXED CODE ###

import fractions

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

A=list(set(A))
N=len(A)
A.sort()

g=A[0]
for i in range(N-1):
    g=fractions.gcd(g,A[i+1])

if K%g==0 and K<=A[-1]:
    ans="POSSIBLE"
else:
    ans="IMPOSSIBLE"
print(ans)
n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
  if cnt >= len(al) / 2
  break
print(cnt)

### FIXED CODE ###

from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)
#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

print(cnt)
n= int(input())
hl = list(map(int,input().split(' ')))


hmax = 0
def hantei(n,x):
    global hmax
    if n == 1:
        print('Yes')
        exit()
        
    if x == n - 1:
        print('Yes')
        exit()
    if (hl[x] >= (hmax - 1)):
        hmax = max(hmax,hl[x])
        return hantei(n,x+1)
    else:
        return print('No')
    

hantei(n,0)

### FIXED CODE ###


n= int(input())
hl = list(map(int,input().split(' ')))


hmax = 0
if n == 1:
    print('Yes')
    exit()

for i in range(n):
    if (hl[i] >= (hmax - 1)):
        hmax = max(hmax,hl[i])
        if i == n - 1:
        	print('Yes')
        	break
    else:
        print('No')
        break
import sys

sys.setrecursionlimit(10 ** 9)
N = input()
N_len = len(N)
'''
75333
'''


# t = []


def dfs(a, depth):
    if depth == N_len:
        if int(a) <= int(N) and a.count('3') > 0 \
                and a.count('5') > 0 and a.count('7') > 0 and str(int(a)).count('0') == 0:
            t.append(a)
            return 1
        else:
            return 0

    ret1 = dfs(a + '0', depth + 1)
    ret2 = dfs(a + '3', depth + 1)
    ret3 = dfs(a + '5', depth + 1)
    ret4 = dfs(a + '7', depth + 1)
    return ret1 + ret2 + ret3 + ret4


ans = dfs('', 0)
print(ans)
# print(t)


### FIXED CODE ###

S = input()

'''
357 375 537 573 735 753 
3357 3375 3537 3573 3735 3753 
5357 5375 5537 5573 5735 5753 
3357,3375,3537,

3けた　、4けた 5 ,6, 7, 8
6,18,54,162,486, 8
sum = [2 * 3,2 * 3 * 3,]
'''

N = len(S)
list375 =['3','5','7']
if N <  3:
    print(0)
    exit(0)

for i in range(N + 1):
    if i ==0:
        continue
    else:
        targetList = list375[:]
        for l in targetList:
            #print(l)
            list375.append(l + '3')
            list375.append(l + '5')
            list375.append(l + '7')

result = [i for i in list(set(list375)) if int(i) <= int(S) and (i.count('3') >0 and i.count('5') >0 and i.count('7') >0)]
#print(result)
print(len(result))


'''
def judge753():
    if keta[0] < 3:
        return 0
    if keta[0] < 5:
        if keta[1] < 3:
            return 0
        if keta[1] < 5:
            if keta[2] < 5:
                return 0
            if keta[2] < 7:
                return 1
            return 2
        if keta[1] < 7:
            
        return sum[len(S)-1]
    if keta[0] < 7:
        if keta[1] < 3:
            return sum[len(S)-1] + sum[len(S)-2]
        if keta[1] < 5:
            if keta[2] < 5:
        
        return sum[len(S)-1]
        
print(min(absList))
'''
scnum = int(input())
score = []
answer = 0
for i in range(scnum):
    word = input()
    if word in score:
        answer += 0
    else:
        score.append(word)
        answer += 1

print(answer)

### FIXED CODE ###

score = list(map(int,input().split()))
if score[0] <= score[1]:
    print('unsafe')
else:
    print('safe')
n = int(raw_input())
a = map(int, raw_input().split())
number = 0

for i in xrange(n):
  while a[n] % 2 == 0:
    number += 1
    a[n] /= 2
    
print number

### FIXED CODE ###

n = int(raw_input())
a = map(int, raw_input().split())
number = 0

for i in xrange(n):
  while a[i] % 2 == 0:
    number += 1
    a[i] /= 2
    
print number
n=raw_input()
print [ABC+n]

### FIXED CODE ###

n=raw_input()
print "ABC"+n
m=0
a=0 
r=0
c=0
h=0
for j in range(n):
  if s[j][0]=="M":
    m+=1
  elif s[j][0]=="A":
    a+=1
  elif s[j][0]=="R":
    r+=1
  elif s[j][0]=="C":
    c+=1
  elif s[j][0]=="H":
    h+=1
    
ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+a*r*h+r*c*h

print(ans)

### FIXED CODE ###

n=int(input())
s=[]
for i in range(n):
  s.append(input())
m=0
a=0 
r=0
c=0
h=0
for j in range(n):
  if s[j][0]=="M":
    m+=1
  elif s[j][0]=="A":
    a+=1
  elif s[j][0]=="R":
    r+=1
  elif s[j][0]=="C":
    c+=1
  elif s[j][0]=="H":
    h+=1
    
ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*c*h+a*r*h+r*c*h

print(ans)
H,W=map(int,input().split())
S=[input() for _ in range(H)]

arr=[]
for h in range(0,H):
    for w in range(0,W):
        if S[w][h]=='#':
            cnt=0
            if w!=0:
                cnt+=S[w-1][h]=='#'
            if w!=W-1:
                cnt+=S[w+1][h]=='#'
            if h!=0:
                cnt+=S[w][h-1]=='#'
            if h!=H-1:
                cnt+=S[w][h+1]=='#'
            arr.append(cnt>0)
print(all(arr))

### FIXED CODE ###

H,W=map(int,input().split())
S=[input() for _ in range(H)]

arr=[]
for h in range(0,H):
    for w in range(0,W):
        if S[h][w]=='#':
            cnt=0
            if w!=0:
                cnt+=S[h][w-1]=='#'
            if w!=W-1:
                cnt+=S[h][w+1]=='#'
            if h!=0:
                cnt+=S[h-1][w]=='#'
            if h!=H-1:
                cnt+=S[h+1][w]=='#'
            arr.append(cnt>0)
print('Yes' if all(arr) else 'No')
n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
    if i < k:
        L[i] = s
    else:
        if s != 10 ** 9
            L[i] = s + 1
        else:
            L[i] = s - 1
print(*L)


### FIXED CODE ###

n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
    if i < k:
        L[i] = s
    else:
        if s != 10 ** 9:
            L[i] = s + 1
        else:
            L[i] = s - 1
print(*L)
S=str(input())
T=str(input())
t=1000

for i in range(1000):
  try:
    k=S[i]
  except IndexError:
    Slen=i
    break
for j in range(1000):
  try:
    k=T[j]
  except IndexError:
    Tlen=j
    break
lists=[]
for i in range(Slen-Tlen+1):
  s=0
  for j in range(Tlen):
    if S[i+j]==T[j]:
      s+=1
    else:
      continue
  t=min(t,Tlen-s)
print (t)

### FIXED CODE ###

S=str(input())
T=str(input())
t=1000
Slen=1000
Tlen=1000
for i in range(1000):
  try:
    k=S[i]
  except IndexError:
    Slen=i
    break
for j in range(1000):
  try:
    k=T[j]
  except IndexError:
    Tlen=j
    break

for i in range(Slen-Tlen+1):
  s=0
  for j in range(Tlen):
    if S[i+j]==T[j]:
      s+=1
    else:
      continue
  t=min(t,Tlen-s)
print (t)
n, l = map (int, input().split())
s = sorted(input() for i in ratnge(n))
print(*s, sep='')

### FIXED CODE ###

n, l = map (int, input().split())
s = sorted([input() for i in range(n)])
print(*s, sep='')
# encoding: "utf-8"

from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[0]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

### FIXED CODE ###

# encoding: "utf-8"

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    x, t = Stdin.read_line(converter=int)
    r = x - t
    if r < 0:
        r = 0
    print(r)

if __name__ == "__main__":
    main()
# to enable variable use in global
global tree, point

# v : current node, f : parent node 
def dfs(v, f):
    for next_v in tree[v]:
        if next_v == f:
            continue
    
        point[next_v] += point[v]
        dfs(next_v, v)

n, q = list(map(int,input().split()))
# initialize global variables
tree = [[]*n for i in range(n)]
point = [0] * n

for _ in range(n-1):
    a, b = list(map(int, input().split()))

    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for _ in range(q):
    p, x = list(map(int, input().split()))

    point[p-1] += x

dfs(0, 0)
print(*point)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

# to enable variable use in global
global tree, point

# v : current node, f : parent node 
def dfs(v, f):
    global tree, point
    for next_v in tree[v]:
        if next_v == f:
            continue
    
        point[next_v] += point[v]
        dfs(next_v, v)

n , q = map(int, input().split())
tree = [[] for _ in range(n)]
point = [0] * n
for _ in range(n - 1):
    a , b = map(int,input().split())
    tree[b - 1].append(a - 1)
    tree[a - 1].append(b - 1)

for _ in range(q):
    p , x = map(int, input().split())
    point[p - 1] += x

dfs(0, 0)
print(*point)
N, M = map(int, input().split())
a_n = list(map(int, input().split()))
a_n = [int(a_n[i]*1/2) for i in range(len(a_n))]
 
def lcm(lis):
    from fractions import gcd
    x = lis[0]
    for i in range(1, len(lis)):
        x = (x * lis[i]) // gcd(x, lis[i])
    return x
res = lcm(a_n)
count = 0
for i in range(len(M)):
    count += 1
    if res*(2*i + 1) > M:
      break
print(count)

### FIXED CODE ###

N,M = map(int, input().split())
a_n = list(map(int, input().split()))
g = a_n.copy()
 
while not any(x%2 for x in g): g = [x//2 for x in g]
if not all(x%2 for x in g): print(0); exit(0)
def gcd(a,b):
  while b: a,b = b,a%b
  return a
lcm = lambda a,b: a*b//gcd(a,b)
tot = 1
for x in a_n: tot = lcm(tot,x//2)
print((M//tot+1)//2)
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
  str = raw_input().split()
  u = int(str[0])
  k = int(str[1])
  for j in range(k):
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]

d[0] = 0
color[0] = 1

while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
    print minv
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
ATCG

enki = input()
if enki == "A":
  return "T"
elif enki == "T":
  return "A"
elif enki == "C":
  return "G"
elif enki == "G":
  return "C"

### FIXED CODE ###

enki = input()
if enki == "A":
  print("T")
elif enki == "T":
  print("A")
elif enki == "C":
  print("G")
elif enki == "G":
  print("C")
S == input()
if S == "ABC":
	print("ARC")
else:
  	print("ABC")

### FIXED CODE ###

S = input()
if S == "ABC":
	print("ARC")
else:
  	print("ABC")
n=int(input())
p = list(map(int, input().split()))
ans=0
x=0
for i in range(n+1):
	if p[x] < p[x+1]:
		ans+=1
		x+=1
print(ans)

### FIXED CODE ###

n=int(input())
p = list(map(int, input().split()))
ans=0

for i in range(1,n-1):
  if p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]:
    ans+=1
print(ans)
li=list(input())
n=len(li)
x=1
y=int((n-1)/2-x+1)
X='a'
Y='a'
while X==Y:
    X=li[x]
    Y=li[y]
    x+=1
    if x == (n+1)/4:
        print('Yes')
        break
    else:
        continue
if x != (n+1)/4: 
    print('No')

### FIXED CODE ###

li=list(input())
li_rev=list(reversed(li))
n=len(li)
li_slice=li[0:int((n-1)/2)]
li_slrev=list(reversed(li_slice))
n=len(li)
if li==li_rev:
    if li_slice==li_slrev:
        print('Yes')
    else:
        print('No')
else:
    print('No')
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

F = s.split("T")

x_list = []
y_list = []
for i, n in enumerate(F):
	if i%2 == 0:  # x軸方向
		x_list.append(len(n))
	else:
		y_list.append(len(n))

"""
x_listから順に取り出して右か左に動く．
dp[i][x] := i回目の移動後にx座標がxとなっていることができるか
y軸も同様
"""

x -= x_list.pop(0)  # 最初のFの分だけ右に動く
x_sum = sum(x_list)
y_sum = sum(y_list)


if (x_sum-x)%2 != 0:  # パリティ
  print("No")
  sys.exit()
else:
  n_x = (x_sum-abs(x))//2
if (y_sum-y)%2 != 0:
  print("No")
  sys.exit()
else:
  n_y = (y_sum-abs(y))//2

dp_x = [[False]*(abs(n_x)+1) for _ in range(len(x_list)+1)]
dp_y = [[False]*(abs(n_y)+1) for _ in range(len(x_list)+1)]
dp_x[0][0] = True
dp_y[0][0] = True

for i in range(1, len(x_list)+1):
	for j in range(n_x+1):
		if dp_x[i-1][j]:
			dp_x[i][j] = True
			if j+x_list[i-1] < n_x+1:
				dp_x[i][j+x_list[i-1]] = True

for i in range(1, len(y_list)+1):
	for j in range(n_y+1):
		if dp_y[i-1][j]:
			dp_y[i][j] = True
			if j+y_list[i-1] < n_y+1:
				dp_y[i][j+y_list[i-1]] = True

if dp_x[-1][-1] and dp_y[-1][-1]:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

x_list = []
y_list = []
for i, s_ in enumerate(s.split('T')):
	if i == 0:
		x -= len(s_)
	elif i % 2 == 0:
		x_list.append(len(s_))
	else:
		y_list.append(len(s_))

def check(d, x):
  se =set([0])
  for dx in d:
    se={a+b for a,b in product(se,[-dx,dx])}  # 直積としてDPを計算
  return (x in se)

print('Yes' if check(x_list, x) and check(y_list, y) else 'No')
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])

number = B - A + 1

answer_C = number // C

answer_D = number // D

answer_E = number // lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
final_answer = int(final_answer)
print(final_answer)


### FIXED CODE ###

import fractions

A,B,C,D = map(int, input().split())
lcm_number = C*D // fractions.gcd(C, D)
all_number = B -A + 1

answer_C = B // C - (A-1) // C
answer_D = B // D - (A-1) // D
answer_lcm = B // lcm_number - (A-1) // lcm_number

print(all_number - answer_C - answer_D + answer_lcm)
from numba.types import i8
ni8 = np.int64

@njit((i8, i8[:,::-1]), cache=True)
def solve(n, qr):
    col = np.full(n - 1, n - 2)
    col[0] = 0
    col_min = n - 1
    prev_col_min = n - 1
    row = np.full(n - 1, n - 2)
    row[0] = 0
    row_min = n - 1
    prev_row_min = n - 1
    white = 0
    for i in range(qr.shape[0]):
        j = qr[i, 1] - 1
        if qr[i, 0] == 1:
            if row_min < prev_row_min:
                for m in range(1, col_min):
                    col[m] = min(col[m], j - 1)
                prev_row_min = row_min
            u = col[j]
            white += u
            col[j] = 0
            if j < col_min:
                col_min = j
        else:
            if col_min < prev_col_min:
                for m in range(1, row_min):
                    row[m] = min(row[m], j - 1)
                prev_col_min = col_min
            u = row[j]
            white += u
            row[j] = 0
            if j < row_min:
                row_min = j
    return white

def main():
    f = open(0)
    n, q = [int(x) for x in f.readline().split()]
    qr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2))
    white = solve(n, qr)
    print((n - 2) ** 2 - white)

main()

### FIXED CODE ###

import numpy as np
from numba import njit
from numba.types import int64
i8 = np.int64


@njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
    col = np.zeros(n - 1, i8)
    col[0] = 0
    col_min = n - 1
    row = np.zeros(n - 1, i8)
    row[0] = 0
    row_min = n - 1
    white = 0
    for i in range(qr.shape[0]):
        j = qr[i, 1] - 1
        if qr[i, 0] == 1:
            if j < col_min:
                white += row_min - 1
                for m in range(j + 1, col_min):
                    col[m] = row_min - 1
                col_min = j
            else:
                white += col[j]
        else:
            if j < row_min:
                white += col_min - 1
                for m in range(j + 1, row_min):
                    row[m] = col_min - 1
                row_min = j
            else:
                white += row[j]
    return white


def main():
    f = open(0)
    n, q = [int(x) for x in f.readline().split()]
    qr = np.fromstring(f.read(), i8, sep=' ').reshape((-1, 2))
    white = solve(n, qr)
    print((n - 2) ** 2 - white)

main()
k = int(input())
s  = input()

if  len(s)<=k:
 print(s)
else:
print(s[:k]+'...')


### FIXED CODE ###

k = int(input())
s  = input()
if  len(s)<=k:
 print(s)
else:
 print(s[:k]+'...')
import numpy
n = numpy.int64(n)
m = numpy.int64(m)
n = n % m
print(min(n, m-n))


### FIXED CODE ###

import numpy

n, m = input().split()
n = numpy.int64(n)
m = numpy.int64(m)
n = n % m
print(min(n, m-n))
n,k=map(int,input().split())
p=float(0)
for i in range(1,n+1):
  divide=float(k/i)
  howmany=math.ceil(math.log(divide,2))
  p+=1/(n*(2**howmany))
print(p)


### FIXED CODE ###

n,k=map(int,input().split())
p=float(0.0)
for i in range(1,n+1):
  howmany=0
  while i<k:
    i*=2
    howmany+=1
  p+=1/(n*(2**howmany))
print(p)