akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	
	int n, x, y; cin >> n >> x >> y;

	// グラフ入力受取 (ここでは無向グラフを想定)
	Graph G(n);
	for (int i = 0; i <= n - 2; ++i) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);;
	}
	x--;
	y--;
	G[x].push_back(y);
	G[y].push_back(x);

	vector<vector<int>> dist(n, vector<int>(n, -1));

	for (int z = 0; z <= n - 2; z++) {

		// BFS のためのデータ構造
		queue<int> que;

		// 初期条件 (頂点 0 を初期ノードとする)
		dist[z][z] = 0;
		que.push(z); // 0 を橙色頂点にする

		// BFS 開始 (キューが空になるまで探索を行う)
		while (!que.empty()) {
			int v = que.front(); // キューから先頭頂点を取り出す
			que.pop();

			// v から辿れる頂点をすべて調べる
			for (int new_v : G[v]) {
				if (dist[z][new_v] != -1) continue; // すでに発見済みの頂点は探索しない

				// 新たな白色頂点 new_v について距離情報を更新してキューに追加する
				dist[z][new_v] = dist[z][v] + 1;
				que.push(new_v);
			}
		}
	}
	
	vector<int> ans(n, 0);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans[dist[i][j]]++;
		}
	}
	for (int i = 1; i <= n-1; i++) {
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 16128
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int x,y,z=0;
	cin>>x>>y;
	if(x>=0 && y>=0){
		if(x+y>=24)
		z=(x+y)-24;
		else
		z=x+y;
	}	
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextLineInt() []int {
	lineString := strings.Split(nextLine(), " ")
	var lineInt = make([]int, len(lineString))
	for i := range lineString {
		lineInt[i], _ = strconv.Atoi(lineString[i])
	}
	return lineInt
}

func bool2int(b bool) int {
	if b {
		return 1
	} else {
		return 0
	}
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func d(a, b int) int {
	return abs(a - b)
}

func main() {
	var n, k int

	fmt.Scanf("%d %d", &n, &k)

	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}

	cost := make([]int, n)

	for i := 0; i < n; i++ {
		cost[i] = 9223372036854775807
	}

	cost[0] = 0

	for i := 0; i < n-1; i++ {
		for j := 1; j < k+1; j++ {
			left := max(0, i-j+1)
			cost[i+1] = min(cost[i+1], cost[left]+abs(h[left]-h[i+1]))
		}
	}

	fmt.Println(cost[n-1])
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(unsigned ll i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MOD 1000000007LL
#define pi 3.14159265358
ll binary_power(ll a, ll n) {
    if (n==0) return 1;
    ll k=binary_power(a,n/2);
    if (n%2==0) return (k*k)%MOD;
    else return (((k*k)%MOD)*a)%MOD;
}
bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i*i <= num ; i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

void solve()
{
    long double r; cin>>r;
    r = 2*pi*r;
    cout<<setprecision(10)<<r;
}

int main()
{
    SPEED;
    ll t = 1;

  // cin>>t;

    while(t--) solve();

   return 0;
}


Measured memory_bytes: 3784
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

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

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int main(){
    int n;
    cin >> n;
    int maxval1 = 0, maxval2 = 0;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ans[i] = a;
        if(maxval1 <= a){
            maxval2 = maxval1;
            maxval1 = a;
        }
        else if(maxval2 <= a){
            maxval2 = a;
        }
    }

    for(int i = 0; i < n; i++){
        if(ans[i] == maxval1){
            cout << maxval2 << endl;
        }
        else{
            cout << maxval1 << endl;
        }
    }
    return 0;
}





































Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int q = sc.nextInt();
		boolean reverseFlag = false;

		StringBuilder front = new StringBuilder();
		StringBuilder back = new StringBuilder();
		for(int i =0;i < q;i++) {
			int t = sc.nextInt();
			if(t ==1) {
				if(reverseFlag) {
					reverseFlag = false;
				}else {
					reverseFlag = true;
				}
			}else {
				int f = sc.nextInt();
				if(f == 1) {
					if(reverseFlag) {
						back.append(sc.next());
					}else {
						front.insert(0, sc.next());
					}
				}else {
					if(reverseFlag) {
						front.insert(0, sc.next());
					}else {
						back.append(sc.next());
					}
				}
			}
		}
		StringBuilder answer = new StringBuilder();
		answer.append(front);
		answer.append(s);
		answer.append(back);
		if(reverseFlag) {
			System.out.println(answer.reverse());

		}else {
			System.out.println(answer);
		}
	}
}

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

