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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

//wierd debugging stuff
#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 << "\n" ; }
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__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}

// no change 
const ll MOD = 1e9+7;  
int n;
const int mx = 2e5;
int H[mx];
int dp[mx];
void Titan(){
	read(n);
	fo(n)cin >> H[i+1];
	dp[0] =0;
	
	fo(i,2,n+1){
		dp[i] = MOD;
		if(i-1>0)umin(dp[i] ,dp[i-1] + abs(H[i] - H[i-1]));
		if(i-2>0)umin(dp[i] , dp[i-2] + abs(H[i] - H[i-2]));
	}

	cout << dp[n];

	debug() << range(dp,dp+n+1);








}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T--){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


Measured memory_bytes: 4440
#include <iostream>
#include <string>
#include <array>

using namespace std;

int main() {
    string l;

    array<int32_t, 27> count = {0};

    while (cin >> l) {
        for (uint8_t c : l) {
            if ('A' <= c && c <= 'Z') {
                count[c - 'A']++;
            } else if ('a' <= c && c <= 'z') {
                count[c - 'a']++;
            }
        }
    }

    for (uint8_t c = 'a'; c <= 'z'; c++) {
        cout << c << " : " << count[c - 'a'] << endl;
    }

    return 0;
}

Measured memory_bytes: 3048
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N;
int a[100010];

int b[100010];

int c[100010];
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    for(int i=0;i<N;i++){
        cin>>b[i];
    }
    
    sort(b,b+N);
    for(int i=0;i<N;i++){
        cin>>c[i];
    }
    sort(c,c+N);
    LL ans=0;
    for(int i=0;i<N;i++){
        ans+=(lower_bound(a,a+N,b[i])-a)*(N-(upper_bound(c,c+N,b[i])-c));
    }
    cout<<ans;
    return 0;
}


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

ll sum(ll a, ll b) {
    return (a+b)*(b-a+1)/2;
}

int main() {
  long long mod = 1000000007;
  long long n, k; cin >> n >> k;
  long long ans;

  for (long long i=k; i<=n+1; i++){
    ll l = sum(0,i-1)/*小さい方からk個の和(=min)*/, r = sum(n-i+1,n);/*大きい方からk個の和(=max)*/
    ans += r-l+1;
  }   
    cout << ans%mod << "\n";
    return 0;
}


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

long long MOD=1000000007;

long long fac[2000002],finv[2000002],inv[2000002];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<2000002;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;
}

long long a(int r,int c){
	long long ret=0;
	for(int i=0;i<=r;i++){
		ret+=COM(i+1+c,c);
		ret%=MOD;
	}
	return ret;
}

int main(){
	COMinit();
	int r1,c1,r2,c2;
	cin >> r1 >> c1 >> r2 >> c2;
	
	cout << (a(r2,c2)-a(r2,c1-1)-a(r1-1,c2)+a(r1-1,c1-1)+MOD*2)%MOD << endl;
	
	return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> vec(32); 
    vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << vec[K-1];
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[31],i,n;
	for(i=1;i<=30;i++){
		a[i]=0;
	}
	for(i=1;i<=28;i++){
		scanf("%d",&n);
		a[n]=1;
	}
	for(i=1;i<=30;i++){
		if(a[i]==0){
		printf("%d\n",i);
		}}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = sc.nextInt();
		boolean reverse = false;
		StringBuilder sb = new StringBuilder(s);
		StringBuilder mae = new StringBuilder();
		for (int i = 0; i < n; i++) {
			int q = sc.nextInt();
			if(q == 1) {
				reverse = !reverse;
			} else {
				int q2 = sc.nextInt();
				if(reverse) q2 = q2%2+1;
				if(q2 == 1) {
					mae.append(sc.next());
				} else {
					sb.append(sc.next());
				}
			}
		}
		mae.reverse();
		mae.append(sb);
		if(reverse) mae.reverse();
		System.out.println(mae.toString());
	}
}


Measured memory_bytes: 124772
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


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

