Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque

def bfs(fd, n):
    visited = set()
    ans = 1
    for i in range(1, n + 1):
        if i in visited: continue
        volume = 1
        queue = deque(list(fd[i]))
        visited.add(i)
        while queue:
            x = queue.popleft()
            if x in visited: continue
            visited.add(x)
            volume += 1
            for l in fd[x]:
                if l not in visited and l not in queue:
                    queue.append(l)
        ans = max(ans, volume)
    return ans

if __name__ == "__main__":
    n, m = map(int, input().split())
    fd = {i+1:set() for i in range(n)}
    for _ in range(m):
        a, b = map(int, input().split())
        fd[a].add(b)
        fd[b].add(a)
    print(bfs(fd, n))

### FIXED CODE ###

def bfs(fd, n):
    visited = set()
    ans = 1
    for i in range(1, n + 1):
        if i in visited: continue
        volume = 1
        queue = fd[i]
        visited.add(i)
        while queue:
            x = queue.pop()
            if x in visited: continue
            visited.add(x)
            volume += 1
            queue |= fd[x]
        ans = max(ans, volume)
    return ans

if __name__ == "__main__":
    n, m = map(int, input().split())
    fd = {i+1:set() for i in range(n)}
    for _ in range(m):
        a, b = map(int, input().split())
        fd[a].add(b)
        fd[b].add(a)
    print(bfs(fd, n))
### BUGGY CODE ###

import copy
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]
# cost = [[-1]*10 for i in range(10)]
# for j in range(10):
#     cost[j] = [[c[i][j], i] for i in range(10)]
cost = [-1]*10
cost[1] = 0

dp = [[-1]*10 for i in range(10)]
for i in range(10):
    dp[i][i] = 0


def search_cost(i, j, reached):
    # if dp[i][j] != -1:
    #     return dp[i][j]
    tmp_list = copy.copy(reached)
    tmp_list.append(i)
    ret = c[i][j]

    for k in range(10):
        if k == i or k == 1 or k in reached:
            continue
        else:
            tmp = c[i][k] + search_cost(k, j, tmp_list)
            ret = min(tmp, ret)
            if ret <= 2:
                break
            #print("i:"+str(i) + "k:" + str(k) + "j:"+str(j) + "=" + str(tmp))

    # dp[i][j] = ret
    # for i in range(10):
    #     print(dp[i])
    return ret


for i in range(10):
    if i == 1:
        continue
    else:
        if c[i][1] <= 2:
            dp[i][1] = c[i][1]
            cost[i] = c[i][1]
        else:
            cost[i] = search_cost(i, 1, [])
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += cost[A[i][j]]
print(ans)


### FIXED CODE ###

import copy
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]
# cost = [[-1]*10 for i in range(10)]
# for j in range(10):
#     cost[j] = [[c[i][j], i] for i in range(10)]
cost = [-1]*10
cost[1] = 0

dp = [[-1]*10 for i in range(10)]
for i in range(10):
    dp[i][i] = 0


def search_cost(i, j, reached):
    # if dp[i][j] != -1:
    #     return dp[i][j]
    if cost[i] != -1:
        return cost[i]
    tmp_list = copy.copy(reached)
    tmp_list.append(i)
    ret = c[i][j]

    for k in range(10):
        if k == i or k == 1 or k in reached:
            continue
        else:
            tmp = c[i][k] + search_cost(k, j, tmp_list)
            ret = min(tmp, ret)
            if ret <= 2:
                break
            #print("i:"+str(i) + "k:" + str(k) + "j:"+str(j) + "=" + str(tmp))

    # dp[i][j] = ret
    # for i in range(10):
    #     print(dp[i])
    return ret


for i in range(10):
    if i == 1:
        continue
    else:
        if c[i][1] <= 2:
            dp[i][1] = c[i][1]
            cost[i] = c[i][1]
        else:
            cost[i] = search_cost(i, 1, [])
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += cost[A[i][j]]
print(ans)
### BUGGY CODE ###

