akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<cstdio>
using namespace std;

struct P
{
  int s,e;
  P(int s,int e):s(s),e(e){}
};

void shuffle(vector<P>& vec,int x,int y,int n)
{
  vector<P> ins;
  for(int i=0;i<vec.size();i++)
    {
      if(vec[i].e <= x)
	{
	  vec[i].s += (n-x),vec[i].e += (n-x);
	}
      else if(vec[i].s <= x && vec[i].e <= y)
	{
	  ins.push_back(P(x+1,vec[i].e));
	  ins[ins.size()-1].s += (n-y)-x,ins[ins.size()-1].e += (n-y)-x;
	  vec[i].e = x;
	  vec[i].s += (n-x),vec[i].e += (n-x);
	}
      else if(vec[i].s <= x && vec[i].e  > y)
	{
	  ins.push_back(P(vec[i].s,x));
	  ins[ins.size()-1].s += (n-x),ins[ins.size()-1].e += (n-x);
	  ins.push_back(P(x+1,y));
	  ins[ins.size()-1].s += (n-y)-x,ins[ins.size()-1].e += (n-y)-x;
	  vec[i].s = y+1;
	  vec[i].s -= y,vec[i].e -= y;
	}
      else if(vec[i].s  > x && vec[i].e <= y)
	{
	  vec[i].s += (n-y)-x,vec[i].e += (n-y)-x;
	}
      else if(vec[i].s  > x && vec[i].s <= y && vec[i].e  > y)
	{
	  ins.push_back(P(vec[i].s,y));
	  ins[ins.size()-1].s += (n-y)-x, ins[ins.size()-1].e += (n-y)-x;
	  vec[i].s = y+1;
	  vec[i].s -= y,vec[i].e -= y;
	}
      else if(vec[i].s  > y)
	{
	  vec[i].s -= y,vec[i].e -= y;
	}
      else 
	assert(false);
    }
for(int i=0;i<ins.size();i++)
  vec.push_back(ins[i]);
}

int main()
{
  int n;
  while(scanf("%d",&n),n)
    {
      int m;
      scanf("%d",&m);
      int p,q,r;
      scanf("%d %d %d",&p,&q,&r);
      vector<P> vec;
      vec.push_back(P(1,r));

      for(int i=0;i<m;i++)
	{
	  int x,y;
	  scanf("%d %d",&x,&y);
	  shuffle(vec,x,y,n);
	}
   

      int cnt = 0;
      for(int i=0;i<vec.size();i++)
	{
	  if(vec[i].s > q || vec[i].e < p)
	    continue;
	  cnt += min(vec[i].e,q) - max(vec[i].s,p)+1;
	  /*
	  cout << "!p: " <<vec[i].s<<"!q : " <<vec[i].e << endl;
	  cout << "p : " << p << " q : " << q << endl;
	  if(vec[i].s == vec[i].e && p <= vec[i].s && vec[i].e <= q)
	    {
	      cout << "P1" << endl;
	      cnt += 1;
	    }
	  else if(vec[i].s <= p && q <= vec[i].e)
	    {
	      cout << "P2" << endl;
	      cnt += q-p + (vec[i].s == p?1:0) + (vec[i].e == q?1:0);
	    }
	  else if(p <= vec[i].s && vec[i].e <= q)
	    {
	      cout << "P3" << endl;
	      cnt += vec[i].e-vec[i].s+1;
	    }
	  else if(vec[i].s <= p && vec[i].e >= p)
	    {
	      cout << "P4" << endl;
	      cnt += vec[i].e-p+ (vec[i].s == p?1:0) + (vec[i].e == p?1:0);
	    }
	  else if(vec[i].s <= q && vec[i].e >= q)
	    {
	      cout << "P5" << endl;
	      cnt += q-vec[i].s+ (vec[i].s == q?1:0) + (vec[i].e == q?1:0);
	    }
	  */
	  // cout << "cnt = " << cnt << endl;
	}
      cout << cnt << endl;
    }
  return 0;
}

Measured memory_bytes: 1312
#include <stdio.h>

typedef struct{
    int dice[7];
}dice;



