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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

/*
vi vec;

ll count(ll in, ll n )
{


    vector<ll> table(n) ;

    table[0]=abs((vec[1]-vec[0]));

    ll cur =0,cc=0;
    for (ll i = 1; i < n-1 ; i++)
    {


            cur =abs((vec[i+1]-vec[i-1]));
            cc=abs((vec[i]-vec[i-1]));
            int ctr=(cc>cur) ? 2 : 1 ;
            table[i]=(cc>cur) ? cur : cc ;
            //table[i]+=table[i-ctr];
    }

    for (ll i = 0; i < n ; i++)
    {

            cout<<table[i]<<" ";


    }
/*
    if(i == n){
        return mn;
    }

    return count(i,n,mn);

    return 0;
 }


int main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);
    ll n;
    cin >>n;
    vec.resize(n);

    for (int i = 0; i <n ; ++i) {
        cin>>vec[i];
    }
    ll sum =0;
    for (int j = 0; j <n ; ++j) {
        sum+=vec[j];
    }


    cout << count(1,n);
    return 0;
}
*/


int dp[MX];

int main (){
    ll n,k;
    cin >> n>>k;
    vi vec(n);
    for(auto &el :vec)cin>>el;
    for (int i = 0; i <n ; ++i) {
        dp[i]=INF;
    }
    dp[0]=0;
    for (int i = 0; i <n ; ++i) {
        for (int j = 1; j <=k  && j <= n; ++j) {
            dp[i+j]=min(dp[i+j] , dp[i]+abs((vec[i]-vec[i+j])));

        }
    }
   
    cout <<dp[n-1];
    //cout<<vec;
    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N, L;
     cin >> N >> L;
     int f = N + L - 1;
      int eat;
      if(L >= 0) eat = L;
      else if(f <= 0) eat = f;
      else eat = 0;

      int ans = (f+L)*(f-L+1)/2 - eat;

      cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn
import scala.math.ceil
object Main extends App {
  val List(a,b,c,x,y) = StdIn.readLine().split(" ").map(_.toInt).toList
  val answer =
    List(
      c * x.max(y) * 2,
      c * x.min(y) * 2 + (if (x > y) a * (x - y) else b * (y -x)),
      a * x + b * y
    ).min
  println(answer)
}


Measured memory_bytes: 27172
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a < b:
  if a + v*t < b +w*t:
    print('NO')
  else:
    print('YES')
else:
  if a - v*t > b - w*t:
    print('NO')
  else:
    print('YES')

Measured memory_bytes: 9188
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>
#include <set>


using namespace std;

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int box[10001]={0};
        
        set<int> se;
        for(int i=1; i<n; i++){
            int ii=i*i % n;
            se.insert(ii);
        }
        
        /*
        for(int i=1; i<=n/2; i++){
            cout<<box[i]<<endl;
        }
        */
        
        // 要素を出力する
        vector<int> a_b;
        set<int>::iterator it = se.begin();
        while( it != se.end() )
        {
            
            //cout << *it << endl;
            a_b.push_back(*it);
            it++;
        }
        
        for(int i=0; i<a_b.size(); i++){
            for(int j=0; j<a_b.size(); j++){
                int ans=abs(a_b[i]-a_b[j]);
                if(ans>n/2)ans=n-ans;
                box[ans]++;
            }
        }
        
        for(int i=1; i<=n/2; i++){
            cout<<box[i]<<endl;
        }
        
        
        
    }
}

Measured memory_bytes: 1548
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
double a,b,c; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}


int main()
{
	cin>>a;
	a = a / 3.0;
	printf("%.6lf",a * a * a);
	
	return 0;
} 

Measured memory_bytes: 256
n=int(input())
#l=["z"]
#for i in range(97,122):
#    l.append(chr(i))
l=[chr(i) for i in range(97,123)]
#print(l)
ans=""
i=1
while True:
    if i==1:
        if n%26!=0:
            x=n%26
            n=n//26
        else:
            x=n%26
            n=n//26 -1
    else:
        if n%26!=0:
            x=n%26
            n=n//26
        else:
            x=n%26
            n=n//26 -1
    ans+=l[x-1]
    #print(ans,n,x)
    i+=1
    if n==0:
        break
ans=ans[::-1]
print(ans)

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

int n,a,b,c;
std::vector<int> l;


//再帰関数
int rec(int i, int x, int y, int z){
    //終端処理
    if(i == n){
        if(!x || !y || !z)return 1000000000;
        return std::abs(a - x) + std::abs(b - y) + std::abs(c - z);
    }

    int res = (rec(i + 1, x, y, z));

    res = std::min(res,rec(i + 1, x + l[i], y, z) + (x ? 10 : 0));
    res = std::min(res,rec(i + 1, x, y + l[i], z) + (y ? 10 : 0));
    res = std::min(res,rec(i + 1, x, y, z + l[i]) + (z ? 10 : 0));

    return res;

}

