akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(1000000)

N=int(input())
edge={i:[] for i in range(1,N+1)}
parent={i:0 for i in range(1,N+1)}
for i in range(0,N-1):
    a=int(input())
    edge[a].append(i+2)
    edge[i+2].append(a)
    parent[i+2]=a

memo={i:-1 for i in range(1,N+1)}
def dp(num):
    if memo[num]!=-1:
        return memo[num]

    if edge[num]==[parent[num]]:
        memo[num]=0
        return memo[num]

    test=[]
    for i in edge[num]:
        if i!=parent[num]:
            test.append(dp(i))
    test.sort(reverse=True)
    memo[num]=max(i+1+test[i] for i in range(0,len(test)))
    return memo[num]

print(dp(1))


Measured memory_bytes: 161892
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int w, h; cin >> w >> h;
    int p[w], q[h];
    for (int i = 0; i < w; i++) cin >> p[i];
    for (int i = 0; i < h; i++) cin >> q[i];
    sort(p, p+w); sort(q, q+h);
    int i = 0, j = 0;
    long long ans = 0;
    while (i < w || j < h) {
        if (i < w && (j == h || p[i] <= q[j]))
            ans += (long long)p[i++] * (h - j + 1);
        else
            ans += (long long)q[j++] * (w - i + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	
	public static long solve(int k) {
		if(k % 2 != 0)return 0;
		long ans = 0;
		ans = 1 + solve(k / 2);
		return ans;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();
		Arrays.sort(a);
		long ans = 0;
		for(int i = 0; i < n; ++i)
			ans += solve(a[i]);
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 33924
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int a,b,c,x;
           cin>>a>>b>>c>>x;
           int ans=0;
           rep(i,0,a+1){
            rep(j,0,b+1){
             rep(k,0,c+1){
              if(500*i+100*j+50*k==x)ans++; 
             }
            }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
int main() {
	int n;
	long long tmp;
	while(~scanf("%d",&n)) {
		int cnt0=0,cnt2=0,cnt4=0;

		for(int j=0; j<n; j++) {
			scanf("%lld",&tmp);
			if(tmp%4==0)
				cnt4++;
			else if(tmp%2==0)
				cnt2++;
			else if(tmp%4!=0&&tmp%2!=0)cnt0++;
		}
		if(cnt4+1==cnt0&&cnt2!=0)
			printf("No\n");
		else if(cnt4+1<cnt0)
			printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 128
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    long long n,ans;
    cin >> n;
    long long x=sqrt(n);
    for(long long i=x; i>=1; i--){
        if(n%i==0){
            ans=n/i;
            break;
        }
    }
    long long x10=1;
    for(int i=0; i<=10; i++){
        if(ans/x10==0){
            cout << i << endl;
            break;
        }
        x10*=10;
    }
}


Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    H.sort(reverse=True)
    res = H[K:]
    
    S = sum(res)
    print(S)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 25744
using System.Linq;
using static System.Console;
using static System.Math;

namespace ConsoleApp3
{
    public class Program
    {

        static void Main()
        {
            WriteLine(Hoge(ReadLine()));
        }

        public static uint Hoge(string s)
        {
            var n = uint.Parse(s);

            var memo = new uint[n + 1];

            memo[n] = 0;

            var piyo = Enumerable.Range(0, 7);
            var a = piyo.Select(x => (uint)Pow(6, x)).Where(x => x <= n);
            var b = piyo.Select(x => (uint)Pow(9, x)).Where(x => x <= n);
            var c = a.Union(b);

            var e = Enumerable.Range(0, (int)n);

            foreach (var i in e)
            {
                var d = n - i;
                var tempStep = memo[d];

                var f = c.Where(y => y <= d);

                foreach (var item in f)
                {
                    if (memo[d - item] == 0)
                    {
                        memo[d - item] = tempStep + 1;
                    }
                    else
                    {
                        if (tempStep + 1 < memo[d - item])
                        {
                            memo[d - item] = tempStep + 1;
                        }
                    }

                }

            }

            return memo[0];
        }
    }
}


Measured memory_bytes: 15836
#include <iostream>
#include <string>>

using namespace std;

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

    string S;
    cin  >> S;

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

    int tmp = S.size();
    while(tmp != 0){
        for (int i = 0; i < 4; ++i) {
            int t = T[i].size();
            if(tmp - t >=0) {
                if (S.compare(tmp - t, t, T[i]) == 0) {
                    tmp -= t;
                    break;
                }
            }
            if(i == 3){
                cout << "NO" <<endl;
                return 0;
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}

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

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

int N, C;
int D[555][555];
int c[555][555];
map<int, int> mp0, mp1, mp2; // map<色, 個数>

// mod0の色、mod1の色、mod2の色を決め打った時の合計コスト
int solve(int zero, int one, int two) {
	int ret = 0;
	// mod0の色を変える合計コストを求める
	for (auto x : mp0) {
		int num = x.first;
		int cnt = x.second;
		ret += D[num-1][zero-1] * cnt;
	}

	// mod1の色を変える合計コストを求める
	for (auto x : mp1) {
		int num = x.first;
		int cnt = x.second;
		ret += D[num-1][one-1] * cnt;
	}

	// mod2の色を変える合計コストを求める
	for (auto x : mp2) {
		int num = x.first;
		int cnt = x.second;
		ret += D[num-1][two-1] * cnt;
	}

	return ret;
}

signed main() {
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> c[i][j];
			int I = i+1, J = j+1;
			// mod0, mod1, mod2ごとにその色が何個あるかを求める
			if ((I+J)%3 == 0) {
				mp0[c[i][j]]++;
			}
			if ((I+J)%3 == 1) {
				mp1[c[i][j]]++;
			}
			if ((I+J)%3 == 2) {
				mp2[c[i][j]]++;
			}
		}
	}

	int ans = 1e18;
	for (int c0 = 1; c0 <= C; c0++) { // mod0の色
		for (int c1 = 1; c1 <= C; c1++) { // mod1の色
			for (int c2 = 1; c2 <= C; c2++) { // mod2の色
				if (c0 == c1) continue;
				if (c0 == c2) continue;
				if (c1 == c2) continue;

				int t = solve(c0, c1, c2);
				chmin(ans, t);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,m,x,y,a[100],b[100],max,nax;
	cin>>n>>m>>x>>y;
	max=x;
	nax=y;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	
	for(int j=0;j<m;j++){
		cin>>b[j];
	}
	
	for(int i=0;i<n;i++){
		if(max<=a[i]){
			max=a[i];
		}
	}
	
	for(int j=0;j<m;j++){
		if(nax>=b[j]){
			nax=b[j];
		}
	}
	
	if(max<nax && x<max && max<=y && max!=x){
		cout<<"No War"<<endl;
	}
	
	else cout<<"War"<<endl;
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}
#include <iomanip>

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

int R; cin >> R;

cout << fixed << setprecision(15);



cout << 2 * R * acos(-1) << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int prea = 0;
    ll ans = 0;
    for(auto a : A)
    {
        if(prea > a)
        {
            int humidai = prea - a;
            prea = a + humidai;
            ans += humidai;
        }
        else prea = a;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3956
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, x, y = tin()
	#s = input()
	if n == 1:
		return abs(int(input())-y)
	else:
		al=lin()
		return max(abs(al[-1]-y), abs(al[-2]-al[-1]))
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 64104
#include <bits/stdc++.h>
#define inf (long long)1e18
using namespace std;
int main(){
    int n, w;
    pair <int, long long> item[201];
    scanf("%d%d", &n, &w);
    for (int i = 0; i < n; i++)
        scanf("%d%lld", &item[i].first, &item[i].second);
    long long dp[200001];
    fill(dp, dp + 200001, inf);
    int ans = 0;
    dp[0] = 0;
    for (int i = 0; i < n; i++)
        for (int j = 1000 * n; j >=item[i].second; j--)
        if (dp[j - item[i].second] != inf){
            dp[j] = min(dp[j], dp[j - item[i].second] + item[i].first);
            if (dp[j] <= w)
                ans = max(ans, j);
        }
            
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

D = []
for i in range(X):
    for j in range(Y):
        D.append(A[i]+B[j])
D.sort(reverse=True)

E = []
for i in range(min(len(D),K)):
    for j in range(Z):
        E.append(D[i]+C[j])
E.sort(reverse=True)

for i in range(K):
    print(E[i])

Measured memory_bytes: 225752
import sys
import math
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def solve(n):
    n = str(n)[-1]
    if n == '2' or n=='4' or n == '5' or n == '7' or n == '9':
        return 'hon'
    
    elif n == '0' or n == '1' or n == '6' or n == '8':
        return 'pon'

    elif n == '3':
        return 'bon'

def main():
    inpu = inp()
    answer = solve(inpu)
    print(answer)

main()




Measured memory_bytes: 9220
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<limits>
#include<iomanip>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;



int main(){
    while(1){
    cout<<fixed<<setprecision(12);
    int r,n;
    vector<int> v(200);
    cin>>r>>n;
        if(r==0 && n==0){break;}
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int t=100+a;t<100+b;t++){
            v[t]=max(v[t],c);
        }
    }
    double mi=1e9;
    for(int i=100-r+1;i<100+r;i++){
        int h=min(v[i],v[i-1]);
        mi=min(mi,(double)h+r-sqrt(r*r-(100-i)*(100-i)));
    }
    mi=min(mi,(double)v[100-r]+r);
    mi=min(mi,(double)v[100+r-1]+r);
    cout<<mi<<endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
typedef unsigned long long ll;
const int N=1e5+7;
int n;
int a[N];
int main(){
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        ans+=a[i]-1;
    }
    printf("%d\n",ans);
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N+1, 0);
    vector<ll> B(N+2, 0);
    for(int i=0;i<N+1;i++) cin >> A[i];
    for(int i=0;i<N  ;i++) cin >> B[i+1];
    ll res = 0;
    for(int i=0; i<N+1; i++){
        for(int j=0; j<2; j++){
            auto v = min(A[i], B[i+j]);
            res += v;
            A[i] -= v;
            B[i+j] -= v;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,a,b;
  cin>>n>>a>>b;
  if((n+a-1)/a>b||n-a+1<b){
    cout<<-1<<endl;
    return 0;
  }
  using P = pair<Int, Int>;
  deque<P> d;
  Int x=1;
  while(x<=n){
    d.emplace_front(x,min(x+a-1,n));
    x=d.front().second+1;
  }
  //for(Int i=0;i<(Int)d.size();i++) cout<<d[i].first<<" "<<d[i].second<<endl;
  Int r=b-d.size();
  assert(r>=0);
  
  deque<P> e;
  while(!d.empty()){
    while(r&&d.front().first!=d.front().second){      
      e.emplace_back(d.front().second,d.front().second);
      d.front().second--;
      r--;
    }
    e.emplace_back(d.front());
    d.pop_front();
  }
  
  bool flg=0;
  for(Int i=0;i<(Int)e.size();i++){
    for(Int j=e[i].first;j<=e[i].second;j++){
      if(flg) cout<<" ";
      flg=1;
      cout<<j;
    }
  }
  cout<<endl;
  return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

// {{{ BinaryIndexedTree

// {{{実装
struct BIT{
    vector<int> data;
    int leng;
    BIT( int n ){
        init(n);
    }
    void init(int n){
        leng = n;
        data.assign(n,0);
        for(int i = 0; i < n; i++ ){
            data[i] = 0;
        }
    }
    int sum(int i){
        int s = 0;
        for( ; i>0; i -= i & -i ){
            s += data[i];
        }
        return s;
    }
    void add(int i, int x){
        for( ; i<=leng ; i += i & -i ){
            data[i] += x;
        }
    }
};
// }}}

// {{{ 説明
/*
BIT.data[1,n] : data
BIT.leng : quantity of data
BIT.init(n) : YES
BIT.sum(a) : sum of data[1,a]
BIT.add(i,x) : add data[i] with x
*/
// }}}

// }}}

int main() {

    int N,K;
    Scd2(N,K);

    vl a(N);
    vl s(N+1,0);
    vl sc(N+1,0);
    Rep(i,N){
        Scll(a[i]);
        a[i] -= K;
        s[i+1] += s[i] + a[i];
        sc[i+1] = s[i+1];
    }

    sort(sc.begin(),sc.end());

    map<ll,int> zatu;

    int ii = 1;
    Rep(i,N+1){
        if( zatu.find(sc[i]) == zatu.end() ) zatu[sc[i]] = ii++;
    }

    ll ans = 0;

    BIT b(N+334);
    Repe(i,N+1,0){
        // printf("%lld -> %d\n", s[i], zatu[s[i]]);
        ans += b.sum(zatu[s[i]]);
        b.add(zatu[s[i]],1);
    }

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

    return 0;
}



Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <string>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = (int)S.size();
    auto dp = make_vec<int>(N+2, N+2, K+2);
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            for (int k = 0; k <= K; ++k) {
                chmax(dp[i+1][j][k], dp[i][j][k]);
                chmax(dp[i][j+1][k], dp[i][j][k]);
                chmax(dp[i+1][j+1][k+1], dp[i][j][k] + 1);
                if (i < N && N-1-j >= 0 && S[i] == S[N-1-j])
                    chmax(dp[i+1][j+1][k], dp[i][j][k] + 1);
            }
        }
    }
    int res = 0;
    for (int k = 0; k <= K; ++k) {
        for (int i = 0; i <= N; ++i) chmax(res, dp[i][N-i][k] * 2);
        for (int i = 0; i < N; ++i) chmax(res, dp[i][N-1-i][k] * 2 + 1);
    }
    cout << res << endl;
}


Measured memory_bytes: 111104
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int,int> PI;

int maze[60][60];
int X, Y, tx, ty, kx, ky;

bool passed[50][50][50][50];

struct P
{
	int tx, ty;
	int kx, ky;
	int cost;

	P(int _tx, int _ty, int _kx, int _ky, int _cost) : tx(_tx), ty(_ty), kx(_kx), ky(_ky), cost(_cost) {};
};

bool check(int x, int y){
	return x < 0 || x >= X || y < 0 || y >= Y || maze[y][x];
}

int main(void){
	while(cin >> X >> Y, X|Y){
		int ans = -1;
		cin >> tx >> ty >> kx >> ky;
		tx--, ty--, kx--, ky--;

		for(int i=0; i<Y; ++i){
			for(int j=0; j<X; ++j){
				cin >> maze[i][j];
			}
		}

		queue<P> que;
		memset(passed, 0, sizeof(passed));


/*		for(int i=0; i<Y; ++i){
			for(int j=0; j<X; ++j){
				for(int k=0; k<Y; ++k){
					for(int l=0; l<X; ++l){
						d[i][j][k][l] = INF;
					}
				}
			}
		}
*/
		for(que.push(P(tx, ty, kx, ky, 0)); !que.empty(); que.pop()){
			P p = que.front();

			if(p.cost >= 100) break;
			if(p.tx == p.kx && p.ty == p.ky){
				ans = p.cost;
				break;
			}

			for(int dx=-1; dx<=1; dx++){
				for(int dy=-1; dy<=1; dy++){
					if(abs(dx-dy) != 1) continue;
					int ntx = p.tx + dx, nty = p.ty + dy;
					int nkx = p.kx - dx, nky = p.ky - dy;

					if(check(ntx, nty)) ntx = p.tx, nty = p.ty;
					if(check(nkx, nky)) nkx = p.kx, nky = p.ky;
					if(passed[ntx][nty][nkx][nky]) continue;

					passed[ntx][nty][nkx][nky] = true;
					que.push(P(ntx, nty, nkx, nky, p.cost + 1));
				}
			}
		}

		if(ans == -1){
			cout << "NA" << endl;
		} else {
			cout << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 7536
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

#define int long long

signed main() {
	int N;
	int a[100000] = {};
	cin >> N;
	int min = 99999999 , max = -9999999;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (min > a[i])min = a[i];
		if (max < a[i])max = a[i];
	}

	int cost = 9999999;

	for (int i = min; i <= max; i++) {
		int tmp = 0;
		for (int j = 0; j < N; j++) {
			tmp += (a[j] - i)*(a[j] - i);
		}
		if (tmp < cost)cost = tmp;
	}



	cout << cost << endl;

	return 0;
}



Measured memory_bytes: 1024
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let s1:Vec<char> = scan.next::<String>().chars().collect();
    let s2:Vec<char> = scan.next::<String>().chars().collect();

    let mut dp:Vec<Vec<usize>> = (0..(s1.len()+1)).map(|_| (0..(s2.len()+1)).map(|_| 0).collect()).collect();

    for i in 1..(s1.len()+1) {
        dp[i][0] = i;
    }

    for i in 1..(s2.len()+1) {
        dp[0][i] = i;
    }

    for i in 1..(s1.len()+1) {
        for j in 1..(s2.len()+1) {
            if s1[i-1] == s2[j-1] {
                dp[i][j] = cmp::min(dp[i-1][j-1],cmp::min(dp[i-1][j]+1,dp[i][j-1]+1));
            } else {
                dp[i][j] = cmp::min(dp[i-1][j-1]+1,cmp::min(dp[i-1][j]+1,dp[i][j-1]+1));
            }
        }
    }

    println!("{}",dp[s1.len()][s2.len()]);
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    LL ans = 1;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
            return;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (ans > INF/a[i]) {
            cout << -1 << endl;
            return;
        }
        ans *= a[i];
    }
    cout << ans <<endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}




Measured memory_bytes: 3988
loop do
  n = gets.chomp.to_i
  break if n==0
  ans = 0
  for i in 0...n
    for j in (i+1)...n
      t = (j*(j+1) - i*(i+1))/2
      if t==n
        ans+=1
      end
    end
  end
  puts ans
end

Measured memory_bytes: 6096
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const s = input[0];
const n = +s;

let fx = 0;
for (const c of s) {
	fx += +c;
}

console.log((n % fx === 0) ? "Yes" : "No");


Measured memory_bytes: 7372
import sys
import numpy as np
import heapq


def input():
    return sys.stdin.readline()[:-1]


def solve():

    # a = [1, 6, 8, 0, -1]
    # heapq.heapify(a)  # リストを優先度付きキューへ
    # print(a)

    # print(heapq.heappop(a))  # 最小値の取り出し
    # print(a)

    # heapq.heappush(a, -2)  # 要素の挿入
    # print(a)
    N, M = map(int, input().split())
    jobs = [[] for _ in range(M)]
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        jobs[M-a].append(b)
    que = []
    heapq.heapify(que)
    total = 0
    for i in reversed(range(M)):
        for b in jobs[i]:
            heapq.heappush(que, -b)
        if que:
            total += -heapq.heappop(que)
    print(total)


if __name__ == "__main__":
    solve()


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

bool cmp(Pii p1, Pii p2) { return p1.second < p2.second; }

int main(){
    int n, m, a, b;
    cin >> n >> m;
    Pii p[m], q[m];
    rep(m){
        cin >> a >> b;
        p[i] = Pii(a, b);
    }
    sort(p, p+m, cmp);
    int e = 0, ans = 0;
    rep(m){
        if(p[i].first >= e){
            ans++;
            e = p[i].second;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int hi = 0;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += max(0, hi - a[i]);
    hi = max(hi, a[i]);
  }
  cout << ans;
}

Measured memory_bytes: 4040
X = int(input())

#x^5-y^5=(x-y)(x^4+x^3y+x^2y^2+xy^3+y^4)

#for x in range(1, 121):
#  if ((x**5) - ((x-1)**5)) >= 1000000000:
#    print(x)

for a in range(0, 121):
  for b in reversed(range(-122, 120)):
    if b**5 == a**5-X:
      print(a, b)
      exit()



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

ll n, ans;

int main(){
    cin >> n;
    for (ll i=2; i * i <= n; i++){
        if (n % i) continue;
        ll n2 = n;
        while (n2 % i == 0) n2 /= i;
        if (n2 % i == 1) ans++;
    }
    ll n2 = n - 1;
    for (ll i=1; i * i <= n2; i++){
        if (n2 % i) continue;
        ans += 2;
        if (i * i == n2) ans--;
    }
    // ans += (n > 2) + 1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
///
//  Author : Author
// Created On : Mon Dec 18 2017
//  File : d.cpp
//
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main() {
  int64_t N, Z, W;
  cin >> N >> Z >> W;

  vector<int64_t> cards(N);
  for (uint32_t i = 0; i < N; i++) {
    cin >> cards[i];
  }

  int64_t prev = 0;
  if (cards.size() > 1) {
    prev = abs(cards[cards.size() - 2] - cards[cards.size() - 1]);
  }

  cout << max(prev, abs(cards[cards.size() - 1] - W)) << endl;

  return 0;
}


Measured memory_bytes: 256
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;
const ll mx = 1e5+123;
int main()
{
    speed;
    ll t,i,j,a,b,c,d=0,e=0,ans=0;
    char s;
    cin>>s;
    if(s>=65 && s<=90)
        cout<<"A"<<endl;
    else
        cout<<"a"<<endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

class UnionFind {
public:
    vector <int> par;
    vector <int> siz;

    UnionFind(int sz_): par(sz_), siz(sz_, 1LL) {
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }

    int root(int x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

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

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

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

signed main() {
  int N, M;
  cin >> N >> M;

  UnionFind uf(N);

  vector<int> X(M), Y(M), Z(M);
  REP(i, M){
    cin >> X[i] >> Y[i] >> Z[i];
    uf.unite(X[i]-1, Y[i]-1);
  }

  set<int> s;
  REP(i, N){
    s.insert(uf.root(i));
  }

  cout << s.size() << "\n";

  return 0;
}


Measured memory_bytes: 11912
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<string>ansl;
string s;
int ary[100005] = {0};
int main(){
  int N,M,flag = 0;
  string opn = "Opened by ",cls = "Closed by ",unk = "Unknown ";

  cin >>N;
  for (int i = 0;i<N;i++){
    cin >>s;
    v.push_back(s);
  }


  cin >>M;
  for(int i = 0;i<M;i++){
    cin >>s;
    int now_flg = flag;
    for(int j = 0;j<N;j++){
      if(s == v[j]){
        if(flag){
          flag = 0;
          ansl.push_back(cls + s);
        }else{
          flag = 1;
          ansl.push_back(opn + s);
        }
      }
    }
    if(now_flg == flag){
      ansl.push_back(unk + s);
    }
  }

  for(int i = 0;i<M;i++){
    cout <<ansl[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define N 7
using namespace std;
int h,w,k,ans,d[N][N];
void count(){
//	for (int i=0;i<h;++i){
//		for (int j=0;j<w;++j){
//			cout<<d[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	int cnt=0;
	for (int i=0;i<h;++i){
		for (int j=0;j<w;++j){
			if (d[i][j]==1){
				++cnt;
			}
		}
	}
	if (cnt==k){
//		cout<<"ANS"<<endl;
		++ans;
	}
//	else{
//		cout<<"NO"<<endl;
//	}
}
void dfs_w(int nw){
//	for (int i=0;i<h;++i){
//		temp[i]=d[i][nw];
//	}
	int l0=d[0][nw],l1=d[1][nw],l2=d[2][nw],l3=d[3][nw],l4=d[4][nw],l5=d[5][nw];
	if (nw>=w){
		count();
		return;
	}
//	for (int i=0;i<h;++i){
//		for (int j=0;j<w;++j){
//			cout<<d[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	dfs_w(nw+1);
	for (int i=0;i<h;++i){
		d[i][nw]=2;
		//2 for $(red)
	}
//	for (int i=0;i<h;++i){
//		for (int j=0;j<w;++j){
//			cout<<d[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	dfs_w(nw+1);
//	for (int i=0;i<h;++i){
//		d[i][nw]=temp[i];
//	}
	d[0][nw]=l0;
	d[1][nw]=l1;
	d[2][nw]=l2;
	d[3][nw]=l3;
	d[4][nw]=l4;
	d[5][nw]=l5;
}
void dfs_h(int nh){
	int l0=d[nh][0],l1=d[nh][1],l2=d[nh][2],l3=d[nh][3],l4=d[nh][4],l5=d[nh][5];
//	for (int i=0;i<w;++i){
//		temp[i]=d[nh][i];
//	}
	if (nh>=h){
		dfs_w(0);
		return;
	}
//	for (int i=0;i<h;++i){
//		for (int j=0;j<w;++j){
//			cout<<d[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	dfs_h(nh+1);
	for (int i=0;i<w;++i){
		d[nh][i]=2;
	}
//	for (int i=0;i<h;++i){
//		for (int j=0;j<w;++j){
//			cout<<d[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	dfs_h(nh+1);
	d[nh][0]=l0;
	d[nh][1]=l1;
	d[nh][2]=l2;
	d[nh][3]=l3;
	d[nh][4]=l4;
	d[nh][5]=l5;
//	for (int i=0;i<w;++i){
//		d[nh][i]=temp[i];
//	}
}
int main(){
	cin>>h>>w>>k;
	string s;
	for (int i=0;i<h;++i){
		cin>>s;
		for (int j=0;j<w;++j){
			char ch=s[j];
			if (ch=='.'){
				d[i][j]=0;
				//0 for .(white)
			}
			else if (ch=='#'){
				d[i][j]=1;
				//1 for #(black)
			}
			else{
				--j;
			}
		}
	}
	dfs_h(0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        boolean[] broken = new boolean[N+1];

        for (int i=0; i<M; i++) {
            broken[scanner.nextInt()] = true;
        }

        long[] dp = new long[N+2];
        dp[N+1] = 0;
        dp[N] = 1;
        for (int i=N-1; i >= 0; i--) {
            if (broken[i]) {
                dp[i] = 0;
                continue;
            }
            dp[i] = (dp[i+1] + dp[i+2]) % 1000000007;
        }
        System.out.println(dp[0]);
    }
}


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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);
  
  int sat=0;
  for(int i=1; i<=D; i++){
    int cont; cin >> cont;
    cont--;
    t[i-1]=cont;
    
    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
    
    //満足度の更新
    sat+=s[i-1][cont];
    for(int j=0; j<26; j++){
      if(j==cont){
        continue;
      }else{
        sat-=c[j]*(i-lastc[i][j]);
      }
    }
  }
  
  int M; cin >> M;
  for(int i=0; i<M; i++){
    int d,q; cin >> d >> q; q--;
    int qold=t[d-1];
    t[d-1]=q;
    
    sat-=s[d-1][qold]; //cout << sat << ",";
    sat+=s[d-1][q]; //cout << sat << ",";
    
    for(int j=d; j<=D; j++){
      if(j==d){
        lastc[j][qold]=lastc[j-1][qold];
        sat-=c[qold]*(j-lastc[j][qold]);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastc[j-1][qold]);
        lastc[j][qold]=lastc[j-1][qold];
      }
    }
    
    for(int j=d; j<=D; j++){
      if(j==d){
        sat+=c[q]*(j-lastc[j][q]);
        lastc[j][q]=j;
      }
      else if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
        lastc[j][q]=d;
      }
    }
    
    cout << sat << endl;
  }
}

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

using namespace::std;

long long dp[20001];

int main(){
    long s,p=1000000007;
    cin >> s;
    dp[3] = 1;
    for(int i=4;i<=s;i++){
        for(int j=3;j<s;j++){
            if(i-j >= 0) dp[i] = (dp[i] + dp[i-j]) % p;
        }
        dp[i]++;
    }
    cout << dp[s];
}


Measured memory_bytes: 3612
a,b,k = map(int,input().split())
minnum = min(a,b)
maxnum = max(a,b)
lis = []
for mi in reversed(range(1,minnum+1)):
  if minnum % mi == 0 and maxnum % mi == 0:
    lis.append(mi)

print(lis[k-1])

Measured memory_bytes: 9044
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N[] = new int[4];
        N[0] = sc.nextInt();
        N[1] = sc.nextInt();
        N[2] = sc.nextInt();
        N[3] = sc.nextInt();
        boolean f1, f9, f7, f4;
        f1 = Arrays.stream(N).anyMatch(a->a==1);
        f9 =Arrays.stream(N).anyMatch(a->a==9);
        f7 =Arrays.stream(N).anyMatch(a->a==7);
        f4 =Arrays.stream(N).anyMatch(a->a==4);
        String result = (f1 && f9 && f7 && f4) ? "YES" : "NO";
        System.out.println(result);
    }
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

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

  cout << (N - i + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d" @@ fun l ->
  let a = Array.init (l+1) @@ fun i ->
    if i = 0 then 0
    else Scanf.scanf " %d" ((+) 0)
  in
  for i = 1 to l do a.(i) <- a.(i) + a.(i-1) done;
  let a x y = a.(y) - a.(x-1) in

  let dpl1, dpl2 = Array.make (l+1) 0, Array.make (l+1) 0 in
  let dpr1, dpr2 = Array.make (l+2) 0, Array.make (l+2) 0 in
  for i = 1 to l do
    dpl1.(i) <- min (a 1 i) @@
      dpl1.(i-1) + if a i i = 0 then 2 else a i i mod 2;
    dpl2.(i) <- min dpl1.(i-1) dpl2.(i-1) + (a i i + 1) mod 2;
  done;
  for i = l downto 1 do
    dpr1.(i) <- min (a i l) @@
      dpr1.(i+1) + if a i i = 0 then 2 else a i i mod 2;
    dpr2.(i) <- min dpr1.(i+1) dpr2.(i+1) + (a i i + 1) mod 2;
  done;

  Array.init (l+1) (fun i ->
    dpl1.(i) + dpr1.(i+1)
    |> min (dpl1.(i) + dpr2.(i+1))
    |> min (dpl2.(i) + dpr1.(i+1)))
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"

Measured memory_bytes: 14464
//Prime Factorize
#include <iostream>
#include <vector>

using namespace std;

vector<int> factorize(int n) {
    vector<int> ans;
    int i = 2;
    while(n > 1) {
        if(n % i == 0) {
            ans.push_back(i);
            n /= i;
        }
        else if(i*i > n) {
            ans.push_back(n);
            break;
        }
        else i++;
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<int> ans = factorize(n);

    cout << n << ":";
    for(auto x: ans) cout << " " << x;
    cout << endl;
}


Measured memory_bytes: 3148
//Binary Search Tree I
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *parent = nullptr, *left = nullptr, *right = nullptr;
    explicit Node(int key) : key(key){}
};

class Tree {
public:
    void insert(int key);
    bool find(int key);
    Node *root = nullptr;
};

void Tree::insert(int key) {
    Node *x = root;
    Node *y = nullptr;
    auto *n = new Node(key);
    while(x != nullptr) {
        y = x;
        if(key < x -> key) x = x -> left;
        else x = x -> right;
    }
    if(y == nullptr) {
        root = n;
    }
    else {
        n -> parent = y;
        if(key < y -> key) y -> left = n;
        else y -> right = n;
    }
}

bool Tree::find(int key) {
    Node *x = root;
    while(x != nullptr) {
        if(x -> key == key) return true;
        else if(key < x -> key) x = x -> left;
        else x = x -> right;
    }
    return false;
}

void inOrder(Node *N) {
    if(N == nullptr) return;
    inOrder(N -> left);
    cout << " " << (N -> key);
    inOrder(N -> right);
}

void preOrder(Node *N) {
    if(N == nullptr) return;
    cout << " " << (N -> key);
    preOrder(N -> left);
    preOrder(N -> right);
}


int main() {
    Tree T;

    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string opr;
        int key;
        cin >> opr;
        if(opr == "insert") {
            cin >> key;
            T.insert(key);
        }
        if(opr == "find") {
            cin >> key;
            if(T.find(key)) cout << "yes" << endl;
            else cout << "no" << endl;
        }
        if(opr == "print") {
            inOrder(T.root);
            cout << endl;
            preOrder(T.root);
            cout << endl;
        }
    }
}


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


int main(){
  int N, M;
  cin >> N >> M;
  map<int, vector<int>> A;
  for(int ii=0; ii<N; ii++){
    int a, b;
    cin >> a >> b;
    A[a].push_back(b);
  }

  long long int ans = 0;
  map<int, int> target;
  for(int ii = 1; ii <= M; ii++){
    auto it = A.find(ii);
    if(it != A.end()){
      for(auto& a : it->second){
        target[a]++;
      }
    }
    if(target.size()==0) continue;
    ans += target.rbegin()->first;
    target.rbegin()->second--;
    if(target.rbegin()->second == 0){
      target.erase(target.rbegin()->first);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	ll sum = 0, ans = 0;
	rep(i, n) {
		sum += a[i];
		sum %= mod;
	}
	
	rep(i, n-1) {
		sum -= a[i];
		if (sum < 0) sum += mod;
		ans += sum * a[i];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3992
using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            string line1 = Console.ReadLine();
            string line2 = Console.ReadLine();


            List<long> NK = new List<long>(line1.Split(' ').Select((arg) => long.Parse(arg)));
            List<long> RowAs = new List<long>(line2.Split(' ').Select((arg) => long.Parse(arg)));

            long inCount = 0;
            long outCount = 0;

            for (int i = 0; i < RowAs.Count; i++)
            {
                if (i + 1 < RowAs.Count)
                {
                    for (int k = i+1; k < RowAs.Count; k++)
                    {
                        if (RowAs[i] > RowAs[k])
                        {
                            inCount++;
                        }
                    }
                }
            }



            for (int i = 0; i < RowAs.Count; i++)
            {
                    for (int k = 0; k < RowAs.Count; k++)
                    {
                        if (RowAs[i] > RowAs[k])
                        {
                            outCount++;
                        }
                    }
            }

            long mod = (long)(Math.Pow(10, 9) + 7);

            inCount = (NK[1] * inCount) % mod;
            outCount = ((((NK[1] * (NK[1] - 1)) / 2) % mod) * outCount) % mod;



            Console.WriteLine((inCount+outCount)%mod);

        }
    }


Measured memory_bytes: 11348
n = int(input())
a = list(map(int, input().split()))
k = sum(a) // (n*(n+1)//2)
if n*(n+1)*k // 2 != sum(a):
  print('NO'); exit(0)
b = [a[i] - a[i-1] - k for i in range(n)]
for x in b:
  if x > 0 or x%n: print('NO'); break
else:
  print('YES')

Measured memory_bytes: 14292
#include <iostream>

using namespace std;

int main(){
    int n, k;
    char s[n];
    cin >> n >> k;
    cin >> s;
    s[k - 1] = tolower(s[k - 1]);
    for (int i = 0; i < n; ++i) cout << s[i] << "";
    cout << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

const ll INF = 1LL<<60;

//#define __DBG__

int N;

void solve(void){
  
  cin >> N;
  
  vector<int> A(N,0);

  REP(i,N){
    cin >> A[i];
  }
  
  int count=0;
  int p=1;
  
  REP(i,N){
    if(A[i]!=p){
      count++;
    }
    else
    {
      p++;
    }
  }
  if(count>=N){
    count = -1;
  }
  
  cout << count << endl;
  
  
  return;
}

int main(int argc, const char * argv[]) {



    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

bool prime[1000000+10];
std::vector<int> v;

void solve(){
  int n = 1000000;
  memset(prime,true,sizeof(prime));
  for(int i=2;i*i<=n;i++){
    if(prime[i]){
      for(int j=2*i;j<=n;j+=i){
        prime[j]=false;
      }
    }
  }
  prime[0]=false;
  prime[1]=false;
  for(int i=2;i<=n;i++){
    if(prime[i] && i%5==1){
      v.push_back(i);
    }
  }
}


int main(){
  solve();
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cout << v[i] << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 1408