akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new D().doIt();
    }
    class D{
    	ArrayList<String> word = new ArrayList<String>();
    	ArrayList<String> wordnumber = new ArrayList<String>();
    	String word_num(String str,int length){
    		StringBuilder sb = new StringBuilder();
    		for(int i = 0;i < length;i++){
    			if(str.charAt(i) == 'a' || str.charAt(i) == 'b' || str.charAt(i) == 'c')sb.append(2);
    			else if(str.charAt(i) == 'd' || str.charAt(i) == 'e' || str.charAt(i) == 'f')sb.append(3);
    			else if(str.charAt(i) == 'g' || str.charAt(i) == 'h' || str.charAt(i) == 'i')sb.append(4);
    			else if(str.charAt(i) == 'j' || str.charAt(i) == 'k' || str.charAt(i) == 'l')sb.append(5);
    			else if(str.charAt(i) == 'm' || str.charAt(i) == 'n' || str.charAt(i) == 'o')sb.append(6);
    			else if(str.charAt(i) == 'p' || str.charAt(i) == 'q' || str.charAt(i) == 'r' || str.charAt(i) == 's')sb.append(7);
    			else if(str.charAt(i) == 't' || str.charAt(i) == 'u' || str.charAt(i) == 'v')sb.append(8);
    			else sb.append(9);
    		}
    		return sb.toString();
    	}
    	class Set{
    		int index;
    		String sb;
    		public Set(int index,String sb){
    			this.index = index;
    			this.sb = sb;
    		}
    	}
    	ArrayList<Set> set = new ArrayList<Set>();
    	void clear(){
    		word.clear();
    		wordnumber.clear();
    	}
    	void doIt(){
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
    			clear();
    			for(int i = 0;i < n;i++){
    				word.add(sc.next());
    				wordnumber.add(word_num(word.get(i),word.get(i).length()));
//    				System.out.println(word.get(i)+" "+wordnumber.get(i));
    			}
    			String str = sc.next();
    			set.add(new Set(0,""));
    			while(set.size() > 0){
    				Set s = set.remove(0);
//    				System.out.println(s.sb);
    				if(s.index == str.length()){
    					System.out.println(s.sb.trim()+".");
    					continue;
    				}
    				for(int i = 0;i < word.size();i++){
    					String wn = wordnumber.get(i);
    					String wn2 = word.get(i);
    					if(str.charAt(s.index) == wn.charAt(0)){
    						if(wn.length() <= str.length() - s.index){
    							boolean check  = true;
    							for(int j = 0;j < wn.length();j++){
    								if(str.charAt(s.index+j) != wn.charAt(j))check = false;
    							}
    							if(check){
    								set.add(new Set(s.index+wn.length(),s.sb + wn2+" "));
    							}
    						}
    					}
    				}
    			}
    			System.out.println("--");
    		}
    	}
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    char b;
    cin >> b;
    if (b == 'A')
        cout << 'T' << endl;
    else if (b == 'T')
        cout << 'A' << endl;
    else if (b == 'C')
        cout << 'G' << endl;
    else if (b == 'G')
        cout << 'C' << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <queue>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr char kBlack = '#';
constexpr char kWhite = '.';
constexpr int kMax = 1e5;

typedef std::pair<int, int> Point;

int main() {
  int H, W; std::cin >> H >> W;
  bool A[1000][1000];
  std::vector<Point> black_points;
  for (int h = 0; h < H; ++h) {
    std::string line; std::cin >> line;
    for (int w = 0; w < W; ++w) {
      if (line[w] == kBlack) {
        A[h][w] = true;
        black_points.push_back(std::make_pair(h, w));
      } else {
        A[h][w] = false;
      }
    }
  }

  int count = 0;
  while (true) {
    std::vector<Point> next_points;
    for (const auto& p : black_points) {
      int h = p.first; int w = p.second;
      if (h-1 >= 0 && !A[h-1][w]) { // up
        A[h-1][w] = true;
        next_points.push_back(std::make_pair(h-1, w));
      }
      if (h+1 < H && !A[h+1][w]) { // down
        A[h+1][w] = true;
        next_points.push_back(std::make_pair(h+1, w));
      }
      if (w-1 >= 0 && !A[h][w-1]) { // left
        A[h][w-1] = true;
        next_points.push_back(std::make_pair(h, w-1));
      }
      if (w+1 < W && !A[h][w+1]) { // right
        A[h][w+1] = true;
        next_points.push_back(std::make_pair(h, w+1));
      }
    }

    if (next_points.empty()) break;

    ++count;
    black_points = next_points;
  }

  std::cout << count<< std::endl;
}


