akhauriyash/Code-Regression huggingface dataset:
import math

N = int(input())
A = list(map(int, input().split()))

mincnt = 250

for i in range(N):
    tmp = A[i]
    tmpcnt = 0
    while tmp%2 == 0:
        tmp = math.floor(tmp/2)
        tmpcnt += 1

    if mincnt > tmpcnt:
        mincnt = tmpcnt

print(mincnt)


Measured memory_bytes: 3060
#include <stdio.h>
#define N 100

int main(){
  int i,j,minj,A[N],n,stac,count=0;

  scanf("%d",&n);

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

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj])minj=j;
    }
    if(i!=minj)count++;
    stac=A[i];
    A[i]=A[minj];
    A[minj]=stac;
  }

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],count);
  return 0;
}

Measured memory_bytes: 600
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);

int main()
{   
    flash

    ll n , m;
    cin >> n >> m;

    ll h[n];
    for(ll i=0;i<n;i++) cin >> h[i];

    bool vis[n];
    memset(vis , true , sizeof(vis));

    int ans=0;

    for(int i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        a-- , b--;
        if(h[a] > h[b]) swap(a , b);
        vis[a] = false;
        if(h[a]==h[b]) vis[b] = false;
    }

    for(ll i=0;i<n;i++){
        if(vis[i]) ans++;
        //ans+=(vis[i]);
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 4524
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    bool yes = false;
    FOR(i,1,10)FOR(j,1,10){
        if(i * j == n){
            yes = true;
        }
    }
    if(yes){
        PUTS("Yes");
    }
    else{
        PUTS("No");
    }
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

vl score(1 << 16);
vi stand(1 << 16);
vl dp(1 << 16, -INF);

//nのkbit表現を表示する
void print_bit(ll n, ll k) {
	ll m = (1LL << (k - 1));;
	while (m >= 1) {
		if ((n&m)) {
			cout << 1;
		}
		else {
			cout << 0;
		}
		m >>= 1;
	}
	cout << endl;
}


ll dfs(int n) {
  if (dp[n] != -INF) return dp[n];
  if (stand[n] == 1) return dp[n] = score[n];
  int m = n;
  ll ans = score[n];
  do {
    int m1 = m, m2 = n - m1;
    if (m1 == 0 || m2 == 0) {
      m = (m - 1)&n;
      continue;
    }
    chmax(ans, score[m1] + dfs(m2));
    m = (m - 1)&n;
  } while (m != n);
  dp[n] = ans;
  return ans;
}

int main() {
  int n;
  cin >> n;
  vll a(n, vl(n));
  rep (i, n) {
    rep (j, n) {
      cin >> a[i][j];
    }
  }
  int m = 1 << n;
  rep (i, m) {
    rep (j, n) {
      for (int k = j + 1; k < n; k++) {
        if (((1 << j) & i) && ((1 << k) & i)) {
          score[i] += a[j][k];
        }
      }
    }
    rep (j, n) {
      if (i & (1 << j)) stand[i]++;
    }
  }
  dp[0] = 0;
  cout << dfs(m - 1) << endl;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 555;

int n,m;
char t[N][N], a[N][N], b[N][N];

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

    cin >> n >> m;
    forn(i,n) cin >> t[i];

    fill(a[0], a[n+2], '.');
    fill(b[0], b[n+2], '.');

    forsn(j,1,m-1) {
        a[0][j] = '#'; b[n-1][j] = '#';
        if (j%2) forsn(i,1,n-1) a[i][j] = '#';
        else forsn(i,1,n-1) b[i][j] = '#';
    }
    forn(i,n) forn(j,m) if (t[i][j] == '#')
        a[i][j] = b[i][j] = '#';

    forn(i,n) { forn(j,m) cout << a[i][j]; cout << '\n'; }
    cout << '\n';
    forn(i,n) { forn(j,m) cout << b[i][j]; cout << '\n'; }

    return 0;
}


Measured memory_bytes: 1536
n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [0]*(s+1)
dp[0] = pow(2, n, MOD)
inv_2 = pow(2, MOD-2, MOD)
for a in A:
    for j in reversed(range(s+1)):
        if s < j+a:
            continue
        dp[j+a] += dp[j]*inv_2
        dp[j+a] %= MOD

print(dp[-1] % MOD)

Measured memory_bytes: 68540
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1005;
const int MOD = 1e9+7;
char arr[N][N];
int dp[N][N];
vector<vector<int> > g;
int n,m;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    
    for(int i=1;i<=n;i++)
    	cin>>arr[i]+1;

    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		if(i==j && i==1){
    			dp[i][j]=1;
    			continue;
    		}
    		if(arr[i][j]=='.'){
    			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    		}
    		else
    			dp[i][j]=0;
    	}
    }

