akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	
	for (auto& e : vec) {
		cin >> e;
	}

	int mmin = 10000000;
	int m;

	for (int j = 1; j <= 100; j++) {
		m = 0;
		for (int i = 0; i < n; i++) {
			m += pow(vec.at(i) - j, 2);
		}
		mmin = min(mmin, m);
	}
	cout << mmin << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	lint A;
	double B;
	cin >> A >> B;

	cout << A * (int)round(B * 100) / 100 << "\n";

	return 0;
}



Measured memory_bytes: 3772
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] a = new int[n + 2];
		a[0] = 0;
		a[n + 1] = 0;
		long sum = 0;
		int[] b = new int[n + 1];
		int[] c = new int[n];

		for (int i = 1; i <= n + 1; i++) {
			if (i != n + 1)
				a[i] = Integer.parseInt(sc.next());

			b[i - 1] = Math.abs(a[i] - a[i - 1]);
			sum += Math.abs(a[i] - a[i - 1]);

			if (i != 1)
				c[i - 2] = Math.abs(a[i] - a[i - 2]);

		}

		for (int i = 0; i < n; i++) {
			System.out.println(sum - b[i] - b[i + 1] + c[i] + " ");
		}
	}

}


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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }


void solve(){
    string s;
    cin >> s;
    if(s.back() == 's') s += "es";
    else s += "s";
    cout << s << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct SegTree {
    int N;
    vector<Int> data;
    SegTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        data.assign(2*N, 0);
    }
    void addrange(int l, int r, Int v) {
        l += N;
        r += N;
        while (l < r) {
            if (r & 1) data[--r] += v;
            if (l & 1) data[l++] += v;
            l /= 2, r /= 2;
        }
    }
    Int operator[](int i) {
        i += N;
        Int ans = 0;
        while (i > 0) {
            ans += data[i];
            i /= 2;
        }
        return ans;
    }
};
int main()
{
    int N, M; cin >> N >> M;
    vector<int> A(N); for (auto& a : A) cin >> a, a--;
    SegTree B(2*M), C(2*M);
    for (int i = 1; i < N; i++) {
        int s = A[i-1];
        int e = A[i] < A[i-1] ? A[i]+M : A[i];
        C.addrange(0, M, e - s);
        B.addrange(s+1, e+1, -1);
        C.addrange(s+1, e+1, s+1);
    }
    Int ans = LLONG_MAX;
    for (int x = 0; x < M; x++) {
        ans = min(ans, B[x] * x + C[x] + B[x+M] * (x+M) + C[x+M]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8832
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  int a;
  cin>>a;
  string s;
  cin>>s;
  string s1=s.substr(0,a/2);
  string s2=s.substr(a/2,a/2);
  if(s1==s2&&a!=1&&a%2==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

#define ll long long int

using namespace std;

int main(void){
    ll n, k, tmp, m;
    cin>>n>>k;
    vector<ll> v;
    for(ll i=0; i<n; i++){
        cin>>tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());

    /*
    vector<ll> sub;
    for(unsigned ll i=0; i<v.size()-1; i++){
        sub.push_back(abs(v[i] - v[i+1]));
    }

    vector<ll> sub_p;
    for(unsigned ll i=0; i<sub.size()-1; i++){
        sub_p.push_back(sub[i] + sub[i+1]);
    }

    m = *min_element(sub_p.begin(), sub_p.end());
    cout<<m<<endl;
    */

    ll d = 10000000000;
    for(int i=0; i<n-k+1; ++i){
        d = min(d, v[i+k-1] - v[i]);
    }
    cout << d << endl;

    return 0;
}


Measured memory_bytes: 1400
class SEGTree:
    def __init__(self,n,fanction,unit):
        self.Unit=unit
        i=1<<(n.bit_length()-1)
        if i!=n:
            i*=2
        self.Fanction=fanction
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.Fanction(self.SEG[i*2+1],self.SEG[i*2+2])
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return self.Fanction(c1,c2)
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)

n,q=map(int,input().split())
SEG=SEGTree(n,min,2**31-1)
for _ in range(q):
    com,x,y=map(int,input().split())
    if com==0:
        SEG.update(x,y)
    else:
        print(SEG.get(x,y+1))


Measured memory_bytes: 8696
program sample
    implicit none
  
    integer(8) :: i,j,m,n
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)
    character(len=100000)::s
    character(len=1)::t
  
  
    read(*,*)s
    n=len_trim(s)
    m=0
    do i=1,n,2
        if (s(i:i)=='1')then
            m=m+1
        end if
    end do
    do i=2,n,2
        if (s(i:i)=='0')then
            m=m+1
        end if
    end do
    if (n-m<m)then
        m=n-m
    end if

    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 3172
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
    int N,i;
    int a[110];
    cin>>N;
    for(i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N,greater<int>());
    int A=0,B=0,j;
    for(j=0;j<N;j++){
        if(j%2==0)
        A+=a[j];
        if(j%2==1)
        B+=a[j];
    }
    cout<<A-B<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n,s;
int solve(int now,int sum,int num){
	if(num>n)return 0;
	int ans=0;
	
	for(int i=now+1;i<10;i++){	
		if(sum+i<s)ans+=solve(i,sum+i,num+1);
		else if(sum+i==s && num+1==n)return 1;
	}
	return ans;
}

int main(){
	while(cin>>n>>s && n+s){
		cout<<solve(-1,0,0)<<endl;
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	
	void main() {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				if(x == 0 && y == 0) break;
				
				System.out.println(Math.min(x, y) + " " + Math.max(x, y));
			} 
		}
		
	}

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

	}

}



