akhauriyash/Code-Regression huggingface dataset:
import std.stdio,std.conv,std.string,std.algorithm,std.array,std.math;
void main(){
    auto s=readln().chomp().split().map!(to!int);
    int a=s[0],b=s[1],c=s[2],ans=0;
    if(a>b && a>c)
        ans=b*c/2;
    else if(b>a && b>c)
        ans=c*a/2;
    else
        ans=a*b/2;
    
    writeln(int(ans));
}

Measured memory_bytes: 256
n = gets.to_i

h = Hash.new{|h,k| h[k] = []}
n.times do |i|
  s, p = gets.split(" ")
  h[s] << [i, p.to_i]
end

h = h.sort_by{|h,k| h}

h.length.times do |i|
  t = h[i][1].sort_by{|a,b| -b}
  t.length.times do |j|
    puts t[j][0] + 1
  end
end
 

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define inf 10000000000LL
#define ll long long
#define pr pair<ll,ll>
using namespace std;

ll dp[100005];
ll arr[100005];

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    ll n,m;
    cin>>n;
    for(ll x=0; x<n; x++){
        cin>>arr[x];
        dp[x]=inf;
    }
    dp[0]=0;
    for(ll x=0; x<n-1; x++){
        if(x+1<n)dp[x+1]=min(dp[x+1], dp[x]+abs(arr[x+1]-arr[x]));
        if(x+2<n)dp[x+2]=min(dp[x+2], dp[x]+abs(arr[x+2]-arr[x]));
    }
    cout<<dp[n-1];
    return 0;
    
}

Measured memory_bytes: 1792
import java.util.Scanner;


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        int R = Integer.parseInt(sc.next());
        int in_rate;

        if(N >= 10){
            in_rate = R;
        }else{
            in_rate = R+100*(10-N);
        }
        System.out.println(in_rate);
        
    }
}


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

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

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

int W, H;
char B[30][30];

int dfs(int y, int x) {
   int ret = 1;
   B[y][x] = '#';
   rep (i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && B[ny][nx] == '.') ret += dfs(ny, nx);
   }
   return ret;
}

int main() {
   while (cin >> W >> H, W) {
      rep (i, H) cin >> B[i];
      int sy = 0, sx = 0;
      rep (i, H) rep (j, W) if (B[i][j] == '@') sy = i, sx = j;
      cout << dfs(sy, sx) << endl;
   }
   
   return 0;
}


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

int N;
vector<int> A;

long long solve() {
    vector<int> alt;
    for (int i = 0; i < N; ++i) alt.push_back(A[i]);
    sort(alt.begin(), alt.end());
    for (int i = 0; i < N; ++i) {
        int it = lower_bound(alt.begin(), alt.end(), A[i]) - alt.begin();
        A[i] = it;
    }
    vector<int> nums(N, 0);
    for (int i = 1; i < N; i += 2) nums[i]++, nums[A[i]]++;
    int res = 0;
    for (int i = 1; i < N; i += 2) if (nums[i] == 2) ++res;
    return N/2 - res;
}

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 1528
N, D = map(int, input().split())
l = []
cnt = 0

for i in range (N):
  l.append(list(map(int, input().split())))
    
for j in range (N-1):
  for k in range (j+1, N):
    t = 0
    for d in range (D):
      t += (l[j][d]-l[k][d])**2
      
    if t**(1/2)%1 ==0:
      cnt += 1
      
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int ret = 0;
    for(int i = 0;i < N;i++) {
        for(int j = i + 1;j < N;j++) {
            for(int k = j + 1;k < N;k++) {
                if(vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k) && vec.at(i) != vec.at(k)) {
                    vector<ll> cnt = {vec.at(i),vec.at(j),vec.at(k)};
                    sort(cnt.begin(),cnt.end());
                    if(cnt.at(0) + cnt.at(1) > cnt.at(2)) {
                        ret++;
                    }
                }
            }
        }
    }
    cout << ret << endl;
}

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

int n;
int m;
int in, out;

int main() {
	cin >> n >> m;
	
	int ans = m;
	int car = m;
	for (int i = 0; i < n; i++) {
		cin >> in >> out;
		car += in - out;
		if (car < 0) { cout << 0 << endl; return 0; }
		ans = max(ans, car);
	}
	cout << ans << endl;
	
	return 0;
}

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


