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

import itertools
import numpy as np

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
A = [1 for i in range(N)]
for A in np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N))):
  score = 0
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1] - A[a-1] == c:
      score += d
  ans = max(ans,score)
print(ans)

### FIXED CODE ###

import itertools
import numpy
N, M, Q = map(int,input().split())
abcd = []*Q
d_list = []
sum_d = 0
for _ in range(Q):
  abcd.append(list(map(int,input().split())))

A = [1 for i in range(N)]
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  for i in range(Q):
    if A[abcd[i][1]-1]-A[abcd[i][0]-1] == abcd[i][2]:
      d_list.append(abcd[i][3])
  if sum_d <= sum(d_list):
    sum_d = sum(d_list)
  d_list.clear()
print(sum_d)
### BUGGY CODE ###

import numpy as np
import sys

N = int(sys.stdin.readline())
A = np.array(sorted(map(int, sys.stdin.readline().split(' '))))

dp = np.ones(N, dtype=np.bool)

for i in range(N - 1):
    if not dp[i]:
        continue
    dp[i + 1:] &= (A[i + 1:] % A[i] != 0)
    dp[i] &= (A[i] != A[i + 1])

print(np.count_nonzero(dp))


### FIXED CODE ###

from collections import Counter
import numpy as np

A_MAX = 10 ** 6 + 1

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

dp = np.zeros(shape=A_MAX, dtype=np.int64)

if A[1] == 1:
    print(1)
elif A[1] > 1:
    print(0)
else:
    for a in A.keys():
        multiples = np.arange(a, A_MAX, a)
        np.add.at(dp, multiples, 1)

    ans = 0
    for a, count in A.items():
        if count > 1:
            continue
        if dp[a] == 1:
            ans += 1

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

S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
print("".join(S))

### FIXED CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 08:50:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(input())
    com = []
    for i in range(n):
        com.append(input().split())
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.insert(0, i[1])
        elif i[0] == COMMAND[1]:
            if i[1] in ans:
                ans.remove(i[1])
        elif i[0] == COMMAND[2]:
            ans.pop(0)
        elif i[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))

### FIXED CODE ###

# -*- coding: utf-8 -*-

from collections import deque
import sys

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ans = deque()
    inp = sys.stdin.readlines()
    for i in range(n):
        com = inp[i].split()
        if com[0] == COMMAND[0]:
            ans.appendleft(com[1])
        elif com[0] == COMMAND[1]:
            if com[1] in ans:
                ans.remove(com[1])
        elif com[0] == COMMAND[2]:
            ans.popleft()
        elif com[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))
### BUGGY CODE ###

#いろはコンテスト day2
import functools
import sys
from heapq import*
from collections import*

input=sys.stdin.readline


p=defaultdict(lambda: -1)
@functools.lru_cache(maxsize=None)
class UNION_FIND(object):
    def __init__(self,n):
        
        self.parent=defaultdict(lambda: -1)

    def root(self,x):
        if type(self.parent[x])!=tuple:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True
def compute_mst_kruskal(max_v, edges, flip):
    edges.sort(key=lambda x: x[2],reverse=flip)
    #print(edges)
    uf = UNION_FIND(max_v)
    mst = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            mst.append(c)
    return mst


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

x=sorted(points,key=lambda x:x[0])
y=sorted(points,key=lambda x:x[1])
#print(x,y)


edges = []
for i in range(1,n):
    (a,b),(c,d)=x[i-1],x[i]
    (e,f),(g,h)=y[i-1],y[i]
    heappush(edges,((a,b),(c,d),abs(a-c)))
    heappush(edges,((e,f),(g,h),abs(f-h)))
#print(edges)
mst = compute_mst_kruskal(n, edges , 0) #0が最小化
print(sum(mst))

### FIXED CODE ###

#いろはコンテスト day2
import functools
import sys
from heapq import*
from collections import*

input=sys.stdin.readline


p=defaultdict(lambda: -1)
@functools.lru_cache(maxsize=None)
class UNION_FIND(object):
    def __init__(self,n):
        
        self.parent=defaultdict(lambda: -1)

    def root(self,x):
        if type(self.parent[x])!=tuple:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True
def compute_mst_kruskal(max_v, edges, flip):
    edges.sort(key=lambda x: x[2],reverse=flip)
    #print(edges)
    uf = UNION_FIND(max_v)
    mst = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            mst.append(c)
    return mst


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

