akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef string::const_iterator State;
class ParseError {};

int number(State&);
int factor(State&);
int term(State&);
int expression(State&);

int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

int factor(State &begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
}

int term(State &begin) {
    int ret = factor(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }

    return ret;
}

int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }

    return ret;
}


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

    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3168
#include <stdio.h>

int main(void)
{
  int n, i, j;
  int h[20];
  int sum = 0;
  int gov = 1;

  scanf("%d", &n);
  
  for(i = 0; i < n; i++)
    scanf("%d ", &h[i]);

  for(i = 1; i < n; i++){
    sum = 0;
    for(j = 0; j < i; j++){
      if(h[j] <= h[i]){
        sum += 1;
      } else sum -= 20;
    } if(sum > 0) gov += 1;
  }

  printf("%d", gov);

  return(0);
}

Measured memory_bytes: 128
// ABC077_C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define ALL(obj) (obj).begin(), (obj).end()
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))

int main() {
  // input
  ll N;
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  // calculation
  ll now_B, num_A, num_C, res = 0;
  ll idx_bound_A, idx_bound_C;

  for (ll i = 0; i < N; ++i) {
    now_B = B[i];
    num_A = 0;
    num_C = 0;

    // 1 段目: now_B 未満の数を求める
    auto iter_A = lower_bound(A.begin(), A.end(), now_B);
    auto iter_C = upper_bound(C.begin(), C.end(), now_B);
    ll num_A = iter_A - A.begin();
    ll num_C = C.end() - iter_C;

    res += num_A*num_C;
  }

  cout << res << "\n";

  return 0;
}

Measured memory_bytes: 2560
def main():
    n, x = map(int, input().split())

    n_layers_at_level = {0: 1}
    n_patties_at_level = {0: 1}
    for i in range(1, n):
        n_layers_at_level[i] = 2 * n_layers_at_level[i-1] + 3
        n_patties_at_level[i] = 2 * n_patties_at_level[i-1] + 1

    def amount_of_patties_from_bottom(level, n_layer):
        if level == 0:
            return 1

        lower_level_n_layer     = n_layers_at_level[level-1]
        lower_level_n_patties   = n_patties_at_level[level-1]
        mid_point = lower_level_n_layer + 2

        ret = 0
        if n_layer <= 1:
            ret = 0
        elif n_layer <= mid_point:
            if n_layer == mid_point:
                ret += 1
            ret += amount_of_patties_from_bottom(level - 1, n_layer - 1)
        else:
            ret += 1 + lower_level_n_patties
            ret += amount_of_patties_from_bottom(level - 1, n_layer - mid_point)
        return ret

    print(amount_of_patties_from_bottom(n, x))
    return