int main()
{
	int N;
	cin >> N;
	int num[110], i = 0, j,temp, Ali=0, Bob=0;
	while (i < N)
	{
		cin >> num[i];
		i++;
	}
	sort(num, num+N, greater<int>());
	i = 0;
	while (i < N)
	{
		if (i % 2 ==0)
			Ali += num[i];
		else
			Bob += num[i];
		i++;
	}
	cout << Ali - Bob << endl;
	return 0;
}

Measured memory_bytes: 3568
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int X;

signed main()
{
	cin >> X;

	int a = 100;
	int ans = 0;

	while (true)
	{
		ans++;
		a = (int)(a * 1.01);
		if (a >= X)
		{
			cout << ans << endl;
			return 0;
		}
	}
}





Measured memory_bytes: 3632
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename T> class LazySegTree_RSQ_RAQ {
  int size = 1;
  std::vector<T> tree, lazy; // 1-indexed

  void flush(int i, int l, int r) {
    tree[i] = tree[i] + lazy[i] * (r - l);
    if (i < size) {
      lazy[i * 2] = lazy[i * 2] + lazy[i];
      lazy[i * 2 + 1] = lazy[i * 2 + 1] + lazy[i];
    }
    lazy[i] = 0;
  }

public:
  LazySegTree_RSQ_RAQ(const int &n) {
    while (size < n) size *= 2;
    tree.assign(size * 2, 0);
    lazy.assign(size * 2, 0);
  }

  // [l, r)
  void add(int l, int r, const int &x) { add(l, r, x, 1, 0, size); }
  void add(const int l, const int r, const int &x, int i, int a, int b) {
    flush(i, a, b);
    if (b <= l || r <= a) return;
    if (l <= a && b <= r) {
      lazy[i] = lazy[i] + x;
      flush(i, a, b);
      return;
    }
    add(l, r, x, i * 2, a, (a + b) / 2);
    add(l, r, x, i * 2 + 1, (a + b) / 2, b);
    tree[i] = tree[i * 2] + tree[i * 2 + 1];
  }

  // [l, r]
  T sum(int l, int r) { return sum(l, r, 1, 0, size); }
  T sum(int l, int r, int i, int a, int b) {
    flush(i, a, b);
    if (b <= l || r <= a) return 0;
    if (l <= a && b <= r) return tree[i];
    T lhs = sum(l, r, i * 2, a, (a + b) / 2);
    T rhs = sum(l, r, i * 2 + 1, (a + b) / 2, b);
    tree[i] = tree[i * 2] + tree[i * 2 + 1];
    return lhs + rhs;
  }
};

main {
  int n, q;
  cin >> n >> q;
  LazySegTree_RSQ_RAQ<int> lst(n);
  while (q--) {
    int a, s, t;
    cin >> a >> s >> t;
    --s, --t;
    if (a) {
      cout << lst.sum(s, t + 1) << endl;
    } else {
      int x;
      cin >> x;
      lst.add(s, t + 1, x);
    }
  }
}

Measured memory_bytes: 7060
#include <stdio.h>

