akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<ll,ll> PI;
#define EPS (1e-10L)
#define rep(i,n) for(ll i=0;i<(int)(n);++i)
#define REP(i,m,n) for(ll i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
ll dx[]={0,1,0,-1,1,1,-1,-1};
ll dy[]={1,0,-1,0,-1,1,1,-1};

int w[10];
typedef pair<double,double> PD;
typedef vector<PD> mo;
vector<pair<double, double> > memo[1<<6];
bool vis[1<<6];
double r;
int s;
mo rec(int have){
  if(vis[have]) return memo[have];
  //cout << have << endl;
  vis[have] = true;
  if(__builtin_popcount(have)==1){
    mo &ret=memo[have];
    ret.clear();
    ret.pb(PD(0,0));
    return ret;
  }

  mo &ret=memo[have];
  ret.clear();
  int sub=(have-1)&have;
  while(sub){
    mo a = rec(sub);
    mo b = rec(have^sub);
    int wa=0,wb=0;
    rep(i,s){
      if((sub>>i)&1) wa += w[i];
      if((have>>i)&1) wb += w[i];
    }
    wb -= wa;
    double la = wb*1./(wa+wb);
    double lb = wa*1./(wa+wb);
    FOR(ita,a)FOR(itb,b){
      ret.pb(mp(max(lb+itb->F,ita->S-la),
                max(la+ita->F,itb->S-lb)));
      ret.pb(mp(max(lb+itb->S,ita->S-la),
                max(la+ita->F,itb->F-lb)));
      ret.pb(mp(max(lb+itb->F,ita->F-la),
                max(la+ita->S,itb->S-lb)));
      ret.pb(mp(max(lb+itb->S,ita->F-la),
                max(la+ita->S,itb->F-lb)));
    }
    sub=(sub-1)&have;
  }
  
  FOR(it,ret) if(it->F < it->S) swap(it->F,it->S);
  sort(ALL(ret));
  ret.erase(unique(ALL(ret)),ret.end());
  return ret;
}

void solve(){
  cin >> r >> s;
  rep(i,s) cin >> w[i];
  memset(vis,0,sizeof(vis));

  vector<pair<double,double> > ans = rec((1<<s)-1);
  //cout << SZ(ans) << endl;
  double out = -1;
  FOR(it,ans)
    if(it->F+it->S<r)
      out = max(out,it->F+it->S);

  printf("%.9f\n",out);
}

