Problem:
RSQ and RUQ

Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:

$update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.

$getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.

Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.

Input

$n$ $q$
$query_1$
$query_2$
:
$query_q$

In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format:

0 $s$ $t$ $x$

or

1 $s$ $t$

The first digit represents the type of the query. '0' denotes $update(s, t, x)$
and '1' denotes $find(s, t)$.

Output

For each $getSum$ query, print the sum in a line.

Constraints

$1 ≤ n ≤ 100000$

$1 ≤ q ≤ 100000$

$0 ≤ s ≤ t < n$

$-1000 ≤ x ≤ 1000$

Sample Input 1

6 7
0 1 3 1
0 2 4 -2
1 0 5
1 0 1
0 3 5 3
1 3 4
1 0 5

Sample Output 1

-5
1
6
8

Solution in Ruby (judge verdict: Accepted)

def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class LazySegTree
  attr_accessor:node,:lazy,:n,:lazyF
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    @node=array(2*@n-1,1,0)
    @lazy=array(2*@n-1,1,0)
    @lazyF=array(2*@n-1,1,false)
  end


  def lazy_eval(i,l,r)
    if @lazyF[i]
      @node[i]=@lazy[i]
      if r-l>1
        @lazy[i*2+1]=@lazy[i]/2
        @lazy[i*2+2]=@lazy[i]/2
        @lazyF[i*2+1]=true
        @lazyF[i*2+2]=true
      end
      @lazy[i]=0
      @lazyF[i]=false
    end
  end
  def update(s,t,x,i,l,r)
    lazy_eval(i,l,r)
    return if r<=s or t<=l
    if s<=l and r<=t
      @lazyF[i]=true
      @lazy[i]=x*(r-l)
      lazy_eval(i,l,r)
    else
      mid=(l+r)/2
      update(s,t,x,i*2+1,l,mid)
      update(s,t,x,i*2+2,mid,r)
      @node[i]=@node[i*2+1]+@node[i*2+2]
    end
  end

  def getSum(s,t,i,l,r)
    return 0 if r<=s or t<=l
    lazy_eval(i,l,r)
    return @node[i] if s<=l and r<=t
    mid=(l+r)/2
    leaf_l=getSum(s,t,i*2+1,l,mid)
    leaf_r=getSum(s,t,i*2+2,mid,r)
    return leaf_l+leaf_r
  end
end

n,q=get_i
lst=LazySegTree.new(n)
q.times do
  qu=get_i
  if qu[0].zero?
    lst.update(qu[1],qu[2]+1,qu[3],0,0,lst.n)
  else
    puts lst.getSum(qu[1],qu[2]+1,0,0,lst.n)
  end
end