akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())

p = list(map(int, input().split()))

for i in range(n):
	p[i] -= 1

current_pos = 0
steps = 0
first_occurence = {}

result = -1

while steps < k:
	if current_pos in first_occurence:
		first = first_occurence[current_pos]
		cycle_length = steps - first
		left = (k - steps) % cycle_length
		x = 0
		while x < left:
			current_pos = p[current_pos]
			x += 1

		result = current_pos
		break
	else:
		first_occurence[current_pos] = steps
		steps += 1
		current_pos = p[current_pos]

if result == -1:
	result = current_pos

print(current_pos + 1)



Measured memory_bytes: 110676
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 200050
typedef long long ll;
int head[N],to[N<<1],nxt[N<<1],cnt,n,siz[N];
int mx[N],se[N],d[N];ll ans;
char w[N];
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
void d1(int x,int y) {
	int i;
	siz[x]=w[x]-'0'; d[x]=w[x]=='0'?(1<<30):0;
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
		d1(to[i],x);
		siz[x]+=siz[to[i]];
		int v=mx[to[i]]+1;
		if(v>mx[x]) se[x]=mx[x],mx[x]=v;
		else if(v>se[x]) se[x]=v;
		if(siz[to[i]]) d[x]=min(d[x],v);
	}
}
void d2(int x,int y) {
	int i;
	int R=min(se[x]+1,mx[x]-1);
	if(d[x]<=R)ans+=R-d[x]+1;
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
		int v=(mx[to[i]]+1==mx[x])?(se[x]+1):(mx[x]+1);
		if(v>mx[to[i]]) se[to[i]]=mx[to[i]],mx[to[i]]=v;
		else if(v>se[to[i]]) se[to[i]]=v;
		if(siz[1]-siz[to[i]]>0) d[to[i]]=min(d[to[i]],v);
		d2(to[i],x);
	} 
}
int main() {
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	scanf("%s",w+1);
	d1(1,0); d2(1,0);
	printf("%lld\n",ans+1);
	return 0;
}


Measured memory_bytes: 14592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  long long  A[100003]={};
  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
  num=a;
  while((num/10!=0)){
    num=num/10;
    cnt++;
 //    printf("%d %d\n",num, cnt);  
  }
  if(cnt==5) ans = a- 9091;
  else if(cnt==4) ans = a-9090;
  else if(cnt==3) ans = 909;
  else if(cnt==2) ans = a-90;
  else if(cnt==1) ans = 9;
  else if(cnt==0) ans = a;
      
  printf("%d\n",ans);
 
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


Measured memory_bytes: 128
def abc081_c():
    from collections import Counter
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    a_count = Counter(a)
    if len(a_count) <= k:
        print(0)
    else:
        val = list(a_count.values())
        val.sort()
        print(sum(val[:-k]))


abc081_c()

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

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

map<int,int> mochi;

rep(i,n)
{int a;
  cin>>a;
  mochi[a]=a;
  }

cout << mochi.size()<<endl;




return 0;

}

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

using namespace std;

int main(){
  int i, j, x, n;
  vector<int>::iterator it, it1, it2;

  const vector<int> _data;
  vector<vector<int> > data(3, _data);

  cin >> n;
  vector<int> ans(n, 0);

  for(i=0; i<n; ++i){
    for(j=0; j<3; ++j){
      cin >> x;
      data[j].push_back(x);
    }
  }

  for(i=0; i<data.size(); ++i){
    for(j=0, it=data[i].begin(); it!=data[i].end(); ++j, ++it){
      it1 = find(data[i].begin(), data[i].end(), *it);
      if(it1 != it) continue;
      it2 = find(it1 + 1, data[i].end(), *it);
      if(it2 != data[i].end()) continue;
      ans[j] += *it;
    }
  }

  for(i=0; i<ans.size(); ++i) cout << ans[i] << endl;
  return 0;
}

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

typedef long long ll;

#define REP(i, n) for (int (i) = 0; (i) < (n); ++(i));
using namespace std;

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

ll GCD(ll a, ll b){

  ll tmp, r;

  if (a == 0 && b != 0){return b;}
  else if (a != 0 && b == 0){return a;}

  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return b;

}

int main(void){

  ll N;
  cin >> N;

  vector<ll> A(N);

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

  vector<ll> L(N + 1),R(N + 1), M(N + 1);
  L.at(0) = 0;
  R.at(N) = 0;

  for (int i = 1; i <= N; ++i){
    L.at(i) = GCD(L.at(i - 1), A.at(i - 1));
    int ind = N - i;
    R.at(ind) = GCD(R.at(ind + 1), A.at(ind));
  }

  for (int i = 0; i < N; ++i){
    M.at(i) = GCD(L.at(i), R.at(i + 1));
  }

  cout << *std::max_element(M.begin(), M.end()) << endl;



  return 0;
}



Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#define ll long long 
using namespace std;

