akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"math"
	"sort"
)

type Num struct {
	Num int
}

type Nums []Num

func (n Nums) Len() int {
	return len(n)
}

func (n Nums) Swap(i, j int) {
	n[i], n[j] = n[j], n[i]
}

func (n Nums) Less(i, j int) bool {
	return n[i].Num < n[j].Num
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)
	sort.Sort(nums)
	max := nums[n-1].Num
	min := nums[0].Num
	minDistance := abs((max - min) - min)
	for i := 0; i < n-1; i++ {
		num := nums[i].Num
		distance := abs((max - num) - num)
		if minDistance > distance {
			min = num
			minDistance = distance
		}
	}
	fmt.Println(fmt.Sprintf("%d %d", max, min))
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func scanNums(len int) (nums Nums) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, Num{Num: num})
	}
	return
}


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

int main() {
	int l, r, d;
  	cin >> l >> r >> d;
  
  	int cnt = 0;
  	for (int i=l; i<=r; i++) {
      if (i%d==0) cnt++;
    }

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

Measured memory_bytes: 3628
n = int(input())
ans = []
while(n > 0):
    x = n %  26
    n = n // 26
    if(x == 0):
        x = 26
        n -= 1
    ans.append(chr(x + ord('a') -1))
    # print(x,n)
ans.reverse()
print("".join(ans))


Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >    vecll;
typedef vector<string > vecstr;
int main()
{
  ll  n, x;
  cin >> n >> x;
  vecll a(n,0);
  REP(i,n) cin >> a[i];
  ll ans = 0;
  if(a[0] > x){
    ans += a[0] - x;
    a[0] = x;
  }
  REP(i, n - 1){
    if(a[i] + a[i + 1] > x){
      ans += a[i + 1] + a[i] - x;
      a[i + 1] = x - a[i];
    }
  }
  cout << ans << endl;
} 

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

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

	int INF=1<<28;
	double EPS=1e-12;

	int n;
	double[] xs, ys, ls;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			xs=new double[n];
			ys=new double[n];
			ls=new double[n];
			for(int i=0; i<n; i++){
				xs[i]=sc.nextInt();
				ys[i]=sc.nextInt();
				ls[i]=sc.nextInt();
			}
			solve();
		}
	}

	double max;

	void solve(){
		max=0;
		// 1点
		for(int i=0; i<n; i++){
			update(xs[i], ys[i]);
		}
		// 2点
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				double[] pin=pin(i, j);
				update(pin[0], pin[1]);
			}
		}
		// 3点
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				for(int k=j+1; k<n; k++){
					// debug(i,j,k);
					double[] pin1=pin(i, j);
					double[] pin2=pin(j, k);
					// debug(i, j, pin1, j, k, pin2);
					double px1=pin1[0];
					double py1=pin1[1];
					double px2=px1+(ys[j]-ys[i]);
					double py2=py1-(xs[j]-xs[i]);

					double qx1=pin2[0];
					double qy1=pin2[1];
					double qx2=qx1+(ys[k]-ys[j]);
					double qy2=qy1-(xs[k]-xs[j]);

					double[] cross=cross(px1, py1, px2, py2, qx1, qy1, qx2, qy2);
					// debug(cross);
					update(cross[0], cross[1]);
				}
			}
		}
		// debug(max);
		println(String.format("%.20f", max));
	}

	double[] cross(double px1, double py1, double px2, double py2, double qx1,
			double qy1, double qx2, double qy2){
		// debug(px1, py1, px2, py2, qx1, qy1, qx2, qy2);
		double det=det(qx2-qx1, qy2-qy1, px2-px1, py2-py1);
		if(abs(det)<EPS){
			return new double[]{0, 0};
		}
		double det2=det(qx2-qx1, qy2-qy1, qx1-px1, qy1-py1);
		double x=px1+(px2-px1)*det2/det;
		double y=py1+(py2-py1)*det2/det;
		return new double[]{x, y};
	}

	double det(double x1, double y1, double x2, double y2){
		return x1*y2-x2*y1;
	}

	double[] pin(int i, int j){
		double ratio=(1+(sq(ls[i])-sq(ls[j]))
				/sq(hypot(xs[i]-xs[j], ys[i]-ys[j])))/2.0;
		// debug("pin", i, j, ratio);
		double x=xs[i]+(xs[j]-xs[i])*ratio;
		double y=ys[i]+(ys[j]-ys[i])*ratio;
		return new double[]{x, y};
	}

	void update(double x, double y){
		double min=Double.MAX_VALUE;
		for(int i=0; i<n; i++){
			min=min(min, sqrt(max(sq(ls[i])-sq(hypot(xs[i]-x, ys[i]-y)), 0)));
		}
		// debug(x, y, min);
		max=max(max, min);
	}

	double sq(double x){
		return x*x;
	}

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

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 35720
#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;
   if(n % 2 == 0){
      cout << n << endl;
   }else{
      cout << n * 2 << endl;
   }

   return 0;
}

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

