akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
def saiki(value,HP,num):
    if num==0:
        #print(HP//base)
        value+=wa[0][min(HP//base,len(wa[0])-1)]
        ans.append(value)
    else:
        for i in range(len(wa[num])):
            if HP-(num+base)*i>=0:
                saiki(value+wa[num][i],HP-(num+base)*i,num-1)
            else:
                break
    return


N,W=map(int,input().split())

lis=[[] for i in range(4)]

for i in range(N):
    w,v=map(int,input().split())
    if i==0:
        base=w
    lis[w-base].append(v)

lis=list(map(lambda x:sorted(x, reverse=True),lis))

wa=[[0] for i in range(4)]

for i in range(len(wa)):
    for item in lis[i]:
        wa[i].append(wa[i][-1]+item)

#print(wa)

ans=[]
saiki(0,W,3)
    

print(max(ans))
    

Measured memory_bytes: 3436
#include <stdio.h>

int main(void){
  int acade,gaten;
  scanf("%d %d",&acade,&gaten);
  int st,end,i,anst=1,anend=acade;
  for (i=0;i<gaten;i++){
  scanf("%d %d",&st,&end);
    if(anst<st){
    anst=st;
    }
    if(anend>end){
    anend=end;
    }
  }
  if(anend-anst+1 <0){
  printf("0\n");
  }else{
  printf("%d\n",anend-anst+1);
  }
return 0;
}

Measured memory_bytes: 128
n = int(input())
raw = input()
if raw[0] == 'B':
  imos = [1]
else:
  imos = [0]
for i in range(1,2*n):
  if raw[i-1] == raw[i]:
    imos.append(0)
  else:
    imos.append(1)
#print(imos)
ans = 1
mod = 10 ** 9 + 7
l = 0
att = 0
for i in range(2*n):
  if imos[i] ^ att == 0:
    if l == 0:
      print(0)
      break
    ans *= l
    ans %= mod
    l -= 1
    att = 1
  else:
    l += 1
    att = 0
  #print(ans,l,att)
else:
  if l != 0:
    print(0)
  else:
    for j in range(1,n+1):
      ans *= j
      ans %= mod
    print(ans)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

int main(){
  string a,b;
  cin >> a >> b;
  reverse(ALL(a));
  cout << (a==b ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int isprime[maxn], prime[maxn], cnt;
const int mod = 1e9 + 7;
void getPrime(int n) {
	isprime[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (!isprime[i]) {
			prime[++cnt] = i;
		}
		for (int j = 1; j <= cnt && i * prime[j] <= n; j++) {
			isprime[i * prime[j]] = 1;
			if (i % prime[j] == 0) {
				break;
			}
		}
	}
}

int getCount(int x, int n) {
	int ans = 0;
	while (n) {
		ans += n/x;
		n/=x;
	}
	return ans;
}



int main() {
	int n;
	cin >> n;
	getPrime(maxn);
	int ans = 1;
	for (int i = 1; prime[i] <= n; i++) {
		int x = getCount(prime[i], n);
		ans = (1LL * ans * (x + 1)) % mod;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 640
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define bs2int(bs) (int)((bs).to_ulong())
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

int n;
ll a[100010];
ll b[100010];

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n;
  REP(i,n) cin>>a[i];
  sort(a,a+n);
  REP(i,n) b[i]=a[i];
  FOR(i,1,n) a[i]+=a[i-1];
  int cnt = 1;
  for(int i=(int)n-2;i>=0;i--)
  {
    if (b[i+1]<=a[i]*2) cnt++;
    else break;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define maxn 200005
using namespace std;
struct Line {
    int m, k;
    Line(int a, int b) :
        m(a), k(b) {}
    int val(int x) {
        return m * x + k;
    }
};

int h[maxn], dp[maxn];
int n, c;

bool chk(Line a, Line b, Line c) {
    //return (c.k - a.k) / (a.m - c.m) <= (b.k - a.k) / (a.m - b.m);
    return (long double)(c.k - a.k) * (a.m - b.m) <= (long double)(b.k - a.k) * (a.m - c.m);
}

//dp[i] = max( (dp[j] + h[j]^2) + (h[i]^2 + c) - 2 * h[i] * h[j]);

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> c;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    deque<Line> dq;
    dq.emplace_back(-2 * h[0], h[0] * h[0]);
    for(int i = 1; i < n; i++) {
        while((int)dq.size() > 1 && dq[0].val(h[i]) >= dq[1].val(h[i])) {
            dq.pop_front();
        }
        dp[i] = dq.front().val(h[i]) + h[i] * h[i] + c;
        Line cur(-2 * h[i], dp[i] + h[i] * h[i]);
        while((int)dq.size() > 1 && chk(dq[(int)dq.size() - 2], dq.back(), cur)) {
            dq.pop_back();
        }
        dq.push_back(cur);
    }
    cout << dp[n - 1] << '\n';
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector <int> x(n);
    vector <int> y(n);
    long double ans=0;
for (int i=0;i<n;i++){
    cin >> x.at(i) >>y.at(i);
}
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
        long tempx= x.at(i)-x.at(j);
        long tempy= y.at(i)-y.at(j);
        ans += sqrt(tempx*tempx+tempy*tempy);
    }
}
cout << setprecision(30) << ans/n <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, M;
char buf[1024];
const char blah[][10] = {
  "Fizz____",
  "Buzz____",
  "FizzBuzz",
};

int main() {
  while (scanf("%d%d",&M,&N),N|M) {
    //fill(flag, flag + M, true);
    queue<int> q;
    rep(i,M) q.push(i+1);
    //int curNum = 1;
    rep(i,N) {
      scanf("%s",buf);
      if (q.size() == 1) continue;
      int cur = q.front(); q.pop();
      int n = strlen(buf);
      bool ok = true;
      int check = 0;
      check |= (i+1)%3 ? 0 : 1 ;
      check |= (i+1)%5 ? 0 : 2 ;
      if (check) {
        if (check == 1) {
          rep(j,4) if (blah[0][j] != buf[j]) ok = false;
          if (n != 4) ok = false;
        } else if (check == 2) {
          rep(j,4) if (blah[1][j] != buf[j]) ok = false;
          if (n != 4) ok = false;
        } else {
          rep(j,8) if (blah[2][j] != buf[j]) ok = false;
          if (n != 8) ok = false;
        }
      } else {
        if (i+1 != atoi(buf)) ok = false;
        rep(j,n) if (!isdigit(buf[j])) ok = false;
      }
      if (ok) q.push(cur);
      //else printf("%s:%d is out.\n",buf,cur);
    }
    vector<int> v;
    while (!q.empty()) { v.push_back(q.front()); q.pop(); }
    sort(v.begin(), v.end());
    rep(i,v.size()) {if(i)putchar(' ');printf("%d",v[i]);} puts("");
  }
  return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <ctime>
#include <map>
#include <deque>
#include <cmath>
#include <functional>
#include <queue>
#include <iomanip>
 
#define lp(i, s, e) for(int i = s; i < e; ++i)
#define lpi(i, s, e) for(int i = s; i<= e; ++i)
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;


const int mod = 998244353;

enum table{
	E,
	A, B, C,
	AB, AC, BC
} ;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt[7];
    cnt[0] = n;
    lp(i,1,7) {cnt[i] = 0;}
    ll ans = 1;
    string t;
    lp(i, 0, 3 * n) {
    	if (s[i] == 'R') {t.pb('A');}
    	if (s[i] == 'G') {t.pb('B');}
    	if (s[i] == 'B') {t.pb('C');}
    }
    s = t;
    lp(i, 0, 3 * n) {
    	if (s[i] == 'A') {
    		if (cnt[table::BC] > 0) {
    			ans *= cnt[table::BC];
    			ans %= mod;
    			--cnt[table::BC];
    			continue;
    		}
    		if (cnt[table::B] > 0) {
    			ans *= cnt[table::B];
    			ans %= mod;
    			--cnt[table::B];
    			++cnt[table::AB];
    			continue;
    		}
    		if (cnt[table::C] > 0) {
    			ans *= cnt[table::C];
    			ans %= mod;
    			--cnt[table::C];
    			++cnt[table::AC];
    			continue;
    		}
    		ans *= cnt[table::E];
    		ans %= mod;
    		--cnt[table::E];
    		++cnt[table::A];
    	}
    	if (s[i] == 'B') {
    		if (cnt[table::AC] > 0) {
    			ans *= cnt[table::AC];
    			ans %= mod;
    			--cnt[table::AC];
    			continue;
    		}
    		if (cnt[table::A] > 0) {
    			ans *= cnt[table::A];
    			ans %= mod;
    			--cnt[table::A];
    			++cnt[table::AB];
    			continue;
    		}
    		if (cnt[table::C] > 0) {
    			ans *= cnt[table::C];
    			ans %= mod;
    			--cnt[table::C];
    			++cnt[table::BC];
    			continue;
    		}
    		ans *= cnt[table::E];
    		ans %= mod;
    		--cnt[table::E];
    		++cnt[table::B];
    	}
    	if (s[i] == 'C') {
    		if (cnt[table::AB] > 0) {
    			ans *= cnt[table::AB];
    			ans %= mod;
    			--cnt[table::AB];
    			continue;
    		}
    		if (cnt[table::A] > 0) {
    			ans *= cnt[table::A];
    			ans %= mod;
    			--cnt[table::A];
    			++cnt[table::AC];
    			continue;
    		}
    		if (cnt[table::B] > 0) {
    			ans *= cnt[table::B];
    			ans %= mod;
    			--cnt[table::B];
    			++cnt[table::BC];
    			continue;
    		}
    		ans *= cnt[table::E];
    		ans %= mod;
    		--cnt[table::E];
    		++cnt[table::C];
    	}
    }
    cout << ans;
    return 0;
}


// 


Measured memory_bytes: 1300
#include <stdio.h>

#define N 100000

typedef struct{
  char type;
  int data;
}A;

int flag=0;

int prtition(A *,int,int);
void my_q_sort(A *,int,int);

int main(){
  int n,i,j,now;
  A ain[N],aout[N];
  //int check[1000000000]={0};
  //char check_c[1000000000][4]={0};

  scanf("%d\n",&n);

  for(i=0; i<n; i++){
    scanf("%c %d\n",&ain[i].type,&ain[i].data);
    aout[i]=ain[i];
    /*check_c[ain[i].data][check[ain[i].data]]=ain[i].type;
    check[ain[i].data]++;
    printf("DEBUG CALC");*/
  }
  /*for(i=0; i<n; i++){
    printf("%c %d\n",aout[i].type,aout[i].data);
    }*/
  my_q_sort(aout,0,n-1);
  now=aout[0].data;
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(ain[j].data==now){
	if(ain[i].type!=aout[i].type){
	  flag=1;
	  break;
	}
      }
    }
    now++;
    if(flag==1) break;
  }
  
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");

  for(i=0; i<n; i++){
    printf("%c %d\n",aout[i].type,aout[i].data);
  }
  
  return 0;
}

int partition(A *a,int p,int r){
  int x,i,j;
  A t;
  x=a[r].data;
  i=p-1;
  //printf("x=%d,i=%d,p=%d,r=%d\n",x,i,p,r);
  for(j=p; j<r; j++){
    if(a[j].data<=x){
      i++;
      //t=a[i].data;a[i].data=a[j].data;a[j].data=t;
      //T=a[i].type;a[i].type=a[j].type;a[j].type=T;
      t=a[i];a[i]=a[j];a[j]=t;
    }
  }
  //t=a[i+1].data;a[i+1].data=a[r].data;a[r].data=t;
  //T=a[i+1].type;a[i+1].type=a[r].type;a[r].type=T;
  t=a[i+1];a[i+1]=a[r];a[r]=t;
  return i+1;
}

void my_q_sort(A *a,int p,int r){
  int q;
  if(p<r){
    q=partition(a,p,r);
    my_q_sort(a,p,q-1);
    my_q_sort(a,q+1,r);
  }
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=n-2;i>=0;i--){
        if(h[i]>h[i+1]+1){
            cout<<"No"<<endl;
            return 0;
        }else if(h[i]==h[i+1]+1){
            h[i]--;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int n1=N%10;
  int n2=(N/10)%10;
  int n3=(N/100)%10;
  int n4=N/1000;
  if(n2==n3 && (n1==n2 || n3==n4)){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define COUT cout<<fixed<<setprecision(12)
#define fast ios:: sync_with_stdio(false),cin.tie(0);

void solve()
{
	string s,t;
	cin>>s>>t;
	ll ans=t.size();
	for(ll i=0;i<=(s.size()-t.size());i++)
	{
		ll cnt=0;
		ll x=i;
		for(ll j=0;j<t.size();j++)
		{
			if(s[x]!=t[j])
			cnt++;
			x++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans;
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<=(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  cin>>s;
  sort(all(s));
  string t="abcdefghijklmnopqrstuvwxyz";
  rep(i,26){
    bool ja=true;
    rep(j,s.length()){
      if(s[j]==t[i]){
        ja=false;
      }
    }
    if(ja){
      cout<<t[i]<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 3732
#include <stdio.h>

int main(void) {
	int a,b,c,r1=0,r2=0;
	while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
		if(c*c==a*a+b*b){r1++;}
		else if(a == b){r2++;}
	}
	printf("%d\n%d\n",r1,r2);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
bool is_(long long x){
    for(long long i = 2;i*i<=x;i++){
        if(x%i == 0)return false;
    }
    return true;
}
int main(void){
    long long a, b, ans = 0;
    set<long long> s;
    cin >> a >> b;
    for(long long i=1;;i++){
        if(a%i == 0 && b%i == 0){
            s.insert(i);
        }
        if(a%i == 0){
            long long j = a/i;
            if(b%j == 0)s.insert(j);
        }
        if(b%i == 0){
            long long j = b/i;
            if(a%j == 0)s.insert(j);
        }
        if(i*i >= a && i*i >= b)break;
    }
    for(auto x = s.begin(); x != s.end(); x++){
        if(is_(*x))ans++;
    }
    cout << ans << endl;
}


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

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int a=0,b=0,p=1;
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) break;
                continue;
            }
            a=p;
            b=c;
            p++;
            break;
        }
        if (a==0) {System.out.println("YES"); return;}
        
        while (true) {
            int c=ni();
            if (c==p) {
                p++; 
                if (p>n) { System.out.println("NO"); return; }
                continue;
            }
            if (c==a && p==b) {p++; break;}
            System.out.println("NO");
            return;
        }
        
        while (p<=n) {
            if (ni()==p) {p++; continue;}
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 1005

const int INF = 1e9 + 7;


int main(){


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

	ll h, w;
	cin >> w >> h;
	vector<pll> a;
	for (int i = 0; i < w; i++)
	{
		ll v;
		cin >> v;
		a.push_back(pii(v, 0));
	}

	for (ll i = 0; i < h; i++)
	{
		ll v;
		cin >> v;
		a.push_back(pii(v, 1LL));
	}
	sort(a.begin(), a.end());

	h++;
	w++;//始めは(h+1)行、(w+1)列引く必要がある

	ll ans = 0;

	for (ll i = 0; i < a.size(); i++)
	{
		if (a[i].second == 0LL)
		{
			//横線
			ans += a[i].first * h;
			w--;
		}
		else
		{
			//縦線
			ans += a[i].first * w;
			h--;
		}

	}
	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 6512
//mangesh2102000

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

int n,k;
int arr[105];
int dp[100005][2];

int solve1(int rem,int p)
{
	//cout << rem << " " << p << "\n";

	if(dp[rem][p]!=-1)
		return dp[rem][p];

	for(int i=1;i<=n;i++)
	{
		if(rem - arr[i] >= 0)
		{
			int tmp = solve1(rem-arr[i],(p+1)%2);
			if(tmp == p)
				return dp[rem][p] = p;
		}
	}

	return dp[rem][p] = (p+1)%2;
}

void solve(int t)
{
    cin >> n >> k;
    for(int i=1;i<=n;i++)
    {
        cin >> arr[i];
    }

    for(int i=0;i<100005;i++)
    {
    	dp[i][0] = dp[i][1] =  -1;
    }

    int ans = solve1(k,0);

   	if(ans == 0)
   		cout << "First";
   	else
   		cout << "Second";
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

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

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

int INF = 1e9;

struct LazySegmentTree {
private:
    int n;
    //lazyを追加
    vector<long long> node, lazy;

public:
    LazySegmentTree(vector<long long> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);

        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }

// k 番目のノードについて遅延評価を行う
void eval(int k, int l, int r) {

    // 遅延配列が空でない場合、自ノード及び子ノードへの
    // 値の伝播が起こる
    if (lazy[k] != 0) {
        node[k] += lazy[k];

        // 最下段かどうかのチェックをしよう
        // 子ノードは親ノードの 1/2 の範囲であるため、
        // 伝播させるときは半分にする（区間に一様に値を足すとすれば、半分に割るというのも納得がいく）
        if (r - l > 1) {
            lazy[2 * k + 1] += lazy[k] / 2;
            lazy[2 * k + 2] += lazy[k] / 2;
        }

        // 伝播が終わったので、自ノードの遅延配列を空にする
        lazy[k] = 0;
    }
}

void add(int a, int b, long long x, int k = 0, int l = 0, int r = - 1) {
    if(r < 0) r = n;

    // k 番目のノードに対して遅延評価を行う
    eval(k, l, r);

    // 範囲外なら何もしない
    if (b <= l || r <= a) return;
    
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
    if (a <= l && r <= b) {
        lazy[k] += (r - l) * x;
        eval(k, l, r);
    }

    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
    else {
        add(a, b, x, 2 * k + 1, l, (l + r) / 2);
        add(a, b, x, 2 * k + 2, (l + r) / 2, r);
        node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
}

long long getsum(int a, int b, int k = 0, int l = 0, int r = - 1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return 0;

    // 関数が呼び出されたら評価！
    eval(k, l, r);
    if(a <= l && r <= b) return node[k];
    long long vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    long long vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
}

};

int main(){
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> acc(n + 1, 0);
    for (int i = 0; i < n; i++) acc[i + 1] = (acc[i] + a[i]) % k;
    for (int i = 0; i <= n; i++) acc[i] = ((long long)n / k * k + k + acc[i] - i) % k;
    map<long long, int> mp;
    vector<long long> id = acc;
    sort(id.begin(), id.end());
    int now = 1;
    for (int i = 0; i < n + 1; i++){
        if (mp[id[i]] == 0) mp[id[i]] = now, now++;
    }
    for (int i = 0; i <= n; i++) acc[i] = mp[acc[i]];
    vector<long long> z(n + 1, 0);
    LazySegmentTree seg(z);
    long long ans = 0;
    for (int i = 1; i < min(n + 1, k); i++) {
        seg.add(acc[i], acc[i] + 1, 1);
    }
    bool flag = false;
    if (k < n) flag = true;
    for (int i = 0; i < n; i++){
        now = acc[i];
        ans += seg.getsum(now, now + 1);
        seg.add(acc[i + 1], acc[i + 1] + 1, - 1);
        if (flag){
            if (i + k > n) continue;
            seg.add(acc[i + k], acc[i + k] + 1, 1);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  vector<vector<int>> D(2, vector<int>(N, 0));
  D[0][0] = A[0][0];
  D[1][N - 1] = A[1][N - 1];
  for (int i = 1; i < N; i++) {
    D[0][i] = D[0][i - 1] + A[0][i];
    D[1][N - i - 1] = D[1][N - i] + A[1][N - i - 1];
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, D[0][i] + D[1][i]);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
long long solve(char *s, long long x) {
    if(*s == '\0')
        return x;
    long long ans = 0, y = 0;
    for(char *t = s; *t; t++) {
        y = y * 10 + *t - '0';
        ans += solve(t + 1, x + y);
    }
    return ans;
}
int main() {
    char s[11];
    scanf("%s", s);
    printf("%lld\n", solve(s, 0));
}



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


void solve()
{
	ll x,k,d;
	cin >> x >> k >> d;
	x=abs(x);
	if(x>0 && ((x/d)>=k))
		cout << (x-(k*d));
	else
	{
		ll y=x/d;
		x=x-(y*d);
		k=k-y;
		if(k%2==0)
			cout << abs(x);
		else
			cout << min(abs(x-d),abs(x+d));
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("ouput.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <climits>
#include <cmath>

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

  uint32_t N;
  uint32_t dp[1000001][3];
  

  std::cin >> N;

  uint32_t values[1000000][3];

  for (uint32_t i = 0; i < N; i++) {
    std::cin >> values[i][0] >> values[i][1] >> values[i][2];
  }

  for (uint32_t i = 0; i < N; i++) {
    for (uint32_t j = 0; j < 3; j++) {
      for (uint32_t k = 0; k < 3; k++) {
        if (j != k) {
          dp[i + 1][k] = std::max(dp[i][j] + values[i][k], dp[i + 1][k]);
        }
      }
    }
  }

  std::cout << std::max(std::max(dp[N][0], dp[N][1]),  dp[N][2]) << std::endl;
  return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(min(a+b,b+c),c+a) << endl;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

T binarySearch(alias pred, T)(T ok, T ng)
{ 
	while (abs(ok-ng) > 1)
	{
		auto mid = ok - (ok-ng) / 2;
		if (unaryFun!pred(mid))
			ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto N = RD;
	auto M = RD;
	auto V = RD;
	auto P = RD;
	auto A = RDA;
	A.sort();
	auto X = A[$-P];
	auto vv = V - P;
	long PP;
	foreach_reverse (i; 0..N)
	{
		if (A[i] < X) break;
		PP = N - i;
	}

	debug writeln(vv);
	debug writeln(A);
	if (vv <= 0)
	{
		long ans;
		foreach_reverse (i; 0..N)
		{
			if (A[i]+M >= X)
				++ans;
		}
		writeln(ans);
	}
	else
	{
		bool f(long p)
		{
			auto y = A[p]+M;
			if (y < X) return false;
			long z = vv * M;
			foreach (i; 0..N-(P-1))
			{
				if (i == p) continue;
				auto d = min(y - A[i], M);
				if (d <= 0) return false;
				z -= d;
				if (z <= 0) return true;
			}
			return false;
		}

		auto r = binarySearch!(f)(N, -1);
		writeln(max(N-r, PP));
	}

	stdout.flush;
	debug readln;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<bool> vecbool;
typedef vector<vector<int>> vec2int;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  vecll a(n, 0);
  for (auto &e : a) cin >> e;
  // reverse(all(a));
  vecll dp(n + 1, 0);
  map<ll, ll> mp1;
  REP(i, n) {
    dp[i + 1] = dp[i] + mp1[i - a[i]];
    mp1[i + a[i]]++;
  }
  ll ans = dp[n];
  cout << ans << endl;
  // reverse(all(a));
  // map<int, int> mp2;
  // vecint dp2(n + 1, 0);
  // REP(i, n) {
  //   dp2[i + 1] = dp2[i] + mp2[i - a[i]];
  //   mp2[i + a[i]]++;
  // }
  // ans += dp2[n];
  // cout << ans << endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(int i= (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    REP(i, 5) {
        int x; cin >> x;
        if(x == 0) {
            cout << i + 1 << "\n";
            break;
        }
    }
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n,l[1000],r[1000];
    int sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> l[i] >> r[i];
    }
    for(int i=0;i<n;i++){
        sum += (r[i]-l[i]+1);
    }
    cout << sum << endl;
    return 0;
}


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

long long my_lcm(long long a, long long b);

int main(){
    int n; cin >> n;
    vector <long long> t(n);

    long long ans = 1;
    for (int i = 0; i < n; i ++){
        long long _t; cin >> _t;
        ans = my_lcm(ans, _t);
        t.at(i) = _t;
    }

    cout << ans << endl;
}

long long my_lcm (long long a, long long b){
    return (a / gcd(a,b)) * b;
}

Measured memory_bytes: 3608
#include <stdio.h>

int digit(int nb)
{
	int sum = 0;
	while (nb > 0)
	{
		sum += nb % 10;
		nb /= 10;
	}
	return (sum);
}

int main(void)
{
	int N,a,b;
	scanf("%d%d%d",&N,&a,&b);
	int i = 1;
	int sum = 0;
	while (i <= N)
	{
		if (digit(i) >= a && digit(i) <= b)
			sum += i;
		i++;
	}
	printf("%d\n", sum);
	return 0;
}

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

int main(){

int a,b,c,d;
scanf("%d %d %d %d" ,&a,&b,&c,&d);
if((a*b)>=(c*d)){

printf("%d\n" ,a*b);}
else{

printf("%d\n" ,c*d);}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, ans = 0, las = 0;
  std::cin >> N;
  std::vector<ll> A(N);
  bool flag = true;
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    if(i!=0&&A[i]<A[i-1]) las = i;
    if(A[i]-(i==0?-1:A[i-1])>=2) flag = false;
  }
  for(int i=1;i<N;i++){
    if(A[i]==A[i-1]+1) ans++;
    else ans+=A[i];
  }
  std::cout << (flag?ans:-1) << '\n';
  return 0;
}


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

typedef long long ll;

ll gcd(ll p, ll q){
  if (p%q == 0) {
    return q;
  }
  else {
    return gcd(q, p%q);
  }
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x = b/c - (a - 1)/c;
  ll y = b/d - (a - 1)/d;
  ll w = (c/gcd(c, d))*d;
  ll z = b/w - (a - 1)/w;
  ll ans = (b - a + 1) - (x + y - z);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
ans = []
for k in range(n):
    for i in reversed(range(n - k)):
        a = b[i]
        if i + 1 == a:
            ans.append(b.pop(i))
            break
if b != []:
    print(-1)
else:
    for a in reversed(ans):
        print(a)

Measured memory_bytes: 3060
N, X = map(int, input().split())

a = [1]
p = [1]

for i in range(N):
  a.append(2*a[i] + 3)
  p.append(2*p[i] + 1)
  
def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  elif X == 2 + a[N-1]:
    return p[N-1]+1
  elif X <= 2 + 2*a[N-1]:
    return p[N-1]+1+f(N-1, X-2-a[N-1])
  else:
    return 2*p[N-1]+1
  
print(f(N, X))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string arr;
int d;
int mod=1e9+7;
long long getsum(int ind,int sum,int flag,vector<vector<vector<long long> > >&dp){
	if(ind==arr.size()) {
		if(sum%d==0) return 1;
		return 0;
	}
	if(dp[ind][sum][flag]!=-1) return dp[ind][sum][flag];
	int limit=9;
	if(!flag) limit=arr[ind]-'0';
	long long res=0;
	for(int i=0;i<=limit;i++){
		if(flag||i<limit){
			res+=getsum(ind+1,(sum+i)%d,1,dp);
		}
		else res+=getsum(ind+1,(sum+i)%d,0,dp);
	}
	dp[ind][sum][flag]=res%mod;
	return res%mod;
	
	
}
int main() {
	
		
		cin>>arr;
	    cin>>d;
	
		
		
		
			vector<vector<vector<long long> > >dp(arr.size()+1,vector<vector<long long> >(200,vector<long long>(2,-1)));
		long long u=getsum(0,0,0,dp);
		
		
		cout<<(u-1+mod)%mod<<endl;
		
		
	
	
	return 0;
}

Measured memory_bytes: 114144
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

ll numDivid(ll x){
    ll cnt = 0;
    while (x % 2 == 0){
        cnt ++;
        x/= 2;
    }
    return cnt;
}

void solve(long long N, std::vector<long long> a){
    ll ans = 0;
    rep(i, N){
        ans += numDivid(a[i]);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

using namespace std;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    bool ok = true;
    for(int i=0; i<N/2; i++){
        if(S[i] != S[i + N/2]) ok = false;
    }
    if(ok && N % 2 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main()
{
	int n;
	int a[200];
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int i;
	for (i = 0;; ++i)
	{
		bool ok = 1;
		for (int j = 0; j < n; ++j)
		{
			ok *= !(a[j] % 2);
		}
		if (ok)
		{
			for (int j = 0; j < n; ++j)
			{
				a[j] /= 2;
			}
			continue;
		}
		break;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::i64;
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    let n: i64 = iter.next().unwrap().parse().unwrap();
    let m: i64 = iter.next().unwrap().parse().unwrap();

    let mut dp: Vec<i64> = vec![i64::MAX; 1 << n];
    dp[0] = 0;
    for i in 0 .. m {
        let a: i64 = iter.next().unwrap().parse().unwrap();
        let b: i64 = iter.next().unwrap().parse().unwrap();

        let c: Vec<i64> = (0..b)
            .map(|_| {
                (
                    iter.next().unwrap().parse::<i64>().unwrap()
                )
            })
            .collect();

        let mask = c.iter().fold(0, |acc, i| {acc | (1 << (i - 1))});
        for idx in 0 .. (1 << n) {
            if dp[idx] < i64::MAX {
                dp[idx | mask] = cmp::min(dp[idx | mask], dp[idx] + a);
            }
        }
    }

    println!("{}", if dp[(1 << n) - 1] < i64::MAX {dp[(1 << n) - 1]} else {-1})
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  string x="ABC";
  int i=0;
  int idx=0;
  int count=0;
  while(i<n){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
        count++;
    }
    i++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1e9 + 7;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define dist(a,b) ( pow(a.X - b.X, 2) + pow( a.Y - b.Y, 2 ) )
typedef tuple <int, int, int> line;
typedef complex <double> point;
typedef vector <point> polygon;
string s, t;
int memo[3005][3005];
int ans = 0;
int solve(int i, int j)
{
    if ( i >= s.size() || j >= t.size() )
        return 0;
    if ( memo[i][j] != -1 )
        return memo[i][j];
    if ( s[i] == t[j] )
        ans = 1 + solve(i + 1, j + 1) ;
    else
        ans =max(solve(i + 1, j), solve(i, j + 1));
    memo[i][j] = ans;
    return ans;
}
void print(int i, int j)
{
    if ( i >= s.size() || j >= t.size() )
        return;
    if ( s[i] == t[j] )
    {
        cout << s[i];
        print(i + 1, j + 1);
    }
    else
    {
        int ans1 = solve(i + 1, j);
        int ans2 = solve(i, j + 1);
        if ( memo[i][j] == ans1 )
            print(i + 1, j);
        else
            print(i, j + 1);
    }
    return;
}
int main()
{
    Hello
    memset(memo, -1, sizeof memo);
    cin >> s >> t;
    solve(0, 0);
    print(0, 0);
    return 0;
}



Measured memory_bytes: 35968
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <iomanip>
// std::cout << std::setprecision(10) << 3.141;
using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

long double dp[110][100100];

int main(void){
    ll n, w;

    cin >> n >> w;

    ll wei[110];
    ll val[110];

    for(int i = 0; i < 110; i++){
        for(int j = 0; j < 100100; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

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

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 100100; j++){
            
            if(j - val[i] >= 0){
                dp[i + 1][j] = min((ll)dp[i + 1][j], (ll)dp[i][j - val[i]] + wei[i]);
            }

            dp[i + 1][j] = min((ll)dp[i + 1][j], (ll)dp[i][j]);

        }
    }

    ll ans = 0;
    for(int i = 0; i < 100100; i++){
        if(dp[n][i] <= w){
            ans = i;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 172288
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    c = C
    for j in range(M):
        c += A[j]*B[j]
    if c>0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 1000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define P pair<int,int> 
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int n;
    cin>>n;
    vector<int> p(n);
    REP(i,n){
        cin>>p[i];
    }
    vector<int> m(n);
    m[0]=p[0];
    for(int i=1;i<n;i++){
        m[i]=min(m[i-1],p[i]);
    }
    int ans=0;
    REP(i,n){
        if(m[i]>=p[i]) ans++;
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 1792
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, x;
    cin>>a>>b>>c>>x;
    int ans = 0;
    rep(i, a + 1)
    {
        rep(j, b + 1)
        {
            rep(k, c + 1)
            {
                if (i * 500 + j * 100 + 50 * k == x)
                    ans++;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

 
int main() {
	int n, m; cin >> n >> m;
	VVI a(101, VI(101));
	VI b(101);
	rep(i, n)rep(j, m)cin >> a[i][j];
	rep(i, m)cin >> b[i];

	VI c(101);
	rep(i, n) {
		rep(j, m)c[i] += a[i][j] * b[j];
		cout << c[i] << endl;
	}
}


Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <cmath>
int main() {
	std::cout << std::fixed << std::setprecision(20);
	double a, b, c, d;
	std::cin >> a >> b >> c >> d;
	std::cout << sqrtl(pow(c - a, 2) + pow(d - b, 2)) << std::endl;

	return 0;
}


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

int main(){
    int S, W;
    cin >> S >> W;

    if (S <= W){
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
int a[5][5],b[5][5];
int main()
{
    ft
    int t,i,j,n,m,l,r,f;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    cin>>n;
    while(n--)
    {
        cin>>l;
        for(i=0;i<3;i++)
        {
            f=0;
            for(j=0;j<3;j++)
            {
                if(a[i][j]==l)
                {
                    a[i][j]=-1;
                    f=1;
                    break;
                }
            }
            if(f==1)
            {
                break;
            }
        }
    }
    f=0;
    for(i=0;i<3;i++)
    {
        if(a[i][0]==a[i][1] && a[i][0]==a[i][2] && a[i][0]==-1)
        {
            f=1;
            break;
        }
    }
    for(i=0;i<3;i++)
    {
        if(a[0][i]==a[1][i] && a[0][i]==a[2][i] && a[0][i]==-1)
        {
            f=1;
            break;
        }
    }
    if(a[0][0]==a[1][1] && a[0][0]==a[2][2] && a[0][0]==-1)
    {
        f=1;
    }
    if(a[0][2]==a[1][1] && a[1][1]==a[2][0] && a[0][2]==-1)
    {
        f=1;
    }
    if(f==1)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int res = 0;
    for(int i = 0; i < 10; i++){
        if(pow(2, i) <= n){
            res = pow(2, i);
        }
        else{
            break;
        }
    }
    cout << res << endl;

    return 0;
}


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

const int INF = 1001001001;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int count=0;
    rep(i,k){
        if(a>=b){
            b*=2;
            count++;
        }
    }
    rep(i,k){
        if(b>=c){
            c*=2;
            count++;
        }
    }
    if(a<b&&b<c&&count<=k){
        cout<<"Yes";
    }else{cout<<"No";}

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define DEBUG if(1)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n;
lli k;
lli a[maxN], f[maxN];
lli af[maxN + 1];

bool can(lli x)
{
  lli cost = 0;
  for (int i = 0; i < n; i ++)
    if (a[i] * f[i] > x)
      cost += a[i] - x / f[i];
  return cost <= k;
}

lli binarySearch()
{
  lli lo = 0, hi = 1e12 + 5;
  while (lo < hi)
  {
    lli mid = (lo + hi) >> 1LL;
    if (can(mid)) hi = mid;
    else lo = mid + 1;
  }
  return lo;
}

int main()
{
  scanf("%d %lld", &n, &k);
  for (int i = 0; i < n; i ++)
    scanf("%lld", &a[i]);
  for (int i = 0; i < n; i ++)
    scanf("%lld", &f[i]);
  sort(a, a+n, greater<lli>()), sort(f, f+n);

  lli ans = binarySearch();
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 3328