Measured memory_bytes: 14568
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n,m;cin>>n>>m;
    vector<bool> se(n);
    deque<int> res(0);
    vector<set<int>> G(n,set<int>());
    for(int i=0;i<m;++i){
        int u,v;cin>>u>>v;
        u--;v--;
        G[u].insert(v);
        G[v].insert(u);
        if(i==0){
            res.push_back(u);
            res.push_front(v);
            se[u] = 1;
            se[v] = 1;
        }
    }
    while(true){
        int v = res.back();
        for(auto itr=G[v].begin();itr!=G[v].end();itr++){
            if(!se[*itr]){
                res.push_back(*itr);
                se[*itr] = 1;
                break;
            }
        }
        if(v==res.back())break;
    }
    while(true){
        int v = res.front();
        for(auto itr=G[v].begin();itr!=G[v].end();itr++){
            if(!se[*itr]){
                res.push_front(*itr);
                se[*itr] = 1;
                break;
            }
        }
        if(v==res.front())break;
    }
    cout<<res.size()<<endl;
    for(auto itr = res.begin();itr != res.end();itr++)cout<<*itr+1<<endl;
    return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(void){
  
  string S; cin >> S;
  int n = (int)S.size();
  deque<char> D;
  for(int i = 0; i < n; i++){ D.push_back(S[i]);}
 
  int Q; cin >> Q;
  int q = Q;
  bool dir = true;
  while(Q--){
    int t; cin >> t;
    if( t == 1 ){ dir = !dir;}
    else{
      int s; char c; cin >> s >> c;
      
      if( s == 1 ){
        if(dir){ D.push_front(c);}
        else{ D.push_back(c);}
      }
      else{
        if(dir){ D.push_back(c);}
        else{ D.push_front(c);}
      }
    }
  }//while
  
  int m = D.size();
  
  if(dir){ 
    for(int i = 0; i < m; i++){ cout << D[i];}
  }
  else{
    for(int i = m-1; i >= 0; i--){ cout << D[i];}
  }
  
  cout << endl;
  
  return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m, c;
	cin >> n >> m >> c;
	int b[m], a[n][m];
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			sum += a[i][j] * b[j];
		}
		sum += c;
		if (sum > 0) {
			ans++;
		}
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
import math
import itertools


N=int(input())
XY=[[None for _ in range(2)] for _ in range(N+1)]

for i in range(N):
    XY[i+1]=list(map(int,input().split()))

l = [_ for _ in range(1,N+1)]
p = itertools.permutations(l, N)
patern=math.factorial(N)

sums=0

for i in p:
    for j in range(N-1):
        sums+=math.sqrt((XY[i[j]][0]-XY[i[j+1]][0])**2 + (XY[i[j]][1] - XY[i[j+1]][1])**2) 

print(sums/patern)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{
  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long mod=1000000007l;
  static int INF=1000000;

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); }
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //
  static long cnt;
  static TreeSet<Integer> ans;
  static int n,m;
  static boolean[][] dp,vis;
  static HashMap<Pair,Boolean> arrl;
  static Stack<Integer> stk;
  static Queue<Integer> queue;
  static HashSet<Integer> mtrnode;
  static ArrayList<Integer> arrlans;


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=1000000007l;

    int n=sc.nextInt();
    double d=sc.nextDouble();
    double[] xy=new double[n];
    int cnt=0;
    for(int i=0;i<n;i++){
        double x=sc.nextDouble();
        double y=sc.nextDouble();
        xy[i]=Math.sqrt(x*x+y*y);
        if(xy[i]<=d) cnt++;
    }
    nl(cnt);


    out.flush();
  }

}

class Pair{
  int x,y;
  Pair(int x,int y){
    this.x=x;
    this.y=y;
  }
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({p + q, p + r, r + q}) << endl;
}


