akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,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=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n;
  cin >> n;
  VI x(n),y(n),h(n);
  int xx,yy,hh;
  REP(i,n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]>=1){
      xx = x[i];
      yy = y[i];
      hh = h[i];
    }
  }

  REP(cx,101)REP(cy,101){
    bool ok=true;
    int H = hh + abs(cx-xx) + abs(cy-yy);
    REP(i,n){
      if(h[i]!=max(H-abs(cx-x[i])-abs(cy-y[i]), 0)){
        ok=false;
        break;
      }
    }
    if(ok){
      cout << cx << " " << cy << " " << H << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        final String[] sl = s.split(" ");
        long N = Long.parseLong(sl[0]);
        long M = Long.parseLong(sl[1]);

        if (M < N) {
            long tmp = N;
            N = M;
            M = tmp;
        }

        if (N == 1) {
            if (M == 1) out.println(1);
            else out.println(M - 2);
        } else
            out.println((N - 2) * (M - 2));

        out.flush();
    }
}


Measured memory_bytes: 22356
use std::str::FromStr;
use std::fmt::Debug;
 
fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}
 
fn main(){
 
	let mut x : Vec<u32> = read_line();
	let mut max : u32 = x[0]; 
	let mut min : u32 = x[0];
	let mut y : u32 = 0;
	
	if x[0] > x[1] {
		y = x[0];
		x[0] = x[1];
		x[1] = y;
	}
	
	if x[1] > x[2] {
		y = x[1];
		x[1] = x[2];
		x[2] = y;
	}
	
	if x[0] > x[1] {
		y = x[0];
		x[0] = x[1];
		x[1] = y;
	}
	
	println!("{} {} {}", x[0], x[1], x[2]);
	}


Measured memory_bytes: 5020
#include <bits/stdc++.h>
 
using namespace std;
 
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
 
double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}
 
std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}
 
std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}
 
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
 
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
 
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
const int mod = 1000000007;
 
 
int main() {
    double r;
    cin >> r;
 
    printf("%.20f\n", r * 2 * PI);
}

Measured memory_bytes: 3792
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i;
    double a,sum=0;
    
    while(scanf("%lf",&a)!=EOF){
        sum+=a;
        for(i=2;i<=10;i++){
            if(i%2==0){
                a*=2;
                sum+=a;
                //printf("%.8f ",a);
            }
            else{
                a/=3;
                sum+=a;
                //printf("%.8f ",a);
            }
        }
        //printf("\n");
        printf("%.8f\n",sum);
        sum=0;
    }
    
    return 0;
}

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

