akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;				//インサーションソート（挿入法）

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] k = new int[4];					// 0 1 2
		int i,j;
		for(i = 0; i < 3; i++) {
			k[i] = scan.nextInt();
		}

		int n = 3;						//データ数
		int hozon;						

		for(i = 1; i < n; i++){
			k[n] = k[i];
			for(j = i-1; j >= 0 && k[j] > k[n]; j--){
				k[j+1] = k[j];
			}
			if(j != i-1){
				k[j+1] = k[n];
			}
			
		}

		for(i = 0; i < n; i++){
			System.out.print(k[i]);
			if(i < n-1) System.out.print(" ");
		}
		System.out.println("");
	}
}



Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	vector<int> dp(n, 0);
	dp[1] = abs(h[0]-h[1]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]));
	}
	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> > g[310000];
vector<pair<long long,long long> > dp[310000];
int n;
long long d[310000];
void dfs(int a){
	for(int i=0;i<g[a].size();i++){
		d[g[a][i].first]=d[a]+g[a][i].second;
		dfs(g[a][i].first);
	}
}
long long T;
void solve(int a){
	if(g[a].size()){
		solve(g[a][0].first);
		solve(g[a][1].first);
		vector<pair<long long,long long> > &L=dp[g[a][0].first];
		vector<pair<long long,long long> > &R=dp[g[a][1].first];
		if(L.size()>R.size()){
			vector<pair<long long,long long> > ad;
			for(int i=0;i<R.size();i++){
				long long t=R[i].second;
				long long rem=T-(t-d[a]);
				if(rem<0)continue;
				int left=-1;
				int right=L.size();
				while(left+1<right){
					int M=(left+right)/2;
					if(L[M].first<=d[a]+rem)left=M;
					else right=M;
				}
				int at=left;
				if(at<0||at>=L.size())continue;
				ad.push_back(make_pair(R[i].first,L[at].second));
				ad.push_back(make_pair(L[at].second,R[i].first));
			}
			std::sort(ad.begin(),ad.end());
			long long last=99999999999999999LL;
			for(int i=0;i<ad.size();i++){
			//	if(ad[i].first-d[a]>T)continue;
				if(last>ad[i].second){
					last=min(last,ad[i].second);
					dp[a].push_back(make_pair(ad[i].first,last));
				}
			}
			return ;
	//		swap(L,R);
	//		swap(g[a][0],g[a][1]);
		}
		vector<pair<long long,long long> > ad;
		for(int i=0;i<L.size();i++){
			long long t=L[i].second;
			long long rem=T-(t-d[a]);
			if(rem<0)continue;
			int left=-1;
			int right=R.size();
			while(left+1<right){
				int M=(left+right)/2;
				if(R[M].first<=d[a]+rem)left=M;
				else right=M;
			}
			int at=left;
			if(at<0||at>=R.size())continue;
			ad.push_back(make_pair(L[i].first,R[at].second));
			ad.push_back(make_pair(R[at].second,L[i].first));
		}
		std::sort(ad.begin(),ad.end());
		long long last=99999999999999999LL;
		for(int i=0;i<ad.size();i++){
		//	if(ad[i].first-d[a]>T)continue;
			if(last>ad[i].second){
				last=min(last,ad[i].second);
				dp[a].push_back(make_pair(ad[i].first,last));
			}
		}
	//	return ret;
	}else{
		dp[a].push_back(make_pair(d[a],d[a]));
	//	return ret;
	}
}
bool check(long long a){
	T=a;
	for(int i=0;i<n;i++)dp[i].clear();
	solve(0);
	if(dp[0].size())return true;
	else return false;
}
int main(){
	int a;scanf("%d",&a);
	n=a;
	for(int i=0;i<a-1;i++){
		int p,q;
		scanf("%d%d",&p,&q);
		p--;
		g[p].push_back(make_pair(i+1,q));
	}
	dfs(0);
	long long left=-1;
	long long right=300020LL*300020LL;
	while(left+1<right){
		long long M=(left+right)/2;
		if(check(M))right=M;
		else left=M;
	}
	printf("%lld\n",right);
}