int main(void)
{
 int a,b,tem = 1 , m = 0;
  scanf( "%d %d",&a,&b );
  while( tem < b )
  {
   tem += a - 1;
    m++;
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 1688
// ITNA SIMPLE QUESTIO SHIIITTTT OFFF
// SOCHA THA TOH USSI DIRECTION ME SOCHNA THA
// WHY SKIPPED

#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 505;
ll n,k,sum = 0;
ll a[MAXN];

bool check(ll x){
    vector<ll> v;

    FOR(i,1,n){
        v.push_back(a[i]%x);
    }

    sort(all(v));

    ll s = 0,e = v.size() - 1;

    ll rem = 0,req = 0;

    while(s<=e){
        if(rem <= 0){
            rem += v[s];
            req += v[s];
            s++;
        }else {
            rem -= (x-v[e]);
            req += (x-v[e]);
            e--;
        }
    }

    if(req > 2*k || rem != 0) return 0;
    return 1;
}

void solve(){
    cin>>n>>k;

    FOR(i,1,n){
        cin>>a[i]; sum += a[i];
    }

    ll ans = 1;

    for(ll i=1;i*i<=sum;i++){
        if(sum%i == 0){
            if(check(i)) ans = max(ans,i);
            if(check(sum/i)) ans = max(ans,(sum/i));
        }
    }

    cout<<ans<<endl;
} 
 
signed main(){
 
   FastRead;    
 
 
    ll t;
    t = 1; 
    //cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void dice_north(int d[], int b[])	//北側に回転
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[1];
	d[1] = b[5];
	d[2] = b[2];
	d[3] = b[3];
	d[4] = b[0];
	d[5] = b[4];
}

void dice_south(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[4];
	d[1] = b[0];
	d[2] = b[2];
	d[3] = b[3];
	d[4] = b[5];
	d[5] = b[1];
}

void dice_west(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[2];
	d[1] = b[1];
	d[2] = b[5];
	d[3] = b[0];
	d[4] = b[4];
	d[5] = b[3];
}

void dice_east(int d[], int b[])
{
	int i;

	for (i = 0; i < 6; i++) {
		b[i] = d[i];
	}
	d[0] = b[3];
	d[1] = b[1];
	d[2] = b[0];
	d[3] = b[5];
	d[4] = b[4];
	d[5] = b[2];
}

int main(void) {
	int dice[100][6];
	int box[6];
	int i, j, k, m;
	int n;
	int d = 0;
	int count = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < 6; j++) {
			scanf("%d", &dice[i][j]);
		}
	}

	for (i = 0; i < n - 1; i++) {
		for (m = i + 1; m < n; m++) {
			for (j = 0; j < 4; j++) {
				for (k = 0; k < 4; k++) {
					if ((dice[i][0] == dice[m][0]) && (dice[i][1] == dice[m][1]))
						if ((dice[i][2] == dice[m][2]) && (dice[i][3] == dice[m][3]))
							if ((dice[i][4] == dice[m][4]) && (dice[i][5] == dice[m][5]))
								d = 1;
					dice_east(dice[i], box);
				}
				dice_north(dice[i], box);
			}

			dice_west(dice[i], box);
			dice_south(dice[i], box);

			for (j = 0; j < 4; j++) {
				for (k = 0; k < 4; k++) {
					if ((dice[i][0] == dice[m][0]) && (dice[i][1] == dice[m][1]))
						if ((dice[i][2] == dice[m][2]) && (dice[i][3] == dice[m][3]))
							if ((dice[i][4] == dice[m][4]) && (dice[i][5] == dice[m][5]))
								d = 1;
					dice_east(dice[i], box);
				}
				dice_north(dice[i], box);
			}

			if (d == 1)
				count++;
			d = 0;

			dice_north(dice[i], box);
			dice_east(dice[i], box);
		}
	}

	if (count == 0)
		printf("Yes\n");
	else
		printf("No\n");

	//scanf("%d", &i);
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <sstream>
#include <complex>
using namespace std;
typedef complex<long> xy_t;
long cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }
vector<string> StringSplit(const string &str, char sep)
{
	vector<std::string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}
