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

int N, A, B, C;
vector<int> L;

int dfs(int i, int a, int b, int c) {
  if (i == N) {
    if (a == 0 || b == 0 || c == 0) return 1e9;
    return abs(A - a) + abs(B - b) + abs(C - c);
  }
  int ans = 1e9;
  ans = min(ans, dfs(i + 1, a + L.at(i), b, c) + (a > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b + L.at(i), c) + (b > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b, c + L.at(i)) + (c > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b, c));
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> N >> A >> B >> C;
  L.resize(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);

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

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

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

  if (S.at(2) == S.at(3) && S.at(4) == S.at(5))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
    top = top - 1;
	return S[top + 1];
}


int main () {
	int a, b;
	top = 0;
	char s[100];
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else
			push(atoi(s));
	}
	printf("%d\n", pop());
	return 0;
}



Measured memory_bytes: 2752
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int operationNum = scan.nextInt();
		BinarySearchTree tree = new BinarySearchTree();
		scan.nextLine();
		for(int i=0; i<operationNum; i++)
			tree.operation(scan);
		// ArrayList<BinarySearchTreeNode> list = 
		//  tree.inOrderConnect(new ArrayList<BinarySearchTreeNode>());

	}

}
class BinarySearchTree{
	private BinarySearchTreeNode root=null;
	public BinarySearchTree(){
		//root = new BinarySearchTreeNode();
	}
	public void operation(Scanner sc){
		if(sc.next().equals("print"))
			print();
		else{
			insert(Integer.parseInt(sc.next()));		
		}

	}
	public void insert(int key){
		if(root==null)
			root = new BinarySearchTreeNode(key);
		else
			root.insertNode(key);
	}
	public void print(){
		ArrayList<BinarySearchTreeNode> list = new ArrayList<BinarySearchTreeNode>();
		keyOrderToString(this.root.inOrderConnect(list));
		list.clear();
		keyOrderToString(this.root.preOrderConnect(list));
	}
	private static void keyOrderToString(ArrayList<BinarySearchTreeNode> list){
		for(Iterator<BinarySearchTreeNode> iter = list.iterator(); iter.hasNext();)
			System.out.print( new StringBuilder().append(" ").append(iter.next().getKey()));
		System.out.println("");	
	}

}



class BinarySearchTreeNode{
	protected int key;
	protected BinarySearchTreeNode parent = null;
	protected BinarySearchTreeNode LeftChild = null;
	protected BinarySearchTreeNode RightChild = null;
	public BinarySearchTreeNode(int key){
		this.key = key;
	}
	public BinarySearchTreeNode(int key, BinarySearchTreeNode parent){
		this.key = key;
		this.parent = parent;
	}
	void insertNode(int key){
		if(key < this.key){
			if(this.LeftChild ==null)
				this.LeftChild = new BinarySearchTreeNode(key, this);
			else
				this.LeftChild.insertNode(key);
			return;
		}else{
			if(this.RightChild ==null)
				this.RightChild = new BinarySearchTreeNode(key, this);
			else
				this.RightChild.insertNode(key);
			return;
		}
	}
	public ArrayList<BinarySearchTreeNode> preOrderConnect(ArrayList<BinarySearchTreeNode> list){
		list.add(this);
		if(LeftChild!=null)
			LeftChild.preOrderConnect(list);
		if(RightChild!=null)
			RightChild.preOrderConnect(list);
		return list;
	}
	public ArrayList<BinarySearchTreeNode> inOrderConnect(ArrayList<BinarySearchTreeNode> list){
		if(LeftChild!=null)
			LeftChild.inOrderConnect(list);
		list.add(this);
		if(RightChild!=null)
			RightChild.inOrderConnect(list);
		return list;
	}	
	public int getKey(){
		return this.key;
	}

}

