Language: C

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define pii pair<int, int>
#define MP make_pair
#define ls i << 1
#define rs ls | 1
#define md (ll + rr >> 1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define mod 1000000007
#define inf 0x3f3f3f3f
#define Pi acos(-1.0)
#define pb push_back
#define eps 1e-12
#define N 200020
#define M 400020

int pw[N];
char s[N];

struct node {
	int c1, c2, n;
	vector<int> a;
	node() {
		n = 0;
	}

	void simple_mul() {
		vector<int> x;
		x.pb(a[0]);
		if(a.size() > 1) x.pb(a[1]);
		for(int i = 2; i < n; ++i) {
			if(a[i] == -3 && i >= 2 && i + 2 < n) {
				x[x.size() - 1] = 1LL * x[x.size() - 1] * a[i + 1] % mod;
				i++;
			}
			else x.pb(a[i]);
		}
		a = x;
		n = x.size();
	}
			

	void simple_add() {
		vector<int> x;
		x.pb(a[0]);
		if(a.size() > 1) x.pb(a[1]);
		for(int i = 2; i < n; ++i) {
			if((a[i] == -2 || a[i] == -1) && i >= 4 && i + 4 < n) {
				int t = x.size() - 1;
				if(x[t - 1] == -2) a[i] = -3 - a[i];
				if(a[i] == -2) x[t] = (x[t] + mod - a[i + 1]) % mod;
				else x[t] = (x[t] + a[i + 1]) % mod;
				i++;
			}
			else x.pb(a[i]);
		}
		a = x;
		n = x.size();
	}

	void simple() {
		simple_mul();
		simple_add();
	}
	void input() {
		scanf("%s", s);
		c1 = c2 = 0;

		a.clear();
		int len = strlen(s);
		for(int i = 0, j; i < len; i = j + 1) {

			j = i;
			if(s[i] == '+') a.pb(-1);
			else if(s[i] == '-') a.pb(-2);
			else if(s[i] == '*') a.pb(-3);
			else {
				int x = 0;
				while(j < len && s[j] >= '0' && s[j] <= '9') {
					x = (1LL * x * 10 + s[j] - 48) % mod;
					++j;
				}
				--j;
				a.pb(x);
			}
		}
		n = a.size();
		if(s[0] >= '0' && s[0] <= '9') {
			c1 = 0;
			for(int i = 0; i < len && s[i] >= '0' && s[i] <= '9'; ++i, ++c1);
		}
		else c1 = -1;
		if(s[len - 1] >= '0' && s[len - 1] <= '9') {
			c2 = 0;
			for(int i = len - 1; i >= 0 && s[i] >= '0' && s[i] <= '9'; --i, ++c2);
		}
		else c2 = -1;
	}
	void calc_mul() {
		vector<int> x;
		for(int i = 0; i < n; ++i) {
			if(a[i] == -3) {
				int t = x.size() - 1;
				x[t] = 1LL * x[t] * a[i + 1] % mod;
				++i;
			}
			else x.pb(a[i]);
		}
		a = x;
		n = a.size();
	}
	int calc() {
		calc_mul();
		int ret = a[0];
		for(int i = 1; i < n; i += 2) {
			if(a[i] == -2) ret = (ret + mod - a[i + 1]) % mod;
			else ret = (ret + a[i + 1]) % mod;
		}
		return ret;
	}

	void output() {
		printf("c1 %d c2 %d n %d\n", c1, c2, n);
		for(int i = 0; i < n; ++i) printf("%d ", a[i]); puts("");
	}

};
node add(node &t1, node &t2) {
	if(t1.n == 0) return t2;
	if(t2.n == 0) return t1;
	node ret;
	ret.c1 = t1.c1, ret.c2 = t2.c2;
	if(t1.c2 >= 1 && t2.c1 >= 1) {
		if(t1.n == 1) {
			ret.c1 += t2.c1;
		}
		if(t2.n == 1) ret.c2 += t1.c2;
		for(int i = 0; i < t1.n; ++i) {
			ret.a.pb(t1.a[i]);
		}
		ret.a[t1.n - 1] = (1LL * ret.a[t1.n - 1] * pw[t2.c1] + t2.a[0]) % mod;
		
		for(int i = 1; i < t2.n; ++i) 
			ret.a.pb(t2.a[i]);
	}
	else {
		for(int i = 0; i < t1.n; ++i) {
			ret.a.pb(t1.a[i]);
		}
		for(int i = 0; i < t2.n; ++i) {
			ret.a.pb(t2.a[i]);
		}
	}
	ret.n = ret.a.size();
	ret.simple();
	return ret;
}

node qpow(node x, int k) {
	node ret;
	while(k) {
		
		if(k & 1) ret = add(ret, x);
		k >>= 1;
		x = add(x, x);
		
	}
	return ret;
}
int n;

int main() {
	
	pw[0] = 1;
	for(int i = 1; i < N; ++i) pw[i] = 1LL * pw[i - 1] * 10 % mod;
	scanf("%d", &n);
	node t;
	for(int i = 1; i <= n; ++i) {
		int k;
		node v;
		scanf("%d", &k);
		v.input();
		v = qpow(v, k);
		t = add(t, v);
	}
	printf("%d\n", t.calc());
	return 0;
}



	

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.