Measured memory_bytes: 36124
#include<iostream>
#include<string>
using namespace std;
typedef long long int ll;

ll indexForNo(ll m){
    ll ret=m/3*4+m/5*4;
    int l=0;
    for(long p=1;p<=m;p*=10){
        l++;
        ll now;
        if(p*10>m)now=m;
        else now=p*10;
        ll last=p-1;
        ret+=((now-now/3-now/5+now/15)-(last-last/3-last/5+last/15))*l;
    }
    return ret;
}
int main(){
    ll n;
    cin>>n;
    ll left=0L,right=(1LL<<60);
    while(left<right-1){
        ll m=(left+right)/2;
        if(indexForNo(m)>=n)
            right=m;
        else left=m;
    }
    string ans="";
    for(ll i=left+1;i<left+30;i++){
        if(i%15==0)
            ans+="FizzBuzz";
        else if(i%3==0)
            ans+="Fizz";
        else if(i%5==0)
            ans+="Buzz";
        else
            ans+=to_string(i);
    }
    ll m=n-indexForNo(left)-1;
    for(ll i=m;i<m+20;i++)
        cout<<ans[i];
    cout<<endl;
    return 0;
}

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

#define INF INT_MAX/3

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define PB push_back
#define pb push_back

#define MP make_pair
#define mp make_pair
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>

#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define in scanf
#define out printf
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())

using namespace std;

int main() {
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;
}


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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  VI a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  rep(i, k) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var N = nextInt();
	if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
		myout("hon");
	}else if(N % 10 == 3){
		myout("bon");
	}else{
		myout("pon");
	}
}


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

using namespace std;

int main(int argc, char const *argv[])
{
  long long n,m,d;
  double t;
  cin >> n >> m >> d;
  if ( d == 0 )
  {
    t= n;
  }
  else if ( 2*d > n )
  {
    t = 2*(n-d);
  }
  else
  {
    t = 2*(n-2*d) + 2*d;
  }
  double ans = t / n;
  ans *= (m-1);
  ans /= n;
  printf("%.7f",ans);

}


Measured memory_bytes: 256
N, M, S, T = gets.split.map(&:to_i)
edges = M.times.map do
  u, v, a, b = gets.split.map(&:to_i)
  [u - 1, v - 1, a, b]
end
yen_graph = Array.new(N) { [] }
snuuk_graph = Array.new(N) { [] }
edges.each do |u, v, a, b|
  yen_graph[u].push([v, a])
  yen_graph[v].push([u, a])
  snuuk_graph[u].push([v, b])
  snuuk_graph[v].push([u, b])
end

