akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int main(){
    int A[100];  
    int N;
    int i,j,mini,z;
    int count=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    for(i=0;i<N;i++){
        mini = i;
        for(j=i;j<N;j++){
            if(A[j]<A[mini]){
                mini = j;
            }
        }  
        if(mini!=i){
            z = A[i];
            A[i] = A[mini];
            A[mini] = z;
            count++;
        }
    }  
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i!=N-1){
                printf(" ");
            }
    }  
    printf("\n%d\n",count);
    return 0;    
}


Measured memory_bytes: 2140
N, L = map(int, input().split())
a = []
for i in range(N):
  a.append(L+i+1-1)
  
if min(a) > 0:
  print(sum(a)-min(a))
  
elif min(a)<=0 and max(a)>=0:
  print(sum(a))
  
else:
  print(sum(a)-max(a))
  

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	c := 0

	for i := 2; i < n; i++ {
		c ^= a[i]
	}

	x := (a[0] + a[1] - c) / 2
	c0, c1 := 0, 0
	for i := 0; i < 50; i++ {
		if x>>i&1 == 0 {
			continue
		}
		c0 += 1 << i
		c1 += 1 << i
	}

	for i := 49; i >= 0; i-- {
		if x>>i&1 == 0 {
			if c>>i&1 == 1 {
				if a[0] >= c0+1<<i {
					c0 += 1 << i
				} else {
					c1 += 1 << i
				}
			}
		}
	}

	if c0 <= 0 || a[0]-c0 < 0 || a[0]+a[1] != c0+c1 || c0^c1 != c {
		fmt.Fprintln(wr, -1)
	} else {
		fmt.Fprintln(wr, a[0]-c0)
	}

}


Measured memory_bytes: 1788
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(1, N-1):
    if P[i-1] < P[i] < P[i+1] or P[i-1] > P[i] > P[i+1]:
        ans += 1

print(ans)

Measured memory_bytes: 9060
S=str(input())
moji=[]
result=[]

for i in range(4):
    if S[i] not in moji:
        moji.append(S[i])
        result.append(0)
    else:
        result[moji.index(S[i])]+=1

if len(result)==2 and result[0]==result[1]:
    print('Yes')
else:
    print('No')

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

int main() {
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    char a=s1[0]-32;
    char b=s2[0]-32;
    char c=s3[0]-32;
    printf("%c%c%c\n",a,b,c);
}


Measured memory_bytes: 256
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int x, y, a, b, c;
        cin >> x >> y >> a >> b >> c;
        vector<ll> p(a), q(b), r(c);
        for (auto &x : p)
            cin >> x;
        for (auto &x : q)
            cin >> x;
        for (auto &x : r)
            cin >> x;
        sort(all(p));
        sort(all(q));
        sort(all(r));
        reverse(all(p));
        reverse(all(q));
        reverse(all(r));
        // for (size_t i = 1; i < a; i++)
        //     p[i] += p[i - 1];
        // for (size_t i = 1; i < b; i++)
        //     q[i] += q[i - 1];
        // for (size_t i = 1; i < c; i++)
        //     r[i] += r[i - 1];
        vector<ll> v;
        for (size_t i = 0; i < x; i++)
            v.pb(p[i]);
        for (size_t i = 0; i < y; i++)
            v.pb(q[i]);
        // pc(p, q, v);
        sort(all(v));
        reverse(all(v));
        pc(p, q, v, r);
        ll res = accumulate(all(v), 0LL);
        int ptr = 0;
        ll sum = res;
        // pc(v);
        while (ptr < r.size() && v.size())
        {
            sum -= v.back();
            v.pop_back();
            sum += r[ptr];
            ++ptr;
            res = max(res, sum);
            db(ptr, res);
            pc(v);
        }
        cout << res << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 4852
#include<iostream>