int main(void){
    
  dice dice1;
	int tmp;
	int a, b, c, d, e, f;
	//char houkou;
	char str[100];
	//int len;
	int i = 0;

	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);

	dice1.dice[1] = a;
	dice1.dice[2] = b;
	dice1.dice[3] = c;
	dice1.dice[4] = d;
	dice1.dice[5] = e;
	dice1.dice[6] = f;

	scanf("%s", str, 100);
	//len = strlen(str);

	while (str[i] != '\0') {



		switch (str[i]) {
		case 'W':
			tmp = dice1.dice[4];
			dice1.dice[4] = dice1.dice[1];
			dice1.dice[1] = dice1.dice[3];
			dice1.dice[3] = dice1.dice[6];
			dice1.dice[6] = tmp;
			break;

		case 'N':
			tmp = dice1.dice[5];
			dice1.dice[5] = dice1.dice[1];
			dice1.dice[1] = dice1.dice[2];
			dice1.dice[2] = dice1.dice[6];
			dice1.dice[6] = tmp;
			break;

		case 'E':
			tmp = dice1.dice[3];
			dice1.dice[3] = dice1.dice[1];
			dice1.dice[1] = dice1.dice[4];
			dice1.dice[4] = dice1.dice[6];
			dice1.dice[6] = tmp;
			break;

		case 'S':
			tmp = dice1.dice[2];
			dice1.dice[2] = dice1.dice[1];
			dice1.dice[1] = dice1.dice[5];
			dice1.dice[5] = dice1.dice[6];
			dice1.dice[6] = tmp;
			break;
		}
		i++;
	}
	printf("%d\n", dice1.dice[1]);
  
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

vector<vector<int>> v;
int ans=0;
ull all=0;

void dfs(ull &visit,int cnt) {
    visit += 1LL << cnt;
    if (visit == all) {
        ans++;
        return;
    }
    for(auto x: v[cnt]) {
        if ((visit & (1LL << x)) == 0) {
            ull vi = visit;
            dfs(vi,x);
        }
    }
    return;
}

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    v.resize(n);
    REP(i,n) all += 1ULL << i;
    REP(i,m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    ull vi = 0;
    dfs(vi,0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
int a[333][333];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	int ans=n;
	int lo=1; int hi=n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
			a[i][j]--;
		}
	}
	while(lo<=hi)
	{
		int mid=(lo+hi)>>1;
		//cerr<<mid<<endl;
		vector<vi> vec(n);
		for(int i=0;i<n;i++)
		{
			for(int j=m-1;j>=0;j--)
			{
				vec[i].pb(a[i][j]);
			}
		}
		bool pos=1;
		bool used[311];
		memset(used,0,sizeof(used));
		int del=0;
		while(1)
		{
			int cnt[311];
			memset(cnt,0,sizeof(cnt));
			for(int i=0;i<n;i++)
			{
				//cerr<<i<<' '<<vec[i].empty()<<endl;
				while(!vec[i].empty()&&used[vec[i].back()]) vec[i].pop_back();
				if(!vec[i].empty())
				{
					//cerr<<vec[i].back()<<'\n';
					cnt[vec[i].back()]++;
				}
				//cerr<<i<<' '<<vec[i].empty()<<endl;
			}
			bool good=1;
			for(int i=0;i<m;i++)
			{
				if(cnt[i]>mid)
				{
					used[i]=1;
					del++;
					good=0;
				}
			}
			if(del>=m)
			{
				pos=0;
				break;
			}
			if(good) break;
			//cerr<<"HERE\n";
		}
		if(del>=m) pos=0;
		if(pos)
		{
			ans=mid;
			hi=mid-1;
		}
		else
		{
			lo=mid+1;
		}
		//cerr<<lo<<' '<<hi<<'\n';
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1328
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int x = 0, max=0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i) == 'I'){
		   		x += 1;
				//System.out.println("added");
		   }else{
	   			x -= 1;
				//System.out.println("sub");
		   }
			if(max < x){
		 		max = x;
			}	
		}
		System.out.println(max);

	}
}	


Measured memory_bytes: 23764
#include <stdio.h>

int main(void) {
int a,b;
scanf("%5d",&a);
scanf("%5d",&b);
 if(a>b){
   printf("a > b\n",a,b);
 }
 if(a<b){
   printf("a < b\n",a,b);
 }
 if(a==b){
   printf("a == b\n",a,b);
 }
}


