akhauriyash/Code-Regression huggingface dataset:
# bfs.rb
#ALDS1_11_C

$n = STDIN.gets.split[0].to_i
$rinsetu = Array.new(101).map{Array.new(101,0)}
$d = Array.new(101,9999999)
$q = Array.new

1.upto($n){|i|
  s = STDIN.gets.split
  u = s[0].to_i
  k = s[1].to_i
  0.upto(k-1){|j| 
    v = s[2+j].to_i
    $rinsetu[u][v] = 1
  }
}

$q << 1
$idx = 0
$d[1]=0

while $idx < $q.length
  node = $q[$idx]
#  printf("node=%d\n",node)
  1.upto($n) {|i|
    if i != node && $rinsetu[node][i]==1 && $d[i] > 1+$d[node]
      $d[i] = 1+$d[node] 
      $q << i
    end
  }
  $idx += 1
end

1.upto($n) {|i|
  if $d[i] != 9999999 
    printf("%d %d\n",i,$d[i])
  else
    printf("%d -1\n",i)
  end
}

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

int insertionSort(int A[], int N){
  int v, j;
  for (int i = 1; i < N; i++){

    v = A[i];

    j = i -1;
    for (; j >= 0 && A[j] > v; j--){
      A[j+1] = A[j];
    }

    A[j+1] = v;

    //??????
    for (int i = 0; i < N; i++){
      if(i == N-1) cout << A[i] << endl;
      else cout << A[i] << " ";
    }

  }
  return 0;
}


