akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        int n, k;
        scanf("%d %d", &n, &k);
        ll a[n];
        for(int i=0; i<n; i++) scanf("%ld", &a[i]);

        ll ans = 1e18;
        for(int i=0; i<(1<<n); i++){
                if(__builtin_popcount(i)<k) continue;

                ll cnt = 0, wall = 0;
                for(int j=0; j<n; j++){
                        if((i>>j)&1){
                                if(wall>=a[j]){
                                        cnt += wall-a[j]+1;
                                        wall++;
                                }
                        }
                        wall = std::max(wall, a[j]);
                }

                ans = std::min(ans, cnt);
        }

        printf("%ld\n", ans);
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int deg(long long int n){
    long long int k=1;
    for(int i=0;;i++){
        if(n>=k)k*=2;
        else {
            return i;
            break;
        }
    }
}
long long int pow(int n){
    if(n==0)return 1;
    else return 2*pow(n-1);
}
int main(void){
    long long int A,B;
    scanf("%lld %lld",&A,&B);
    long long int ans=0;
    int Bdeg=deg(B);
    int Adeg=deg(A);
    int subBdeg;
    while(1){
        if(Adeg==Bdeg){
            A-=pow(Adeg-1);
            B-=pow(Bdeg-1);
        }
        else{
            ans+=pow(Bdeg-1);
            ans-=A;
            subBdeg=deg(B-pow(Bdeg-1));
            B=pow(Bdeg-1)+pow(subBdeg)-1;
            if(B-pow(Bdeg-1)<A){
                ans+=(B-A)+1;
            }
            else ans+=pow(Bdeg-1);
            break;
        }
        if(A==B){
            ans++;
            break;
        }
        Adeg=deg(A);
        Bdeg=deg(B);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define INF 1e8

int main(){
    

    int n, ma, mb; cin >> n >> ma >> mb;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

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

    int dp[50][500][500];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    /*
     for(int i = 0; i < n; i++){
        cout << i << endl;
        for(int j = 0; j < 50; j++){
            for(int k = 0; k < 50; k++){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
    }*/

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 450; j++){
            for(int k = 0; k < 450; k++){
                if(dp[i][j][k] != INF){
                    dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                    dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
                }
            }
        }
    }    

    
    /*for(int i = 0; i <= n; i++){
        cout << i << endl;
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
    }*/

    int ans = INF;
    
    for(int j = 1; j < 500; j++){
        for(int k = 1; k < 500; k++){
            if(k * ma == j * mb) ans = min(ans, dp[n][j][k]);
        }
    }

    if(ans == INF) ans = -1;

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




Measured memory_bytes: 42240
import sys
from collections import Counter

read = sys.stdin.read


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def sieve_of_eratosthenes(n):
    sieve = [True] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N, *A = map(int, read().split())
mod = 10 ** 9 + 7

primes = sieve_of_eratosthenes(max(A) + 1)
dic = {i: 0 for i in primes}

n = len(primes)
p = [0] * n
for i in A:
    tmp = Counter(prime_factorize(i))
    for key, value in tmp.items():
        #print(key, value)
        if dic[key] < value:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    if j == 0:
        continue
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = 0
for i in A:
    answer += lcm * pow(i, mod - 2, mod)
    answer %= mod

print(answer)


Measured memory_bytes: 15608
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	int L[100010], R[100010];

	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i];
	}
	sort(L + 1, L + M + 1);
	sort(R + 1, R + M + 1);
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (i <= R[1] && i >= L[M])ans++;
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);

    if((a != b && b ==c) || (a != b &&  a==c) || (c != b && b == a)){
        printf("Yes");
    }else
    {
        printf("No");
    }
    
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 1 << 18, M = 100005;

int n, q, V[N], W[N], Log[1 << 9];
long long f[1 << 9][M];
long long sumw[1 << 9], sumv[1 << 9];

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(V[i]), read(W[i]);
	}
	Log[0] = -1;
	for (int i = 1; i <= n && i < 512; ++i) {
		Log[i] = Log[i >> 1] + 1;
		int fa = i >> 1;
		for (int j = 0; j < M; ++j) {
			f[i][j] = f[fa][j];
		}
		for (int j = W[i]; j < M; ++j) {
			f[i][j] = std::max(f[i][j], f[fa][j - W[i]] + V[i]);
		}
	}
	read(q);
	while (q--) {
		int v, L;
		read(v), read(L);
		std::vector<int> p;
		for (; v >= 512; v >>= 1) {
			p.push_back(v);
		}
		sumw[0] = sumv[0] = 0;
		for (int S = 1; S < (1 << p.size()); ++S) {
			sumw[S] = sumw[S & (S - 1)] + W[p[Log[S & -S]]];
			sumv[S] = sumv[S & (S - 1)] + V[p[Log[S & -S]]];
		}
		long long ans = 0;
		for (int S = 0; S < (1 << p.size()); ++S) {
			if (sumw[S] <= L) {
				ans = std::max(ans, sumv[S] + f[v][L - sumw[S]]);
			}
		}
		print(ans);
	}
}

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

