akhauriyash/Code-Regression huggingface dataset:
def IntBaseConvert(N,K):
    if (type(N) is int) and (type(K) is int):
        if K>=2 and N>=0:
            if N==0:
                return [0]
            else:
                ConvertNum = []
                while N>0:
                    ConvertNum.append(N%K)
                    N = N//K
                return ConvertNum[::-1]
        elif K<=-2:
            if N==0:
                return [0]
            else:
                ConvertNum = []
                while abs(N)>0:
                    ConvertNum.append(N%abs(K))
                    N = (N-N%abs(K))//K
                return ConvertNum[::-1]
        else:
            return []
    else:
        return []
      
ConvertNum = IntBaseConvert(int(input()),-2)
print(''.join(str(T) for T in ConvertNum))

Measured memory_bytes: 9220
def calc(x):
    count=0
    while x <K:
        count+=1
        x*=2
    return count
    
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    num=calc(i)
    ans+=1/N*((1/2)**num)
print(ans)

Measured memory_bytes: 3060
N = input()
N_list = list(N)
N_num = int(N)

if len(N_list)==6:
    print(90909)

elif len(N_list)==5:
    print(9 + 900 + (N_num-9999))


elif len(N_list)==4:
    print(909)

elif len(N_list)==3:
    print(9 + (N_num-99))

elif len(N_list)==2:
    print(9)

elif len(N_list)==1:
    print(N_num)

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

int main(){
    int n,m,a[100][100],b[100],c[100]={0};
    cin >> n >> m;
    for(int i=0;n>i;i++)
        for(int j=0;m>j;j++) cin >> a[i][j];

    for(int j=0;m>j;j++) cin >> b[j];

    for(int i=0;n>i;i++)
        for(int j=0;m>j;j++) c[i]+=a[i][j]*b[j];

    for(int j=0;n>j;j++) cout << c[j] << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using Graph = vector<vector<int>>;

int gcd(int a, int b)
{
    while(b > 0)
    {
        int tmp = a;
        a = b;
        b = tmp % b;
    }
    return a;
}

ll lcm(ll a, ll b)
{
    return a * b / (ll)gcd(a, b);
}

int main()
{
    int A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		int[][][] data = new int[4][3][10];

		for(int i = 0; i < n; i++) {
			int b = scan.nextInt() - 1;
			int f = scan.nextInt() - 1;
			int r = scan.nextInt() - 1;
			int v = scan.nextInt();

			try {
				if(data[b][f][r] < 0 || 9 < data[b][f][r]) {
					throw new Exception();
				}
				data[b][f][r] += v;
			}
			catch(Exception e) {

			}
		}

		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 10; k++) {
					System.out.printf(" %d", data[i][j][k]);
				}
				System.out.println();
			}
			if(i != 3) {
				System.out.println("####################");
			}
		}

		scan.close();
	}
}