int main(void)
{
	using namespace std;
	int n, m, l, r, c;
	cin >> n >> m >> l;
	int A[n][m], B[m][l];
	long long int C[n][l];
	for(r = 0; r < n; r++)
	{
		for(c = 0; c < m; c++)
		{
			cin >> A[r][c];
		}
	}
	for(r = 0; r < m; r++)
	{
		for(c = 0; c < l; c++)
		{
			cin >> B[r][c];
		}
	}
	for(r = 0; r < n; r++)
	{
		for(c = 0; c < l; c++)
		{
			C[r][c] = 0;
			for(int i = 0; i < m; i++)
			{
				C[r][c] += (A[r][i] * B[i][c]);
			}
		}
	}
	for(r = 0; r < n; r++)
	{
		for(c = 0; c < l; c++)
		{
			cout << C[r][c];
			if(c != l-1)
				cout << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3244
n = int(input())

for i in range(1, n+1):
    if i % 3 == 0 or i % 10 == 3:
        print(' %d' % i, end='')
    else:
        tmp = i
        while tmp is not 0:
            tmp //= 10
            if tmp % 10 == 3:
                print(' %d' % i, end='')
                break
print()





Measured memory_bytes: 5868
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

L = []
BC.sort(key=lambda x:x[1], reverse=True)
A.sort()
# ans = sum(A)
ans = 0
# flag = False
cnt = 0
# for k in range(N):
#     if k <= len_L-1:
#         if flag and L[k] > A[k]:
#             ans += L[k]
#         else:
#             flag = False
#             ans += A[k]
#     else:
#         ans += A[k]
for i in range(M):
    for j in range(BC[i][0]):
        if cnt < N and A[cnt] < BC[i][1]:
            ans += BC[i][1]
            cnt += 1
        else:
            break
    else:
        continue
    break

if cnt < N:
    ans += sum(A[cnt::])

print(ans)

Measured memory_bytes: 81816
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var nums = new int[num];
            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = int.Parse(Console.ReadLine());
            }

            ShellSort(nums);
            Array.ForEach(nums, x => Console.WriteLine(x));
            Console.Read();
        }

        private static void ShellSort(int[] nums)
        {
            var cnt = 0;
            var m = 0;

            if (nums.Length == 1) m = 1;
            else m = (int)Math.Log(nums.Length, 2);
            Console.WriteLine(m);

            var G = new int[m];
            for (int i = 0; i < G.Length; i++)
            {
                G[i] = (int)Math.Pow(2,i+1) - 1;
            }
            Array.Reverse(G);
            Console.WriteLine(string.Join(" ", Array.ConvertAll(G,x=>x.ToString())));

            for (int i = 0; i < G.Length; i++)
            {
                cnt += insertionSort(nums, G[i]);
            }

            Console.WriteLine(cnt);

        }

        private static int insertionSort(int[] nums, int g)
        {
            var cnt = 0;
            for (int i = g; i < nums.Length; i++)
            {
                var v = nums[i];
                var j = i - g;
                while ((j >= 0) && (nums[j] > v))
                {
                    nums[j + g] = nums[j];
                    j = j - g;
                    cnt++;
                }
                nums[j + g] = v;
            }
            return cnt;
        }

    }
}