Measured memory_bytes: 43276
#include <bits/stdc++.h>
using namespace std;
#define MAXN 200000
#define ll long long
#define rint register int
inline int rf(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int A[MAXN+5], n, m; ll Ans; int main(){n = rf(); generate(A,A+n,rf); for(rint i = 0; i < n; A[i] -= i, i++); sort(A,A+n); m = A[n>>1]; for(rint i = 0; i < n; Ans = Ans+abs(A[i]-m), i++); return !printf("%lld\n",Ans);}

Measured memory_bytes: 1024
import sys
import bisect
n = int(input())
A = list(map(int,input().split()))
A.sort()
m = A[-1]
if n == 2:
    print(A[-1],A[0])
    sys.exit()
i = bisect.bisect_left(A,m//2)
if i == 0:
    print(m,A[0])
else:
    if m - A[i] < A[i-1]:
        print(m,A[i-1])
    else:
        print(m,A[i])

Measured memory_bytes: 14428
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int now=b-a,k=0;
	for(int i=1;i<=now;++i)
	{
		k+=i;
	}
	printf("%d",k-b);
	return 0;
}


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


int main() {

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

  int a,b,c;
  cin >> a >> b >> c;

  int k;
  cin >> k;

  int sum = a + b + c - max(a,max(b,c));

  int cur = max(a,max(b,c));
  for (int i = 1; i <= k; i++) {
    cur *= 2;
  }

  sum += cur;
  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,ml;
	float a[50],b[51],mi=1001;
	cin>>n;
	for(int t=0;t<n;t++)
	{
		cin>>a[t];
	}
	for(int i=1;i<=n;i++)
	{
		mi=1001;
		for(int t=0;t<n;t++)
		{
			if(a[t]<mi)
			{
				mi=a[t];
				b[i]=mi;
				ml=t;
				//cout<<"b["<<i<<"]="<<mi<<" ";
			}
		}
		a[ml]=1001;
	}
	for(int t=2;t<=n;t++)
	{
		b[t]=(b[t-1]+b[t])/2;
		//cout<<b[t]<<" ";
	}
	cout<<b[n];
	return 0;
} 

Measured memory_bytes: 256
def get_list(str):
    str_list = str.split(" ")
    result_list = []
    for str in str_list:
        result_list.append(int(str))
    return result_list

n = int(input())
b_str = input()
b_list = get_list(b_str)

result = 0
pre_num = pow(10, 5)
for b in b_list:
    if b >= pre_num:
        result += pre_num
    else:
        result += b
    pre_num = b
result += b_list[-1]

print(result)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N,X;
     cin >> N >> X;
     int sum = 0;
     vector<int> m(N);
     for(int i = 0; i < N; i++){
          cin >> m[i];
          sum += m[i];
     }
     sort(m.begin(),m.end());
     int y = X - sum;
     cout << N + y / m[0] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <type_traits>
#include <map>

using namespace std;

int64_t n, a, b, c, d;
int64_t low_limit;

vector<unordered_map<int64_t, int64_t>> dp(2);

// vector<int64_t> divs = {2, 3, 5};

int64_t GetAns(int64_t x, int state, int64_t limit = -1) {
    if (x <= 0) {
        return 0;
    }

    if (x < low_limit) {
        return x * d;
    }

    auto it = dp[state].find(x);
    if (it != dp[state].end()) {
        return it->second;
    }

    int64_t result = numeric_limits<int64_t>::max() / 2;
    if (state == 0) {
        for (int i = -4; i < 4; ++i) {
            if (x + i < limit) {
                result = min(result, d * abs(i) + GetAns(x + i, 1 - state));
            }
        }
    } else {
        if (x % 2 == 0) {
            result = min(result, a + GetAns(x / 2, 1 - state, x));
        }
        if (x % 3 == 0) {
            result = min(result, b + GetAns(x / 3, 1 - state, x));
        }
        if (x % 5 == 0) {
            result = min(result, c + GetAns(x / 5, 1 - state, x));
        }
    }

    dp[state][x] = result;
    return result;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

#ifdef TEST
    std::freopen("../input.txt", "r", stdin);
    // std::freopen("../output.txt", "w", stdout);
#endif

    int t;
    cin >> t;
    for (int test = 0; test < t; ++test) {
        cin >> n >> a >> b >> c >> d;

        low_limit = numeric_limits<int64_t>::max();
        low_limit = min(low_limit, 2 * a / d);
        low_limit = min(low_limit, 3 * b / 2 / d);
        low_limit = min(low_limit, 5 * c / 4 / d);

        dp[0].clear();
        dp[1].clear();

        auto ans = GetAns(n, 0, n + 5);

        cout << ans << endl;
    }

    return 0;
}


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

int main(){
    int n, x[100],y[100];
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<n;i++) cin >> y[i];
    
    double d[4];
    for(int i=0;i<4;i++) d[i]=0.0;
    
    for(int p=1;p<=3;p++){
        for(int i=0;i<n;i++){
            d[p] += pow(fabs(x[i]-y[i]),p);
            
        }
        d[p]=pow(d[p],1.0/p);
    }
    
    for(int i=0;i<n;i++){
        d[0] = (d[0] < fabs(x[i]-y[i])?fabs(x[i]-y[i]):d[0]);
    }
    printf("%lf\n",d[1]);
    printf("%lf\n",d[2]);
    printf("%lf\n",d[3]);
    printf("%lf\n",d[0]);
    
    return 0;
}


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

