akhauriyash/Code-Regression huggingface dataset:
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 15:12:19
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2000 + 5;

int n;
pii a[N];
ll dp[N][N];

ll solve(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l == r) {
        return 1ll * abs(a[n].se - l) * a[n].fi;   
    }
    ll& res = dp[l][r];
    int x = a[n - r + l].fi, p = a[n - r + l].se;
    res = max(solve(l + 1, r) + 1ll * abs(p - l) * x, solve(l, r - 1) + 1ll * abs(p - r) * x);
    return res;
}

void run() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        a[i] = MP(x, i);
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    memset(dp, -1, sizeof(dp));
    ll ans = solve(1, n);
    cout << ans << '\n';
}

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

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	int max=INT_MIN;
	int maxi=0;
	
	for(int i=0;i<n;i++){
		cin >> v[i];
		if(max<v[i])max=v[i],maxi=i;
	}
	if(n==1){cout<<v[0];exit(0);}
	int max2=INT_MIN;
	for(int i=0;i<n;i++){
		if(i!=maxi&&v[i]>max2)
		  max2=v[i];
	}
	for(int i=0;i<n;i++){
		if(v[i]==max)cout<<max2<<"\n";
		else cout<<max<<"\n";
		
	}
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int func(long long N, std::vector<long long> B) {
    // cout << fixed << setprecision(8);

    ll ans;
    // A[0]を入れる。
    ans = B[0];
    // A[N-1]を足す。
    ans += B[N - 2];
    // A[i]を合計する。
    for (int i = 1; i < N - 1; i++) {
        ans += min(B[i - 1], B[i]);
    }
    cout << ans << endl;

    return 0;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> B(N - 1);
    for (int i = 0; i < N - 1; i++) {
        scanf("%lld", &B[i]);
    }

    func(N, std::move(B));

    return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	vector<int> c(n-1), s(n-1), f(n-1);
	vector<int> ans(n);
	rep(i, n-1){
		cin >> c[i] >> s[i] >> f[i];
	}
	
	for(int start = 0; start < n-1; start++){
		int t = 0;
		for(int i = start; i < n-1; i++){
			if(t < s[i]) t = s[i];
			if(t % f[i] != 0) t += f[i] - t % f[i];
			t += c[i];
		}
		ans[start] = t;
	}
	rep(i, n){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

const ll int MOD=1000000007;
ll int fact[1000001];
ll int modInv[1000001];

ll int power(ll int base,ll int p)
{
    ll ans=1;
    base=base%MOD;
    while(p>0)
    {
        if(p & 1)
            ans=(ans*base)%MOD;
            
        p=p>>1;
        base=(base*base)%MOD;
    }
    return ans;
}

void factInit()
{
    fact[0]=1;
    modInv[0]=1;
    for(ll int i=1;i<1000001;i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;
        modInv[i]=power(fact[i],MOD-2)%MOD;
    }
}


void solve()
{
   float r;
   cin>>r;
   cout<<2*3.14*r;
}

int main()
{
    FAST;
    ll int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3804
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def fact(self, n):
        '''
        n!の値を返す
        '''
        return self.f[n]

    def comb(self, n, r):
        '''
        nCrの値を返す
        '''
        ret = self.f[n] * self.inv[n-r]*self.inv[r]
        ret %= self.mod
        return ret

    def perm(self, n, r):
        """
        nPrの値を返す
        """
        ret = self.f[n] * self.inv[n-r]
        ret %= self.mod
        return ret

    def fact(self, n):
        return self.f[n]


MOD = 10**9+7
N = int(input())
S = input()[:-1]
F = FactMod(N+1, MOD)

cnt_W = 0
cnt = 0
ans = 1
for i, c in enumerate(S):
    if c == "B":
        tmp = 1
    else:
        tmp = 0
    if i % 2 == 0:
        tmp ^= 1

    if tmp == 0:
        cnt += 1
    else:
        ans *= cnt
        ans %= MOD
        cnt -= 1
        cnt_W += 1
if cnt_W != N:
    ans = 0
else:
    ans *= F.fact(N)
    ans %= MOD
print(ans)


Measured memory_bytes: 48476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print1(a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep2(i,1,10) rep2(j,1,10){
		if(n==i*j){
			print1("Yes");
			return 0;
		}
	}
	print1("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  int ans = min(a, b) + min(c, d);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 632
import java.util.Random;
import java.util.Scanner;

public class Main {
	private static final int K = 26;
	private static Random rand = new Random(System.currentTimeMillis());

	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var d = sc.nextInt();
		var c = new int[K];
		var s = new int[d][K];
		for (var i = 0; i < K; i++) {
			c[i] = sc.nextInt();
		}
		for (var i = 0; i < d; i++) {
			for (var j = 0; j < K; j++) {
				s[i][j] = sc.nextInt();
			}
		}
		sc.close();

		var t = create(c, s, d);
		//var max = score(c, s, t, d);
		for (var i = 0; i < 500000; i++) {
			for (var j = 1; j < K; j++) {
				var mdi = i % d;
				var mti = (t[mdi] + j - 1) % K;
				var tbk = t[mdi];
				var check = check(c, s, t, d, mdi, mti);
				t[mdi] = mti + 1;
				//var sum = score(c, s, t, d);
				//if (sum - max != check) {
				//	System.out.printf("%d, %d, %d, %d\r\n", max, sum, sum - max, check);
				//}
				if (check < 0) {
					t[mdi] = tbk;
				}
			}
		}

		for (var i = 0; i < d; i++) {
			System.out.println(t[i]);
		}
		//System.out.println(score(c, s, t, d));
	}

	private static int check(int[] c, int[][] s, int[] t, int d, int mdi, int mti) {
		var sum = 0;
		var ti = t[mdi] - 1;
		sum += s[mdi][mti] - s[mdi][ti];

		var last1 = 0;
		var last2 = 0;
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == ti + 1) {
				last1 = i + 1;
				break;
			}
		}
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == mti + 1) {
				last2 = i + 1;
				break;
			}
		}

		var count1 = 1;
		var count2 = 1;
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == ti + 1) {
				break;
			}
			count1++;
		}
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == mti + 1) {
				break;
			}
			count2++;
		}
		sum += (mdi - last2 + 1) * c[mti] * count2 - (mdi - last1 + 1) * c[ti] * count1;

		//		System.out.printf("*****%d, %d, %d, %d, %d,     %d, %d\r\n", t[0], t[1], t[2], t[3], t[4], mdi + 1, mti + 1);
		//		System.out.printf("*****%d, %d, %d, %d, %d, %d, %d, %d\r\n", s[mdi][mti], s[mdi][ti], c[mti], c[ti], last1,
		//				last2, count1, count2);

		return sum;
	}

	private static int score(int[] c, int[][] s, int[] t, int d) {
		var sum = 0;
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var ti = t[i] - 1;
			sum += s[i][ti];
			last[ti] = i + 1;
			for (var j = 0; j < K; j++) {
				sum -= ((i + 1) - last[j]) * c[j];
			}
		}

		return sum;
	}

	private static int[] create(int[] c, int[][] s, int d) {
		var t = new int[d];
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var v = new int[K];
			for (var j = 0; j < K; j++) {
				v[j] = s[i][j] + (((i + 1) - last[j]) * c[j]);
			}
			t[i] = rand(v) + 1;
			last[t[i] - 1] = i + 1;
		}
		return t;
	}

	private static int rand(int[] v) {
		var sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
		}
		var value = rand.nextInt(sum);
		var index = 0;
		sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
			if (value < sum) {
				break;
			}
			index++;
		}
		//System.out.printf("%d %d %d\r\n", value, sum, index);
		return index;
	}
}