int main()
{
	ll a, b,sum=0;
	cin >> a >> b;
	ll* arr = new ll[a];
	for (int i = 0; i < a; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + a);
	for (int i = 0; i < b; i++)
	{
		sum += arr[i];
	}

	cout << sum << endl;







}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string S,R;
    cin>>S;
    R = S;
    reverse(ALL(R));
    if (S == R) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
a = []
pts = []
for i in range(m):
    la, lb = na()
    a.append(la)
    pt = 0
    for x in na():
        pt |= 1<<x-1
    pts.append(pt)

price = [99999999999999999] * (1<<n)
for i in range(m):
    price[pts[i]] = min(price[pts[i]], a[i])

dp = [9999999999999999] * (1<<n)
dp[0] = 0
for i in range(1<<n):
    if price[i] <= 100000:
        for j in range(1<<n):
            dp[j|i] = min(dp[j|i], dp[j] + price[i])
if dp[(1<<n)-1] >= 100000000:
    print(-1)
else:
    print(dp[(1<<n)-1])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x; cin>>n>>x;
    vector<int> m(n);
    for(int i=0; i<n; i++){cin>>m.at(i); x-=m.at(i);}
    sort(m.begin(),m.end());
    n+=x/m.at(0);
    cout<<n<<endl;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  int n, tmp;
  cin >> n;
  vector<int> a(n);
  int now = 1, ret = 0;
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    if (tmp == now) {
      now++;
    } else {
      ret++;
    }
  }

  cout << (ret == n ? -1 : ret) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;

    int maxValue = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        maxValue = max(maxValue, p);
        sum += p;
    }

    cout << sum - maxValue / 2;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
const int nmax = 8;
bool graph[nmax][nmax];
 
int dfs(int v,int N,bool visited[nmax]){
  bool all_visited = true;
  for(int i = 0;i<N;++i){
    if(visited[i] == false){
      all_visited = false;
      break;
    }
  }
  
  if(all_visited){
    return 1;
  }
  
  int ret = 0;
  for(int i = 0; i<N;++i){
    if(graph[v][i] == false) continue;
    if(visited[i] == true) continue;
    
    visited[i] = true;
    ret+=dfs(i,N,visited);
    visited[i] = false;
  }
  
  return ret;
}
 
int main(){
  int N,M;
  cin >> N >> M;
  int a,b;
  for(int i=0;i<M;++i){
    cin >> a >> b;
    a--;
    b--;
    graph[a][b] = graph[b][a] = true;
  }
  
  bool visited[nmax];
  for(int i = 0; i < nmax ; ++i){
    visited[i] = false;
  }
  
  visited[0] = true;
  
  cout << dfs(0,N,visited) << endl;
  return 0;
 
}

Measured memory_bytes: 256
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  [<EntryPoint>]
  let main _ =
    let s = Console.ReadLine()
    (if s |> Seq.distinct |> Seq.length = s.Length then "yes" else "no") |> printfn "%s"
    0


Measured memory_bytes: 12892
# include <iostream>

using namespace std;

int a[10010];
int g[110][110];

