#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
scalar_t__ malloc(int);
char *next(char *, short);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int main() {
  char *string, *original, *transformed;
  short n, i, j;
  size_t len;
  freopen("names.in", "r", stdin);
  freopen("names.out", "w", stdout);
  string = (char *)malloc(21);
  original = (char *)malloc(21);
  transformed = (char *)malloc(21);
  scanf("%hd", &n);
  for (i = 0; i < n; i += 1) {
    scanf("%s", string);
    if (i == 0) {
      strcpy(original, string);
      strcpy(transformed, string);
    }
    len = strlen(string);
    for (j = 1; j <= len; j += 1) {
      if (strcmp(transformed, next(string, j)) > 0) {
        strcpy(original, string);
        strcpy(transformed, next(string, j));
      }
    }
  }
  printf("%s\n", original);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1060 <freopen@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
lea    0xe50(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1060 <freopen@plt>
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe1f(%rip),%rdi
lea    -0x22(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
movw   $0x0,-0x24(%rbp)
movswl -0x24(%rbp),%eax
movswl -0x22(%rbp),%ecx
cmp    %ecx,%eax
jge    12f7 <main+0x177>
mov    -0x10(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
movswl -0x24(%rbp),%eax
cmp    $0x0,%eax
jne    1252 <main+0xd2>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
movw   $0x1,-0x26(%rbp)
movswq -0x26(%rbp),%rax
cmp    -0x30(%rbp),%rax
ja     12e2 <main+0x162>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
movswl -0x26(%rbp),%esi
call   1070 <next@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jle    12cd <main+0x14d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
movswl -0x26(%rbp),%esi
call   1070 <next@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
jmp    12d2 <main+0x152>
movswl -0x26(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x26(%rbp)
jmp    1265 <main+0xe5>
jmp    12e7 <main+0x167>
movswl -0x24(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x24(%rbp)
jmp    1209 <main+0x89>
mov    -0x18(%rbp),%rsi
lea    0xd1c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1060 <freopen@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1060 <freopen@plt>
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x15,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe21(%rip),%rdi
lea    0xe(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
cmpw   $0x0,0xe(%rsp)
jle    12df <main+0x15f>
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    1242 <main+0xc2>
cs nopw 0x0(%rax,%rax,1)
nop
shl    $0x10,%r12d
mov    %r12d,%ebp
add    $0x10000,%ebp
mov    %ebp,%r12d
sar    $0x10,%r12d
movswl 0xe(%rsp),%eax
cmp    %eax,%r12d
jge    12df <main+0x15f>
lea    0xdd2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
test   %ebp,%ebp
jne    126f <main+0xef>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1220 <main+0xa0>
mov    %rax,%r13
mov    $0x1,%r14w
jmp    129d <main+0x11d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14d
movswq %r14w,%rax
cmp    %rax,%r13
jb     1220 <main+0xa0>
movswl %r14w,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <next@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jle    1290 <main+0x110>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <next@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1290 <main+0x110>
lea    0xd38(%rip),%rdi
mov    0x10(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"names.in\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [10 x i8] c"names.out\00"
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [4 x i8] c"%hd\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i64
store i32 0, i32* %1
%9 = load i32, i32* @stdin
%10 = call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @stdout
%12 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i64 @malloc(i32 21)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %2
%15 = call i64 @malloc(i32 21)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %3
%17 = call i64 @malloc(i32 21)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i16* %5)
store i16 0, i16* %6
br label %20
20: ; preds = %70, %0
%21 = load i16, i16* %6
%22 = sext i16 %21 to i32
%23 = load i16, i16* %5
%24 = sext i16 %23 to i32
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %75
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = load i16, i16* %6
%30 = sext i16 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = load i8*, i8** %2
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %4
%37 = load i8*, i8** %2
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %39
39: ; preds = %32, %26
%40 = load i8*, i8** %2
%41 = call i64 @strlen(i8* %40)
store i64 %41, i64* %8
store i16 1, i16* %7
br label %42
42: ; preds = %64, %39
%43 = load i16, i16* %7
%44 = sext i16 %43 to i64
%45 = load i64, i64* %8
%46 = icmp ule i64 %44, %45
br i1 %46, label %47, label %69
47: ; preds = %42
%48 = load i8*, i8** %4
%49 = load i8*, i8** %2
%50 = load i16, i16* %7
%51 = call i8* @next(i8* %49, i16 signext %50)
%52 = call i64 @strcmp(i8* %48, i8* %51)
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %47
%55 = load i8*, i8** %3
%56 = load i8*, i8** %2
%57 = call i32 @strcpy(i8* %55, i8* %56)
%58 = load i8*, i8** %4
%59 = load i8*, i8** %2
%60 = load i16, i16* %7
%61 = call i8* @next(i8* %59, i16 signext %60)
%62 = call i32 @strcpy(i8* %58, i8* %61)
br label %63
63: ; preds = %54, %47
br label %64
64: ; preds = %63
%65 = load i16, i16* %7
%66 = sext i16 %65 to i32
%67 = add nsw i32 %66, 1
%68 = trunc i32 %67 to i16
store i16 %68, i16* %7
br label %42
69: ; preds = %42
br label %70
70: ; preds = %69
%71 = load i16, i16* %6
%72 = sext i16 %71 to i32
%73 = add nsw i32 %72, 1
%74 = trunc i32 %73 to i16
store i16 %74, i16* %6
br label %20
75: ; preds = %20
%76 = load i8*, i8** %3
%77 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"names.in\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [10 x i8] c"names.out\00"
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [4 x i8] c"%hd\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @stdout
%6 = tail call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = tail call i64 @malloc(i32 21)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @malloc(i32 21)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i64 @malloc(i32 21)
%12 = inttoptr i64 %11 to i8*
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i16* %1)
%14 = load i16, i16* %1
%15 = icmp sgt i16 %14, 0
br i1 %15, label %16, label %47
16: ; preds = %0, %40
%17 = phi i32 [ %43, %40 ], [ 0, %0 ]
%18 = phi i32 [ %42, %40 ], [ 0, %0 ]
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%20 = icmp eq i32 %18, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @strcpy(i8* %10, i8* %8)
%23 = call i32 @strcpy(i8* %12, i8* %8)
br label %24
24: ; preds = %21, %16
%25 = call i64 @strlen(i8* dereferenceable(1) %8)
%26 = icmp eq i64 %25, 0
br i1 %26, label %40, label %27
27: ; preds = %24, %36
%28 = phi i16 [ %37, %36 ], [ 1, %24 ]
%29 = call i8* @next(i8* %8, i16 signext %28)
%30 = call i64 @strcmp(i8* %12, i8* %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = call i32 @strcpy(i8* %10, i8* %8)
%34 = call i8* @next(i8* %8, i16 signext %28)
%35 = call i32 @strcpy(i8* %12, i8* %34)
br label %36
36: ; preds = %27, %32
%37 = add i16 %28, 1
%38 = sext i16 %37 to i64
%39 = icmp ult i64 %25, %38
br i1 %39, label %40, label %27
40: ; preds = %36, %24
%41 = shl nsw i32 %17, 16
%42 = add i32 %41, 65536
%43 = ashr exact i32 %42, 16
%44 = load i16, i16* %1
%45 = sext i16 %44 to i32
%46 = icmp slt i32 %43, %45
br i1 %46, label %16, label %47
47: ; preds = %40, %0
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %10)
ret i32 0
}