int main(){

	string a, b, c;
	cin >> a >> b >> c;
	string ans = "YES";
	reverse(a.begin(), a.end());
	if(a[0] != b[0]) ans ="NO";
	reverse(b.begin(), b.end());
	if(b[0] != c[0]) ans ="NO";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use std::collections::{HashMap, HashSet, VecDeque};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, // ノード数
        edges: [(usize1, usize1, usize); n-1], // usize1 は 1-origin to 0-origin変換を行う
    }

    let mut edgemap = HashMap::new();

    for (n0, n1, l) in edges {
        edgemap.entry(n0).or_insert(vec![]).push((n1, l));
        edgemap.entry(n1).or_insert(vec![]).push((n0, l));
    }

    let mut visit = HashSet::new();
    let mut q = VecDeque::new();
    let mut ans = Vec::new();
    ans.resize(n, true);

    q.push_back((0, true));

    while q.len() > 0 {
        let (n, color) = q.pop_front().unwrap();
        visit.insert(n);
        ans[n] = color;
        let nexts = edgemap.get(&n).unwrap();
        for &(nx, l) in nexts {
            if !visit.contains(&nx) {
                let new_color = if l % 2 == 0 { color } else { !color };
                q.push_back((nx, new_color));
            }
        }
    }

    for i in 0..n {
        println!("{}", if ans[i] { 0 } else { 1 });
    }
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

signed main()
{
  int n, m, a;
  
  while (cin >> n >> m >> a, (n + m + a) != 0){
    vector<pair<int, pair<int, int>>> vpi;
    rep(i, m){
      int h = in(), p = in(), q = in();
      vpi.pb(mp(h, mp(p, q)));
    }
    sort(all(vpi), greater<pair<int, pair<int, int>>>());
    int rank = INF;
    for (auto l : vpi){
      if (rank == l.fst) continue;
      auto line = l.sec;
      if (a == line.fst) a = line.sec, rank = l.fst;
      else if (a == line.sec) a = line.fst, rank = l.fst;
    }
    print(a);
  }

  return (0);
}

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

bool isNum(char x){
	return '0' <= x and x<='9';
}

int main(){
  int a,b; cin >> a >> b;
  string s; cin >> s;
  string ans="Yes";
  for(int i=0;i<s.length();i++){
  	if(i==a){
    	if(s[i]=='-') continue;
       else ans="No";
    }
    else{
      if(isNum(s[i])) continue;
      else ans="No";    
    }
  }
  cout << ans << endl;
 return 0;
  
}


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

