akhauriyash/Code-Regression huggingface dataset:
H,W,K = map(int,input().split())
S = [list(map(int,input())) for _ in range(H)]
ans = float("inf")
for i in range(2**(H-1)):
    kari = 0
    l = [0]*H
    if H > 1:
        for j in range(0,H-1):
            if i >> j & 1:
                l[j+1] = l[j]+1
                kari += 1
            else:
                l[j+1] = l[j]
    num = [0]*H

    for w in range(W):
        tmp = [0]*H
        for h in range(H):
            if S[h][w]:
                tmp[l[h]] += 1

        if max(tmp) > K:
            break

        if max([num[i]+tmp[i] for i in range(H)]) <= K:
            num = [num[i]+tmp[i] for i in range(H)]
            
            #num += tmp
        else:
            num = tmp
            kari += 1
    else:

        ans = min(ans,kari)
print(ans)


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353
ll N,M;
ll Fa[5050505];
ll i,j,k,ans;
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}
int main(){
    scanf("%lld%lld", &N,&M);
    Fa[0] = 1;
    fornum(i,0,N+M*3){
        Fa[i + 1] = (Fa[i] * (i + 1)) % MOD;
    }

    for (i = M%2; i<=N&&i <= M;i+=2)
    {
        ll b = 3 * M - i;
        ans = (ans + moddiv(Fa[N], Fa[i] * Fa[N - i]) * (moddiv(Fa[b / 2 + N - 1], Fa[N - 1] * Fa[b / 2]))) % MOD;
        ll c = M - i;
        if(i==N){
            ans = (ans - moddiv(Fa[c / 2 + N - 1], Fa[N - 1] * Fa[c / 2]) * N % MOD+MOD) % MOD;
        }else{
            ans = (ans 
                -(moddiv(Fa[N], Fa[N - i] * Fa[i]) * moddiv(Fa[c / 2 + N - 1], Fa[N - 1] * Fa[c / 2]) % MOD * N % MOD)
                +(moddiv(Fa[N - 1], Fa[N - 1 - i] * Fa[i]) * moddiv(Fa[c / 2 + N - 2], Fa[N - 2] * Fa[c / 2]) % MOD* N % MOD)+MOD)%MOD;
        }
        //printf("%lld\n", ans);
    }
    printf("%lld",ans);

    return 0;
}

Measured memory_bytes: 20736
using System;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ');
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);

        var ans = 0;
        for (int i = a; i <= b; i++)
        {
            var x1 = i % 10;
            var x2 = i / 10 % 10;
            var x4 = i / 1000 % 10;
            var x5 = i / 10000;

            if (x1 == x5 && x2 == x4) ans++;
        }

        Console.WriteLine(ans);
    }
}


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