int main(){
  int t;
  cin >> t;
  rep(i,t) solve();
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	const int mod = 1e9 + 7;
	int h, w; cin >> h >> w;
	vector<string> s(h); rep(i, h) cin >> s[i];
	vector<vi> dp(h, vi(w));
	dp[0][0] = 1;
	rep(i, h) rep(j, w) if(s[i][j] == '.'){
		if(i) (dp[i][j] += dp[i - 1][j]) %= mod;
		if(j) (dp[i][j] += dp[i][j - 1]) %= mod;
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define rep(n) for(int i = 0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto n:v){cout << n << "\t";}
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
using namespace std;
void solve(){
	char c;
	cin >> c;
	// cout << c;
	if(c>='a' && c<='z'){
		cout << 'a' ;
	}
	else{
		cout << 'A';
	}
	cout << endl;
	

}


int main(){
	// int t;
	// cin >> t;
	solve();
	// while(t--){
	// 	solve();
	// }

	return 0;
}

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

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

    int cnt = 0, ans = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'R') {
            cnt++;
            ans = max(ans, cnt);
        } else { cnt = 0; }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
int MOD=1000000000+7;
int INF=1e6;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

ll int a,b,c,s,k;
main(){
    cin>>a>>b>>c>>k;
    
    if(k%2){
        cout<<b-a;
    }
    else cout<<a-b;
}

Measured memory_bytes: 256
#include <iostream>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    
    int func(int n){
        int out =(n%2==0) ? (n/2) : (3*n + 1);
        return out;
    }

    int main() {
        string s; cin>>s;
        int min=10000;
        int val = 753;
        for(int i=0; i<s.size()-2;i++){
            int sub = atoi(s.substr(i,3).c_str());
            //cout<<sub<<endl;
            min = (min > abs(val -sub))?abs(val -sub):min; 
        }
        cout << min <<endl;

        return 0;
    }

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

float ans=0;
int d[8] = {128, 64, 32, 16, 8, 4, 2, 1};
float f[4] = {0.5, 0.25, 0.125, 0.0625};
int output[12];
float input;
int tmp = 0;
int main(){
	while(1){
		tmp = 0;
		for(int i=0; i < 12; i++)output[i] = 0;

		cin >> input;
		if(input < 0) break;

		for(int i=0; i < 8; i++){
			if(d[i] <= input){
				output[i] = 1;
				input -= d[i];
				tmp = 1;
			}
		}
		for(int i=0; i < 4; i++){
			if(f[i] <= input){
				output[i+8] = 1;
				input -= f[i];
				tmp = 1;
			}
		}
		if(tmp = 1 && input == 0){
			for(int i=0; i < 8; i++){
				cout << output[i];
			}
			cout << '.';
			for(int i=8; i < 12; i++){
				cout << output[i];
			}
			cout << endl;
		}
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 1224
import math
import itertools
import statistics
#n = int(input())
n, T = list(map(int, input().split()))
c = []
t = []
for i in range(n):
    x,y = [int(j) for j in input().split()]
    c.append(x)
    t.append(y)

m = 10000
for i in range(n):
    if t[i] <= T:
        if c[i] < m:
            m = c[i]

if m==10000:
    print("TLE")
else:
    print(m)



Measured memory_bytes: 5144
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC065
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Enumerable.Range(0, n).Select(i => int.Parse(Console.ReadLine())).ToArray();
            var hashSet = new HashSet<int>();

            var i = 0;
            var count = 0;
            while (true)
            {
                if (!hashSet.Add(i))
                {
                    Console.WriteLine(-1);
                    return;
                }

                i = a[i] - 1;
                count++;

                if (i == 1)
                {
                    Console.WriteLine(count);
                    return;
                }
            }
        }
    }
}


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


int main(){
  int n, u, v, m;
  cin >> n >> u >> v >> m;
  map<int, pair<int,int> > U, N;
  int t;
  if(n == 1){
    if(u > 1){
      u += 5;
    }
    if(v > 1){
      v += 5;
    }
  }
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> t;
      U[t] = make_pair(i+1,j+1);
    }
  }
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> t;
      N[t] = make_pair(i+1,j+1);
    }
  }
  
  int T[m];
  vector< vector<int> > U_(2,vector<int>(n+1,n)), N_(2,vector<int>(n+1,n));
  for(int i = 0; i < m; ++i) cin >> T[i];
  for(int i = 0; i < m; ++i){
    int k = T[i], s = U[k].first, t = U[k].second;
    if(s&&t){
      --U_[0][s];
      --U_[1][t];
      if(s == t) --U_[0][0];
      if(s + t == n+1) --U_[1][0];
      if(!U_[0][s]){
	--u;
	--U_[0][s];
      }
      if(!U_[1][t]){
	--u;
	--U_[1][t];
      }
      if(!U_[0][0]){
	--u;
	--U_[0][0];
      }
      if(!U_[1][0]){
	--u;
	--U_[1][0];
      }
    }
    s = N[k].first, t = N[k].second;
    if(s&&t){
      --N_[0][s];
      --N_[1][t];
      if(s == t) --N_[0][0];
      if(s + t == n+1) --N_[1][0];
      if(!N_[0][s]){
	--v;
	--N_[0][s];
      }
      if(!N_[1][t]){
	--v;
	--N_[1][t];
      }
      if(!N_[0][0]){
	--v;
	--N_[0][0];
      }
      if(!N_[1][0]){
	--v;
	--N_[1][0];
      }
    }
    if(u <= 0 && v <= 0){
      cout << "DRAW" << endl;
      return 0;
    }else if(u <= 0){
      cout << "USAGI" << endl;
      return 0;
    }else if(v <= 0){
      cout << "NEKO" << endl;
      return 0;
    }
  }
  cout << "DRAW" << endl;
  return 0;
}

Measured memory_bytes: 22712
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,H = map(int,S().split())
ab = [LI() for i in range(N)]

A = [(ab[i][0],1) for i in range(N)]
B = [(ab[i][1],2) for i in range(N)]