int main()
{
  int deg[101];
  int vertices = 0, i, j;
  memset(deg, 0, sizeof(deg));
  while ((cin >> i >> j), !cin.eof())
  {
    if (i && j)
    {
      deg[i]++;
      deg[j]++;
      vertices = max(vertices, max(i, j));
    }
    else
    {
      for (i = 1; i <= vertices; i++)
	if (deg[i] % 2) j++;
      cout << (j == 2 ? "OK": "NG") << endl;
      memset(deg, 0, sizeof(deg));
      vertices = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, l;
    cin >> n >> l;
    int64_t res = n*(n-1+2*l)/2;
    if(0 <= l){
        res -= l;
    }else if(l+n-1 <= 0){
        res -= (l + n - 1);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
MOD = 998244353

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

dp = [[0] * (S + 1) for i in range(N)]
dp[0][0] = 2
if A[0] < S + 1:
	dp[0][A[0]] = 1

for i in range(1, N):
	for j in range(S + 1):
		dp[i][j] = (2 * dp[i - 1][j]) % MOD
		if 0 <= j - A[i] <= S:
			dp[i][j] = (dp[i][j] + dp[i - 1][j - A[i]]) % MOD
print(dp[-1][-1])

Measured memory_bytes: 135288
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<unordered_set>
using namespace std;

typedef long long ll;

#define FOR(i,N) for(int i=0;i<N;i++)

int mod=1e9+7;



int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int>b;
    int i;
    for(i=n;i>0;i-=2){
        b.push_back(a[i-1]);
    }
    if(i==0){
        i=1;
    } else {
        i=2;
    }
    for(;i<n;i+=2){
        b.push_back(a[i-1]);
    }
    for(auto x:b){
        cout<<x<<" ";
    }
    cout<<endl;
}


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

int main()
{
  int a, b;
  std::cin >> a >> b;
  
  if (a < b)
  {
    std::cout << 2 * b - 1 << std::endl;
  }
  else if (a == b)
  {
    std::cout << 2 * a << std::endl;
  }
  else
  {
    std::cout << 2 * a - 1<< std::endl;
  }
  
  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/


const long long mod = 1e+7 ;
const int N = 1e5+5;
const double PI=acos(-1);


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i,l,m) for(ll i=l;i<m;i++)
#define frr(i,l,m) for(int i=l;i>m;i--)
# define vii vector<int>
#define vll vector<ll>
#define vpr vector<pair<ll,ll> >
#define dbg(x) cout << #x << " is " << x << endl;
#define gcd(l,r) __gcd(l,r)
#define cd complex<double>
#define vcd vector<cd>
#define clr(x) memset(x,0,sizeof(x))
/*
pow(2,20)->1e6;
pow(2,30)->1e9;
stoll - string to ll;
string with space getline(cin, str);
*/
ll pwr(ll x,ll y, ll m);
ll mult(ll a,ll b,ll m);

////
int a[N],dp[N];
///
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);

int n;
cin>>n;
fr(i,1,n+1){cin>>a[i];}

dp[n]=0;
dp[n-1]=abs(a[n]-a[n-1]);
frr(i,n-2,0)
{
   dp[i]=min(dp[i+1]+abs(a[i+1]-a[i]),dp[i+2]+abs(a[i+2]-a[i]));
}
cout<<dp[1]<<endl;

return 0;

 }
 ////
 ////

ll pwr(ll x,ll y,ll m)
{ll ans=1;x=x%m;while(y){if(y&1)ans=(x*(ans%m))%m;x=(x*x)%m;y>>=1;}
return ans%mod;}
////
////
ll mult(ll x,ll y, ll m){
    ll ans=0;
    while(y){if(y&1)ans=(ans+x)%m;
x=(x+x)%m;
y>>=1;}
return ans%m;}


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


void solve(long long N){

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string N;
    cin >> N;
    char n = N[N.length()-1];

    char hon[]  = {'2', '4', '5', '7', '9'};
    char pon[] = {'0', '1', '6', '8'};
    char bon = '3';
    
    for(int i = 0; i < 5; i++) {
        if(hon[i] == n) {
            cout << "hon" << endl;
            return 0;
        }
    }
    for(int i = 0; i < 4; i++) {
        if(pon[i] == n) { 
            cout << "pon" << endl;
            return 0;
        }
    }
    cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	int t=(1<<n);
	if(k==0){
		rep(i,t){
			if(i==t-1) cout << i << " " << i << endl;
			else cout << i << " " << i << " ";
		}
	}
	else if(k>=t || n==1) cout << -1 << endl;
	else{
		vector<int> a((t<<1));
		a.at(0)=0;
		a.at(1)=k;
		a.at(2)=0;
		int i=3,m=1;
		while(m<t){
			if(m==k){
				m++;
				if(m==t) break;
			}
			a.at(i)=m;
			m++;
			i++;
		}
		m--;
		a.at(i)=k;
		i++;
		while(m>0){
			if(m==k){
				m--;
				if(m==0) break;
			}
			a.at(i)=m;
			m--;
			i++;
		}
		rep(j,(t<<1)){
			if(j==(t<<1)-1) cout << a.at(j) << endl;
			else cout << a.at(j) << " ";
		}
	}
}


Measured memory_bytes: 2816
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	long long a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if ((a * b * c) % 2 == 0) cout << 0 << endl;
	else {
		cout << min(a*b, min(b*c, c*a)) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll n,d;
  cin>>n>>d;

  int ans=0;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    if(x*x+y*y<=d*d) ans++;
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=35000;
const int Mod=1e9+7;
struct gao{   int A,B;   }Edge[MAXN];
int Ans,End,n,m,Two[MAXN]={1},A[MAXN],B[MAXN],F[3][MAXN];
int main()
{   scanf("%d%d",&n,&m),End=(1<<n)-1;
	for(rg int i=1;i<=m;i++) scanf("%d%d",&Edge[i].A,&Edge[i].B);
	for(rg int i=1;i<=m;i++) Two[i]=(Two[i-1]<<1)%Mod;
	for(rg int i=1;i<=End;i++)
		for(rg int j=1;j<=m;j++)
		{	if((i&(1<<(Edge[j].A-1)))&&(i&(1<<(Edge[j].B-1)))) A[i]++;
			if((i&(1<<(Edge[j].A-1)))||(i&(1<<(Edge[j].B-1)))) B[i]++;
		}
	for(rg int S=1;S<=End;S++)
	{   F[1][S]=Two[A[S]]*(S&1),F[2][S]=Two[A[S]]*(S>>1&1);
		for(rg int T=(S-1)&S;T;T=(T-1)&S)
		{	if(T&1) F[1][S]=(F[1][S]-1ll*F[1][T]*Two[A[S^T]])%Mod;
			if(T&2) F[2][S]=(F[2][S]-1ll*F[2][T]*Two[A[S^T]])%Mod;
		}
	}
	for(rg int S=1;S<=End;S++)
		for(rg int T=(End^S);T;T=(T-1)&(End^S))
		{   if(A[S]+A[T]!=A[S|T]||~S&1||~T&2) continue ;
			Ans=(Ans-1ll*F[1][S]*F[2][T]%Mod*Two[A[End^S^T]])%Mod;
		}
	printf("%lld\n",(1ll*Ans+Two[m]+Mod)%Mod);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N - 1);
	int ans = 0;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		ans += B[i];
	}
	for (int i = 0; i < N-1; i++) cin >> C[i];

	for (int i = 0; i < N-1; i++) {
		if (A[i + 1] - A[i] == 1) ans += C[A[i]-1];
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		long[] An = new long[N];
		for(int i = 0; i < N; i++) An[i] = in.nextLong() - (i + 1);
		
		Arrays.sort(An);
		long b = An[N / 2];
		long sum = 0;
		for(int i = 0; i < N; i++) sum += Math.abs(An[i] - b);
		System.out.println(sum);
	}
}