main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	ll ans=0;
	FOR(i,1,n+1){
		if(i%3==0 || i%5==0) continue;
		ans+=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    auto cnt = vec(19, vec(19, 0LL));
    // cnt[t][f] = 2^t 5^fで割り切れるものの個数
    // ただしt, f > 18のときはt, f = 18として扱う

    while (n--) {
        std::string s;
        std::cin >> s;

        std::string g;  // 小数点以下を取り出したもの
        if (std::count(s.begin(), s.end(), '.') != 0) {
            while (s.back() != '.') {
                g.push_back(s.back());
                s.pop_back();
            }
            s.pop_back();
            std::reverse(g.begin(), g.end());
        }
        while ((int)g.length() < 9) g.push_back('0');

        // 整数に変換
        lint x = std::stoi(s) * 1000000000LL + std::stoi(g);

        // t, fを求める
        int t = 0;
        while (x % 2 == 0 && t < 18) {
            x /= 2;
            ++t;
        }

        int f = 0;
        while (x % 5 == 0 && f < 18) {
            x /= 5;
            ++f;
        }

        ++cnt[t][f];
    }

    lint ans = 0;
    for (int t1 = 0; t1 <= 18; ++t1) {
        for (int f1 = 0; f1 <= 18; ++f1) {
            for (int t2 = 0; t2 <= 18; ++t2) {
                for (int f2 = 0; f2 <= 18; ++f2) {
                    // 条件チェック
                    if (t1 + t2 < 18 || f1 + f2 < 18) continue;

                    if (t1 == t2 && f1 == f2) {
                        ans += cnt[t1][f1] * (cnt[t1][f1] - 1);
                    } else {
                        ans += cnt[t1][f1] * cnt[t2][f2];
                    }
                }
            }
        }
    }

    // ダブりを除く
    ans /= 2;
    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#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 bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
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;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  v(ll) A(N),B(N);
  rep(i,N) {
    cin >> A[i];
  }
  rep(i,N) {
    cin >> B[i];
  }
  ll lim = 0;
  rep(i,N) {
    lim += (B[i] - A[i]);
  }
  ll need = 0;
  rep(i,N) {
    if(A[i] < B[i]) {
      need += (B[i] - A[i] + 1) / 2;
    }
  }
  if(need <= lim) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

int N, X;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    int L[N];
    REP(i, 0, N) cin >> L[i];
    int tmp_D = 0;
    int ans = 1;
    REP(i, 0, N){
        tmp_D += L[i];
        if(tmp_D > X) break;
        ans += 1;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  for(int i=1;i<=k;i++){
    if(a % 2 == 1){
      a--;
    }
    a = a / 2;
    b = b + a;
    int tmp;
    tmp = a;
    a = b;
    b = tmp;
  }
  if(k % 2 != 0){
    cout << b << " " << a << endl;
  }else{
    cout << a << " " << b << endl;
  }
  return 0;
}


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

int main() {
  int N, D;
  cin >> N >> D;
  if (N % (2 * D + 1) == 0) {
    cout << N / (2 * D + 1);
  }
  else {
    cout << N / (2 * D + 1) + 1;
  }
}

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

int main() {
	int N;
 	cin>>N;
  	int a[N];
  	int s=10000000;
  	rep(i,N) cin>>a[i];
  	
  	for(int i=-100;i<=100;i++){
      	int sum=0;
     	rep(j,N) sum+=(i-a[j])*(i-a[j]);
      	s=min(s,sum);
    }
 	cout<<s<<endl;
  	
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

ll N, M;
VLL A,AA;

ll judge(ll X) {
	ll ans = 0;
	for (ll n = 0; n < N; n++) {
		ll s = -1, e = N;
		while (e - s > 1) {
			ll m = (e + s) / 2;
			if (A[n] + A[m] >= X)s = m;
			else e = m;
		}
		ans += e;
	}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N >> M;
	A.resize(N);
	for (ll n = 0; n < N; n++)cin >> A[n];
	sort(A.begin(), A.end(), [](ll a, ll b) {
		return a > b;
	});
	ll s = -1, e = 2 * (ll)1e5 * M+1;
	while (e - s > 1) {
		ll m = (e + s) / 2;
		if (judge(m) <= M)e = m;
		else s = m;
	}
	ll X = e;
	ll ans = 0;
	AA.resize(N);
	AA[0] = A[0];
	for (ll n = 1; n < N; n++) {
		AA[n] = AA[n - 1] + A[n];
	}
	ll cand = 0;
	for (ll n = 0; n < N; n++) {
		s = -1, e = N;
		while (e - s > 1) {
			ll m = (e + s) / 2;
			if (A[n] + A[m] >= X)s = m;
			else e = m;
		}
		ans += A[n] * e;
		if (e > 0)ans += AA[s];
		M -= e;
		if (e < N)cand = max(cand, A[n] + A[e]);
	}
	ans += M * cand;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
n=int(input())
D={}
for i in range(1,n+1):
   s=(str(i)[0],str(i)[-1])
   if s in D:
      D[s]+=1
   else:
      D[s]=1

ans=0
for aj,bj in D:
   if (bj,aj) in D:
      ans+=D[(aj,bj)]*D[(bj,aj)]
print(ans)

Measured memory_bytes: 40428
#include<stdio.h>
long long int h[100005];
int l;
void f1(long long int n)
{
	h[l] = n;
	int now = l;
	l++;
	while (now > 0)
	{
		if (h[(now - 1) / 2] < h[now])
		{
			long long int f = h[now];
			h[now] = h[(now - 1) / 2];
			h[(now - 1) / 2] = f;
		}
		now = (now - 1) / 2;
	}
	return;
}
long long int f2()
{
	long long int res = h[0];
	l--;
	h[0] = h[l];
	int now = 0;
	for (;;)
	{
		if (2 * now + 2 < l)
		{
			if (h[2 * now + 1] < h[2 * now + 2])
			{
				if (h[now] < h[2 * now + 2])
				{
					long long int f = h[now];
					h[now] = h[2 * now + 2];
					h[2 * now + 2] = f;
				}
				now = 2 * now + 2;
			}
			else
			{
				if (h[now] < h[2 * now + 1])
				{
					long long int f = h[now];
					h[now] = h[2 * now + 1];
					h[2 * now + 1] = f;
				}
				now = 2 * now + 1;
			}
		}
		else if (2 * now + 1 < l)
		{
			if (h[now] < h[2 * now + 1])
			{
				long long int f = h[now];
				h[now] = h[2 * now + 1];
				h[2 * now + 1] = f;
			}
			now = 2 * now + 1;
		}
		else
			break;
	}
	return res;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	long long int a[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	l = 0;
	for (i = 0; i < n; i++)
		f1(a[i]);
	long long int b;
	for (i = 0; i < m; i++)
	{
		b = f2();
		b /= 2;
		f1(b);
	}
	long long int ans = 0;
	for (i = 0; i < n; i++)
		ans += f2();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
( L, R ) = gets.split(' ').map(&:to_i)
a = R - L
if a > 2019
  puts 0
else
  ret = 2019
  (L..R).each{|i|
    (L..R).each{|j|
      if i != j
        ret = i * j % 2019 < ret ? i * j % 2019 : ret 
      end
    }
  }
  puts ret
end

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

typedef long long ll;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll max = a * c;
    if (max < a * d) max = a * d;
    if (max < b * c) max = b * c;
    if (max < b * d) max = b * d;

    cout << max << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
map<char,ll> mp;
int main(){
int n,m,q;
cin>>n>>m>>q;
vector<vector<int>>root(n,vector<int>(n,0)),sum(n,vector<int>(n+1,0));
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    root.at(a).at(b)++;
}
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
        sum.at(i).at(j+1)=sum.at(i).at(j)+root.at(i).at(j);
    }
}
vector<int> ans;
for(int t=0;t<q;t++){
  int l,r;
  cin>>l>>r;
 // l--;r--;
 int res=0;
  for(int i=l-1;i<r;i++){
    res+=(sum.at(i).at(r)-sum.at(i).at(l-1));
  }
ans.push_back(res);
}
for(int i=0;i<ans.size();i++)cout<<ans.at(i)<<endl;
}


Measured memory_bytes: 3452
tmp = input().split()
N = int(tmp[0])
M = int(tmp[1])

max = N
min = 0
for i in range(M):
  inputcard = list(map(int, input().split()))
  if min < inputcard[0]:
    min = inputcard[0]
  
  if max > inputcard[1]:
    max = inputcard[1]
  
if (max - min + 1 < 0):
  print(0)
else:
  print(max - min + 1)

Measured memory_bytes: 3064
import Control.Monad

main = do
  n <- readLn :: IO Int
  sts <- replicateM n ((\x -> (x !! 0, read (x !! 1))) . words <$> getLine) :: IO [(String, Int)]
  x <- getLine :: IO String
  putStrLn $ show $ sleep x sts

foldlState :: (a -> c -> b -> (a, c)) -> a -> c -> [b] -> a
foldlState f a s l = fst $ foldl (\(a,s) -> f a s) (a, s) l

sleep x sts = foldlState step 0 False sts
    where step a b (s, t) = (a + if b then t else 0, b || s == x)


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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x_length = x2 - x1;
  int y_length = y2 - y1;
  
  int x3 = 0; int y3 = 0; int x4 = 0; int y4 = 0;
    x3 = x2 - y_length;
    y3 = y2 + x_length;
    x4 = x1 - y_length;
    y4 = y1 + x_length;
 
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl; 
}

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

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	vector<ll> h(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	ll ans = h[0];
	for (ll i = 0; i < N - 1; i++)
	{
		if (h[i + 1] > h[i]) ans += h[i + 1] - h[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
use Data::Dumper;

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @A = map { $_ - 0 } split(/\s+/,<STDIN>);

my @rB = (); $#rB = $n;

$rB[$n] = +[$A[$n],$A[$n]];

if( $n <= 46 and $A[$n] > 2**$n ){ print "-1\n"; exit(0); }

for(my $i=$n-1;$i>=0;$i--){
  $rB[$i] = +[ $A[$i] + int((1+$rB[$i+1]->[0])/2), $A[$i] + $rB[$i+1]->[1] ];
  if( $i <= 46 ){
    my $li = 2**$i;
    if( $rB[$i]->[0] > $li ){
      print "-1\n";exit(0);
    }
    if( $rB[$i]->[1] > $li ){
      $rB[$i]->[1] = $li;
    }
  }
}

#print &Dumper(\@rB);

my $tot = 0;
my $dn = +[1,1];
for(my $i=1;$i<=$n;$i++){
  my $mn = $dn->[0] - $A[$i];
  my $mx = $dn->[1]*2 - $A[$i];
  if( $i < $n and $mn <= 0 ){ $mn = 1; }
  if( $i<=47 and $mx > 2**$i - $A[$i] ){
    $mx = 2**$i - $A[$i];
  }
  if( $i < $n and $mx <= 0 ){    print "-1\n";exit(0); }
  $mn = max($mn,$rB[$i]->[0] - $A[$i]);
  $mx = min($mx,$rB[$i]->[1] - $A[$i]);
  if( $mn>$mx ){    print "-1\n";exit(0); }
  
  $dn = +[$mn,$mx];
  $tot += $mx + $A[$i];
}

$tot += 1;

print "$tot\n";

exit(0);
sub max {
  my $x = shift; my $y = shift;
  return ( $x > $y ? $x : $y );
}

sub min {
  my $x = shift; my $y = shift;
  return ( $x > $y ? $y : $x );
}


Measured memory_bytes: 34764
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>str;
    rep(i,str.length()){
        if(str[i]=='?') cout<<'D';
        else cout<<str[i];

    }
ln;
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
	int a, b;
	char op;
	cin >> a >> op >> b;
	
	if(op == '+') printf("%d\n", a+b);
	else printf("%d\n", a-b);
	
	return 0;
}

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

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

    size_t A;
    size_t maximum = 0;
    size_t ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A;
        if (maximum > A)
        {
            ans += maximum - A;
        }
        else
        {
            maximum = A;
        }
    }
    cout << ans << endl;
}


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

const string YES = "Yes";
const string NO = "No";
int main(){
  int N; cin >> N;
  string S; cin >> S;
  bool ans = true;
  if (N % 2 == 1) ans = false;
  rep(i, N / 2) if (S[i] != S[N/2 + i]) ans = false;
  if (ans) cout << YES << endl;
  else cout << NO << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<ll> f(n+1);
  for(int i=1; i<=n; i++){
    for(int j=i; j<=n; j+=i){
      f[j]++;
    }
  }
  ll ans = 0;
  for(ll i=1; i<=n; i++){
    ans+=f[i]*i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 81388
#include <iostream>

using namespace std;

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

	string SS = "CODEFESTIVAL2016";

	int count = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != SS[i]) {
			count++;
		}
	}
	cout << count << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  float w,h;
  int x,y;
  cin >> w >> h >> x >> y;
  if(x==w/2.0 && y==h/2.0) cout << w/2.0*h << " "<< 1;
  else cout << w/2.0*h <<" " << 0;
}


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

