akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, D, A;
ll X[200010], H[200010];
std::vector<P> ps;
ll ans = 0;

int main()
{
  std::cin >> N >> D >> A;

  rep( i, N ) {
    std::cin >> X[i] >> H[i];

    ps.emplace_back( X[i], H[i] );
  }

  std::sort(all(ps));

  std::queue<P> que;
  ll acc = 0;

  rep( i, N ) {
    while( !que.empty() && que.front().second < ps[i].first )
      acc -= que.front().first, que.pop();

    ps[i].second -= acc;

    if( ps[i].second < 0 )
      continue;

    ll num = (ps[i].second+A-1)/A;
    ans += num;
    acc += num*A;
    que.emplace( num*A, ps[i].first+2*D );
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 8560
#include<stdio.h>
int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a < b){
        puts("a < b");
    }
    else if(a > b){
        puts("a > b");
    }
    else if(a == b){
        puts("a == b");
    }
    return 0;
}


Measured memory_bytes: 2088
def factor(n):
    res = []
    last = -1
    i = 2
    while i ** 2 <= n:
        while n % i == 0:
            if i != last:
                res.append([i,1])
                last = i
            else:
                res[-1][1] += 1
            n //= i
        i += 1
    if n != 1:
        res.append([n,1])
    return res


n = int(input())

ls = factor(n)
ans=0
for p,cnt in ls:
    i=0
    while 1:
        cnt-=i
        if cnt<(i+1):
            break
        else:
            i+=1
    ans+=i

print(ans)





Measured memory_bytes: 63176
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    def f(a, b):
        return max(len(str(a)), len(str(b)))

    res = f_inf
    for a in range(1, int(pow(n, 0.5)) + 1):
        if n % a == 0:
            b = n // a
            t = f(a, b)
            res = min(res, t)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define INF 1e9
using namespace std;