int main()
{
    string str;
    int alp[26];
    char c;
    int x;
    for (int i = 0; i < 26; i++)
        alp[i] = 0;
    while (cin >> str)
    {
        for (unsigned i = 0; i < str.length(); i++) {
            str[i] = tolower(str[i]);
            if (str[i] >= 'a'&&str[i] <= 'z') {
                x = str[i] - 'a';
                alp[x]++;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        c = 'a' + i;
        cout << c << " : " << alp[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
N = int(input())
F = [ int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**10

for i in range(1,1<<10):
    ans = max(ans, sum(P[n][bin(i&F[n]).count('1')] for n in range(N)))
print(ans)


Measured memory_bytes: 44380
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  int n;
  cin >> n;
  int p[n];
  rep(i, n) {
  	cin >> p[i];
  }
  
  int ans = 0;
  for (int i=1; i<n-1; i++) {
  	if ((p[i-1] <= p[i] && p[i] <= p[i+1])|| (p[i-1] >= p[i] && p[i] >= p[i+1])) {
  		ans++;
  	}
  }
  
  cout << ans << endl;

  return 0;
}


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

using namespace std;


int main(void)
{
  int n;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  string s;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> s;
    if(s == "AC"){
      ac++;
    }else if(s == "WA"){
      wa++;
    }else if(s == "TLE"){
      tle++;
    }else if(s == "RE"){
      re++;
    }
  }
  cout << "AC x " << ac <<"\nWA x " << wa << "\nTLE x " << tle << "\nRE x " << re << endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int A, B, C, D, E, F;
int main() {
	cin >> A >> B >> C >> D >> E >> F;
	int x = -1, y = -1;
	for (int i = 0; i <= F; i += 100 * A) {
		for (int j = 0; i + j <= F; j += 100 * B) {
			for (int k = 0; i + j + k <= F; k += C) {
				for (int l = 0; i + j + k + l <= F; l += D) {
					if (i + j + k + l == 0 || (100 + E) * (k + l) > E * (i + j + k + l)) continue;
					if (x == -1 || x * (i + j + k + l) < y * (k + l)) {
						x = k + l;
						y = i + j + k + l;
					}
				}
			}
		}
	}
	cout << y << ' ' << x << '\n';
	return 0;
}

Measured memory_bytes: 256
#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>;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3536
#include<stdio.h>
int main()
{
    int final;
    int base;

    scanf("%d", &final);
    base = (int)( (double)final / 1.08 );
    
    if( (int)((double)base * 1.08) == final )
    {
    	printf("%d\n", base);
    }
    else if( (int)((double)(base+1) * 1.08) == final )
    {
    	printf("%d\n", (base+1));
    }
    else
    {
    	printf(":(\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
bool dp[101][10001] = {};

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

    for(int i=0; i<N; ++i) dp[i][0] = true;
    for(int i=0; i<N; ++i) {
        for(int j=0; j<=10000; ++j) {
            dp[i+1][j] = dp[i][j];
            if(j >= s[i] && dp[i][j - s[i]]) dp[i+1][j] = true; 
        }
    }

    int res = 0;
    for(int j=10000; j>=0; --j) {
        if(j % 10 != 0 && dp[N][j]) {
            res = j;
            break;
        }
    }
    cout << res << endl;
}

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

using namespace std;

int main() {
	vector<int> v;
	v.push_back(0);
	int n;
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		v.push_back(a);
	}
	int i = 1;
	int a = 0;
	
	while(1){
		if(v[i] == 2){
			cout<<a+1;
			return 0;
		}	
		
		if(v[i] == -1){
			cout<<-1;
			return 0;
		}
		
		int t = v[i];
		v[i] = -1;
		i = t;
		a+=1;
	}

	return 0;
}

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


ll N, K;
const ll MOD = 1000000007;

struct range_info { // 区間 [l,h)
	ll l;
	ll h;
	ll ct;
};

range_info r[70000]; // [1..N] の範囲を sqrt(N)*2 個ぐらいの区間に分割する。

int main(){
	cin >> N >> K;
	
	ll r_count;
	{
		ll i = 0;
		ll x = 1;
		while ( N/x != N/(x+1) ){
			r[i++] = {x,x+1,1};
			x++;
		}
		
		ll y = N / x;
		ll l = x;
		while ( y ){
			ll h = N/y+1;
			r[i++] = {l, h, h-l};
			y--;
			l = h;
		}
		r_count = i;
	}
	
	//for ( int i = 0; i < r_count; i++ )
	//	cout << r[i].l << " - " << r[i].h << endl;
	
	
	vector<ll> acc(r_count+1);
	ll ct[2][70000];
	
	
	for ( int i = 0; i < r_count; i++ ){
		ct[0][i] = r[i].ct;
	}
	
	
	for ( int k = 1; k < K; k++ ){
		ll f = k%2;
		ll b = (k+1)%2;
		
		ll sum = 0;
		acc[0] = 0;
		for ( int i = 0; i < r_count; i++ ){
			sum = (sum + ct[b][i])%MOD;
			acc[i+1] = sum;
		}
		
		for ( int i = 0; i < r_count; i++ ){
			ct[f][i] = (acc[r_count-i] * r[i].ct)%MOD;
		}
		
	}
	
	ll sum = 0;
	ll f = (K-1)%2;
	for ( int i = 0; i < r_count; i++ ){
		sum = (sum + ct[f][i])%MOD;
	}
	
	cout << sum << endl;
}



Measured memory_bytes: 3200
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=1e5,p=1e9+7;
const int A[3][3]={
	{1,2,1},
	{0,1,1},
	{1,2,2},
};
const int B[3][3]={
	{1,2,1},
	{0,1,1},
	{0,0,1},
};
struct Matrix{
	int v[3][3];
	Matrix(){memset(v,0,sizeof(v));}
	void clear(){memset(v,0,sizeof(v));}
	void init(){for (int i=0;i<3;i++)	v[i][i]=1;}
}trans,Ans,T;
Matrix operator *(const Matrix &x,const Matrix &y){
	Matrix z;
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				z.v[i][k]=(z.v[i][k]+1ll*x.v[i][j]*y.v[j][k])%p;
	return z;
}
Matrix mlt(Matrix a,int b){
	Matrix res; res.init();
	for (;b;b>>=1,a=a*a)	if (b&1)	res=res*a;
	return res;
}
int val[N+10];
int main(){
	int n=read(),m=read(),Last=0;
	memcpy(T.v,B,sizeof(B));
	memcpy(trans.v,A,sizeof(A));
	Ans.v[0][0]=1;
	Ans=Ans*trans,Last=1;
	for (int i=1;i<=m;i++){
		int x=read();
		Ans=Ans*mlt(trans,x-Last);
		Ans=Ans*T,Last=x+1;
	}
	Ans=Ans*mlt(trans,n-Last);
	printf("%d\n",Ans.v[0][2]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> pa(a);
  vector<ll> pb(b);
  vector<ll> pc(c);
  for(int i = 0; i < a; ++i)cin >> pa[i];
  for(int i = 0; i < b; ++i)cin >> pb[i];
  for(int i = 0; i < c; ++i)cin >> pc[i];

  sort(pa.rbegin(), pa.rend());
  sort(pb.rbegin(), pb.rend());
  sort(pc.rbegin(), pc.rend());

  priority_queue<ll, vector<ll>, greater<ll>> que; 
  for(int i = 0; i < x; ++i){
  	que.push(pa[i]);
  }
  for(int i = 0; i < y; ++i){
  	que.push(pb[i]);
  }

  for(int i = 0; i < c; ++i){
  	if(pc[i] > que.top()){
  		que.pop();
  		que.push(pc[i]); 
  	}
  }

  ll ans = 0;
  for(int i = 0; i < x + y; ++i){
  	ans += que.top();
  	que.pop();
  }

  cout << ans << endl;

  return 0;
}


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

int main () {
  
  int N; cin >> N;
  
  vector<long long> s(N + 1);
  
  for (int i = 0; i < N; i++) {
    long long a; cin >> a;
    s[i + 1] = s[i] + a;
  }
  
  int l = 1, r = 3;
  
  long long res = 2000000000000000;
  
  for (int a = 2; a <= N - 2; a++) {
    
    long long lsum = s[a];
    long long rsum = s[N] - s[a];
    
    // 左の処理
    
    while (l < a - 1 && 2 * s[l] < lsum) l++;
    
    if (l > 1 && max(s[l], lsum - s[l]) - min(s[l], lsum - s[l]) > max(s[l - 1], lsum - s[l - 1]) - min(s[l - 1], lsum - s[l - 1])) l--;
    
    long long P = s[l], Q = lsum - s[l];
    
    // 右の処理
    
    while(r < N - 1 && 2 * (s[r] - s[a]) < rsum) r++;
    
    if (r > a && max(s[r] - lsum, s[N] - s[r]) - min(s[r] - lsum, s[N] - s[r]) > max(s[r - 1] - lsum, s[N] - s[r - 1]) - min(s[r - 1] - lsum, s[N] - s[r - 1])) r--;
    
    long long R = s[r] - lsum, S = s[N] - s[r];
    
    //4つの数の差を比較
    
    long long x = max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S)));
    if(x < res) res = x;
    
  }
  
  cout << res << endl;
  
}

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

int calc(string a,int an,string b,int bn){
    int num=0;
    string tmp="X";
    for(int i=0;i<an;i++){
        bool s=false;
        for(int k=0;k<tmp.length();k++){
            if(tmp[k]==a[i]){
                s=true;
            }
        }
        if(!s){
            tmp+=a[i];
        }
        if(!s){
            for(int j=0;j<bn;j++){
                if(a[i]==b[j]){
                    num++;
                    break;
                }
            }   
        }
    }
    return num;
}


int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int maxpointer=0;
    int max=0;
    for(int i=1;i<N;i++){
        int tmp = calc(S.substr(0,i),i,S.substr(i,N-i),N-i+1);
        if(tmp>max){
            max=tmp;
        }
    }
    cout << max;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll h, w;
  cin >> h >> w;
  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = min(h, w);
  for (ll i = 1LL; i < h; i++) {
    ll j = w / 2;
    ll tmp = max(abs(w * i - j * (h - i)), max(abs(w * i - (w - j) * (h - i)),
                                               abs((w - 2 * j) * (h - i))));
    ans = min(ans, tmp);
  }
  for (ll j = 1LL; j < w; j++) {
    ll i = h / 2;
    ll tmp = max(abs(h * j - i * (w - j)), max(abs(h * j - (h - i) * (w - j)),
                                               abs((h - 2 * i) * (w - j))));
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	int MOD = 1000000007;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			long n = sc.nextLong();
			
			long [] data = new long[3];
			data[0] = a * 4;
			data[1] = b * 2;
			data[2] = c;
			Arrays.sort(data);
			if(n == 1){
				System.out.println(data[0]);
				continue;
			}
			
			long res = data[0] * 2;
			if(res > d){
				res = d;
			}
			if(n % 2 == 0){
				System.out.println((long)res * (n / 2));
			}
			else{
				System.out.println((long)res * (n / 2) + data[0]);
			}
			
			
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <set>
#define sf(n) scanf("%d",&n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define ll long long
#define MAXL 1000000
#define eps 1e-6
#define MAXV 10005
#define INF 1000000005
#define mod 1000000007
using namespace std;
int a[100005];
bool f[100005];
int k[2][100005];
int main(){
    int n;sf(n);
    int mmin,mmax;
    int pmin=0,pmax=0;
    for(int i=0;i<n;i++){
        sf(a[i]);
        if(i==0){
            mmin=a[0];
            mmax=a[0];
        }
        else{
            if(mmin>a[i]){
                mmin=a[i];
                pmin=i;
            }
            if(mmax<a[i]){
                mmax=a[i];
                pmax=i;
            }
        }
    }
    if(pmin==pmax){
        if(a[0]>0){
            f[0]=0;
            for(int i=1;i<n;i++)f[i]=1;
            pmin=0;
            pmax=1;
        }
        else{
            f[0]=1;
            for(int i=1;i<n;i++)f[i]=0;
            pmin=1;
            pmax=0;
        }
    }
    else{
        for(int i=0;i<n;i++){
            if(i==pmin){
                f[i]=0;
            }
            else if(i==pmax){
                f[i]=1;
            }
            else{
                if(a[i]>=0)f[i]=1;
                else f[i]=0;
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(f[i])sum+=a[i];
        else sum-=a[i];
    }
    printf("%d\n",sum);
    for(int i=0;i<n;i++){
        if(i==pmin||i==pmax)continue;
        if(f[i]==0){printf("%d %d\n",a[pmax],a[i]);a[pmax]-=a[i];}
        else {printf("%d %d\n",a[pmin],a[i]);a[pmin]-=a[i];}
    }
    printf("%d %d\n",a[pmax],a[pmin]);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;

#define REP(i, j) for(int i=0;i<j;i++)
#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define LAST(x) (x[SIZE(x)-1])
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

int n, h, k;
ll dp[100005];
VI nums;

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

    cin >> n >> k;

    REP(i, n){
        cin >> h;
        nums.pb(h);
    }

    dp[0]=0;
    dp[1]=abs(nums[1]-nums[0]);

    for(int i=2;i<n;i++){
        dp[i] = INT_MAX;
        for(int j=i-1;j>=max(0, i-k);j--)
        dp[i]=min(dp[i], dp[j]+abs(nums[j] - nums[i]));
    }

    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 1528
import java.util.*;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int[] arr = new int[h + 1];
        for (int i = 1; i < h + 1; i++) {
            arr[i] = sc.nextInt();
        }

        for (int i = 1; i < h + 1; i++) {
            int key = arr[i];
            Integer parent = i / 2 == 0 ? null : arr[i / 2];
            Integer left = i * 2 >= h + 1 ? null : arr[i * 2];
            Integer right = i * 2 + 1 >= h + 1 ? null : arr[i * 2 + 1];
            System.out.println("node "
                    + i
                    + ": key = " + key + ", "
                    + (parent == null ? "" : "parent key = " + parent + ", ")
                    + (left == null ? "" : "left key = " + left + ", ")
                    + (right == null ? "" : "right key = " + right + ", ")
            );
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}



Measured memory_bytes: 27508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n,a,b,c,d,e; cin>>n>>a>>b>>c>>d>>e;
    int f=min({a,b,c,d,e});
    cout<<(n-1)/f+5<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
#include <set>
#include <cassert>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

const int MAXN = 10;
const int INF = 1e3;

template<typename T1, typename T2> inline void chkmin(T1 & a, const T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chkmax(T1 & a, const T2 b) { if (a < b) a = b; }

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(0), cout.tie(0);
    // freopen("input.txt", "r", stdin);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
    	if (i % k == 0) {
    		cout << "OK";
    		return 0;
    	}
    }
    cout << "NG";
    return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);


int main(){
  int n;
  cin >> n;
  vector<int>b;
  rep(i,n){
    int B;
    cin >> B;
    b.push_back(B);
    if(b[i]>i+1){
      cout << -1 << endl;
      return 0;
    }
  }
  int num=n;
  vector<int>ans;
  while(num){
    int kesu=-1;
    rep(i,num){
      if(b[i]==i+1){
        if(kesu<i)kesu=i;
      }
    }
    if(kesu==-1){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(b[kesu]);
    b.erase(b.begin()+kesu);
    num--;
  }
  rep(i,n) cout<<ans[n-1-i]<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

def loop():
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

ans = ['S'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] * (n-1) + ['S']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['S'] * (n-1) + ['W']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == 'o' and ans[n-2] == 'S'):
        print(''.join(ans))
        exit()        

print(-1)


Measured memory_bytes: 5956
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  int N;
  cin >> N;
  cout << N * 800 - 200 * (N / 15) << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
from operator import itemgetter
N,M = map(int,input().split())
table=[[1]*N for i in range(N)]
for i in range(N):
    table[i][i]=0
for i in range(M):
    a,b=map(int,input().split())
    table[a-1][b-1]=0
    table[b-1][a-1]=0
visit=[False]*N
color =[-1]*N
def f(i):
    q=deque()
    q.append(i)
    color[i]=0
    visit[i]=True
    r=[0,0]
    r[0]+=1
    while q:
        x= q.popleft()
        for j in range(N):
            if table[x][j]==0:
                continue
            if visit[j]:
                if (color[x]==color[j]):
                    print(-1)
                    sys.exit()
                continue
            q.append(j)
            color[j]=(color[x]+1)%2
            r[color[j]]+=1
            visit[j]=True
    return r
ans=[]
for i in range(N):
    if not visit[i]:
        ans.append(f(i))
#print(ans)
dp=[set() for i in range(len(ans)+1)]
dp[0].add(0)
L=N//2+1
for i in range(1,len(ans)+1):
    for a in dp[i-1]:
        if a+ans[i-1][0]<L:
            dp[i].add(a+ans[i-1][0])
        if a+ans[i-1][1]<L:
            dp[i].add(a+ans[i-1][1])
    #print(dp)
s = max(dp[len(ans)])
def dou(k):
    return (k*(k-1))//2
print(dou(s) + dou(N-s))





Measured memory_bytes: 22268
S = input()
head, tail = int(S[:2]), int(S[2:])
head_mm = 1 <= head <= 12
tail_mm = 1 <= tail <= 12
if head_mm and tail_mm:
    print("AMBIGUOUS")
elif head_mm:
    print("MMYY")
elif tail_mm:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 2940
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{		//二つの整数
	 public static void main(String[] args) {
	        try (Scanner sc = new Scanner(System.in)) {	//Scanerクラスを変数scで使えるようにする
	            int a = sc.nextInt();	//二つの変数a,bに整数を入力
	            int b = sc.nextInt();
	            
	            //ifを用いた比較
	            if(a > b) {			//aがbより大きかった場合
	            	System.out.println("a > b");	//
	            }else if(a < b) { //aがbより大きかった場合
	            	System.out.println("a < b");
	            }else if(a == b) {
	            	System.out.println("a == b");
	            }
	        }
	    }
}





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

int main(){
  int x,y;

  while(1){
    cin >> x >> y ;
    if ( x == 0 && y == 0) break;
    if ( y <= x )cout << y << " " << x <<endl;
    else if ( x <= y )cout << x << " " << y << endl;
    
  }
    return 0;
}

Measured memory_bytes: 1160
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}


const ll N=2e5+5;

 
int main()
{ 

IOS;

ll n,k;
cin>>n>>k;

vl a(n);

ll mx=0;

FOR(i,n)cin>>a[i],chmax(mx,a[i]);


ld l=1,r=1e9,mid;
ll ans=mx;
ll cnt=0;
while(cnt!=100){
  mid=(l+r)/2;
  ll times=0;
  cnt++;
  FOR(i,n){
    ll z=(ll)mid;
    ll y=(a[i]-1)/z;
    times+=y;
  }

//d2(mid,times);
  if(times<=k){
    chmin(ans,round(mid));
    r=mid;
  }
  else l=mid;
}


d1(ans);


//end_routine();

return 0;
 
 }


Measured memory_bytes: 4868
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<char> t(q), d(q);
  for (int i = 0; i < q; i++) {
    cin >> t[i] >> d[i];
  }
  int lo = -1, hi = n;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    int pos = mid;
    for (int i = 0; i < q; i++) {
      if (s[pos] == t[i]) {
        if (d[i] == 'L') pos--;
        else pos++;
        if (pos == -1 || pos == n) break;
      }
    }
    if (pos == -1) lo = mid;
    else hi = mid;
  }
  int l = hi;
  lo = -1, hi = n;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    int pos = mid;
    for (int i = 0; i < q; i++) {
      if (s[pos] == t[i]) {
        if (d[i] == 'L') pos--;
        else pos++;
        if (pos == -1 || pos == n) break;
      }
    }
    if (pos == n) hi = mid;
    else lo = mid;
  }
  int r = lo;
  cout << min(n, r - l + 1) << endl;
  return 0;
}

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

using namespace std;

using LL = long long;

void solver() {
	int n; 
	cin >> n;
	
	vector<int> v(n);
	
	for(int &x : v) 
		cin >> x;

	sort(v.begin(), v.end());

	if (n == 1) {
		cout << 0 << '\n';
		return;
	}
	if (n == 2) {
		cout << v[n - 1] << '\n';
		return;
	}
	
	LL ans = v[n - 1];

	int j = n - 3;
	int i = n - 2;

	while(j >= 0 && i >= 0) {
		ans += v[i];
		--j;
		if (j >= 0)
			ans += v[i];
		--j;
		--i;
	}

	cout << ans << '\n';

}

int main() {

	ios_base :: sync_with_stdio(0); cin.tie(NULL);

	int t;
	//cin >> t;
	t = 1;

	while(t--)
		solver();

	return 0;
}


Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
struct node{
	double x,y;
}a,b,c,d;
node operator - (node a,node b)
{
	return (node){a.x-b.x,a.y-b.y};
}
double DJ(node a,node b)
{
	return a.x*b.x+a.y*b.y;
}
double CJ(node a,node b)
{
	return a.x*b.y-a.y*b.x;
}
double len(node a)
{
	return a.x*a.x+a.y*a.y;
}
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	int n=read();
	while(n--)
	{
		a=(node){read(),read()};
		b=(node){read(),read()};
		c=(node){read(),read()};
		d=(node){read(),read()};
		if(CJ(b-a,d-c)==0.0)puts("2");
		else if(DJ(b-a,d-c)==0.0)puts("1");
		else puts("0");
	}
	return 0;
}


Measured memory_bytes: 3108
function Main(input) {
    var input = input.split(' ').map(n =>parseInt(n));
    var a = input[0];
    var b = input[1];
    var av = (a + b)/2;
    console.log(Math.ceil(av));
    
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>

using namespace std;
#define REP(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int A = 0;
    REP(i, 0, N) {
        cin >> a[i];
        A = A^a[i];
    }
    REP(i, 0, N) {
        if (a[i] != (A^a[i])) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 888
#! /usr/bin/env ruby
n = gets.chomp.to_i
require 'set'
dic = Set.new
ok = true
last = "$"
n.times do |i|
  w = gets.chomp
  if dic.include?(w)
    ok = false
  end
  dic.add(w)
  if i>0
    if last!=w[0]
      ok = false
    end
  end
  last = w[-1]
end

puts ok ? "Yes" : "No"


Measured memory_bytes: 1916
#include <iostream>

using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  if( abs(a-c) <= d ||
      (abs(a-b) <= d && abs(c-b) <= d ))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 100000

int N;
long long x;
long long a[MAX];

int main() {
	cin >> N >> x;
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	long long ans = 0;
	for( int i = 0; i < N - 1; i++ ) {
		long long sum = a[i] + a[i + 1];
		if( sum <= x ) {
			continue;
		}
		long long d = sum - x;
		ans += d;
		if( a[i + 1] >= d ) {
			a[i + 1] -= d;
		}
		else {
			d -= a[i + 1];
			a[i + 1] = 0;
			a[i] -= d;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    int i, j ,k;
    int dpw[310000], dpe[310000];
    char s[310000];
    int east=0, west=0;
    int min = 330000;
    int minw, mine;
    int N;

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%s", s);
    }

    dpw[0] = 0;
    dpe[0] = 0;

    for(i=1; i<=N; i++){
        if(s[i-1] == 'E'){
            east += 1;
        }else{
            west += 1;
        }
        dpe[i] = east;
        dpw[i] = west;
    }
    dpw[N+1] = dpw[N];
    dpe[N+1] = dpe[N];

    for(i=1; i<=N; i++){
        minw = dpw[i-1];
        mine = dpe[N+1] - dpe[i];
        if(minw+mine < min){
            min = minw + mine;
        }
    }

    printf("%d", min);

    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<double>v(n);
	rep(i, n)cin >> v[i];

	sort(v.begin(), v.end());
	double g = (v[0] + v[1]) / 2;
	REP(i, 2, n) {
		g = (g + v[i]) / 2;
	}
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

int main () {
  int n, x;
  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }

    int count = 0;
    for (int a = 1; a <= n - 2; a++)
    {
      for (int b = a + 1; b <= n - 1; b++)
      {
        int c = x - a - b;
        if (c <= n && a < b && b < c) {
          count++; 
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
          

Measured memory_bytes: 3096
K,N=map(int,input().split())
li=list(map(int,input().split()))

tmp=[]
for i in range(N):
    if(i!=N-1):
        tmp.append(li[i+1]-li[i])
    else:
        tmp.append(li[0]+K-li[i])

id =tmp.index(max(tmp))
if(id<N-1):
    print(li[id]+K-li[id+1])
else:
    print(li[id]-li[0])

Measured memory_bytes: 26444
/**
*    created: 14.06.2020 21:14:22
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int M = 1000005;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(M);
    for (int x : a) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i < M; i+=x) cnt[i]++;
    }
    
    int ans = 0;
    for (int x : a) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12696
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main(){
    int N; cin >> N;
    string s; cin >> s;


    int left_idx = 0;
    int right_idx = N-1;

    int ans = 0;
    while(left_idx != right_idx){
        if( s[right_idx] == 'W' ){
            right_idx--;
        }else{
            //if right == R
            if( s[left_idx] == 'W'){
                swap(s[left_idx], s[right_idx]);
                ans++;
                right_idx--;
            }else{
                left_idx++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3752
#n, x = map(int,input().split())
n = int(input())
ls = [["",[[]]]]
for i in range(n):
  s, p = input().split()
  for j in ls:
    if s == j[0]:
      j[1].append([i+1,int(p)])
      break
    elif j == ls[-1]:
      ls.append([s,[[i+1,int(p)]]])
      break
#ls = list(map(int,input().split()))
#s = input()
ls.remove(ls[0])
ls.sort()
for i in ls:
  i[1].sort(key=lambda x: x[1],reverse=True)
  for j in i[1]:
    print(j[0])


Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
	int n,m;
	cin >> n >> m;
	string a[55],b[55];
	for(int i=1;i<=n;i++)
		cin >> a[i-1];
	for(int i=1;i<=m;i++)
		cin >> b[i-1];
	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			bool ans=true;
			for(int i2=1;i2<=m;i2++)
				for(int  j2=1;j2<=m;j2++)
				{
//cout << i << ":" << j << ":" << i2 << ":" << j2 << endl;
					if(i+i2-1>n or j+j2-1>n)
					{
//cout << "edge" << endl;
						ans=false;
						break;
					}
					if(a[i+i2-1-1][j+j2-1-1]!=b[i2-1][j2-1])
					{
//cout << "not" << endl;
						ans=false;
						break;
					}
				}
			if(ans==true)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}

	cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


X = S()
num_S = [0] * len(X)
t_count = 0
s_count = 0
ans = 0
prev = X[-1]
if (prev == 'S'):
    s_count = 1
else:
    t_count = 1
for x in reversed(X[:-1]):
    if (prev == 'S' and x == 'T'):
        # リセット
        rest = max(s_count - t_count, 0)
        ans += (rest*2)
        t_count = max(t_count - s_count, 0)
        s_count = 0
    if (x == 'S'):
        s_count += 1
    if (x == 'T'):
        t_count += 1
    prev = x
print(ans)


# for i, x in enumerate(X):
#     if(x == 'S'):
#         num_S[i] = 1

# num_S = list(accumulate(num_S))
# print(num_S)


Measured memory_bytes: 11196
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int N, L, T; cin >> N >> L >> T;
   V<int> X(N), W(N);
   for (int i = 0; i < N; i++) {
      cin >> X[i] >> W[i];
   }
   DUMP(X)
   DUMP(W)

   V<P<int,int>> Y(N);
   for (int i = 0; i < N; i++) {
      if (W[i] == 1) {
         Y[i].first = (X[i] + T) % L;
      } else {
         Y[i].first = (((X[i] - T) % L) + L) % L;
      }
      Y[i].second = i;
   }
   DUMP(Y)
   sort(Y.begin(), Y.end());
   DUMP(Y)

   map<int,int> cnt;
   for (int i = 0; i < N; i++) {
      cnt[Y[i].first]++;
   }
   P<int,int> y;
   for (auto it = cnt.begin(); it != cnt.end(); ++it) {
      if (it->second == 1) {
         y = make_pair(it->first, 0);
         break;
      }
   }
   int idx = lower_bound(Y.begin(), Y.end(), y)->second;
   int Y_idx = lower_bound(Y.begin(), Y.end(), y) - Y.begin();
   DUMP(idx)
   DUMP(Y_idx)

   int sum = 0;
   for (int i = 0; i < N; i++) if (W[idx] != W[i]) {
      int d = (X[i] - X[idx] + L) % L;
      if (W[idx] == 2) {
         d = (L - d) % L;
      }
      if (2 * T >= d) {
         (sum += (2 * T - d) / L + 1) %= N;
      }
      DUMP(sum)
   }
   if (W[idx] == 2) {
      sum = (N - sum) % N;
   }
   DUMP(sum)


   V<int> ans(N);
   for (int i = 0; i < N; i++) {
      ans[(i+idx+sum)%N] = Y[(i+Y_idx)%N].first;
   }
   for (int i = 0; i < N; i++) {
      cout << ans[i] << (i == N-1 ? "\n" : " ");
   }
   DUMP(ans)

   return 0;
}


Measured memory_bytes: 11392
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}

signed main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b)
{
    if(a!=c)
     cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}
if(b==c)
{
    if(b!=a)
     cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}
if(a==c)
{
    if(a!=b)
     cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}
if(a!=b&&b!=c&&a!=c)
cout<<"No"<<endl;
}





Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, m] <- getIntList
  let elapsed1 = m * 1900 + (n - m) * 100
      eSubmits = 2 ^ m
      ans = eSubmits * elapsed1
  print ans


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n;
    cin>>n;
    Array x(n);
    REP(i,n) cin>>x[i];

    vec<P> a; 
    REP(i,n){
        a.push_back({x[i],i});
    }
    sort(all(a));

    Array ans(n*n,-1);
    int pos=0;
    int ret=0;
    int pre=-1;
    vec<P> nokori;
    REP(i,n){
        int now=a[i].first;
        ll num=a[i].second;
        now--;
        if(ans[now]!=-1){
            cout<<"No"<<en;
            return;
        }
        ans[now]=num+1;
        ret += now-pre-1;
        //cout<<ret<<" "<<num<<en; 
        if(ret < num){
            cout<<"No"<<en;
            return;
        }
        REP(k, num){
            while(ans[pos]!=-1) pos++;
            if(ans[pos] == -1){
                ans[pos] = num+1;
            }
        }
        ret-=num;
        pre=now;
        REP(j, n-1-num) nokori.push_back({now, num+1});
    }

    reverse(all(nokori));
    pos = n*n-1;
    REP(i,nokori.size()){
        int now = nokori[i].first;
        ll num = nokori[i].second;
        while(ans[pos]!=-1) pos--;
        if(pos<now){
            cout<<"No"<<en;
            return;
        }
        ans[pos]=num;
    }

    cout<<"Yes"<<en;
    for(auto i:ans) cout<<i<<" ";
    cout<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 5232