int main()
{
    std::cin >> n >> a >> b >> c;
    l.resize(n);
    for(int i = 0; i < n; i++)std::cin >> l[i];

    std::cout << rec(0,0,0,0) << std::endl;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    string s; cin >> s;
    int n = s.size();
    rep(i,n){
        if(s[i] == ',')cout << " ";
        else cout << s[i];
    }
    cout << endl;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> v(N + 1, 0);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		v[a] += 1;
		v[b] += 1;
	}

	bool ok = true;
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] % 2 == 1) { ok = false; }
	}

	if (ok) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	vector<int> v(3);
	REP(i, 3) cin >> v[i];
	sort(ALL(v));
	
	set<int> ss;
	REP(i, 3) ss.insert(v[i]);
	
	puts([&] {
		return ss.size() == 2;
	}() ? "Yes": "No");
	
	return 0;
}


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

int main(){
  int n, t_lim;
  cin>>n>>t_lim;
  int c = 2000, c_temp;
  int t = 2000, t_temp;

  for (int i = 0; i < n; i++){
    cin>>c_temp>>t_temp;
    if(t_temp <= t_lim && c_temp < c){
    c = c_temp;
    t = t_temp;
    }
  }

  if(t <= t_lim){
    cout<<c<<endl;
  }else{
    cout<<"TLE"<<endl;
  }


}


Measured memory_bytes: 256
use input::Input;

fn main() {
    let mut input = Input::default();

    let x: u32 = input.parse();
    let x = std::f64::consts::PI / 180.0 * x as f64;

    let d = 0.001f64;
    let r = 1.0f64;
    let mut a = 0.0f64;
    let mut b = 0.0f64;
    let mut dest = std::f64::consts::FRAC_PI_2;
    for i in 1..=360 {
        a += r * dest.cos();
        b += r * dest.sin();
        if a.abs() < d && b.abs() < d {
            println!("{}", i);
            break;
        }
        dest += x;
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2908
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int inf = 0x3f3f3f3f;
bool ok; char ch;
void read(int& x) {
	for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') ok = 1;
	for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if (ok) x = -x;
}
void write(int x)
{
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
int main() {
	string s;
	cin >> s;
	int t = s.size();
	while (t--)cout << "x";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int ans = 0;
		
		if (x == y) {
			if ((a+b) > (c*2)) {
				ans = x * (c*2);
			} else {
				ans = x * (a+b);
			}
		} else {
			int large;
			int small;
			int price;
			
			if (x > y) {
				large = x;
				small = y;
				price = a;
			} else {
				large = y;
				small = x;
				price = b;
			}
			
			if ((a+b) > (c*2)) {
				ans = small * (c*2);
			} else {
				ans = small * (a+b);
			}
			
			if (price > (c*2)) {
				ans += (c*2) * (large-small);
			} else {
				ans += price * (large-small);
			}
		}
		
		System.out.println(ans);
	}
}

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


using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 3007;

LL dp[N][N][2];
int A[N];
//dp[l][r][0] = max(dp[l+1][r][1]+A[l], dp[l][r-1][1]+A[r])
//dp[l][r][1] = min(dp[l+1][r][0], dp[l][r-1][0])

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    LL sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> A[i];
        sum += A[i];
    }
    for(int d = 0; d < n; d++){
        for(int i = 1; i <= n-d; i++){
            //cout << "L R " << i << " " << i+d << '\n';
            dp[i][i+d][0] = max(dp[i+1][i+d][1]+A[i], dp[i][i+d-1][1]+A[i+d]);
            dp[i][i+d][1] = min(dp[i+1][i+d][0], dp[i][i+d-1][0]);
            //cout << dp[i][i+d][0] << " " << dp[i][i+d][1] << '\n';
        }
    }
    LL x = dp[1][n][0];
    LL y = sum-x;
    cout << x-y << '\n';
    
    
    
    return 0;
}

