akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, M;
  cin >> N >> M;
  map<ll,int> mp;
  rep(i, 0, N) {
    int a; cin >> a;
    ++mp[a];
  }
  rep(i, 0, M) {
    int b, c; cin >> b >> c;
    mp[c] += b;
  }

  ll ans = 0;
  int cnt = 0;
  for (auto it = rbegin(mp); it != std::rend(mp); ++it) {
    if (cnt == N) break;
    ll x = min(it->se, N-cnt);
    ans += x * it->fi;
    cnt += x;
  }
  cout << ans << endl;
}

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

using namespace std;

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

map <pair<long long, long long>, int> mp;
long long pw[200005];

int main() {
	int n;
	scanf("%d", &n);
	
	pw[0] = 1LL;
	for (int i = 1; i <= n; i++) {
		pw[i] = (pw[i - 1] * 2LL) % MOD;
	}
	
	int extra = 0;
	
	for (int i = 0; i < n; i++) {
		long long x, y;
		scanf("%lld%lld", &x, &y);
		
		if (x < 0) {
			x *= -1;
			y *= -1;
		}
		
		long long gcd = abs(__gcd(x, y));
		
		if (x == 0 && y == 0) extra++;
		else if (x == 0) {
			mp[make_pair(INF, 0)]++;
		}
		else if (y == 0) {
			mp[make_pair(0, -INF)]++;
		}
		else {
			mp[make_pair(x / gcd, y / gcd)]++;
		}
	}
	
	long long res = 1LL;
	
	for (auto v : mp) {
		pair <long long, long long> rev;
		if (v.first.second >= 0) rev = make_pair(v.first.second, -v.first.first);
		else rev = make_pair(-v.first.second, v.first.first);
		if (mp.count(rev)) {
			long long tot = pw[v.second] + pw[mp[rev]] - 1;
			mp[rev] = 0;
			res = (res * tot) % MOD;
		}
		else {
			res = (res * pw[v.second]) % MOD;
		}
		
		mp[make_pair(v.first.first, v.first.second)] = 0;
	}
	
	printf("%lld\n", (res - 1 + MOD + extra) % MOD);
}


Measured memory_bytes: 17652
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string S;
    cin>>S;
    int res=S.size();
    int a=S.size();
    for(int i=1;i<S.size();i++){
        if(S[i]!=S[i-1])
            res=min(res,max(i,a-i));
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n >> m;
  ll a[n]={};
  for(int i=0;i<m;i++){
    ll b;
    cin >> b;
    a[b]=1;
  }

  ll dp[100100]={};
  dp[0]=1;
  if(a[1]!=1)dp[1]=1;
  else dp[1]=0;

  for(int i=0;i<n;i++){
    if(a[i+2]!=1)dp[i+2]=(dp[i+1]+dp[i])%mod;
    else dp[i+2]=0;
  }

  cout << dp[n] << endl;

}

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

using namespace std;

const int max_n = 5555, inf = 1000111222;

int n, k;
string s;

string getr(const string &s, int pos) {
    return {s.rbegin() + s.length() - 1 - pos, s.rbegin() + s.length() - 1 - pos + n};
}

