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

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

  vector<map<string, int>> data(N);

  data.at(0)["a"]= 1;

  string word; int Nchar;
  for(int i=1; i<N; i++){
    for(auto elem:data.at(i-1)){
      tie(word, Nchar)= elem;

      for(int j=0; j<Nchar; j++){
        char c_tail= 'a'+ j;
        data.at(i)[word+ c_tail]= Nchar;
      }
      char c_tail= 'a'+ Nchar;
      data.at(i)[word+ c_tail]= Nchar+ 1;
    }
  }

  for(auto elem:data.at(N-1)){
    cout << elem.first << endl;
  }
}


Measured memory_bytes: 17408
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
Integer a = sc.nextInt();
Integer b = sc.nextInt();
Integer c = sc.nextInt();
Integer d = sc.nextInt();

int ans = Math.min(b,d) - Math.max(a,c);
if(ans < 0 ) ans = 0;
System.out.println(ans);
}
}

Measured memory_bytes: 23892
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

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

    using pll = pair<ll, ll>;

    pll p1, p2;
    cin >> p1.first >> p1.second >> p2.first >> p2.second;
    auto p_m = min(p1, p2);
    auto p_M = max(p1, p2);
    p1 = p_m;
    p2 = p_M;
    ll N;
    cin >> N;
    vector<pll> P(N);
    for (ll i = 0; i < N; i++) {
        cin >> P[i].first >> P[i].second;
    }
    sort(P.begin(), P.end());

    ll dist = (abs(p1.first - p2.first) + abs(p1.second - p2.second)) * 100LL;
    constexpr long double ADV = 4.292036732051034;
    constexpr long double DISADV = 11.415926535897931;

    vector<pll> internal;
    for (int i = 0; i < N; i++) {
        if (P[i].first >= p1.first and P[i].first <= p2.first and P[i].second >= min(p1.second, p2.second) and P[i].second <= max(p1.second, p2.second)) {
            internal.push_back(P[i]);
        }
    }
    show(internal);

    if (p1.first == p2.first or p1.second == p2.second) {
        if (internal.empty()) {
            cout << dist << endl;
        } else {
            cout << fixed << setprecision(15) << (long double)(dist) + DISADV << endl;
        }
        return 0;
    }

    vector<ll> data1;
    for (int i = 0; i < internal.size(); i++) {
        data1.push_back((p1.second < p2.second) ? internal[i].second : -internal[i].second);
    }

    const int size1 = data1.size();
    vector<ll> dp1(size1 + 1, INF<ll>);
    for (int i = 0; i < size1; i++) {
        *lower_bound(dp1.begin(), dp1.end(), data1[i]) = data1[i];
    }
    const int num1 = lower_bound(dp1.begin(), dp1.end(), INF<ll>) - dp1.begin();
    show(num1);

    if (num1 == 1 + min(abs(p1.first - p2.first), abs(p1.second - p2.second))) {
        cout << fixed << setprecision(15) << (long double)(dist)-ADV * (num1 - 1) + DISADV << endl;
    } else {
        cout << fixed << setprecision(15) << (long double)(dist)-ADV * num1 << endl;
    }


    return 0;
}


Measured memory_bytes: 11116
import java.util.Scanner;