Measured memory_bytes: 139648
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	string s;
  	cin >> s;
  	int ans = 0;
	int sz = s.size();
  
  	// sz が偶数のとき
  	if(sz % 2 == 0){
    	rep(i, sz/2){
        	if(s[i] != s[sz-1-i]){ans++;}
        }
    }  
  	// sz が奇数のとき
	else{
    	rep(i,(sz-1)/2){
        	if(s[i] != s[sz-1-i]){ans++;}
        }  
    }
  cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        var S = ReadLine();
        var T = ReadLine();

        if (S.Contains(T)) {
            WriteLine(S.Replace('?', 'a'));
            return;
        }

        var Srev = string.Join("", S.Reverse());
        var Trev = string.Join("", T.Reverse());

        for (int i = 0; i < S.Length - (T.Length - 1); i++) {
            var tmp = Sub(Srev, Trev, i);
            if (tmp != null) {
                WriteLine(string.Join("", tmp.Reverse()).Replace('?', 'a'));
                return;
            }
        }

        WriteLine("UNRESTORABLE");
    }

    static char[] Sub(string Srev, string Trev, int i) {
        var tmp = new char[Srev.Length];
        Array.Copy(Srev.ToCharArray(), tmp, Srev.Length);

        for (int j = 0; j < Trev.Length; j++) {
            if (Srev[i + j] == Trev[j]) {
                continue;
            } else if (Srev[i + j] == '?') {
                tmp[i + j] = Trev[j];
            } else {
                return null;
            }
        }

        return tmp;
    }
}

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

int main() {
    long int a, b, c, d,maxabc,ret;
    cin >> a >> b >> c;
    int evena, evenb, evenc;
    evena = a%2;
    evenb = b%2;
    evenc = c%2;
    if(evena*evenb*evenc==1||(evena==0&&evenb==0&&evenc==0)){
        maxabc = max(max(a,b),c);
        ret = -1 * (a+b+c) + maxabc * 3;
        ret /= 2;
    }
    else if(evena==evenb){
        maxabc = max(max(a,b),c-1);
        ret = maxabc*3 - (a+b+c-1);
        ret/=2;
        ret+=1;
    }
    else if(evenb==evenc){
        maxabc = max(max(a-1,b),c);
        ret = maxabc * 3 - (a+b+c-1);
        ret/=2;
        ret+=1;
    }
    else{
        maxabc = max(max(a,b-1),c);
        ret = maxabc*3 - (a+b+c-1);
        ret/=2;
        ret+=1;
    }
    
    cout <<  ret << endl;
}

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

int i;
string a;


int main(){
    cin>>a;
    a.erase(5,1);
    a.erase(12,1);
    for(i=0;i<=a.length()-1;i++){
        cout<<a[i];
        if(i==4){
            cout<<" ";
        }
        else if(i==11){
            cout<<" ";
        }
    }
}

Measured memory_bytes: 3632
<?php
$n = (int)trim(fgets(STDIN));

$input = explode(' ', trim(fgets(STDIN)));
$as = [];
foreach ($input as $v) {
	$as[] = (int)$v;
}
sort($as);

$l_gcd = [];
$r_gcd = [];
$l_gcd[0] = $as[0];
$l_tmp = gcd($as[0], $as[1]);
$l_gcd[1] = $l_tmp;
$r_gcd[$n-1] = $as[$n-1];
$r_tmp = gcd($as[$n-1], $as[$n-2]);
$r_gcd[$n-2] = $r_tmp;

for ($i=2; $i < $n; $i++) { 
	$l_tmp = gcd($l_tmp, $as[$i]);
	$l_gcd[$i] = $l_tmp;
	$r_tmp = gcd($r_tmp, $as[$n-$i-1]);
	$r_gcd[$n-$i-1] = $r_tmp;
}
$max = 1;

for ($i=0; $i < $n; $i++) { 
	if ($i === 0) {
		$max = max($max, $r_gcd[1]);
	} elseif ($i === $n-1) {
		$max = max($max, $l_gcd[$n-2]);
	} else {
		$max = max($max, gcd($l_gcd[$i-1], $r_gcd[$i+1]));
	}
}
echo $max;

function gcd($a, $b){
	$l = max($a, $b);
	$s = min($a, $b);
	$r = $l % $s;
	if ($r === 0) {
		return $s;
	}else{
		return gcd($s, $r);
	}
}