Measured memory_bytes: 89988
#include <bits/stdc++.h>
using namespace std;
int a[26];
int main()
{
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  for (int i = 0; i < s.size(); i++)
    a[s[i] - 'a']++;
  for (int i = 0; i < 26; i++)
  {
    if (a[i] == 0)
    {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**8)
N = int(input())
a = [[] for i in range(N)]
for i in range(N-1):
  A, B, C = map(int, input().split())
  a[A-1].append([B-1, C])
  a[B-1].append([A-1, C])
dist = [-1]*N
Q, K = map(int, input().split())
dist[K-1] = 0

def dfs(now):
  for i, dis_e in a[now]:
    if dist[i] == -1:
      dist[i] = dist[now] + dis_e
      dfs(i)

def main():
  dfs(K-1)
  ans = []
  for i in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])
  #print(*ans, sep = "\n")

if __name__ == "__main__":
  main()

Measured memory_bytes: 137884
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}
const ll mod = 998244353;

ll powmod(ll x,ll n){
    if(n == 0)return 1;
    if(n%2)return x*powmod(x*x%mod,n/2)%mod;
    return powmod(x*x%mod,n/2)%mod;
}
ll frac[200020],ifrac[200020];
ll conbi(ll n,ll k){return ((frac[n]*ifrac[n-k]%mod)*ifrac[k]%mod+mod)%mod;}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    rep(i,200020)i == 0 ? frac[i] = 1:frac[i] = frac[i-1]*i%mod;
    rep(i,200020)ifrac[i] = powmod(frac[i],mod-2);
    ll n,m,k; cin >> n >> m >> k;
    ll ans = 0;
    rep(i,k+1){
        ll num = n-i;
        ans += ((m * powmod(m-1,num-1))%mod * conbi(n-1,i))%mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6800
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[5];
	cin>>s+1;
	if(s[1]=='S'&&s[2]=='U') cout<<7<<endl;
	if(s[1]=='S'&&s[2]=='A') cout<<1<<endl;
	if(s[1]=='F'&&s[2]=='R') cout<<2<<endl;
	if(s[1]=='T'&&s[2]=='H') cout<<3<<endl;
	if(s[1]=='W'&&s[2]=='E') cout<<4<<endl;
	if(s[1]=='T'&&s[2]=='U') cout<<5<<endl;
	if(s[1]=='M'&&s[2]=='O') cout<<6<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
const int maxn=1000000+10;
int gcd[maxn],maxSum=0;
int GCD(int a,int b){
   if(b==0) return a;
   return GCD(b,a%b);
}
void slide(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
           gcd[i]++;
           while(x%i==0) x/=i;
        }
    }
    if(x>1) gcd[x]++;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int gc=m;
    for(int i=2;i<=n;i++)
    {
        cin>>m;
        maxSum=max(maxSum,m);
        gc=GCD(gc,m);
        slide(m);
    }
    if(gc==1)
    {
        for(int i=2;i<=maxSum;i++)
        {
            if(gcd[i]>1)
            {
                cout<<"setwise coprime"<<endl;
                return 0;
            }
        }
        cout<<"pairwise coprime"<<endl;
                return 0;
    }
    cout<<"not coprime"<<endl;
    return 0;
}


