akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void) {

	char str[1200];

	scanf("%[^\n]%*c", str);

	for (int i = 0; i < strlen(str); i++) {

		if (str[i] >= 65 && str[i] <= 90) {
			str[i] = str[i] + 32;
		}
		else if (str[i] >= 97 && str[i] <= 122) {
			str[i] = str[i] - 32;
		}
	}

	printf("%s\n", str);

	return 0;
}




Measured memory_bytes: 2080
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B;
	cin >> A >> B;

	cout << (B - 1) / A +1<< endl;
	return 0;
}




Measured memory_bytes: 3156
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let x: Vec<i64> = (0..n).map(|_| read()).collect();

    let ans = x
        .windows(k)
        .map(|x_k| {
            min(
                x_k[0].abs() + (x_k[k - 1] - x_k[0]).abs(),
                x_k[k - 1].abs() + (x_k[0] - x_k[k - 1]).abs(),
            )
        })
        .min()
        .unwrap();

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import std.stdio, std.string, std.conv, std.array, std.algorithm;
import std.uni, std.range, std.math, std.container, std.datetime;
import core.bitop, std.typetuple, std.typecons;

immutable long MOD = 1_000_000_007;
alias tie = TypeTuple;

void main(){
    int a, b;
    char op;

    while(true){
        readVars(a, op, b);

        switch(op){
            case '+':
                writeln(a + b);
                break;

            case '-':
                writeln(a - b);
                break;

            case '*':
                writeln(a * b);
                break;

            case '/':
                writeln(a / b);
                break;

            default:
                return;
        }
    }
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 2712
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
    int n,i,ans=0,count=0,j;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++)
    cin >> a[i];
    for(i=0;i<n;i++)
    {
        for(j=0;j<i;j++)
        {
            if(a[j]>a[i])
            {
                ans++;
                break;
            }
        }
        if(ans==0)
        count++;
        ans=0;
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
acum=[[0]*w for _ in range(h)]

def count(x1,y1,x2,y2): #事前に求めた2次元累積和を用いて左上の点が(x1,y1)、右下の点(x2,y2)の長方形に含まれる1の個数を数える
  ret=acum[y2][x2]
  if x1!=0:
    ret-=acum[y2][x1-1]
  if y1!=0:
    ret-=acum[y1-1][x2]
  if x1!=0 and y1!=0:
    ret+=acum[y1-1][x1-1]
  return ret

for i in range(h): #2次元累積和により左上の点が(0,0)、右下の点が(j,i)の長方形に含まれる1の個数を数える
  for j in range(w):
    if board[i][j] == '1':
      acum[i][j]+=1
    if i!=0:
      acum[i][j]+=acum[i-1][j]
    if j!=0:
      acum[i][j]+=acum[i][j-1]
    if i!=0 and j!=0:
      acum[i][j]-=acum[i-1][j-1]

ans = 10**18
for i in range(2**(h-1)):
  cnt = 0
  list = []
  flag = format(i,'b')[::-1] # '1'と'10'と'100'の区別のために必要
  #print(flag)
  for j in range(len(flag)):
    if flag[j] == '1': # ''をつける！
      cnt += 1
      list.append(j)
  list.append(h-1)
  #print(list)
  x1 = 0
  for x2 in range(w-1): #x1(最初は0)とx1+1の間からx=w-1とx=wの間までの区切り方をそれぞれ確かめる
    y1 = 0
    for y2 in list: #長方形のブロックの右下の点のy座標の候補をすべて試す
      if count(x1,y1,x2,y2) > k: #ある横の区切り方の下で、どのように縦を区切ってもブロックに含まれる1の個数がKより大きくなるとき、条件を満たす切り分け方は存在しない
        cnt += 10**18
      if count(x1,y1,x2,y2) <= k and count(x1,y1,x2+1,y2) > k: #ある位置でブロックを区切ると1の個数がK以下になるが、区切る位置を1つ進めると1の個数がKより大きくなるとき、その位置で区切る必要がある
        cnt += 1
        x1 = x2+1 #ある位置x2で区切ったとき、次からはx2+1を長方形のブロックの左上の点のx座標として見ればよい
        break
      y1 = y2+1 #(いま見ているブロックの右下の点のy座標)+1が次に見るブロックの左上の点のy座標に等しくなる
  y1 = 0
  for y2 in list:
    if count(x1,y1,w-1,y2) > k: #最後に縦で区切った位置以降で、あるブロックに含まれる1の個数がKより大きくなるとき、条件を満たすような区切り方は存在しない
      cnt += 10**18
      break
    y1 = y2+1
  ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 50140
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
  for(int n;cin>>n,n;){
    bool kn[100][101]={{}};
    for(int i=0;i<n;i++){
      int m;
      cin>>m;
      while(m--){
    int p;
    cin>>p;
    kn[i][p]=true;
      }
    }
    int k;
    cin>>k;
    bool pr[100];
    fill(pr,pr+100,true);
    while(k--){
      int l;
      cin>>l;
      for(int i=0;i<n;i++){
    if(!kn[i][l]){
      pr[i]=false;
    }
      }
    }
    cout<<((count(pr,pr+n,true)!=1)?-1:find(pr,pr+n,true)-pr+1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll s,w;
  cin >> s >> w;
  if(s>w){
    cout << "safe" << endl;
  }
  else
    cout << "unsafe" << endl;
}

Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

int n, m;
V memo;
vector<vector<int>> g;
void calc() {
	cin >> n >> m;
	memo.resize(n, -1);
	g.resize(n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int q; cin >> q;
	using T = tuple<int, int, int>;
	vector<T> qs(q);
	rep(i, q) {
		int v, d, c; cin >> v >> d >> c;
		v--;
		qs[i] = (T(v, d, c));
	}
	V anses(n);
	reverse(all(qs));
	rep(i, q) {
		queue<T> que;
		que.push(qs[i]);
		int tp = get<1>(qs[i]);
		while (!que.empty()) {
			int v, d, c;
			tie(v, d, c) = que.front(); que.pop();
			if (memo[v] >= d) continue;
			int nd = d - 1;

			if (memo[v] == -1) {
				anses[v] = c;
			}

			memo[v] = d;
			for (auto e : g[v]) {
				if (memo[e] >= nd) continue;
				que.push(make_tuple(e, nd, c));
			}
		}
	}
	rep(i, n) {
		cout << anses[i] << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 12812
from math import ceil
N,H=map(int,input().split())
a=[]
Amax=0
Bsum=0

for _ in range(N):
    A,B=map(int,input().split())
    Amax=max(A,Amax)
    a.append([B,A])
a.sort(reverse=True)

for i in range(N):
    Bsum+=max(Amax,a[i][0])

if H>Bsum:
    print(ceil((H-Bsum)/Amax)+N)
else:
    n=0
    while H>0:
        H-=max(Amax,a[n][0])
        n+=1
    print(n)

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n];
	int xo=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		xo^=a[i];
	}
	//cout<<xo<<endl;
	int b1,b2;
	for(int i=0;i<n;i++){
		int ans=0;
		for(int j=0;j<32;j++){
			b1=(a[i]&(1<<j));
			b2=(xo&(1<<j));
			//cout<<b1<<"  "<<b2<<endl;
			if(b1!=b2)
				ans+=(1<<j);
		}
		cout<<ans<<" ";
	}
	cout<<endl;

	return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h /2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

typedef std::complex<double> Com;
Com ver[105];

long n;

double cross(Com x, Com y){
    return (conj(x)*y).imag();
}

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < n; i++){
        double x, y;
        scanf("%lf%lf", &x, &y);
        ver[i] = Com(x, y);
    }
    double ans = 0;
    for(int i = 0; i < n-1; i++){
        ans += cross(ver[i], ver[i+1]);
    }
    ans += cross(ver[n-1], ver[0]);
    printf("%.1lf\n", ans/2.0);
}



Measured memory_bytes: 3236
X=int(input())
def ans165(X:int):
    cash=100
    count=0
    while True:
        # cash=int(cash*1.01)
        cash+=cash//100#元本に１パーセントの利子をつけ小数点以下切り捨て
        count += 1#利子をつける回数だけcountを増やす
        if cash>=X:#cashがXの値以上になったらループ終了
            break
    return count
print(ans165(X))


Measured memory_bytes: 9012
import copy

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

partial_sum = copy.deepcopy(A)
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))


