Pure function with static variables

1
2
3
4
5
6
7
8
9
10
int f(int l, int r) {
	static int l0 = 0;
	static int r0 = -1;
	static int s = 0;
	while(r0 < r) s += ++r0;
	while(r0 > r) s -= r0--;
	while(l0 < l) s -= l0++;
	while(l0 > l) s += --l0;
	return s;
}