mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    a, b, c, d = map(int, input().split())
    N = int(input())
    x = y = pow(2, (N+1) // 2, mod)
    if 0 <= N%8 < 3:
        x *= b
    elif 4 <= N%8 < 7:
        x *= -a
    else:
        x = 0
    if N%8 == 0 or 6 <= N%8:
        y *= d
    elif 2 <= N%8 <= 4:
        y *= -c
    else:
        y = 0
    print((x + y)%mod)


if __name__ == '__main__':
    main()