akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int x = min(a[n-1]-a[0],k-(a[1]-a[0]));
  repeat(i,1,n-1) {
    x = min(x,min(k-(a[i-1]-a[i]),k-(a[i+1]-a[i])));
  }
  x = min(x,min(a[n-1]-a[0],k-(a[n-1]-a[n-2])));
  cout << x <<endl;
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<algorithm>
#define maxn 200005
#define inf 0x3f3f3f3f
using namespace std;
typedef long int ll;
bool prime[60000];
int ans[60000], p;
int main()
{
    for (int i = 2; i < 60000; ++i){
        if (!prime[i]) for (int j = 2; j * i < 60000; ++j) prime[j * i] = 1;
    }
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= 55555; ++i) if (!prime[i] && i % 5 == 1) ans[++p] = i;
    for (int i = 1; i < n; ++i) printf("%d ", ans[i]);
    printf("%d\n", ans[n]);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
#define end _____end
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int dp[216000];
Int l[216000], r[216000], a[216000];
Int n, m;
vector<P> Interval[216000];
vector<Int> add[216000], end[216000];
Int seg[1 << 20];
Int all[1 << 20];
void addval(Int l, Int r, Int val, Int bottom = 0, Int top = (1<<19), Int pos = 1){
  if(r <= bottom || top <= l)return;
  if(l <= bottom && top <= r){
    all[pos] += val;
    return;
  }
  Int mid = (bottom + top ) / 2;
  addval(l, r, val, bottom, mid, pos * 2);
  addval(l, r, val, mid, top, pos * 2+1);
  seg[pos] = max(seg[pos * 2] + all[pos * 2],
		 seg[pos * 2 + 1] + all[pos * 2 + 1]);
}

Int getval(Int l, Int r, Int bottom = 0, Int top = 1 << 19, Int pos = 1){
  if(r <= bottom || top <= l)return -LINF;
  if(l <= bottom && top <= r){
    return seg[pos] + all[pos];
  }
  Int mid = (bottom + top) / 2;
  Int res = getval(l, r, bottom, mid, pos * 2);
  Int res2 = getval(l, r, mid, top, pos * 2 + 1);
  return max(res, res2) + all[pos];
}


int main(){
  cin >> n >> m;
  for(Int i = 0;i < m;i++){
    cin >> l[i] >> r[i] >> a[i];
    add[l[i]].push_back(i);
    end[r[i]].push_back(i);
  }
  dp[0] = 0;
  for(Int i = 1;i <= n;i++){
    for(Int j = 0;j < add[i].size();j++){
      Int id = add[i][j];
      addval(0, l[id], a[id]);
      //      cout << "add " << l[id] << " " << a[id] << endl;
    }
    dp[i] = getval(0, i);
    //    cout << i << " " << dp[i] << endl;
    for(Int j = 0;j < end[i].size();j++){
      Int id = end[i][j];
      addval(0, l[id], -a[id]);
      ///      cout << "add " << l[id] << " " << -a[id] << endl;
    }
    addval(i, i+1, dp[i]);
  }
  cout << getval(0,n+1) << endl;
  return 0;
}

Measured memory_bytes: 43520
import java.util.*;

public class Main{   
    
      static int N;
      static int W;
      static int[] w;
      static int[] v;
      
      static Map<String,Long> memo = new HashMap<>();
    
      public static void main(String[] args) {          
          
        Scanner sc = new Scanner(System.in);
      
        N = sc.nextInt();
        W = sc.nextInt();
        
        w = new int[N];
        v = new int[N];
        
        for(int i = 0;i < N;i++){
             w[i] = sc.nextInt();
             v[i] = sc.nextInt();
        }
        
        System.out.println(calc(0,0));
        
      }
      
      static long calc(int d,long weight){
          String key = d + ":" + weight;
          
          if(d >= N){
              return 0;
          }
          
          if(memo.containsKey(key)){
              return memo.get(key);
          }
          
          long v1 = 0;
          
          if(weight + w[d] <= W){
              v1 = calc(d+1,weight + w[d]) + v[d];
          }
          
          long v2 = calc(d+1,weight);
          
          long vr = Math.max(v1,v2);
          
          memo.put(key,vr);
          
          return vr;          
      }
      
}       