int main () {
  int N , M , K ;
  cin >> N >> M >> K ;
  bool ans =  false ;
  for(int i = 0 ; i <= N ; i++ ){
    for(int j = 0 ; j <= M ; j++ ){
      if( i*(M-j)+(N-i)*j == K )ans = true ;
    }
  }
  if(ans) cout << "Yes" << endl ;
  else cout << "No" << endl ;
}

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

int main(){

    int n;
    cin >> n ;
    if(n == 0){
        cout << 0 << endl ;
        return 0 ;
    }
    vector<int> ans ;

    while(n){
        if(n < 0){
            int x = 0 - n ;
            ans.push_back(x % 2) ;
            n = (x + 1) / 2 ;
        }
        else{
            ans.push_back(n % 2) ;
            n = 0 - n / 2 ;
        }
    }

    reverse(ans.begin(), ans.end()) ;
    for(auto i : ans)
        cout << i;
    cout << endl ;

    return 0 ;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  GVI(A, N);
  FOR(i, N) A[i] -= i + 1;
  sort(ALL(A));
  int mid = A[N / 2];
  ll ans = 0;
  FOR(i, N) { ans += abs(A[i] - mid); }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

bool is_prime(int x) {
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

vector<int> argsort(vector<int> v) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    // ソートする。
    sort(indices.begin(), indices.end(), [&v](int i1, int i2) {
        return v[i1] < v[i2];
    });
    return indices;
}


int main() {
    string t;
    cin >> t;
    int p = 1e9;
    rep (i, t.size()) {
        if (t[0] != t[i]) {
            break;
        } else if (i == t.size() - 1) {
            cout << 0 << endl;
            exit(0);
        }
    }
    for (int target = 0; target < 26; ++target) {


        int ans = 1;
        bool flag = false;
        string s = t;
        while (true) {
            if (flag || ans > s.size()) {
                break;
            }
            string _s;
            rep (i, s.size() - 1) {
                if (s[i] - 'a' == target || s[i + 1] - 'a' == target) {
                    _s += char('a' + target);
                } else {
                    _s += s[i];
                }
            }
            rep (i, _s.size()) {
                if (_s[i] != _s[0]) {
                    break;
                } else if (i == _s.size() - 1) {
                    chmin(p, ans);
                    flag = 1;
                    break;
                }
            }
            s = _s;
            ans++;
        }

    }
    cout << p << endl;
}

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

using namespace std;

long long totaldist(vector<vector<long long> >& a, int h, int w) {
    long long res=0;

    for(int i=0; i<(int)a.size(); ++i) {
        for(int j=0; j<(int)a[0].size(); ++j) {
            res+=a[i][j]*min(abs(i-h),abs(j-w));
        }
    }
    return res;
}

int main()
{
    int H,W;
    cin >> H >> W;

    vector<vector<long long> > a;
    a.resize(H);

    for(int i=0; i<H; ++i) {
        a[i].resize(W);
        for(int j=0; j<W; ++j) {
            cin >> a[i][j];
        }
    }

    long long ans=10000000000;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            ans=min(ans,totaldist(a,i,j));
        }
    }

    cout << ans << endl;

    return 0;
}



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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