int mod = 1e9+7;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N){
        int a; cin >> a;
        A[a]++;
    }
    ll ans = 1;
    bool ok = true;
    if(N%2 == 1){
        for (int i = 0; i < N; i+=2){
            if(i == 0){
                if(A[i] != 1)ok = false;
            } else {
                if(A[i] != 2){
                    ok = false;
                } else {
                    ans *= 2;
                    ans %= mod;
                }
            }
        }
    } else {
        for (int i = 1; i < N; i+=2){
            if(A[i] != 2){
                ok = false;
            } else {
                ans *= 2;
                ans %= mod;
            }
        }
    }

    if(ok){
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 3740
N, P = [int(_) for _ in input().split()]

from math import sqrt, ceil
from collections import defaultdict

rootp = ceil(sqrt(P))

cs = defaultdict(int)

x = P
for i in range(2, rootp):
    while x % i == 0:
        cs[i] += 1
        x //= i
cs[x] += 1

#print(cs)

result = 1

for n in cs:
    x = cs[n] // N
    if x:
        result *= n ** x

print(result)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class RMQ{
public : 
  typedef long long ll;
  ll INF = 1LL<<55;
  struct data{
    bool type; //0 - empty   , 1 - update
    ll value;
  };
  ll n,n_;
  vector<ll> dat;
  vector<data> td;
  int toMax; //0 -> RangeMin 1->RangeMax;
  
  RMQ(){n=-1;}
  RMQ(int n_,int toMax = 0):n_(n_),toMax(toMax){
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,(data){0,0});
    dat.resize(2*n-1,INF);
  }
  
  //[a,b)の値をxに変更　update(a,b,x)
  ll update(int a,int b,ll x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r == -1) {
      r = n;
      assert(a <= b), assert(a <= n && b <= n), assert(a >= 0 && b >= 0);
      if(toMax) x *= -1;
    }
    
    if(r<=a||b<=l)return flg? dat[k]:INF;
    if(a<=l&&r<=b){
      if(flg==true){
        td[k]=(data){1,x};
        dat[k]=x;
      }
      return dat[k];
    }
    
    if(td[k].type){
      td[k].type=0;
      dat[k*2+1] = dat[k*2+2] = td[k].value;
      td[k*2+1] = td[k*2+2] = (data){1,td[k].value};
    }
    
    ll vl=update(a,b,x,flg,k*2+1,l,(l+r)/2);
    ll vr=update(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg==true)dat[k]=min(vl,vr);
    return min(vl,vr);
  }
  
  //[a,b)の最小値を得る　find(a,b);
  ll find(int a,int b){return (toMax? -1:1) * update(a,b,0,false);};
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;
  
  RMQ mn(n),mx(n,1);
  for(int i=0;i<n;i++) mn.update(i, i+1, A[i]);
  for(int i=0;i<n;i++) mx.update(i, i+1, A[i]);
  
  int q;
  cin>>q;
  while(q--){
    int com, b, e;
    cin>>com >> b >> e;
    int ans = com==0? mn.find(b, e):mx.find(b, e);
    cout<<ans<<endl;

  }
  
  return 0;
}



Measured memory_bytes: 3116
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N,K;
    cin >> N >> K;
    ll A[200010] = {};
    rep(i,0,N) cin >> A[i];
    
    ll num = min(K, 800LL);
    ll nxt[200010] = {};
    ll cur[200010] = {};
    rep(i,0,N) cur[i] = A[i];

    rep(k,0,num){
        rep(i,0,N) nxt[i] = 0;
        rep(i,0,N){
            ll v = cur[i];
            ll lv = max(0LL, i - v);
            ll rv = min(N, i + v+1);
            nxt[lv]++;
            nxt[rv]--;
        }
        rep(i,0,N+1){
            nxt[i+1] += nxt[i];
        }
        rep(i,0,N){
            cur[i] = nxt[i];
        }
    }
    printa(cur, N);


    

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 8380
#include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int sum=0;
		for(int i=1;i*i<=n;i++){
			if(n%i==0){
				int j=n/i;
				if(i!=n)sum+=i;
				if(i!=j&&j!=n)sum+=j;
			}
		}
		if(sum==n)std::cout<<"perfect number"<<std::endl;
		else if(sum<n)std::cout<<"deficient number"<<std::endl;
		else if(sum>n)std::cout<<"abundant number"<<std::endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int motonokazu;
  motonokazu =N;
  int sum = 0;

  for(int i = 0 ; i < 8;i++){
    sum += N%10;
    N /= 10;
  }

 if(motonokazu%sum == 0){
   cout << "Yes" <<endl;
 }

 else{
   cout << "No" <<endl;
 }

}