string one_step(const string &s) {
    string rs = s;
    reverse(rs.begin(), rs.end());
    string t = s + rs;
    string res = s;
    for (int i = 1; i <= n; ++i) {
        res = min(res, t.substr(i, n));
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k >> s;
    --k;
    char mn = s[0];
    for (char c : s) {
        mn = min(mn, c);
    }
    if (k) {
        string rs = s;
        reverse(rs.begin(), rs.end());
        int mx = 0, pos = 0;
        string t = s + rs;
        for (int i = 0; i < t.length(); ++i) {
            int st = i;
            while (i < t.length() && t[i] == mn) {
                ++i;
            }
            int cnt = i - st;
            if (cnt == 0 || i < n) {
                continue;
            }
            if (i >= n && (mx < cnt || mx == cnt && getr(t, pos) > getr(t, i - 1))) {
                pos = i - 1;
                mx = cnt;
            }
        }
        //cout << t << endl;
        //cout << mx << " " << pos << " " << getr(t, pos) << endl;
        s = t.substr(pos - n + 1, n);
        k--;
        //reverse(s.begin(), s.end());
        //cout << "$" << s << " " << k << endl;
        mx = min(mx, n);
        while (k--) {
            string rs = s;
            reverse(rs.begin(), rs.end());
            string t = s + rs;
            s = t.substr(s.length() + mx - n, n);
            mx *= 2;
            mx = min(mx, n);
            if (mx == n) {
                break;
            }
        }
        //cout << s << endl;
    }
    cout << one_step(s) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int>dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1]<<endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


int main(void) {
	int64 A, B, Q;
	cin >> A >> B >> Q;
	vector<int64> s(A), t(B);
	REP(i, A) cin >> s[i];
	REP(j, B) cin >> t[j];
	while(Q--) {
		int64 res = INF_LL;
		int64 x; cin >> x;
		int64 ls = upper_bound(all(s), x)-s.begin()-1, rs = lower_bound(all(s), x)-s.begin();
		int64 lt = upper_bound(all(t), x)-t.begin()-1, rt = lower_bound(all(t), x)-t.begin();
		if (ls != -1 && lt != -1)
			chmin(res, x - min(s[ls], t[lt]));
		if (ls != -1 && rt != t.size())
			chmin(res, min(abs(x-s[ls]), abs(x-t[rt])) + t[rt]-s[ls]);
		if (lt != -1 && rs != s.size())
			chmin(res, min(abs(x-t[lt]), abs(x-s[rs])) + s[rs]-t[lt]);
		if (rs != s.size() && rt != t.size())
			chmin(res, max(s[rs], t[rt]) - x);
		cout << res << endl;
	}
}


Measured memory_bytes: 2944
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define sc(x) scanf("%lld",&(x));
#define sci(x) scanf("%d",&(x));
#define si signed
#define P pair<int,int>
#define fi first
#define se second

using namespace std;
int n,m;

si main() {
    cin>>n;
    printf("%.6f",1.0/27*n*n*n);


    return 0;
}


Measured memory_bytes: 256
import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

void main() {
    int N = readln.chomp.to!int,
        K = readln.chomp.to!int,
        X = readln.chomp.to!int,
        Y = readln.chomp.to!int;
  int ans;

  if (N <= K) {
    ans = N * X;
  } else {
    int cost1 = K * X,
        cost2 = (N - K) * Y;
    ans = cost1 + cost2;
  }

  writeln(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
   int a[10], i, max, t, j=3;
   for(i=0; i<10; i++) scanf("%d", &a[i]);
   while(j--) {
      max=a[0];
      for(i=1; i<10; i++) if(a[i]>max)  { max=a[i]; t=i; }
      printf("%d\n", max);
      a[t]=0;
      t=0;
   }
   return 0;
}

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

int main() {
    ll D, G;
    cin >> D >> G;
    vector<ll> p(D), c(D);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    ll INF = 1LL << 60;
    ll MIN = INF;

    for (int i = 0; i < (1 << D); i++) {
        ll score = 0;
        ll count = 0;
        for (int j = 0; j < D; j++) {
            if (i & (1 << j)) {
                int val = 100*(j+1);
                score += val*p[j];
                score += c[j];
                count += p[j];
            }
        }

        if (score >= G) {
            MIN = min(MIN, count);
        }

        for (int j = D-1; j >= 0; j--) {
            if (i & (1 << j)) continue;
            for (int k = 0; k < p[j]; k++) {
                if (score >= G) break;
                score += 100*(j+1);
                count ++;
            }
        }
        MIN = min(MIN, count);
    }

    cout << MIN << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		int N = sc.nextInt();
		String S = sc.next();
		
		// 結果の出力
		int count = 0;
		while (S.indexOf("ABC") >= 0) {
			count++;
			S = S.substring(S.indexOf("ABC") + 3);
		}
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 35772
#include<cstdio>
#include<cctype>

int main() {
    char ch;
    while (1) {
        scanf("%c", &ch);
        if (islower(ch)) {
            ch = toupper(ch);
        } else if (isupper(ch)) {
            ch = tolower(ch);
        }
        printf("%c", ch);
        if (ch == '\n') break;
    }
    return 0;
}

Measured memory_bytes: 940
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  string s; cin>>s;
  int a;
  a=s.length();
  for(int i=0;i<a;i++){
    cout<<"x";
  }
  return 0;
}

Measured memory_bytes: 256
long p[444][444],a[444],s[444],S;
long f(i,j,k){
	if(j-i<2)return 0;
	if(!p[i][j]){
		p[i][j]=9e18;
		for(k=i;++k<j;)p[i][j]=fmin(p[i][j],f(i,k)+f(k,j)+s[j]-s[i]);
	}
	return p[i][j];
}
main(i){
	while(~scanf("%d",a-i--))s[-i]=S+=i?a[~i]:0;
	printf("%ld",f(0,~i));
}

Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())

def factorial(a):
    if a == 0:
        return 1
    else:
        return (a * factorial(a - 1)) % 1000000007

if n < m:
    n, m = m, n

if n - m >= 2:
    print(0)

elif n - m == 1:
    z = ((factorial(n) % 1000000007) * (factorial(m) % 1000000007)) % 1000000007
    print(z)

else:
    z = 2 * ((factorial(n) % 1000000007) * (factorial(m) % 1000000007)) % 1000000007
    print(z)


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

 using namespace std;

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

 vector<int> A(N);
  for (int i = 0; i < N; ++i) {
 cin >> A[i];
 --A[i];
 }
 vector<int> B(N);
 for (int i = 0; i < N; ++i) {
 cin >> B[i];
 }
 vector<int> C(N-1);
 for (int i = 0; i < N; ++i) {
 cin >> C[i];
 }

 int ans = 0;
 for (int i = 0; i < N; ++i) {
 ans += B[A[i]];
 if (i > 0 && A[i] == A[i-1]+1) {
 ans += C[A[i-1]];
 }
 }

  cout<<ans;
}


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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

