akhauriyash/Code-Regression huggingface dataset:
import numpy as np

n, m = map(int, input().split())
ab = np.zeros((n, 2))
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    ab[i, 0] = a_tmp
    ab[i, 1] = b_tmp

ab = sorted(ab, key=lambda x: x[0])

cnt = 0
yen = 0
for i in range(n):
    if m - cnt >= ab[i][1]:
        cnt += ab[i][1]
        yen += ab[i][0] * ab[i][1]
    else:
        yen += (m - cnt) * ab[i][0]
        cnt += m - cnt

        break

print(int(yen))


Measured memory_bytes: 32076
N = int(input())
if N == 0:
    print("0")
    exit()
a = []
#N = abs(N)
for i in range(1000000000):
    if N == 0:
        break
    else:
        if abs(N) % pow(2,i+1) != 0:
            a.append(1)
            N -= pow(-2,i)
        else:
            a.append(0)
        #print(N)
#print(a)
s = 0
for i in range(len(a)):
    s += a[i] * pow(10,i)
print(s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

const int M = 9;
const int N = 110000;

int V[1 << 18], W[1 << 18];
int dp[1 << M][N], sumW[N], sumV[N];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> V[i] >> W[i];
	for (int i = 1; i < min(1 << M, n + 1); i++) {
		for (int j = N - 1; j >= 0; j--) {
			dp[i][j] = max(dp[i][j], dp[i / 2][j]);
			if (j + W[i] < N) dp[i][j + W[i]] = max(dp[i][j + W[i]], dp[i / 2][j] + V[i]);
		}
		for (int j = 1; j < N; j++) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
	}
	int q; cin >> q;
	while (q--) {
		int u, L; cin >> u >> L;
		if (u < (1 << M)) cout << dp[u][L] << "\n";
		else {
			int v = u;
			vector<pair<int, int>> val;
			while (u) val.emplace_back(V[u], W[u]), u >>= 1;
			sumW[0] = sumV[0] = 0;
			int ans = 0;
			for (int i = 0; i < val.size() - M; i++) v >>= 1;
			for (int s = 0; s < (1 << val.size() - M); s++) sumW[s] = sumV[s] = 0;
			for (int s = 1; s < (1 << val.size() - M); s++) {
				int nn = __builtin_ctz(s);
				sumW[s] = max(sumW[s], sumW[s ^ (1 << nn)] + val[nn].second);
				sumV[s] = max(sumV[s], sumV[s ^ (1 << nn)] + val[nn].first);
				if (sumW[s] <= L) ans = max(ans, sumV[s] + dp[v][L - sumW[s]]);
			}
			cout << max(ans, dp[v][L]) << "\n";
		}
	}
	
	return 0;
}


Measured memory_bytes: 225272
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
vector<int> a(30);
int n,q,m;
bool check(int cnt, int m){
  if(m == 0) return true;
  if(cnt >= n) return false;
  int res = check(cnt+1,m) || check(cnt+1,m-a[cnt]);
  return res;
}
int main(){
  cin >> n;
  rep(i,n) cin >> a[i];
  cin >> q;
  rep(i,q) {
    cin >> m;
    if(check(0,m) == true) cout << "yes" << endl;
    else cout << "no" << endl;
  } 
  return 0;
}



Measured memory_bytes: 3084
l = list(input().strip())

for i in range(len(l)):
    # odd
    if i % 2 == 0:
        if l[i] not in ['R', 'U', 'D']:
            print('No')
            exit()
    else:
        if l[i] not in ['L', 'U', 'D']:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 38384
import std.stdio, std.conv, std.string, std.array, std.algorithm,
    std.numeric, std.math, std.range;

