Harryxun/stf_run huggingface dataset:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,q=map(int,input().split())
C=[int(i) for i in input().split()]
LR=[]
for i in range(q):
    l,r=map(int,input().split())
    LR.append((i,l,r))
LR.sort(key=lambda x:x[2])


LST=[0]*n
Ans=[0]*q

n_max=5*10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)

def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT
cur=0
for i,l,r in LR:
    while cur<r:
        if LST[C[cur]]!=0:
            bitadd(BIT,LST[C[cur]],-1)
        LST[C[cur]]=cur+1
        bitadd(BIT,LST[C[cur]],1)
        cur+=1
    Ans[i]=bitsum(BIT,r+1)-bitsum(BIT,l-1)
for ans in Ans:
    print(ans)

### FIXED CODE ###

import sys
input=lambda: sys.stdin.readline().rstrip()
n,q=map(int,input().split())
C=[int(i) for i in input().split()]
LR=[]
for i in range(q):
    l,r=map(int,input().split())
    LR.append((i,l,r))
LR.sort(key=lambda x:x[2])


LST=[0]*(n+1)
Ans=[0]*q

n_max=5*10**5+1
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)

def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT
cur=0
for i,l,r in LR:
    while cur<r:
        if LST[C[cur]]!=0:
            bitadd(BIT,LST[C[cur]],-1)
        LST[C[cur]]=cur+1
        bitadd(BIT,LST[C[cur]],1)
        cur+=1
    if l==1:
        Ans[i]=bitsum(BIT,r+1)
    else:
        Ans[i]=bitsum(BIT,r+1)-bitsum(BIT,l-1)
for ans in Ans:
    print(ans)
N = int(input())
x = list(map(int, input().split()))
l = []
minx = min(x)
maxx = max(x)
for p in range(minx, maxx):
  s = 0
  for j in range(N):
    s += (x[j]-p)**2
  l.append(s)
minp = min(l)
p = l.index(minp)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))

### FIXED CODE ###

N = int(input())
x = list(map(int, input().split()))
p = int(sum(x)/N)
hp1 = 0
hp2 = 0
for i in range(N):
  hp1 += (x[i]-p)**2
  hp2 += (x[i]-p-1)**2
print(min(hp1, hp2))
from itertools import permutations
import numpy as np
N=int(input())
l=[i+1 for i in range(N)]
P=np.array(list(map(int, input().split())))
Q=np.array(list(map(int, input().split())))
counter=0
for t in permutations(l):
  tmp=np.array(t)
  if sum(P==tmp)==N:
    a=counter
    
  if sum(Q==tmp)==N:
    b=counter
    
  counter+=1
  
print(abs(a-b))

### FIXED CODE ###

from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))
N, M = map(int, input().split())

A =[]

for i in range(M):
  A.append(int(input().split()))

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

### FIXED CODE ###

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

A =[]

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

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)
n,m = map(int,input().split())

while n > 0:
    a = a + n

while m > 0:
    a = a + m

print(a)

### FIXED CODE ###

n,m = map(int,input().split())
a = 0
n = n - 1
m = m - 1

while n > 0:
    a = a + n
    n = n - 1

while m > 0:
    a = a + m
    m = m - 1

print(a)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range)m:
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if a[i] > k:
        break;
    while b[m] > k-a[i]:
        m -= 1
    e = max(e, i+m)
print(e)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range(m):
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if c[i] > k:
        break;
    while c[i]+d[m] > k:
        m -= 1
    e = max(e, i+m)
print(e)
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        id = S_.rfind(T[i])
        if id < 0:
            continue
        flag = True
        for j in range(i+1, len(T)):
            if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                continue
            else:
                flag = False
                break
            for j in reversed(range(i)):
                if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                    continue
                else:
                    flag = False
                    break
        if flag:
            ans[id - i:id - i + len(T)] = T
            for i in range(len(ans)):
                if ans[i] == "?":
                    ans[i] = "a"
            print("".join(ans))
            exit(0)


print("UNRESTORABLE")


### FIXED CODE ###

S_ = input()
T = input()
ans = list(S_)


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        print("".join(ans))

        exit(0)

print("UNRESTORABLE")
n = int(input())

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