from operator import itemgetter

C = sorted(A+B,key = itemgetter(0),reverse=True)

damage = 0  # 与ダメージ
ans = 0  # 攻撃回数
for i in range(2*N):
    if C[i][1] == 1:
        ans += (H-damage+C[i][0]-1)//C[i][0]
        break
    else:
        ans += 1
        damage += C[i][0]
        if damage >= H:
            break

print(ans)

Measured memory_bytes: 75868
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    ll ans;
    if( (A+B) >= C){
        ans=B+C;
    }else{
        ans=2*B+A+1;
    }
    cout<<ans<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
string s;
cin >> s;
ll count=0;
map<char, int> map1;
for(auto i : s){
	map1[i]++;
}
for(int i=0; i<s.length(); i++){
	if(map1[s[i]]%2!=0){
		cout << "No"; 
		return 0;
	}
}

cout << "Yes";
return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   ll n,k;
   cin>>n>>k;
   
   ll r[100001];

   rep(i,100001){
      r[i]=0;
   }
   rep(i,n){
      ll a,b;
      cin>>a>>b;
      r[a]+=b;
   }
   ll ans=0;
   rep(i,100001){
      ans+=r[i];
      if(ans>=k){
         cout<<i;
         break;
      }
   }
   
   return 0;
}


Measured memory_bytes: 4388
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [-1, 0, 1]
dy = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for d_x in dx:
                for d_y in dy:
                    if 0 <= i + d_x < h and 0 <= j + d_y < w and s[i + d_x][j + d_y] != '#':
                        if s[i + d_x][j + d_y] == '.':
                            s[i + d_x][j + d_y] = 1
                        else:
                            s[i + d_x][j + d_y] += 1
                    else:
                        continue

        else:
            continue

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            s[i][j] = 0
        print(s[i][j], end='')  # 改行せずにprint
    print()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[105],b[105];
int main()
{
	int n,sum1=0,sum2=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++) 
		{
			sum1+=a[j];
		}
		for(int k=i+1;k<=n;k++)
		{
			sum2+=a[k];
		}
		b[i]=abs(sum1-sum2);
		//cout<<sum1<<" "<<sum2<<endl;	
		sum1=0;sum2=0;
	}
	sort(b+1,b+n+1);
	cout<<b[1];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long N, std::vector<long long> h){
    lint dp[N];
    lint dst;
    REP(i, N) {dp[i] = 1LL<<60;}
    dp[0] = 0LL;
    REP(i, N-1) {
        dst = i + 1;
        if(dst >= N) continue;
        dp[dst] = min(dp[dst], dp[i] + abs(h[i] - h[dst]));
        dst = i + 2;
        if(dst >= N) continue;
        dp[dst] = min(dp[dst], dp[i] + abs(h[i] - h[dst]));
    }
    cout << dp[N-1] << "\n";

}

int main(){

    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

int main() {
	int d;
	int i;
	long gross;

	while(scanf("%d", &d) != EOF) {
		gross = 0;
		for(i = d; i <= 600 - d; i += d) {
			gross += i * i * d;
		}
		printf("%ld\n", gross);
	}

	return 0;
}

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

int main() {
	string N;
	cin >> N; // 各桁のみを考えるならstringやchar*を推奨
	if (N[1] == N[2] && (N[0] == N[1] || N[1] == N[3])) cout << "Yes"; // 良い整数
	else cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

こういう各桁だけを見たい、しかも桁数が等しい整数を渡された時は、
あえて文字列型で読み込むと各桁を取り出しやすいので便利です
つまり、4つの数を渡されたことにしてしまうわけですね

後は次のことを考えます
整数が良い整数の時、次の3パターンが考えられる
1. 先頭が別の数 ex. 1118
2. 末尾が別の数 ex. 8111
3. 全て等しい数 ex. 7777
共通点は2番目と3番目は必ず等しくなることだね
そして、1番目と2番目、あるいは3番目と4番目のどちらかが等しければ3つが連続していると言えるね
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i])
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int a,b;
	cin >> a>>b;
	cout << 1 + 2 + 3 - a - b;
	return 0;
}


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

using namespace std;

#define MAX 100000
#define INF (1LL<<58)
typedef long long ll;