Measured memory_bytes: 31592
#include "bits/stdc++.h"

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

int main() {
	int A, B;
	cin >>A >> B;
	cout << max(0, A - 2 * B);
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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;
}

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if(a + b >= x && a <= x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

now = 1000
kabu = 0
temp = 0


for i in range(n-1):
    if A[i+1] > A[i]:
        temp = now//A[i]
        kabu += now//A[i]
        now -= temp*A[i]
    elif A[i+1] == A[i]:
        continue
    else:
        if kabu == 0:
            continue
        else:
            now += A[i]*kabu
            kabu = 0

now += kabu*A[-1]

print(now)


Measured memory_bytes: 61352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef tuple<int,int,int,int> tp;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int H,W;
    cin >> H >> W;
    int V[H][W];
    rep(i,0,H)rep(j,0,W)cin >> V[i][j];
    vector<tp> ans;
    rep(i,0,H){
        rep(j,0,W-1){
            if(V[i][j] % 2 == 0)continue;
            V[i][j+1]++;
            ans.emplace_back(i+1, j+1, i+1, j+2);
        }
        if(i == H-1)break;
        if(V[i][W-1] % 2 == 0)continue;
        V[i+1][W-1]++;
        ans.emplace_back(i+1, W, i+2, W);
    }
    cout << ans.size() << endl;
    rep(i,0,ans.size()){
        cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl;
    }
}