Measured memory_bytes: 27372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int height, width; 
  cin >> height >> width;

  vector<char> vec(width*height);
  for (int i = 0; i < vec.size(); i++)
    cin >> vec.at(i);

  for (int i = 0; i < height + 2; i++){
    for (int j = 0; j < width + 2; j++){
      if (i == 0 || i == height + 1){
        cout << '#'; 
	if (j == width+ 1) cout << endl;
      } else {
        if (j == 0 || j == width + 1){
	  cout << '#';
	  if (j == width+ 1) cout << endl;
	} else {
	  cout << vec.at(j-1+width*(i-1));
	} 
      } 
    } 
  }
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, l, max, cnt = 0, n = 20, now = 0;
  scanf("%lld", &l);
  --l;
  vector<ll> u, v, w;
  for(i = 0; i < 21; ++i) if((l >> i) & 1) max = i;
  for(i = 1; i < n; ++i) u.push_back(i), v.push_back(i + 1), w.push_back(0);
  for(i = 0; i < max; ++i) u.push_back(n - i - 1), v.push_back(n - i), w.push_back(1 << i);
  while(now - l) {
    now += (1 << max);
    max = 0;
    for(i = 0; i < 21; ++i) if(((l - now) >> i) & 1) max = i;
    u.push_back(1), v.push_back(n - max), w.push_back(now);
  }
  printf("%lld %lld\n", n, u.size());
  for(i = 0; i < v.size(); ++i) printf("%lld %lld %lld\n", u[i], v[i], w[i]);
  return 0;
}

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

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

    int ans = 0;
    rep(i, n) {
        int x;
        cin >> x;
        ans += min(x, k - x) * 2;
    }

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


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

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    ll c = 0;
    if(a < k){
        c = k - a;
    }
    a -= k;
    b -= c;
    ll d = 0;
    cout << max(d, a) << " " << max(d, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
#define nep(x) next_permutation(x);
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template <class X> X lcm(X a, X b){
    X mm = a, nn = b, tmp;
    while(a % b != 0){
        tmp = b;
        b = a % b;
        a = tmp;
    }
    return mm * nn / b;
}
int main() {
   int N;
   cin >> N;
   vector<ll> A(N);
   for(int i = 0; i < N; i++) cin >> A[i];
   ll sum = 0;
   for(int i = 0; i < N; i++) sum += A[i] - 1;

   cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    unordered_map<string,long> u;
    for(int i=0;i<n;i++){
        string a; cin >> a;
        sort(a.begin(),a.end());
        u[a]++;
    }
    long ans = 0;
    for(auto x:u){
        long y = x.second;
        ans += y*(y-1)/2;
    }
    cout << ans << endl;
}


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

struct Node {
	int iKey_;
	Node *pParent_;
	Node *pLeftChild_;
	Node *pRightChild_;
};

class Tree {
public:
	Tree(int iNum) :iMaxNodeNum_(iNum), iCurNodeNum_(0) {}

	void setNodeValue() {
		for (int iCurNode_i = 0; iCurNode_i < iMaxNodeNum_; iCurNode_i++) {
			string sCommand;
			cin >> sCommand;
			if (sCommand[0] == 'i') {
				int iKey;
				cin >> iKey;
				insertNode(iKey);
			}
			else if (sCommand[0] == 'f') {
				int iKey;
				cin >> iKey;
				bool bIsFinding = isNode(iKey);
				if (bIsFinding) cout << "yes" << endl;
				else			cout << "no" << endl;
			}
			else {
				print();
			}
		}
	}

private:
	void insertNode(int iKey) {
		Node *pNewNode = new Node;
		//????????????
		pNewNode->iKey_ = iKey;
		pNewNode->pParent_ = NULL;
		pNewNode->pLeftChild_ = NULL;
		pNewNode->pRightChild_ = NULL;
		iCurNodeNum_++;
		if (iCurNodeNum_ == 1) { //??????????????????????????????
			pRoot_ = pNewNode;
			return;
		}

		searchNewNodeLocation(pNewNode);
	}
	void searchNewNodeLocation(Node *pNewNode) {
		Node *pCurNode = pRoot_;
		Node *pCurParentNode = NULL;
		while (pCurNode != NULL) {
			pCurParentNode = pCurNode;
			if (pNewNode->iKey_ < pCurNode->iKey_) pCurNode = pCurNode->pLeftChild_;
			else                                   pCurNode = pCurNode->pRightChild_;
		}
		pNewNode->pParent_ = pCurParentNode;

		if (pNewNode->iKey_ < pCurParentNode->iKey_) pCurParentNode->pLeftChild_ = pNewNode;
		else                                   pCurParentNode->pRightChild_ = pNewNode;
	}

	bool isNode(int iKey) {
		Node *curNode = pRoot_;
		while (curNode != NULL) {
			if (curNode->iKey_ == iKey) return true;
			if (iKey < curNode->iKey_) {
				curNode = curNode->pLeftChild_;
			}
			else {
				curNode = curNode->pRightChild_;
			}
		}
		return false;
	}

	void print() {
		printWidthInorder(pRoot_);
		cout << endl;
		printWidthPreorder(pRoot_);
		cout << endl;
	}
	void printWidthPreorder(Node *pN) {
		if (pN == NULL) return;
		cout << " " << pN->iKey_;
		printWidthPreorder(pN->pLeftChild_);
		printWidthPreorder(pN->pRightChild_);
	}
	void printWidthInorder(Node *pN) {
		if (pN == NULL) return;
		printWidthInorder(pN->pLeftChild_);
		cout << " " << pN->iKey_;
		printWidthInorder(pN->pRightChild_);
	}

	Node *pRoot_;
	int iCurNodeNum_;
	const int iMaxNodeNum_;
};

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

	//?????????
	Tree trNodeTree(iNodeNum);

	//???????????§??\????????????
	trNodeTree.setNodeValue();

	return 0;
}