struct Edge {
    ll to, cost;
    Edge (ll to, ll cost) : to(to), cost(cost) {}
};

struct State {
    ll c, v, h;

    State (ll c, ll v, ll h) :
        c(c), v(v), h(h) {}

    bool operator < (const State &st) const {
        if (c != st.c) {
            return c > st.c; 
        } else {
            return h < st.h;
        }
    }       
};

int main()
{
    ll N, M, X;
    cin >> N >> M >> X;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    
    ll a, b, c;
    vector<Edge> G[MAX];
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c; a--; b--;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }

    vector<ll> dist(N, INF);
    dist[0] = 0;
    
    priority_queue<State> Q;
    Q.push(State(0, 0, X));


    ll res = INF;    
    while (!Q.empty()) {
        State s = Q.top(); Q.pop();
        ll v = s.v, h = s.h;
        
        if (v == N-1) {
            res = min(res, s.c + (H[v] - h));
            continue;
        }

        for (int i = 0; i < (int)G[v].size(); i++) {
            Edge &e = G[v][i];
            ll nh = h - e.cost;

            if (nh < 0) {
                if (h - nh > H[v]) continue;
                if (s.c + e.cost - nh < dist[e.to]) {
                    dist[e.to] = s.c + e.cost - nh;
                    Q.push(State(dist[e.to], e.to, 0));
                }                
            } else {
                if (nh > H[e.to]) {
                    if (h - (nh - H[e.to]) < 0) continue;
                    if (s.c + (nh - H[e.to]) + e.cost < dist[e.to]) {
                        dist[e.to] = s.c + (nh - H[e.to]) + e.cost;
                        Q.push(State(dist[e.to], e.to, H[e.to]));
                    } 
                } else {                    
                    if (s.c + e.cost < dist[e.to]) {
                        dist[e.to] = s.c + e.cost;
                        Q.push(State(dist[e.to], e.to, nh));
                    }
                }
            }
        }
    }
    
    cout << (res != INF ? res : -1) << endl;
    return 0;
}

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

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

    long long int H[N];
    int tower[N] = {};
    for (int i = 0; i < N; i++) {
        cin >> H[i];
        // tower[i] = 1;
    }
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        if (H[A-1] > H[B-1]) {
            // tower[A-1] = 0;
            tower[B-1] = 1;
        } else if (H[A-1] < H[B-1]) {
            // tower[B-1] = 0;
            tower[A-1] = 1;
        } 
        else if(H[A-1] ==  H[B-1]) {
            tower[A-1] = 1;
            tower[B-1] = 1;
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        
        if (!tower[i]) {
            cnt++;
        }
        
       //cnt += tower[i];
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 4920
import math
x = int(input())
check = False
check2 = False
a = x
if a % 2 == 0 and a != 2:
    a += 1
while check == False:
    b = math.floor(a/2)
    for i in range(2,b+1):
        if a % i == 0:
            check2 = True
            break
        else:
            pass
    if check2 == True:
        a += 2
        check2 = False
    else:
        check = True
        break
print(a)

Measured memory_bytes: 3060
n , m , x = gets.chomp.split(" ").map(&:to_i)
arr = []
(0..n-1).each do |i|
aa = gets.chomp.split(" ").map(&:to_i)
arr << aa
end
saisyou = []
["a","b"].repeated_permutation(n) do |randamu|
    ggg = 0
    count = 0
    countall = []
    kakuarr = Array.new(m+1).map{Array.new}
    (0..n-1).each do |e|
        if randamu[e] == "a"
            (0..m).each do |t|
            kakuarr[t] << arr[e][t]
            end
        end
    end
    (0..m).each do |ff|
        count = 0
        if kakuarr[ff] != []
       ggg = kakuarr[ff].inject(:+)
         if ggg >= x
            count += 1
         end
         countall << count
        end
    end
     countall = countall[1..m]
     if !countall .nil?
    if countall.inject(:+) == m
        fff = kakuarr[0].inject(:+)
        saisyou << fff
    end
end
end
if saisyou != []
    hhhh = saisyou.sort.shift
    puts  hhhh
else
    puts "-1"
end

Measured memory_bytes: 14584
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  string s="####################";
  int f[4][3][10];
  rep(i,0,4) rep(j,0,3) rep(k,0,10) f[i][j][k]=0;
  int n; cin>>n;
  rep(i,0,n){
    int a,b,c,d; cin>>a>>b>>c>>d;
    f[a-1][b-1][c-1]+=d;
  }
  rep(i,0,4){
    rep(j,0,3){
      rep(k,0,10){
        cout<<" "<<f[i][j][k];
      }
      co("");
    }
    if(i!=3) co(s);
  }
  return 0;
}


Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		String A = Integer.toString(a);
		String B = Integer.toString(b);

		String AtimesB = "";
		for(int i = 0; i < b; i++){
			AtimesB += A;
		}

		String BtimesA = "";
		for(int i = 0; i < a; i++){
			BtimesA += B;
		}
		String result = "";
		if(AtimesB.compareTo(BtimesA) < 0){
			result = AtimesB;
		}else{
			result = BtimesA;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

const int MAX_N = 100000;
int N, M;
int p[MAX_N], x[MAX_N], y[MAX_N];

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

void solve() {
    int answer = 0;
    UnionFind uf(N+1);
    REP(i,0,M) {
        uf.unionSet(x[i], y[i]);
    }
    REP(i,0,N) {
        if(uf.findSet(p[i], i+1)) answer++;
    }
    cout << answer << "\n";
    return;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    REP(i,0,N) cin >> p[i];
    REP(i,0,M) {
        cin >> x[i] >> y[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


string solve(){
    string res;
    string s; cin >> s;
    res += s.front();
    res += to_string(s.length()-2);
    res += s.back();
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i, 0, m) {
        int a;
        cin >> a;
        sum += a;
    }
    int ans = max(-1, n - sum);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
}
using namespace my_std;

int main()
{
	int n;
	cin>>n;
	vector<pii>v;
	rep(i,1,n) rep(j,i+1,n) if (i+j!=n+(!(n&1))) v.push_back(MP(i,j));
	printf("%d\n",(int)v.size());
	rep(i,0,(int)v.size()-1) printf("%d %d\n",v[i].fir,v[i].sec);
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<pair<int, int>> robot(N);
  rep(i, N)
  {
    int X, L;
    cin >> X >> L;
    robot[i] = make_pair(X, L);
  }
  sort(robot.begin(), robot.end());
  pair<long long, long long> pre_hani;
  pre_hani = make_pair(robot[0].first - robot[0].second, robot[0].first + robot[0].second);
  int ans = 0;
  rep(i, N - 1)
  {
    long long LX = robot[i + 1].first - robot[i + 1].second;
    long long RX = robot[i + 1].first + robot[i + 1].second;
    long long preLX = pre_hani.first;
    long long preRX = pre_hani.second;

    if (preRX <= LX)
    {
      pre_hani = make_pair(LX, RX);
    }
    else
    {
      long long L = (RX - LX) / 2;
      long long pre_L = (preRX - preLX) / 2;
      if (preRX > RX)
      {
        pre_hani = make_pair(LX, RX);
      }
      ans++;
    }
  }
  cout << N - ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;
//indexed_set s;

int n;

int main() {

    cin >> n;
    int cnt = n%1000;
    cout << (1000-cnt)%1000;
return 0;
}


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

double mnk(double a,double b,double c){
  double s = (a + b + c) / 2;
  double S = sqrt(s*(s - a)*(s - b)*(s - c)); //テ」ツδ佚」ツδュテ」ツδウテ」ツ?ョテ・ツ?ャテ・ツシツ?
  return S;
}

// A-iks(ver2)

int main(){
  double x1,y1,x2,y2,x3,y3,xp,yp;
  
  while( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp ){
    double a = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    double b = sqrt(pow(x1-x3,2) + pow(y1-y3,2));
    double c = sqrt(pow(x3-x2,2) + pow(y3-y2,2));
    double S1 = mnk(a,b,c);
    
    double x = sqrt(pow(x1-xp,2) + pow(y1-yp,2));
    double y = sqrt(pow(x2-xp,2) + pow(y2-yp,2));
    double z = sqrt(pow(x3-xp,2) + pow(y3-yp,2));
    double S2 = mnk(x,y,a) + mnk(x,z,b) + mnk(y,z,c);
    
    if ((float)S1 == (float)S2){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
    
    
  }
  return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
  if(a+b==15)
  {
      printf("+\n");
  }
else if(a*b==15)
  {
    printf("*\n");
  }
else{
    printf("x\n");
}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
	char N[5];
	cin >> N;
	if (N[0] == N[1] && N[1] == N[2]) {
		cout << "Yes" << endl;
	}
	else if (N[1] == N[2] && N[2] == N[3]) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((abs(A-B) <= D && abs(B-C) <= D)|| abs(A-C) <= D){
    cout<<"Yes"<<endl;
    return 0;
  }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; ++i)

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];
    ll ans = 0;
    
    rep(i, n) {
        Rep(j, i+1, n) {
            if (a[i] < a[j]) {
                ans += k * (k - 1) / 2;
                ans %= mod;
            } 
            if (a[i] > a[j]) {
                ans += (k + 1) * k / 2;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef vector<int> vi;

int main(){
    map<string, vi> m;
    string s; int n;
    while (cin >> s >> n){
        m[s].push_back(n);
    }
    for (auto e : m){
        sort(all(e.second));
        cout << e.first << endl;
        rep(i, e.second.size() - 1){
            cout << e.second[i] << " ";
        }
        cout << e.second.back() << endl;
    }
}

Measured memory_bytes: 1240
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    string s;
    cin >> s;

    vector<int> w(N + 1, 0);
    vector<int> b(N + 1, 0);
    rep(i, N) {
        if (s[i] == '#')
            b[i + 1] = 1;
        else
            w[i] = 1;
    }

    rep(i, N) { b[i + 1] += b[i]; }

    reverse(all(w));
    rep(i, N) { w[i + 1] += w[i]; }
    reverse(all(w));

    ll ans = INF;
    rep(i, N + 1) {
        ll tmp = b[i] + w[i];
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5140
// https://atcoder.jp/contests/abc139/tasks/abc139_e
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t, cnt = 0;
    cin >> n;
    vector<queue<int>> q(n);
    REP(i, n) REP(j, n - 1) {
        cin >> t;
        q[i].push(t - 1);
    }
    set<pii> st;
    set<int> sl;
    REP(i, n) sl.insert(i);
    while (true) {
        // 全てのキューが空なら終了
        if (sl.size() == 0) {
            break;
        }
        set<int> sk;
        bool nfound = true;
        // 前回更新したペアのみ
        for (auto i : sl) {
            pii p = {i, q[i].front()};
            if (p.first > p.second) {
                swap(p.first, p.second);
            }
            if (st.count(p) == 0) {
                st.insert(p);
            } else {
                nfound = false;
                q[p.first].pop();
                q[p.second].pop();
                if (!q[p.first].empty()) {
                    sk.insert(p.first);
                }
                if (!q[p.second].empty()) {
                    sk.insert(p.second);
                }
            }
        }
        if (nfound) {
            cnt = -1;
            break;
        }
        sl = sk;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 24576
#include <iostream>

int main(){
	
	//???????????????
	for(int i = 1; i <= 9; ++i){
		for(int j = 1; j <= 9; ++j){
			std::cout << i << "x" << j << "=" << i*j << std::endl;
		}
	}
	return 0;
}

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

#define max 20000

//qsort(d, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main()
{
    int k, n, i, ppmax=0;
    int a[200000];
    
    scanf("%d %d", &k, &n);
    for (i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    
    for (i=0; i<n-1; i++) {
        if(a[i+1]-a[i]>ppmax){
            ppmax=a[i+1]-a[i];
        }
    }
    
    if (a[0]+(k-a[n-1])>ppmax) {
        ppmax=a[0]+(k-a[n-1]);
    }
    
    printf("%d",k-ppmax);

    return 0;
}




Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int INF = 1001001001;
 
int a[12][12];
 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
 
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] V = new int[N];
            for (int i = 0; i < N; i++) {
                V[i] = in.nextInt();
            }

            long max = 0;
            int[] array = new int[100];

            int maxGet = Math.min(N, K);
            for (int get = 0; get <= maxGet; get++) {
                int put = K - get;
                for (int getL = 0; getL <= get; getL++) {
                    int getR = get - getL;

                    int size = 0;
                    for (int i = 0; i < getL; i++) {
                        array[size++] = V[i];
                    }
                    for (int i = 0; i < getR; i++) {
                        array[size++] = V[V.length - 1 - i];
                    }

                    Arrays.sort(array, 0, size);

                    long sum = 0;
                    for (int i = 0; i < size; i++) {
                        sum += array[i];
                    }
                    max = Math.max(max, sum);
                    for (int i = 0; i < put; i++) {
                        sum -= array[i];
                        max = Math.max(max, sum);
                    }
                }
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    int a,b,c,d,e,n,x,y,z;
    cin>>n>>d;
    if(n%(1+2*d)==0) cout<<n/(1+2*d);
    else cout<<n/(1+2*d)+1;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
vector<ll> fact;
vector<ll> ifact;
ll add(ll a,ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
ll mult(ll a,ll b)
{
	return (a*1LL*b)%MOD;
}
ll binpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll choose(ll a, ll b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	ll r = mult(ifact[b],ifact[a-b]);
	r = mult(r,fact[a]);
	return r;
}
ll inv(int a){return binpow(a,MOD-2);}
void init(ll n)
{
	fact.clear(); ifact.clear();
	fact.resize(n+1);
	ifact.resize(n+1);
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=n;i++){fact[i]=mult(fact[i-1],i);}
	ifact[n] = inv(fact[n]);
	for(int i=n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
}
ll rchoose(ll n,ll r){
	ll res = 1;
	for(int i=0;i<r;i++)res = mult(res,n-i);
	return res;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	init(n);
	ll red = n-k;
	for(ll i=1;i<=k;i++){
		cout<<mult(choose(red+1,i),choose(k-1,i-1))<<'\n';
	}
}


Measured memory_bytes: 3624
A,B,C,D,E,F=map(int,input().split())
A,B=A*100,B*100
water=[]
for i in range(F//A+1):
    for j in range(F//B+1):
        if A*i+B*j<=F and not(i==0 and j==0):
            water.append((A*i+B*j))
water=list(set(water))
ans=[water[0],0]
mconc=0
for x in water:
    up=min(x*E//100,F-x)
    sDP=[0]*(up+1)
    for i in range(1,up+1):
        if(i>=D):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C,sDP[i-D]+D)
        elif(i>=C):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C)
        else:
            sDP[i]=sDP[i-1]
    conc=100*sDP[-1]/(x+sDP[-1])
    if(conc>=mconc):
        mconc=conc;ans[0]=x+sDP[-1];ans[1]=sDP[-1]
print(*ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i, n, m) for(int i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = std::int_fast64_t;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-15;
template<typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, v.size()) {
        if(i) os << " ";
        os << to_string(v[i]);
    }
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> sum(n, 0);
    REP(i, n - 1) {
        int x, y, a;
        cin >> x >> y >> a;
        sum[x] ^= a;
        sum[y] ^= a;
    }
    vector<int> c(16, 0);
    REP(i, n) c[sum[i]]++;
    int ans = 0;
    FOR(i, 1, 16) ans += c[i] / 2;
    vector<int> dir((1 << 16), inf);
    int tmp = 0;
    FOR(i, 1, 16) if(c[i] % 2) tmp ^= (1 << i);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push({0, tmp});
    dir[tmp] = 0;
    while(!q.empty()) {
        int c = q.top().first;
        int p = q.top().second;
        q.pop();
        if(dir[p] != c) continue;
        bitset<16> b(p);
        FOR(i, 1, 16) {
            if(!b[i]) continue;
            FOR(j, i + 1, 16) {
                if(!b[j]) continue;
                FOR(k, 1, 16) {
                    bitset<16> nb(p);
                    int cost = c + 1;
                    nb[i] = 0;
                    nb[j] = 0;
                    if(i ^ k) {
                        nb[i ^ k] = !nb[i ^ k];
                        if(!nb[i ^ k]) cost++;
                    }
                    if(j ^ k) {
                        nb[j ^ k] = !nb[j ^ k];
                        if(!nb[j ^ k]) cost++;
                    }
                    if(dir[nb.to_ullong()] > cost) {
                        dir[nb.to_ullong()] = cost;
                        q.push({dir[nb.to_ullong()], nb.to_ullong()});
                    }
                }
            }
        }
    }
    cout << ans + dir[0] << endl;
    return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MIN(a,b) ((a) < (b) ? (a) : (b))

int main(void){
    int N;
    scanf("%d",&N);

    int* B;
    NEW(B,N-1);
    for(int i=0;i<N-1;i++){
        scanf("%d\n", &B[i]);
    }

    long ans;
    ans=B[0]; //A[0]=B[0]
    for(int i=1;i<N-1;i++){
        ans+=MIN(B[i-1],B[i]); //A[i]=min(B[i-1],B[i])
    }
    ans+=B[N-2]; //A[N-1]=B[N-2];

    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
x, y = list(map(int, input().split()))

def ncr(n, r, p):
    num = 1
    den = 1

    for i in range(r):
        num = (num*(n-i)) % p
        den = (den*(i+1)) % p

    return (num*pow(den, p-2, p)) % p

if (x+y)%3 == 0:
    n = (x+y)//3

    if not (n <= x <= 2*n):
        print(0)
    else:
        print(ncr(n, x-n, 1000000007))
else:
    print(0)

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

int main() {
   int N,K,x;
   int sum = 0;
   cin >> N >> K;
   for(int i = 0; i < N; i++){
       cin >> x;
       if(K-x < x){
           if(K-x < 0){
               sum+=-2*(K-x);
           }else{
               sum+=2*(K-x);
           }
       }else{
           sum+=2*x;
       }
   }
   cout << sum << endl;
} 

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

int main() {
  int H = 0, W = 0;
  cin >> H >> W;
  
  for(int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for(int i = 0; i < H; i++) {
    string s;
    cin >> s;
    cout << '#' << s << '#' << endl;
  }
  
  for(int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


int main()
{
	int n;
	cin >> n;
	vll a(n);
	rep(i, n) cin >> a[i];

	sort(all(a));
	
	ll ma = a[n - 1];
	double nans = ma / 2.0;
	double d = INF;
	ll ans = 0;
	rep(i, n) {
		double diff = nans - double(a[i]);
		if (diff < 0) diff *= -1;
		if (diff < d) {
			d = diff;
			ans = a[i];
		}
	}

	cout << ma << ' ' << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include <stack>
#include<set>
#include<algorithm>
#include<stdio.h>

using namespace std;
int main() {

	int w, s;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe";
	else
		cout << "safe";

	

		return 0;
}
	




Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n)ans += i;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
}

Measured memory_bytes: 28164
import java.util.*;

public class Main{
	  public static void main(String[] args) {
	      Scanner sc = new Scanner(System.in);
		  int n = sc.nextInt();        //n件
		  int[][][] count = new int[4][3][10];
		  
		  
		  //b棟f階のr番目の部屋にv人が追加で入居した情報を宣言
		  for(int i = 0; i < n; i++){
			int b = sc.nextInt(); //b棟
		    int f = sc.nextInt(); //f階
		    int r = sc.nextInt(); //r番目の部屋
		    int v = sc.nextInt(); //v人入居
		    count[b - 1][f - 1][r - 1] += v;
		  }

		  //表示させるものを宣言
		         for (int i = 0; i < count.length; i++) {
		             for (int j = 0; j < count[i].length; j++) {
		            	 for (int k = 0; k < count[i][j].length; k++) {
		            		 System.out.print(" " + count[i][j][k]);
		            	 }
		            	 System.out.println("");
		             }
		             if(i < 3){
		             System.out.println("####################");
		             }
		         }
      }
}



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

int main(void) {
  int A, B, C;
  long long K;
  scanf("%d%d%d%lld", &A, &B, &C, &K);

  if (K%2 == 0) {
    printf("%d\n", A-B);
  } else {
    printf("%d\n", B-A);
  }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main(){
  int N;
  string ps, s;
  map<string, bool> W;
  
  cin >> N;
  cin >> ps;
  W[ps] = true;
  for(int i = 1;i < N;i++){
    cin >> s;
    if(W[s] || ps[ps.size() - 1] != s[0]){
      cout << "No" << endl;
      return 0;
    }
    W[s] = true;
    ps = s;
  }
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256