def shortest_path(graph, s)
  w_list = Array.new(graph.size, 1 << 60)
  w_list[s] = 0
  queue = [[s, 0]]
  while !queue.empty?
    u, w = queue.shift
    next if w > w_list[u]
    graph[u].each do |(v, c)|
      if w_list[u] + c < w_list[v]
        new_cost = w_list[u] + c
        w_list[v] = new_cost
        queue.push([v, new_cost])
      end
    end
  end
  w_list
end

yen_cost = shortest_path(yen_graph, S - 1)
snuuk_cost = shortest_path(snuuk_graph, T - 1)
cost_list = N.times.map { |i| yen_cost[i] + snuuk_cost[i] }
FIRST_YEN = 10 ** 15
current_cost = 1 << 60
ans = Array.new(N)
(N - 1).downto(0) do |i|
  current_cost = current_cost > cost_list[i] ? cost_list[i] : current_cost
  ans[i] = FIRST_YEN - current_cost
end
ans.each do |a|
  puts a
end

Measured memory_bytes: 61800
#include <stdio.h>

int main()
{
  float a, b, c, d, e, f;
  double det, x, y;
  while (scanf("%f", &a) != EOF) {
    scanf("%f%f",       &b, &c);
    scanf("%f%f%f", &d, &e, &f);

    det = a * e - b * d;
    x = ( e * c - b * f) / det;
    y = (-d * c + a * f) / det;
    if (x == 0.0) x = 0.0; /* to avoid -0.000 */
    if (y == 0.0) y = 0.0;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > adj[100005],res;
int n,m,s[100005],dg[100005],visited[100005],dem;
void dfs(int u){
	visited[u]=1;
	s[u]+=dg[u];
	for(int i=0;i<adj[u].size();i++){
		int v=adj[u][i].first;
		if(!visited[v]){
			dfs(v);
			s[u]+=s[v];
			if(s[v]%2==1) swap(res[adj[u][i].second].first,res[adj[u][i].second].second);
		}
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		dg[u]++;
		adj[u].push_back(make_pair(v,i));
		adj[v].push_back(make_pair(u,i));
		res.push_back(make_pair(u,v));
	}
	for(int i=1;i<=n;i++){
		dg[i]%=2;
		if(dg[i]==1) dem++;
	}
	if(dem%2==1) printf("-1");
	else{
		dfs(1);
		for(int i=0;i<res.size();i++){
			printf("%d %d\n",res[i].first,res[i].second);
		}
	}
}

Measured memory_bytes: 15092
#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	size_t N;
	cin >> N;
	vector<int> h(N);
	vector<pair<int, int>> dp(N);
	for (auto& x : h) cin >> x;
	dp.at(1).first = abs(h.at(0) - h.at(1));
	dp.at(1).second = abs(h.at(0) - h.at(1));
	for (size_t i = 2; i < N; ++i) {
		dp.at(i).first = abs(h.at(i - 1) - h.at(i)) + min(dp.at(i - 1).first, dp.at(i - 1).second);
		dp.at(i).second = abs(h.at(i - 2) - h.at(i)) + min(dp.at(i - 2).first, dp.at(i - 2).second);
	}
	cout << min(dp.at(N - 1).first, dp.at(N - 1).second);
}

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

using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

const int MAXN=50;
const int MAXLEN=50;
int n;
string str;
map<char, int> common;

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

    cin >> str;
    for (auto c : str) {
        common[c]++;
    }
    
    FOR(i,n-1) {
        map<char, int> count;
        cin >> str;
        for (auto c : str)
            count[c]++;
        for (auto &p : common)
            p.second = min(p.second, count[p.first]);
    }

    for (auto p : common)
        FOR(i,p.second) printf("%c", p.first);
    printf("\n");
    
    return 0;
}


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

const int inf = 1e9;
const int N = 202;
int d[N][N];

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (i != j) d[i][j] = inf;

    vector< int> p(r);
    for (int &e : p) cin >> e;
        
    while (m--) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);


    sort(p.begin(), p.end());
    int best = inf;


    do {
        int cur = 0;
        for (int i = 0; i < r - 1; i++) cur += d[p[i]][p[i + 1]];
        best = min(best, cur);
    } while (next_permutation(p.begin(), p.end()));

    cout << best << endl;
}

