#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 numbersFromStdInSeparatedByString:@" "];
		NSInteger n = [[numbers objectAtIndex: 0] integerValue];
		NSInteger a = [[numbers objectAtIndex: 1] integerValue];
		NSInteger b = [[numbers objectAtIndex: 2] integerValue];
		NSInteger Sum = 0;
		for (NSInteger i = 0; i<=n; i++) {
			NSInteger sum = 0;
			for (NSString *j in [[NSString stringWithFormat:@"%ld", i] characters]) {
				sum += [j integerValue];
			}
			//[StdIO puts: @"i=%ld, sum=%ld", i, sum];
			if (a <= sum && sum <= b) {
			//[StdIO puts: @"HIT"];
				Sum += i;
			}
		}
		[StdIO puts: @"%ld", Sum];
	}

	return 0;
}

Measured memory_bytes: 16024