akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

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 unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = TEN(9) + 7;

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

	int a[3] = {0, 0, 0};

	rep(i, S.size()) {
		a[S[i]-'a']++;
	}

	int mn = min({a[0], a[1], a[2]});

	rep(i, 3) a[i] -= mn;

	rep(i, 3) {
		if (a[i] >= 2) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
}



Measured memory_bytes: 512
import numpy as np

D = int(input())
c = np.array( list(map(int, input().split())) )
s = [[] for i in range(365+1)]
for i in range(D):
  s[i] = np.array( list(map(int, input().split())) )
#
last = np.array( [-1]*26 )
av = np.array( [0]*26 )
id = np.identity(4,dtype=int)

v = 0
for d in range(D):
  av = s[d] - sum( c*(d-last) ) + c*(d-last) 
  t =  int(input())
  t -= 1
  last[t] = d
  v += av[t]
  print( v )
#


Measured memory_bytes: 27336
n,a=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
y=[i-a for i in x]
m=sum(x)+1
dp=[[0 for j in range(m*2+1)] for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    for j in range(-m,1+m):
        if j-y[i-1]>=-m and j-y[i-1]<=1+m:
            dp[i][j]=dp[i-1][j]+dp[i-1][j-y[i-1]]
        else:
            dp[i][j]=dp[i-1][j]

print(dp[n][0]-1)


Measured memory_bytes: 5108
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int a[5],ans=0;
	for(int i=1; i<=3; i++)
		scanf("%d",&a[i]);
	sort(a+1,a+4);
	if((a[3]-a[2])%2) {
		ans+=a[3]-a[2];
		a[1]+=a[3]-a[2];
		a[2]=a[3];
	} else if((a[3]-a[2])%2==0) {
		ans+=(a[3]-a[2])/2;
		a[2]=a[3];
	}
	if((a[2]-a[1])%2==1) {
		a[3]++;
		a[2]++;
		a[1]+=2;
		ans+=2;
	}
	if((a[2]-a[1])%2==0) {
		ans+=(a[3]-a[1])/2;
		a[1]=a[3];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void no(){
    cout << -1 << endl;
    exit(0);
}
vector<int> ans[100005];
bool paint[100005] = {};
lli n;
lli par[100005] = {};
lli tree_size[100005] = {};
lli tmp[100005] = {};
lli dp[100005] = {};
lli very[100005] = {};
lli fi(int u,int p){
    for(auto s:ans[u]){
        if(s != p){
            dp[u] += fi(s, u) + tree_size[s];
        }
    }
    very[u] = dp[u];
    return dp[u];
}
void calc(int u,int p){
    if(u!=0){
        very[u] = very[p] + n - 2 * tree_size[u];
    }
    for(auto s:ans[u]){
        if(p!=s)
            calc(s, u);
    }
}
lli recalc_size(int u, int p){
    tree_size[u] = 1;
    for(auto s:ans[u]){
        if(s==p)continue;
        tree_size[u] += recalc_size(s,u);
    }
    //cout << u << " " << tree_size[u] << endl;
    return tree_size[u];
}
void check_and_emit(){
    rep(i,n){
        if(par[i]!=-1)
        {
            ans[i].push_back(par[i]);
            ans[par[i]].push_back(i);
        }
    }
    recalc_size(0,-1);
    fi(0,-1);
    calc(0,-1);
    rep(i,n){
        if(very[i] != tmp[i]){
            no();
        }
    }
    rep(i,n){
        for(auto s:ans[i]){
            if(s>i)
            cout << i+1 << " " << s+1 << endl;
        }
    }
}



int main() {
    cin >> n;
    vector<pair<lli,lli>> d(n);
    map<lli,lli> m;
    rep(i,n){
        cin >> d[i].first,d[i].second = i;
        tmp[i] = d[i].first;
        m[d[i].first] = i;
        par[i] = -1;
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    vector<bool> used(n);
    if(n==2){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n)tree_size[i] = 1;
    rep(i,n-1){
        int cur = d[i].second;
        // 現在のcurが属する部分木の大きさ
        lli next = d[i].first - n + 2 * tree_size[cur];
        //cout << next << endl;
        if(next >= d[i].first ){
            no();
        }else {
            if(m.find(next) == m.end()){
                no();
            }
            par[cur] = m[next];
            tree_size[m[next]] += tree_size[cur];
        }
    }
    check_and_emit();
}


Measured memory_bytes: 24832
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M, D = in_nn()
    comb = N ** 2
    if D == 0:
        count = N - D
    else:
        count = (N - D) * 2

    print(count * (M - 1) / comb)


if __name__ == '__main__':
    main()


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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll t = 0;
  rep(i, n) t += a[i];
  int ans = 0, ai = n;
  for (int bi = 0; bi <= m; bi++) {
    while (ai > 0 && t > k) {
      ai--;
      t -= a[ai];
    }
    if (t > k) break;
    ans = max(ans, ai + bi);
    if (bi == m) break;
    t += b[bi];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4804
/**
 *    author        : Saurav Paul 
 *    created       : August 29, 2020 6:02 PM
 *    Problem Name  : B - Substring
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc177/tasks/abc177_b
 *    @genarated by : ai-virtual-assistant
**/

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

using ll = long long int ;

class TC{

    public :
    void solve(){
        string s ,t ;
        cin >> s >> t ;
        int ss = s.size() , st = t.size() ;
        int mn = st ;

        for(int i = 0 ; i <= ss-st; i++){
            int cnt = 0;
            
            for(int j = i ; j < i + st ; j++){
                if(s[j] != t[j-i]) cnt ++ ;
                 
            }
            mn = min(cnt,mn) ;
            /* cout << i << " " << cnt <<" " <<mn << endl; */
        }
        /* cout <<s << " " << t <<" " << ss <<" " << st << endl ; */
        cout << mn << endl ;
    }
};

int main(){
    ios_base::sync_with_stdio(false);

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        TC tc;
        tc.solve() ;
    }

    return 0 ;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int par[100'010];
int find(int n){
    return par[n]?par[n]=find(par[n]):n;
}
bool merge(int a,int b){
    a=find(a);
    b=find(b);
    if(a^b){
        par[a]=b;
        return true;
    }return false;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        merge(a,b);
    }
    int ans=0;
    for(int i=1;i<n;i++){
        if(merge(i,i+1))ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    
    int s[n],b[n],c[n];
    
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>b[i]>>c[i];
    }
    int  dp[3][n];
    
    dp[0][0]=s[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[0][i]=s[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;;
    

    return 0;
}


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

vector<pair<ll,ll>> factorize(ll n){
	vector<pair<ll,ll>> res;
	for (ll i = 2; i*i <= n; ++i) {
		if(n % i)continue;
		res.emplace_back(i,0);
		while(n % i == 0){
			res.back().second++;
			n /= i;
		}
	}
	if(n > 1){
		res.emplace_back(n,1);
	}
	return res;
}

int main(){
	ll n;
	cin >> n;
	auto v = factorize(n);
	ll ans = 0;
	rep(i, v.size()){
		ll count = 0;
		while(1){
			if((count+1)*count/2 > v[i].second){
				count--;
				break;
			}
			count++;
		}
		ans += count;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  double a, b, x;cin>>a>>b>>x;
  double ans;
  if(x>=a*a*b/2){
    ans = atan(2*(a*a*b-x)/(a*a*a));
  }else{
    ans = atan((a*b*b)/(2*x));
  }
  cout<<fixed<<setprecision(10)<<ans*(180/acos(-1))<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

const int INF = 1e9 + 5;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  vector<int> dp(n, INF);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; i+j < n && j<=k; j++) {
      dp[i+j] = min(dp[i+j], dp[i]+abs(v[i+j]-v[i]));
    }

    // for (int j = i+1; j <= i+k; j++) {
    //   if (j < n)
    //     dp[j] = min(dp[j], dp[i]+abs(v[j]-v[i]));
    // }
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll l,r;
const ll md = 2019;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>l>>r;
    Vi v;
    if(r-l >= md*2)r = l + md*2;
    ll ans = md-1;
    repi(i,l,r+1){
        repi(j,i+1,r+1){
            chmin(ans,(i*j)%md);
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main() {
    char str[1201];
    
    fgets(str, sizeof(str), stdin);
    
    for (int i = 0; i < strlen(str); i++){
        if (str[i] >= 97 && str[i] <= 122)
            str[i] -= 32;
        else if (str[i] >= 65 && str[i] <= 92)
            str[i] += 32;
    }
    cout << str;
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){

    int n, l; cin >> n >> l;
    vector<int>a(n);

    rep(i,n) a[i] = l+i;

    if(l<=0){
        if(n+l-1<=0){
            a[n-1]=0;
        } else {
        }
    } else {
        a[0]=0;
    }

    int ans=0;

    rep(i,n) ans += a[i];

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N,R;cin>>N>>R;
  cout<<R+max(100*(10-N),0)<<endl;
  
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    H,W,A,B = mis()
    for i in range(H):
        if i < B:
            print('0'*A + '1'*(W-A))
        else:
            print('1'*A + '0'*(W-A))

main()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N, P;
int64 mpow(int64 a, int64 b, int64 P) {
  if (b == 0) return 1;
  if (b % 2) return a * mpow(a, b-1, P)%P;
  int64 ret = mpow(a, b/2, P);
  return ret*ret%P;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int64 P1 = 3, P2 = 673;
  cin >> s;
  int64 now1 = 0, now2 = 0, res = 0;
  map<pair<int64, int64>, int64> cnt;
  cnt[{0, 0}]++;
  int64 div = 1;
  int64 d101 = mpow(10%P1, P1-2, P1);
  int64 d102 = mpow(10%P2, P2-2, P2);
  REP(i, s.size()) {
    now1 = now1 * 10 + s[i]-'0';
    now2 = now2 * 10 + s[i]-'0';

    now1 %= P1; now2 %= P2;
    res += cnt[{now1*mpow(d101, i, P1)%P1, now2*mpow(d102, i, P2)%P2}];
    cnt[{now1*mpow(d101, i, P1)%P1, now2*mpow(d102, i, P2)%P2}]++;
  }
  cout << res << endl;
}


Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
	int rab[100000],n,z;
	int pair=0;
	
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>rab[i];
	}
	
	for(int i=1;i<=n;i++){
		
			z=rab[i];
			if(z==rab[i]&&i==rab[z])pair=pair+1;
		
	}
		cout<<pair/2<<endl;
	
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
    
   
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c)cout << "Yes" << endl;
    else if (a == c && a != b)cout << "Yes" << endl;
    else if (c == b && a != c)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

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


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

	cout<<min(a+b,min(b+c,c+a))<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 17;
int e[N][N];
int n;
int book[N];
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
inline int count(int x){
	int res = 0;
	while(x){
		if(x & 1) res++;
		x >>= 1;
	}
	return res;
}
int main(){
	memset(e,-1,sizeof(e));
	n = read();
	for(int i = 1;i <= n;++i){
		int num = read();	
		while(num--){
			int x = read(),y = read();
			e[i][x] = y;
		}
	}
	int ans = 0;
	for(int i = 0;i < (1 << n);++i){
		memset(book,-1,sizeof(book));bool flag = 1;
		for(int j = 0;j < n;++j) 
		if(i & (1 << j)) book[j + 1] = 1;
		else book[j + 1] = 0;
		for(int j = 0;j < n;++j){
			if(i & (1 << j)){
				for(int k = 1;k <= n;++k){
					if(e[j + 1][k] == -1) continue;
					if(book[k] != e[j + 1][k]) {flag = 0;continue;}
				}
			}
		}
		for(int j = 0;j < n;++j){
			if(i & (1 << j)) continue;bool ok = 0;
			for(int k = 1;k <= n;++k){
				if(e[j + 1][k] == -1) continue;
				if(e[j + 1][k] != book[k]) ok = 1;
			}
			flag &= ok;
		}
		if(flag) ans = max(ans,count(i));
	}
	cout << ans;
	return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,n){cin>>a[i];a[i]--;}
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    ll ans = 0;
    rep(i,n){
        ans+=b[a[i]];
        if(i>0&&a[i]-a[i-1]==1)ans+=c[a[i-1]];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def maxHeapfy(a, h, i):
    l = 2 * i
    r = 2 * i + 1

    if l <= h and a[l] > a[i]:
        largest = l
    else:
        largest = i
    if r <= h and a[r] > a[largest]:
        largest = r

    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        maxHeapfy(a, h, largest)


n, m = [int(v) for v in input().split()]
a = [-1]
a.extend([int(v) for v in input().split()])

for i in range(n//2, 0, -1):
    maxHeapfy(a, n, i)

for i in range(m):
    a[1] //= 2
    maxHeapfy(a, n, 1)

print(sum(a[1:]))


Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll k;
    cin >> k;
    vi a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    print(a[k - 1]);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const ll kInf = 1LL << 62;
ll n, s, sol = kInf;

inline void Check(ll base) {
  ll sum = 0;
  for (ll x = n; x; x /= base)
    sum += x % base;
  if (sum == s)
    sol = min(sol, base);
}

ll Solve() {
  if (n < s)
    return -1;
  if (n == s)
    return n + 1;
  ll diff = n - s;
  for (ll i = 1; i * i <= diff; ++i) {
    if (diff % i)
      continue;
    Check(i + 1);
    Check(diff / i + 1);
  }
  return sol == kInf ? -1 : sol;
}

int main() {
  scanf("%lld%lld", &n, &s);
  return printf("%lld\n", Solve()), 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll A, B, K;
    cin >> A >> B >> K;

    Rep (i, K) {
        if (A % 2 == 1) {
            A--;
        }

        A /= 2;
        B += A;            
        swap(A, B);
    }

    if (K % 2 == 1) swap(A, B);

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int A,B,Q; cin >> A >> B >> Q;
  vl s(A),t(B),x(Q);
  rep(i,A) cin >> s[i];
  rep(i,B) cin >> t[i];
  rep(i,Q) cin >> x[i];

  
  rep(q,Q) {
    int a = lower_bound(all(s),x[q]) - s.begin();
    int b = lower_bound(all(t),x[q]) - t.begin();
    ll ans = INF;
    if(a < A && b < B){
      chmin(ans, abs(x[q] - s[a]) + abs(s[a] - t[b]));
      chmin(ans, abs(x[q] - t[b]) + abs(t[b] - s[a]));
    }
    if(a < A && b-1 >= 0){
      chmin(ans, abs(x[q] - s[a]) + abs(s[a] - t[b-1]));
      chmin(ans, abs(x[q] - t[b-1]) + abs(t[b-1] - s[a]));
    }
    if(a-1 >= 0 && b < B){
      chmin(ans, abs(x[q] - s[a-1]) + abs(s[a-1] - t[b]));
      chmin(ans, abs(x[q] - t[b]) + abs(t[b] - s[a-1]));
    }
    if(a-1 >= 0 && b-1 >= 0){
      chmin(ans, abs(x[q] - s[a-1]) + abs(s[a-1] - t[b-1]));
      chmin(ans, abs(x[q] - t[b-1]) + abs(t[b-1] - s[a-1]));
    }
    cout << ans << endl;
  }
}


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

class Program
{
    static void Main(string[] args)
    {
        var N = Int64.Parse(Console.ReadLine());
        var H = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var beforeNum = 0L;
        var ans = "Yes";
        foreach (var h in H)
        {
            if(h < beforeNum)
            {
                ans = "No";
                break;
            }
            var n = beforeNum <= h - 1 ? h - 1 : h;
            beforeNum = n;
        }
        Console.WriteLine(ans);
    }

}


Measured memory_bytes: 31452
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i = a;i < n;i++)
#define INF 1e9
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll n,k;
	cin >> n >> k;
	
	ll a[n];
	rep(i,0,n) cin >> a[i];
	
	sort(a,a+n);
	
	ll ans = INF;
	rep(i,0,n-k+1){
		ans = min(ans,abs(a[i+k-1]-a[i]));
	}
	
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  float sum = a + b;
  int x1 = sum / 2;
  float x2 = sum / 2;
  if ((x1 + .4) < x2) cout << x1 + 1;
  else cout << x1;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int k = in.nextInt();
        long[] a= new long[n];
        for (int i = 0; i < n;i++) {
            a[i] = in.nextLong();
        }
        Arrays.sort(a);
        long r =0 ;
        for (int i = 0; i < k; i++) {
            r += a[i];

        }
        out.println(r);
    }

    final int mod = 998244353;

    int mul(int x, int y) {
        return (int) ((x * 1L * y) % mod);
    }

    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 33288
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
int main()
{
	long int n;
	cin>>n;
	long int arr[n+1];
	arr[0]=-1;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	unordered_set<long int> h;
	long int count=0;
	int i=1;
	h.insert(i);
	while(1)
	{
		i=arr[i];
		count++;
		if(i==2)
		{
			cout<<count<<endl;
			return 0;
		}
		
		if(h.find(i)!=h.end())
		{
			cout<<"-1\n";
			return 0;
		}
		else
		{
			h.insert(i);
		}

	}
	return 0;
}

Measured memory_bytes: 5156
#include<iostream>
#include<string>
#include<vector>
using namespace std; 
int main(){
	for(int i=0;i<3;i++){
		int a,b,c,d,e,f;
		cin>>a>>b>>c>>d>>e>>f;
		int end=d*3600+e*60+f;
		int start=a*3600+b*60+c;
		int time=end-start;
		cout<<time/3600<<" "<<time%3600/60<<" "<<time%3600%60<<endl;
	}
	

	return 0;
}

Measured memory_bytes: 1160
from collections import defaultdict
n, k = map(int, input().split())
s = defaultdict(int)
for j in range(n):
    i, v = map(int, input().split())
    s[i] += v
f = sorted(s.items())
tmp = 0
for g in f:
    tmp += g[1]
    if tmp >= k:
        print(g[0])
        exit()


Measured memory_bytes: 14940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   int x,y,z;scanf("%d%d%d",&x,&y,&z);
   printf("%d",(x-z)/(y+z));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=unsigned long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void zalgo(vector<ll>& s,vector<int>& z){
    int c=0,n=s.size();
    z.resize(n,0);
    for(int i=1;i<n;++i){
        int l=i-c;
        if(i+z[l]<c+z[c]) z[i]=z[l];
        else{
            int j=max(0,c+z[c]-i);
            for(;i+j<n&&s[j]==s[i+j];++j);
            z[i]=j;c=i;
        }
    }
    z[0]=n;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<ll> a(n),b(n),A(n),B(n),c(3*n+1);
    for(auto&i:a) in>>i;
    for(auto&i:b) in>>i;
    fr(i,n) A[i]=a[i]^a[(i+1)%n];
    fr(i,n) B[i]=b[i]^b[(i+1)%n];
    vector<int> d;
    int s=n;
    fr(i,n) c[i]=B[i];
    c[n]=-1;
    fr(i,n){
        c[n+1+i]=A[i];
        c[2*n+1+i]=A[i];
    }
    vector<int> z;
    zalgo(c,z);
    Fr(i,n){
        if(n%i==0){
            bool F=true;
            fr(j,i){
                bool f=true;
                ll C=A[j];
                fr(k,n/i) if(A[j+k*i]!=C) f=false;
                if(f) continue;
                F=false;
                break;
            }
            if(F){
                s=i;
                break;
            }
        }
    }
    bool f=false;
    for(int i=n+1;i<=3*n;++i){
        if(z[i]==n){
            i-=n+1;
            while(i<n){
                cout<<i<<" "<<(a[i]^b[0])<<endl;
                i+=s;
            }
            return 0;
        }
    }
}

Measured memory_bytes: 16768
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,x=MI()
size=[0 for i in range(a+1)]
size[0]=1
for i in range(a):
    size[i+1]=size[i]*2+3
#print(size)
#print(size[1])
patty=[0 for i in range(a+1)]
patty[0]=1
for i in range(a):
    patty[i+1]=2*patty[i]+1

def porb(k,n):
    if k==1 and n==0:
        return 1
    elif k==1:
        return 0
    elif k==size[n]:
        return patty[n]
    elif k>(size[n]+1)//2:
        return patty[n-1]+1+porb(k-(size[n]+1)//2,n-1)
    elif k==(size[n]+1)//2:
        return patty[n-1]+1
    else:
        return porb(k-1,n-1)

print(porb(x,a))

Measured memory_bytes: 3316
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  s <- getLine
  let (p, m) = ('+' `count` s, '-' `count` s)
   in print $ p - m


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  bool dp[30010][5][1010] = {};
  for (int i = 0; i < 30000; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 1000; k++) {
        dp[i][j][k] = false;
      }
    }
  }
  
  dp[0][0][0] = true;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k < 1000; k++) {
        if (dp[i][j][k]) {
          if (j <= 2) {
          dp[i+1][j+1][10 * k + S[i] - '0'] = true;
            
          }
          dp[i+1][j][k] = true;
        }
      }
    }
  }
  
  
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    if (dp[N][3][i])  ans++;
  }
  
  cout << ans << endl;
  
  
  
  
}

Measured memory_bytes: 151672
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;

int main()
{
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++)
	{
		string ss; cin >> ss;
		s += ss;
	}
	for (int j = 0;; j++)
	{
		stringstream ss; ss << j;
		string x = ss.str();

		if (s.find(x) == string::npos)
		{
			cout << j << endl;
			break;
		}
	}
}

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

int main(){
    long N;
    cin >> N;
    long A[N + 1];
    for(long i = 0; i < N + 1; i++)
        cin >> A[i];
    long B[N + 1];
    B[N] = A[N];
    for(long i = N - 1; i >= 0; i--){
        B[i] = B[i + 1] + A[i];
    }
    long ans = 0, a = 1;
    bool sw = true;
    for(long i = 0; i < N; i++){
        if(a < A[i]){
            sw = false;
            break;
        }
        ans += a;
        a = min(2 * (a - A[i]), B[i + 1]);
    }
    if(a != A[N]) sw = false;
    ans += A[N];
    if(sw) cout << ans << endl;
    else cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 5184
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int count(int y, int m, int d);

int main()
{
    int n, year, month, date;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> year >> month >> date;
        cout << count(year, month, date) << endl;
    }
   return 0;
}

int count(int y, int m, int d)
{
    int ans = 0;
    for(int i = y + 1; i < 1000; i++){
        if(i % 3 == 0) ans += 10 * 20;
        else ans += 5 * 20 + 5 * 19;
    }
    for(int i = m + 1; i <= 10; i++){
        if(y % 3 == 0) ans += 20;
        else {
            if(i % 2 == 1) ans += 20;
            else ans += 19;
            }
    }
    if(m % 2 == 0 && y % 3 != 0) ans += 19;
    else ans += 20;
    ans -= d - 1;
    return ans;
}

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

int main()
{
    string a, b, c;
    stack<int> A, B, C;
    int cond=1;
    cin >> a >> b >> c;
    for(int i = 0; i < a.size(); i++)
        A.push(a[a.size()-i-1]);
    for(int i = 0; i < b.size(); i++)
        B.push(b[b.size()-i-1]);
    for(int i = 0; i < c.size(); i++)
        C.push(c[c.size()-i-1]);
    while(true)
    {
       if(cond==1){
           if(A.empty()){
               cout << 'A';
               return 0;
           }
           if(A.top()=='b')cond=2;
           else if(A.top()=='c')cond=3;
           A.pop();
       }
       else if(cond==2){
           if(B.empty()){
               cout << 'B';
               return 0;
           }
           if(B.top()=='a')cond=1;
           else if(B.top()=='c')cond=3;
           B.pop();
       }
       else{
           if(C.empty()){
               cout << 'C';
               return 0;
           }
           if(C.top()=='a')cond=1;
           else if(C.top()=='b')cond=2;
           C.pop();
       }
    }
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

string tmp = "";
vector<string> ans;

void pri(string s,int ma, int poi, int ch)
{
	string tmpp = s;

	if (poi == ma)
	{
		ans.push_back(tmpp);
	}
	else
	for (int i = 0; i <= ch+1; i++)
	{
		tmpp[poi] = (char)('a' + i);
		ll mt = max(ch, i);
		pri(tmpp, ma, poi + 1, mt);
	}

	
}

int main(void)

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

	ll n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		tmp.push_back('a');
	}

	pri(tmp,n, 1, 0);
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 7796
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())