import sys
n=int(input())
a=list(map(int,input().split()))
i=0
b = []
j=0

while i < n:
    j =a.index(min(a))+1
    a[j-1]+=n
    i+=1
    print(j, end=" ")


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
i=1
b = []
j=0

map = {a[i]:str(i+1) for i in range(n)}
print(" ".join([map[i] for i in range(1, n+1)]))
### BUGGY CODE ###

import sys

for line in sys.stdin:
	lis = []
	i = 2
	while i <= int(line):
		j = 1
		while j <= i-2:
			if i % (j+1) == 0:
				break
			j += 1
		else:
			lis.append(i)
		i += 1
	print len(lis)	

### FIXED CODE ###

import sys
N = 999999
lis = []
if N >= 2:
	lis.append(2)
if  N >= 3:
	lis.append(3)
if N >= 5:
	for i in xrange(5,N+1,2):
		for item in lis:
			if item > (i**0.5):
				lis.append(i)
				break
			if i % item == 0:
				break
		else:
			lis.append(i)
dp = [0]*999999
for item in lis:
	dp[item-1] += 1
for i in xrange(1,999999):
	dp[i] += dp[i-1]

for line in sys.stdin:
	num = int(line)
	print dp[num-1]
### BUGGY CODE ###

from collections import deque

def main():
  H,W,K=map(int,input().split())
  x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
  S=[list(input()) for _ in range(H)]
  INF = 10**20

  def bfs(x0,y0,x_goal,y_goal):
    seen = [[0 for i in range(W)] for j in range(H)]
    d = [[INF for i in range(W)] for j in range(H)]
    d[x0][y0] = 0
    todo = deque()
    seen[x0][y0] = 1
    todo.append((x0,y0))
    while todo:
      x0,y0 = todo.popleft()
      dx,dy = (1,-1,0,0),(0,0,1,-1)
      for i in range(4):
        for k in range(K):
          x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
          if x<0 or x>=H:break
          if y<0 or y>=W:break
          if seen[x][y]==1:continue
          if S[x][y]=='@':break
          seen[x][y] = 1
          todo.append((x,y))
          d[x][y] = d[x0][y0] + 1
          if x==x_goal and y == y_goal: return d[x][y]
    return d[x_goal][y_goal]

  ans = bfs(x1,y1,x2,y2)
  print(ans if ans < INF else -1)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

from collections import deque

def main():
  H,W,K=map(int,input().split())
  x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
  S=[list(input()) for _ in range(H)]
  INF = 10**20

  def bfs(x0,y0,x_goal,y_goal):
    seen = [[0 for i in range(W)] for j in range(H)]
    d = [[INF for i in range(W)] for j in range(H)]
    d[x0][y0] = 0
    todo = deque()
    seen[x0][y0] = 1
    todo.append((x0,y0))
    while todo:
      x0,y0 = todo.popleft()
      dx,dy = (1,-1,0,0),(0,0,1,-1)
      for i in range(4):
        for k in range(K):
          x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
          if x<0 or x>=H:break
          if y<0 or y>=W:break
          if d[x][y] < d[x0][y0] + 1: break
          if S[x][y]=='@':break
          if seen[x][y]: continue
          seen[x][y] = 1
          todo.append((x,y))
          d[x][y] = d[x0][y0] + 1
          if x==x_goal and y == y_goal: return d[x][y]
    return d[x_goal][y_goal]

  ans = bfs(x1,y1,x2,y2)
  print(ans if ans < INF else -1)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

N,K = map(int,input().split())
P = list(map(int,input().split()))
memo = {}

exp = []
for p in P:
  exp.append((1+p)/2)

res = 0
i = 0
k = K
while k <= N:
  res = max(res, sum(exp[i:k]))
  i += 1
  k += 1

print(res)

### FIXED CODE ###

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

T = [0] * (N+1)