// 距離でやると困る
int main(){
    int N;
    cin >> N;

    int a[N], b[N], c[N], d[N];
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
    for(int i=0; i<N; i++) cin >> c[i] >> d[i];

    P rl[N];
    for(int i=0; i<N; i++){
        rl[i] = P(c[i], d[i]);
    }

    sort(rl, rl+N);

    int cnt = 0;
    bool used[N];
    fill(used, used+N, false);
    for(int i=0; i<N; i++){
        int rx = rl[i].first;
        int ry = rl[i].second;
        int mx = -1;
        int ind = -1;
        for(int j=0; j<N; j++){
            if(used[j]) continue;
            if(i == j) continue;
            if(rx <= a[j] || ry <= b[j]) continue;
            if(mx < b[j]){
                mx = b[j];
                ind = j;
            }
        }
        if(ind != -1){
            cnt++;
            used[ind] = true;
            // cout << i << " " << ind << endl;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int h,w;cin>>h>>w;
	vector<vector<char>> a(h+2,vector<char>(w+2));
	rep(i,h+2)rep(j,w+2){
		if(i==0||(j==0||j==w+1)||i==h+1){
			a[i][j]='#';
		}else{
			cin>>a[i][j];
		}
	}
	rep(i,h+2)rep(j,w+2){
		cout<<a[i][j];
		if(j==w+1)cout<<"\n"<<endl;
	}
}

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

int main() {
  int TH, T, AH, A;
  cin >> TH >> T >> AH >> A;

  for (int i = 0; i < 200; i++) {
    if (i % 2 == 0) {
      AH -= T;
    } else {
      TH -= A;
    }



    if (AH <= 0) {
      cout << "Yes" << endl;
      return 0;
    }

    if (TH <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	int n,y,m,d,ans,small;
	cin >> n;
	for(int i=0;i<n;i++){
		ans =0;
		cin >> y >> m >> d;
		if(y%3==0){
			ans += 200-20*(m-1)-d+1;
		}else{
			small = (m-1)/2;
			ans += 195-20*(m-1-small)-19*small-d+1;
		}
		ans += 200*(333-y/3)+195*(666-(y-y/3));
		cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
  int* x = new int[5];
  int* y = new int[5];
  cin >> x[1] >> y[1] >> x[2] >> y[2];
  int dx, dy;
  if(x[1] <= x[2]){
    dx=x[2]-x[1];
    if(y[1] <= y[2]){
      dy = y[2] - y[1];
      x[3] = x[2] - dy;
      y[3] = y[2] + dx;
      x[4] = x[3] - dx;
      y[4] = y[3] - dy;
      
    }else{
      dy = y[1] - y[2];
      x[3] = x[2] + dy;
      y[3] = y[2] + dx;
      x[4] = x[3] - dx;
      y[4] = y[3] + dy;
      
    }    
  }else{
    dx = x[1] - x[2];
    if(y[1] <= y[2]){
      dy = y[2] - y[1];
      x[3] = x[2] - dy;
      y[3] = y[2] - dx;
      x[4] = x[3] + dx;
      y[4] = y[3] - dy;
      
    }else{
      dy = y[1] - y[2];
      x[3] = x[2] + dy;
      y[3] = y[2] - dx;
      x[4] = x[3] + dx;
      y[4] = y[3] + dy;
    
    }
  }
  cout << x[3] << ' ' << y[3] << ' ' << x[4] << ' ' << y[4] << endl;
  return 0;
}

Measured memory_bytes: 256
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
tmp = 0
for i in range(N):
  tmp += A[i]
  a.append(tmp)
tmp = 0
for i in range(M):
  tmp += B[i]
  b.append(tmp)

total = 0
count = []
best_j = len(b)-1
for i in range(len(a)):
  if a[i] <= K:
    for j in range(best_j, -1, -1):
      total = a[i] + b[j]
      if total <= K:
        count.append(i+j)
        best_j = j
        break
if len(count) == 0:
  print(0)
else:
  print(max(count))
    
  

Measured memory_bytes: 48776
using System;

namespace NTL_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long ret = n;
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    ret /= i; ret *= i - 1;
                    while (n % i == 0) n /= i;
                }
            }
            Console.WriteLine(n == 1 ? ret : ret / n * (n - 1));
        }
    }
}


Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  // vector<vector<vector<int> > > DP =  vector<vector<vector<int> > >(100001,vector<vector<int> >(2,vector<int>(2,0)));
  vector<vector<int> > DP (100001,vector<int>(2,0));