using namespace std;

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

Measured memory_bytes: 256
#直感を証明できなかった

n = int(input())
l = []
for i in range(n):
    a,b = map(int, input().split())
    l.append((b, a)) #終了時間、工数
l = sorted(l) #終了時間が速い順に並べる

def check(l):
    t = 0 #現時刻
    for end, worktime in l:
        t += worktime
        if t > end:
            return 'No'
            break
            
    return 'Yes'
print(check(l))

Measured memory_bytes: 30972
n,m = map(int, input().split())
mise_list = [list(map(int, input().split())) for _ in range(n)]
mise_list.sort()
ans = 0
for i in range(n):
    smaller = min(m, mise_list[i][1])
    ans += mise_list[i][0] * smaller
    m -= min(m, mise_list[i][1])
    if m <= 0:
        break
print(ans) 

Measured memory_bytes: 27880
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int max=1;

		for(int i=0; i<N; i++){
			String str = sc.next();
			if(map.containsKey(str)){
				int num = map.get(str);
				map.replace(str, num+1);
				if(max<num+1){
					max = num+1;
				}
			}else{
				map.put(str, 1);
			}
		}
		List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(map.entrySet());

		Collections.sort(list, new Comparator<Entry<String, Integer>>() {
			public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2) {
				if(obj1.getValue()==obj2.getValue()){
					return obj1.getKey().compareTo(obj2.getKey());
				}else{
					return obj2.getValue().compareTo(obj1.getValue());
				}
			}
		});

		for(Entry<String, Integer> entry : list) {
			if(entry.getValue()==max){
				System.out.println(entry.getKey());
			}
		}
        
    }
}


Measured memory_bytes: 89840
s=input()
t=input()

count_min = 1000

for i in range(len(s)-len(t)+1):
  count = 0
  for j in range(len(t)):
    if s[i+j] != t[j]:
      count+=1 
  if count < count_min:
    count_min = count

print(count_min)

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

using namespace std;

int main()
{
   int arr[200000];
   vector<int>vec;
   int num;
   cin>>num;
   for(int i=0;i<num;i++)
   {
       cin>>arr[i];
       vec.push_back(arr[i]);
   }
   sort(vec.begin(),vec.end());
   for(int r=0;r<num;r++)
   {
       if(arr[r]<vec[vec.size()-1])
          cout<<vec[vec.size()-1]<<endl;
       else
          cout<<vec[vec.size()-2]<<endl;
   }
   return 0;
}


Measured memory_bytes: 3316
#include <stdio.h>