Measured memory_bytes: 53716
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s,t;
    cin>>s>>t;
    int n=SZ(s);
    string ans="";
    REP(i,n) {
        string tmp=s;
        bool mat=1;
        REP(j,SZ(t)) {
            if(i+j>=n) {
                mat=0;
                break;
            }
            if(s[i+j]==t[j] || s[i+j]=='?') {
                tmp[i+j]=t[j];
            } else {
                mat=0;
                break;
            }
        }
        if(!mat) {
            continue;
        }
        REP(j,n) {
            if(tmp[j]=='?') {
                tmp[j]='a';
            }
        }
        ans=tmp;
    }
    if(ans=="") {
        cout<<"UNRESTORABLE"<<endl;
    } else {
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

N = len(S)
M = len(T)
l = []
for i in range(N+1):
  sim = 0
  if len(S[i:i+M]) != M: break
  for j in range(M):
    if S[i:i+M][j] == T[j]:
      sim += 1
  dis = M - sim
  l.append(dis)
  
print(min(l))

Measured memory_bytes: 9048
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;


typedef long long ll;

#define int ll

const int INF = 1e12 + 239;

int n;
vector<int> a;
vector<ll> ps;
vector<ll> s;

ll get_sum(int l, int r) {
	r++;
	return ps[r] - ps[l];
}

ll solve(int x1) {
	// if (abs(x1 - a[n - 2]) > abs(x1 - a[n - 1])) {
	// 	return s[n - 1];
	// } else {
		int l = -1;
		int r = INF;
		while (r - l > 1) {
			int m = (r + l) >> 1;
			int tl = lower_bound(a.begin(), a.end(), x1 - m) - a.begin();
			int tr = prev(upper_bound(a.begin(), a.end(), x1 + m)) - a.begin();
			if (tr - tl + 1 >= n - 1 - tr) {
				r = m;
			} else {
				l = m;
			}
		}
		{
			int m = r;
			int tl = lower_bound(a.begin(), a.end(), x1 - m) - a.begin();
			int tr = prev(upper_bound(a.begin(), a.end(), x1 + m)) - a.begin();
			if (tr - tl + 1 == n - 1 - tr) {
				//
			} else {
			 	tr--;
			}
			int l1, l2, r1, r2;
			l1 = tl;
			r1 = tr;
			l2 = tr + 1;
			r2 = n - 1;
			int len = (n - l1);
			ll ans = get_sum(l2, r2);
			if (len % 2 == 0 && l1 > 0) {
				ans += s[l1 - 1];
			} else if (len % 2 == 1 && l1 > 1) {
				ans += s[l1 - 2];
			}
			return ans;
		}
	// }
}

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

	int q;
	cin >> n >> q;
	a.resize(n);
	for (auto &t : a) {
		cin >> t;
	} 
	s.resize(n);
	for (int i = 0; i < n; i++) {
		if (i > 1) {
			s[i] = s[i - 2];
		}
		s[i] += a[i];
	}
	ps.resize(n + 1);
	for (int i = 0; i < n; i++) {
		ps[i + 1] = ps[i] + a[i];
	}
	while (q--) {
		int x;
		cin >> x;
		cout << solve(x) << '\n';
	}
}


Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int res=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='+') res++;
		else res--;
	}
	cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#pragma warning (disable: 4996)

class BIT {
public:
	int size_;
	vector<int> bit;

	void init(int sz) {
		size_ = sz + 2;
		bit.resize(size_ + 2, 0);
	}
	void add(int pos, int x) {
		pos++;
		while (pos <= size_) {
			bit[pos] += x;
			pos += (pos & -pos);
		}
	}
	int sum(int pos) {
		pos++; int s = 0;
		while (pos >= 1) {
			s += bit[pos];
			pos -= (pos & -pos);
		}
		return s;
	}
};

long long N, K, A[1 << 18];

int main() {
	scanf("%lld%lld", &N, &K);
	for (int i = 1; i <= N; i++) { scanf("%lld", &A[i]); A[i] -= K; }
	for (int i = 1; i <= N; i++) A[i] += A[i - 1];

	vector<long long> val;
	for (int i = 0; i <= N; i++) val.push_back(A[i]);
	sort(val.begin(), val.end());
	for (int i = 0; i <= N; i++) A[i] = lower_bound(val.begin(), val.end(), A[i]) - val.begin();

	BIT C; C.init(val.size() + 2);
	C.add(A[0], 1);

	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += C.sum(A[i]);
		C.add(A[i], 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    sort(all(s));
    if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])couty;
    else coutn;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int n,m;

