import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.PriorityQueue; import java.util.TreeMap; public class Main { static ContestScanner in;static Writer out;public static void main(String[] args) {try{in=new ContestScanner();out=new Writer();Main solve=new Main();solve.solve(); in.close();out.flush();out.close();}catch(IOException e){e.printStackTrace();}} static void dump(int[]a){for(int i=0;i0){if((n&1)==1)r*=a;a*=a;n>>=1;}return r;} static String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');} static void sort(int[]a){m_sort(a,0,a.length,new int[a.length]);} static void sort(int[]a,int l){m_sort(a,0,l,new int[l]);} static void sort(int[]a,int l,int[]buf){m_sort(a,0,l,buf);} static void sort(int[]a,int s,int l,int[]buf){m_sort(a,s,l,buf);} static void m_sort(int[]a,int s,int sz,int[]b) {if(sz<7){for(int i=s;is&&a[j-1]>a[j];j--)swap(a, j, j-1);return;} m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz; while(la[r])b[idx++]=a[r++];else b[idx++]=a[l++];} while(rs&&a[j-1]>a[j];j--)swap(a, j, j-1);return;} m_sort(a,s,sz/2,b);m_sort(a,s+sz/2,sz-sz/2,b);int idx=s;int l=s,r=s+sz/2;final int le=s+sz/2,re=s+sz; while(la[r])b[idx++]=a[r++];else b[idx++]=a[l++];} while(rv)r=m-1;else{l=m+1;s=m;}}return s;} static int binarySearchSmallerMax(int[]a,int v,int l,int r) {int s=-1;while(l<=r){int m=(l+r)/2;if(a[m]>v)r=m-1;else{l=m+1;s=m;}}return s;} @SuppressWarnings("unchecked") static List[]createGraph(int n) {List[]g=new List[n];for(int i=0;i();return g;} void solve() throws NumberFormatException, IOException{ int n = in.nextInt(); int[] s = new int[n]; int[] c = new int[n]; for(int i=0; i0; i>>=1) tree[i] = (tree[i]+x)%mod; } } class LazySegTree{ // benchmark: (n=10^5, q=2*10^5) * 100try --- 13772ms ( 137ms/try) // : (n=10^6, q=2*10^6) * 10try --- 18512ms (1851ms/try) SegTree st; final long mod = 1000000007; long[] value; long[] hold; int length, n, bits; public LazySegTree(int n) { for(length=1; length[] node; int[] child; int[] len; int n; int size; int[] s, c; HLD_light(int n, int[] s, int[] c) { node = new List[n]; for(int i=0; i(); init(n); this.s = s; this.c = c; } public HLD_light(List[] node) { this.node = node; init(node.length); } void init(int n){ this.n = n; child = new int[n]; len = new int[n]; Arrays.fill(child, -1); st = new int[n]; pst = new int[n]; } void edge(int v, int u){ node[v].add(u); node[u].add(v); } int[] st, pst; void decomp(int root){ boolean[] back = new boolean[n]; int sp = 0; pst[0] = root; st[sp++] = root; size = node[root].size(); while(sp>0){ int p = st[--sp]; int par = pst[sp]; boolean b = back[sp]; if(b){ if(len[p]+1>len[par] && p!=root){ child[par] = p; len[par] = len[p]+1; } }else{ len[p] = 1; back[sp++] = true; if(node[p].size()>1 && p!=root) size += node[p].size()-2; for(int v: node[p]){ if(v==par) continue; st[sp] = v; pst[sp] = p; back[sp] = false; sp++; } } } } int[][] vertex; LazySegTree[] lst; int[] idx, pidx; int[] parent, dep; void graph(int root){ int[] isp = new int[size]; idx = new int[n]; pidx = new int[n]; int number = 0; vertex = new int[size][]; // lst = new LazySegTree[size]; parent = new int[size]; dep = new int[size]; int sp = 0; pst[0] = root; st[sp++] = root; vertex[0] = new int[len[root]]; isp[0]++; while(sp>0){ int p = st[--sp]; int par = pst[sp]; for(int v: node[p]){ if(v==par || v==child[p]) continue; idx[v] = ++number; pidx[v] = isp[number]; dep[number] = dep[idx[p]]+1; parent[number] = p; // child to parent vertex[number] = new int[len[v]]; vertex[number][isp[number]++] = v; st[sp] = v; pst[sp] = p; sp++; } if(child[p]>=0){ int cld = child[p]; idx[cld] = idx[p]; pidx[cld] = isp[idx[cld]]; vertex[idx[cld]][isp[idx[cld]]++] = cld; st[sp] = cld; pst[sp] = p; sp++; } } lst = new LazySegTree[size]; for(int i=0; idep[idx[l]]){ h = h^l; l = h^l; h = h^l; } lst[idx[l]].add(0, pidx[l], z); l = parent[idx[l]]; } if(pidx[h] > pidx[l]){ h = h^l; l = h^l; h = h^l; } lst[idx[h]].add(pidx[h], pidx[l], z); } final long mod = 1000000007; int sum(int h, int l){ long res = 0; while(idx[h] != idx[l]){ if(dep[idx[h]]>dep[idx[l]]){ h = h^l; l = h^l; h = h^l; } res = (res+lst[idx[l]].sum(0, pidx[l]))%mod; l = parent[idx[l]]; } if(pidx[h] > pidx[l]){ h = h^l; l = h^l; h = h^l; } return (int)((res + lst[idx[h]].sum(pidx[h], pidx[l]))%mod); } } @SuppressWarnings("serial") class MultiSet extends HashMap{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);} public MultiSet merge(MultiSet set) {MultiSets,l;if(this.size()e:s.entrySet())l.add(e.getKey(),e.getValue());return l;} } @SuppressWarnings("serial") class OrderedMultiSet extends TreeMap{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);} public OrderedMultiSet merge(OrderedMultiSet set) {OrderedMultiSets,l;if(this.size(){ int a,b;final int hash;Pair(int a,int b){this.a=a;this.b=b;hash=(a<<16|a>>16)^b;} public boolean equals(Object obj){Pair o=(Pair)(obj);return a==o.a&&b==o.b;} public int hashCode(){return hash;} public int compareTo(Pair o){if(a!=o.a)return a