Measured memory_bytes: 256
import Base.parse
import Base.StringVector
using DataStructures

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        if !isdelim(c, delims)
            break
        end
    end
    push!(out, c)
    if eof(s)
        return out
    end
    while !eof(s)
        c = read(s, UInt8)
        if isdelim(c, delims)
            break
        end
        push!(out, c)
    end
    return out
end

delimset = Set([0x0a, 0x20])

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i = 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

function main()
    N,M = reads(Int,Int)
    con = [Set(Int[]) for i in 1:N]
    for i in 1:M
        a,b = reads(Int,Int)
        push!(con[a], b)
        push!(con[b], a)
    end
    root = Union{Tuple{Int,Int},Nothing}[nothing for i in 1:N]
    root[1] = (0,0)
    q = PriorityQueue{Int,Int}()
    enqueue!(q, 1, 0)
    while !isempty(q)
        index = dequeue!(q)
        for n in con[index]
            if isnothing(root[n]) || root[n][2] > root[index][2]+1
                v = root[index][2]+1
                root[n] = (index, v)
                enqueue!(q, n, v)
            end
        end
    end
    ans = root
    for i in ans[2:end]
        if isnothing(i)
            println("No")
            return
        end
    end
    println("Yes")
    for i in 2:N
        println(ans[i][1])
    end
end

main()


Measured memory_bytes: 291004
import numpy as np
import copy

n = int(input())

a = list(map(int,input().split()))
b=copy.deepcopy(a)

cntm=0
cntp=0
sum_a=0
sum_b=0

if a[0]<=0:
    cntp+=-a[0]+1
    a[0]=1
if b[0]>=0:
    cntm+=b[0]+1
    b[0]=-1
for i in range(n-1):
    sum_a += a[i]
    sum_b += b[i]
    if abs(sum_a) >= abs(a[i+1]) or sum_a*a[i+1]>=0:
            cntp += abs(-sum_a-np.sign(sum_a) -a[i+1])
            a[i+1]=-sum_a-np.sign(sum_a)
    if abs(sum_b) >= abs(b[i+1]) or sum_b*b[i+1]>=0:
            cntm += abs(-sum_b-np.sign(sum_b) -b[i+1])
            b[i+1]=-sum_b-np.sign(sum_b)
print(min(cntm, cntp))

Measured memory_bytes: 23260
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

#define INF (1<<29)
#define MAX (1<<16)

int N;
int memo[MAX];
vector< vector<int> > vvs;

int dfs(int bit)
{
	if (memo[bit] != -1) return memo[bit];
	if (bit == (1<<N)-1) return memo[bit] = 0;

	int ans = INF;
	rep(i, N) {
		if ((bit>>i)&1) continue;
		int d = vvs[i][0];
		rep(j, N)
			if ((bit>>j)&1)
				d = min(d, vvs[i][j+1]);
		ans = min(ans, dfs(bit|(1<<i))+d);
	}
	return memo[bit] = ans;
}

int main(void)
{
	while (cin >> N, N) {
		memset(memo, -1, sizeof(memo));

		vvs = vector< vector<int> >(N, vector<int>(N+1));
		rep(j, N)
			rep(i, N+1)
				cin >> vvs[j][i];

		cout << dfs(0) << endl;
	}
	return 0;
}

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

int mp[3];
int n, x;

int main() {
	ios::sync_with_stdio(false);
	while (cin >> n) {
		memset(mp, 0, sizeof(mp));
		for (int i = 0; i < n; i++) {
			cin >> x;
			if (x % 4 == 0)
				mp[2]++;
			else if (x % 2 == 0)
				mp[1]++;
			else
				mp[0]++;
		}
		if (mp[1] > 0)
			mp[0]++;
		if (mp[0] - 1 > mp[2])
			cout << "No\n";
		else
			cout << "Yes\n";
	}
	return 0;
}

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