vector<int>visited,dp;

vector<vector<int>> edge2;
int bfs(int nod)
{
  queue<int> que;
  que.push(nod);
  int res=0;
  while(!que.empty())
  {
    int no;
    no=que.front();que.pop();
    for(int nn:edge2[no])
    {
      visited[nn]--;
      if(visited[nn]==0)
      {
        que.push(nn);
        dp[nn]=max(dp[nn],dp[no]+1);
        res=max(res,dp[nn]);

      }
      else
      {
        dp[nn]=max(dp[nn],dp[no]+1);
      }

    }
  }
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  edge2=vector<vector<int>>(n+1) ;
  visited=vector<int>(n+1,1);
  dp=vector<int>(n+1,-1);

  for(int i=0;i<m;i++)
  {
    int a,b;
    cin>>a>>b;
    edge2[a].push_back(b);
    visited[b]++;
  }
  edge2[0]=vector<int>(n);
  for(int i=0;i<n;i++)
  {
    edge2[0][i]=i+1;
  }
  cout<<bfs(0)<<endl;


  return 0;

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n = 3;
    vector<vi> a(n, vi(n)), b(n, vi(n));
    forn(i, n) {
        forn(j, n) {
            cin >> a[i][j];
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        forn(i, n) {
            forn(j, n) {
                if (x == a[i][j]) b[i][j] = 1;
            }
        }
    }
    forn(i, n) {
        if (b[i][0] && b[i][1] && b[i][2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    forn(i, n) {
        if (b[0][i] && b[1][i] && b[2][i]) {
            cout << "Yes\n";
            return 0;
        }
    }
    if (b[0][0] && b[1][1] && b[2][2]) {
        cout << "Yes\n";
        return 0;
    }
    if (b[2][0] && b[1][1] && b[0][2]) {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) h[i] = inp.nextInt();

            int[] dp = new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);

            dp[0] = 0;
            for (int i = 0; i < n; i++) {
                if (i + 1 < n) {
                    dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(h[i] - h[i+1]));
                }
                if (i + 2 < n) {
                    dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(h[i] - h[i+2]));
                }
            }
            out.print(dp[n-1]);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 31684
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


ll sumofdigits(ll n){
    int sum =0;
    while(n>0){
        sum += n%10;
        n /=10;
    }
    return sum;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m,d[200010],c[200010],sum=0,n=0;
    cin>>m;
    rep(i,m){
        cin>>d[i]>>c[i];
        sum+=d[i]*c[i];
        n+=c[i];
    }
    ll ans=n-1;
    string s=to_string(sum);
    rep(i,s.size()){
        ll t=sum;
        while(t>0){
            ans+=t/10;
            t/=10;
        }
        sum=sumofdigits(sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const long long inf=1000000000000000000;
int main(){
    int n;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++)cin>>l[i];
    int x=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++)if(l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i] && l[i]+l[j]+l[k]-max({l[i],l[j],l[k]})>max({l[i],l[j],l[k]}))x++;
        }
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  
  if(a == "000"){
    cout << "0" << endl;
  
  }else if(a == "001" || a == "010" || a == "100"){
  	cout << "1" << endl;
  
  }else if(a == "011" || a == "110" || a == "101"){
    cout << "2" << endl;
  }else{
   	cout << "3" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; 
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int A, B; cin >> A >> B;
    cout << max(A+B, max(A-B, A*B)) << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
 
typedef long long LL;
using namespace std;
 
int n, k;
int a[100005];
 
int min(int x, int y){
	return x < y ? x : y;
}
 
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
 
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		//if(a[i] < 0) a[i] = a[i] * 2;
	}
	int ans = 0x3f3f3f3f;
	for (int i = k; i <= n; i++){
		ans = min(ans, a[i] - a[i - k + 1] + min(abs(a[i]), abs(a[i - k + 1])));
	}
	printf("%d\n", ans);
 
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(void){
  long long int a,b,n,x,ans=0;
  scanf("%lld %lld %lld",&a,&b,&n);
  if(b-1<=n){
    x=b-1;
  }else{
    x=n;
  }
  ans=floor((a*x)/b)-(x/b);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int datasets = Integer.parseInt(in.nextLine());
		
		int[] output = new int[datasets];
		
		for (int i = 0; i < datasets; i++) {
			String set1 = in.nextLine();
			String set2 = in.nextLine();
			output[i] = LCS(set1, set2);
		}
		in.close();
		
		for (int i = 0; i < datasets; i++) {
			System.out.println(output[i]);
		}
	}
	
	public static int LCS(String set1, String set2) {
		int[][] substring = new int[set1.length()+1][set2.length()+1];
		
		for (int i = 0; i < set1.length()+1; i++) {
			for (int j = 0; j < set2.length()+1; j++) {
				if (i == 0 || j == 0) {
					substring[i][j] = 0;
				} else if (set1.charAt(i-1) == set2.charAt(j-1)) {
						substring[i][j] = substring[i-1][j-1] + 1;
						
				} else {
					substring[i][j] = Math.max(substring[i-1][j], substring[i][j-1]);
				}
			}
		}
		
		return substring[set1.length()][set2.length()];
	}
}



Measured memory_bytes: 64656
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())


