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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K;
	cin >> N >> K;
	vector<int64> X(N+1), X2(N+1);
	REP(i, N) {
	  cin >> X[i];
	  X2[N-i-1] = -X[i];
	}
	X[N] = X2[N] = INF_LL;
	int64 Q;
	cin >> Q;

	auto tor = make_v<int64>(N+1, 20), suml = make_v<int64>(N+1, 20);
	fill_v<int64>(tor, N);
  fill_v<int64>(suml, 0);
  auto tol = make_v<int64>(N+1, 20), sumr = make_v<int64>(N+1, 20);
  fill_v<int64>(tol, N);
  fill_v<int64>(sumr, 0);
  REP(i, N) {
    tor[i][0] = lower_bound(all(X), X[i] + K)- X.begin();
    tol[i][0] = lower_bound(all(X2), X2[i] + K) -X2.begin();
    suml[i][0] = lower_bound(all(X), X[i] + K)- X.begin();
    sumr[i][0] = N - (tol[i][0]) - 1;
  }
  REP(i, 19) {
    REP(j, N) {
      tor[j][i + 1] = tor[tor[j][i]][i];
      tol[j][i + 1] = tol[tol[j][i]][i];
      suml[j][i + 1] = suml[j][i] + suml[tor[j][i]][i];
      sumr[j][i + 1] = sumr[j][i] + sumr[tol[j][i]][i];
    }
  }

  REP(_, Q) {
    int64 L, R, L2, R2;
    cin >> L >> R; L--; R--;
    L2 = N-L-1; R2 = N-R-1;
    int64 res = 0;
    int64 ret = 1, ret2 = 1, nowl = L, nowl2 = R2, sumll = L, sumrr = R;
    for (int64 i = 19; i >= 0; i--) {
      if (tor[nowl][i] <= R) {
        ret += 1 << i;
        sumll += suml[nowl][i];
        nowl = tor[nowl][i];
      }
      if (tol[nowl2][i] <= L2) {
        ret2 += 1 << i;
        sumrr += sumr[nowl2][i];
        nowl2 = tol[nowl2][i];
      }
    }
    chmax(res, ret);
    chmax(res, ret2);
    cout << sumrr - sumll + res << endl;
  }
}


Measured memory_bytes: 162692
import heapq
import sys
input = sys.stdin.readline
 
INF = 10 ** 18
 
class Edge():
    def __init__(self, end, cost, time):
        self.end = end
        self.cost = cost
        self.time = time
 
dp = []
h = []
 
def push(t, v, x):
    if x < 0:
        return
    if dp[v][x] <= t:
        return
    dp[v][x] = t
    heapq.heappush(h, (t, v, x))
 
def dijkstra(n, G, cd, start, s, max_s):
    global dp
    dp = [[INF for j in range(max_s+1)] for i in range(n)] 
    push(0, start, s)
 
    while h:
        # 使っていない頂点のうち、現時点で最も到達短時間が短いものを選びvとする
        t, v, x = heapq.heappop(h)
        if dp[v][x] < t:
            continue
        # 両替
        if x < max_s:
            push(t+cd[v][1], v, min(x+cd[v][0], max_s))
        # vから到達可能な頂点について、到達時間が短くなれば更新
        for e in G[v]:
            push(t+e.time, e.end, x-e.cost)
 
 
n, m, s = map(int, input().split())
uvab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(n)]
 
es = [[] for i in range(n)]
max_s = 50 * (n-1)
 
for u, v, a, b in uvab:
    es[u-1].append(Edge(v-1,a,b))
    es[v-1].append(Edge(u-1,a,b))
 
dijkstra(n, es, cd, 0, min(max_s,s), max_s)
 
for i in range(1, n):
    print(min(dp[i]))

Measured memory_bytes: 23904
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

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

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

  int res = 0;
  for (int i = N; ; i += N) {
    if (i % 2 == 0) {
      res = i;
      break;
    }
  }
  cout << res << endl;

  return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, q;
    cin >> n;
    string s;
    cin >> s;
    cin >> q;
    vector<set<int>> V(26);
    for (int i = 0; i < n; i++) {
    	V[s[i] - 'a'].insert(i);
    }
    while (q--) {
    	int t;
    	cin >> t;
    	if (t == 2) {
    		int l, r;
    		cin >> l >> r;
    		l--, r--;
    		int cnt = 0;
    		for (int i = 0; i < 26; i++) {
    			auto it = V[i].lower_bound(l);
    			if (it == V[i].end()) continue;
    			if (*it <= r) {
    				cnt++;
    			}
    		}
    		cout << cnt << "\n";
    	} else {
    		int idx;
    		char c;
    		cin >> idx >> c;
    		idx--;
    		V[s[idx] - 'a'].erase(V[s[idx] - 'a'].find(idx));
    		s[idx] = c;
    		V[c - 'a'].insert(idx);
    	}
    }
}

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