int main(void)
{
    int H,W,N;
    int a[10000];
    int tmp[10000];
    scanf("%d %d",&H, &W);
    scanf("%d", &N);
    for( int i = 0; i < N; i++){
        scanf("%d",&a[i]);
    }
    int k = 0;
    for( int i = 0; i < H; i++){
        for( int j = 0; j < W; j++){
            if( a[k] > 0){
                tmp[i*W+j] = k+1;
                a[k]--;
            }
            else if( a[k] == 0){
                k++;
                tmp[i*W+j] = k+1;
                a[k]--;
            }
        }
        if( i % 2 == 1){
            for( int j = 0; j < W/2; j++){
                tmp[i*W+j] += tmp[(i+1)*W-j-1];
                tmp[(i+1)*W-j-1] = tmp[i*W+j] - tmp[(i+1)*W-j-1];
                tmp[i*W+j] -= tmp[(i+1)*W-j-1];
            }
        }

        for( int j = 0; j < W; j++){
            printf("%d ", tmp[i*W+j]);
        }
        puts("");
    }

    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X = read().rstrip().decode()

s, t = 0, 0
for x in X:
    if x == 'S':
        s += 1
    else:
        if s == 0:
            t += 1
        else:
            s -= 1

print(s+t)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  int List[9] = {-1,1,2,4,8,16,32,64,128};
  for (int i = 8; i >= 1; i--) {
    if (List[i] > N && N >= List[i - 1]) {
      ans = List[i - 1];
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastReader sc=new FastReader();
// 		constructST(a,n);RMQ(n, qs, qe)
        // sieveOfEratosthenes();
//		Stack<Character> st=new Stack <> ();
		int n=sc.nextInt(),a[]=new int[n],i;
		long dp[]=new long[n];
		for(i=0;i<n;i++)
			a[i]=sc.nextInt();
		dp[0]=0;dp[1]=Math.abs(a[1]-a[0]);
		for(i=2;i<n;i++)
			dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		System.out.println(dp[n-1]);
	}
	static int lower_bound(int a[],int x){
         int n=a.length,low=0,high=n-1,res=-1;
         while(low<=high){
             int mid=(low+high)>>1;
             if(a[mid]>=x){
                res=mid;high=mid-1;
             }
             else 
                low=mid+1;
         }
         return res;
     }
      static int upper_bound(int a[],int x){
          int n=a.length,low=0,high=n-1,res=-1;
          while(low<=high){
              int mid=(low+high)>>1;
              if(a[mid]<=x){
                  res=mid;low=mid+1;
              }
              else 
                  high=mid-1;
          }
          return res;
      }
      static long modexpo(long x,long n,long m){
        if(n==0)
            return 1;
        else if(n%2==0)
            return (modexpo(((x%m)*(x%m))%m,n/2,m))%m;
        else
            return ((x%m)*((modexpo(((x%m)*(x%m))%m,(n-1)/2,m))%m))%m;
      } 
       static int gcd(int a,int b){
           if(b==0)
              return a;
           else 
              return gcd(b,a%b);
       }
       static long gcd(long a,long b){
           if(b==0)
              return a;
           else 
              return gcd(b,a%b);
       }
	 static class FastReader{
          BufferedReader in;
          StringTokenizer st;
          public FastReader(){
              in=new BufferedReader(new InputStreamReader(System.in));
          }
          String next(){
              while(st==null || !st.hasMoreElements()){
                  try{
                      st=new StringTokenizer(in.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 str19 = "";
            try{
                str19 = in.readLine();
            }
            catch (IOException e){
                e.printStackTrace();
             }
            return str19;
        }
      }    
}

Measured memory_bytes: 31624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c;
    char op;
    scanf("%lld %c %lld",&a,&op,&b);
    if(op=='+') printf("%lld\n",a+b);
    else printf("%lld\n",a-b);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    int Q = Integer.parseInt(sc.next());
    
    int[] val = new int[N];
    for(int i = 0; i < Q; i++){
      int A = Integer.parseInt(sc.next());
      val[A-1]++;
    }
    
    String ans = "";
    for(int i = 0; i < N; i++){
      if(Q-val[i] < K){
        ans = "Yes";
      }else{
        ans = "No";
      }
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 50188
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int ans = (H-h)*(W-w);
		System.out.println(ans);
		sc.close();
	}
	

}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
   int N;
   cin>>N;
   vector<int> A(N);
   for(int i=0;i<N;i++){
       cin>>A.at(i);
   }
   sort(A.begin(),A.end());
   int sum=0;
   for(int i=0;i<N-1;i++){
      sum+=A.at(i);
   }
   if(sum>A.at(N-1)) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}    

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	string s;
	cin >> s;
	ll v = 0;
	rep(i, 0, s.size())v += s[i] - '0';
	puts(v % 9 == 0 ? "Yes" : "No");
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string S;
	cin >> S;
	REP(i, S.size()){
		if(i==5||i==13) cout << ' ';
		else cout << S[i];
	}
	cout << endl;
    return 0;
}

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt=0;
    bool flg=true;
    while(flg){
        if(a>=b){
            b*=2;
            cnt++;
        }if(b>=c){
            c*=2;
            cnt++;
        }
        if(a<b && b<c) flg=false;
    }
    if(cnt<=k) cout << "Yes"<<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int k,n;
	cin >> k >> n;
	int a[2*n];
	forr(i,n) cin >> a[i];
	for(int i = n; i < 2*n; i++){
		a[i] = a[i - n] + k;
	}
	int ans = INF;
	for(int i = n-1 ; i < 2*n; i++){
		ans = min(ans,a[i] - a[i-n+1]);
	}
	cout << ans;
}

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