Measured memory_bytes: 6932
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int n,k,x,y,kk,ans=0;
signed main()
{
	scanf("%lld%lld",&n,&k);n++;
	if(k>=n){printf("1\n");exit(0);}
	for(k;k<=n;k++)
	{
		x=(0+k-1)*k/2;
		y=(n-k+n-1)*k/2;
		ans+=y-x+1;
		ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin >> n >> k;
  
  vector<ll> h;
  h.resize(n);
  for(int i = 0; i < n;i++){
    cin >> h[i];
  }

  sort(h.begin(),h.end());

  if(n-k>0){
  h.resize(n-k);
  }else{
    cout << 0 << endl;
    return 0;
  }

  ll sum = 0;
  for(int i = 0; i < h.size(); i++){
    sum += h[i];
  }

  cout << sum << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        var syusseki_no_key = new int[n];
        var syusseki_no_value = new int[n];
        for (int i = 0; i < n; i++)
        {
            syusseki_no_key[i] = i + 1;
            syusseki_no_value[i] = sc.nextInt();
        }

        Array.Sort(syusseki_no_value, syusseki_no_key);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < n; i++)
        {
            Console.Write(syusseki_no_key[i]);
            if (i == n - 1) Console.Write("\n");
            else Console.Write(" ");
        }
        Console.Out.Flush();
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 23800
import sys
N = int(input())
A = tuple(map(int, input().split()))
count = [0] * (10 ** 5 + 1)

for a in A:
    count[a] += 1
s = sum(A)

Q = int(input())
for _ in range(Q):
    b, c = map(int, sys.stdin.readline().split())
    s -= count[b] * b
    s += count[b] * c
    count[c] += count[b]
    count[b] = 0
    print(s)

Measured memory_bytes: 20860
from collections import deque
n = int(input())
lst1 = list(map(int,input().split()))

p = sum(lst1)

b = deque([])

for i in range(n):
    if i%2 == 0:
        b.appendleft(lst1[i])
    else:
        b.append(lst1[i])

if n%2==0:
    b.reverse()
    print(*b)
else:
    print(*b)

Measured memory_bytes: 99000
#include <iostream>
#include <stdlib.h>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, m;
llint dp[100005];
bool used[100005];

int main(void)
{	
	cin >> n >> m;
	int x;
	for(int i = 1; i <= m; i++){
		cin >> x;
		used[x] = true;
	}
	
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		if(i+1 <= n && !used[i+1]) dp[i+1] += dp[i], dp[i+1] %= mod;
		if(i+2 <= n && !used[i+2]) dp[i+2] += dp[i], dp[i+2] %= mod;
	}
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1152
def examA():
    S = SI()
    N = len(S)
    if N<26:
        d = defaultdict(bool)
        for s in S:
            d[s] = True
        for a in alphabet:
            if not d[a]:
                ans = S + a
                print(ans)
                return
    keep = []
    for i in range(N-1)[::-1]:
        keep.append(S[i+1])
        if S[i]<S[i+1]:
            break
    #print(keep)
    n = len(keep)
    c = "zz"
    for s in keep:
        if s>S[(N-n-1)]:
            c = min(c,s)
    if c=="zz":
        print(-1)
        return
    ans = S[:(N-n-1)] + c
    print(ans)
    return

def examB():
    N = I()
    ans = [2*(i+1) for i in range(N)]
    if N%2==0:
        for i in range(4998):
            ans[-3-i] = 3+i*6

    print(" ".join(map(str,ans)))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

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

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array
#define del 1e-8

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 998244353;
const int N=100005;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
    string s;
    cin>>s;
    if(s[s.size()-1]=='s')s+="es";
    else s+="s";
    cout<<s;

    }
	return 0;
}