Measured memory_bytes: 384
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[list(input().split()) for i in range(n)]
    x=input()
    cnt=0
    flag=False
    for s,t in l:
        if s==x:
            flag=True
        if s!=x and flag:
            cnt+=int(t)
    print(cnt)
resolve()

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

using namespace std;

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

int main(void)
{
  int n;
  while(cin >> n){
    if(!n) break;
    bool array[21][21] = {};
	
    for(int i = 0; i < n; i++){
      int a, b; cin >> a >> b;
      array[a][b] = true;
    }
    int x = 10;
    int y = 10;
    int m; cin >> m;
    for(int i = 0; i < m; i++){
      int num;
      char input;
      int h = 0;
      
      cin >> input >> num;

      if(input == 'N') h = 0;
      if(input == 'E') h = 1;
      if(input == 'S') h = 2;
      if(input == 'W') h = 3;
      
      for(int j = 0; j < num; j++){
	x += dx[h];
	y += dy[h];
	if(array[x][y] == true){
	  n--;
	  array[x][y] = false;
	}
      }
    }
    if(!n) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    ll sum=0;
    for (ll k=1; k<=N; ++k) sum+= (k*(N/k) * (1+N/k))/2; 
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int count = Integer.parseInt(sc.nextLine());
        int[] nums = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        System.out.println(Arrays.toString(nums).replaceAll("[\\[\\],]", ""));
        insertionSort(count, nums);
    }

    private static void insertionSort(int count, int[] nums) {
    	int j, v;
    	for (int i = 1; i < count; i++) {
    		v = nums[i];
    		j = i - 1;
    		while (j >= 0 && nums[j] > v) {
    			nums[j + 1] = nums[j];
    			j--;
    		}
    		nums[j + 1] = v;
    		System.out.println(Arrays.toString(nums).replaceAll("[\\[\\],]", ""));
    	}
    }

}


Measured memory_bytes: 34320
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