using namespace std;

struct P{int p,d;};

bool cmp_x(const P& a, const P& b){
  return a.p>b.p;
}

int main(void){
  int n,m,d,p;
  vector<P>ar;
  P in;

  while(cin >> n >> m,n|m){
    ar.clear();
    for(int i=0;i<n;i++){
      cin >> in.d >> in.p;
      ar.push_back(in);
    }
    int sum=0;
    for(int i=0;i<n;i++)
      sum+=ar[i].d*ar[i].p;

    sort(ar.begin(),ar.end(),cmp_x);

    for(int i=0;i<ar.size();i++){
      if(ar[i].d>=m){
	sum-=ar[i].p*m;
	break;
      }
      else {
	sum-=ar[i].d*ar[i].p;
	m-=ar[i].d;
      }
    }

    cout << sum << endl;
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;


ll rec(int N, ll X){
  if( N == 0){ return 1;} // ベース
  
  ll length = (1LL << ( N + 1 ) ) - 3;
  ll num = (1LL << ( N ) ) - 1;
  //レベルN - 1バーガーに帰着する
  
  if( X == 1){ return 0;}
  else if( X <= length + 1){ return rec( N - 1, X - 1);}
  else if( X == length + 2){ return num + 1;}
  else if( X <= 2 * length + 2){ return num + 1 + rec( N - 1, X - length - 2);}
  else if( X == 2*length + 3){ return 2* num + 1;}}


int main(){
  int N; ll X; cin >> N >> X;
  cout << rec(N,X) << endl; return 0;}
                              

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int runner[]=new int[4];
		int n,out,i,score;
		String str;
		n=sc.nextInt();
		while(n--!=0){
			out=0;
			score=0;
			Arrays.fill(runner,0);
			while(true){
				if(3<=out) break;
				str=sc.next();
				if(str.equals("HIT")){
					for(i=2;0<=i;i--){
						runner[i+1]=runner[i];
					}
					runner[0]=1;
					score+=runner[3];
				}
				if(str.equals("HOMERUN")){
					for(i=0;i<3;i++){
						score+=runner[i];
					}
					score++;
					Arrays.fill(runner,0);
				}
				if(str.equals("OUT")){
					out++;
				}
			}
			System.out.println(score);
		}
	}
}

Measured memory_bytes: 12000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

int main(){
    int N;
int Max=-1000000000;
int Min;
 int r;  
    cin>>N;
    cin>>Min;
    for(int i=1;i<N;i++){
      cin>>r; 
      Max=max(Max,r-Min);
      Min=min(Min,r);
    }
      
    cout<<Max<<"\n";
    return 0;
    }


Measured memory_bytes: 3116
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, m, a[100][100], b[100], c[100] = {};
  cin >> n >> m;
  rep(i, n) rep(j, m) {
    cin >> a[i][j];
  }
  rep(i, m) {
    cin >> b[i];
  }
  rep(i, n) rep(j, m) {
    c[i] += a[i][j] * b[j];
  }
  rep(i, n) {
    cout << c[i] << endl;
  }
  return 0;
}


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