Measured memory_bytes: 197324
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int a1 = Integer.parseInt(tokens[0]);
		int a2 = Integer.parseInt(tokens[1]);
		int a3 = Integer.parseInt(tokens[2]);
		List<Integer> result = calcAllCost(a1, a2, a3);
		System.out.println(result.get(0));
		in.close();
	}

	private static List<Integer> calcAllCost(int a1, int a2, int a3) {
		List<Integer> result = new ArrayList<>();
		// a1->a2->a3
		result.add(Math.abs(a2 - a1) + Math.abs(a3 - a2));
		// a1->a3->a2
		result.add(Math.abs(a3 - a1) + Math.abs(a2 - a3));
		// a2->a1->a3
		result.add(Math.abs(a1 - a2) + Math.abs(a3 - a1));
		// a2->a3->a1
		result.add(Math.abs(a3 - a2) + Math.abs(a1 - a3));
		// a3->a1->a2
		result.add(Math.abs(a1 - a3) + Math.abs(a2 - a1));
		// a3->a2->a1
		result.add(Math.abs(a2 - a3) + Math.abs(a1 - a2));
		Collections.sort(result);
		return result;
	}

}

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

typedef long long ll;

const ll INF = (ll)9e18;
int A, B, Q;
vector<ll> S, T;

void input_init(void) {
	cin >> A >> B >> Q;
	S.resize(A + 1);
	S[0] = (ll)0;
	for (int i = 1; i <= A; ++i)
		cin >> S[i];
	S.push_back(INF);
	T.resize(B + 1);
	T[0] = (ll)0;
	for (int i = 1; i <= B; ++i)
		cin >> T[i];
	T.push_back(INF);
}