Measured memory_bytes: 20032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a,ll b){
	ll out=1;
	ll p=a%MOD;
	while(b){
		if(b&1)out=out*p%MOD;
		p=p*p%MOD;
		b>>=1;
	}
	return out;
}
// nCr
ll nCr(ll n,ll r){
	ll out=1;
	r=min(r,n-r);
	for(ll i=n;i>n-r;i--)out=out*(i%MOD)%MOD;
	ll t=1;
	for(ll i=2;i<=r;i++)t=t*i%MOD;
	return out*powmod(t,MOD-2)%MOD;
}
int main(){
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	ll out=0;
	ll q[2]={h-a-1+b,a-2+w-b};
	ll e[2]={b,q[1]-a+1};
	ll s=nCr(q[0],b);
	ll t=nCr(q[1],a-1);
	rep(i,w-b){
		out=(out+s*t%MOD)%MOD;
		q[0]++;e[0]++;
//		cout<<q[0]<<" "<<e[0]<<" "<<s<<endl;
		s=s*q[0]%MOD*powmod(e[0],MOD-2)%MOD;
		t=t*e[1]%MOD*powmod(q[1],MOD-2)%MOD;
		q[1]--;e[1]--;
	}
	cout<<out<<endl;
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    int n = 0;
    while (1){
	cin >> n;
	if (!n) break;
	vector<vector<int> > matrix(n+1, vector<int>(n+1));
	int input;
	for (int a = 0; a < n; a++){
	    matrix[a][n] = 0;
	    for (int b = 0; b < n; b++){
		cin >> matrix[a][b];
		matrix[a][n] += matrix[a][b];
	    }
	}
	for (int a = 0; a < n; a++){
	    for (int b = 0; b < n; b++){
		matrix[n][b] += matrix[a][b];
	    }
	}
	for (int b = 0; b < n; b++)
	    matrix[n][n] += matrix[n][b];

	for (int a = 0; a < n+1; a++){
	    for (int b = 0; b < n+1; b++)
		cout << right << setw(5) << matrix[a][b];
	    cout << '\n';
	}
    }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

// par[i]  は，iがrootなら-(連結成分のサイズ)を，iがrootではないならばrootを返す
// root(x) は必ずroot を返す
struct UnionFindSize {
    vector<int> par;
    
    UnionFindSize(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

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

    ll N, M;
    cin >> N >> M;

    UnionFindSize uf(N+M);

    REP(i, N){
    	ll K;
    	cin >> K;
    	REP(j, K){
    		ll L;
    		cin >> L;
    		L--;
    		uf.merge(i, N+L);
    	}
    }

    bool ok = true;
    REP(i, N){
    	if(uf.root(0) != uf.root(i)) ok = false;
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    string S;
    
    cin >> S;
    
    
    int start;
    int end;
    
    for ( char c = 'a'; c <= 'z'; c++ ) {
        
        start = -1;
        end = -1;
        
        bool is_ok = false;
        
        for ( int i = 0; i < S.length(); i++ ) {        
            if ( *(S.substr( i, 1 ).c_str()) == c ) {
                if ( start != -1 && i - start < 3 ) {
                    end = i;
                    is_ok = true;
                    break;
                }
                else { start = i; }
            }
        }
        
        if ( is_ok ) { break; }
    }
    
    
    if ( end == -1 ) {
        cout << "-1 -1" << endl;
    }
    else {
        cout << start+1 << " " << end+1 << endl; 
    }
    
    return 0;
}

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

using namespace std;


inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}


vector<long long> num, p;
long long ans = 0;

void rec(long long n, long long x) {
    if (x <= 0) return;

    if (x >= num[n] - 1) {
        ans += p[n];
        return;
    }

    if (x > num[n] / 2) {
        ans += p[n-1] + 1;
        x -= num[n-1] + 2;
        rec(n-1, x);
        return;
    }

    if (x <= num[n] / 2) {
        rec(n-1, x-1);
        return;
    }
}

void solve() {
    int N;
    long long X;
    cin >> N >> X;

    num.resize(N+1);
    p.resize(N+1);

    num[0] = 1; p[0] = 1;
    for (int i = 1; i < N+1; i++) {
        num[i] = num[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }

    rec(N, X);

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int res;

    vector<int> v;

    v.push_back(1);
    int i = 2;
    while(i <= min(a,b)){
        if (a%i == 0 && b%i ==0){
            v.push_back(i);
        }
        i += 1;
    }

    res = v[v.size()-k];
    cout << res << endl;
}


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

#define MAX 100000

int a[MAX], N, mi, mx, o;
int memo[MAX + 1];

int main(){
    scanf("%d", &N);

    mi = 1145141919;
    mx = -1;
    o = 0;
    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);

        mi = std::min(mi, a[i] - 1);
        mx = std::max(mx, a[i] + 1);

        if(a[i] - 1 < 0){
            o++;
            continue;
        }
        memo[a[i] - 1]++;
        memo[a[i] + 1]++;
        memo[a[i]]++;
    }

    int ans = 0;
    for(int i = mi; i <= mx; i++){
        ans = std::max(ans, memo[i]);
    }

    ans = std::max(ans, o);

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 896
#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 << "Left" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(long number1,long number2){
	return number1/ggd(number1,number2)*number2;	
}


int main(){
    int n,m;
    std::cin >> n>>m;
    string s,t;
    std::cin >> s>>t;
    ll g=ggd(n,m),l=lcm(n,m);
    ll a=n/g,b=m/g;
    //bool b=1;
    string ss,tt;
    rep(i,n){
        if(i%a==0)ss.pb(s[i]);
    }
    rep(i,m){
        if(i%b==0)tt.pb(t[i]);
    }
    if(ss==tt)std::cout << l << std::endl;
    else std::cout << -1 << std::endl;
    
    
}




Measured memory_bytes: 512
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n-2):
  a = l[i]
  for j in range(i + 1, n-1):
    ans += bisect.bisect_left(l, l[j]+a)-j-1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define lson rt<<1