Measured memory_bytes: 256
def isok(mid):
    cnt = 0
    for i in range(N):
        if A[i] % mid == 0:
            cnt += A[i]/mid-1
        else:
            cnt += A[i]//mid
    if cnt <= K:
        return True
    else:
        return False

N,K = map(int,input().split())
A = list(map(int,input().split()))

#答えの範囲
left = 0
right = 10**9

while right - left > 1:
    mid = (right+left)//2
    if isok(mid):
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 30880
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
static const int INF = 99999999;
struct SEdge
{
	int To;
	int Cost;
};
int V, E;
vector<int> d;
vector< vector<SEdge> > G;

void Dijkstra(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		int v = p.second;
		if(d[v] < p.first)
		{
			continue;
		}
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Cost)
			{
				d[e.To] = d[v] + e.Cost;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void solve()
{
	cin >> V >> E;
	d.resize(V);
	G.resize(V);
	for(int i = 0; i < E; ++i)
	{
		int From, To, Cost1, Cost2;
		scanf("%d,%d,%d,%d", &From, &To, &Cost1, &Cost2);
		--From;
		--To;
		SEdge e1, e2;
		e1.To = To;
		e2.To = From;
		e1.Cost = Cost1;
		e2.Cost = Cost2;
		G[From].push_back(e1);
		G[To].push_back(e2);
	}
	int sum = 0;
	int x[2], y[2];
	scanf("%d,%d,%d,%d", &x[0], &y[0], &x[1], &y[1]);
	--x[0];
	--y[0];
	Dijkstra(x[0]);
	sum += d[y[0]];
	Dijkstra(y[0]);
	sum += d[x[0]];
	cout << x[1] - y[1] - sum << endl;
}

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

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  int n,x,m,i,min=1000,ans=0;
  scanf("%d %d",&n,&x);
  for(i=0;i<n;i++){
    scanf("%d", &m);
    if(min>m)min=m;
    x-=m;
    ans++;
  }
  while(x>=min){
    x-=min;
    ans++;
  }
  printf("%d\n",ans);
  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }


int main(){
    ll n;
    cin >> n;
    ll a[n] = {};
    vector<ll> vec;

    rep(i,0,n){
        ll a;
        cin >> a;

        ll ok = sz(vec), ng = -1;
        while(abs(ok-ng) > 1){
            ll mid = (ok+ng)/2;
            if(vec[mid] < a) ok = mid;
            else ng = mid;
        }

        if(ok == sz(vec)) vec.push_back(a);
        else{
            vec[ok] = a;
        }
    }
    
    cout << sz(vec) << endl;
    return 0;
}


Measured memory_bytes: 4952
fun main(args: Array<String>) {
  val S = readLine()!!.toString()
  var ans = "AC"
  if(S.take(1) != "A") {
    ans = "WA"
  }    
  if(S.drop(S.length -1) == "C") {
    ans = "WA"
  }    

  val bool = (2..S.length - 2).any{it ->
    S[it] == 'C'
  }
  if(bool == false){
    ans = "WA"
  }

  val boolUpperCase = S.count{it ->
    it.toInt() < 97
  }
  if(boolUpperCase > 2) {
    ans = "WA"
  }

  println(ans)
}

Measured memory_bytes: 33820
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_6_a{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    int[] num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    int size = 10001;
    int[] c = new int[size];
    for(int i=0; i<n; i++){
      c[num[i]]++;
    }
    for(int i=1; i<size; i++){
      c[i] += c[i-1];
    }
    int[] ans = new int[n];
    for(int i=n-1; i>=0; i--){
      ans[c[num[i]]-1] = num[i];
      c[num[i]]--;
    }
    Console.WriteLine(string.Join(" ",ans));
  }
}



Measured memory_bytes: 176076
$>.sync = true
def query(n)
  puts n
  c = gets[0]
  exit if c == ?V
  c == ?M
end

N = gets.to_i
prev = query(0)
prev_i = 0
(1...N).bsearch{|i|
  curr = query(i)
  # p [[prev_i, prev], [i, curr]]
  if (i%2 == prev_i%2) ^ (i < prev_i)
    curr != prev
  else
    curr == prev
  end.tap{
    prev = curr
    prev_i = i
  }
}


Measured memory_bytes: 4176
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if((A<=8)&&(B<=8)){
			System.out.println("Yay!");
        }else{
			System.out.println(":(");
        }
	}
}


