akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

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

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

vector<pair<ll, ll>> calc_factor(ll x) {
  vector<pair<ll, ll>> retv;
  ll tmp_x = x;
  ll max_divider = sqrtl(ld(x));
  for (ll divider = 2; divider <= max_divider; divider++) {
    pair<ll, ll> f{divider, 0};
    while (tmp_x % divider == 0) {
      tmp_x /= divider;
      max_divider = sqrtl(ld(x));
      f.second++;
    }

    if (f.second > 0) {
      retv.push_back(f);
    }
  }

  if (tmp_x != 1) {
    retv.push_back(pair<ll, ll>{tmp_x, 1});
  }
  return retv;
}

ll calc_div_time(ll x) {
  ll retv = 0;
  ll tmp_x = x;
  while (retv < tmp_x) {
    tmp_x -= (retv + 1);
    retv++;
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  // main procedure
  auto factor_N = calc_factor(N);
  ll ans = 0;

  for (auto &&f : factor_N) {
    if (f.first != 1) {
      ans += calc_div_time(f.second);
    }
  }

  // output
  cout << ans << endl;

  return 0;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

string s[2];

int main()
{
    cin >> s[0] >> s[1];
    if (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0])
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		BigInteger n = sc.nextBigInteger();
		BigInteger k = sc.nextBigInteger();
		// NとKの余り
		BigInteger ans = n.remainder(k);

		// NとKの余りと余りとKの差を大小比較
		System.out.println(ans.min(ans.subtract(k).abs()));
	}
}

Measured memory_bytes: 23892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_172
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nmk = ReadInts();
            int n = nmk[0];
            int m = nmk[1];
            long k = nmk[2];

            long[] aArray = ReadLongs();
            long[] bArray = ReadLongs();

            long[] aSums = new long[n + 1];
            for (int i = 0; i < n; i++)
            {
                aSums[i + 1] = aArray[i];
                aSums[i + 1] += aSums[i];
            }

            long[] bSums = new long[m + 1];
            for (int i = 0; i < m; i++)
            {
                bSums[i + 1] = bArray[i];
                bSums[i + 1] += bSums[i];
            }

            int bI = m;
            int res = 0;
            for(int i = 0; i <= n; i++)
            {
                while (bI > 0 && aSums[i] + bSums[bI] > k)
                {
                    bI--;
                }

                if (aSums[i] + bSums[bI] > k)
                {
                    break;
                }

                res = Max(res, i + bI);
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 72820
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }


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

    ll a,b,c; cin >> a>>b>>c;
    cout << ((a+b+c>21)?"bust":"win") << '\n';
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[110], res = 0, plus = 0;
    int b[8] = {0};
    bool flag = false;
    rep(i,n){
        cin >> a[i];
            if(1<=a[i]&&a[i]<=399)
                b[0]++, flag = true;
            if(400<=a[i]&&a[i]<=799)
            b[1]++,flag = true;
            if(800<=a[i]&&a[i]<=1199)
            b[2]++,flag = true;
            if(1200<=a[i]&&a[i]<=1599)
            b[3]++,flag = true;
            if(1600<=a[i]&&a[i]<=1999)
            b[4]++,flag = true;
            if(2000<=a[i]&&a[i]<=2399)
            b[5]++,flag = true;
            if(2400<=a[i]&&a[i]<=2799)
            b[6]++,flag = true;
            if(2800<=a[i]&&a[i]<=3199)
            b[7]++,flag = true;
            if(a[i]>3199)
                plus++;
    }
    for (int i = 0; i < 8;i++){
        if(b[i]>0)
            res++;
    }
    if(flag){
    cout << res << ' ' << res + plus << endl;
    }
    else
        cout << 1 << ' ' << plus << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;
int n,a[N],b[N],ans;
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&b[i]);
	for (int i=n;i;i--)
		ans+=(b[i]-(ans+a[i])%b[i])%b[i];
	printf("%lld",ans);	
} 

Measured memory_bytes: 1792
#include<iostream>


using namespace std;