string strrev(string a){
	string ans = "";
	for(int i=a.size()-1;i>=0;i--){
		ans += a[i];
	}
	return ans;
}
int main(){
	string s,t;
	cin>>s>>t;
	int n = s.size();
	int m = t.size();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j] = 0;
		}
	}
	string ans="";
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}
			else if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	// cout<<dp[n][m]<<endl;
	int i=n,j=m;
	while(i>0 && j>0){
		// cout<<dp[i-1][j]<<" "<<dp[i][j-1]<<endl;
		if(s[i-1]==t[j-1]){
			ans += s[i-1];
			i--,j--;
		}
		else if(dp[i-1][j] > dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
		// cout<<ans<<endl;
	}
	// ans = ans.substr(0,dp[n][m]);
	ans = strrev(ans);
	cout<<ans<<endl;
}


Measured memory_bytes: 35456
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli A, B, C;
	cin >> A >> B >> C;

	COUT(A + B + C - max({ A,B,C }));

	return 0;
}


Measured memory_bytes: 256
H, W, K = [int(x) for x in input().split()]
div = 1000000007


def baai(L):
    if L == []:
        return 1
    elif L == [0]:
        return 2
    elif L == [1]:
        return 1
    elif L == [0, 0]:
        return 3
    elif len(L) == 2:
        return 1

    if L[0:2] == [1, 0]:
        return baai(L[2:])
    elif L[0:2] == [0, 1]:
        return baai(L[1:])
    elif L[0:2] == [0, 0]:
        return baai(L[2:])+baai(L[1:])
    else:
        print("hoge", L)
        return 0


ans = [0]*(H+1)                       # 高さnに対するあみだくじ本数
dp = [[0]*W for _ in range(H)]


for i in range(H):
    for j in range(W):
        # print(i, j)
        if j-1 > i:
            break
        elif i == 0:
            if j == 0:
                dp[i][j] = baai([0]*(W-2))
            else:
                buf = [0] * (W-1)
                buf[0] = 1
                dp[i][j] = baai(buf)
            dp[i][j] = dp[i][j] % div
            continue

        buf = [0]*W
        buf[j] = 1
        dp[i][j] += dp[i-1][j]*baai(buf)
        if j-1 >= 0:
            buf = [0]*(W-1)
            buf[j-1] = 1
            dp[i][j] += dp[i-1][j-1]*baai(buf)
        if j+1 < W:
            buf = [0]*(W-1)
            buf[j] = 1
            dp[i][j] += dp[i-1][j+1]*baai(buf)
        dp[i][j] = dp[i][j] % div

print(dp[H-1][K-1])


Measured memory_bytes: 3188
import sys
n = int(sys.stdin.readline())

cards = {"S": [], "H": [], "C": [], "D": []}
for line in sys.stdin:
    (suit, number) = line.split()
    cards[suit].append(int(number))

for suit in ("S", "H", "C", "D"):
    for i in range(1, 14):
        if i not in cards[suit]:
            print(suit, i)

Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n, h, w;
  cin >> n >> h >> w;
  
  cout << (n - h + 1) * (n-w+1) << endl;

  return 0;
}


Measured memory_bytes: 3580
import sys 
input = sys.stdin.readline
mod = 10**9 + 7
h, w = [int(x) for x in input().split()]
g = [list(input().rstrip()) for _ in range(h)]

dp = [[0]*w for _ in range(h)]

dp[0][0] = 1

for i in range(h):
    for j in range(w):
        if g[i][j] == "#":
            continue
        xy = [(i - 1, j), (i, j - 1)]
        for k in xy:
            x, y = k
            if 0 <= x < h and 0 <= y < w:
                dp[i][j] += dp[x][y]
                dp[i][j] %= mod

print(dp[-1][-1])

Measured memory_bytes: 89948
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 305, mod = 1e9 + 7;
const int inf = 1e9;

void solve(int p){
    ll n;
    cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
        return;
    }
    cout << 1000 - n % 1000 << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve(p);
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 

struct edge {int to, cost;};
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;} return false;}
// dijjkstra(グラフ、始点)
VI dijkstra(vector<vector<edge>> &G, int s){   
    int V = G.size();
    VI d(V, INF); // d[i] = 頂点 s から i への最短距離
    d[s] = 0;
    // 最悪計算量 O(ElogV) ．0≤E≤O(V²)。全て正の距離の場合．
    priority_queue<PII, VP, greater<PII>> q; //firstは最短距離，secondは頂点番号
    q.emplace(0, s);
    while(!q.empty()){
        PII p = q.top(); q.pop();
        int v = p.second;
        if (d[v] < p.first) continue; 
        for (edge e: G[v])
            if (chmin(d[e.to], d[v] + e.cost))
                q.emplace(d[e.to], e.to);
    }
    return d;
}

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