x=sorted(points,key=lambda x:x[0])
y=sorted(points,key=lambda x:x[1])
#print(x,y)


edges = []
for i in range(1,n):
    (a,b),(c,d)=x[i-1],x[i]
    (e,f),(g,h)=y[i-1],y[i]
    heappush(edges,((a,b),(c,d),abs(a-c)))
    heappush(edges,((e,f),(g,h),abs(f-h)))
#print(edges)
mst = compute_mst_kruskal(n, edges , 0) #0が最小化
print(sum(mst))
### BUGGY CODE ###

import heapq
n, m, s, t = map(int, input().split())


def to_v(i, j):
    return 2*i+j


N = 2*n
edges = [[]for _ in range(N)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    edges[to_v(u, 0)].append((a, to_v(v, 0)))
    edges[to_v(v, 0)].append((a, to_v(u, 0)))
    edges[to_v(u, 1)].append((b, to_v(v, 1)))
    edges[to_v(v, 1)].append((b, to_v(u, 1)))

for u in range(n):
    edges[to_v(u, 0)].append((0, to_v(u, 1)))


def dijkstra(init_v):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*N
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist
  

for i in range(n):
    if i != 0:
        i -= 1
        edges[to_v(i, 0)].pop()
    dist = dijkstra(to_v(s-1, 0))
    print(10**15-dist[to_v(t-1, 1)])


### FIXED CODE ###

import heapq
n, m, s, t = map(int, input().split())
edges_yen = [[]for _ in range(n)]
edges_snuuk = [[]for _ in range(n)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    edges_yen[u-1].append((a, v-1))
    edges_yen[v-1].append((a, u-1))
    edges_snuuk[u-1].append((b, v-1))
    edges_snuuk[v-1].append((b, u-1))


def dijkstra(init_v, edges):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist


dist_yen = dijkstra(s-1, edges_yen)
dist_snuuk = dijkstra(t-1, edges_snuuk)
dist = [x+y for x, y in zip(dist_yen, dist_snuuk)]
ans = []
INF = 10**18
MIN = INF
for x in dist[::-1]:
    if x < MIN:
        MIN = x
    ans.append(MIN)
for x in ans[::-1]:
    print(10**15-x)
### BUGGY CODE ###

n,k =map(int,input().split())
x = list(map(int, input().split()))
a = []
a.append(0)
a.append(abs(x[0]-x[1]))
for i in range (2,n):
    a.append(min([abs(x[i]-x[j])+a[j] for j in range(max(0,i-k),i)]))
print (a[-1])

### FIXED CODE ###

def main():
    
    n,k =map(int,input().split())
    x = list(map(int, input().split()))
    a = [0]*n
    for i in range (1,n):
        a[i]=(min([abs(x[i]-x[j])+a[j] for j in range(max(0,i-k),i)]))
    print (a[-1])
if __name__ == "__main__":
    main()
### BUGGY CODE ###

X, Y, Z, K  = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R  = [sum([A[0], B[0], C[0]])]
Q  = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D  = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}
iS = [((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q if (a < X) and (b < Y) and (c < Z)]

while len(R) < K:
    iS = sorted(iS, key=lambda x: [x[1], x[0]], reverse=True)
    R.append(iS[0][1])
    abc     = iS[0][0]
    a, b, c = abc[0], abc[1], abc[2]
    iS      = iS[1:]
    if a + 1 < X:
        if not (a + 1, b, c) in D:
            iS.append(((a + 1, b, c), sum([A[a + 1], B[b], C[c]])))
            D.add(     (a + 1, b, c))
    if b + 1 < Y:
        if not (a, b + 1, c) in D:
            iS.append(((a, b + 1, c), sum([A[a], B[b + 1], C[c]])))
            D.add(    (a, b + 1, c))
    if c + 1 < Z:
        if not (a, b, c + 1) in D:
            iS.append(((a, b, c + 1), sum([A[a], B[b], C[c + 1]])))
            D.add(     (a, b, c + 1))

for r in R:
    print(r)


### FIXED CODE ###

X, Y, Z, K  = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R  = [sum([A[0], B[0], C[0]])]
Q  = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D  = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}
iS = [((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q if (a < X) and (b < Y) and (c < Z)]
iS = sorted(iS, key=lambda x: [x[1], x[0]], reverse=True)

while len(R) < K:
    R.append(iS[0][1])
    abc     = iS[0][0]
    a, b, c = abc[0], abc[1], abc[2]
    iS      = iS[1:]
    if a + 1 < X:
        if not (a + 1, b, c) in D:
            s = sum([A[a + 1], B[b], C[c]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a + 1, b, c), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a + 1, b, c), s)]
            D.add((a + 1, b, c))
    if b + 1 < Y:
        if not (a, b + 1, c) in D:
            s = sum([A[a], B[b + 1], C[c]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a, b + 1, c), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a, b + 1, c), s)]
            D.add((a, b + 1, c))
    if c + 1 < Z:
        if not (a, b, c + 1) in D:
            s = sum([A[a], B[b], C[c + 1]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a, b, c + 1), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a, b, c + 1), s)]
            D.add((a, b, c + 1))