map<ll, int> prime_factor(ll n)
{
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L, R;
    cin >> L >> R;
    if (R - L + 1 >= 2019)
    {
        cout << 0 << endl;
    }
    else
    {
        ll ans = 2019;
        for (int l = L; l <= R; l++)
        {
            for (int r = l + 1; r <= R; r++)
            {
                ll a = l % 2019;
                ll b = r % 2019;
                ll res = a * b % 2019;
                chmin(ans, res);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<vector<int>> c(51,vector<int>(51,0));
int w,h;

void search(int x,int y){
	c[x][y] = 0;
	for(int i = -1; i <= 1; i++) {
		for(int j = -1; j <= 1; j++) {
			if (x + i >= 0 && x + i < h && y + j >= 0 && y + j < w && c[x + i][y + j] == 1){
				search(x + i,y + j);
			}
		}
	}
}

int main(){
	while (1) {
		cin>>w>>h;
		if (w == 0 && h == 0){
			break;
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				cin >> c[i][j];
			}	
		}
		int ans = 0;

	// for(int i = 0; i < h; i++) {
	// 	for(int j = 0; j < w; j++) {
	// 		cout << c[i][j];
	// 	}
	// 	cout << endl;
	// }
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if (c[i][j] == 1){
					search(i,j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000


int A[MAX],n;

int partition(int p, int r){
    int x,i,j,t;
    x = A[r];
    i = p-1;
    for(j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            t = A[i];A[i] = A[j];A[j] = t;
        }
    }
    t = A[i+1];A[i+1] = A[r];A[r] = t;
    return i+1;
}

int main(){
    int i,q;

    scanf("%d",&n);
    for(i = 0; i < n; i++) scanf("%d",&A[i]);
    
    q = partition(0,n-1);
    
    for(i = 0; i < n; i++){
        if(i) printf(" ");
        if(i == q) printf("[");
        printf("%d",A[i]);
        if(i == q) printf("]");
    }
    printf("\n");
    return 0;
}





Measured memory_bytes: 3476
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1e9;
using namespace std;

signed main() {
    string S; cin >> S;
    int cnt=0;
    rep(i,6){
        if(S[i]=='1') cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
	int n;
	char s[50]={'\0'};
	int i,ans=0;

	scanf("%d\n",&n);
	scanf("%s",s);
	for(i=0;i<n;i++){
		if(s[i]=='\0'||s[i+1]=='\0'||s[i+2]=='\0'){
			break;
		}
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}


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

using namespace std;
int n,k;
int a[100000+5];
int dp[100000+5];

int solve(int i)
{
    if(i==n-1) return 0;
    int &ret = dp[i];
    if(ret!=-1) return ret;

    ret =1e9;
    for(int j=1;j<=k;j++)
    {
        if(i+j<=n-1)
            ret = min(ret,solve(i+j)+abs(a[i+j]-a[i]));
    }
    return ret;
}

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

    memset(dp,-1,sizeof dp);

    int ans = solve(0);

    cout<<ans<<endl;
}


Measured memory_bytes: 5760
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n , m = tin()
	#s = input()
	
	path = [[] for _ in range(n)]
	for _ in range(m):
		a, b = tin()
		path[a-1].append(b-1)
		path[b-1].append(a-1)
		
	nn = [-1]*n
	st=1
	for i, p in enumerate(nn):
		if nn[i] != -1:
			continue
		nn[i]=st
		cc = st
		st += 1
		q = collections.deque()
		q.append(i)
		while q:
			pos = q.popleft()
			for np in path[pos]:
				if nn[np] == -1:
					q.append(np)
					nn[np]=cc
	return cc-1
			
		
		
	
	
	
#+++++
isTest=False

def pa(*vl):
	if not isTest:
		return
	for v in vl:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 82100
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (a.size())
#define int long long
#define SYNC ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define F first
#define S second
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x, y) cout << #x << " = " << x << " , " << #y << " = " << y << endl;
#define debug3(x, y, z) cout << #x << " = " << x << " , " << #y << " = " << y << " , " << #z << " = " << z << endl;
const int M = 1000000007;
const int N = 1e9 + 1;

signed main()
{
    int n , i , k ;
    cin>>n>>k;
    int a[n];
    if(k>=n) {
        cout<<0<<endl;
        return 0;
    }
    for(i=0 ; i<n ;i++)
    {
        cin>>a[i];
    }
    sort(a , a+n);
    int sum=0;
    for(i=0 ; i<n - k ; i++) sum+=a[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N;
  cin >> N;
  vector<vector<ll>> to(N);
  vector<vector<ll>> cost(N);
  ll a,b,c;
  rep(i,N-1){
    cin >> a >> b >> c;
    a--; b--;
    to[a].pb(b);
    to[b].pb(a);
    cost[a].pb(c);
    cost[b].pb(c);
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  vector<ll> d(N);
  rep(i,N) d[i] = -1;
  d[K] = 0;
  queue<ll> q;
  q.push(K);

  while(!q.empty()){
    int now = q.front(); q.pop();
    rep(i,(int)to[now].size()){
      if(d[to[now][i]]>=0) continue;
      q.push(to[now][i]);
      d[to[now][i]] = d[now] + cost[now][i];
    }
  }

  ll x,y;

  rep(i,Q){
    cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 15464
i, t;
p( n )
{
	for ( i = t = 2; i * i <= n; ++i )
	{
		n%i?:t++;
	}
	return t - 2;
}
main( l, s, u )
{
	for ( ; scanf("%d", &l ), u = l; )
	{
		for( ; p(l); l-- );
		for( ; p(u); u++ );
		printf( "%d\n",  u - l );
	}
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class395
    {
        static void Main()
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0], b = ab[1];
            if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
                Console.WriteLine("Possible");
            else
                Console.WriteLine("Impossible");
        }
    }
}


Measured memory_bytes: 28136
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  int q;
  cin >> str;
  cin >> q;
  while(q--){
    string s;
    cin >> s;
    if(s == "print"){
      int a, b;
      cin >> a >> b;
      cout << str.substr( a, b - a + 1) << endl;
    } else if(s == "reverse"){
      int a, b;
      cin >> a >> b;
      reverse( str.begin() + a, str.begin() + b + 1);
    } else {
      int a, b;
      string p;
      cin >> a >> b >> p;
      str.replace( a, b - a + 1, p);
    }
  }
}


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

int mp[101010];
const int MOD = 1e9+7;

ll modpow(ll n, ll p, ll m) {
    ll res = 1;
    while(p>0){
        if(p%2==1) res = (res * n) % m;
        n = (n * n) % m;
        p /= 2;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> A(n);
    rep(i,n) cin>>A[i];
    rep(i,n) mp[A[i]]++;
    // 偶数ならば1~n-1, 奇数ならば0+2~n-1
    if(n%2){
        if(mp[0] != 1){
            cout<<0<<endl;
            return 0;
        }
        for(int i=2; i<=n-1; i+=2){
            if(mp[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }else{
        for(int i=1;i<=n-1; i+=2){
            if(mp[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    cout<<modpow(2, n/2, MOD)<<endl;
    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    llint N;

    cin >> N;

    string ans = "";

    for(N --; N >= 0; N = N / 26 - 1){
        ans += (char) (N % 26) + 'a';
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

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



int main (){
int n,avg,i,j,k;
unsigned long long total;

while(cin>>n>>avg){
	unsigned long long a[2501][51]={0};
	unsigned long long c[2501][51]={0};
	int b[51]={0};
	total=0;
		
	for (i=0;i<n;i++){
		cin>>b[i];
	}
	
	for(i=0;i<n;i++){		
		for(j=1;j<n+1;j++){
			for(k=1;k<2501;k++){
				if(a[k][j]>0){
					
						c[k+b[i]][j+1]=a[k+b[i]][j+1]+a[k][j];
				//		cout <<"j "<<j+1<<endl;
				//		cout <<"k "<<k+b[i]<<endl;
				//		cout <<c[k+b[i]][j+1]<<endl;
				}
					
			}
		}
		c[b[i]][1]=a[b[i]][1]+1;
		
		for(j=1;j<n+1;j++){
			for(k=1;k<2501;k++){
				a[k][j]=c[k][j];
			}
		}
		
		
	}
	
	

/*	for(i=1;i<2;i++){
		for(j=0;j<n;j++)
		a[b[j]][i]++;
	}
	
	
	
	
	for(i=2;i<n+1;i++){
		for(j=0;j<n;j++){
			for(k=1;k<2501;k++){
//				if(a[k][i-1]>0)
//					a[k+b[j]][i]+=a[k][i-1];
			}
		}
	}
*/
	for(j=1;j<n+1;j++){
		for(k=1;k<2501;k++){
			if(k==j*avg){
				//cout <<"j "<<j<<endl;
//				cout <<"k "<<k<<endl;
				//cout <<a[k][j]<<endl;
				total += a[k][j];

			}
		}
	}
	cout <<total<<endl;
}

return 0;
	
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

#include <complex>

typedef complex<double> Point;
typedef vector<Point> Polygon;

static const double INF = 1e+10;

#define CURR(P, i) (P[i])
#define NEXT(P, i) (P[(i + 1) % P.size()])

struct Line : public vector<Point> {
  Line() {;}
  Line(Point a, Point b) { push_back(a); push_back(b); }
};

struct Circle {
  Point p;
  double r;
  Circle() {;}
  Circle(Point p, double r) : p(p), r(r) {;}
};

namespace std {
  bool operator<(const Point &lhs, const Point &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

inline double cross(const Point &a, const Point &b) {
  return imag(conj(a) * b);
}

inline double dot(const Point &a, const Point &b) {
  return real(conj(a) * b);
}

inline int ccw(Point a, Point b, Point c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0) { return 1; }
  if (cross(b, c) < 0) { return -1; }
  if (dot(b, c) < 0) { return 2; }
  if (norm(b) < norm(c)) { return -2; }
  return 0;
}


int n;
Polygon poly;
Point center;

int main() {
  while (scanf("%d", &n) > 0) {
    poly.clear();
    center = Point(0, 0);
    REP(i, n) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      poly.push_back(Point(x, y));
      center += Point(x, y);
    }
    center /= (double)n;
    REP(i, n) {
      Point vect = poly[i] - center;
      Point need = center - vect;
      REP(j, n) {
        if (abs(poly[j] - need) <= EPS) { goto ok; }
      }
      puts("NA");
      goto end;
ok:;
    }
    printf("%.10f %.10f\n", center.real(), center.imag());
end:;
  }
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#define long long long

using namespace std;

int n;
long x[50], y[50];
set<pair<long, long>> st;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        st.insert({x[i], y[i]});
    }

    int best = 1e9;
    if (n == 1) best = 1;
    for (int r = 0; r < n; ++r) {
        for (int s = 0; s < n; ++s) {
            if (r == s) continue;
            long p = x[s] - x[r];
            long q = y[s] - y[r];
            int res = n;
            for (int i = 0; i < n; ++i) {
                if (st.count({x[i]+p, y[i]+q})) res--;
            }
            best = min(best, res);
        }
    }
    cout << best << "\n";
}


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

using namespace std;

typedef long long LL;

int main(){
  int Q; cin >> Q;
  for(int i=0;i<Q;++i){
	int C, A, N;
	cin >> C >> A >> N;
	int ans = 0;
	for(int i=0;;++i){
	  int C_ = C - i*2, A_ = A - i;
	  if(C_ < 0 || A_ < 0) break;
	  for(int j=0;;++j){
		int C__ = C_ - 3*j;
		if(C__ < 0) break;
		ans = max(ans, i+j+min(C__,min(A_,N)));
	  }
	}
	cout << ans << endl;
  }
  

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w, h, n;
  cin >> w >> h >> n;
  int lx = 0, ly = 0, rx = w, uy = h;
  int x, y, a;
  for(int i=0;i<n;i++){
    cin >> x >> y >> a;
    switch(a){
      case 1: lx = max(lx, x);break;
      case 2: rx = min(rx, x);break;
      case 3: ly = max(ly, y);break;
      case 4: uy = min(uy, y);break;
    }
  }
  cout << ((rx-lx) > 0 && (uy-ly) > 0?(rx-lx)*(uy-ly):0)<< endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> H >> W;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	vector<string>r(H, string(W, '.'));
	vector<string>b(H, string(W, '.'));
	for (int i = 0; i < W; i++) {
		r[0][i] = '#';
		b.back()[i] = '#';
	}
	for (int i = 0; i < W; i++) {
		for (int j = 1; j < H - 1; j++) {
			if (i & 1)b[j][i] = '#';
			else r[j][i] = '#';
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				r[i][j] = '#';
				b[i][j] = '#';
			}
		}
	}
	for (auto i : r)cout << i << endl;
	cout << endl;
	for (auto i : b)cout << i << endl;
	return 0;
}

Measured memory_bytes: 1536
#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 FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int ans=0;
  int N;
  string num;
  cin >> N;
  num = to_string(N);
  if(num.length() == 6) ans = 9+900+90000;
  else if(num.length() == 5) ans = 9+900+N-9999;
  else if(num.length() == 4) ans = 9+900;
  else if(num.length() == 3) ans = 9+N-99;
  else if(num.length() == 2) ans = 9;
  else ans = N;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
const ll INF = 1e9+7;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    map<char,ll> m;
    for(auto i:s){
        m[i]++;
    }
    ll ans =-1+accumulate(m.begin(),m.end(),1,[INF](ll sum, pair<char,ll> i){
        return sum*(i.second+1)%INF;
    });
    cout << ans;
    return 0;
}

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

const int maxn=1e5+6;
int vis[maxn],c[maxn],cnt,ans;
int n,m;

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;++i) {
		int a;char s[4];
		scanf("%d",&a);
		scanf("%s",s);
		if(s[0]=='A'&&vis[a]==0) cnt++,ans+=c[a],vis[a]=1;
		else c[a]++;
	}
	printf("%d %d",cnt,ans);
}

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

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

	int a;
	string s;
	cin >> a >> s;

	if (a >= 3200)
		cout << s;
	else
		cout << "red";

	cout << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


ll forest_size=0;
vll a(1e5);
vll visited(1e5);
vvll edge(1e5);

void la(ll i, vll& v){
  if(visited[i])
    return;

  visited[i]=1;
  v.push_back(a[i]);
  for(auto e:edge[i]){
    la(e,v);
  }

  return;
}



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,m;
  cin>>n>>m;
  REP(i,n)cin>>a[i];
  vll x(m),y(m);
  REP(i,m)cin>>x[i]>>y[i];

  REP(i,m){
    edge[x[i]].push_back(y[i]);
    edge[y[i]].push_back(x[i]);
  }

  ll cost=0;
  vll p;
  REP(i,n){
    if(visited[i])
      continue;

    vll v;
    la(i,v);
    sort(ALL(v));

    cost+=v[0];
    for(ll i=1; i<ll(v.size()); i++)
      p.push_back(v[i]);

    forest_size++;
  }

  sort(ALL(p));

  if(n<(forest_size-1)*2){
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(forest_size==1){
    cout<<0<<endl;
    return 0;
  }

  REP(i,forest_size-2)
    cost+=p[i];


  cout<<cost<<endl;



}



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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, list) for(auto i : list)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define fi first
#define se second
#define mp make_pair

using namespace std;

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N, M; cin >> N >> M;
    ll ans = 0;
    vl x(N), y(N), z(N); REP(i, N) cin >> x[i] >> y[i] >> z[i];
    REP(i, 1 << 3)
    {
        vl v(N);
        REP(j, N)
        {
            v[j] += (i & 1) ? x[j] : -x[j];
            v[j] += (i & (1 << 1)) ? y[j] : -y[j];
            v[j] += (i & (1 << 2)) ? z[j] : -z[j];
        }
        sort(v.rbegin(), v.rend());
        ll tmp = 0;
        REP(j, M) tmp += v[j];
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(string, n);
	REP(i, n.size()) {
		if (n[i] == '1') n[i] = '9';
		else if (n[i] == '9') n[i] = '1';
	}

	OUT(n)BR;
  
  return 0;
}


Measured memory_bytes: 256
using System;
    using System.Text;
    class Program
    {
        static void Main(string[] args)
        {
            int rot = int.Parse(Console.ReadLine());
            string origin = Console.ReadLine();
            string ret = string.Empty;

            byte[] origin_byte = Encoding.ASCII.GetBytes(origin);
            byte[] newbyte = new byte[origin_byte.Length];

            for (int i = 0; i < origin_byte.Length; i++)
            {
                newbyte[i] = (byte)(origin_byte[i] + rot);
                if (newbyte[i] > 90)
                {
                    newbyte[i] = (byte)(newbyte[i] - 26);
                }
            }

            ret = Encoding.ASCII.GetString(newbyte);

            Console.WriteLine(ret);

        }
    }

Measured memory_bytes: 11164
#include<stdio.h>
int main()
{
	double a,b;
	while(scanf("%lf%lf",&a,&b)!=EOF){
		if(a<35.5&&b<71.0){
			printf("AAA\n");
		}else if(a<37.5&&b<77.0){
			printf("AA\n");
		}else if(a<40.0&&b<83.0){
			printf("A\n");
		}else if(a<43.0&&b<89.0){
			printf("B\n");
		}else if(a<50.0&&b<105.0){
			printf("C\n");
		}else if(a<55.0&&b<116.0){
			printf("D\n");
		}else if(a<70.0&&b<148.0){
			printf("E\n");
		}else{
			printf("NA\n");
		}
	}
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


const string YES = "YES";
const string NO = "NO";

void func(long long N, std::vector<long long> A){

    lli oneAct = (N+1)*N/2;
    vector<lli> b(N);
    lli sum = 0;
    REP(i,0,N){
        sum += A[i];
        b[i] = A[(i+1)%N] - A[i];
    }

    if(sum%oneAct != 0){
        cout<<NO<<endl;
        return;
    }

    lli cnt = 0;
    lli target = sum/oneAct;

    REP(i,0,N){
        LOG3(i,b[i],N);
        if((target-b[i])<0 || (target-b[i])%N != 0){
            cout<<NO<<endl;
            return;
        }
        cnt += (target-b[i])/N;
    }

    if(cnt != target){
        cout<<NO<<endl;
        return;
    }
    cout<<YES<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792