int n, m, s, t; cin >> n >> m >> s >> t;
vector<vector<edge>> Gy(n+1), Gs(n+1); // yen と suuke それぞれで最短経路求める。
rep(i, 0, m){
    int u, v, a, b; cin >> u >> v >> a >> b;
    Gy[u].push_back(edge{v, a});
    Gy[v].push_back(edge{u, a});
    Gs[u].push_back(edge{v, b});
    Gs[v].push_back(edge{u, b});
}
VI dy = dijkstra(Gy, s), ds = dijkstra(Gs, t); 

rep(i, 1, n+1) ds[i] += dy[i];
VI minid = ds; 
Rrep(i, n-1, 1) minid[i] = min(ds[i], minid[i+1]);
i64 snu = 1e15;
rep(i, 1, n+1){
    cout << snu - minid[i] << "\n";
}


return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 16120
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n;
	for (ll h = 0; cin >> n; ++h) {
		if (h != 0)cout << endl;
		ll dg[5] = { n / 10000, n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10 };
		REP(i, 5)cout << (dg[i] / 5 == 0 ? '*' : ' ');
		cout << endl;
		REP(i, 5)cout << (dg[i] / 5 == 1 ? '*' : ' ');
		cout << endl;
		cout << "=====";
		cout << endl;
		REP(i, 5) {
			REP(j, 5)cout << (dg[j] % 5 == i ? ' ' : '*');
			cout << endl;
		}
	}
}


Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll n, m;
    cin >> n >> m;
    ll ret = min(n, m / 2);
    m -= ret * 2;
    ret += m / 4;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	long long T;
	cin>>N>>T;
	vector<long long> A(N,0);
	int i;
	for (i=0;i<N;i++){
		cin>>A[i];
	}
	vector<long long> MinI(N,0);
	MinI[0]=A[0];
	for (i=1;i<N;i++){
		MinI[i]=min(MinI[i-1],A[i-1]);
	}
	vector<long long> d(N,0);
	for (i=0;i<N;i++){
		if (A[i]>MinI[i]){
			d[i]=A[i]-MinI[i];
		}
	}
	sort(d.begin(),d.end(),greater<long long>());
	long long x=d[0];	
	int aw=1;
	for (i=1;i<N-1;i++){
		if (x==d[i]){
			aw++;
		}
	}
	cout<<aw<<endl;
	return 0;
}

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


typedef long long int ll;


int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n,M;
	cin>>n>>M;
	vector < pair <ll,ll> > vec;
		
	priority_queue < pair <ll,ll> > pq;
	for(ll i=0;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;
		vec.push_back({a,b});
	}
	sort(vec.begin(),vec.end());
	//j = n-1;
	ll ans = 0;
	ll j = 0;	
	for(ll i=M-1;i>=0;i--)
	{
		
		while(j<n and vec[j].first+i<=M)
		{	
			pq.push({vec[j].second,vec[j].first});
			j++;
			//cout<<i<<" "<<j<<endl;
		}
		if(pq.size()!=0){
			ans += pq.top().first;
			pq.pop();
		}

	}
		
	cout<<ans<<endl;
	
	
}


Measured memory_bytes: 4848
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

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

  int m = toInt(s.substr(5,2));


  if((m > 4)){
    cout << "TBD" << endl;
  }else cout << "Heisei" << endl;
  return 0;
}


Measured memory_bytes: 256
type info = {b : int;
             f : int;
             r : int;
             v : int} ;;
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d %d %d %d\n" (fun x y z w -> {b = x; f = y; r = z; v = w})) in
  for i = 1 to 4 do             (* 棟 *)
    for j = 1 to 3 do           (* 階 *)
      for k = 1 to 10 do         (* 番号 *)
        let f res =
          for m = 0 to (n-1) do
            if (as_.(m)).b = i && (as_.(m)).f = j && (as_.(m)).r = k then
              begin res := !res + (as_.(m)).v end
          done;
          if !res <> 0 then begin  Printf.printf " %d" !res end
          else Printf.printf " %d" 0
        in
        f (ref 0)
      done ;
      print_newline ()
    done;
    if i < 4 then begin print_endline "####################" end
  done;;



Measured memory_bytes: 2628
a = input()
b = input()