class Main{
public static void main(String[] args){

 int a;
 int b;
int c;

Scanner s = new Scanner(System.in);
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
if(a>b){if(c>a){System.out.println(b+" "+a+" "+c);}
else if(c<b){System.out.println(c+" "+b+" "+a);}
else{System.out.println(b+" "+c+" "+a);}
}else{if(c<a){System.out.println(c+""+a+""+b);}else if(c>b){System.out.println(a+" "+b+" "+c);}else{System.out.println(a+" "+c+" "+b);}}}}


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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    long long int result = 0;
    result += min(A, K);
    K -= A;
    if(K <= 0) {
        cout << result << endl;
        return 0;
    }
    K -= B;
    if(K <= 0) {
        cout << result << endl;
        return 0;
    }
    result -= min(C, K);
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,i,sum=0,l;
    vector<int>v;
    cin>>n;
    for(i=0;i<n;i++)
    {cin>>a;
    v.push_back(a);

    }

      for(int i=n-1;i>=0;i-=2)
      {
          cout<<v[i]<<" ";
      }
      if(n%2==0){l=0;}
      else{l=1;}
      for(int i=l;i<n;i+=2)
      {
          cout<<v[i]<<" ";
      }


}


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int ans = X;
    rep(i, N) {
        string S;
        cin >> S;
        if (S[0] == 'n') {
            ans = max(0, ans + A);
        }
        else if (S[0] == 't') {
            ans = max(0, ans + B);
        }
        else {
            ans = 0;
        }
    }

    write(ans);
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main() {
     int n; cin >> n;
     if(n < 10) cout << n << endl;
     else if(n < 100) cout << 9 << endl;
     else if(n < 1000) cout << 9 + n - 99 << endl;
     else if(n < 10000) cout << 9 + 900 << endl;
     else if(n < 100000) cout << 9 + 900 + n - 9999 << endl;
     else cout << 9 + 900 + 90000;     
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	vi a(n),b(n,0),c(n,0);
	REP(i,n)a[i]=read()-1;
	int ans=0;
	REP(i,n){
		int w=0;
		while(a[i]>=(1<<w)-1)w++;
		w--;
		b[i]=w;
		if(a[i]>(1<<w)-1)c[i]=1;
		ans+=b[i]+c[i];
	}
	//cerr<<b<<endl;
	//cerr<<c<<endl;
	int last=0;
	REP(i,n){
		int m1=min(last,b[i]);
		ans-=m1;
		last-=m1;
		if(last>0&&c[i]>0){
			ans--;
			c[i]--;
		}
		last=b[i]+c[i];
	}
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll x, y, z;
    cin >> x >> y >> z;
    cout << (x * y) / 2 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
import string


def solve(N, Ss):
    counters = []
    for s in Ss:
        counters.append(Counter(s))
    ans = ""
    for c in string.ascii_lowercase:
        vs = [counter[c] for counter in counters if c in counter]
        if len(vs) == N:
            ans += c * min(vs)
    return ans


if __name__ == "__main__":
    n = int(input())
    Ss = [input() for _ in range(n)]
    print(solve(n, Ss))


Measured memory_bytes: 3760
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
//cin.tie(0);ios::sync_with_stdio(false);
////////////////////////////////////////////////
long long cnt;
int l,n;
int a[1000000];
VI G;
void insS(int a[],int n,int g)
{
	for(int i=g;i<n;i++)
	{
		int v=a[i];
		int j=i-g;
		while(j>=0&&a[j]>v)
		{
			a[j+g]=a[j];
			j-=g;
			cnt++;
		}
		a[j+g]=v;
	}
}

void shellS(int a[],int n)
{
	for(int h=1;;)
	{
		if(h>n)break;
		G.PB(h);
		h=h*3+1;
	}
	
	for(int i=G.size()-1;i>=0;i--)
	{
		insS(a,n,G[i]);
	}
}

int main()
{
	cin>>n;
	REP(i,n)
	{
		scanf("%d",a+i);
	}
	cnt=0;
	shellS(a,n);
	cout<<G.size()<<endl;
	DREP(i,SZ(G))
	{
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	REP(i,n)
	{
		printf("%d\n",a[i]);
	}
	return 0;
}
	

Measured memory_bytes: 7184
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {




    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in) ;
        int N = Integer.parseInt(scan.next());
        String[] wordArray = new String[N];


        for(int i = 0; i < N; i++){
            wordArray[i] = scan.next();
        }


        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                if( (i != j) && wordArray[i].equals(wordArray[j])){
                    System.out.println("No");
                    return;
                }
            }
        }

        String end;
        String top;
        String a;


        for(int i = 0; i < N -1; i++){


            end = wordArray[i].substring(wordArray[i].length()-1);
            top = wordArray[i+1].substring(0,1);

            if(end.equals(top) == false) {
                System.out.println("No");
                return;
            }





        }

        System.out.println("Yes");
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define f(i,s,n)for(register int i=s;i<=n;++i)
#define f2(i,s,n)for(register int i=n;i>=s;--i)
#define N 60
using namespace std;
bool inline cmp(int a,int b){
	return a>b;
}
int a[N];
int main(){
	ios::sync_with_stdio(false);
	long long n,k,sum=0;
	cin>>n>>k;
	f(i,1,n){
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	f(i,1,k){
		sum+=a[i];
	}
	cout<<sum<<"\n";
	return 0;
}


Measured memory_bytes: 256
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;


signed main()
{
    fast;
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
}





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

#define int long long

using namespace std;

const int N = 2e5 + 5;
const int md = 1e9 + 7;

int dp[N];

signed main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> y;
  for (int i = 0; i < m; i++) {
    int cnt = 1;
    while (i + 1 < m && s[i + 1] == s[i]) {
      ++i;
      ++cnt;
    }
    y.push_back(cnt);
  }
  if (y.size() == 1) {
    vector<int> f(N), g(N);
    f[1] = 2, f[2] = 3;
    for (int i = 3; i <= n; i++) {
      f[i] = (f[i - 1] + f[i - 2]) % md;
    }
    g[2] = 3, g[3] = 4;
    for (int i = 4; i <= n; i++) {
      g[i] = (f[i - 1] + f[i - 3]) % md;
    }
    cout << g[n] << '\n';
    return 0;
  } else if (n % 2 == 1) {
    cout << 0 << '\n';
    return 0;
  }
  y.pop_back();
  int C = y[0] + 1;
  bool is = true;
  for (int x : y) {
    if (is && (x % 2 == 1)) {
      C = min(C, x);
    }
    is ^= 1;
  }
  dp[0] = dp[2] = 1;
  for (int i = 4; i < N; i += 2) {
    dp[i] = 2 * dp[i - 2] % md;
    if (i - 3 - C >= 0) {
      (dp[i] += md - dp[i - 3 - C]) %= md;
    }
  }
  int ans = dp[n];
  for (int l = 1; l <= C; l += 2) {
    if (n - l - 1 >= 0) {
      (ans += l * dp[n - l - 1] % md) %= md;
    }
  }
  ((ans %= md) += md) %= md;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6752
<?php
/**
 * ABC119
 * C - Synthetic Kadomatsu
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, '%d %d %d %d', $N, $A, $B, $C);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $l[$i]);
}


echo dfs(0, 0, 0, 0), PHP_EOL;

function dfs($current, $a, $b, $c) {
    global $N, $A, $B, $C, $l;
    if ($current === $N) {
        if (min($a, $b, $c) > 0) {
            return abs($a - $A) + abs($b - $B) + abs($c - $C) - 30;
        } else {
            return 10000000;
        }
    }
    $ret = [
        dfs($current + 1, $a, $b, $c),
        dfs($current + 1, $a + $l[$current], $b, $c) + 10,
        dfs($current + 1, $a, $b + $l[$current], $c) + 10,
        dfs($current + 1, $a, $b, $c + $l[$current]) + 10,
    ];
    return min($ret);
}


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
int n,f,s[14][8],t,h,ans;
int main()
{
  	cin>>n>>f;
  	for(int i=1;i<=11;i++)
    	for(int j=1;j<=7;j++)
    		t++,s[i][j]=t;
  	for(int i=1;i<=11;i++)
    	for(int j=1;j<=7-3+1;j++)
   		{
      		t=0;
      		for(int k=0;k<3;k++)
        		for(int l=0;l<3;l++)
          			t+=s[(i+k-1)%11+1][j+l];
      		if(t%11==f)h++;
    	}
  	ans+=max(0,(n/11-1))*h;
  	if(n/11>0)n-=(n/11-1)*11;
  	for(int i=1;i<=n-3+1;i++)
   		for(int j=1;j<=7-3+1;j++)
    	{
      		t=0;
      		for(int k=0;k<3;k++)
        		for(int l=0;l<3;l++)
          			t+=s[(i+k-1)%11+1][j+l];
      		if(t%11==f)ans++;
    	}
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("int.txt", "r", stdin);
#endif

int n;
cin>>n;
vector<int> v;
forn(i,0,n-1){
    int x;
    cin>>x;
    v.pb(x);
}
int ans=0;
ans+=v[0]+v[n-2];
//cout<<v[0]<<" "<<v[n-2]<<endl;
forn(i,1,n-1){
   // cout<<v[i]<<" "<<v[i-1]<<endl;
    ans+=min(v[i-1],v[i]);
}
cout<<ans<<endl;
}



Measured memory_bytes: 3620
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    S, T = input().split()

    ans = ""
    for i in range(N):
        ans += S[i] + T[i]
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
inline void rd(int &x)
{
	x=0;register char k=getchar();int s=1;
	while(k>'9'|k<'0'){if(k=='-')s=-1;k=getchar();}
	while(k>='0'&&k<='9')x=x*10+k-48,k=getchar();x*=s;
}
int main()
{
	int n,m;
	cin>>n>>m;
	cout<<n-m+1;
}

Measured memory_bytes: 256
X = list(map(int, input().split()))
X.sort()
d1 = X[2] - X[1]
d2, m = divmod(X[2] - X[0] - d1, 2)
if m == 1:
    print(d1 + d2 + 2)
else:
    print(d1 + d2)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct data {
    int a,b;
} p[N];
bool operator<(data a,data b) {
    return a.a-a.b>b.a-b.b;
}
int n,x,y,z;
ll ans=0,mx=-1e18,sum=0,sa[N],sb[N];
int main() {
    x=gi(),y=gi(),z=gi(),n=x+y+z;
    for(int i=1;i<=n;i++) {
        int a=gi(),b=gi(),c=gi();
        p[i]={a-c,b-c},ans+=c;
    }
    sort(p+1,p+n+1);
    priority_queue<int,vector<int>,greater<int>> Q;
    for(int i=1;i<x;i++) Q.push(p[i].a),sum+=p[i].a;
    for(int i=x;i<=n;i++) {
        Q.push(p[i].a),sum+=p[i].a;
        while(Q.size()>x) sum-=Q.top(),Q.pop();
        sa[i]=sum;
    }
    while(!Q.empty()) Q.pop();
    sum=0;
    for(int i=n-y+2;i<=n;i++) Q.push(p[i].b),sum+=p[i].b;
    for(int i=n-y+1;i;i--) {
        Q.push(p[i].b),sum+=p[i].b;
        while(Q.size()>y) sum-=Q.top(),Q.pop();
        sb[i]=sum;
    }
    for(int i=x;i<=n-y;i++) mx=max(mx,sa[i]+sb[i+1]);
    printf("%lld\n",mx+ans);
    return 0;
}


Measured memory_bytes: 2560
n=int(input())
if n == 0:
    print(0)
s = ""

while n != 0:
    if n%2 == 0:
        
        s = "0" + s
    elif n%2 == 1:
        n -= 1
        s = "1" +s
    n = (n//-2)

print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL; 
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
LL dp[2000001];
LL mod=1e9+7;
bool vis[100000],ok=1;
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
LL modexpo(LL a, LL b) {
  LL ans=1;
  a=a%mod;
  while(b>0){
    if((b&1)==1){
      ans=((ans%mod)*(a%mod))%mod;
    }
    b=b>>1;
    a=((a%mod)*(a%mod))%mod;
  }
  return ans; 
}
LL invmod(LL n){
  return modexpo(n,mod-2);
}
LL comb(LL n,LL r){
  if(r==0){
    return 1;
  }
  LL fact[n+1];
  fact[0] = 1; 
    for (LL i = 1; i <= n; i++){
       fact[i] = (fact[i - 1] * i) %mod;}
    return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) %mod; 
}
LL gcd(LL a, LL b) {
  if (a == 0){
       return b;
       }  
    return gcd(b % a, a);  
}
LL lcm(LL a, LL b) {
  return (a*b)/gcd(a,b);
}
void solve(LL k){
  LL n;
  cin>>n; 
  LL a[n];
  for(LL i=0;i<n;i++){
    cin>>a[i];
  }
  LL d[n];
  d[0]=0,d[1]=abs(a[1]-a[0]);
  for(LL i=2;i<n;i++){
    d[i]=min(d[i-1]+abs(a[i]-a[i-1]),d[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<d[n-1]<<endl; 
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
 LL t=1;
//cin>>t;
 LL k=1;
while(k<=t){
  if(ok==0){
    break; 
  }
   solve(k);
  k++;
  }
   return 0;
   }

Measured memory_bytes: 5192
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


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

	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	vb water(f + 1, false);
	vb sugar(f + 1, false);
	water[0] = sugar[0] = true;

	rep(i, f + 1) {
		if (i - 100 * a >= 0 && water[i - 100 * a]) {
			water[i] = true;
		}
		if (i - c >= 0 && sugar[i - c]) {
			sugar[i] = true;
		}
	}
	rep(i, f + 1) {
		if (i - 100 * b >= 0 && water[i - 100 * b]) {
			water[i] = true;
		}
		if (i - d >= 0 && sugar[i - d]) {
			sugar[i] = true;
		}
	}
	double rate = -1;
	int sum = 0, sug = 0;

	rep(i, f + 1) {
		reprev(j, f + 1) {
			if (water[i] && sugar[j] && i + j <= f) {
				if (i * e >= j * 100 && (double)j / (i + j) > rate) {
					rate = (double)j / (i + j);
					sum = i + j;
					sug = j;
					break;
				}
			}
		}
	}

	if (rate < 0) {
		cout << 100 * a << " " << 0 << endl;
	}
	else {
		cout << sum << " " << sug << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    v_int a(n);
    cin >> a;
    
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            ans += a[i] * a[j];
        }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC125B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = ReadInt;
            var V = ReadInts;
            var C = ReadInts;

            var VD = new int[N];
            for (int i = 0; i < N; i++)
            {
                VD[i] = V[i] - C[i];
            }

            int ans = VD.Where(x => x > 0).Sum();
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <map> 
#include <set>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ll long long

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

void solve() {
    int N, K;
    cin >> N >> K;

    int L[N];
    rep(i, N) cin >> L[i];

    int ans = 0;
    rep(i, K+1) {
        rep(j, K+1) {
            bool t[N];
            rep(_i, N) {
                t[_i] = false;
                if (_i < i) t[_i] = true;
                if (_i >= N-j) t[_i] = true;
            }

            vector<int> v;
            rep(_i, N) {
                if (t[_i]) v.push_back(L[_i]);
            }
            sort(v.begin(), v.end());

            rep(k, K) {
                if(i + j + k > K) break;
                rep(_i, min(k, (int)v.size())) {
                    if(v[_i] < 0) v[_i] = 0;
                }
                int _ans = 0;
                rep(_i, v.size()) _ans += v[_i];
                ans = max(_ans, ans);
            }
        }
    }


    cout << ans << endl;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;

    solve();
}


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

int main(){
    ll q, h, s, d; cin >> q >> h >> s >> d;
    ll n;   cin >> n;

    ll X = min(2*min(2*q, h), s);
    ll XL = min(2*X, d);
    
    cout << n%2*X+n/2*XL << endl;

    
}

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

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll MOD = 1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[2*n];
  for (int i = 0; i < 2*n; i++) {
    cin >> a[i];
  }
  sort(a,a+2*n);
  int ans = 0;
  for (int i = 0; i < 2*n; i++) {
    if (i%2 == 0) {
      ans += a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 99999999999
#define MOD 1000000007
 
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
 
int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};
 
ll n, k, h[100001], dp[100001];
bool m[100001];

int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> h[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	m[0] = true;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k&&i+j<n;j++){
			if(m[i]){
				dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
				m[i+j] = true;
			}
		}
	}
	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define N_MAX 100005

using namespace std;

int main()
{
	int N, Q;
  	string S;
  	cin >> N >> Q;
  	cin >> S;
  	int l[N_MAX];
  	int r[N_MAX];
  	int d[N_MAX];
  	int ans = 0;
  	d[0] = 0;
  	for(int i = 0; i < Q; i++){
     	cin >> l[i] >> r[i]; 
    }
  	for(int i = 1; i < N; i++){
      	d[i] = d[i-1];
    	if(S[i-1] == 'A' && S[i] == 'C') d[i]++;
      	cerr << i << ' ' << d[i] << endl;
    }
  	for(int i = 0; i < Q; i++){
     	ans = d[r[i]-1] - d[l[i]-2];
      	if(S[l[i]-1] == 'C' && S[l[i]-2] == 'A') ans--;
      	cout << ans << endl;
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct T{
    int key;
    T *parent,*left,*right;
};
    T *root=NULL;
void insert(int k){
    T *y=NULL;
    T *x=root;
    T *z=new T();
    *z={NULL};
    z->key=k;
    while(x!=NULL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NULL){
        root=z;
    }
    else if(z->key < y->key){
        y->left=z;
    }
    else{
        y->right=z;
    }
}
int find(T *x,int k){
    T *z=new T();
    *z={NULL};
    z->key=k;
    while(x!=NULL){
        if(z->key==x->key){
            return true;
        }
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    return false;
}
void Preorder(T *root){
    if(root!=NULL){
        cout<<" "<<root->key;
        Preorder(root->left);
        Preorder(root->right);
    }
}
void Inorder(T *root){
    if(root!=NULL){
        Inorder(root->left);
        cout<<" "<<root->key;
        Inorder(root->right);
    }
}
int main(){
    int n,k;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="insert"){
            cin>>k;
            insert(k);
        }
        else if(s=="find"){
            cin>>k;
            if(find(root,k)){
                cout<<"yes"<<endl;
            }
            else{
                cout<<"no"<<endl;
            }
        }
        else{
            Inorder(root);
            cout<<endl;
            Preorder(root);
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26632
#include<stdio.h>

int main() {
	int n, t[100], m, p, x, temp1, temp2, total;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &t[i]);

	scanf("%d", &m);

	for (int i = 0; i < m; i++)
	{
		scanf("%d", &temp1);
		scanf("%d", &temp2);

		total = 0;

		for (int j = 0; j < n; j++)
		{
			if (temp1 == j + 1)
				total += temp2;
			else
				total += t[j];
		}
			

		printf("%d\n", total);
	}


	return 0;
}

Measured memory_bytes: 1712
d[1001],c;
main(w,n,i,C,W,b)
{
  for(;scanf("%d",&w),b=w;printf("Case %d:\n%d\n%d\n",++c,d[w],b),bzero(d,4004)){
    for(scanf("%d",&n);i=n--;)
        for(i=w,scanf("%d,%d",&C,&W);i>=W;i--)
            d[i]=fmax(d[i],d[i-W]+C),b=d[i]-d[w]?b:i;
  }exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

vb a(30);

int main(){
	int t;
	for(int i=0;i<28;i++){
		cin>>t;
		a[t-1]=1;
	}
	for(int i=0;i<30;i++){
		if(!a[i]) cout<<i+1<<endl;
	}
}

Measured memory_bytes: 1192
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0]*(K+1) for i in range(N)]
for i, a in enumerate(A):
  if i == 0:
    for j in range(a+1):
      dp[0][j] = 1
  
  else:
    dp[i][0] = 1
    for j in range(1, K+1):
      dp[i][j] = dp[i][j-1] + dp[i-1][j]
      if j > a:
        dp[i][j] -= dp[i-1][j-a-1]

      dp[i][j] %= MOD

print(dp[N-1][K])

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

int main()
{
  long long N,M;
  long long ans=1;
  cin>>N>>M;
  for (long long i=1;i*i<=M;i++){
    if (M%i==0){
      if (i*N<=M)
	ans=max(ans,i);
      if ((M/i)*N<=M)
	ans=max(ans,(M/i));
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char , char> pcc;
#define pb push_back
#define mp make_pair
#define ft first
#define se second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define mod 1000000007

ll dp[1005][1005];

int main()
{
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	ll h,w;
  	cin >> h >> w;
  	string s[h];
  	for(ll i=0;i<h;i++)
  	{
  		cin >> s[i];
  	}
  	dp[h-1][w-1]=1;
  	for(ll i=h-1;i>=0;i--)
  	{
  		for(ll j=w-1;j>=0;j--)
  		{
  			if(i==h-1&&j==w-1)
  			{
  				continue;
  			}
  			else if(i==h-1)
  			{
  				if(s[i][j]=='#')
  				{
  					dp[i][j]=0;
  				}
  				else 
  				{
  					dp[i][j]=dp[i][j+1];
  				}
  			}
  			else if(j==w-1)
  			{
  				if(s[i][j]=='#')
  				{
  					dp[i][j]=0;
  				}
  				else 
  				{
  					dp[i][j]=dp[i+1][j];
  				}	
  			}
  			else 
  			{	
  				if(s[i][j]=='#')
  				{
  					dp[i][j]=0;
  				}
  				else 
  				{
  					dp[i][j]=dp[i+1][j]+dp[i][j+1];
  					dp[i][j]%=mod;
  				}
  			}
  		}
  	}
  	cout << dp[0][0] << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>

int main(){
  int N,A[100],i,j,k,key;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }  
  
  for(i=0;i<=N-1;i++){
    key=A[i];
    j=i-1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1]=key;
    }
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k<N-1)printf(" ");
    }
    printf("\n");
  }   
  return 0;
}

Measured memory_bytes: 604
toInt :: (String -> Int)
toInt x = read x ::Int
max' [] = error "empty"        -- 1番目
max' [x] = x                   -- 2番目
max' (x:xs) = max x (max' xs)

main = do
  args <- words <$> getLine
  let argsInt = map(toInt) args
  let addResult = sum argsInt
  let distResult =  toInt (args !! 0) - toInt(args !! 1)
  let prodResult = product argsInt
  print (max' [addResult, distResult, prodResult])


Measured memory_bytes: 508
s = input().rstrip()
n = len(s)
mod = 10**9 + 7
dp = [0] * 4
dp[0] = 1

for i in range(n):
    next = [0] * 4
    if s[i] == 'A':
        next[1] += dp[0]
    elif s[i] == 'B':
        next[2] += dp[1]
    elif s[i] == 'C':
        next[3] += dp[2]
    else:
        next[1] += dp[0]
        next[2] += dp[1]
        next[3] += dp[2]
        next[0] += dp[0] * 2
        next[1] += dp[1] * 2
        next[2] += dp[2] * 2
        next[3] += dp[3] * 2
    next[0] += dp[0]
    next[1] += dp[1]
    next[2] += dp[2]
    next[3] += dp[3]

    for j in range(4):
        next[j] %= mod
    dp = next
print(dp[3])


Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	ll n,k; cin>>n>>k;
	rep(i,0,n)cin>>to[0][i],to[0][i]--;

	rep(i,0,D-1){
		rep(j,0,n){
			to[i+1][j]=to[i][to[i][j]];
		}
	}
	ll ans=0;
	for(int i=D-1; i>=0; --i){
		ll L=1ll<<i;
		if(L<=k){
			k-=L;
			ans=to[i][ans];
		}
	}
	cout << ans+1 << endl;



	return 0;
}

Measured memory_bytes: 97396
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    li k, a, b;
    cin >> k >> a >> b;
    li ans = k + 1;
    if (b - a > 2) {
        li exchangable_action = k - (a - 1);
        li exchange = exchangable_action / 2;
        li rem = exchangable_action % 2;
        ans = max(ans, a + (b - a) * exchange + rem);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    sort(begin(A), end(A));
    sort(rbegin(B), rend(B));
    if (N % 2 == 1) {
        cout << B[N / 2] - A[N / 2] + 1 << endl;
    } else {
        int a2 = A[N / 2 - 1] + A[N / 2];
        int b2 = B[N / 2 - 1] + B[N / 2];
        cout << b2 - a2 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
using std::map;

map<ll,ll> mp;
ll a,b,c,d,T,N;

inline ll dfs(ll n){
    if(mp.count(n)) return mp[n];
    if(n == 0) return 0;
    if(n == 1) return d;
    ll tmp = 0x7f7f7f7f7f7f7f7f;
    if(n < tmp / d) tmp = n * d;
    ll a1 = n/2*2 , a2 = (n+1)/2*2;
    ll b1 = n/3*3 , b2 = (n+2)/3*3;
    ll c1 = n/5*5 , c2 = (n+4)/5*5;
    tmp = std::min(tmp,a + dfs(a1/2) + d * std::abs(a1-n)),
    tmp = std::min(tmp,a + dfs(a2/2) + d * std::abs(a2-n)),
    tmp = std::min(tmp,b + dfs(b1/3) + d * std::abs(b1-n)),
    tmp = std::min(tmp,b + dfs(b2/3) + d * std::abs(b2-n)),
    tmp = std::min(tmp,c + dfs(c1/5) + d * std::abs(c1-n)),
    tmp = std::min(tmp,c + dfs(c2/5) + d * std::abs(c2-n));
    mp[n] = tmp;
    return tmp;
}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> T;
    while(T--){
        mp.clear();
        cin >> N >> a >> b >> c >> d;
        cout << dfs(N) << "\n";
    }
    return 0;
}

Measured memory_bytes: 4364
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int siz=2e5+1;

struct edge{
	int v,nxt;
}e[siz];

int n,m;
int head[siz];
int c[siz];
ll cnt[2];

//inline
//int dif(int x){return x^1;}

void dfs(int now,int fc=0);
void add_edge(int u,int v,bool o=true);

int main()
{
	memset(c,0x7f,sizeof c);
	scanf("%d%d",&n,&m);
	int rt=-1;
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		if(rt==-1)
			rt=u;
	}
	dfs(rt);
	for(int i=1;i<=n;i++)
		if(c[i]!=c[0])
			cnt[c[i]]++;
	printf("%lld\n",(cnt[0]*cnt[1])-m);
}

void dfs(int now,int fc)
{
	c[now]=fc^1;
	const int sc=c[now]^1;
	for(int i=head[now];i!=0;i=e[i].nxt){
		if(c[e[i].v]==c[0]){
			dfs(e[i].v,c[now]);
			continue;
		}
		if(c[e[i].v]!=sc){
			printf("%lld\n",(((ll)n*(n-1))>>1)-m);
			exit(EXIT_SUCCESS);
		}
	}
}

void add_edge(int u,int v,bool o)
{
	static int cnt;
	e[++cnt]={v,head[u]};
	head[u]=cnt;
	if(o)
		add_edge(v,u,false);
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            long K = in.nextLong();

            // bc ac ab
            // aabc abbc abcc
            // aabbbccc aaabbccc aaabbbcc
            //
            if (K % 2 == 0) {
                if (Math.abs(A - B) > 1e18) {
                    System.out.println("Unfair");
                    return;
                }
                System.out.println(A - B);
                return;
            }
            if (Math.abs(B - A) > 1e18) {
                System.out.println("Unfair");
                return;
            }
            System.out.println(B - A);
            return;
        }
    }

    private static int f(int n) {
        return (int) Math.floor((n * n + 4.0) / 8.0);
    }
}


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

int main()
{
    multiset<pair<ll, ll> > pq;
    ll n, m;
    cin >> n >> m;

    for (ll i = 0; i < n; i++) {
        ll coin, num;
        scanf("%lld %lld", &coin, &num);

        pq.insert({coin, -num});
    }

    ll cnt = 0;
    ll koyta_nilam = 0;
    for (auto tmp : pq) {

        ll curcoin = tmp.first;
        ll curnum = -tmp.second;

        if (curnum + koyta_nilam > m) cnt += (m - koyta_nilam) * curcoin, koyta_nilam = m;
        else cnt += curnum * curcoin, koyta_nilam += curnum;

        if (koyta_nilam == m) break;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int n,x;
    cin >> n >> x;
    vl a(n);
    rep(i,n){
        int b;
        cin >> b;
        a[i]=abs(x-b);
    }
    ll ans = a[0];
    rep(i,n){
        ans = __gcd(ans,a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  char a,ans;cin >> a;
  switch(a){
    case 'A':
      ans = 'T';
      break;
    case 'C':
      ans = 'G';
      break;
    case 'T':
      ans = 'A';
      break;
    case 'G':
      ans = 'C';
      break;
  }
  cout << ans << endl;
}

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

ll x;

int main(){
	cin >> x;
	int cnt = 0;
	for(ll Now = 100; Now < x;){
		cnt++;
		Now += Now / 100;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(size_t i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(size_t i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define INF INT_MAX/2

int main(){
	int N;
	vector<int> A;
	cin >> N;
	A.resize(N);
	REP(i, N) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int ans = 0;
	int before = A[0];
	Foreach(item, A) {
		ans += (item - before);
		before = item;
	}
	out(ans);
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;

int main(){
    string T;
    string S;
    cin >> S;
    if(S.size() == 2){
        cout << S << endl;
    }
    else {
        for(int i = 0; i < 3; i++){
        cout << S[2 - i];
    }
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 256