int32_t main()
{
	Raghav();
	int t;
	cin >> t;
	if(t>=30)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3520
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
 

public class Main{
          
     static int[][] hisigata=new int[100][100];
     static int[][] sumHisi=new int[100][100];
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{ String line; int readC=0;
             while((line=br.readLine())!=null){if(line.isEmpty())break;
             String spl[]=line.split(",");
             for(int i=0; i<spl.length;i++) hisigata[readC][i]=Integer.parseInt(spl[i]);
             readC++;             
             } br.close();
             int hisiSize=readC;sumHisi[hisiSize-1][0]=hisigata[hisiSize-1][0];
            for(int i=hisiSize-1;i>=hisiSize/2 ;i--){
                int hisiYouso=hisiSize-i;
                for(int j=0;j<hisiYouso;j++){
                    if(j==0)sumHisi[i][j]=hisigata[i][j]+sumHisi[i+1][j];
                    else sumHisi[i][j]=hisigata[i][j]+Math.max(sumHisi[i+1][j-1],sumHisi[i+1][j]);
                }
            }
            for(int i=hisiSize/2 -1; i>=0;i--){
                int hisiYouso=i+1;
                for(int j=0;j<hisiYouso;j++){
                    sumHisi[i][j]=hisigata[i][j]+Math.max(sumHisi[i+1][j],sumHisi[i+1][j+1]);
                }
            }
            
            /*for(int i=0;i<=8;i++){
                for(int j=0;j<=6;j++){System.out.print(sumHisi[i][j]+" ");}
                System.out.println("");
            }*/
             System.out.println(sumHisi[0][0]);
         }catch(Exception e){e.printStackTrace();}         
     }  
     
     
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 4000

// 400, 2h で解けず解答を見る

ll N, X;
ll A[MAX_N];

int n;                      // 葉の数。2 のべき乗を入力する。 2 のべき乗でないなら NOTE 参照
int dat[MAX_N * 2 - 1];     // 配列は余裕を持って取っておいた方がいいかも（以前ここで RuntimeError になった）
// セグメント木での Range Minimum Query (RMQ) の実装
// 区間[i, j] に含まれる最小値の取得と、値の更新
// 初期化
void init() {
    REP(i, 2*n-1){ dat[i] = INT_MAX; }
}
// 値の更新 O(log n)
// i 番目の値 (0-indexed) を x に変更
void update(int i, int x) {
    // 葉の番号
    i += n - 1;
    dat[i] = x;
    // 登りながら更新
    while(i>0) {
        i = (i-1)/2;
        dat[i] = min(dat[i*2+1], dat[i*2+2]);
    }
}
// 最小値の取得 O(log n)
// [a, b) の最小値、 l, r にはノード k に対応づく区間を与える
// 一番初めは query_impl(a, b, 0, 0, n) のように呼ぶ
int query_impl(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l){ return INT_MAX; } // 交差しない？
    if(a <= l && r <= b){ return dat[k]; }  // 完全に含む？
    else {
        int vl = query_impl(a, b, k * 2 + 1, l, (l + r) / 2);    // 左の子を見る
        int vr = query_impl(a, b, k * 2 + 2, (l + r) / 2, r);    // 右の子を見る
        return min(vl, vr);
    }
}
// [a, b) の最小値を返す O(log n)
int query(int a, int b) {
    return query_impl(a, b, 0, 0, n);
}
// NOTE: n が 2 のべき乗じゃない場合は値の更新を再帰関数で書き換え、配列サイズを MAX_N * 4 にする
// もしくは、 n を 2 のべき乗にしてしまって、元の n - 2 のべき乗までは適当な値で埋める
// この場合には以下の関数が有用↓↓
// 2 のべき乗かどうか判定
// 2 のべき乗なら 0 を、そうでないなら一番近い num より大きい 2 のべき乗までの差を返す
int isPow(int num) {
    int res = 1;
    while(res < num) { res *= 2; }
    if(res == num) { return 0; }
    else { return res - num; }
}