n = len(S)

ans = n
for i in range(1,n):
    if S[i]!=S[i-1]:
        temp = max(i,n-i)
        if temp<ans:
            ans = temp

print(ans)

Measured memory_bytes: 39792
#include <stdio.h>
 
int main()
{
  int W,H,x,y,r;
  int  ans=1;
 
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r<0)ans=0;
  if(r+x>W)ans=0;
  if(y-r<0)ans=0;
  if(y+r>H)ans=0;
 
  if(ans)printf("Yes\n");
  else printf("No\n");
 
  return 0;
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a!=c)
    cout<<1;
    else
    cout<<0;   
}

Measured memory_bytes: 256
from itertools import product
from collections import deque
INF = 1e7
def main():
    H, W = map(int, input().split())
    ch, cw = map(lambda x: int(x)+1, input().split())
    dh, dw = map(lambda x: int(x)+1, input().split())
    S = [["#"]*(W+4) for _ in range(H+4)]
    # whites = [] #　道であるindex
    for i in range(2, H+2):
        tmp = input()
        for j in range(2, W+2):
            S[i][j] = tmp[j-2]
            # if S[i][j] == ".":
                # whites.append((i,j))

    dxdy = [(1,0), (-1,0), (0,1), (0,-1)]
    magic = list(product(range(-2, 3), repeat=2))
    magic.remove((0, 0))
    for to_remove in dxdy:
        magic.remove(to_remove)
    
    # graph = {idx: deque() for idx in whites}
    # for idx in whites:
    #     x = idx[0]
    #     y = idx[1]
    #     for dx, dy in dxdy:
    #         if S[x+dx][y+dy] == ".":
    #             graph[idx].append((x+dx, y+dy))
    # graph2 = {idx: deque() for idx in whites}
    # for idx in whites:
    #     x = idx[0]
    #     y = idx[1]
    #     for mx, my in magic:
    #         if S[x+mx][y+my] == ".":
    #             graph2[idx].append((x+mx, y+my))
    
    def bfs(u,v):
        dist = [[INF] * (W+4) for _ in range(H+4)] #indexed from 1
        # seen = [[0] * (W+4) for _ in range(H+4)] #indexed from 1
        queue = deque()
        # seen[u][v] = 1
        dist[u][v] = 0
        queue.append((u,v))
        while queue:
            p, q = queue.popleft()
            # if not graph[(p,q)]:
            #     queue.popleft()
            #     continue
            # g,h = graph[(p,q)].popleft()
            # if seen[g][h]:
            #     continue
            # seen[g][h] = 1
            # dist[g][h] = min(dist[g][h], dist[p][q])
            for dx, dy in dxdy:
                g = p+dx
                h = q+dy
                if S[g][h]=="." and dist[g][h] > dist[p][q]:
                    dist[g][h] = dist[p][q]
                    queue.appendleft((g,h))
            for dx, dy in magic:
                g = p+dx
                h = q+dy
                if S[g][h]=="." and dist[g][h] > dist[p][q]+1:
                    dist[g][h] = dist[p][q]+1
                    queue.append((g,h))
            # dist[g][h] = min(dist[g][h], dist[p][q]+1)
            # queue.append((g,h))
        return dist

    D = bfs(ch, cw)
    ans = D[dh][dw]
    if ans == INF:
        print(-1)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 136584