Measured memory_bytes: 5104
C = []
for _ in range(3):
    C.append([int(c) for c in input().split(' ')])

# print(C)

pairs = [(0, 1), (1, 2), (0, 2)]

for i, j in pairs:
    values = [C[i][col] - C[j][col] for col in range(3)]
    if len(set(values)) != 1:
        print('No')
        exit()

for i, j in pairs:
    values = [C[row][i] - C[row][j] for row in range(3)]
    if len(set(values)) != 1:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 38512
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
int n;
cin >> n;
long long int l,r,ans=0;
for(int i=0;i<n;i++) {
  cin >> l>> r;
  ans+=(r-l+1);
}
cout <<ans<<endl;
}


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

int main()
{
        int num;
        bool cards[4][14];
        char a;
        int b;

        for(int i=0; i<4; i++){
                for(int j=0; j<14; j++){
                        cards[i][j] = false;
                }
        }

        scanf("%d\n", &num);

        for(int i=0; i<num; i++){
                scanf("%c %d\n", &a, &b);
                switch(a){
                case 'S' :{ cards[0][b] = true; break; }
                case 'H' :{ cards[1][b] = true; break; } 
                case 'C' :{ cards[2][b] = true; break; }
                case 'D' :{ cards[3][b] = true; break; }
                }
        }

        for(int i=0; i<4; i++){
                for(int j=1; j<14; j++){
                        if( cards[i][j] == false ){ 
                                switch(i){
                                case 0 :{ cout << "S" << " " << j << endl; break; }
                                case 1 :{ cout << "H" << " " << j << endl; break; } 
                                case 2 :{ cout << "C" << " " << j << endl; break; }
                                case 3 :{ cout << "D" << " " << j << endl; break; }
                                }
                        }
                }
        }

        return 0;
}

Measured memory_bytes: 1212
fun main(args: Array<String>) {
    var (x,y,a,b,c)= readLine()!!.split(' ').map { it.toInt() }
    var p_a= readLine()!!.split(' ').map { it.toLong() }.sortedDescending().toMutableList()
    var p_b= readLine()!!.split(' ').map { it.toLong() }.sortedDescending().toMutableList()
    var p_c= readLine()!!.split(' ').map { it.toLong() }.sortedDescending().toMutableList()
    p_a=p_a.subList(0, x)
    p_b=p_b.subList(0, y)
    p_c=p_c.plus(p_a).plus(p_b).sortedDescending().subList(0, x+y).toMutableList()
    println(p_c.sum())
}

Measured memory_bytes: 111168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back

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

}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair< int , int > Pi;
int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};
int main(){
  int tmp[] = {10,50,100,500},n;
  bool ok = false;
  while(cin >> n && n){
    if(ok) cout << endl;
    ok = true;
    int a[4],b[4]={};
    for(int i=0;i<4;i++){
      cin >> a[i];
    }
    int money = (a[3] * 500 + a[2] * 100 + a[1] * 50 + a[0] * 10) - n;
    for(int i=3;i>=0;i--){
      while(money >= tmp[i]){
        money -= tmp[i];
        b[i]++;
      }
    }
    for(int i=0;i<4;i++){
      if(a[i] - b[i] > 0){
        cout << tmp[i] << " " << a[i] - b[i] << endl;
      }
    }
  }
}