al = len(a)
bl = len(b)

if al>bl:
    print('GREATER')
elif al<bl:
    print('LESS')
else:
    i = 0
    check = 0
    for i in range(al):
        if a[i] == b[i]:
            pass
        else:
            check += int(a[i]) - int(b[i])
            break

    if check > 0:
        print('GREATER')
    elif check < 0:
        print('LESS')
    else:
        print('EQUAL')


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int n,a,b,ans;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
main(){
    cin>>n>>a;
    ans=a;
    for(int i=1;i<n;i++){
        cin>>b;
        ans=gcd(ans,b);
    }
    cout<<ans<<endl;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

 
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
#include<stdio.h>
int main(){
  int n,i,j,ans=0,sum=0;
  scanf("%d\n",&n);
  for(i=1;i<=n;i=i+2){
    for(j=1;j<=n;j++){
      if(i%j==0){
        sum++;
      }
    }
    if(sum==8){
      ans++;
    }
    sum=0;
  }
  printf("%d\n",ans);
  return 0;
}

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

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int n, xx;
	cin >> n >> xx;
	long long x[n];
	cin >> x[0];
	long long ans = abs(x[0] - xx);
	for (int i = 1;i < n;i++) {
		cin >> x[i];
		ans = GCD(ans, abs(x[i] - xx));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
w = list(map(int, input().split()))

s1, s2 = 0, sum(w)
ans = abs(s2 - s1)
for i in range(n):
    s1 += w[i]
    s2 -= w[i]
    ans = min(ans, abs(s2 - s1))
print(ans)
    


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
  
  int n, i, j, c=0;
  int A[10000];

  scanf("%d",&n);
  if( n<1 || 100000<n ) exit(1);

  for( i=0 ; i<n ; i++ ){
    scanf("%d",&A[i]);
    if( A[i]<2 || 100000000<A[i] ) exit(2);
  }

  for( i=0 ; i<n ; i++ ){
    if( A[i] == 2 ){
      c++;
      continue;
    }
    if( A[i]%2 == 0 ) continue;

    for( j=3 ; j<=sqrt(A[i]) ; j+=2 ){
      if( A[i]%j == 0 ){
	break;
      }
    }
    if( j>sqrt(A[i]) ) c++;
  }

  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
	

ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	int n, m; cin >> n;
	map<ll, int> flag;
	rep(i, n) { cin >> a; flag[a]++; }
  cin>>m;
	rep(i, m) {
		cin >> b;
		if (flag[b] == 0) { cout << "NO" << endl; return 0; }
		else flag[b]--;
	}
	cout << "YES" << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)
#define sz(x) int(x.size())

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  ll left = 4 * a * b;
  ll right = (c - a - b) * (c - a - b);
  if (a + b > c)
  {
    cout << "No" << endl;
    return 0;
  }
  if (left < right)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// bool visited[100001];
//vector<int> v(n,-1);
vector<int> dp(100001,-1);
vector<int> v[100001];
int  dfs(int s){
        if(dp[s]!=-1) return dp[s];
        dp[s]=0;
        for(int i=0;i<v[s].size();++i){
             dp[s]=max(dp[s],1+dfs(v[s][i]));
        }
        return dp[s];
    }
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
  }
  int ans=INT_MIN;
  // memset(visited,false,sizeof(visited));
  for(int i=1;i<=n;i++){
          ans=max(ans,dfs(i));
        }
  cout<<ans<<endl;
  // for(int i=topo.size()-1;i>=0;i--) cout<<topo[i]<<" ";
  return 0;
}

Measured memory_bytes: 8192
import math

a,b = list(map(int,input().split()))

res1 = math.floor(a / 0.08)

while True:
    if math.floor(res1 * 0.08) != a:
        res1 += 1
    else:
        break

while True:

    if math.floor(res1 * 0.1) == b and math.floor(res1 * 0.08) == a:
        print(res1)
        break
    elif math.floor(res1 * 0.1) > b or math.floor(res1 * 0.08) > a:
        print(-1)
        break    
    else:
        res1 += 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
