import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict, Counter import string import random input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') N, Pmax, C = map(int, input().split()) P = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0 for _ in range(Pmax + 1)] for _ in range(2 * N + 1)] for i in range(N): price, value = P[i] value += C for j in range(Pmax + 1): if j + price <= Pmax: dp[i + 1][j + price] = max(dp[i + 1][j + price], dp[i][j] + value) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) for i in range(N): price, value = P[i] for j in range(Pmax + 1): if j + price <= Pmax: dp[N + i + 1][j + price] = max(dp[N + i + 1][j + price], dp[N + i][j] + value, dp[N + i + 1][j] + value) dp[N + i + 1][j] = max(dp[N + i + 1][j], dp[N + i][j]) print(max(dp[2 * N]))