#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSString*)stringFromStdIn;
+(NSMutableArray*)stringsFromStdInSeparatedByString:(NSString*)separator;
+(NSMutableArray*)numbersFromStdInSeparatedByString:(NSString*)separator;
+(void)puts:(NSString*)format, ...;
@end

@interface NSString (Split)
-(NSMutableArray*)splitCharacterEvery:(NSUInteger)number;
-(NSMutableArray*)characters;
@end

@implementation NSString (Split)
-(NSMutableArray*)splitCharacterEvery:(NSUInteger)number
{
	if ([self length] <= number) {
		return [NSMutableArray arrayWithObject: self];
	}

	NSMutableArray  *mArray = [NSMutableArray array];
	NSMutableString *mStr   = [NSMutableString stringWithString: self];

	NSRange range = NSMakeRange(0, number);

	while ([mStr length] > 0) {
		if ([mStr length] < number) {
			[mArray addObject: [NSString stringWithString: mStr]];
			[mStr deleteCharactersInRange:NSMakeRange(0, [mStr length])];
		} else {
			[mArray addObject: [mStr substringWithRange: range]];
			[mStr deleteCharactersInRange: range];
		}
	}

	return mArray;
}

-(NSMutableArray*)characters {
	return [self splitCharacterEvery:1];
}

@end

@implementation StdIO
+(NSString*)stringFromStdIn
{
	NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
	NSMutableString *result = [NSMutableString string];
	NSData *data = [handle availableData];
	while ([data length] > 0) {
		[result appendString:[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]];
		data = [handle availableData];
	}

	return result;
}

+(NSMutableArray*)stringsFromStdInSeparatedByString:(NSString*)separator
{
	return [NSMutableArray arrayWithArray:[[StdIO stringFromStdIn] componentsSeparatedByString:separator]];
}

+(NSMutableArray*)numbersFromStdInSeparatedByString:(NSString*)separator
{
	NSMutableArray *strings = [StdIO stringsFromStdInSeparatedByString: separator];
	NSMutableArray *numbers = [NSMutableArray array];
	for (NSString *string in strings) {
		[numbers addObject: [NSNumber numberWithInteger: [string integerValue]]];
	}
	return numbers;
}

+(void)puts:(NSString*)format, ...
{
	va_list arguments;
	va_start(arguments, format);
	NSString *stdoutString = [[NSString alloc] initWithFormat: format arguments: arguments];
	
	NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
	[fileHandle writeData:[stdoutString dataUsingEncoding: NSUTF8StringEncoding]];
	[fileHandle writeData:[@"\n" dataUsingEncoding: NSUTF8StringEncoding]];
	
	va_end(arguments);	
}
@end



int main(int argc, const char * argv[]) {
	@autoreleasepool {
		NSArray *numbers = [StdIO stringsFromStdInSeparatedByString:@"\n"];
		NSInteger a = [[numbers objectAtIndex: 0] integerValue];
		NSInteger b = [[numbers objectAtIndex: 1] integerValue];
		NSInteger c = [[numbers objectAtIndex: 2] integerValue];
		NSInteger X = [[numbers objectAtIndex: 3] integerValue] / 50;
		// count (x,y,z) with 10x + 2y + z == X, x<=a, y<=b, z<=c
		NSInteger count = 0;
		NSInteger x = 0;
		while (x<=a && x <= X/10) {
			NSInteger Y = X-10*x;
			NSInteger y = 0;
			while (y<=b && y<= Y/2) {
				NSInteger z = Y-2*y;
				if (z<=c) {
					count++;
				}
				y++;
			}
			x++;
		}
		[StdIO puts: @"%ld", count];
	}

	return 0;
}

Measured memory_bytes: 8736