int main(){
  char a,b;
  cin >> a >> b;
  if(int(a)<int(b)){
    cout << "<" << endl;
  }
  else if(int(a)==int(b)){
    cout << "=" << endl;
  }
  else{
    cout << ">" << endl;
  }
}


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

const ll MAX_N = (ll)1e5;

std::vector<ll> G[MAX_N];
std::vector<ll> vans;

int main()
{
  ll N;
  std::cin >> N;
  for (ll i = 0; i < N-1; i++) {
    ll a, b;
    std::cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  std::vector<ll> vc(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> vc[i];
  }
  std::sort(vc.begin(), vc.end(), std::greater<>());

  vans = std::vector<ll>(N, 0LL);

  ll sum = std::accumulate(vc.begin()+1, vc.end(), 0LL);

  std::map<ll, bool> mused;
  std::queue<ll> que;
  ll idx = 0;
  que.push(0);
  vans[0] = vc[idx];
  mused[0] = true;
  idx++;
  while (!que.empty()) {
    ll v = que.front(); que.pop();
    for (ll i = 0; i < (ll)G[v].size(); i++) {
      if (!mused[G[v][i]]) {
	que.push(G[v][i]);
	vans[G[v][i]] = vc[idx];
	mused[G[v][i]] = true;
	idx++;
      }
    }
  }

  print(sum);
  for (auto x : vans) {
    std::cout << x << " ";
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;
vector<long long> fact_inv, inv;
void init_nCk(long long k){
  fact_inv.resize(k+5);
  inv.resize(k+5);
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for(long long i=2;i<k+5;i++){
    inv[i]=MOD-inv[MOD % i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
}
long long nCk(long long n,long long k){
  assert(!(n<k));
  assert(!(n<0||k<0));
  long long ans=1;
  for(long long i=n;i>=n-k+1;i--){
    ans*=i;
    ans%=MOD;
  }
  return ans*fact_inv[k]%MOD;
}
int main(){
    long long N,K;
    long long ans=0;
    cin>>N>>K;
    for(long long i=1;i<=K;i++){//iこに分ける
        if(i==1){
            cout<<N-K+1<<endl;
            continue;
        }
        init_nCk(K+N+K+N);
        long long count=0;
        for(long long j=1;j<=N-K;j++){//青にjこ赤を混ぜる
            //K個のボールをj個の仕切りでi個のグループに分ける(i>=2)
            //N-K-j個のこる
            //jこをi-1こに分ける
            if(j<i-1){continue;}
            count+=(N-K-j+1)*nCk(K-1,i-1)%MOD*nCk(j-1,i-2)%MOD;
            count%=MOD;
            //if(i>9)cout<<i<<" "<<j<<" "<<count<<endl;
            //cout<<i<<" "<<j<<" "<<N-K-j+1<<" "<<nCk(K-1,i-2)*(K-i+1)/(i-1)<<" "<<nCk(j-1,i-2)<<endl;
        }
        cout<<count<<endl;
    }
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int ng[500];
int dp[500];

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x;
    cin >> x;
    if(x >= 400 && x <= 599) print(8);
    if(x >= 600 && x <= 799) print(7);
    if(x >= 800 && x <= 999) print(6);
    if(x >= 1000 && x <= 1199) print(5);
    if(x >= 1200 && x <= 1399) print(4);
    if(x >= 1400 && x <= 1599) print(3);
    if(x >= 1600 && x <= 1799) print(2);
    if(x >= 1800 && x <= 1999) print(1);

    

}



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

struct Cloth
{
	int mini, maxi, glitz;
	bool operator<(const Cloth& c) const
	{
		if (this->glitz < c.glitz) return true;
		else if (this->glitz == c.glitz){
			if (this->mini < c.mini) return true;
			else if (this->mini == c.mini && this->maxi < c.maxi) return true;
			return false;
		}
		return false;
	}
};

int d, n;
int temp[256];
Cloth cloth[256];
int memo[256][256];

int solve(int day, int before);

int main()
{
	scanf("%d %d", &d, &n);
	for (int i = 1; i <= d; i++) scanf("%d", temp + i);
	for (int i = 1; i <= n; i++){
		scanf("%d %d %d", &cloth[i].mini, &cloth[i].maxi, &cloth[i].glitz);
	}
	cloth[0] = cloth[1];
	//sort(cloth, cloth + n);
	memset(memo, -1, sizeof(memo));
	
	solve(1, 0);
	int maxi = 0;
	for (int i = 1; i <= d; i++){
		for (int j = 1; j <= n; j++){
			maxi = max(maxi, memo[i][j]);
		}
	}
	printf("%d\n", maxi);
	/*
	for (int i = 1; i <= d; i++){
		for (int j = 1; j <= n; j++){
			printf("%d ", memo[i][j]);
		}
		puts("");
	}*/
	
	return 0;
}

int solve(int day, int before)
{
	if (day > d) return 0;
	if (memo[day][before] >= 0) return memo[day][before];
	
	int t = 0;
	for (int i = 1; i <= n; i++){
		if (cloth[i].mini <= temp[day] && temp[day] <= cloth[i].maxi){
			/*
			printf("%*d %d\n", day, day, i);
			printf("%*s %d %d %d %d\n", day, "", solve(day + 1, i), cloth[before].glitz, cloth[i].glitz, t);
			*/
			t = max(t, solve(day + 1, i) + abs(cloth[before].glitz - cloth[i].glitz));
			/*
			printf("%*d %d\n", day, day, i);
			printf("%*s %d %d %d %d\n", day, "", solve(day + 1, i), cloth[before].glitz, cloth[i].glitz, t);
			*/
		}
	}
	
	return memo[day][before] = t;
}

Measured memory_bytes: 1468
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

constexpr lnt MOD = 1e9+7;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<lnt> a(n);
	rep(i,n) std::cin >> a[i];
	std::sort(all(a));
	mint ans=1;
	if(a[n-1]<0&&k%2) {
		rep(i,k) ans*=a[n-i-1];
		print(ans);
		return 0;
	}
	int l=0,r=n;
	rep(i,k) {
		if(-a[l]>a[r-1]) l++;
		else r--;
	}
	debug(l,r);
	if(l%2==0||l==r) {
		rep(i,l) ans*=a[i];
		for(int i=r;i<n;i++) ans*=a[i];
		print(ans);
		return 0;
	}
	if(r!=n&&(l==0||a[l]*a[l-1]>=a[r-1]*a[r])) {
		rep(i,l+1) ans*=a[i];
		for(int i=r+1;i<n;i++) ans*=a[i];
	} else {
		rep(i,l-1) ans*=a[i];
		for(int i=r-1;i<n;i++) ans*=a[i];
	}
	debug(l,r);
	print(ans);
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n;
  cin >> n;
  vector<ll> a(n), b(n);

  rep(i, n){
    cin >> a[i] >> b[i];
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll ans = 0;
  if(n % 2 == 0){

    ll left = a[n/2] + a[n/2-1];
    ll right = b[n/2] + b[n/2-1];

    ans = right - left + 1;

  }else{

    ll left = a[n/2];
    ll right = b[n/2];

    ans = right - left + 1;

  }

  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 6352
n, m = gets.to_s.split.map{|i| i.to_i }

bits = Array.new(n){|i| 2**i }
# p bits = Array.new(12){|i| 2**i } #=> [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
shops = Array.new(m) do
  a = gets.to_s.to_i
  c = gets.to_s.split.map{|i| i.to_i - 1 }
  bit = c.map{|t| bits[t] }.reduce(0){|s,t|s+t}
  [bit, a]
end.sort_by{|(bit, _)| bit }

inf = 10 ** 12
state_size = 2 ** n
d = Array.new(state_size, inf)
d[0] = 0

state_max = 0
shops.each do |(bit, a)|
  state_max |= bit
  state_max.times do |k|
    new = k | bit
    d[new] = d[k] + a if d[new] > d[k] + a
  end
  
end

puts d[-1] == inf ?  -1 : d[-1]

Measured memory_bytes: 2296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    long long a,b,k;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(k<a){
        printf("%lld %lld",a-k,b);
        return 0;
    }
    if(a<=k && k<a+b){
        printf("0 %lld",a+b-k);
        return 0;
    }
    printf("0 0");
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  int n;
  cin >> n;
  
  int b=0;
  long long ret=0;
  long long ret2=0;
  for(int i=0;i<n;i++){
    cin >>b;
    ret2+=b;
    if(b==0){
      ret += ret2/2;
      ret2=0;
    }
  }
  ret += ret2/2;
  cout << ret<<endl;
}


Measured memory_bytes: 256
let n = Int(readLine()!)!
let DList = (0..<n).map { _ in readLine()!.split(separator: " ").compactMap { Int($0) } }

var maxCount = 0
var three = false
for i in 0..<n {
    if DList[i][0] == DList[i][1] {
        maxCount += 1
        if maxCount == 3 {
            three = true
            break
        }
    } else {
        maxCount = 0
    }
}
print(three ? "Yes" : "No")


Measured memory_bytes: 8212
N, K = map(int, input().split())
a = list(map(int, input().split()))

def s(n):
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n > 1:
        ret.append(n)
    return ret

def j(N, K, a):
    flag = 1
    if K > max(a):
        flag = 0
    else:
        minE = min(a)
        eles = s(minE)
        ce = []
        for e in eles:
            boolA = [ea % e == 0 for ea in a]
            if all(boolA):
                a = [ea // e for ea in a]
                ce.append(e)
        for e in ce:
            if K % e != 0:
                flag = 0
                break
            else:
                K //= e
    print(('IMPOSSIBLE', 'POSSIBLE')[flag])

j(N, K, a)
        


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

int main() {
  ll l, r;
  cin >> l >> r;
  r = min(r, l+4038);
  int ans = 2018;
  for (ll i = l; i <= r; i++) {
    for (ll j = i+1; j <= r; j++) {
      int x = i*j%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (A == B && A == C && B == C) {
			System.out.println("No");
		} else if (A != B && A != C && B != C) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		sc.close();
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for ( int i=0; i<n; i++ ) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans=1;
  for ( int i=1; i<n; i++ ) {
    if ( v[i]>v[i-1] )
      ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int V, K; cin >> V >> K;
  vector<vector<int>> g(V);
  for (int i = 0; i < V-1; i++) {
    int u, v; cin >> u >> v; u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int res = V;
  auto dfs = [&](auto f, int n, int p, int d) -> int {
    if (d == 0) return 0;
    int cnt = 1;
    for (auto x : g[n]) {
      if (x == p) continue;
      cnt += f(f, x, n, d-1);
    }
    return cnt;
  };
  for (int i = 0; i < V; i++) {
    if (K % 2 == 0) res = min(res, V - dfs(dfs, i, -1, K/2+1));
    else {
      for (auto x : g[i]) {
        res = min(res, V - dfs(dfs, i, x, K/2+1) - dfs(dfs, x, i, K/2+1));
      }
    }
  }
  cout << res << endl;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n) {


	string  str = to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size() / 2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if (str[i] != str[str.size() - i - 1]) {
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m, k;
	ll sum=0;
	c_p_c();
	// cin>>n;
	string s;
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
	{
		/* code */
		sum+=s[i]-'0';
	}
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}


Measured memory_bytes: 3716
#include<stdio.h>
#include<string.h>

const int maxn= 100;
char s[maxn];

int main()
{
	while(scanf("%s",s) == 1)
	{
		int ok = 0;
		if(strcmp(s,"KIHBR") == 0) ok = 1;
		if(strcmp(s,"AKIHBR") == 0) ok = 1;
		if(strcmp(s,"KIHABR") == 0) ok = 1;
		if(strcmp(s,"KIHBAR") == 0) ok = 1;
		if(strcmp(s,"KIHBRA") == 0) ok = 1;
		if(strcmp(s,"AKIHABR") == 0) ok = 1;
		if(strcmp(s,"AKIHBAR") == 0) ok = 1;
		if(strcmp(s,"AKIHBRA") == 0) ok = 1;
		if(strcmp(s,"KIHABAR") == 0) ok = 1;
		if(strcmp(s,"KIHABRA") == 0) ok = 1;
		if(strcmp(s,"KIHBARA") == 0) ok = 1;
		if(strcmp(s,"AKIHABAR") == 0) ok = 1;
		if(strcmp(s,"AKIHABRA") == 0) ok = 1;
		if(strcmp(s,"AKIHBARA") == 0) ok = 1;
		if(strcmp(s,"KIHABARA") == 0) ok = 1;
		if(strcmp(s,"AKIHABARA") == 0) ok = 1;
		
		if(ok) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

immutable inf = 101101101;
int n, m;
int[][] adj;

void main() {
    scan(n, m);
    adj = new int[][](n, 0);

    int ai, bi;

    foreach (i ; 0 .. m) {
        scan(ai, bi);
        ai--;
        bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto d = new int[](n);
    d[] = inf;
    d[0] = 0;

    auto q = DList!int();
    q.insertBack(0);

    while (!q.empty) {
        auto u = q.front;
        q.removeFront();

        if (u == n - 1) break;

        foreach (v ; adj[u]) {
            if (d[v] == inf) {
                d[v] = d[u] + 1;
                q.insertBack(v);
            }
        }
    }

    writeln(d[n - 1] == 2 ? "POSSIBLE" : "IMPOSSIBLE");
    
}




void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 22908
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
  if b[i]>a[i]:
    b[i]-=a[i]
    if b[i]<a[i+1]:
      a[i+1]-=b[i]
      ans+=a[i]+b[i]
    else:
      ans+=a[i]+a[i+1]
      a[i+1]=0
  else:
    ans+=b[i]
print(ans)

Measured memory_bytes: 18624
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=300005;

struct Edge{
	int v,f,nxt;
}edge[6*N];
int head[N],cur[N];
int n,cnt,s,t,ecnt;
int a[N],b[N],d[N];
bool spe[N],vis[N];

inline void AddEdge(int u,int v,int c1,int c2) {
	edge[ecnt]=(Edge){v,c1,head[u]},head[u]=ecnt++;
	edge[ecnt]=(Edge){u,c2,head[v]},head[v]=ecnt++;
}
void Build() {
	memset(head,-1,sizeof(head));
	scanf("%d",&n); cnt=2*n;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++)
		if(!vis[i]) {
			int x=i;
			do {
				vis[x]=true;
				x=a[x];
				AddEdge(cnt,x,INF,INF);
			}while(!vis[x]);
			cnt++;
		}
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++)
		if(!vis[i]) {
			int x=i;
			do {
				vis[x]=true;
				x=b[x];
				AddEdge(cnt,x+n,INF,INF);
			}while(!vis[x]);
			cnt++;
		}
	s=cnt,t=cnt+1;
	for(int i=0;i<n;i++) {
		if(a[i]==i&&b[i]==i)
			AddEdge(s,i,1,0),AddEdge(i,t,1,0);
		else if(a[i]==i&&b[i]!=i) AddEdge(s,i+n,1,0);
		else if(a[i]!=i&&b[i]==i) AddEdge(i,t,1,0);
		else if(a[i]==b[i]) AddEdge(i,i+n,1,1);
		else AddEdge(i,i+n,1,0);
	}
}
bool Bfs() {
	for(int i=0;i<=t;i++) {
		cur[i]=head[i];
		d[i]=INF;
	}
	queue<int>Q;
	d[s]=0; Q.push(s);
	while(!Q.empty()) {
		int u=Q.front(); Q.pop();
		for(int i=head[u];i!=-1;i=edge[i].nxt) {
			int v=edge[i].v;
			if(edge[i].f>0&&d[v]>d[u]+1) {
				d[v]=d[u]+1;
				Q.push(v);
			}
		}
	}
	return d[t]!=INF;
}
int Dfs(int u,int flow) {
	if(u==t) return flow;
	int sum=0,delta=0;
	for(int &i=cur[u];i!=-1;i=edge[i].nxt) {
		int v=edge[i].v;
		if(d[v]==d[u]+1&&edge[i].f>0) {
			delta=Dfs(v,min(flow,edge[i].f));
			flow-=delta;
			edge[i].f-=delta;
			edge[i^1].f+=delta;
			sum+=delta;
			if(!flow) break;
		}
	}
	if(sum==0) d[u]=-1;
	return sum;
}
int Dinic() {
	int maxflow=0;
	while(Bfs())
		maxflow+=Dfs(s,INF);
	return maxflow;
}
int main() {
	//freopen("door.in","r",stdin);
	//freopen("door.out","w",stdout);
	Build();
	printf("%d\n",n-Dinic());
	return 0;
}


Measured memory_bytes: 20352
MOD = 10**9 + 7
s = input()
now = [0] * 13
now[0] = 1
k = 1
for c in reversed(s):
    nxt = [0] * 13
    if c == '?':
        for i in range(10):
            a = k * i % 13
            for j in range(13):
                nxt[(j + a) % 13] += now[j]
                nxt[(j + a) % 13] %= MOD
    else:
        i = int(c)
        a = k * i % 13
        for j in range(13):
            nxt[(j + a) % 13] += now[j]
            nxt[(j + a) % 13] %= MOD
    now = nxt
    k = k * 10 % 13
print(now[5])


Measured memory_bytes: 43372
#include <cstdio>
#include <queue>
#include <string.h>
using namespace std;

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

inline int enc(int y,int x){
    return 52*y+x;
}

inline int enc2(int ty, int tx, int ky, int kx){
    return enc(ty,tx)*52*52 + enc(ky,kx);
}

int main(){
    int w,h,tx,ty,kx,ky;
    static char board[52][52];
    static char dist[52*52*52*52];
    while(scanf("%d%d",&w,&h),w){
        queue< pair<int,int> > Q;
        scanf("%d%d%d%d",&tx,&ty,&kx,&ky);
        for(int i=0; i<52; i++)
            for(int j=0; j<52; j++)
                board[i][j] = 1;
        for(int i=1; i<=h; i++)
            for(int j=1; j<=w;j++){
                int x;
                scanf("%d",&x);
                board[i][j] = x;
            }
        memset(dist,101,sizeof(dist));
        if(enc(ty,tx)==enc(ky,kx)){
            printf("%d\n",0);
            goto end;
        }

        dist[enc2(ty,tx,ky,kx)] = 0;
        for(int k=0; k<4; k++){
            int nty = ty + dy[k],
                ntx = tx + dx[k],
                nky = ky - dy[k],
                nkx = kx - dx[k];
            if(board[nty][ntx]) nty = ty, ntx = tx;
            if(board[nky][nkx]) nky = ky, nkx = kx;
            if(enc(nty,ntx)==enc(nky,nkx)){
                printf("%d\n",1);
                goto end;
            }
            int p = enc2(nty,ntx,nky,nkx);
            if(1 < dist[p]){
                dist[p] = 1;
                Q.push( make_pair(p,2) );
            }
        }
        while(!Q.empty()){
            ty = (Q.front().first/(52*52))/52;
            tx = (Q.front().first/(52*52))%52;
            ky = (Q.front().first%(52*52))/52;
            kx = (Q.front().first%(52*52))%52;
            int d = Q.front().second;
            if(d > 100) break;
            Q.pop();
            for(int k=0; k<4; k++){
               int nty = ty + dy[k],
                   ntx = tx + dx[k],
                   nky = ky - dy[k],
                   nkx = kx - dx[k];
               if(board[nty][ntx]) nty = ty, ntx = tx;
               if(board[nky][nkx]) nky = ky, nkx = kx;
               if(enc(nty,ntx)==enc(nky,nkx)){
                    printf("%d\n",d);
                    goto end;
               }
               int p = enc2(nty,ntx,nky,nkx);
               if(d < dist[p]){
                   dist[p] = d;
                   Q.push( make_pair(p,d+1) );
               }
           }
        }
        printf("NA\n");
end:;
    }
}

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

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

  if(a%2 == 0 || b%2 == 0 || c%2 == 0) cout << "0" << "\n";
  else cout << min(a*b, min(b*c, c*a)) << "\n";
  return 0;
}


Measured memory_bytes: 256
using System;
class program
{
    static void Main(string[] args)
    {
        int num = int.Parse(Console.ReadLine());
        float z;
        for(int k=1;k<=9;k++)
        {
            
            z = (float)num / (float)k;
            int y;
            y=(int)z * k ;


            if (y==num&&(int)z<=9)
            {
                Console.WriteLine("Yes");
                Environment.Exit(0);
            }

        }
            Console.WriteLine("No");
        
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
    string N, N_;
    cin >> N;
    N_ = N;

    reverse(N_.begin(), N_.end());

    if(N_ == N){
      cout << "Yes";
    }else{
      cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
long f(long x){if(x==1)return 1l;return x*f(x-1)%1000000007;}
int main()
{
	long n,m;std::cin>>n>>m;
	std::cout<<(abs(n-m)<2?f(n)*f(m)%1000000007*(2-abs(n-m))%1000000007:0)<<std::endl;
}

Measured memory_bytes: 1792
d,g  = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]

ans = float('inf')

for bit in range(1<<d):
  sum = 0
  cnt = 0
  rem = set(range(d))
  for i in range(d):
    if bit & 1<<i:
      sum += pc[i][0]*(i+1)*100 + pc[i][1]
      cnt += pc[i][0]
      rem.discard(i)
    
  if sum < g:
    u = max(rem)
    n = min(pc[u][0],  -( -(g-sum)//((u+1)*100) ))
    cnt += n
    sum += n*(u+1)*100
    
  if sum >= g:
    ans = min(ans, cnt)
    

print(ans)

Measured memory_bytes: 3064
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define mp make_pair
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;
vector<int> solve(ll n){
    vector<int> v;
    while(n > 0){
        v.pb(n % 2);
        n /= 2;
    }
    while(v.size() < 40)
    v.pb(0);
    reverse(v.begin(), v.end());
    return v;
}

int main()
{
   FASTIO
   int n;
   cin >> n;
   ll k;
   cin >>k;
   ll a[n];
   vector<int> A[n];
   rep(i, 0, n){
   cin >> a[i];
   A[i] = solve(a[i]);
   }
   vector<int> K = solve(k);
   int f = 0;
   rep(i, 0, 40){
       if(K[i] == 1){
           f = i;
           break;
       }
   }
   vector<int> ans;
   bool small = false;
   rep(j, 0, 40){
       int c = 0;
       rep(i, 0, n){
           if(A[i][j] == 1)
           c++;
       }
       if(c * 2 >= n){
       ans.pb(0);
       if(K[j] == 1)
       small = true;
       }
       else{
            if(small || K[j] == 1)
            ans.pb(1);
            else
            ans.pb(0);
       }
   }
   reverse(ans.begin(), ans.end());
   ll t = 1;
   ll val = 0;
   rep(i, 0, ans.size()){
       val += (ans[i] * t);
       t = (t << 1);
   }
   t = 0;
   rep(i, 0, n){
       t += (val ^ a[i]);
   }
   cout << t ;
    return 0;
}




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

int main()
{
	int K;
	int bottomOfRange;
	int cielingOfRange;
	cin >> K >> bottomOfRange >> cielingOfRange;

	bool result = false;
	for (int index = 0; index * K <= cielingOfRange; ++index) {
		if (index * K >= bottomOfRange) {
			result = true;
			break;
		}
	}
	const auto outputMessage = result ? "OK" : "NG";

	cout << outputMessage;
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int,input().split()))
q = int(input())

dp = [0] *( 10 ** 5 +10)

bc = [input() for _ in range(q)]

for ai in a:
  dp[ai] += 1
ans = 0
for i in range(1,len(dp)):
  ans += dp[i] * i
  
for bci in bc:
  b,c = map(int,bci.split())
  ans += (dp[b] * c) -(dp[b] * b)
  print(ans)
  dp[c] += dp[b] 
  dp[b] = 0


Measured memory_bytes: 21692
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,s=0,k,m=0,n=0;
	cin>>a;
	int b[a];
	for(int i=1;i<=a;i++)
	{
		cin>>b[i];
		s+=b[i];
	}
	k=s/a;
	for(int i=1;i<=a;i++) 
	{
		m+=(k-b[i])*(k-b[i]);
		n+=(k+1-b[i])*(k+1-b[i]);
	}
	if(m>n)
	swap(m,n);
	cout<<m<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, t;
  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
  return 0;
}


Measured memory_bytes: 256
// you**can**do**anything :~  
#include <bits/stdc++.h>
#include<iostream> 
#include<algorithm> 
#include<vector> 
#define ll long long
//#define  loop(y)  for((int)i=0 ; i<int(y) ,i++)
const int maxn=5e5+10;
using namespace std;
int main() {
cin.tie(0); cout.tie(0);
//ios_base :: sync_with_stdio( 0 ) ;
 ll n ,m ,x,sum=0;
 cin>>n>>m;
 for(int i=0 ;i<m ;i++){
 	cin>>x;
 	sum+=x;
}
if(sum<=n)
cout<<n-sum;
else
cout<<"-1";


}

Measured memory_bytes: 3632
#include<iostream>
#include <algorithm>

int main()
{
  int A,B;
  std::cin >> A >> B;
  
  int maxp;
  
  maxp = std::max(A,B);
  if(maxp==A)
    A--;
  else
    B--;
  maxp+=std::max(A,B);
  std::cout<< maxp << std::endl;
}
  
  

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:1710886400")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

bool intersect(pair <long long, long long> a, pair <long long, long long> b) {
	return max(a.first, b.first) <= min(a.second, b.second);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for (int i = 0; i < n; ++i) {
		int j = n - 1 - i;
		pair <long long, long long> x1, x2, x3, x4;
		x1 = { a - i * 1ll * d, a - i * 1ll * c };
		x2 = { a + i * 1ll * c, a + i * 1ll * d };
		x3 = { b - j * 1ll * d, b - j * 1ll * c };
		x4 = { b + j * 1ll * c, b + j * 1ll * d };
		if (intersect(x1, x3) || intersect(x1, x4) ||
			intersect(x2, x3) || intersect(x2, x4)) {
			cout << "YES\n";
			my_return(0);
		}
	}
	cout << "NO\n";

	my_return(0);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (n == 2) {
		cout << "Borys" << endl;
	} else if ((b - a) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
n,k = mis()

mod = n % k

mod_k = abs(mod - k)

if mod_k < mod:
    print(mod_k)
else:
    print(mod)

Measured memory_bytes: 3924
#include<iostream>
#include<bitset>
using namespace std;
int main(void){
    int n,c,benefit,ma=-1000000000;
    cin>>n;
    bool f[n][10];
    int p[n][11];
    for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin>>f[i][j];
    for(int i=0;i<n;i++)for(int j=0;j<=10;j++)cin>>p[i][j];
    bitset<10>bit;
    for(int b=1;b<1<<10;b++){
        bit=b;
        benefit=0;
        for(int i=0;i<n;i++){
            c=0;
            for(int j=0;j<10;j++)c+=(bit[j]&&f[i][j]);
            benefit+=p[i][c];
        }
        ma=max(ma,benefit);
    }
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n=sc.nextInt();
			if( n == 0 ) break;
			int[] ans = new int[n+1];
			ans[0] = n;
			dfs(1, n, ans);
		}
	}
	
	void dfs(int i, int num, int ans[]) {
//		debug(i, num);
//		if(i == n+1) return;
		if(num == 0) {
			print(ans);
			return;
		}
		for(int j=min(num,ans[i-1]);j>=1;j--) {
			ans[i] = j;
			dfs(i+1, num - j, ans);
			ans[i] = 0;
		}
	}
	
	void print(int[] ans) {
		System.out.print(ans[1]);
		for(int i=2; i!= n+1 && ans[i]!=0;i++) System.out.print(" " + ans[i]);
		System.out.println();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

def main():
    N, M, X = map(int, input().split())
    S = [list(map(int,input().split())) for i in range(N)]
    ret = 10**7
    for i in range(2 ** N):
        TA = [0] * M
        TC = 0
        for j in range(N):    #
            if (i >> j) & 1:  #
                TC += S[j][0]
                for m in range(M):
                    TA[m]+=S[j][m+1]  #
        if min(TA)>=X:
            ret = min(ret, TC)
    if ret == 10**7:
        print(-1)
    else:
        print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, T) for(int i=k; i<T; i++)
#define reps(i ,S) for(int i=0; i<S; i++)

int N;
int W, H;
bool field[100][100];
int main(){
    scanf("%d%d%d", &W, &H, &N);
    fill(field[0], field[H], true);
    int x, y, a;
    for(int i=0;i<N;i++){
        scanf("%d%d%d", &x, &y, &a);
        if(a==1){
            reps(i, H){
                rep(j, 0, x){
                    field[i][j] = false;
                }
            }
        }
        else if(a==2){
            reps(i, H){
                rep(j, x, W){
                    field[i][j] = false;
                }
            }
        }
        else if(a==3){
            reps(j, W){
                rep(i, 0, y){
                    field[i][j] = false;
                }
            }
        }
        else{
            reps(j, W){
                rep(i, y, H){
                    field[i][j] = false;
                }
            }
        }
    }
    int cnt = 0;
    reps(i, H){
        reps(j , W){
            if(field[i][j]) cnt++;
        }
    }
    printf("%d\n", cnt);

}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	vector<int> p(n);
	vector<int> q(n);
	for(auto &x : p){
		cin>>x;
	}
	for(auto &x : q){
		cin>>x;
	}
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		a[i] = i + 1;
	}
	int indp, indq;
	int ind = 0;
	while(true){
		if(p == a)indp = ind;
		if(q == a)indq = ind;
		ind++;
		if(!next_permutation(a.begin(), a.end()))break;
	}
	cout<<abs(indp - indq)<<endl;

	return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;

constexpr int INF = 1LL<<60;
constexpr int MOD = 1000000007;
//constexpr int MAX_N = 1005;
constexpr int MAX_H = 1005;
constexpr int dx[] = {0, 1};
constexpr int dy[] = {1, 0};

int h, w, n, fld[MAX_H][MAX_H], dp[MAX_H][MAX_H];

bool Solve() {
    cin >> h >> w >> n;
    if (!h) return false;

    memset(fld, -1, sizeof(fld));
    memset(dp, 0, sizeof(dp));

    for (int y = 1; y <= h; ++y) {
        for (int x = 1; x <= w; ++x) {
            cin >> fld[x][y];
        }
    }

    dp[1][1] = n - 1;
    for (int y = 1; y <= h; ++y) {
        for (int x = (y == 1 ? 2 : 1); x <= w; ++x) {
            for (int i = 0; i < 2; ++i) {
                int tx = x - dx[i], ty = y - dy[i];
                dp[x][y] += dp[tx][ty] / 2 + (dp[tx][ty] % 2 && fld[tx][ty] == i ? 1 : 0);
            }
        }
    }

    for (int y = 1; y <= h; ++y) {
        for (int x = 1; x <= w; ++x) {
            fld[x][y] += dp[x][y];
            fld[x][y] %= 2;
        }
    }

    {
        int x = 1, y = 1;

        while (fld[x][y] != -1) {
            int nx = x + dx[fld[x][y]];
            y += dy[fld[x][y]];
            x = nx;
        }

        cout << y << " " << x << endl;
    }

    return true;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    while (Solve());
}

Measured memory_bytes: 18808