akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    vector<vector<long long int> > D(C, vector<long long int>(C));
    for(int i=0; i<C; i++) {
        for(int j=0; j<C; j++) {
            cin >> D[i][j];
        }
    }
    vector<vector<long long int> > G(N, vector<long long int>(N));
    vector<map<long long int, long long int> > mp(3);
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            cin >> G[i][j];
            mp[(i+j)%3][G[i][j]]++;
        }
    }
    
    long long int ans=1e9;
    for(int i=0; i<C; i++) {
        for(int j=0; j<C; j++) {
            if(i==j) continue;
            for(int k=0; k<C; k++) {
                if(k==i || k==j) continue;
                long long int tmp=0;
                for(int l=0; l<3; l++) {
                    for(auto m=mp[l].begin(); m!=mp[l].end(); m++) {
                        if(l%3==0) {
                            tmp += D[((m->first)-1)][i] * m->second;
                        } else if(l%3==1) {
                            tmp += D[((m->first)-1)][j] * m->second;
                        } else {
                            tmp += D[((m->first)-1)][k] * m->second;
                        }
                    }
                }
                ans = min(ans, tmp);
            }
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 2304
import Control.Monad
import Prelude
import Data.Char
import Control.Applicative

main :: IO()
main = do
  [b,c] <- map (read :: String -> Int) . words <$> getLine :: IO [Int]
  let a=show b++show c :: String
  let bool= elem (read a)  (map(^2)[0..1000]) 
  if bool ==True
    then putStrLn "Yes"
    else putStrLn "No"

Measured memory_bytes: 508
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}

	max := 0
	max2 := 0
	for _, a := range A {
		if a >= max {
			max2 = max
			max = a
		} else if a >= max2 {
			max2 = a
		}
	}

	for _, a := range A {
		if a == max {
			fmt.Println(max2)
		} else {
			fmt.Println(max)
		}
	}
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define debug(x) cerr<<#x<<": "<<x<<endl
typedef long long ll;

int S(ll x){
    string str = to_string(x);
    int res = 0;
    for(char c : str){
        res += c-'0';
    }
    return res;
}

using P = pair<double,pair<ll,ll>>;

int main(void){
    int k;
    cin>>k;
    vector<P> v;
    ll nine = 0;
    rep(d,16){
        rep(i,400000){
            ll a = i*(nine+1);
            if(nine >= LLONG_MAX - a) break;
            ll x = nine + a;
            ll sx = S(x);
            v.push_back({(double)x/sx, {x,sx}});
        }
        nine = nine*10+9;
    }
    sort(all(v));
    ll max = 0;
    int cnt = 0;
    for(P p : v){
        ll x = p.second.first;
        if(max >= x) continue;
        max = x;
        cout<<x<<endl;
        cnt++;
        if(cnt == k)break;
    }

    return 0;
}


Measured memory_bytes: 198876
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
typedef long long ll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,k,s; cin>>n>>k>>s;
    vector <int> a(n);
    if(s==(int)1e9)rep(i,n)a[i] = 1;
    else rep(i,n)a[i] = 1e9;

    rep(i,k)a[i] = s;

    for(auto x:a)cout<<x<<' '; cout<<endl; return 0;
}


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

int main() {
	int x; cin >> x;
	int c500, h500 = 1000, c5, h5 = 5;
	c500 = x / 500, x = x % 500;
	c5 = x / 5, x = x % 5;
	cout << c500 * h500 + c5 * h5 << endl;
}



Measured memory_bytes: 256
// Getting Started - Maximum Profit
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
using System;
using System.Linq;

namespace ALDS1_1_D {
	class Program {
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var N = int.Parse(Input);	// Number of elements
			int min = int.Parse(Input);
			int max = -min;
			
			for(int i = 1; i < N; i ++) {
				int r = int.Parse(Input);
				if(max < r - min) max = r - min;
				if(min > r) min = r;
			}
			
			Output(max.ToString());
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}
	}
}

Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
void solve()
{
   long long n;
   n=3;
   vector<long long> v(n);
   cin>>v[0]>>v[1]>>v[2];
   sort(v.begin(),v.end());
   cout<<v[0]+v[1]<<"";
}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 256
N,M=map(int, raw_input().split())
S=[ map(int, raw_input().split())[1:] for _ in range(M) ] 
P=map(int, raw_input().split())

ans=0
for i in range(2**N):
	for m in range(M):
		tmp=0
		for s in S[m]:
			tmp+=( i>>(N-s) ) & 1

		tmp%=2

		if tmp!=P[m]:
			break
	else:
		ans+=1

print ans

