akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;

struct edge
{
    int from,to;
    int cost;
};

long long d[100005];
bool vis[100005];

vector<edge> edges;
vector<int> v[100005];

void adde(int from,int to,int cost)
{
    edge e;
    e.from = from;
    e.to = to;
    e.cost = cost;

    edges.push_back(e);

    int m = edges.size() - 1;

    v[from].push_back(m);
}

void bfs(int s)
{
    vis[s] = 1;
    d[s] = 0;

    queue<int> q;

    q.push(s);

    while (!q.empty())
    {
        int now = q.front();q.pop();

        for (int i = 0;i < v[now].size();i++)
        {
            int id = v[now][i];

            edge tmp = edges[id];

            if (!vis[tmp.to])
            {
                vis[tmp.to] = 1;

                d[tmp.to] = d[now] + tmp.cost;

                q.push(tmp.to);
            }
        }
    }
}

int main()
{
    int n;

    scanf("%d",&n);

    for (int i = 1;i <= n - 1;i++)
    {
        int a,b,c;

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

        adde(a,b,c);
        adde(b,a,c);
    }

    int q,k;

    scanf("%d%d",&q,&k);

    bfs(k);

    for (int i = 0;i < q;i++)
    {
        int a,b;

        scanf("%d%d",&a,&b);

        printf("%lld\n",d[a] + d[b]);
    }

    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum += a[i];
    int cnt = 0;
    rep(i, n) {
        if (a[i] * (4 * m) >= sum) cnt++;
    }
    if (cnt >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    ll N, M;
    ll ans = 1;
    cin >> N >> M;
    ans *= (N - 2) < 0 ? 1 : N - 2;
    ans *= (M - 2) < 0 ? 1 : M - 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

/**
 * <pre>
 * NumberOfIsland
 *
 * ??¶?????°???????????????
 * </pre>
 *
 * @author ?????????????????§???
 *
 */
public class Main{

	static boolean map[][] = new boolean[12][12];
	static int ans = 0;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			for (int cnt1 = 0; cnt1 < 12; cnt1++) {
				char[] c = sc.next().toCharArray();
				for (int cnt2 = 0; cnt2 < 12; cnt2++) {
					map[cnt1][cnt2] = (c[cnt2] == '1');
				}
			}
			int ans = 0;
			for (int cnt1 = 0; cnt1 < 12; cnt1++) {
				for (int cnt2 = 0; cnt2 < 12; cnt2++) {
					if (map[cnt1][cnt2]) {
						test(cnt1, cnt2);
						ans++;
					}
				}
			}
			System.out.println(ans);
		} // ?????????????????????
	}// ?????????????????????????????????

	public static void test(int mh, int mw) {
		map[mh][mw] = false;
		int move_h[] = { 1, 0, -1, 0 };
		int move_w[] = { 0, 1, 0, -1 };
		for (int cnt = 0; cnt < 4; cnt++) {
			int tmp_h = mh + move_h[cnt];
			int tmp_w = mw + move_w[cnt];
			if (0 <= tmp_h && 0 <= tmp_w && tmp_h < map.length && tmp_w < map[0].length && map[tmp_h][tmp_w])//
				test(tmp_h, tmp_w);
		}
	}
}// ??????????????????????????????

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

int main (int argc, char **argv) {
  // data in
  long x, y;
  cin >> x >> y;
  
  // precondition x >= y
  long mod;
  if (x<y) {
    long t;
    t = x;
    x = y;
    y = t;
  }
  mod = x % y;

  while (mod>0) {
    x = y;
    y = mod;
    mod = x % y;
  }

  cout << y << endl;
}

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

typedef long long int lli;

vector<int> number;

int main(void){
    // Here your code !
    
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
        number.push_back(s[i]-'0');

    lli res = 0;

    for(int i = 0; i < pow(2,s.size()-1); i++){
        
        vector<bool> flag(s.size()-1,false);
        
        for(int j = 0; j < s.size()-1; j++){
            if(((int)pow(2,j)) & i){
                flag[j] = true;
                //cout << 1 ;
            }else{
                //cout << 0 ;
            }
        }
        //cout << endl;
        
        lli t = 0;
        lli tmp = number[0];
        
        for(int j = 0; j < flag.size(); j++){
            if(flag[j]){
                t += tmp;
                tmp = number[j+1];
            }else{
                tmp *= 10;
                tmp += number[j+1];
            }
            //cout << tmp << endl;
        }
        
        t += tmp;
        //cout << t << endl;
        res += t;
        
    }
    
    cout << res << endl;

}


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

using namespace std;
using lint = long long;

int H, W;
char s[405][405];
bool visited[405][405];
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