Measured memory_bytes: 46984
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N;
    cin >> N;

    map<int, int> mp;

    FOR(i, 0, N){
        int a;
        cin >> a;
        mp[a-1]++;
        mp[a]++;
        mp[a+1]++;
    }

    int max_count = 0;
    for(auto a : mp){
        int count = a.second;
        max_count = max(max_count, count);
    }

    p(max_count);
    
    return 0;
}

Measured memory_bytes: 4736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var l = inputLongArray[0];
            var r = inputLongArray[1];
            var d = inputLongArray[2];

            long ans = 0;
            for (long i = l; i <= r; i++)
            {
                if (i % d == 0) ans++;
            }

            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27900
#include<stdio.h>

int main(void)
{
  double r, pai = 3.14159265359, a1 = 0.0, a2 = 0.0;

  scanf("%lf", &r);

  a1 = r * r * pai;
  a2 = r * 2 * pai;

  printf("%f %f\n", a1, a2);

  return 0;
}

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

int main() {
    int n, i, j;
    cin >> n;
    vector<int> A(n), B(n), C(n);
    long long ret = 0;
    for (i = 0; i < n; ++i) cin >> A[i];
    for (i = 0; i < n; ++i) cin >> B[i];
    for (i = 0; i < n; ++i) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    for (i = 0; i < n; ++i) {
        auto pos1 = lower_bound(A.begin(), A.end(), B[i]);
        long long a_cnt = pos1 - A.begin();
        //printf("%d\n", a_cnt);
        auto pos2 = upper_bound(C.begin(), C.end(), B[i]);
        long long b_cnt = C.end() - pos2;
        //printf("%d\n", b_cnt);
        ret += a_cnt*b_cnt;
    }
    
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include <algorithm>

using namespace std;


int N;
int X[200000];
int sX[200000];

int main() {
  int mi;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &X[i]);
    sX[i] = X[i];
  }


  mi = N / 2;

  sort(sX, sX + N);
  int m1 = sX[mi - 1];
  int m2 = sX[mi];

  for (int i = 0; i < N; i++) {
    if (X[i] <= m1) {
      printf("%d\n", m2);
    } else {
      printf("%d\n", m1);
    }
  }

  return 0;

}