int main() {
	int N,A[2][101],ans=0;
	cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++)cin>>A[i][j];
	}
	for (int i = 0; i < N; i++) {
		int x=0;
		for (int j = 0; j < N; j++) {
			if (j <= i)x += A[0][j];
			if (j >= i)x += A[1][j];
		}
		ans = max(ans, x);
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
N=int(input())
s=str(N)
l=len(s)
ans=0
stack=[[] for i in range(l)] 
stack[0]=["3","5","7"]
for i in range(l-1):
  for a in stack[i]:
    if "5" in list(a+"3") and "7" in list(a+"3") and int(a+"3")<=N:
      ans+=1
    if "3" in list(a+"5") and "7" in list(a+"5") and int(a+"5")<=N:
      ans+=1
    if "3" in list(a+"7") and "5" in list(a+"7") and int(a+"7")<=N:
      ans+=1
    stack[i+1].append(a+"3")
    stack[i+1].append(a+"5")
    stack[i+1].append(a+"7")
print(ans)  
  
  
  

Measured memory_bytes: 5192
import sys
def input(): return sys.stdin.readline().rstrip()
import bisect
def main():
    s=input()
    t=input()
    s_abc=[]
    for i in range(26):
        s_abc.append([j for j,ss in enumerate(s) if ord(ss)==ord('a')+i])
    cur=-1
    loop=0
    for tt in t:
        tt_num=ord(tt)-ord('a')
        if s_abc[tt_num]==[]:
            print(-1)
            sys.exit()
        next_idx=bisect.bisect(s_abc[tt_num],cur)
        if next_idx==len(s_abc[tt_num]) or s_abc[tt_num][next_idx]<=cur:
            loop+=1
            cur=s_abc[tt_num][0]
        else:
            cur=s_abc[tt_num][next_idx]
    print(len(s)*loop+cur+1)


if __name__=='__main__':
    main()

Measured memory_bytes: 47724
#include<bits/stdc++.h>
    using namespace std;
    #include<bits/stdc++.h>
    using namespace std;
     
    int main(){
      string s,t;
      vector<string> v;
      cin>>s>>t;
      if(t.size()>s.size()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
      }
     
      for(int i=0;i<=s.size()-t.size();i++){
        string u=s;
        for(int a=0;a<u.size();a++){
          if(u[a]=='?')u[a]='a';
        }
        for(int j=0;j<t.size();j++){
          u[i+j]=t[j];
        }
        v.push_back(u);
      }
      sort(v.begin(),v.end());
     
      for(int i=0;i<v.size();i++){
        bool jdg=true;
        for(int j=0;j<v[i].size();j++){
          if(s[j]!='?'&& s[j]!=v[i][j]){
            jdg=false;
          }
        }
        if(jdg){
          cout<<v[i]<<endl;
          return 0;
        }
      }
      cout<<"UNRESTORABLE"<<endl;
      return 0;
    }

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
x=[0];s=[0]
for a in A:x.append(x[-1]^a);s.append(s[-1]+a)
l=1;r=1;ans=0
while l<=n:
  while r<=n and x[r]^x[l-1]==s[r]-s[l-1]:r+=1;ans+=1
  l+=1;ans+=r-l
print(ans)

Measured memory_bytes: 31208
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
#define rep(i,n) for (int i=0; i< (n); ++i)                                                           
typedef pair<int, int> P;                                                                             
                                                                                                      
                                                                                                      
int main() {                                                                                          
  int n;                                                                                              
  cin >> n;                                                                                           
  vector<int> h(n);                                                                                   
  rep(i,n) {                                                                                          
    cin >> h[i];                                                                                      
  }                                                                                                   
  int x = 0;                                                                                          
  int ans = 0;                                                                                        
  rep(i,n) {                                                                                          
    chmin(x, h[i]);                                                                                   
    ans += h[i] - x;                                                                                  
    x = h[i];                                                                                         
  }                                                                                                   
  cout << ans << endl;                                                                                
  return 0;                                                                                           
}         

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std; 
    
    
    
    int main() {
    int n;	
    cin >> n;
    int count = 0;
    for(int i = 1; i <= n; i+=2){
    	int four = 0;
    	int prior = 0;
    	for(int j = 1; j <= i; j+=2){
    		if(i % j == 0)	four++;	
    	}
    	
    	if(four == 8) count++;
    }
    cout << count << endl; 
     return 0;
    }
    

Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var n = int.Parse(Console.ReadLine());
            var input = test.ConvertIntArray(test.ReadInput());
            var count = 0;
            var num = 1;
            for (var i = 0; i < n; i++)
            {
                if (input[i] == num)
                {
                    num++;
                }
                else
                {
                    count++;
                }
            }

            if (count == n)
            {
                count = -1;
            }
            Console.WriteLine(count);
        }




        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public long[] ConvertLongArray(string[] x)
        {
            var convertedArray = new long[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = long.Parse(x[i]);
            }

            return convertedArray;
        }
    }
}


Measured memory_bytes: 29404
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll ans = 0;
  ll N;
  cin >> N;
  vector<char> num = {'3', '5', '7'};
  queue<string> q;
  q.push("3");
  q.push("5");
  q.push("7");
  while (!q.empty())
  {
    string check = q.front();
    q.pop();
    for (ll i = 0; i < 3; ++i)
    {
      string temp = check;
      temp += num.at(i);
      if (temp.size() > 9)
      {
        continue;
      }
      ll next_num = stoi(temp);
      if (next_num > N)
      {
        continue;
        // cout << temp << endl;
      }
      q.push(temp);
      bool t = false, f = false, s = false;
      for (ll j = 0; j < temp.size(); ++j)
      {
        if (temp[j] == '3')
        {
          t = true;
        }
        else if (temp[j] == '5')
        {
          f = true;
        }
        else
        {
          s = true;
        }
      }
      if (t && f && s)
      {
        // cout << temp << endl;
        ans += 1;
      }
      // ans += 1;
    }
  }
  cout << ans << endl;
}


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