vector<pair<ll, int >> factorize(ll n) {
    vector<pair<ll, int >> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res.emplace_back(i, 0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }

    if (n != 1) res.emplace_back(n, 1);
    return res;

}

ll comb(ll l, ll r) {
    vector<ll> factors(50);
    for (ll j = l; j > (l - r); j--) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] += f.second;
        }
    }

    for (ll j = 1; j <= r; j++) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] -= f.second;
        }
    }

    ll s = 1;

    for (int j = 1; j < 50; j++) {
        for (int k = 0; k < factors[j]; k++) {
            s *= j;
        }
    }

    return s;

}


int main() {
    int n, p;

    cin >> n >> p;
    int odd = 0, even = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 1) odd++;
        else even++;
    }

    ll even2 = 1ll << even,
            odd2 = 0;

    for (int i = 0; i <= odd; i++) {
        if (i % 2 != p) continue;
        odd2 += comb(odd, i);
    }


    cout << even2 * odd2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define iterator IT
#define SIZ(V) V.size()
#define FS(a) fixed<<setprecision(a)
using namespace std;
namespace STARTER {
	int MAX(int a,int b) {
		return a>b?a:b;
	}
	int MIN(int a,int b) {
		return a<b?a:b;
	}
	int ABS(int a) {
		return a<0?-a:a;
	}
	int GCD(int a,int b) {
		return !b?a:GCD(b,a%b);
	}
	int LCM(int a,int b) {
		return a/GCD(a,b)*b;
	}
	int QSM(int a,int b,int p) {
		int ret=1;
		while (b) {
			if (b&1)
				ret=ret*a%p;
			a=a*a%p;
			b>>=1;
		}
		return ret;
	}
	int ROUND(double a) {
		return a+0.5;
	}
}
using STARTER::MAX;
using STARTER::MIN;
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::QSM;
using STARTER::ROUND;
const int maxN=105;
#define int long long
int n,X[maxN],d[maxN][maxN];
signed main() {
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>X[i];
	for (int i=1;i<=n;i++)
		for (int P=1;P<=100;P++)
			d[i][P]=(X[i]-P)*(X[i]-P);
	int ans=INT_MAX;
	for (int i=1;i<=100;i++) {
		int sum=0;
		for (int j=1;j<=n;j++)
			sum+=d[j][i];
		ans=min(sum,ans);
	}
	cout<<ans<<'\n';
	return 0;
			
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

ll A[100], B[100], C[100];

int main(){

    ll N;
    cin >> N;
    for(ll i = 1; i <= N; i++)cin >> A[i];
    for(ll i = 1; i <= N; i++)cin >> B[i];
    for(ll i = 1; i < N; i++)cin >> C[i];
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        ans += B[A[i]];
        if(A[i] + 1 == A[i + 1])ans += C[A[i]];
    }
    cout << ans << endl;
    return 0;
}

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