Measured memory_bytes: 3712
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=(1<<14)+5,M=205;
int r[N],rt[2][N<<1],lim,d,ilim;
void NTT(int *A,int ty){
    fp(i,0,lim-1)if(i<r[i])swap(A[i],A[r[i]]);
    for(R int mid=1;mid<lim;mid<<=1)
        for(R int j=0,t;j<lim;j+=(mid<<1))
            fp(k,0,mid-1)
                A[j+k+mid]=dec(A[j+k],t=mul(rt[ty][mid+k],A[j+k+mid])),
                A[j+k]=add(A[j+k],t);
    if(!ty)fp(i,0,lim-1)A[i]=mul(A[i],ilim);
}
int coef[N],fac[N],ifac[N],f[N],g[N],n,m,res;
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
void init(int n=10000){
    fp(i,1,(1<<d)-1)r[i]=(r[i>>1]>>1)|((i&1)<<(d-1));
    for(R int t=(P-1)>>1,i=1,x,y;i<lim;i<<=1,t>>=1){
        x=ksm(3,t),y=ksm(332748118,t),rt[0][i]=rt[1][i]=1;
        fp(k,1,i-1)
            rt[1][i+k]=mul(rt[1][i+k-1],x),
            rt[0][i+k]=mul(rt[0][i+k-1],y);
    }
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
	coef[0]=0;fp(i,1,lim>>1)coef[i]=ifac[i+2];
	NTT(coef,1);
}
void calc(){
	fp(i,0,n)g[i]=mul(f[i],ifac[i]);fp(i,n+1,lim-1)g[i]=0;
	NTT(g,1);
	fp(i,0,lim-1)g[i]=mul(g[i],coef[i]);
	NTT(g,0);
	fp(i,0,n)f[i]=add(mul(g[i],fac[i+2]),mul(f[i],(i*(i+1)>>1)+1));
//	puts("qwq");
//	fp(i,0,n)printf("%d ",f[i]);
//	puts("");
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&m);
	lim=1,d=0;while(lim<=(n<<1))lim<<=1,++d;
	ilim=ksm(lim,P-2);
	init();
	f[0]=1;
	fp(i,1,m)calc();
	fp(i,0,n)upd(res,mul(C(n,i),f[i]));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc108/tasks/arc102_a