Measured memory_bytes: 21844
using System;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        Console.WriteLine(solve(N));
    }

    public static int solve(int n)
    {
        int threeDigit = n / 100;
        int twoDigit = (n - threeDigit * 100) / 10;
        int oneDigit = n - (threeDigit * 100) - (twoDigit * 10);

        if (threeDigit < twoDigit) threeDigit++;
        else if (threeDigit == twoDigit && threeDigit < oneDigit) threeDigit++;
        twoDigit = threeDigit;
        oneDigit = threeDigit;

        return  threeDigit * 100 + twoDigit * 10 + oneDigit;
    }
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var V = ReadLongs();
            var C = ReadLongs();

            var ans = 0L;
            for (int i = 0; i < N; i++)
            {
                if (V[i] - C[i] > 0)
                {
                    ans += V[i] - C[i];
                }
            }

            return ans;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28216
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long long a[40]={},p=1;
  
  for(int i=1;i<40;i++){
    
    if(i>=2&&i%2)p*=3;
    a[i]=a[i-1]+p;
  }
  int n;
  
  while(cin>>n){

    cout<<a[n]<<endl;
  }
  
}

Measured memory_bytes: 2992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;
 
using namespace std;
 
ll a[200000];
ll b[200000];
int main()
{
	int n;
	ll ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
 
	for(int k=28;k>=0;k--)
	{
		ll tmp=0;
		for(int i=0;i<n;i++)
			a[i]%=(1LL<<(k+1));
		for(int i=0;i<n;i++)
			b[i]%=(1LL<<(k+1));
		//aを固定する
		sort(b,b+n);
		for(int i=0;i<n;i++)
		{
			tmp+=lower_bound(b,b+n,(1<<k)*2-a[i])-lower_bound(b,b+n,(1<<k)-a[i]);
			tmp+=lower_bound(b,b+n,(1<<k)*4-a[i])-lower_bound(b,b+n,(1<<k)*3-a[i]);
		}
		if(tmp&1)
			ans+=(1<<k);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin>>N;
	vector<int> a(N+2);
	FDS(i,N){
		cin>>a[i+1];
	}
	int summ=0;
	FDS(k,N+1){
	    summ+=abs(a[k]-a[k+1]);
	}
	FDS(k,N){
		int sum=0;
		sum=summ;
		sum+=abs(a[k]-a[k+2]);
		sum-=abs(a[k]-a[k+1]);
		sum-=abs(a[k+1]-a[k+2]);
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
void apply(long long &mn, long long &mx, long long x){
    long long rmn;
    if(mn % x == 0) rmn = mn;
    else rmn = mn - mn % x + x;
    long long rmx = mx - mx % x;
    if(rmn > mx && rmx < mn) {
        puts("-1");
        exit(0);
    }
    mn = rmn;
    mx = rmx + x - 1;
}
int main(){
    int k;
    long long nmin = 2, nmax = 2;
    scanf("%d", &k);
    vector<int> a(k);
    for(int i = 0; i < k; i++) scanf("%d", &a[i]);
    reverse(a.begin(), a.end());
    for(auto x : a) apply(nmin, nmax, x);
    printf("%lld %lld\n", nmin, nmax);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>vec(n);
    int64_t x=0;
    for(int i=0;i<n;i++){
    cin>>vec.at(i);
    x+=vec.at(i);
}
sort(vec.begin(),vec.end());
cout<<vec.at(0)<<" "<<vec.at(n-1)<<" "<<x<<endl;}


Measured memory_bytes: 3172
# coding: utf-8


def main():
    n, k = map(int, input().split())
    h = []
    for _ in range(n):
        h.append(int(input()))

    h.sort()

    min_diff = 99999999999
    for i in range(n - k + 1):
        tmp = h[i + k - 1] - h[i]
        if tmp < min_diff:
            min_diff = tmp

    print(min_diff)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7384
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)%s
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;
int n,a[100005];
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=a[1];
	For(i,2,n) ans=1ll*ans*gcd(a[i],i-1)%998244353;
	printf("%d\n",ans); 
}

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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	while(cin >> n >> k){
		vector<pair<int,int> >v;
		if(k>(n-1)*(n-2)/2){
			cout<<-1<<endl;
			exit(0);
		}
		set<pair<int,int> >st;
		f1(n){
			fr(j,i+1,n+1){
				st.insert({i,j});
			}
		}
		f1(n-1){
			fr(j,i+1,n){
				if(!k)break;
				st.erase({i,j});
				k--;
			}
		}
		cout << st.size() << endl;
		for(auto i:st){
			cout << i.F << ' '<< i.S << '\n';
		}
	}
}