class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

es = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    es[i] = (a - 1, b - 1)

u = UnionFind(N)
ans = []
pair = N * (N - 1) // 2
ans.append(pair)
for i in range(M - 1, -1, -1):
    a, b = es[i]
    if u.is_same(a, b):
        ans.append(pair)
        continue
    pair -= (u.get_size(a) * u.get_size(b))
    u.unite(a ,b)
    if pair < 0:
        pair = 0
    ans.append(pair)

for i in list(reversed(ans))[1:]:
    print(i)

Measured memory_bytes: 29976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll has[n];
    for(ll i=0;i<n;i++)
    {
        has[i]=1e10;
        cin>>a[i];
    }
    
    has[0]=0;
    for(ll i=1;i<n;i++)
    {
        ll start=i-k;
        if(start<=0)
            start=0;
        for(ll j=start;j<i;j++)
        {
            if(has[j]+abs(a[j]-a[i])<has[i])
                has[i]=has[j]+abs(a[j]-a[i]);
        }
    }
    cout<<has[n-1];
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        print(" {}".format(i), end="")
        continue
    ii = i
    while(ii  > 1):
        if ii % 10 == 3:
            print(" {}".format(i), end="")
            break
        ii //= 10
print()


Measured memory_bytes: 5872
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		sc.close();
		if (N == M) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22100
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


int main() {
	int  n = 0, p = 0,q=0;
	cin >> n;
	vector<int>b(n);
	for (int a = 0; a < n; a++)
	{
		cin >> b[a];
		if (a != 0 && b[a] <= b[a - 1]){p++; }
		else { p = 0; }
		if (p > q) { q = p; }
	}
	cout << q;
	return 0;
}

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

struct vec{
    double x,y;
};

double inner_product(vec& a, vec& b){
    return a.x*b.x+a.y*b.y;
}

int main(void){
    vec p1,p2,p,p12;
    int q;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    p12.x=p2.x-p1.x; p12.y=p2.y-p1.y;
    cin >> q;
    cout.precision(10);
    cout.setf(std::ios::showpoint);
    for(int i=0;i<q;i++){
        cin >> p.x >> p.y;
        p.x-=p1.x; p.y-=p1.y;
        double k=inner_product(p,p12)/inner_product(p12,p12);
        cout << fixed << p1.x+k*p12.x << " " << p1.y+k*p12.y << endl;
    }
    return 0;
}

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