Measured memory_bytes: 2700
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

vector<vector<pair<int, int>>> g;

bool f;
void dfs(int cur, vector<int>& cost){
	for(auto e : g[cur]){
		int to, dis;
		tie(to,dis) = e;
		if(cost[to] == INF){
			cost[to] = cost[cur] + dis;
			dfs(to, cost);
		}else{
			if(cost[to] != cost[cur] + dis){
				f = false;
			}
		}
	}
}

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

	g = vector<vector<pair<int, int>>>(n);
	rep(i,m){
		int l, r, c;
		cin >> l >> r >> c;
		l--; r--;
		g[l].emplace_back(r,c);
		g[r].emplace_back(l,-c);
	}

	f = true;
	vector<int> cost(n,INF);
	rep(i,n){
		if(cost[i] != INF) continue;
		cost[i] = 0;
		dfs(i, cost);
	}
	cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 12032
<?php
$input = trim(fgets(STDIN));

$n = (int)$input;
$args = explode(' ', trim(fgets(STDIN)));;

if ($n == 2) {
	echo abs((int)$args[1] - (int)$args[0]);
	exit();
}

$sums = [];
$sums[0] = (int)$args[0];
for ($i=1; $i < $n; $i++) { 
	$sums[$i] = $sums[$i-1] + (int)$args[$i];
}

