akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let mut v: Vec<f64> = (0..n).map(|_| read()).collect();
    v.sort_by(|a, b| a.partial_cmp(b).unwrap());
    let mut ans: f64 = (v[0] + v[1]) / 2.0;
    for i in 2..n{
        ans = (ans + v[i]) / 2.0;
    }
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
N = int(input())
E ={i:[] for i in range(N+1)}
for i in range(N-1):
  a,b,c = [int(x) for x in input().split()]
  E[a].append([b,c])
  E[b].append([a,c])
Q,K = [int(x) for x in input().split()]
cost= [0]*(N+1)
stk=[[K,-1,0]]
while stk:
  v,p,c = stk.pop()
  if cost[v]!=0:
    continue
  cost[v]=c
  for i,j in E[v]:
    if i!=p:
      stk.append([i,v,c+j])
for i in range(Q):
  a,b = [int(x) for x in input().split()]
  print(cost[a]+cost[b])

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s, t;
    cin >> s >> t;
    s += t;
    int ab = stoi(s);
    int tmp = sqrt(ab);
    if (tmp*tmp == ab) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#define SIZE 100

using namespace std;

int main()
{
    char s[SIZE][SIZE];
    int h, w;

    cin >> h >> w;

    for(int i = 1; i <= h; i++) { 
        for (int j = 1; j <= w; j++) {
            cin >> s[i][j];
        }
    }

    cout << endl;
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(s[i][j] == '#') {
                // cout << i << j << endl;
                if(s[i-1][j] != '#'
                && s[i+1][j] != '#'
                && s[i][j-1] != '#'
                && s[i][j+1] != '#') {
                    // cout << i << j << endl;
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

// start ~ end の範囲内に##が含まれているかチェック
bool check(string s, int start, int end) {
  for (int i = start; i + 1 <= end; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') return false;
  }
  return true;
}

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--, B--, C--, D--;
  string S;
  cin >> S;
  bool ok = true;
  // ##が含まれてたらNG
  if (!check(S, A, C) || !check(S, B, D)) ok = false;
  // C > D の場合
  // ...が含まれていればすぬけ君がふぬけ君を追い抜かせる
  if (C > D) {
    bool over = false;
    for (int i = B; i <= D; ++i) {
      if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
        over = true;
        break;
      }
    }
    ok = over;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a[i] = tmp-i-1;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    if (n%2){
        rep(i, n){
            ans += abs(a[i] - a[n/2]);
        }
    }else{
        rep(i, n){
            ans += abs(a[i] - a[n/2]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int n, d, x[100][100], i, j, k, cnt=0;
    double ans=0.0;
    cin >> n >> d;
    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            cin >> x[i][j];
        }
    }

    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            for(k=0;k<d;k++){
                ans=ans+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            ans=sqrt(ans);
            if(ceil(ans)==floor(ans)) cnt++;
            ans=0;
        }
    }

    cout << cnt <<endl;
            
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
char pattern[4] = { 'S', 'H', 'C', 'D' };//絵柄

void Pickup(int a[4][13], int n)
{
    for(int i=1;i<=n;i++)
    {
        int x;
    	char op;
    	
    	scanf(" %c%d",&op,&x);
    	if(op==pattern[0])
    		a[0][x-1]=1;
    	else if(op==pattern[1])
    		a[1][x-1]=1;
    	else if(op==pattern[2])
    		a[2][x-1]=1;
    	else
    		a[3][x-1]=1;
    }
}
void Shortage(int a[4][13], int n)
{
    int i,j;
    for(int i=0;i<4;i++)
    {
		for(int j=0;j<13;j++)
		{
			if(a[i][j]==0)
			{
				if(i==0)
				{
				    printf("%c %d\n",pattern[0],j+1);
				}
				else if(i==1)
				{
				    printf("%c %d\n",pattern[1],j+1);
				}
				else if(i==2)
				{
				    printf("%c %d\n",pattern[2],j+1);
				}
				else
				{
				    printf("%c %d\n",pattern[3],j+1);
				}
			}
		}
    }
}

int main(void)
{
    int a[4][13]={};
	int n;//枚数
	scanf("%d",&n);
	Pickup(a, n);
	Shortage(a,n);
	return 0;
}



Measured memory_bytes: 2040
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef tuple<int, int, string> e;
const int MN =50;
string dp[MN][MN*12];
bool used[MN][MN*12];

bool solve() {
    int n,m,s,g;
    cin >> n >> m >> s >> g;
    vector<e> edge;
    if (!n) return false;
    for (int i = 0; i < m; i++) {
        int a, b;
        string d;
        cin >> a >> b >> d;
        edge.push_back(e(a, b, d));
    }
    fill_n(dp[0], MN*MN*12, "");
    fill_n(used[0], MN*MN*12, false);
    used[s][0] = true;
    for (int i = 1; i < MN*12; i++) {
        for (e ee: edge) {
            int a, b;
            string d;
            tie(a, b, d) = ee;
            int u = d.size();
            if (i < u) continue;
            if (used[a][i-u]) {
                if (used[b][i]) {
                    dp[b][i] = min(dp[b][i], dp[a][i-u]+d);
                } else {
                    used[b][i] = true;
                    dp[b][i] = dp[a][i-u]+d;
                }
            }
        }
    }
    string res;
    bool f = false;
    for (int i = 1; i < MN*6; i++) {
        if (used[g][i]) {
            if (f) {
                res = min(res, dp[g][i]);
            } else {
                f = true;
                res = dp[g][i];
            }
        }
    }
    if (!f) {
        cout << "NO" << endl;
        return true;
    }
    string res2 = res;
    for (int i = MN*6; i < MN*12; i++) {
        if (used[g][i]) {
            res2 = min(res2, dp[g][i]);
        }
    }
    if (res != res2) {
        cout << "NO" << endl;
        return true;
    }
    cout << res << endl;
    return true;
}

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

Measured memory_bytes: 13508
def bfs(ini, g, goal)
  dist = Array.new(g.length,-1)
  dist[ini] = 0
  queue = [ini]
  while !queue.empty?
    v = queue[0]
    queue.shift
    g[v].each{|des|
      if dist[des] == -1
        dist[des] = dist[v] + 1
        queue.push(des)
      end
     }
   end
   dist[goal]
end
h,w = gets.chomp.split(" ").map(&:to_i)
wall = "##"
for i in 0..w-1
  wall += "#"
end
s = Array.new(h+2, wall)
1.upto(h) do |i|
  s[i] = "#" + gets.chomp + "#"
end
v = h * w
g = Array.new(v).map{Array.new}
for i in 1..h
  for j in 1..w
    if s[i][j] == "."
      if s[i-1][j] == "."
        g[(i-1)*w+(j-1)].push((i-2)*w+(j-1))
      end
      if s[i][j-1] == "."
        g[(i-1)*w+(j-1)].push((i-1)*w+(j-2))
      end
      if s[i][j+1] == "."
        g[(i-1)*w+(j-1)].push((i-1)*w+j)
      end
      if s[i+1][j] == "."
        g[(i-1)*w+(j-1)].push(i*w+(j-1))
      end
    end
  end
end
cnt = 0
h.times do |i|
  w.times do |j|
    cnt += 1 if s[i+1][j+1] == "."
  end
end
d = bfs(0,g,(h-1)*w+w-1)
puts cnt - d - 1 if d != -1
puts -1 if d == -1

Measured memory_bytes: 14756
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	string s;
	cin >> s;
	int count=0;
	int count1=0;
	int count2=0;
/*
	rep(i,0,s.size()-1){
		if(s[i] != s[i+1]){
			count1++;
			}else{
				break;
			}
	}
	rel(i,s.size,1){
		if(s[i] != s[i-1]){
			count2++;
		}else{
			break;
		}
	}
	*/
	//if(count1 > count2){
		rep(i,0,s.size()-1){
			if(s[i] == s[i+1]){
				count++;
				if(s[i+1] == '1'){
					s[i+1] = '0';
				}else{
					s[i+1] = '1';
				}
			}
		}
	/*
	}else{
		rel(i,s.size(),1){
			if(s[i] == s[i-1]){
				count++;
				if(s[i-1] == '1'){
					s[i-1] = '0';
				}else{
					s[i-1] = '1';
				}
			}
		}
	}
	*/
	cout << count << endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""   

x = int(input())

if x <= 6:
    print("1")
elif x <= 11:
    print("2")
else:
    a = x // 11
    b = x % 11
    if b == 0:
        print(2*a)
    elif b > 6:
        print(2*a+2)
    else:
        print(2*a+1)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d[51],sum=0;
	cin>>n;
	for(int i=0;i<n;i++) cin>>d[i];
	for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) sum+=d[i]*d[j];
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int ans = 0;
        if(x<600){ ans = 8; }
        else if(x<800){ ans = 7; }
        else if(x<1000){ ans = 6; }
        else if(x<1200){ ans = 5; }
        else if(x<1400){ ans = 4; }
        else if(x<1600){ ans = 3; }
        else if(x<1800){ ans = 2; }
        else if(x<2000){ ans = 1; }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35684
/*
  ***
  0.0
  *-*
 * * *
*  *  *
*  *  *
   *
   *
  * *
 *   *
 *   *
 	   	  		*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define F first
#define S second
// set <int> :: iterator it = x.begin(); it != x.end(); it ++
using namespace std;
string n;ll sum,num,maxi=-10e9,maxn=-10e9,mini=10e9,minn=10e9;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();	cout.tie();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	if(n.size()==1){
		cout<<n;
		return 0;
	}
	for(int i = n.size()-1;i > 0;i--){
		if(n[i]=='9'){
		}
		else{
		if(sum==1){
			n[i]='8';
			n[i-1]--;
		}
		if(i-1==0){
			if(n[i-1]>1){
				n[i-1]--;
				n[i]='9';
			}
			else{
				num=1;
				n[i]='9';
			}
		}
		else{
			if(n[i-1]>0){
				n[i]='9';
				n[i-1]--;
			}
			else{
				n[i]='9';
				sum=1;
			}
		}
		}
	}
	sum=0;
	for(int i = num;i < n.size();i++){
		sum+=n[i]-48;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int w;
	while(1){
		scanf("%d",&w);
		if(w==-1)
			break;
		if(w<=10)
		w=1150;
		else if(w<=20)
			w=1150+(w-10)*125;
		else if(w<=30)
			w=1150+10*125+(w-20)*140;
		else
			w=1150+10*125+10*140+(w-30)*160;
		printf("%d\n",4280-w);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;

	cin >> n;

	int A[n];
	int q;
	int com, b, e;
	int answer = 0;

	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	cin >> q;

	for (int j = 0; j < q; j++) {
		cin >> com >> b >> e;
		
		//min
		if (com == 0) { 
		    answer = 1000000000;
			for (int k = b; k < e; k++) {
				if (answer > A[k])
					answer = A[k];
			}
		}
		//max
		else {
		    answer = -1000000000;
			for (int k = b; k < e; k++) {
				if (answer < A[k])
					answer = A[k];
			}
		}

		cout << answer << endl;
	}


}




Measured memory_bytes: 3124
#include <stdio.h>          // printf(), scanf()
#include <ctype.h>          // isdigit()

#define min(a, b) ((a) < (b) ? a : b)
#define max(a, b) ((a) > (b) ? a : b)

int
main(int argc, char** argv)
{
	int r;
	int n, i;
	int c;

	int maxv = -1000000000;
	int minv = 0;
	
	n = 0;
	c = getc(stdin);
	while (isdigit(c))
	{
		n = n * 10 + c - '0';
		c = getc(stdin);
	}

	while (!isdigit(c) && c != EOF)
		c = getc(stdin);

	minv = 0;
	while (isdigit(c))
	{
		minv = minv * 10 + c - '0';
		c = getc(stdin);
	}

	for (i = 1; i < n; ++i)
	{
		while (!isdigit(c) && c != EOF)
			c = getc(stdin);

		r = 0;
		while (isdigit(c))
		{
			r = r * 10 + c - '0';
			c = getc(stdin);
		}

		maxv = max(maxv, r - minv);
		minv = min(minv, r);
	}

	printf("%d\n", maxv);
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;

int main(){
    int n;
    cin>>n;
    while(n--){
        string s;
        int out=0,score=0,base=0;
        while(out<3){
            cin>>s;
            if(s=="HIT"){
                base++;
                if(base>3){
                    score+=base%3;
                    base-=base%3;
                }
            }
            if(s=="HOMERUN"){
                score+=base+1;
                base=0;
            }
            if(s=="OUT"){
                out++;
            }
        }
        cout<<score<<endl;;
        
    }
}

Measured memory_bytes: 1212
(defstruct queue (entrance nil) (exit nil))
(defun enqueue (item queue)
  (let ((cell (list item)))
    (if (queue-entrance queue)
        (setf (cdr (queue-entrance queue)) cell)
        (setf (queue-exit queue) cell))
    (setf (queue-entrance queue) cell)))
(defun dequeue (queue)
  (when (queue-exit queue)
    (prog1 (pop (queue-exit queue))
      (unless (queue-exit queue)
        (setf (queue-entrance queue) nil)))))

(let ((k (read))
      (q (make-queue)))
  (loop :for i :from 1 :to 9
        :do (enqueue i q))
  (loop :for i :from 1 :to (1- k)
        :for x := (dequeue q)
        :if (/= 0 (mod x 10))
        :do (enqueue (+ (* 10 x) (mod x 10) -1) q)
        :do (enqueue (+ (* 10 x) (mod x 10)) q)
        :if (/= 9 (mod x 10))
        :do (enqueue (+ (* 10 x) (mod x 10) 1) q))
  (format t "~A~%" (dequeue q)))


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

using namespace std;

long long getgcd(long long n, long long m)
{
  int r;
 
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
  return n;
}

int main(){

  long long N,K;
  cin >> N >> K;
  long long a;
  vector <long long> b;
  for(int i = 0;i<N;i++){
    cin >> a;
    b.push_back(a);
  }

  sort(b.begin(),b.end());
  long long gcd = 0,k = 2;
  gcd = getgcd(b[0],b[1]);
  while(gcd != 1){
    if(k >= b.size())
      break;
    gcd = getgcd(gcd,b[k]);
    k++;
  }

  if(gcd == 1 ||(b.size() == 1 && b[0] == K))
    cout << "POSSIBLE" << endl;
  else if(K%gcd == 0 && b[b.size()-1] >= K){
    cout << "POSSIBLE" << endl;
  }
  else
    cout << "IMPOSSIBLE" << endl;
  

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}

ll g = 1000000000000000000;

int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i;
	ll n;
	cin>>n;
	ll ans=1;
	ll flag =0;
	ll flagi=0;
	ll k;
	for(i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		if(a==0)
		{
			flag =2;
			flagi = 1;
		}
		if(flagi==0)
		 k = g/ans;

		ans = ans*a;
		if(a>k)
		{
			flag =1;
			ans =-2;
		}

		

	}

	if(flag==0)
		cout<<ans<<endl;
	else if(flagi==1)
		cout<<0<<endl;
	else 
		cout<<-1<<endl;


	
	

	
	


	
	return 0;
		}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <int> cnt1(n,0), cnt2(n,0), cnt3(n,0);
	rep0(i,n){
		if(s[i]=='R') cnt1[i]++;
		if(s[i]=='G') cnt2[i]++;
		if(s[i]=='B') cnt3[i]++;
		if(i){
			cnt1[i] += cnt1[i-1];
			cnt2[i] += cnt2[i-1];
			cnt3[i] += cnt3[i-1];
		}
	}

	ll ans = 0;
	rep0(i,n){
		for(int k=i+2;k<n;k++){
			if(s[i]!=s[k]){
				if(s[i]=='R' && s[k]=='G'){
					ans += cnt3[k] - cnt3[i];
					if((i+k)%2==0 && s[(i+k)/2]=='B') ans--;
				}
				if(s[i]=='R' && s[k]=='B'){
					ans += cnt2[k] - cnt2[i];
					if((i+k)%2==0 && s[(i+k)/2]=='G') ans--;
				}
				if(s[i]=='G' && s[k]=='B'){
					ans += cnt1[k] - cnt1[i];
					if((i+k)%2==0 && s[(i+k)/2]=='R') ans--;
				}
				if(s[i]=='G' && s[k]=='R'){
					ans += cnt3[k] - cnt3[i];
					if((i+k)%2==0 && s[(i+k)/2]=='B') ans--;
				}
				if(s[i]=='B' && s[k]=='R'){
					ans += cnt2[k] - cnt2[i];
					if((i+k)%2==0 && s[(i+k)/2]=='G') ans--;
				}
				if(s[i]=='B' && s[k]=='G'){
					ans += cnt1[k] - cnt1[i];
					if((i+k)%2==0 && s[(i+k)/2]=='R') ans--;
				}
			}
		}
		// cout << ans << " ";
	}
	cout << ans;

	return;
}

int main(){

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

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3892
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
const int N = 10001;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n + 1], dp[n + 1];
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        dp[1] = 0;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + abs (a[i] - a[i - 1]);
            if (i > 2) {
                dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
            }
        }
        cout << dp[n] << endl;


    }
    return 0;

}






Measured memory_bytes: 5160
n, kk = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

# nxnの行列積


def matrix_product(A, B):
    res = [[0] * n for _ in range(n)]
    for i in range(n):
        for k in range(n):
            for j in range(n):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res


def matrix_exponents(A, t):
    res = [[0] * n for _ in range(n)]
    for i in range(n):
        res[i][i] = 1

    while t:
        if t & 1 == 1:
            res = matrix_product(res, A)
        A = matrix_product(A, A)
        t //= 2
    return res


temp = matrix_exponents(AA, kk)


ans = 0
for i in range(n):
    for j in range(n):
        ans += temp[i][j]
        ans %= mod
print(ans)


Measured memory_bytes: 41324
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int H;
int W;
int K;
char A[1145][1145];
int mind[1145][1145];

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

pii st;
const int INF = 0x3fffffff;
using Pair = pair<int, pii>;
priority_queue<Pair, vector<Pair>, greater<Pair>> que;

bool WithinRange(int y, int x) {
  if (y < 0 || H <= y) return false;
  if (x < 0 || W <= x) return false;
  return true;
}

int main() {
  scanf("%d%d%d", &H, &W, &K);
  fill(mind[0], mind[H], INF);
  rep(i, H) {
    rep(j, W) {
      scanf(" %c", &A[i][j]);
      if (A[i][j] == 'S') {
        st = pii(i, j);
        mind[i][j] = 0;
      }
    }
  }

  que.push(Pair(0, st));

  int ans = INF;
  while (!que.empty()) {
    auto p = que.top(); que.pop();
    int cost = p.first;
    int y, x;
    tie(y, x) = p.second;
    if (mind[y][x] < cost) continue;

    rep(i, 4) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (!WithinRange(ny, nx)) {
        continue;
      }

      int use = cost;
      if (A[ny][nx] == '#') use = max(use, K);

      if (mind[ny][nx] > use+1) {
        mind[ny][nx] = use+1;
        que.push(Pair(mind[ny][nx], pii(ny, nx)));
      }
    }
  }

  rep(i, H) {
    ans = min(ans, mind[i][0]);
    ans = min(ans, mind[i][W-1]);
  }

  rep(i, W) {
    ans = min(ans, mind[0][i]);
    ans = min(ans, mind[H-1][i]);
  }

  printf("%d\n", 1 + (ans-1)/K);
}


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

typedef long long ll;
//#define int ll
#define db(x) cout<<#x<<" = "<<x<<"\n";
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ALL(a) a.begin(),a.end()
#define mset(a,b) memset(a,b,sizeof(a));


main() 
{
	FIN;
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	int ans=0;
	sort(arr,arr+n);
	for(int i=0;i<k;i++)
    ans=ans+arr[i];
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#n = int(input())
x1, y1, x2, y2 = map(int,input().split())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split())) for i in range(n)]
#ls = [input() for i in range(n)]
X = (x2 - x1)
Y = (y2 - y1)

print(x2-Y, y2+X, x1-Y, y1+X)


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

int n,m,d[5010],v[5010][210],st[210][5010];
LL sum[5010],Ans;

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<n;i++)
		scanf("%d",&d[i]);
	for (i=1;i<=n;i++)
	for (j=1;j<=m;j++)
		scanf("%d",&v[i][j]);

	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
//			printf("j=%d\n",j);
			int last=0;
			while (st[j][0]&&v[i][j]>=v[st[j][st[j][0]]][j])
			{
				sum[st[j][st[j][0]]]-=v[st[j][st[j][0]]][j]-last;
//				printf("*sum[%d]-=%d\n",st[j][st[j][0]],v[st[j][st[j][0]]][j]-last);
				last=v[st[j][st[j][0]]][j];
				st[j][0]--;
			}
			sum[i]+=v[i][j];
//			printf("sum[%d]+=%d\n",i,v[i][j]);
			if (st[j][0])
			{
				sum[st[j][st[j][0]]]-=v[i][j]-last;
//				printf("#sum[%d]-=%d\n",st[j][st[j][0]],v[i][j]-last);
			}
			st[j][++st[j][0]]=i;
		}

//		printf("i=%d :\n",i);
//		for (j=1;j<=i;j++)
//			printf("%lld ",sum[j]);
//		puts("");
//		puts("");

		LL tmp=0;
		for (j=i;j>=1;j--)
		{
			tmp+=sum[j];
			Ans=max(Ans,tmp);
		}
		sum[i]-=d[i];
	}
	printf("%lld\n",Ans);

}


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

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

	System.out.println(a[n2]-a[n2-1]);


	}}

Measured memory_bytes: 50480
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
//const ll MOD = 1e9+7;
const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

struct Edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

const ll MAX_V = 1000000;
ll V;
vector<Edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            Edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/if.hpp>

ll Main() {
    cin >> V;
    ll E;
    cin >> E;
    for (ll i=0; i<E; ++i) {
        ll from, to;
        cin >> from >> to;
        from--;
        to--;
        Edge e = {to, 1};
        G[from].push_back(e);
        Edge e2 = {from, 1};
        G[to].push_back(e2);
    }
    
    dijkstra(0);
    for (ll i=0; i<V; ++i) {
        if(d[i] == INF) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (ll i=1; i<V; ++i) {
        //        cout << "0から" << i << "までのコスト: " << d[i] << endl;
        
        if (d[i]== 1) {
            cout << 1 << endl;
        } else {
            ll mi = INF;
            ll nowTo = 0;
            for(auto n: G[i]) {
                if (d[n.to] <= mi) {
                    mi = d[n.to];
                    nowTo = n.to;
                }
            }

            cout << nowTo+1 << endl;
        }
    }
    return 0;
}

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


Measured memory_bytes: 39764
# -*- coding: utf-8 -*-


def main():
    x = nums =0
    dic = {'I': 1, 'D': -1}
    for i in s:
        x += dic[i]
        nums = max(x, nums)
    print(nums)


if __name__ == '__main__':
    n = int(input())
    s = input()
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int n;
vll len(3);
int ans = INF;
vector<pll> now(4, pll(0, 0)); // (sum_len, num)
void dfs(int depth, vll &t) {
  if (depth < n) {
    rep(i, 4) {
      now[i].first += t[depth];
      now[i].second += 1;

      dfs(depth + 1, t);

      now[i].first -= t[depth];
      now[i].second -= 1;
    }
  }else {
    int mp = 0;
    rep(i, 3) {
      if (now[i].second == 0) return;
      mp += abs(len[i] - now[i].first) + 10 * (now[i].second -1);
    }
    ans = min(ans, mp);
  }
}

int main() {
  cin >> n;
  rep(i, 3) cin >> len[i];
  vll t(n); rep(i, n) cin >> t[i];
  dfs(0, t);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int N = 200000 + 10;
int a[N], b[N];

int main() {
    int n;  cin >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i];
    sort(a + 1, a + 1 + n, [&](int a, int b) {
        return a > b;
    });
    long long ans = 0;
    for (int i = 1; i <= n / 2; i++) {
        ans += a[i] << 1;
    }
    if (n & 1)  ans += a[n / 2 + 1] - a[1];
    else    ans -= a[1];
    cout << ans;
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

Measured memory_bytes: 4428
#include <stdio.h>
#include <stdlib.h>

#define M 256

typedef struct Node {
  int x;
  struct Node *prev;
  struct Node *next;
} Node;

Node *head, *tail;

void dump();
void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();



int main(int argc, char **argv) {

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

  int i;
  int x;
  char buf[M];
  char tmp[M];
  for (i = 0; i < n; ++i) {
    fgets(buf, 256, stdin);

    if (buf[0] == 'i' || buf[6] == ' ') {
      sscanf(buf, "%s %d", tmp, &x);

      if (buf[0] == 'i') insert(x);
      else               delete(x);
    } else if (buf[6] == 'F') {
      deleteFirst();
    } else if (buf[6] == 'L') {
      deleteLast();
    }
  }

  dump();

  return 0;
}

void dump() {
  int l = 0;
  Node *p = head;
  while (p != NULL) {
    if (l == 0)  printf("%d",  p->x);
    else printf(" %d", p->x);
    ++l;
    p = p->next;
  }
  printf("\n");
}

void insert(int x) {
  Node *nod = malloc(sizeof(Node));
  
  nod->x = x;
  nod->prev = NULL;
  nod->next = NULL;

  if (head == NULL) {
    head = nod;
    tail = nod;
  }
  else {
    nod->next = head;
    head->prev = nod;
    head = nod;
  }
}

void delete(int x) {
  Node *p = head;
  int flg = 0;

  while (flg == 0 && p != NULL) {
    if (p->x == x) {
      Node *c = p;
      if (c->prev != NULL) {
        p->prev->next = c->next;
      }
      else {
        head = c->next;
      }

      if (c->next != NULL) {
        p->next->prev = c->prev;
      }
      else {
        tail = c->prev;
      }
      flg = 1;
    }
    else {
      p = p->next;
    }
  }
}

void deleteFirst() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  }
  else if (head != NULL) {
    if (head->next != NULL) head->next->prev = NULL;
    head = head->next;
  }
}

void deleteLast() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  }
  else if (tail != NULL) {
    if (tail->prev != NULL) {
      tail->prev->next = NULL;
    }
    tail = tail->prev;
  }
}



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

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;

inline bool isRange(pii &p1) {
  return 0 <= p1.first && p1.first <= 5000 && 0 <= p1.second && p1.second <= 5000;
}

inline double dis(pii &p1, pii &p2) {
  double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second);
  return sqrt(a * a + b * b);
}

bool exist[5005][5005] = {false};

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

  int n;

  while (cin >> n, n) {
    pii ps[3005];
    fill(exist[0], exist[5005], false);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      ps[i] = pii(x, y);
      exist[x][y] = true;
    }
    sort(ps, ps + n);

    int res = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
	if (i == j) continue;
	for (int k = -1; k < 2; k += 2) {
	  int dx = k * abs(ps[i].second - ps[j].second), dy = k * abs(ps[i].first - ps[j].first);
	  pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy), pii(ps[j].first + dx, ps[j].second + dy)};

	  if (!isRange(temp[0]) || !isRange(temp[1]) || !exist[temp[0].first][temp[0].second] || !exist[temp[1].first][temp[1].second]) continue;

	  double seg = dis(ps[i], ps[j]);
	  res = max(res, (long long) (seg * seg + 0.00000001));
	}
      }
    }

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 25704
#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> vec(n);
    rep(i, n) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    int d = vec[n-1] - vec[0];
    vector<int> sum(d+1);
    int p = vec[0];
    rep(i, sum.size()) {
        rep(j, n) {
            sum[i] += pow((vec[j] - p), 2);
        }
        p++;
    }
    sort(sum.begin(), sum.end());
    cout << sum[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[5000][5000];

ll topdown(ll *arr,ll l,ll r)
{
    if(l>r)
    {
        dp[l][r]=0;
        return 0;
    }
    if(dp[l][r]!=-1)
    {
        return dp[l][r];
    }
    ll op1=arr[l]+min(topdown(arr,l+1,r-1),topdown(arr,l+2,r));
    ll op2=arr[r]+min(topdown(arr,l,r-2),topdown(arr,l+1,r-1));
    dp[l][r]=max(op1,op2);
    return dp[l][r];
}

int main()
{
    ll n=0,sum=0;
    cin>>n;
    ll *arr= new ll[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<2*topdown(arr,0,n-1)-sum;
    return 0;
}

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

int main(){
  int N,R,T,p[101],A[1001],B[1001]={},ans=0;

  cin>>N>>R>>T;
  for(int i = 0;i<N;i++)cin>>p[i];

  for(int i = 1;i<=T;i++){
    for(int j=0;j<R;j++)A[j]=0;
    for(int j=0;j<N;j++)A[(p[j]*i)%R]++;
    for(int j=0;j<R;j++){
      if(i==1)ans+=A[j];
      else {
	if(B[j]<A[j]){
	  ans+=A[j]-B[j];
	  B[j]=A[j];
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<stdio.h>
#include<vector>
using namespace std;

int main(){
  int X,A;
  cin >> X >> A;

  if(X < A){
    cout << "0" << endl;
  }else if(A <= X){
    cout << "10" << endl;
  }

  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
#define sz(a) a.size()
#define lb lower_bound
#define up upper_bound
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	vector<ll> vl(n);
	for(int i=0;i<n;i++)	cin>>vl[i];
	sort(all(vl));
	ll ans = 0;
	for(int i=0;i<k;i++)
		ans+=vl[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    vector<P> vec(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        vec[i] = {a, b};
    }
    sort(vec.begin(), vec.end());

    ll ans = 1;
    ll cnt_max = 0;
    for (ll i = 0; i < n - 1; i++) {
        for (ll j = i + 1; j < n; j++) {
            P tei_v = {vec[j].fi - vec[i].fi, vec[j].se - vec[i].se};
            ll cnt = 0;
            for (ll k = 0; k < n - 1; k++) {
                for (ll l = k + 1; l < n; l++) {
                    if (tei_v == make_pair(vec[l].fi - vec[k].fi,
                                           vec[l].se - vec[k].se)) {
                        cnt++;
                    }
                }
            }
            chmax(cnt_max, cnt);
        }
    }

    cout << n - cnt_max << endl;
    return 0;
}

Measured memory_bytes: 3572
N, W = map(int, input().split())

from collections import defaultdict

dp = defaultdict(lambda: float('inf'))

dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv+v] = min(dp[nv+v], nw+w)

print(max(dp))

Measured memory_bytes: 76764
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
struct Cycle
{
  int n;
  struct edge
  {
    int from, to;
  };
  vector<vector<edge>> es;
  Cycle(int n) : n(n)
  {
    es.resize(n);
  }
  void add(int u, int t)
  {
    es[u].push_back(edge{u, t});
  }
  bool dfs(int u, int dep, int &first, vector<int> &visit)
  {
    visit[u] = dep;
    for (auto s : es[u])
    {
      if (visit[s.to] >= 0)
      {
        first = s.to;
        return true;
      }
      if (dfs(s.to, dep + 1, first, visit))
        return true;
    }
    visit[u] = -1;
    return false;
  }
  vector<int> find_cycle(int u)
  {
    vector<int> visit(n, -1);
    int first = -1;
    vector<int> ans;
    if (dfs(u, 0, first, visit))
    {
      int dep = *max_element(visit.begin(), visit.end());
      map<int, int> m;
      rep(i, n) m[visit[i]] = i;
      assert(first >= 0);
      for (int i = visit[first]; i <= dep; i++)
      {
        ans.push_back(m[i]);
      }
    }
    return ans;
  }
};

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B)
{
  rep(i, M) A[i]--, B[i]--;
  Cycle cy(N);
  rep(i, M) cy.add(A[i], B[i]);
  rep(l, N)
  {
    auto cycle = cy.find_cycle(l);
    if (cycle.empty())
    {
      continue;
    }
    bool upd = false;
    do
    {
      set<int> in_cycle;
      for (auto s : cycle)
        in_cycle.insert(s);
      set<pair<int, int>> idx;
      map<int, int> cyc;
      rep(i, cycle.size()) cyc[cycle[i]] = i;
      upd = false;
      rep(i, M)
      {
        if (in_cycle.count(A[i]) &&
            in_cycle.count(B[i]))
        {
          if ((cyc[A[i]] + 1) % cycle.size() != cyc[B[i]])
          {
            upd = true;
            decltype(cycle) newCycle;
            for (int j = cyc[B[i]]; j != cyc[A[i]]; j = (j + 1) % cycle.size())
              newCycle.push_back(cycle[j]);
            newCycle.push_back(A[i]);
            cycle = newCycle;
            upd = true;
            break;
          }
        }
      }
    } while (upd);
    cout << cycle.size() << endl;
    for (auto s : cycle)
    {
      cout << s + 1 << endl;
    }
    return;
  }
  cout << -1 << endl;
}

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

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int N=(int)1e5+5;

int grundy[N];

int calculateMex(unordered_set<int> Set) 
{ 
    int Mex = 0; 
  
    while (Set.find(Mex) != Set.end()) 
        Mex++; 
  
    return (Mex); 
} 

int a[105];

int main(int argc, char const *argv[])
{
	crap;
	rep(i,N)
		grundy[i]=-1;

	int n,k;
	cin>>n>>k;

	in1(a,n);

	// sort(a+1,a+n+1);

	grundy[0]=0;

	f(i,1,k)
	{
		unordered_set<int> Set;
		f(j,1,n)
		{	
			if (i-a[j]>=0)
			{
				Set.insert(grundy[i-a[j]]);
			}
		}

		grundy[i]=calculateMex(Set);
	}

	// rep(i,100+1)
	// 	cout<<i<<" "<<grundy[i]<<endl;

	int who;
	int val=grundy[k];
	if (val)
		cout<<"First\n";
	else
		cout<<"Second\n";

	return 0;
}

Measured memory_bytes: 640
let () =
  try
    while true do
      let s = Scanf.scanf "%d %d %d %d " (fun a b c d -> [a; b; c; d]) in
      let t = Scanf.scanf "%d %d %d %d " (fun a b c d -> [a; b; c; d]) in
      let h = List.fold_left2 (fun acc a b -> acc + if a = b then 1 else 0) 0 s t in
      List.fold_left (fun b a -> b + if List.mem a t then 1 else 0) 0 s - h
      |> Printf.printf "%d %d\n" h
    done
  with _ -> ()

Measured memory_bytes: 2224
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	x := readInt()
	y := readInt()
	z := readInt()
	nx := x - z
	println(nx / (y + z))
}


Measured memory_bytes: 640
#include <iostream>

int main(int argc, char **argv)
{
    std::string T;

    std::cin >> T;

    for(int i = 0; i < T.size(); i++){
        if(T.at(i) == '?'){
            T.at(i) = 'D';
        }
    }
    std::cout << T << std::endl;
}


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

int main(void)
{
  int n;
  cin>>n;
  vector<int>w(n);
  int sum1=0,sum2=0;
  int minn;
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=0;j<=i;j++){
      sum1+=w[j];
    }
    for(int a=i+1;a<n;a++){
      sum2+=w[a];
    }
    if(i==0)
      minn=abs(sum1-sum2);
    else if(minn>abs(sum1-sum2))
      minn=abs(sum1-sum2);
    sum1=0;
    sum2=0;
  }
    cout<<minn<<endl;
}


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

#define ll long long
const ll N = 998244353;
const ll MAX = 100000000000;

int main()
{
ios_base::sync_with_stdio(false);
int R;
cin>>R;
if (R<1200) {cout<<"ABC"; return 0;}
if (R<2800) {cout<<"ARC"; return 0;}
cout<<"AGC";
}

Measured memory_bytes: 256
#include <stdio.h>

// 10 5 1
// N Y/1000

int main()
{
	int n, y;
	scanf("%d %d", &n, &y);
	y /= 1000;

	int a = 0;
	for(;a<=y/10;a++)
	{
		if((y-n-9*a)>=0 && (5*n-y+5*a)>=0)
			if((y-n-9*a)%4==0 &&(5*n-y+5*a)%4==0)
			{
				int b = (y-n-9*a)/4;
				int c = (5*n-y+5*a)/4;
				printf("%d %d %d\n", a, b, c);
				break;
			}
	}
	if(a>y/10)
		printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;

int main(int argc, char const *argv[]) {
	int a, b;
	while (cin >> a >> b) {
		int sum = a + b;
		int res = 0;
		while (sum > 0) {
			sum /= 10;
			res++;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
package main

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


type Node struct {
	val int
	parent *Node
	child []*Node
}

type DisjointSet map[int]*Node

func (ds DisjointSet)makeSet( value int) {
	ds[value] = &Node{value, nil, nil}
}

func (ds DisjointSet)findSet (value int) *Node{
	//fmt.Println(value)
	node := ds[value]
	for {
		if node.parent == nil || node.parent.val == node.val{
			return node
		}
		// fmt.Printf("node:%v, parent:%v\n", node.val, node.parent.val)
		node = node.parent
	}
}

func (ds DisjointSet) unite(x int, y int) {
	ds.findSet(x).parent = ds.findSet(y)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	ds := DisjointSet{}

	for i := 0; i < n; i++ {
		ds.makeSet(i)
	}

	for i := 0; i < q; i++{
		sc.Scan()
		query := sc.Text()
		sc.Scan()
		val1, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		val2, _ := strconv.Atoi(sc.Text())

		switch query {
		case "0":
			// unite
			//fmt.Printf("unite:%v, %v\n", val1, val2)
			ds.unite(val1,val2)
 		case "1":
			//fmt.Printf("find:%v, %v\n", val1, val2)
			if ds.findSet(val1) == ds.findSet(val2) {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}



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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    double r; cin >> r;
    cout << 2.0 * r * M_PI << endl;
    return 0;
}


Measured memory_bytes: 3804