int main() {
	int n[21][12];
	int Num[21];
	for (int i = 0;i < 21;i++) {
		n[i][0] = n[i][11] = 0;
	}
	for (int i = 1;i < 11;i++) {
		n[0][i] = 1;
	}
	for (int i = 1;i < 21;i++) {
		for (int j = 1;j <= 10;j++) {
			n[i][j] = n[i - 1][j - 1] + n[i - 1][j] + n[i - 1][j + 1];
		}
	}

	int k;
	cin >> k;
	int i, j;
	for (i = 0;i <21;i++) {
		for (j = 2;j <= 10;j++) {
			k -= n[i][j];
			if (k <= 0)break;
		}
		if (k <= 0)break;
	}
	k += n[i][j];
	int msb = i;
	Num[i] = j;
	for (int x = i - 1;x >= 0;x--) {
		for (int y = -1;y <= 1;y++) {
			k -= n[x][Num[x + 1] + y];
			if (k <= 0) {
				k+= n[x][Num[x + 1] + y];
				Num[x] = Num[x + 1] + y;
				break;
			}
		}
		
	}

	for (int x = msb;x >= 0;x--) {
		cout << Num[x]-1;
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll pat[52];
ll siz[52];

int main(){
    int n;
    cin >> n;
    pat[0] = 1;
    siz[0] = 1;
    for ( int i = 1; i <= n; ++i ) {
        pat[i] = pat[i-1] * 2 + 1;
        siz[i] = siz[i-1] * 2 + 3;
    }
    ll x;
    cin >> x;
    ll ret = 0;
    while(n>0 && x>0) {
        if (x>=2+2*siz[n-1]) {
            ret+=1+2*pat[n-1];
            x=0;
            break;
        }
        if(x>=2+siz[n-1]) {
            ret+=1+pat[n-1];
            x-=2+siz[n-1];
        }
        else if (x==1+siz[n-1]) {
            ret+=pat[n-1];
            x-=1+siz[n-1];
        }
        else {
            --x;
        }
        --n;
    }
    if (x) ++ret;
    cout << ret << endl;
    return 0;
}


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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}

Measured memory_bytes: 3640
n = int(input())
a = list(map(int, input().split()))

count = 0
j = 1
for i in range(n):
    if a[i] == j:
        #kudakanai
        j += 1
    else:
        #kudaku
        count += 1
if count == n:
    print(-1)
else:
    print(count)

Measured memory_bytes: 24744
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
int a[200002], b[200002];
int p[200002];
ll x[200002];
ll cou[200002];
bool checked[200002];
vector<int> v[200002];

int main()
{
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n - 1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    for(int i = 0; i < q; i++){
        cin >> p[i] >> x[i];
        p[i]--;
        cou[p[i]] += x[i];
    }
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int now = que.front();
        que.pop();
        checked[now] = true;
        for(int next : v[now]){
            if(!checked[next]){
                cou[next] += cou[now];
                que.push(next);
            }
        }
    }
    for(int i = 0; i < n; i++) cout << cou[i] << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    ll k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;++i)
    {
        cin>>vec[i];
        vec[i]--;
    }
    vector<int> vec1;
    set<int> s;
    int count=0;
    int temp=0;
    s.insert(temp);
    vec1.push_back(temp);
    while(1)
    {
        count++;
        temp=vec[temp];
        if(s.find(temp)!=s.end())
        break;
        else
        {
        s.insert(temp);
        vec1.push_back(temp);
        }
    }
    int n1=s.size();
    if(k>=n1)
    {
        k=k-n1;
        int i;
        for(i=0;i<n1;++i)
        {
            if(vec1[i]==temp)
            break;
        }
        int n2=n1-i;
        k=k%n2;
        k=i+k;
    }
    //cout<<k<<" ";
    cout<<vec1[k]+1<<"\n";
    

}



Measured memory_bytes: 13836
N, K = (int(x) for x in input().split())
P = [int(x) for x in input().split()]

# (n*(n+1))/2 /n == (n+1)/2

P2 = [(n+1) for n in P]

S = sum(P2[:K])
max_s = S
for i in range(1, N-K+1):
    S -= P2[i-1]
    S += P2[i+K-1]

    max_s = max(max_s, S)