Measured memory_bytes: 32620
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
  string t,p;
  cin >> t >> p;

  for(int i = 0; i < t.size(); i++){
    if(t[i] == p[0]){
      bool flag = true;
      for(int j = 0; j < p.size(); j++){
        if(t[i+j] != p[j]){
          flag = false;
          break;
        }
      }
      if(flag) cout << i << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3240
using System;
class program
{
  static void Main()
  {
    // スペース区切りの整数の入力
    string[] input = Console.ReadLine().Split(' ');
    
    // データ型をintに変換
    int first = int.Parse(input[0]);
    int second = int.Parse(input[1]);
    
    // 2つの整数の積
    int product = first * second;
    
    // if文で奇数・偶数の分岐
    if ( product % 2 == 0)
    {
      Console.WriteLine("Even");
    }
    else
    {
      Console.WriteLine("Odd");
    }
  }
}

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

using namespace std;

int main() {
  int N, cnt = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int in1, in2;
    
    cin >> in1 >> in2;
    
    if (in1 == in2) {
      cnt++;
    } else {
      cnt = 0;
    }
    
    if (cnt == 3) {
      cout << "Yes" << endl;
      
      return 0;
    }
  }
  
  cout << "No" << endl;
  
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int q; cin >> q;
  vector<ll> b(q), c(q);
  rep(i, q) cin >> b[i] >> c[i];

  map<ll, ll> mp;
  for(auto x : a) ++mp[x];
  ll sum = accumulate(ALL(a), 0ll);
  rep(i, q) {
    ll x = mp[b[i]];
    mp[b[i]] -= x;
    mp[c[i]] += x;
    sum += (c[i]-b[i])*x;
    cout << sum << endl;
  }
}

Measured memory_bytes: 11360
import sys

with sys.stdin as f:
    s_input = f.read()

    s_args = s_input.splitlines()
    n = int(s_args[0])
    s = s_args[1].split()

    if len(set(s)) >= 4:
        print("Four")
    else:
        print("Three")
        
sys.exit(0)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;

const int INF = 1000000;

enum {TO, WEIGHT};
typedef tuple<int, int> Edge;

enum {COST, ENTERED, VERTEX};
typedef tuple<int, int, int> Node;

int m, n, k, d;
int home, office, size;
vector<vector<Edge>> edge;

int index(const string& s) {
    if(s == "H") return home;
    if(s == "D") return office;
    int result = 0;
    for(int i = 1; i < s.size(); ++i) {
        result *= 10;
        result += s[i] - '0';
    }
    --result;
    return s[0] == 'C' ? result : result + m;
}

int bfs() {
    priority_queue<Node, vector<Node>, greater<Node>> q;
    q.push(Node(0, 0, home));
    vector<vector<int>> memo(size, vector<int>(1 << m, INF));
    while(!q.empty()) {
        int from = get<VERTEX>(q.top());
        int cost = get<COST>(q.top());
        int entered = get<ENTERED>(q.top());
        q.pop();
        if(memo[from][entered] <= cost) continue;
        memo[from][entered] = cost;
        for(const auto& e: edge[from]) {
            int to = get<TO>(e);
            int weight = get<WEIGHT>(e);
            int ent = entered;
            if(to < m && entered & (1 << to)) continue;
            if(to < m) ent |= 1 << to;
            q.push(Node(cost + weight, ent, to));
        }
    }
    return *min_element(memo[office].begin(), memo[office].end());
}

int main() {
    while(cin >> m >> n >> k >> d, m | n | k | d) {
        home = m + n;
        office = m + n + 1;
        size = m + n + 2;

        vector<int> calorie(m);
        for(int i = 0; i < m; ++i) cin >> calorie[i];

        edge = vector<vector<Edge>>(size);
        for(int i = 0; i < d; ++i) {
            string s1, s2;
            int cost;
            cin >> s1 >> s2 >> cost;

            int v1 = index(s1);
            int v2 = index(s2);
            cost *= k;

            if(v2 < m) edge[v1].push_back(Edge(v2, cost - calorie[v2]));
            else       edge[v1].push_back(Edge(v2, cost));

            if(v1 < m) edge[v2].push_back(Edge(v1, cost - calorie[v1]));
            else       edge[v2].push_back(Edge(v1, cost));
        }

        cout << bfs() << endl;
    }
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
const int N=500100,mod=998244353;
typedef long long ll;
int jc[N],jc2[N],n,k;
int inv(int x){return x==1?1:mod-mod/x*(ll)inv(mod%x)%mod;}
void init(){
	jc[0]=1;
	for(int i=1;i<=k;++i)jc[i]=(ll)jc[i-1]*i%mod;
	jc2[k]=inv(jc[k]);
	for(int i=k;i;--i)jc2[i-1]=(ll)jc2[i]*i%mod;
}
int C(int n,int k){
	if(n<k||k<0)return 0;
	return (ll)jc[n]*jc2[k]%mod*jc2[n-k]%mod;
}
int ans;
int main(){
	cin>>n>>k;init();
	for(int i=0;i<=k-i;++i){
		int j=k-i,tmp=n-(j-i);
		if(tmp>i)continue;
		if(i!=j)ans=(ans+C(k,i)-C(k,tmp-1))%mod;
		else ans=(ans+C(k-1,i-1)-C(k-1,n-2))%mod;
	}
	cout<<(ans+mod)%mod<<'\n';
	return 0;
}



Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,bj;
	string s;
	cin>>a>>b;
	cin>>s;
	if(s[a]!='-'){cout<<"No"<<endl;return 0;}
	for(int i=0;i<a+b+1;i++)
	{
		if(s[i]<48||s[i]>57)bj++;
		if(bj>=2){cout<<"No"<<endl;return 0;}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

class Node {
	public int id;
	public int[] childrenIds;
	public Node[] children;
	public Node parent;
	public int level = 0;
	
	public Node(int id, int[] childrenIds) {
		this.id  = id;
		this.childrenIds = childrenIds;
		this.children = new Node[childrenIds.length];
	}
	
	//puts children in 'children'
	public void putChildren(Node[] nodes) {
		for (int i = 0; i < childrenIds.length; i++) {
			for (int j = 0; j < nodes.length; j++) {
				if (childrenIds[i] == nodes[j].id) {
					children[i] = nodes[j];
					nodes[j].parent = this;
				}
			}
		}
	}
}

public class Main {
	public static int findDistance(Node start, Node end, Node[] allNodes) {
		LinkedList<Node> queue = new LinkedList<>();
		boolean[] visited = new boolean[allNodes.length+1];
		queue.add(start);
		Node currentNode = null;
		int level = 0;
		start.level = level;
		
		//find thing using BFS
		while (!queue.isEmpty()) {
			currentNode = queue.removeFirst();
			visited[currentNode.id] = true;
			
			if (currentNode == end) return currentNode.level;
			
//			for (int i = 0; i < currentNode.children.length; i++) {
//				if (!visited[currentNode.children[i].id]) {
//					queue.add(currentNode.children[i]);
//				}
//			}
			
			Node[] children = currentNode.children;
			for (int i = 0; i < children.length; i++) {
//				if (children[i].id == end.id) return currentNode.level+1;
				
				if (!visited[children[i].id]) {
					queue.add(children[i]);
					children[i].level = currentNode.level+1;
					visited[children[i].id] = true;
				}
			}
			
//			if (!queue.isEmpty()) System.out.println(queue.getFirst().id);
			
//			level++;
		}
		
		//use parents to trace to start
//		while (currentNode != start) {
//			currentNode = currentNode.parent;
//			
//		}
		
		
		return -1;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int numNodes = scanner.nextInt();
		Node[] nodes = new Node[numNodes];
		
		//load up nodes
		for (int i = 0; i < numNodes; i++) {
			int id = scanner.nextInt();
			int numChildren = scanner.nextInt();
			int[] children = new int[numChildren];
			
			for (int j = 0; j < numChildren; j++) {
				children[j] = scanner.nextInt();
			}
			
			nodes[i] = new Node(id, children);
		}
		scanner.close();
		
		//put children in nodes
		for (int i = 0; i < nodes.length; i++) {
			nodes[i].putChildren(nodes);
		}
		
		//use breadth first search to find the route from node 1 to all other nodes
		for (int i = 0; i < nodes.length; i++) {
			System.out.println(nodes[i].id + " " + findDistance(nodes[0], nodes[i], nodes));
		}
//		System.out.println(findDistance(nodes[0], nodes[2]));
	}
}



Measured memory_bytes: 28508
def main():
    n = int(input())
    L = [list(map(int,input().split())) for _ in range(n)]
    L.sort(key = lambda x: x[1])
    now = 0
    for l in L:
        now += l[0]
        if now > l[1]:
            print('No')
            return
    print('Yes')
main()

Measured memory_bytes: 53720
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, a, b; cin >> n >> a >> b;
  int one, two, three;
  one = two = three = 0;
  REP(i, n) {
    int p; cin >> p;
    if (p <= a) ++one;
    else if (p <= b) ++two;
    else ++three;
  }
  cout << min({one, two, three}) << '\n';
  return 0;
}


Measured memory_bytes: 256
cache = {}
def fib(x):
	if x in cache:
		return cache[x]
	elif x == 0 or x == 1:
		return 1
	else:
		v = fib(x - 1) + fib(x - 2)
		cache[x] = v
		return v

x = input()
print fib(x)

Measured memory_bytes: 4216
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		char[] N = s.next().toCharArray();
		
		long amount = 0;
		for(char v : N) {
			amount += v - '0';
		}
		
		if(amount % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 40452
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int mv[3] = {-1, 0, 1};

signed main() {
    int H, W;
    cin >> H >> W;
    V(V(char)) tbl(H, V(char)(W));
    rep(i, H) {
        string S;
        cin >> S;
        rep(j, W) {
            tbl[i][j] = S[j];
        }
    }

    V(V(char)) res(H, V(char)(W, '#'));
    rep(i, H) rep(j, W) {
        if(tbl[i][j]=='#') continue;
        int cnt = 0;
        rep(y, 3) rep(x, 3) {
            if(i+mv[y]<0 || i+mv[y]>=H || j+mv[x]<0 || j+mv[x]>=W) continue;
            if(tbl[i+mv[y]][j+mv[x]] == '#') cnt++;
        }
        res[i][j] = char(cnt + '0');
    }

    rep(i, H) {
        rep(j, W) cout << res[i][j];
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long sum_a = 0;
        for (int i = 0; i < tmp[1]; i++)
        {
            sum_a += a[i];
        }

        if (tmp[0] > sum_a)
        {
            Console.WriteLine("No");
        }
        else
        {
             Console.WriteLine("Yes");
        }
        
    }
}

Measured memory_bytes: 19680
N,A,B = map(int,input().split())

if B==0:
    print(N)
elif A==0:
    print(0)
else:
    n = (N//(A+B))
    ans = n * A
    N -= n*(A+B)
    if N >= A:
        ans+=A
    else:
        ans+=N
    print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 30001;

int main() {
	int N;
	int sum = 0;
	vector<int> ary;

	cin >> N;

	if (N <= 5) {
		switch (N) {
		case 3:
			cout << "2 5 63" << endl;
			break;
		case 4:
			cout << "2 5 20 63" << endl;
			break;
		case 5:
			cout << "2 5 20 30 63" << endl;
			break;
		}
		return 0;
	}

	ary.push_back(2);
	ary.push_back(3);
	ary.push_back(4);
	for (int i = 6; i < MAX; i += 6) {
		ary.push_back(i);
		if(i + 2 < MAX)ary.push_back(i + 2);
		if(i + 3 < MAX)ary.push_back(i + 3);
		if(i + 4 < MAX)ary.push_back(i + 4);
	}

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

	int j = N;
	int k = N;
	while (ary[j] % 6)j++;
	while ((ary[k] - 4) % 6)k++;

	switch (sum % 6) {
	case 2:
		ary[4] = ary[j];
		break;
	case 3:
		ary[5] = ary[j];
		break;
	case 5:
		ary[5] = ary[k];
		break;
	}

	for (int i = 0; i < N; i++) {
		if (i != 0)cout << " ";
		cout << ary[i];
	}
	cout << endl;


	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
void sort(int samy[] , int n)
{
    int t;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j<n; j++)
        {
            if (samy[i]>samy[j])
            {
                t = samy[j];
                samy[j] = samy[i];
                samy[i] = t;
            }
        }
    }
}
int main() {
    int n , count=0 , min;
    cin>> n >> min;
    int num [n] ;
    for (int i=0 ; i<n ; i++)
    {
        cin>> num[i];
    }
    sort (num , n);
    for (int j=0 ; j<min ; j++)
    {
        count+=num[j];
    }
    cout<<count;
    return 0;
}

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i <= b;++i) cout << ary[i] << (b == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

vector<int> par,depth;

void init(int n) {
    par = vector<int>(n,0);
    depth = vector<int>(n,0);
    for (int i = 0;i < n;++i) {
        par[i] = i;
        depth[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x,int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

bool same(int x,int y) {
    return find(x) == find(y);
}

int main() {
    int n,m,s = 0;
    long long ans = 0;
    int a[100010];
    vector<int> b;
    map<int,vector<int>> list;
    cin >> n >> m;
    for (int i = 0;i < n;++i) cin >> a[i];

    init(n);
    for (int i = 0;i < m;++i) {
        int x,y;
        cin >> x >> y;
        unite(x,y);
    }

    for (int i = 0;i < n;++i) list[find(i)].push_back(a[i]);
    for (auto it = list.begin();it != list.end();++it) {
        vector<int> c = it->second;
        sort(c.begin(),c.end());
        ans += c[0];
        s++;
        for (int i = 1;i < c.size();++i) b.push_back(c[i]);
    }
    
    if (s == 1) cout << 0 << endl;
    else if (b.size() < s-2) cout << "Impossible" << endl;
    else {
        sort(b.begin(),b.end());
        for (int i = 0;i < s-2;++i) ans += b[i];
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC"){
        cout<<"ARC";
    }
    else{
        cout<<"ABC";
    }
    
    return 0;
}

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

int main() {
	int H, N;
	cin >> H >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		H -= a;
	}
	if (H > 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
using namespace std;

int main() {
 double h[2],g,s;
 int n,i,j;
 while(true) {
	 for (i=0;i<2;i++) {
		 cin >> n;
		 h[i]=0;
		 if (n==0) return 0;
		 for (j=0,s=0;j<n-1;j++) {
			 cin >> g; s+=g;
			 h[i]+=sin(PI*g/180);
		 }
         h[i]+=sin(PI*(360-s)/180);
	 }
	 cout << (h[0]>h[1])+(h[0]<h[1])*2 << endl;
 }
 return 0;
 }

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, x;
string s[4] = {
  "AMBIGUOUS",
  "MMYY",
  "YYMM",
  "NA"
};
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  if(n/100>12 || n/100==0) x += 2;
  if(n%100>12 || n%100==0) x += 1;
  cout << s[x] << endl;
}

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

ll const MOD=1e9+7;

int main(){
    ll n;cin>>n;
    ll an=0;
    ll dp[110][4][4][4];
    rep(i,0,4)rep(j,0,4)rep(k,0,4)dp[3][i][j][k]=1;
    dp[3][0][2][1]=0;
    dp[3][0][1][2]=0;
    dp[3][2][0][1]=0;
    for(int i=4;i<=n;i++){
        rep(j,0,4){
            rep(k,0,4){
                rep(l,0,4){
                    rep(m,0,4){
                        if((m==0&&k==2&&l==1)||(m==0&&j==2&&l==1)||(j==0&&k==2&&l==1)||(j==0&&k==1&&l==2)||(j==2&&k==0&&l==1))continue;
                        dp[i][j][k][l]+=dp[i-1][m][j][k];
                        dp[i][j][k][l]%=MOD;
                    }
                }
            }
        }
    }
    rep(i,0,4)rep(j,0,4)rep(k,0,4){an+=dp[n][i][j][k];an%=MOD;}
    cout<<an<<endl;
}

    









Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO



getvuil :: IO (VU.Vector Int)
getvuil = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readi :: BSC8.ByteString -> Int
readi = fst . fromJust . BSC8.readInt
readil :: BSC8.ByteString -> [Int]
readil = map readi . BSC8.words
geti :: IO Int
geti = readi <$> BSC8.getLine
getil :: IO [Int]
getil = readil <$> BSC8.getLine

getNis :: Int -> IO [(Int, BSC8.ByteString)]
getNis 0 = return []
getisl n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getisl (n - 1))
    return ((readi aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

main :: IO ()
main = do
    aN <- geti
    let fizzBuzz = if ((mod aN 3 == 0) && (mod aN 5 == 0))
            then "FizzBuzz"
            else if (mod aN 3 == 0)
                then "Fizz"
                else if (mod aN 5 == 0) then "Buzz" else (show aN)

    let
        ret = foldl
            (\acc x ->
                if ((mod x 3) == 0) || ((mod x 5) == 0) then acc else acc + x
            )
            0
            [1 .. aN]

    print ret


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

int main() {
    int n;
    cin >> n;
    int max_count = 0;
    int max = 0;
    for(int i=n;i>0;i--){
        int count = 0;
        int temp = i;
        while(temp % 2 == 0){
            count++;
            temp /= 2;
        }
        if(count > max_count){
            max = i;
            max_count = count;
        }
    }
    if(n == 1){
        cout << 1 << endl;
    }else{
        cout << max << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int a[10010];
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]&1) continue;
		if(a[i]%3!=0 && a[i]%5!=0){
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> d[1005],a;
int v,e;
bool c[1005],dd[1005][1005];
bool f(int n,int m){
    if(c[m])return m==n;
    c[m]=true;
    for(int i : d[m]){
        a.push_back(i);
        if(f(n,i))return true;
        a.pop_back();
    }
    return false;
}
int main(){
    scanf("%d %d",&v,&e);
    for(int i=0;i<e;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        d[x].push_back(y);
        dd[x][y]=true;
    }
    for(int i=1;i<=v;i++){
        memset(c,0,v+1);
        a.push_back(i);
        if(f(i,i)){
            int x=0,y=a.size()-2,m=a.size()-1;
            for(int j=0;j<a.size()-1;j++)for(int k=0;k<a.size()-1;k++){
                if(dd[a[k]][a[j]])if(((k-j+1+a.size()-1)%(a.size()-1))<m&&(k-j+1+a.size()-1)%(a.size()-1)){
                    m=(k-j+1+a.size()-1)%(a.size()-1);
                    x=j,y=k;
                }
            }
            printf("%d\n",m);
            for(int j=0;j<m;j++)printf("%d\n",a[(x+j)%(a.size()-1)]);
            return 0;
        }
        a.pop_back();
    }
    printf("-1");
}

Measured memory_bytes: 1280
// @Team    : nupt2017team12
// @Author  : Zst
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define LL long long
#define MOD 1000000007
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define pb push_back
#define FOR(i,a,b) for( int i = ( a ); i <= ( b ); ++i )

const int N = 200+7;
char maps[N][N];
int vis[N][N];

int r, c;
int posX, posY;

int princess;
int soldier;

void solve( int x, int y, int times )
{
	vis[x][y] = times;
	if( maps[x][y] == '@' ) {
		princess = min( princess, times );
	} else if( maps[x][y] == '$' ) {
		soldier = min( soldier, times );
	}
	if( x-1 >= 0 ) {
		if( vis[x-1][y] == -1 ) {
			solve( x-1, y, times+1 );
		} else if( times+1 < vis[x-1][y] ) {
			solve( x-1, y, times+1 );
		}
	}
	if( y-1 >= 0 ) {
		if( vis[x][y-1] == -1 ) {
			solve( x, y-1, times+1 );
		} else if( times+1 < vis[x][y-1] ) {
			solve( x, y-1, times+1 );
		}
	}
	if( x+1 < r ) {
		if( vis[x+1][y] == -1 ) {
			solve( x+1, y, times+1 );
		} else if( times+1 < vis[x+1][y] ) {
			solve( x+1, y, times+1 );
		}
	}
	if( y+1 < c ) {
		if( vis[x][y+1] == -1 ) {
			solve( x, y+1, times+1 );
		} else if( times+1 < vis[x][y+1] ) {
			solve( x, y+1, times+1 );
		}
	}
	return;

}


int main()
{
    // freopen( "B.txt", "r", stdin );
    while( scanf( "%d%d", &r, &c ) != EOF ) {
    	princess = soldier = INF;
		CLR( vis, -1 );
	    FOR( i, 0, r-1 ) {
	    	scanf( "%s", maps[i] );
			FOR( j, 0, c-1 ) {
				if( maps[i][j] == '%' ) {
					posX = i;
					posY = j;
				} else if( maps[i][j] == '#' ) {
					vis[i][j] = true;
				}
			}
	    }
	    solve( posX, posY, 0 );
	    if( princess < soldier ) {
	    	printf( "Yes\n");
	    } else {
	    	printf( "No\n");
	    }
	}
	return 0;
}

Measured memory_bytes: 5324
#include<bits/stdc++.h>
using namespace std;
int N , K;
int l[50];
int main()
{
    cin >> N >> K;
    for(int i=0; i<N; ++i)
        cin >> l[i];
    sort(l, l+N); reverse(l, l+N);
    int sum = 0;
    for(int i=0; i<K; ++i)
        sum += l[i];
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
//for maximum flow
const int N = 210;
#define INF (1 << 21)//#define INF (1LL << 60)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
int cap[N][N];
bool visited[N];
int parent[N];
int flow[N][N];
int layer[N];
 
void make_layer(int n,int s,int t){
 queue<int> Q;
 Q.push(s);
 layer[s]=0;
 while(!Q.empty()){
   int now = Q.front();Q.pop();
   rep(i,n){
     if ( cap[now][i]-flow[now][i]>0 &&layer[i]==-1){
    layer[i]=layer[now]+1;
    Q.push(i);
     }
   }
 }
}
 
int augment(int now,int t,int n,int f){
 if ( now == t||f==0)return f;
 if ( visited[now])return 0;
 visited[now]=true;
 rep(i,n){
   if ( layer[now]<layer[i] ){
     int tmp=  augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
     if ( tmp > 0){
    flow[now][i]+=tmp;
    flow[i][now]=-flow[now][i];
    visited[now]=false;
    return tmp;
     }
   }
 }
 return 0;
}
 
int dinic(int n,int s,int t){
 int ansflow=0;
 bool flag=true;
 rep(i,n)rep(j,n)flow[i][j]=0;
 while(flag){
   fill(layer,layer+n,-1);
   fill(visited,visited+n,false);
   flag = false;
   //make layer
   make_layer(n,s,t);
   if (layer[t]==-1)break;//if no such path to go to sink
 
   //find blocking flow
   for(int f=1;f;flag=true){
     f = augment(s,t,n,INF);
     if ( f == 0)break;
     ansflow+=f;
   }
 }
 return ansflow;
}

/*
  与えられた入力から二部グラフを作って、最小パス被覆の本数を求める。
*/
int solve(vector<int> &in){
  int n = in.size();
  int src = 2*n,dst = 2*n+1,node = dst+1;
  rep(i,2*n+2)rep(j,2*n+2)cap[i][j] = 0;
  rep(i,n)cap[src][i] = cap[n+i][dst] = 1;
  rep(i,n){
    rep(j,n){
      if (i != j && in[j] % in[i] == 0){
	cap[i][n+j] = 1;
      }
    }
  }
  return n-dinic(node,src,dst);
}

main(){
  int n;
  while(cin>>n && n){
    vector<int> in(n),ans;
    rep(i,n)cin>>in[i];
    int num = solve(in);
    rep(i,n){/*i番目の要素を含むかどうか。*/
      bool isok=true;
      rep(j,ans.size())if (in[i] % in[ans[j]] == 0 || in[ans[j]] % in[i] == 0)isok=false;
      if (!isok)continue;
      /*すでに選ばれた要素とi番目の要素、の倍数は自明に含んではいけないので消去しておく。*/
      vector<int> tin;
      vector<int> tmp = ans;
      tmp.push_back(i);
      REP(j,i+1,n){
	rep(k,(int)tmp.size()){
	  if (in[j] % in[tmp[k]] == 0 || in[tmp[k]] % in[j] == 0)goto end;
	}
	tin.push_back(in[j]);
      end:;
      }
      rep(j,tmp.size())tin.push_back(in[tmp[j]]);
      int tans = solve(tin);
      if (tans == num)ans.push_back(i);
    }
    rep(i,ans.size()){
      if (i)cout << " " ;
      cout << ans[i]+1;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    int a;
    vector<int> co(9,0);
    FOR(i,0,N) {
        cin >> a;
        int c = a/400;
        if(c<8) co[c]+=1;
        else co[8]+=1;
    }
    int cnt =0;
    FOR(i,0,8){
        if(co[i]>=1)cnt+=1;
    }
    if(cnt==0){
        cout << 1 << " " << N << endl;
    }else{
        cout << cnt << " " << cnt + co[8] << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define endl "\n"

ll dp[100005][5];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	ll n;
	cin >> n;

	ll a, b, c;
	for(ll i=0; i<n; i++)
	{
		cin >> a >> b >> c;

		if(i)
		{
			dp[i][0] = a + max(dp[i-1][1], dp[i-1][2]);
			dp[i][1] = b + max(dp[i-1][0], dp[i-1][2]);
			dp[i][2] = c + max(dp[i-1][1], dp[i-1][0]);
		}

		else
		{
			dp[i][0]=a;
			dp[i][1]=b;
			dp[i][2]=c;
		}
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

	return 0;
}

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

int main() {

    int n, k;
    scanf("%d %d", &n, &k);

    int arr[n];

    for (int i = 0; i < n; i++) {
        arr[i] = 0;
    }

    int d, a;
    for (int j = 0; j < k * 2; j += 2) {
        scanf("%d", &d);
        for (int k = 0; k < d; k++) {
            scanf("%d", &a);
            arr[a - 1] = 1;
        }
    }
    int cnt = 0;

    for (int l = 0; l < n; l++) {
        if (arr[l] == 1) {
            cnt++;
        }
    }

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

    return 0;
} 

Measured memory_bytes: 1736
#include<stdio.h>

int main(void) {
   int H, W, i, j, k;

   for(i=1;;i++){
     scanf("%d %d", &H, &W);
     if(H ==0 && W ==0) break;
     for(j=1;j<=H;j++){
       for(k=1;k<=W;k++){
         if(j>1 && j<H && k>1 && k<W) printf(".");
         else printf("#");
       }
       printf("\n");
     }
     printf("\n");
   }
   return 0;
}



Measured memory_bytes: 2600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;

int f(int x)  {

    if (x%2 == 0) {
        return x/2;
    }
    else {
        return 3*x + 1;
    }
}

int main(int argc, const char * argv[]) {
    
    int s;
    cin >> s;

    map<int, bool> m;
    int x = s;
    int i=2;
    for (; ; i++) {
        m[x] = true;
        x = f(x);
        if (m[x] ) break;
    }

    cout << i << endl;

    return 0;
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A!=5 && A!=7) cout << "NO" << endl;
    else if(B!=5 && B!=7) cout << "NO" << endl;
    else if(C!=5 && C!=7) cout << "NO" << endl;
    else if(A+B+C==17) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int N;
	scanf("%d", &N);
	if (N % 2 == 0) {
		printf("%d", (N / 2) - 1);
		return 0;
	}
	printf("%d", N / 2);

	return 0;
}

Measured memory_bytes: 256
H,W,D=gets.chomp.split.map(&:to_i)
a = []
H.times do
    a << gets.chomp.split.map(&:to_i)
end

p = []
0.upto(H-1) do |i|
    0.upto(W-1) do |j|
        p[a[i][j]] = [i+1,j+1]
    end
end

t = Array.new(H*W+1,0)

(D+1).upto(H*W) do |i|
    t[i] = t[i-D] + (p[i][0] - p[i-D][0]).abs + (p[i][1] - p[i-D][1]).abs
end

Q=gets.to_i
Q.times do
    l,r = gets.chomp.split.map(&:to_i)
    puts t[r] - t[l]
end


Measured memory_bytes: 11900
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P;

const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a - b) < eps;
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

double getDistanceLP(P s1, P s2, P p) {
  return abs(cross(s2 - s1, p - s1) / abs(s2 - s1));
}

double getDistanceSP(P s1, P s2, P p) {
  if (dot(s2 - s1, p - s1) < 0.0) return abs(p - s1);
  if (dot(s1 - s2, p - s2) < 0.0) return abs(p - s2);
  return getDistanceLP(s1, s2, p);
}

const int MAXN = 5555;
const double inf = 1e10;
int N, M;
P ps[MAXN];
double dist[MAXN];

int main() {
  while (cin >> N >> M >> ps[0].real() >> ps[0].imag()) {
    for (int i = 1; i <= N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    dist[0] = inf;
    for (int i = 1; i <= N; ++i) {
      dist[i] = abs(ps[i] - ps[0]);
    }
    double res = 0;
    for (int r = 0; r < M; ++r) {
      int s = 0;
      for (int i = 0; i <= N; ++i) {
        if (dist[s] > dist[i] + eps) {
          s = i;
        }
      }
      int t = 0;
      for (int i = 0; i <= N; ++i) {
        if (dist[i] != inf) continue;
        if (norm(ps[t] - ps[s]) > norm(ps[i] - ps[s])) {
          t = i;
        }
      }
      res += abs(ps[t] - ps[s]);
      dist[s] = inf;
      for (int i = 0; i <= N; ++i) {
        if (dist[i] == inf) continue;
        dist[i] = min(dist[i], getDistanceSP(ps[s], ps[t], ps[i]));
      }
    }
    printf("%.10f\n", res);
  }
  return 0;
}

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

#define int long long

const int N = 3e3+5 , inf = 0x3f3f3f3f3f3f3f3f;
int n , dp[N][N][2] , A[N];

int rec(int x , int y , int cnt){
  if(dp[x][y][cnt] != inf) return dp[x][y][cnt];
  if(cnt == 1){
    return dp[x][y][1] = max(rec(x+1,y,0)+A[x],rec(x,y-1,0)+A[y]);
  }
  else{
    return dp[x][y][0] = min(rec(x+1,y,1)-A[x],rec(x,y-1,1)-A[y]);
  }
}

main(){
  cin >> n;
  for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < N ; j++) 
      for(int z = 0 ; z <= 1 ; z++) dp[i][j][z] = inf;
  for(int i = 1 ; i <= n ; i++){
    cin >> A[i];
    dp[i][i][1] = A[i] ,  dp[i][i][0] = -dp[i][i][1];
  }
  rec(1,n,1);
  cout << dp[1][n][1] << "\n";
}


Measured memory_bytes: 141568
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X,N;
    cin >> X >> N;
    if(N==0){
        cout << X << endl;
        return 0;
    }
    int p[N];
    for(int i = 0; i < N ; i++)cin >> p[i];
    for (int i = 0;true; i++)
    {
        int f1,f2;
        f1 = count(p,p+N,X-i);
        f2 = count(p,p+N,X+i);
        if(f1==0){
            cout << X-i << endl;
            break;
        }
        else if(f2==0){
            cout << X+i << endl;
            break;
        }
    }
    
}


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

int main(){
  int N,A;
  cin >> N;
  set<pair<int64_t,int> > sp;
  int64_t ma=1000;
  for(int i=0;i<N;i++){
    cin >> A;
    for(auto & p:sp){
      ma=max(ma,p.first*A+p.second);
    }
    sp.insert(make_pair(ma/A,ma%A));
  }
  cout << ma << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int sx,sy,tx,ty;
  int i;
  cin>>sx>>sy>>tx>>ty;
  for(i=0;i<(ty-sy);i++) cout<<"U";
  for(i=0;i<(tx-sx);i++) cout<<"R";
  for(i=0;i<(ty-sy);i++) cout<<"D";
  for(i=0;i<=(tx-sx);i++) cout<<"L";
  for(i=0;i<=(ty-sy);i++) cout<<"U";
  for(i=0;i<=(tx-sx);i++) cout<<"R";
  cout<<"D";
  cout<<"R";
  for(i=0;i<=(ty-sy);i++) cout<<"D";
  for(i=0;i<=(tx-sx);i++) cout<<"L";
  cout<<"U"<<endl;
  return 0;
}

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

using namespace std;

int main(void)
{
    int n, k;
    cin >> n >> k;

    vector<int> high(n);
    for (int i = 0; i < n;i++){
        cin >> high.at(i);
    }
    int M = 1000000005;
    sort(high.begin(), high.end());
    for (int i = 0; i < n - k+1;i++){
        int temp = high.at(i + k - 1) - high.at(i);
        M = min(M, temp);
    }
    cout << M << endl;
    return 0;
}

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

int main(void){
    string N;
    cin >> N;
    ll ans = 0;
    FOR(i,0,N.length()){
        ans += N[i] - '0';
    }
    if(ans % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3716
package main

import (
	"fmt"
	"sort"
)

func sum(vs []int) int {
	s := 0
	for _, v := range vs {
		s += v
	}
	return s
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	xs := make([]int, m)
	for i := range xs {
		fmt.Scan(&xs[i])
	}
	sort.Ints(xs)

	ds := make([]int, m-1)
	for i := range ds {
		ds[i] = xs[i+1] - xs[i]
	}

	sort.Sort(sort.Reverse(sort.IntSlice(ds)))

	if n > m {
		fmt.Println(0)
	} else {
		fmt.Println(sum(ds[n-1:]))
	}
}


Measured memory_bytes: 5504
#!python3

# input
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]


def main():
    w = []
    for i in range(2):
        l = [0] * (N + 1)
        for j in range(N):
            l[j + 1] = l[j] + A[i][j]
        w.append(l)
    
    ans = 0
    for i in range(N):
        x = w[0][i + 1] + (w[1][-1] - w[1][i])
        ans = max(ans, x)
    
    print(ans)


if __name__ == "__main__":
    main()


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

public class Main{
	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new Main().run();
	}
	
	public void run() throws NumberFormatException, IOException
	{
		BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(file.readLine());
		boolean[] bools = new boolean[N+1];
		int[] ints = new int[N+1];
		int max = 0;
		for(int i = 0;i<N;i++)
		{
			int x = Integer.parseInt(file.readLine());
			bools[x] = true;
			if(bools[x-1])
				ints[x] = ints[x-1];
			else
				ints[x] = x;
			max = Math.max(max, x-ints[x]+1);
		}
		System.out.println(N - max);
	}
	
}


Measured memory_bytes: 38560
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,d;
    cin>>n>>d;
    vector<vector<int> > x(n, vector<int>(d));

    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
        cin>>x[i][j];

        int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int sum=0;
            for(int k=0;k<d;k++)
            {
                int s=abs(x[i][k]-x[j][k]);
                sum+=s*s;
            }
            int k=sqrt(sum);
            if(k*k==sum)
                ans++;
        }
    }
    cout<<ans<<endl;


}











































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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep (i, N) cin >> h[i];//h[i]は足場i+1の高さ。
  vector<int> dp(N);
  //vector dp[i]には、足場iまで到達した場合の最小コストを記入する。
  rep(i,N){
    if(i==0)dp[0]=0;//足場1にいるとき(i=0)、コストは0
    else if(i==1)dp[1]=abs(h[1]-h[0]);//足場2にいるとき、足場1からくることだけを考える
    else dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));//足場3以上の時は両方計算して小さいほう
  }
  cout << dp[N-1] << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int n, m;
    
    while (scanf("%d %d", &n, &m) && n){
        int inf[20001] = {0};
        pair<int, pair<int, int> > log[20000];
        
        for (int i = 0; i < m; i++){
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            log[i] = make_pair(a, make_pair(b, c));
        }
        
        sort(log, log + m);
        
        inf[1] = 1;
        for (int i = 0; i < m; i++){
            if (inf[log[i].second.first]) inf[log[i].second.second] = 1;
        }
        
        int ans = 0;
        for (int i = 1; i <= n; i++) ans += inf[i];
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 1512