int main()
{
	string num;
	int n;
	cin >> n;
	while (n--)
	{
		long xy[8];
		for (int i = 0; i < 8; i++)
		{
			cin >> num;
			auto num_s = StringSplit(num, '.');
			auto lambda = [&](int dec) {int l = 5 - num_s[1].length(); while (l--) { dec *= 10; }if (num[0] == '-') { dec *= -1; }return dec; };
			int num_i = stoi(num_s[0]) * 100000 + lambda(stoi(num_s[1]));
			xy[i] = num_i;
		}
		long cp = cross_product(xy_t(xy[2] - xy[0], xy[3] - xy[1]), xy_t(xy[6] - xy[4], xy[7] - xy[5]));
		if (cp == 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}



Measured memory_bytes: 3200
#include <stdio.h>

int main(){
    int n, x;
    scanf("%d%d", &n, &x);
    int dist = 0, cnt = 1;
    for(int i = 0; i < n; i++){
        int l;
        scanf("%d", &l);
        dist += l;
        if(dist <= x) cnt++;
    }
    printf("%d\n", cnt);
}

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

  if(a<b) cout<<"a < b"<<endl;
  if(a>b) cout<<"a > b"<<endl;
  if(a==b) cout<<"a == b"<<endl;

  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  int ans=0;
  rep(i,n) {
    if(i%2==0&&a[i]%2) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3604
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N= 100005;
const ll lmod = 1e9+7;

int a[MAX_N];
ll b[MAX_N];

int msb(int K){
  int i;
  for(i=30;(1<<i)>K;i--){
    // Nope
  }
  return i;
}

int main(){
  int N, K;
  cin >> N >> K ;
  rep(i,N){
    scanf("%d%lld",a+i,b+i);
  }
  ll ans = -1;
  for(int f=30;f>=0;f--){
    if((((1<<f)&K)==0)&&(f!=0)) continue;
    ll val = 0;
    if(f!=0){
      rep(i,N){
        //1<<f 未満の数は全て使って良いとして価値を計算する
        if(a[i]<(1<<f)){
          val += b[i];
        }else{
          a[i] -= 1<<f;
        }
      }
    }else{
      if((K&1)==1){
        rep(i,N) if(a[i]<=1) val+=b[i];
      }else{
        rep(i,N) if(a[i]==0) val+=b[i];
      }
    }
    // cout << f << "," << val << endl;
    ans = max(ans,val);
  }

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

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] nk = in.readLineAsIntArray();
        final int N = nk[0];
        final int K = nk[1];

        double p = 0.0;

        double mul = 1.0;

        int high = N;
        int k = K;
        while (high > 0) {
            if (high >= k) {
                p += (Math.max(high - k + 1, 0) * mul) / N;
                high = k - 1;
            } else {
            }
            if(k%2==0){
                k = k / 2;
            }else{
                k = k / 2 + 1;
            }
            mul *= 0.5;
        }
        System.out.println(p);

    }


    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

Measured memory_bytes: 22100
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]

total = 0
for i in range(n+1):
    total += abs(a[i] - a[i+1])

for i in range(1, n+1):
    if (a[i-1] - a[i]) * (a[i] - a[i+1]) > 0:
        print(total)
    else:
        x = min(abs(a[i-1] - a[i]), abs(a[i] - a[i+1]))
        print(total - x*2)

Measured memory_bytes: 20620
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))

#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
typedef vector<vi>		vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6+13, M = N;
//=======================
vi g[N];
int a[N];
int n, m, k;
//=======================

int  count_digits(int n) 
{ 
    string num = to_string(n); 
    return num.size() ;
} 
void solve() {

int n,x,t;
cin>>n>>x>>t;
if(n<=x){cout<<t;}
else{
    if(n%x==0){int temp=n/x;cout<<temp*t;}
    else{int temp1=n/x;cout<<(temp1+1)*t;}
}
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
      cout<<endl;
    }

    return 0;
}

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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//

ll ar[55];
ll dp[55][5100];
ll n,avg;

ll solve(ll ind, ll sum){
    if(ind>=n){
        if(sum==0)return 1;
        else return 0;
    }
    if(dp[ind][sum+2500]!=-1)return dp[ind][sum+2500];

    return dp[ind][sum+2500]=solve(ind+1, sum+ar[ind]-avg)+solve(ind+1, sum);
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    n=rr;avg=rr;
    loop(i,n)ar[i]=rr;
    memset(dp, -1 ,sizeof(dp));
    cout << solve(0,0)-1<< endl;
    
    return 0;
}

Measured memory_bytes: 2432
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))

dp = [-1] * (N + 1)
dp[N] = 0
dp[N - 1] = abs(h[N] - h[N - 1])

for i in reversed(range(1, N - 1)):
    candidates = [10 ** 5] * K
    for k in range(1, K + 1):
        if i + k > N:
            continue
        candidates[k - 1] = dp[i + k] + abs(h[i + k] - h[i])
    dp[i] = min(candidates)
print(dp[1])


Measured memory_bytes: 52704
#include <stdio.h>