for r in R:
    print(r)
### BUGGY CODE ###

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

from itertools import permutations
p = list(set(l))
q = list(permutations(p, 2))

if len(p) == 1:
    print(int(len(l)/2))
    exit()

gu, ki = [], []
for i in range(n):
    if i % 2 == 0:
        gu.append(l[i])
    else:
        ki.append(l[i])

y = []
for k in range(len(q)):
    x = 0
    for j in range(int(len(l)/2)):
        if q[k][0] != gu[j]:
            x += 1
        if q[k][1] != ki[j]:
            x += 1
    y.append(x)

print(min(y))

### FIXED CODE ###

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

if len(set(l)) == 1:
    print(len(l)//2)
    exit()

even = [l[_] for _ in range(n) if _%2 ==1]
odd = [l[_] for _ in range(n) if _%2 ==0]

from collections import Counter

odd_cnt = Counter(odd)
even_cnt = Counter(even)

if odd_cnt.most_common()[0][0] != even_cnt.most_common()[0][0]:
    print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[0][1])
else:
    if odd_cnt.most_common()[1][1] >= even_cnt.most_common()[1][1]:
        print(len(odd) - odd_cnt.most_common()[1][1] + len(even) - even_cnt.most_common()[0][1])
    else:
        print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[1][1])
### BUGGY CODE ###

import sys

input = sys.stdin.readline
n = int(input())
strs = [input() for i in range(n)]


ret = []
for str in strs:
  l = list(str)
  l.sort()
  ret.append("".join(l))

set = set(ret)

count = 0
for index, content in enumerate(ret):
  if index < len(ret) - 1:
    list = ret[index+1:]
    count += list.count(content)
print(count)

### FIXED CODE ###

import sys

n = int(input())
originals = [input() for i in range(n)]

ret = {}
count = 0
for original in originals:
  str = "".join(sorted(list(original)))
  if str in ret:
    count += ret[str]
    ret[str] += 1
  else:
    ret[str] = 1
print(count)
### BUGGY CODE ###

n,a,b,c = map(int,input().split())
now = [[a,b,c,[]]]
for _ in range(n):
  q = input()
  tmp = []
  if q == 'AB':
    for x in now:
      a,b,c,his = x
      if a > 0:
        tmp.append([a-1,b+1,c,his+['B']])
      if b > 0:
        tmp.append([a+1,b-1,c,his+['A']])
  elif q == 'AC':
    for x in now:
      a,b,c,his = x
      if a > 0:
        tmp.append([a-1,b,c+1,his+['C']])
      if c > 0:
        tmp.append([a+1,b,c-1,his+['A']])
  else:
    for x in now:
      a,b,c,his = x
      if b > 0:
        tmp.append([a,b-1,c+1,his+['C']])
      if c > 0:
        tmp.append([a,b+1,c-1,his+['B']])
  if not tmp:
    print('No')
    exit()
  now = []
  m = max(tmp,key=lambda x:x[0])
  if m not in now:
    now.append(m)
  m = min(tmp,key=lambda x:x[0])
  if m not in now:
    now.append(m)
  m = max(tmp,key=lambda x:x[1])
  if m not in now:
    now.append(m)
  m = min(tmp,key=lambda x:x[1])
  if m not in now:
    now.append(m)
  m = max(tmp,key=lambda x:x[2])
  if m not in now:
    now.append(m)
  m = min(tmp,key=lambda x:x[2])
  if m not in now:
    now.append(m)