#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    ll n, k, sum = 0, cnt;
    cin >> n >> k;

    // 入力例1：N=3、K=2の出力結果は
    // [1, 3]の2種類を3乗 + [2]の1種類を3乗
    // 例えばK=8の場合、組み合わせの値は以下2通り
    // ・4, 12, 20,... (k*x - k/2)
    // ・8, 16, 24,... (k*x)
    // また、K=5の場合、組み合わせは以下1通り
    // ・5, 10, 15,... (K*x)

    // 偶数・奇数で共通なK倍の値のパターンを出す
    cnt = 0;
    for (int i = k; i <= n; i += k) {
        cnt++;
    }
    sum += cnt * cnt * cnt;

    // 偶数の場合
    if (k % 2 == 0) {
        cnt = 0;
        for (int i = k / 2; i <= n; i += k) {
            cnt++;
        }
        sum += cnt * cnt * cnt;
    }

    cout << sum << endl;

    return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll n; cin >> n;
  vector<ll> a(n+1);
  vector<bool> seen(n+1);
  for (ll i = 1; i <= n; i++) cin >> a[i];
  ll cnt = 0;
  ll cur = 1;
  seen[1] = true;
  while (true) {
    cur = a[cur];
    cnt++;
    if (cur == 2) {
      cout << cnt << endl;
      return 0;
    }
    if (seen[cur]) {
      cout << -1 << endl;
      return 0;
    }
    seen[cur] = true;
  }
  

  return 0;
}