void main()
{
    long a, b, c;
    readf("%d %d %d", &a, &b, &c);

    if (a - b >= c)
    {
        writeln(0);
    }
    else
    {
        writeln(c - (a - b));
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  bool result = true;
  F0R(i, N) {
    int a;
    cin >> a;
    if (!(a & 1)) {
      if (a % 3 != 0 && a % 5 != 0) {
        result = false;
      }
    }
  }

  cout << (result ? "APPROVED" : "DENIED");
}
#endif


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,X,sum;
  cin>>N>>X;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  vector<int> D(N+1);
  D.at(0)=0;
  for(int i=0;i<N;i++){
    D.at(i+1)=D.at(i)+vec.at(i);
  }
  sum=0;
  for(int i=0;i<N+1;i++){
      if(X<D.at(i)){
        break;
      }
    sum++;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

long long n,x,y,m,M, dis,flag;

void add()
{
    dis+=((long long)(M/m))*m*2;
    if(M%m==0) {dis-=m; flag=1;}
    else {long long tmp=M; M=m; m=tmp%m;}
}

int main()
{
    scanf("%lli%lli",&n,&x);
    y=n-x; m=min(x,y); M=max(x,y); dis=flag=0;
    dis+=(x+y);
    for(;flag==0;) add();
    printf("%lli\n",dis);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<cstring>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int main()
{
	int n;cin >> n;
	
	vector<ll> v(3*n);
	
	REP(i,3*n)cin >> v[i];
	
	sort(ALL(v),greater<ll>());
	
	ll ans = 0;
	
	REP(i,2*n)
	{
		if(i%2==1)ans+=v[i];
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main()
{
	int win[4],win2[4],booby[4],ssteam,sstime;
	int n,i,j;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		for(i=1;i<4;i+=2)
		{
			win[i]=10000000;
			win2[i]=10000000;
			booby[i]=0;
		}
		for(i=0;i<n;i++)
		{
			sstime=0;
			cin >> ssteam ;
			for(j=0;j<8;j++)
			{
				int a;
				cin >> a ;
				if(j%2==0)
					sstime+=a*60;
				else
					sstime+=a;
			}
			if(win[1]>sstime)
			{
				win2[0]=win[0];
				win2[1]=win[1];
				win[0]=ssteam;
				win[1]=sstime;
			}
			else if(win2[1]>sstime)
			{
				win2[0]=ssteam;
				win2[1]=sstime;
			}
			if(booby[3]<sstime)
			{
				booby[0]=booby[2];
				booby[1]=booby[3];
				booby[2]=ssteam;
				booby[3]=sstime;
			}
			else if(booby[1]<sstime)
			{
				booby[0]=ssteam;
				booby[1]=sstime;
			}
		}
		cout << win[0] << endl;
		cout << win2[0] << endl;
		cout << booby[0] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

template<typename I>
inline bool next_combination(const I first, I k, const I last)
{
  if ((first == last) || (first == k) || (last == k))
    return false;
  I it1 = first;
  I it2 = last;
  ++it1;
  if (last == it1)
    return false;
  it1 = last;
  --it1;
  it1 = k;
  --it2;
  while (first != it1) {
    if (*--it1 < *it2) {
      I j = k;
      while (!(*it1 < *j))
        ++j;
      std::iter_swap(it1, j);
      ++it1;
      ++j;
      it2 = k;
      std::rotate(it1, j, last);
      while (last != j) {
        ++j;
        ++it2;
      }
      std::rotate(k, it2, last);
      return true;
    }
  }
  std::rotate(first, k, last);
  return false;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }
  vector<int> pm(N);
  vector<int> cb(N + 1);
  iota(pm.begin(), pm.end(), 0);
  iota(cb.begin(), cb.end(), 0);
  int ans = INF;
  do {
    do {
      int mp = 0;
      int a = 0, b = 0, c = 0;
      int n = cb[3] - cb[0];
      for (int j = cb[0]; j < cb[1]; j++)
        a += l[pm[j]];
      for (int j = cb[1]; j < cb[2]; j++)
        b += l[pm[j]];
      for (int j = cb[2]; j < cb[3]; j++)
        c += l[pm[j]];
      mp += (10 * (n - 3)); // n-3回は結合魔法
      mp += abs(A - a);
      mp += abs(B - b);
      mp += abs(C - c);
      // dump(a, b, c, n, mp);
      ans = min(ans, mp);
    } while (next_combination(cb.begin(), cb.begin() + 4, cb.end()));
  } while (next_permutation(pm.begin(), pm.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;

int main(int argc, char ** argv) {
	int a, b;
	scanf("%d%d", &a, &b);
	if(a > b) swap(a, b);
	if(a > 0 && b > 0) puts("Positive");
	else if(a < 0 && b < 0) {
		a = -a; b = -b;
		if(abs(a-b)%2) puts("Positive");
		else puts("Negative");
	}
	else puts("Zero");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

void take(vector<vector<bool>> &m, int &x, int &y, char dir, int dis){
	m[x][y] = false;
	switch(dir) {
		case'N':
			for(int i = 0; i < dis; i++){
				m[x][++y] = false;
			}
			break;
		case'S':
			for(int i = 0; i < dis; i++){
				m[x][--y] = false;
			}
			break;
		case'E':
			for(int i = 0; i < dis; i++){
				m[++x][y] = false;
			}
			break;
		case'W':
			for(int i = 0; i < dis; i++){
				m[--x][y] = false;
			}
			break;
	}
	m[x][y] = false;
}

bool calc(vector<vector<bool>> &m){
	//for(auto a: m){for(auto e : a) if(e)cerr << 1; else cerr << 0;cerr << endl;}
	for(auto a: m)for(auto e : a) if(e) return false;
	return true;
}

signed main(){
	int n;
	while(true){
		cin >> n;
		if(n == 0) break;
		vector<pair<int, int>> jewel(n);
		for(auto &&e: jewel) cin >>e.first >> e.second;
		vector<vector<bool>> m(21, vector<bool>(21,false));
		for(auto e : jewel) m[e.first][e.second] = true;

		int iter; cin >> iter;
		int x = 10, y = 10;
		for(int i = 0; i < iter; i++){
			char c;
			int dis; cin >> c >> dis;
			//cerr << x << " " << y << endl;
			take(m,x,y,c,dis);
			//cerr << x << " " << y << endl;
		}
		if(calc(m)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int A; cin >> A;
    int B; cin >> B;
    int C; cin >> C;
    int X; cin >> X;
    int Y; cin >> Y;

    int min_price = 1 << 30;
    rrep(i, 0, 100000) {
        int price = 2 * C * i; // ABピザは2枚で2C円の1セットと考える
        int a = X - i; // A ピザの枚数
        int b = Y - i; // A ピザの枚数
        if (a > 0) price += A * a; // A ピザが足りなければ買い足す
        if (b > 0) price += B * b; // B ピザが足りなければ買い足す
        min_price = min(min_price, price);
    }

    cout << min_price << endl;
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
alist = list(map(int, input().split()))
ans = 0
for i in range(N):
    sbn = max(0, alist[i] - x)
    ans += sbn
    alist[i] -= sbn

for i in range(1, N):
    val = alist[i] + alist[i-1]
    if val > x:
        sbn = val - x
        ans += sbn
        alist[i] -= sbn
print(ans)

Measured memory_bytes: 14540
#include<bits/stdc++.h>
#define pb push_back

using namespace std;
typedef long long LL;
const LL MOD = 998244353;
LL dp[3001][3001];

int main(){
	int N, S;
	scanf("%d%d", &N, &S);
	int arr[N + 1];
	for (int i = 0; i < N; i++) {
		scanf("%d", &arr[i]);
	}
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= S; j++) {
			dp[i + 1][j] += 2 * dp[i][j];
			dp[i + 1][j] %= MOD;
			if (j + arr[i] <= S) {
				dp[i + 1][j + arr[i]] += dp[i][j];
				dp[i + 1][j + arr[i]] %= MOD;
			}
		}
	}
	printf("%lld\n", dp[N][S]);
}

Measured memory_bytes: 74052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,k; cin>>n>>k;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    ll res=0;
    for(ll a=0; a<=k; a++){
        for(ll b=0; b<=k; b++){
            if(a+b>k || a+b>n) continue;
            ll x=k-a-b;
            vector<ll> memo={};
            rep(i,a) memo.push_back(v[i]);
            rep(i,b) memo.push_back(v[n-1-i]);
            sort(memo.begin(), memo.end());
            ll tmp=0;
            rep(i, a+b){
                if(i<x && memo[i]<0) continue;
                tmp+=memo[i];
            }
            chmax(res, tmp);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int sum=0;
	for(int i=0;i<s.length();i++){
        sum=sum+s[i]-48;
	}
    if (sum%9==0) cout << "Yes";
    else {
        cout<< "No";
    }

    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, n, s = 0;
  cin >> h >> n;
  for(int i = 0;i < n;i++) {
    int a;
    cin >> a;
    s += a;
  }
  cout << (h <= s ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>
#include <cstring>
#include <unordered_map>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

vector<pair<string, int>>v;
set < pair<string, int>>st;
vector<pair<int, string>>vis;
int main() {


    int N;
    cin >> N;
    rep(i, N) {
        string S;
        int P;
        cin >> S >> P;
        v.push_back({ S,P });
        st.insert({ S,P });
    }

    for (auto x : st) {
        vis.push_back({ x.second,x.first });
    }



    int j = 0;
    rep(i, N - 1) {
        if (vis[i].second != vis[i + 1].second) {
            reverse(vis.begin() + j, vis.begin() + i + 1);
            j = i + 1;
        }
        if (i == N - 2) {
            reverse(vis.begin() + j, vis.begin() + i + 2);
            j = i + 1;

        }

    }
    rep(j, N) {
        rep(i, N) {
            if (v[i].first == vis[j].second&&v[i].second == vis[j].first) {
                cout << i + 1 << endl;
            }
        }

    }



}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string str;

  cin >> str;

  for (uint32_t i = 0; i < str.size(); i++) {
    for (uint32_t j = i + 1; j < str.size(); j++) {
      if (str[i] == str[j]) {
        cout << "no" << endl;
        return 0;
      }
    }
  }

  cout << "yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};

const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

int main(){
    int n;
    while(cin >> n, n){
        vec seed(n+1);
        for(int i=0;i<n+1;i++){
            cin >> seed[i];
        }
        for(int i=0;i<n+1;i++){
            vec cpy_seed = seed;
            cpy_seed.erase(cpy_seed.begin()+i);
            for(int j=n;j>=1;j--){
                cpy_seed[j] -= cpy_seed[j-1];
            }
            set<int> s(cpy_seed.begin()+1, cpy_seed.end());
            if(s.size()==1){
                cout << seed[i] << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
int main(){
	int a,b,c,d;
	int ab,bc,ac;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	ab= a>b ? a-b : b-a;
	bc= b>c ? b-c : c-b;
	ac= a>c ? a-c : c-a;
	if(ac<=d || (ab<=d&&bc<=d))puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 128
// https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_c
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, s: chars
    };

    let mut tw = vec![0; n + 1];
    let mut tb = vec![0; n + 1];
    for i in 0..n {
        let w = tw[i];
        tw[i + 1] += w;
        if s[i] == '#' {
            tw[i + 1] += 1;
        }
    }
    for i in 0..n {
        let b = tb[n - i];
        tb[n - i - 1] += b;
        if s[n - 1 - i] == '.' {
            tb[n - i - 1] += 1;
        }
    }
    let mut best = n * 2;
    for i in 0..n + 1 {
        best = min(best, tw[i] + tb[i]);
    }

    println!("{}", best);
}


Measured memory_bytes: 8444
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int n,a;
    cin>>n;
    map<int,int>c;
    for(int i=0;i<n;i++){
        cin>>a;
        c[a]++;
    }
    int parity=0,ans=0;
    for(auto itr=c.begin();itr!=c.end();++itr){
        parity+=(itr->second-1);
        ans++;
    }
    if(parity%2==0)cout<<ans<<endl;
    else cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[1000],c=0,an=10000000;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=a[0];i<=a[n-1];i++){
		for(int j=0;j<n;j++){
			c+=pow(i-a[j],2);
		}
		if(an>c)an=c;
		c=0;
	}
	cout<<an<<endl;
}	


Measured memory_bytes: 256
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

maxa = max(src)[0]
ans = 0
for a,b in sorted(src, key=lambda x:x[1], reverse=True):
    if b <= maxa:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += (H-1)//maxa + 1
print(ans)


Measured memory_bytes: 18844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long l,r;
	cin>>l>>r;
	long t=2019;
	for(long i=l;i<=r;i++)
	{
		for(long j=i+1;j<=r;j++)
		{
			t=min(t,(i*j)%2019);
          	if(t==0)
            {
              cout<<t;
              return 0;
            }
		}
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 256
n,k,c = list(map(int,input().split()));s=[True if i=="o" else False for i in input()]
front=[0]*n;back=[0]*n;count=0

day = 0
while day < n:
  if s[day]:
    count += 1
    front[day]= 1
    day += c+1
  else:
    day += 1
    
s = s[::-1]
day = 0
while day < n:
  if s[day]:
    back[day]= 1
    day += c+1
  else:
    day += 1
back = back[::-1]
    
if count ==k:
  for i in range(n):
    if front[i] ==1 and back[i] == 1:
      print(i+1)

Measured memory_bytes: 9764
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    string str; cin >> str;

    int q; cin >> q;

    int re = 0;
    rep(_, q){
        int query = 0;
        cin >> query;
        re %= 2;
        if(query == 1){
            re++;
        }
        else{
            int f;
            char c; cin >> f >> c;
            if(f == 1){// sento
                if(re == 0){
                    str.insert(str.begin(), c);
                }
                else{
                    str.push_back(c);
                }
            }
            else{ // usiro
                if(re == 1){
                    str.insert(str.begin(), c);
                }
                else{
                    str.push_back(c);
                }

            }
        }
    }

    if(re % 2 == 1){
        reverse(ALL(str));
    }

    print(str);
    
    
    return 0;
}


Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int n, k;
	cin >> n >> k;
	if(k==1)
	{
		cout << 0 << endl;
		return 0;
	}
	long long int m = n%k;
	long long int p = abs(m - k);
	cout << min(p, m) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  double ans = 0;
  for(int i = 0; i < n; i++){
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY") ans += x;
    else ans += 380000.0 * x;
  }
    //cout << ans << endl;
  printf("%.6f\n",ans);

  return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.empty(N,dtype=np.int32)
B = np.empty(N,dtype=np.int32)
for i in range(N):
  (A[i],B[i]) = map(int,input().split())

ans = 0
for i in range(N-1,-1,-1):
  ans += B[i] - 1 - ((A[i]+ans-1) % B[i])

print(ans)

Measured memory_bytes: 13240
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S.emplace_back(s);
  }
  const vector<string> T = {"AB", "BC", "AC"};
  vector<char> res;
  function<bool(int, int, int, int)> dfs = [&](int a, int b, int c, int idx) {
    if (idx == N) return true;
    if (S[idx] == T[0]) {
      if (a == 0 && b == 0) return false;
      if (a > 0 && dfs(a - 1, b + 1, c, idx + 1)) {
        res.emplace_back('B');
        return true;
      }
      if (b > 0 && dfs(a + 1, b - 1, c, idx + 1)) {
        res.emplace_back('A');
        return true;
      }
      return false;
    }
    if (S[idx] == T[1]) {
      if (b == 0 && c == 0) return false;
      if (b > 0 && dfs(a, b - 1, c + 1, idx + 1)) {
        res.emplace_back('C');
        return true;
      }
      if (c > 0 && dfs(a, b + 1, c - 1, idx + 1)) {
        res.emplace_back('B');
        return true;
      }
      return false;
    }
    if (S[idx] == T[2]) {
      if (a == 0 && c == 0) return false;
      if (a > 0 && dfs(a - 1, b, c + 1, idx + 1)) {
        res.emplace_back('C');
        return true;
      }
      if (c > 0 && dfs(a + 1, b, c - 1, idx + 1)) {
        res.emplace_back('A');
        return true;
      }
      return false;
    }
    return false;
  };
  if (dfs(A, B, C, 0)) {
    reverse(res.begin(), res.end());
    cout << "Yes" << '\n';
    for (char c : res) {
      cout << c << '\n';
    }
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 25360
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;

using namespace std;
int main()
{
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> qq(q);
	vector<int>pt(n, k - q);
	for (int i = 0;i < q;i++) { //round
		int s; cin >> s;
		//-1してptにいれる
		pt[s - 1]++;
	}
	for (int i = 0;i < n;i++) { 
		if (pt[i] > 0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}




Measured memory_bytes: 4056
# 初期入力
N,A,B = map(int, input().split(" "))

# 青A個と赤Bを並べると、A+Bの組み合わせが何個あるか
kanz = N//(A+B) *A

# 余りを考える
saigo = min(N%(A+B),A)
print(kanz + saigo)

Measured memory_bytes: 2940
N, A, B = map(int,input().split())
S = input()
ok = A + B
passed = 0
forign = 0
for s in S:
  if s == "a":
    if passed < ok:
      passed += 1
      print("Yes")
    else:
      print("No")
  elif s == "b":
    if passed < ok and forign < B:
      print("Yes")
      passed += 1
      forign += 1
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int n1,n2,n3,n4;
  cin >> N;
  n1 = N / 1000;
  n2 = (N - n1 * 1000) / 100 ;
  n3 = (N - (n1 * 1000 + n2 * 100)) / 10;
  n4 = (N - (n1 * 1000 + n2 * 100 + n3 * 10));
  if ((n1 == n2 && n2 == n3) || (n2 == n3 && n3 == n4)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N;
	int xs, ys, xt, yt;
	int x[1005], y[1005], r[1005] = {};

	cin >> x[0] >> y[0];
	cin >> x[1] >> y[1];
	cin >> N;
	rep(i,N) cin >> x[i+2] >> y[i+2] >> r[i+2];

	// vector<pair<int,double>> edge[1005];
	// rep(i,N+2) rep(j,N+2){
	// }

	typedef pair<double,int> pdi;
	priority_queue<pdi, vector<pdi>, greater<pdi>> que;
	que.emplace(0, 0);
	double D[1005];
	Fill(D, 1e18);
	D[0] = 0;
	while( !que.empty() ){
		double d = que.top().X;
		int n = que.top().Y;
		que.pop();
		if( d > D[n] ) continue;
		if( n == 1 ) break;
		reps(i,1,N+2) if( D[i] > d ){
			double dx = x[i] - x[n];
			double dy = y[i] - y[n];
			double dist = sqrt(dx*dx + dy*dy) - r[i] - r[n];
			chmax(dist, 0.0);
			if( D[i] > d + dist ){
				D[i] = d + dist;
				que.emplace(D[i], i);
			}
		}
	}

	double ans = D[1];

	printf("%.12f\n", ans);

	return 0;
}

Measured memory_bytes: 6512
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

		var x1 = new PQ<long>(a.Take(n));
		var x2 = new PQ<long>(a.Skip(2 * n), (x, y) => -x.CompareTo(y));
		var s1 = new long[n + 1];
		var s2 = new long[n + 1];
		s1[0] = x1.Sum();
		s2[n] = x2.Sum();

		for (int i = 0, j = n - 1; i < n; i++, j--)
		{
			var v1 = a[n + i];
			if (v1 > x1.First)
			{
				s1[i + 1] = s1[i] + v1 - x1.Pop();
				x1.Push(v1);
			}
			else s1[i + 1] = s1[i];

			var v2 = a[n + j];
			if (v2 < x2.First)
			{
				s2[j] = s2[j + 1] + v2 - x2.Pop();
				x2.Push(v2);
			}
			else s2[j] = s2[j + 1];
		}
		Console.WriteLine(Enumerable.Range(0, n + 1).Max(i => s1[i] - s2[i]));
	}
}

class PQ<T> : List<T>
{
	Comparison<T> _c;
	public T First => this[0];

	public PQ(IEnumerable<T> vs = null, Comparison<T> c = null)
	{
		_c = c ?? Comparer<T>.Default.Compare;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j)
	{
		var t = this[i];
		this[i] = this[j];
		this[j] = t;
	}

	void UpHeap(int i) { for (int j; i > 0 && _c(this[(j = (i - 1) / 2)], this[i]) > 0; Swap(i, j), i = j) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count; i = j)
		{
			if (j + 1 < Count && _c(this[j], this[j + 1]) > 0) j++;
			if (_c(this[i], this[j]) > 0) Swap(i, j); else break;
		}
	}

	public void Push(T v) { Add(v); UpHeap(Count - 1); }
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 53700
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<long long> a(n);
    map<int, int> uniq;
    for(int i=0; i<n; i++){
        cin >> a[i];
        uniq[a[i]];
    }
    if(a.size() == uniq.size())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

// デバッグを消し忘れるな！！！

int main() {
    ll x, n; cin >> x >> n;
    map<ll, ll> ma;
    rep(i, 0, n){
        ll p; cin >> p;
        ma[p] = 1;
    }

    ll m = INF, y = -INF;
    Rep(i, -1, 150){
        if(ma[i]) continue;
        ll dis = llabs(x-i);
        if(dis < m){
            m = dis;
            y = i;
        }
    }
    co(y);

    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

string s;
ll dp[1000010];

int main(){
    cin>>s;
    dp[0]=1;
    if(s[0]==s[1]){
        dp[1]=1;
        dp[2]=2;
    }
    else{
        dp[1]=2;
        if(s[1]==s[2]) dp[2]=2;
        else dp[2]=3;
    }
    for(int i=3;i<=s.size();i++){
        if(s[i]!=s[i-1]) dp[i]=dp[i-1]+1;
        else dp[i]=dp[i-3]+2;
    }
    cout<<dp[s.size()-1]<<"\n";
    return 0;
}

Measured memory_bytes: 5320
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int **dmatrix(int x,int y);	//x行y列の配列を確保する.
void free_dmatrix(int **a,int x);//x行の配列を解放する

int main(void){
	int N,M,Q;
	int **S,*A,max_p=0,p;
	int i;
	char str[100000];
 
	fgets(str, sizeof(str), stdin);
	N=atoi(strtok(str," "));
	M=atoi(strtok(NULL," "));
	Q=atoi(strtok(NULL," "));

	S=dmatrix(4,Q);
	A=(int*)calloc(N,sizeof(int));

	for(i=0;i<Q;i++){
		fgets(str, sizeof(str), stdin);	
		S[0][i]=atoi(strtok(str," "));	//a
		S[1][i]=atoi(strtok(NULL," "));	//b
		S[2][i]=atoi(strtok(NULL," ")); //c
		S[3][i]=atoi(strtok(NULL," "));	//d
	}

	for(i=0;i<N;i++){//初期化
		A[i]=1;
	}

	while(1){
		int f_num=1;

		/*得点計算*/
		p=0;
		for(i=0;i<Q;i++){
			if( (A[S[1][i]-1]-A[S[0][i]-1]) == S[2][i] ) p+=S[3][i];
		}
		if(p>max_p) max_p=p;
		/*得点計算*/
		A[N-1]=A[N-1]+1;
	
		if(A[N-1]>M){
			for(i=N-2;i>=0;i--){
				if( A[i] < M){
					A[i]=A[i]+1;
					f_num=A[i];
					break;
				}
			}
			if(i<0)break;
			i++;
			for(;i<N;i++){
				A[i]=f_num;
			}
		}
	}

	printf("%d\n",max_p);


	free_dmatrix(S,4);
	free(A);

	return 0;
}

int **dmatrix(int x,int y)			//x行y列の配列を確保する.
{
	int i;
	int **a;
	if ( ( a = (int**)calloc(x,sizeof(int*)) ) == NULL){
		//printf("メモリの確保に失敗しました.\nプログラムを終了します.");
		exit(1);
	}
	for(i=0;i<x;i++) a[i]=(int*)calloc(y,sizeof(int));
	return (a);
}

void free_dmatrix(int **a,int x)//x行の配列を解放する.
{
	int i;
	for (i=0;i<x;i++) free((void*)(a[i]));	
	free((void*)(a)); 
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;

void selectionsort(vi a, int n, int cnt){
  for(int i=0; i<n; i++){
    int minj=i;
    for(int j=i; j<n; j++){
      if(a[j]<a[minj])minj=j;
    }
    if(a[i]!=a[minj]){
      int x=a[i], y=a[minj];
      a[i]=y;
      a[minj]=x;
       cnt++;
    }
  }
  rep(i, n-1)cout << a[i] << " ";
  cout << a[n-1] << endl << cnt << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, cnt=0, i, j;
  cin >> n;
  vi a(n);
  rep(i, n)cin >> a[i];
  selectionsort(a, n, cnt);

  return 0;
}


Measured memory_bytes: 3168
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL mod = 998244353;
LL N, A, B, K, ans;

// ユークリッドの互除法
LL extgcd(LL a, LL b, LL &x, LL &y)
{
	LL g = a; x = 1; y = 0;
	if (b != 0)
	{
		g = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	return g;
}

// 逆元
LL mod_inverse(LL a, LL m)
{
	LL x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

// 階乗
std::vector<LL>fact;
void mod_fact(LL n, LL m)
{
	fact.resize(n + 1);
	fact[0] = 1;
	for (LL i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i%m;
}

// nCk mod p
LL mod_comb(LL n, LL k, LL m)
{
	if (n < k) return 0;
	return fact[n] * mod_inverse(fact[k] * fact[n - k] % m, m) % m;
}

int main()
{
	in >> N >> A >> B >> K;
	mod_fact(N, mod);
	for (LL x = 0; x <= N; ++x)
	{
		LL y = (K - A * x) / B;
		if (y < 0 || N < y) continue;
		if (A*x + B * y == K)
		{
			ans += (mod_comb(N, x, mod)*mod_comb(N, y, mod)) % mod;
			ans %= mod;
		}
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

class Main {
    public static class Calculator {
        private char[] input;
        private int ptr;

        public Calculator(char[] input) {
            this.input = input;
            this.ptr = 0;
        }

        private int expr() {
            int value = term();
            while (input[ptr] == '+' || input[ptr] == '-') {
                if (input[ptr] == '+') {
                    ptr++;
                    value += term();
                } else {
                    ptr++;
                    value -= term();
                }
            }
            return value;
        }

        private int term() {
            int value = factor();
            while (input[ptr] == '*' || input[ptr] == '/') {
                if (input[ptr] == '*') {
                    ptr++;
                    value *= factor();
                } else {
                    ptr++;
                    value /= factor();
                }
            }
            return value;
        }

        private int factor() {
            int value;
            if (input[ptr] == '(') {
                ptr++;
                value = expr();
                assert input[ptr] == ')';
                ptr++;
            } else {
                value = number();
            }
            return value;
        }

        private int number() {
            StringBuilder number = new StringBuilder();
            while (Character.isDigit(input[ptr])) {
                number.append(input[ptr++]);
            }
            return Integer.valueOf(number.toString());
        }

        public int run() {
            int value = expr();
            assert input[ptr] == '=';
            return value;
        }
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            char[] input = scanner.next().toCharArray();
            System.out.println(new Calculator(input).run());
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<long long> a(x), b(y), c(z);
	cin >> a;
	cin >> b;
	cin >> c;

	vector<long long> ab;
	for(auto i : a){
		for(auto j : b){
			ab.emplace_back(i + j);
		}
	}

	sort(all(ab));
	sort(all(c));

	typedef tuple<long long,int,int> T;
	priority_queue<T> q;

	rep(i,ab.size()){
		q.emplace(ab[i] + c.back(), i, c.size() - 1);
	}

	while(k--){
		long long value;
		int index, target;

		tie(value, index, target) = q.top();
		cout << value << endl;

		q.pop();

		target--;
		if(target  >= 0){
			q.emplace(ab[index] + c[target], index, target);
		}
	}
}


Measured memory_bytes: 26732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    long long int ans = 0;
    int hmax = a[0];
    for(int i = 0; i < n; i++){
        if(a[i] < hmax){
            ans += hmax-a[i];
        }else{
            hmax = a[i];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n, m;
    for(;;) {
        cin >> n >> m;
        if(n == 0 && m == 0) return 0;
        vector<int> a(n); rep(i, n) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = 0;
        rep1(i, n - 1) {
            if(a[i] + a[0] > m) continue;
            auto res = lower_bound(a.begin(), a.end(), m - a[i] + 1);
            if(res == a.begin()) continue;
            if(res - 1 == a.begin() + i) res --;
            ans = max(ans, a[i] + *(res - 1));
        }
        if(ans == 0) {
            cout << "NONE" << endl;
        } else {
            cout << ans << endl;
        }
    }

	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class FenwickTree {
private:
    ll n;
    vector<ll> dat;
public:
    FenwickTree(ll _n): n(_n), dat(_n+1, 0) {}
    FenwickTree(ll _n, ll init): n(_n), dat(_n+1, 0) {
        for (ll i = 0; i <= _n; i++) {
            add(i, init);
        }
    }
    
    void add(ll idx, ll value) {
        for (idx++; idx <= n; idx += idx & -idx) {
            dat[idx] += value;
        }
    }

    ll query(ll l, ll r) {
        ll ans = 0;
        for (r++; r > 0; r -= r & -r) {
            ans += dat[r];
        }
        for (; l > 0; l -= l & -l) {
            ans -= dat[l];
        }
        return ans;
    }
};

bool comp(pair<ll,ll> a, pair<ll,ll> b)
{
    return a.second - a.first < b.second - b.first;
}

int main(void)
{
    ll n, m;
    cin >> n >> m;

    vector< pair<ll,ll> > A(n);
    for (ll i = 0; i < n; i++) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(), A.end(), comp);

    FenwickTree ft(m+1);

    ll idx = 0;
    for (ll d = 1; d < m+1; d++) {
        for(; idx < n && A[idx].second - A[idx].first < d; idx++) {
            ft.add(A[idx].first, 1);
            ft.add(A[idx].second+1, -1);
        }
        ll count = n - idx;
        for (ll i = 0; i < m+1; i += d) {
            count += ft.query(0, i);
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 6400
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
//#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(void)
{
    int a, b, c;

    cin >> a >> b >> c;
    if(a == b && b == c && a == c) {
        cout << "No" << endl;
        return 0;
    }
    if(a != b && b != c && a != c) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256