print('Yes')
ans = now[0][3]
for s in ans:
  print(s)

### FIXED CODE ###

#人生終わり
#解説解答
n,a,b,c = map(int,input().split())
if a + b + c == 0:
  print('No')
  exit()
elif a + b + c == 1:
  ans = []
  for _ in range(n):
    q = input()
    if q == 'AB':
      if a + b == 0:
        print('No')
        exit()
      a,b = b,a
      if a:
        ans.append('A')
      else:
        ans.append('B')
    elif q == 'BC':
      if b + c == 0:
        print('No')
        exit()
      b,c = c,b
      if b:
        ans.append('B')
      else:
        ans.append('C')
    else:
      if c + a == 0:
        print('No')
        exit()
      c,a = a,c
      if a:
        ans.append('A')
      else:
        ans.append('C')
  print('Yes')
  for x in ans:
    print(x)
  exit()
p = []
for _ in range(n):
  p.append(input())
if a + b == 0 and p[0] == 'AB':
    print('No')
    exit()
if b + c == 0 and p[0] == 'BC':
    print('No')
    exit()
if a + c == 0 and p[0] == 'AC':
    print('No')
    exit()
print('Yes')
for i in range(n):
  if p[i] == 'AB':
    if a == 0:
      a += 1
      b -= 1
      print('A')
    elif b == 0:
      a -= 1
      b += 1
      print('B')
    elif i != n-1:
      if p[i+1] == 'BC':
        a -= 1
        b += 1
        print('B')
      else:
        a += 1
        b -= 1
        print('A')
    else:
      a += 1
      b -= 1
      print('A')
  elif p[i] == 'BC':
    if b == 0:
      b += 1
      c -= 1
      print('B')
    elif c == 0:
      b -= 1
      c += 1
      print('C')
    elif i != n-1:
      if p[i+1] == 'AC':
        b -= 1
        c += 1
        print('C')
      else:
        b += 1
        c -= 1
        print('B')
    else:
      b += 1
      c -= 1
      print('B')
  else:
    if a == 0:
      a += 1
      c -= 1
      print('A')
    elif c == 0:
      a -= 1
      c += 1
      print('C')
    elif i != n-1:
      if p[i+1] == 'BC':
        a -= 1
        c += 1
        print('C')
      else:
        a += 1
        c -= 1
        print('A')
    else:
      a += 1
      c -= 1
      print('A')
### BUGGY CODE ###

n,k = map(int,input().split())
h = [int(i) for i in input().split()]
def cost(i,j): return abs(h[i]-h[j])
INF = float("INF")
dp = [INF]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+cost(i,j))
print(dp[n-1])

### FIXED CODE ###

n,K = map(int,input().split())
h = [0]
for i in input().split(): h.append(int(i))
def cost(i,j): return abs(h[i]-h[j])

dp = [float("inf") for _ in range(n+1)]
dp[0] = dp[1] = 0
for i in range(2,n+1):
    for k in range(1,K+1):
        if i-k > 0:
            dp[i] = min(dp[i-k]+cost(i,i-k),dp[i])

print(dp[n])
### BUGGY CODE ###