Measured memory_bytes: 512
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[100005]={},b[100005]={},c[100005]={},ans=0,x,y;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  for(int i=0; i<n; i++) {
    cin >> c[i];
  }
  sort(a,a+n);
  sort(c,c+n);
  for(int i=0; i<n; i++) {
    x=lower_bound(a,a+n,b[i])-a;
    y=upper_bound(c,c+n,b[i])-c;
    ans+=x*(n-y);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> takoyaki = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            takoyaki.add(sc.nextInt());
        }
        sc.close();

        int ans = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                ans += takoyaki.get(i) * takoyaki.get(j);
            }
        }
        System.out.println(ans);

    }
}



Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int main(){
	int z;
	while(cin>>z){
		if(z==0)break;
		
		int xymax=0;
		int z3=z*z*z;
		for(int i=1;2*i*i*i<z3;i++){
			int i3=i*i*i;
			for(int j=i;i3+j*j*j<z3;j++){
				int j3=j*j*j;
				xymax=max(xymax,i3+j3);
			}
		}
		cout<<z3-xymax<<endl;
	}
}

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

int main() {
    ll a,b,k;
    cin >> a >> b >> k;
    if(k > a){
        k -= a;
        a = 0;
    }
    else{
        a -= k;
        k = 0;
    }
    if(k > b){
        b = 0;
    }
    else{
        b -= k;
    }
    cout << a << " "<< b;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>; //(x, y, dx, dy)
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, A, B;
	cin >> N >> A >> B;
	vector<ll> p(N);
	for (int i = 0;i < N;i++) {
		cin >> p[i];
		p[i]--;
	}
	vector<ll> minimax(N, -1);
	for (int base = 0;base < N;base++) {
		for (int i = base + 1;i < N;i++) {
			if (p[i] < p[base])
				minimax[base] = max(minimax[base], p[i]);
		}
	}
	vector<vector<ll>> dp(N + 1, vector<ll>(N, INF));
	dp[0][0] = 0;
	for (int i = 0;i < N;i++) {
		ll nowmini = INF;
		for (int j = 0;j < N;j++) { // jより小さいやつは飛ばす
			if (p[i] < j)
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + B);
			else {
				if (minimax[i] >= j)
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + A);
				else
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
				nowmini = min(nowmini, dp[i][j]);
			}
		}
		dp[i + 1][p[i]] = min(dp[i + 1][p[i]], nowmini);
	}
	ll ans = INF;
	for (int i = 0;i < N;i++)
		ans = min(ans, dp[N][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 196096
PROGRAM RoadToMillionair
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 16
      integer(p) :: n,yen,kabu, i,mi
      integer(p),allocatable :: a(:)
      logical,allocatable :: isPeak(:)
      
      read*,n
      allocate( a(n+1),isPeak(n) )
      read*,a(1:n)
      a(n+1) = 100
      
      isPeak = .false.
      do i = 2,n
        if( a(i-1)<=a(i) .and. a(i)>a(i+1) )then
          isPeak(i) = .true.
        end if
      end do
      
      
      yen = 1000
      kabu = 0
      mi = a(1)
      do i = 1,n
        if( isPeak(i) )then
          !売り
          kabu = yen / mi
          yen = yen - mi*kabu
          
          !買い
          yen = yen + kabu*a(i)
          kabu = 0
          
          mi = a(i+1)
          
          
        else
          mi = min( a(i),mi )
        end if
      end do
      
      
      print*,yen
      
      stop
      !debugg
      print*,''
      print*,n
      print*,a
      print*,isPeak
      
      
      END PROGRAM

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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int Mod = 1e9 + 7;

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

int mul(int x, int y){
	return (long long)x * y % Mod;
}

struct Matrix{

	const static int n = 4;

	int M[n][n];

	Matrix(int id = 0){
		memset(M, 0, sizeof M);
		if(id == 1) For(i, 0, n - 1) M[i][i] = 1;
	}

	Matrix operator * (const Matrix &A) const{
		Matrix C;
		For(k, 0, n - 1) For(i, 0, n - 1) For(j, 0, n - 1) add(C.M[i][j], mul(M[i][k], A.M[k][j]));
		return C;
	}

	Matrix operator ^ (int e){
		Matrix x = *this, ret(1);
		while(e){
			if(e & 1) ret = ret * x;
			x = x * x;
			e >>= 1;
		}
		return ret;
	}

};


const int N = 100010;

int n, m;
int pos[N];

int main(){	

	scanf("%d%d", &n, &m);
	For(i, 1, m) scanf("%d", &pos[i]);
	pos[++m] = n;

	Matrix tr;
	tr.M[0][0] = tr.M[1][0] = 1;
	tr.M[1][1] = tr.M[3][1] = 1, tr.M[2][1] = 2, tr.M[0][1] = 4;
	tr.M[2][2] = tr.M[3][2] = 1, tr.M[0][2] = 2;
	tr.M[0][3] = tr.M[3][3] = 1;

	Matrix base;
	base.M[0][0] = 1;

	base = base * (tr ^ pos[1]);
	For(i, 2, m){
		base.M[0][0] = 0;
		base = base * (tr ^ (pos[i] - pos[i - 1]));
	}

	printf("%d\n", base.M[0][0]);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=((ans%mod)*(x%mod))%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
int main()
{
fast_io
li a,b,i;
cin>>a>>b;
for(i=1;i<10000;i++)
{
  li x=(8*i)/100;
  li y=i/10;
  if((x==a)&&(y==b))
  break;
}
if(i==10000)
cout<<"-1";
else
cout<<i;

  return  0;
}


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

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

  ll x = n;
  if(n>=b-1) x=b-1;
  ll ans = a * (x % b) / b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
n = int(input())
A=list(map(int,input().split()))
cnt=0
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    try:
        cnt+=Bd[k]*Cd[-k]
    except KeyError:
        continue
print(cnt)

Measured memory_bytes: 197360
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A,B;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
    B = fetch_vec<ll>(N);
}
#define YES do{cout <<"Yes" << endl;return 0;}while(false);
#define NO do{cout <<"No" << endl;return 0;}while(false);

int solve(){
    if(A==B) YES
    ll as = accumulate(A.begin(),A.end(),0LL);
    ll bs = accumulate(B.begin(),B.end(),0LL);
    if(as>=bs) NO
    ll diff = bs-as;
    ll diff_A=0;
    ll diff_b=0;
    for (int i = 0; i < N; i++)
    {
        if(B[i]<A[i]) diff_b+=(A[i]-B[i]);
        else diff_A +=(B[i]-A[i])/2;
    }
    if(diff_b>diff) NO
    if(diff_A<diff_b) NO
    YES
    return 0;
}   

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

Measured memory_bytes: 384
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <numeric>

size_t f(size_t a, size_t b, size_t w) {
  a %= w+w;
  b += w+w+w+w;
  if ((a+b) % 2 == 0) {
    b -= a;
  } else {
    b += a;
  }
  if ((b/w) % 2 == 0) {
    return b%w;
  } else {
    return w - (b%w) - 1;
  }
}

int main() {
  size_t h, w, n;
  scanf("%zu %zu %zu", &h, &w, &n);

  std::vector<std::pair<size_t, size_t>> s(n);
  for (auto& si: s)
    scanf("%zu %zu", &si.first, &si.second);
  std::sort(s.begin(), s.end());

  std::vector<size_t> cur(w);
  std::iota(cur.begin(), cur.end(), 0);
  for (const auto& si: s) {
    size_t a, b;
    std::tie(a, b) = si;

    size_t lf = f(a, b-1, w);
    size_t rg = f(a, b, w);
    std::swap(cur[lf], cur[rg]);
  }

  std::vector<size_t> res(w);
  for (size_t i = 0; i < w; ++i)
    res[cur[f(h, i, w)]] = i+1;

  for (auto ri: res) printf("%zu\n", ri);
}



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

using namespace std;

const int mxn = 1e5;
unsigned long long a[mxn + 11];
const long long mm = 1e18;

int main(){
	int n;
	scanf("%d", &n);
	unsigned long long ans = 1;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	sort(a, a + n);
	if (a[0] == 0LL){
		puts("0");
		return 0;
	}
	for (int i = 0; i < n; i++){
		if (a[i] <= mm / ans)
			ans *= a[i];
		else {
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4612
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 300000 + 9;
int n,k,a[N],val[N*5];

void up(int s,int e,int p,int idx,int v)
{
    if(s==e)
    {
        val[p]=max(val[p], v);
        return ;
    }
    int mid =(s+e)/2;
    if(idx<=mid) up(s,mid,p*2,idx,v);
    else up(mid+1,e,p*2+1,idx,v);
    val[p] = max(val[p*2],val[p*2+1]);
}


int get(int s,int e,int p,int l,int r)
{
    if(s>=l&&e<=r) return val[p];
    int mid =(s+e)/2;
    if(r<=mid) return get(s,mid,p*2,l,r);
    else if(l>mid)return get(mid+1,e,p*2+1,l,r);
    else return max(get(s,mid,p*2,l,r),get(mid+1,e,p*2+1,l,r));

}
 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n>>k;
        forr(i,1,n)cin>>a[i];
        int ans=0;
        forr(i,1,n)
        {
            int mx = get(1,300000,1,max(1,a[i]-k),min(300000,a[i]+k));
            ans=max(ans,mx+1);
            up(1,300000,1,a[i], mx+1);
        }

        cout<<ans<<endl;









return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int n;
    cin >> n;
    vi d(n);
    REP(i, n) cin >> d[i];
    set<int> seq;
    int a = 1, b = 10;
    while (1) {
        REP(i, n-a+1) {
            int n = 0;
            FOR(j, i, i+a) {
                n *= 10;
                n += d[j];
            }
            seq.insert(n);
        }
        REP(i, b) {
            if (!EXIST(seq, i)) {
                cout << i << endl;
                return 0;
            }
        }
        a++;
        b *= 10;
    }
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  REP(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  REP(i, D) { REP(j, 26) cin >> s[i][j]; }
  ll score = 0;
  vector<ll> ans(0);
  unordered_map<int, int> lastday{};
  REP(i, D) {
    vector<pair<ll, int>> tmp(26);
    REP(j, 26) {
      //貪欲に選ぶ
      tmp[j].first = score + s[i][j];
      tmp[j].second = j;
      REP(k, 26) {
        if (j == k) continue;
        tmp[j].first -= c[k] * (i + 1 - lastday[k]);
      }
    }
    sort(tmp.begin(), tmp.end());
    ans.push_back(tmp[25].second);
    lastday[tmp[25].second] = i;
    score = tmp[25].first;
  }
  REP(i, D) { cout << ans[i] + 1 << endl; }
}

Measured memory_bytes: 3692
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		long[] a = new long[n];
		for(int i=0; i<a.length; ++i){
			a[i] = scn.nextInt();
		}
      	int count = 0;
      	for(int i=0; i<a.length; ++i){
			for(int j=0; j<1000; j++){
              if(a[i]%2==1) break;
              a[i]=a[i]/2;
              count++;
            }
		}
      	System.out.println(count);
	}
}


Measured memory_bytes: 48112
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    int Bplace;
    if(B/100 == 1)Bplace = 2;
    if(B/10 >= 1 && B/10 < 10 )Bplace = 1;
    if(1 <= B && B < 10)Bplace = 0;
    bool frag = 0;
    for(int i = 0;i < 1000;i++){
        if(A*pow(10,Bplace+1)+B == i*i) frag = 1;
        }
    if(frag) cout << "Yes" << endl;
    else cout << "No" << endl;
   
}   

Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b,int c){
	int t,d=b;
	while(b!=0){
		t=a%b;
		a=b;
		b=t;
	}
	while(d!=0){
		t=c%d;
		c=d;
		d=t;
	}
	while(c!=0){
		t=a%c;
		a=c;
		c=t;
	}
	return a;
} 
int main(){
	int n,i,j,k;
	scanf("%d",&n);
	unsigned long long sum=0;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				sum+=gcd(i,j,k);
			}
		}
	}
	printf("%lld",sum);
	return 0;
} 