Measured memory_bytes: 21740
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	int x, y, i, j, m, n;
	char a;
	while (1) {
		cin >> x >> a >> y;
		if (a == '+') {
			n = x + y;
		}
		if (a == '-') {
			n = x - y;
		}
		if (a == '*') {
			n = x*y;
		}
		if (a == '/') {
			n = x / y;
		}
		if (a == '?') {
			break;
		}
		printf("%d\n", n);

	}
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int dp[200000];
    REP(i,200000)dp[i] = 100000;
    dp[0] = 0;
    vector<int> plus = {1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
    REP(i,100000){
        REP(l,plus.size()){
            dp[i+plus[l]] = min(dp[i+plus[l]],dp[i]+1);
        }
    }
    int N = in();
    cout << dp[N] << "\n";
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> field(h);
    for (int i = 0; i < h; i++) {
        cin >> field[i];
    }
    int ans = 0;
    for (int sh = 0; sh < h; sh++) {
        for (int sw = 0; sw < w; sw++) {
            if (field[sh][sw] == '#') {
                continue;
            }
            auto spos = make_tuple(sh, sw, 0);
            map< pair<int, int>,  int> memo;
            queue< tuple<int, int, int> > que;
            que.push(spos);
            int max_step = 0;
            while (!que.empty())
            {
                auto pos = que.front();
                que.pop();
                int cy = get<0>(pos), cx = get<1>(pos), step = get<2>(pos);
                if (memo.find(make_pair(cy, cx)) != memo.end()) {
                    continue;
                }
                memo[make_pair(cy, cx)] = step;
                max_step = step;
                int next_step = step + 1;
                int dy[4] = {0, 1, 0, -1};
                int dx[4] = {1, 0, -1, 0};
                for (int i = 0; i < 4; i++) {
                    int ny = cy + dy[i], nx = cx + dx[i];
                    if (ny < 0 || h <= ny) { continue; }
                    if (nx < 0 || w <= nx) { continue; }
                    if (field[ny][nx] == '#') { continue; }
                    que.push(make_tuple(ny, nx, next_step));
                }
            }
            ans = max(max_step, ans);
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    int n;
    cin>>n;
    int a[n];
    long mod=1000000000+7;
    int ans[100000+1]={0};
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans[a[i]]++;
    }
    int f=0;
    for(int i=1;i<100000+1;i++){
        if(ans[i]%2!=0)f=1;
    }
    if(f==1)cout<<0<<endl;
    else {
        long mul=1;
        for(int i=0;i<n/2;i++){
            mul=(mul*2)%mod;
        }    
        cout<<mul<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main (void)


{


int a,b,c;


int count=0;


int i;


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


for(i=a; i<=b; i++)


{


if(c%i==0) 

count++;





}


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


return 0;


}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    cout << n * (n + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm> 
#include<string>
#include<string.h>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct node
{
	int now;
	int step;
	node(int X,int Z)
	{
		now=X;
		step=Z; 
	}
	friend bool operator <(node s1,node s2)
	{
		return s1.step>s2.step;
	}
};
int ans[2005][2005];
vector<node> ve[2005];
int ans2[2005];
void bfs(int n)
{
	priority_queue<node> q;
	for(int i=0;i<ve[n].size();i++)
	{
		q.push(ve[n][i]);
	}
	while(!q.empty())
	{
		node now=q.top();
		q.pop();
		if(ans[n][now.now]!=0)
		{
			continue;
		}
		ans[n][now.now]=now.step;
		for(int i=0;i<ve[now.now].size();i++)
		{
			node temp=now;
			temp.step=now.step+1;
			temp.now=ve[now.now][i].now; 
			q.push(temp);
		}
	}
}
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	ve[x].push_back(node(y,1));
	ve[y].push_back(node(x,1));
	for(int i=1;i<=n-1;i++)
	{
		ve[i].push_back(node(i+1,1));	
		ve[i+1].push_back(node(i,1));
	} 
	for(int i=1;i<=n-1;i++)
	{	
		bfs(i);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i==j)
				continue;
			if(ans[i][j]==0&&ans[j][i]!=0)
			{
				ans2[ans[j][i]]++;
//				cout<<i<<" "<<j<<" "<<ans[j][i]<<endl;
			}
			else if(ans[i][j]!=0&&ans[j][i]==0)
			{
				ans2[ans[i][j]]++;
//				cout<<i<<" "<<j<<" "<<ans[i][j]<<endl;
			}
			else
			{
				ans2[min(ans[i][j],ans[j][i])]++;
//				cout<<i<<" "<<j<<" "<<min(ans[i][j],ans[j][i])<<endl;
			}
		}
	}
	for(int i=1;i<n;i++)
	{
		cout<<ans2[i]/2<<endl;
	}
	return 0;
} 

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 210;
int n;
char s[N];
bool e[N][N];

int col[N];
bool flag;
inline void dfs(int u,int c){
	col[u]=c;
	For(i,1,n) if (e[u][i]){
		if (col[i]==-1) dfs(i,c^1);
		else if (col[i]!=(c^1)) flag=1;
	}
}
inline bool check(){
	fil(col,-1);
	flag=0,dfs(1,0);
	return flag;
}

int dis[N];
inline int bfs(int s){
	For(i,1,n) dis[i]=-1;
	queue<int>q;q.push(s),dis[s]=1;
	while (!q.empty()){
		int u=q.front();q.pop();
		For(i,1,n) if (e[u][i]&&dis[i]==-1){
			dis[i]=dis[u]+1,q.push(i);
		}
	}
	int mx=0;
	For(i,1,n) mx=max(mx,dis[i]);
	return mx;
}

int main(){
	n=read();
	For(i,1,n){
		scanf("%s",s+1);
		For(j,1,n) e[i][j]=(s[j]=='1');
	}
	if (check()) return puts("-1"),0;
	int ans=0;
	For(i,1,n) ans=max(ans,bfs(i));
	printf("%d\n",ans);
}

Measured memory_bytes: 3840
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())
L = []