for i in range(N):
  T[i+1] = T[i] + (1+p[i])/2

ans = 0
for j in range(K, N+1):
  ans = max(ans, T[j]-T[j-K])

print(ans)
### BUGGY CODE ###

import sys

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    if n > max(primes):
      for i in range(max(primes) + 1, n + 1):
        if i % 2 == 0:
          continue
        primes.append(i)
        for p in primes:
          if i % p == 0 and i != p:
            primes.pop()
            break
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break

### FIXED CODE ###

import sys
import math

# Sieve of Eratosthenes
N = 999999
searchList = list(range(3, N + 1, 2))
primes = [2]
while True:
  top = searchList.pop(0)
  primes.append(top)
  if top > math.sqrt(N):
    break
  searchList = [s for s in searchList if s % top != 0]
primes.extend(searchList)

# solve
for line in sys.stdin:
  try:
    n = int(line)
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break
### BUGGY CODE ###

import sys
n = int(sys.stdin.readline()[:-1])
S = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))
q = int(sys.stdin.readline()[:-1])
T = list(map(int, (sys.stdin.readline()[:-1]).split()))

def search(A, leng, i):
    if leng == 1:
        return A[0] == i
    half = leng // 2
    h = A[half]
    if h == i:
        return True
    elif h < i:
        return search(A[half:], len(A[half:]), i)
    elif i < h:
        return search(A[:half], len(A[:half]), i)


count = 0
for t in T:
    if search(S, n, t):
        count += 1
print(count)

### FIXED CODE ###

import sys
n = int(sys.stdin.readline()[:-1])
S = [int(x) for x in (sys.stdin.readline()[:-1].split())]
q = int(sys.stdin.readline()[:-1])
T = [int(x) for x in (sys.stdin.readline()[:-1].split())]

count = 0
for t in T:
    l = 0
    h = n - 1
    while l <= h:
        half = (h + l) // 2
        if S[half] == t:
            count += 1
            break
        elif S[half] < t:
            l = half + 1
        else:
            h = half - 1

print(count)
### BUGGY CODE ###

N=int(input())
A=[i for i in map(int,input().split())]
k=0
while len(A)!=1:
    if A[1]%A[0]!=0:
        A[1]=A[1]%A[0]
        k+=1
    else:
        A.remove(A[1])
    A.sort()
    if A[0]==1:
        break
print(A[0])


### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)
### BUGGY CODE ###

import sys
import numpy
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())

# めちゃくちゃ遅くて TLE
#V = [[0]*N for _ in range(N)]
#
#for i in range(N-1):
#    u,v,w = list(map(int, input().split()))
#    V[u-1][v-1] = w

U = numpy.zeros(N, dtype=numpy.int32)
V = numpy.zeros(N, dtype=numpy.int32)
W = numpy.zeros(N, dtype=numpy.int32)

for i in range(N-1):
    u,v,w = list(map(int, input().split()))
    U[i] = u-1
    V[i] = v-1
    W[i] = w

D = dijkstra(csr_matrix((W,(U,V)), shape=(N,N)), directed=False, indices=0)

for d in D:
    if d % 2 == 0: #even
        print(0)
    else:
        print(1)


### FIXED CODE ###

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

import sys
#import numpy
#from collections import deque
sys.setrecursionlimit(10**5)

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())

childsof = [[] for _ in range(N+1)]

for _ in range(N-1):
    u,v,w = list(map(int, input().split()))
    childsof[u].append((v,w))
    childsof[v].append((u,w))

distances = [-1]*(N+1)
distances[1] = 0

def dfs(i):
    childs = childsof[i]

    for c in childs:
        j = c[0]
        if distances[j] == -1:
            distances[j] = distances[i] + c[1]
            dfs(j)

dfs(1)

for d in distances[1:]:
    if d % 2 == 0: #even
        print(0)
    else:
        print(1)
### BUGGY CODE ###

