import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; long powmod(long a, long x, long m) { long ret = 1; while (x >= 1) { if (x % 2 == 1) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; } void main() { immutable long BASE = 1000000009; immutable long MOD = 1000000097; auto powsum = new long[](10^^6+1); pragma(inline, true) { powsum[0] = 1; foreach (i; 0..10^^6) powsum[i+1] = (powsum[i] + powmod(BASE, i+1, MOD)) % MOD; } auto s = readln.split.map!(to!int); int N = s[0]; int Q = s[1]; long L, R, K; int[long] hash_table; hash_table[0] = 0; long prev = 0; foreach (i; 1..Q+1) { auto q = readln.split; if (q[0] == "!") { L = q[1].to!long; R = q[2].to!long; K = q[3].to!long; long plus = ((abs(K) * powmod(BASE, L, MOD)) % MOD * powsum[R-L-1]) % MOD; if (K >= 0) prev = (prev + plus) % MOD; else if (plus > prev) prev = (prev - plus) % MOD + MOD; else prev = (prev - plus) % MOD; if (!(prev in hash_table)) hash_table[prev] = i; } else { hash_table[prev].writeln; } } }