Measured memory_bytes: 3640
Module _20190526

    Sub Main()
        'https://atcoder.jp/contests/abc128/tasks/abc128_a

        Dim sRead As String = Console.ReadLine()

        Dim iApple As Integer = sRead.Split(" ")(0)
        Dim iPart As Integer = sRead.Split(" ")(1)

        Dim iAll As Integer = iApple * 3 + iPart

    Console.WriteLine(iAll \ 2)

    End Sub

End Module


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

int N=1e5+100;
int mod=1e9+7;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    char s;cin>>s;
    if(s>='A'&&s<='Z') cout<<'A'<<endl;
    else cout<<'a'<<endl;
    return 0;
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long X;
    scanf("%lld",&X);
    if(X>=1800){
        cout << 1 << endl;
    }else if(X>=1600){
        cout << 2 << endl;
    }else if(X>=1400){
        cout << 3 << endl;
    }else if(X>=1200){
        cout << 4 << endl;
    }else if(X>=1000){
        cout << 5 << endl;
    }else if(X>=800){
        cout << 6 << endl;
    }else if(X>=600){
        cout << 7 << endl;
    }else if(X>=400){
        cout << 8 << endl;
    }
    return 0;
}


Measured memory_bytes: 3796
n, m = list(map(int,input().split()))
array = [list(map(int,input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
array_2 = [[0 for i in range(m)] for j in range(n)]

for i in range(n):
    d = 0
    for j in range(m):
        c = array[i][j]*b[j]
        d += c
    print(d)

Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long floor_sum(long long n, long long m, long long a, long long b) {
	long long ans = 0;
	if (a >= m) {
		ans += (n - 1) * n * (a / m) / 2;
		a %= m;
	}
	if (b >= m) {
		ans += n * (b / m);
		b %= m;
	}

	long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
	if (y_max == 0) return ans;
	ans += (n - (x_max + a - 1) / a) * y_max;
	ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
	return ans;
}

void solve() {
	int t; cin >> t;
	while (t--) {
		ll n, m, a, b; cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << endl;
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}


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

int n;
int b[110];
int sum = 0;

int main() {
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        cin >> b[i];
    }
    sum += b[0];
    for (int i = 1; i < n-1; ++i) {
        sum += min(b[i], b[i-1]);
    }
    sum += b[n-2];
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int arr[][] = new int[3000][2];
		int i = 0, temp = 0, count = 0;
		for (i = 0; i < 3000; i ++) {
			arr[i][0] = stdin.nextInt();
			arr[i][1] = stdin.nextInt();
			if (arr[i][0] > arr[i][1]) {
				temp = arr[i][0];
				arr[i][0] = arr[i][1];
				arr[i][1] = temp;
			}
			if (arr[i][0] == 0 && arr[i][1] == 0) {
				count = i;
				break;
			}
		}
		for (int j = 0; j < count; j++) {
			System.out.println(arr[j][0] + " " + arr[j][1]);
		}
	}
}

Measured memory_bytes: 36040
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}

Measured memory_bytes: 35676
#include <bits/stdc++.h>
#define vll vector< ll >
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <b; i++)
#define pii pair<ll,ll> 
#define v(a) vector<a>
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define ll long long
 
using namespace std;
//using ll = long long;
 