typedef long long ll;
int a[N];
int main()
{
  ll n,x,mi=INT_MAX,cnt=0,s=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>x;
    if(x<0) cnt++,s-=x;
    else s+=x;
    mi=min(mi,abs(x));
  }
  if(cnt&1) cout<<s-2*abs(mi)<<endl;
  else cout<<s<<endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    if(n%2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    for (int i=0; i<n/2; i++)
    {
        if(s[i] != s[i+n/2])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

//int cut_vertical(const int);

int H, W, K;
//cin >> H >> W >> K;
vector<string> chocolate;
/*
for (int i = 0; i < H; i++) {
  cin >> chocolate[i];
}
*/

int main() {
  //int h, w, k;
  cin >> H >> W >> K;
  //H = h; W = w; K = k;
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    chocolate.push_back(s);
  }

  int ret = 10000;
  vector<int>whites(10, 0);
  int cuts;
  for (int tmp = 0; tmp < (1 << (H-1)); tmp++) {
    cuts = 0;
    bitset<9>b = tmp;
    cuts += b.count();
    //cout << "cuts: " << cuts << endl;
    for (int i = 0; i < whites.size(); i++) {
      whites[i] = 0;
    }
    int before_x = -1;
    for (int x = 0; x < W; x++) {
      int v_i = 0;
      //whites[v_i] += (int) ((char)chocolate[0][x] - '0');
      for (int y = 0; y < H; y++) {
        if ((y != 0) && (tmp >> y-1) & 1) { //tmpのy-1桁目が1(cut)
          v_i++;
        }
        whites[v_i] += (int) ((char)chocolate[y][x] - '0');
        if (whites[v_i] > K) {
          cuts++;
          //cout << "x: " << x << endl;
          if (before_x == x) {
            cuts = 10000;
            x = W;
            break;
          }
          before_x = x;
          x--;
          //init_v();
          for (int i = 0; i < whites.size(); i++) {
            whites[i] = 0;
          }
          break;
        }
      }
    }
    //cout << "cuts: " << cuts << endl;
    ret = min(ret, cuts);
  }

  cout << ret << endl;
}


Measured memory_bytes: 256
<?php
function binarize($decimal) {
    if ($decimal == 0)
        return "0";

    $binary = "";
    while($decimal != 0) {
        if ($decimal%2 == 0)
            $binary = "0" . $binary;
        else
            $binary = "1" . $binary;
        $decimal = floor($decimal/2);
    }

    return $binary;
}

$L = binarize(intval(fgets(STDIN)));
$M = strlen($L);
$ones = count(explode("1", $L)) - 1;
printf("%d %d\n", $M, 2*($M-1) + $ones - 1);
for($i = 1; $i < $M; $i++) {
    printf("%d %d %d\n", $i, $i+1, 0);
    printf("%d %d %d\n", $i, $i+1, 2**($M-$i-1));
}

$a = 0;
for($i = 1; $i < $M; $i++) {
    if ($L[$M-$i] == "1") {
        printf("%d %d %d\n", 1, $M-$i+1, 2**($M-1) + $a);
        $a += 2**($i-1);
    }
}
?>


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

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

void solve(ll H, ll W, vector<vector<ll>> a){
    int N = 0;
    vector<vector<ll>> P;
    rep(i, H) {
        rep(j, W) {
            bool inv = i % 2 == 1 ? true : false;
            int k = inv ? W - j - 1 : j;
            if (i == H-1 and j == W-1) break;
            if (a[i][k] % 2 == 1) {
                N++;
                vector<ll> v;
                if (inv) {
                    if (k > 0) {
                        v = {i, k, i, k-1};
                        a[i][k-1] += 1;
                    } else {
                        v = {i, k, i+1, k};
                        a[i+1][k] += 1;
                    }
                    P.push_back(v);
                } else {
                    if (k < W-1) {
                        v = {i, k, i, k+1};
                        a[i][k+1] += 1;
                    } else {
                        v = {i, k, i+1, k};
                        a[i+1][k] += 1;
                    }
                    P.push_back(v);
                }
            }
        }
    }
    cout << N << endl;
    rep(i, P.size()) {
        rep(j, 4) {
            cout << P[i][j] + 1;
            if (j < 3) cout << " ";
        }
        cout << endl;
    }
}

int main() {
  ll H;
    scanf("%lld",&H);
    ll W;
    scanf("%lld",&W);
    vector<vector<ll>> a(H, vector<ll>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&a[i][j]);
        }
    }
  solve(H, W, move(a));
  return 0;
}


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

#define mat vector<vector<ll> >

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

mat mat_mul(mat a, mat b, ll mod) {
    int m = a.size();
    int n = b[0].size();
    int o = b.size();
    mat c(m, vector<ll>(n, 0));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < o; k++) {
                c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
            }
        }
    }
    return c;
}