import itertools as it
N=int(input())
S=[0,1,2,3,4,5]
for k in range(N//100):
  for i in it.product(S,repeat=N//100):
    if sum(i)==N%100:
      print("1")
      exit()
print("0")
    
    

### FIXED CODE ###

import itertools as it
N=int(input())
S=[0,1,2,3,4,5]
for k in range(N//100):
  for i in it.combinations_with_replacement(S,N//100):
    if sum(i)==N%100:
      print("1")
      exit()
print("0")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from fractions import gcd
import math
n = int(input())
a = list(map(int, input().split()))
def lcm(a, b):
    return (a * b) // gcd(a, b)
m = 1
for x in a:
    m = (m * x) // gcd(m, x)
# print(m)
MOD = 1000000007
ans = 0
for x in a:
    b = m // x
    ans = (ans + b) % MOD
print(math.floor(ans))


### FIXED CODE ###

import sys
input = sys.stdin.readline
from fractions import gcd
import math
n = int(input())
a = list(map(int, input().split()))
def lcm(a, b):
    return (a * b) // gcd(a, b)
m = 1
for x in a:
    m = (m * x) // gcd(m, x)
# print(m)
MOD = 1000000007
ans = 0
for x in a:
    b = m // x
    ans = ans + b
ans = ans % MOD
print(math.floor(ans))
### BUGGY CODE ###

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

pos = 0
saidai = 0
for i in range(N-K+1):
  temp = sum(p[i:i+K])
  if saidai < temp:
    saidai = temp
    pos = i
    
kitaichi = 0
for i in range(K):
  temp = 0
  for j in range(p[pos+i] + 1):
    temp = temp + j
  kitaichi = kitaichi + float(temp/p[pos+i])
  
print('{:.12f}'.format(kitaichi))

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
 
now = sum(p[:K])
saidai = now
for i in range(K, N):
  now -= p[i-K]
  now += p[i]
  if now > saidai:
    saidai = now
 
print('{:.12f}'.format((saidai + K)/2))
### BUGGY CODE ###

def main():
    N, K = [int(x) for x in input().split()]
    H = [int(x) for x in input().split()]
    DP = [float("inf")]*N
    DP[0] = 0
    
    for i in range(0,N):
        for k in range(1,K+1):
            if i+k < N:
                DP[i+k] = min(DP[i+k],DP[i] + abs(H[i+k]-H[i]))

    print(DP[-1])


if __name__ == "__main__":
    main()
    pass

### FIXED CODE ###

def main():
    N, K = [int(x) for x in input().split()]
    H = [int(x) for x in input().split()]
    DP = [float("inf")]*N
    DP[0] = 0
    
    for i in range(0,N):
        for k in range(1,K+1):
            if i+k < N:
                DP[i+k] = min(DP[i+k],DP[i] + abs(H[i+k]-H[i]))

    print(DP[-1])


if __name__ == "__main__":
    main()
    pass
### BUGGY CODE ###

s1 = input()
s2 = s1[::-1]
q = int(input())
x = 0
for i in range(q):
    query = input()
    if query == '1':
        x += 1
    else :
        if (x + int(query[2])) % 2 == 0:
            s1 +=  query[-1]
            s2 = query[-1] + s2
        else :
            s1 = query[-1] + s1
            s2 += query[-1]
if x % 2 == 0:
    print(s1)
else :
    print(s2)

### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')
### BUGGY CODE ###

# = int(input())
N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = []

for i in range(K):
    List.append(next)
    next = A[next-1]
    if len(set(List)) != len(List):
        break

if len(set(List)) != len(List):
    count = [i for i, x in enumerate(List) if x == List[-1]]
    loop = count[1] - count[0]
    afterloop = (K-count[0])%loop
    print(List[count[0]+afterloop])

else:
    print(next)


### FIXED CODE ###

# = int(input())
N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = [-1]*N

for i in range(K):
    if List[next-1] == -1:
        List[next-1] = i
        next = A[next-1]

    else:
        loop = i - List[next-1]
        afterloop = (K-(i-loop))%loop
        print(List.index((i-loop) + afterloop)+1)
        exit()

print(next)
### BUGGY CODE ###

def solve():
    factors = [1]*(n+1)
    ans = 1
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            factors[j] += 1
        ans += (factors[i]*i)
    return ans

if __name__ == '__main__':
    n = int(input())
    print(solve())
    

### FIXED CODE ###

def solve():
    ans = 0
    for x in range(1, n + 1):
        y = int(n / x)
        ans += y * (y + 1) * x // 2
    return ans

if __name__ == '__main__':
    n = int(input())
    print(solve())
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    A[i] += A[i-1]
for i in range(1, M+1):
    B[i] += B[i-1]

ans = 0

for a_index in range(N+1):
    left = K - A[a_index]
    if left < 0: break

    b_index = M
    while left - B[b_index] < 0:
        b_index -= 1

    ans = max(ans, a_index + b_index)

print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    A[i] += A[i-1]
for i in range(1, M+1):
    B[i] += B[i-1]

ans = 0

b_index = M

for a_index in range(N+1):
    left = K - A[a_index]
    if left < 0: continue

    while left - B[b_index] < 0:
        b_index -= 1

    ans = max(ans, a_index + b_index)

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

r,g,b,n=map(int, input().split())

sum=0

for i in range((n//r)+1):
    for j in range((n-(i*r)//g)+1):
        if (n-(i*r)-(j*g))%b==0 and (n-(i*r)-(j*g))//b>=0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)


### FIXED CODE ###

r,g,b,n=map(int, input().split())

sum=0

for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b==0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)