N = int(raw_input())
t = [[0,0] for i in range(N)]
for i in range(N):
    l = []
    l = raw_input().split()
    t[i][0] = int(l[0])
    t[i][1] = int(l[1])
min_ = [0,0]
min_[0] = t[0][0]
min_[1]= t[0][1]
for i in range(1,N):
    cnt = 1
    while cnt*t[i][0]<min_[0] or cnt*t[i][1]<min_[1]:
        cnt = cnt+1
    min_[0] = cnt*t[i][0]
    min_[1] = cnt*t[i][1]
print min_[0]+min_[1]

### FIXED CODE ###

N = int(raw_input())
t = [[0,0] for i in range(N)]
for i in range(N):
    l = []
    l = raw_input().split()
    t[i][0] = int(l[0])
    t[i][1] = int(l[1])
min_ = [0,0]
min_[0] = t[0][0]
min_[1]= t[0][1]
for i in range(1,N):
#    cnt = max(int(math.ceil(1.0*min_[0]/t[i][0])),int(math.ceil(1.0*min_[1]/t[i][1])))
    cnt_0 = min_[0]/t[i][0]
    if min_[0]%t[i][0]!=0:
        cnt_0+=1
    cnt_1 = min_[1]/t[i][1]
    if min_[1]%t[i][1]!=0:
        cnt_1+=1
    cnt = max(cnt_0,cnt_1)
    min_[0] = cnt*t[i][0]
    min_[1] = cnt*t[i][1]
print min_[0]+min_[1]
### BUGGY CODE ###

import math

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

def combi(n):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - 2) * 2)

a2 = sorted(a)
a2.append(n+1)
dic = {}
n = 0
cnt = 1
total = 0
for i in a2:
    if n != i:
        if cnt > 1:
            dic[str(n)] = cnt
            total += combi(cnt)
        n = i
        cnt = 1
    else:
        cnt += 1

for i in a:
    if str(i) in dic:
        cnt = dic[str(i)]
        print(total - combi(cnt) + combi(cnt-1))
    else:
        print(total)

### FIXED CODE ###

import math

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

def combi(n):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - 2) * 2)

a2 = sorted(a)
a2.append(n+1)
dic = {}
n = 0
cnt = 1
total = 0
for i in a2:
    if n != i:
        if cnt > 1:
            dic[str(n)] = cnt
            total += combi(cnt)
        n = i
        cnt = 1
    else:
        cnt += 1

for i in a:
    if str(i) in dic:
        cnt = dic[str(i)]
        print(total - cnt + 1)
    else:
        print(total)
### BUGGY CODE ###

h,w=map(int,input().split())

M=[]
for i in range(h):
    M.append(input())

L=[]
for j in range(h):
    Lj=[]
    for i in range(w):
        if M[j][i]=="#":
            Lj.append(0)
        elif i==0:
            Lj.append(1)
        else:
            Lj.append(Lj[i-1]+1)
    L.append(Lj)
R=[]
for j in range(h):
    Rj=[]
    for i in range(w):
        if M[j][w-1-i]=="#":
            Rj.append(0)
        elif i==0:
            Rj.append(1)
        else:
            Rj.append(Rj[i-1]+1)
    R.append(Rj[::-1])   
U=[]
for i in range(w):
    Ui=[]
    for j in range(h):
        if M[j][i]=="#":
            Ui.append(0)
        elif j==0:
            Ui.append(1)
        else:
            Ui.append(Ui[j-1]+1)
    U.append(Ui)
D=[]
for i in range(w):
    Di=[]
    for j in range(h):
        if M[h-1-j][i]=="#":
            Di.append(0)
        elif j==0:
            Di.append(1)
        else:
            Di.append(Di[j-1]+1)
    D.append(Di[::-1])

s=0
for i in range(w):
    for j in range(h):
        s=max(s,L[j][i]+R[j][i]+U[i][j]+D[i][j]-3)

print(s)

### FIXED CODE ###

h,w=map(int,input().split())