#define rson rt<<1|1
#define scd(x) scanf("%d",&x)
#define scdd(x,y) scanf("%d%d",&x,&y)
const int maxn=3e5+10;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
int arr[maxn],sum[maxn*4],val[maxn*4];
void push_up(int rt) {
    int l=lson,r=rson;
    sum[rt]=sum[l]+sum[r];
    val[rt]=min(val[l],val[r]);
}
void build(int rt,int l,int r) {
    if(l==r) {
        sum[rt]=1;
        val[rt]=l;
        return ;
    }
    int mid=(l+r)/2;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(rt);
}
void update(int rt,int l,int r,int pos) {
    if(l==r) {
        sum[rt]=0;
        val[rt]=INF;
        return ;
    }
    int mid=(l+r)/2;
    if(pos<=mid)update(lson,l,mid,pos);
    else update(rson,mid+1,r,pos);
    push_up(rt);
}
pii query(int rt,int l,int r,int ql,int qr) {
    if(ql<=l&&qr>=r) {
        return pii(sum[rt],val[rt]);
    }
    int mid=(l+r)/2;
    pii ans=pii(0,0);
    if(ql<=mid)ans=query(lson,l,mid,ql,qr);
    if(qr>mid&&ans.first==0)ans=query(rson,mid+1,r,ql,qr);
    return ans;
}
vector<int>vec;
multiset<int>s;
int find_pos(int x,int l,int r){
    int ans=-1;
    while(r>=l){
        int mid=(l+r)/2;
        if(arr[mid]>=x){
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return ans;
}
int main() {
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif // LOCAL
    int n;
    //cout<<(1<<18)<<endl;
    scd(n);
    int la=1<<n;
    for(int i=1; i<=la; i++) {
        scd(arr[i]);
        s.insert(arr[i]);
    }
    sort(arr+1,arr+la+1,greater<int>() );
   // build(1,1,la);
    bool flag=false;
    vec.clear();
    vec.push_back(arr[1]);
    //update(1,1,la,1);
    multiset<int>::iterator it=s.lower_bound(arr[1]);
    s.erase(it);
    while(!flag) {
        if(vec.size()==la) {
            flag=true;
            break;
        }
        int siz=vec.size();
        sort(vec.begin(),vec.end(),greater<int>() );
        //cout<<"?"<<endl;
        for(int i=0; i<siz; i++) {
//            int pos=find_pos(vec[i],1,la);
//            if(pos==la){
//                flag=true;break;
//            }
//            pii ans=query(1,1,la,pos+1,la);
//            if(ans.first==0){
//                flag=true;break;
//            }
//            update(1,1,la,ans.second);

            multiset<int>::iterator it = s.lower_bound(vec[i]);
            if(it==s.begin()){
                flag=true;break;
            }
            it--;
            vec.push_back(*it);
            s.erase(it);
        }
    }
    if(vec.size()==la)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main(){
 int h,e;
 while(1){
    cin>>h;
    if(h==0) break;
    for(int i=0;i<9;i++){
       cin>>e;
       h-=e;
    }
      cout<<h<<endl;
 }
   return 0;
}


Measured memory_bytes: 3024
fn main() {
    proconio::input! {
        a: usize,
        mut b: usize,
        mut c: usize,
        mut k: usize,
    }
    while a>=b && k>0 {
        b*=2;
        k-=1;
    }
    while b>=c && k>0 {
        c*=2;
        k-=1;
    }
    println!("{}",if a<b && b<c {"Yes"} else {"No"});
}

Measured memory_bytes: 2156
using System;
using System.Collections.Generic;
using System.IO;
namespace I_am_the_brown_coder{
    class Inonoa{
        static void Main(){
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            Console.SetOut(sw);
            long n = long.Parse(Console.ReadLine());
            string[] sa = Console.ReadLine().Split();
            long[] a = new long[n];
            long mn = -1000000;
            long minindex = -1;
            for(long i=0;i<n;i++){
                a[i] = long.Parse(sa[i]);
            }

            long[,] ans = new long[n-1,2];
            long index = 0;

            Array.Sort(a);

            for(long i=0;i<n;i++){
                if(a[i]<=0 && a[i]>=mn){
                    mn = a[i];
                    minindex = i;
                }
            }
            if(minindex==-1){
                mn = a[0];
                minindex = 0;
            }

            for(long i=minindex+1;i<n-1;i++){
                ans[index,0] = a[minindex];
                ans[index,1] = a[i];
                a[minindex] -= a[i];
                index ++;
            }
            if(minindex<n-1){
                ans[index,0] = a[n-1];
                ans[index,1] = a[minindex];
                index ++;
                a[minindex] -= a[n-1];
                a[minindex] *= -1;
            }
            for(long i=minindex-1;i>-1;i--){
                ans[index,0] = a[minindex];
                ans[index,1] = a[i];
                a[minindex] -= a[i];
                index ++;
            }
            

            Console.WriteLine(a[minindex]);
            for(long i=0;i<n-1;i++){
                Console.Write(ans[i,0]);
                Console.Write(" ");
                Console.WriteLine(ans[i,1]);
            }
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 30808
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int N,Q;
vint adj[200001];
int p[200001];
ll tasu[200001];
ll ans[200001];
bool visited[200001]={};
int depthmax=0;
map<pint,bool> usededge;
void dfs(int u,int depth,ll plus){
	visited[u]=1;
	ans[u]=plus;
	depthmax=max(depthmax,depth);
	int flag=0;
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(visited[v]==0){
			flag=1;
			p[v]=u;
			dfs(v,depth+1,plus+tasu[v]);
		}
	}
}
int main(){
	scan(N>>Q);
	rep(i,N-1){
		int a,b;
		scan(a>>b);
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	p[0]=-1;
	rep(i,Q){
		ll P,X;
		scan(P>>X);
		P--;
		tasu[P]+=X;
	}
	dfs(0,0,tasu[0]);
	rep(i,N){
		printf("%lld ",ans[i]);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 29696
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
   double n;
   cin >> n;
   double cnt = 0;
   for(int i=1;i<=n;i++){
      if(i % 2 != 0){
         cnt++;
      }
   }
   double ans = cnt / n;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;
  ll a, b;
  vvl ab(N + 1, vl(2, 0));
  rep(i, M){
    cin >> a >> b;
    if(a == 1) ab[b][0] = 1;
    if(b == N) ab[a][1] = 1;
  }

  stable_sort(ab.begin(), ab.end());

  if((ab[N][0] == 1) && (ab[N][1] == 1))
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  
  return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	string S;
	cin >> S;
	int ans = 0;
	int tmp = 0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'S') tmp++;
		else if(tmp == 0) ans++;
		else tmp--;
	}
	cout << ans*2 << endl;

	return 0;
}

Measured memory_bytes: 720
#include<stdio.h>

int main(void){

    int N;
    int FRAG[200000+1] = {0};
    int n,i;

    scanf("%d", &N);

    for( i = 1; i <= N-1; i++ ){
        scanf("%d", &n);
        FRAG[n] += 1;
    }

    for( i = 1; i <= N; i++ ){
        printf("%d\n", FRAG[i]);
    }

    return 0;
}
        


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 x, y;
    cin >> x >> y;
    for (i64 i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y) {
            cout << "Yes" << endl;
            return;
        }
    }

    cout << "No" << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3656
#include <stdio.h>

int min(int a, int b)
{
  return a < b ? a : b;
}

int main(void)
{
  int N, K;
  scanf("%d %d", &N, &K);
  char S[N+1];
  scanf("%s", S);

  int j = N;
  for(int i = 0; i < N; j--){
      char x = S[i];
      while(i < N && x == S[i])
          i++;
  }
  printf("%d", min(N - 1, j + 2 * K));
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm;

void main(string[] args) {
  readln();
  auto p = readln().chomp.split.map!(to!int);
  int a;
  for(int i; i<p.length; i++){
    if(p[i]==i+1){a++; i++;}
  }
  a.writeln;
}

Measured memory_bytes: 4284
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

t = [0] * D
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  res = 0
  for d in range(day):
    contest = t[d] - 1
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = 0
  mxx = randint(1, 27)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx
for d in range(1, D + 1):
  mx = 0
  mxx = t[d - 1]
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for x in t: print(x + 1)

Measured memory_bytes: 79696
#include <iostream>

using namespace std;

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

    bool cards[4][13];
    for (int i = 0; i < 4; i++)
        for (int j = 0; j < 13; j++) cards[i][j] = false;

    char suit;
    int rank;
    for (int i = 0; i < n; i++) {
        cin >> suit >> rank;

        if (suit == 'S') cards[0][rank - 1] = true;
        else if (suit == 'H') cards[1][rank - 1] = true;
        else if (suit == 'C') cards[2][rank - 1] = true;
        else if (suit == 'D') cards[3][rank - 1] = true;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (!cards[i][j]) {
                if (i == 0) suit = 'S';
                else if (i == 1) suit = 'H';
                else if (i == 2) suit = 'C';
                else if (i == 3) suit = 'D';
                cout << suit << ' ' << j + 1 << endl;
            }
        }
    }
}


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

using namespace std;

int l[105];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n, x, d = 0, b = 1;
	cin >> n >> x;
	for (int i = 1; i <= n; ++i) {
		cin >> l[i];
	}
	while (b < n + 1) {
		d = d + l[b];
		if (d > x) break;
		b++;
	}
	cout << b << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>

int main(){
    int n;
    scanf("%d", &n);
    
    double x[100], y[100];
    for ( int i = 0; i < n; i++ ) scanf("%lf", &x[i]);
    for ( int i = 0; i < n; i++ ) scanf("%lf", &y[i]);
    
    double D1 = 0;
    for ( int i = 0; i < n; i++ ){
        D1 += fabs( x[i] - y[i] );
    }
    printf("%lf\n", D1);
    
    double D2, S2 = 0;
    for ( int i = 0; i < n; i++ ){
        S2 += pow( x[i]-y[i], 2 );
    }
    D2 = sqrt(S2);
    printf("%lf\n", D2);
    
    double D3, S3 = 0;
    for ( int i = 0; i < n; i++ ){
        S3 += pow ( fabs(x[i]-y[i]), 3);
    }
    D3 = pow(S3, 1.0/3.0);
    printf("%lf\n", D3);
    
    double Di = 0;
    for ( int i = 0; i < n; i++ ){
        if ( fabs( x[i] - y[i] ) > Di ) Di = fabs( x[i] - y[i] );
    }
    printf("%lf\n", Di);
    
    return 0;
}


Measured memory_bytes: 2860
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		int n = a % 500;

		if (n <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
int INF=1e+9+1;
int N;
vpint adj[10000];
int d[10000],color[10000],p[10000];
void dijkstra(){
	priority_queue<pint> PQ;
	rep(i,N){
		d[i]=INF;
		color[i]=0;
	}
	d[0]=0;
	color[0]=1;
	PQ.push(mp(0,0));
	while(!PQ.empty()){
		pint f=PQ.top();
		PQ.pop();
		int u=f.second;
		color[u]=2;
		if(d[u]< -f.first) continue;
		rep(j,adj[u].size()){
			int v=adj[u][j].first;
			if(color[v]==2) continue;
			if(d[v]>d[u]+adj[u][j].second){
				d[v]=d[u]+adj[u][j].second;
				PQ.push(mp(-d[v],v));
				color[v]=1;
			}
		}
	}
}
int main(){
	scan(N);
	int k,c,u,v;
	rep(i,N){
		scan(u);scan(k);
		rep(j,k){
			scan(v);scan(c);
			adj[u].push_back(mp(v,c));
		}
	}
	dijkstra();
	rep(i,N){
		printf("%d %d\n",i,(d[i]==INF ? -1 : d[i]));
	}
	return 0;
}



Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int r;
  cin >> r;
  cout << r * r << endl;
  
  return 0;
}


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

int main(){
	int X;
	cin>>X;
	int res = 1;
	for(int b=2;b<=X;b++){
		int tmp = b;
		for(int p=2; tmp <= X; p++){
			tmp = tmp * b;
			if(tmp <= X) res = max(tmp, res);
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
	ll S;
	cin >> S;
	ll temp_s = S;
	
	vector<ll> num_list;
	
	while(temp_s > 0){
		num_list.push_back(temp_s%10);
		temp_s/=10;
		}
		
	ll n = (int)num_list.size() - 1;
	ll ans = 0;
		
	for (ll bit = 0; bit < (1<<n); ++bit) {
		ll cnt = 1;
        for (ll i = 0; i < (n + 1); ++i) {
        	ans += num_list[i] * cnt;
        	if(i == n){
        		cnt = 1;
        		}
            else if (bit & (1<<i)) {
                cnt = 1;
            	}
            else{
            	cnt *= 10;
            	}
        }
    }
    
    cout << ans << endl;

	return 0;
	}


Measured memory_bytes: 3600
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  string s;
  cin >> s;
  int sum = 0;
  for(int i=0;i<s.size();i++){
    sum+=(s[i]-'0');
  }
  if(sum%9){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }


return 0;
}
///....


Measured memory_bytes: 3776
x,y,a,b,c= map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
li=p[:x]+q[:y]
li.sort()
ans=sum(li)
for i in range(min((x+y),c)):
    if li[i]<r[i]:
        ans+=r[i]-li[i]
    else:
        break
print(ans)



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

int main(){
	int n, m;
  	cin >> n >> m;
  	int work = 0;
  	rep(i, m){
    	int a;
      	cin >> a;
      	work += a;
    }
  	int ans = n - work;
  
  	cout << (ans >= 0 ? ans : -1) << endl;
}

Measured memory_bytes: 3624
function Main(input) {
	input = input.trim().split(" ").map((a)=>Number(a));
  input.sort(function(a,b){
  	return b - a;
  });
  var output = 0;
  output += Math.abs(input[0] - input[1]);
  output += Math.abs(input[2] - input[1]);
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN_LOG = 12;

int F[MAXN_LOG][MAXN_LOG][MAXN_LOG][MAXN_LOG][3], dig[MAXN_LOG], cnt;

int dp(int p, int s, int f, int t, int lim, int last) {
    if (p == cnt) return (s > 0 && f > 0 && t > 0);
    if (F[p][s][f][t][lim] != -1) return F[p][s][f][t][lim];

    int &curr = F[p][s][f][t][lim];
    curr = 0;
    if (lim) {
        if (3 <= dig[cnt - p - 1])
            curr += dp(p + 1, s, f, t + 1, 3 == dig[cnt - p - 1], 0);
        if (5 <= dig[cnt - p - 1])
            curr += dp(p + 1, s, f + 1, t, 5 == dig[cnt - p - 1], 0);
        if (7 <= dig[cnt - p - 1])
            curr += dp(p + 1, s + 1, f, t, 7 == dig[cnt - p - 1], 0);
    } else {
        curr += dp(p + 1, s, f, t + 1, 0, 0);
        curr += dp(p + 1, s, f + 1, t, 0, 0);
        curr += dp(p + 1, s + 1, f, t, 0, 0);
    }
    if (last) curr += dp(p + 1, s, f, t, 0, 1);
    return curr;
}

int main() {
    int n;
    scanf("%d", &n);

    cnt = 0;
    do {
        dig[cnt++] = n % 10;
        n /= 10;
    } while (n);

    std::memset(F, -1, sizeof (F));
    int ans = dp(0, 0, 0, 0, 1, 1);
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long i64;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

namespace task {
const int MOD = 998244353;
const int N = 200001;
int n, x, d;
pair<int, int> a[N];
int t[2 * N];
int b[N];
int dp[N];

void set(int p, int v) {
  for (t[p += n] = v; p > 1; p >>= 1) {
    t[p >> 1] = max(t[p], t[p ^ 1]);
  }
}

int get(int l, int r) {
  int v = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) v = max(v, t[l++]);
    if (r & 1) v = max(v, t[--r]);
  }
  return v;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> d;
    a[i] = {x, d};
  }
  sort(a, a + n);
  for (int i = n - 1; i >= 0; --i) {
    tie(x, d) = a[i];
    int p = lower_bound(a, a + n, pair<int, int>(x + d, 0)) - &a[0];
    b[i] = max(i, get(i + 1, p));
    set(i, b[i]);
  }
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    dp[b[i] + 1] = (dp[b[i] + 1] + dp[i]) % MOD;
  }
  cout << dp[n] << '\n';
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    ll ans = 700;

    rep(i, 3) if(s[i] == 'o') ans += 100;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H,W; char a; a='#';
    for(int i=0; i<300; i++){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int h=0; h<H;h++){
            for(int j=0; j<W;j++){
            cout<<a;
            }
            cout<<endl;
    }
    cout<<endl;
    }
}





Measured memory_bytes: 3080
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);

  vector<ll> min_a(n);
  min_a.at(0) = a.at(0);
  for (int i = 1; i < n; ++i) {
    min_a.at(i) = min(min_a.at(i-1), a.at(i));
  }

  ll cnt = 0;
  ll bef_max = 0;


  for (int i = n - 1; i > 0; --i) {
    ll max_ = a.at(i) - min_a.at(i);
    if (bef_max < max_) {
      bef_max = max_;
      cnt = 1;
    } else if (bef_max == max_) {
      ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


class DGraph:
    def __init__(self, n, edges):
        self._vertice = [{} for _ in range(n)]
        for e in edges:
            self._vertice[e[0]][e[1]] = e[2] if len(e) == 3 else 1

    def __len__(self):
        return len(self._vertice)

    def edges(self, n=None):
        srcs = range(len(self)) if n is None else [n]
        return sum([[(s, d, c) for d, c in self._vertice[s].items()] for s in srcs], [])

    def transpose(self):
        tedges = [(t, f, c) for f, t, c in self.edges()]
        return DGraph(len(self), tedges)

    def cost(self, src, dst):
        return self._vertice[src].get(dst, float('inf'))

class Graph(DGraph):
    def __init__(self, n, edges):
        nd_edges = edges + [(d, s, c) for s, d, c in edges]
        super().__init__(n, nd_edges)

    def transpose(self):
        return self



def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    edges = [(ca - 1, cb - 1, 0) for ca, cb in zip(a, b)]
    g = Graph(N, edges)
    s = [-1] * N

    c = deque(sorted(c, reverse=True))
    q = deque([0])
    while 0 < len(q):
        n = q.popleft()
        if s[n] != -1:
            continue
        s[n] = c.popleft()
        for _, d, _ in g.edges(n):
            q.append(d)

    ret = 0
    for b, e, _ in g.edges():
        ret += min(s[b], s[e])
    ret //= 2
    return '\n'.join([str(ret), ' '.join([str(n) for n in s])])

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, a, b, c)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

int main () {
  int n;cin>>n;
  vector<int> list(n);
  for (int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  map<int,int> check;
  int temp=1;
  int count=0;
  int flag=0;
  while(1) {
    count++;
    temp=list.at(temp-1);
    if(temp==2) {
      cout << count << endl;
      break;
    }
    else if(check.count(temp)) {
      cout << "-1" << endl;
      break;
    }
    else {
      check[temp]=1;
    }
  }
}


Measured memory_bytes: 5376