namespace B
{
    public class Program
    {
        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 n = int.Parse(Console.ReadLine());
            var count = 0;
            var num = 1;
            while (num <= n)
            {
                if (num.ToString().Length % 2 == 0)
                {
                    num *= 10;
                    continue;
                }
                count++;
                num++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
import bisect as bi
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()

  ans = 0

  for i in range(N):
    a = bi.bisect_left(A,B[i])
    c = N-bi.bisect_right(C,B[i])
    ans += a*c
  print(ans)
main()


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 405;

char s[2][MAXN];

char ans[10];

char cc[4][2];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, 4){
		cc[i][0] = ((i & 1) ? '#' : '.');
		cc[i][1] = ((i & 2) ? '#' : '.');
	}
	int fl = 0;
	int st = 0;
	while(1){
		int fl1 = 0;
		REP(i, 0, 4){
			REP(j, 0, 2){
				s[j][st] = cc[i][j];
			}
			
			printf("%s\n%s\n", s[0], s[1]);
			fflush(stdout);
			scanf("%s", &ans[0]);
			if (ans[0] == 'e'){
				return;
			}
			if (ans[0] == 'T'){
				fl1 = 1;
				break;
			}
		}
		if (fl1){
			st++;
		} else {
			break;
		}
	}
	while(1){
		int fl1 = 0;
		REP(i, 0, 2){
			for(int j = st; j > 0; j--){
				s[i][j] = s[i][j - 1];
			}
		}
		REP(i, 0, 4){
			REP(j, 0, 2){
				s[j][0] = cc[i][j];
			}
			printf("%s\n%s\n", s[0], s[1]);
			fflush(stdout);
			scanf("%s", &ans[0]);
			if (ans[0] == 'e'){
				return;
			}
			if (ans[0] == 'T'){
				fl1 = 1;
				break;
			}
		}
		st++;
		assert(st <= n);
	}
}	

int main(){
/*#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif*/
	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 724
n = int(input())
li = list(map(int, input().split()))
res = 0
sum1 = sum(li)
sum2 = 0
m = 10**9 + 7
for i in range(0, len(li)-1):
    sum2 += li[i]
    res = (res + li[i]*(sum1-sum2))%m
print(res)

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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int FindNearest(int[] p, List<int[]> ms) {
        int index = 0;
        int min = Math.Abs(p[0] - ms[0][0]) + Math.Abs(p[1] - ms[0][1]);
        for (int i = 0; i < ms.Count; i++) {
            int d = Math.Abs(p[0] - ms[i][0]) + Math.Abs(p[1] - ms[i][1]);
            if (d < min) {
                index = i;
                min = d;
            }
        }
        return index;
    }

    static void Calc(List<int[]> ns, List<int[]> ms) {
        foreach (var n in ns) {
            int x = FindNearest(n, ms);
            Console.WriteLine(x + 1);
        }
    }

    static void Main() {
        var nm = ReadInts();
        int n = nm[0], m = nm[1];

        var ns = new List<int[]>();
        for (int i = 0; i < n; i++) {
            ns.Add(ReadInts());
        }

        var ms = new List<int[]>();
        for (int i = 0; i < m; i++) {
            ms.Add(ReadInts());
        }

        Calc(ns, ms);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353
typedef vector<ll> vl;
typedef vector<vl> matrix;//A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Sortup(V) sort(V.begin(), V.end())
#define Sortdown(V) sort(V.rbegin(), V.rend())
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;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll llpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}


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

    // solution comes here

    matrix c(3, vl(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    rep(i, 2){
        if(c[0][i]-c[0][i+1]!=c[1][i]-c[1][i+1]||c[2][i]-c[2][i+1]!=c[1][i]-c[1][i+1]||c[i][0]-c[i+1][0]!=c[i][1]-c[i+1][1]||c[i][2]-c[i+1][2]!=c[i][1]-c[i+1][1]){
            cout << "No" << nl;
            return 0;
        }
    }

    cout << "Yes" << nl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#define LL long long
using namespace std;
LL n,k;
LL ans;
inline LL Pow(LL a,int b) {return a*a*a;}
int main() 
{
	//freopen("cgss.in","r",stdin);
	//freopen("cgss.out","w",stdout);
    scanf("%lld%lld", &n, &k);
    LL t = n / k;
    if(k&1) ans=Pow(t, 3);
    else 
	{
        ans = Pow(t, 3);
        t = t + (n % k >= k / 2 ? 1 : 0);
        ans += Pow(t, 3);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <map>

using namespace std;
typedef long long int lint;

lint LCM(lint a, lint b)
{
	lint na, nb, buf;
	na = a;
	nb = b;
	while (a % b != 0){
		a = a % b;
		buf = a;
		a = b;
		b = buf;
	}
	return (na * nb) / b;
}

lint electro_fly(lint a, lint m)
{
	lint ret = 0;
	lint x = 1;
	do{
		x = a * x % m;
		ret++;
	} while (x != 1);

	return ret;
}

lint solve(lint a1, lint m1, lint a2, lint m2, lint a3, lint m3)
{
	return LCM(electro_fly(a1, m1), LCM(electro_fly(a2, m2), electro_fly(a3, m3)));
}

int main()
{
	lint a1, m1, a2, m2, a3, m3;
	while (1){
		cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
		if (a1 == 0) break;
		cout << solve(a1, m1, a2, m2, a3, m3) << endl;
	}
	return 0;
}

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

long long n, x;
vector<int> a;
template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}
long long ans = 1e18+9;
vector<vector<long long> > v;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> x;
	readVector(n, a);
	v.resize(n);
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			v[i].push_back(a[(i-j+n)%n]);
	for(int i=0; i<n; ++i)
		for(int j=1; j<n; ++j)
			v[i][j] = min(v[i][j], v[i][j-1]);
	for(int i=0; i<n; ++i){
		long long tmp = x * i;
		for(int j=0; j<n; ++j)
			tmp += v[j][i];
		ans = min(ans, tmp);
	}
	cout << ans << "\n";
}

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

using namespace std;

#define endl "\n"

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   string s,t,s1;
   cin>>s>>t;
   
   int i,j,mn=INT_MAX,cnt=0;
   
   for(i=0;i<=s.length()-t.length();++i)
   {
       s1=s.substr(i,t.length());
       cnt=0;
       for(j=0;j<t.length();++j)
       {
           if(s1[j]!=t[j])
             cnt++;
       }
       
       mn=min(mn,cnt);
   }
   
   cout<<mn;
   
   
     return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long N, K;
  cin >> N >> K;
  long long Y = N * K;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int next[N], cost[N];
  const int M = 212345;
  int pos[M];
  fill(pos, pos + M, -1);
  for (int i = N * 2 - 1; i >= 0; i--) {
    if (i < N) {
      next[i] = (pos[A[i]] + 1) % N;
      cost[i] = pos[A[i]] - i + 1;
    }
    pos[A[i % N]] = i;
  }
  debugArray(next, N);
  debugArray(cost, N);
  long long dist[N];
  fill(dist, dist + N, -1);
  long long sum = 0;
  int cur = 0, prev = 0;
  while (true) {
    if (dist[cur] != -1) {
      break;
    }
    dist[cur] = sum;
    if (dist[cur] > Y) {
      break;
    }
    sum += cost[cur];
    prev = cur;
    cur = next[cur];
  }
  if (Y < dist[cur]) {
    cur = prev;
    Y -= dist[prev];
  } else {
    Y -= dist[cur];
    Y %= sum - dist[cur];
  }
  fill(dist, dist + N, -1);
  sum = 0;
  while (true) {
    if (dist[cur] != -1) {
      break;
    }
    dist[cur] = sum;
    if (dist[cur] > Y) {
      break;
    }
    sum += cost[cur];
    prev = cur;
    cur = next[cur];
  }
  if (Y < dist[cur]) {
    cur = prev;
    Y -= dist[prev];
  }
  vector<int> s;
  bool exist[M];
  fill(exist, exist + M, false);
  while (Y--) {
    if (exist[A[cur]]) {
      while (s.back() != A[cur]) exist[s.back()] = false, s.pop_back();
      s.pop_back();
      exist[A[cur]] = false;
    } else {
      s.push_back(A[cur]);
      exist[A[cur]] = true;
    }
    cur = (cur + 1) % N;
  }
  for (size_t i = 0; i < s.size(); i++)
    cout << s[i] << (i == s.size() - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 9196
n,k = map(int,input().split())
X = list(map(int,input().split()))
res = 10**10
for i in range(n-k+1):
    if X[i]<=0 and X[i+k-1]<=0:
        res= min(-X[i],res)
    elif X[i]<=0 and X[i+k-1]>=0:
        res = min(res,2*min(abs(X[i]),X[i+k-1])+max(abs(X[i]),X[i+k-1]))
    else:
        res = min(res,X[i+k-1])
print(res)

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
int a[100005];
int main() {
    memset(a, 0, sizeof(a));
    int n; cin >> n;
    for(int i = 1; i <= n; ++i){
        int x; cin >> x;
        a[x] = i;
    }
    for(int i = 1; i <= n; ++i){
        cout << a[i] << " ";
    }
    cout << endl;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    if(n % (2 * d + 1) == 0) cout << n / (2 * d + 1) << endl;
    else cout << n / (2 * d + 1) + 1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long int lli;

lli countMul(lli u, lli b){
	return u/b +1;
}
lli countMul(lli l, lli u, lli b){
	return countMul(u, b) -countMul(l-1, b);
}
lli countLen(lli l, lli u, lli d){
	lli num = u-l+1;
	lli mul = countMul(l, u, 3) +countMul(l, u, 5) -countMul(l, u, 15);
	return (num-mul)*d + (countMul(l, u, 3) +countMul(l, u, 5))*4;
}

int main(){
	lli n;
	cin >> n;
	
	lli pow10[20] = {1};
	for(int i=0; i<19; i++){
		pow10[i+1] = pow10[i]*10;
	}
	
	lli sum = 0;
	int dig;
	for(int i=1; i<=17; i++){
		lli tmpsum = countLen(pow10[i-1], pow10[i]-1, i);
		if(sum +tmpsum >= n){
			dig = i;
			break;
		}
		sum += tmpsum;
	}
	
	lli base = pow10[dig-1];
	lli lb = base, ub = pow10[dig]-1;
	while(lb < ub){
		lli mid = (lb + ub +1)/2;
		lli subt = countLen(base, mid, dig);
		if(sum +subt < n){
			lb = mid;
		}else{
			ub = mid-1;
		}
	}
	lli subt = (lb==base)? sum : sum + countLen(base, lb-1, dig);
	string out = "";
	for(int i=0; i<50; i++){
		if(lb+i == 0) continue;
		if((lb+i)%3==0 || (lb+i)%5==0){
			if((lb+i)%3 == 0) out += "Fizz";
			if((lb+i)%5 == 0) out += "Buzz";
		}else{
			out += to_string(lb+i);
		}
	}
	cout << out.substr(n-subt-1, 20) << endl;
	return 0;
}



Measured memory_bytes: 3296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader br = null;

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

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	str = null;

		while((str = parseStr()) != null) {
			str = reverse(str);
			System.out.println(str);
		}
	}

	private static String parseStr() {
		String	str = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					str = line;
				}
			}
		}
		catch (NumberFormatException e) {}
		catch (IOException e) {}

		return str;
	}

	private static String reverse(String str) {
		char[]	buff = str.toCharArray();
		int		nLen = str.length();
		char	c    = 0;

		for(int n1 = 0, n2 = nLen - 1; n1 < n2; n1++, n2--) {
			c        = buff[n1];
			buff[n1] = buff[n2];
			buff[n2] = c;
		}

		
		return String.valueOf(buff);
	}
}

Measured memory_bytes: 16876
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vi x(n);
    rep(i, n) cin >> x[i];
    ll ans = INF;
    rep(i, 101) {
        ll tmp = 0LL;
        rep(j, n) {
            tmp += (x[j] - i) * (x[j] - i);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ls = list(map(int,input().split()))

if N >= M:
    print(0)

else:
    ls.sort()
    long1 = ls[-1]-ls[0]

    ls2 = []
    for i in range(1,M):
        ls2.append(ls[i]-ls[i-1])

    ls2.sort(reverse=True)
    des = 0
    for i in range(N-1):
        des += ls2.pop(0)

    print(long1-des)
    

Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
#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++)
const int INF = 1001001001;
using ll = long long;


int main() {
  string S,T;
  cin >> S >> T;
  int counter = 0;
  rep(i,S.size()){
    if(S.at(i)!=T.at(i)){
      counter += 1;
    }
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

string s;
string ans="";

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>s;

for(int i=0; i<s.size(); i++){
	if(s[i]=='0'){
		ans+='0';
	}
	if(s[i]=='1'){
		ans+='1';
	}
	if(s[i]=='B'){
		if(ans!="") ans.erase(ans.end()-1);
	}
}

cout<<ans<<endl;

}



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

using namespace std;

typedef long long ll;

vector<pair<int,ll> > v;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    k--; // Logic loc -> Machine loc
    int a,b;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		v.push_back({a,b});
	}
	sort(v.begin(),v.end());
	ll cnt = 0;
	ll down,up;
	for(int i=0;i<n;i++){
		down = cnt; up = down+v[i].second-1;
		if(down<=k && up>=k){
			cout << v[i].first << "\n";
			return 0;
		}
		cnt = up+1;
	}

	return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+8
#define PI acos(-1)
#define TAU PI * 2
#define EPS 0.00000001
const ll MOD = 1000000007;

ll gcd(ll a, ll b){
    if(a < b) std::swap(a, b);

    ll result = b;
    while(a % result != 0){
        result = a % b;
        a = b;
        b = result;
    }

    return result;
}

ll num(ll n, ll c, ll d){
    ll g = gcd(c, d);
    ll l = c / g * d;
    // 全体 - Cの倍数 - Dの倍数 + C,Dの倍数
    ll res = n - (n / c) - (n / d) + (n / l);
    return res;
}

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    // B以下の条件にあう個数 - (A - 1)以下の条件にあう個数
    ll B = num(b, c, d);
    ll A = num(a - 1, c, d);
    ll ans = B - A;
    println(ans);
}

Measured memory_bytes: 256
n,k=[int(x) for x in input().rstrip().split()]
dic={}
for i in range(n):
  a,b=[int(x) for x in input().rstrip().split()]
  if a not in dic:
    dic[a]=b
  else:
    dic[a]+=b

dic=sorted(dic.items())

now=0
for i,v in dic:
  now+=v
  if k<=now:
    print(i)
    break


Measured memory_bytes: 14560
n = int(raw_input())
a = map(int, raw_input().split())
print " ".join(map(str, a))
for i in range(1, n):
    v = a[i]
    j = i -1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j-=1
    a[j+1] = v
    print " ".join(map(str, a))


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }

  sort(A.begin(), A.end());
  ll a=-1, b=-1;
  REPR(i, A.size()-1){
    if(A[i] == A[i-1] && a==-1){
      a = A[i];
      i--;
    }
    else if(A[i]== A[i-1] && a!=-1){
      b=A[i];
      break;
    }
  }
  if(b!=-1){
    cout << a*b << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 640
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long[2][][] memo;
long md;
 
T[N] toS(T, int N)(T[N] data){ return data; }
long[2][] dfs(int p) {
    if (g[p].empty) {
        static auto leaf = [[0L, 0L].toS];
        return leaf;
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
    memo[p].length = 0;
    memo[p].assumeSafeAppend;
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1, rt.length.to!int)-1;
        if (idx == -1) continue;
        memo[p] ~= [co[0]+ld, rt[idx][1]+rd].toS;
        memo[p] ~= [rt[idx][1]+rd, co[0]+ld].toS;
    }
    auto ans = memo[p];
    sort(ans);
    if (ans.empty) return ans;
    long ma = 10L^^15;
    int co = 0;
    foreach (ref e; ans) {
        if (ma <= e[1]) {
            continue;
        }
        ma = min(ma, e[1]);
        ans[co] = e;
        co++;
    }
 
    return ans[0..co];
}
 
//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}
 
int main(string[] argv) {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    memo = new long[2][][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }
    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long C = A + B;
  long ans = 0;
  ans += A * (N / C);
  ans += min(A, N % C);
  cout << ans << "\n";
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    if(a<b)
        return a;
    else 
        return b;
}
int main()
{   int n;
    cin>>n;
    int arr[n];
    int i,j;
    for(i=0;i<n;i++)
        cin>>arr[i];
    int dp[n];
    for(i=0;i<n;i++)
    {
        if(i==0)
            {
                dp[i]=0;
                
            }
        else if(i==1)
        {
            dp[i]=abs(arr[i]-arr[i-1]);
        }
        else
        {
           dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1])); 
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//<< setprecision(5)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	string str;cin>>str;
	vector<pair<int,char>> nuki;//xなし
	int i,n;n=str.size();
	int now=0;
	for(i=0;i<n;i++){
		if(str[i]!='x'){nuki.pub(mp(now,str[i]));now=0;}
		else{now++;}
	}
	nuki.pub(mp(now,'#'));
	int m=nuki.size();
	for(i=0;i<m-1;i++){
		if(nuki[i].sec!=nuki[m-2-i].sec){cout<<-1<<endl;return 0;}
	}
	int ans=0;
	for(i=0;i<m/2;i++){
		ans+=abs(nuki[i].fir-nuki[m-1-i].fir);
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	rep (i,s.size()) {
		ans += s[i] - '0';
		ans %= 9;
	}
	if (ans == 0) s = "Yes";
	else s = "No";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
using namespace std;
using ll = long long;
const int MAX_F = 10030;

int dp_w[MAX_F];
int dp_s[MAX_F];

int main()
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;


    dp_w[0] = 1;
    rep(w, 0, f + 1)
    if(dp_w[w])
    {
        dp_w[w + 100 * a] = 1;
        dp_w[w + 100 * b] = 1;
    }

    dp_s[0] = 1;
    rep(s, 0, f + 1)
    if(dp_s[s])
    {
        dp_s[s + c] = 1;
        dp_s[s + d] = 1;
    }

    int best_w = a * 100;
    int best_s = 0;
    rep(w, 1, f + 1)
    if (dp_w[w])
    {
        for (int s = e * (w / 100); s >= 0; s--)
        if (dp_s[s] and s + w <= f)
        {
            // cout << w << ' ' << s << ' ' << endl;
            if (best_s * (w + s) < (best_w + best_s) * s)
            {
                best_w = w;
                best_s = s;
            }
            // break;
        }
    }

    cout << best_w + best_s << ' ' << best_s << endl;;
    return 0;
}

Measured memory_bytes: 256
//2020 1.25 マージソート
#include <stdio.h>
#define MAX 500000
#define INFTY 1000000001

void merge(int *,int ,int ,int );
void mergeSort(int *,int ,int );

int cnt=0;

int main(void)
{
    int n;
    int i;
    int array[MAX];

    scanf("%d",&n);

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

    mergeSort(array,0,n);

    for(i=0;i<n;i++)
    {
        printf("%d",array[i]);
        if(i != n-1) printf(" ");
    }

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

    return 0;
}

void mergeSort(int *array,int left,int right)
{
    int mid;

    if(left+1<right)
    {
        mid = (left+right)/2;
        mergeSort(array,left,mid);
        mergeSort(array,mid,right);
        merge(array,left,mid,right);
    }
    return;
}

void merge(int *array,int left,int mid,int right)
{
    int n1,n2;
    int i,j,k;
    static int L[MAX/2+2],R[MAX/2+2];   //LとRの配列を保存しておくためにstatic変数を使う

    n1 = mid-left;
    n2 = right-mid;

    for(i=0;i<n1;i++) L[i] = array[left+i];
    for(i=0;i<n2;i++) R[i] = array[mid+i];
    i=j=0;

    L[n1]=R[n2]=INFTY;          //最大の値を入れる事によって必ず配列に入れた値を比較しマージできる
    for(k=left;k<right;k++)
    {
        cnt++;
        if(L[i]<=R[j])
        {
            array[k]=L[i]; i++;
        }
        else
        {
            array[k]=R[j]; j++;
        }
    }
    return;
}



Measured memory_bytes: 5612
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int w,h,p[100000],q[100000],l,r;
ll ans,ps[100000];

int main(){
	cin>>w>>h;
	ans=0;
	lp(w){
		cin>>p[i];
		ans+=p[i];
	}
	lp(h){
		cin>>q[i];
		ans+=q[i];
	}
	sort(p,p+w);
	ps[0]=p[0];
	lp(w-1)
		ps[i+1]=ps[i]+p[i+1];
	lp(h){
		l=-1;
		r=w;
		while(l+1!=r){
			if(p[(l+r)/2]<q[i])
				l=(l+r)/2;
			else r=(l+r)/2;
		}
		ans+=(l!=-1?ps[l]:0)+ll(q[i])*(w-r);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int num1, num2, angkaAwal;
    int angka,jumlah = 0;
   
    scanf("%d %d %d", &num1, &num2, &angkaAwal);
    angka = angkaAwal;  
    for(int a = num1; a <= 100; a++){
    if(angka >= num1 && angka <= num2){
            jumlah++;  
        } 
    angka += angkaAwal;
    }
printf("%d\n", jumlah);

    return 0;
}

Measured memory_bytes: 1712
#pragma once

#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
/*
 * @see https://snuke.hatenablog.com/entry/2017/07/18/101026
 */
//BEGIN CUT HERE
// longest prefix suffix matching of [0, i)
vector<int> knuth_morris_pratt(const string &s){
  int n=s.size();
  vector<int> kmp(n+1,-1);
  for(int i=0,j=-1;i<n;i++){
    while(~j&&s[i]!=s[j]) j=kmp[j];
    kmp[i+1]=++j;
    if(i+1<n&&s[i+1]==s[j]) kmp[i+1]=kmp[j];
  }
  return kmp;
}
// positions for t that match s
vector<int> pattern_match(string s,string t){
  int n=s.size(),m=t.size();
  vector<int> kmp=knuth_morris_pratt(s);

  vector<int> res;
  int i=0,j=0;
  while(i+j<m){
    if(s[j]==t[i+j]){
      if(++j!=n) continue;
      res.emplace_back(i);
    }
    i+=j-kmp[j];
    j=max(kmp[j],0);
  }
  return res;
}
//END CUT HERE
#ifndef call_from_test

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE

// test knuth_morris_pratt
signed ABC135_F(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s,t;
  cin>>s>>t;

  int n=s.size(),m=t.size();

  string b;
  while(b.size()<t.size()) b+=s;
  auto kmp=knuth_morris_pratt(t+'$'+b+b);

  vector<int> match(n);
  for(int i=m+1;i<=m+n;i++)
    match[i-(m+1)]=kmp[i+m]==m;

  vector< vector<int> > G(n);
  for(int i=0;i<n;i++)
    if(match[i]) G[i].emplace_back((i+m)%n);

  vector<int> indeg(n,0);
  for(int i=0;i<n;i++)
    for(int j:G[i]) indeg[j]++;

  queue<int> que;
  for(int i=0;i<n;i++)
    if(indeg[i]==0) que.emplace(i);

  vector<int> dp(n,0);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int u:G[v]){
      chmax(dp[u],dp[v]+1);
      indeg[u]--;
      if(indeg[u]==0) que.emplace(u);
    }
  }