Measured memory_bytes: 3980
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*-----Library-----*/
int n,k;
int sum[210000];
int make_index(int s){
    int t=(sum[s]-(s+1)%k+k)%k;
    return t;
}
signed main(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    bool k[110000]={};
    for(int i=0;i<s.size();i++){
        if(s[i]=='1')k[i]=true;
    }
    int now=n;
    vector<int> ans;
    while(1){
        if(now-m<=0){
            if(now!=0)ans.push_back(now);
            break;
        }
        int memo=-1;
        for(int i=m;i>0;i--){
            if(k[now-i]==false){
                memo=i;
                break;
            }
        }
        if(memo==-1){
            cout<<-1<<endl;
            return 0;
        }
        now-=memo;
        ans.push_back(memo);
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1656
S = str(input())

if S[0]=='S' and S[1]=='S' and S[2]=='S':
  sum = 0
elif (S[0]=='R' and S[1]=='R' and S[2]=='S') or (S[0]=='S' and S[1]=='R' and S[2]=='R'):
  sum = 2
elif S[0]=='R' and S[1]=='R' and S[2]=='R':
  sum = 3
else:
  sum = 1
  
print(sum)

Measured memory_bytes: 8996
s = input()
t = input()

n = len(s)
m = len(t)
ans = 10**9

for i in range(n-m+1):
  res = 0
  u = s[i:i+m]
  for j in range(m):
    if t[j]!=u[j]:
      res += 1
  ans = min(ans, res)

print(ans)


Measured memory_bytes: 9084
#include<stdio.h>
#include<string.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[2010];
int dp[2][2][2010][2010],cnt[2];

int main(){
	int k;
	scanf("%s %d",s,&k);
	int n=strlen(s);
	for(int i=0;i<2005;i++)for(int j=0;j<2005;j++)for(int x=0;x<2;x++){
		dp[x][0][i][j]=1e9;
		dp[x][1][i][j]=-1e9;
	}
	
	dp[0][0][0][0]=dp[0][1][0][0]=0;
	dp[1][0][0][0]=dp[1][1][0][0]=0;
	for(int i=0;i<n;i++){
		int f=s[i]=='L'||s[i]=='R';
		int d=s[i]=='R'||s[i]=='U';
		cnt[f]++;
		for(int j=0;j<=cnt[f];j++){
			if(j){
				dp[f][0][cnt[f]][j]=min(dp[f][0][cnt[f]-1][j]+(d^(j%2==0)?-1:1),dp[f][0][cnt[f]-1][j-1]+(d^(j%2==0)?1:-1));
				dp[f][1][cnt[f]][j]=max(dp[f][1][cnt[f]-1][j]+(d^(j%2==0)?-1:1),dp[f][1][cnt[f]-1][j-1]+(d^(j%2==0)?1:-1));
			}else{
				dp[f][0][cnt[f]][j]=dp[f][0][cnt[f]-1][j]+(d?1:-1);
				dp[f][1][cnt[f]][j]=dp[f][1][cnt[f]-1][j]+(d?1:-1);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=k;i++)for(int j=k-i;j>=0;j--){
		ans=max(ans,max(-dp[0][0][cnt[0]][i],dp[0][1][cnt[0]][i])+max(-dp[1][0][cnt[1]][j],dp[1][1][cnt[1]][j]));
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 64788
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int nextInt(){int a;cin>>a;return a;}
int main(){
  int n,a,b,c,x,ct;
  vector<int> y;
  while(cin>>n >> a >> b >> c >> x){
    if(!n&&!a&&!b&&!c&&!x)break;
    y.resize(n);
    REP(i,n)y[i] = nextInt();
    ct=0;
    int i;
    if(a==0 && n>1){cout << -1 << endl;continue;}
    for(i=0;i<10001;i++){
	if(y[ct] == x){
	  ct++;
	}
      if(ct==n)break;
      x = (a * x + b)%c;
    }
    if(ct==n) cout << i << endl;
    else cout << -1 << endl;

    y.clear();
  }

  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int n, m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 f(s64 x)
{
    s64 ret = 0;
    s64 k = 0;
    x = x + 1;
    while (x / (1ULL << k) && k < 64ULL)
    {
        if (k == 0)
            ret |= (x / 2ULL) % 2ULL;
        else
            ret |= ((
            MAX(
            ( (s64)(x % (1ULL << (k + 1ULL))) - (s64)(1ULL << k) ),
            0
            )
            % 2ULL)) << k;
        ++k;
    }

    return ret;
}

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

    s64 A, B;
    cin >> A >> B;

    if (A == 0) A = 1;
    cout << (f(B) ^ f(A - 1)) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=a*b;
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String s = in.nextLine();
        for (int i = 0; i < s.length(); i++){
            System.out.print((char) ((s.charAt(i) - 65 + n) % 26 + 65));
        }
        System.out.println();

    }
}


Measured memory_bytes: 26556
#B
import math
a = []
a1 = []
f = 10
for i in range(5):
    a.append(int(input()))
    a1.append(math.ceil(a[i] / 10) * 10)
    if f > a[i] % 10 and a[i] % 10 != 0:#ロスタイムfが小さい0はすぐに注文できるから
        f = a[i] % 10
#累計時間sum(a1)-最小ロスタイムf
print(sum(a1) - 10 + f)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 405;
const ll INF = 1e18L + 5; // 10^18+5
ll dp[nax][nax];
// dp[i][j] - the minimum total cost of combining interval [i,j] into one vertex

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    auto sum = [&](int L, int R) {
        ll s = 0;
        for(int i = L; i <= R; ++i) {
            s += a[i];
        }
        return s;
    };
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = 0;
            }
            else {
                dp[L][R] = INF;
                ll s = sum(L, R);
              //// here is magic thinking
                for(int i = L; i <= R - 1; ++i) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + s);
                }
            }
        }
    }
    
    printf("%lld\n", dp[0][n-1]);
}