Measured memory_bytes: 2624
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
l = [0]*n

for i in A:
    l[i-1] += 1

for i in l:
    print(i)

Measured memory_bytes: 32176
K, N = map(int, input().split())
A_list = list(map(int, input().split()))

distance_list = []
for i, j in zip(A_list[0:-1], A_list[1:]):
    distance_list.append(j - i)
    
max_distance = max(distance_list)
distance_last_to_first = K - A_list[-1] + A_list[0]
max_distance = max(max_distance, distance_last_to_first)

ans = K - max_distance
print(ans)

Measured memory_bytes: 26060
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int cnt[101];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n;
	string s;
	cin>>n>>s;
	cnt[0]=(s[0]=='('?1:-1);
	fo(i,1,n)cnt[i]=cnt[i-1]+(s[i]=='('?1:-1);
	int x=0;
	fo(i,0,n)x=min(x,cnt[i]);
	int y=-x;
	fo(i,0,y)cout<<'(';
	cout<<s;
	fo(i,0,cnt[n-1]+y)cout<<')';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	int d = 0;
	rep(i,0,n) {
		cin >> a[i];
		d ^= a[i];
	}
	rep(i,0,n) {
		cout << (d ^ (a[i])) << ' ';
	}
	cout << endl;
	
}

Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;
const long long INF = 1LL<<60;

int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    // 2017-like 数かどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    // 累積和
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    // クエリ処理
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


signed main(){
    int m;
    while(cin >> m, m){
        vector<PII> v(m);
        rep(i, 0, m) cin >> v[i].first >> v[i].second;
        int n;
        cin >> n;
        vector<PII> u(n);
        map<PII, bool> mp;
        rep(i, 0, n) cin >> u[i].first >> u[i].second, mp[u[i]] = true;
        int dx = -1, dy = -1;
        rep(i, 0, n){
            dx = u[i].first-v[0].first;
            dy = u[i].second-v[0].second;
            bool f = true;
            rep(j, 0, m) if(!mp[make_pair(v[j].first+dx, v[j].second+dy)]) f = false;
            if(f) break;
        }
        cout << dx << ' ' << dy << endl;
    }

    return 0;
}


Measured memory_bytes: 10928
#include <iostream>
#include <string>
using namespace std;

int main(){
	int am[9],pm[9];
	string str[9];
	for(int i=0;i<9;i++)cin>>str[i]>>am[i]>>pm[i];
	for(int i=0;i<9;i++)cout<<str[i]<<' '<<am[i]+pm[i]<<' '<<am[i]*200+pm[i]*300<<endl;
	return 0;
}

Measured memory_bytes: 1204
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto F = new long[](10^^6*2+10);
    auto RF = new long[](10^^6*2+10);

    long pow(long x, long n) {
        long y = 1;
        while (n) {
            if (n%2 == 1) y = (y * x) % P;
            x = x^^2 % P;
            n /= 2;
        }
        return y;
    }

    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;

    auto xy = readln.split.to!(long[]);
    auto X = xy[0];
    auto Y = xy[1];
    auto a = 2*X - Y;
    auto b = 2*Y - X;
    if (a < 0 || b < 0 || a%3 != 0 || b%3 != 0) {
        writeln(0);
        return;
    }
    a /= 3;
    b /= 3;

    if (a == 0 || b == 0) {
        writeln(1);
        return;
    }

    writeln(((F[a+b] * RF[a]) % P * RF[b]) % P);
}

Measured memory_bytes: 34556
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


int p,q;