int main (){
  int A,B,C,D;
  bool b=false;
  cin>>A>>B>>C>>D;
  
  while(!b){
    C=C-B;
    if(C<=0){
      cout<<"Yes";
      b=true;
    }
    A=A-D;
    if(!b&&A<=0){cout<<"No";
             b=true;
            }
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main(){
int a,b,c;
char d[7];
while(1){
scanf("%s",d);
if(strcmp(d,"HEISEI")!=0){
break;
}
else{
scanf("%d %d %d\n",&a,&b,&c);
if(a<31){
printf("HEISEI %d %d %d\n",a,b,c);
}
else if(a==31 && b<5){
printf("HEISEI %d %d %d\n",a,b,c);
}
else{
a=a-30;
printf("? %d %d %d\n",a,b,c);
}
}
}
return 0;
}


Measured memory_bytes: 2032
#include<string>
#include<iostream>
using namespace std;
int main() {
	string str;
	int count = 0;
	while (cin >> str) {
		bool b = true;
		int g = str.size();
		if (g % 2 == 0) {
			for (int i = 0; i < g; i++){
				if (str[i] != str[g - 1 - i])
					b = false;
			}
			if (b != false)count++;
		}
		else{
			if (g == 1){
				count++;
			}
			else{
				for (int i = 0; i < g; i++){
					if (str[i] != str[g - i - 1])b = false;
				}
				if (b != false)count++;
			}
		}
	}
	cout << count << endl;
}

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

int main() {
  int N;
  string s;
  cin >> N >> s;
  int R = 0, B = 0;
  for (int i = 0; i < N; i++) if (s[i] == 'R') R++; else B++;
  if (R > B) cout << "Yes" << endl; else cout << "No" << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  long long ans=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        int A=L.at(i);
        int B=L.at(j);
        int C=L.at(k);
        if(A==B || B==C || C==A){
          continue;
        }
        if(A<B+C && B<C+A && C<A+B){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3652
#include <bits/stdc++.h>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

ll modpow(ll base, ll index, ll mod)
{
	ll res = 1;
	while(index)
	{
		if(index & 1) res = (res * base) % mod;
		base = (base * base) % mod;
		index /= 2;
	}
	return res;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, oc = 0; cin >> n;
	ll m1 = 0, m2 = 0;
	string x; cin >> x;
	vector<int> pre(n + 1);
	for(int i = 1; i <= n; i++)
	{
		int ii = i;
		while(ii)
		{
			ii %= __builtin_popcount(ii);
			pre[i]++;
		}
	}
	for(int i = 0; i < n; i++) oc += x[i] == '1';
	if(!oc)
	{
		for(int i = 0; i < n; i++) cout << 1 << endl;
		return 0;
	}
	for(ll i = n - 1; i > -1; i--) if(x[i] == '1')
	{
		if(oc > 1) m1 = (m1 + modpow(2, n - i - 1, oc - 1)) % (oc - 1);
		m2 = (m2 + modpow(2, n - i - 1, oc + 1)) % (oc + 1);
	}
	for(int i = 0; i < n; i++)
	{
		if(x[i] == '1' && oc == 1)
		{
			cout << 0 << endl;
			continue;
		}
		ll dec = (oc == 1) ? -1 : modpow(2, n - i - 1, oc - 1), inc = modpow(2, n - i - 1, oc + 1);
		if(x[i] == '1') cout << pre[(((m1 - dec) % (oc - 1)) + (oc - 1)) % (oc - 1)] + 1 << endl;
		else cout << pre[(m2 + inc) % (oc + 1)] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 4368
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll i = s.size()-1;
  if (s[i] == '2' || s[i] == '4' || s[i] == '5' || s[i] == '7' || s[i] == '9') {
    cout << "hon" << endl;
  } else if (s[i] == '0' || s[i] == '1' || s[i] == '6' || s[i] == '8') {
    cout << "pon" << endl;
  } else if (s[i] == '3') {
    cout << "bon" << endl;
  }

  return 0;
}


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

int main(void) {
	char kugimiya_rie[1024];
	while (fgets(kugimiya_rie, sizeof(kugimiya_rie), stdin) != NULL && strchr(kugimiya_rie, '?') == NULL) {
		int a, b;
		char op[4];
		int ans = 0;
		if (sscanf(kugimiya_rie, "%d%1s%d", &a, op, &b) != 3) return 1;
		switch (op[0]) {
			case '+': ans = a + b; break;
			case '-': ans = a - b; break;
			case '*': ans = a * b; break;
			case '/': ans = a / b; break;
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

#include <iostream>
 
int main(void)
{
    int64_t N;
    std::cin >> N;

    if (N%2 == 1) {
        std::cout << ((N/2)+1.0)/N << std::endl;
    } else {
        std::cout << (N/2+0.0)/N << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
Item = Struct.new(:w, :v)

n, w = gets.split.map(&:to_i)
items = n.times.map {Item[*gets.split.map(&:to_i)]}

# dp[i][sum_w]
dp = Array.new(w+1, 0)
dp1 = Array.new(w+1, 0)
#dp = (n+1).times.map {Array.new(w+1, 0)}
(1..n).each do |i|
	item = items[i-1]
	(0..w).each do |u|
		dp[u] = [
			u >= item.w ? dp1[u-item.w] + item.v : 0,
			dp1[u]
		].max
	end
	dp, dp1 = dp1, dp
end

puts dp1[w]


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

//conversion
//------------------------------------------
inline int toInt(string s) {int 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;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  string S;
  cin >> S;
  int N = SZ(S), A=0, B=0;
  
  REP(i,N) {
    if(i%2 == 0 && S.at(i) == '0') {
      A++;
    }
    else if (i%2 == 1 && S.at(i) == '1') {
      A++;
    }
  }
  REP(i,N) {
    if(i%2 == 1 && S.at(i) == '0') {
      B++;
    }
    else if (i%2 == 0 && S.at(i) == '1') {
      B++;
    }
  }
  
  int ans = min(A,B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
if __name__ == "__main__":
    x_p1, y_p1, x_p2, y_p2 = map(lambda x: int(x), input().split())
    q = int(input())

    p1p2 = (x_p2 - x_p1, y_p2 - y_p1)
    for _ in range(q):
        x_p0, y_p0 = map(lambda x: int(x), input().split())
        p1p0 = (x_p0 - x_p1, y_p0 - y_p1)
        r = (p1p2[0] * p1p0[0] + p1p2[1] * p1p0[1]) / (p1p2[0] ** 2 + p1p2[1] ** 2)
        print(x_p1 + p1p2[0] * r, y_p1 + p1p2[1] * r)



Measured memory_bytes: 5628
from numba import jit

N = int(input())

@jit
def f():
    ret = [0] * 10001

    for i in range(1, 200):
        for j in range(1, 200):
            for k in range(1, 200):
                z = i**2 + j**2 + k**2 + i*j + j*k + k*i
                if z < 10001:
                    ret[z] += 1

    return ret


ans = f()

for x in range(1, N+1):
    print(ans[x])


Measured memory_bytes: 111860
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0

int aa[100005],bb[100005];
int main () {
    ll n,m,c=0,w=0;
    cin>>n>>m;
    while(m--){
        ll a;
        string s;
        cin>>a>>s;
            if(s[0]=='A' && !aa[a])
                aa[a]=1;
            else if(s[0]=='W' && !aa[a])
                bb[a]++;
    }
     for(ll i=1; i<=n; i++){
            c+=aa[i];
            if(aa[i]){
                w+=bb[i];
            }
     }
     cout<<c<<" "<<w<<endl;
    End;
}
/* pray for me
All is well
*/


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int n,a,s,x,i;
	while(1)	{
		scanf("%d",&a);
		if(a==0)	break;
		s=0;
		for(i=0;i<9;i++){
			scanf("%d",&n);
			s+=n;
		}
		x=a-s;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, c;
  cin >> n >> c;
  vi v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];
  vi dp(c + 1, 0);
  rep(i, n) for(int j = c; j >= 0; j--) {
    if(j + w[i] <= c) dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
  }
  cout << *max_element(all(dp)) << endl;
}


Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];
int num[200010];

signed main(){
	cin>>N;
	int R=1;
	REP(i,N){
		cin>>A[i];
	}
	bool flag=true;
	REP(i,N){
		if(A[i]==1){
			flag=false;
		}
	}
	if(flag==true){
		cout<<-1<<endl;
		return 0;
	}
	int Q=0;
	REP(i,N){
		if(R==A[i]){
			R++;
		}
	}
	R--;
	cout<<N-R<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll n;
  int m = 100;
  scanf("%lld", &n);
  vector<pair<ll, ll>> p;
  for(ll i = 1; i * i <= n; i++)
    if(n % i == 0)
      p.push_back({i, n / i});
  for(auto x : p) {
    int a = 0, b = 0;
    while(x.first) {
      a++;
      x.first /= 10;
    }
    while(x.second) {
      b++;
      x.second /= 10;
    }
    m = max(a, b);
  }
  printf("%d\n", m);
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
        
      int a = scan.nextInt();
      int b = scan.nextInt();
      int c = scan.nextInt();
      
      if((c-a)*(b-c) > 0){
      	System.out.println("Yes");
      } else {
      	System.out.println("No");
      }
    }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int kyori = 0;
 
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    int kyoriA, kyoriB;
    kyoriA = x * 2;
    kyoriB = (K - x) * 2;
    
    if (kyoriA <= kyoriB) {
      kyori += kyoriA;
    }
    else {
      kyori += kyoriB;
    }
    
  }
  
  cout << kyori << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,m;
    cin>>n>>m;
    vector<ll>a(n);
    ll c=0;
    rep(0,i,n){
        cin>>a[i];
        c+=a[i];
    }
    sort(a.rbegin(),a.rend());
    rep(0,i,m){
        if(1.*a[i]<1.*c/(4.*m)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>

using namespace std;

int n;
vector<pa> a[10200];
void dij(){
	int d[10200]={0};
	int ans[10200]={0};
	priority_queue<pa>  PQ; 
	pair<int,pa> q;
	pa r;
	int wei=0;
	int u=0,z=0;
	d[0]=1;
	while(z!=n-1){
		for(int j=0;j<a[u].size();j++){
			r=make_pair(ans[u]+a[u][j].second,a[u][j].first);
			if(d[a[u][j].first]==0 ) PQ.push(r);
		}
	while(1){
		if(PQ.size()==0) {
			cout<<"dv"<<endl;
		break;
		}
		r=PQ.top();
		PQ.pop();
		
		if(d[r.second]==0) break;
	
		}
	u=r.second;
	d[u]=1;
	ans[u]=r.first;
	
	z++;
	}
//	cout<<-wei<<endl;
	for(int i=0;i<n;i++) cout<<i<<" "<<-ans[i]<<endl;
}



int main(){
	// your code goes here
	int m,k,z,l;
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>z>>k;
	
		for(int j=0;j<k;j++){
		cin>>m>>l;
		a[i].push_back(make_pair(m,-l));
		}
	}
	dij();

	return 0;
}

Measured memory_bytes: 8176
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;

int n,A[M];
int B[M],P[M],ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=n;i>=1;i--){
		int s=0;
		for(int j=i<<1;j<=n;j+=i)s^=B[j];
		B[i]=A[i]^s;
		if(B[i])P[++ans]=i;
	}
	printf("%d\n",ans);
	for(int i=ans;i>=1;i--)printf("%d ",P[i]);
	return 0;
}

Measured memory_bytes: 2944
function main(input) {
  var n = input[0]-0;
  var p = input[1];
  var q = input[2];

  var list = [];
  for(var i=1;i<=n;i++)list.push(i);
  var perm = list.permutation(n);
  var pp = -1, qq=-1;
  perm.forEach((v,i)=>{
    var txt = v.join(" ");
    if(p==txt){
      pp=i;
    }
    if(q==txt){
      qq=i;
    }
  });
  console.log(Math.abs(pp-qq));

}

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

// JavaScript Array permutation generator
// (optimized from CoffeeScript output: see ArrayPermutation.coffee)
(function() {
  var generatePermutation = function(perm, pre, post, n) {
    var elem, i, rest, len;
    if (n > 0)
      for (i = 0, len = post.length; i < len; ++i) {
        rest = post.slice(0);
        elem = rest.splice(i, 1);
        generatePermutation(perm, pre.concat(elem), rest, n - 1);
      }
    else
      perm.push(pre);
  };

  /*
  extend Array.prototype
  e.g. [0, 1, 2].permutation(2)
  => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
  */
  Array.prototype.permutation = function(n) {
    if (n == null) n = this.length;
    var perm = [];
    generatePermutation(perm, [], this, n);
    return perm;
  };
})();

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 28108
#include<iostream>
int main(){int h,b,i,j;std::string r,a;while(std::cin>>r>>a,r!="0"&&a!="0"){for(h=b=i=0;i<4;i++)for(j=4;j-->0;)if(a[i]==r[j])i==j?h++:b++;printf("%d %d\n",h,b);}}

Measured memory_bytes: 920
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <deque> // deque
#include <iomanip> //setprecsion
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <utility> // pair, make_pair
#include <vector> // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll k, a, b; cin >> k >> a >> b;
  for(ll i = a;i <= b;i++)
  {
    if(i % k == 0) fin("OK");
  }
  fin("NG");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll ans=b/x;
    if(a%x==0){
        ans-=a/x-1;
    }
    else ans-=a/x;
    cout<<ans<<endl;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

Measured memory_bytes: 256