Measured memory_bytes: 1160
a,b,c=map(int,input().split())
a=abs(a)
temp=a//c
if(temp>b):
    temp=temp-b
    if(a%c==0):
        if(temp>b):
            print(a-(b*c))
        else:
            print(temp*c)
    else:
        print(a-(b*c))
else:
    if(temp==b):
        if(a%c==0):
            print(0)
        else:
            print(a%c)
    else:
        if(a%c==0):
            b=b-temp;
            if(b%2==0):
                print(0)
            else:
                print(c)
        else:
            b=b-temp;
            if(b%2==0):
                print(a%c)
            else:
                t1=(a%c)-c
                t2=(a%c)+c
                if(abs(t1)>abs(t2)):
                    print(abs(t2))
                else:
                    print(abs(t1))
                
    


Measured memory_bytes: 9092
#include <iostream>
#include <algorithm>
#include <vector>
#define NIL -2000000000-1

struct Node {
    int key, parent = NIL, L_child = NIL, R_child = NIL;
};

std::vector<Node> heap;

void SetNodeRelation(int num) {
    if (num*2 > heap.size()-1) {
        return;
    } else {
        heap.at(num*2).parent = heap.at(num).key;
        heap.at(num).L_child = heap.at(num*2).key;
        SetNodeRelation(num*2);
    }
    if (num*2+1 > heap.size()-1) {
        return;
    } else {
        heap.at(num*2+1).parent = heap.at(num).key;
        heap.at(num).R_child = heap.at(num*2+1).key;
        SetNodeRelation(num*2+1);
    }
}

void Display() {
    for (int i=1; i<heap.size(); i++) {
        std::cout << "node " << i << ": ";
        std::cout << "key = " << heap.at(i).key << ", ";
        if (heap.at(i).parent != NIL) {
            std::cout << "parent key = " << heap.at(i).parent << ", ";
        }
        if (heap.at(i).L_child != NIL) {
            std::cout << "left key = " << heap.at(i).L_child << ", ";
        }
        if (heap.at(i).R_child != NIL) {
            std::cout << "right key = " << heap.at(i).R_child << ", ";
        }
        std::cout << "\n";
    }
}

int main() {
    int total;
    std::cin >> total;

    heap.resize(total+1);
    for (int i=1; i<heap.size(); i++) {
        std::cin >> heap.at(i).key;
    }

    SetNodeRelation(1);
    Display();
}


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int N, ans = 0;
    cin >> N;
    vector<pair<int,int>>red(N),blue(N);
    vector<bool>check(N,false);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        red[i] = make_pair(x, y);
    }
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        blue[i] = make_pair(x, y);
    }

    sort(blue.begin(), blue.end());
    for (int i = 0; i < N; i++) {
        int y_max = -1;
        int memo=-1;
        for (int j = 0; j < N; j++) {
            if ((blue[i].first > red[j].first) && (blue[i].second > red[j].second) && (red[j].second > y_max) && (check[j] == false)) {
                y_max = red[j].second;
                memo = j;
            }
        }
        if (memo >= 0) {
            ans++;
            check[memo] = true;
        }
    }

    cout << ans << endl;


    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

inline bool is_month(int i){
    return 1 <= i && i <= 12;
}