M=[]
for i in range(h):
    M.append(input())

L=[]
for j in range(h):
    Lj=[]
    for i in range(w):
        if M[j][i]=="#":
            Lj.append(0)
        elif i==0:
            Lj.append(1)
        else:
            Lj.append(Lj[i-1]+1)
    L.append(Lj)
R=[]
for j in range(h):
    Rj=[]
    for i in range(w):
        if M[j][w-1-i]=="#":
            Rj.append(0)
        elif i==0:
            Rj.append(1)
        else:
            Rj.append(Rj[i-1]+1)
    R.append(Rj)   
U=[]
for i in range(w):
    Ui=[]
    for j in range(h):
        if M[j][i]=="#":
            Ui.append(0)
        elif j==0:
            Ui.append(1)
        else:
            Ui.append(Ui[j-1]+1)
    U.append(Ui)
D=[]
for i in range(w):
    Di=[]
    for j in range(h):
        if M[h-1-j][i]=="#":
            Di.append(0)
        elif j==0:
            Di.append(1)
        else:
            Di.append(Di[j-1]+1)
    D.append(Di)

s=0
for i in range(w):
    for j in range(h):
        s=max(s,L[j][i]+R[j][w-1-i]+U[i][j]+D[i][h-1-j]-3)

print(s)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
arr = [-1 for _ in range(len(s))]
tmp = 0
for i in range(len(s)):
    tmp = tmp + int(s[i]) * (10 ** (len(s) - i))
    arr[i] = tmp % 2019
a = list(set(arr))
b = Counter(arr)
ans = 0
for i in a:
    tmp = b[i]
    if i == 0:
        ans += (tmp + 1) * tmp // 2
    else:
        ans += tmp * (tmp - 1) // 2
print(ans)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = [int(i) for i in STR()]
l = len(s)
arr = [-1 for _ in range(l)]
tmp = 0
for i in range(l):
    tmp += s[i] * pow(10, l - i, 2019)
    tmp %= 2019
    arr[i] = tmp
arr.sort()
tmp = arr[0]
cnt = 1
ans = 0
for i in range(1, l):
    if tmp == arr[i]:
        cnt += 1
    else:
        ans += cnt * (cnt - 1) // 2
        if tmp == 0:
            ans += cnt
        cnt = 1
        tmp = arr[i]
ans += cnt * (cnt - 1) // 2
if tmp == 0:
    ans += cnt
print(ans)
### BUGGY CODE ###

from sys import stdin
input = stdin.readline

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

if b > n  :
    for i in range(n+1):
        tmp = int((a * i) / b)  - a * int(i/b) 
        maxpoint = max(tmp,maxpoint)

else:
    for i in reversed(range(n+1)):
        tmp = int((a * i) / b)  - a * int(i/b) 
        if b > 1:
            if i % (b-1) == 0 :
                maxpoint = max(tmp,maxpoint)
                print(maxpoint) 
                exit()
        elif b == 1:
            print(0)
            exit()
        maxpoint = max(tmp,maxpoint)

print(maxpoint)


### FIXED CODE ###

from sys import stdin
input = stdin.readline
 
a,b,n = map(int,input().split())
maxpoint = 0
 
if b > n  :
    tmp = int((a * n) / b)  - a * int(n/b) 
    maxpoint = max(tmp,maxpoint)
else:
    k = int(n/b)*b -1
    maxpoint =  int((a * k) / b)  - a * int(k/b) 
    if b == 1:
        maxpoint = 0
 
print(maxpoint)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

print(min([S[0:i].count('W') + S[i+1:].count('E') for i in range(N)]))


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

W_num = [0] * N
E_num = [0] * N

for i in range(1, N):
    k = N - (i - 1) - 2
    W_num[i] = W_num[i-1] + 1 if S[i-1] == 'W' else W_num[i-1]
    E_num[k] = E_num[k+1] + 1 if S[k+1] == 'E' else E_num[k+1]

