The C# Program: E_lock/Lock.cs

  1 using System;
  2 
  3 class Lock {
  4    public static void Main (String[] args) {
  5       input: for (int ds=1; /**/; ds++) {
  6          string[] tokens = Console.ReadLine().Split(' ');
  7          int n = int.Parse(tokens[0]);
  8          if (n==0) break;
  9          int t1 = int.Parse(tokens[1]);
 10          int t2 = int.Parse(tokens[2]);
 11          int t3 = int.Parse(tokens[3]);
 12          int answer = 4*n-1 + ((t2-t1+n) % n) + ((t2-t3+n) % n);
 13          Console.WriteLine(answer);
 14       }
 15    }
 16 }