int main()
{
    cin >> N >> X;
    REP(i, N) { cin >> A[i]; }

    // セグ木の作成
    n = N + isPow(N);
    init();
    REP(i, N) { update(i, A[i]); }

    ll ans = -1;
    for(int i = 0; i < N; ++i) {
        // i 回魔法を使うとする
        ll cand = 0;
        for(int j = 0; j < N; ++j) {
            // A[j] を手に入れるのに最小の秒数を求める
            // [j-i, j] までで最小の a を求めればよい
            if(j - i < 0) {
                cand += min(query(N - abs(j - i), N), query(0, j + 1));
            } else {
                cand += query(j - i, j + 1);
            }
        }
        if(ans < 0) {
            ans = cand + i * X;
        } else {
            ans = min(ans, cand + i * X);
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll h,w;
    char c[110][110];
    bool H[110]={},W[110]={};
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
            if(c[i][j]=='#'){
                H[i]=true;
                W[j]=true;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(H[i]==false) continue;
        for(int j=0;j<w;j++){
            if(W[j]) cout<<c[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3604
package main

import (
	"fmt"
)

func some(n int) int {
	var sum int
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

func main() {
	var n, a, b, count int
	fmt.Scan(&n, &a, &b)
	for i := 1; i <= n; i++ {
		sum := some(i)
		if a <= sum && sum <= b {
			count += i
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

lli findSum(lli val)
{
    lli j=n-1,cnt=0,sum=0;
    for(auto x:a)
    {
        while(j>=0&&val-x<=a[j])
        {
            sum+=a[j];
            j--;
        }
        cnt+=sum+(n-1-j)*x;
    }
    return cnt;
}

lli count(lli val)
{
    lli j=n-1,cnt=0;
    for(auto x:a)
    {
        while(j>=0&&val-x<=a[j])
            j--;
        cnt+=n-1-j;
    }
    dbg(val,cnt);
    return cnt;
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m;
    a.clear();a.reserve(n);

    fo(i,n)
    {
        cin>>in;
        a.pb(in);
    }

    sort(all(a));

    lli l=0,r=INF;
    while(r-l>1)
    {
        lli mid=(l+r)/2;
        if(count(mid)>=m)
            l=mid;
        else
            r=mid;
    }
    dbg(r);
    lli sum=findSum(r),cnt=count(r);
    dbg(sum,m-cnt);
    cout<<sum+(m-cnt)*(r-1)<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b;
  cin >> a >> b;
  if (a + b < 10) cout << a + b << endl;
  else cout << "error" << endl;
}

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

int main() {
  vector<int> h(10000), w(10000);
  int idx = 0;
  while(true) {
    cin >> h.at(idx) >> w.at(idx);
    if (h.at(idx) == 0 && w.at(idx) == 0) break;
    idx++;
  }
  idx = 0;
  while(!(h.at(idx) == 0 && w.at(idx) == 0)) {
    for(int i = 0; i < h.at(idx); i++) {
      for(int j = 0; j < w.at(idx); j++) {
        if(i == 0 || i == h.at(idx) - 1) cout << '#';
        else if (j == 0 || j == w.at(idx) - 1) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    idx++;
    cout << endl;
  }
}


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

using namespace std;

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n, e, t;
	cin >> n >> e >> t;
	
	long long arr[n+2];
	for(int i = 1;i <= n;i++) cin >> arr[i];
	arr[0] = 0;
	long long far[n+2];
	long long dp[n+2];
	multiset<long long> close;
	dp[0] = 0;
	far[0] = -2 * arr[1];
	close.insert(0);
	
	int c = 0;
	for(int i = 1;i <= n;i++){
		///from c onwards, add t, before c, add 2 * (arr[i] - arr[j+1]);
		while(2 * (arr[i] - arr[c+1]) > t){
			close.erase(close.find(dp[c] - arr[c]));
			c++;
		}
		
		dp[i] = 10234567890123242;
		if(c != 0){
			dp[i] = min(dp[i], far[c-1] + 3 * arr[i]);
		}
		if(!close.empty()){
			long long v = *(close.begin());
			//cout << i << " " << v << "\n";
			dp[i] = min(dp[i], v + t + arr[i]);
		}
		
		
		
		
		
		far[i] = dp[i] - 2 * arr[i+1] - arr[i];
		far[i] = min(far[i],far[i-1]);
		close.insert(dp[i] - arr[i]);
	}
	
	//for(int i = 1;i <= n;i++) cout << dp[i] << " ";
	
	cout << dp[n] + (e-arr[n]);
}


Measured memory_bytes: 4608
use std;
use std::collections::VecDeque;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

/*
ここまでテンプレ
*/
fn ord(a: (i32, i32), b: (i32, i32)) -> bool {
    if (a.0 < b.0) {
        true
    } else {
        false
    }
}
fn main() {
    let N = read::<i32>();
    let mut A: Vec<i32> = Vec::new();
    for i in 0..N as usize {
        let num = read::<i32>();
        A.push(num - 1);
    }
    let mut ans: i32 = 0;
    let mut now: i32 = 0;
    for i in 0..N + 10 {
        ans += 1;
        now = A[now as usize];
        if now == 1 {
            println!("{}", ans);
            return;
        }
    }
    println!("-1");
}


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

ll A[500005];
ll dp[500005];

void I_m_Beast()
{	
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		A[i+1]=s[i]-'0';
	}
	A[0]=-1;
	ll cum[n+1],idx[n+1];
	cum[0]=0;
	idx[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(A[i]==0)
			idx[i]=i;
		else
			idx[i]=idx[i-1];
		cum[i]=cum[i-1]+A[i];
		dp[i]=0;
	}

	dp[0]=0;
	for(int i=3;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if(A[i]!=0)
		{
			if(A[i-1]==0 && A[i-2]!=0)
			{
				int x=idx[i-2];
				dp[i]=max(dp[i],dp[x]+cum[i-3]-cum[x]+max(A[i],A[i-2]));
				dp[i]=max(dp[i],dp[x+1]+cum[i-3]-cum[x+1]+max(A[i],A[i-2]));
			}
			else if(A[i-1]!=0)
			{
				int x=idx[i];
				if(x>1 && A[x-1]!=0)
				dp[i]=max(dp[i],dp[x-2]+cum[i]-cum[x+1]+max(A[x-1],A[x+1]));
			}
		}
	}
	cout<<dp[n]<<endl;
	return ;
}

int main()
{
	fastio;
	int t=1;
	// cin>>t;
	while(t--)
	{
		I_m_Beast();
	}	
	return 0;	
}



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

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

    int ans = 0;
    for(int i=1; i<n; i++){// cutting place
        string a = s.substr(0,i);
        string b = s.substr(i,n-i);
        //cout << a << " " << b << endl;
        int count = 0;

        vector<int> alpha(26), bet(26);
        for(int x=0; x<i; x++){
            alpha[(int)(a[x] - 'a')] += 1;
        }
        for(int y=0; y<n-i; y++){
            bet[(int)(b[y] - 'a')] += 1;
        }
        for(int j=0; j<26; j++){
            if(alpha[j] > 0 && bet[j] > 0) count += 1;
        }
        if(ans < count) ans = count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.lang.Math;


public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        double x = in.nextDouble();
        double y = in.nextDouble();
        double average = (x+y)/2;

        System.out.println(Math.round(average));

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int gcd(int x, int y){
    return (x % y)? gcd(y, x % y): y; 
}
int main () {
    int N; cin >> N;
  
  ll a = 0, b = 0;
  rep(x,N) {
    ll S, T; cin >> S >> T;
    if(S*(b/T+(b%T!=0)) >= a)
      a = S*(b/T+(b%T!=0)), b = (b/T+(b%T!=0))*T;
    else
      a = (a/S+(a%S!=0))*S, b = T*(a/S);
    if(x == 0) a = S, b = T;
  }
  
  cout << a + b << "\n";
    return 0 ;
}

 


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <climits>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

#define ll long long

#define mkp make_pair
#define eb emplace_back
#define sz(s) (ll)(s.size())
const int N = 1e5 + 123;
const ll INF = 1e18 + 123;

#define int ll
#define all(s) s.begin(), s.end()

char a[600][600];

int p1[600][600], p2[600][600];

main (){
	clog << "Ready\n";
	
	int a, b;
	cin >> a >> b;
	if (a == 1 and b == 1) {
		cout << 1000000 << '\n';
		return 0;
	}
	int sum = 0;
	if (a == 1)
		sum += 300000;
	if (a == 2)
		sum += 200000;
	if (a == 3)
		sum += 100000;
	if (b == 1)
		sum += 300000;
	if (b == 2)
		sum += 200000;
	if (b == 3)
		sum += 100000;
	cout << sum;
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;


vector<pair<ll, int>> Pfact(ll num) {
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= num; i++) {
        int cnt = 0;
        while (num % i == 0) {
            cnt++;
            num /= i;
        }
        if (cnt) res.emplace_back(i, cnt);
    }
    if (num != 1) res.emplace_back(make_pair(num, 1));
    return res;
}

ll mpow(ll a,ll b) {
  a %= MOD;
  ll res = 1;
  while(b > 0) {
    if(b&1) {
      res = (res*a) % MOD;
    }
    a = (a*a) % MOD;
    b >>= 1;
  }
  return res;
}
 
ll lcmMOD(vl &A) {
  ll res  = 1;
  map<ll,int> mp;
  rep(i,sz(A)) {
    vector<pair<ll,int>> a = Pfact(A[i]);
    rep(j,sz(a)){
      mp[a[j].first] = max(mp[a[j].first],a[j].second);
    } 
  }
  for(auto x: mp) {
    ll k = mpow(x.first,x.second);
    k %= MOD;
    res *= k;
    res %= MOD;
  }
  return res;
}

ll modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}
  
int main() {
  int N;
  cin >> N;
  vl  A(N);
  
  rep(i,N) {
    cin >> A[i];
  }
  ll lcm = lcmMOD(A);
  ll ans = 0;
  rep(i,N) {
    ans += lcm * modinv(A[i]);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    vector<int> vec(n);
    iota(vec.begin(),vec.end(),0);
    vector<int> x(n);
    vector<int> y(n);
    rep(i,n){
        int a,b;cin >> a >> b;
        x[i] = a;
        y[i] = b;
    }
    double sum = 0;
    double ans = 0;
    int c=0;
    do{
        /*for(auto &i:vec){
            cout << i << " ";
        }
        cout << endl;*/
        sum = 0;
        for(int i=1;i<n;i++){
            sum+=sqrt(pow(x[vec[i-1]]-x[vec[i]],2)+pow(y[vec[i-1]]-y[vec[i]],2));
        }
        ans+=sum;
        c++;
    }while(next_permutation(vec.begin(),vec.end()));
    ans = ans/c;
    cout << fixed;
    cout << setprecision(6) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];
int len;

bool Cat(int &pos) {
  bool ret = true;
  if (str[pos] == 'm') {
    pos++;
    ret &= Cat(pos);
    ret &= (str[pos] == 'e');
    pos++;
    ret &= Cat(pos);
    ret &= (str[pos] == 'w');
    pos++;
  }
  return ret;
}

int main() {
  while (scanf("%s", str) > 0) {
    int pos = 0;
    len = strlen(str);
    puts((Cat(pos) && pos == len) ? "Cat" : "Rabbit");
  }
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){
	int x,y,z;
	scanf("%d",&x);
	z=x/2+1;
	y=x/2;
	
	if (x%2!=0){
		printf("%d",z);
	}
	else  
	{
		printf ("%d",y);
	}
	
	return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int X,Y;cin>>X>>Y;
  int sum=0;
  if(X==1||X==2||X==3)sum+=(4-X)*100000;
  if(Y==1||Y==2||Y==3)sum+=(4-Y)*100000;
  if(X==1&&Y==1)sum+=400000;
  cout<<sum<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int H,W;
vpi oc[16];

bool adj(pi a, pi b) {
    return abs(a.f-b.f)+abs(a.s-b.s) == 1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> H >> W;
    F0R(i,H) F0R(j,W) {
        char c; cin >> c;
        if (c == '#') oc[i+j].pb({i,j});
    }
    F0R(i,H+W-1) if (sz(oc[i]) != 1) {
        cout << "Impossible";
        exit(0);
    }
    F0R(i,H+W-2) if (!adj(oc[i][0],oc[i+1][0])) {
        cout << "Impossible";
        exit(0);
        
    }
    cout << "Possible";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
#define IN(v, val) find(v.begin(), v.end(), val) != v.end()
using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    vector<string> S(N);
    REP(i, N)
    cin >> S[i];
    if (IN(S, "Y"))
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = sc.next();
		}
		int[][] kyori = new int[h][w];
		Queue<Integer> queue = new ArrayDeque<>();
		boolean[][] visited = new boolean[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i].charAt(j) == '#') {
					visited[i][j] = true;
					queue.add(i * 10000 + j);
				}
			}
		}
		while (!queue.isEmpty()) {
			int tmp = queue.remove();
			int r = tmp / 10000;
			int c = tmp % 10000;
			int count = kyori[r][c];
			if (r > 0 && !visited[r - 1][c]) {
				kyori[r - 1][c] = count + 1;
				visited[r - 1][c] = true;
				queue.add(((r - 1) * 10000 + c));
			}
			if (r < h - 1 && !visited[r + 1][c]) {
				kyori[r + 1][c] = count + 1;
				visited[r + 1][c] = true;
				queue.add((r + 1) * 10000 + c);
			}
			if (c > 0 && !visited[r][c - 1]) {
				kyori[r][c - 1] = count + 1;
				visited[r][c - 1] = true;
				queue.add(r * 10000 + c - 1);
			}
			if (c < w - 1 && !visited[r][c + 1]) {
				kyori[r][c + 1] = count + 1;
				visited[r][c + 1] = true;
				queue.add(r * 10000 + c + 1);
			}
		}
		int max = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				max = Math.max(max, kyori[i][j]);
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 67160
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
ll ctoi(char c) {
    if (c == '0')return 0;
    else if (c == '1')return 1;
    else if (c == '2')return 2;
    else if (c == '3')return 3;
    else if (c == '4')return 4;
    else if (c == '5')return 5;
    else if (c == '6')return 6;
    else if (c == '7')return 7;
    else if (c == '8')return 8;
    else if (c == '9')return 9;
    else return -1;
}int main() {
    ll N;
    cin >> N;
    ll n;
    ll red = 0;
    map<ll, ll> color;
    rep(i, N) {
        cin >> n;
        if (n < 3200)color[n / 400]++;
        else {
            color[8]++;//8jiyuu
            red++;
        }
    }
    ll shurui = 0;
    rep(i, 8) {
        if (color[i])shurui++;
    }
    if (shurui == 0) {
        cout << "1" << " ";
        cout << red << endl;
    }
    else {
        cout << shurui << " ";
        ll ans = shurui + red;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int h, w;
    std::cin >> h >> w;
    std::vector<std::vector<bool>> t1(h, std::vector<bool>(w));
    std::vector<std::vector<int>> t2(h, std::vector<int>(w));
    for(int i = 0; i < h; ++i){
        std::string tmp;
        std::cin >> tmp;
        for(int j = 0; j < w; ++j) t1[i][j] = tmp[j] == '.';
    }
    t2[0][0] = ((t1[0][0])? 0 : 1);
    for(int i = 1; i < h + w - 1; ++i){
        for(int j = 0; j <= i; ++j){
            if(j >= h || i - j >= w) continue;
            if(j > 0){
                if(i - j > 0){
                    if(t1[j][i - j]) t2[j][i - j] = std::min(t2[j - 1][i - j], t2[j][i - j - 1]);
                    else{
                        t2[j][i - j] = t2[j - 1][i - j] + ((t1[j - 1][i - j])? 1 : 0);
                        t2[j][i - j] = std::fmin(t2[j][i - j], t2[j][i - j - 1] + ((t1[j][i - j - 1])? 1 : 0));
                    }
                }
                else{
                    if(t1[j][i - j]) t2[j][i - j] = t2[j - 1][i - j];
                    else t2[j][i - j] = t2[j - 1][i - j] + ((t1[j - 1][i - j])? 1 : 0);
                }
            }else{
                if(t1[j][i - j]) t2[j][i - j] = t2[j][i - j - 1];
                else t2[j][i - j] = t2[j][i - j - 1] + ((t1[j][i - j - 1])? 1 : 0);
            } 
        }
    }
    std::cout << t2[h - 1][w - 1] << std::endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	rep(i, N) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end());

	ll cnt = 0;
	int tmp_id = 0;
	ll tmp = 0;
	int i = 1;
	for(; i<N; i++) {
		bool ana = true;
		rep(k, s[i].size()) {
			if(s[tmp_id][k]!=s[i][k]) {
				ana = false; 
				break;
			}
		}
		if(ana) { 
			tmp++;
		} else {
			cnt += tmp*(tmp+1)/2;
			tmp_id = i;
			tmp = 0;
		}
	}
	cnt += tmp*(tmp+1)/2;

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 7296
def main():
    import sys
    input = sys.stdin.readline
    
    N, X = map(int, input().split())
    
    dp = [[0,0] for i in range(N+1)]
    dp[0] = [1,1]
    for i in range(1,N+1):
        dp[i][0] = 2*dp[i-1][0] + 1
        dp[i][1] = 2*dp[i-1][1] + 3
    dp = dp[::-1]
    tmp = X
    i = 0
    j = 0
    ans = 0
    
    while tmp != 0:
        if tmp <= N - i:
            break
        if tmp < i - j + dp[i][1]:
            i += 1
        else:
            ans += dp[i][0]
            tmp -= (i - j + dp[i][1])
            if tmp >= 1:
                tmp -= 1
                ans += 1
                j = i
    print(ans)
            

main()

Measured memory_bytes: 38256
// C++ program to count number of triangles that can be 
// formed from given array 
#include <bits/stdc++.h> 
using namespace std; 

/* Following function is needed for library function 
qsort(). Refer 
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */
int comp(const void* a, const void* b) 
{ return *(int*)a > *(int*)b ; } 

// Function to count all possible triangles with arr[] 
// elements 
int findNumberOfTriangles(int arr[], int n) 
{ 
	// Sort the array elements in non-decreasing order 
	qsort(arr, n, sizeof( arr[0] ), comp); 

	// Initialize count of triangles 
	int count = 0; 

	// Fix the first element. We need to run till n-3 
	// as the other two elements are selected from 
	// arr[i+1...n-1] 
	for (int i = 0; i < n - 2; ++i) 
	{ 
		// Initialize index of the rightmost third 
		// element 
		int k = i + 2; 

		// Fix the second element 
		for (int j = i + 1; j < n; ++j) 
		{ 
			// Find the rightmost element which is 
			// smaller than the sum of two fixed elements 
			// The important thing to note here is, we 
			// use the previous value of k. If value of 
			// arr[i] + arr[j-1] was greater than arr[k], 
			// then arr[i] + arr[j] must be greater than k, 
			// because the array is sorted. 
			while (k < n && arr[i] + arr[j] > arr[k]) 
			++k; 

			// Total number of possible triangles that can 
			// be formed with the two fixed elements is 
			// k - j - 1. The two fixed elements are arr[i] 
			// and arr[j]. All elements between arr[j+1]/ to 
			// arr[k-1] can form a triangle with arr[i] and arr[j]. 
			// One is subtracted from k because k is incremented 
			// one extra in above while loop. 
			// k will always be greater than j. If j becomes equal 
			// to k, then above loop will increment k, because arr[k] 
			// + arr[i] is always greater than arr[k] 
			if(k > j) 
			count += k - j - 1; 
		} 
	} 

	return count; 
} 

// Driver code 
int main() 
{ 
    int size;
    cin>>size;
	int arr[size] ;
	for(int i=0;i<size;i++){
	    cin>>arr[i];
	}

	cout<<findNumberOfTriangles( arr, size ); 

	return 0; 
} 

// This code is contributed by rathbhupendra 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <float.h>

#include <cstdio>
#include <iomanip>


using namespace std;
typedef long long ll;
#define loop(i, N) for(int i=0; i<N; ++i)

int n;
int a[110000];
bool his[110000] = { false };
bool can = false;
int cnt = 0;

void push(int i, int cnt) {
	if (his[i]) {
		cout << -1 << endl;
		return;
	}
	else if (a[i] == 2) {
		cout << cnt+1 << endl;
		return;
	}
	else {
		his[i] = true;
		++cnt;
		push(a[i], cnt);
	}
}


int main(void) {
	cin >> n;
	for (int i = 1; i <= n;i++) {
		cin >> a[i];
		if (a[i] == 2) can = true;
	}

	if (!can) cout << -1 << endl;
	else {
		push(1,cnt);
	}
	
}

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

int main() {
  int A, B, C, D;

  cin >> A >> B >> C >> D;
  
  if (A+B < C+D) {
  	cout << "Right" << endl;
  }
  else if (A+B > C+D){
  	cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

const int MAX_D=365;
const int MAX_type=26;
const int BeamWidth=50;

int D;
int c[MAX_D+5];
int s[MAX_D+5][MAX_type+5];

struct State{
    vector<int> contest;
    vector<int> last;
    int day;
    int score;

    State(){
        //cout<<"hoge"<<endl;
        day=0;
        score=0;
        for(int i=0;i<MAX_type+5;++i)last.push_back(0);
        //fill(last.begin(),last.end(),0);
        //cout<<last[0]<<endl;
    }

    void update(int type,int d){
        contest.push_back(type);
        //last[type]=d;
        day++;
        score+=s[d][type];
        for(int i=0;i<MAX_type;++i){
            score-=c[i]*(day-last[i]);
        }
    }

    State nextState(State now,int type){
        State next;
        next=now;
        next.update(type,now.day+1);
        return next;
    }
};

bool operator< (const State &state1, const State &state2){
    return state1.score < state2.score;
};

bool operator> (const State &state1, const State &state2){
    return state1.score > state2.score;
};

State beamsearch(){
    int D_=D;
    priority_queue<State, vector<State>, greater<State> > nowpq;
    for(int type=0;type<MAX_type;++type){
        State s;
        //cout<<s.score<<endl;
        //cout<<s.nextState(s,type).contest[0]<<endl;
        nowpq.push(s.nextState(s,type));
    }
    while(nowpq.size()>BeamWidth)nowpq.pop();
    D_--;
    while(D_--){
        //cout<<D<<endl;
        priority_queue<State, vector<State>, greater<State> > nextpq;
        while(nowpq.size()){
            State now=nowpq.top();
            nowpq.pop();
            for(int type=0;type<MAX_type;++type){
                nextpq.push(now.nextState(now,type));
                //cout<<now.nextState(now,type).score<<endl;
            }
        }
        while(nextpq.size()>BeamWidth)nextpq.pop();
        nowpq=nextpq;
    }
    while(nowpq.size()>1)nowpq.pop();
    State ret=nowpq.top();
    return ret;
}

void input(){
    cin>>D;
    for(int i=0;i<MAX_type;++i)cin>>c[i];
    for(int i=0;i<D;++i){
        //cout<<D<<endl;
        for(int j=0;j<MAX_type;++j){
            cin>>s[i][j];
        }
    }
}

signed main(){
    input();
    auto res=beamsearch();
    if(res.contest.size()!=D)cout<<0/0<<endl;
    for(auto u:res.contest){
        cout<<u+1<<endl;
    }
    //cout<<"score is "<<res.score<<endl;
    //for(int i=0;i<MAX_type;++i)cout<<res.last[i]<<endl;
    //int score=0;
}

Measured memory_bytes: 11584
//https://atcoder.jp/contests/abc128/tasks/abc128_c

import java.util.Scanner;
import java.util.ArrayList;

class Main{
    static int N,M;
    static ArrayList<ArrayList<Integer>> s = new ArrayList<>();
    static ArrayList<Integer> p = new ArrayList<>();
    static int[] a;
    static int ans = 0;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        for (int i=0;i<M;i++){
            int k = sc.nextInt();
            ArrayList<Integer> si = new ArrayList<>();
            for (int j=0;j<k;j++){
                si.add(sc.nextInt());
            }
            s.add(si);
        }
        for (int i=0;i<M;i++){
            p.add(sc.nextInt());
        }
        sc.close();
        a = new int[N];
        dfs(0);
        System.out.println(ans);
    }
    
    public static void dfs(int pos){
        if (pos==N){
            func();
        } else {
            a[pos] = 0;
            dfs(pos+1);
            a[pos] = 1;
            dfs(pos+1);
        }
    }

    public static void func(){
        int count = 0;
        for (int i=0;i<s.size();i++){
            int cnt1 = 0;
            for (Integer si:s.get(i)){
                if (a[si-1]==1){
                    cnt1++;
                }
            }
            if (cnt1%2==p.get(i)){
                count++;
            }
        }
        if (count==M){
            ans++;
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int K,N;
  cin>>K>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  vector<int64_t>dist;
  dist.push_back(A[0]+K-A[N-1]);
  for(int i=0;i<N-1;i++){
     dist.push_back(A[i+1]-A[i]);
  }
  int mx=*max_element(dist.begin(),dist.end());
  cout<<K-mx<<endl;
  return 0;  
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll mdis=x%d;
    ll mreq=x/d;
    ll ans;
    if(mreq>=k){
        ans=x-(k*d);
    }
    else{
        k-=mreq;
        if(k%2==0)ans=mdis;
        else ans=d-mdis;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    string s,t;cin>>s>>t;
    string ans = "";
    REP(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256