int main(){
	while(cin>>p>>q){
		p%=q;
		map<int,int> m;
		string s;
		for(int i=0; p!=0; i++){
			if(m[p]>0){
				rep(j,m[p]-1){
					s+=' ';
				}
				for(int j=m[p]; j<=i; j++){
					s+='^';
				}
				cout<<endl;
				cout<<s;
				break;
			}
			else{
				m[p]=i+1;
			}
			p*=10;
			cout<<p/q;
			p%=q;
			//cout<<p<<endl;
			//cout<<p<<endl;

		}
		cout<<endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    bool ok = false;
    string s;
    cin >> s;
    int y = 0,m = 0,d = 0;
    rep(i,4){
        y += pow(10,3-i)*(s[i]-'0');
    }
    rep(i,5,7){
        m += pow(10,6-i)*(s[i]-'0');
    }
    rep(i,8,10){
        d += pow(10,9-i)*(s[i]-'0');
    }
    y = y*10000+m*100+d;
    if (y > 20190430) PRINT("TBD");
    else PRINT("Heisei");
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

#define double long double

typedef pair <double, double> ii;

double dist(const ii &a, const ii &b) {
  return (double) sqrt((a.first - b.first) * (a.first - b.first) +
              (a.second - b.second) * (a.second - b.second));
}

int main() {
  vector <ii> vec;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, y});
  }
  sort(vec.begin(), vec.end());
  double ans = 0;
  int fac = 1;
  for (int i = 1; i <= n; i++) fac *= i;
  do {
    double here = 0.0;
    for (int i = 1; i < n; i++) {
      here += dist(vec[i - 1], vec[i]);
    }
    ans += here;
  } while (next_permutation(vec.begin(), vec.end()));
  cout << fixed << setprecision(12) << ans / (double) fac << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
tmp = 1
flg = 1
if 0 in a:
    print(0)
else:
    for i in a:
        tmp *= i
        if tmp > 10**18:
            flg = 0
            break
    if flg:
        print(tmp)
    else:
        print(-1)


Measured memory_bytes: 84864
#![allow(clippy::many_single_char_names)]
#[allow(unused_imports)]
use proconio::{
    input,
    marker::{Chars, Usize1},
};

