akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=2005,mod=924844033;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,k;
int Fac[N];
int dp1[N][N][4],dp[N];
void add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
int main(){
	n=read(),k=read();
	int t=n/k+1;
	memset(dp1,0,sizeof dp1);
	dp1[0][0][2]=1;
	for (int i=0;i<t;i++)
		for (int j=0;j<t;j++){
			/*
				0 = __ --> ___ | __* , *__
				1 = _* --> _*_ | _** , **_
				2 = *_ --> *__ | *_*
				3 = ** --> **_ | ***
			*/
			add(dp1[i+1][j][0],dp1[i][j][0]);
			add(dp1[i+1][j][2],dp1[i][j][1]);
			add(dp1[i+1][j][0],dp1[i][j][2]);
			add(dp1[i+1][j][2],dp1[i][j][3]);
			add(dp1[i+1][j+1][0],dp1[i][j][0]);
			add(dp1[i+1][j+1][1],dp1[i][j][0]);
			add(dp1[i+1][j+1][3],dp1[i][j][1]);
			add(dp1[i+1][j+1][2],dp1[i][j][1]);
			add(dp1[i+1][j+1][1],dp1[i][j][2]);
			add(dp1[i+1][j+1][3],dp1[i][j][3]);
		}
	dp[0]=1;
	for (int i=1;i<=k;i++){
		int t=n/k+(i<=n%k?1:0);
		for (int j=n;j>=0;j--)
			for (int k=1;k<=t&&k+j<=n;k++)
				dp[j+k]=(1LL*dp[j]*(dp1[t][k][0]+dp1[t][k][2])+dp[j+k])%mod;
	}
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=1LL*Fac[i-1]*i%mod;
	int ans=0;
	for (int i=0;i<=n;i++){
		dp[i]=1LL*dp[i]*Fac[n-i]%mod;
		if (i&1)
			ans=(ans-dp[i]+mod)%mod;
		else
			ans=(ans+dp[i])%mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 63104
#include<bits/stdc++.h> 
  
using namespace std; 
#define mod 1000000007 

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    cin>>n;
    int a[n],i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int mx[n],j;
    mx[0]=0;
    for(i=1;i<n;i++)
    {
     mx[i]=INT_MAX;
     j=i-1;
     mx[i]=min(mx[i],mx[j]+abs(a[j]-a[i]));
     if(i-2>=0)
     {
     j=i-2;
     mx[i]=min(mx[i],mx[j]+abs(a[j]-a[i]));
     }
    }
    cout<<mx[n-1];
    
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  double ans;
  REP(i, N) {
    double x;
    string v;
    cin >> x >> v;
    if (v == "JPY") {
      ans += x;
    } else {
      ans += x * 380000;
    }
  }
  printf("%.8f\n", ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.*

/**
 * 閉路を含まない有向グラフにおいて，特定の２点の間の最長パスを求める問題
 *
 * 一次元メモ配列の中で，直接つながっているものの間での遷移を考える
 *
 * スタート地点を dp 遷移の開始として, 自身i へと入っている ものの j 中で最大の値を持つもの + 1する
 * 次に，i から出ていった先 の全てへ順に遷移していく（キュー）
 *
 * 遷移の終了条件は？？？ 順番を考えないと重複
 *
 * ゴールt地点を dp 遷移の開始とする， スタックで幅優先探索で流入元へ自身 + + 1 or それよりも大きい場合はそのままの値を割り当てていく
 *
 * 全体として有効エッジ数の総和分だけ計算が必要になる
 *
 * dp[i]: ノード i を起点としたときの G の有効パスの長さの最大値
 *
 * グラフをトポロジカルソート（結合方向が順方向のみなるように，グラフのノードを１次元配列の中でソート）
 *
 * トポロジカルソートして，一番端の点から順に dp を更新していけば良い？（最長のものを求めるだけの場合）
 *
 * 左がなるべくsource 右がなるべくtarget となるようになっている
 *
 * 右から順に dp の値を更新していく
 *
 * (i)  値が入っていない場合は自身 + 1
 * (ii) 値が入っている場合は自身 + 1 と大きさを比較する, 大きい方の値を代入
 *
 * つながっている場合は値が入っていく，トポロジカルソート結果の末端から入れていくことで各ノードからスタート下
 *
 * 何の値を入れているのかわからないなってきた
 *
 */

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    // グラフの情報 特定のノードへ入力するノードを格納
    // map を使う場合 putIfAbsent, getOrElse 方法
    // Array を使う場合 空のリストを入れる
    val graphIn = Array(n) { mutableListOf<Int>() }
    val graphOut = Array(n) { mutableListOf<Int>() }
    for (i in 0 until m) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        graphIn[y - 1].add(x - 1)
        graphOut[x - 1].add(y - 1)
    }


    // stack push/pop, queue offer/poll,
    // pop, poll は 値が存在芝居場合 null を返すのに対して，removeLast, First は値が存在しない場合は NoSuchElementException を返す
    // push = addFirst(, offer = addLast
    // 常にキュー・スタックの中身があるかどうか確認して処理をする場合は add, remove を使えばよいのでは

    // トポロジカルソートを実装
    // どのノードも出力先のノードよりも前に来るように並べる

    // 訪問済みノードを管理し，親ノードがすべて訪問済みとなっているノードから順に訪問する
    // 毎回各ノードで訪問済みかどうかを for 文で確認するのはコスパよくないのでは？？
    // ↓
    // 各ノードの入力次数を管理しておく
    // 入力次数を訪問したノードから順に減じていく

    // 実装によってはノード番号とエッジ数を保持するクラスを作成しなくてはいけないがその必要はない
    // この部分の実装方針がすぐに頭に浮かぶかどうかが大事

    // 入力エッジ数が0 になったノードのみを格納する （出したときに トポロジカルソート配列に格納)
    val queue = ArrayDeque<Int>()
    val inEdges = Array(n) { graphIn[it].size }

    // 入力エッジ数が 0 になったものを格納
    for (i in 0 until inEdges.size) {
        if (inEdges[i] == 0) queue.addLast(i)
    }

    val topoSorted = mutableListOf<Int>()
    while (!queue.isEmpty()) {
        val n = queue.removeFirst()
        topoSorted.add(n)

        // n が出力している先の入力ノード次数を減じる
        for (node in graphOut[n]) {
            inEdges[node] -= 1

            // 入力次数が0 になったノードは queue に加える
            if (inEdges[node] == 0) {
                queue.addLast(node)
            }
        }
    }

    // dp の要領で最長パスを求める
    val dp = IntArray(n) { 0 }

    // ノード番号とトポロジカルソートした結果の対応表を作成
    // あまり賢くないか？？
    val rel = IntArray(n) { 0 }
    for (i in 0 until topoSorted.size) {
        rel[topoSorted[i]] = i
    }

    for ((i, n) in topoSorted.withIndex()) {
        // 結合先へ + 1
        for (j in graphOut[n]) {
            // トポロジカルソートした結果のどこに値を加えるかを知らなくてはいけない
            dp[rel[j]] = dp[i] + 1
        }
    }

    println(dp.max())
}

Measured memory_bytes: 102148
#include <bits/stdc++.h>
using namespace std;
int N, W;
vector<int> value(110);
vector<int> weight(110);

int dp[110][10010];

int main() {
    cin >> N >> W;
    for(int i = 0; i < N; ++i) {
        cin >> value.at(i) >> weight.at(i);
    }

    for(int w = 0; w <= W; ++w) {
        dp[0][w] = 0;
    }

    for(int i = 0; i < N; ++i) {
        for(int w = 0; w <= W; ++w) {
            if(w >= weight.at(i)) {
                dp[i+1][w] = max(dp[i][w - weight.at(i)] + value.at(i), dp[i][w]);
            }else {
                dp[i+1][w] = dp[i][w];
            }
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 7052
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <valarray>
#include <utility>
#include <set>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP2(i,m,n) for(int i=m+1;i<=(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<=(int)(n);i++)
#define INF 500000000  //
#define INFLL 1000000000000000000  //
#define MOD (1e9)+7

typedef long long int ll;

// a 0x61  z 0x7a  0 0x30


//------------------------------------------------------

int main() {
    int c[3][3];
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    int a[3], b[3];

    bool suc = false;

    rep(i, 101) {

        a[0] = i;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];

        int d[3][3];

        rep(i, 3) rep(j, 3) d[i][j] = a[i] + b[j];

        bool equal = true;

        rep(i, 3) {

            rep(j, 3) {
                if (c[i][j] != d[i][j]) equal = false;
            }
        }

        if (equal) {
            suc = true;
            break;
        }
    }

    cout << (suc ? "Yes" : "No") << endl;

    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();	//A
		int b = sc.nextInt();	//B
		int k = sc.nextInt();	//K
		int[] aS = new int[a];

		int aScnt = 0;
		for(int x=1;x<=a;x++){
			if(a%x==0){
				aS[aScnt] = x;
				aScnt++;
			}
		}
		aScnt--;
		int ans = 0;
		for(int x=b;x>0;x--){
			while(aS[aScnt]>x){
				aScnt--;
			}
			if(b%x==0&&aS[aScnt]==x){
				ans++;
				if(ans==k)break;
			}
		}
		System.out.println(aS[aScnt]);
	}
}

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

int main() {
  int N, x, count;
  cin >> N;
  vector<int> a(N+1);
  x = 0;
  count = 0;
  
  a.at(0) = 1;
  for (int i = 1; i < a.size(); i++) 
    cin >> a.at(i);
  
  while (true) {
    if (a.at(x) == 2)
      break;
    if (count > N+1) {
      count = -1;
      break;
    }
    count++;
    x = a.at(x);
    
  }
  
  cout << count << endl;
}


Measured memory_bytes: 640
// AOJ 2199: Differential Pulse Code Modulation
// 2017.9.21 bal4u@uu
// 2017.11.22

#include <stdio.h>
#include <string.h>

int code[18];			// code book
char y[2][260];			// signal
long long ss[2][260];	// Sum of Squares

char buf[20], *p;
int getint()
{
	int n = 0;
	if (*p == '-') {
		p++;
		while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}
int main()
{
	int n, m, i, j, k, x, k1, k2;
	long long ans, s;

	while (fgets(p=buf, 20, stdin) && *p != '0') {
		n = getint(), p++, m = getint();
		for (j = 0; j < m; j++) {
			fgets(p=buf, 10, stdin);
			code[j] = getint();
		}
		memset(ss, -1, sizeof(ss)), memset(y, 0, sizeof(y)); y[0][128] = 1, ss[0][128] = 0;
		for (k1 = 0, k2 = 1, k = 0; k < n; k++, k1 = k2, k2 = !k2) {
			for (i = 0; i < 256; i++) y[k2][i] = 0, ss[k2][i] = -1LL;
			fgets(p=buf, 10, stdin);
			x = getint();
			for (i = 0; i < 256; i++) {
				if (!y[k1][i]) continue;
				for (j = 0; j < m; j++) {
					int t = i + code[j];
					if (t < 0) t = 0;
					if (t >= 256) t = 255;
					y[k2][t] = 1;
					s = (t-x)*(t-x) + ss[k1][i];
					if (ss[k2][t] < 0 || s < ss[k2][t])	ss[k2][t] = s;
				}
			}
		}
		for (ans = 1LL << 60, i = 0; i < 256; i++) 
			if (ss[k1][i] >= 0 && ss[k1][i] < ans) {
				ans = ss[k1][i]; if (ans == 0) break;
			}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0;
  for(c = getchar();c < '0' || c > '9';c = getchar());
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res;
}
char s[maxn];
int n,num0;
int main(){
  scanf("%s",s + 1);
  n = strlen(s + 1);
  for(int i = 1;i <= n;i++) num0 += (s[i] == '0');
  printf("%d\n",2 * min(num0,n - num0));
  return 0;
}


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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N , M;
	cin >> N >> M;
	int a,i;
	int x=10,y=10,z=10,x1=0,y1=0,z1=0;
	FOR(j,0,M){
	cin >> i >> a ;
	if((i==1)&&(a==0)&&(N!=1)) {
      cout << "-1" <<endl; 
      return 0;
    }
	else if((i==1)&&(a!=x)&&(x1>=1)){
      cout << "-1" <<endl; 
      return 0;
    }
	else if((i==2)&&(a!=y)&&(y1>=1)) {
      cout <<"-1"<<endl; 
      return 0;
    }
	else if((i==3)&&(a!=z)&&(z1>=1)) {
      cout <<"-1"<<endl; 
      return 0;
    }
	else if(i==1) {
      x=a;
      x1++;
    }
	else if(i==2) {
      y=a;
      y1++;
    }
	else if(i==3) {
      z=a;
      z1++;
    }
	}
	
  	if((x==10)&&(N==1)) x=0;
	else if(x==10) x=1;
	if(y==10) y=0;
	if(z==10) z=0;

	if(N==3) cout << x << y << z <<endl;
    else if(N==2) cout << x << y <<endl;
    else if(N==1) cout << x <<endl;

    return 0;
}



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

int main() {
    int a[5], k;

    for (int i = 0;i < 5;i++) cin >> a[i];
    cin >> k;

    for (int i = 0;i < 5;i++) {
        for (int j = i+1;j < 5;j++) {
            if (a[j] - a[i] > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) {//最大公約数
    if(a<b){
        ll tmp = a;
        a = b;
        b = tmp; 
    }
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {//最小公倍数
    return a * b / gcd(a, b);
}

int main() {
    string n; cin >> n;
    rep(i,3){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;
const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;

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

    auto h = a * a * b;
    h /= 2.0;

    double res;

    auto xs = x / a;
    if (x >= h) {
        xs = a * b - xs;
        xs *= 2;
        xs /= a;
        res = atan2(a, xs);
    }
    else {
        xs *= 2;
        xs /= b;
        res = atan2(xs, b);
    }
    res *= Rad2Deg;
    res = 90 - res;
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i, a, b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i, n)  FOR(i,0,(n))
typedef vector<int> vec;


class BTollGates {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n, m, x;
      in >> n >> m >> x;
      x--;
      vector<int> a(m);
      REP(i, m) {
        in >> a[i];
        a[i]--;
      }
      vec b(n, 0);
      REP(i, m) {
        b[a[i]]++;
      }
      int front = 0, back = 0;
      FOR(i, x, n) {
        front += b[i];
      }
      RFOR(i, 0, x) {
        back += b[i];
      }
      int min_c = min(front, back);
      out << min_c << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BTollGates solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int n;
vector<vector<int>>  lst;
//n!通りの通り道を探す
void func(vector<int> seen){
    if(seen.size() == n){
        lst.push_back(seen);
        return;
    }
    for(int i=0; i<n; i++){
        auto iter = find(all(seen), i);
        if(iter == seen.end()){
            seen.push_back(i);
            func(seen);
            seen.pop_back();
        }
    }

}

int main() {
    cin >> n;
    vector<double> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    double res = 0;
    vector<int> seen;
    func(seen);
    
    for(vector<int> vc: lst){
        double d = 0;
        rep(i, vc.size()-1){
            int cx=x[vc[i]], cy=y[vc[i]], nx=x[vc[i+1]], ny=y[vc[i+1]];
            d = sqrt(pow(cx-nx,2) + pow(cy-ny,2));
            res += d;
        }
    }
    cout << fixed << setprecision(10);
    cout << res / lst.size() << ln;

}

Measured memory_bytes: 3256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 100005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,next;
}edg[maxn*2];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;
	edg[++ecnt]=(edge){v,u,ehead[v]};
	ehead[v]=ecnt;
}

int nop[maxn],n;bool ok=false;
void dfs(int u,int fa) {
	for (int v,j=ehead[u];j;j=edg[j].next)
	if ((v=edg[j].v)!=fa) {
		dfs(v,u);nop[u]+=nop[v];
	}
	ok|=nop[u]>1;nop[u]^=1;
}
int main()
{
	#ifdef Amberframe
		freopen("agc014d.in","r",stdin);
		freopen("agc014d.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),add(u,v);
	dfs(1,0);printf("%s",ok|nop[1]?"First":"Second");
	return 0;
}

Measured memory_bytes: 3328
s = input()
t = []

for i in range(len(s)):
    if s[i] == "A":
        t.append("T")
        continue

    if s[i] == "T":
        t.append("A")
        continue

    if s[i] == "G":
        t.append("C")
        continue

    if s[i] == "C":
        t.append("G")
        continue

ans = "".join(t)
print(str(ans))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n;

int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return 2 * i + 1;
}

void swap(int *x, int *y) {
	int tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void maxHeapify(int *A, int i) {
	int l, r, largest;

	l = left(i);
	r = right(i);

	if (l <= n && A[l] > A[i]) largest = l;
	else largest = i;

	if (r <= n && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(&A[i], &A[largest]);
		maxHeapify(A, largest);
	}
}

void heapIncreaseKey(int *A, int i, int key) {
	if (key >= A[i]) {
		A[i] = key;
		while (i > 1 && A[parent(i)] < A[i]) {
			swap(&A[i], &A[parent(i)]);
			i = parent(i);
		}
	}
}

void maxHeapInsert(int *A, int key) {
	n++;
	A[n] = -32768;
	heapIncreaseKey(A, n, key);
}

int heapExtractMax(int *A) {
	int max;

	if (n >= 1) {
		max = A[1];
		A[1] = A[n];
		n--;
		maxHeapify(A, 1);
		return max;
	}

	return -1;
}

main() {
	int *node;
	int key;
	char order[8];

	node = (int*)malloc(sizeof(int) * 2000000);

	while (1) {
		scanf("%s", &order);
		if (!strcmp(order, "insert")) {
			scanf("%d", &key);
			maxHeapInsert(node, key);
		}
		else if (!strcmp(order, "extract")) printf("%d\n", heapExtractMax(node));
		else if (!strcmp(order, "end")) break;
	}

	free(node);

	return 0;
}

Measured memory_bytes: 5516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N, count = 0;
    cin >> N;
    vector<long> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    bool flg = true;

    while (flg) {
        flg = false;
        for(int i=0; i<N; i++) {
            if(A[i] % 2 == 0 && flg == false) {
                A[i] /= 2;
                flg = true;
            }
            else {
                A[i] *= 3;
            }
        }
        if(flg) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		for (int x = 10 * b; x < 10 * (b + 1); x++) {
			if (x * 8 / 100 == a) {
				System.out.println(x);
				return;
			}
		}
		System.out.println(-1);
	}

}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string n; cin >> n;
    bool ok=false;
    rep(i,0,3) if(n[i]=='7') ok =true;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#include<new>
#include<float.h>
#include<ctype.h>
#include<cfloat>
#include<cmath>
#include<cctype>
#include<sstream>
#define fo(i,w,n) for(ll i=w;i<n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define sz size()
#define em empty()
#define ct continue
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=m/n+50000;i;i--)if(m%i==0&&i*n<=m){
		cout<<i<<endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3 24" ].parse.expand.solve == 2 );
	assert( [ "5 1" ].parse.expand.solve == 1 );
	assert( [ "1 111" ].parse.expand.solve == 111 );
	assert( [ "4 972439611840" ].parse.expand.solve == 206 );
	
	assert( [ "190000000000 972439611841" ].parse.expand.solve == 1 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto np = input.front.split.to!( long[] );
	return tuple( np[ 0 ], np[ 1 ] );
}

auto solve( long n, long p )
{
	// pを素因数分解して素因数ごとの個数をカウント
	auto gs = primefactorize( p ).group;
	
	// as全部に掛けられる個数の素因数があったら最大公約数を大きくできる
	auto ans = 1L;
	foreach( g; gs )
	{
		auto d = g[ 1 ] / n;
		if( 0 < d ) ans *= g[ 0 ] ^^ d;
	}
	return ans;
}

// 素数列
auto primes( long x )
{
	long[] ps;
	if( x < 2 ) return ps;
	
	auto cs = new bool[]( x + 1 );
	ps = [ 2L ];
	for( auto i = 3L; i * i < cs.length; i += 2 )
	{
		if( cs[ i ] ) continue;
		for( auto j = i; i * j < cs.length; j++ )
		{
			cs[ i * j ] = true;
		}
	}
	for( auto i = 3L; i < cs.length; i += 2 )
	{
		if( !cs[ i ] ) ps ~= i;
	}
	return ps;
}

// 素因数分解
long[] primefactorize( long x )
{
	auto s = cast( long ) sqrt( cast( float ) x ) + 1;
	return primefactorize( x, s.primes );
}

// 素因数分解（事前に作った素数列を使う）
auto primefactorize( long x, long[] ps )
{
	long[] fs;
	if( x < 2 ) return fs;
	
	foreach( p; ps )
	{
		while( x % p == 0 )
		{
			x /= p;
			fs ~= p;
		}
	}
	if( 1 < x ) fs ~= x;
	return fs;
}


Measured memory_bytes: 3452
using System;
using static System.Math;

class Program {
  static void Main(string[] args) {
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int a = int.Parse(input[1]);
    int b = int.Parse(input[2]);

    Console.WriteLine(Min(b, n * a));
  }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
 
struct node{
    int id;
    struct node *parentNode;
    struct node *firstChild;
    struct node *sibling;
};
 
struct node* createNode(int);
struct node* searchNode(int);
int getHeight(struct node* nd);
 
struct node* nodes[26];
int n;
 
int main(){
 
int i,j;
int id;
int tmpId;
int left, right;
int depth;
struct node* currentNode;
struct node* tmpNode;
struct node* leftChild;
struct node* rightChild;
 
scanf("%d",&n);
     
for(i=0;i<n;i++){
     
    scanf("%d",&id);
    currentNode = createNode(id);
     
    scanf("%d",&left);
    leftChild = createNode(left);
    scanf("%d",&right);
    rightChild = createNode(right);
     
    if(leftChild){
        leftChild->sibling = rightChild;
        leftChild->parentNode = currentNode;
        currentNode->firstChild = leftChild;
    }
    if(rightChild){
        rightChild->sibling = leftChild;
        rightChild->parentNode = currentNode;
        if(leftChild==NULL) currentNode->firstChild = rightChild;
    }
     
}
     
    for(i=0; i<n; i++){
         
        printf("node %d: ",nodes[i]->id);
        printf("parent = %d, ",(nodes[i]->parentNode?nodes[i]->parentNode->id:-1));
        printf("sibling = %d, ",(nodes[i]->sibling?nodes[i]->sibling->id:-1));
        printf("degree = ");
        if(nodes[i]->firstChild){
            if(nodes[i]->firstChild->sibling) printf("2");
            else printf("1");
        }else{
            printf("0");    
        }
        printf(", ");
         
        depth = 0;
        tmpNode = nodes[i]->parentNode;
        while(tmpNode){
            depth++;
            tmpNode = tmpNode->parentNode;
        }
        printf("depth = %d, ",depth);
        printf("height = %d, ",getHeight(nodes[i]));
 
        if(depth==0) printf("root");
        else if(nodes[i]->firstChild==NULL) printf("leaf");
        else printf("internal node");
         
        printf("\n");
         
    }
 
return 0;
}
 
struct node* createNode(int id){
    struct node *newNode;
    if(id < 0) return NULL;
    if(newNode = searchNode(id)) return newNode;
    newNode = (struct node*)malloc(sizeof(struct node));
    newNode->id=id;
    newNode->parentNode = NULL;
    newNode->firstChild = NULL;
    newNode->sibling = NULL;
    nodes[id] = newNode;
    return newNode;
}
 
struct node* searchNode(int id){
    if(nodes[id]) return nodes[id];
    return NULL;
}
 
int getHeight(struct node* nd){
    int tmpLeft=-1, tmpRight=-1;
    if(nd->firstChild) tmpLeft = getHeight(nd->firstChild);
    if(nd->firstChild && nd->firstChild->sibling) tmpRight = getHeight(nd->firstChild->sibling);
    return (tmpLeft>tmpRight?tmpLeft:tmpRight)+1;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] set = new int[5];
		for(int i = 0; i < 5; i++){
				set[i] = scan.nextInt();
		}
		scan.close();
		if(set[0] > set[1]){
			set[0] = set[1];
		}
		if(set[0] > set[2]){
			set[0] = set[2];
		}
		if(set[0] > set[1]){
			set[0] = set[1];
		}
		if(set[3] > set[4]){
			set[3] = set[4];
		}
		System.out.println(set[0] + set[3] - 50);
	}
}

Measured memory_bytes: 17160
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

#define fs first
#define sc second

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

const ll mod = 1e9+7;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[22][1 << 21];
unordered_map<int, bool> mp;

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

    for(int i = 0; i < 22; i++){
        for(int j = 0; j < (1 << 21); j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    queue<P> q;
    q.push(P(0, 0));
    while(!q.empty()){
        P p = q.front(); q.pop();
        int state = p.fs;
        int num = p.sc;
        if(num == N){
            break;
        }

        for(int j = 0; j < N; j++){
            if(a[num][j] == 1 && (state >> j) % 2 == 0){
                int nextState = state + (1 << j);
                dp[num+1][nextState] = add(dp[num+1][nextState], dp[num][state]);
                if(mp.find(nextState) == mp.end()){
                    q.push(P(nextState, num+1));
                    mp[nextState] = true;
                }
            }
        }
    }

//    for(int i = 0; i <= N; i++){
//        for(int j = 0; j < (1 << N); j++){
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    cout << dp[N][(1 << N) - 1] << endl;


    return 0;
}

Measured memory_bytes: 445648
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define itn int
#define all(c) c.begin(),c.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std; 

const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& mas) {
    for (const auto& x : mas) {
        out << x << ' ';
    }
    return out;
}

void ok() {
    cout << "YES" << '\n';
}

void no() {
    cout << "NO" << '\n';
}

inline ll nxt() {
    ll x;
    cin >> x;
    return x;
} 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int x = nxt(), n = nxt();
    vector<int> a(n);
    generate(all(a), nxt);
    int r = INT_MAX;
    int ans = -1;
    for (int i = -105; i <= 105; i++) {
        if (find(all(a), i) == a.end()) {
            int cur = abs(x - i);
            if (cur < r) {
                r = cur;
                ans = i;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <string>

int main(){
    using namespace std;
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    // ターンごとに計算してOK
    int t, hp_a, hp_c;
    hp_a = A;
    hp_c = C;
    for(t=0;;t++){
        // takahashi attack
        if((hp_c-B)<=0){    // takahashi win
            cout << "Yes"<< endl;
            break;
        }else{
            hp_c -= B;
        }

        // aoki attack
        if((hp_a-D)<=0){    // aoki win
            cout << "No"<< endl;
            break;
        }else{
            hp_a -= D;
        }
    }

    return 0;
}

Measured memory_bytes: 3636
class UnionFind:
    def __init__(self,n):
        self.n = n
        self.p = [i for i in range(n)]
        self.rank = [0]*n

    def same(self,x,y):
        return self.root(x)==self.root(y)

    def root(self,x):
        if x!=self.p[x]:self.p[x] = self.root(self.p[x])
        return self.p[x]

    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if self.rank[y]<self.rank[x]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[y]==self.rank[x]:
                self.rank[y]+=1

def main():
    n,m = map(int,input().split())
    UF = UnionFind(n)
    for _ in range(m):
        a,b = map(int,input().split())
        UF.unite(a,b)
    q = int(input())
    for _ in range(q):
        a,b = map(int,input().split())
        if UF.same(a,b):print ('yes')
        else           :print ('no')


if __name__ == '__main__':
    main()




Measured memory_bytes: 10464
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename Container>
ostream &pprint(const Container &a, string_view sep = " ",
                string_view ends = "\n", ostream *os = nullptr) {
  if (os == nullptr) os = &cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  return pprint(a, ",", "", &(os << "[")) << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &a) {
  return pprint(a, ",", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  int sr, sc;
  cin >> sr >> sc;
  sr--;
  sc--;
  int dr, dc;
  cin >> dr >> dc;
  dr--;
  dc--;
  V<string> grid(H);
  REP(i, H) { cin >> grid[i]; }

  const int INF = 1e8;

  MinHeap<tuple<i64, int, int>> hp;
  V<V<int>> cost(H, V<int>(W, INF));
  hp.emplace(0, sr, sc);
  while (!hp.empty()) {
    auto [d, cr, cc] = hp.top();
    assert(grid[cr][cc] == '.');
    hp.pop();
    if (d >= cost[cr][cc]) continue;
    cost[cr][cc] = d;
    if (cr == dr && cc == dc) break;

    for (int dy = -2; dy <= 2; ++dy) {
      for (int dx = -2; dx <= 2; ++dx) {
        if (dx == 0 && dy == 0) continue;
        int r2 = cr + dy;
        int c2 = cc + dx;
        if (0 > r2 || r2 >= H || 0 > c2 || c2 >= W) continue;
        if (grid[r2][c2] == '#') continue;
        int co;
        if (dx * dy == 0 && max(abs(dx), abs(dy)) == 1) {
          co = 0;
        } else {
          co = 1;
        }
        hp.emplace(d + co, r2, c2);
      }
    }
  }

  i64 ans = cost[dr][dc];
  cout << (ans == INF ? -1LL : ans) << endl;
}


Measured memory_bytes: 10188
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>

using namespace std;

const int maxm = 100002;

int n, m, w, v;
long long f[maxm];

int main() {

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

	cin >> n >> m;
	for (int i = 0; i < n; ++i)
	{
		cin >> w >> v;
		for (int j = m; j >= w; --j)
			f[j] = max(f[j], f[j-w] + v);
	}
	
	cout << f[m] << endl;

	return 0;
}

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

using namespace std;

int main(void)
{
    int X, N;
    int p[100];
    cin >> X >> N;
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    
    for(int i = 0; 1; i++){
        if(find(p, p+N, X - i) == p + N){
            cout << X - i << endl;
            break;
        }
        if(find(p, p+N, X+i) == p + N){
            cout << X + i << endl;
            break;
        }
    }
        return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ '0');
	return sum * fg;
}

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

const int MAXN = (int) 1e5;

// Template-Libs

// END

int n, m;

char S[MAXN + 5], T[MAXN + 5];

inline void input()
{
	n = read<int>(), m = read<int>();
	scanf("%s%s", S + 1, T + 1);
}

inline void solve()
{
	static map<LL, char> X;
	LL L = (LL) n * m / __gcd(n, m);
	for(int i = 1; i <= n; ++i) X[1 + (LL) (i - 1) * (L / n)] = S[i];
	for(int i = 1; i <= m; ++i) if(X.find(1 + (LL) (i - 1) * (L / m)) != X.end() && X[1 + (i - 1) * (L / m)] != T[i]) { puts("-1"); return; }
	printf("%lld\n", L);
}

int main()
{
	input();
	solve();

	return 0;
}



Measured memory_bytes: 6144
N, P = map(int, input().split())


def factorization(n):
    tmp = n
    d = {}
    for i in range(2, int(n ** 0.5) + 1):
        while tmp % i == 0:
            tmp //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1

    if tmp != 1:
        d[tmp] = 1

    return d


d = factorization(P)
ans = 1
for k, v in d.items():
    if v >= N:
        n = v // N
        ans *= k ** n

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
double a,b,c,d,e,f;
while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF)
{
printf("%.3lf %.3lf\n", (b*f - c*e)/(b*d - a*e)+0.0001, (a*f - c*d)/(a*e - b*d)+0.0001);
}
return 0;
}

Measured memory_bytes: 1736
-- http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A

main = do
    l <- getLine
    let (a:b:[]) = map read $ words l :: [Int]
    putStrLn $ cmpr a b

cmpr :: Int -> Int -> String
cmpr a b
    | a > b = "a > b"
    | a < b = "a < b"
    | a == b = "a == b"



Measured memory_bytes: 3600
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
const int maxn = 1<<21, mod = 1e9 + 7;
using ld = long double;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);
	int x, y, a, b;
	cin >> a >> b >> x >> y;
	cout << (ld)a*b/2. << " " << (2*x==a&&2*y==b);
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    int odp = 0;
    for (int l = 0; l < n; )
    {
        int p = l;
        while (p < n && nap[l] == nap[p])
            ++p;
        --p;
        ++odp;
        l = p + 1;
    }
    --odp;
    cout << odp;
    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    w,a,b=map(int,input().split())
    if(a>=b): a,b=b,a
    print(max(0,b-a-w))
resolve()

Measured memory_bytes: 38256
n = gets.chomp.to_i
k = []
n.times do |i|
  k[i] = gets.chomp.split.map(&:to_i)
end

# dp[幸福のmax][前日に選んでたやつ]
dp = Array.new(10 ** 5 + 5) { Array.new(3, 0) }

1.upto(n) do |i|
  (0..2).each do |j| # 前日
    (0..2).each do |d| # 当日
      next if d == j
      dp[i][j] = [dp[i][j], dp[i-1][d] + k[i-1][d]].max
    end
  end
end
p dp[n].max


Measured memory_bytes: 16124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a;cin>>a;
    if('a'<=a && a<='z'){
        cout<<'a'<<endl;
        return 0;
    }else{
        cout<<'A'<<endl;
        return 0;
    }
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 

using namespace std;

int main() {
	int i, j, x, y, z;
	int cnt;

	cin >> x >> y >> z;

	for (i = z, cnt = 0; i <= x; i += (y+z)) {

		cnt++;
	}


	cout << cnt-1 << endl;





	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    int a,b;cin>>a>>b;
    if(a==b)cout<<a*2<<endl;
    else cout<<max(a,b)*2-1<<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a == b){
    cout << "Draw" << endl;
    return 0;
  } 
  

  if (a == 1){
    cout << "Alice" << endl;
  } else if (b == 1){
    cout << "Bob" << endl;
  } else {
    if (max(a, b) == a) {
      cout << "Alice" << endl;
    } else {
      cout << "Bob" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  string s;
  cin >> s;
  int cnt0 = count(s.cbegin(), s.cend(), '0');
  int cnt1 = count(s.cbegin(), s.cend(), '1');
  cout << 2*min(cnt0, cnt1) << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashSet<String> set = new HashSet<String>();
    for(int i = 0; i < n; i++) {
      set.add(sc.next());
    }
    System.out.println(set.size());
  }
}

Measured memory_bytes: 76916
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
tmp = 0
u = []
for i in range(n):del a[i][0]
for i in range(n):
    for j in range(len(a[i])):
        if not(a[i][j] in u):u.append(a[i][j])
for i in range(len(u)):
    for j in range(n):
        if u[i] in a[j]: tmp += 1
    if tmp == n: ans += 1
    tmp = 0
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int sum = 0;
      if(n==10||n==100||n==1000||n==10000||n==100000){
      	System.out.println(10);
        return;
      }
      while(n>0){
      	sum+=n%10;
        n/=10;
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


int dp[N];
void test_case() {

    int n;
    cin>>n;


    vec arr(n);
    rep(i,n) {
        cin>>arr[i];
    }

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


    for(int i=2; i<n; i++) {
        dp[i] = min(dp[i-2] + abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i] - arr[i-1] ));
    }

    cout<<dp[n-1]<<endl;




}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 3988
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using usize = std::size_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

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

struct edge {
  usize to;
  u64 cost;

  bool operator<(const edge &r) const { return r.cost < cost; }
};

static constexpr u64 inf = std::numeric_limits<u64>::max();

std::vector<u64> dijkstra(const std::vector<std::vector<edge>> &g,
                          const usize s) {
  const usize n = g.size();
  std::vector<u64> dist(n, inf);

  dist[s] = 0;
  std::priority_queue<edge> que;
  que.push({s, 0});

  while (!que.empty()) {
    const usize v = que.top().to;
    const usize c = que.top().cost;
    que.pop();
    if (dist[v] < c) {
      continue;
    }
    for (const auto &e : g[v]) {
      if (dist[e.to] > c + e.cost) {
        dist[e.to] = c + e.cost;
        que.push({e.to, dist[e.to]});
      }
    }
  }

  return dist;
}

int main() {

  usize n, m;
  std::cin >> n >> m;

  struct e_tp {
    usize x, y;
    u64 t;
  };

  std::vector<e_tp> es(m);
  for (auto &e : es) {
    std::cin >> e.x >> e.y >> e.t;
    e.x -= 1;
    e.y -= 1;
  }

  usize v0;
  std::cin >> v0;

  usize a, b, c;
  std::cin >> a >> b >> c;

  const auto idx = [&](const usize r, const usize ve, const usize i) {
    return (r * c + ve) * n + i;
  };

  std::vector<std::vector<edge>> g(2 * c * n);

  const auto span = [&](const usize x, const usize y, const u64 t) {
    for (const auto r : {0, 1}) {
      for (usize i = 0; i != c; ++i) {
        g[idx(r, i, x)].push_back({idx(r, (a * i + b) % c, y), t * i});
      }
    }
  };

  for (const auto &e : es) {
    span(e.x, e.y, e.t);
    span(e.y, e.x, e.t);
  }

  for (usize i = 0; i != c; ++i) {
    g[idx(0, i, n - 1)].push_back({idx(1, i, n - 1), 0});
  }

  u64 ans = inf;
  const auto dist = dijkstra(g, idx(0, v0, 0));

  for (usize i = 0; i != c; ++i) {
    chmin(ans, dist[idx(1, i, 0)]);
  }

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 28300
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

n = int(ipt())
a = [int(i) for i in ipt().split()]
if 0 in a:
    print(0)
    exit()
ans = 1
for i in a:
    if 10**18/ans < i:
        print(-1)
        exit()
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)


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

int main() {
  string s;
  map<char, int> m;
  cin >> s;
  for (int i{}; i < s.length(); ++i)
    ++m[s[i]];

  bool ans{true};
  for (const auto& p : m) {
    if (p.second != 2) {
      ans = false;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
S=input()
K=float(input())
lis=list(S)
ss=set(lis)

if len(ss)==1:
  print(S[0])
else:
  if K<=len(S):
    check_list=lis[:int(K)]
    check_set=set(check_list)
    if len(check_set)==1:
      print(check_list[0])
    else:
      for num in lis:
        if int(num)!=1:
          print(int(num))
          break            
  else:
    for num in lis:
      if int(num)!=1:
        print(int(num))
        break

Measured memory_bytes: 3064