#!/usr/bin/env python #coding:utf8 def read(): return map(int, raw_input().split()) def work((A, B, C, D)): print A * B * C % D if __name__ == "__main__": work(read())