for i in range(N):
    S, P = input().split()
    P = 1000 - int(P)
    L.append([S, P, i])

L = sorted(L)

for i in range(N):
    print(L[i][2] + 1)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct segment_tree{
  int N;
  vector<T> ST;
  function<T(T, T)> f;
  T E;
  segment_tree(int n, function<T(T, T)> F, T e){
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<T>(N * 2 - 1, e);
    f = F;
    E = e;
  }
  segment_tree(vector<T> A, function<T(T, T)> F, T e){
    int n = A.size();
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<T>(N * 2 - 1, e);
    f = F;
    E = e;
    for (int i = 0; i < n; i++){
      ST[N - 1 + i] = A[i];
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = f(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  T operator [](int k){
    return ST[N - 1 + k];
  }
  void update(int k, T x){
    k += N - 1;
    ST[k] = x;
    while (k > 0){
      k = (k - 1) / 2;
      ST[k] = f(ST[k * 2 + 1], ST[k * 2 + 2]);
    }
  }
  T val(int L, int R, int i, int l, int r){
    if (R <= l || r <= L){
      return E;
    } else if (L <= l && r <= R){
      return ST[i];
    } else {
      int m = (l + r) / 2;
      return f(val(L, R, i * 2 + 1, l, m), val(L, R, i * 2 + 2, m, r));
    }
  }
  T query(int L, int R){
    return val(L, R, 0, 0, N);
  }
};
int f(int a, int b){
  return a + b;
}
int main(){
  int n, q;
  cin >> n >> q;
  segment_tree<int> A(n, f, 0);
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int x, y;
      cin >> x >> y;
      x--;
      A.update(x, A[x] + y);
    }
    if (t == 1){
      int x, y;
      cin >> x >> y;
      cout << A.query(x - 1, y) << endl;
    }
  }
}


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

list_aaa = []

for i in range(1,100000+1):
    if i ==1:
        list_aaa.append(s)
    elif s%2 ==0:
        s= s//2
        list_aaa.append(s)
    elif s%2 ==1:
        s= (3*s)+1
        list_aaa.append(s)
#print(list_aaa)

for i in list_aaa:
    index_num = [n for n, v in enumerate(list_aaa) if v == i]
    if len(index_num) >=2:
        print(index_num[1]+1)
        break


Measured memory_bytes: 5132
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;
/*
* * * * * * * * * * * * * * * * * * * * * *
*       ☆꧁𝓑𝓐𝓒𝓚_𝓛𝓞𝓖꧂☆              **
*                                        ***
* * * * * * * * * * * * * * * * * * * * *****
*/ 

int32_t main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ac=a*c;
  int ad=a*d;
  int bc=b*c;
  int bd=b*d;
  int ans=-1e18-7;
  ans=max(ac,ans);
  ans=max(ans,ad);
   ans=max(ans,bc);
    ans=max(ans,bd);
   
    cout<<ans<<endl;
    
return 0;

}