Measured memory_bytes: 1732
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    minv = i
    for j in range(i, n):
        if a[j] < a[minv]:
            minv = j
    if minv != i:
        a[i], a[minv] = a[minv], a[i]
        cnt += 1

print(*a)
print(cnt)



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

using namespace std;

set<string> st;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  for(char ch = 'a'; ch <= 'z'; ++ch) {
    for(int i = 0; i < s.length(); ++i)
      if(s[i] == ch)
        for(int j = i + 1; j <= i + 1 + 10; ++j)
          st.insert(s.substr(i, j - i));
    if(st.size() >= k)
      break;
  }

  int cnt = 1;
  for(set<string>::iterator it = st.begin(); it != st.end(); ++it, ++cnt)
    if(cnt == k) {
      cout << *it << endl;
      return 0;
    }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n){
      cin >> h[i];
    }
    sort(rall(h));
    ll ans = 0;
    if(k >= n){
      print(0);
      return 0;
    }
    REP(i,k,n){
      ans += h[i];
    }

    print(ans);

}


Measured memory_bytes: 1792
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    dp = [0] * n
    for i in range(1, n):
        h = a[i]
        cost = 10**9
        for j in range(max(0, i-k), i):
            if dp[j] + abs(h - a[j]) < cost:
                cost = dp[j] + abs(h - a[j])
        dp[i] = cost

    print(dp[n-1])