void dfs(int x, int y, lint &black, lint &white) {
    if (visited[x][y]) return;
    visited[x][y] = true;

    if (s[x][y] == '#') {
        black++;
    } else {
        white++;
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (0 <= nx && nx < H && 0 <= ny && ny < W &&
            s[nx][ny] != s[x][y]) {
            dfs(nx, ny, black, white);
        }
    }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    lint ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!visited[i][j]) {
                lint b = 0, w = 0;
                dfs(i, j, b, w);
                ans += b * w;
            }
        }
    }

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


Measured memory_bytes: 13056
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS

int main(void) {
	char station[4];
	int a = 0;
	int b = 0;
	scanf("%s", station);
	for (int i = 0;i < strlen(station);i++) {
		if (strncmp(station + i, "A", 1) == 0) {
			a += 1;
		}
		if (strncmp(station + i, "B", 1) == 0) {
			b += 1;
		}
	}
	if (a != 3 && b != 3) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>


int main()
{
	int a, b, sum = 0, counts = 0;
	
	while(scanf("%d %d", &a, &b) != EOF)
	{
		sum = a + b;
		counts = 0;
		while(sum != 0)
		{
			sum /= 10;
			counts++; 
		}
		printf("%d\n", counts);
	}
	

	
	
}


Measured memory_bytes: 2676
#include<iostream>
#include<bits/stdc++.h>
#include<vector>

using namespace std;

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum = 0;
    sum = sum + min(a,k);
    k = k - min(a,k);
    //
    k = k - min(b,k); 
    sum = sum - min(c,k);
    k = k - min(c,k);

    cout<<sum<<endl;

}


Measured memory_bytes: 3616
#
# abc068 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """32"""
        output = """32"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """100"""
        output = """64"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    ans = 1
    while ans * 2 <= N:
        ans *= 2
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main(){
    int s ;
    cin >> s;
    if (s /  100 == 7 ) cout << "Yes" << endl;
    else if ((s%100)/10 == 7) cout << "Yes" << endl;
    else if (((s%100)%10)/1 == 7) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
fun main() {
  val S = readString()
  val a = S.substring(0..1).toInt()
  val b = S.substring(2..3).toInt()
  if (a in 1..12 && b !in 1..12) println("MMYY")
  if (a !in 1..12 && b in 1..12) println("YYMM")
  if (a in 1..12 && b in 1..12) println("AMBIGUOUS")
  if (a !in 1..12 && b !in 1..12) println("NA")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 35868
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<complex>
#include<algorithm>
using namespace std;
#define ll long long
int main(){
  ll N,tmp;
  cin >> N;
  ll A[N];
  ll i;
  for(i=0;i<N;i++){
    cin >> tmp;
    A[i]= tmp-i-1;
  }
  sort(A,A+N);
  ll b=A[(N-1)/2];
  ll ans=0;
  for(i=0;i<N;i++){
    ans+=abs(A[i]-b);
  }
  cout << ans;
  return 0;
}


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

int main(){
	string s;
	string n=" ";
	int idx=0;
	cin >> s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='0'){
			n[idx]='0';
			idx++;
		}
		else if(s[i]=='1'){
			n[idx]='1';
			idx++;
		}
		else if(s[i]=='B'){
			if(idx!=0){
				idx--;
			}
		} 
	}
	for(int i=0;i<idx;i++){
		cout << n[i];
	}
}

Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int inf=1000000000;