int main(){
  int N, A[1000];
  cin >> N;
  for ( int i = 0; i < N; i++) cin >> A[i];
  //????????????
  for (int i = 0; i < N; i++){
    if(i == N-1) cout << A[i] << endl;
    else cout << A[i] << " ";
  }
  insertionSort(A, N);

  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int mod = 1000000007;
int n;
int a[105];
ll exp(ll a, ll x){
    if (x == 0) return 1ll;
    ll p = exp(a,x/2);
    p = (p*p)%mod;
    if (x & 1){
        p = (p*a)%mod;
    }
    return p;
}
ii solve(int l, int r, int s){
    if (l > r) return ii(1ll,0ll);
    int pos = l;
    for (int i = l; i <= r; i++){
        if (a[i] < a[pos]) pos = i;
    }
    ii L = solve(l,pos-1,a[pos]);
    ii R = solve(pos+1,r,a[pos]);
    ll prod1 = (ll)(L.first)*(R.first)%mod;
    ll prod2 = (ll)(L.first+L.second)*(R.first+R.second)%mod;
    ll ex = exp(2,a[pos]-s);
    ll dp1 = (ex*prod1)%mod;
    ll dp2 = (2*prod2 + (ex-2)*prod1)%mod;
    //printf("%d %d %lld %lld\n",l,r,dp1,dp2);
    return ii(dp1,dp2);
}
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++) scanf("%d",&a[i]);
    printf("%lld",solve(0,n-1,0).second);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  ll k=0,l=1,m=0;
  for(ll i=n-1;i>-1;i--){
    if(m==2){
      cout << l;
      return 0;
    }
    if(i==n-1)k++;
    else if(a[i]!=a[i+1])k=1;
    else{
      k++;
      if(k==2){
        l=l*a[i];
        k=0;
        m++;
      }
    }
  }
  if(m==2){
    cout << l;
    return 0;
  }
  cout << 0;
}

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main() {FIN
	
	int n, x, y, i, j, d;
	cin >> n >> x >> y;
	x--, y--;
	vi dis(n);
	
	for (i = 0; i < n; i++)	{
		for (j = i + 1; j < n; j++) {
			if (i < y) {
				if (j > x) {
					d = abs(x - i) + 1 + abs(j - y);
					if (d < j - i) {
						dis[d]++;
					} else
						dis[j - i]++;
				} else
					dis[j - i]++;
			} else
				dis[j - i]++;
		}
	}
	
	for (i = 1; i < n; i++)
		cout << dis[i] << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
#define mod  1000000007
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
ll i, j, k;
void solve(){
  ll n;  cin >> n;
   vl v(n);
   for(i = 0;  i< n; i++){
     cin >> v[i];
   }
   ll mn = v[0];
   ll ans = 1;
   for(i = 1; i< n; i++){
           if(v[i] <= mn) ans ++ , mn = v[i];
    }
    cout << ans << endl;
           

     return ; 
} 
    signed main(){
   
    //CASET
    solve();
    
   
    return 0;
  }

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vl a(n+1,0);
	rep(i,m){
		int l,r;cin>>l>>r;
		a[l-1]++;a[r]--;
	}
	partial_sum(all(a),a.begin());
	ll ans=0;
	rep(i,n+1)if(a[i]==m)ans++;
	puta(ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main() {
  int n;
  int f = 1;
  cin >> n;
  for (int i =0; i < n; i++){
     int a;
     cin >> a;
     if(a%2 == 0){
       if (a%3 != 0 && a%5 !=0){
         f = 0;
      }

     }
  }
  if (f == 1){
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}


  

  
    
  
  
 
 





















Measured memory_bytes: 256
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 200005;
const ll mod = 2000000011;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
}

//3. Structure or classes
struct Value{
    int val = 1e9+7;
};
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    int x;
    cin>>x;
    map<int,Value>mp;
    map<int,int>rev;
    for(int i=-1000;i<=1000;i++){
        int a = i*i*i*i*i;
        mp[a].val=i;
    }
    for(auto i:mp){
        if(mp[i.first+x].val!=1e9+7){
           cout<<mp[i.first+x].val<<" "<<mp[i.first].val<<"\n";
           return;
        }
        else{
            mp.erase(i.first+x);
        }
    }
    cout<<"-1";
    return;

}
// how r u bro

Measured memory_bytes: 3712
/**
*    Name: Ajay
*    Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{
  //fastio();
  //input();
  int n,l,i;
  cin>>n>>l;
  vi v;
  int sum=0;  
  for(i=1;i<=n;i++)
  {
      v.pb(l+i-1);
      sum+=(l+i-1);
  }
  int ans=-1,diff=inf,act=-1;
  for(i=0;i<v.size();i++)
  {
    int d=sum-v[i];
      
    if(diff==inf)
    {
      diff=abs(sum-d);
      act=v[i];
    }
    else if(abs(sum-d)<diff)
    {
      diff=abs(sum-d);
      act=v[i];
    }
  }
    cout<<sum-act;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
 
using namespace std;
 
typedef pair<double,double> P;
double EPS=1e-10;
 
int main(void){
  int n;
  double x[100],y[100];
 
  while(cin >> n,n){
    vector<P>d;
 
    for(int i=0;i<n;i++)
      scanf("%lf,%lf",&x[i],&y[i]);
     
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
    double L=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    if(L>2.0000)continue;
    double theta=atan2(y[j]-y[i],x[j]-x[i]);
    double a=acos(L/2);
    d.push_back(make_pair(x[i]+cos(theta+a),y[i]+sin(theta+a)));
    d.push_back(make_pair(x[i]+cos(theta-a),y[i]+sin(theta-a)));
      }
    }
 
    int count,ans=1;
    for(int i=0;i<d.size();i++){
      count=0;
       
      for(int j=0;j<n;j++){
    if(pow(d[i].first-x[j],2)+pow(d[i].second-y[j],2)<=1.0+EPS){
      count++;
    }
      }
    ans=max(ans,count);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n,cnt;
int V[100010],F[100010];
int main() {
	scanf("%d",&n);
	V[++cnt]=1;
	for(int i=6;i<=n;i*=6) V[++cnt]=i;
	for(int i=9;i<=n;i*=9) V[++cnt]=i;
	memset(F,127,sizeof(F));
	F[0]=0;
	for(int i=1;i<=cnt;i++)
		for(int j=V[i];j<=n;j++)
			F[j]=min(F[j-V[i]]+1,F[j]);
	printf("%d\n",F[n]);
	return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (s == u) {
    a--;
    cout << a << " " << b << endl;
  } else {
    b--;
    cout << a << " " << b << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;	
string s;
int n;
LL cal(int x,int y)
{
	LL res=0;
	LL base=1;
	for(int i=y;i>=x;i--)
	{
		res+=int(s[i]-'0')*base;
		base*=10;
	}
//	cout<<res<<endl;
	return res;
}
LL ans=0;
void solve(int pre,int x,LL sum)
{
	if(x>n)
	{
		ans+=sum;
		//cout<<sum<<",,"<<endl;
		return ;
	}
	//cout<<pre<<" "<<x<<" "<<sum<<endl;
	solve(x,x+1,sum+cal(pre,x-1));
	if(x!=n)solve(pre,x+1,sum);
}
int main()
{
	
	while(cin>>s)
	{
		n=s.length();
		solve(0,1,0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#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() {
  string s;
  cin >> s;
  
  string t = "";
  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (t.size()) t.pop_back();
    }
    else t.push_back(s[i]);
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
using namespace std;
#define NN 510
#define rep(i,j,k) for(i=j;i<=k;++i)
#define down(i,j,k) for(i=j;i>=k;--i)
struct E{
	int wh,num,pos,r,nxt;
}ed[NN*10];
int n,i,j,k,top,min;
int X[NN],N[NN],G[NN],ans[NN*NN],head[NN*NN],lst[NN];
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
void add(int wh,int u,int num){
	top++; ed[top]=(E){wh,num,u,0,head[u]}; head[u]=top;
}
int main(){
	read(n);
	rep(i,1,n){
		read(k);
		add(i,k-1,i-1);
		if((k==1) && (i-1)){
			puts("No");
			return 0;
		}
		add(i,k,i);
		if((k==n*n)&&(i!=n)){
			puts("No");
			return 0;
		}
		if(!((i==n)&&(k==n*n))) add(i,n*n,n);
		if(!((i==1)&&(k==1))) add(i,0,0);
	}
	down(i,n*n,0){
		for(j=head[i];j;j=ed[j].nxt){
			if(i!=n*n) ed[j].r=lst[ed[j].wh];
			lst[ed[j].wh]=j;
		}
	}
	rep(i,0,n*n)
	if(i==0){
	 	for(j=head[i];j;j=ed[j].nxt){
			X[ed[j].wh]=ed[ed[j].r].pos-i;
			N[ed[j].wh]=ed[ed[j].r].num-ed[j].num;
			G[ed[j].wh]=X[ed[j].wh]-N[ed[j].wh];
	 	}
	}else{
	 	min=0;
	 	rep(j,1,n)
		if(N[j]){
			if(!min) min=j;
			else if(G[min]>G[j]) min=j;
		}
		rep(j,1,n){
			X[j]--;
			if(j==min) N[j]--;
			else G[j]--;
			if(G[j]<0){
				puts("No");
				return 0;
			}
		}
		ans[i]=min;
		for(j=head[i];j;j=ed[j].nxt){
			X[ed[j].wh]=ed[ed[j].r].pos-i;
			N[ed[j].wh]=ed[ed[j].r].num-ed[j].num;
			G[ed[j].wh]=X[ed[j].wh]-N[ed[j].wh];
		}
	}
	puts("Yes");
	rep(i,1,n*n){
		if(i<n*n) printf("%d ",ans[i]);
		else printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

string a,b="",c="";
int main(void){
	cin >> a;
	int tmp = 0;
	int q;
	cin >> q;
	while(q--){
		int t;
		scanf("%d",&t);
		if(t==1) tmp++;
		else{
			int k;
			char d;
			scanf("%d\n%c",&k,&d);
			if((tmp%2)==0){
				if(k==1) b += d;
				else c += d;
			}else{
				if(k==1) c += d;
				else b += d;
			}
		}
	}
	if(tmp%2){
		reverse(c.begin(),c.end());
		reverse(a.begin(),a.end());
		string now = c + a + b;
		cout << now;
	}else{
		reverse(b.begin(),b.end());
		string now = b + a + c;
		cout << now;
	}
	return 0;
}


Measured memory_bytes: 1348
#include <iostream>
#include <math.h>
#include <strings.h>
using namespace std;

int main()
{
    int N;
    int *A,*B;
    cin >> N;
    A = new int[N];
    B = new int[N];
    int i;
    B[0]=0;
    A[0]=0;
    for(i=1;i<N;i++){
        cin >> A[i];
        B[i]=0;
    }
    for(i=0;i<N;i++){
        if (A[i]>0){
        B[A[i]-1]++;
        }
    }
    for(i=0;i<N;i++){
        cout << B[i]<< endl;
    }
    return 0;
}


Measured memory_bytes: 5160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << (min(k, n) * x + max(0, n - k) * y) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

void insertionSort(int *a, int n, int g, int *cnt){
  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;
  }
  return;
}

void shellSort(int *a, int n){
  int cnt = 0;
  int g[100] = {};
  int k = 0; g[0] = 1;
  
  while(1){
    if(g[k] <= n && 3 * g[k] + 1 > n){
      k++;
      break;
    }
    g[k + 1] = 3 * g[k] + 1;
    k++;
  }

  printf("%d\n", k);
  for(int i = 0; i < k - 1; i++) printf("%d ", g[k - 1 - i]);
  printf("1\n");

  for(int i = 0; i < k; i++){
    insertionSort(a, n, g[k - 1 - i], &cnt);
  }
  printf("%d\n", cnt);
  return;
}

int
main(int argc, char *argv[])
{
  int n, a[1000000];
  scanf("%d", &n);
  rep(i, n) scanf("%d", &a[i]);

  shellSort(a, n);
  rep(i, n) printf("%d\n", a[i]);
  return 0;
}
  



Measured memory_bytes: 5708
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int h, w, K;
	cin>>h>>w>>K;
	ll dp[8][101]={};
	K--;
	ll ct[8]={};
	ct[0]=1;
	for(int i=1; i<w; i++){
		for(int j=0; j<(1<<i); j++){
			vector<int> v;
			for(int k=0; k<i; k++){
				if(j&(1<<k)) v.push_back(k);
			}
			bool nuee=0;
			if(v.size()<=1){
				ct[i]++;
				continue;
			}
			for(int k=0; k<v.size()-1; k++){
				if(v[k+1]-v[k]==1){
					nuee=1;
					break;
				}
			}
			if(!nuee) ct[i]++;
		}
	}
	dp[0][0]=1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			ll c=ct[w-1];
			if(j>0){
				ll c1=(j==1?1:ct[j-2]), c2=(j==w-1?1:ct[w-j-2]);
				c-=(c1*c2);
				dp[j-1][i+1]+=(dp[j][i]*c1*c2);
				dp[j-1][i+1]%=MOD;
			}
			if(j<w-1){
				ll c1=(j==0?1:ct[j-1]), c2=(j+1==w-1?1:ct[w-j-3]);
				c-=(c1*c2);
				dp[j+1][i+1]+=(dp[j][i]*c1*c2);
				dp[j+1][i+1]%=MOD;
			}
			dp[j][i+1]+=(dp[j][i]*c);
			dp[j][i+1]%=MOD;
		}
	}
	cout<<dp[K][h]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;
#define MAX 300100

vector<ll> g[MAX];
ll dep[MAX];
ll fkt[MAX];
ll ans = 1;
ll n , k;
void pre(){
	fkt[0] = 1;
	for(ll i = 1; i<MAX; i++)
		fkt[i] = fkt[i-1] * i, fkt[i]%=modulo;
}
ll pow_mod(ll a, ll b){
	a = a%modulo;
	ll mx = 0;
	ll has = 1;
	for(ll i = 62; i>-1; i--){
		has*=has;
		has%=modulo;
		if(((ll)1<<i)&b)
			has*=a, has%=modulo;
	}
	return has;
}

ll inv(ll a){
	return pow_mod(a, modulo-2);
}
ll kmb(ll a, ll b){ // a choose b
	return fkt[a] * inv(fkt[a-b]) %modulo *inv(fkt[b]) %modulo;
}
void dfs(ll hd, ll pr){
	for(auto hr : g[hd]){
		if(hr == pr)
			continue;
		dep[hr] = dep[hd]+1;
		dfs(hr, hd);
	}
	ll ch = k-min((ll)2, dep[hd]+1);
//	cout<<"at "<<hd<<endl;
	if(g[hd].size() - (ll)(hd != 0) > ch)
		ans = 0;
	else{
//		cout<<" we are choosin "<<ch<<" "<<g[hd].size() - (ll)(hd != 0) <<endl;
		ans *= (fkt[ch]*inv(fkt[ch-(g[hd].size() - (ll)(hd != 0) )]) % modulo) , ans%=modulo;
	}
}


void deal(){
	pre();
	cin>>n>>k;
	fori(n-1){
		ll a, b;
		cin>>a>>b; --a, --b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0, -1);
	ans*=k;
	ans%=modulo;
	cout<<ans;
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int d = 0;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        d += l[i];
        if (d <= x) ans++;
        else break;
    }
    cout << ans << endl;
}

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

const int N = 1e5;

int n,m,k;

int par[N+5];
int sz[N+5];

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

vector<int> fri[N+5];
vector<int> ene[N+5];

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		par[i] = i;
		sz[i] = 1;
	}
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		fri[x].push_back(y);
		fri[y].push_back(x);
		int pu = find_par(x);
		int pv = find_par(y);
		if(pu == pv) continue;
		par[pu] = pv;
		sz[pv] += sz[pu];
	}
	for(int i=1;i<=k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		int pu = find_par(x);
		int pv = find_par(y);
		if(pu!=pv) continue;
		ene[x].push_back(y);
		ene[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(i>1) printf(" ");
		int pi = find_par(i);
		printf("%d",sz[pi] - fri[i].size() - ene[i].size() - 1);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 13176
import sys
def input():
    return sys.stdin.readline()[:-1]
l = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
L = [None]*N
for i in range(N):
    L[i] = int(input())

for i in range(N):
    elm = L[i]
    for j in range(3):
        for k in range(3):
            if l[j][k]==elm:
                l[j][k] = 0
for i in range(3):
    if sum(l[i])==0:
        print('Yes')
        exit()
    if (l[0][i]+l[1][i]+l[2][i])==0:
        print('Yes')
        exit()
if l[0][0]+l[1][1]+l[2][2]==0:
    print('Yes')
    exit()
if l[0][2]+l[1][1]+l[2][0]==0:
    print('Yes')
    exit()
print('No')

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

int main()
{
  string s;
  cin >> s;
  
  int ans = 1000;
  for(int i = 0; i < s.size() - 2; ++i)
  {
    int tmp = atoi(s.substr(i, 3).c_str());
    tmp = (tmp >= 753 ? tmp - 753 : 753 - tmp);
    if(ans > tmp) ans = tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  
  int h,v;
  cin>>h>>v;
  if(h==1||v==1)
    cout<<1<<endl;
 else if((h*v)%2==0)
    cout<<(h*v)/2<<endl;
    else
    cout<<(h*v+1)/2<<endl;
  
}

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

int main() {
    ll x;
    cin>>x;
    ll judge = 0;
    for(ll i=-1000;i<1000;i++){
        for(ll j=-1000;j<1000;j++){
            ll i5 = pow(i,5);
            ll j5 = pow(j,5);
            if(i5-j5 == x){
                cout<<i<<" "<<j<<endl;
                judge = 1;
                break;
            }
        }
        if(judge == 1){
            break;
        }
    }
}

Measured memory_bytes: 4064
#include<iostream>
#include<string>

using namespace std;

int main(void){
    string S;
    string ans;
    cin >> S;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'B'){
            if(ans.length() > 0){
                ans.resize(ans.size() - 1);
            }
        }else{
            ans.push_back(S[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int mod = 1000000007;
constexpr int inf = 1e9;
int n, a, b, u, m;
int main(){
	cin>>n>>m;
	vector<int> h(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>h[i];
	}
	vector<int> g(n, 0);
	for(int i = 0; i < m; ++i){
		cin>>a>>b;
		a--, b--;
		if(h[b] > g[a])g[a] = h[b];
		if(h[a] > g[b])g[b] = h[a];
	}
	u = 0;
	for(int i = 0; i < n; ++i){
		if(g[i] < h[i])u++;
	}
	cout<<u<<endl;					   
	return 0;
}


Measured memory_bytes: 4048
package main

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

func main() {
  const mod int64 = 1000000007
  input := Input{bufio.NewReaderSize(os.Stdin,1000)}
  n,m := input.NextInts()
  a := make(map[int]struct{})
  for i:=0;i<m;i++ { a[input.NextInt()] = struct{}{} }
  dp := make([]int64,n+1)
  dp[0],dp[1] = 1,1
  if _,ok := a[1];ok { dp[1] = 0 }
  for i:=2;i<n+1;i++ {
    if _,ok := a[i];ok { continue }
    dp[i] = (dp[i-1]+dp[i-2])%mod
  }
  fmt.Println(dp[n])
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  x,_ := strconv.Atoi(i.NextLine())
  return x
}
func(i *Input) NextInts() (int,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 4736
//
// Created by ?????°?????? on 2016/03/19.
//

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

struct point { double x,y;};

void koch(int n,point a,point b){
    if(n == 0) return;
    point s,t,u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1,a,s);
    cout <<  setprecision(9) << s.x << " " << setprecision(9) << s.y << endl;
    koch(n-1,s,u);
    cout <<  setprecision(9) << u.x << " " <<  setprecision(9) << u.y << endl;
    koch(n-1,u,t);
    cout <<  setprecision(9) << t.x << " " <<  setprecision(9) << t.y << endl;
    koch(n-1,t,b);
}

int main (){
    point a,b;
    int n;

    cin >> n;
    a.x = 0; a.y = 0;
    b.x = 100; b.y = 0;

    cout << setprecision(9) << a.x << " " <<  setprecision(9) << a.y << endl;
    koch(n,a,b);
    cout << setprecision(9) << b.x << " " <<  setprecision(9) << b.y << endl;
    return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll h,n;
pii p[1001];
ll dp[200001],mm=200001;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,k,ans,a,b,g,mc,mh;
    	cin>>h>>n;
    	mc=mod; mh=0; vec v;
    	rep(i,0,n)
    	{
    		cin>>a>>b;
    		p[i].F=a; p[i].S=b;
    		if(b<mc)
    		{
    			mc=b; mh=a;
			}
		}
    	repi(i,0,mm)
    	dp[i]=mod;
    	dp[0]=0;
    	repi(i,1,mh)
    	dp[i]=mc;
    	repi(i,1,mm)
    	{
    		rep(j,0,n)
    		{
    			a=p[j].F; b=p[j].S;
    			if(i>=a)
    			dp[i]=min(dp[i],dp[i-a]+b);
			}
		}
		ans=mod;
		rep(i,h,mm)
		ans=min(ans,dp[i]);
		cout<<ans;
    } 
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
#define min(a,b) (a>b?b:a)
#define MAX 1010
#define INF 12345678

int N, a[MAX], w[MAX], used[11]={1,};

int huga(int t, int y){
	int dis = 0;
	if(!a[t]&&a[y]) dis += w[t];
	if(a[y]&&!a[t]) dis += w[y];
	return dis;
}

int solve(int z){//cout<<z<<endl;
	int ans = INF, count = 0;
	
	for(int i = 0; i < N; i++){
		if(used[i]) continue;
		used[i] = true;
		ans = min(ans,solve(i)+huga(z,i));
		used[i] = false;
		count++;
	}//cout<<z<<" "<<ans<<" "<<count<<endl;
	if(count == 0) return huga(z,0);
	return ans;
}

int main(){
	cin>>N;
	for(int i = 0; i < N; i++)cin>>a[i];
	for(int i = 0; i < N; i++)cin>>w[i];
	
	cout<<solve(0)<<endl;
	return 0;
}

/*
5
1 0 0 1 0
2 3 5 1 2

3
0 0 0
1 2 3
*/


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

#define SZ(v) ((int)(v).size())
using ll = long long;

ll solve(void);

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int nb_tests;
	cin >> nb_tests;

	for (int i(0); i < nb_tests; ++i)
		solve();
}