  for(int i=0;i<n;i++){
    if(indeg[i]!=0){
      cout<<-1<<endl;
      return 0;
    }
  }

  cout<<*max_element(dp.begin(),dp.end())<<endl;
  return 0;
}
/*
  verified on 2020/08/20
  https://atcoder.jp/contests/abc135/tasks/abc135_f
*/

signed main(){
  ABC135_F();
  return 0;
}
#endif


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

struct Trie{
	struct Node{
		int sum,term;
		Node* ch[26];
		vector<pair<char*,int>> qs;
		void Init(){
			sum=0,term=0;
			fill(ch,ch+26,(Node*)NULL);
		}
	} buf[501919];
	int bufUsed;
	Node* newNode(){
		buf[bufUsed].Init();
		return &buf[bufUsed++];
	}
	Node* root;
	void Init(){
		bufUsed=0;
		root=newNode();
	}
	Node* Add(Node* x,const char* s,int n,int i){
		if(i==n){
			x->term++;
			return x;
		}else{
			int nx=s[i]-'a';
			if(x->ch[nx]==NULL)
				x->ch[nx]=newNode();
			return Add(x->ch[nx],s,n,i+1);
		}
	}
	Node* Add(const char* s,int n){
		return Add(root,s,n,0);
	}
	void Set(Node* x){
		REP(i,26)
			if(x->ch[i]){
				Set(x->ch[i]);
				x->sum+=x->ch[i]->sum;
			}
		x->sum+=x->term;
	}
	void Set(){
		Set(root);
	}
	int battle[26][26];
	int idx[26];
	void Ans(Node* x,vector<int>&dst,int sh){
		for(auto q:x->qs){
			REP(i,26)
				idx[int(q.first[i]-'a')]=i;
			int ret=sh;
			REP(i,26)
				REP(j,26)if(idx[i]>idx[j])
					ret+=battle[i][j];
			dst[q.second]=ret;
		}
		REP(i,26)if(x->ch[i]){
			REP(j,26)if(i!=j&&x->ch[j])
				battle[i][j]+=x->ch[j]->sum;
			Ans(x->ch[i],dst,sh+x->term);
			REP(j,26)if(i!=j&&x->ch[j])
				battle[i][j]-=x->ch[j]->sum;
		}
	}
	void Ans(vector<int>& dst){
		memset(battle,0,sizeof(battle));
		Ans(root,dst,0);
	}
} trie;