int main(void)
{
	int A[100], i, j, k, l, N, v;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (l = 0; l < N; l++) {
		if (l < N - 1) {
				printf("%d ", A[l]);
		} else {
				printf("%d\n", A[l]);
		}
	}
	for (i = 1; i < N; i++) {
		v = A[i];
		for (j = 0; j < i; j++) {
			if (A[j] > A[i]) {
				for (k = i - 1; k >= j; k--) {
					A[k + 1] = A[k];
				}
				A[j] = v;
			}
		}
		for (l = 0; l < N; l++) {
			if (l < N - 1) {
				printf("%d ", A[l]);
			} else {
				printf("%d\n", A[l]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> A(n, vector<int>(m));
	vector<int> b(m);
	rep(i, n) rep(j, m) cin >> A[i][j];
	rep(i, m) cin >> b[i];
	rep(i, n) {
		int a = 0;
		rep(j, m) {
			a += A[i][j] * b[j];
		}
		cout << a << endl;
	}
}



Measured memory_bytes: 3248
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string password;
	string O;
	string E;
	int pass_length;
	int difference;

	cin >> O;
	cin >> E;

	difference = O.length() - E.length();

	for (int i = 0; i < E.length(); i++) {
		password += O[i];
		password += E[i];
	}

	if (difference == 1) {
		password += O[O.length()-1];
	}
	
	cout << password << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll n; cin >> n;
    vector<ll> a(100001),b(100001);
    ll ans = 0;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    rep(i,n){
        if(b[i]<=a[i]){
            a[i] -= b[i];
            ans += b[i];
        }else{
            ans += a[i];
            b[i] -= a[i];
            a[i] = 0;
            if(b[i] >= a[i+1]){
                ans += a[i+1];
                a[i+1] = 0;
            }else{
                ans += b[i];
                a[i+1] -= b[i];
            }
        }
    }

    cout << ans;


    return 0;
}











Measured memory_bytes: 4808
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        String[] s = new String[n];
      
        for(int i = 0; i < n ; i++){
          s[i] = sc.next();
        }
      
        Arrays.sort(s);
      
        for(int i = 0; i < n ; i++){
          System.out.print(s[i]);
        }
      
        System.out.println();   
	}
}


Measured memory_bytes: 37452
import heapq
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

q = []
idx = 0
ans = 0
for i in range(1, M+1):
    while idx < N:
        a, b = AB[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b

print(ans)

Measured memory_bytes: 31596
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="Sunny")
    	cout<<"Cloudy";
    else if(s=="Cloudy")
    	cout<<"Rainy";
    else
    	cout<<"Sunny";
    cout<<endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException{
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    int i;
		int [] mountain;
		int escape = 0;

		mountain = new int[10];
		/*
		mountain[0] = 2362;
		mountain[1] = 1121;
		mountain[2] = 1462;
		mountain[3] = 1896;
		mountain[4] = 1082;
		mountain[5] = 2362;
		mountain[6] = 953;
		mountain[7] = 1545;
		mountain[8] = 3532;
		mountain[9] = 1170;
		*/

		/*System.out.println("山の高さ一覧");
		for(int i = 0; i < 10; i++) {
			System.out.println(mountain[i]);
		}
		*/

		for(i=0;i<10;i++)
	        mountain[i]=Integer.parseInt(br.readLine());

		/*System.out.println("ソート中");*/
		for(int a = 0; a < 9; a++) {
		    for(int b = a + 1; b < 10; b++) {
		    	if(mountain[a] < mountain[b]) {
		    		escape = mountain[b];
					mountain[b] = mountain[a];
					mountain[a] = escape;
				}
		    }
		    //System.out.println(mountain[i]);
		}

		/*System.out.println("ソート完了：高い順に３つ出力します");*/
		System.out.println(mountain[0]);
        System.out.println(mountain[1]);
        System.out.println(mountain[2]);

	}
}


Measured memory_bytes: 24288
import sys
input = sys.stdin.readline

def main():
  result = [0] * int(input())
  arg = [int(i) for i in input().split()]
  
  for i in arg:
    result[i-1] = result[i-1] + 1
  
  for i in result:
    print(i)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 92732
#include <stdio.h>