int main()
{
    string s;
    cin>>s;
    string ans;
    if(s=="ABC"){
        ans="ARC";
    }else{
        ans="ABC";
    }

    cout<<ans;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int A[100], B[100], C[100];

int main()
{
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++)
    {
        cin >> B[i];
    }
    for (int i = 1; i <= N - 1; i++)
    {
        cin >> C[i];
    }

    for (int i = 1; i <= N; i++)
    {
        ans += B[i];
        if (i < N && A[i + 1] == A[i] + 1)
        {
            ans += C[A[i]];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL INF=1e16+1000;
const int magic=348;

int n;
LL a[148];

int main ()
{
	int i,j;
	cin>>n;
	for (i=1;i<=n;i++) cin>>a[i];
	LL ans=0;
	do
	{
		bool f=false;
		for (i=1;i<=n;i++)
			if (a[i]>=n)
			{
				f=true;
				LL d=a[i]-(n-1);
				LL ss;
				if (d%n==0) ss=d/n; else ss=d/n+1;
				ans+=ss;
				a[i]-=ss*n;
				for (j=1;j<=n;j++)
					if (i!=j) a[j]+=ss;
			}
		if (!f) break;
	}
	while (true);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 x;
    cin >> x;
    int64 _5 = ((x+10)/11);
    int64 _6 = ((x+10)/11);
    if ((_5-1)*5 + _6*6 >= x) _5--;
    cout << _5 + _6 << endl;
}

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

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int a = in.nextInt();
        out.println(a + (a * a) + (a * a * a));
    }
}


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

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// 町の数

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		for(int k=0; k<m; k++){
		  for(int i=0; i<m; i++){
		    for(int j=0; j<m; j++){
		      if(T[i][j]>T[i][k]+T[k][j]){
			T[i][j] = T[i][k]+T[k][j];
		      }
		    }
		  }
		}

		int ans = INF;
		int t;
		for(int i=0; i<m; i++){
		  int sum = 0;
		  for(int j=0; j<m; j++){
		    sum = sum+T[i][j];
		  }
		  if(sum<ans){
		    ans = sum;
		    t=i;
		  }
		}
		cout << t << ' ' << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	LL A, B, C;
	cin >> A >> B >> C;
	LL ans = 999999999999999997;


	LL a1 = A / 2;
	LL a2 = A - a1;
	ans = min(ans, abs(a1*B*C - a2*B*C));
	LL b1 = B / 2;
	LL b2 = B - b1;
	ans = min(ans, abs(A*b1*C - A*b2*C));
	LL c1 = C / 2;
	LL c2 = C - c1;
	ans = min(ans, abs(A*B*c1 - A*B*c2));
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    if(n%2!=0) n*=2;
    cout<<n<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
const int NS = 1e5 + 100;
ll N, m, a[NS];

struct Tuple {
	ll a;
	ll b;
	Tuple(ll x, ll y) {
		a = x;
		b = y;
	}
};

void bp() {
}

int main() {
	ll sum = 0;
	std::vector<Tuple> z;
	cin >> N >> m;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	for (int i = 0; i < m; ++i) {
		ll a, b;
		cin >> a >> b;
		z.push_back(Tuple(a, b));
	}
	std::sort(z.begin(), z.end(), [](const Tuple &t1, const Tuple &t2) {
			return t1.b < t2.b;
			});
	for (int i = 0; i < N; ++i) {
		Tuple zz = z.back();
		ll c = zz.a;
		ll n = zz.b;
		ll x = a[i];
		if (x >= n) {
			for (;i < N; ++i) {
				sum += a[i];
			}
			break;
		}
		sum += n;
		a[i] = n;
		if (c == 1) {
			z.pop_back();
			if (z.size() == 0) {
				++i;
				for (;i < N; ++i) {
					sum += a[i];
				}
				break;
			}
			continue;
		}
		z.pop_back();
		z.push_back(Tuple(c - 1, n));
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll	        long long
#define all(v)      (v).begin() , (v).end()
#define vi          vector <ll>
#define vii         vector <pair<ll,ll>>
#define ii          pair<int,int>
#define lp(i,a,b)	for(int i=a;i<b;i++)
#define pb          push_back
#define F           first
#define S           second
const ll mod=1e9+7,MAX=2e3+5;

void fast();
int main()
{
    fast();
    int a,b;
    cin>>a>>b;
    if(a>b)
        cout<<"safe";
    else
        cout<<"unsafe";
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		double a=s.nextLong();
		double v1=s.nextLong();
		
		double b=s.nextLong();
		double v2=s.nextLong();
		
		double t=s.nextLong();
		
		if(v2>=v1)
		{
			System.out.println("NO");
		}
		else
		{
			double take=Math.abs(a-b)/Math.abs(v2-v1);
			
			if(take<=t)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
		
	}
	
}


Measured memory_bytes: 35848
#include <iostream>
using namespace std;
int main(void){
  int n,c[100000][3],i,j,k,dp[100000][3],max,t;
  cin >> n;
  for (i=0;i<n;i++) cin >> c[i][0] >> c[i][1] >> c[i][2];
  for (i=0;i<3;i++) dp[0][i]=c[0][i];
  for (i=1;i<n;i++){
    for (j=0;j<3;j++){
      max=0;
      for (k=0;k<3;k++){
        if (j!=k){
          t=dp[i-1][k]+c[i][j];
          if (max<t) max=t;
        }
      }
      dp[i][j]=max;
    }
  }
  for (max=0,i=0;i<3;i++){
    if (max<dp[n-1][i]) max=dp[n-1][i];
  }
  cout << max << '\n';
  return 0;
}

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

int main(){

    string s;


    while (1){
	bool b = true;
	
	getline(cin, s);
	if (s == ".") break;

	stack<char> st;
	
	for (int i = 0; i < s.size(); i++){
	    
	    switch (s[i]){
	    case '(': st.push('('); break;
	    case ')':
		if (st.empty() || st.top() != '(') b = false;
		else st.pop();
		break;
	    case '[': st.push('['); break;
	    case ']':
		if (st.empty() || st.top () != '[') b = false;
		else st.pop();
		break;
	    default: break;
	    }
	}

	if (b && st.empty()) cout << "yes" << endl;
	else cout << "no" << endl;
    }

}

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

    using namespace std;

    #define INF 2000000000

    typedef long long int ll;

    typedef pair<ll,ll> ii;

    typedef pair<ii,ll> iii;

    typedef vector<ll> vi;

    typedef vector<ii> vii;

    #define getbit(n,i) (((n)&(1<<(i)))!=0)

    #define setbit0(n,i) ((n)&(~(1<<(i))))

    #define setbit1(n,i) ((n)|(1<<(i)))

    #define togglebit(n,i) ((n)^(1<<(i)))

    #define lastone(n) ((n)&(-(n)))

    #define read freopen("debug\\in.txt","r",stdin)

    #define write freopen("debug\\out.txt","w",stdout)

    #define fi first

    #define se second

    #define getI(a) scanf("%d",&a)

    #define getII(a,b) scanf("%d%d",&a,&b)

    #define PI (acos(-1))

    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)

    #define mod (1000000007)

    #define asz 500005

    #define pb push_back

    #define ppf pop_front

    #define ppb pop_back

    #define pf push_front

    queue<pair<ll,ll> >q;

    vector<pair<ll,ll> >v;

    void solver(){

      ll n,i,k,l,m,d,a;

      cin>>n>>d>>a;

      for(i=1;i<=n;i++){

        cin>>k>>l;

        v.pb({k,l});

      }

      sort(v.begin(),v.end());

      ///q.push(v[0].fi,(v[0].se+a-1)/a);

      ll sum=0;

      ll res=0;

      for(i=0;i<n;i++){

        while(!q.empty()&&v[i].fi-q.front().fi>0){

          sum-=q.front().se;

          q.pop();

        }

        ll temp=(v[i].se+a-1)/a;

        if(temp>sum)

        {

          temp-=sum;

          q.push(make_pair(v[i].fi+2*d,temp));

          sum+=temp;

          res+=temp;

          }

      }

      cout<<res;

    }

    int main()

    {

        fastread;

        solver();

        return 0;

    }

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    map<string, int> mp;
    int n;
    cin >> n;
    while(n--) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int maxi = 0;
    rall(p, mp) {
        maxi = max(maxi, p.se);
    }
    vector<string> ans;
    rall(p, mp) {
        if(p.se == maxi) {
            ans.pb(p.fi);
        }
    }
    sort(rng(ans));
    rall(s, ans) {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  
  if (N == "Sunny"){
    cout << "Cloudy" << endl;
  }
  if (N == "Cloudy"){
    cout << "Rainy" << endl;
  }
  if (N == "Rainy"){
    cout << "Sunny" << endl;
  }
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count = 0;
  string S;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S[i] == 'R'){
      	count++;
    }
  }
  if(count == 2 && S[1] == 'S'){
    count = 1;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3508
#include<stdio.h>
#include<math.h>
int main(){
int i,j,k;
int sum,n,r,s[10000];
s[0]=2;
for(i=3,j=1;j<10000;i+=2){
r=(int)sqrt(i)+1;
for(k=3;k<r;k+=2){
if(i%k==0)
r=0;
}
if(r){
s[j]=i;
j++;
}
}
for(;;){
scanf("%d",&n);
if(n==0)
break;
sum=0;
for(i=0;i<n;i++)
sum+=s[i];
printf("%d\n",sum);
}
return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;

struct fuck{
    int x;
    int y;
    int h;
};

int main(){
    int N;cin >> N;
    fuck A[N];
    int j;
    rep(i, N){
        cin >> A[i].x >> A[i].y >> A[i].h;
        if(A[i].h != 0)j = i;
    }
    for(int x = 0;x <= 100;++x){
        for(int y = 0;y <= 100;++y){
            bool flg = true;
            int H = abs(A[j].x - x) + abs(A[j].y - y) + A[j].h;
            for(int q = 0;q < N;++q){
                if(A[q].h != max(H - (abs(A[q].x - x) + abs(A[q].y - y)), 0))
                    flg = false;
            }
            if(flg){
                cout << x << ' ' << y << ' ' << H;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]

    Iterator.continually(readInt).takeWhile(_!=0).foreach{ n =>

      def count(step:Int,total:Int):Int = {
        if(total>n) 0
        else if(total==n) 1
        else {
          count(1,total+1)+count(2,total+2)+count(3,total+3)
        }
      }
      val m = count(0,0)
      val p = m/3650; val q = if(m%3650==0) 0 else 1
      b += p + q
    }
    println(b.mkString("\n"))
  }
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}






int main(void){
    long long n;
    long long min = 10000000005;
    int cnt = 0;
    scanf("%lld", &n);
    for (long long i = 1; i <= (long long)sqrt((double)n); i++){
        if (n == i * (n/i)){
            if (min > (i>n/i?i:n/i)){
                min = i>n/i?i:n/i;
            }
        }
    }

    while (min != 0){
        min /= 10;
        cnt++;
    }

    printf("%d\n", cnt);


    return 0;
}


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

using namespace std;

int main()
{
    int a,b,k;
    cin>>k>>a>>b;
    for (int i=a;i<=b;i++)
        if (i%k==0)
    {
        cout<<"OK";
        return 0;
    }
    cout<<"NG";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll sum = 0;
    rep(i, n) sum += (s[i] - '0');
    
    if(sum % 9 == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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


int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<list<int>> G(N);
  for(int ii=0; ii<N-1; ii++){
    G[ii].push_back(ii+1);
    G[ii+1].push_back(ii);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  vector<int> ans(N, 0);
  for(int ii=0; ii<N; ii++){
    vector<bool> flg(N, false);
    vector<vector<int>> bfs(N, vector<int>(2));

    int pos_1=0;
    int pos_2=1;
    flg[ii] = true;
    bfs[0][0] = ii;
    bfs[0][1] = 0;
    for(pos_1=0; pos_1<N; pos_1++){
      for(auto& next : G[bfs[pos_1][0]]){
        if(flg[next]) continue;
        flg[next] = true;
        bfs[pos_2][0] = next;
        bfs[pos_2][1] = bfs[pos_1][1] + 1;
        ans[bfs[pos_2][1]]++;
        pos_2++;
      }
    }
  }
  for(int ii=1; ii<N; ii++){
    cout << ans[ii] / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define M 1000000007
 
using namespace std;
 
int main(){
  int n,i,j,m;
  scanf("%d %d",&n,&m);
  string a[n];
  vector<vector<int>>dp(n,vector<int>(m,0));
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  dp[0][0] = 1;
  for(i=1;i<n;i++){
    if(a[i][0] == '.')
      dp[i][0] = max(0,dp[i-1][0]);
    else dp[i][0] = 0;
  }
  for(i=1;i<m;i++){
    if(a[0][i] == '.')
      dp[0][i] = max(0,dp[0][i-1]);
    else dp[0][i] = 0;
  }
  for(i=1;i<n;i++){
    for(j=1;j<m;j++){
      if(a[i][j] == '#'){
        dp[i][j] = 0;
        continue ;
      }
      dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
    }
  }
  printf("%d\n",dp[n-1][m-1]);
}

Measured memory_bytes: 5248
#!/usr/bin/env python
# coding: utf-8

# In[12]:


import sys
#import numpy as np
import itertools
input = sys.stdin.readline
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(M+1)]


# In[ ]:


"""
5 2
3 1 2 5
2 2 3
1 0
"""


# In[4]:


#print(l)
#import numpy as np


# In[15]:


cnt = 0
#print(itertools.product(range(0, 2), repeat=N))
for on in itertools.product(range(0, 2), repeat=N):
    for i in range(M):
        sum_ = 0
        for j in range(l[i][0]):
            ind = l[i][j+1]-1
            sum_ += on[ind]
        if sum_%2 != l[-1][i]:
            break
    else:
        cnt += 1
print(cnt)

"""
s = range(N)
cnt = 0
# N個がonになる
for e in range(1, N+1):
    c = list(itertools.combinations(s,e))# N個onになる通り
    o = list(range(N))
    for b in c:
        #print(b)
        a = np.zeros((N))
        for d in b:
            a[d] = 1
        #print(a)
        for i in range(M):
            sum_ = 0
            for j in range(l[i][0]):
                ind = l[i][j+1]-1
                #print(ind)
                sum_ += a[ind]
            o[i] = sum_%2==l[-1][i]
        if np.all(o):
            cnt += 1
#0個on
o = list(range(N))
a = np.zeros((N))
for i in range(M):
    sum_ = 0
    for j in range(l[i][0]):
        ind = l[i][j+1]-1
        sum_ += a[ind]
    o[i] = sum_%2==l[-1][i]
if np.all(o):
    cnt += 1
print(cnt)
"""


# In[ ]:


"""
2 2
2 1 2
1 2
0 1
"""



Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var k = IO.RInt;

            var que = new Queue<long>();
            for (int i = 1; i < 10; i++)
            {
                que.Enqueue(i);
            }
            long now = 0;
            for (int i = 0; i < k; i++)
            {
                now = que.Dequeue();
                for (int j = -1; j <= 1; j++)
                {
                    var add = (now % 10) + j;
                    if (add >= 0 && add <= 9) que.Enqueue(now * 10 + add);
                }
            }
            WriteLine(now);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 31508
# -*- coding:utf-8 -*-

def solve():
    N, M, K = list(map(int, input().split()))
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    sumAs = [0]*(N+1)
    for i in range(1, N+1):
        sumAs[i] = sumAs[i-1] + As[i-1]

    sumBs = [0]*(M+1)
    for i in range(1, M+1):
        sumBs[i] = sumBs[i-1] + Bs[i-1]

    i = 0
    while True:
        if i==(N+1) or sumAs[i] > K:
            break
        i += 1
    i = max(0, i-1)

    j = 0
    while True:
        if j==(M+1) or sumBs[j] + sumAs[i] > K:
            break
        j += 1
    j = max(0, j-1)

    ans = i+j

    # iを少しずつ減らし、jをその分増やし、最適解を見つける
    for n in range(i, -1, -1):
        while True:
            if j==(M+1) or sumBs[j] + sumAs[n] > K:
                break
            j += 1
        j = max(0, j-1)
        ans = max(ans, n+j)

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 47540
kstr = input()
klist = list(kstr)
klength = len(kstr)
ansstr = ["k","e","y","e","n","c","e"]
if klist[0:7] == ansstr :
  print("YES")
else:
  if (klist[0:6]+klist[klength-1:klength]) == ansstr :
    print("YES")
  else:
    if (klist[0:5]+klist[klength-2:klength]) == ansstr :
      print("YES")
    else:
      if (klist[0:4]+klist[klength-3:klength])== ansstr:
        print("YES")
      else:
        if (klist[0:3]+klist[klength-4:klength])== ansstr:
          print("YES")
        else:
          if (klist[0:2]+klist[klength-5:klength])== ansstr:
            print("YES")
          else:
            if (klist[0:1]+klist[klength-6:klength])== ansstr:
              print("YES")
            else:
              if (klist[klength-7:klength])== ansstr:
                print("YES")
              else:
                print("NO")

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
answer = []

for i in range (n) :
    number = 0
    odd = a[i] % 2
    a[i] = a[i] // 2    
    while odd <= 0 :
        number += 1
        odd = a[i] % 2
        a[i] = a[i] // 2
    answer.append(number)

print(min(answer))

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

int main(void) {
std::string s;
int n = 0;
std::cin >> s;

for (int i = 0; i < 4; i++) {
  if (s[i] == '+') {
    n++;
  } else n--;
}
std::cout << n << '\n';
return 0;
}


Measured memory_bytes: 256
n = int(input())

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s):
    if len(s) == n:
        print(conv(s))
    else:
        mx = max(s)+1
        for i in range(mx+1):
            dfs(s+[i])


dfs([0])

Measured memory_bytes: 56536
import sys

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

A, B = LIST()

print(max(A+B, A-B, A*B))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

int main(){
    DRI(n);
    VPLL a(n);
    REP(i,n){
        LL x,y;
        RII(x,y);
        a[i]={x-y,x+y};
    }

    sort(ALL(a));
    int tk=1;
    LL minend=0;
    bool hasminend=false;
    for (auto i: a){
        if (!hasminend) {hasminend=true; minend=i.S;}
        else{
            if (i.F>=minend) {tk++; minend=i.S;}
            else {minend=min(minend,i.S);}
        }
    }
    printf("%d\n",tk);
}


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

char s[99];

int main(){
    scanf("%s", s);
    int N = strlen(s);
    for(int i = 0; i < N - 1; ++i){
        if(s[i] == 'A' && s[i + 1] == 'C')return 0 & puts("Yes");
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
import math

a,b = map(int,input().split())
x = math.gcd(a,b)
s = [1]
for i in range(2,int(math.sqrt(x)+1)):
    if x%i == 0:
        while x%i == 0:
            x //= i
        s.append(i)
if x != 1:
    s.append(x)
l = len(s)
print(l)

Measured memory_bytes: 9144
N,L = map(int,input().split())
P = [L+i-1 for i in range(1,N+1)]
p = list(map(abs,P))
if 0 in P:
    print(sum(P))
else:
    print(sum(P)-min(p) if min(P) > 0 else sum(P)+min(p))

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

#define ll long long
#define fi first
#define sec second

ll n,m,k,x,x2,y,y2,sol=0,rep,cnt,sad;
char c;
string s;
vector <ll> V;

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++){
        if (i%3==0 || i%5==0) continue;
        sol+=i;
    }
    cout << sol;
}


Measured memory_bytes: 3636
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,a[210000],b[210000],c[210000],te;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	b[1]=a[1];
	fo(i,2,n){
		b[i]=b[i-1];
		if (a[i]>b[i]) b[i]=a[i];
	}
	c[n]=a[n];
	fd(i,n-1,1){
		c[i]=c[i+1];
		if (a[i]>c[i]) c[i]=a[i];
	}
	fo(i,1,n){
		te=b[i-1];
		if (c[i+1]>te) te=c[i+1];
		printf("%d\n",te);	
	}
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i = 0 ; i < n ; i++)
 
int main(){
  int N;
 
  cin >> N;
  double x[N], y[N];
  rep(i,N){
    cin >> x[i]; 
  }
  rep(i,N){
    cin >> y[i];
  }
 
  double p1 = 0, p2 = 0, p3 = 0, pINF = 0;
  rep(i,N){
    double diff = fabs(x[i]-y[i]);
    p1 += diff;
    p2 += pow(diff, 2.);
    p3 += pow(diff, 3.);
    pINF = max(pINF, diff);
  }
  p2 = sqrt(p2);
  p3 = pow(p3, 0.33333333333333333333);
  printf("%.6f\n%.6f\n%.6f\n%.6f\n" ,p1 ,p2 ,p3, pINF);
 
  return 0;
}


Measured memory_bytes: 3416
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	fmt.Println(n/2 - (1 - n%2))
}


Measured memory_bytes: 1772
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
const int N=4e5+10;
inline bool vaild(char c){return c>='A'&&c<='B';}
inline char gc(){char c=getchar();while(!vaild(c))c=getchar();return c;}
int n,k,a[N],st=1,flag;
int main(){
	scanf("%d%d",&n,&k);
	rep(i,1,n)a[i]=gc()-'A';
	int i;
	for(i=1;i<=k&&st<=n;++i){
		if((a[st]^flag)==0)a[st]^=1;
		else{
			a[n+st]=!flag;++st;
			flag^=1;
		}
	}--i;
	if((a[st]^flag))rep(i,st,st+n-1)printf("%c",'A'+(flag^a[i]));
	else{
		if((k-i)&1)putchar('B');else putchar('A');
		rep(i,st+1,st+n-1)printf("%c",'A'+(flag^a[i]));
	}
	return 0;
}


Measured memory_bytes: 1920
a,b = map(str,input().split())

if a == 'H' and b == 'H':
    print('H')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')
elif a == 'H' and b == 'D':
    print('D')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
bool kaibun(string h){
    int N = h.size();
string h_rev;
for(int i=0; i<N; i++){
    h_rev.push_back(h[N-1-i]);
}
if (h == h_rev) return true;
else return 0;
}


int main(){
    string S,S_rev;
    cin >> S;
    int N =S.size();
    bool a=false;bool b=false; bool c=false;

    a = kaibun(S);

    string l;
    for(int i=0; i<(N-1)/2; i++){
        l.push_back(S[i]);
    }
    b = kaibun(l);

    string v;
    for(int i=(N+3)/2-1; i<N; i++){
        v.push_back(S[i]);
    }
    c = kaibun(v);

    if(a && b && c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

    

Measured memory_bytes: 256
N, Y = gets.split.map(&:to_i)
 
flag = false
result = [-1, -1, -1]
(0..N).each do |i|
  (0..(N - i)).each do |j|
    if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y
      flag = true
      result = [i, j, N - i - j]
      break
    end
  end
  break if flag
end
 
puts "#{result[0]} #{result[1]} #{result[2]}"

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

const int INF = 100000;
typedef pair<int, int> P;

int n, m;
int sx, sy;
int gx, gy;

//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int main() {
	cin >> n;
	int a[300000] = { 0 };
	ll sum = 0;
	for (int i = 0; i < 3*n; i++) {
		cin >> a[i];
	}
	sort(a, a+3*n);
	for (int i = 1; i <= n; i++) {
		sum += a[3 * n - 2 * i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>

void swap(int array[], int a, int b){
	int c = array[a];
	array[a] = array[b];
	array[b] = c;
}

int main(){
	int array[50];
	int w,n,a,b;

	for(int i=0 ; i<50 ; i++){
		array[i] = i;
	}
	
	scanf("%d", &w);
	scanf("%d", &n);
	for(int i=0 ; i<n ; i++){
		scanf("%d,%d", &a, &b);
		swap( array , a , b );
	}
	for(int i=1 ; i<=w ; i++){
		printf("%d\n", array[i]);
	}
}

Measured memory_bytes: 1024
import scala.io.StdIn.{readLine,readInt}
import scala.math.pow

object Main {
  def main(args: Array[String]) = {
    val l = readLine().split(" ").map(_.toDouble)
    val (vx, vy) = (l(2)-l(0), l(3)-l(1))
    val n = readInt()

    val str = new StringBuilder
    for( i <- 1 to n ) {
      val l2 = readLine().split(" ").map(_.toDouble)
      val (vx2, vy2) = (l2(0)-l(0), l2(1)-l(1))
      val sqr = pow(vx,2) + pow(vy,2)
      val in_p = vx*vx2 + vy*vy2
      val (xt, yt) = ( in_p*vx/sqr + l(0), in_p*vy/sqr + l(1) )

      str ++= xt + " "+ yt + "\n"
    }
    print(str.toString)
  }
}

Measured memory_bytes: 47480
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a(n),summ(n+1);
  rep(i,n)cin>>a[i];
  rep(i,n)summ[i+1]=summ[i]+a[i];
  ll res=1e18;
  rep(i,n-1)
  {
    chmin(res,abs(summ[n]-2*summ[i+1]));
  }
  cout<<res<<endl;



  return 0;

}


Measured memory_bytes: 3456
def function(k, n, array)
	# 隣接する家の間の最大の距離.
	max_distance = array.first + k - array.last
	(0...(n - 1)).each do |index|
		distance = array[index + 1] - array[index]
		max_distance = (distance > max_distance) ? distance : max_distance
	end
	k - max_distance
end

k, n = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
puts function(k, n, a)



Measured memory_bytes: 16644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n;
    cin >> n;
    ll ans = 1000 - n%1000;
    if (ans == 1000) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 3628
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

int main()
{
	vector<int>map_x, map_y;
	int N;
	int map_x_size,map_y_size;
	int x, y, w;
	cin >> N >> map_x_size >> map_y_size;
	map_x_size *= 2; map_y_size *= 2;
	map_x_size++; map_y_size++;
	map_x.resize(map_x_size+1);
	map_y.resize(map_y_size+1);
	for (size_t i = 0; i < N; i++)
	{
		cin >> x >> y >> w;
		x *= 2; y *= 2; w *= 2;
		map_x[max(0, x - w)]++;
		map_x[min(x + w+1, map_x_size)]--;
		map_y[max(0, y - w)]++;
		map_y[min(y + w+1, map_y_size)]--;
	}
	bool f1 = 1, f2 = 1;
	for (size_t i = 0; i < map_x_size; i++)
	{
		if (i)
		{
			map_x[i] += map_x[i - 1];
			
		}
		if (map_x[i] < 1)
		{
			f2 = 0;
		}
	}

	for (size_t i = 0; i < map_y_size; i++)
	{
		if (i)
		{
			map_y[i] += map_y[i - 1];
			
		}
		if (map_y[i] < 1)
		{
			f1 = 0;
		}
		
	}
	cout << (f1||f2?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 2584
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


int D;
int c[26];
int s[365][26];



void greedy() {
	int last[26] = {};
	rep(i, 26)last[i] = -1;

	rep(i, D) {
		int ma = -INF;
		int con = -1;

		int pena[26];
		rep(j, 26) {
			pena[j] = c[j] * (i - last[j]);
		}

		rep(j,26) {
			int score = s[i][j] + pena[j];
			if (ma < score) {
				ma = score;
				con = j;
			}
		}
		assert(con != -1);

		last[con] = i;
		cout << con + 1 << endl;
	}
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> D;
	cerr << D << endl;
	rep(i, 26)cin >> c[i];
	rep(i, 365) {
		rep(j, 26)cin >> s[i][j];
	}

	greedy();



	return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second


void solve(){
    string s;cin>>s;
    int k;cin>>k;
    REP(i,s.size()){
        int x='z'-s[i]+1;
        if(s[i]!='a'&&x<=k){s[i]='a';k-=x;}
    }
    s[s.size()-1]+=k%26;
    cout<<s<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> x(n),a(n);
    rep(i,n){
        cin >> x[i];
        a[i] = x[i];
    }
    
    sort(a.begin(),a.end());
    rep(i,n){
        if(x[i] < a[n/2]) cout << a[n/2] << endl;
        else cout << a[n/2-1] << endl;
    }
    
}


Measured memory_bytes: 3840
from copy import deepcopy
from math import sqrt

string = input()
split = string.split()
N = int(split[0])
D = int(split[1])

vectors = []
for i in range(N):
    string = input()
    split = string.split()
    vec = []
    for j in range(D):
        vec.append(int(split[j]))
    vectors.append(deepcopy(vec))

cnt = 0
for i in range(N):
    for k in range(i + 1, N):
        val = 0
        for a in range(D):
            val += (vectors[i][a] - vectors[k][a]) ** 2
        if sqrt(val).is_integer():
            cnt += 1
print(cnt)


Measured memory_bytes: 3444
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAX=110;
char m[MAX][MAX];
int a,b,ac=1,bc=1,h,w,now;
int main(){
    scanf("%d%d",&a,&b);
    for(int i=0;i<100;i++) for(int j=0;j<50;j++) m[i][j]='.';
    for(int i=0;i<100;i++) for(int j=50;j<100;j++) m[i][j]='#';
    for(int i=0;i<100;i+=2){
        for(int j=0;j<40;j+=2){
            if(bc<b) m[i][j]='#',bc++;
        }
    }
    for(int i=0;i<100;i+=2){
        for(int j=60;j<100;j+=2){
            if(ac<a) m[i][j]='.',ac++;
        }
    }
    printf("100 100\n");
    for(int i=0;i<100;i++) printf("%s\n",m[i]);
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n;
  cin >> n;
  vector< lint > a(n);
  for (lint i=0; i<n; ++i) cin >> a[i];
  sort(a.rbegin(), a.rend());
  lint ans = 0;
  priority_queue< lint > q;
  q.push(a[0]);
  for (lint i=1; i<n; ++i) {
    ans += q.top();
    q.pop();
    q.push(a[i]);
    q.push(a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6892