char* readString(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

int main(){
	int n=read();
	vector<Trie::Node*> s;
	trie.Init();
	REP(i,n){
		char* str=readString();
		s.PB(trie.Add(str,strlen(str)));
	}
	trie.Set();
	int q=read();
	REP(i,q){
		int k=read()-1;
		char* ord=readString();
		s[k]->qs.PB(MP(ord,i));
	}
	vector<int> dst(q);
	trie.Ans(dst);
	for(auto a:dst)
		printf("%d\n",a+1);
}


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

int main()
{
  char s[100];
  int k;
  scanf("%d", &k);
  scanf("%s", s);
  
  if(strlen(s) <= k){
    printf("%s\n", s);
  }else{
    for(int i = 0; i < k; i++){
      printf("%c", s[i]);
    }
    printf("...\n");
  }
  
  return 0;
}

Measured memory_bytes: 1664
//Resting_Prince
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define all(v) v.begin(),v.end()
#define rep(i,a,b)    for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    ll n,i,j,k,q,l,o,p;
    string s;
    cin>>n>>q;
    cin>>s;
    k=0;
    ll a[200055]={0};
    rep(i,0,n-1)
    {
        if(s[i]=='A' && s[i+1]=='C')k++;
        a[i+1]=k;
    }
    while(q--)
    {
        cin>>l>>o;l--;o--;
        cout<<a[o]-a[l]<<en;
    }
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>

using namespace std;
#define M 110
int remain(int a[], int start, int goal){
  int sum=0, i;
  for (i = start; i <= goal; i++){
    sum += a[i];
  }
  return sum;
}
int main(){
  int N, a[M], b[M], i, max=-1, val;
  cin >> N;
  for (i = 1; i <= N; i++){
    cin >> a[i];
  }
  for (i = 1; i <= N; i++){
    cin >> b[i];
  }
  for (i = 1; i <= N; i++){
    val = remain(a, 1, i) + remain(b, i, N);
    if (max < val)
      max = val;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256