int main(){
    int n,d,a;
    cin >> n >> d >> a;
    vector<pair<int,int>> monsters; 
    for(int i = 0;i<n;++i){
        int x,h;
        cin >> x >> h;
        h = (h+a-1)/a;//number of bombs to drop on monster i to kill it
        monsters.emplace_back(x,h);
    }
    sort(monsters.begin(),monsters.end());
    
    int base = 1;//n = 5
    while(base <  n)//base = 8
        base*=2;
    vector<int> tree(2*base,0);
    
    for(int i = 0;i<n;++i)
        tree[base+i] = monsters[i].second;
    
    
    auto getval = [&] (int i){
        int sum = 0;
        for(int j = base + i;j>=1;j/=2){
            sum += tree[j];
        }
        return sum;
    };
    
    auto addInterval = [&](int l,int r,int val){
        l += base;
        r += base;
         tree[l] += val;
        if(l!=r)
         tree[r] += val;
        
        while(l+1 < r){
            if(l%2 == 0)
                tree[l+1]+=val;
            if(r%2)
                tree[r-1] += val;
            l/=2;
            r/=2;
        }
    };
    
    long long ans = 0;
    for(int i = 0;i<n;++i){
        int health = getval(i);
        if(health <= 0)
            continue;
        //binary search  for the monsters that will be affected by the diameter of detonation of bomb
        int l = i;
        int r = n-1;
        int ok = -1;
        while(l <= r){
            int mid = l+((r-l)>>1);
            if(monsters[mid].first <= (long long)monsters[i].first+2*d){
                ok = mid;
                l = mid+1;
            }
            else{
                r = mid-1;
            }
        }
        assert(ok!=-1);
        addInterval(i,ok,-health);
        ans += health;
    }
    cout << ans <<"\n";
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;

    if((s[0] == s[1] && s[1] == s[2]) || (s[2] == s[3] && s[1] == s[2])) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}



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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    /**/
    bool ans = 1;
    if(n%2 == 1){
        ans = 0;
    }
    else{
        for(int i = 0;i < n/2;i++){
            if(s.at(i) != s.at(i + n/2)){
                ans = 0;
                break;
            }
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lld long long int
using namespace std;

lld field[201][21];

int main(void){
   int n;scanf("%d",&n);n--;
   int atlas[200];
   for(int i = 0;i < n;i++) scanf("%d",&atlas[i]);
   int a;scanf("%d",&a);
   field[0][atlas[0]] = 1;
   for(int i = 1;i < n;i++){
      for(int j = 0;j <= 20;j++){
         if(j-atlas[i]>=0)field[i][j] += field[i-1][j-atlas[i]];
         if(j+atlas[i]<=20)field[i][j] += field[i-1][j+atlas[i]];
      }
   }

   printf("%lld\n",field[n-1][a]);
   return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
string s,t;
char ANS[3002];
long long int dp[3002][3002];
long long int len1,len2,len=0;
void debug(long long int a,long long int b)
{
  cout << "A - " << a << endl << "B - " << b << endl;
}
void resolve(long long int idx1,long long int idx2)
{
  if(idx1<=0||idx2<=0)
    return;
  if(s[idx1-1]==t[idx2-1])
  {
    ANS[len++]=s[idx1-1];
    resolve(idx1-1,idx2-1);
  }
  else if(dp[idx1-1][idx2]>dp[idx1][idx2-1])
    resolve(idx1-1,idx2);
  else
    resolve(idx1,idx2-1);
}
int main()
{
  long long int i,j;
   cin >> s >> t;
   len1=s.length();
   len2=t.length();
   //cout << len1 << len2 << endl;
   for(i=1;i<=len1;i++)
    for(j=1;j<=len2;j++)
    {
      if(s[i-1]==t[j-1])
        dp[i][j]=1+dp[i-1][j-1];
      else
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
   resolve(len1,len2);
   for(i=len-1;i>=0;i--)
    cout << ANS[i];
    cout << endl; 
}

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
int main() {
    int N ;
    cin >> N;
    vector<ll> CC(5,0);
    rep(i, 0, N){
        string S;
        cin >> S;
        switch (S[0]) {
            case 'M':
                CC[0]++;
                break;
            case 'A':
                CC[1]++;
                break;
            case 'R':
                CC[2]++;
                break;
            case 'C':
                CC[3]++;
                break;
            case 'H':
                CC[4]++;
                break;
            default:
                break;
        }
    }
    ll ans = 0;
    rep(i, 0, 5){
        rep(j, i+1, 5){
            rep(k, j+1, 5){
                ans += CC[i]*CC[j]*CC[k];
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    S = raw_input()
    if S == '0':
        break
    m = [1] + [0 for i in range(10)]
    diff = ans = 0
    even = 1
    S = reversed(S)
    for c in S:
        diff = (diff + int(c) * even) % 11
        if int(c) != 0:
            ans += m[diff]
        m[diff] += 1
        even *= -1
    print ans


Measured memory_bytes: 5060
#include <bits/stdc++.h>
#define MAX 10005
#define mp make_pair
#define pb push_back
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define len(x) (x.size())
#define all(a) a.begin(),a.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
#define trace1(x)							cerr << #x << ": " << x << endl;
#define trace2(x, y)						cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)						cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) 			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << :  << f << endl;
using namespace std;

signed main(){
	ios_base::sync_with_stdio(false);	
	cin.tie(0);
	cout.tie(0);

 	int a,b;
 	cin>>a>>b;
 	int soc = 1,str = 0;
 	while(soc<b){
 		soc+=a-1;
 		str ++;
 	}
 	cout<<str;
	return 0;
}



Measured memory_bytes: 256
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
while m != 0:
    a.sort()
    where = bisect.bisect_left(a,a[-1]//2)
    where = abs(where-(n+1))
    for i in range(1,min(where,m+1)):
        a[-i] = a[-i]//2
        m = m-1
print(sum(a))

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

int main() {
	unsigned long long x, y,i;
	int count = 0;
	cin >> x >> y;
	i = x;

	while (1) {
		if (i > y)break;
		count++;
		i *= 2;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
n,u,v=map(int,input().split())
u-=1
v-=1
ki=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  ki[a].append(b)
  ki[b].append(a)
du=[0]*n
dv=[0]*n
from collections import deque
def distance(i):
  seen=[-1]*n
  seen[i]=0
  todo=deque([i])
  while todo:
    t=todo.popleft()
    l=ki[t]
    d=seen[t]
    for li in l:
      if seen[li]==-1:
        seen[li]=d+1
        todo.append(li)
  return seen
du=distance(u)
dv=distance(v)
ans=0
for i in range(n):
  if dv[i]>du[i]:
    ans=max(ans,dv[i])
print(ans-1)

Measured memory_bytes: 68128
// Math = ♥️

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
// #define ordered_set                            \
//     tree<ll, null_type, less<ll>, rb_tree_tag, \
//          tree_order_statistics_node_update>
const ll MOD = (ll)(1e9 + 7);

inline ll add(ll a, ll b) {
    return (a + b >= MOD) ? a + b - MOD : a + b;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, m;
    cin >> n >> m;

    vvii seg(n + 1);

    for (int i = 0; i < m; i++) {
        ll x, y, z;
        cin >> x >> y >> z;
        x, y, z;
        seg[y].pb({x, z});
    }

    ll dp[n + 2][n + 2][n + 2] = {};
    dp[0][0][0] = 1;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j; k++) {
                for (auto it : seg[i]) {
                    if ((i >= it.ff) + (j >= it.ff) + (k >= it.ff) != it.ss) {
                        dp[i][j][k] = 0;
                    }
                }
                dp[i + 1][j][k] = add(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][i][j] = add(dp[i + 1][i][j], dp[i][j][k]);
                dp[i + 1][i][k] = add(dp[i + 1][i][k], dp[i][j][k]);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            ans = add(ans, dp[n][i][j]);
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 218868
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> rev(n);
	for (int i = 0; i < n; i++) {
		rev[a[i] - 1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << rev[i] << " ";
	}
}

Measured memory_bytes: 4048
main(){
int a,b,c,k,j,i,n;
scanf("%d%d%d%d",&a,&b,&c,&k);
if(a>b&&a>c)i=a;
else if(b>c)i=b;
else i=c;
j=i;
for(n=k;n--;)i*=2;
printf("%d\n",a+b+c+i-j);}

Measured memory_bytes: 128
n=int(input())
l=list(map(int,input().split()))
a=list(l)
l.reverse()
for i in range(1,n):
    l[i]=l[i]+l[i-1]
c=0
l.reverse()
for i in range(n-1):
    c+=(a[i]*l[i+1])%((10**9)+7)
c=c%((10**9)+7)
print(c)
    

Measured memory_bytes: 31596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

    int n, w; // the number of temperatures to analyse
    int weight[101], value[101];
    long long dp[101][1000100];
    long long ans=0;

int main() {
    


    cin >> n >>w; cin.ignore();
    for (int i = 0; i < n; i++) {
        cin >> weight[i]>> value[i]; cin.ignore();
    }

    //init
    for (int i = 0; i < w; ++i)
    {
      dp[0][i] = 0; 
    }

    for (int i = 0; i < n; ++i)
    {//till dp[n] 
    	for( int j = 0; j<=w; ++j)
    	{
	    	if (j >= weight[i])
	    	{
	    		dp[i+1][j] = max(dp[i][j], dp[i][j-weight[i]]+value[i]); 
	    	} 
	    	else
	    	{
	    		dp[i+1][j] = dp[i][j];
	    	}
	    	//cout<<"i="<<i<<" j="<<j<<" "<< dp[i+1][j]<< endl;
		}
    }

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

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

Measured memory_bytes: 285696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
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 int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int gcd(int a, int b) {
  int smaller = min(a, b);
  int bigger = max(a, b);
  int surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

int main() {
  Sieve sieve(1e6);
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> cn(1e6 + 1);
  rep(i, n) cin >> A[i];
  int all_gcd = A[0];
  map<int, int> mp;
  rep(i, n){
    auto f = sieve.factor(A[i]);
    for (auto p : f) {
      mp[p.first]++;
    }
    all_gcd = gcd(all_gcd, A[i]);
  }
  int coprime = 1;
  for (auto k : mp){
    if(k.second > 1){
      coprime = 0;
      break;
    }
  }
  
  if(all_gcd != 1){
    cout << "not coprime" << endl;
  }else if(all_gcd == 1 && coprime == 0){
    cout << "setwise coprime" << endl;
  }else{
    cout << "pairwise coprime" << endl;
  }
}

Measured memory_bytes: 18980
#include<iostream>
using namespace std;
main()
{
	int n,a[200000],b[200000];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int m=n/2;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)b[n/2*2-m--]=a[i];
		else b[m]=a[i];
	}
	if(n%2)for(int i=n;i--;)cout<<b[i]<<(i==0?"\n":" ");
	else for(int i=0;i<n;i++)cout<<b[i]<<(i==n-1?"\n":" ");
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

int main(){
	//freopen("test.txt", "r", stdin);
	int n;
	cin >> n;

	vector<pair<int, P> > v(n);
	rep(i, n){
		cin >> v[i].Y.X >> v[i].Y.Y >> v[i].X;
	}
	sort(all(v));

	vi dp(400, -1);
	rep(i, n){
		for(int w = v[i].Y.X; w <= v[i].Y.Y; w++) dp[w] = v[i].X;
	}

	rep(w, 400){
		for(int i = w/2; i < w; i++){
			if(dp[i] == -1 || dp[w-i] == -1) continue;
			dp[w] = max(dp[w], dp[w-i]+dp[i]);
		}
	}

	int m;
	cin >> m;
	vi res;
	rep(i, m){
		int w;
		cin >> w;
		if(dp[w] != -1) res.push_back(dp[w]);
	}

	if(res.size() != m){
		cout << -1 << endl;
	}else{
		rep(i, m){
			cout << res[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1228
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,a,b,N,M;
  cin>>N>>M;
  mat g(N);
  vec h(N,0),ans(N,0);
  while(M--){
    cin>>a>>b;
    a--;b--;
    h[b]++;
    g[a].pb(b);
  }
  queue<ll> que;
  rep(i,N)if(!h[i])que.push(i);
  while(!que.empty()){
    a=que.front();que.pop();
    for(auto next:g[a]){
      ans[next]=ans[a]+1;
      if(--h[next]==0)que.push(next);
    }
  }
  cout<<*max_element(all(ans))<<endl;
  return 0;
}


Measured memory_bytes: 7296
S = input()
cnt = 0
length = len(S)
mem = 0
for i, s in enumerate(S):
    w = 1
    if (i < mem): continue
    while(s == "A"):
        if (i+3 > length):
            mem = i
            break
        elif (S[i+1] == "A"):
            i += 1
            w += 1
        elif (S[i+1:i+3] == "BC"):
            i += 2
            cnt += w
        else:
            mem = i
            break
print(cnt)


Measured memory_bytes: 43740
#include<stdio.h>
int main(){
  int n,i,min;
  scanf("%d",&n);
  int p[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  min=p[0];
  int count=1;
  for(i=1;i<n;i++)
    if(min>=p[i]){
      count++;
      min=p[i];
    }
  printf("%d\n",count);
  return 0;
}


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

using namespace std;

int main()
{
    int n {0}, k {0};
    cin >> n >> k;
    vector <int> h (n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        int minimum = dp[i - 1] + abs(h[i] - h[i - 1]);
        for (int j = 2; j <= k && i - j >= 0; j++)
        {
            if (i - j >= 0)
            {
                minimum = min(dp[i - j] + abs(h[i] - h[i - j]), minimum);
            }  
        }
        dp[i] = minimum;
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 3992
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
//aoj 0189
using namespace std;
int n;
struct pt{
	int e;
	int d;
};
int mbh,mans;
int ans;
int bh[11];
vector<pt> cun[21];
int vis[21];
int dis[21];
queue<int> dl;
void spfa(int ji)
{
	memset(dis,127,sizeof(dis));
	memset(vis,0,sizeof(vis));
	while(!dl.empty())
	{
		dl.pop();
	}
	dis[ji]=0;
	vis[ji]=1;
	dl.push(ji);
	while(!dl.empty())
	{
		int ls=dl.front();
		dl.pop();
		for(int i=0;i<cun[ls].size();i++)
		{
			int ee=cun[ls][i].e;
			int dd=cun[ls][i].d;
			if(dis[ee]>dis[ls]+dd)
			{
				dis[ee]=dis[ls]+dd;
				if(vis[ee]==0)
				{
					vis[ee]=1;
					dl.push(ee);
				}
			}
		}
		vis[ls]=0;
	}
	return;
}
int main()
{
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		mans=271270;
		ans=0;
		memset(bh,0,sizeof(bh));
		for(int i=0;i<=9;i++)
		{
			cun[i].clear();
		}
		for(int i=1;i<=n;i++)
		{
			int s,e;
			pt ls;
			scanf("%d%d%d",&s,&e,&ls.d);
			bh[s]=1;
			bh[e]=1;
			ls.e=e;
			cun[s].push_back(ls);
			ls.e=s;
			cun[e].push_back(ls);
		}
		for(int i=0;i<=9;i++)
		{
			if(bh[i]!=0)
			{
				spfa(i);
				for(int j=0;j<=9;j++)
				{
					if(dis[j]<20000)
					{
						ans+=dis[j];
					}
				}
				if(ans<mans)
				{
					mans=ans;
					mbh=i;
				}
			}
			ans=0;
		}
		printf("%d %d\n",mbh,mans);
	}
	return 0;
}








Measured memory_bytes: 2792
[n,h,w] = [int(i) for i in input().split()]
a = {}
for i in range(n):
    a[i] = [int(i) for i in input().split()]
cnt = 0
for i in a.values():
    if i[0] >= h and i[1] >= w:
        cnt += 1
print(cnt)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

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

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int n;
int sx[11];
int sy[11];

const int dx[12] = { -2, -2, -2, -1, -1,  0, 0,  1, 1,  2, 2, 2 };
const int dy[12] = { -1,  0,  1, -2,  2, -2, 2, -2, 2, -1, 0, 1 };

bool dps(int k, bool *flag){
  if(k == n){
    bool ret = false;
    REP(i, 9) ret |= flag[i];
    return ret;
  }

  bool nflag[9] = { false };

  int x  = sx[k]  , y  = sy[k];
  int nx = sx[k+1], ny = sy[k+1];
  REP(i,9){
    if(flag[i]){
      int xx = x + (i % 3) - 1;
      int yy = y + (i / 3) - 1;
      REP(j,12){
        int xxx = xx + dx[j];
        int yyy = yy + dy[j];
        if(xxx < 0) continue;
        if(yyy < 0) continue;
        if(xxx > 9) continue;
        if(yyy > 9) continue;
        if(abs(xxx-nx) <= 1 && abs(yyy-ny) <= 1){
          int pos = (xxx - nx + 1) + (yyy - ny + 1) * 3;
          nflag[pos] = true;
        }
      }
    }
  }

  return dps(k+1, nflag);
}

int main(){
  while(scanf("%d%d",&sx[0],&sy[0]), sx[0]+sy[0]){
    bool flag[9] =
      { 0, 0, 0,
        0, 1, 0,
        0, 0, 0 };

    scanf("%d",&n);
    REP(i,n) scanf("%d%d",&sx[i+1], &sy[i+1]);

    puts(dps(0, flag) ? "OK" : "NA");
  }
  return 0;
}

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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> lr(M+1);
    for(int i=0; i<N; i++){
        int l, r;
        cin >> l >> r;
        lr[r-l+1].emplace_back(l, r);
    }

    BIT<int> bit(M+2);

    int all = N;
    for(int d=1; d<=M; d++){
        int ans = all;
        for(int i=d; i<=M; i+=d) ans += bit.sum(i);
        cout << ans << endl;

        for(auto& p : lr[d]){
            int l = p.first, r = p.second;
            bit.plus(l, 1);
            bit.plus(r+1, -1);
            all--;
        }
    }
}

Measured memory_bytes: 8064
program ABC113B
    implicit none
    integer(8)::i
    integer(8)::N
    integer(8)::t_place
    real::T,A
    real::t_best
    real,allocatable,dimension(:)::H

    read(5,*)N
    read(5,*)T,A
    allocate(H(N))
    read(5,*)(H(i),i=1,N)
    
    do i=1,N
        if(i==1)then
            t_best=abs(A-(T-0.006*H(i)))
            t_place=i
        else if(abs(A-(T-0.006*H(i)))<t_best)then
            t_best=abs(A-(T-0.006*H(i)))
            t_place=i
        end if
    end do
    
    print'(i0)',t_place

end program ABC113B

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

int main(){
  int X,Y;
  cin>>X>>Y;

  for(int i=0; i<=X; i++){
    for(int j=X-i; i+j<=X; j++){
      if(i*2+j*4 == Y){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


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

int main() {
  int n, k; cin >> n >> k;
  vector<int> l(n);

  rep(i, n) {
    cin >> l.at(i);
  }
  
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());

  int sum = 0;
  rep(i, k) {
    sum += l[i];
  }
  p(sum);
}


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll A; cin >> A;
    long double B; cin >> B;
    cout << fixed << setprecision(0) << floorl(A*B) << endl;
    return 0;
    
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          uint[] num = Input.ScanUintArray();
          uint res = num[1];
          for(uint i=1;i<num[0];i++)
            res *= num[1]-1;
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

vi a(60),b(60);
int out;
void f(int n,int m){
	int c=b[n-1];
	if(m==1)out++;
	else if(m<c+1){
		out++;
		f(n-1,m-1);
	}else if(m<=c+2)out+=a[n-1]+1;
	else if(m==b[n])out+=a[n];
	else if(m==b[n]-1)out+=a[n]-1;
	else{
		out+=a[n-1]+1;
		f(n-1,m-c-2);
	}
}
signed main(){
	a[0]=0,b[0]=1;
	rep(i,55)a[i+1]=a[i]*2+2,b[i+1]=b[i]*2+3;
	
	int n,m;
	cin>>n>>m;
	f(n,m);
	cout<<m-out<<endl;
}


















Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        ArrayList<Town> towns = new ArrayList<>();
        for (int i = 0; i < n; i++){
            towns.add(new Town(in.nextInt(), in.nextInt()));
        }
        ArrayList<Double> distances = new ArrayList<>();
        for (int i = 0; i < n; i++){
            ArrayList<Town> clone = new ArrayList<>(towns);
            helper(0,clone.remove(i),clone, distances);
        }
        double total = 0;
        for (double d : distances) total += d;
        System.out.println(total/distances.size());
    }

    private static class Town{
        int x;
        int y;
        Town(int x, int y){
            this.x = x;
            this.y = y;
        }
    }

    private static double distance(Town t1, Town t2){
        return Math.sqrt(Math.pow(t1.x-t2.x,2)+Math.pow(t1.y-t2.y,2));
    }

    private static void helper (double travelled, Town current, ArrayList<Town> remaining, ArrayList<Double> distances){
        if (remaining.isEmpty()) {
            distances.add(travelled);
        } else {
            for (int i = 0; i < remaining.size(); i++){
                ArrayList<Town> clone = new ArrayList<>(remaining);
                Town next = clone.remove(i);
                helper(travelled + distance(current, next), next, clone, distances);
            }
        }
    }
}

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

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

#define roop(i, n) for(int i = 0;i < n;i++)
#define INF 1000000000

int main(void){

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

    roop(i, n){
        string s;
        cin >> s;
        for(int j = 0;s[j] != '\0';j++){
            a[i][s[j]-'a']++;
        }
    }

    roop(i, 26){
        int value = INF;
        roop(j, n){
            value = min(value, a[j][i]);
        }
        roop(j, value) cout << (char)(i+'a');
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
character(len=100) :: w
integer :: i, j, len, count

read(*,*) w
len = len_trim(w)

do i = 1, len
	count = 0
    do j = 1, len
    	if(w(i:i) == w(j:j))then
    		count = count + 1
    	end if
	end do
	if (mod(count,2) == 1)then
    	write(*,'(a)') 'No'
        stop
    end if
end do

write(*,'(a)') 'Yes'

END PROGRAM ATCODER

Measured memory_bytes: 256
#from collections import deque
from bisect import bisect_left
N=int(input())
A=[int(i) for i in input().split()]
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]

num=10**14
for i in range(2,N-1):
    ans=[]
    x=(A[i]+A[0])/2
    j=bisect_left(A,x)
    #print(j,x)
    if A[j]-x>x-A[j-1]:
        j-=1
    ans+=[A[j]-A[0],A[i]-A[j]]
    y=(A[N]+A[i])/2
    k=bisect_left(A,y)
    #print(k,y)
    if A[k]-y>y-A[k-1]:
        k-=1
    ans+=[A[N]-A[k],A[k]-A[i]]
    #print(ans)
    t=max(ans)-min(ans)
    num=min(num,t)
print(num)

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

#define int long long
const int N = 1e5 + 10 ;
vector<int> G[N] ;

void dfs(int start , int* v , int d = 0 , int parent = -1 ){
	v[start] = d ;
	for(auto i : G[start]){
		if(i == parent) continue ;
		dfs(i,v,d+1,start) ;
	}
}

int32_t main(){
	int n , u , v ;
	cin >> n >> u >> v ;
	u-- , v-- ;
	for(int i = 0 ; i < n - 1 ; i++){
		int f, s ;
		cin >>f >> s ;
		f-- , s-- ;
		G[f].push_back(s) ;
		G[s].push_back(f) ;
	}
	int v1[n] = {0} , v2[n] = {0} ;
	dfs(u,v1) ;
	dfs(v,v2) ;
	int ans = 0 ;
	for(int i = 0 ; i < n ; i++){
		if(v1[i] < v2[i]){
			ans = max(v2[i]-1, ans) ;
			// v2[i] vo place hai jaha murderer late pahuchega ,
			// marne se just pehle v1 wala leaf pe hoga
			// v2[i] leaf hai jispe marne ke pehle v1 khada hoga 
			// jisme v1 ka next step hoga parent of leaf pe jana jaha v2
			// khada hoga ya pahuchne wala hoga aur marr jaega ( atm hatya karlega bc lel)
		}
	}
	cout << ans;
	return 0 ;
}



Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int mem[n];

  for (int i = 0; i < n; i++)
  {
    mem[i] = 0;
  }

  for (int i = 0; i < n - 1; i++)
  {
    int a;
    cin >> a;
    mem[a - 1] += 1;
  }

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

  return 0;
}

Measured memory_bytes: 4016