const int MAXP = 60;
vector<ll> val;
string joueurs;

ll solve(void)
{
	int nbTours;
	cin >> nbTours;
	val.clear();
	val.resize(nbTours);
	for (auto &v : val)
		cin >> v;

	cin >> joueurs;
	vector<ll> base(MAXP);
	for (int i(nbTours-1); i >= 0; --i)
	{
		if (joueurs[i] == '0')
		{
			ll cur = val[i];
			for (int j(MAXP-1); j >= 0; --j)
				if ((1LL<<j) & cur)
				{
					if (base[j])
						cur ^= base[j];
					else
					{
						base[j] = cur;
						break;
					}

				}
		}
		else
		{
			ll cur = val[i];
			for (int j(MAXP-1); j >= 0; --j)
				if ((1LL<<j) & cur)
					cur ^= base[j];
			if (cur)
			{
				cout << 1 << '\n';
				return 0;
			}

		}
	}

	cout << 0 << '\n';
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

typedef struct {
    int p;
    int y;
    int order;
    int id;
} City;

bool cmp(const City& a, const City& b) {
    if (a.p == b.p)
        return a.y < b.y;
    return a.p < b.p;
}

signed main() {
    int n, m;
    cin >> n >> m;
    vector<City> v(m);
    for (int i = 0; i < m; i++) {
        int p, y;
        cin >> p >> y;
        v[i] = City{p, y, i, 0};
    }
    sort(v.begin(), v.end(), cmp);
    int current_p = 0;
    int ord_in_p = 0;
    for (auto && x : v) {
        if (x.p != current_p) {
            current_p = x.p;
            ord_in_p = 0;
        }
        ord_in_p++;
        x.id = ord_in_p;
    }
    sort(v.begin(), v.end(), [](const City& a, City& b) {
        return a.order < b.order;
    });
    for (auto && x : v) {
        printf("%06lld%06lld\n", x.p, x.id);
    }
}

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

int main(){
    int n;
    cin >> n;
    int s[n];
    for(int i=0;i<n;i++)cin >> s[i];
    int q;
    cin >> q;
    int t[q];
    for(int i=0;i<q;i++)cin >> t[i];
    sort(t,t+q);
    int count=0;
    int left=0,right,m;
    for(int i=0;i<q;i++){
        right = n-1;
        m = (left+right)/2;
        while(left <= right){
            if(s[m]==t[i]){
                count++;
                left=m+1;
                break;
            }
            else if(s[m] >t[i]){
                right = m-1;
            }
            else{
                left =m+1;
            }
            m=(left+right)/2;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3592
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int a=Integer.parseInt(br.readLine());
        pw.println(a+a*a+a*a*a);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 32684
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int);
int pop(void);
void isEmpty();
void isFull();
int hantei(char *);
void mozi(char *);
int toridashi(char *);

char S[100];
int Stack[100];
int top=0;

int main(){
  int a,b,c,i=0,x;
  while(scanf("%s", S) != EOF){
    if(S[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(S[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(S[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
      x=atoi(S);
      push(x);
    }
  }

  printf("%d\n",pop());


  return 0;
}

void push(int c){

  Stack[++top]=c;
}

int pop(){
  top--;
  return Stack[top+1];
}

Measured memory_bytes: 548
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

class Main {
    public static void main(String[] args) throws IOException {
        // Solution sol = new Solution();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int[] a = new int[n];
        st = new StringTokenizer(br.readLine());
        for (int i=0; i<n; i++)
            a[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(a);
        long ans = a[n-1];
        double j=n-2;
        for (int i=2; i<n; i++){
            ans+=a[(int)Math.ceil(j)];
            j-=0.5;
        }
        System.out.println(ans);
    }



}

Measured memory_bytes: 56152
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n, x;
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		a[x + 1]++;
	}
	int ans = 0;
	for (int i = 0; i <= 100000; i++) {
		ans = max(ans, a[i] + a[i + 1] + a[i + 2]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

int main()
{
	ll n,ans=0;
	string s ;

	cin >> s;
		
	if (s == "ABC")
	{
		s = "ARC";
	}
	else
	{
		s = "ABC";
	}

	cout << s;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    int D = X * Y, E = K * Z;
    vector<long long> a(X), b(Y), c(Z), d(D), ans(E);
    rep(i, 0, X)
    {
        cin >> a[i];
    }
    rep(i, 0, Y)
    {
        cin >> b[i];
    }
    rep(i, 0, Z)
    {
        cin >> c[i];
    }
    int p = 0;
    rep(i, 0, X)
    {
        rep(j, 0, Y)
        {

            d[p++] = a[i] + b[j];
        }
    }
    p = 0;
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    rep(i, 0, min(K, D))
    {
        rep(j, 0, Z)
        {
            ans[p++] = d[i] + c[j];
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    rep(i, 0, K)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 31616
n, k = map(int, input().split())
A = list(map(int, input().split()))

seen = {1: 0}
a = 1

for i in range(1, n+1):
  if seen.setdefault(a:=A[a-1], i) != i:
    break

p = seen[a]         # cycle offset
q = i - seen[a]     # cycle length

assert q > 0
# print(f'{p = }, {q = }, {i = }, {seen = }')

if k >= p+q:
  k = (k - p) % q + p

a = 1
for i in range(k):
  a = A[a-1]

print(a)

Measured memory_bytes: 38744
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, c;
	cin >> n >> c;
	vector<pll>  v(n + 2);
	REP(i, n)cin >> v[i + 1].first >> v[i + 1].second;
	v[0] = { 0,0 };
	v[n + 1] = { c,0 };
	vl a(n + 1), b(n + 1);
	a[0] = 0;
	b[n] = 0;
	REP(i, n) {
		a[i + 1] = a[i] + v[i + 1].second - (v[i + 1].first - v[i].first);
	}
	vl ma(n + 1), mb(n + 1);
	ma[0] = 0;
	mb[n] = 0;
	REP(i, n)ma[i + 1] = max(ma[i], a[i + 1]);
	RREP(i, n) {
		b[i] = b[i + 1] + v[i + 1].second - (v[i + 2].first - v[i + 1].first);
	}
	RREP(i, n)mb[i] = max(mb[i+1], b[i]);
	ll ans = 0;
	REP(i, n) {
		ans = max(ans, max(a[i + 1], a[i + 1] - v[i + 1].first + mb[i + 1]));
	}
	REP(i, n) {
		ans = max(ans, max(b[i], b[i] - (c - v[i + 1].first) + ma[i]));
	}
	cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> vp;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vp.push_back(make_pair(b, a));
  }

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

  int tm = 0;
  string ans = "Yes";
  for (auto q : vp) {
    tm += q.second;
    if (tm > q.first) {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5284
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define foreach(a,A) for(auto &a:A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll n; cin >> n;
    string S = to_string(n);
    reverse(S.begin(), S.end());
    if(S[0] == '3'){
        cout << "bon" << endl;
    } else if(S[0] == '0' or S[0] == '1' or S[0] == '6' or S[0] == '8'){
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

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

int main(){
  string S;
  cin >> S;
  int Ans=0;
  for(int i=0; i<S.size()/2; i++){
    if(S.at(i)!=S.at(S.size()-1-i)){
      Ans++;
    }
  }
  cout << Ans << endl;
}

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

int main() {
  char S[15];
  cin >> S;

  int N = strlen(S);
  int cindex = 0;
  int ucount = 0;
  for (int i = 1; i < N; ++i) {
    if (S[i] == 'C') cindex = i;
    if (isupper(S[i])) ++ucount;
  }

  if (S[0] == 'A' &&
      2 <= cindex &&
      cindex <= N-2 &&
      ucount == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
N, K = map(int, input().split())
xlist = list(map(int, input().split()))

d = []
for i in range(N - K + 1):
    left = xlist[i]
    right = xlist[i + K - 1]
    if right < 0:
        tmp_d = - left
    elif left > 0:
        tmp_d = right
    else:
        tmp_d = 2 * min(-left, right) + max(-left, right)
    d.append(tmp_d)

print(min(d))


Measured memory_bytes: 14252
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    An = [int(x) for x in input().strip().split()]
    ans = 1
    limit = 10 ** 18
    if 0 in An:
        print(0)
        exit()
    for a in An:
        ans *= a
        if ans > limit:
            print(-1)
            exit()
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21576
#include<bits/stdc++.h>
using namespace std;
const int N=262145;
int n,a[N],x,y;
int main()
{
	for(int i=1;i<=1000;i++)
	  a[i]=a[i-1]+i;
	cin>>x>>y;
	cout<<a[y-x]-y;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    ans = [0, 0]
    for i in s:
        ans[0] |= i == "C"
        ans[1] |= i == "F" and ans[0]
    print("Yes" if ans[1] else "No")
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){

    int N;
    cin >> N;
    vector<int> b(N);
    rep (i, N) cin >> b[i];

    vector<int> ans;
    rep (i, N){
        for (int j = b.size(); j != 0; j--){
            if (j == b[j-1]){
                ans.push_back(j);
                b.erase(b.begin()+j-1);
                break;
            }
        }
    }

    reverse(ans.begin(), ans.end());
    if (ans.size() == N) rep (i, N) cout << ans[i] << endl;
    else cout << "-1" << endl;

    return 0;
}

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

int main(){
	int N, i, j, k;
	scanf("%d", &N);
	N = (1 << N);
	vector<int> S(N);
	for(i = 0; i < N; i++){
		scanf("%d", &S[i]);
		S[i] *= -1;
	}
	for(i = 1; i < N; i <<= 1){
		sort(S.begin(), S.begin() + i);
		sort(S.begin() + i / 2 * 2, S.end());
		for(j = 0, k = i; j < i; swap(S[i + j++], S[k])){
			while(S[j] >= S[k]){
				if(++k == N){
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1280