import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; 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 MOD = 1234567891; immutable long BASE = uniform(0, MOD); 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; } } }