Measured memory_bytes: 3648
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0]*(n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
A = [0]*M
B = [0]*M
uf = UnionFind(N)
for i in range(M):
    A[i], B[i] = map(int, input().split())
    uf.union(A[i], B[i])

cnt = 0 #新しく作った橋の数

for j in range(1,N):
    if uf.same_check(j, j+1) == False:
        uf.union(j,j+1)
        cnt+=1

print(cnt)
#print(uf.par[1:])
#print(uf.rank[1:])

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

using namespace std;
using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    vector<vector<pair<i64, i64>>> dp(N, vector<pair<i64, i64>>(N, {0, 0}));
    for (int i = 0; i < N; ++i) {
        dp[i][i].first = a[i];
        dp[i][i].second = -a[i];
    }
    for (int d = 1; d < N; ++d) {
        for (int i = 0; i < N; ++i) {
            int j = i + d;
            if (j < N) {
                dp[i][j].first = max(dp[i + 1][j].second + a[i], dp[i][j - 1].second + a[j]);
                dp[i][j].second = min(dp[i + 1][j].first - a[i], dp[i][j - 1].first - a[j]);
            }
        }
    }
    cout << dp[0][N - 1].first << "\n";

    return 0;
}

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

i64 n,k,m;
int main()
{ 
    fastInOut
    cin>>n>>m;
    if(n!=1&&n%2==0)
           cout<<"No";
     else if(m!=1&m%2==0)
            cout<<"No";
     else 
       cout<<"Yes";
    
  return 0;
}















Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{ 
    int a,b;
    cin>>a>>b;
    if(b>0){
        if(a*b>a+b){
            cout<<a*b<<endl;
        }
        else{
            cout<<a+b<<endl;
        }
    }
    else{
        if(a*b>a-b){
            cout<<a*b<<endl;
        }
        else{
            cout<<a-b<<endl;
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

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

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

    int n, k;
    cin >> n >> k;

    int ans = 1;
    rep(i, n){
        int x = ans * 2;
        int y = ans + k;
        ans = min(x, y);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
/////////////////////////////////TEST CASES////////////////////////////////////
/*
 
*/
/////////////////////////////////////CODE/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define VL vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 1000000000;
ll MOD = 1000000007;
int main()
{
	fastio
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
	ll test = 1;
	//cin>>test;
	while (test--)
	{
		IN(n);
        ll k=n%10;
        if(k==1 || k==3 || k==7 || k==9)
        {
            ll t=7,cnt=1;
            while(t%n!=0)
            {
                t*=10;
                t+=7;
                t%=n;
                cnt++;
                //cout<<t<<endl;
                if(cnt>n)
                {
                    cout<<-1<<endl;
                    return 0;
                }
            }
            cout<<cnt<<endl;
        }
        else
            cout<<-1;
	}
}

Measured memory_bytes: 3644
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (f x; doit l; doit r)
  in doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (doit l; f x; doit r)
  in doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = sub s 0 i in
        doit s1 (sub s (i + 1) (length s - length s1 - 1) :: acc)
  in doit str []

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then begin
      match split (read_line ()) ' ' with
      | ["print"] -> (print t; read (i + 1) t)
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | _ -> ()
    end in
  read 0 (create ())

Measured memory_bytes: 31852
/* ex3_2
   kohei0713 */

#include <stdio.h>

int main(void){
    
    int penNumber;
    
    //input
    scanf("%d", &penNumber);

    //penNumberの1の位を計算
    int onesPlace = penNumber % 10;

    if(onesPlace == 3){
        printf("bon\n");
    }
    else if(onesPlace == 0 || onesPlace == 1 || onesPlace == 6 || onesPlace == 8){
        printf("pon\n");
    }
    else{
        printf("hon\n");
    }

    return 0;
}

Measured memory_bytes: 1640
#%%
X = int(input())
l = []

a = round(1000*0.5)

for i in range(2,a):
    j = 2
    b = 0
    while b <= 1000:
        b = i ** j
        if b <= 1000:
            l.append(b)
        j += 1

l.append(1)
l.sort()

ans_list =[]
for i in range(len(l)):
    if l[i] <= X:
        ans_list.append(l[i])
print(max(ans_list))

Measured memory_bytes: 3064
import sys

s = int(input())
a = [s]

n = 0
while True:
    if a[n] % 2 == 0:
        a_nn = int(a[n]/2)
        if a_nn in a:
            print(n+2)
            sys.exit()
        else:
            a.append(a_nn)
    else:
        a_nn = int(3*a[n]+1)
        if a_nn in a:
            print(n+2)
            sys.exit()
        else:
            a.append(a_nn)
    n += 1
    


Measured memory_bytes: 3060
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
K = c.keys()

ans = "No"
if len(K)==3:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and c[B[1]]==c[B[2]] and B[0]^B[1]==B[2]:
        ans = "Yes"
elif len(K)==2:
    B = []
    for k in K:
        B.append(k)
    if (c[B[0]]==2*c[B[1]] or c[B[1]]==2*c[B[0]]) and (B[0]==0 or B[1]==0):
        ans = "Yes"
elif sum(A)==0:
    ans = "Yes"

print(ans)


Measured memory_bytes: 14468
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local MOD = math.floor(10^9) + 7
local S = read.l():totable()
local K = read.n()
local tbl = array(3, 0)
local FIT = 0
local SMALLER = 1
tbl[0][FIT][0] = 1

for i=1,#S do
    -- decide tbl[i] from tbl[i-1]
    local constraint_digit = tonumber(S[i])
    local oldtbl = tbl[i-1]
    local newtbl = tbl[i]
    local function has_transition(oldfs, newfs, oldk, newk, newd)
        -- Specific to this problem --
        if newd == 0 then
            if newk ~= oldk then
                return false
            end
        else
            if newk ~= oldk + 1 then
                return false
            end
        end
        -- Boiler plate code for digit DP --
        local new_digit = newd
        if oldfs == FIT and newfs == FIT then
            return new_digit == constraint_digit
        elseif oldfs == FIT and newfs == SMALLER then
            return new_digit < constraint_digit
        elseif oldfs == SMALLER and newfs == FIT then
            return false
        elseif oldfs == SMALLER and newfs == SMALLER then
            return true
        end
    end
    local function do_transition(oldfs, newfs, oldk, newk)
        local v = oldtbl[oldfs][oldk]
        newtbl[newfs][newk] = (newtbl[newfs][newk] + v) % MOD
    end
    for oldk=0,3 do
        local newk_start = math.max(0, oldk-1)
        local newk_end = math.min(3, oldk+1)
        for newk=newk_start,newk_end do
            for oldfs=0,1 do
                for newfs=0,1 do
                    for newd=0,9 do
                        if has_transition(oldfs, newfs, oldk, newk, newd) then
                            do_transition(oldfs, newfs, oldk, newk)
                        end
                    end
                end
            end
        end
    end
end
local ans = (tbl[#S][FIT][K] + tbl[#S][SMALLER][K]) % MOD
print(ans)

Measured memory_bytes: 888
import queue
K=int(input())

q = queue.Queue()
for i in range(9):
    i+=1
    q.put(i)

tmp=9

while tmp<K:
    a=q.get()
    d=a%10
    if d != 0:
        hoge=a*10+(d-1)
        q.put(hoge)
        tmp+=1
        if tmp==K:
            break
    
    hoge=a*10+d
    q.put(hoge)
    tmp+=1
    if tmp==K:
        break

    if d != 9:
        hoge=(a*10)+(d+1)
        q.put(hoge)
        tmp+=1
        if tmp==K:
            break

if K <= 9:
    print(K)
else:
    print(hoge)

Measured memory_bytes: 6768
n = int(input())

lucas_list = [0] * 90
lucas_list[0] = 2
lucas_list[1] = 1

def lucas_num(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    elif lucas_list[n] == 0:
        lucas_list[n] = lucas_num(n-1) + lucas_num(n-2)
        return lucas_list[n]
    else:
        return lucas_list[n]

print(lucas_num(n))


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

#define ll long long
#define pb push_back
#define mp make_pair


int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cin.tie(NULL);
     
		 int x,n;
		 cin>>x>>n;

		 int a[110];
		 int flag[110];
		 for(int i=0;i<110;i++)
		 {
			 flag[i]=0;
		 }
				  if(n==0)
		{cout<<x;
		return 0;}
		
		 for(int i=0;i<n;i++)
		{ cin>>a[i];
			flag[a[i]]=1;
		}
		
		
		/* vector<int>v;
		for(int i=0;i<n;i++)
		{   int k=abs(a[i]-x);
			v.pb(k);
			//cout<<k<<" ";
		 }
		 sort(v.begin(),v.end());
		 int maxi=v[n-1];
		 for(auto i: v)
		 cout<<i<<" ";*/
		 int a1=-1,a2=-1;
		 for(int i=0;i<110;i++)
		 {
			/* if(i<n-1 && v[i]==v[i+1] )
			{ i+=2;
			 continue;}
			 else if(i<n-1 && v[i]!=v[i+1])
			 {*/
				 if(flag[abs(x-i)]==0)
				 {
					a1=abs(x-i);
					
				 }
				 if(flag[x+i]==0)
				 {
					 a2=x+i;
				 }
				 if(a1!=-1 && a2!=-1)
				 {cout<<min(a1,a2);
				 return 0;}
				 else if(a1==-1 && a2!=-1)
				{ cout<<a2;
					return 0;
				}
				  else if(a2==-1 && a1!=-1)
				 { cout<<a1;return 0;
				 }
				  
			 
		 }
		 
		 
	   
   }
		 

Measured memory_bytes: 3636