int main() {
    int n=read(),k=read(),s=read();
    if (s==inf) {
        if (k==0) {
            for (re int i=1;i<=n;++i) printf("%d ",1);
            puts("");
        } else {
            for (re int i=1;i<k;++i) printf("%d ",inf);
            printf("%d ",inf-(n-k));
            for (re int i=k+1;i<=n;++i) printf("%d ",1);
            puts("");
        }
    } else {
        for (re int i=1;i<=k;++i) printf("%d ",s);
        for (re int i=k+1;i<=n;++i) printf("%d ",inf);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll d = abs(a - b);
    if((v - w) * t >= d) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 2000000

int H,st[MAX+1];

void maxHeapify(int i){
  int l,r,large,t;
  l=2*i;
  r=2*i+1;

  if(l<=H && st[l]>st[i])large=l;
  else large=i;
  if(r<=H && st[r]>st[large])large=r;

  if(large!=i){
    t=st[i];
    st[i]=st[large];
    st[large]=t;
    maxHeapify(large);
  }
}

int main(){

  int i;

  scanf("%d",&H);

  for(i=1;i<=H;i++)scanf("%d",&st[i]);

  
  for(i=(H/2);i>=1;i--)maxHeapify(i);

  for(i=1;i<=H;i++){
     printf(" %d",st[i]);
       
  }
  printf("\n");

  return 0;

}



Measured memory_bytes: 3732
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=15;
char s[maxn];

inline LL cal(int x,int y) {
    LL res=0;
    for (int i=x;i<=y;i++) res=res*10+(s[i]-'0');
    return res;
}

int main() {
    while (~scanf("%s",s+1)) {
        int len=strlen(s+1);
        LL ans=0;
        for (int i=0;i<(1<<(len-1));i++) {
            int p1=0,p2=0;
            for (int j=0;j<len;j++) {
                if (i&(1<<j)) {
                    p2=p1+1; 
                    p1=j+1;
                    ans+=cal(p2,p1);
                }
            }
            if (p1<len) ans+=cal(p1+1,len);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
N=int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,"",1)
    print(1,"",1)
    quit()
find=False
for i in range(2,N+1):
    if i*(i-1)==2*N:
        find=True
        k=i
        break
if not find:
    print("No")
    quit()
S=2*N//k


list=[[] for i in range(k)]
par1=0
par2=1
for _ in range(k-1):
    num=S-len(list[par1])
    for j in range(num):
        list[par1].append(par2+j)
    for i in range(S-par1):
        list[par1+1+i].append(par2+i)
    #print("WW",list)
    par2+=S-par1
    par1+=1
print("Yes")
print(k)
for i in range(k):
    print(str(S)+" "+" ".join(map(str,list[i])))


Measured memory_bytes: 44620
def main():
    N = int(input())
    S = list(map(int,list(input())))
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                cnt = 0
                for n in range(N):
                    if cnt == 0 and S[n] == i:
                        cnt += 1
                    elif cnt == 1 and S[n] == j:
                        cnt += 1
                    elif cnt == 2 and S[n] == k:
                        cnt += 1
                    
                    if cnt == 3:
                        ans += 1
                        break
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 42972
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  vector<long long> A(N);
  long long tmp;
  for(int i=0; i<N; i++)
    {
      cin >> A[i];//tmp;
      // A.push_back(tmp);
    }
  sort(A.begin(), A.end());

  for(int i=0; i<N-1; i++)
    {
      if(A[i+1]-A[i]==0)
	{
	  cout << "NO" << endl;
	  return 0;
	}
    }

  cout << "YES" << endl;
  


  return 0;
}



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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

int main()
{
	string s[3];
  uint id[3], now;

	cin >> s[0] >> s[1] >> s[2];
  id[0] = id[1] = id[2] = 0;
  now = 0;
  while(true){
    if(id[now] == s[now].size()) break;
    switch(s[now][id[now]]){
    case 'a':
      id[now]++;
      now = 0;
      break;
    case 'b':
      id[now]++;
      now = 1;
      break;
    case 'c':
      id[now]++;
      now = 2;
      break;
    }
  }
	cout << (char)('A'+now) << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        PriorityQueue<Integer> qPlus = new PriorityQueue<>();
        PriorityQueue<Integer> qMinus = new PriorityQueue<>(Collections.reverseOrder());

        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a < 0) qMinus.add(a);
            else qPlus.add(a);
            sum += Math.abs(a);
        }

//        debug(qPlus);
//        debug(qMinus);

        if (qMinus.size() == 0) {
            int min = qPlus.peek();
            System.out.println(sum - min * 2);
            int tmp = qPlus.poll();
            for (int i = 0; i < n - 1; i++) {
                int a = qPlus.poll();
                if (qPlus.isEmpty()) {
                    System.out.println(a + " " + tmp);
                } else {
                    System.out.println(tmp + " " + a);
                    tmp = tmp - a;
                }
            }
        } else if (qMinus.size() == n) {
            int min = qMinus.peek();
            System.out.println(sum - Math.abs(min) * 2);
            int tmp = qMinus.poll();
            for (int i = 0; i < n - 1; i++) {
                int a = qMinus.poll();
                System.out.println(tmp + " " + a);
                tmp = tmp - a;
            }
        } else {
            System.out.println(sum);
            int qMinusSize = qMinus.size();
            int qPlusSize = qPlus.size();
            int tmp = qPlus.poll();
            for (int i = 0; i < qMinusSize - 1; i++) {
                int a = qMinus.poll();
                System.out.println(tmp + " " + a);
                tmp = tmp - a;
            }
            qPlus.add(tmp);
            int minusTmp = qMinus.poll();
            for (int i = 0; i < qPlusSize - 1; i++) {
                int a = qPlus.poll();
                System.out.println(minusTmp + " " + a);
                minusTmp = minusTmp - a;
            }
            System.out.println(qPlus.poll() + " " + minusTmp);
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 77784
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii;//相当于含两个元素的结构体(算法笔记230)
 
vector<vector<ii>> g;//用邻接表储存(详情可看算法笔记P348)
vector<int> ans;//记录每一条边用什么颜色标记
int mx = 0;//最大的颜色号
void dfs(int u, int p, int usedColor)//u当前的点，p其父节点，usedColor当前的颜色号
{
    int idx = 1;
    for (auto cur : g[u])//由于不知道具体的个数，用auto方便 
	{
        int v = cur.first;//记录下一节点
        int edgeNumber = cur.second;//记录边号
        if (v == p) // 由于无向图，路径双向，防止走回路
            continue;
        if (usedColor == idx)//防止相同颜色变用同一结点
            idx++;
        mx = max(mx, idx);//更新mx
        ans[edgeNumber] = idx;
        dfs(v, u, idx);//进入下一层。（如果不加这句话，那么就单单只标记一个结点与其所有连边的颜色）
        idx++;
    }
}
 
int main()
{
    int n;
    scanf("%d", &n);
 
    g = vector<vector<ii>>(n, vector<ii>());//这一行和下一行看不懂，大概是准备工作什么的
    ans = vector<int>(n - 1, -1);
    for (int i = 0; i < n - 1; i++) //读入3个关键信息
	{
        int u, v;
        scanf("%d %d", &u, &v);
        u--;//这两句话尊重STLpush_back函数从0开始，所以向左偏一个单位
        v--;
 
        g[u].push_back(ii(v, i));
        g[v].push_back(ii(u, i));
    }
 
    dfs(0, -1, -1);
 
    printf("%d\n", mx);
    for (int i = 0; i < n - 1; i++)
        printf("%d\n", ans[i]);
 
    return 0;
}

Measured memory_bytes: 8320
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const int N = 1e5+5;
int dp[N];
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	int n,k;
	cin >> n >> k;
	k=min(n-1,k);
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<=k;i++)
	{
		dp[i]=abs(arr[i]-arr[0]);
		for(int j=0;j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
		}
	}
	for(int i=k+1;i<n;i++)
	{
		dp[i]=1e9;
		for(int j=(i-k);j<i;j++)
		{
			dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);	
		}
	}
	cout << dp[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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

  return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

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

	int countA[100001];
	int countB[100001];
	int maxA1 = 0;
	int maxB1 = 0;
	int vA1 = 0;
	int vB1 = 0;
	int maxA2 = 0;
	int maxB2 = 0;
	memset(countA, 0, sizeof(countA));
	memset(countB, 0, sizeof(countB));

	for (auto i = 0; i < n; ++i)
	{
		int v;
		cin >> v;
		if (i % 2 == 0)
		{
			++countA[v];
			if (maxA1 < countA[v])
			{
				maxA1 = countA[v];
				vA1 = v;
			}
			else if (maxA2 < countA[v])
			{
				maxA2 = countA[v];
			}
		}
		else
		{
			++countB[v];
			if (maxB1 < countB[v])
			{
				maxB1 = countB[v];
				vB1 = v;
			}
			else if (maxB2 < countB[v])
			{
				maxB2 = countB[v];
			}
		}
	}

	auto keep = maxA1 + maxB1;
	if (vA1 == vB1)
	{
		keep = max(maxA1 + maxB2, maxB1 + maxA2);
	}
	cout << n - keep << endl;

	return 0;
}


Measured memory_bytes: 1152
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in range(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            elif ices[i] > ices[i+1]:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        elif i == N-1:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,input().strip().split())
ices = [int(input().strip()) for _ in range(N)]


orderN(N,L,ices)

Measured memory_bytes: 15644
function main(arg) {
	var data = arg.trim().split("\n")[0].split(" ").map(Number)
	var a = data[0]
	var b = data[1]
	var ans = 0
	for (var i = 0;i < 2; i++) {
		if (a > b) {
			ans += a
			a--
		} else {
			ans += b
			b--
		}
	}
	console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define rep(i,x) for(int i=0;i<x;i++)
#define mod 1000000007
ll n,k;
vector<ll>num,cnt;
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
int main(){
	cin >> n >> k;
	for(ll i=1;i*i<=n;i++){
		if(n%i == 0) num.pb(i);
		if(n%i == 0 && i*i != n) num.pb(n/i);
	}
	sort(num.begin(),num.end()); 
	ll ret = 0;
	for(int i=0;i<num.size();i++){
		cnt.pb(1);
		int q = (num[i]+1)/2;
		cnt[i] = modpow(k,q); //cout << cnt[i] << endl;
		for(int j=0;j<i;j++){
			if(num[i]%num[j] == 0){
				cnt[i] = cnt[i]+mod-cnt[j]*(num[j]%2==0?2:1);
				cnt[i] %= mod;
			}
		}
		if(num[i]%2 == 0) cnt[i] = cnt[i]*(500000004LL)%mod;
		//cnt[i] = cnt[i] * num[i] % mod;
		ret += cnt[i] * num[i] % mod; //cout << cnt[i] << endl;
	}
	cout << ret%mod << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char c;

  while(1){
    scanf("%c",&c);
    if(c == '\n'){
        printf("\n");
    break;
    }
    if('A' <= c && c <= 'Z') c += 32;
    else if('a' <= c && c <= 'z') c -= 32;
    printf("%c",c);
  }
  return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n, k;
    while(cin>>n>>k){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            ans+=(a[i]>=k);
        }
        cout<<ans<<endl;
    }
  return 0;
}




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

ll gcd(ll a, ll b) { return (b == 0)? a : gcd(b,a%b);}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{

    ll n, m;
    cin >> n >> m;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n) {
        if (a[i]%2 != 0) {
            cout << 0 << endl;
            return 0;
        }
        a[i]/=2;
    }

    auto f = [&](ll x){
        ll ret = 0;
        while (x%2 == 0) {
            x /= 2;
            ret++;
        }
        return ret;
    };
    ll t = f(a[0]);
    rep(i,n) {
        if (f(a[i]) != t) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;    
    }
    m >>= t;

    ll l = 1;
    rep(i,n) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    ll ans = (m+1)/2;
    cout << ans << endl;
   
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int a, b;
    cin >> a >> b;
    cout << ((a <= 8 && b <= 8) ? "Yay!" : ":(") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<cmath>

using namespace std;
typedef long long LL;
const int N=100050;
int s[N],n,q;

int main(){
	
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&j);
		s[j]++;
	}
	for(i=1;i<=100000;i++)
		q=max(q,s[i-1]+s[i]+s[i+1]);
	cout<<q;

	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int A = int.Parse(Console.ReadLine());
		string ans = "Christmas";
		if(A==22){
			ans = "Christmas Eve Eve Eve";
		} else if(A==23){
			ans = "Christmas Eve Eve";
		} else if(A==24){
			ans = "Christmas Eve";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
cmp :: String -> String -> Ordering
cmp [] [] = EQ
cmp _  [] = GT
cmp [] _  = LT
cmp (x:xs) (y:ys) = let c = compare x y in if c == EQ then cmp xs ys else c

main :: IO ()
main = do
    a <- getLine
    b <- getLine
    let l = compare (length a) (length b)
    let c = if l == EQ then cmp a b else l
    putStrLn $ case c of
                GT -> "GREATER"
                LT -> "LESS"
                EQ -> "EQUAL"


Measured memory_bytes: 380
#include<stdio.h>

int parent(int);
int left(int);
int right(int);

struct node{
  int k;
  int pk;
  int lk;
  int rk;
};

main(){
  int i,heap_size;
  struct node A[251];
  scanf("%d",&heap_size);

  for(i=1 ; i <= heap_size ; i++){
    scanf("%d",&A[i].k);
  }

  for(i=1 ; i <= heap_size ; i++){
    if(i > 1){
    A[i].pk = A[parent(i)].k;
    }

    if(i <= heap_size/2){
      A[i].lk = A[left(i)].k;
    }

    if(i <= heap_size/2 && right(i) <= heap_size){
    A[i].rk = A[right(i)].k;
    }
}
  
  for(i=1 ; i <= heap_size ; i++){
    
    if(i == 1){
      printf("node %d: key = %d, left key = %d, right key = %d, \n",i,A[i].k,A[i].lk,A[i].rk);
    }
    
    if(i <= heap_size/2 && i >= 2 && right(i) <= heap_size){
      printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i].k,A[i].pk,A[i].lk,A[i].rk);   
    }

 if(i <= heap_size/2 && i >= 2 && right(i) > heap_size){
      printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i].k,A[i].pk,A[i].lk);   
 }
 
 
 
 if(i > heap_size/2){
   
   if(i == heap_size){
     printf("node %d: key = %d, parent key = %d, \n",i,A[i].k,A[i].pk);
     break;      
   }
   printf("node %d: key = %d, parent key = %d, \n",i,A[i].k,A[i].pk);
   
 }
  }
  return 0;
}

