Harryxun/stf_run huggingface dataset:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,x,m=map(int,input().split())
s=set()
l=[]
flag=False
cnt=1
ans=0

l.append(x)
for i in range(m):
  if x not in s:
    s.add(x)
    x=(x**2)%m
    l.append(x)
  else:
    break

h=len(l)
cnt=1
num=0
for i in range(h):
  if l[i]==l[h-1]:
    while l[i+cnt]!=l[h-1]:
      cnt+=1
    flag=True
    break
  else:
    num+=1
    ans+=l[i]

n-=num
if num!=0:
  del l[h-1]
  del l[0:num]

if n>=len(l):
  mod=n%len(l)
  ans+=sum(l)*(n//len(l))
  for i in range(1,mod):
    ans+=l[i-1]
  print(ans)
else:
  for i in range(n):
    ans+=l[i]
  print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
s=str(input())
if s[len(s)-1]=='s':
  print(s+'es')
else:
  print(s+'s')
import sys
sys.setrecursionlimit(100001)

N=int(input())
S=input()


def solve(n,str):
  if n==N:
    if str[-2]==str[0] and str[-1]==str[1]:
      str=str[1:-1]
    else:
      str=""
    return str
  else:
    if (S[n]=="o" and str[-1]=="S") or (S[n]=="x" and str[-1]=="W"):
      str=str+str[-2]
    else:
      if str[-2]=="W":
        str=str+"S"
      else:
        str=str+"W"
    ans=solve(n+1,str)
    return ans

flgT=["SSS","SWW","WWS","WSW"]
flgF=["SSW","WSS","SWS","WWW"]
imp=True
if S[0]=='o':
  for i in range(4):
    ans=solve(1,flgT[i])
    if len(ans)>0:
      print(ans)
      imp=False
      break
else:
  for i in range(4):
    ans=solve(1,flgF[i])
    if len(ans)>0:
      print(ans)
      imp=False
      break
if imp:
  print(-1)

### FIXED CODE ###

import sys

N=int(input())
S=input()

flgT=["SSS","SWW","WWS","WSW"]
flgF=["SSW","WSS","SWS","WWW"]

if S[0]=='o':
  for i in range(4):
    str=flgT[i]
    for j in range(1,N):
      if (S[j]=="o" and str[-1]=="S") or (S[j]=="x" and str[-1]=="W"):
        str=str+str[-2]
      else:
        if str[-2]=="W":
          str=str+"S"
        else:
          str=str+"W"
    if str[-2]==str[0] and str[-1]==str[1]:
      str=str[1:-1]
      print(str)
      sys.exit()
else:
  for i in range(4):
    str=flgF[i]
    for j in range(1,N):
      if (S[j]=="o" and str[-1]=="S") or (S[j]=="x" and str[-1]=="W"):
        str=str+str[-2]
      else:
        if str[-2]=="W":
          str=str+"S"
        else:
          str=str+"W"
    if str[-2]==str[0] and str[-1]==str[1]:
      str=str[1:-1]
      print(str)
      sys.exit()

print(-1)
#n=int(input())
n,m=input_list()
#a=input_list()
if n>9 or m>9:
    print(-1)
    exit()

print(n*m)

### FIXED CODE ###

from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



#n=int(input())
n,m=input_list()
#a=input_list()
if n>9 or m>9:
    print(-1)
    exit()

print(n*m)
n=int(input())
l=list(map(int,input().split()))
lcount=[0]*10**9
count=0
for i in l:
    lcount[i]+=1
    if lcount[i]>i:
        count+=1
for j in l:
    if lcount[j]<j:
        count+=1
print(count)

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
count=0
lcount=[0]*(10**5+1)
for i in l:
    if i>10**5:
        count+=1
    else:
        lcount[i]+=1
        if lcount[i]>i:
            count+=1
for j in l:
    if j<=10**5 and lcount[j]<j:
        count+=1
print(count)
import sys
A, B, N = map(int, input().split())

if N < B :
  print(int(N * A // B) - A * int(N // B))
  sys.exit()
else :
  print(((B-1) * A // B) - A * ((B-1) // B))


### FIXED CODE ###

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

dist = A % K + B - A

if dist >= K :
  print("OK")
elif A % K == 0 or B % K == 0:
  print("OK")
else :
  print("NG")
def f(x,y,z):
    n=x**2 + y**2 + z**2 + x*y + y*z + z*x
    return n

N=int(input())

if N>=8000:
  print(aaa)

anslist=[0]*60100

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            n= f(x,y,z)
            anslist[n-1]+=1

for i in range(N):
    print(anslist[i])


### FIXED CODE ###

def f(a,b,c):
    n=(a+b+c)**2 -a*b -b*c -c*a
    return n

N=int(input())

anslist=[0]*1000005

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            n= f(x,y,z)
            anslist[n-1]+=1

for i in range(N):
    print(anslist[i])
import sys
from collections import deque
N,M,P = map(int, input().split())
ABC = []
Adake = [[] for _ in range(M)]
Bdake = [[] for _ in range(M)]
for _ in range(M):
    A,B,C = map(int, input().split())
    ABC.append((A-1,B-1,C-P))
    Adake[A-1].append(B-1)
    Bdake[B-1].append(A-1)
    
def dfs(x,s):
    used = {s}
    search = deque([s])
    while search:
        ss = search.pop()
        for sss in x[ss]:
            if sss in used:
                continue
            used.add(sss)
            search.append(sss)
    return used

U = dfs(Adake,0) & dfs(Bdake,N-1)
ABC = [(a,b,c) for (a,b,c) in ABC if a in U and b in U]

dist = [-float("inf")]*N
dist[0]=0
    
for i in range(N):
    ju = True
    for a,b,c in ABC:
        if dist[a] + c > dist[b]:
            dist[b] = dist[a] + c
            ju = False
if ju:
    print(max(0,dist[-1]))
    sys.exit()
print(-1)

### FIXED CODE ###

import sys
from collections import deque

    
def dfs(x,s):
    used = {s}
    search = deque([s])
    while search:
        ss = search.pop()
        for sss in x[ss]:
            if sss in used:
                continue
            used.add(sss)
            search.append(sss)
    return used


def bellmanford(edges):
    coins = [-float("inf")] * N
    coins[0] = 0
    for _ in range(N):
        f = True
        for u,v,c in edges:
            if coins[u] + c > coins[v]:
                coins[v] = coins[u] + c
                f = False
        if f:
            return max(0, coins[-1])
    return -1

N,M,P = map(int, input().split())
ABC = []
Adake = [[] for _ in range(N)]
Bdake = [[] for _ in range(N)]
for _ in range(M):
    A,B,C = map(int, input().split())
    ABC.append((A-1,B-1,C-P))
    Adake[A-1].append(B-1)
    Bdake[B-1].append(A-1)

U = dfs(Adake,0) & dfs(Bdake,N-1)
ABC = [(a,b,c) for (a,b,c) in ABC if a in U and b in U]

print(bellmanford(ABC))
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=b[a[0]]
for i in range(1,n):
  if a[i]==a[i-1]+1:
    s+=b[a[i]-1]+c[a[i-1]-1]
  else:
    s+=b[a[i]-1]
print(s)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=b[a[0]-1]
for i in range(1,n):
  if a[i]==a[i-1]+1:
    s+=b[a[i]-1]+c[a[i-1]-1]
  else:
    s+=b[a[i]-1]
print(s)
n= int(input())
a=list(map(int, input().split()))
for i in range(n):
    print(li2[i]+1,end=" ")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=["0"]*n
for i in range(n):
    ans[a[i]-1]=str(i+1)
print(" ".join(ans))
N, M = map(int, input().split())
s = []
c = []
num = [0] * N

def judge():
    for i in range(M):
        s1, c1 = map(int, input().split())
        s.append(s1)
        c.append(c1)

    for i in range(M):
        for j in range(M):
            if s[i] == s[j] and i != j and c[i] != c[j]:
                print(-1)
                return

    if M == 3:        
        for i in range(M):
            if s[i] - 1 < 0 or s[i] - 1 > 2:
                print(-1)
                return
            num[s[i] - 1] = c[i]
    elif M == 2:
        for i in range(M):
            if s[i] < 0 or s[i] > 2:
                print(-1)
                return
            num[s[i] - 1 + 1] = c[i]
    else:
        if s[i] + 1 < 0 or s[i] + 1 > 2:
                print(-1)
                return
        num[s[i] - 1 + 2] = c[i] 



    if num[0] == 0:
        if num[1] == 0:
            if num[2] == 0:
                print(-1)
                return
            print(num[2])
        print("{0}{1}".format(num[1], num[2]))
        return
    else:
        print("{0}{1}{2}".format(num[0], num[1], num[2]))
        return

judge()


### FIXED CODE ###

N, M = map(int, input().split())
sc = []
for i in range(M):
    sp, cp = map(int, input().split())
    sc.append((sp, cp))

ans = 10000

if N == 1:
    for i in range(10):
        num = str(i)
        flag = True
        for pair in sc:
            if (num[pair[0] - 1] != str(pair[1])):
                flag = False
                break
        if flag:
            ans = min(ans, i)
else:
    for i in range(10 ** (N - 1), 10 ** N):
        num = str(i)
        flag = True
        for pair in sc:
            if (num[pair[0] - 1] != str(pair[1])) or len(num) < pair[0]:
                flag = False
                break
        if flag:
            ans = min(ans, i)

if ans == 10000:
    ans = -1
print(ans)
N = int(input())
memo = [0]*N
memo[0] = 2
memo[1] = 1
for n in range(2,N):
    memo[n] = memo[n-1]+memo[n-2]
print(memo[-1])

### FIXED CODE ###

N = int(input())
memo = [0]*(N+1)
memo[0] = 2
memo[1] = 1
for n in range(2,N+1):
    memo[n] = memo[n-1]+memo[n-2]
print(memo[-1])
"""everything has a cost!"""

from math import *
import random
import functools
import collections
import sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')

n, m = 0, 0


@functools.lru_cache(maxsize=None, typed=False)
def read(ti: int, tj: int, i: int, j: int) -> int:
    if (ti < n and (tj == m or a[ti] < b[tj])):
        return 1
    elif (tj < m and (ti == n or b[tj] < a[ti])):
        return 2
    elif (ti < n and tj < m):
        return read(ti+1, tj+1, i, j)
    else:
        if (ti == i):
            return 3
        else:
            return 1


if __name__ == '__main__':
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    mins = 0
    i, j = 0, 0
    while (mins < k):
        v = read(i, j, i, j)
        # print(i, j, v)
        if (v == 1):
            mins += a[i]
            i += 1
        elif (v == 2):
            mins += b[j]
            j += 1
        else:
            break
    if mins > k:
        print(i+j-1)
    else:
        print(i+j)


### FIXED CODE ###

"""everything has a cost!"""

from math import *
import random, functools, collections, sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')


if __name__ == '__main__':
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    for i in range(1,len(a)):
        a[i] += a[i-1]
    for i in range(1,len(b)):
        b[i] += b[i-1]

    j = len(b)-1
    while j > -1 and b[j] > k:
        j -= 1
    ans = j+1
    i = len(a)-1
    while i > -1 and a[i] > k:
        i -= 1
    ans = max(i+1,ans)

    for inx in range(i+1):
        while j > -1 and a[inx] + b[j] > k:
            j -= 1
        ans = max(inx+j+2,ans)
    print(ans)
n = int(input())
d = {}
for _ in range(n):
    s = input()
    if s in d:
        d[s] = +1
    else:
        d[s] = 1
max_d = max(d.values())
ans = sorted([a[0] for i in d.items() if a[1] == max_d])
print(ans)

### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    s=input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
max_d = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_d]))
A,B=map(int,input().split())
S=input()
ass=True
for i in range(len(S)):
  if i==A:
    if S[i]!='-':
      ass=False
      break
  else:
    if S[i]=='-':
      ass=False
      break
if ass:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

n=int(input())
a=24-n
print(24+a)
s=input().split()
i=int(s[0])
j=int(s[1])
k=int(s[2])
if k>=i:
  i=0
  j=j-k+i
else:
  i=i-k
print(str(i)+" "str(j))

### FIXED CODE ###

s=input().split()
i=int(s[0])
j=int(s[1])
k=int(s[2])
if k>=i:
  j=j-(k-i)
  i=0
  if j<0:
    j=0
else:
  i=i-k
print(str(i)+" "+str(j))
a,n =map(str, input().split())
b=str(a[2:])
ans=0

for i in range(int(n)+1):
  for j in range(1):
      c=b[i:]+str(a[j])+b[i+1:]
      ans+=1
print(ans*2)

### FIXED CODE ###

import math
a=int(input())
i=a*360/math.gcd(a,360)
print(int(i/a))
h,w=map(int,input().split())
for i in range(n):
  s=input()
  for j in range(2):
    print(s)

### FIXED CODE ###

h,w=map(int,input().split())
for _ in range(h):
	s=input()
	print(s)
	print(s)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N=int(input())
T=input().split()
X=[]
for i in range(int(input())):
    X.append(input().split()[1])
    
T=list(map(int,T))
X=list(map(int,X))
for y in range(len(X)):
    T_tmp = T
    X_tmp = X
    T_tmp[y] = X_tmp[y]
    print(sum(T_tmp))
    

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

i = input().split()
if i[1] == '+':
    print(int(i[0])+int(i[2]))
if i[1] == '-':
    print(int(i[0])-int(i[2]))
N, M = map(int, input().split())
NM = [[0]*N]*M
count = 0
# print(NM)
if N == 1 and M > 1:
    count = M-2
elif M == 1 and N > 1:
    count = N-2
elif N >= 2 or M >= 2:
    count = (N-2)*(M-2)

print(count)


### FIXED CODE ###

N, M = map(int, input().split())
# print(NM)
if N == 1 and M == 1:
    print(1)
elif N == 1 and M > 1:
    print(M-2)
elif M == 1 and N > 1:
    print(N-2)
elif N >= 2 or M >= 2:
    print((N-2)*(M-2))
n,q = map(int, input().split())
s = input()
lr = list(map(str, [input() for i in range(q)]))

ac = [0]*n


for i in range(1,n):
	if s[i] =='C':
		if s[i-1] == 'A':
			ac[i-1] = 1

for i in range(q):
	answer = sum(ac[int(lr[i][0])-1:int(lr[i][2])])
	if ac[int(lr[i][2])-1] == 1:
		answer -= 1
	print(answer)


### FIXED CODE ###

#累積和　なるほど！

n,q = map(int, input().split())
s = input()
lr = list(map(str, [input() for i in range(q)]))

ac = [0]*n
#012345678
# ACACTACG
# 01122233

for i in range(1,n):
	if s[i-1:i+1] =='AC':
		ac[i] = ac[i-1] + 1
	else:
		ac[i] = ac[i-1]

for i in range(q):
	l,r = map(int, lr[i].split())
	answer = ac[r-1]-ac[l-1] 

	print(answer)
N, T = map(int, input().split())

mc = float("inf")
ans = "TLE"

for i in range(N):
    c, t = map(int, input().split())
    if t <= T and c < mc:
        mc = c
        ans = str(c)

print(ans)

### FIXED CODE ###

N = int(input())

if N == 1: print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
import math

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

gcd = 0

for x in range(N):
    gcd = math.gcd(abs(a[x] - X), gcd)
print(gcd)


### FIXED CODE ###

import fractions

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

gcd = 0

for x in range(N):
    gcd = fractions.gcd(abs(a[x] - X), gcd)
print(gcd)
s = list(input())
N = len(s)
a = [0] * (1+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
sum_ = 0
start = 0
end = 0
for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        #print('a')
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        #print('b')
        count += 1
    elif(s[i] == '<'):
        #print('c')
        end = i
        if(count > count2):
            t = count
            a[max_] = t
            max_ -= 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ -= 1
                t -= 1
            k = 0
            a[end] = 0
            k += 1
            while(k < count2):
                a[end-k] = k
                k += 1
        else:
            t = count2
            a[max_] = t
            max_ += 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ += 1
                t -= 1
            k = 0
            a[start] = 0
            k += 1
            while(k < count):
                a[start+k] = k
                k += 1
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
        #print(a)
    else:
        #print('d')
        count2 += 1
        
if(count > count2):
    if(max_==0):
        max_= N
    t = count
    a[max_] = t
    max_ -= 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ -= 1
        t -= 1
    k = 0
    a[end] = 0
    k += 1
    while(k < count2):
        a[end-k] = k
        k += 1
else:
    t = count2
    a[max_] = t
    max_ += 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ += 1
        t -= 1
    k = 0
    a[start] = 0
    k += 1
    while(k < count):
        a[start+k] = k
        k += 1
sum(a)

### FIXED CODE ###

s = list(input())
N = len(s)
a = [0] * (10+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
A = 0
start = 0
end = 0

for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        #print('a')
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        #print('b')
        count += 1
    elif(s[i] == '<'):
        #print('c')
        end = i
        if(count > count2):
            count2 -=1
            A += count*(count+1)/2
            A += count2*(count2+1)/2
        else:
            count -=1
            A += count*(count+1)/2
            A += count2*(count2+1)/2
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
    else:
        #print('d')
        count2 += 1
if(count > count2):
    count2 -=1
    A += count*(count+1)/2
    A += count2*(count2+1)/2
else:
    count -=1
    A += count*(count+1)/2
    A += count2*(count2+1)/2
print(int(A))
[a,b]=map(int,raw_input().split())
print(a*b,(a+b)*2)

### FIXED CODE ###

[a,b]=map(int,input().split())
print(a*b,(a+b)*2)
import  copy
h = w = 0
mymap =[]
const_mymap = []
qlist = []
ans = 0
def bfs(n):
    while True:
        if len(qlist) != 0:
            temp = qlist.pop(0)
            x = temp[0]
            y = temp[1]
            deep = temp[2]

            #print(temp)
            if mymap[y][x] == str(n):

                return temp
            mymap[y] = mymap[y][:x] + '*' + mymap[y][x + 1:]

            if x + 1 < w:
                if mymap[y][x + 1] not in '*X':
                    qlist.append([x + 1, y, deep + 1])
            if x - 1 >= 0:
                if mymap[y][x - 1] not in '*X':
                    qlist.append([x - 1, y, deep + 1])
            if y + 1 < h:
                if mymap[y + 1][x] not in '*X':
                    qlist.append([x, y + 1, deep + 1])
            if y - 1 >= 0:
                if mymap[y - 1][x] not in '*X':
                    qlist.append([x, y - 1, deep + 1])
        else:
            break
h, w, n = list(map(lambda x: int(x), input().split(" ")))
for i in range(0, h):
    const_mymap.append(input())

mymap = copy.deepcopy(const_mymap)

for i in range(0, h):
    for j in range(0, w):
        if mymap[i][j] == 'S':
            nstart = [j, i, 0]

qlist.append(nstart)

for i in range (n):
    mymap = copy.deepcopy(const_mymap)
    temp = bfs(i+1)
    #print(temp)
    #print(const_mymap)
    ans = temp[2]
    qlist = []
    qlist.append(temp)
    #print(ans)

print(ans)

### FIXED CODE ###

import  copy
h = w = 0
mymap =[]
const_mymap = []
qlist = []
ans = 0
def bfs(n):
    while True:
        if len(qlist) != 0:
            temp = qlist.pop(0)
            x = temp[0]
            y = temp[1]
            deep = temp[2]

            #print(temp)
            if mymap[y][x] == str(n):
                #print('get')
                return temp
            if mymap[y][x] != '*':
                mymap[y] = mymap[y][:x] + '*' + mymap[y][x + 1:]

                if x + 1 < w:
                    if mymap[y][x + 1] not in '*X':
                        qlist.append([x + 1, y, deep + 1])
                if x - 1 >= 0:
                    if mymap[y][x - 1] not in '*X':
                        qlist.append([x - 1, y, deep + 1])
                if y + 1 < h:
                    if mymap[y + 1][x] not in '*X':
                        qlist.append([x, y + 1, deep + 1])
                if y - 1 >= 0:
                    if mymap[y - 1][x] not in '*X':
                        qlist.append([x, y - 1, deep + 1])
        else:
            break
h, w, n = list(map(lambda x: int(x), input().split(" ")))
for i in range(0, h):
    const_mymap.append(input())

mymap = copy.deepcopy(const_mymap)

for i in range(0, h):
    for j in range(0, w):
        if mymap[i][j] == 'S':
            nstart = [j, i, 0]
#print(nstart)

qlist.append(nstart)
#print(qlist)
for i in range (n):
    #print(i)
    mymap = copy.deepcopy(const_mymap)
    xy = bfs(i+1)
    #print(xy)
    #print(const_mymap)
    ans = xy[2]
    qlist = []
    qlist.append(xy)
    #print(ans)

print(ans)
#ABC127C-Prison.py

from sys import stdin

input = stdin.readline

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

L = []
R = []

for i in range(M):
    l, r = input().split()
    L.append(int(l))
    R.append(int(r))

maxL = max(L)
minR = min(R)


if maxL <= N and maxL <= minR:
    if N >= minR:
        print(minR-maxL+1)
    else:
        print(N-maxL+1)
else:
    print(0)


### FIXED CODE ###

#ABC127A-FerrisWheel.py

from sys import stdin

A, B = list(map(int, stdin.readline().split()))

if A >= 13:
    print(B)
elif A >= 6:
    print(B//2)
else:
    print(0)
A, B = map(int, input().split())
S = input()
if S.index("-") == A:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

A, B = map(int, input().split())
S = input()
pos_hyphen = [i for i in range(len(S)) if S[i] == "-"]
if len(pos_hyphen) == 1 and pos_hyphen[0] == A:
    print("Yes")
else:
    print("No")
S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and slice5 ==0:
  print("Heisei")
  else:
    print("TBD")


### FIXED CODE ###

S=str(input())
slice6=S[6]
slice5=S[5]
if int(slice6) < 5 and int(slice5) ==0:
  print("Heisei")
else:
  print("TBD")
a = int(input())
b = int(input())
c = int(input())
d = int(input())
li = [a*b, c*d]
print(max(li))

### FIXED CODE ###

x,y,z,w = map(int, input().split())

if x*y >= z*w:
        print(x*y)
else:
        print(z*w)
n,d=map(int,input().split())

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

lis=[False for i in range(5000)]
for i in range(65):
  lis[i*i]=True
  
ans=0
for i in range(n):
  for j in range(i):
    dis=sum([(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) for k in range(d)])
    print(dis)
    if lis[dis]:
      ans += 1
print(ans)

### FIXED CODE ###

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

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

lis=[False for i in range(16001)]
i=0
while(i*i<16000):
  lis[i*i]=True
  i+=1
  
ans=0
for i in range(n):
  for j in range(i):
    dis=sum([(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) for k in range(d)])
 #   print(dis)
    if lis[dis]:
      ans += 1
print(ans)
a, b = map(float, input().split())
if a < 100000:
    print(int(int(a)*b))
else:
    num = str(int(int(a) * b))
    a = int(a)
    a = str(a)
    a = str(a[-6:])
    a = int(a)
    t = a * b
    t = int(t)
    t = str(t)
    t = "0000000" + t
    print(num[:-3] + t[-4:-1])


### FIXED CODE ###

import numpy as np
import math
A, B, H, M = map(int, input().split())
thetaB = 6 * M
thetaA = 0.5 * (60 * H + M)
Ax = math.sin(math.radians(thetaA)) * A
Ay = math.cos(math.radians(thetaA)) * A
Bx = math.sin(math.radians(thetaB)) * B
By = math.cos(math.radians(thetaB)) * B
AA = np.array([Ax,Ay])
BB = np.array([Bx,By])
print(np.linalg.norm(AA-BB))