print(min([W_num[i] + E_num[i] for i in range(N)]))
### BUGGY CODE ###

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

D = [pow(i, 2) for i in range(1, N + 2)]

ok = N
ng = 1
List = [-1 for i in range(N + 1)]
while abs(ok - ng) > 2:
  LR = [(ok - ng) // 3 + ng, 2 * (ok - ng) // 3 + ng]
  Ans = [0, 0]
  for j in range(2):
    if List[LR[j]] != -1:
      Ans[j] = List[LR[j]]
      continue
    least = 0
    Ans[j] = X * (N + LR[j])
    cnt = -1
    t = 0
    flag = False
    for i in x[::-1]:
      if flag:
        Ans[j] += (D[least + 1] - D[least]) * x[cnt]    
      else:
        Ans[j] += (D[0] + D[1]) * x[cnt]
      cnt -= 1
      t += 1
      if t == LR[j]:
        t = 0
        least += 1
        flag = True
    List[LR[j]] = Ans[j]
  if Ans[0] < Ans[1]:
    ok = LR[1]
  else:
    ng = LR[0]
 
FA = 1e20
for j in range(ng, ok + 1):
  if List[j] != -1:
    FA = min(FA, List[j])
    continue
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
  FA = min(FA, Ans)
print(FA)

### FIXED CODE ###

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

D = [pow(i, 2) for i in range(1, N + 2)]

ok = N
ng = 1
List = [-1 for i in range(N + 1)]
while abs(ok - ng) > 2:
  LR = [(ok - ng) // 3 + ng, 2 * (ok - ng) // 3 + ng]
  Ans = [0, 0]
  for j in range(2):
    if List[LR[j]] != -1:
      Ans[j] = List[LR[j]]
      continue
    least = 0
    Ans[j] = X * (N + LR[j])
    cnt = -1
    t = 0
    flag = False
    for i in x[::-1]:
      if flag:
        Ans[j] += (D[least + 1] - D[least]) * x[cnt]    
      else:
        Ans[j] += (D[0] + D[1]) * x[cnt]
      cnt -= 1
      t += 1
      if t == LR[j]:
        t = 0
        least += 1
        flag = True
    List[LR[j]] = Ans[j]
  if Ans[0] < Ans[1]:
    ok = LR[1]
  else:
    ng = LR[0]
 
FA = 1e20
for j in range(ng, ok + 1):
  if List[j] != -1:
    FA = min(FA, List[j])
    continue
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
  FA = min(FA, Ans)
print(FA)
### BUGGY CODE ###

import math
a, b, n = map(int, input().split())
arr = []
for i in range(n):
  x = i + 1
  arr.append(math.floor(a * x / b) - a * math.floor(x / b))
ans = max(arr)
print(ans)

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
### BUGGY CODE ###

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

for i in range(n):
    sum = 0
    b = a.copy()
    b.pop(i)
    temp = 0
    for k in range(n-1):
        sum += abs(b[k] - temp)
        temp = b[k]
    sum += abs(temp)
    print(sum)

### FIXED CODE ###

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

default= 0
tmp = 0
for i in range(n+2):
    default += abs(a[i]-tmp)
    tmp = a[i]

for i in range(1,n+1):
    if a[i-1] <= a[i] <= a[i+1] or a[i-1] >= a[i] >= a[i+1]:
        print(default)
    else:
        distance = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i])
        sa = distance - abs(a[i+1] - a[i-1])
        print(default-sa)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

count = 0
for i in range(N+1):
    for j in range(N+1):
        if (N - R*i - G*j) >= 0 and (N - R*i - G*j) % B == 0:
            count += 1

print(count)


### FIXED CODE ###

R, G, B, N = map(int, input().split())

count = 0
for i in range(N // R + 1):
    n = N - R * i
    for j in range(n // G + 1):
        if (n - G*j) >= 0 and (n - G*j) % B == 0:
            count += 1

print(count)