akhauriyash/Code-Regression huggingface dataset:
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

dp = np.array([np.inf] * N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
        if i - K >= 0:
            dp[i] = min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
        else:
            dp[i] = min(dp[0:i]+abs(h[i]-h[0:i]))
print(int(dp[N-1]))

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

int main(){
  int i,j,cnt=0;
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int N=tx-sx,M=ty-sy;
  int n=max(N,-N),m=max(M,-M);
  string s="";
  for(i=0;i<m;i++)s+='U';
  for(i=0;i<n;i++)s+='R';
  for(i=0;i<m;i++)s+='D';
  for(i=0;i<n;i++)s+='L';
  s+='L';
  for(i=0;i<m+1;i++)s+='U';
  for(i=0;i<n+1;i++)s+='R';
  s+="DR";
  for(i=0;i<m+1;i++)s+='D';
  for(i=0;i<n+1;i++)s+='L';
  s+='U';
  cout<<s<<endl;
}

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

void ten_to_m_sinsu(int n, int m){//n:変換したい10進数、m進数への変換。
	string ans = "";
	while(n != 0){
		int a = ( abs(m) + ( n % abs(m) ) ) % abs(m);
		ans = to_string(a) + ans;
		n = ( n - a ) / ( m );
	}
	if( ans == "" ) ans = "0";
	cout << ans << endl;
}

int main(){
    int n;
    cin >> n;
    ten_to_m_sinsu(n,-2);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long V[50];
void Calc(){
	int N = rei();
	int K = rei();
	for(int i=0;i<N;i++){
		V[i] = rei();
	}
	long ans = 0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			if(i+j > N || i+j > K){
				break;
			}
			long sum = 0;
			priority_queue<long,vector<long>,greater<long>> pq;
			for(int k=0;k<i;k++){
				sum += V[k];
				pq.push(V[k]);
			}
			for(int k=0;k<j;k++){
				sum += V[N-1-k];
				pq.push(V[N-1-k]);
			}
			int res = K-i-j;
			while(res){
				res--;
				if(pq.empty()){
					break;
				}
				if(pq.top() >= 0){
					break;
				}
				sum -= pq.top();
				pq.pop();
			}
			ans = max(ans,sum);
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
from statistics import median

n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
al = []
bl = []
for ab in abl:
  al.append(ab[0])
  bl.append(ab[1])
if n%2 == 1:
  print(median(bl)-median(al)+1)
else:
  print(int(median(bl)*2-median(al)*2+1))


Measured memory_bytes: 52624
A, B, N = [int(i) for i in input().split()]
if B == 1:
    max = 0
elif B > N:
    x = N
    max = ((A * x) // B) - A * (x // B)
else:
    x = N
    maxn = ((A * x) // B) - A * (x // B)
    x = B * (N // B) - 1
    maxx = ((A * x) // B) - A * (x // B)
    if maxx > maxn:
        max = maxx
    else:
        max = maxn

print(max)


Measured memory_bytes: 9192
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

fn main() {
    input! {
        k: i64,
        s: i64,
    }

    let ans: u64 = (0..k + 1)
        .map(move |x| {
            (0..k + 1)
                .map(move |y| s - x - y >= 0 && s - x - y <= k)
                .filter(|b| *b)
                .count() as u64
        })
        .sum();

    println!("{}", ans);
}


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

using namespace std;

#define ll long long

int main()
{
    ll h, n, a;
    cin >> h >> n;
    ll sum = 0;
    while(n--)
    {
        cin >> a;
        sum += a;
    }

    if(sum < h) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

int main(){
	int s,ans=1,cnt=0;
    cin >> s;
    if(s==1||s==2)
      cnt =4;
    else{
      while(s>1){
      if(s%2==0)
       	s = s/2;
      else
        s = 3*s+1;
      ans++;
      }
      cnt = ans + 1;
    }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = (int)1e9 + 7;
const int INF = (int)1e9;
const int N = (int)1e6 + 10;
const int MAXA = (int)3e6;


ll deg[N],t[N];

ll binpow(ll a,ll n){
    ll res = 1;
    while(n){
        if(n & 1)res = res * a,res %= mod;
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll a){
    return binpow(a, mod - 2);
}
ll C(ll n, ll k){
    return (((t[n] * inv(t[k])) % mod) * inv(t[n - k])) % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    ll n;
    cin >> n;
    t[0] = 1;
    for(ll i = 1;i <= n;i++)t[i] = (t[i - 1] * i) % mod;
    ll ans = 0;
    deg[0] = 1;
    for(int i = 1;i <= n;i++)deg[i] = (deg[i - 1] * 8) % mod;
    for(ll i = 2;i <= n;i++){
        ans += (((C(n, i) * deg[n - i]) % mod) * ((binpow(2, i) - C(i, 0) - C(i, i) + mod) % mod) % mod);
        ans %= mod;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 19136
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Ford(i,a,b) for(int i=(a);i>=(b);--i)
#define fio(s) freopen(s".inp","r",stdin)
#define foo(s) freopen(s".out","w",stdout)
#define task "test"
using namespace std;
typedef long long LL;
const LL N=3009,OO=1e9+7;
LL n,m,f[N][N];
string a,b;
vector<char> ans;
void trace(LL i, LL j){
    if(i<=0||j<=0) return;
    if(f[i-1][j-1]+1==f[i][j]&&a[i]==b[j]) {ans.push_back(a[i]); trace(i-1,j-1);}
    else if(f[i-1][j]>f[i][j-1]) trace(i-1,j);
    else trace(i,j-1);
}
int main(){
    //fio(task); foo(task);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>a>>b; n=a.length(); m=b.length();
     a='#'+a; b='#'+b;
    For(i,1,n)
    For(j,1,m)
        if(a[i]==b[j]){
            f[i][j]=f[i-1][j-1]+1;
        }else f[i][j]=max(f[i-1][j],f[i][j-1]);
    //cout<<f[n][m]<<endl;
    trace(n,m);
    Ford(i,ans.size()-1,0)
        cout<<ans[i];
    return 0;
}


Measured memory_bytes: 70784
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
const int MOD = (int)1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()


int main(int argc, char const *argv[]) {
vector<int> v(6);
REP(i,6){
  cin>>v[i];
}
REP(i,5){
  FOR(j,i,5){
    if(abs(v[i]-v[j])>v[5]){
      cout<<":("<<endl;
      return 0;
    }
  }
}
cout<<"Yay!"<<endl;



return 0;
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

void panic() {
	puts("NO");
	exit(0);
}

int main() {
	int n = nxt(), m = nxt(), a = nxt(), b = nxt();
	int max_hor = n * (m / 2);
	int max_ver = (n / 2) * m;

	if (a > max_hor || b > max_ver || (a + b) * 2 > n * m) {
		panic();
	}

	vector<string> ans(n, string(m, '.'));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j + 1 < m; j += 2) {
			ans[i][j] = '<';
			ans[i][j + 1] = '>';
		}
	}
	if (m % 2) {
		for (int i = 0; i + 1 < n; i += 2) {
			ans[i][m - 1] = '^';
			ans[i + 1][m - 1] = 'v';
		}
	}
	if ((a + b) * 2 == n * m) {
		if (a % 2 != max_hor % 2) {
			panic();
		}

		for (int i = 0; i + 1 < n; i += 2) {
			if (max_hor == a) {
				break;
			}
			for (int j = 0; j + 1 < m; j += 2) {
				if (max_hor == a) {
					break;
				}
				max_hor -= 2;
				ans[i][j] = ans[i][j + 1] = '^';
				ans[i + 1][j] = ans[i + 1][j + 1] = 'v';
			}
		}
	} else if ((a + b) * 2 + 1 == n * m) {
		if (a % 2 != max_hor % 2) {
			assert(n >= 3 && m >= 3);
			ans[n - 2][m - 3] = '^';
			ans[n - 1][m - 3] = 'v';
			ans[n - 1][m - 2] = '<';
			ans[n - 1][m - 1] = '>';
			ans[n - 2][m - 2] = '.';
			--max_hor;
		}

		for (int i = 0; i + 1 < n; i += 2) {
			if (max_hor == a) {
				break;
			}
			for (int j = 0; j + 1 < m; j += 2) {
				if (max_hor == a) {
					break;
				}
				max_hor -= 2;
				ans[i][j] = ans[i][j + 1] = '^';
				ans[i + 1][j] = ans[i + 1][j + 1] = 'v';
			}
		}
	} else {
		ans = vector<string>(n, string(m, '.'));
		if (n % 2) {
			for (int j = 0; j + 1 < m; j += 2) {
				if (a) {
					--a;
					ans[n - 1][j] = '<';
					ans[n - 1][j + 1] = '>';
				}
			}
		}
		if (m % 2) {
			for (int i = 0; i + 1 < n; i += 2) {
				if (b) {
					--b;
					ans[i][m - 1] = '^';
					ans[i + 1][m - 1] = 'v';
				}
			}
		}
		for (int i = 0; i + 1 < n; i += 2) {
			for (int j = 0; j + 1 < m; j += 2) {
				if (a) {
					ans[i][j] = '<';
					ans[i][j + 1] = '>';
					--a;
					if (a) {
						ans[i + 1][j] = '<';
						ans[i + 1][j + 1] = '>';
						--a;
					}
				} else if (b) {
					ans[i][j] = '^';
					ans[i + 1][j] = 'v';
					--b;
					if (b) {
						ans[i][j + 1] = '^';
						ans[i + 1][j + 1] = 'v';
						--b;
					}
				}
			}
		}
	}

	printf("YES\n");
	for (auto s : ans) {
		printf("%s\n", s.c_str());
	}

	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    ll hoge = 1;
    int cnt2 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] /= 2;
        if (a[i] % 2 == 0) cnt2++;
        if (hoge <= m) hoge = a[i] / __gcd(a[i], hoge) * hoge;
    }
    ll ans = (m / hoge + 1) / 2;
    if (hoge <= m) {
        for (int i = 0; i < n; ++i) {
            if (hoge / a[i] % 2 == 0) {
                ans = 0;
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
c = [list(map(int, input().split())) for i in range(3)]

if c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1] and \
    c[0][1] - c[0][2] == c[1][1] - c[1][2] == c[2][1] - c[2][2] and \
    c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2] and \
    c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", bool, "haspair");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto red = new Pair[](n);
    auto blue = new Pair[](n);
    foreach (i; iota(n))
    {
        long a, b;
        scan(a, b);
        red[i] = Pair(a, b, false);
    }
    foreach (j; iota(n))
    {
        long c, d;
        scan(c, d);
        blue[j] = Pair(c, d, false);
    }
    red.sort!"a.x<b.x"();
    blue.sort!"a.x<b.x"();
    long count;
    foreach (i; iota(n))
    {
        long maxy = -1;
        foreach (j; iota(n))
        {
            if (red[j].x > blue[i].x)
                break;

            if (red[j].haspair)
                continue;

            if (maxy < 0 || red[j].y > red[maxy].y)
            {
                if (red[j].y < blue[i].y)
                    maxy = j;
            }
        }
        if (maxy >= 0)
        {
            red[maxy].haspair = true;
            count++;
        }
    }
    count.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2808
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
x=0
y=0
z=0
for p in P:
  if p<=A:
    x+=1
  elif A+1<=p and p<=B:
    y+=1
  else:
    z+=1
print(min(x,y,z))    

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
using ll = long long;
using IR = pair<int, int>;

int K, N, A[200000];

int main() {
	S2(K, N);
	R(i, N) scanf("%d", A + i);
	int ans = K - (A[0] + (K - A[N - 1]));
	for (int i = 1; i < N; i++) {
		int range = K - (A[i] - A[i - 1]);
		ans = min(ans, range);
	}
	P(ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;

vector<vector<int>> suretsu;



int main()
{
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<lint>> a(q, vector<lint>(4));
  REP(i,q) cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];

  vector<int> res(n+1, m);
  res[0] = 0;
  lint max = 0;
  while(res[1] != 0){
    //処理
    //REP(i,n+1) cout << res[i];
    //cout << "\n";
    lint cnt = 0;
    REP(i,q){
      if(res[a[i][1]]-res[a[i][0]] == a[i][2]) cnt += a[i][3];
    }
    if(cnt > max) max = cnt;
    //数列のカウントダウン
    IFOR(i,1,n+1){
      if(res[i-1] < res[i]){
        res[i]--;
        FOR(j,i+1,n+1) res[j] = m;
        break;
      }
    }
  }

  cout << max << "\n";
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    long long arr[100000]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    long long b=1,mx=0;
    bool f=false,z=false;
    for(int i=0;i<n;i++){
        if(arr[i]==0){
            z=true;
            break;
        }
    }
    if(z){
        cout<<0<<'\n';
    }else{
        for(int i=0;i<n;i++){
            b*=arr[i];
            if(arr[i]>mx){
                mx=arr[i];
            }
            if(b<mx){
                f=true;
                break;
            }

        }
        if(b>1000000000000000000||f){
            cout<<-1<<'\n';
        }else{
            cout<<b<<'\n';
        }
    }

    return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


Measured memory_bytes: 4376
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ld r;std::cin >> r;
  std::cout << fixed << setprecision(20) << 2*r*M_PI << '\n';
  return 0;
}


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

#define ll long long
#define ld long double

void solve() {
	ll num1;
	ld num2;
	ld ans;
	cin >> num1 >> num2;
	ans = num1 * num2;
	cout << (ll)ans << endl;
}

int main() {
	solve();

	return 0;
}

Measured memory_bytes: 3732
/*https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	long long n, m;
	cin >> n >> m;
	if (n == 1 || m == 1)
	{
		cout << "1";
	}
	else if (n * m % 2 != 0)
		cout << n*m / 2 + 1;
	else
		cout << n*m / 2;
}

Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String[] v = br.readLine().split(" ");
			int a = Integer.parseInt(v[0]);
			int b = Integer.parseInt(v[1]);

			if (a < b) {
				System.out.println("a < b");
			} else if (a > b) {
				System.out.println("a > b");
			} else {
				System.out.println("a == b");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24312
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
typedef struct Node
{
  int key;
  struct Node *next,*prev;
}Node;
 
Node *nl;
 
Node* listSearch(int key)
{
  Node *cu=nl->next;
  while(cu!=nl && cu->key !=key)
    {
      cu=cu->next;
    }
  return cu;
}
 
void init()
{
  nl=(Node *)malloc(sizeof(Node));
  nl->next=nl;
  nl->prev=nl;
}
 
void printlist()
{
  Node*cu=nl->next;
  int f=0;
  while(1)
    {
      if(cu==nl) break;
      if(f++>0)printf(" ");
      printf("%d",cu->key);
      cu=cu->next;
    }
  printf("\n");
}
 
void deleteNode(Node *r)
{
  if(r==nl)return;
  r->prev->next=r->next;
  r->next->prev=r->prev;
  free(r);
}
 
void deletefirst()
{
  deleteNode(nl->next);
}
 
void deletelast()
{
  deleteNode(nl->prev);
}
 
void deletekey(int key)
{
  deleteNode(listSearch(key));
}
 
void insert(int key)
{
  Node *a=(Node *)malloc(sizeof(Node));
  a->key=key;
  a->next=nl->next;
  nl->next->prev=a;
  nl->next=a;
  a->prev=nl;
}
 
int main()
{
  int key,i,n;
  int cnt=0;
  char order[20];
  int p=0,d=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++)
    {
      scanf("%s%d",order,&key);
      if(order[0]=='i')
    {
      insert(key);
      p++;
      cnt++;
    }
      else if(order[0]=='d')
    {
      if(strlen(order)>6)
        {
          if(order[6]=='F') deletefirst();
          else if(order[6]=='L')deletelast();
        }
      else
        {
        deletekey(key);
        d++;
        }
      cnt--;
    }
    }
  printlist();
  return 0;
}

Measured memory_bytes: 31788
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
int main()
{
    //fast
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,p=0;
        cin>>n;
        string s;
        cin>>s;
        ll l=0,r=n-1;
       while(l<r)
        {
            while(s[l]!='W' && l<n)
            {
                l++;
            }
            while(s[r]!='R' && r>=0)
            {
                r--;
            }
            if(l<r){
            swap(s[l],s[r]);
            p++;
            }
        }
        cout<<p;

    }
    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

template <typename T>
struct li_chao_tree {
    const T INF = numeric_limits<T>::max();
    struct line {
        T a, b;
        line(T a, T b) : a(a), b(b) {}
        T eval(T x) { return a*x + b;}
    };
    int n;
    vector<line> data;
    vector<T> pos;
    
    li_chao_tree(int n) {
        pos.resize(n);
        iota(pos.begin(), pos.end(), 0);
        init(n);
    }
    
    li_chao_tree(const vector<T>& pos_) : pos(pos_) {
        sort(pos.begin(), pos.end());
        init(pos.size());
    }

    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        while ((int)pos.size() < n) pos.emplace_back(pos.back() + 1);
        data.assign(n<<1, line(0, INF));
    }

    void add_line(T a, T b) {
        line x(a, b);
        update(1, 0, n-1, x);
    }

    inline bool over(line& a, line& b, T lb, T ub) {
        return a.eval(lb) >= b.eval(lb) && a.eval(ub) >= b.eval(ub);
    }
    
    void update(int k, int l, int r, line& x) {
        T lb = pos[l], ub = pos[r];
        if (over(x, data[k], lb, ub)) return;
        if (over(data[k], x, lb, ub)) {
            data[k] = x;
            return;
        }
        int c = (l+r) >> 1;
        if (x.eval(pos[c]) < data[k].eval(pos[c])) swap(x, data[k]);
        if (x.eval(lb) <= data[k].eval(lb)) update(k<<1|0, l, c, x);
        else update(k<<1|1, c+1, r, x);
    }

    T get_min(ll x) {
        int i = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
        T res = INF;
        int k = i + n;
        while (k > 0) {
            res = min(res, data[k].eval(pos[i]));
            k >>= 1;
        }
        return res;
    }
};

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

    int n; ll c;
    cin >> n >> c;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    vector<ll> pos(n);
    rep(i, n) pos[i] = -2 * h[i];
    li_chao_tree<ll> seg(pos);
    
    vector<ll> dp(n);
    for (int i = 1; i < n; ++i) {
        seg.add_line(h[i-1], dp[i-1] + h[i-1] * h[i-1]);
        dp[i] = seg.get_min(-2 * h[i]) + h[i] * h[i] + c;
    }
    cout << dp[n-1] << endl;
    
}


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

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    string data[] = {"dream", "dreamer", "erase", "eraser"};

    for(int i = 0 ; i < 4 ; i++){
        reverse(data[i].begin(), data[i].end());
    }

    int now = 0;
    while(1){
        bool flag = false;
        for(int i = 0 ; i < 4 ; i++){
            if(s.substr(now, data[i].size()) == data[i]){
                flag = true;
                now += data[i].size();
                break;
            }
        }
        if(now >= s.size()){
            cout << "YES" << endl;
            return 0;
        }
        if(!flag){
            cout << "NO" << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 512
A, B, C = map(int, input().split())
K = int(input())
arr = [A, B, C]
for _ in range(K):
    arr1 = 2 * arr[0] + arr[1] + arr[2]
    arr2 = arr[0] + 2 * arr[1] + arr[2]
    arr3 = arr[0] + arr[1] + 2 * arr[2]
    tmp = [arr1, arr2, arr3]
    idx = tmp.index(max(tmp))
    arr[idx] *= 2
print(sum(arr))


Measured memory_bytes: 3064
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int a, b, c, d, n;
    cin >> a >> b >> c >> d >> n;
    int one = min(4 * a, min(2 * b, c));
    if (one + one <= d) {
        cout << 1LL * n * one << endl;
    } else {
        cout << 1LL * (n / 2) * d + (n & 1) * one << endl;
    }
    return 0;
}


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

int main(){

  int N;
  string s;
  int numR = 0,numB = 0;



  cin >>N>>s;

  for(int i = 0;i<N;i++){
    if(s[i] == 'R')numR++;
    else numB++;
  }


  if(numR > numB){
    cout <<"Yes"<<endl;
  }else cout <<"No"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int o,f;
	o = 0;
	f = 0;

	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		if (n % 4 == 0) f++;
		if (n % 2) o++;
	}

	if (o > f) {
		if ((o + f == N) && (o - 1 == f)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  
  vector<ll> a(n), b(n + 1);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  for (int i = n - 1; i >= 0; i--) {
    b.at(i) = a.at(i);
    if (i < n - 1) b.at(i) += b.at(i + 1);
  }
  
  ll l = 0, r = 200001;
  while (r - l > 1) {
    ll mid = (l + r) / 2;
    ll count = 0;
    for (int i = 0; i < n; i++) {
      count += a.end() - lower_bound(a.begin(), a.end(), mid - a.at(i));
    }
    if (count >= m) l = mid;
    else r = mid;
  }
  
  ll ans = 0, count = 0;
  for (int i = 0; i < n; i++) {
    ll left2 = 0, right2 = n;
    if (a.at(i) + a.at(0) >= l) right2 = 0;
    while (right2 - left2 > 1) {
      ll mid = (left2 + right2) / 2;
      if (a.at(i) + a.at(mid) >= l) right2 = mid;
      else left2 = mid;
    }
    ans += b.at(right2) + a.at(i) * (n - right2);
    count += n - right2;
  }
  
  if (count > m) ans -= l * (count - m);
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
<?php

function chmin(&$a, $b) {
    if ($a > $b) {
        $a = $b;
    }
}

fscanf(STDIN, "%d %d", $n, $k);
$h = explode(' ', trim(fgets(STDIN)));

$dp = array_fill(0, $n, PHP_INT_MAX);
$dp[0] = 0;
$dp[1] = abs($h[1] - $h[0]);

for ($i = 2; $i < $n; ++$i) {

    $junp_count = min($i, $k);
    for ($j = 1; $j <= $junp_count; ++$j) {
        chmin($dp[$i], $dp[$i - $j] + abs($h[$i] - $h[$i - $j]));
    }
}

echo $dp[$n - 1];


Measured memory_bytes: 16884
def digit_sum(num):
    total_num = 0
    while num > 0:
        total_num += num % 10
        num //= 10
    return total_num
num_list= []
n, a, b = map(int, input().split())
for i in range(1,n+1):
    num = digit_sum(i)
    if num >= a and num <= b:
        num_list.append(i)
print(sum(num_list))

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int x, n;
    cin >> x >> n;
    vector<bool> check(100, true);
    rep(i, n){
        int p;
        cin >> p;
        check[p-1] = false;
    }
    bool flag=true;
    int ans = 0;
    if(check[x-1]){
        ans = x;
        flag = false;
    }

    int dis=1;
    while(flag){
      if (x - 1 - dis>=0){
        if (check[x - 1 - dis]){
          ans = x - dis;
          flag = false;
        }
      }else{
        flag = false;
        break;
      }

      if (flag && x - 1 + dis < 100) {
        if (check[x - 1 + dis]){
          ans = x + dis;
          flag = false;
        } 
      }else{
          if(flag){
            ans = 101;
            flag = false;
          }
      }
        dis++;
        // if (x - 1 - dis < 0 && x - 1 + dis >= 100){
        //     flag = false;
        // }
    }

    cout << ans << endl;

    return 0;
}

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

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

    int N, M; cin >> N >> M;
    int l = 1, r = N;
    for (int i = 0; i < M; i++) {
        int L, R; cin >> L >> R;
        l = max(l, L);
        r = min(r, R);
    }
    cout << (l > r ? 0 : r - l + 1) << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

INF = pow(10,6)

# @njit
def solve(n,a):
  res = INF
  for i in range(1,101):
    res = min(res,sum(pow(i-x,2) for x in a))
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 3e6 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
	string s;
	cin >> s;
	deque<char> q;
	for (int i = 0; i < s.size(); i ++) {
		q.pb(s[i]);
	}
	ll rev = 0;
	ll g;
	cin >>g;
	while (g --) {
		ll t;
		cin >> t;
		if (t == 1) {
			rev ^= 1;
		}
		else {
			ll f;
			cin >> f;
			char c;
			cin >> c;
			if (f == 1 && !rev) q.push_front(c);
			if (f == 2 && rev) q.push_front(c);
			if (f == 1 && rev) q.pb(c);
			if (f == 2 && !rev) q.pb(c); 
		}
	}
	string t = "";
	for (auto k : q) t += k;
	if (rev) reverse(all(t));
	cout << t;
    return (0);
}

Measured memory_bytes: 1368
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll x, y;
	cin>>x>>y;
	ll z = x*(y-1);
	if(x%y==0) cout<<-1<<endl;
	else cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 764
# -*- coding: utf-8 -*-
import collections
import copy
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

dq = collections.deque([])
list_val_a = []

for i in range(1, m+1):
    dq.append([i])

while(len(dq) > 0):
    tmp_la = dq.popleft()
    # print(tmp_la)
    last_ai = tmp_la[-1]
    # print(last_ai)
    for j in range(last_ai, m+1):
        t_tmp_la = copy.copy(tmp_la)
        # print("j: " + str(j))
        t_tmp_la.append(j)
        if len(t_tmp_la) >= n:
            list_val_a.append(t_tmp_la)
        else:
            dq.append(t_tmp_la)

max_score = 0
for lai in list_val_a:
    tmp_score = 0
    for j in range(q):
        if lai[b[j]-1]-lai[a[j]-1] == c[j]:
            tmp_score += d[j]
    if tmp_score > max_score:
        max_score = tmp_score

print(max_score)



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

int main () {
  int a,b,c;
  cin>>a>>b>>c;
  if(a == b+c || b== c+a || c== a+b){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

const int64_t MOD= 1000000007;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};
// ^^^ テンプレここまで ^^^

mint solve(const string &N){// a + b = (a XOR b)+ 2*(a AND b)より、
                            // 求めるのは a XOR b <= L, a AND b = 0 なる(a,b)の組み合わせ
  mint dp0= 1;
  mint dp1= 2;
  mint buf0,buf1;
  for(int i=1; i<N.size(); i++){
    if(N.at(i)=='1'){
      buf0= dp0* 3+ dp1;
      buf1= dp1* 2;
    }
    else{
      buf0= dp0* 3;
      buf1= dp1;
    }
    dp0= buf0; dp1= buf1;
  }

  return dp0+ dp1;
}

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

  cout << solve(N) << endl;
}

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

using namespace std;

long long gcd(long long a, long long b){
    if(b == 0){ return a;}
    return gcd(b, a%b);
}
long long lcm(long long a, long long b) { 
    long long g = gcd(a,b);
    return (a/g)*b; 
}


int main(){
  int n;
  cin >> n;
  long long tmp;
  int a4 = 0, a2 = 0, odd = 0;
  for(int i = 0; i < n; i++){
      cin >> tmp;
      if(tmp % 4 == 0){
          a4++;
      }else if(tmp % 2 == 1){
          odd++;
      }else{
          a2++;
      }
  }
//    cout << a4 << "," << odd << endl;
  if(a4 >= odd + a2 - 1 || (a4 >= odd  && a2 >= 2) || (a4 >= odd)){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }

  return 0;
} 

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

#define fi first
#define se second
#define eb emplace_back

typedef long long ll;

using namespace std;

const int nm = 100002;

int n, m;
vector<int>adj[nm];
bool vs[nm];

void dfs(int i) {
	vs[i] = 1;
	for (int j: adj[i]) {
		if (!vs[j]) {
			dfs(j);
		}
	}
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
    	int u, v;
    	cin >> u >> v;
    	adj[u].eb(v);
    	adj[v].eb(u);
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
    	if (!vs[i]) {
    		res++;
    		dfs(i);
    	}
    }
    cout << res - 1 << "\n";
}


Measured memory_bytes: 9664
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n=II()
	A=[0]+[II() for _ in range(n)]

	a=1

	for i in range(n+3):
		if a==2:
			ans=i
			break
		a=A[a]
	else:
		ans=-1

	print(ans)









if __name__ == "__main__":
	main()


Measured memory_bytes: 13672
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#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 WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>
 
#define pb(a) push_back(a)
#define mp make_pair
 
ll Kai(ll t){
  int tt=1;
  FOR(i,2,t+1)tt*=i;
  return tt;
}
int main(){

  CIN(n,p);V a(n);VECCIN(a);
  V cou(2,0);REP(i,n)(a[i]%2==1?cou[1]:cou[0])++;
  if(cou[1]==0){
    COUT(p==0?1LL<<n:0);
    return 0;
  }
  COUT(1LL<<(n - 1));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector> 
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    vector<long long> A(N);
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < N; i++){
        if(A[i] % 2 != 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = 0;
    bool check = true;
    
    do{
        
        for(int i = 0; i < N; i++){
            
            if(A[i] % 2 != 0){
                check = false;
                
            }
            else{
                A[i] /= 2;
            }
        }
        
        if(check) ans++;

    }while(check);

    cout << ans << endl;
    
}


Measured memory_bytes: 256
import sys
X,n=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]

nai=[]
if n==0:
  print(X)
  sys.exit()
else:
  if X not in p:
    print(X)
    sys.exit()
  else:
    for i in range(-200,301):
      if i not in p:
        nai.append(i)
    nai.append(X)
    nai.sort()

    ind=nai.index(X)
    
    if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
      print(nai[ind-1])
      sys.exit()
    else:
      print(nai[ind+1])
      sys.exit()



Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(v,a) for(auto &v:a)
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(a) a.begin(),a.end()
int re(){int x=0; char c; bool neg=false;while(c!='-'&&(c<'0'||'9'<c)) c=getchar();if (c=='-'){neg=true; c=getchar();}while ('0'<=c && c<='9'){x=x*10+c-'0';c=getchar();}if (neg) x=-x;return x;}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ran(int l, int r) {return l+rng()%(r-l+1);}
typedef long long ll;
const int N=100010;
int n;
int a[4][N],f[N][4];
int main()
{
    //freopen("vacation.inp","r",stdin);
    cin>>n;
    forinc(i,1,n) cin>>a[0][i]>>a[1][i]>>a[2][i];
    forinc(i,0,n-1) forinc(j,0,2)
    {
        forinc(J,0,2) if (j!=J) f[i+1][J]=max(f[i+1][J],f[i][j]+a[J][i+1]);
    }
    cout<<max({f[n][0],f[n][1],f[n][2]});
}


Measured memory_bytes: 2944
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto s = readln.chomp;
  auto k = readln.chomp.to!long;
  
  int index;
  foreach (e; s) {
    if (e != '1') {
      break;
    }
    index++;
  }

  if (index.to!long >= k) {
    writeln("1");
  } else {
    s[index].writeln;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

std::vector<ll> fn;

int solve(int a){
  if(a<0){
    for(int i=0;i<fn.size();i++){
      if(2*(fn[i]-1)/3 >= abs(a)){
        int rt = 2*(fn[i]-1)/3;
        for(int j=i;j>=0;j--) if(rt-abs(a)>=2*fn[j]) rt-=2*fn[j];
        return -rt;
      }
    }
  }else{
    for(int i=0;i<fn.size();i++){
      if((fn[i]-1)/3 >= abs(a)){
        int rt = (fn[i]-1)/3;
        for(int j=i;j>=0;j--) if(rt-abs(a)>=fn[j]) rt-=fn[j];
        return rt;
      }
    }
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  ll N, reg=1, reg2=-1, ans=0;
  std::cin >> N;
  std::vector<int> data;
  while(reg<100000000000000) {
    fn.push_back(reg);
    reg *=4;
  }
  while(N!=0 && reg2 !=0){
    reg2 = solve(N);
    N = N - reg2;
    ans += abs(reg2);
  }
  while(ans>0){
    data.push_back(ans%2==1?1:0);
    ans /= 2;
  }
  if(data.size()!=0) for(int i=data.size()-1;i>=0;i--) std::cout << data[i];
  else std::cout << 0;
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda:sys.stdin.readline().strip()
n,k = map(int,input().split())
vis = [False]*n
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for i in a:
        vis[i-1]=True
ans = vis.count(False)
print(ans)

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

typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;

#define MOD1        1000000007
#define MOD2        998244353
#define PI          3.1415926535897932384626433832795
#define FILL(a, value) memset(a, value, sizeof(a))
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ASSERT(left,operator,right) { if(!((left) operator (right))){ std::cerr << "ASSERT FAILED: " << #left << #operator << #right << " @ " << __FILE__ << " (" << __LINE__ << "). " << #left << "=" << (left) << "; " << #right << "=" << (right) << std::endl; } }

#define rep01(k,n)      for (ll i=k; i<n; i++)
#define rep02(k,n)      for (ll j=k; j<n; j++)
#define rep03(k,n)      for (ll k=k; k<n; k++)
#define rep11(k,n)      for (ll i=k; i<=n; i++)
#define rep12(k,n)      for (ll j=k; j<=n; j++)
#define rep13(k,n)      for (ll k=k; k<=n; k++)
#define repIT(c,it)     for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define all(c)      c.begin(), c.end()

using namespace std;

const double pi = acos(-1.0);
const double epsilon = 1e-9;        // Add epsilon when casting double to int to avoid rounding pitfall issues, eg, 0.94*8178 in int
const int maxn = 1e6+10;


void solve()
{
    string a, b;
    cin >> a >> b;

    ll n = stoi(a+b);
    if(floor(sqrt(n)) == ceil(sqrt(n)))
        cout << "Yes";
    else
        cout << "No";
}

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

    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3824