$total = $sums[$n-1];
$min = NULL;
for ($i=0; $i < $n-1; $i++) { 
	$diff = abs($total - $sums[$i]*2);
	if (is_null($min) || $diff < $min) {
		$min = $diff;
	}
}

echo $min;

Measured memory_bytes: 31212
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
int main() {
	int h, w;
	int cnt = 0;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h; i++) {
			for (int j=0; j < w; j++) {
				if (cnt % 2 == 0)cout << "#";
				else cout << ".";
				cnt++;
			}
			cout << endl;
			
			if (w % 2 == 0)cnt++;
		}
		cnt = 0;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
gp_hash_table<int, int> table;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
int n;
string s;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    map<string,int>m;
    cin>>n;
    while(n--)
    {
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<'\n';
    cout<<"WA x "<<m["WA"]<<'\n';
    cout<<"TLE x "<<m["TLE"]<<'\n';
    cout<<"RE x "<<m["RE"]<<'\n';
    return 0;
}


Measured memory_bytes: 3664
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

tuplify2 (x : y : _) = (x, y)
tuplify2 _ = undefined

readInt = fst . fromJust . BS.readInt

readIntTuple = tuplify2 . map readInt . BS.words

getIntTuple = readIntTuple <$> BS.getLine

main = getIntTuple >>= \xs -> print $ maximum [(fst xs + snd xs), (fst xs - snd xs), (fst xs * snd xs)]