for i in range(101):
    for j in range(101):
        res = [abs(i-ab[0][0])+abs(j-ab[0][1])+ab[0][2]]
        f = False
        for k in range(1,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            res.append(abs(i-dx)+abs(j-dy)+dh)
        if len(set(res)) == 1:
            ansx =i
            ansy =j
            ansr = res[0]
            break
        
print(str(ansx)+" "+str(ansy)+" "+str(ansr))

### FIXED CODE ###

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

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))
, b = map(int, input().split())
tap = a - 1
count = 0
while True:
  if a == b:
    count = 1
    break
  elif a + tap * count < b:
    count += 1
  else:
    count += 1
    break
print(count)

### FIXED CODE ###

a, b = map(int, input().split())
tap = a - 1
count = 1
while True:
  if b == 1:
    count = 0
    break
  elif a == b:
    break
  elif a + tap * (count - 1) < b:
    count += 1
  else:
    break
print(count)
n,k = map(int,input().split())
s = input()
s[k-1] = s[k-1].lower()
print(s)

### FIXED CODE ###

n,k = map(int,input().split())
s = input()
print(s[:k -1] + s[k -1].lower() + s[k:])
import numpy as np
a,b = input().split()
np.trunc((a+b)2)

### FIXED CODE ###

import numpy as np
a,b = input().split()
print(int(np.ceil((int(a)+int(b))/2)))
# -*- coding: utf-8 -*-
# get a integer
a = int(raw_input())

list = a.split()

left = int(list[0])+int(list[1])
right = int(list[2])+int(list[3])

if left < right:
  print("Right")
elif left > right:
  print("Left")
else:
  print("Balanced")

### FIXED CODE ###

# -*- coding: utf-8 -*-
# get a integer
a = raw_input()

list = a.split()

left = int(list[0])+int(list[1])
right = int(list[2])+int(list[3])

if left < right:
  print("Right")
elif left > right:
  print("Left")
else:
  print("Balanced")
input_list = input().split(" ")
syoumi = int(input_list[0])
mae = int(input_list[1])
eat = int(input_list[2])
if eat < mae:
  print("delicious")
else if (eat - mae) < syoumi:
  print("safe")
else:
  print("dangerous")

### FIXED CODE ###

input_list = input().split(" ")
syoumi = int(input_list[0])
mae = int(input_list[1])
eat = int(input_list[2])
if eat <= mae:
  print("delicious")
elif (eat - mae) <= syoumi:
  print("safe")
else:
  print("dangerous")
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(int(input()))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)


### FIXED CODE ###

w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)
arrayNM = list(map(int, input().split()))
array = list(map(int, input().split()))
route = [array[0] + arrayNM[0] - array[arrayNM[1] - 1]]
for i in range(1,arrayNM[1]):
  route.append(array[i] - array[i-1])
  
Max = max(route)
maxIndex = route.index(Max)
distance = 0

for i in range(0,maxIndex):
  distance += route[i]

for i in range(maxIndex + 1, array[1]):
  distance += route[i]

print(distance)



### FIXED CODE ###

arrayNM = list(map(int, input().split()))
array = list(map(int, input().split()))
route = [array[0] + arrayNM[0] - array[arrayNM[1] - 1]]
for i in range(1,arrayNM[1]):
  route.append(array[i] - array[i-1])
  
Max = max(route)
maxIndex = route.index(Max)
distance = 0

for i in range(0,maxIndex):
  distance += route[i]

for i in range(maxIndex + 1, arrayNM[1]):
  distance += route[i]

print(distance)
from collections import Counter
from operator import mul
n = int(input())
s = input()
c = Counter(s)
ans = 0
for i in range(n):
    ans += mul(*[v for k, v in c.items()if k != s[i]])
    c[s[i]] -= 1
    for j in range(i+1, n):
        x = s[i]
        y = s[j]
        if x == y:
            continue
        idx_diff = j-i
        if n <= j+idx_diff:
            continue
        z = s[j+idx_diff]
        if x != z and y != z:
            ans -= 1
print(ans)


### FIXED CODE ###

from collections import Counter
from operator import mul
n = int(input())
s = input()
c = Counter(s)
if n < 3:
    print(0)
    exit()
elif len(c.keys()) < 3:
    print(0)
    exit()
ans = 0
for i in range(n):
    x = s[i]
    ans += mul(*[v for k, v in c.items()if k != x])
    c[x] -= 1
    for j in range(i+1, n):
        y = s[j]
        if x == y:
            continue
        idx_diff = j-i
        if n <= j+idx_diff:
            continue
        z = s[j+idx_diff]
        if x != z and y != z:
            ans -= 1