main()

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

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

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


n,a,b = map(int,input().split())

ans = min(b,n*a)

print(ans)

Measured memory_bytes: 4596
package main

import (
        "fmt"
        "strconv"
)

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Printf("%d\n", dfs(0, s))
}

func dfs(sum int, s string) int {
        result := sum
        for i := 1; i < len(s); i++ {
                a, _ := strconv.Atoi(s[0:i])
                result += dfs(sum+a, s[i:len(s)])
        }
        a, _ := strconv.Atoi(s)
        return result + a
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((a+b) > (c+d)) printf("Left");
    else if((a+b) < (c+d)) printf("Right");
    else printf("Balanced");
    return 0;
}

Measured memory_bytes: 128
#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>;

bool isKibun(string s) {
  for (int i = 0; i < s.size() / 2; ++i) {
    if (s[i] == s[s.size() - 1 - i]) {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;

  bool res = isKibun(s);
  if (!res) {
    cout << "No" << endl;
    return 0;
  }

  int n = s.size() - 1;
  int n2 = (n - 1) / 2 + 1;
//  cout << n2 << endl;
  string s2 = s.substr(0, n2);
  res = isKibun(s2);

  int n3 = (n + 3) / 2;
//  cout << n3 << endl;
  string s3 = s.substr(n3, n - n3);

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;
int main() {
    while (cin >> str) {
        cout << str[0] << (int)str.size() - 2 << str.back() << endl;
    }
}

Measured memory_bytes: 256
#124_D
N,K=map(int,input().split())
S=input()
cnt=[]
if S[0]=='0':
    cnt.append(0)
res=1
for i in range(1,N):
    if S[i-1]==S[i]:
        res+=1
    else:
        cnt.append(res)
        res=1
cnt.append(res)
if S[-1]=='0':
    cnt.append(0)

cnt_sum=[0]
for i in range(len(cnt)):
    tmp=cnt_sum[i]+cnt[i]
    cnt_sum.append(tmp)
    
ans=1
for i in range(0,len(cnt_sum),2):
    res=cnt_sum[min(len(cnt_sum)-1,2*K+1+i)]-cnt_sum[i]
    ans=max(ans,res)
    
print(ans)

Measured memory_bytes: 7932
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<int> pre, in, post;

int N, M;

vector<vector<int> > e;
vector<vector<int> > r;

vector<int> ball_count;
vector<bool> include_w;


int main(){
  cin >> N >> M;
  ball_count.resize(N+1);
  FOR(i,1,N+1)ball_count[i]=1; 

  include_w.resize(N+1);
  FOR(i,1,N+1)include_w[i] = false;
  include_w[1] = true;

  REP(i,M){
    int x, y;
    cin >> x >> y;

    if(include_w[x])include_w[y] = true;

    ball_count[x] -= 1;
    ball_count[y] += 1;
    if(ball_count[x] == 0)include_w[x] = false;
  }

  int ans = 0;
  FOR(i,i,N+1)if(include_w[i])ans++;
  cout << ans << endl;

}



Measured memory_bytes: 640