# print(f'{max_s:.9f}')
print('{:.10f}'.format(max_s/2))


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

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

	int count = 0;

	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if (h >= K) count++;
	}

	cout << count << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    int d; cin >> d;
    cout << "Christmas ";
    if(d==25){
        return 0;
    }
    if(d==24){
        cout << "Eve";
    }
    if(d==23)
    {
        cout << "Eve Eve";
    }
    if(d==22){
        cout << "Eve Eve Eve";
    }
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, k, a, b;

int32_t main(){_

   cin>>k>>a>>b;

   if(a >= b){
      cout<<k+1;
      return 0;
   }

   if(k == 1){
      cout<<2;
      return 0;
   }

   if(k <= a or (a+1 == b)){
      cout<<1+k;
      return 0;
   }

   int bisc = b;
   k -= (a+1);

   bisc += (k/2) * (b-a) + (k%2);
   tr(bisc);

   cout<<bisc;

   return 0;
}

Measured memory_bytes: 256
/*
    author : SAMRAT DE
    username : Alucard_01
    NIT Durgapur
*/

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>*/
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define pi(x,y) pair<x,y>
#define mpp(x,y) map<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pf push_front
#define indexof order_of_key
#define valueat find_by_order
#define myds tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

using namespace std;
//using namespace __gnu_pbds;

ll nCr(ll n,ll r){
    vec(ll) C;
    C[0]=1;
    rep(i,1,n+1) for(int j=min(i,r);j<1;--j)C[j]=(C[j]+C[j-1])%mod;
    return C[r];
}