signed main(){
    string s; cin >> s;
    int a = stoi(s.substr(0,2));
    int b = stoi(s.substr(2,2));
    
    if(is_month(a) && is_month(b)){
        cout << "AMBIGUOUS" << endl;
    }else if(is_month(a)){
        cout << "MMYY" << endl;
    }else if(is_month(b)){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
}

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


int main(){
    int n,l;
    cin >> n >> l;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    
    int answer = -1;
    
    for(int i = 0; i < n - 1; i++){
        if(a.at(i) + a.at(i + 1) >= l){
            answer = i;
            break;
        }
    }
    
    if(answer == -1){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        
        for(int i = 0; i < answer; i++){
            cout << i + 1 << endl;
        }
        
        for(int i = n - 2; i >= answer; i--){
            cout << i + 1 << endl;
        }
    }
    
}

Measured memory_bytes: 1152
s = input()
memo = ''
len_s = len(s)
cnt = 0
ans = 0

for i in range(2 * 10 ** 5):
    ans += 1
    if memo == s[cnt]:
        if cnt == len_s - 1:
            ans -= 1
        memo = s[cnt:cnt + 2]
        cnt += 2
    else:
        memo = s[cnt]
        cnt += 1
    if cnt > len_s - 1:
        break

print(ans)


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	string s;
	cin>>s;
	ll res=0;
	for(ll i=0;i<3;i++){
		ll val=0;
		for(ll j=i;j<3;j++){
			if(s[j]=='S')
				break;
			val++;
		}
		res=max(res,val);
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3812
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
long long int dp[100040] = {};
int main() {
	int bitdp[4] = {};
	int a, b, c, d;
	string s;
	cin >> s;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int sum = a;
				if (i == 0) {
					sum = sum + b;
				}
				else {
					sum = sum - b;
				}
				if (j == 0) {
					sum = sum + c;
				}
				else {
					sum = sum - c;
				}
				if (k == 0) {
					sum = sum + d;
				}
				else {
					sum = sum - d;
				}
				if (sum == 7) {
					cout << a;
					if (i == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << b;
					if (j == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << c;
					if (k == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << d;
					cout << "=7";
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W = list(map(int, sys.stdin.readline().split()))
A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]


def ok(h, w):
    return 0 <= h < H and 0 <= w < W


def dfs(h, w):
    A[h][w] = '.'
    dh = [0, 1, 0, -1]
    dw = [1, 0, -1, 0]
    cnt = 0
    for i, j in zip(dh, dw):
        cnt += ok(h + i, w + j) and A[h + i][w + j] == '#'
    if cnt == 1:
        for i, j in zip(dh, dw):
            if ok(h + i, w + j) and A[h + i][w + j] == '#' and i >= 0 and j >= 0:
                return dfs(h + i, w + j)
    return cnt == 0 and h == H - 1 and w == W - 1


if dfs(0, 0):
    print('Possible')
else:
    print('Impossible')


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

typedef struct {
    bool L, R;
} p_t;

int main() {
    Int a[3][3] = {};
    for (Int i = 0; i < 3; i++) {
        for (Int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    bool b[3][3] = {};
    Int n;
    cin >> n;
    vector<Int> c(n);
    for (Int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < 3; j++) {
            for (Int k = 0; k < 3; k++) {
                if (a[j][k] == c[i]) {
                    b[j][k] = true;
                }
            }
        }
    }
    bool check = false;
    for (Int i = 0; i < 3; i++) {
        if (b[i][0] and b[i][1] and b[i][2]) {
            check = true;
        }
    }
    for (Int i = 0; i < 3; i++) {
        if (b[0][i] and b[1][i] and b[2][i]) {
            check = true;
        }
    }
    if (b[0][0] and b[1][1] and b[2][2]) {
        check = true;
    }
    if (b[0][2] and b[1][1] and b[2][0]) {
        check = true;
    }
    dump(check ? "Yes" : "No");
    return 0;
}


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

int N;
map<string,bool> vis;

int main(){
    cin>>N;
    string Last;
    cin>>Last;
    vis[Last]=1;
    int Ans=1;
    for(int i=2;i<=N;i++){
        string tmp;
        cin>>tmp;
        if(vis.count(tmp)||tmp[0]!=Last[Last.length()-1])
            Ans=0;
        vis[Last=tmp]=1;
    }
    if(Ans) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0217
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int asd = Int32.Parse(Console.ReadLine());
                if (asd == 0) { break; }
                int[] kanja = new int[asd];
                int[] yobi = new int[asd * 2];
                for (int i = 0; i < asd; i++)
                {
                    int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    kanja[i] = a[1] + a[2];
                    yobi[i * 2] = a[0];
                    yobi[i * 2 + 1] = kanja[i];
                }
                Array.Sort(kanja);
                for (int i = 0; i < asd; i++)
                {
                    if (kanja[asd-1] == yobi[i * 2 + 1])
                    {
                        Console.WriteLine(yobi[i * 2] + " " + yobi[i * 2 + 1]);
                        break;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 10072
#include<stdio.h>
#include<string.h>

void push();

int head,X[1000];//Xがスタックの配列,headはスタックの位置をしめす。

int main(){
  char s[100];
  int a, b;
  while(scanf("%s",s)!=EOF){

    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
    
  }
  printf("%d\n",pop());
  return 0;
  
}

void push(int x){

  X[++head]=x;
  
}
int pop(){
  head--;
  return(X[head+1]);
}



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

using namespace std;


int main(void){

    string str; cin >> str;

    if(str[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    int count = 0;
    for(int i = 2;i < str.length()-1;i++){
        if(str[i] == 'C') count++;
    }

    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }
    count = 0;

    for(int i = 0;str[i] != '\0';i++){
        if('A' <= str[i] && str[i] <= 'Z') count++;
    }

    if(count == 2) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int k,s;
  cin >> k >> s;
  int cnt = 0;
  for(int x = 0;x <= k;x++){
    for(int y = 0;y <= k;y++){
      int z = s - x - y;
      if(0 <= z && z <= k){
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    string S, T;
    cin>>S>>T;
    int A, B;
    cin>>A>>B;
    string U;
    cin>>U;
    if(S==U){
        cout<<A-1<<" "<<B<<endl;
    }
    else{
        cout<<A<<" "<<B-1<<endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str;
		String[] arrStr;
		int cntDivisor = 0;
		try {
			str = br.readLine();
			arrStr = str.split(" ");

			int s = Integer.parseInt(arrStr[0]);
			int e = Integer.parseInt(arrStr[1]);
			int chk = Integer.parseInt(arrStr[2]);

			for (int i =s; i <= e; i++) {
				if(chk%i ==0){
					cntDivisor++;
				}
			}

			System.out.println(cntDivisor);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
    int D;
    cin >> D;
    if (D == 25) {
        cout << "Christmas" << endl;
    } else if (D == 24) {
        cout << "Christmas Eve" << endl;
    } else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else {
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[25000001] = {};
	vector<tuple<ll, ll>> vec;
	string s;
	string t;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> a;
	cin >> b;
	if (a<b)
	{
		cout << 0 << endl;

	}
	else
	{
		cout << 10 << endl;

	}
	//cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;
ll pow(ll x, ll n)
{
    if(n==0){
        return 1;
    }
    if(n&1){ // Power is odd
        ll val=pow(x,n/2);
        return val*val*x;
    }else{ // Power is even
        ll val=pow(x,n/2);
        return val*val;
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll h; cin >> h;
        ll cnt=0;
        while(h>1){
            h/=2;
            cnt++;
        }
        // cout << cnt << endl;
        ll ans = pow(2,cnt+1) -1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
import time

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return

#C
def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return

#D
def D():
    n = II()
    print(n * (n - 1) // 2)
    return

#E
def E():
    start = time.time()
    n = II()
    a = LIR_(n)
    ans = 0
    tern = [0] * n
    while 1:
        ans += 1
        f = True
        c = defaultdict(int)
        for i in range(n):
            if c[i]:
                continue
            if tern[i] == n - 1:
                continue
            rival = a[i][tern[i]]
            if c[rival]:
                continue
            if tern[rival] == n - 1:
                continue
            if a[rival][tern[rival]] == i:
                c[i] += 1
                c[rival] += 1
                tern[rival] += 1
                tern[i] += 1
                f = False
        if time.time() - start >= 1:
            print(n * (n - 1) // 2)
            return
        if f:
            if tern == [n - 1] * n:
                print(ans-1)
                return
            else:
                print(-1)
                return
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()


Measured memory_bytes: 64088
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=1e5+5,mo=1e9+7;
int i,j,n,l,a[maxn],s[maxn],now,re[maxn];
ll ans;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]),s[i]=(s[i-1]+a[i])%mo;
	now=s[n-1]-s[1];
	re[1]=re[0]=1;
	fo(i,2,n) re[i]=(ll)(mo-mo/i)*re[mo%i]%mo;
	fo(l,1,n-2){
		ans+=(ll)now*re[l+1]%mo*re[l+2]%mo;
		(now+=s[n-l-1]-s[l+1])%=mo;
	}
	ans<<=1;
	fo(l,1,n-1) ans+=(ll)(s[l]+s[n]-s[n-l])*re[l+1]%mo;
	(ans+=s[n])%=mo;
	fo(l,2,n) ans=ans*l%mo;
	printf("%lld\n",(ans+mo)%mo);
}

Measured memory_bytes: 1408
#include <stdio.h>

#define NMAX 500000
#define NIL -1
int n;
int root = NIL;
int id = 0;       // new node id (=node count in the tree)
int P[NMAX + 10]; // parent
int L[NMAX + 10]; // left child
int R[NMAX + 10]; // right child
int V[NMAX + 10]; // value

void insert(int val) {
    V[id] = val;
    L[id] = NIL;
    R[id] = NIL;
    // all below is to set P[id], L[P[id]], R[P[id]]

    if (root == NIL) {
        P[id] = NIL;
        root = id;
        id++;
        return;
    }
    int c = root;
    int parent = NIL; // parent = P[id]
    // find P[id]
    while (c != NIL) {
        parent = c;
        if (val <= V[c])
            c = L[c];
        else
            c = R[c];
    }
    P[id] = parent;
    // update L[parent] or R[parent]
    if (V[id] <= V[parent])
        L[parent] = id;
    else
        R[parent] = id;
    id++;
}

void pre_order(int _root) {
    if (_root == NIL)
        return;
    printf(" %d", V[_root]);
    pre_order(L[_root]);
    pre_order(R[_root]);
}

void in_order(int _root) {
    if (_root == NIL)
        return;
    in_order(L[_root]);
    printf(" %d", V[_root]);
    in_order(R[_root]);
}

int main() {
    scanf("%d", &n);
    char cmd[10];
    int val;
    for (int i = 0; i < n; i++) {
        scanf("%s", cmd);
        if (cmd[0] == 'i') {
            scanf("%d", &val);
            insert(val);
        } else {
            in_order(root);
            printf("\n");
            pre_order(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 10500
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string S;
	cin >> S;
	N = S.size();
	if (N & 1) {
		cout << "No" << endl;
		return 0;
	}
	rep(i, N) {
		if ((i & 1) && S[i] != 'i' || i % 2 == 0 && S[i] != 'h') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    string s;
    cin >> s;
    stack<char> st;
    int sum = 0;
    st.push(s[0]);
    for(int i = 1; i < s.size(); ++i) {
        if (st.empty() || st.top() == s[i]) {
            st.push(s[i]);
        }
        else {
            st.pop();
            sum += 2;
        }
    }
    cout << sum << "\n";
}

Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        c: usize,
        dv: [[usize; c]; c],
        cv: [[usize; n]; n]
    };

    let mut cnv:Vec<Vec<usize>> = (0..3).map(|_| {(0..c).map(|_| 0).collect()}).collect();
    for i in 0..n {
        for j in 0..n {
            cnv[(i+j)%3][ cv[i][j]-1 ] += 1;
        }
    }

    let mut mv = 1000*500*500;
    for u in 0..c {
        for v in 0..c {
            if u==v { continue; }
            for w in 0..c {
                if u==w || v==w { continue; }
                let a = (0..c).map(|cc| {
                    let a1 = dv [cc] [u] * cnv[0][cc];
                    let a2 = dv [cc] [v] * cnv[1][cc];
                    let a3 = dv [cc] [w] * cnv[2][cc];
                    a1+a2+a3
                }).sum();
                if mv > a { mv = a;}
            }
        }
    }

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


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

int main() {
    vector<int> P(3), D(2);
    for (auto& i : P) cin >> i;
    for (auto& i : D) cin >> i;

    int ans = 1 << 28;
    for (auto i : P) {
        for (auto j : D) {
            ans = min(ans, i + j - 50);
        }
    }

    cout << ans << endl;
}

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

int mul_3(int x) {
  if(x % 3 == 0) {
    return 1;
  }
  else {
    return 0;
  }
}

int main() {
  int A, B, C;
  cin >> A >> B;
  C = A + B;
  int a, b, c;
  a = mul_3(A);
  b = mul_3(B);
  c = mul_3(C);
  if(a + b + c > 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 3536