print(ans)
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

num=[-1]*n

for i in l:
  if num[i[0]-1]==-1 or num[i[0]-1]==i[1]:
    num[i[0]-1]=i[1]
  elif i[0]==1 and i[1]==0 and n==1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
    
if num[0]==0:
  print(-1)
elif n=1 and num[0]==-1:
  print(0)
else:
  for i in range(len(num)):
    if num[i]==-1 and i==0:
      num[i]=1
    elif num[i]==-1:
      num[i]=0
    
  print(*num,sep='')

### FIXED CODE ###

N,M = map(int,input().split())
a = [-1]*N
ans = 0
for i in range(M):
    s,c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] != c:
        ans = -1
        break
if a[0] == 0 and N>1:
    ans = -1
if ans != -1:
    if a[0] == -1 and N>1:
        a[0] = 1
    if a[0] == -1 and N == 1:
        a[0] = 0
    for i in range(N):
        if a[i] == -1:
            a[i] = 0
        a[i] = str(a[i])
    ans = "".join(a)
print(ans)
n=int(input())
l=list(map(int,input().split()))
b=[]
emp=[0]*n
ans=0
for i in range(n)[::-1]:
  c=n//(i+1)
  s=0
  while (c+1)*(i+1)<=n:
    s+=emp[(c+1)*(i+1)-1]
    c+=1
    s%=2
  if l[i]!=s:
    b.append(str(i+1))
    ans+=1
    emp[i]=1
print(ans)
print(" ".join(b))


### FIXED CODE ###

a=int(input())
print(3*a*a)
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B = [int(i) for i in input().split(" ")]

print(lcm(A, B))

### FIXED CODE ###


def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if 0==x%y:
        return y
    else:
        while not 0==x%y:
            z = x%y
            x = y
            y = z
        return z

def lcm(x, y):
    return (x*y)//gcd(x,y)

A, B = [int(i) for i in input().split(" ")]

print(lcm(A, B))
N=int(input())
c=0
rN=int(N**0.5)+1

for i in range(rN):
    xi = rN - i
    for j in range(N-xi) :
        yj= xi+j
        if ((xi)*(yj))==N:
            x=xi
            y=yj
            c=1
            break
    if c==1:break


d=x+y-2

print(d)

### FIXED CODE ###

N=int(input())
c=0
d=10000000000000
rN=int(N**0.5)

for i in range(rN):
    if (N%(i+1)==0) :
        x=i+1
        y=int(N/(i+1))
        if d>(x+y):
            d=x+y

print(d-2)
if A == B:
    print("Draw")
elif A == 1:
    print("Alice")
elif B == 1:
    print("Bob")
elif A > B:
    print("Alice")
else:
    print("Bob")

### FIXED CODE ###

(A,B) = [int(x) for x in input().split()]
if A == B:
    print("Draw")
elif A == 1:
    print("Alice")
elif B == 1:
    print("Bob")
elif A > B:
    print("Alice")
else:
    print("Bob")
number = int(input())
num_list = list(map(int, input().split()))

count = 0
for i in num_list:
  if i % 2 == 0:
    count += 1
    # print(count)
  else:
    print(0)
    break

count_s = 0
if count == number:
  num_min = min(num_list)
  while num_min % 2 == 0:
    num_min = num_min / 2
    count_s += 1
  print(count_s)


### FIXED CODE ###

text = input()
ans = text.count('1')
print(ans)
import sys


sys.setrecursionlimit(100000)

to = [[] for _ in range(200005)]
ans: list


def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    return


