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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

#define MAXN 100005

int n;
vi adjList[MAXN];

ll PD[MAXN][2];

ll pd(int i, int cb, int p){
	ll &ans = PD[i][cb];
	if(ans!=-1){
		return ans;
	}
	ans = 1;
	for(int v: adjList[i]){
		if(v==p) continue;
		ans *= pd(v, 1, i);
		ans = ans%MOD;
	}
	if(cb){
		ll bAns = 1;
		for(int v: adjList[i]){
			if(v==p) continue;
			bAns *= pd(v, 0, i);
			bAns = bAns%MOD;
		}
		ans += bAns;
		ans = ans%MOD;
	}
	return ans;
}

int main(){
	scanf("%d", &n);
	FOR(i, 0, n-1){
		int x, y;
		scanf("%d%d", &x, &y);
		x--;y--;
		adjList[x].pb(y);
		adjList[y].pb(x);
	}
	memset(PD, -1, sizeof PD);
	printf("%lld\n", pd(0, 1, -1));
	return 0;
}

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

using namespace std;
typedef long long ll;
const int N = 200010;
int _w;

int n;
char s[N];
ll ans;

int main() {
	_w = scanf( "%s", s+1 );
	n = (int)strlen(s+1);
	int bc = 0;
	for( int i = n-1; i >= 1; ) {
		if( s[i] == 'B' && s[i+1] == 'C' ) {
			++bc;
			int j = i-1;
			while( j >= 1 && s[j] == 'A' ) {
				ans += bc;
				--j;
			}
			i = j-1;
		} else {
			bc = 0;
			--i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3948
#include <iostream>
#define MAXN 1000001;
using namespace std;
int m,e,sum1,sum2,x,y,z,minn;
int main(){
	while(1){
		cin >>e;
		if(e==0)break;
		x=y=z=0;
		minn=MAXN;
		while(1){
			sum1=z*z*z;
			if(e<sum1)break;
			y=0;
			while(1){
				sum2=sum1+y*y;
				if(e<sum2)break;
				if(y+z+(e-sum2)<minn)minn=y+z+(e-sum2);
				y++;
			}
			z++;
		}
		cout <<minn<<endl;
	}
}

Measured memory_bytes: 2980
#include<iostream>
#include<set>
#include <cstdio>
#include<vector>
#include<algorithm>

#define ll long long
using namespace std;
	long long n ;
int main(){
    cin>>n;
    vector<ll> a(n),b(n);
    ll res=0;
    for(int i=0; i<n; i++) scanf("%lld %lld", &a[i], &b[i]);
    for(int i=n-1; i>=0; i--){
	ll d = (a[i]+res)%b[i];
	if(d){
	    res+=b[i]-d;
	}
    }
    cout<<res<<"\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s,a;
int p,l,c;
    
string bnf(){
  string r;
  c=0;
  while(p!=l){
    char t=s[p];
    if(t=='+')p++,c++;
    if(t=='-')p++,c--;
    if('A'<=t&&t<='Z')
      r+=((s[p++]+c+M*N)-'A')%M+'A',c=0;
    if(t=='?')r+=s[p++],c=0;
    if(t=='[')p++,r+=bnf();
    if(t==']'){
      p++;
      reverse(r.begin(),r.end());
      break;
    }
  }  
  return r;
}
    
int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    l=s.size();
    p=0;
    a=bnf();
    for(int i=0;i<a.size();i++)
      if(a[i]=='?')a[i]='A';
    cout<<a<<endl;
  }
  return 0;
}

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

int main() {
  int n;cin>>n;
  vector<pair<int,int>> pr(n);
  rep(i,n){
    int a,b;cin>>a>>b;
    pr[i]=make_pair(a,b);
  }
  sort(all(pr));
  reverse(all(pr));
  ll ans=pr[n-1].first+pr[0].second;
  rep(i,n-1){
    ans+=pr[i].first-pr[i+1].first;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4032
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define vpii vector<pair<int,int>> 
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>> 
#define pii pair<int,int> 
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>

ld pie=3.141592653589793238462643383279;
int mod=1e9+7;

vvi mat_mul(vvi mat1,vvi mat2){
  vvi ret;
  f(i,0,2){
    vi xx;
    f(j,0,2){
      int r=0;
      f(k,0,2) r=(r+(mat1[i][k]*mat2[k][j])%mod)%mod;
      xx.pb(r%mod);
    }
    ret.pb(xx);\
  }
  return ret;
}

vvi mat_exp(vvi mat,int p){
  vvi iden={{1,0},{0,1}};
  while(p!=0){
    if(p&1) iden=mat_mul(iden,mat);
    p/=2; 
    mat=mat_mul(mat,mat);
  }
  return iden;
}


int32_t main(){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int a,b,c; cin>>a>>b>>c;
  int k; cin>>k;
  int m=0;
  while(b<=a){
    b*=2;
    ++m;
  }
  while(c<=b){
    c*=2;
    ++m;
  }
  if(m<=k) cout<<"Yes\n";
  else cout<<"No\n";
  return 0; 
}

Measured memory_bytes: 3664
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    string a;
    while(cin>>a>>k)
    {
        if(a.sz==1) cout<<a.at(0)<<en;
        else
        {
                bool f=1;
            for(i=0;i<1000&&i<k;i++)
            {
                if(a.at(i)=='1') continue;
                else
                {
                    f=0;
                    cout<<a.at(i)<<en;
                    break;
                }
            }
            if(f) cout<<1<<en;
        }
    }
}



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

bool isSorted(vector<int> a) {
    for (int i = 0; i < a.size() - 1; i++) {
        if (a[i] > a[i+1]) return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N; cin >> N;
    vector<int> a;
    for (int i = 0; i < N; i++) {
        int ai; cin >> ai;
        a.push_back(ai);
    }
    if (isSorted(a)) {
        cout << "YES\n";
        return 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            swap(a[i],a[j]);
            if (isSorted(a)) {
                cout << "YES\n";
                return 0;
            }
            swap(a[i],a[j]);
        }
    }
    cout << "NO\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  int n; cin >>n;
  int ans=0;
  for(int i=0;i<n;i++){
    int l,r;
    cin >> l >> r;
    ans+=r-l+1;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <time.h>
using namespace std;
int main()
{
	int sum[1000];
	int i, n, j, k;
	scanf("%d", &n);
	int su[1000];
	su[1] = 2;
	int count = 1;
	int vis;
	for(i = 3 ; i <= 3000 ; i++)
	{
		vis = 1;
		for(j = 2 ; j < i ; j++)
		{
			if(i % j == 0)
			{
				vis = 0;
			}
		}
		if(vis == 1)
		{
			count++;
			su[count] = i;
		}
	}
	int xixi = 0;
	for(i = 1 ; i <= 400 ; i++)
	{
		if(su[i] % 5 == 1)
		{
			xixi++;
			if(xixi == n)
			{
				printf("%d\n", su[i]);
			}
			else
			{
				printf("%d ", su[i]);
			}
		}
		if(xixi == n) break;
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

int main() {
	string s;
	cin >> s;
	rep(i, 0, s.size()) {
		if (s[i] == ',')cout << " ";
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    ll n; cin >> n;
    vs s(n);
    map<string,int> mp;
    rep(i,n){
        cin >> s[i];
        mp[s[i]]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 6372
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    char a[20];
    cin>>a;
    a[3]='8';
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 768
s = list(input())
if s[0] == 'A' and s[2:-1].count('C') == 1 and s.count('C') == 1:
     s.remove('A')
     s.remove('C')
     if str(s).islower() == True:
          print('AC')
     else:
          print('WA')
else:
     print('WA')

Measured memory_bytes: 3060
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, k;
    cin >> n >> k;

    if(k == 1){
        cout << 0 << endl;
    } else {
        cout << n - k << endl;
    }
}

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

#define LLINF (1LL<<60)
typedef long long ll;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int N,X;
    cin >>N>>X;

    vector<int> L(N);
    rep(i,N) cin >> L[i];
    
    //-----------------------------------
    int sum=0,cnt=1;
    rep(i,N){
        sum+=L[i];
        if(sum<=X)cnt++;
            else break;
    }
    cout << cnt <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  rep(i, 0, a) cin >> p[i];
  rep(i, 0, b) cin >> q[i];
  rep(i, 0, c) cin >> r[i];
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());

  rep(i, 0, x) r.push_back(p[i]);
  rep(i, 0, y) r.push_back(q[i]);

  sort(r.rbegin(), r.rend());
  ll ans = 0;
  rep(i, 0, x + y) ans += r[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7876
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int n,w;
   cin>>n>>w;
   int wt[n],val[n];
   for(int i=0;i<n;i++)
    cin>>wt[i]>>val[i];
    int v=0;
    for(int i=0;i<n;i++)
        v+=val[i];
   int dp[n+1][v+1];
   for(int i=0;i<=n;i++)
   {
       for(int j=0;j<=v;j++)
       {
           dp[i][j]=1e13;
       }
   }

 dp[0][0]=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=0;j<=v;j++)
       {

          if(j==0)
                {dp[i][j]=0;continue;}
          if(j<val[i-1])
            dp[i][j]=dp[i-1][j];
          else
            dp[i][j]=min(dp[i-1][j],wt[i-1]+dp[i-1][j-val[i-1]]);
       }
   }
 /*  for(int i=0;i<=n;i++)
   {
       for(int j=0;j<=v;j++)
       {
           cout<<dp[i][j]<<" ";
       }
       cout<<endl;
   }*/
  // cout<<dp[3][90]<<endl;
   int max1=0;
       for(int j=0;j<=v;j++)
       {
           if(dp[n][j]<=w)
           max1=j;
       }
   cout<<max1<<endl;
    return 0;
}


Measured memory_bytes: 79232
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>



using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

string s;

int main(){
    long long int ans=0;
    cin >> s;
    int n = s.size();
    long long int a;
    rep(i,(1<<(n-1))){
        a = 0;
        rep(j,n){
            a = a*10 + s[j] - '0';
            //cout << a << endl;
            if(j == n-1) break;
            else if((i>>j) & 1){
                ans += a; 
                a = 0;
            }
        }
        ans += a;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    char *p, s[20], tmp[20];
    int i;
    scanf("%s", s);

    while (strchr(s, ',')!=NULL) {
        p = strchr(s,',');
        strcpy(tmp,p+1);
        strcpy(p," ");
        strcat(s,tmp);
    }

    printf("%s\n", s);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;

    vector<uint64_t> h(n);

    vector<bool> ok(n, true);

    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

     for (int i = 0; i < m; i++)
    {
        int a,b;
        cin >> a >> b;

        a--; b--;

        if(h[a] <= h[b]){
            ok[a] = false;
        }
        if(h[a] >= h[b]){
            ok[b] = false;
        }
    }

    int ans = 0;
    for(int i=0; i < n; i++){
        if(ok[i]){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4012
s = input()
n = len(s)
k = int(input())
dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for a in range(n):
    for b in range(k + 1):
        for c in range(2):
            nd = int(s[a])
            for d in range(10):
                na, nb, nc = a + 1, b, c
                if d != 0:
                    nb += 1
                if nb > k:
                    break
                if nc == 0:
                    if d < nd:
                        nc = 1
                    if d > nd:
                        break
                dp[na][nb][nc] += dp[a][b][c]
print(sum(dp[-1][-1]))


Measured memory_bytes: 3064
#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 mt make_tuple
#define pqueue priority_queue
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 N, K;
int parent[100005];
int depth[100005];
bool ok[100005];
vector<vector<int> > edge(100005);

void getdepth(ll u, ll dist) {
  depth[u] = dist;
  for(ll i=0;i<edge[u].size();++i) {
    getdepth(edge[u][i], dist+1);
  }
  return;
}

int main() {
  cin>>N>>K;
  ll tmp;
  ll ans = 0;
  for(ll i=0;i<N;++i) {
    cin>>tmp;
    tmp--;
    if(i==0 && tmp!=0) ans++;
    if(i!=0) {
      parent[i] = tmp;
      edge[tmp].push_back(i);
    }
  }
  getdepth(0, 0);
  vector<pair<ll, ll> > arr(N);
  for(ll i=0;i<N;++i) arr[i] = mp(depth[i], i);
  sort(arr.begin(), arr.end(), greater<pair<ll, ll> >());
  ll cut;
  ll now;
  bool can;
  for(ll i=0;i<N;++i) {
    if(ok[arr[i].se]) continue;
    if(arr[i].fi<=K) continue;
    now = arr[i].se;
    can = false;
    for(ll j=0;j<K;++j) {
      if(ok[now]) {
        can = true;
        break;
      }
      ok[now] = true;
      now = parent[now];
    }
    if(!can) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 15780
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[200010];
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
void Y(){
  cout<<"Yes"<<endl;
  exit(0);
}
int main(){
  int a[9],b[9];
  for (int i = 0; i < 9; i++)  cin >> a[i];
  int n,x; cin>>n;
  for(int i = 0; i < n; i++){
    cin>>x;
    for (int i = 0; i < 9; i++){
      if(x==a[i]) b[i]=1;
    }
  }
  if(b[0]*b[1]*b[2]==1) Y();
  if(b[3]*b[4]*b[5]==1) Y();
  if(b[6]*b[7]*b[8]==1) Y();
  if(b[0]*b[3]*b[6]==1) Y();
  if(b[1]*b[4]*b[7]==1) Y();
  if(b[2]*b[5]*b[8]==1) Y();
  if(b[0]*b[4]*b[8]==1) Y();
  if(b[2]*b[4]*b[6]==1) Y();
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
struct m {
	int x, y, x1, y1;
};
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int> > grid(H, vector<int>(W));
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		cin >> grid[i][j];
	}
	bool oflag = false;
	int fx, fy;
	vector<m> ans;
	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; j++) {
				if (oflag) {
					ans.push_back({ fx + 1, fy + 1,j + 1,i + 1 });
				}
				if (grid[i][j] % 2 == 1) {
					if (oflag) {
						oflag = false;
					}
					else {
						oflag = true;
					}
				}
				fx = j; fy = i;
			}
		}
		else {
			for (int j = W-1; j >= 0; j--) {
				if (oflag) {
					ans.push_back({ fx + 1, fy + 1,j + 1,i + 1 });
				}
				if (grid[i][j] % 2 == 1) {
					if (oflag) {
						oflag = false;
					}
					else {
						oflag = true;
					}
				}
				fx = j; fy = i;
			}
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].y << " " << ans[i].x << " " << ans[i].y1 << " " << ans[i].x1 << endl;
	}
	return 0;
}

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

int main() {
  string str;
  cin >> str;
  int n;
  cin >> n;
  while(n) {
    string str1;
    cin >> str1;
    if (str1 == "replace") {
      int a, b;
      cin >> a >>b;
      string str2;
      cin >> str2;
      int j=0;
      for (int i=a; i<=b; i++) {
        str[i] = str2[j];
        j++;
      }
    } else if (str1 == "reverse") {
      int a, b;
      cin >> a >>b;
      int j = b;
      for (int i=a; i<=(a+b)/2; i++) {
        int tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
        j--;
      }
    } else if (str1 == "print") {
      int a, b;
      cin >> a >>b;
      for (int i=a; i<=b; i++) {
        cout << str[i];
      }
      cout << endl;
    }
    n--;
  }
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    int N,M;
    cin >> N >> M;
    vec<ll> A(N),B(N);
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
    vec<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int i,int j){return A[i]<A[j];});
    ll ans = 0;
    for(auto i:idx){
        if(B[i]<M){
            ans += A[i]*B[i];
            M -= B[i];
        }else{
            ans += A[i]*M;
            M = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2176
#line 1 "test/GRL_1_A.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp"
#line 1 "macro/macros.hpp"



/*
@title Macro
@category template
*/
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";


#line 1 "graph/shortest_path/dijkstra.cpp"


#line 4 "graph/shortest_path/dijkstra.cpp"
/*
@title Dijkstra法(Simple Class)
@category グラフ/最短経路問題
*/
template<class T> class Dijkstra {
public:
    int N;
    T inf;
    vector<T> cost;
    vector<vector<pair<T, int>>> edge;
 
    Dijkstra(const int _N, T _inf = INFLL) : N(_N), inf(_inf),cost(N), edge(N) {
    }
 
    void make_edge(int from, int to, T w) {
        edge[from].push_back({ w,to });
    }
 
    void solve(int start) {
        for(int i = 0; i < N; ++i) cost[i] = inf;
 
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        cost[start] = 0;
        pq.push({ 0,start });
 
        while (!pq.empty()) {
            T v = pq.top().first;
            int from = pq.top().second;
            pq.pop();
            for (auto u : edge[from]) {
                T w = v + u.first;
                int to = u.second;
                if (w < cost[to]) {
                    cost[to] = w;
                    pq.push({ w,to });
                }
            }
        }
        return;
    }
};

#line 4 "test/GRL_1_A.test.cpp"

int main() {
    const long long INFLL = (long long)1e18+1;
    int V, E, r;
    cin >> V >> E >> r;

    Dijkstra<long long> G(V, INFLL);

    for(int _ = 0; _ < E; _++){
        int s, t;
        long long d;
        cin >> s >> t >> d;
        G.make_edge(s, t, d);
    }

    G.solve(r);

    for(int i = 0; i < V; i++){
        if(G.cost[i] == INFLL)cout << "INF" << endl;
        else cout << G.cost[i] << endl;
    }
}



Measured memory_bytes: 19412
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}

int main(){
    char S[101], T[101];
    scanf("%s %s", S, T);
    int len = strlen(S);
    int judge = 0;
    for(int i=0; i<len; i++){
        for(int j=0; j<len; j++){
            if(S[j]!=T[(j+i)%len]) break;
            if(j==len-1) judge++;
        }
        if(judge) break;
    }
    printjudge(judge);
    return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <iomanip>
#include <vector>
#define REP(i, start, n) for (int i = start; i < n; ++i)
#define debug(var)                  \
    do {                            \
        std::cout << #var << " : "; \
        view(var);                  \
    } while (0)
#define debug2d(var)                  \
    do {                              \
        std::cout << #var << " : \n"; \
        view(var);                    \
    } while (0)
template <typename T>
void view(T e) {
    std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T> >& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

using namespace std;
using ll = long long;

typedef pair<int, int> P;

double dist(P p1, P p2) {
    return sqrt((p1.first - p2.first) * (p1.first - p2.first) +
                (p1.second - p2.second) * (p1.second - p2.second));
}

int facctorial(int k) {
    int sum = 1;
    for (int i = 1; i <= k; ++i) {
        sum *= i;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    vector<P> coords(n);
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        coords[i] = make_pair(x, y);
    }

    double sumDist = 0;
    do {
        for (int j = 1; j < n; ++j) {
            sumDist += dist(coords[v[j - 1]], coords[v[j]]);
        }
    } while (next_permutation(v.begin(), v.end()));
    
    cout << fixed << setprecision(10) << sumDist / (double)facctorial(n) << endl;

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int func(int m,int* n){
	int k=0;
	while(m>=*n){
		*n=*n*2;
		k++;
		
		
	}
	return k;
}

int main(){
  int a,b,c,n;
  cin>>a>>b>>c>>n;
  int k1=func(a,&b);
  int k2=func(b,&c);
  if(k1+k2<=n)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 3632
using System;


namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {

            int H = 1;
            int W = 1;
            for (int a = 0; a < 5;)
            {
                string[] str = Console.ReadLine().Split(' ');
                H = int.Parse(str[0]);
                W = int.Parse(str[1]);
                if (H == 0 && W == 0)
                {
                    break;
                }
                else
                {
                    for (int I = 0; I < H; I++)
                    {
                        int i = 0;
                        int y = I % 2;
                        int x = i % 2;
                        if (y == 0)
                        {
                            for (i = 0; i < W; i++)
                            {
                                x = i % 2;
                                if (x == 0)
                                {
                                    Console.Write("#");
                                }
                                else if (x == 1)
                                {
                                    Console.Write(".");
                                }
                            }
                        }
                        else if (y == 1)
                        {
                            for (i = 0; i < W; i++)
                            {
                                x = i % 2;
                                if (x == 0)
                                {
                                    Console.Write(".");
                                }
                                else if (x == 1)
                                {
                                    Console.Write("#");
                                }
                            }
                        }
                        Console.WriteLine("");
                    }
                     Console.WriteLine("");
                }
            }


        }
    }
}

Measured memory_bytes: 8736
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n==1){
			System.out.println("Hello World");
		}
		else{
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}
	}
}

Measured memory_bytes: 23124
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }

    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int D, N;
    cin >> D >> N;
    int bekijo = pow(100, D);
    if (N != 100) {
        cout << bekijo * N << endl;
    }
    else {
        cout << bekijo * 101 << endl;
    }
}


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

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b[0] && b.back() == c[0]) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
using namespace std;

int main() {
	int N;//文字数
	string S;//文字列
	int K;//場所
	char s;

	cin >> N;
	cin >> S;
	cin >> K;

	s = S[K - 1];//変える文字

	for (int i = 0; i < N; i++) {
		if (S[i] != s) {
			S[i] = '*';
		}
	}

	cout << S << endl;


}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}

int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int cnt=1;
	deque<pair<int,int>>zero;
	int znt=0;
	rep(i,n-1){
		if(s[i]==s[i+1]){
			cnt++;
		}else{
			if(s[i]=='0'&&zero.size()==0){
				znt++;
				zero.push_back(make_pair(i+1,0));
			}
			if(s[i]=='1'){
				znt++;
				zero.push_back(make_pair(i+1,i+1-cnt));
			}
			cnt=1;
		}
		//cout<<i<<" "<<cnt<<endl;
	}
	if(s[n-1]=='1'){
		zero.push_back(make_pair(n,n-cnt));
	}else{
		znt++;
		zero.push_back(make_pair(n,n-cnt));
	}
	int ans=0;
	int m=min(znt,min(k,(int)zero.size()-1));

	rep(j,zero.size()){
		//cout<<zero[j].F<<" "<<zero[j].S<<endl;
		if(j+m<zero.size()){
		ans=max(ans,zero[j+m].F-zero[j].S);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 768
class Main {
	public static void main(String[] a) {

		// ?????°???
		int arg1[] = {1,2,3,4,5,6,7,8,9};
		// ?????°???
		int arg2[] = {1,2,3,4,5,6,7,8,9};

		for(int i =0; i<9; ++i){
			for(int j = 0; j<9; ++j){

				System.out.println(arg1[i] + "x" + arg2[j] + "=" + arg1[i]*arg2[j] );
			}
		}
	}
}

Measured memory_bytes: 23872
#include <bits/stdc++.h>
#define Tree int h,int l,int r,int L,int R
#define left 2*h,l,(l+r)/2,L,R
#define right 2*h+1,(l+r)/2+1,r,L,R
#define F first
#define S second
#define Pb push_back
using namespace std;
long long n,ANS;
double t,a,h[2000],Z=9999999999;
main ()
{
	cin>>n;
	cin>>t>>a;
	
	for (int i=1; i<=n; i++)
	{
		cin>>h[i];
		h[i]=t-0.006*h[i];
		
		if (abs(a-h[i])<=Z)
		{
			Z=abs(a-h[i]);
			ANS=i;
		}
	}
	
	cout<<ANS<<endl;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

S = [ord(s)-97 for s in S]
T = [ord(t)-97 for t in T]

N = len(S)

dp = [[-1 for j in range(26)] for i in range(N)]

for i,s in enumerate(S):
    if dp[N-1][s] == -1:
        dp[N-1][s] = i

for i in range(N-2,-1,-1):
    for j in range(26):
        dp[i][j] = dp[i+1][j]
    dp[i][S[i+1]] = i+1

M = len(T)
ans = dp[N-1][T[0]] + 1
now = dp[N-1][T[0]]
if now == -1:
    print(-1)
    exit()
for i in range(1,M):
    t = T[i]
    if dp[now][t] == -1:
        print(-1)
        exit()
    if now < dp[now][t]:
        ans += dp[now][t] - now
    else:
        ans += N + dp[now][t] - now
    now = dp[now][t]

print(ans)



Measured memory_bytes: 92580
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    long long int n,k;
    long long int mod = 1e9+7;
    cin >> n >> k;
    
    long long int mn = 0,mx = 0,sum = 0;
    for(int i = 0;i < n+1;i++){
        mn += i;
        mx += n-i;
        if(i+1 >= k)sum += (mx-mn+1),sum %= mod;
    }
    cout << sum % mod << endl;
}

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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        int n;
        cin >> n;
        if(n>=30){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3616
s = str(input())
n = len(s)

X = ['']
temp = ''
for i in range(n):
    temp += s[i]
    if temp == X[-1]:
        continue
    else:
        X.append(temp)
        temp = ''
else:
    if temp != '':
        if temp == X[-1]:
            X[-1] += temp
        else:
            X.append(temp)

#print(X)
print(len(X)-1)


Measured memory_bytes: 81848
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
int solve(){
  ll x;cin>>x;
  ll val=(x/500)*(1000);
  x=x%500;
  val+=(x/5)*(5);
  cout<<val<<endl;
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    cat();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pll> A;
  for (ll i = 0; i < N; i++) {
    ll a;
    cin >> a;
    A.push_back({a, 1});
  }
  for (ll i = 0; i < M; i++) {
    ll b, c;
    cin >> b >> c;
    A.push_back({c, b});
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  ll total = 0;
  ll cnt = 0;
  for (auto& x : A) {
    ll addcnt = min(x.second, N - cnt);
    total += x.first * addcnt;
    cnt += addcnt;
    if (cnt >= N) break;
  }

  cout << total << endl;
  return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
//#define IORD
#define eps 1e-8
#define inf 0x3f3f3f3f
//#define mod (1000000007)

using namespace std;
typedef long long LL;
typedef pair<int,int> pp;

set<string> se;

int main()
{
    #ifdef IORD
    freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif // IORD
    int n=0,fg=1;
    string s;
    char c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(fg)
        {
        int len=s.size();
        if(i==0)
        {
            se.insert(s);
            c=s[len-1];
        }
        else
        {
            if(s[0]!=c)
            {
                fg=0;
                //break;
            }
            else if(se.find(s)!=se.end())
            {
                fg=0;
                //break;
            }
            else
            {
                se.insert(s);
                c=s[len-1];
            }
        }
        }
    }
    if(fg) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    string as[] = {"Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"};
    int d;
    cin >> d;
    d -= 22;
    cout << as[d] << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<deque> 
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define inf 9999999999
#define mod 1000000007
using namespace std;
ll n,m;
ll fun(ll a)
{
	ll ans = 1;
	while(a)
	{
		ans = ans * a % mod;
		a--;
	}
	return ans;
}
int main()
{
	while(cin >> n >> m)
	{
		ll ans = 1;
		if(n == m)
		{
			ll k = fun(n);
			ans = k * k * 2 % mod;
		}
		else if(abs(n - m) <= 1)
		{
			ll k = fun(n);
			ll p = fun(m);
			ans = k * p % mod;
		}
		else 
			ans = 0;
		cout << ans << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const float EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

double path[100][100];
double mincost[100];
bool used[100];

class Data{
public:
	double x;
	double y;
	double z;
	double r;
	Data(double _x,double _y,double _z,double _r){
		x = _x;
		y = _y;
		z = _z;
		r = _r;
	}
};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<Data> nodes;

		fill((bool*)used,(bool*)used + 100,false);
		fill((double*)mincost,(double*)mincost + 100,numeric_limits<double>::max());

		for(int i=0;i<n;i++){
			double x,y,z,r;
			scanf("%lf %lf %lf %lf",&x,&y,&z,&r);
			nodes.push_back(Data(x,y,z,r));
		}

		
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				double diff = sqrt((nodes[i].x-nodes[j].x) * (nodes[i].x-nodes[j].x)
					+ (nodes[i].y-nodes[j].y) * (nodes[i].y-nodes[j].y)
					+ (nodes[i].z-nodes[j].z) * (nodes[i].z-nodes[j].z));
				double cost = (diff - (nodes[i].r + nodes[j].r) >= 0 ? diff - (nodes[i].r + nodes[j].r) : 0);
				path[i][j] = path[j][i] = cost;
			}
		}


		mincost[0]=0;

		double res=0;
		while(1){
			int v=-1;
			for(int u=0;u<n;u++){
				if(!used[u] && (v==-1 || mincost[u] < mincost[v])){
					v = u;
				}
			}

			if(v==-1) break;
			used[v] = true;		
			res+=mincost[v];
			
			for(int u=0;u<n;u++){
				mincost[u] = min(mincost[u],path[v][u]);
			}
			
		}

		printf("%.3lf\n",res);
	}
}

Measured memory_bytes: 0
#include<stdio.h>
int max(int a,int b){
	return a>b?a:b;
}
int ABS(int a){
	return 0<a?a:-a;
}
int main(void){
	int n,i,j,k;
	int H,flag;
	int x[100],y[100],h[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
	}
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			for(k=0;h[k]==0;k++);
			H=h[k]+ABS(x[k]-i)+ABS(y[k]-j);
			for(k=0,flag=1;k<n;k++){
				if(h[k]!=max(H-ABS(x[k]-i)-ABS(y[k]-j),0)){
					flag=0;
					break;
				}
			}
			if(flag==1){
				printf("%d %d %d",i,j,H);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >>n;
    int zentai=1,cnt=0;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] % 2 ==  0)cnt++;
    }
    cnt = pow(2,cnt);
    
    rep(i,n) zentai *= 3;
    cout << zentai - cnt << endl;
    
}

Measured memory_bytes: 256