int main(void) {
  int x, y;
  scanf("%d %d", &x, &y);
  if (x == y) printf("Yes\n");
  if (x == 4 || x == 6 || x == 9 || x == 11) {
    if (y == 4 || y == 6 || y == 9 || y == 11)
      printf("Yes\n");
    else
      printf("No\n");
  } else {
    if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template<typename T>
void dump(T a, int n) { for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); }

template<typename T>
void dump(T a) { dump<T>(a, a.size()); }

const int LIM = 1000000;
const int INF = INT_MAX;

int main(void) {
	VI nums;
	VI evens;
	for (int i= 1; i <= LIM; i++) {
		int num = i * (i + 1) * (i + 2) / 6;
		if (num > LIM) {
			break;
		}

		nums.push_back(num);

		if (num % 2) {
			evens.push_back(num);
		}
	}

	VI dpa(LIM + 1, INF);
	VI dpb(LIM + 1, INF);
	dpa[0] = 0;
	dpb[0] = 0;
	
	for (int i = 0; i < LIM; i++) {
		if (dpa[i] != INF) {
			for (auto a : nums) {
				int n = i + a;
				if (n <= LIM) {
					dpa[n] = min(dpa[n], dpa[i] + 1);
				}
			}
		}

		if (dpb[i] != INF) {
			for (auto b : evens) {
				int n = i + b;
				if (n <= LIM) {
					dpb[n] = min(dpb[n], dpb[i] + 1);
				}
			}
		}
	}

	for (int N; cin >> N, N;) {
		cout << dpa[N] << " " << dpb[N] << endl;
	}

	return 0;
}

Measured memory_bytes: 8852
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
//#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MOD = 998244353;
const ll MAX = 1000010;

ll add(ll x, ll y){
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
ll sub(ll x, ll y){
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
ll mult(ll x, ll y){
  return (x * y) % MOD;
}
ll powm(ll x, ll p){
  if (p == 0) return 1;
  if (p & 1) return mult(x, powm(x, p - 1));
  return powm(mult(x, x), p / 2);
}
ll modinv(ll a) {
  return powm(a, MOD-2);
}

ll w[MAX]; // index:i のiを除く約数xについて Sum of w[x] が 1/i な w[i]
void winit(){
  reps(i,1,MAX){
    w[i]=modinv(i);
  }
  reps(i,1,MAX){
    for(int j=2*i; j<MAX; j+=i){
      w[j]=sub(w[j], w[i]);
    }
  }
}

void Main(){

  int N;
  cin>>N;

  winit();

  ll a[MAX]={};

  rep(i,N){
    ll aa; cin>>aa;
    ++a[aa];
  }

  ll ans=0;
  reps(i,1,MAX){
    ll sum1=0; ll sum2=0;
    for(int j=i; j<MAX; j+=i){
      sum1=add(sum1,a[j]*j%MOD);
      sum2=add(sum2,mult(a[j]*j%MOD,j));
    }
    sum1=mult(sum1,sum1);

    ll here=mult(w[i],sub(sum1,sum2));
    ans=add(ans,here);
  }

  ans=mult(ans,modinv(2));

  cout<< ans <<"\n";
}

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


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
#define INF (1e18)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,C;
    cin >> N >> C;
    ll D[40][40];
    rep(i,0,C){
        rep(j,0,C){
            cin >> D[i][j];
        }
    }
    ll c[510][510];
    rep(i,0,N){
        rep(j,0,N){
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    ll ans = INF;
    ll iwakan[35][3] = {};
    rep(i,0,C){
        rep(j,0,3){
            ll val = 0;
            rep(y,0,N){
                rep(x,0,N){
                    if((x+y) % 3 == j){
                        val += D[c[y][x]][i];
                    }
                }
            }
            iwakan[i][j] = val;
        }
    }
    rep(i,0,C){
        rep(j,0,C){
            rep(k,0,C){
                if(i == j || j == k || k == i) continue;
                ll tt = iwakan[i][0] + iwakan[j][1] + iwakan[k][2];

                ans = min(ans, tt);
            }
        }
    }
    print(ans);

    
}

Measured memory_bytes: 2304
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int k, n;
    cin >> k >> n;
    vector<int> v(n);
    FOR(i, 0, n) { cin >> v[i]; }
    int mx = v[0] + (k - v[n - 1]);
    FOR(i, 1, n) { mx = max(mx, v[i] - v[i - 1]); }
    cout << k - mx << '\n';
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
ll A[101010];
ll mk[101010];
ll i, j, k, ans;
bool bs(ll a){
    ll n = 0, i = 0, j = N;
    ans = 0;
    fornum(i,0,N){
        while(j>0&&A[i]+A[j-1]>=a){
            --j;
        }
        n += N - j;
    }
    return n >= M;
}
ll ret(ll a){
    ll n = 0, i = 0, j = N, sm = 0, ans = 0;
    fornum(i,0,N){
        while(j>0&&A[i]+A[j-1]>=a){
            --j;
            sm += A[j];
        }
        n += N - j;
        ans += sm + (N - j) * A[i];
    }
    ans -= a * (n - M);
    return ans;
}

int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    sort(A, A + N);
    ll l = 0, r = 1e9;
    while(l<r){
        ll c = (l + r + 1) / 2;
        if(bs(c)){
            l = c;
        }else{
            r = c - 1;
        }
    }

    //printf("%lld ", r);
    printf("%lld", ret(r));
    return 0;
}

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

int main()
{
    int n,k,count=0,b;
    cin>>n>>k;
    int a[n];

    for(int i=0;i<n;i++)
    {
        cin>>b;
        if(b>=k)
            count++;
    }

    cout<<count<<endl;

    return 0;

}


Measured memory_bytes: 256
$n, $m, $q = gets.chomp.split(" ").map(&:to_i)
$a = []
$b = []
$c = []
$d = []
$q.times do |i|
  $a[i], $b[i], $c[i], $d[i] = gets.chomp.split(" ").map(&:to_i)
end
$max = 0

def calc(arr)
  # p arr
  score = 0
  $q.times do |i|
    # p "#{$b[i]} #{$a[i]}"
    score += $d[i] if arr[$b[i]] - arr[$a[i]] == $c[i]
    # p score
  end
  $max = $max >= score ? $max : score
end

def dfs(arr)
  if arr.length == $n+1
    return calc(arr)
  end
  arr.last.upto($m) do |v|
    # p arr
    dfs(arr + [v])
  end
end

def main()
  dfs([1])
  puts $max
end

main()

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, m;
    cin >> n >> m;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vpii c(n);
    rep(i, n) {
        c[i].first = a[i];
        c[i].second = b[i];
    }
    VSORT(c);
    ll ans = 0;
    int now = 0;
    rep(i, m) {
        if (c[now].second==0) ++now;
        ans += c[now].first;
        c[now].second--;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<double> X(11);
	vector<string> U(11);
	int i;
	double S = 0;
	for (i = 0; i < N; i++) {
		cin >> X.at(i) >> U.at(i);
	}
	for (i = 0; i < N; i++) {
		if (U.at(i) == "JPY") {
			S += X.at(i);
		}
		else {
			S += X.at(i) * 380000;
		}
	}
	cout << S;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

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

const int MOD = 1e9 + 7;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void) {
  int n; cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  vector<int> a(n);
  for (int i = 0; i <= n - 1; ++i) {
    if (i == 0) a[i] = b[i];
    if (i == n - 1) a[i] = b[i - 1];
    else {
      if (a[i] > b[i]) a[i] = b[i];
      a[i + 1] = min(b[i], b[i + 1]);
    }
  }

  // for (int i = 0; i < n; ++i) cout << a[i] << endl;

  cout << accumulate(a.begin(), a.end(), 0) << endl;
}


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func solve(n, iMin int, adj [][]int) int {
	vertexes := make([]int, n)
	count := 1
	vertexes[iMin] = count
	queue := make([]int, 0)
	queue = append(queue, iMin)
	for {
		for len(queue) > 0 && vertexes[queue[0]] == count {
			u := queue[0]
			queue = queue[1:]
			for v, a := range adj[u] {
				switch {
				case a == 0:
					continue
				case vertexes[v] == 0:
					vertexes[v] = count + 1
					queue = append(queue, v)
				case vertexes[v] == count-1 || vertexes[v] == count+1:
					continue
				default:
					return -1
				}
			}
		}
		if len(queue) == 0 {
			break
		}
		count++
	}
	return count
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n := nextInt()

	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
		s := nextStr()
		for j, r := range s {
			if r == '1' {
				adj[i][j] = 1
			}
		}
	}

	/*
		divMin := n
		iMins := make([]int, 0)
		for i := range adj {
			div := 0
			for _, a := range adj[i] {
				div += a
			}
			switch {
			case div < divMin:
				divMin = div
				iMins = []int{i}
			case div == divMin:
				iMins = append(iMins, i)
			}
		}
	*/

	ans := -1
	/*
		for _, iMin := range iMins {
			cnt := solve(n, iMin, adj)
			if cnt > ans {
				ans = cnt
			}
		}
	*/
	for i := 0; i < n; i++ {
		cnt := solve(n, i, adj)
		if cnt > ans {
			ans = cnt
		}
	}
	fmt.Println(ans)
}


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

#define INPUT_MAX (int)20000
#define INPUT_MIN (int)1



class CAREA
{
	public:
		CAREA();
		void CalcArea(string str);			//各水たまりの面積を計算する関数
		void DispArea(void);				//結果表示関数
	private:
		int indexSlash;						//slashPositionの添え字
		int indexPuddle;					//puddleAreaとpuddlePositionの添え字
		int slashPosition[INPUT_MAX];		//＼が出た位置
		int puddleCpy;						//水たまりの面積の計算用
		int puddleArea[INPUT_MAX/2];		//各水たまりの面積
		int puddlePosition[INPUT_MAX/2];	//水たまりがある左端の位置
		int sumArea;						//水たまりの面積の合計
};

CAREA::CAREA()
{
	indexSlash = 0;
	indexPuddle = 0;
	memset(slashPosition, 0, sizeof(slashPosition));
	puddleCpy = 0;
	memset(puddleArea, 0, sizeof(puddleArea));
	memset(puddlePosition, 0, sizeof(puddlePosition));
	sumArea = 0;
}

/*
-------------------------------------
関数名：CalcArea
	入力：str(地域の断面図)
	return：なし
-------------------------------------
*/
void CAREA::CalcArea(string str){
	for(int i = 0; i < (int)str.size(); i++){
		if(str[i] == '\0'){
			break;
		}
		else if(str[i] == '\\'){
			//＼の位置を格納
			slashPosition[indexSlash] = i;
			indexSlash++;
		}
		else if(str[i] == '_'){
			//処理なし
		}
		else if(str[i] == '/'){
			if(indexSlash == 0){
				//対になる＼がなければ処理なし
			}
			else{
				puddleCpy = i - slashPosition[indexSlash - 1];
				
				if(indexPuddle == 0){
					//水たまりの面積が1つも格納されていなければ面積と位置をそのまま格納
					puddlePosition[indexPuddle] = slashPosition[indexSlash - 1];
					puddleArea[indexPuddle] = puddleCpy;
					indexPuddle++;
				}
				else{
					//すでに格納されている水たまりと合わせて1つの場合、水たまりを足し合わせる
					while(slashPosition[indexSlash - 1] < puddlePosition[indexPuddle - 1]){
						indexPuddle--;
						puddleCpy += puddleArea[indexPuddle];
						puddleArea[indexPuddle] = 0;
						puddlePosition[indexPuddle] = 0;
						
						if(indexPuddle == 0){
							break;
						}
					}
					
					puddleArea[indexPuddle] = puddleCpy;
					puddlePosition[indexPuddle] = slashPosition[indexSlash - 1];
					indexPuddle++;
				}
				
				indexSlash--;
			}
		}
		else{
			//入ってくることはない
		}
	}
}


/*
-------------------------------------
関数名：DispArea
	入力：なし
	return：なし
-------------------------------------
*/
void CAREA::DispArea(void)
{
	for(int i = 0; i < indexPuddle; i++){
		sumArea += puddleArea[i];
	}
	//水たまりの面積の合計を表示
	cout << sumArea << endl;
	//水たまりの数を表示
	cout << indexPuddle;
	
	//各水たまりの面積を表示
	for(int i = 0; i < indexPuddle; i++){
		cout << ' ' << puddleArea[i];
	}
	cout << endl;
}


int main(void)
{
	CAREA area;
	
	string str;
	cin >> str;
	
	area.CalcArea(str);
	area.DispArea();
	
	
	return 0;
}




Measured memory_bytes: 3416
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	ll X, Y; cin >> X >> Y;
	ll ans = 1;
	ll cur = X;
	while (cur*2 <= Y) {
		ans += 1;
		cur *= 2;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
2019/04/30


Heisei
TBD

 */
string s;

int main(){
  cin>>s;
  if(s <= "2019/04/30"){
    cout<<"Heisei\n";
  } else {
    cout<<"TBD\n";
  }

  return 0;
}


Measured memory_bytes: 256