fn main() {
    input!(n: usize, a: [u64; n]);
    let mut max = 0;
    let mut ans = 0;
    for x in a {
        if x < max {
            ans += max - x;
        } else {
            max = x;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5540
#include<stdio.h>
#define INF 100100100
int t[1000]={0};
int v[1000]={0};
int f1(int x,int i){
	if(x<=2*t[i]){
		return 2*v[i]-x+2*t[i];
	}
	return INF;
}
int f2(int x,int i){
	if(x>=2*t[i+1]){
		return 2*v[i]+x-2*t[i+1];
	}
	return INF;
}
int main(void){
	int n;
	int i,j,y,y1;
	long sum=0;
	long tmax=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&t[i]);
	}
  for(i=1;i<=n;i++){
    t[i]+=t[i-1];
  }
	for(i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	y1=0;
	for(i=0;i<=2*t[n];i++){
		y=INF;
		for(j=0;j<n;j++){
			if(f1(i,j)<y) y=f1(i,j);
			if(f2(i,j)<y) y=f2(i,j);
		}
		if(i<y) y=i;
		if(2*t[n]-i<y) y=2*t[n]-i;
      int k=0,flg=0;
      while(flg*2<i){
        k++;
        flg=t[k];
      }
      //if(k>0&&t[k-1]==i&&2*v[k]<y) y=2*v[k];

      if(k>0&&2*v[k-1]<y) y=2*v[k-1];
      //printf("%d\n",v[k-1]);
		//if(2*v[k-1]<y) y=2*v[k-1];
      //printf("%d %d\n",y,i);
            //printf("%d %d %d\n",v[k-1],f1(i,1),y);
		sum+=y1+y;
		y1=y;
	}
	printf("%f\n",sum/8.0);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;

int main(){
    cin >> n;

    int cou = log2(n);
    if((int)log2(n + 1) > cou){
        cou ++;
    }

    cout << cou << endl;
}


Measured memory_bytes: 3276
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;

    int sum1, sum2, sum3;
    for (int i = 0; i < a+1; i++) {
        sum1 = 500 * i;
        for (int j = 0; j < b+1; j++) {
            sum2 = 100 * j;
            for (int k = 0; k < c+1; k++) {
                sum3 = sum1 + sum2 + 50 * k;
                if (sum3 == x)count++;
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define mkp make_pair
#define cerr if (0) cerr

const int N = 1e5 + 7, INF = 1e15;

int a[N], up[N];

void solve() {
    int n; cin >> n;
    loop(i, n + 1)
        cin >> a[i];
    if (n == 0) {
        cout << (a[0] == 1 ? 1 : -1); return;
    }
    if (a[0] != 0)
        no;
    up[0] = 1;
    loop1(i, n) {
        up[i] = min((up[i - 1] - a[i - 1]) * 2, INF);
        if (up[i] < a[i])
            no;
    }
    up[n] = a[n];
    for (int i = n - 1; i >= 0; --i)
        up[i] = min(up[i], up[i + 1] + a[i]);
    int ans = 0;
    loop(i, n + 1)
        ans += up[i];
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


Measured memory_bytes: 5112
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ull = unsigned long long;

int main(){
	unsigned N;
	scanf("%u", &N);
	vector<unsigned> adjacency_list[N];
	int adjacency_v[N];
	memset(adjacency_v, 0, sizeof adjacency_v);
	for (int i = 0; i < N - 1; ++i){
		unsigned tmp1, tmp2;
		scanf("%u %u", &tmp1, &tmp2);
		tmp1--, tmp2--;
		adjacency_list[tmp1].push_back(tmp2);
		adjacency_list[tmp2].push_back(tmp1);
		adjacency_v[tmp1]++;
		adjacency_v[tmp2]++;
	}
	unsigned c[N];
	ull sum = 0;
	for (int i = 0; i < N; ++i){
		scanf("%u", c + i);
		sum += c[i];
	}
	sort(c, c + N);
	sum -= c[N - 1];
	queue<unsigned> qu;
	unsigned answer[N];
	for (int i = 0; i < N; ++i)
	{
		if(adjacency_list[i].size() == 1) qu.push(i);
	}
	unsigned present = 0;
	while(!qu.empty()){
		answer[qu.front()] = c[present++];
		for (int i = 0; i < adjacency_list[qu.front()].size(); ++i){
			adjacency_v[adjacency_list[qu.front()][i]]--;
			if(adjacency_v[adjacency_list[qu.front()][i]] == 1) qu.push(adjacency_list[qu.front()][i]);
		}
		qu.pop();
	}
	printf("%llu\n", sum);
	for (int i = 0; i < N; ++i){
		if(i) printf(" ");
		printf("%u", answer[i]);
	}
	printf("\n");
	return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    while(!(a==0&&b==0))
    {
        cin >> a >> b;
        if(a==0&&b==0)
        {
            return(0);
        }
        for(int i=0;i<a;i++)
        {
            for(int j=0;j<b;j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return(0);
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
typedef struct{
    ll x; ll y; ll z;
}Cake;
int main() {
    int n, m; cin >> n >> m;
    vector<Cake> cake(n);
    rep(i, n) cin >> cake[i].x >> cake[i].y >> cake[i].z;
    ll ans = 0;
    rep(i, 2)rep(j, 2)rep(k, 2) {
        vector<ll> score(n);
        rep(l, n) {
            score[l] += i ? cake[l].x : -cake[l].x;
            score[l] += j ? cake[l].y : -cake[l].y;
            score[l] += k ? cake[l].z : -cake[l].z;
        }
        sort(score.rbegin(), score.rend());
        ll t = 0;
        rep(l, m) t += score[l];
        ans = max(t, ans);
    }
    cout << ans;
}


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

using namespace std;

int main() {

    int N, K;
    cin >> N >> K;
    long a;

    // 例外 N = 1

    if  (N ==1 ){
        a = K;    cout << a << endl;
        return 0;
    }

    // 1つめを任意の色で塗る
    a = pow(K - 1, N - 1);

    /*
      for (int i = 0; i < N-1; ++i) {
        a *= (K-1)
    }
     */

    // 1つ目の選び方はｋ通りある
    a = a * K;

    cout << a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int f[1001],d[1001],g[1001][1001],a,s,h,j,i;
int main(void)
{
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++){
		scanf("%d",&d[i]);
	}
	for(i=0;i<s;i++){
		scanf("%d",&f[i]);
	}
	for(i=0;i<=s;i++){
		for(j=0;j<=a;j++){
			g[i][j]=200000000;
		}
	}
	g[0][0]=0;
	for(i=0;i<s;i++){
		for(j=0;j<=a;j++){
			if(g[i+1][j]>g[i][j]){
				g[i+1][j]=g[i][j];
			}
			if(g[i+1][j+1]>d[j]*f[i]+g[i][j]&&a>=j){
				g[i+1][j+1]=d[j]*f[i]+g[i][j];
			}
		}
	}
	printf("%d\n",g[s][a]);
	return 0;
}

Measured memory_bytes: 4944
str = gets.chomp
q = gets.to_i
q.times do
	args = gets.split
	case args[0]
	when "print"
		puts str.slice(args[1].to_i, args[2].to_i - args[1].to_i + 1)
	when "reverse"
		s = str.clone
		(args[1].to_i..args[2].to_i).each do |i|
			str[i] = s[args[2].to_i - i + args[1].to_i]
		end
	when "replace"
		s = str.clone
		(args[1].to_i..args[2].to_i).each do |i|
			str[i] = args[3][i - args[1].to_i]
		end
	end
end

Measured memory_bytes: 8872
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt=0,ab=0;
    rep(i,n){
        if(s[i]=='('){
            cnt++;
        }else{
            cnt--;
            if(cnt<0)ab = max(ab,-cnt);
        }
    }
    rep(i,ab)s = '(' + s;
    n+=ab;
    cnt=0;
    rep(i,n){
        if(s[i]=='(')cnt++;
        else cnt--;
    }
    rep(i,cnt)s = s + ')';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char od[7];
int main(){
	scanf("%s",od+1);
	int f=0;
	for(int i=1;i<=3;i++){
		if(od[i]==od[i+1])f=1;
	}
	if(f)printf("Bad");
	else printf("Good");
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

signed main() {
    string S; cin >> S;
    char t;
    int cnt=S.size();
    rep(i,S.size()){
        if(S[i]!='1'){
            t=S[i];
            cnt = i;
            break;
        }
    }
    ll K; cin >> K;
    if(K<=cnt) cout << 1 << endl;
    else cout << t << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int64_t x;
    cin>>x;
    for(int64_t i=0;; i++)
        if(i*i+i>=2*x)
        {
            cout<<i<<endl;
            break;
        }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

char c;

void solve()
{
    cin>>c;
    if(c>='A' && c<='Z')
        cout<<'A';
    else
        cout<<'a';
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */
/* union_find.cpp {{{ */
class UnionFind {
public:
  UnionFind(int n = 0): cnt(n), data(n, -1){}
  int root(int x) const { return data[x] < 0 ? x : (data[x] = root(data[x])); }
  bool same(int x, int y) const { return root(x) == root(y); }
  bool unite(int x, int y){
    if ((x = root(x)) == (y = root(y))) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    cnt--;
    return true;
  }
  int count() const { return cnt; }
  int size(int x) const { return -data[root(x)]; }
private:
  int cnt;
  mutable vector<int> data;
};
/* }}} */

int n, w, h;
int x[40000], y[40000];
vector<tuple<int, int, int>> v, u;
bool f[40000][4];

int main(){
  cin >> n >> w >> h;
  rep(i, n) cin >> x[i] >> y[i];
  rep(i, n){
    if (x[i] == 1) f[i][0] = true;
    if (x[i] == w) f[i][1] = true;
    if (y[i] == 1) f[i][2] = true;
    if (y[i] == h) f[i][3] = true;
  }
  rep(i, n) v.emplace_back(x[i], y[i], i);
  rep(i, n) u.emplace_back(y[i], x[i], i);
  sort(all(v)), sort(all(u));
  UnionFind tr(n);
  rep(i, n - 1){
    int ax, ay, ai, bx, by, bi;
    tie(ax, ay, ai) = v[i];
    tie(bx, by, bi) = v[i + 1];
    if (ax == bx){
      rep(i, 4) f[tr.root(bi)][i] |= f[tr.root(ai)][i];
      rep(i, 4) f[tr.root(ai)][i] |= f[tr.root(bi)][i];
      tr.unite(ai, bi);
    }
  }
  rep(i, n - 1){
    int ay, ax, ai, by, bx, bi;
    tie(ay, ax, ai) = u[i];
    tie(by, bx, bi) = u[i + 1];
    if (ay == by){
      rep(i, 4) f[tr.root(bi)][i] |= f[tr.root(ai)][i];
      rep(i, 4) f[tr.root(ai)][i] |= f[tr.root(bi)][i];
      tr.unite(ai, bi);
    }
  }
  int mn = inf;
  rep(i, 4){
    int res = n + tr.count() - 1;
    rep(j, n) if (tr.root(j) == j && f[j][i]) res--;
    chmin(mn, res);
  }
  if (tr.count() == 1) chmin(mn, n - 1);
  cout << mn << endl;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    int n, a[mx2];
    cin >> n;

    int S = 0, f = INT_MAX;
    for(int i = 0; i < n; i++){
        cin >> a[i];

        S += a[i];
        if(a[i] % 10)
            f = min(f, a[i]);
    }

    if(S % 10)
        cout << S << '\n';
    else if(f == INT_MAX)
        cout << 0 << '\n';
    else
        cout << S - f << '\n';
    return 0;
}


Measured memory_bytes: 3624
/* ex9_1
   YSK722 */

#include <stdio.h>
//スタックに格納するデータの最大数
#define SIZE 11

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if (stk->count > 0){
        latest = *(stk->top);
        stk->top++;
        stk->count--;
    }
    return latest;
}

int main(void){
    stack stk;
    char text[SIZE], *ptr;
    int i = 0;
    scanf("%s", text);
    //スタックを初期化
    initialize_stack(&stk);
    //スタックにデータを追加
    // "B"ならば削除
    for (i = 0; text[i] != '\0'; i++){
        if (text[i] == 'B'){
            pop(&stk);
        }
        else{
            push(&stk, text[i]);
        }
    }
    ptr = stk.top;
    ptr += stk.count - 1;
    // 古いものから出力
    for (i = 0; i < stk.count; i++){
        printf("%c", *ptr--);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main(){
	int N;
	cin >> N;
	if(N<82&&N>0){
		if(N % 2 == 0|| N % 3 == 0 || N % 5 == 0 || N % 7 == 0 || N == 1){
			if (N % 11 == 0|| N % 13 == 0 || N % 17 == 0 || N % 19 ==0 || N == 60 || N == 80 || N == 75 || N==46 || N == 50||N == 58||N == 62 || N == 66 || N== 68 || N==70|| N==74 || N==76 || N==78  ){
				cout << "No";
			}
			else cout << "Yes";
		}
		else cout << "No";
	}
	else cout << "No";	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

private val scanner = Scanner(System.`in`)
private fun readAtOnce(): List<String> = readLine()!!.split(" ")
private fun readInts(): List<Int> = readAtOnce().map(String::toInt)
private fun readLongs(): List<Long> = readAtOnce().map(String::toLong)
private fun zeroArray(size: Int): IntArray = IntArray(size) { 0 }
private fun Int.repeat(predicate: (Int) -> Unit) = repeat(this, predicate)

fun main(array: Array<out String>) {
    val A = Array(9) { scanner.nextInt() }
    val bingo = Array(9) { false }
    val N = scanner.nextInt()
    (0 until N)
            .map { A.indexOf(scanner.nextInt()) }
            .filter { it != -1 }
            .forEach { bingo[it] = true }

    val vertical = setOf(0, 1, 2).any { bingo[it] && bingo[it + 3] && bingo[it + 6] }
    val horizontal = setOf(0, 3, 6).any { bingo[it] && bingo[it + 1] && bingo[it + 2] }
    val diagonal = (bingo[0] && bingo[4] && bingo[8]) || (bingo[2] && bingo[4] && bingo[6])

    println(if (vertical || horizontal || diagonal) "Yes" else "No")
}

Measured memory_bytes: 34244
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  pair<pair<string,int>,int> s[101];
  for (int i=0; i < n; i++){
    int tem;
    cin >> s[i].first.first;
    cin >> tem;
    s[i].first.second=0-tem;
    s[i].second=i+1;
  }
  sort(s,s+n);
  for (int i=0; i<n; i++){
    cout << s[i].second << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 107;

string s;

void read() {
  cin >> s;
}


void kill() {
  string cur = "";
  for (char c : s) {
    if (c == 'T' && !cur.empty() && cur.back() == 'S')
      cur.pop_back();
    else
      cur.push_back(c);
  }
  cout << cur.length() << "\n";
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int f[1010][1010];

int main(){
	int n=read(),m=read(),q=read();
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		f[x][y]++;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			f[i][j]=f[i][j]+f[i-1][j]+f[i][j-1]-f[i-1][j-1];
		}
	}
	for(int i=1;i<=q;i++){
		int x=read(),y=read();
		cout<<f[y][y]-f[y][x-1]-f[x-1][y]+f[x-1][x-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};


int main(void) {
    ll N;
    ll a[100000];
    ll sub[100000];
    ll i;
    ll sum=0;
    ll count;
    cin >> N;
    for(i=0; i<N; i++) {
        cin >> a[i];
        sum+=a[i];
    }
    
    for(i=0; i<N; i++) {
        sub[i]=a[(i+1)%N]-a[i];
    }
    
    if(sum*2%(N*(N+1))!=0) {
        pNO;
        return 0;
    }
    
    count=sum*2/N/(N+1);
    
    ll ans=0;
    for(i=0; i<N; i++) {
        sub[i]-=count;
        if(sub[i]>0) {
            pNO;
            return 0;
        }
        
        if(sub[i]<0 && abs(sub[i])%N==0) {
            ans+=abs(sub[i])/N;
        }
    }
    
    if(ans==count) pYE;
    else pNO;
}

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(R);
    double ans=R*2*3.1415926535;
    printf("%.10f",ans);

    return 0;
}


Measured memory_bytes: 3748
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

//_(＾～＾ ｣ ∠)_

using LL = long long;

vector<int> G[4];

int main() {

    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int odd = 0;
    int even = 0;
    for (int i = 0; i < 4; i++) if (G[i].size() % 2 == 0) even++; else odd++;

    if (odd == 2 && even == 2) cout << "YES";
    else cout << "NO";

    return 0;
}



























Measured memory_bytes: 256
void main()
{
    dchar[] s = readln.chomp.to!(dchar[]);
    long k = readln.chomp.to!long;

    long n = s.length;
    foreach (i, ref x; s)
    {
        if (i == n - 1)
        {
            s[i] = ((s[i] - 'a' + (k % 26)) % 26 + 'a').to!dchar;
        }
        else
        {
            long m = (26 - (s[i] - 'a')) % 26;
            if (k >= m)
            {
                s[i] = 'a';
                k -= m;
            }
            else
            {
                continue;
            }
        }
    }

    s.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




//-----------------------------------------------------------------
#define rrep(i,a,b) for(int i=a;i>=b;i--)
vector<int> mul9(vector<int> s) {
	int n = s.size(), carry = 0;
	vector<int> ret;
	rrep(i, n - 1, 0) {
		int c = s[i] * 9 + carry;
		carry = c / 10;
		c %= 10;
		ret.push_back(c);
	}
	while (0 < carry) {
		ret.push_back(carry % 10);
		carry /= 10;
	}
	reverse(ret.begin(), ret.end());
	return ret;
}
vector<int> add(vector<int> s, int x) {
	int n = s.size(), carry = x;
	vector<int> ret;
	rrep(i, n - 1, 0) {
		int c = s[i] + carry;
		carry = c / 10;
		c %= 10;
		ret.push_back(c);
	}
	while (0 < carry) {
		ret.push_back(carry % 10);
		carry /= 10;
	}

	return ret;
}
//-----------------------------------------------------------------
vector<int> S;
bool chk(int k) {
	auto s = add(S, k * 9);
	int cnt = 0;
	for (int c : s) cnt += c;

	return cnt <= 9 * k;
}
//-----------------------------------------------------------------
int main() {
	string _S; cin >> _S;
	for (char c : _S) S.push_back(c - '0');

	S = mul9(S);

	int lo = 0, hi = 501010;
	while (lo + 1 != hi) {
		int mi = (lo + hi) / 2;
		if (chk(mi)) hi = mi;
		else lo = mi;
	}
	cout << hi << endl;
}

Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n,k;
  cin >> n >> k;

  double ans = 0;
  FOR(i,1,n+1){
    int tmp = i;
    int num = 0;
    while(tmp < k){
      tmp *= 2;
      num++;
    }
    double x = 1.0;
    rep(i,num){
      x *= 0.5;
    }
    ans += x * 1.0/n;
  }
  printf("%0.10lf\n",ans);
  return 0;
}


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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

void func(long long N, long long K)
{
    N = N%K;
    cout << min(abs(N-K) % K, N % K) << endl;
}

int main()
{
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    func(N, K);
    return 0;
}


Measured memory_bytes: 256