int32_t main()
{
    fastio;
    //best of luck don't loose hope man 
        
    int n;
    cin>>n;
    mpp(string,int) m;
    ll ans=0;
    rep(i,0,n){
        string s;
        cin>>s;
        sort(all(s));
        if(m.count(s)==0)
            m[s]=0;
        else
            ans+=++m[s];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11264
from itertools import permutations

def main():
    N = int(input())

    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    
    perm_list = list(permutations(range(1, N+1), N))
    perm_list.sort()
    print(abs(perm_list.index(P) - perm_list.index(Q)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 8052
#include<iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n,m;
    ll a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    
    m=n/(a+b);
    if(n-m*(a+b)<=a)
    {
        m=m*a+(n-m*(a+b));
    }
    else
    {
        m=m*a+a;
    }
    
    printf("%lld\n",m);
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
   int n,m,x,ans=1e8,tmp=0;
   cin >> n >> m >> x;
   vector<int> c(n);
   vector<int> cnt(m,0);
   vector<vector<int>> a(n,vector<int>(m));
   rep(i,n){
       cin >> c[i];
       rep(j,m){
           cin >> a[i][j];
       }
    }
    bool flag=true;
    for (int bit = 0; bit < (1<<n); ++bit) {
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                rep(j,m){
                    cnt[j] += a[i][j];
                }
                tmp += c[i];
            }
        }
        rep(i,m){
            if(cnt[i]<x) flag = false;
        }
        if(flag) ans = min(ans,tmp);
        tmp = 0;
        flag = true;
        rep(i,m){
            cnt[i] = 0;
        }
    }
    if(ans!=1e8) cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
bool asikiri(int n, VL& a) {
	bool res = false;
	if (n == 0 && a[0] != 1) res = true;
	else if (n != 0 && a[0] != 0) res = true;
	return res;
}
int main() {
	int n;
	cin >> n;
	VL a(n + 1);
	rep(i, n + 1) {
		cin >> a[i];
	}
	VL sum(n + 1, 0);
	sum[n] = a[n];
	for (int i = n - 1; i >= 0; i--) {
		sum[i] += sum[i + 1] + a[i]; // これが深さiの最大値
	}
	ll ans = 1;
	ll now = 1;
	if (asikiri(n, a)) {
		puts("-1");
		return 0;
	}
	/*
	深さiの最大値は
	min(2^i,a(dからnまでの総和)
	2^iは二分木は頂点を二つしか増やせないから,
	a(dからnまでの総和)は葉の数を変えることなく次の頂点の数を減らすことができないから
	*/
	rep1(i, n) {
		now *= 2;
		chmin(now, sum[i]);
		ans += now;
		now -= a[i];
		if (now < 0) {
			puts("-1");
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

    int H,W;
    char field[1005][1005];
    ll dp[1005][1005];
    cin >> H >> W;
    rep(i,H) rep(j,W) cin >> field[i][j];

    dp[0][0] = 1;
    rep(i,H) rep(j,W) {
        if(field[i][j] == '#') continue;
        else if(i == 0 and j== 0) continue;
        else if(i == 0) dp[i][j] = dp[i][j-1] % mod;
        else if(j == 0) dp[i][j] = dp[i-1][j] % mod;
        else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}



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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

struct Elm {
  int d = -1;
  vi last;
  int val = -1;
  int sel = -1;

  Elm() {last.resize(26);}
  Elm(int d, vi last, int val, int sel): d(d), val(val), last(last), sel(sel) {}
};

bool operator<(Elm e1, Elm e2) {
  return make_tuple(e1.val, e1.d, e1.sel, e1.last) > make_tuple(e2.val, e2.d, e2.sel, e2.last);
}

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

  int d;
  cin >> d;
  int n = 26;
  vi c(n);
  REP(i, n) {
    cin >> c[i];
  }

  vvi s(n, vi(d));
  REP(j, d) {
    REP(i, n) {
      cin >> s[i][j];
    }
  }

  map<Elm, Elm> prev;
  vector<priority_queue<Elm>> pq(d+1);
  vi init(n);
  pq[0].push(Elm(0, init, 0, -1));

  int ma = 50;

  REP(k, d) {
    while (!pq[k].empty()) {
      auto now = pq[k].top();
      pq[k].pop();
      //cerr << now.d << " " << now.val << "\n";
      vi last = now.last;
      int nowd = now.d;
      int nxtd = nowd + 1;
      int nowval = now.val;
      REP(i, n) {
        int nxtval = nowval;
        REP(j, n) {
          if (i != j) nxtval -= c[j] * (nxtd - last[j]);
        }
        nxtval += s[i][nowd];

        int prevlast = last[i];
        last[i] = nxtd;
        auto nxt = Elm(nxtd, last, nxtval, i);
        pq[k+1].push(nxt);
        prev[nxt] = now;
        last[i] = prevlast;
      }
      while (SZ(pq[k+1]) > ma) {
        //cerr << pq.top().val << endl;
        pq[k+1].pop();
      }
      //cerr << pq[k+1].top().val << endl;
    }
  }

  auto now = pq[d].top();
  //cerr << now.val << endl;

  vi hukugen(d);

  while(now.d > 0) {
    //cerr << now.d << endl;
    hukugen[now.d-1] = now.sel+1;
    //cerr << now.d << ":" << now.sel << endl;
    if(prev.count(now) == 0) break;
    now = prev[now];
  }
  //cerr << SZ(hukugen) << endl;

  //cerr << hukugen << endl;

  REP(i, d) {
    cout << hukugen[i] << endl;
  }

  //cerr << hukugen[0] << endl;


}








Measured memory_bytes: 168032
#include <iostream>
using namespace std;
int main() {
int n,m,a[100][100]={},b[100]={},c[100]={};
cin>>n>>m;
for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
    cin>>a[i][j];
  }
}
for(int j=0;j<m;j++){
  cin>>b[j];
}
for(int i=0;i<n;i++){
  for(int j=m-1;j>=0;j--){
    c[i]+=b[j]*a[i][j];
  }
}
for(int i=0;i<n;i++){
  cout<<c[i]<<endl;
}
  return 0;
}

Measured memory_bytes: 1208
sx, sy, tx, ty = map(int, input().split())
ans = ''
ans += 'R' * (tx - sx) + 'U' * (ty - sy)
ans += 'L' * (tx - sx) + 'D' * (ty - sy + 1)
ans += 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
ans += 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R'
print(ans)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {
	static final String YES = "Yes";
	static final String NO = "No";

	public static void main(String[] args) {
		final FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int total = 0;
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			total += a[i];
			a[i] *= 4 * m;
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] >= total) count++;
		}

		if (count >= m) System.out.println(YES);
		else System.out.println(NO);
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> v1(100010),v2(100010);
    rep(i,100010){
        v1[i].second=i+1;
        v2[i].second=i+1;
    }
    rep(i,n){
        int x;
        cin >> x;
        if(i%2==0){
            v1[x].first++;
        }else{
            v2[x].first++;
        }
    }
    sort(v1.begin(),v1.end());
    reverse(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    reverse(v2.begin(),v2.end());

    pair<int,int> pii1[2],pii2[2];
    pii1[0].first = v1[0].second;
    pii1[0].second =v1[0].first;
    pii1[1].first =v1[1].second;
    pii1[1].second =v1[1].first;

    pii2[0].first = v2[0].second;
    pii2[0].second =v2[0].first;
    pii2[1].first =v2[1].second;
    pii2[1].second =v2[1].first;

    if(pii1[0].first!=pii2[0].first){
        cout<<n-pii1[0].second-pii2[0].second<<endl;
        return 0;
    }

    int ans1 = n - pii1[0].second - pii2[1].second;
    int ans2 = n - pii1[1].second - pii2[0].second;
    cout<< min(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  vector<int> arr;
  bool nowr = true;
  arr.push_back(0);
  for(int i=1;i<S.size();++i) {
    if(nowr) {
      if(S[i]=='L') {
        arr.push_back(i);
        nowr = false;
      }
    }
    else {
      if(S[i]=='R') {
        arr.push_back(i);
        nowr = true;
      }
    }
  }
  int index;
  int ans[S.size()];
  for(int i=0;i<S.size();++i) {
    index = upper_bound(arr.begin(), arr.end(), i)-arr.begin();
    if(index%2==0) { // R
      index = arr[index-1];
      if((i-index)%2==0) {
        ans[i] = index;
      }
      else {
        ans[i] = index - 1;
      }
    }
    else {
      index = arr[index];
      if((i-index)%2==0) {
        ans[i] = index;
      }
      else {
        ans[i] = index-1;
      }
    }
  }
  map<int, int> amap;
  for(int i=0;i<S.size();++i) {
    amap[ans[i]]++;
  }
  for(int i=0;i<S.size();++i) cout<<amap[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 8924
c = []
for _ in [0]*3:
  c += [list(map(int, input().split()))]

flag = True
for i in [0,1]:
  for j in [0,1]:
    if c[i][j] + c[i+1][j+1] != c[i+1][j] + c[i][j+1]:
      flag = False
print("Yes" if flag else "No")

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<math.h>
#include<map>
using namespace std;

#define MST(vis,x) memset(vis,x,sizeof(vis))
#define INF 0x3f3f3f3f
#define ll long long
#define maxn  30000005
int main()
{
    int a,b,c,d;
    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
    {
        int l=max(a,c);
        int r=min(b,d);
        if(l>=r)printf("0\n");
        else printf("%d\n",r-l);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int k; string s; cin >> k >> s;
    if(s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,j,a[2][105],dp[2][105]={};
  
  cin >> n;
  for (i=0;i<2;i++) for (j=1;j<=n;j++){
    cin >> a[i][j];
  }
  
  for (i=1;i<=n;i++) dp[0][i]=dp[0][i-1]+a[0][i];
  
  for (i=1;i<=n;i++) dp[1][i]=max(dp[0][i],dp[1][i-1])+a[1][i];
  
  cout << dp[1][n] << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << ((N + 999) / 1000) * 1000 - N << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<list>

using namespace std;

class zone{
public:
	int s,t,id;
	zone(int s,int t,int id):s(s),t(t),id(id){}
};


int main()
{
	int n;
	while(cin>>n && n!=0){
		list<zone> L;
		for(int i=0;i<n;i++){

			char c;
			cin>>c;
			if(c=='W'){
				int id,length;
				cin>>id>>length;
				int now=0;
				for(list<zone>::iterator it=L.begin();it!=L.end();){
					zone look=*it;
					if(now<look.s){
						it=L.insert(it,zone(now,now+min(length,look.s-now)-1,id));
						length=length-min(length,look.s-now);
						if(length==0) break;
						now=look.t+1;
						continue;
					}
					now=look.t+1;
					it++;
				}
				if(length!=0)
					L.push_back(zone(now,now+length-1,id));
			}
			else if(c=='D'){
				int id; cin>>id;
				for(list<zone>::iterator it=L.begin();it!=L.end();){
					zone look=*it;
					if(look.id==id){
						it=L.erase(it);
						continue;
					}
					it++;
				}
			}
			else{
				int id;cin>>id;
				bool ok=false;
				for(list<zone>::iterator it=L.begin();it!=L.end();){
					zone look=*it;
					if(look.s>id){break;}
					if(look.s<=id && id<=look.t){ok=true;cout<<look.id<<endl;break;}
					it++;
				}
				if(!ok) cout<<-1<<endl;
			}
		}
		cout<<endl;
	}
	return 0;	
}

Measured memory_bytes: 988
fun main(args: Array<String>) {
    val (o, e) = (1..2).map { readLine()!! }
    var marged = arrayOfNulls<Char>(o.length + e.length)
    for (i in 0 until o.length + e.length) {
        if (i % 2 == 0) {
            marged[i] = o.toCharArray()[i/2]
        } else {
            marged[i] = e.toCharArray()[i/2]
        }
    }
    println(marged.joinToString(""))
}

Measured memory_bytes: 36260
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, L = map(int, readline().split())
  A = [L+i-1 for i in range(1, N+1)]
  S = sum(A)
  diff = INF
  ans = 0
  for i in range(N):
    x = S - A[i]
    d = abs(S-x)
    if d<diff:
      diff = d
      ans = x
  
  
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Measured memory_bytes: 12388
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,sse2,sse,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<ll>;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	cout << max(0ll, ((n-1)*b + a)-((n-1)*a + b)+1);
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


def calc_comb(a, b):
    if b > a - b:
        return calc_comb(a, a - b)

    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= (a - i)
        ans_div *= (i + 1)
        ans_mul %= mod
        ans_div %= mod

    ans = ans_mul * mod_pow(ans_div, mod - 2) % mod
    return ans


n, a, b = map(int, input().split())
ans = mod_pow(2, n) - calc_comb(n, a) - calc_comb(n, b) - 1
print(ans % mod)

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    map<int,int> kani;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        kani[a]++;
    }
    int ans=0;
    for(auto x : kani){
        if(x.first>x.second) ans+=x.second;
        if(x.first<x.second) ans+=x.second-x.first;
    }
    cout << ans << endl;

}

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

int main(void) {
int d,e;
string a, b, c;
cin >> a >> b >> c;
d = a.size() -1;
e = b.size() -1;
if (a[d] == b[0] && b[e] == c[0]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}


// vector<int> G[1010];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    vvi G(n, vi(n - 1));
    REP(i, n) {
        cin >> G[i];
        REP(j, n - 1) G[i][j]--;
    }

    int ans = 0;
    vector<int> orders(n, 0);
    deque<pair<int, int>> que, que_next;
    REP(i, n) que.emplace_back(i, G[i][0]);
    while(!que.empty()) {
        map<int, bool> used;
        while (!que.empty()) {
            int u, v;
            tie(u, v) = que.front(); que.pop_front();
            // cout << u << " " << v << endl;
            if (G[u][orders[u]] == v and G[v][orders[v]] == u and !used[u] and !used[v]) {
                // cout << "add " << endl;
                used[u] = used[v] = true;
                orders[u]++;
                orders[v]++;
                if (orders[u] < n - 1) que_next.emplace_back(u, G[u][orders[u]]);
                if (orders[v] < n - 1) que_next.emplace_back(v, G[v][orders[v]]);
            }
        }
        ans++;
        swap(que, que_next);
        // if (que.empty()) break;
    }

    REP(i, n) if( orders[i] < n - 1) {
        cout << -1 << endl;
        return 0;
    }

        /*
        int remN = 0;
        vvi g(n); vi h(n, 0);
        REP(i, n) {
            if (orders[i] == n - 1) continue;
            g[i].push_back(G[i][orders[i]]);
            h[G[i][orders[i]]]++;
            remN++;
        }
        stack<int> st;
        REP(i, n) if (orders[i] != n - 1 and h[i] == 0) st.push(i);

        vi tpl;
        while(st.size()) {
            int i = st.top(); st.pop(); orders[i]++;
            tpl.push_back(i);
            for (auto& j: g[i]) {
                h[j]--;
                if (h[j] == 0) st.push(j);
            }
        }

        cout << "tpl: "; for (auto e: tpl) cout << e << " "; cout << endl;

        cout << tpl.size() << " " << remN << endl;
        if (tpl.size() != remN) {
            cout << -1 << endl;
            return 0;
        }

        ans++;
        */

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))


n, m = load_list()
A = []
for _ in range(m):
    A.append(load())
A = set(A)

dp = dict()

s = list()
s.append(0)

def f(now, goal, A):
    if now > goal:
        return 0
    if now == goal:
        return 1
    
    cnt = 0
    if now + 1 in A:
        pass
    elif now + 1 in dp:
        cnt += dp[now+1]
    else: 
        dp[now+1] = f(now+1, goal, A) 
        cnt += dp[now+1]

    if now + 2 in A:
        pass
    elif now + 2 in dp:
        cnt += dp[now+2]
    else:
        dp[now+2] = f(now+2, goal, A) 
        cnt += dp[now+2]
    return cnt
sys.setrecursionlimit(1000000) 
cnt = f(0, n, A)
print(cnt % 1000000007)
    



Measured memory_bytes: 546568
//////////////** SATYAM * SHIVAM * SUNDARAM **////////////
/**
* author: G.Pavan Kumar
**/

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

#define eps 10e-9
#define mod 1000000007
#define ump unordered_map // operations take less time compared to map
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define ins insert
#define pof pop_front()
#define pob pop_back()
#define cnt(x) count(x)
#define ety empty()
#define mae *max_element
#define mie *min_element
#define acc accumulate
#define bs binary_search
#define rep(i,l,h) for(int i=l;i<h;i++)
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x) // easy method to iterate through a ds
#define sq(a) (a)*(a)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define f(x) find(x)


typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<str,int> psi;
typedef pair<ll,int> pli;
typedef ump<int,int> umpii;


int main(){
	FIO
	
	int n,l;cin>>n>>l;
	vector<str> s;
	while(n--){
		str x;cin>>x;
		s.pb(x);
	}
	sort(s.B,s.E);
	ds2(i,s)cout<<i;
	return 0;
}



Measured memory_bytes: 256
t=$<.map{a,b=_1.split.map &:to_r
b ?a*b==0?1[a]-1[b]:a/b:0}.tally
M=10**9+7
z=1
t.map{w=t[_1==0?0:-1/_1]||0
w>0&&_1<=0||z=z*(2**_2+2**w-1)%M}
p (t[0]-2+z)%M

Measured memory_bytes: 39236
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;  //これで"std::cout"が"cout"と書ける

//MACRO
typedef long long ll;                  //64bit以上を表現可能な型
#define INF 100000000                  //ほぼ無限
#define itn int                        //タイポ対策
#define all(x) (x).begin(), (x).end()  //sort(all(x))などとする
#define SZ(x) ((int)(x).size())        //size()簡略化
//repetition
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repR(i, n) for (int i = n; i >= 0; i--)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;
template <class T>
bool chmax(T &a, const T &b) {  //aよりbが大きければaに代入
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //aよりbが小さければaに代入
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

//
//
//

int main() {
    string s, a;
    cin >> a >> s >> a;

    cout << "A" << s.at(0) << "C" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,m;
int a[2020][2020],b[2020][2020],c[2020][2020],d[2020][2020];
int aa[2020],bb[2020],cc[2020],dd[2020];
string s[2020];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>m;
	fo(i,0,n)cin>>s[i];
	fo(i,0,2020)aa[i]=bb[i]=cc[i]=dd[i]=0;
	fo(i,0,n){
		int lst=-1;
		fo(j,0,m) if(s[i][j]=='#'){
			a[i][aa[i]++]=j-lst-1;
			lst=j;
			b[i][bb[i]++]=j;
		}
		a[i][aa[i]++]=m-lst-1;
	}
	fo(i,0,m){
		int lst=-1;
		fo(j,0,n) if(s[j][i]=='#'){
			c[i][cc[i]++]=j-lst-1;
			lst=j;
			d[i][dd[i]++]=j;
		}
		c[i][cc[i]++]=n-lst-1;
	}
	int ans=0;
	fo(i,0,n) fo(j,0,m) if(s[i][j]!='#')
	ans=max(ans,a[i][lb(b[i],b[i]+bb[i],j)-b[i]]+c[j][lb(d[j],d[j]+dd[j],i)-d[j]]-1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 67968