void solve(void)
{
  string L;
  cin>>L;
  vector<int> n;
  for (int i = 0; i < L.size(); i++)
  {
    n.push_back(L[i] - '0');
  }
  int l = n.size();
    DP[0][0] = 1;
  for (int i = 0; i < l; i++)
  {
    // for (int j = 0; j < 2; j++)
    // {
    //   for (int k = 0; k < 2; k++)
    //   {
    //     for (int p = 0; p <= (j?1:n[i]); p++)//未満フラグが経って入れば9まで走査 未満フラグが経っていなければその数字の上限となりうる桁まで走査
    //     {
    //       DP[i+1][j||p<n[i]] += DP[i][j]*2;
    //       DP[i+1][j||p<n[i]] %= MOD;
    //     }
        
    //   }
      
    // }
    DP [i+1][1] += (DP[i][1]*3)%MOD;
    DP[i+1][1] %= MOD;

    if(n[i] == 1)
    {
      DP[i+1][1] += DP[i][0];
      DP[i+1][0] += (DP[i][0]*2%MOD);
      DP[i+1][1] %= MOD;
      DP[i+1][0] %= MOD;


    }
    else
    {
      DP[i+1][0] += DP[i][0];
      DP[i+1][0] %= MOD;
    }
    DP[i+1][0] %=MOD;
    DP[i+1][1] %=MOD;
    
  }
  // DEBUG(DP[0]);
  cout<<(DP[l][0] + DP[l][1])%MOD<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 6984
s=int(input())

def func(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1

a=[]
a.append(s)
for i in range(1,1000000):
    p=func(a[i-1])
    if not p in a:
        a.append(p)
    else:
        print(i+1)
        break

Measured memory_bytes: 3316
//   Rishabh Agarwal
#include <bits/stdc++.h>

using namespace std;

typedef long double ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
        long long int n;
        cin>>n;
        long long int a;
        ll ans=1;
        for(ll x=0; x<n; x++){
           cin>>a;
          if(ans!=-1){
                ans=ans*a;
            }
            if(a==0){
                ans=0;
            }
            if(ans>1000000000000000000||ans<0){
                ans=-1;
            }
            
        }
        cout<<(long long int)ans;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <map>

using namespace std;

// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 1 2 3 4 5 1 2 3 1  2  3  2  3  4  5  6  7  2  3  4

// 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//  5  6  7  4  5  6  3  4  5  5  6  7  8  9 10  1  2  3  4  5

int main()
{
  int N;
  cin >> N;
  
  vector< int > dp(N + 5, 1e9);
  for(int i = 0; i < 6; i++) dp[i] = i;
  int check9 = 9, check6 = 6;
  vector< int > check;
  for(int i = 6; i <= N; i++) {
    if(i % check6 == 0) {
      check.push_back(check6);
      dp[i] = 1;
      check6 *= 6;
    }
    else if(i % check9 == 0) {
      check.push_back(check9);
      dp[i] = 1;
      check9 *= 9;
    }
    else {
      int tmp = 1e9;
      for(auto c : check) {
	tmp = min(tmp, dp[i - c]);
      }
      dp[i] = min(dp[i-1]+1, tmp + 1);
    }
  }

  cout << dp[N] << endl;
  
  return 0;
}


Measured memory_bytes: 640
#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>;
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a >= 10 || b >= 10)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    int alp[n][26];
    string s[n];
    
    rep(i, n)   cin >> s[i];
    rep(i, n){
        rep(j, 26){
            alp[i][j] = 0;
        }
    }
    
    rep(i, n){
        int len = s[i].size();
        rep(j, len){
            alp[i][s[i][j] - 'a']++;
        }
    }
    
    int cnt;
    char tmp;
    rep(j, 26){
        cnt = INFTY;
        rep(i, n){
            cnt = min(cnt, alp[i][j]);
        }
        tmp = j + 'a';
        rep(k, cnt){
            cout << tmp;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#C
import itertools

def point(abcd,lst):
    p = 0
    for i in range(Q):
        a,b,c,d = abcd[i]
        if lst[b-1] - lst[a-1] == c:
            p += d
    return p

N,M,Q = map(int,input().split())
check = [None]*Q
for i in range(Q):
    check[i] = list(map(int,input().split()))

#print(check)
#print(check[1])

nums = list(range(1,M+1))
ans = 0

for comb in itertools.combinations_with_replacement(nums, N):
    #print(sorted(comb))
    ans = max(point(check,sorted(comb)),ans)
print(ans)

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll a,b,c,s,t,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll count;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>a>>b;

		cout<<(a*(a-1))/2+(b*(b-1))/2;



	return 0;

}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int dx=c-a,dy=d-b;
	rep(i,dx)cout<<"R";
	rep(i,dy)cout<<"U";
	rep(i,dx)cout<<"L";
	rep(i,dy)cout<<"D";
	cout<<"D";
	rep(i,dx+1)cout<<"R";
	rep(i,dy+1)cout<<"U";
	cout<<"L"<<"U";
	rep(i,dx+1)cout<<"L";
	rep(i,dy+1)cout<<"D";
	cout<<"R";
}

Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

string s;

signed main(){
    io();

    in(s);
    int ans=700;
    for(auto e:s){
        if(e=='o') ans+=100;
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, (int)1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, (int)1);
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

// ATC001(https://atcoder.jp/contests/atc001/tasks/unionfind_a)
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, Q;
    cin >> N >> Q;

    UnionFind uf(N);

    rep(i,Q){
        int  A, B;
        cin >> A >> B;
        --A; --B;
        uf.merge(A, B);
    }
	int ans = 0;
	rep(i,N){
		ans = max(ans, uf.size(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N;cin >> N;

    const int MAXN=21;

    int V[MAXN];
    int C[MAXN];

    rep(i,N)cin >> V[i]; 
    rep(i,N)cin >> C[i];
    int ans = 0;
    rep(i,N){
        if(V[i]>C[i])ans += (V[i]-C[i]);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main()
{
    int t; cin>>t;
    if(t==0)return cout<<0,0;
    long double s = 1;
    vector<ld> vec(t);
    for(int i=0; i<t; cin>>vec[i++]); 
    sort(vec.begin(),vec.end());
    for(auto &it: vec){
        if(it==0)return cout<<0,0;
        if(s>1e18/it or s<0)return cout<<-1,0;
        s *= it;
    }
    cout<<(ll)(s)<<'\n';
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define lli long long int 
#define MOD 1000000007
#define fi(i,a,n) for(lli i = a; i < n; i++)
#define fd(i,a,n) for(lli i = a; i > n; i--)
#define fv(i,a) for(auto i:a)
#define pb push_back
#define mp make_pair

lli dp[10000000];

lli cost(lli i,lli arr[],lli last,lli n,lli k)
{
	if(i>n-1)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	if(i==n-1)
		return abs(arr[i]-last);
	lli ans=abs(last-arr[i])+cost(i+1,arr,arr[i],n,k);
	if(n-i<k)
	{
		for(lli j=1;j<=n-i-1;j++)
		ans=min(ans,abs(last-arr[i+j])+cost(i+j+1,arr,arr[i+j],n,k));	
		dp[i]=ans;
		return dp[i];
	}
	for(lli j=1;j<k;j++)
		ans=min(ans,abs(last-arr[i+j])+cost(i+j+1,arr,arr[i+j],n,k));
	dp[i]=ans;
	return dp[i];
}

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

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
lli t=1;
//cin>>t;
while(t--)
{
	memset(dp,-1,sizeof(dp));
	lli n,k;
	cin>>n>>k;
	lli arr[n];
	fi(i,0,n)
	cin>>arr[i];
	cout<<cost(1,arr,arr[0],n,k);
}
return 0;
}

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

int get_Max_size(int money, int base) {
  int count = 0;
  int tmp_money = money;
  for (;;) {
    if (tmp_money - base > 0) {
      tmp_money -= base;
      count += 1;
    } else {
      break;
    }
  }
  return count;
}

int main() {
  int N = 0;
  int Y = 0;
  std::cin >> N;
  std::cin >> Y;
  if (Y / 1000 == N) {
    std::cout << "0"
              << " "
              << "0"
              << " " << N << std::endl;
    return 0;
  } else if (Y / 5000 == N) {
    std::cout << "0"
              << " " << N << " "
              << "0" << std::endl;
    return 0;
  } else if (Y / 10000 == N) {
    std::cout << N << " "
              << "0"
              << " "
              << "0" << std::endl;
    return 0;
  }

  int x = 0;
  int y = 0;
  int z = 0;

  int x_counter = 0;
  int y_counter = 0;
  int z_counter = 0;

  int max_10000 = get_Max_size(Y, 10000);

  for (int i = 0; i < max_10000 + 1; i++) {
    int tmp_Y = Y - 10000 * i;
    x_counter = i;
    int max_5000 = get_Max_size(tmp_Y, 5000);
    for (int j = 0; j < max_5000 + 1; j++) {
      y_counter = j;
      z_counter = (tmp_Y - 5000 * j) / 1000;

      if (x_counter + y_counter + z_counter == N) {
        std::cout << x_counter << " " << y_counter << " " << z_counter
                  << std::endl;
        return 0;
      }
    }
  }

  std::cout << "-1"
            << " "
            << "-1"
            << " "
            << "-1" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N, A, B;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> A >> B;

  int ans = min(A * N, B);

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


Measured memory_bytes: 384
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
               
                int n=sc.nextInt();
                
                int a[]=new int[n];
                int v[]=new int[100001];
                long s=0;
                for(int i=0;i<n;i++){
                    a[i]=sc.nextInt();
                    v[a[i]]++;
                    s+=a[i];
                }
                int q=sc.nextInt();
                while(q-->0) {
                	int b=sc.nextInt();
                	int c=sc.nextInt();
                	int res=v[b];
                	
                	if(b>c)
                		s-=(b-c)*res;
                	else
                		s+=(c-b)*res;
                	v[b]=0;
                	v[c]+=res;
                	
                	System.out.println(s);
                }
                
        
                
           
            
        }catch(Exception e){
            return;
        }
    } 
}



Measured memory_bytes: 57304
#include <stdio.h>
int main()
{
	int a,b,t=0,m=1,d=1;
	
	scanf("%d %d",&a,&b);
	
	while(m<a){
	
		if(m==d){
			t++;
		}
		
		d++;
		
		if(d>31){
			d=d-31;
			m++;
		}
	}
	while(d<=b){
		if(m==d){
			t++;
		}
		d++;
	}
	printf("%d",t);
	return 0;
}

Measured memory_bytes: 128
from sys import stdin
import sys
# sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]

# def comp0(n, aList):
# 	num=n//2
# 	score=[[None for _ in range(num)] for i in range(n)]
# 	
# 	for i in range(n):
# 		
# 		if i==0:
# 			score[i][0]=aList[i]
# 		else:
# 			score[i][0]=max(aList[i], score[i-1][0])
# 			
# 		for j in range(1, num):
# 			nextScore=[]
# 			if i>=1:
# 				s=score[i-1][j]
# 				if s is not None:
# 					nextScore.append(s)
# 			if i>=2:
# 				s=score[i-2][j-1]
# 				if s is not None:
# 					s+=aList[i]
# 					nextScore.append(s)
# 			if len(nextScore)>0:
# 				nextScore=max(nextScore)
# 				score[i][j]=nextScore
# 	
# # 		print(i, aList[i], *[str(s) for s in score[i]], sep="\t")
# 	
# 	print(score[-1][-1])
	
	
def comp(n, aList):
	num=n//2
	score=[[None for _ in range(num)] for i in range(3)]
# 	base=[0 for _ in range(num)]
	
	for i in range(n):
		for j in range(max(0, num-(n-i)//2-1), min(i//2+1,num)):
			if j==0:
				if i==0:
					ns=aList[i]
				else:
					ns=max(aList[i], score[(i-1)%3][0])
			else:
				nextScore=[]
				if i>=1:
					s=score[(i-1)%3][j]
					if s is not None:
						nextScore.append(s)
				if i>=2:
					s=score[(i-2)%3][j-1]
					if s is not None:
						s+=aList[i]
						nextScore.append(s)
				if len(nextScore)>0:
					ns=max(nextScore)
			
			score[i%3][j]=ns
	
# 		print(i, *[str(s) for s in score[i%3]], sep="\t")
	
	print(score[(n-1)%3][-1])


def main():
	n=int(nextLine())
	aList=nextIntList()

# 	import numpy as np
# 	n=200000
# # 	aList=list(np.random.randint(-1000000000, 1000000001, n))
# # 	n=22
# 	aList=list(np.random.randint(-9, 10, n))
	
	comp(n, aList)
# 	comp0(n, aList)
	
	
if __name__=="__main__":
	main()


Measured memory_bytes: 33876
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    if((A + B) % 2 == 0){
    cout << (A + B) / 2;
    }
    else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    char c;

    for ( int i=0; i<3; i++ ) {
        scanf("%c", &c);
        if ( c == '1' )
            printf("9");
        else if ( c == '9' )
            printf("1");
        else
            printf("%c", c);
    }
    printf("\n");

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }
    
    z->parent = y;
    
    if(y == NIL){
        root = z;
    }
    else{
        if(z->key < y->key){
            y->left = z;
        }
        else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 26716
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, m;
  cin >> a >> b >> m;
  vi v(a), w(b);
  REP(i, a)cin >> v[i];
  REP(i, b)cin >> w[i];
  int ans = *min_element(ALL(v)) + *min_element(ALL(w));
  REP(i, m) {
    int s, t, c;
    cin >> s >> t >> c;
    s--; t--;
    chmin(ans, v[s] + w[t] - c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import Data.Array
import Data.Char
import Control.Monad

--面倒なので、一マス大きい入力にすること。
trans::Array Int (Array Int Char) -> (Int,Int)-> Array Int(Array Int Char)
trans ar (h,w) = listArray (1,h) [listArray (1,w) [   if (ar!i)!j == '#'then '#' else  (intToDigit.length.(filter (\x-> x== '#')))  [(ar!x!y)|(x,y)<-[(i+1,j),(i+1,j+1),(i,j+1),(i-1,j+1),(i-1,j),(i-1,j-1),(i,j-1),(i+1,j-1)]]           |j<-[1..w]] |i<-[1..h]]


wrapper::[[Char]]->(Int,Int)-> Array Int (Array Int Char)
wrapper ls (h,w)= listArray (0,h+1) (map (listArray (0,w+1)) (  (take (w+2) (repeat '.')) : (map (\cs -> '.':cs++ ['.'] ) ls)++ [(take (w+2) (repeat '.'))] ) )

getter::Int -> IO [[Char]]
getter 0 =return []
getter n = do
  cs<-getLine
  rest<-getter (n-1)
  return (cs:rest)

printer::Array Int (Array Int Char)->IO()
printer ar = forM_ (map elems (elems ar)) oneline
            where oneline ls = do
                            putStr ls
                            putStr "\n"

main::IO()
main =do
  d<-getLine
  let h:w:[]= map read (words d)
  lsdat<-getter h
  let input = wrapper lsdat (h,w)
  printer (trans input (h,w))

Measured memory_bytes: 1020
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int main(void) {

    while (true) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0) { break; }
        if (x < y) {
            printf("%d %d\n", x, y);
        }
        else {
            printf("%d %d\n", y, x);
        }
    }

    return 0;
}

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

int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if (a >= k)
  {
    cout << k << endl;
  }
  else if (a + b >= k)
  {
    cout << a << endl;
  }
  else
  {
    cout << a - k + a + b << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N >> A;
    vi a(N);
    cin >> a;
    auto dp = make_vec<ll>(55, 2600, 55, 0LL);
    dp[0][0][0] = 1;
    REP(i, N) {
        REP(j, 2501) {
            REP(k, N) {
                dp[i + 1][j + a[i]][k + 1] += dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }
    REP(j, 2501)
    REP(k, N + 1) {
        if (A * k == j) {
            ans += dp[N][j][k];
        }
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 70236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;
	int a[N+1];
	int c[10001];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int x=0;
	for (int i = 0; i<H*W; i++) {
		c[i]=x+1;
      	a[x]--;
      	if(a[x]==0) x++;
	}
  	int cnt=0;
  	for(int i=0; i<H*W; i++){
      cout<<c[i]<<" ";
      cnt++;
      if(cnt%(2*W)==W){cout<<endl; sort(c+cnt,c+cnt+W); reverse(c+cnt,c+cnt+W);}
      else if(cnt%(2*W)==0)cout<<endl;
    }
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    String S = sc.next();
    String T = sc.next();
    long L = lcm(N, M);
    HashMap<Long, Character> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      if (!map.containsKey((L / N) * i)) {
        map.put((L / N) * i, S.charAt(i));
      }
    }
    for (int i = 0; i < M; i++) {
      if (map.containsKey((L / M) * i)) {
        if (map.get((L / M) * i) != T.charAt(i)) {
          System.out.println(-1);
          return;
        }
      }
    }
    System.out.println(L);
  }

  public static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }

  public static long lcm(int a, int b) {
    return (long) a / gcd(a, b) * b;
  }
}

Measured memory_bytes: 33968