int parent(int i)
{
  return i/2;
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i+1;
}

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

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

const long long INF = 1LL << 60;

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

  bool ok = false;
  while(n > 0){
    if(n % 7 == 0 || n % 4 == 0){
      ok = true;
      break;
    }
    n -= 7;
  }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int judge;
  long long N, H[100000];
  cin >> N;
  rep(i,N) cin >> H[i];
  judge =0;
  
  for (int i = N-2; i>=0; i--){
    if (H[i] >= H[i+1] + 2) {
      judge++;
      break;
    }
    else if (H[i] == H[i+1] + 1) {
      H[i]--;
    }
    else{}
  }
  if (judge >= 1)
  	cout << "No" << endl;
   if (judge == 0)
  	cout << "Yes" << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner parameter = new Scanner(System.in);

        Integer count = 1;

        String[] input1 = parameter.nextLine().split(" ");
        String[] input2 = parameter.nextLine().split(" ");

        String limit = input1[1];

        Integer total = 0;

        for (int i = 0; i < input2.length; i++) {

        	total = total + Integer.valueOf(input2[i]);

        	if (total <= Integer.valueOf(limit)) {

        		count = count + 1;
        	} else {

        		break;
        	}
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>

//#define DEBUG

#define N 999999

int division_trial( int n ){
	int p=0;//The number of prime numbers
	bool flag;
	int i, j;

	for( i=2; i<=n; i++ ){
		flag=true;
		for( j=2; j<i; j++ ){
			if( i % j == 0 ){
				flag=false;
				break;
			}
		}
		if( flag == true )
			p++;
	}

	return p;
}

//Eratosthenes' sieve
int E_sieve( int n ){
	int p=0;//The number of prime numbers
	bool* plist = (bool*)malloc( sizeof(bool)*(n+1) );
	int i, j, k;

	memset( plist, true, sizeof(bool)*(n+1) );

	/***sieve***/
	for( i=2; i*i<=n; i++ ){

		//find a prime number
		for( j=i; plist[j]!=true; j++ )
			;

		//eliminate multiple of the prime number
		for( k=2*j; k<=n; k+=j ){
			plist[k]=false;
		}

	}

	/***count***/
	for( i=2; i<=n; i++ )
		if( plist[i] == true )
			p++;

	return p;
}

int main(){
#ifdef DEBUG
	
	clock_t start, end;
	int prime;

	start = clock();
	prime = E_sieve( 999999 );
	end = clock();

	printf("prime=%d\n", prime);
	printf("Time=%f\n", (double)(end-start)/CLOCKS_PER_SEC);
	
#else
	
	int n;

	while( scanf("%d", &n) != EOF ){
		printf("%d\n", E_sieve( n ) );
	}
	
#endif
	return 0;

}

Measured memory_bytes: 14876
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int cnt[100050];
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		cnt[t1]++;
		cnt[t2]++;
	}

	for (i = 1; i <= N; i++) if (cnt[i] % 2) return !printf("NO\n");
	return !printf("YES\n");
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a>b && a>c)
	{
		if(b<c)
		{
			printf("%d %d %d\n",b,c,a);
		}
		else 
		{
			printf("%d %d %d\n",c,b,a);
		}
	}
	else if(b>a&&b>c)
	{
		if(a>c)
		{
			printf("%d %d %d\n",c,a,b);
		}
		else
		{
			printf("%d %d %d\n",a,c,b);
		}
	}
	else
	{
		if(a>b)
		{
			printf("%d %d %d\n",b,a,c);
		}
		else
		{
			printf("%d %d %d\n",a,b,c);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef deque<ll> dqll;

const ll mod = 1000000007;

vector<ll> cst;
vector<vector<P>> lst;

void dfs(ll v, ll d) {
  cst[v] = d;
  for (auto p : lst[v]) {
    if (cst[p.first] == -1) dfs(p.first, d + p.second);
  }
}

int main() {
  ll N, Q, K;
  cin >> N;

  lst.assign(N, vector<P>(0));
  cst.assign(N, 0);

  for (int i = 1; i <= N - 1; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    lst[a].push_back(P(b, c));
    lst[b].push_back(P(a, c));
  }

  cst.assign(N, -1);

  cin >> Q >> K;
  K--;
  dfs(K, 0);

  for (int i = 0; i < Q; i++) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    cout << cst[u] + cst[v] << endl;
  }

  return 0;
}


Measured memory_bytes: 12800
lst1 = input().split()

N = int(lst1[0])
M = int(lst1[1])

lst2 = []

for i in range(M):
   lst2.append(input().split())

lst3 = []
for i in range(N):
   lst3.append(0)

for i in range(M):
   for j in range(2):
      lst3[ int(lst2[i][j]) - 1 ] += 1

for i in range(N):
   print(lst3[i])

Measured memory_bytes: 9100
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  int i,j,k;
  vector<int> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(v[j]>v[i]){
	k=v[i];
	v.erase(v.begin()+i);
	v.insert(v.begin()+j,k);
	break;
      }
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 1220
#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<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
#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
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
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;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,i;cin>>n;
	llint ans=0;
	vector<int>a(n);for(i=0;i<n;i++){cin>>a[i];}
	vector<int>b(n);for(i=0;i<n;i++){cin>>b[i];}
	for(int h=0;h<=28;h++){
		llint gen=0;
		vector<int>iti;
		vector<int>zro;
		for(i=0;i<n;i++){
			if(b[i]&(1<<h)){iti.pub(b[i]);}
			else{zro.pub(b[i]);}
		}
		b.clear();
		b=move(zro);for(auto it:iti){b.pub(it);}
		//for(auto it:b){cerr<<it<<" ";}cerr<<endl;
		iti.clear();zro.clear();
		for(i=0;i<n;i++){
			if(a[i]&(1<<h)){iti.pub(a[i]);}
			else{zro.pub(a[i]);}
		}
		a.clear();
		a=move(zro);for(auto it:iti){a.pub(it);}
		//cerr<<"de";
		//LBIを削減する
		//マージソートした後、アを行う
		vector<int>hon(n);
		vector<int>st;
		vector<int>ue;
		for(i=0;i<n;i++){
			llint it=a[i]%(1<<(h+1));
			hon[i]=2*(1<<h)-it;
			if(a[i]&(1<<h)){ue.pub(3*(1<<h)-it);gen+=n;}
			else{st.pub((1<<h)-it);}
		}
		for(auto it:st){ue.pub(it);}
		REV(hon);
		REV(ue);
		int ubas=0,hbas=0;
		//for(auto it:ue){cerr<<" "<<it;}cerr<<endl;
		//cerr<<"de";
		for(i=0;i<n;i++){
			int aaa=b[i]%(1<<(h+1));
			while(hbas<n&&hon[hbas]<=aaa){gen+=i;hbas++;}
			while(ubas<n&&ue[ubas]<=aaa){gen+=i;ubas++;}
		}
		gen+=n*(n-hbas);
		gen+=n*(n-ubas);
		if(gen%2==1){ans+=(1<<h);}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6096
import math

n = int(input())
ab = [list(map(int, input().split(" "))) for _ in range(n)]
ab.sort(key=lambda x: (x[1], x[0]))

jt = 0
for a, b in ab:
    jt += a
    if b < jt:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 66364
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, m;
vector<int> a, b, c[100005];

priority_queue<int> que;
inline void solve(){

    cin >> n >> m;

    a.resize(n+5);
    b.resize(n+5);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        c[a[i]].bash(b[i]);
        
    }

    ll ans = 0;
    
    for(int i = 1; i <= m; i++) {
        for(auto&&x : c[i])
            que.push(x);
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }

    cout << ans << endl;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


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

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i <= n - 1; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int sum=999999999;
		for (int i = 0; i <= n -k; i++) {
			if(sum>a[i+k-1]-a[i]){
				sum=a[i+k-1]-a[i];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 50176
l=int(input())
n=len(bin(l-1))-2 #頂点数
V=[]
if all([(l-1)>>i&1 for i in range(n)]):
    n+=1
    for i in range(n-1):
        V.append([i+1,i+2,0])
        V.append([i+1,i+2,2**(n-i-2)])


else:
    for i in range(n-1):
        V.append([i+1,i+2,0])
        V.append([i+1,i+2,2**(n-i-2)])

    now=2**(n-1)
    for i in range(n-2):
        if (l-1)>>(n-i-2)&1:
            V.append([1,i+2,now])
            now+=2**(n-i-2)
    if (l-1)&1:
        V.append([1,n-1,now])
    else:
        V.append([1,n,now])
print(n,len(V))
for v in V:
    print(*v)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//define
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007

string syugei(int N){
  string ST="b";
  for(int i=0;i<N;i++){
    if(i%3==0||i==0)ST="a"+ST+"c";
    else if(i%3==1||i==1)ST="c"+ST+"a";
    else if(i%3==2||i==2)ST="b"+ST+"b";
  }
  return ST;
}
//main
signed main(){
  int N,M,O,P,X,count=0,count2=0;
  double D;
  int c='A'-'a';
  char C;
  str S,T;
  cin>>S>>T;
  rep(0,3)if(S[i]==T[i])count++;
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A;
	for(int i=0; i<N; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	int cnt = 0;
	bool flag = true;
    while(1)
    {
    	for(int i=0; i<N; i++)
    	{
    		if(A[i]%2==0)
    		{
    			A[i] /= 2;
    		}
    		else
    		{
    		    flag = false;
    		    break;
    	    }
    	}
    	if(flag) cnt++;
    	else break;
    }
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
	int r = 0;
	for(int i = 0; i < 2; i++) {
		cin >> a >> b >> c >> d;
		r = max(r, a + b + c + d);
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std ;
int a[10][10];
int vis[1000000];
signed main()
{
	
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	int k=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&k);
		vis[k]++;
	}
	int flag=0;
	if((vis[a[1][1]]==1&&vis[a[1][2]]==1&&vis[a[1][3]]==1)||(vis[a[2][1]]==1&&vis[a[2][2]]==1&&vis[a[2][3]]==1)||(vis[a[3][1]]==1&&vis[a[3][2]]==1&&vis[a[3][3]]==1))
	flag=1;
	if((vis[a[1][1]]==1&&vis[a[2][1]]==1&&vis[a[3][1]]==1)||(vis[a[1][2]]==1&&vis[a[2][2]]==1&&vis[a[3][2]]==1)||(vis[a[3][3]]==1&&vis[a[2][3]]==1&&vis[a[1][3]]==1))
	flag=1;
	if((vis[a[1][1]]==1&&vis[a[2][2]]==1&&vis[a[3][3]]==1)||(vis[a[3][1]]==1&&vis[a[2][2]]==1&&vis[a[1][3]]==1))
	flag=1;
	if(flag==0){
		printf("No\n");
	} 
	else{
		printf("Yes\n");
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
        int n,m,i,j,num,tmp;
        int *B,**A;
        scanf("%d %d",&n,&m);
        B = (int *)malloc(sizeof(int)*m);
        A = (int **)malloc(sizeof(int*)*n);
        for(i=0;i<n;i++){
                A[i] = (int *)malloc(sizeof(int)*m);
        }
        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        scanf("%d",&A[i][j]);
                }
        }
        for(i=0;i<m;i++){
                scanf("%d",&B[i]);
        }
        for(i=0;i<n;i++){
                tmp = 0;
                for(j = 0;j<m;j++){
                        tmp = tmp + A[i][j] * B[j];
                }
                printf("%d\n",tmp);
        }
        for(i=0;i<n;i++){
                free(A[i]);
        }
        free(A);
        return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int N;
 cin >> N;
 vector<int> a(N);
 int sum = 0;

 for (int i = 0; i < N; ++i) {
 cin >> a[i];
 sum += a[i];
 }

 int mini = sum;
 int prefix_sum = 0;
 for (int i = 0; i < N; ++i) {
 cin >> a[i];
 prefix_sum += a[i];
 mini = min(mini, abs(prefix_sum - (sum - prefix_sum)));
 }

 cout << mini << endl;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

ll dp[3001][3001][2];
bool vis[3001][3001][2];
int T[3001];

ll count_dp(int a, int b, int c)
{
    if(vis[a][b][c]) return dp[a][b][c];
    if(a == b) return (c ? T[a]*(-1) : T[a]);
    vis[a][b][c] = true;

    if(c == 0)
        dp[a][b][c] = max(count_dp(a + 1, b, 1) + T[a], count_dp(a, b - 1, 1) + T[b]);  
    if(c == 1)
        dp[a][b][c] = min(count_dp(a + 1, b, 0) - T[a], count_dp(a, b - 1, 0) - T[b]);

    return dp[a][b][c];
}
int main()
{
    turbo

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> T[i];

    cout << count_dp(1, n, 0);
    
    return 0;
}

Measured memory_bytes: 158208
str = input()
q = int(input())
for i in range(q):
 c = input().split()
 if c[0] == 'print':
  a,b = list(map(int,c[1:3]))
  print(str[a:b+1])
 elif c[0] == 'reverse':
  a,b = list(map(int,c[1:3]))
  str = str[:a]+''.join(reversed(str[a:b+1]))+str[b+1:]
 elif c[0] == 'replace':
  a,b = list(map(int,c[1:3]))
  p = c[3]
  str = str[:a]+p+str[b+1:]

 


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

int main()
{
  int n, m, ans = 0;
  cin >> n;
  map<string, int> s;
  map<string, int> t;
  for (int i = 0; i < n; i++)
  {
    string blue;
    cin >> blue;
    s[blue]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    string red;
    cin >> red;
    t[red]++;
  }

  for (auto i = s.begin(); i != s.end(); i++)
  {
    ans = max(ans, i->second - t[i->first]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 998244353;
const int M = 1e6 + 10;

int fun[M], prod[M], suma[M];

void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

int inv(int a, int m) {
    if (a == 1) return 1;
    auto k = -inv(m%a, a);
    if (k < 0) k += a;
    return (ll(k)*m+1)/a;
}

void process(ll x, ll d) {
    add(prod[d], ll(x) * suma[d] % MOD);
    add(suma[d], x);
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    for (int i = 1; i < M; i++) fun[i] = inv(i,MOD);
    for (int i = 1; i < M; i++) {
        for (int j = i+i; j < M; j += i) {
            add(fun[j], MOD-fun[i]);
        }
    }
    int n; cin >> n;
    while (n--) {
        int x; cin >> x;
        for (int d = 1; d*d <= x; d++) if (x%d == 0) {
            process(x,d);
            if (d*d < x) process(x,x/d);
        }
    }

    ll ans = 0;
    forn(i,M) ans += ll(prod[i]) * fun[i] % MOD;
    cout << ans % MOD << endl;

    return 0;
}


Measured memory_bytes: 12032