Measured memory_bytes: 1536
using System;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            int a = 0, b = 0;

            foreach (var c in line.Substring(1)) {
                if (c == 'A') a++;
                else b++;
            }

            if (a > b) a++;
            else b++;

            Console.WriteLine(a + " " + b);
        }
    }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, ans=0;
	int a[100005];

	cin >> N;
	rep(i,N) cin >> a[i];

	int cnt[100005] = {};
	rep(i,N){
		if( a[i] % 4 == 0 )      cnt[2]++;
		else if( a[i] % 2 == 0 ) cnt[1]++;
		else cnt[0]++;
	}
	if( cnt[0] <= cnt[2] ){
		ans = 1;
	}else if( cnt[1] == 0 && cnt[0] <= cnt[2]+1 ){
		ans = 1;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int N, D;

int main() {
    cin >> N >> D;
    vector<vector <int> > vec(N, vector<int>(D));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> vec[i][j];
        }
    }
    int count = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            double d = 0;
            for (int k = 0; k < D; ++k) {
                d += pow(vec[i][k] - vec[j][k], 2);
            }
            d = sqrt(d);
            if(abs(d - (int)d) < 1e-6){
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=1e5;

struct edge{
    int to,cost;
};

int n;
vector<vector<edge> > G(MAXN);
vector<int> color(MAXN,-1);

void dfs(int u,int c){
    color[u]=c;
    for(auto e:G[u]){
        if(color[e.to]!=-1) continue;
        if(e.cost%2==0) dfs(e.to,c);
        else if(e.cost%2==1) dfs(e.to,1-c);
    }
    return ;
}

int main(){
    int n;cin>>n;
    for(int i=0;i<n-1;i++){
        int from,to,cost;
        cin>>from>>to>>cost;
        from--;to--;
        G[from].push_back(edge{to,cost});
        G[to].push_back(edge{from,cost});
    }
    dfs(0,0);
    for(int i=0;i<n;i++){
        cout<<color[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 10212
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll X,A,B;
  cin >> X >> A >> B;
  if(abs(X-A)<abs(X-B)){
    cout << "A" << endl;
  }
  else{
    cout << "B" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A = sc.nextInt();
		long B = sc.nextInt();
		long res = 0;
		int[] data = new int[N];
		for(int i = 0 ; i<N; i++){
			int input = sc.nextInt();
			data[i] = input;
		}
		for(int i = 1; i<N; i++){
			int r = data[i];
			int l = data[i-1];
			if ( (r-l)*A > B){
				res+=B;
			}
			else{
				res+=A*(r-l);
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 49976
def main():
    n, m = [int(v) for v in input().split(' ')]
    map_table = {}
    for _ in range(m):
        a, b = [int(v) - 1 for v in input().split(' ')]
        if a not in map_table.keys():
            map_table[a] = [b]
        else:
            map_table[a].append(b)

        if b not in map_table.keys():
            map_table[b] = [a]
        else:
            map_table[b].append(a)

    stack = [0]
    min_step = [None for _ in range(n)]
    min_step[0] = 0
    n_step = 0

    while len(stack) > 0:
        n_step += 1
        next_stack = []
        for n in stack:
            next_nodes = map_table[n]
            for next_n in next_nodes:
                if min_step[next_n] is None:
                    min_step[next_n] = n
                    next_stack.append(next_n)
        stack = next_stack

    suucess = True
    for v in min_step:
        if v is None:
            suucess = False
    if suucess is True:
        print('Yes')
        for n in min_step[1:]:
            print(int(n) + 1)
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans;
    for(ll i = 0; i < 1e5; i++) {
        if(i * i > n) {
            ans = (i - 1) * (i - 1);
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define pi pair<int,int>
#define debug(a) cout << #a << " " << a << endl;
#define pb emplace_back
#define REP(i,j,k) for(int i = j; i < k; ++i)
#define all(v) (v).begin(),(v).end() 
using namespace std;

int ans;
int n, k;
vector<int> b,c;
signed main()
{IOS
	cin >> n >> k;
	int ok = 0;
	b.pb(0);
	REP(i,0,n)
	{
		int t; cin >> t;
		if(t == 0) --k;
		if(t > 0) b.pb(t);
		if(t < 0) c.pb(-t);
	}	
	c.pb(0), reverse(all(c));
	ans = 1e18;
	REP(i,0,k+1)
	{
		if(i >= c.size() || k-i >= b.size()) continue;
		ans = min(ans,2*c[i]+b[k-i]);
		ans = min(ans,c[i]+2*b[k-i]);
	}
	cout << ans;
}

Measured memory_bytes: 1656
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());

		int multiple = 2;
		if (n < 2) {
			System.out.println(1);
		} else {
			while (multiple <= n) {
				if (multiple * 2 > n) {
					System.out.println(multiple);
					break;
				} else {
					multiple *= 2;
				}
			}
		}

	}

}


Measured memory_bytes: 35652
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val d = sc.nextLong()
  val xy = (1..n).map { Pair(sc.nextLong(), sc.nextLong()) }


  val list = mutableListOf<Long>()

  for (xyi in xy) {
    val x = xyi.first
    val y = xyi.second

    val tmp = x * x + y * y
    list.add(tmp)
  }

  val size = list.filter { it <= d * d }.size
  println(size)

}


Measured memory_bytes: 81368
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

typedef long long LL;

inline int read()
{
	char c=getchar();int num=0,f=1;
	for(;!isdigit(c);c=getchar())
		f=c=='-'?-1:f;
	for(;isdigit(c);c=getchar())
		num=num*10+c-'0';
	return num*f;
}

const int N=305;
const int mod=1e9+7;

inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}

int n,m;
int f[N][N][N];
vector<pii> vec[N];

bool check(int r,int g,int b)
{
	int k=max(r,max(g,b));
	int siz=vec[k].size();
	for(int i=0,l,x,cnt;i<siz;++i)
	{
		l=vec[k][i].fi,x=vec[k][i].se;
		cnt=0;
		if(r>=l) ++cnt;
		if(g>=l) ++cnt;
		if(b>=l) ++cnt;
		if(cnt!=x) return 0;
	}
	return 1;
}

int main()
{
	n=read(),m=read();
	for(int i=1,l,r,x;i<=m;++i)
	{
		l=read(),r=read(),x=read();
		vec[r].pb(mp(l,x));
	}
	f[0][0][0]=1;
	int ans=0;
	for(int r=0;r<=n;++r)
		for(int g=0;g<=n;++g)
			for(int b=0;b<=n;++b)
			{
				if(!f[r][g][b]) continue;
				if(!check(r,g,b)){f[r][g][b]=0;continue;}
				int k=max(r,max(g,b));
				if(k==n) add(ans,f[r][g][b]);
				add(f[k+1][g][b],f[r][g][b]),
				add(f[r][k+1][b],f[r][g][b]),
				add(f[r][g][k+1],f[r][g][b]);
			}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 110848
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int leng = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        if(leng == 1){
            leng+=13;
        }
        if(b == 1){
            b+=13;
        }
        if(leng > b){
            WriteLine("Alice");
        }else if(b > leng){
            WriteLine("Bob");
        }else if(leng == b){
            WriteLine("Draw");
        }
    }
}


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

using namespace std;

#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=1e6+10;
int a[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        sint(a[i]);
        sort(a,a+n);
    ll ans=0;
    for(int i=0;i<n-k;i++)
        ans+=a[i];
    cout<<ans;
    return 0;
}


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

using namespace std;

int main(void) {
	long long N,M;
	cin >> N >> M;
	if (M < N) {
		swap(N,M);
	}

	long long res = 0;
	if (N == 1) {
		if (M == 1) {
			res = 1;
		}
		else {
			res = M - 2;
		}
	}
	else {
		res = (N-2) * (M-2);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
//atcoder arc090 c
#include <bits/stdc++.h>
#define fi first
#define se second
typedef long long ll;
typedef std::pair <ll, int> pr;
const ll P = 1e9 + 7;
const ll inf = 10000000000000000ll;
const int N = 1e5 + 54;

int n, m, x[N << 1], y[N << 1], z[N << 1];
ll all, disN;
struct graph {
	int start, head[N], vis[N], cnt;
	ll dp[N], dis[N];
	struct node { int u, v, w; } edge[N << 2];
	inline void init() { memset(head, -1, sizeof head); }
	inline void add(int x, int y, int z) {
		edge[cnt] = (node) {head[x], y, z}; head[x] = cnt++;
		edge[cnt] = (node) {head[y], x, z}; head[y] = cnt++;
	}
	std::priority_queue <pr, std::vector < pr >, std::greater < pr > > q;
	inline void walk() {
		for (int i = 1; i <= n; ++i) dis[i] = inf;
		dis[start] = 0, dp[start] = 1;
		q.push(std::make_pair(0, start));
		while (! q.empty()) {
			int x = q.top().se; ll d = q.top().fi; q.pop();
			if (vis[x] || dis[x] < d) continue;
			vis[x] = 1;
			for (int i = head[x]; ~i; i = edge[i].u) {
				int y = edge[i].v;
				if (dis[y] > d + edge[i].w) dis[y] = d + edge[i].w, dp[y] = dp[x], q.push(std::make_pair(dis[y], y));
				else if (dis[y] == d + edge[i].w) dp[y] = (dp[y] + dp[x]) % P; 
			}
		}
	}
	inline void print() { for (int i = 1; i <= n; ++i) std::cout << dis[i] << ' ' << dp[i] << '\n'; std::cout << "-------+" <<'\n'; }
} g0, g1;


inline void meet_point() {
	for (int i = 1; i <= n; ++i) 
		if (g0.dis[i] == g1.dis[i] && g0.dis[i] + g1.dis[i] == disN) 
			all = all - g0.dp[i] * g0.dp[i] % P * g1.dp[i] % P * g1.dp[i] % P, all = (all + P) % P;
}
inline void meet_edge() {
	for (int i = 1; i <= m; ++i) {
		int u = x[i], v = y[i];
		if (g0.dis[u] + g1.dis[v] + z[i] == disN && g0.dis[u] < disN / 2 && g1.dis[v] < disN / 2) 
			all = all - g0.dp[u] * g0.dp[u] % P * g1.dp[v] % P * g1.dp[v] % P, all = (all + P) % P;
		std::swap(u, v);
		if (g0.dis[u] + g1.dis[v] + z[i] == disN && g0.dis[u] < disN / 2 && g1.dis[v] < disN / 2) 
			all = all - g0.dp[u] * g0.dp[u] % P * g1.dp[v] % P * g1.dp[v] % P, all = (all + P) % P;
	}
}
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    std::cin >> n >> m >> g0.start >> g1.start;
    g0.init(), g1.init();
    for (int i = 1; i <= m; ++i) std::cin >> x[i] >> y[i] >> z[i], g0.add(x[i], y[i], z[i]), g1.add(x[i], y[i], z[i]);
    g0.walk(), g1.walk();
    all = g0.dp[g1.start] * g0.dp[g1.start] % P;
    disN = g0.dis[g1.start];
	meet_point(), meet_edge();
	std::cout << all << '\n';
	//g0.print(), g1.print();
	return 0;
}


Measured memory_bytes: 23900
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'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'};
//vc Alp ={'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'};
//cout<<""<<endl;

int main(){
  ll n;cin>>n;vl a(n);rep(i,n)cin>>a[i];
  sort(all(a));
  ll m=a[n-1];
  ll k=0;
  ll l=0;
  if(m%2==0){
    k=abs(a[0]-a[n-1]/2);
    rep(i,n-1){
      if(k>=abs(a[i]-a[n-1]/2)){
        l =a[i];
        k=abs(a[i]-a[n-1]/2);
      }
    }
      cout<<m<<" "<<l<<endl;
  }
  else{
    k=min(abs(a[0]-a[n-1]/2) ,abs(a[0]-a[n-1]/2-1));
    
    rep(i,n-1){
      if(k>=min(abs(a[i]-a[n-1]/2) ,abs(a[i]-a[n-1]/2-1))){
        k=min(abs(a[i]-a[n-1]/2) ,abs(a[i]-a[n-1]/2-1));
        l=a[i];
       }
    }
      cout<<m<<" "<<l<<endl;
  }

}






Measured memory_bytes: 1024