/*template<typename T>inline void in(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
 template<typename T>inline void out(T n){if(n<0){outchar('-');n*=-1;}char snum[65];ll i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
ll pr[M+1],freq[M+1];
ll fact[M+1],inv[M+1];*/
ll md=MD;
ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
//ll chose(ll n,ll k){ll r=fact[n]%md;r=(r+md)%md;r=r*inv[k]%md;r=(r+md)%md;r=r*inv[n-k]%md;r=(r+md)%md;return r;}
bool isPrime(ll n)
 {
    if (n == 1) {
        return false;
    }
    ll i= 2;
    while (i*i <= n) {
        if (n % i == 0) {
             return false;
        }
        i += 1;
    }
    return true;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
long long  C(long long n, long long k) {
    double res = 1;
    for (int i = 1; i <= k; ++i)
        res = res * (n - k + i) / i;
    return (int)(res + 0.01);
}
long long  get_pisano_period(long long m)
 {
    long long a = 0, b = 1, c = a + b;
    for (long long i = 0; i < m * m; i++) {
        c = (a + b) % m;
        a = b;
        b = c;
        if (a == 0 && b == 1) 
		return i + 1;
    }
}

int main() 
{  
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
   cin>>a[i];
  int ans=a[0]^a[1];
  for(int i=2;i<n;i++)
     ans=ans^a[i];
     vector<int>v;
	 for(int i=0;i<n;i++)
	   {
	   	v.push_back(ans^a[i]);
			}
			for(int i=0;i<v.size();i++)
			  cout<<v[i]<<" ";
			  cout<<endl;	 
			return 0;
   
   return 0;
 }

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 200005;

LL n , k;
LL ara[N];
int vis[N];
/*
5 3
2 3 4 5 2
*/
int main()
{
//    #ifdef VAMP
//        clock_t tStart = clock();
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
//    #endif
    cin >> n >> k;
    FOR(i,1,n)cin >> ara[i];
    vis[1] = 1;

    LL pos = 1,done = 0;
    vector<LL>nodes;
    LL source;
    while(1){
        LL go = ara[pos];
        done++;
        if(done == k){
            cout << go << "\n";
            return 0;
        }

        if(vis[go]){
            source = go;
            break;
        }
        vis[go] = vis[pos] + 1;
        pos = go;
    }
    k = k - (vis[source] - 1);

    LL node = source;
    while(ara[node] != source){
        nodes.push_back(node);
        node = ara[node];
    }
    nodes.push_back(node);

    k = k % nodes.size();
    cout << nodes[k] << "\n";
//    #ifdef VAMP
//        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
//    #endif
}


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

vector<int> nums, odd;
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	if (m == 1)
	{
		int x; scanf("%d", &x);
		printf("%d\n", x);
		if (x == 1) printf("1\n%d\n", x);
		else printf("2\n%d %d\n", 1, x-1);
		return 0;
	}
	for (int i = 0;i < m;i++)
	{
		int x; scanf("%d", &x);
		if (x&1) odd.push_back(x);
		else nums.push_back(x);
	}
	if (odd.size() > 2)
	{
		printf("Impossible\n");
		return 0;
	}
	if (odd.size() >= 1)
	{
		nums.push_back(odd.back()); odd.pop_back();
	}
	if (odd.size() >= 1)
	{
		nums.insert(nums.begin(), odd.back()); odd.pop_back();
	}
	for (unsigned i = 0;i < nums.size();i++)
	{
		if (i) printf(" ");
		printf("%d", nums[i]);
	}
	nums[0]++; nums.back()--;
	if (nums.back() == 0) nums.pop_back();
	printf("\n%d\n", nums.size());
	for (unsigned i = 0;i < nums.size();i++)
	{
		if (i) printf(" ");
		printf("%d", nums[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
//Problem: DP_D From Educational DP Contest
//Progress: Working
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

const ll maxN = 1e5 + 11;
const ll INF = 999999999;

ll n, w;

ll aw[maxN], av[maxN];
ll dp[101][maxN];

void init(){
	memset(dp, 0, sizeof(dp));
}

ll solve(ll i, ll j){
	if(dp[i][j] != 0)
		return dp[i][j];
	if(j <= 0 || i >= n)
		return 0;
	ll tmp = 0, tmp2;
	if(aw[i] <= j)
		tmp = av[i] + solve(i+1, j-aw[i]);
	tmp2 = solve(i+1, j);
	dp[i][j] = max(tmp2, tmp);
	return dp[i][j];
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	init();
	cin >> n >> w;
	for(ll i=0; i<n; i++)
		cin >> aw[i] >> av[i];
	cout << solve(0, w);
	return 0;
}

Measured memory_bytes: 82608
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[100010];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int s = 0; int tmp = 0;
	rep(i, n) {
		s += a[i];
		if (i % 2 == 1)tmp += a[i] * 2;
	}
	dp[0] = s - tmp;
	cout << dp[0] << endl;
	rep(i, n-1) {
		dp[i + 1] = 2 * a[i] - dp[i];
		cout << dp[i + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
n, m = gets.chomp.split.map(&:to_i)
max_l = 0
min_r = 10**5
for i in 0..(m - 1) do
  l, r = gets.chomp.split.map(&:to_i)
  max_l = l if max_l < l
  min_r = r if min_r > r
end

if min_r - max_l >= 0
  card = min_r - max_l + 1
else
  card = 0
end
print("#{card}\n")

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void){

    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; i++){
        if(i%3!=0 && i%5!=0)
            sum += i;
    }
    cout << sum << endl;
    return 0;
    }


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>

#define max(x, y)	(((x) > (y))? (x) : (y))
#define abs(x)		(((x) < 0)? (-1*(x)) : (x))

using namespace std;

int N,Y, a=-1,b=-1,c=-1;

int main() {
	int i,j;
	
	cin >> N >> Y;
	
	for ( i = 0; i <= 2000; i++ ) {
		for ( j = 0; j <= N - i;j++ ) {
			if ( (10000*i + 5000*j + 1000*(N-i-j) ) == Y) {
				a=i;b=j;c=N-i-j;
			}
		}
	}
	
	cout << a << " " << b << " " << c << endl;

	return 0;
}


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

int main(int argc, char **argv)
{
    std::string S;
    std::cin >> S;
    std::vector<char> C(26); // #. of alphabets

    for(int i = 0; i < S.size(); i++){
        C.at(S.at(i) - 'a')++;
    }
    
    for(int i = 0; i < C.size(); i++){
        if(C.at(i) == 0){
            std::cout << ((char)('a'+i)) << std::endl;
            return 0;
        }
    }
    std::cout << "None" << std::endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += b[i] * (b[i] - 1) / 2;
  }

  for (int i = 0; i < n; i++) {
    cout << ans - (b[a[i]] - 1) * b[a[i]] / 2 +
                (b[a[i]] - 2) * (b[a[i]] - 1) / 2
         << endl;
  }
}


Measured memory_bytes: 6424
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cstring>

using namespace std;

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

struct Edge {
	Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
	int to, cap, rev;
};

class MaxFlow {
public:
	explicit MaxFlow(int n) : g(n), level(n), iter(n) {}
	vector< vector<Edge> > g;
	vector<int> level;
	vector<int> iter;
	void addEdge(int src, int dst, int cap){
		g[src].emplace_back(Edge(dst, cap, g[dst].size()));
		g[dst].emplace_back(Edge(src, 0, g[src].size()-1));
	}
	int dfs(int pos, int dst, int f){
		if(pos == dst) return f;
		for(int& i=iter[pos];i<g[pos].size();++i){
			Edge& e = g[pos][i];
			if(e.cap == 0 || level[e.to] <= level[pos]) continue;
			int d = dfs(e.to, dst, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
	int maxFlow(int s, int t){
		int res = 0;
		int n = g.size();
		while(true){
			for(int i=0;i<n;i++) level[i] = -1;
			level[s] = 0;
			queue<int> qu; qu.push(s);
			while(!qu.empty()){
				int p = qu.front(); qu.pop();
				for(const Edge& e : g[p]){
					if(e.cap > 0 && level[e.to] == -1){
						level[e.to] = level[p]+1;
						qu.push(e.to);
					}
				}
			}
			if(level[t] == -1) break;
			for(int i=0;i<n;i++) iter[i] = 0;
			for(int f;(f=dfs(s,t,1000000007)) > 0;res+=f);
		}
		return res;
	}
};

int main(){
	int H, W;
	while(cin >> H >> W){
		vector<string> vs(H);
		for(int i=0;i<H;++i) cin >> vs[i];
		bool ok = true;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(vs[i][j] != 'X') continue;
				if(i == 0 || i == H-1 || j == 0 || j == W-1){
					ok = false;
					continue;
				}
			}
		}
		if(!ok){
			cout << -1 << endl;
			continue;
		}
		MaxFlow f(2*H*W+2);
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				int p = i*W+j;
				if(i == 0 || i == H-1 || j == 0 || j == W-1){
					f.addEdge(2*p+2, 2*H*W+1, 10000);
				}
				if(vs[i][j] == 'X'){
					f.addEdge(2*p+1, 2*p+2, 10000);
					f.addEdge(0, 2*p+2, 10000);
				} else {
					f.addEdge(2*p+1, 2*p+2, 1);
				}
				for(int k=0;k<4;k++){
					int nx = i+dx[k], ny = j+dy[k];
					if(nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
					int np = nx*W+ny;
					f.addEdge(2*p+2, 2*np+1, 10000);
				}
			}
		}
		cout << f.maxFlow(0, 2*H*W+1) << endl;
	}
}



Measured memory_bytes: 2944