int main()
{
	int h , w;
	cin >> h >> w;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	int x = 1;
	for(int i = 1; i <= h; i++)
	{
		if(i % 2 == 1)
		{
			for(int j = 1; j <= w; j++)
			{
				if(a[x] > 0)
				{
					g[i][j] = x;
					a[x]--;
				}
				else
				{
					x++;
					g[i][j] = x;
					a[x]--;
				}
			}
		}
		else
		{
			for(int j = w; j > 0; j--)
			{
				if(a[x] > 0)
				{
					g[i][j] = x;
					a[x]--;
				}
				else
				{
					x++;
					g[i][j] = x;
					a[x]--;
				}
			}
		}
	}
	for(int i = 1; i <= h; i++)
	{
		for(int j = 1; j <= w; j++)
		{
			cout << g[i][j] << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int max_n=1e7+10;
typedef long long ll;
int num[max_n];
int prime_num[max_n];
int snum[max_n];
void init()
{
    for(int i=2;i<max_n;i++){
		if(num[i]==0){
	  		num[++num[0]]=i;
	  		snum[i] = 2;
	  		prime_num[i] = 1;
        }
        for(int j = 1; j <=num[0] ; j++){
            if(i * num[j] > max_n) break;
            num[i * num[j]]=1;
            if(i % num[j]==0){
                prime_num[i * num[j]]=prime_num[i] + 1;
                snum[i * num[j]] = snum[i] / (prime_num[i] + 1) * (prime_num[i] + 2);
                break;
            }else{
                snum[ i * num[j] ] = snum[i] * snum[num[j]];
                prime_num[ i * num[j] ] = 1;
            }
        }
	}
}
int main(){
	init();

    ll n;
    scanf("%lld",&n);
    ll ans=0;
    snum[1]=1;
    for(int i=1;i<=n;++i)
    {
        ans+=1ll*i*snum[i];
    }
    cout<<ans<<endl;



}


Measured memory_bytes: 120944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
string s,t;
cin>>s>>t;
int a=s.size(),ans=0;
for (int i = 0; i < a; i++)
{
    if (s.at(i)!=t.at(i))
    {
        ans++;
    }
    
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3832
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,x,*a=map(int,open(0).read().split())\n"
"a=[0]+a\n"
"c=0\n"
"for i in range(n):\n"
"  c+=max(0,a[i+1]+a[i]-x)\n"
"  a[i+1]=min(a[i+1],x-a[i])\n"
"print(c)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 14504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
int N,M,K;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];

ll mymod(ll a,ll b){
    a%=MOD;
    ll result=1;
    while(b>0){
        if(b&1){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return result;
    
}
ll modInverse(ll n){
    return mymod(n,MOD-2);
}

void init_combination(){
    const int MAX = 10000002;   //1e6+2
    Factorial[0]=1;
    inv[0]=1;
    for(int i=1;i<=MAX;i++){
        Factorial[i]=(Factorial[i-1]*i)%MOD;
    }
    FactorialInv[MAX]=modInverse(Factorial[MAX]);
    for(int i=MAX-1;i>=0;i--){
        FactorialInv[i]=FactorialInv[i+1]*(i+1)%MOD;
    }
    for(int i=1;i<=MAX;i++){
        inv[i]=(FactorialInv[i]*FactorialInv[i-1])%MOD;
    }
}

ll combination(ll n,ll k){
    if(n==k||k==0){
        return 1;
    }
    if(n<k){
        return 0;
    }
    ll ans=(Factorial[n]*FactorialInv[k])%MOD;
    ans=(ans*FactorialInv[n-k])%MOD;
    return ans;
}
void solve(){
    cin>>N>>M>>K;
    init_combination();
    ll ans=combination(N*M-2,K-2);
    ll sum=0;
    for(ll i=1;i<M;i++){
        ll now=M-i;
        now=(now*N*N)%MOD;
        now=now*i%MOD;
        sum=(sum+now)%MOD;
    }
    for(int i=1;i<N;i++){
        ll now=N-i;
        now=(now*M*M)%MOD;
        now=(now*i)%MOD;
        sum=(sum+now)%MOD;
    }
    sum=(sum*ans)%MOD;
    out(sum);


}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 234752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define db double
#define mp make_pair
#define X first
#define Y second
#define FR first
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<(a).size();++i)
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
#define gc getchar
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const ll inf=1ll<<60;
int tt,cc,S,T;
namespace F
{
	const int N=1010;
	int hd[N],q[N*N],vis[N],pre[N],iter[N];ll d[N];
	struct E{int v,nxt;ll w,c;}e[100000];
	inline void add(int u,int v,ll w,ll c)
	{
		e[++cc]=(E){v,hd[u],w,c};hd[u]=cc;
		e[++cc]=(E){u,hd[v],0,-c};hd[v]=cc;
	}
	inline bool spfa()
	{
		rep(i,0,tt)d[i]=inf,pre[i]=0,vis[i]=0,iter[i]=hd[i];
		int ql=0,qr=0;q[++qr]=S;d[S]=0;vis[S]=1;
		while(ql<qr)
		{
			int x=q[++ql];vis[x]=0;
			for(int i=hd[x],y;i;i=e[i].nxt)if(e[i].w&&d[y=e[i].v]>d[x]+e[i].c)
			{
				d[y]=d[x]+e[i].c;pre[y]=i;
				if(!vis[y]){q[++qr]=y;vis[y]=1;}
			}
		}
		return d[T]<inf;
	}
	ll dfs(int x,ll f)
	{
		if(x==T)return f;ll sf=0;vis[x]=1;
		for(int&i=iter[x];i;i=e[i].nxt)if(e[i].w&&d[e[i].v]==d[x]+e[i].c&&!vis[e[i].v])
		{
			ll w=dfs(e[i].v,min(f-sf,e[i].w));
			e[i].w-=w;e[i^1].w+=w;sf+=w;vis[e[i].v]=w==0;
			if(sf==f)break;
		}
		vis[x]=0;return sf;
	}
	void flw(vector<pll>&p)
	{
		while(spfa())
		{
			ll sf=dfs(S,inf);p.pb(mp(d[T],sf));if(sf>(1ll<<50))break;
//			ll w=inf;for(int x=T;x!=S;x=e[pre[x]^1].v)w=min(w,e[pre[x]].w);p.pb(mp(d[T],w));
//			for(int x=T;x!=S;x=e[pre[x]^1].v)e[pre[x]].w-=w,e[pre[x]^1].w+=w;if(w>(1ll<<50))break;
		}
	}
}
const int N=35;
int n,m,o[N][N],c[N];
struct st{int s,p;ll c;}a[N][N];
inline bool cmp(st a,st b){return a.s<b.s;}
int main()
{
	n=rd();
	rep(i,1,n)
	{
		c[i]=rd();rep(j,1,c[i])a[i][j]=(st){rd(),rd(),rd()};
		sort(a[i]+1,a[i]+c[i]+1,cmp);
	}
	S=1;T=2;tt=2;cc=1;
	rep(i,1,n)
	{
		o[i][0]=S;o[i][c[i]]=T;
		rep0(j,1,c[i])o[i][j]=++tt;
		rep(j,1,c[i])
		{
			F::add(o[i][j-1],o[i][j],a[i][j].p,0);
			F::add(o[i][j],o[i][j-1],inf,0);
			F::add(o[i][j-1],o[i][j],inf,a[i][j].c);
		}
	}
	m=rd();
	while(m--)
	{
		int u=rd(),v=rd(),w=rd();
		for(int j=1,k=1;j<=c[v];j++)
		{
			while(k<=c[u]&&a[u][k].s+w<a[v][j].s)k++;
			F::add(o[v][j-1],o[u][k-1],inf,0);
		}
	}
	vector<pll>p;p.clear();F::flw(p);m=rd();
	vector<pll>q;q.clear();ll x=0,y=0;
	fore(i,p){q.pb(mp(x,y));x+=p[i].Y;y+=p[i].X*p[i].Y;}
	while(m--)
	{
		ll A=rd();int x=lb(p.begin(),p.end(),mp(A,-inf))-p.begin();
		if(x==p.size())puts("-1");else printf("%lld\n",q[x].X*A-q[x].Y);
	}
	return 0;
}


Measured memory_bytes: 4700
#include<iostream>
#include<vector>

using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;


int main() {
	int n;
	ll l;
	cin >> n >> l;
	vl A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int P = -1;
	for (int i = 0; i < n - 1; i++) {
		if (A[i] + A[i + 1] >= l) {
			P = i;
			break;
		}
	}
	if (P < 0) {
		cout << "Impossible" << endl;
		return 0;
	}
	else {
		cout << "Possible" << endl;
		P++;
		for (int i = n - 1; i > P; i--) {
			cout << i << endl;
		}
		for (int i = 1; i < P; i++) {
			cout << i << endl;
		}
		cout << P << endl;
		return 0;
	}
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,l; cin>>n>>l;
  
  ll sum=0;
  reps(i,n){
    sum+=l+i-1;
  }
  ll d=INF;
  ll ans=sum;
  reps(i,n){
    if(chmin(d,abs(sum-(sum-(l+i-1))))){
      ans=sum-(l+i-1);
    }
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <limits>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

int const inf = 1<<29;

typedef long long ll;

namespace flow {

struct edge {
  int to, cap, cost, rev;
  edge(int t, int ca, int co, int r) : to(t), cap(ca), cost(co), rev(r) {}
};

struct primal_dual {

  vector<vector<edge>> G;
  vector<int> h;
  vector<int> dist;
  vector<int> prevv, preve;

  primal_dual(int V) : G(V), h(V), dist(V), prevv(V), preve(V) {}

  void add_edge(int from, int to, int cap, int cost) {
    G[from].emplace_back(to, cap, cost, G[to].size());
    G[to].emplace_back(from, 0, -cost, G[from].size()-1);
  }

  int min_cost_flow(int s, int t, int f) {
    int ret = 0;
    fill(h.begin(), h.end(), 0);
    while(f > 0) {
      typedef pair<int, int> P;
      priority_queue<P, vector<P>, greater<P>> pq;
      fill(dist.begin(), dist.end(), inf);
      dist[s] = 0;
      pq.emplace(0, s);
      while(!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;
        if(dist[v] < p.first) { continue; }
        for(int i=0; i<G[v].size(); i++) {
          auto& e = G[v][i];
          if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            pq.emplace(dist[e.to], e.to);
          }
        }
      }

      if(dist[t] == inf) { return -1; }
      for(int i=0; i<h.size(); i++) h[i] += dist[i];

      int d = f;
      for(int i=t; i!=s; i=prevv[i]) {
        d = min(d, G[prevv[i]][preve[i]].cap);
      }
      f -= d;
      ret += d * h[t];
      for(int i=t; i!=s; i=prevv[i]) {
        auto& e = G[prevv[i]][preve[i]];
        e.cap -= d;
        G[i][e.rev].cap += d;
      }
    }
    return ret;
  }

};

}

int main() {

  int A, B, K; cin >> A >> B >> K;
  vector<string> a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];

  flow::primal_dual pd(A + B + 2);

  int const s = A + B;
  int const t = s + 1;

  rep(i, A) pd.add_edge(s, i, 1, 0);
  rep(i, B) pd.add_edge(i+A, t, 1, 0);

  rep(i, A) rep(j, B) {
    int cost = 0;
    if(a[i][j] == '1') { cost ++; }
    if(b[j][i] == '1') { cost ++; }
    pd.add_edge(i, A + j, 1, cost);
  }

  int l = 0, r = min(A, B) + 1;
  while(r - l > 1) {
    int m = (l + r) / 2;
    auto cpd = pd;
    if(cpd.min_cost_flow(s, t, m) <= K) { l = m; }
    else { r = m; }
  }

  cout << l << endl;

  return 0;
}

Measured memory_bytes: 6052
import std.stdio,std.string,std.conv,std.array;

int main()
{
	while(true)
	{
		string[] s = readln.chomp.split(" ");
		int a[3];
		a[0] = s[0].to!int;
		a[1] = s[1].to!int;
		a[2] = s[2].to!int;

		if(a[0] == 0 && a[1] == 0 && a[2] == 0)
		{
			break;
		}

		a.sort;

		int d = a[0]*a[0] + a[1]*a[1];

		int n = readln.chomp.to!int;
		while(n--)
		{
			int r = readln.chomp.to!int;
			if(d < (r*2)*(r*2))
			{
				"OK".writeln;
			}
			else
			{
				"NA".writeln;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(){
  int w,h,n; cin >> w >> h >> n;
  vector<int> xmax(h+1); xmax[h]=0;
  for(int i=0;i<n;++i){
    int x,y;
    cin >> x >> y;
    xmax[y]=max(xmax[y],x);
  }
  int ans=1e9,maxi=0;
  for(int i=h-1;i>=0;--i) {
    maxi=max(maxi,xmax[i+1]);
    ans=min(ans,maxi+i);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, ma, mb, a[40], b[40], c[40], dp[401][401];

int main() {
  cin >> n >> ma >> mb;
  for (lli i=0; i<n; ++i) cin >> a[i] >> b[i] >> c[i];
  for (lli j=0; j<=400; ++j) {
    for (lli i=0; i<=400; ++i) {
      dp[j][i] = 1e10;
    }
  }
  dp[0][0] = 0;
  for (lli i=0; i<n; ++i) {
    for (lli xa=400; xa >= a[i]; --xa) {
      for (lli xb=400; xb >= b[i]; --xb) {
        dp[xa][xb] = min(dp[xa][xb], dp[xa-a[i]][xb-b[i]] + c[i]);
      }
    }
  }
  lli ans = 1e10;
  for (lli xa = ma, xb = mb; xa <= 400 && xb <= 400; xa += ma, xb += mb) {
    ans = min(ans, dp[xa][xb]);
  }
  cout << (ans < 1e10 ? ans : -1) << '\n';
  return 0;
}



Measured memory_bytes: 1536
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 1e5 + 5, M = 998244353; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(3) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//

void solve() {
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ABC170B
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int X,Y;
    cin>>X>>Y;
    int mx=Y/4;
    for (int t=0; t<=mx; t++) {
        int c_leg_num=Y-4*t;
        int c=(X-t);
        if (c_leg_num==2*c) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

const int maxn(2e5 + 5);

int l, a[maxn];
ll ans = 1e18, presum[maxn], sufsum[maxn], preval[maxn], midval[maxn], sufval[maxn], minpre[maxn], minsuf[maxn], mx, mn;

int main() {
	int i;
	scanf("%d", &l);
	for (i = 1; i <= l; ++i) {
		scanf("%d", &a[i]);
		midval[i] = midval[i - 1] + (~a[i] & 1);
		preval[i] = preval[i - 1] + (a[i] < 2 ? 2 - a[i] : (a[i] & 1));
		presum[i] = presum[i - 1] + a[i];
	}
	for (i = l; i; --i) {
		sufval[i] = sufval[i + 1] + (a[i] < 2 ? 2 - a[i] : (a[i] & 1));
		sufsum[i] = sufsum[i + 1] + a[i];
	}
	for (mx = 0, i = 1; i <= l; ++i) mx = max(mx, preval[i] - presum[i]), minpre[i] = preval[i] - mx;
	for (mx = 0, i = l; i; --i) mx = max(mx, sufval[i] - sufsum[i]), minsuf[i] = sufval[i] - mx;
	for (mn = 0, i = 0; i <= l; ++i) {
		mn = min(mn, minpre[i] - midval[i]);
		ans = min(ans, mn + midval[i] + minsuf[i + 1]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

vector<int> g[100005];
vector<int> res[100001];

int dp(int x){
    if(g[x].empty()) return 0;

    REP(i, g[x].size()) res[x].push_back(dp(g[x][i]));
    sort(all(res[x]), greater<>());

    int ret = 0;
    REP(i, res[x].size()) chmax(ret, res[x][i] + i + 1);

    return ret;
}

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

    for(int i = 2; i <= N; i++) {
        int a;
        cin >> a;

        g[a].push_back(i);
    }

    cout << dp(1) << endl;

    return 0;
}


Measured memory_bytes: 18944
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int N = 20;
const int K = 17712;
const ll mod = 100000;

int mask;

char m[N][N];
map<int,int> M;
int memo[20][20][K];


inline int getIndex(int st)
{
	int index = M.size();
	if (M.find(st) == M.end()) M[st] = index;
	return M[st];
}

int rec(int &h, int &w, int now, int st)
{
	if(w * h == now) return 1;
	int index = getIndex(st);
	
	int y = now / w, x = now % w;
	if(memo[y][x][index] != -1) return memo[y][x][index];
	
	ll res = 0;
	
	// J
    if (m[y][x] == '?' || m[y][x] == 'J')
	{
		int next = st;
		if (next % 2 == 1) next = ((next - 1) << 1) | 1; // (next << 1) & (~2) | 1
		else next = (next << 1) | 1;
		next = next & mask;
		
		res = (res + rec(h, w, now+1, next)) % mod;
    }
	
	// O
    if (m[y][x] == '?' || m[y][x] == 'O')
	{
		// JO
		if (st % 2 == 1)
		{
			int next = st;
			next = (next << 1);
			next = next & mask;
			
			res = (res + rec(h, w, now + 1, next)) % mod;
		}
		else
		{
			int next = st;
			next = (next << 1);
			next = next & mask;
			
			res = (res + rec(h, w, now + 1, next)) % mod;
		}
    }
	
	// I
    if (m[y][x] == '?' || m[y][x] == 'I')
	{
		if (((1 << (w - 1)) & st) == 0 || x == w - 1)
		{
			int next = st;
			if (st % 2 == 1) next = (next - 1) << 1;
			else next = (next << 1);
			next = next & mask;
			
			res = (res + rec(h, w, now + 1, next)) % mod;
		}
    }
	
	return memo[y][x][index] = res;
}

int main()
{
    int h, w;
	while(cin >> h >> w && h)
	{
		ll all = 1;
		
		rep(i, h) cin >> m[i];
		rep(y, h) rep(x, w)if (m[y][x] == '?') all = (all * 3) % mod;
		rep(k, K) rep(y, h) rep(x, w) memo[y][x][k] = -1;
		
		mask = (1 << w) - 1;
		
		ll cans = rec(h, w, 0, 0);
		ll ans = (all - cans + mod) % mod;
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
package main
import (
  "fmt"
)

func max(arr []int) int {
  num := 0
  for _, a := range arr {
    if num < a {
      num = a
    }
  }
  return num
}

func diff(a, b float64) float64 {
  if a < b {
    return b - a
  }
  return a - b
}

func main() {
  var n int
  fmt.Scan(&n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  maxNum := max(as)
  target := float64(maxNum)/2
  
  otherNum := 0
  for _, a := range as {
    if diff(float64(a), target) < diff(float64(otherNum), target) {
      otherNum = a
    }
  }
  fmt.Println(maxNum, otherNum)
}

Measured memory_bytes: 5504
using System;

class Program
{
    static void Main()
    {
 
            for (int i = 1; i <= 9; i++) {
 
                for (int j = 1; j <= 9; j++) {
 
                    int re = i * j;
 
 
                Console.Write ("{0}x{1}={2}", i,j,re);
Console.WriteLine();
 
                }
            }
    }
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

 ll n,c=0,mx=0; cin>>n;
 for(int i=0;i<n;i++)
 {
     ll a[n],b[n];
     cin>>a[i]>>b[i];
     if(a[i]==b[i])
     {
         c++;
     }
     else
     {
         c=0;
     }
    mx=max(mx,c);
     //cout<<mx<<endl;
 }

 if(mx>=3)
cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
 }

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N, W;
ll w[110];
ll v[110];
ll dp[110][110000];

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

  rep(i, N) cin >> w[i] >> v[i];

  rep(i, N) {
    rep(j, W) {
      if (j >= w[i]) {
        dp[i][j] = max(dp[i-1][j], dp[i-1][j - w[i]] + v[i]);
      } else {
        dp[i][j] = dp[i-1][j];
      }

      //cout << i << j << dp[i][j] << "\n";
    }
  }

  cout << dp[N][W] << "\n";
}

Measured memory_bytes: 87424
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())



template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
  int n, ans = 0; cin >> n;
  Vint A(n); vREP(ele, A) cin >> ele;
  int preNumber = A.at(0);
  for(int i = 1; i < n; i++){
    if(preNumber == A.at(i)){
      ans++; preNumber = -1;
    }
    else preNumber = A.at(i);
  }
  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    int l=s1.size()+s2.size();
    for(int i=0,j=0,k=1;k<=l;k++){
        if(k%2){
            cout<<s1[i];
            i++;
        }else{
            cout<<s2[j];
            j++;
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  long long sum=0;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    A.at(i)=A.at(i)-(i+1);
  }
  sort(A.begin(),A.end());
  long long b=0;
  if(N%2==1){
    if(N==1){
      b=A.at(0);
    }
    else{
      b=A.at(N/2);
    }
    for(int i=0;i<N;i++){
    sum=sum+abs(A.at(i)-b);
    }
  }
  else{
    b=(A.at(N/2)+A.at(N/2-1))/2;
    long long c=A.at(N/2);
    long long d=A.at(N/2-1);
    for(int i=0;i<N;i++){
    sum=sum+abs(A.at(i)-b);
    }
    long long sum2=0;
    long long sum3=0;
    for(int i=0;i<N;i++){
    sum2=sum2+abs(A.at(i)-c);
    }
    for(int i=0;i<N;i++){
    sum3=sum3+abs(A.at(i)-d);
    }
    sum=min(sum,min(sum3,sum2));
  }
  cout<<sum<<endl;
}
    
  
  
  


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#define rep(i, n)   for(int i = 0; i < (n); i++)
#define PI 3.14159265359
using namespace std;
typedef long long ll;

int main(){
    int a,b,x;  cin >> a >> b >> x;
    double theta = 0;
    if((double)a*a*b/2 > x){    //tan(theta)
        theta = (double)a*b*b/(2*x);
    }else{
        theta = (double)2*b/a - (double)2*x/(a*a*a);
    }
    theta = (double)180*atan(theta)/PI;
    printf("%f\n", theta);
}


Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

static const int M = (int)2e5+5;
int A[M];
int ans[M];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&A[i]);
	int L=1,R=n;
	for(int i=n;i>=1;--i){
		if((i&1)==(n&1))ans[L++]=A[i];
		else ans[R--]=A[i];
	}
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3712
from collections import deque

K = int(input())
que = deque([i for i in range(1, 10)])
lunlun = []

while que:
    num = que.pop()
    lunlun.append(num)
    for i in range(10):
        if abs(int(str(num)[-1]) - i) <= 1:
            cand = int(str(num) + str(i))
            if cand < 10000000000:
                que.append(cand)

lunlun.sort()
print(sorted(lunlun)[K - 1])

Measured memory_bytes: 12884
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    if (n % 2 == 0) {
        cout << 0.5 << endl;
    } else {
        cout << setprecision(10) << ((n - 1) / 2 + 1) / (double)n << endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let ans = if a * b % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", ans);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;
ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}


int main(){
 ll n;
 cin>>n;
 string s;
 cin>>s;
 ll d=0;
 rep(i,n-1){
   if(s[i]==s[i+1])d++;
 }
 cout<<s.size()-d<<endl;
}



Measured memory_bytes: 3732
n = int(input())
abc = [list(map(int,input().split())) for _ in range(n)]
dp = [[0]*3 for i in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
#dp[j][i]はj番目でiを選んだ時の最大値
for j in range(n-1):
    dp[j+1][0] = max(dp[j][1],dp[j][2])+abc[j+1][0]
    dp[j+1][1] = max(dp[j][0],dp[j][2])+abc[j+1][1]
    dp[j+1][2] = max(dp[j][0],dp[j][1])+abc[j+1][2]
print(max(dp[n-1]))

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const double eps = 1e-8;

int main()
{
    int n,a,b;
    cin >>n >>a >>b;
    vector<ll> v(n);
    rep(i,n) cin >>v[i];

    sort(all(v),greater<ll>());

    long double max_av = 0;
    for(int i=a; i<=b; ++i)
    {
        long double t = 0;
        rep(j,i) t+=v[j];
        t/=i;
        max_av = max(max_av, t);
    }

    ll C[51][51]={};
    C[0][0]=1;
    for(int i=1; i<=50; ++i)
    {
        C[i][0]=C[i][i]=1;
        for(int j=1; j<i; ++j) C[i][j]=C[i-1][j-1]+C[i-1][j];
    }

    ll ans = 0;
    for(int i=a; i<=b; ++i)
    {
        long double t = 0;
        rep(j,i) t+=v[j];
        t/=i;

        if(fabs(max_av - t)<eps)
        {
            ll f_v = v[i-1];

            int l=i-1, r=i-1;
            while(l>=0 && v[l]==f_v) --l;
            ++l;
            while(r<n && v[r]==f_v) ++r;
            --r;

            ans += C[r-l+1][i-1-l+1];
        }
    }

    printf("%.10Lf\n", max_av);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

string s;
int ans;

int main() {
	fastio; cin >> s;
	if (s[0] == 'R' or s[1] == 'R' or s[2] == 'R') ans = 1;
	if ((s[1] == 'R') and (s[0] == s[1] or s[1] == s[2])) ans = 2;
	if (s[0] == 'R' and s[1] == 'R' and s[2] == 'R') ans = 3;
	cout << ans;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {

  vint v(5),b(5);
  for (ll i=0;i<5;i++) {
    cin >> v.at(i);
    b.at(i) = v.at(i)%10;
  }
  
  ll x=10;
  sort(b.begin(),b.end());
  for (ll i=0;i<5;i++) {
    if (b.at(i)!=0) {
      x = b.at(i);
      break;
    }
  }
  
  for (ll i=0;i<5;i++) {  
    if (v.at(i)%10!=0) {
      ll a=v.at(i)/10;
      v.at(i) = 10*(a+1);
    }
  }
  
  
  ll ans=0;
  for (ll i=0;i<5;i++) { 
    ans += v.at(i);
  }
  
  cout << ans-10+x;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <algorithm>
//#include <cmath>
//#include <iostream>
//#include <vector>
//#include <numeric>
//#include <string>
//#include <functional>

using namespace std;

//#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
 
int main(){
  int N,M;
  cin>>N>>M;
  
  vector<int>oks(N+1,true);
 
  for(int i=0;i<M;++i){
    int a;cin>>a;
    oks[a]=false;
  }
  vector<long long int>dp(N+1);
  dp[0]=1;
 
  for(int now=0;now<N;++now){
    for(int next=now+1;next<=min(N,now+2);++next){
      if(oks[next]){
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
     }
   }
   cout<<dp[N]<<endl;
   return 0;
}

/*
void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}


int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> v(M+1);
  vector<int> ansv(M+1);
  long long ans = 1;
  for (int i=0;i<M;i++){
    cin >> a[i];
    if (i == 0){
      v[i] = a[i];
    } else {
      v[i] = a[i] - a[i-1] - 1;
    }
  }
  v[M] = N - a[M-1];

  int aflag = 0;
  for(int i=0;i<M+1;i++){
    long long sum = 0;
    //for(int j=0;j<v[i];j++){
    if (v[i] < 3){
      if(i!=0 &&v[i]<2){
        cout << 0 << endl;
        return 0;
      } else {
        sum = 1;
      }
    } else {
      int pre = (v[i]-3)/2;
      int cnt = pre + 1;
      for(int j=0;j<cnt+1;j++){
        if(j==0){
          sum += 1;
        } else {
          int NN = v[i]-j-1;
          vector<vector<long long int> > vt(NN+1,vector<long long int>(NN+1,0));
          comb(vt);
          sum += vt[NN][j];
        }
      }
    }
    ansv[i] = sum;
    cout << sum << endl;
    ans *= sum;
  }
  
  cout << ans << endl;
  return 0;
}

*/

Measured memory_bytes: 1408
#include <stdio.h>
int main(void)
{
	int n,i;
	int s[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	for(i=0;i<n;i++)
	{
		printf("%d",s[n-i-1]);
		if(i!=n-1)
		printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600