Measured memory_bytes: 3692
using System;

namespace ABC116B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aa = Console.ReadLine().Split(' ');
            int a = int.Parse(aa[0]);
            int b = int.Parse(aa[1]);
            int c,v;
            int x = 0;
            a = a + 1;
            int[] d = new int[a];
            for(int m = a-1; m >=0 ; m--)
            {
                d[m] = 1;
            }



            for (int i = 1; i <= b; i++)
            {
                c = int.Parse(Console.ReadLine());
                var ab = Console.ReadLine().Split(' ');
                for (int n = 1; n <= c; n++)
                {
                    v = int.Parse(ab[n-1]);
                    d[v] = 0;
                   
                }

            }

            for (int s = a - 1; s >= 0; s--)
                x += d[s];

            Console.WriteLine(x-1);

        }
    }
}

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

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

	int N, K, temp;
	vector<int> friends;
	cin >> N >> K;

	REP(i, N)
	{
		cin >> temp;
		friends.push_back(temp);
	}
	sort(friends.begin(), friends.end());

	REP(i, N)
	{
		if (K <= friends[i])
		{
			cout << N - i << endl;
			break;
		}
		else if(i == N-1)
		{
			cout << 0 << endl;
		}
		
	}

	return 0;
}

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

int main(){
  int n,k;cin>>n>>k;
  int p[n];
  for(int i=0;i<n;i++) cin>>p[i];
  sort(p,p+n);
  int ans=0;
  for(int i=0;i<k;i++) ans+=p[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main()
{
    int c[200020]={};
    int n; cin>>n;
    for(int i=1; i<n; i++){
        int a; cin>>a; a--;
        c[a]++;
    }
    for(int i=0; i<n; i++) cout<<c[i]<<endl;
	return 0;
}


Measured memory_bytes: 4416
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int R,G,B,N;
    cin >> R >> G >> B >>N;
    int r=0,g=0,b=0,ans=0;
    for(r=0;r<=N;r++){
        for(g=0;g<=N;g++){
                int tmp = (R*r)+(G*g);
                if(tmp <= N && (N-tmp)%B==0){
                    ans++;
                }
            }
        }
    
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>        
int a[100005],n,x,flag=0,cnt=0;       
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	x=1;
	cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[x]==2)
		{
			flag=1;
			cnt++;
			break;
		}
		cnt++;
		x=a[x];
	}
	if(flag==1)
		printf("%d",cnt);
	else
		printf("-1");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;