int main(void){
  int N,X;cin>>N>>X;
  vector<int>Le;
  Le.resize(N);
  for(int i = 0;i < N;i++)cin>>Le[i];

  int sum = 0;
  int count = 1;
  for(int t = 0;t < N;t++){
    sum += Le[t];
    if(sum <= X)count++;
  }
  cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll N, K; 
  cin >> N >> K;
  ll X;
  ll co = 0;
  rep(i, N) {
    cin >> X;
    if(X >= K) {
      co++;
    }
  }
  cout << co << endl;
}

Measured memory_bytes: 3624
s=input()
a=''
b=''
countA,countB = 0,0
aDefined = False
bDefined = False

for char in list(s):
    if char == a :
        countA += 1
    elif char == b:
        countB += 1
    elif not aDefined:
        aDefined = True
        countA += 1
        a = char
    elif not bDefined:
        bDefined = True
        countB += 1
        b = char
    else:
        break
if countA == 2 and countB == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#   AtCoder abc056 a
#   ストレッチ課題

#   入力
a, b = map(str, input().split())

#   判定
# if ((a == "H") and (b == "H")) or ((a == "D") and (b == "D")):
#     print("H")
# else:
#     print("D")
if a == b:
    print("H")
else:
    print("D")


Measured memory_bytes: 8888
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

int main() {
	int a, b;
	while(cin >> a >> b) {
		cout << toString<int>(a+b).size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 2222
int a[3][N],dp[3][N];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1; i<=2; i++)
            for(int j=1; j<=n; j++)
                scanf("%d",&a[i][j]);
        memset(dp,0,sizeof dp);
        for(int i=1; i<=2; i++)
            for(int j=1; j<=n; j++)
            {
                dp[i][j]=max(dp[i-1][j]+a[i][j],dp[i][j-1]+a[i][j]);
            }
            printf("%d\n",dp[2][n]);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#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 repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  typedef pair<int, int> P;
  vector<P> ct(N);
  rep(i, N) cin >> ct[i].fi >> ct[i].se;

  sort(all(ct));

  for (int i = 0; i < N; i++) {
    if (ct[i].se <= T) {
      cout << ct[i].fi << endl;
      return 0;
    }
  }
  cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int X;
  cin >> X;
  if(X>=30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            int a;int b;int c;int d;
            Multi(out a, out b, out c, out d);
            var ans = YesNo((Math.Abs(a - c) <= d) || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d));

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static void Solve()
        {
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c,out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);d=cv<V>(ar[3]) ;
        }
    }
}

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