/*    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++)
    		cout<<dp[i][j]<<' ';
    	cout<<endl;
    }*/

    cout<<dp[n][m];
    return 0;
}

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

int main() {
  ll n,x,ans=1e9;
  cin>>n>>x;
  vector<ll> a(n);
  for(ll i=0; i<n; i++) {
    ll m; cin>>m;
    a[i] = abs(m - x);
    ans = min(ans,a[i]);
  }
  for(ll i=0; i<n; i++){
    ans = __gcd(a[i],ans);
  }
  cout<<ans;
}

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

int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)
      break;

    int ans = 0;
    for(int i=1; i<=n/2; i++){
      int temp = 0;
      for(int j=i; temp < n; j++){
        temp += j;
      }
      if(temp == n)
        ans += 1;
    }

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

Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int[] NM = readLineInt();
		int N = NM[0];
		int M = NM[1];
		int O = NM[2];
		
		print(O+" "+N+" "+M);
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC


	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N, M; cin >> N >> M;
  string A[N], B[M];
  rep(i, N){
    cin >> A[i];
  }
  rep(i, M){
    cin >> B[i];
  }
  bool ans = false;
  rep(i, N-M+1){
    rep(j, N-M+1){
      bool can = true;
      rep(k, M){
        rep(l, M){
          if(A[i+k][j+l]!=B[k][l]){
            can = false; 
          }
        }
      }
      if(can) ans = true;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>

int main(){
	int num;
	std::cin >> num;
	for(int i = num;i <1000;i++){
		if(i < 10){
			std::cout << i;
			break;
		}else if(i < 100){
			std::string str;
			str=std::to_string(i);
			if(str[0] == str[1]){
				std::cout << i;
				break;
			}
		}
		else {
			std::string str;
			str = std::to_string(i);
			if (str[0] == str[1] && str[0] == str[2]){
				std::cout << i;
				break;
			}
		}
	}
	std::cout <<'\n';
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define mem(x,val) memset(x,val,sizeof(x))
//#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pii>
 
const int mod=1e9+7;
const int N=2e5+10;
const int MAXN=1e6+10;
const int INF=1e18;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
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 pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

vi divi[MAXN+10];

void pre(){
    rep(i,2,MAXN){
        for(int j=i;j<=MAXN;j+=i){
            divi[j].pb(i);
        }
    }
}

int mark[MAXN+10],a[MAXN];

void solve(){
    int n;
    cin>>n;
    int g;
    rep(i,1,n){
        cin>>a[i];
        g=(i==1)?a[i]:(__gcd(g,a[i]));
    }
    mem(mark,0);
    if(g!=1){
        cout<<"not coprime"<<endl;
    }
    else{
        rep(i,1,n){
            if(a[i]==1){
                mark[1]=1;
                continue;
            }
            for(auto u:divi[a[i]]){
                if(mark[u]==1){
                    cout<<"setwise coprime"<<endl;
                    return;
                }
                mark[u]=1;
            }
        }
        cout<<"pairwise coprime"<<endl;
    }
}


int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("inputf.in", "r", stdin);
    //     //freopen("outputf.in", "w", stdout);
    // #endif
    SPEED;
    pre();
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        solve();
        t1++;
        if(t1>T)
            break;
    }
}

Measured memory_bytes: 195196
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

/*
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


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

    int N, K;
    cin >> N >> K;
    int A[N+1];
    A[0] = 0;
    for(int i=1;i<=N;i++){
        A[i] = A[i-1] + i;
    }
    int ans = 0;
    for(int i=K;i<=N;i++){
        ans += (A[N] - A[N-i]) - A[i-1] + 1;
        ans %= MOD;
    }
    cout << (ans + 1) % MOD << endl;
}

Measured memory_bytes: 5152
# coding: utf-8
def main():
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    A = [a,b,c]
    n = int(input())
    B = []
    C = []
    for i in range(n):
        B.append(int(input()))
    for i in range(3):
        for j in range(3):
            if A[i][j] in B:
                C.append(i*10 + j)
    D = []
    if 0 in C:
        D += [1,4,7]
    if 1 in C:
        D += [1,5]
    if 2 in C:
        D += [1,6,8]
    if 10 in C:
        D += [2,4]
    if 11 in C:
        D += [2,5,7,8]
    if 12 in C:
        D += [2,6]
    if 20 in C:
        D += [3,4,8]
    if 21 in C:
        D += [3,5]
    if 22 in C:
        D += [3,6,7]
    for i in range(1,9):
        if D.count(i) == 3:
            print("Yes")
            quit()
    print("No")
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;


int bcnt(string s){
	int bc=0;
	for(auto x: s) if(x=='B') bc++;
	return bc;
}

int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	
	int n=sz(s), bc=bcnt(s);
	if(bc==0 || bc==n){ puts("0"); return 0;}

	auto s2=s; reverse(all(s2));
	int ct=0;
	rep(i,n-1) if(s2[i] != s2[i+1]) ct++;
	
	cout << ct << endl;
	return 0;
}


Measured memory_bytes: 512
a=input()
b=int(a[:2])
c=int(a[2:])
y=0
m=0
if c>0 and c<13:
    m=1
if b>0 and b<13:
    y=1
if m==1==y:
    print("AMBIGUOUS")
elif m==y==0:
    print("NA")
elif m==1:
    print("YYMM")
else:
    print("MMYY")

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

for i in range(1000):
    n = str(i)
    if len(n) == N:
        if all( n[s-1] == str(c) for s,c in A):
            print(i)
            break
else:
    print(-1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;


int main(){
    int n,q;
    cin>>n>>q;
    n*=2;
    ll a[n],b[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ans=a[0]+a[n-1];
    int posi=0,ze=0;
    multiset<ll> st;
    rep(i,n-2){
        ans+=max(a[i+1],b[i+1]);
        if(a[i+1]<b[i+1])posi++;
        st.insert(abs(a[i+1]-b[i+1]));
    }
    rep(i,q){
        ll p,x,y;
        cin>>p>>x>>y;
        p--;
        if(p==0||p==n-1)ans+=(ll)(x-a[p]);
        else{
        ans+=max(x,y);
        ans-=max(a[p],b[p]);
        auto it=st.find(abs(a[p]-b[p]));
        st.erase(it);
        st.insert(abs(x-y));
        if(a[p]<b[p])posi--;
        if(x<y)posi++;
        }
        a[p]=x;
        b[p]=y;
        if(posi%2==0)cout<<ans<<endl;
        else cout<<ans-*st.begin()<<endl;
    }
}

Measured memory_bytes: 14208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		
		if (A <= B) {
			if (C <= B && A <= C) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			if (C >= B && A >= C) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(int argc, const char * argv[]){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a < b && b < c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 2056
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ans = int.MaxValue;
        for (int i = 0; i <= n - k; i++)
        {
            var b = Math.Abs(a[i + k - 1] - a[i]);
            var b2 = Math.Min(Math.Abs(a[i]), Math.Abs(a[i + k - 1])) + b;
            ans = Math.Min(ans, b2);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 20320
n = int(input())
d_list = [int(i) for i in input().rstrip().split(' ')]
d_list.sort()

a = int(n/2) -1
b = int(n/2)

if d_list[a] == d_list[b]:
  print(0)
else:
  print(d_list[b] - d_list[a])


Measured memory_bytes: 14120
n=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                A=list((L[i],L[j],L[k]))
                if 2*max(A)<sum(A):
                    ans+=1           
print(ans)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define rep(x) for(int i=0;i<x;i++)
#define reprev(x) for(int i=x-1;i>=0;i--)
#define repdef(x,n) for(int i=x;i<n;i++)
#define Debug(x) cout<<x<<"\n";
#define Debug2(x,y) cout<<x<<" "<<y<<"\n";
#define TEST(t) while(t--)
#define mod 1000000007
#define MAX 100005
int fast_exp(ll base,ll exp){
    if(exp==1){
        return base%mod;
    }
    if(exp&1){
        int ans=fast_exp(base,exp-1);
        return (base%mod*ans%mod)%mod;
    }else{
        int ans=fast_exp(base,exp/2);
        return (ans%mod*ans%mod)%mod;
    }
}
int fast_exp_itr(ll base,ll exp,ll p){
    ll ans=1;
    base=base%p;
    while(exp>0){
        if(exp&1){
            ans=((ans%p)*(base%p))%p;
        }
        exp>>=1;
        base=((base%p)*(base%p))%p;
    }
    return ans;
}
int euclid_gcd(int a,int b){
    if(b==0){
        return a;
    }
    return euclid_gcd(b,a%b);
}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    pair<int,int> arr[n];
    rep(n){
    	cin>>arr[i].first;
    	arr[i].second=i+1;
    }
    sort(arr,arr+n);
    rep(n){
    	cout<<arr[i].second<<" ";
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 1664
# ABC137 D - Summer Vacation
import heapq as hp
n,m=map(int,input().split())
AB=[[] for i in range(m+1)]
l=[]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        AB[a].append(-b)
ans=0
hp.heapify(l)
for ab in AB:
    for x in ab:
        hp.heappush(l,x)
    if len(l)>0:
        ans-=hp.heappop(l)
print(ans)



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

void replace_all(string& s,string from,string to){
	string::size_type p = 0;
	while(p=s.find(from,p), p!=string::npos){
		s.replace(p,from.length(),to);
		p+=to.length();
	}
}

int main(void){
	int i,j,k,l,count;
	string s,ts,num[3]={"0","1","2"};
	string to0[6]={"(0*0)","(0*1)","(0*2)","(1*0)","(2*0)","(0+0)"};
	string to1[6]={"(1*1)","(1*2)","(2*1)","(0+1)","(1+0)","(1+1)"};
	string to2[6]={"(2*2)","(0+2)","(1+2)","(2+0)","(2+1)","(2+2)"};

	while(cin>>ts && ts!="."){
		count = 0;
		replace_all(ts,"--","");

		for(i=0;i<=2;i++){
			for(j=0;j<=2;j++){
				for(k=0;k<=2;k++){
					s = ts;
					replace_all(s,"P",num[i]);
					replace_all(s,"Q",num[j]);
					replace_all(s,"R",num[k]);

					while(s.length() != 1){
						replace_all(s,"-1","1");
						replace_all(s,"-2","0");
						replace_all(s,"-0","2");

						for(l=0;l<6;l++){
							replace_all(s,to0[l],"0");
							replace_all(s,to1[l],"1");
							replace_all(s,to2[l],"2");
						}
					}
					if(s=="2") count++;
				}
			}
		}

		cout<<count<<endl;
	}

	return 0;
}

Measured memory_bytes: 924
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,H,W;cin>>N>>H>>W;
  cout << (N-H+1)*(N-W+1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    int n;cin>>n;
    int q;cin>>q;
    vector<int> v[n+1];
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
        
    }
    ll cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rep(i,0,q){
        ll p,x;cin>>p>>x;
        cnt[p]+=x;
    }
    ll ans[n+1];
    queue<pll> qq;
    qq.push(make_pair(1,cnt[1]));
    ans[1]=cnt[1];
    bool used[n+1];
    fill(used,used+n+1,false);
    used[1]=true;
    while(qq.size()>0){
        pll p=qq.front();
        qq.pop();
        ll now=p.first,ata=p.second;
        rep(i,0,v[now].size()){
            ll ne=v[now][i];
            if(used[ne])continue;
            used[ne]=true;
            qq.push(make_pair(ne,ata+cnt[ne]));
            ans[ne]=ata+cnt[ne];
        }
    }
    rep(i,1,n+1)cout<<ans[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 20468
#include<cstdio>
int N,T,A,X;
int main(){
  scanf("%d%d%d",&N, &T, &A);
  int res=0;
  int cc=1<<30;
  for(int i=1;i<=N;i++){
    scanf("%d",&X);
    int d=(T*1000-X*6)-A*1000;
    if(d<0)d=-d;
    if(cc>d)cc=d,res=i;
  }
  printf("%d\n",res);
}


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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s,t;
    int a,b;
    string u;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(s == u){
        a--;
    }else{
        b--;
    }
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI adj[110];
int indeg[110] = {};
int V,E;

int DAG_check(int indeg[]){
    stack<int> st;
    REP(i,V){
        if(indeg[i] == 0) st.push(i);
    }
    VI ans;

    while(!st.empty()){
        int i = st.top(); st.pop();
        ans.eb(i);
        for(auto j : adj[i]){
            indeg[j]--;
            if(indeg[j] == 0) st.push(j);
        }
    }

    if(SZ(ans) == V) return 0;
    else return 1;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E;
    REP(i,E){
        int s,t; cin >> s >> t;
        adj[s].eb(t);
        indeg[t]++;
    }
    cout << DAG_check(indeg) << endl;

}



Measured memory_bytes: 3212
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
	int n, x;
	while (1) {
		int correct = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		for (int i = 1; i <= n - 2; i++)
			for (int j = i + 1; j <= n - 1; j++)
				for (int k = j + 1; k <= n; k++)
					if (i + j + k == x) correct++;

		cout << correct << endl;
	}

	return 0;
}



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

using namespace std;

#define ll long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);
#define F first
#define S second


typedef pair<int, int> P;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;

const ll INF = 1ll << 50;

struct Edge {
  int from, to, cost;
  Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool operator<(const Edge &e, const Edge &f) {
  return e.cost > f.cost;
}

vector<ll> dijkstra(const Graph &g, int s) {
  vector<ll> d(g.size(), INF);
  d[s] = 0;
  priority_queue<PLL, vector<PLL>, greater<PLL>> que;
  que.push(PLL(0, s));
  while(!que.empty()) {
    ll dist = que.top().F;
    ll v= que.top().S;
    que.pop();
    if(d[v] < dist) continue;
    for(const auto &e : g[v]) {
      if(d[e.to] <= d[v] + e.cost) continue;
      d[e.to] = d[v] + e.cost;
      que.push(PLL(d[e.to], e.to));
    }
  }
  return d;
}


int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  Graph g(n);
  int a, b, c;
  REP(i, n-1) {
    cin >> a >> b >> c;
    g[a-1].pb(Edge(a-1, b-1, c));
    g[b-1].pb(Edge(b-1, a-1, c));
  }

  int q, k; cin >> q >> k;
  vector<ll> dist = dijkstra(g, k-1);
  // REP(i, n) {
  //   cout << dist[i] << endl;
  // }
  vector<ll> ans(q);
  int x, y;
  REP(i, q) {
    cin >> x >> y;
    ans[i] = dist[x-1] + dist[y-1];
  }

  REP(i, q) {
    cout << ans[i] << endl;
  }
  
  
}


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

int		main(void)
{
	int N, max, tmp;

	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	for (int i = 0; i < N - 1; i++)
	{
		max = i;
		for (int j = i + 1; j < N; j++)
		{
			if (a[max] < a[j])
				max = j;
		}
		tmp = a[i];
		a[i] = a[max];
		a[max] = tmp;
	}

	int sum = 1;

	for (int i = 0; i < N - 1; i++)
	{
		if (a[i] > a[i + 1])
			sum++;	
	}
	cout << sum << endl;
}

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

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(n); STR(s);
    vlint leftw(n+1, 0), rightw(n+1, 0);
    vlint lefte(n+1, 0), righte(n+1, 0);
    rep(i, n){
        if (s[i] == 'W'){
            leftw[i] ++;
        }
        else{
            lefte[i] ++;
        }
        leftw[i+1] += leftw[i]; lefte[i+1] += lefte[i];
    }
    for (int i = n-1; i > 0; --i){
        if (s[i] == 'W'){
            rightw[i]++;
        }
        else{
            righte[i]++;
        }
        rightw[i-1] += righte[i];
        righte[i-1] += righte[i];
    }

    lint ans = 2 * n;
    rep1(i, n-1){
        chmin(ans, leftw[i-1] + righte[i+1]);
    }
    chmin(ans, righte[1]); chmin(ans, leftw[n-2]);
    print(ans);

}


Measured memory_bytes: 13008
using DataStructures
f()=(x->parse(Int,x)).(split(readline()))
function m()
	N,Q=f()
	P=FenwickTree(f())
	p=prefixsum
	for _=1:Q
		t,l,r=f()
		inc!(P,l+1,r*(1-t))
		t>0&&println(p(P,r)-(l<1 ? 0 : p(P,l)))
	end
end
m()

Measured memory_bytes: 261768
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdin);
    ll n,x,y;
    cin>>n>>x>>y;
    x--,y--;
    map<ll,ll>m;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            ll dist=min(abs(i-j),abs(x-i)+1+abs(y-j));
            dist=min(dist,abs(y-i)+1+abs(x-j));
            m[dist]++;
        }
    }
    for(ll i=1;i<n;i++){
        cout<<m[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

template <class BidirectionalIterator>
void reverse(BidirectionalIterator first, BidirectionalIterator last) {
    for ( ; first != last && first != --last; ++first){
        std::iter_swap(first, last);
    }
}

int main(){
    long long int n,k;
    long long int sum;
    long long int temp;
    int num;
    string str;
    char buffer[256];
    int i = 0;

    cin >> n >> k;

    sum = k * pow((k - 1), (n - 1));

    //cout << "str.size() = " << str.size() << endl;
    while(1){
        if(sum < 1){
            break;
        }
        temp = sum % 10;
        sum = sum / 10;
        num = temp;
        sprintf(buffer,"%d",num);
        str.push_back(buffer[0]);
        //cout << str[i] << " " << i << '\n';
        i++;
    }
    
    //cout << "str.size() = " << str.size() << endl;
    //cout << str << "\n";

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

    cout << str << '\n';

    return 0;
}

Measured memory_bytes: 384
using System;
class Program
{
  static void Main(string[] args)
  {
    // 入力文字列を取得
    int n = int.Parse(Console.ReadLine());
    string[] aArrayStr = Console.ReadLine().Split(' ');
    string[] bArrayStr = Console.ReadLine().Split(' ');
    string[] cArrayStr = Console.ReadLine().Split(' ');
    
    // A列を数値に変換
    int[] aArray = new int[n];
    for (int a = 0; a < n; a++) {
      aArray[a] = int.Parse(aArrayStr[a]);
    }
    
    // B列を数値に変換
    int[] bArray = new int[n];
    for (int b = 0; b < n; b++) {
      bArray[b] = int.Parse(bArrayStr[b]);
    }
    
    // C列を数値に変換
    int[] cArray = new int[n-1];
    for (int c = 0; c < n-1; c++) {
      cArray[c] = int.Parse(cArrayStr[c]);
    }
    
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
      // 満足度
      sum += bArray[aArray[i] - 1];
      
      // 追加満足度
      if ((0 < i) && (aArray[i] - 1 == aArray[i-1]))
      {
        sum += cArray[aArray[i-1]-1];
      }
    }
    Console.WriteLine(sum);
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
const long long mod = 1e9+7;

int main(){
    int W, a, b;
    cin >> W >> a >> b;
    int ans;
    int l,r;
    if (a+W <= b) ans = b - (a+W);
    else if (b+W <= a) ans = a - (b+W);
    else {
        l = (a+W) - b;
        r = (b+W) - a;
        if (l < r) ans = l;
        else ans = r;
    }
    if (abs(a-b) <= W) ans = 0;
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 256
n, m, x = map(int, input().split())
bk = [list(map(int, input().split())) for _ in range(n)]
pr = 10 ** 7
for i in range(2 ** n):
    ef = [0] * (m + 1)
    for j in range(n):
        if i >> j & 1:
            ef = [p + q for (p, q) in zip(ef, bk[j])]
    for k in range(1, m + 1):
        if ef[k] < x:
            break
        if k == m:
            pr = min(pr, ef[0])
print(pr if pr != 10 ** 7 else -1)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = INF;
    rep(i, n-k+1) chmin(ans, h[i+k-1] - h[i]);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <queue>
#include <vector>
#include <iostream>
#include <functional>
#include <string>
#include <algorithm>

using namespace std;
int main() {
    int n;
    cin>>n;
    
    vector<pair<int,int>> a;
    int x,l;
    for(int i=0;i<n;++i){
        cin>>x>>l;
        a.emplace_back(x-l,x+l);
    }
    
    sort(a.begin(),a.end(),[](auto a,auto b){return a.second<b.second;});
    int max_r = -100000000;
    int c = 0;
    for(int i = 0; i < a.size();++i){
        if (max_r <= a[i].first) {
            ++c;
            max_r = a[i].second;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 1400
#include<stdio.h>

int main() {
	int n, Yellow_exists, i;
	char str[101];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%c", &str[i]);
	}

	Yellow_exists = 0;
	for (i = 0; i < n; i++) {
		if (str[i] == 'Y') {
			Yellow_exists = 1;
			break;
		}
	}

	printf(Yellow_exists ? "Four" : "Three");
	return 0;
}

Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))

ans=0;x=10**9;minus_n=0
for a in A:
  if a<0:
    minus_n+=1
    ans+=-a
  else:
    ans+=a
    
  if x>abs(a):
    x=abs(a)

if minus_n%2==0:
  print(ans)
else:
  print(ans-2*x)

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

int main() {
    ll n;
    cin >> n;
    if (n % 2) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    n /= 2;
    ll d = 5;
    while (d <= n) {
        ans += n / d;
        d *= 5;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int INF = 1 << 30;

int main() {
	int N, M; 
	string S;
	cin >> N >> M >> S;
	vector<int>Ans;
	int now = N;
	while (now != 0) {
		bool b = false;
		for (int n = M; n > 0; --n) {
			if (now -n < 0){
				continue;
			}
			if ('1' != S[now- n]) {
				now -= n;
				Ans.push_back(n);
				b = true;
				break;
			}
		}
		if (b == false) {
			cout << "-1" << endl;
			return 0;
		}
	}
	reverse(Ans.begin(),Ans.end());
	for (int n = 0;n < Ans.size();++n) {
		if (0 != n) {
			cout << " ";
		}
		cout << Ans[n];
	}
	return 0;
}



Measured memory_bytes: 4092
/// NHDanDz
#include <bits/stdc++.h>
#define nmax 3000005
#define MOD 10000000000007
#define F first
#define S second
#define PB push_back
#define reset(a) memset(a,0,sizeof(a))
#define pii pair<int,int>
#define ll long long
#define Task "D"
#define endl '\n'
#define sz() size()
#define forinc(a,b,c) for(int a = b; a <= c; a++)
#define fordec(a,b,c) for(int a = b; a >= c; a--)
using namespace std;
int n , root[nmax];
struct hd
{
    int x,y,id;
}a[nmax];
struct ha
{
    int u,v,w;
}d[nmax];
bool cmp1(hd a, hd b)
{
    if(a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}
bool cmp2(hd a, hd b)
{
    if(a.y==b.y)
        return a.x < b.x;
    return a.y < b.y;
}
int get_root(int u){
    return root[u] ? (root[u] = get_root(root[u])) : u ;
}
void READ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    forinc(i,1,n)
    {
        a[i].id = i;
        cin >> a[i].x >> a[i].y;
    }
    sort(a + 1, a + 1 + n, cmp1);
    forinc(i,1,n - 1)
    {
        d[i].u = a[i].id;
        d[i].v = a[i + 1].id;
        int t =min(abs(a[i + 1].x - a[i].x),abs(a[i + 1].y - a[i].y));
        d[i].w = t;
    }
    sort(a + 1, a + 1 + n, cmp2);
    forinc(i,1,n - 1)
    {
        d[i + n - 1].u = a[i].id;
        d[i + n - 1].v = a[i + 1].id;
        d[i + n - 1].w = min(abs(a[i + 1].x - a[i].x),abs(a[i + 1].y - a[i].y));
    }
}
bool cmp3(ha a,ha b)
{
    return a.w < b.w;
}
void SOLVE()
{
    ll ans(0);
    sort(d + 1, d + 1 + 2*n -2,cmp3);
    forinc(i,1,2*n - 2)
    {
        int p = get_root(d[i].u) , q = get_root(d[i].v);
        //cout << p << " " << q << endl;
        if(p != q)
        {
            root[p] = q;
            ans += d[i].w;
        }
    }
    cout << ans;
}
int main()
{
    READ();
    SOLVE();
    return 0;
}


Measured memory_bytes: 8448
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }

int main(void){
	uint32_t a=nextpint();
	uint32_t b=nextpint();
	uint32_t c=nextpint();
	uint32_t k=nextpint();
	int32_t ans;
	if(a>=k){
		ans=k;
	}else if(a+b>=k){
		ans=a;
	}else{
		ans=a-(k-a-b);
	}
	printf("%"PRId32"\n", ans);
}


Measured memory_bytes: 1576
#include<stdio.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int n,m;
        while(~getII(n,m)){
                printf("%s\n",n==m?"Yes":"No");
        }
}

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

using Point=System.Tuple<long,long>;

public static class Program {
    public static void Main() {
        long[]nk=Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n=nk[0];
        long k=nk[1];
        k=Math.Min(k,n);
        long[]a=Console.ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(a);
        long ans=0;
        for(int i=0;i<n-k;i++){
            ans+=a[i];
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 39808