int main(){
  string s,t;
  for(cin>>s;cin>>s;cout<<atoi(s.c_str())-atoi(t.c_str())<<endl)
    t=s,sort(t.begin(),t.end()),sort(s.begin(),s.end(),greater<int>());
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i32 N = input(), M = input();
    vector< i32 > A(N + 1);
    range(i, 1, N + 1) {
        A[i] = (input() + A[i - 1]) % M;
    }

    map< i32, i32 > cnt;
    for (auto i: A) cnt[i]++;

    i64 ans = 0;
    for (auto p: cnt) {
        i64 n = p.second;
        ans += n * (n - 1) / 2;
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

Measured memory_bytes: 3584
# A0J 0053 Sum of Prime Numbers

MAX_N = 10000

def prime?(n)
  max = Math.sqrt(n).to_i
  not_prime = (2..max).any? {|x| n % x == 0}
  !not_prime
end

sum_of_prime_numbers = [0]
n_primes = 0
last_sum = 0
i = 2
while n_primes < MAX_N
  if prime?(i)
    n_primes += 1
    last_sum += i
    sum_of_prime_numbers << last_sum
  end
  i += 1
end

while line = gets
  n = line.to_i
  break if n.zero?

  puts sum_of_prime_numbers[n]
end

Measured memory_bytes: 6188
#include<stdio.h>
int main(void){
    int x, n, high1, high2, high3;
    high1=0;
    high2=0;
    high3=0;
    scanf("%d", &x);
    
    n=0;
    while(n<10){
        if(x>high1){
            high3=high2;
            high2=high1;
            high1=x;
        }
        else if(x>high2){
            high3=high2;
            high2=x;
        }
        else if(x>high3){
            high3=x;
        }
        n++;
        scanf("%d", &x);
    }
    
    printf("%d\n%d\n%d\n", high1, high2, high3);
    return 0;
}
    
    


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin>>s;
  ll n=s.size();
  ll dp[n+1][4];
  REP(i,n+1)REP(j,4)dp[i][j]=0;
  dp[0][0]=1;

  REP(i,n){
    if(s[i]=='?'){
      REP(j,4){
        dp[i+1][j]=3*dp[i][j]%MOD;
        if(j!=0)
          dp[i+1][j]+=dp[i][j-1];
        dp[i+1][j]%=MOD;
      }
    }
    else{
      REP(j,4){
        dp[i+1][j]=dp[i][j]%MOD;
        if(j==s[i]-'A'+1)
          dp[i+1][j]+=dp[i][j-1];
        dp[i+1][j]%=MOD;
      }

    }
  }

  cout<<dp[n][3]<<endl;
}



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

string s, t;
int a, b;
string x;

int main()
{
    cin >> s >> t;
    cin >> a >> b;
    cin >> x;
    if (x == s) a--;
    else b--;
    printf("%d %d\n", a, b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=1000+10;
const int M=200000+10;

int n,m;
vector<int> G[N];
bool f[N][N],g[N][N],t[N];

void dfs(int o,int u)
{
	f[o][u]=true;
	for(vector<int>::iterator it(G[u].begin());it!=G[u].end();++it)if(!f[o][*it])
		dfs(o,*it);
}

void dfs2(int o,int u)     
{                          
	t[u]=true;
	for(vector<int>::iterator it(G[u].begin());it!=G[u].end();++it)if(*it!=o&&!t[*it])
		dfs2(o,*it);
}

void prework()
{
	int i;
	for(i=1;i<=n;++i)
		dfs(i,i);
	vector<int>::iterator it;
	vector<int>::reverse_iterator it2;
	for(i=1;i<=n;++i)
	{
		memset(t,0,sizeof t);
		for(it=G[i].begin();it!=G[i].end();++it)
			if(!t[*it])dfs2(i,*it);
			else g[i][*it]=true;
		memset(t,0,sizeof t);
		for(it2=G[i].rbegin();it2!=G[i].rend();++it2)
			if(!t[*it2])dfs2(i,*it2);
			else g[i][*it2]=true;
	}
}

int u[M],v[M];

int main()
{
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",u+i,v+i);
		G[u[i]].push_back(v[i]);
	}
	prework();
	for(i=1;i<=m;++i)
		printf((f[v[i]][u[i]]^g[u[i]][v[i]])?"diff\n":"same\n");
	return 0;
}


Measured memory_bytes: 6272
#include<iostream>

using namespace std;

int main()
{
  int a,b;

  cin >> a >> b;

  if(a < b)
    cout << "a < b" << endl;
  if(a > b)
    cout << "a > b" << endl;
  if(a == b)
    cout << "a == b" << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s=="SUN"){
    cout<< 7<<endl;
  }
  if(s=="MON"){
    cout<< 6<<endl;
  }
  if(s=="TUE"){
    cout<< 5<<endl;
  }if(s=="WED"){
    cout<< 4<<endl;
  }
  if(s=="THU"){
    cout<< 3<<endl;
  }
  if(s=="FRI"){
    cout<< 2<<endl;
  }
  if(s=="SAT"){
    cout<< 1<<endl;
  }
  
}

Measured memory_bytes: 256
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
# N = list(map(int, input()))[::-1]
N = input()

if N[1] == 'B':
    print('ARC')
else:
    print('ABC')


Measured memory_bytes: 9336