def main():
    N, Q = map(int, input().split())
    for _ in range(N-1):
        a, b = map(int, input().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1)
    global ans
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    dfs(0)
    print(*ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


sys.setrecursionlimit(300000)

to = [[] for _ in range(200005)]
ans: list


def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    return


def main():
    N, Q = map(int, input().split())
    for _ in range(N-1):
        a, b = map(int, input().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1)
    global ans
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    dfs(0)
    print(*ans)


if __name__ == "__main__":
    main()
a, b = map(int, input().split())
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")
import math
import scipy.optimize

a, b, x = [int(i) for i in input().split()]

def func_a(theta):
    S = 0.5 * b**2 / math.tan(theta)
    V = S * a
    equal = V - x

    return equal

def func_b(theta):
    S = a * b - 0.5 * a**2 * math.tan(theta)
    V = S * a
    equal = V - x

    return equal

if x <= 0.5 * a**2 * b:
    result = scipy.optimize.bisect(func_a, 0 + 10**(-6), math.pi/2 - 10**(-6))
else:
    result = scipy.optimize.bisect(func_b, 0 + 10**(-6), math.pi/2 - 10**(-6))

print(math.degrees(result))


### FIXED CODE ###

import math
a, b, x = [int(i) for i in input().split()]

V_max = a * a * b

if x <= 0.5 * V_max:
    theta = math.atan((a*b*b)/(2*x))
else:
    theta = math.atan(2*(a**2*b - x)/(a**3))

print(math.degrees(theta))
def play():
    result_dic = {}    
    for i in range(tate):
        depart = i+1
        arrival = drawing_lots[depart][0]
        arrival = aaa(depart, arrival)
        result_dic[arrival] = depart
    
    for k in sorted(result_dic):
        print(result_dic[k])

def aaa(depart, arrival):
    offset = 0
    for point in drawing_lots[arrival]:
        if point == depart:
            break
        offset += 1
    
    if offset+1 <= len(drawing_lots[arrival])-1:
        depart = arrival
        arrival = drawing_lots[arrival][offset+1]
        return aaa(depart, arrival)
    else:
        return arrival
        
tate = int(raw_input())
yoko = int(raw_input())

drawing_lots = {}
for num in range(tate):
    drawing_lots[num+1] = []
    
for i in range(yoko):
    horizontal_line = raw_input().split(',')
    left_num = int(horizontal_line[0])
    right_num = int(horizontal_line[1])
    drawing_lots[left_num].append(right_num)
    drawing_lots[right_num].append(left_num)

play()

### FIXED CODE ###

ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a
from collections import defaultdict
import sys
sys.setrecursionlimit(200000)

def dfs(source, used, all_weight, connect):
    max_weight = all_weight
    max_source = source
    used[source] = 1
    for target, weight in connect[source]:
        if not used[target]:
            now_weight = all_weight + weight
            this_source, this_weight = dfs(target, used, now_weight, connect)
            if max_weight < this_weight:
                max_weight = this_weight
                max_source = this_source
    return [max_source, max_weight]

vertice = int(input())
connect = defaultdict(list)
for _ in range(vertice - 1):
    v1, v2, weight = (int(n) for n in input().split(" "))
    connect[v1].append([v2, weight])
    connect[v2].append([v1, weight])
answer = 0
start_v = 0
for i in range(2):
    used = [0 for n in range(vertice)]
    start_v, answer = dfs(start_v, used, 0, connect)
print(answer)

### FIXED CODE ###

from collections import defaultdict

v_num, e_num, flow = (int(n) for n in input().split(" "))
edges = defaultdict(list)
for _ in range(e_num):
    s1, t1, cap, cost = (int(n) for n in input().split(" "))
    edges[s1].append([t1, cap, cost, len(edges[t1])])
    edges[t1].append([s1, 0, -cost, len(edges[s1]) - 1])
answer = 0
before_vertice = [float("inf") for n in range(v_num)]
before_edge = [float("inf") for n in range(v_num)]
sink = v_num - 1
while True:
    distance = [float("inf") for n in range(v_num)]
    distance[0] = 0
    updated = 1
    while updated:
        updated = 0
        for v in range(v_num):
            if distance[v] == float("inf"):
                continue
            for i, (target, cap, cost, trace_i) in enumerate(edges[v]):
                if cap > 0 and distance[target] > distance[v] + cost:
                    distance[target] = distance[v] + cost
                    before_vertice[target] = v
                    before_edge[target] = i
                    updated = 1
    if distance[sink] == float("inf"):
        print(-1)
        break
    decreased = flow
    trace_i = sink
    while trace_i != 0:
        decreased = min(decreased, edges[before_vertice[trace_i]][before_edge[trace_i]][1])
        trace_i = before_vertice[trace_i]
    flow -= decreased
    trace_i = sink
    while trace_i != 0:
        this_edge = edges[before_vertice[trace_i]][before_edge[trace_i]]
        this_edge[1] -= decreased
        answer += this_edge[2] * decreased
        edges[trace_i][this_edge[3]][1] += decreased
        trace_i = before_vertice[trace_i]
    if flow <= 0:
        print(answer)
        break
N,M=map(int,input().split())
#AB=[list(map(int,input().split()) for _ n range(N))]
p=[[] for _ in range(N+1)]
for _ in range(N):
    a,b=map(int,input().split())
    p[a].append(b)
    p[b].append(a)

sirube=[-1]*N
visited=[False]*N
def bfs():
    global visited,sirube
    queue=[1]
    while queue:
        now=queue.pop(0)
        for n in p[now]:
            if not visited[n-1]:
                queue.append(n)
                visited[n-1]=True
                sirube[n-1]=now
    return
bfs()
if -1 in sirube[1:]:
    print("No")
    exit()

print("Yes")
for sir in sirube[1:]:
    print(sir)








### FIXED CODE ###

N,M=map(int,input().split())
#AB=[list(map(int,input().split()) for _ n range(N))]
p=[[] for _ in range(N+1)]
for _ in range(M):
    a,b=map(int,input().split())
    p[a].append(b)
    p[b].append(a)
#print(p)
sirube=[-1]*N
visited=[True]+[False]*(N-1)
def bfs():
    global visited,sirube
    queue=[1]
    while queue:
        now=queue.pop(0)
        #print(now)
        for n in p[now]:
            if not visited[n-1]:
                queue.append(n)
                visited[n-1]=True
                sirube[n-1]=now
    return
bfs()
if -1 in sirube[1:]:
    print("No")
    exit()

print("Yes")
for sir in sirube[1:]:
    print(sir)
from itertools import count
a,b,c=map(int,raw_input().split())
g=set()
for n in count(0):
    p=(c+60*n)//(a+b)
    print (a+b)*p,c+60*n,(a+b)*p+a
    if ((a+b)*p-(c+60*n),(c+60*n)-((a+b)*p+a)) in g:
        n=-1
        break
    if (a+b)*p<=c+60*n<=(a+b)*p+a:
        break
    else:
        d=(a+b)*p-(c+60*n)
        e=(c+60*n)-((a+b)*p+a)
        g.add((d,e))
if n>=0:
    print(c+60*n)
else:
    print(n)



### FIXED CODE ###

from itertools import count
a,b,c=map(int,input().split())
g=set()
for n in count(0):
    p=(c+60*n)//(a+b)
    if ((a+b)*p-(c+60*n),(c+60*n)-((a+b)*p+a)) in g:
        n=-1
        break
    if (a+b)*p<=c+60*n<=(a+b)*p+a:
        break
    else:
        d=(a+b)*p-(c+60*n)
        e=(c+60*n)-((a+b)*p+a)
        g.add((d,e))
if n>=0:
    print(c+60*n)
else:
    print(n)
S = input()
if S[0] == S[1] == S[2] == S[3]:
    print("no")
else:
    print("yes")


### FIXED CODE ###

s = input()
if s == "AAA" or s == "BBB":
    print("No")
else:
    print("Yes")
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        list_.append((abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))

print(N-Counter(list_).most_common()[0][1])

### FIXED CODE ###

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

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]==0:
            list_.append(((xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))
        elif xy[i][0]-xy[j][0]<0:
            list_.append((-(xy[i][0]-xy[j][0]),-(xy[i][1]-xy[j][1])))
        else:
            list_.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S.count(march[i])

import itertools
ptr = list(itertools.combinations(march_number,3))

ans = 0
seki = 1

for i in range(len(ptr)):
    for j in range(3):
        seki *= ptr[i][j]
    ans += seki
    seki = 1

print(ans)

### FIXED CODE ###

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

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

import itertools
ans = 0
for v in itertools.combinations(march_number,3):
    ans += v[0]*v[1]*v[2]
print(ans)
#!/usr/bin/python3
# -*- coding: utf-8 -*-

s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']


def dfs(n):
    if n == len(s):
        return True
    for w in words:
        if w in s[n:]:
            if dfs(n + len(w)):
                return True
    return False


if dfs(0):
    print('YES')
else:
    print('NO')


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

s = input()
revs = s[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']


def scan(n):
    for w in words:
        if revs[n:].startswith(w):
            return len(w)
    print('NO')
    exit()


n = 0
while revs[n:] != '':
    n += scan(n)

print('YES')