ll solve(ll x) {
	vector<ll>::iterator s_itr = upper_bound(S.begin(), S.end(), x);
	ll sr = *s_itr;
	ll sl = *(--s_itr);
	vector<ll>::iterator t_itr = upper_bound(T.begin(), T.end(), x);
	ll tr = *t_itr;
	ll tl = *(--t_itr);

	ll dr = INF;
	if (sr != INF && tr != INF)
		dr = max(sr, tr) - x;
	ll dl = INF;
	if (sl != 0 && tl != 0)
		dl = x - min(sl, tl);
	ll dsrtl = INF;
	if (sr != INF && tl != 0)
		dsrtl = (sr - tl) + min(sr - x, x - tl);
	ll dtrsl = INF;
	if (tr != INF && sl != 0)
		dtrsl = (tr - sl) + min(tr - x, x - sl);

	ll res = dr;
	res = min(dl, res);
	res = min(dsrtl, res);
	res = min(dtrsl, res);
	return res;
}

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

	input_init();
	for (int i = 0; i < Q; ++i) {
		ll x;
		cin >> x;
		ll ans = solve(x);
		cout << ans << '\n';
	}

	return 0;
}


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

  #define rep(i, n) for (int i = 0; i < int(n); i++)
  #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
  #define reps(i, n) for (int i = 1; i <= int(n); i++)
  #define rreps(i, n) for (int i = int(n); i >= 1; i--)
  #define repc(i, n) for (int i = 0; i <= int(n); i++)
  #define rrepc(i, n) for (int i = int(n); i >= 0; i--)
  #define repi(i, a, b) for (int i = int(a); i < int(b); i++)
  #define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
  #define all(a) (a).begin(), (a).end()
  #define bit32(x) (1 << (x))
  #define bit64(x) (1ll << (x))
  #define sz(v) ((int) v.size())

  using namespace std;

  using i64 = long long;
  using f80 = long double;
  using vi32 = vector<int>;
  using vi64 = vector<i64>;
  using vf80 = vector<f80>;
  using vstr = vector<string>;

  inline void yes() { cout << "Yes" << endl; exit(0); }
  inline void no() { cout << "No" << endl; exit(0); }
  inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
  inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
  template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
  template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
  template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
  template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
  template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
  template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
  template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
  void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

  void solve() {
    int a, p;
    cin >> a >> p;
    int sum = a * 3 + p;
    cout << sum / 2 << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/
inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int mpow(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return mpow(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, mpow(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<i64> a(n);
  for (i64 &x : a) cin >> x;
  int ans = 0;
  int pw = 1;
  for (int b = 0; b < 62; ++b) {
    int cnt = 0;
    for (auto &x : a) cnt += x >> b & 1LL;
    muls(cnt, n - cnt);
    adds(ans, mul(pw, cnt));
    muls(pw, 2);
  }
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    
    if(x1 == 0) cout << 1 << endl;
    else if(x2 == 0) cout << 2 << endl;
    else if(x3 == 0) cout << 3 << endl;
    else if(x4 == 0) cout << 4 << endl;
    else if(x5 == 0) cout << 5 << endl;
 
    return 0;
}

Measured memory_bytes: 3568
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	long long int q, s, d, h, n, A, B;
	cin >> q >> h >> s >> d >> n;
	A = min(q * 8, h * 4);A = min(A, s * 2);A = min(A, d);
	B = min(q * 4, h * 2); B = min(B, s);
	if (n % 2)cout << A*(n / 2) + B << endl;
	else cout << A*(n / 2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int count;
    for (int i=a; i<=b; ++i) {
        if (c % i == 0) {
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3116
<?php
error_reporting(0);

$N = trim(fgets(STDIN));
$A = explode(" ", trim(fgets(STDIN)));

$min = min($A);
$tmp = $A;

while (true) {
    $tmp2 = [];
    foreach ($tmp as $t) {
        if ($t % $min != 0) {
            $tmp2[] = $t % $min;
        }
    }

    $tmp2[] = $min;

    $chk = min($tmp2);

    if ($chk == $min) {
        echo $min . "\n";
        break;
    } else {
        $tmp = $tmp2;
        $min = $chk;
    }

}

Measured memory_bytes: 18932
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
using namespace std;

long long x[50];
long long y[50];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }

    map <pair <long long, long long>, int> pq_map;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                continue;
            }
            auto pq = make_pair(x[i] - x[j], y[i] - y[j]);
            if(pq_map.find(pq) != pq_map.end()){
                pq_map[pq] ++;
            } else {
                pq_map[pq] = 1;
            }
        }
    }

    int max_zero_cost = 0;
    for(auto it = pq_map.begin(); it != pq_map.end(); it++){
        int num = it->second;
        max_zero_cost = max(max_zero_cost, num);
    }
    cout << N - max_zero_cost << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
    int N,b,c,d,e,f,g,h,i,l,m,n,max,min,sum;
    int a;
    
    b = 0;
    c = 0;
    d = 0;
    e = 0;
    f = 0;
    g = 0;
    h = 0;
    l = 0;
    m = 0;
    n = 0;
    
    
    scanf( "%d\n", &N );
    
    for( i = 0; i < N; i++){
        scanf( "%d", &a);
        
        if( a >= 1 && a <= 399 ){
            b = 1;
        }
        else if( a >= 400 && a <= 799 ){
            c = 1;
        }
        else if( a >= 800 && a <= 1199 ){
            d = 1;
        }
        else if( a >= 1200 && a <= 1599 ){
            e = 1;
        }
        else if( a >= 1600 && a <= 1999 ){
            f = 1;
        }
        else if( a >= 2000 && a <= 2399 ){
            g = 1;
        }
        else if( a >= 2400 && a <= 2799 ){
            h = 1;
        }
        else if( a >= 2800 && a <= 3199 ){
            l = 1;
        }
        else{
            n++;
        }
    }
    
    sum = b + c + d + e + f + g + h + l;

    max = sum + n;
    
    if( sum == 0 && n > 0 ) min = 1;
    else min = sum;
    
    printf( "%d %d\n",min,max );

  return 0;
}

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

struct UnionFind{
    vector<int> r;

    UnionFind(int N){
        r = vector<int>(N, -1);
    }

    int root(int x){
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x,int y){
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if(r[x] > r[y]) swap(x,y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x){
        return -r[root(x)];
    }


};

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

    UnionFind UF(N);

    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        A -= 1;
        B -= 1;
        UF.unite(A,B);
    }

    int ans = 0;

    for(int i=0; i < N; i++){
        if(UF.size(i) >= ans){
            ans = UF.size(i);
        }
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4048
S = list(input())
T = list(input())
s = len(S)
t = len(T)

check =1
ans = -1
if t > s:
    check = -1


else:
    for i in range(s-t+1):
        c = 1
        for j in range(t):
            if S[i+j] == '?':
                pass
            elif S[i+j] == T[j]:
                pass
            else:
                c = -1
        if c == 1:
            ans = i

#print(ans)

if check == 1:
    if ans != -1:
        S = S[:ans] + T + S[ans+t:]
        #print(S)
        for i in range(s):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
string N;
  cin>>N;
  if((N[0]==N[1] && N[1]==N[2]) ||(N[1]==N[2] && N[2]==N[3]))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
def main():
    N, *A = map(int, open(0).read().split())

    A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

    dp = [[0] * r for r in reversed(range(1, N + 2))]
    for l in range(N):
        for r in range(N - l):
            p, a = A[l + r]

            dp[l + 1][r] = max(
                dp[l + 1][r],
                a * (p - l) + dp[l][r]
            )
            dp[l][r + 1] = max(
                dp[l][r + 1],
                a * (N - 1 - r - p) + dp[l][r]
            )

    print(max(dp[l][N - l] for l in range(N)))

main()

Measured memory_bytes: 108836
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};
ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
typedef vector<set<Edge>> Graph;
signed main(void) {
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	ll dp[2][93100] = {}, dp2[2][93100] = {};

	dp2[0][0] = 1;
	dp[0][0] = 1;

	REP(i, n) {
		int turn = i % 2;
		Fill(dp[1 - turn], 0);
		Fill(dp2[1 - turn], 0);
		REP(j,sum + 1) {
			dp[1-turn][j + a[i]] += dp[turn][j];
			dp[1-turn][j] += dp[turn][j] * 2;
			dp[1-turn][j + a[i]] %= MODU;
			dp[1-turn][j] %= MODU;

			dp2[1-turn][j + a[i]] += dp2[turn][j];
			dp2[1-turn][j] += dp2[turn][j];
			dp2[1-turn][j + a[i]] %= MODU;
			dp2[1-turn][j] %= MODU;
		}
	}

	ll ans = mod_pow(3, n, MODU);

	rep(i, (1 + sum) / 2, 90001) {
		ans -= dp[n%2][i] * 3;
		ans %= MODU;
	}
	if(sum % 2 == 0)
		ans += dp2[n%2][sum/2] * 3;
	ans %= MODU;

	cout << (ans + MODU) % MODU << endl;
	return 0;
}

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

//const int MAX_LEN = 200002;

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

int ans = a + a*a + a*a*a;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	string S;
	ll di[40]={1};
	for(int i=1;i<40;i++)
		di[i]=di[i-1]*-2;
	ll bo[40]={1},to[40]={1};
	ll le[40]={0},ri[40]={1};
	for(int i=1;i<40;i++){
		bo[i]+=le[i-1]+di[i];
		to[i]+=ri[i-1]+di[i];
		le[i]=min(bo[i],le[i-1]);
		ri[i]=max(to[i],ri[i-1]);
	}
	for(int i=39;i>0;i--){
		if(bo[i]<=N && N<=to[i]){
			S+="1";
			N-=di[i];
		}
		else
			S+="0";
	}
	S+='0'+N%2;
	bool flag=0;
	for(int i=0;i<S.length();i++){
		if(S[i]=='1')
			flag=1;
		if(flag || i==S.length()-1)
			cout<<S[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int h, w, num;
int field[100][100];

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
int dx2[] = { 2, 0, -2, 0 };
int dy2[] = { 0, 2, 0, -2 };

void solve(){
	field[0][0] = 1;

	queue<P> que;
	que.push(P(0, 0));

	while (que.size()){
		P p = que.front(); que.pop();

		int y = p.first, x = p.second;

		for (int i = 0; i < 4; i++){
			int ny = y + dy2[i], nx = x + dx2[i], cy = y + dy[i], cx = x + dx[i];
			if (ny >= 0 && ny < h * 2 - 1 && nx >= 0 && nx < w * 2 - 1){
				if (field[cy][cx] != -1 && field[ny][nx] == INF){
					field[ny][nx] = field[y][x] + 1;
					que.push(P(ny, nx));
				}
			}
		}
	}

}

int main(){
	while (cin >> w >> h&&h + w){
		REP(i, 100)REP(j, 100)field[i][j] = INF;
		REP(i, 2 * h - 1){
			if (i % 2 == 0){
				REP(j, w - 1){
					cin >> num;
					if (num == 1)field[i][j * 2 + 1] = -1;
					else field[i][j * 2 + 1] = 0;
				}
			}
			else{
				REP(j, w){
					cin >> num;
					if (num == 1)field[i][j * 2] = -1;
					else field[i][j * 2] = 0;
				}
			}
		}
		solve();
		if (field[2 * h - 1 - 1][2 * w - 1 - 1] == INF)cout << 0 << endl;
		else cout << field[2 * h - 1 - 1][2 * w - 1 - 1] << endl;
	}
}

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

int main() {
  char c;
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      cin >> c;
      if (i==j) {cout << c;}
    }
  }
  cout << endl;
}


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

using namespace std;

#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int dp[100005];

int main(void) {
  int n,m; cin >> n >> m;
  set<int> as; REP(i, m) { int k; cin >> k; as.insert(k); }

  dp[0] = 1;
  int mod = INF+7;

  FOR(i, 1, n+1) {
    if (EXIST(as, i)) continue;
    if (!EXIST(as, i-1)) dp[i] += dp[i-1];
    if (i >=2 && !EXIST(as, i-2)) dp[i] += dp[i-2];
    dp[i] = dp[i] % mod;
  }
  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 4992
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

@njit((i8, ), cache=True)
def precompute(M):
    # 残り M 秒あるとする。
    # dp1：人数
    # dp2：生産開始時刻の総和
    g = M + 10
    dp1 = np.ones(M, np.int64)
    dp2 = np.zeros(M, np.int64)
    while g * (g - 1) // 2 > M:
        g -= 1
    while g >= 1:
        newdp1 = np.ones_like(dp1)
        newdp2 = np.zeros_like(dp2)
        for m in range(2 * g, M):
            newdp1[m] = (newdp1[m - g] + dp1[m - g]) % MOD
            newdp2[m] = (newdp2[m - g] + dp2[m - g] + g * newdp1[m]) % MOD
        g -= 1
        dp1, dp2 = newdp1, newdp2
    return dp1, dp2

@njit((i8[:], ), cache=True)
def main(NC):
    dp1, dp2 = precompute(100_010)
    N, C = NC[::2], NC[1::2]
    for i in range(len(N)):
        n, c = N[i], C[i]
        q, r = divmod(n, c)
        ans = dp1[q] * n - dp2[q] * c
        print(ans % MOD)

NC = np.array(read().split(), np.int64)[1:]

main(NC)

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


#define	ll_int	long long int


ll_int **STACK, *S_STACK;
int *SP;	// スタックポインタを別の配列で管理する


// スタックの初期化
// スタックポインタを0とすることで空という具合にする
void  Init(int n)
{
	int i;

	for(i = 0; i < n; i++)
		SP[i] = 0;
}


void Push(int t, int x)
{
	STACK[t][SP[t]++] = x;
}


void Top(int t)
{
	if(SP[t] - 1 >= 0)
		printf("%lld\n", STACK[t][SP[t] - 1]);
}


void Pop(int t)
{
	if(SP[t] - 1 >= 0)
		SP[t]--;
}


int main()
{
	int n, q;
	int size;
	int query, t;
	ll_int x;
	int i;

	scanf("%d %d", &n, &q);

	if(q > n)
		size = q;
	else
		size = n;

	S_STACK = (ll_int *)malloc(sizeof(ll_int) * n * size);
	STACK = (ll_int **)malloc(sizeof(ll_int *) * n);
	for(i = 0; i < n; i++)
		STACK[i] = S_STACK + (i * size);
	SP = (int *)malloc(sizeof(int) * n);

	Init(n);

	for(i = 0; i < q; i++){
		scanf("%d", &query);

		if(query == 0){
			scanf("%d %lld", &t, &x);
			Push(t, x);
		}else if(query == 1){
			scanf("%d", &t);
			Top(t);
		}else if(query == 2){
			scanf("%d", &t);
			Pop(t);
		}
	}

	return 0;
}

/*
push(t, x): Stに整数xを挿入する。
top(t): Stから次に取り出される要素を報告する。ただし、Stが空の場合は何もしない。
pop(t): Stから要素を取り出し削除する。ただし、Stが空の場合は何もしない。
*/


Measured memory_bytes: 6256
#include<iostream>
using namespace std;
int main(){
  string ss;
  cin >> ss;
  int len = ss.length();
  int mid = len/2;
  for(int i=0; i<mid; i++){
  	if (ss[i]!=ss[len-1-i]){
  		cout << "No" << endl;
  		return 0;
  	}
  }
  cout << "Yes" << endl;
}


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

int main() {
	string a,b,c;
  	cin>>a>>b>>c;
  	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout<<"YES"<<endl;
  	else cout<<"NO"<<endl;
  
}	

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


int main() {
	int N,x;
	cin >> N >> x;
	vector<int> a(N);
	for (auto &i : a)
		cin >> i;
	
  int64_t sum = 0;
  sum += max( a.at(0) - x, 0 );
  a.at(0) -= max( a.at(0) - x, 0 );
  sum += max( a.at(N-1) - x, 0 );
  a.at(N-1) -= max( a.at(N-1) - x, 0 );
	
  for (int i=1; i<N-1; i++){
    sum += max (a.at(i-1) + a.at(i) -x, 0);
    a.at(i) -= max (a.at(i-1) + a.at(i) -x, 0);      
  }
  sum += max(a.at(N-2) + a.at(N-1) - x, 0);
  a.at(N-2) -= max(a.at(N-2) + a.at(N-1) - x, 0);
  cout << sum << endl;
	
  return 0;
}

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

vector<vector<ll>> g;
vector<ll> depth;
bool flag = false;

void dfs(int pos, int dep){
  if(depth[pos] >= 0) {
      if(depth[pos] != dep) flag = true;
      return;
  }
  depth[pos] = dep;
  for(auto x:g[pos]) dfs(x,dep^1);
}

int main(){
  ll n;cin>>n;
  vector<string> s(n);
  rep(i,n) cin>>s[i];
  vector<vector<ll>> dist(n,vector<ll>(n,1<<29));
  g.resize(n);
  rep(i,n){
	rep(j,n) if(s[i][j] == '1') {
        g[i].push_back(j);
        dist[i][j] = 1;
    }
  }
  //二部グラフ判定
  depth.resize(n,0);
  rep(i,n) depth[i] = -1;
  dfs(0,0);
  if(flag){
      puts("-1");
      return 0;
  }
  //warshall_floyd法
  rep(i,n) dist[i][i]=0;
  rep(k,n)rep(i,n)rep(j,n) dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
  ll ans=0;
  rep(i,n) ans = max(ans,*max_element(dist[i].begin(),dist[i].end()));
  cout << ans + 1 << endl;
  return 0;
}
  


Measured memory_bytes: 1024
N=int(input())
A = [list(map(int, input().split())) for i in range(N)]

from collections import defaultdict
dp = defaultdict(int)
for i in range(N):
    dp[i] = [0]*3

for i,v in enumerate(A[0]):
    dp[0][i]=v
    

for i in range(1,N):
    for after in range(3):
        max_value = max([A[i][after] + dp[i-1][before] for before in range(3) if after!=before])
        dp[i][after] = max_value

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

Measured memory_bytes: 83288
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,45){
        if(_%4==0){
            rep(i,0,D){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
        else{
            per(i,D-1,0){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3756
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B
#include <iostream>
#include <queue>

using namespace std;

int main() {
    int n, l, time, sum = 0;
    string name;
    queue<pair<string, int> > q;
    
    cin >> n >> l;
    while (n--) {
        cin >> name >> time;
        q.push(make_pair(name, time));
    }
    
    while (!q.empty()) {
        if (q.front().second <= l) {
            sum += q.front().second;
            cout << q.front().first << " " << sum << endl;
            q.pop();
        } else {
            pair<string, int> temp;
            temp = q.front();
            q.pop();
            sum += l;
            q.push(make_pair(temp.first, temp.second - l));
        }
    }
}


Measured memory_bytes: 6356
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    sort(d, d + n);
    int ans;
    if(d[n/2] == d[n/2-1]) ans = 0;
    else ans = d[n/2] - d[n/2-1];
    cout << ans << endl;
}

Measured memory_bytes: 3984
class Stack():
    def __init__(self):
        self.top=0
        self.S=[None]*1000
    def isEmpty(self):
        return self.top==0
    def push(self,fig):

        if fig.isdigit():
            self.top += 1
            self.S.insert(self.top,fig)
        else:#ここで代入したものが記号なら
            before,after = self.pop(),self.pop()
            result = eval(str(after)+fig+str(before))
            self.top += 1
            self.S.insert(self.top, result)
    def pop(self):
        self.top-=1
        vari=self.S[self.top + 1]
        self.S[self.top + 1]=None
        return vari

Stck=Stack()

# math=[int(x) if x.isdigit() else x for x in input().split()]#ここに入る内容を一つずつ処理
[Stck.push(x) for x in input().split()]
print(Stck.S[1])


Measured memory_bytes: 5576
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <numeric>
#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(){
    ll a,b;
    cin >> a >> b;
    //cout << lcm(A,B) << endl;

    ll x = a * b;
    if(a<b){
        ll tmp = a;
        a = b;
        b = tmp;
    }
    /* ユークリッドの互除法 */
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    cout << x/b << endl;


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList();
			var alice = firstLine[0];
			var bob = firstLine[1];
			if(alice == bob)
			{
				Console.WriteLine("Draw");
			}
			else if(alice == 1)
			{
				Console.WriteLine("Alice");
			}
			else if(bob == 1)
			{
				Console.WriteLine("Bob");
			}
			else if(alice > bob)
			{
				Console.WriteLine("Alice");
			}
			else
			{
				Console.WriteLine("Bob");
			}
        }
	}
}


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

int main()
{
    const int mod = 1000000007;
    int n;
    cin >> n;
    long long ans = 1ll;
    for(int i = 1;i <= n;++i)
        ans = ans * i % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define MED(a,b,c) ((a)<(b)?(a)>(c)?(a):(b)<(c)?(b):(c):(a)>(c)?(b)<(c)?(c):(b):(a))
#define RANGE(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RANGE3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXI(a,b) if(a<b)a=b;
#define MINI(a,b) if(a>b)a=b;
#define BEGINFOR(a,b,c,d,e,f,g,h,i) a;goto i##_6;i##_2:c;goto i##_6;i##_3:h;goto i##_7;i##_4:d;goto i##_8;i##_5:f;goto i##_8;i##_6:if(b)goto i##_4;else goto i##_9;i##_7:if(g)goto i##_5;else goto i##_1;i##_8:if(e)goto i##_2;else goto i##_3;i##_9:
#define CONTINUE(i) goto i##_3
#define BREAK(i) goto i##_1
#define ENDFOR(i) goto i##_3;i##_1:

using ull = unsigned long long;

int main(void) {
	int h, w, c[10][10], ans = 0;
	scanf("%d%d", &h, &w);
	REP(i, 100) scanf("%d", *c + i);
	bool re = true;
	while (re) {
		re = false;
		REP(i, 10) REP(j, 10) REP(k, 10) {
			if (c[i][j] + c[j][k] < c[i][k]) {
				c[i][k] = c[i][j] + c[j][k];
				re = true;
			}
		}
	}
	REP(i, h * w) {
		int hoge;
		scanf("%d", &hoge);
		if (hoge != -1) ans += c[hoge][1];
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
    ll x;
    double n;
    cin>>x;
    n=x/3.0;
    n=n*n*n;
    cout << fixed << setprecision(10) << n;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef long long _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n,s;

ll f(ll b,ll n){
  ll r = 0;
  while(n>0){
    r += n%b;
    n /= b;
  }
  return r;
}

const ll INF = 83025252525252521ll;

int main(){
  cin>>n>>s;
  if(s==n){
    printf("%lld\n",n+1);
    return 0;
  }
  ll ans = INF;
  FOR(b,2ll,1000000ll){
    ll x = f(b,n);
    if(x==s){
      ans = b;
      break;
    }
  }
  FOR(p,1ll,1000000ll){
    ll q = s-p;
    ll b = (n-q)/p;
    if(b<2)continue;
    ll x = f(b,n);
    if(x==s){
      CHMIN(ans,b);
    }
  }
  if(ans==INF)ans=-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import queue
h,w=map(int,input().split())
a=[input() for _ in range(h)]
q=[]
dist=[[-1 for _ in range(w)]for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append([i,j])
            dist[i][j]=0
q=queue.deque(q)
d=[[1,0],[0,1],[-1,0],[0,-1]]
while q:
    y,x=q.popleft()
    for dy,dx in d:
        ny,nx=y+dy,x+dx
        if 0<=ny and ny<h and 0<=nx and nx<w and dist[ny][nx]==-1:
            dist[ny][nx]=dist[y][x]+1
            q.append([ny,nx])
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,dist[i][j])
print(ans)

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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int a = Integer.parseInt(strArr[0]);
            int b = Integer.parseInt(strArr[1]);
            int c = Integer.parseInt(strArr[2]);
            if (c >= a && b >= c) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 21076
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    int N = readln.chomp.to!int;
    int[] ary = readln.split.to!(int[]).sort().array;
    iota(ary.front, ary.back+1).map!(i =>
        ary.map!(a => (a-i)^^2).sum
    ).reduce!min.writeln;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int i = 0;
	long long x, answer;

	cin >> x;
	answer = (x / 11) * 2;

	if (0 != x%11) {
		if (x % 11 <= 6) {
			answer++;
		}
		else if (x % 11 <= 12) {
			answer += 2;
		}
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

int dp[100010];
int n,m;
vector<vector<int>>g;

int rec(int v){
    if(dp[v]!=-1)return dp[v];
    int res=0;
    for(auto nv:g[v]){
        if(res<rec(nv)+1){
            res=rec(nv)+1;
        }
    }
    return dp[v]=res;
}

int main(void){
    int x,y;
    cin>>n>>m;
    g.assign(n,vector<int>());
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--;
        y--;
        g[x].push_back(y);
    }
    for(int i=0;i<n;i++)dp[i]=-1;
    int res=0;
    for(int v=0;v<n;++v){
        if(res<rec(v)){
            res=rec(v);
        }
    }
    cout<<res<<endl;
    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)(n); i++)
#define reps(i,s,e) for(int i=s; i<(int)(e); i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (D <= T * S) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

long long int max(long long int a, long long int b){
  if (a < b)
    return b;
  else
    return a;
}

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

  if (a > k){
    cout << a - k << " " << b << endl;
  }
  else {
    cout << 0 << " " << max(0, a + b - k) << endl;
  }

  return 0;
}


Measured memory_bytes: 256