N,M = map(int, input().split())
S = sorted([[int(i) for i in input().split()] for i in range(N)])

num = 0
price = 0
for s in S:
	if s[1] + num < M:
		price += s[0] * s[1]
		num += s[1]
	else:
		price += s[0] * (M - num)
		break
    
print(price)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  // cout<<50*50<<endl;
  
  ll a,b; cin>>a>>b;
  ll x=a;
  rep(i,100) rep(j,100) G[i][j]='.';
  a--;
  
  if(a) for(int i=1; ;i+=2){
    rep(j,100) G[i][j]='#';
    a--;
    if(a==0) break;
    bool flg=0;
    for(int j=1; j<99; j+=2) {
      G[i-1][j]='#';
      a--;
      if(a==0) {
        flg=1;
        break;
      }
    }
    if(flg) break;
  }
  
  if(x>1) b--;
  if(b) for(int i=30; ;i+=2){
    bool flg=0;
    for(int j=0; j<100; j+=2){
      G[i][j]='#';
      b--;
      if(b==0){
        flg=1;
        break;
      }
    }
    if(flg) break;
  }
  
  cout<<100<<' '<<100<<endl;
  rep(i,100){
    rep(j,100){
      cout<<G[i][j];
    }
    cout<<endl;
  }
  
}

Measured memory_bytes: 3704