int main(){
    int n;  cin>>n;
    string word[n]; for(int i=0;i<n;i++)cin>>word[i];

    bool flag=true;
    for(int i=0;i<n-1;i++){
        if(word[i][word[i].length()-1]!=word[i+1][0]){
            flag=false;
            break;
        }

        for(int j=i+1;j<n;j++){
            if(word[i]==word[j])flag=false;
        }if(flag==false)break;
    }
    flag==true? cout<<"Yes"<<endl : cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
L = [input() for _ in range(N)] # 小技1

#L = [] ← 小技1を使わない場合
#for n in range(N): ← 小技1を使わない場合
    #S = input() ← 小技1を使わない場合
    #L.append(S) ← 小技1を使わない場合

Dic = Counter(L)
max_value = max(Dic.values())
max_k_list = [i for i, j in Dic.items() if j == max_value]
max_k_list = sorted(max_k_list)
 
print(*max_k_list , sep="\n")

Measured memory_bytes: 35824
def __main__():
    orders = []
    for i in range(5):
        orders.append(int(input()))
    last = min(orders, key=(lambda x: (x-1)%10))
    orders.remove(last)
    print(sum(map((lambda x: (x+9)//10*10), orders)) + last)
if __name__ == "__main__":
    __main__()

Measured memory_bytes: 3060
#include <stdlib.h>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

using Point = pair<int, int>;

const int MAXN = 1000;
const int INF = 0x3f3f3f3f;
const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int h, w, n;
char field[MAXN + 1][MAXN + 1];

int BFS(Point start, Point goal) {
    int start_x = start.first;
    int start_y = start.second;
    int goal_x = goal.first;
    int goal_y = goal.second;
    int dist[MAXN][MAXN];
    for (size_t i = 0; i < h; i++) {
        for (size_t j = 0; j < w; j++) {
            dist[i][j] = INF;
        }
    }
    queue<Point> queue;
    queue.emplace(start_x, start_y);
    dist[start_x][start_y] = 0;

    while (queue.size()) {
        auto point = queue.front();
        queue.pop();
        if (point == make_pair(goal_x, goal_y)) { break; }
        for (size_t i = 0; i < STEP_NUM; i++) {   
            int new_x = point.first + STEP[i][0];
            int new_y = point.second + STEP[i][1];
            if (0 <= new_x && new_x < h && 0 <= new_y && new_y < w
                && field[new_x][new_y] != 'X' && dist[new_x][new_y] == INF) {
                queue.emplace(new_x, new_y);
                dist[new_x][new_y] = dist[point.first][point.second] + 1;
            }
        }
    }

    return dist[goal_x][goal_y];
}

int main() {
    scanf("%d %d %d\n", &h, &w, &n);
    Point start;
    vector<Point> goals(n + 1);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            scanf("%c", &field[i][j]);
            switch (field[i][j]) {
                case 'S':
                    goals[0] = make_pair(i, j);
                    break;
                case '.':
                case 'X':
                    break;
                default:
                    goals[field[i][j] - '0'] = make_pair(i, j);
            }
        }
        getchar();
    }

    int best_time = 0;
    for (int i = 0; i < n; i++) {
        best_time += BFS(goals[i], goals[i + 1]);
    }
    printf("%d\n", best_time);

    return 0;
}

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

int main(){
	int w,n;
	cin >> w >> n;
	int num[w + 1];
	for(int i = 1; i <= w; i++)num[i] = i;
	int a,b,temp;
	char c;
	while(cin >> a >> c >> b){
		temp = num[a];
		num[a] = num[b];
		num[b] = temp;
	}
	for(int i = 1; i <= w; i++)cout << num[i] << endl;
}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
map<string,bool>mp;
int n,cnt,digit,baki;
struct
{
    vector<string>sz[11];
} num[10];

void solve(int i, int k)
{
    int ss=num[k].sz[baki].size();
    for(int l=0; l<ss; l++,cnt++)
    {
        string str;
        str+=(i+'0');
        str.append(num[k].sz[baki][l]);
        num[i].sz[digit].push_back(str);
        if(i==1)
        {
            string st;
            st+='0',st.append(str);
            num[0].sz[digit+1].push_back(st);
        }
        if(cnt+1==n)
        {
            cnt++;
            cout<<str<<endl;
            //    for(i=0;i<num[0].sz[9].size();i++)cout<<num[0].sz[9][i]<<endl;
            return;
        }
    }
}

int main()
{
    int k,i,j,a;
    cin>>n;
    if(n<10)printf("%d\n",n),exit(0);
    num[0].sz[1].push_back("0");
    num[0].sz[2].push_back("00");
    num[0].sz[2].push_back("01");
    for(j=1; j<10; j++)
    {
        string str;
        str+=(j+'0');
        num[j].sz[1].push_back(str);
    }
    digit=2,cnt=0,n-=9;
    while(cnt<n)
    {
        baki=digit-1;
        int ss=num[0].sz[digit].size();
        for(int l=0; l<ss; l++)
        {
            string str;
            str+='0',str.append(num[0].sz[digit][l]);
            num[0].sz[digit+1].push_back(str);
        }
        for(i=1; i<10; i++)
        {
            solve(i,i-1);
            if(cnt!=n)solve(i,i);
            else exit(0);
            if(i!=9)solve(i,i+1);
        }
        digit++;
    }
    return 0;
}


Measured memory_bytes: 12668
# abc118_a.py
# https://atcoder.jp/contests/abc118/tasks/abc118_a

# A - B +/- A /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 正整数 A,Bが与えられます。

# Aが B の約数なら A+B を、そうでなければ B−Aを出力してください。

# 制約
#     入力は全て整数である。
#     1≤A≤B≤20

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B

# 出力
# Aが B の約数なら A+B を、そうでなければ B−Aを出力せよ。

# 入力例 1
# 4 12

# 出力例 1
# 16

# 4は 12 の約数なので 4+12=16を出力します。

# 入力例 2
# 8 20

# 出力例 2
# 12

# 入力例 3
# 1 1

# 出力例 3
# 2

# 1は 1 の約数です。


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    A, B = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))

    if B % A == 0:
        result = A+B
    else:
        result = B-A

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 12']
        lines_export = [16]
    if pattern == 2:
        lines_input = ['8 20']
        lines_export = [12]
    if pattern == 3:
        lines_input = ['1 1']
        lines_export = [2]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

using namespace std;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
#define rep(i,n)for(int i=0;i<n;i++)
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
char b[200000], ok[100000]{ 1 };
deque<int>que;

void bfs(int u, bool t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
			if (d[v[i]] < d[u[i]]) {
				E[v[i]].emplace_back(u[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
		if (d[v[r[i]]] < d[u[r[i]]] && !ok[u[r[i]]]) {
			E[v[r[i]]].emplace_back(u[r[i]]);
			if (ok[v[r[i]]]) {
				cnt++; ok[u[r[i]]] = 1;
				bfs(u[r[i]], 1);
			}
		}
	}
	rep(i, q)writerLn(ans[i]);
}

Measured memory_bytes: 13572
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


nn,k=map(int,input().split())
*A,=sorted(map(int,input().split()))
B=sorted(A,reverse=True)
mod=10**9+7

mi,ma=0,0
for i in range(k-1,nn):
    L=cmb(i,k-1,mod)    
    ma+=L*A[i]
    mi+=L*B[i]
    
print((ma-mi)%mod)


Measured memory_bytes: 26728
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e2;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int N,A[MAX];
ll sum,sum2,xx[2];
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    int avg=sum/N;
    
    
    for(int k=0;k<2;k++){
        for(int i=0;i<N;i++){
            xx[k]+=pow(A[i]-avg-k,2);
        }
    }
    
    cout<<min(xx[0],xx[1])<<"\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 100
 
int main()
{
  int x[N],i=0;
  char s[N];
 
  while(scanf("%s", s) != EOF){
    if (s[0] == '+'){
      x[i-2]=x[i-2]+x[i-1];
      i--; 
    } else if(s[0] == '-'){
      x[i-2]=x[i-2]-x[i-1];
      i--;
    } else if(s[0] == '*'){
      x[i-2]=x[i-2]*x[i-1];
      i--;
    } else{
      x[i] = atoi(s);
      i++;
    }
  }
  printf("%d\n",x[0]);
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define pi pair<int, int>
#define pb push_back

using namespace std;

const int maxn = 1e5 + 1;

int a[maxn], p[maxn];

signed main() {
  	int x, y, z;
  	cin >> x >> y >> z;
 	swap(x, y); swap(x, z);
  	cout << x << ' ' << y << ' ' << z;
    return 0;
}
/*
2
aabbaabbbaaaa
aaaabbbaabbaa

2
bbaabaaaaabbbbbbbababaabaabaabbabababbbabbabbabbbabaabbbbbbaabaaaaaaaaababaaabbabbaaaaaabaababbaaabbbbbaaabababbaaabbbbaaababbbabaaabaaabbbbbbbbbbbabaaaaabaabababababbbaabaaaababaababbaaaabbababbbabba
abbabbbababbaaaabbabaababaaaabaabbbababababaabaaaaababbbbbbbbbbbaaabaaababbbabaaabbbbaaabbababaaabbbbbaaabbabaabaaaaaabbabbaaababaaaaaaaaabaabbbbbbaababbbabbabbabbbabababbaabaabaabababbbbbbbaaaaabaabb
*/


Measured memory_bytes: 256
INF = float('inf')
n = int(input())
h = [int(i) for i in input().split()]
dp = [0, abs(h[1] - h[0])]
for i in range(2, n):
    dp += [min(dp[-1] + abs(h[i] - h[i - 1]), dp[-2] + abs(h[i] - h[i - 2]))]
print(dp[-1])

Measured memory_bytes: 13980
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

vll M;

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

ll dfs(ll v){
	if(M[v]>=0) return M[v];

	ll B=0,V=v;
	while(V){
		if(V&1) B++;
		V/=2;
	}

	if(!B){
		M[v]=0;
		return 0;
	}
	if(!(v%B)){
		M[v] = 1;
		return 1;
	}

	ll C = dfs(v%B)+1;
	M[v] = C;
	return C;
}

ll safemod(ll a,ll m){
	return (a%m+m)%m;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	string X=in<string>();
	M.resize(N+1,-1);
	ll C=0;
	REP(i,N){
		if(X[i]=='1'){
			C++;
		}
	}
	ll modP=0,modD=0;
	if(C<N){
		REP(j,N){
			if(X[N-1-j]=='1'){
				modP += powermod(2,j,C+1);
				modP %= (C+1);
			}
		}
	}
	if(C>1){
		REP(j,N){
			if(X[N-1-j]=='1'){
				modD += powermod(2,j,C-1);
				modD %= (C-1);
			}
		}
	}

	ll K[2]={C-1,C+1};
	REP(i,N){
		ll B;
		auto T=X;
		ll mod=0;
		if(T[i]=='0'){
			T[i] = '1';
			B = 1;
			mod = modP;
			mod += powermod(2,N-1-i,K[B]);
			mod %= K[B];
		}
		else{
			T[i] = '0';
			B = 0;
			if(K[B]==0){
				out(0);
				continue;
			}
			mod = modD;
			mod -= powermod(2,N-1-i,K[B]);
			mod = safemod(mod,K[B]);
		}

		ll Z=1;
		while(mod){
			Z++;
			ll P=0,V=mod;
			while(V){
				if(V&1) P++;
				V/=2;
			}
			mod %= P;
		}
		out(Z);
	}


	return 0;
}


Measured memory_bytes: 5292
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(register int i=a;i<=b;i++)
template <typename T>
void read(T &x){
    x=0;
    int flag=1;
    char c=getchar();
    while(c=='-'){
        flag=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    x*=flag;
}
int n,k,a[100010],sum[100010],dp[100010],cnt=0;
char s[100010];
int main()
{
    read(n);read(k);
    cin>>s;
    if(s[0]=='0')a[++cnt]++;
    else a[cnt]++;
    rep(i,1,n-1){
        if(s[i]==s[i-1])a[cnt]++;
        else a[++cnt]++;
    }
    cnt++;
    sum[0]=a[0];
    rep(i,1,cnt)sum[i]=sum[i-1]+a[i];
    if(cnt/2<=k){cout<<sum[cnt];return 0;}
    int ans=0;
    for(int i=k*2;i<=cnt;i+=2){
        if(i==k*2)ans=sum[k*2];
        else ans=max(ans,sum[i]-sum[i-2*k-1]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1152
package main

import (
    "fmt"
)


var route []int

func main() {
  var N,M int
  var a,b int

  fmt.Scan(&N,&M)

  route = make([]int,N)

    for i := 0; i < M; i++ {
      fmt.Scan(&a,&b)

      route[a-1]++
      route[b-1]++
    }

    for i := 0; i < N ; i++{
      fmt.Println(route[i])
    }
}


Measured memory_bytes: 512
//
//  main.cpp
//  atcoder_c
//
//  Created by kao ching shan on 2019/3/9.
//  Copyright © 2019年 kao ching shan. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    
    long long int a=0,b=0,c=0;
    long long int bxor=0,axor=0,ans;
    cin >> a;
    cin >> b;
    if (a!=0)
        c = a-1;
    
    if(b%4==1)
        bxor = 1;
    else if(b%4==2)
        bxor = b+1;
    else if(b%4==3)
        bxor = 0;
    else if(b%4 == 0)
        bxor = b;
    
    if(c%4==1)
        axor = 1;
    else if(c%4==2)
        axor = c+1;
    else if(c%4==3)
        axor = 0;
    else if(c%4 == 0)
        axor = c;

    ans  = axor^bxor ;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, //data type
 null_type, //
 less<int>, //
 rb_tree_tag, //red-black tree
 tree_order_statistics_node_update> new_data_set;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e4 + 5);
const int MOD = 1000000007;




int main(){
    FASTIO;
#ifdef _online_judge
    freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
#endif

    vector<int> v(5);
    int ans = INT_MAX;
    FOR(i,0,5) cin >> v[i];
    do{
        int j=0;
        for(int k:v){

            if(j%10 != 0){
                j += 10-(j%10);
            }
            j += k;
        }
        ans = min(ans,j);
    }while(next_permutation(v.begin(),v.end()));
    cout << ans;
}


Measured memory_bytes: 256