public static int getTotalTime(List<Character> tasks, int cooldown) {
		// time for the events in the window
		int[] ci=new int[cooldown];
		// characters in the window
		char[] cc = new char[cooldown];
		// shift is the number of hours one needs to move the window
		// ct the time for the current task
		int ct=0, shift=1;
		Arrays.fill(cc, ' ');
		for (Character c:tasks) {
			shift=1;
			for (int i=cooldown-1;i>=0;--i) {
				// delay happens
				if (cc[i]==c) {
					int tmp=ci[i]+cooldown+1;
					shift = tmp-ct;
					ct=tmp;
					break;
				}
			}
			// no delay happens
			if (shift==1)++ct;
			// shift the window, override
			for (int j=shift; j<ci.length;++j) {
				ci[j-shift]=ci[j];
				cc[j-shift]=cc[j];
			}
			// fill the right side of the window
			if (shift<ci.length)
				for (int j=ci.length-shift;j<ci.length-1;++j) {
					ci[j]=ci[j-1]+1;
					cc[j]=' ';
				}
			else Arrays.fill(cc, ' ');
			ci[cooldown-1]=ct;
			cc[cooldown-1]=c;
		}

		return ct;
	}