Measured memory_bytes: 30456
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
	int len,sa,ans=999;
	string s;
	cin >> s;
	len = s.size();
	for (int i = 0; i < len-2; i++) {
		sa = abs(753 - stoi(s.substr(i,3)));
		if (ans > sa) {
			ans = sa;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
n = int(input())
li = []
ans_li = []
d = {}
for i in range(n):
    buf = list(input())
    li.append("".join(sorted(buf)))
 
for i in range(ord('a'),ord('z')+1):
    tmp = chr(i)
    d[tmp] = 10**5
 
for i in range(n):
    for j in range(ord('a'),ord('z')+1):
        tmp = chr(j)
        if li[i].count(tmp) < d[tmp]:
            d[tmp] = li[i].count(tmp)
 
for kk in d.keys():
    if d[kk] != 0:
        for i in range(d[kk]):
            ans_li.append(kk)
 
print("".join(sorted(ans_li)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>b){
    swap(a,b);
  }
  if(b>c){
    swap(b,c);
  }
  if(a>b){
    swap(a,b);
  }
  cout<<a+b;
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int V = 100005;
vvi to(2*V);
vi seen(2*V);
vi cnt;

void dfs(int v) {
    if (seen[v]) return;
    seen[v] = true;
    cnt[v/V]++;
    for (int nv : to[v]) dfs(nv);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        y += V;
        to[x].pb(y);
        to[y].pb(x);
    }
    ll ans = 0;
    rep(i, 2*V) {
        if (seen[i]) continue;
        cnt = vi(2, 0);
        dfs(i);
        ans += (ll)cnt[0] * cnt[1];
    }
    ans -= n;
    cout << ans << endl;

}

Measured memory_bytes: 10752
import itertools

def main():
    n = int(input())
    nums = []
    for i in range(2):
        nums.append(list(map(str, input().split())))
    kumi = list(itertools.permutations([str(i) for i in range(1, n+1)], n))
    f, t = 0, 0
    for i, s in enumerate(kumi):
        if ''.join(nums[0]) == ''.join(s):
            f = i
        if ''.join(nums[1]) == ''.join(s):
            t = i
    print(abs(f - t))

if __name__ == '__main__':
    main()

Measured memory_bytes: 46188
/*
Code Author: ADITYA SHETH (^_^)
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
//freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long // remove when constraints are tight.
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	int a[n];
	int b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	set<pair<int,int>>se;
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		se.insert({b[i],i});
	}
	int ans=0;
	while(se.size())
	{
		auto pt=se.end();
		pt--;
		auto tmp=*pt;
		se.erase(pt);
		int i=tmp.second;
		if(b[i]==a[i])
		{
			continue;
		}
		int k=(b[i]-a[i])/(b[(i+1)%n]+b[(i+n-1)%n]);
		ans+=k;
		if(k==0)
		{
			cout<<"-1\n";
			return 0;
		}

		b[i]-=k*((b[(i+1)%n]+b[(i+n-1)%n]));
		se.insert({b[i],i});
	}	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 17920
// https://atcoder.jp/contests/abc042/tasks/abc042_a

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a[3];

  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);

  string result = a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO";

  cout << result << "\n";

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        boolean judge = s.matches("(A|)KIH(A|)B(A|)R(A|)");
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int a[200001],r[200001];
int n;
vector<int> v;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for (int i=n;i>=1;i--)
	{
		int cr=0;
		for (int j=2;j<=n/i;j++)
		    cr+=r[i*j];
		r[i]=abs((a[i]-cr)%2);
		if (r[i]) v.push_back(i);
	}
	cout<<v.size()<<endl;
	for (int i=0;i<v.size();i++)
	    cout<<v[i]<<" \n"[i==v.size()-1];
	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
    cout << "vowel" << endl;
  }
  
  else {
    cout << "consonant" << endl;
  }
}


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

int main(){
    char a[5];
    cin >> a;
    if (a[0]==a[1] && a[1]!=a[2] && a[2]==a[3]) cout << "Yes";
    else if (a[0]==a[2] && a[0]!=a[1] && a[1]==a[3]) cout << "Yes";
    else if (a[0]==a[3] && a[0]!=a[1] && a[1]==a[2]) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define POW(u) ((u)*(u))
#define RAD(a,b) sqrt(POW((double)a/2.0)+POW((double)b/2.0))
signed main(void){
	ios::sync_with_stdio(false);
	int a,b,c,n,x;
	while(cin>>a>>b>>c&&(a|b|c)){
		cin>>n;
		if(a>c)	swap(a,c);
		if(b>c)	swap(b,c);
		for(int i=1;i<=n;i++){
			cin>>x;
			if(x>RAD(a,b))
				cout<<"OK"<<endl;
			else
				cout<<"NA"<<endl;
		}
	}
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  int N,i,j,c,ans = 0;string s;cin >> N >> s;
  //i文字ずらして,i文字以下揃っているならばansにカウント
  for(i=1;i<N;i++){
    c = 0;//連続して揃っている文字数カウント
    for(j=0;j+i<N;j++){
      if(s[j] == s[j+i]){
        c++;
        if(c <= i){
          ans = max(ans,c);
        }
      } else c = 0;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3664
#include <cstdio>
#include <algorithm>

using namespace std;

//DP?

int main() {
    int A, B, C, D, E, F;
    scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);
    int maxs1 = F / (100 * A);
    double max_noudo = 0.0;
    pair<int, int> ans;
    for (int i = 0; i <= maxs1; ++i) {
        int maxs2 = (F - 100 * A * i) / (100 * B);
        for (int j = 0; j <= maxs2; ++j) {
            int maxs3 = min((F - i * 100 * A - j * 100 * B) / C, E * (i * A + j * B) / C);
            for (int k = 0; k <= maxs3; ++k) {
                int maxs4 = min((F - i * 100 * A - j * 100 * B - k * C) / D, (E * (i * A + j * B) - k * C) / D);
                for (int l = 0; l <= maxs4; ++l) {
                    double noudo = (double) (C * k + l * D) / (i * A * 100 + j * B * 100 + C * k + l * D);
                    if (C * k + l * D == 0 || i * A * 100 + j * B * 100 + C * k + l * D == 0)
                        noudo = 0.0;
                    if (noudo >= max_noudo) {
                        ans.first = i * A * 100 + j * B * 100 + C * k + l * D;
                        ans.second = C * k + l * D;
                        //printf("%d * %d + %d * %d / %d * %d * 100 + %d * %d * 100 + Sugar\n", k, C, l, D, i, A, j, B);
                        max_noudo = noudo;
                    }
                }
            }
        }
    }

    printf("%d %d\n", ans.first, ans.second);
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val list = readLine()!!.split(" ").map(String ::toInt)
    val A   = list[0]
    val A2  = list[1]
    val ans = A * A2
    if(A <= 9 && A2 <=9) {
        println(ans)
    } else {
        println("-1")
    }
}

Measured memory_bytes: 37876
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;
		if(k%2==1)continue;
		else if(k%3==0||k%5==0)continue;
		cout<<"DENIED";
			return 0;
	}
	cout<<"APPROVED";	
}



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int mn = INT_MAX, ret = 0;
    for (int i=0; i<n; i++) {
        int p;
        cin >> p;
        if (p < mn) {
            mn = p;
            ret++;
        }
    }
    cout << ret << "\n";

    return 0;
}


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

typedef long long ll;

// Vectors
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, d;
    cin >> n >> d;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        double x, y;
        cin >> x >> y;
        double dist = sqrt((pow(x, 2) + pow(y, 2)));
        if (dist <= d) {
            count++;
        }
    }
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 3844
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    
    if(N%111!=0){
        int am = N%111;
        N -= am;
        N += 111;
    }
    
    printf("%d\n",N);
    
    return 0;
    
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include <cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define ll long long
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,z;
  int ct=0;
  cin >> x >> y >> z;
  int sum = z;
  while(1){
      if(sum+y+z<=x){
        sum = sum + y + z;
        ct++;
      }
      else break;
  }
  cout << ct << endl;
}


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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}
	int ans = 0;
	for(int i = 1; i < N; ++i)
	{
		if (a[i - 1] == a[i])
		{
			++ans;
			a[i] = 0;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int maxx=0;
	for (int i=1; i<n; i++)
		if (max(a[n]-a[i],a[i])<max(a[n]-maxx,maxx)) maxx=a[i];
	printf("%d %d\n",a[n],maxx);
	return 0;
}

Measured memory_bytes: 512
use std::io::{stdin, stdout, BufReader, BufRead, StdinLock, Write, BufWriter};

fn main() {
    let (std_in, std_out) = (stdin(), stdout());
    let mut br = BufReader::new(std_in.lock());
    let mut bw = BufWriter::new(std_out.lock());
    
    let tmp = rvn::<usize>(&mut br);
    let (l, r) = (tmp[0], tmp[1]);
    let mut ans = 2019;
    for i in l..l+2020 {
        if i >= r {break;}
        for j in i+1..i+2021 {
            if j > r {break;}
            ans = std::cmp::min(ans, (i*j) % 2019);
        }
    }
    writeln!(&mut bw, "{}", ans);
}


//////////////////////////////////////////////////////////////////////////////////
#[allow(dead_code)]
fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

#[allow(dead_code)]
fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

#[allow(dead_code)]
fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> datas(N, vector<int>(3));
    vector<int> keyData;
    for (int i = 0; i < N; ++i)
    {
        int xi, yi, hi;
        cin >> xi >> yi >> hi;
        datas[i] = { xi, yi, hi };
        if (hi > 0)
        {
            keyData = { xi, yi, hi };
        }
    }
    for (int cx = 0; cx <= 100; ++cx)
    {
        for (int cy = 0; cy <= 100; ++cy)
        {
            bool isValid = true;
            int H = abs(cx - keyData[0]) + abs(cy - keyData[1]) + keyData[2];
            for (const auto &data : datas)
            {
                int expectedH = max(H - abs(cx - data[0]) - abs(cy - data[1]), 0);
                if (expectedH != data[2])
                {
                    isValid = false;
                    break;
                }
            }
            if (isValid)
            {
                cout << cx << ' ' << cy << ' ' << H << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let _n: usize = parse_line().unwrap();
    let t: Vec<u32> = parse_line().unwrap();
    let m: usize = parse_line().unwrap();

    let sum: u32 = t.iter().sum();
    for _ in 0..m {
        let (p, x): (usize, i64) = parse_line().unwrap();
        let diff = t[p - 1] as i64 - x;
        println!("{}", sum as i64 - diff);
    }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



vector<string> ans3 {
    "aa.",
    "..a",
    "..a"
};

vector<string> ans4 {
    "aacd",
    "bbcd",
    "cdaa",
    "cdbb"
};

vector<string> ans5 {
    "aabbc",
    "dee.c",
    "d..ab",
    "a..ab",
    "accdd"
};

vector<string> ans7 {
    "aabc...",
    "ddbc...",
    "a.eeff.",
    "a...haa",
    ".a..hbb",
    ".a..e.f",
    "..aae.f"
};


vector<vector<char>> res;


void fill(pair<int, int> from, const vector<string>& what) {
    int k = what.size();
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            res[from.first + i][from.second + j] = what[i][j];
        }
    }
}


void print() {
    for (int i = 0; i < res.size(); ++i) {
        for (int j = 0; j < res.size(); ++j) {
            cout << res[i][j];
        }
        cout << '\n';
    }
}


int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());
    auto start = clock();


    int n; cin >> n;
    if (n < 3) {
        cout << -1;
        return 0;
    }
    res.assign(n, vector<char>(n, '.'));
    pair<int, int> cur = {0, 0};
    if (n % 3 == 0) {
        while (cur.first < n) {
            fill(cur, ans3);
            cur = {cur.first + 3, cur.second + 3};
        }
    } else if (n == 4) {
        fill(cur, ans4);
    } else if (n == 5) {
        fill(cur, ans5);
    } else if (n == 7) {
        fill(cur, ans7);
    } else if (n == 11) {
        fill({0, 0}, ans7);
        fill({7, 7}, ans4);
    } else {
        while(n > cur.first && (n - cur.first) % 4 != 0) {
            fill(cur, ans5);
            cur = {cur.first + 5, cur.second + 5};
        }
        while(n > cur.first) {
            fill(cur, ans4);
            cur = {cur.first + 4, cur.second + 4};
        }
    }

    print();


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



int n, m, p[15], ans;
vector <vi> sv;
vb state;

void check()
{
    for (int t1 = 1; t1 <= m; ++t1)
    {
        int cnt = 0;

        for (ci &s: sv[t1])
            if (state[s]) ++cnt;

        if (cnt%2 != p[t1]) return;
    }

    ++ans;
}

void solve(int i)
{
    if (i == n+1)
    {
        check();
        return;
    }

    state[i] = 0;
    solve(i+1);

    state[i] = 1;
    solve(i+1);
}

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

    cin >> n >> m;
    sv.resize(m+1);
    state.assign(n+1, 0);

    for (int t1 = 1; t1 <= m; ++t1)
    {
        int k;
        cin >> k;
        sv[t1].resize(k);

        for (int t2 = 0; t2 < k; ++t2)
            cin >> sv[t1][t2];
    }

    for (int t1 = 1; t1 <= m; ++t1)
        cin >> p[t1];

    solve(1);
    cout << ans << '\n';







































    return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  unordered_map<int, int> count;
  for (int x = 1; x * x <= N; ++x) {
    for (int y = 1; y * y <= N; ++y) {
      for (int z = 1; z * z <= N; ++z) {
        int M = x * x + y * y + z * z + x * y + y * z + z * x;
        count[M]++;
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    cout << count[i] << endl;
  }
  return 0;
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	ll ans = 0, cur = 0;
	for (int i=0; i<s.size(); i++) {
		if (s[i] == 'B') {
			cur ++;
		} else {
			ans += cur;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 720
// C - Cat Snuke and a Voyage
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

string solve(int N, int M, vi &A, vi &B){
	vvi tree(N+1, vi());
	rp(i, 1, M+1) tree[A[i]].push_back(B[i]);
	for(int c:tree[1])
		for(int goal:tree[c]) if(goal==N) return "POSSIBLE";
	return "IMPOSSIBLE";
}

int main(){
	int N,M; cin>>N>>M;
	vi A(M+1), B(M+1);
	rp(i, 1, M+1) cin>>A[i]>>B[i];
	cout<< solve(N, M, A, B) <<endl;
}

Measured memory_bytes: 10112
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4)
    {
        if(s[i] == '+') ans++;
        if(s[i] == '-') ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

const static sl HMAX = 80;
const static sl WMAX = 80;
const static sl AijMAX = 80;

const static sl M = (HMAX + WMAX) * AijMAX;

static sl H, W;
static vector<vector<sl>> Aij;
static vector<vector<sl>> Bij;
static vector<vector<vector<bool>>> dp;

void solve(void) {
  dp[0][0][abs(Aij[0][0] - Bij[0][0])] = true;
  FOR0(i, H) {
    FOR0(j, W) {
      FOR0(k, M) {
        if (dp[i][j][k]) {
          if (i + 1 <= H - 1) {
            sl diff = abs(Aij[i + 1][j] - Bij[i + 1][j]);
            dp[i + 1][j][k + diff] = true;
            dp[i + 1][j][abs(k - diff)] = true;
          }
          if (j + 1 <= W - 1) {
            sl diff = abs(Aij[i][j + 1] - Bij[i][j + 1]);
            dp[i][j + 1][k + diff] = true;
            dp[i][j + 1][abs(k - diff)] = true;
          }
        }
      }
    }
  }
  FOR0(k, M) {
    if (dp[H - 1][W - 1][k]) {
      cout << k << endl;
      break;
    }
  }
}

int main(void) {
  cin >> H >> W;
  Aij.resize(H, vector<sl>(W));
  Bij.resize(H, vector<sl>(W));
  dp.resize(H);
  FOR0(i, H) {
    dp[i].resize(W);
    FOR0(j, W) {
      dp[i][j].resize(M, false);
      cin >> Aij[i][j];
    }
  }
  FOR0(i, H) {
    FOR0(j, W) {
      cin >> Bij[i][j];
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n), b;
    rep(i, n) cin >> a[i];
    
    rep(i, n) {
        int p = n - 1 - i * 2;
        
        if (p < 0) {
            p = -p - 1;
        }
        
        printf("%d%s", a[p], ((i == (n - 1)) ? "\n" : " "));
    }
    
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	REP(i, 3) {
		if (s[i] == t[i])
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])
    
    

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

t = [0] * N
t[0] = sum(A[::2]) - sum(A[1::2])
for i in range(1, N):
    t[i] = 2 * A[i - 1] - t[i - 1]
print(*list(map(str, t)))


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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    using P = pair<int,int>;
    vector<P> vp(n);
    rep(i,n) {
        cin >> a[i] >> b[i];
        vp[i] = {a[i]+b[i], i};
    }
    sort(all(vp),greater<P>());
    ll res = 0;
    rep(i,n) {
        int id = vp[i].second;
        if (i%2 == 0) {
            res += a[id];
        } else {
            res -= b[id];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
a,b,c,x,y=map(int,input().split())
if (a+b)/2>c:
	C=min(x,y)*2
	if x>y:
		if 2*c>a:
			print(a*(x-y)+c*C)
		else:
			print(c*max(x,y)*2)
	else:
		if 2*c>b:
			print(b*(y-x)+c*C)
		else:
			print(c*max(x,y)*2)
else:
	print(a*x+b*y)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for(int i=0; i<n; ++i)
        cin >> l[i];

    int pos = 0;
    int ans = 1;
    for(int i=0; i<n; ++i){
        pos += l[i];
        if(pos > x)
            break;
        ++ ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def dfs(c, num, to, cols):
    for n, nw in to[c]:
        if cols[n] == -1:
            y = (num + nw) % 2
            cols[n] = (num + nw) % 2
            dfs(n, y, to, cols)

def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v, w = mapline()
        to[u].append((v, w))
        to[v].append((u, w))
    cols = [-1] * (N+1)
    cols[1] = 0
    dfs(1, 0, to, cols)

    for x in cols[1:]:
        print(x)

if __name__ == "__main__":
    run()


Measured memory_bytes: 84656
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
//typedef vector<int> vi;
//typedef vector<vi> vvi;
//typedef vector<string> vs;
//typedef pair<int, int> pii;
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}



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

	int s, w;
	cin >> s >> w;
	w >= s ? puts("unsafe") : puts("safe");

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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;}

void write(int h,int w){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<"#";
        }
        cout<<endl;
    }
    cout<<endl;
    return;
}

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

    int h,w;
    cin>>h>>w;
    while(h!=0 or w!=0){
        write(h,w);
        cin>>h>>w;
    }
    return 0;
}


Measured memory_bytes: 3108
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

x=INT()
k=100
n=0
while True:
    if k>=x:
       print(n)
       exit()
    k=int(k*1.01)
    n+=1

Measured memory_bytes: 63568
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var X = long.Parse(Console.ReadLine());
            var answer = 2 * (X / 11);
            if (X % 11 == 0) ;
            else if (X % 11 <= 6) answer += 1;
            else answer += 2;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27364
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    String ans = "";
    for(int i = 0; i < 3; i++) {
      String a = String.valueOf(n.charAt(i));
      if(a.equals("1")) {
        a = "9";
      } else {
        a = "1";
      }
      ans += a;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve() {
    int n;
    vector<pair<ll, ll>> p;
    ll x, y;
    ll count = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        p.push_back(make_pair(x, y));
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    count += p[0].first + p[0].second;
    cout << count << endl;
}

int main() {
    solve();
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int k = s.nextInt();
        if(k<600)
            System.out.println(8);
        else if(k<800)
            System.out.println(7);
        else if(k<1000)
            System.out.println(6);
        else if(k<1200)
            System.out.println(5);
        else if(k<1400)
            System.out.println(4);
        else if(k<1600)
            System.out.println(3);
        else if(k<1800)
            System.out.println(2);
        else
            System.out.println(1);
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

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

}

Measured memory_bytes: 25404
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end(), [](const int a, const int b) { return a > b; });
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] * m * 4 < sum) break;
    cnt++;
  }
  puts(cnt >= m ? "Yes" : "No");
}


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

using namespace std;

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

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


int main() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  vl x(m);
  rep (i, m) {
    cin >> x[i];
  }
  sort(all(x));
  vl dif;
  rep (i, m - 1) {
    dif.push_back(x[i + 1] - x[i]);
  }
  sort(all(dif));
  ll ans = 0;
  DEBUG_VEC(dif);
  rep (i, m - n) {
    ans += dif[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		map<string, int> name;
		vector<int> price;
		string t;
		int a;
		for (int i=0; i<n; ++i) {
			cin >> t >> a;
			name[t] = i;
			price.push_back(a);
		}

		int m;
		cin >> m;
		vector<vector<int> > renkin(n);
		for (int i=0; i<m; ++i) {
			vector<int> t;
			string s;
			int a;
			cin >> s >> a;
			for (int j=0; j<a; ++j) {
				string u;
				cin >> u;
				t.push_back(name[u]);
			}

			renkin[name[s]] = t;
		}

		string target;
		cin >> target;

		bool changed = true;
		while (changed) {
			changed = false;
			for (int i=0; i<renkin.size(); ++i) {
				if (renkin[i].empty()) continue;
				int c = 0;
				for (int j=0; j<renkin[i].size(); ++j)
					c += price[renkin[i][j]];
				if (price[i] > c) {
					changed = true;
					price[i] = c;
				}
			}
		}

		cout << price[name[target]] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int now = 0, nb = 0;
	rep(i, 0, n){
		if(s[i] == 'a' && now < a + b){
			cout << "Yes" << endl;
			now++;
		}else if(s[i] == 'b' && now < a + b && nb < b){
			cout << "Yes" << endl;
			now++;
			nb++;
		}else{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
#include <stdio.h>
int main (void) {
	int n, h, w, r = 0;
	int a[2000], b[2000];
	scanf("%d %d %d", &n, &h, &w);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	for (int i = 0; i < n; i++) {
		if (a[i] >= h && b[i] >= w) {
			r++;
		}
	}
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }

int count(vector<int> p){
  vector<int> s;
  rep(i,24)if(p[i]==1)s.push_back(i);
  s.push_back(24);
  int res=24;
  rep(i,s.size()-1){
    chmin(res,s[i+1]-s[i]);
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int d[n];
  rep(i,n)cin >> d[i];
  vector<int> t(13,0);
  rep(i,n)t[d[i]]++;
  vector<int> a;
  vector<int>p(24,0);
  p[0]=1;
  if(t[0]>=1||t[12]>=2){
    cout << 0 << endl;
    return 0;
  }
  if(t[12]==1)p[12]=1;
  rep(i,11){
    if(t[i+1]>2){
      cout << 0 << endl;
      return 0;
    }
    if(t[i+1]==2)p[i+1]=1,p[24-i-1]=1;
    if(t[i+1]==1)a.push_back(i+1);
  }
  int ans=0;
  rep(i,1<<a.size()){
    vector<int>p2(24,0);
    copy(p.begin(), p.end(), p2.begin());
    rep(j,a.size()){
      if((i>>j)&1){
        p2[a[j]]=1;
      }else{
        p2[24-a[j]]=1;
      }
    }
    // rep(i,p2.size())cout << p2[i];
    // cout << endl;
    // cout << count(p2) << endl;
    chmax(ans,count(p2));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;

	vector<int> load(n+1);
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		load.at(a)++;
		load.at(b)++;		
	}

	for(int i = 1; i < n+1; i++) cout << load.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <stack>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <regex>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) obj.begin(), obj.end()
#define UNIQUE(v) v.erase(unique(All(v)), v.end());
typedef long long ll;

typedef pair<int, int> P;
vector<P> vecp;
int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1};

#define N 1000
// input

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(true);
  int n,m;
  cin >> n >> m;
  int L = 1, R = n;
  REP(i,m){
    int l,r;
    cin >> l >> r;
    if (l > L){
      L = l;
    } 
    if (r < R){
      R = r;
    }
  }
  if(L <= R){
    int ans = R - L + 1;
    cout << ans;
  }else{
    cout << 0;
  }
}

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

const int MAX = 1000000;
const int MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X, Y;
    cin >> X >> Y;

    int sum = X + Y;
    if (sum % 3 != 0) {
        cout << "0" << endl;
        return 0;
    }

    int m = (2 * Y - X) / 3;
    int n = (2 * X - Y) / 3;

    if (m < 0 || n < 0) {
        cout << "0" << endl;
        return 0;
    }

    COMinit();

    cout << COM(m+n, n) << endl;

    return 0;
}

Measured memory_bytes: 23680
my $N = <>;
my $s = <>; chomp $s;
my @dat = split(/ /,$s);

my %DB;
my $sum =0;
for(my $i=0;$i<=$#dat;$i++){
    $DB{$dat[$i]}++;
    $sum = $sum +$dat[$i];
}
#print "sum $sum\n";
my $Q = <>;

for(my $i=0;$i<$Q;$i++){
    my $c =<>;chomp $c;
    my ($a,$b) = split(/ /,$c);
    #print "$i a$a b$b, $DB{$a} $DB{$b} \n";
    $sum = $sum + ($b-$a)* $DB{$a};
    $DB{$b} =$DB{$b}+ $DB{$a};
    $DB{$a} = 0;
    print "$sum\n";
}


Measured memory_bytes: 28624
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**10 for i in range(N)]
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i<N-j:
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])

Measured memory_bytes: 56544