mat mat_exp(mat m, ll k, ll mod) {
    int n = m.size();
    if (k == 0) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j)
                    m[i][j] = 1;
                else
                    m[i][j] = 0;
            }
        }
        return m;
    } else if (k == 1) {
        return m;
    } else if (k & 1LL) {
        mat ms = mat_mul(m, m, mod);
        ms = mat_exp(ms, (k ^ 1LL) >> 1, mod);
        return mat_mul(m, ms, mod);
    } else {
        m = mat_mul(m, m, mod);
        return mat_exp(m, k >> 1, mod);
    }
}

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

    int n;
    ll k;
    cin >> n >> k;
    mat m(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> m[i][j];
        }
    }

    m = mat_exp(m, k, MOD);

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            // cout << m[i][j] << " ";
            ans = (ans + m[i][j]) % MOD;
        }
        // cout << endl;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    long double w, h, x , y; cin >> w >> h >> x >> y;

    printf("%lf %d\n", (double)w*(double)h/2.0, x*2 == w && y*2 == h);
    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;


int main(void) {
    int n,x;
    cin >> n >> x;
    
    vector<int> kids;
    
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        kids.push_back(temp);
    }
    sort(kids.begin(), kids.end());
    
    int happy_kids = 0;
    for (int j = 0; j < n && x > 0; j++) {
        if (j == n - 1) {
            if (kids.at(j) == x) {
                happy_kids++;
                break;
            }
            else{
                break;
            }
        }
        if (x - kids.at(j) >= 0) {
            x -= kids.at(j);
            happy_kids++;
        }else{
            break;
        }
    }
    
    cout << happy_kids << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

int main(){
	int n, k;
	int price[1020];
	scanf("%d%d", &n, &k);
	for(int i=0; i<n; i++){
		scanf("%d", &price[i]);
	}
	qsort(price, n, sizeof(int), compare_int);
	int ans=0;
	for(int i=0; i<k; i++){
		//printf("%d\n", price[i]);
		ans += price[i];
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 1748
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	min := math.MaxInt32
	for i := 1; i <= 100; i++ {
		sum := 0
		for _, x := range xs {
			sum += (x - i) * (x - i)
		}
		if sum < min {
			min = sum
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int A=0;
  int B=0;
  int C=0;
  int X=0;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&X);

  int ia,ib,ic,total;
  int cnt=0;
  for(ia=0;ia<=A;ia++){
    for(ib=0;ib<=B;ib++){
      for(ic=0;ic<=C;ic++){
        total=500*ia+100*ib+50*ic;
        if(total==X){
          cnt++;
        }
      }
    }
  }
  printf("%d",cnt);
  return 0;
}


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

struct edge { long long to, cap, rev;};

void add_edge(long long from, long long to, long long cap, vector<edge> G[]){
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size()-1});
}

long long dfs_flow(long long v, long long t, long long f, vector<bool> &used, vector<edge> G[]){
    if(v==t) return f;
    used[v] = true;
    for(long long i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            long long d = dfs_flow(e.to, t, min(f, e.cap), used, G);
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

long long max_flow(long long N, long long s, long long t, vector<edge> G[]){
    long long flow = 0;
    const long long INF = 1e18;
    vector<bool> used(N);
    while(true){
        fill(used.begin(), used.end(), false);
        long long f = dfs_flow(s, t, INF, used, G);
        if(f==0) return flow;
        flow += f;
    }
}

int main(){
    long long i, j, k;
    long long N;
    cin >> N;
    vector<long long> A(N+1);
    for(i=1; i<=N; i++) cin >> A[i];
    vector<edge> edges[102];
    long long S = 0, T = N+1;
    long long pos = 0;
    for(i=1; i<=N; i++){
        if(A[i] > 0){
            pos += A[i];
            add_edge(i, T, A[i], edges);
        }else{
            add_edge(S, i, -A[i], edges);
        }
        for(j=1; j<=N; j++){
            if(i*j > N) break;
            add_edge(i, i*j, 1LL<<60, edges);
        }
    }

    cout << pos - max_flow(N+2, S, T, edges) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long a,b=1,t,q=1e18;
    double d=1;
    cin>>t;
    while(t--)
    {
        cin>>a;
        d*=a;
        b*=a;
    }
    if(d>q||b>q)
        cout<<"-1"<<endl;
    else
        cout<<(long long)b<<endl;
}


Measured memory_bytes: 3192