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

int main() {
  int n;
  cin>>n;
  vector<int> a(n+1);
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(i!=a[i])cnt++;
  }
  if(cnt==2||cnt==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!};
}
let a = readInts();
let N = a[0], M = a[1];
var A: Array<Array<Int>> = Array();
for i in 0 ..< a[1] {
    let b = readInts();
    let k = b[0];
    A.append([Int]());
    for j in 0 ..< N {
        A[i].append(0);
    }
    for j in 1 ... k {
        A[i][b[j]-1] = 1;
    }
}
var answer = 0;
let p = readInts();
for bit in 0 ..< (1<<N) {
    var rock = 0;
    var check: Array<Int> = Array(repeating: 0, count: 12);
    for i in 0 ..< N {
        if bit & 1<<i > 0 {
            check[i] = 1;
        }
    }
    for i in 0 ..< M {
        var count = 0;
        for j in 0 ..< N {
            if check[j] == 1 && A[i][j] == 1 {
                count += 1;
            }
        }
        if count % 2 == p[i] {
            rock += 1;
        }
    }
    if rock == M {
        answer += 1;
    }
}
print(answer);

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

using namespace std;
static int a = 0 , w = 0 , t = 0 , r = 0;
 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    //int a , w  , t , r ;
    cin >> n;
    while(n--)
    {
    string s;
    cin >> s;
    //int a, w , t , r ;
    	for (int i = 1;i < s.size() ; i++)
    	{
    		if (s[0] == 'A'){
    			a++;
			}
			else if (s[0] == 'W'){
				w++;
			}
			else  if (s[0] == 'T'){
				t++;
			}
			else {
				r++;
			}

	}
}
		cout << "AC" << " " << 'x' << " " <<  a << '\n';
	    cout << "WA" << " " << 'x' << " " <<  w << '\n';
	    cout << "TLE" << " " << 'x' << " " <<  t / 2 << '\n';
	    cout << "RE" << " " << 'x' << " " <<  r << '\n';
		 
}

Measured memory_bytes: 3608
function main(arg) {
  const lines = arg.trim().split('\n');
  let nums = lines[0].split(' ');
  nums.sort((a, b) => {
    return b - a;
  });
  nums = nums.map((elem) => Number(elem));
  const ans = nums[0] * 10 + nums[1] + nums[2];
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29624
def main():
    N, W = map(int, input().split())
    l = []
    w, v = map(int, input().split())
    ww = w
    dp = [[[0] * (3*N) for _ in range(N+1) ]for _ in range(N)]
    dp[0][1][0] = v
    l.append((0, v))
    for _ in range(N-1):
        w, v = map(int, input().split())
        l.append((w-ww, v))
    if W < ww:
        return 0
    for i in range(1, N):
        w, v = l[i]
        for j in range(1, N+1):
            for k in range(w):
                dp[i][j][k] = dp[i-1][j][k]
            for k in range(w, 3*N):
                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)
    r = 0
    for i in range(N+1):
        wt = W - i * ww
        if wt < 0:
            break
        r = max(r, max(dp[-1][i][:wt+1]))
    return r
print(main())


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

using namespace std;

int a[100010];
int n,k;

bool check(int x)
{
    int cnt=0,now=0;
    for(int i=0;i<n;i++)
    {
        if(x<a[i])
        {
            return false;
        }
        if(now<a[i])
        {
            cnt++;
            now=x-a[i];
        }else
        {
            now-=a[i];
        }
    }

    return cnt<=k;
}

int main()
{

    while(scanf("%d %d",&n,&k)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }

        int l=0,r=1e9+10;

        while(l<r)
        {
            int mid=(l+r)/2;
            if(check(mid))
            {
                r=mid;
            }else
            {
                l=mid+1;
            }
        }

        cout<<l<<endl;
    }



    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

bool fun(string s) {
	string tmp = s;
	reverse(tmp.begin(), tmp.end());
	if (s != tmp) return 0;

	tmp = s.substr(0, (s.size() - 1) / 2);
	string tmp2 = tmp;
	reverse(tmp2.begin(), tmp2.end());
	if (tmp2 != tmp) return 0;

	tmp = s.substr((s.size() + 2) / 2, 100);
	tmp2 = tmp;
	reverse(tmp2.begin(), tmp2.end());
	if (tmp2 != tmp) return 0;

	return 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;

	if (fun(s)) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;
    vector<int> h(N); REP(i,N) cin >> h[i];
    sort(ALL(h));

    int ans = INF;
    REP(i,N-K+1){
        ans = min(ans, h[i+K-1] - h[i]);
    }

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

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  
  sort(all(a), greater<ll>());
  pql pique;
  pique.push(a[0]);
  ll ans=0;
  rep2(i, n-1) {
    ans += pique.top();
    pique.pop();
    rep(_, 2) pique.push(a[i]);
  }
  cout << ans << newl;
  return 0;
}

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

int n;
string s;
int main() {
	cin >> n >> s;
	for(int i=0; s[i]; i++) {
		s[i] += n;
		if(s[i] > 'Z') s[i] -= 26;
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            Console.WriteLine(doCollatz(n));
        }
    }
    public static long doCollatz(long n)
    {
        if (n == 1) return 0;
        var count = 1L;
        while (true)
        {
            if (n % 2 == 0) n /= 2;
            else n = 3 * n + 1;
            if (n == 1) return count;
            count++;
        }
    }
}

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

int main(void){
    int r,g,b;
    cin >> r >> g >> b;
    int n;
    n = 100*r + 10*g + b;
    if(n % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    int counter = 0;

    while (input.ready())
    {
      final String[] INPUT_STR = input.readLine().split(" ");
      final int FROM_YEAR = Integer.valueOf(INPUT_STR[0]);
      final int TO_YEAR = Integer.valueOf(INPUT_STR[1]);

      if (TO_YEAR == 0)
      {
        break;
      }

      if (counter > 0)
      {
        System.out.println();
      }
      counter++;

      final ArrayList<Integer> ansList = leapYearCount(FROM_YEAR, TO_YEAR);

      if (ansList.size() == 0)
      {
        System.out.println("NA");
        continue;
      }

      for (Integer each : ansList)
      {
        System.out.println(each);
      }
    }

  }

  private static ArrayList<Integer> leapYearCount(int fromYear, int toYear)
  {
    ArrayList<Integer> yearList = new ArrayList<>();
    for (int i = fromYear; i <= toYear; i++)
    {
      if (isLeapYear(i))
      {
        yearList.add(i);
      }
    }
    return yearList;
  }

  private static boolean isLeapYear(int year)
  {
    if (year % 4 != 0)
    {
      return false;
    }

    if (year % 100 == 0)
    {
      if (year % 400 == 0)
      {
        return true;
      }
      return false;
    }
    return true;
  }
}

Measured memory_bytes: 25948
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair< int, int> P;
struct edge{ll to, cost; };

static const double EPS = 1e-8;
static const double PI = 3.141592653589;
static ll INF = 999999999999;
int mod = 1000000007;

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define MIN(a,b)    (a) < (b) ? (a):(b)
#define MAX(a,b)    (a) > (b) ? (a):(b)
#define debug(x) cerr << #x << " = " << x << endl;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,-1,1,1,-1};

using namespace std;




int main() {

    int N,k;
    int X,Y;
    int ans = 0;
    cin >> N;
    cin >> k;
    cin >> X;
    cin >> Y;
    if(N < k)k = N;
    ans += k * X;
    ans += (N - k) * Y;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

int dp[100][100];

int main(void){
string ws,wk;
int dm[101][52]={0};
int lw=0,cl,mcl=0;;
	while(getline(cin,ws)){
		replace(ws.begin(),ws.end(),',',' ');
		stringstream zz(ws);
		cl = 0;
		while( zz >> dm[lw][cl] ){
			cl++;
			mcl=max(cl,mcl);
		}
		lw++;
		if(cl== 1 && lw > 2 ) break;
	}

	rep(i, lw){
		rep(j, i+1){
			if(i <= lw/2){
				if(i == 0) dp[i][j] = dm[i][j]; 
				else if(j == 0)dp[i][j] = dp[i-1][j] + dm[i][j];
				else dp[i][j] = max(dp[i-1][j] + dm[i][j],
						dp[i-1][j-1] + dm[i][j]);
      		}else{
				dp[i][j] = max(dp[i-1][j] + dm[i][j],dp[i-1][j+1] + dm[i][j]);
      		}
    	} 
  	}
	cout << dp[lw-1][0] << endl;
//	rep(i,mcl) printf("%d, ",dp[lw-1][i]);
	return 0;
	
}

Measured memory_bytes: 1292
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		int c = a + b;
		int d = a - b;
		int e = a * b;
		int ans = Math.max(c, d);
		System.out.println(Math.max(ans, e));
	}

}


Measured memory_bytes: 23124
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		String S = sc.next();

		if(S.length()==2){
			System.out.println(S);
		}else {
			String[] str = S.split("");
			String ans = str[2]+str[1]+str[0];
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 39212
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	ll x, q, r;
  	ll count = 0;
  	cin >> x;
  	q = x/11;
 	if(x%11==0){ ; }
  	else if(x%11<=6){ count ++;}
  	else{ count += 2; }
	cout << 2*q + count << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(1<<N);
	
	long long B = 1000000;
	
	for(int i=0;i<(1<<N);i++){
		scanf("%lld",&A[i]);
	}
	
	vector<vector<pair<long long,long long>>> dp(2,vector<pair<long long,long long>> (1<<N));
	vector<long long> V(4);
	for(int i=0;i<=N;i++){
		for(int j=0;j<(1<<N);j++){
			if(i==0){
				dp[0][j] = make_pair(0,A[j]);
			}
			else{
				if((j>>(i-1))&1){
					V[0] = dp[1][j].first;
					V[1] = dp[1][j].second;
					V[2] = dp[1][j&(~(1<<(i-1)))].first;
					V[3] = dp[1][j&(~(1<<(i-1)))].second;
					sort(V.rbegin(),V.rend());
					//V.erase(unique(V.begin(),V.end()),V.end());
					dp[0][j].first = V[0];
					dp[0][j].second = V[1];
				}
				else dp[0][j] = dp[1][j];
			}
		}
		swap(dp[0],dp[1]);
	}
	
	//vector<long long> ans(1<<N);
	
	for(int i=0;i<(1<<N);i++){
		dp[1][i].first += dp[1][i].second;
		if(i!=0)dp[1][i].first = max(dp[1][i].first,dp[1][i-1].first);
	}
	
	for(int i=1;i<(1<<N);i++){
		printf("%lld\n",dp[1][i].first);
		//cout<<ans[i]<<endl;
	}
	
	
	
    return 0;
}

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

using namespace std;

int main() {
  int N, A, B;

  cin>>N>>A>>B;

  int train, taxi;

  train = A * N;
  taxi = B;

  if(train<=taxi) {
    cout<<train<<endl;
  } else {
    cout<<taxi<<endl;
  }

  return 0;
}

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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    unsigned long long h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
    } else {
        cout << fixed << setprecision(0);
        cout << ceil(h * w / 2.0) << endl;
    }
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 384
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import defaultdict
dic = defaultdict(int)
for a in A:
    dic[a] += 1
sort_dic = sorted(dic.items(), key = lambda x:x[1])
n = len(sort_dic)
if n<=K: print(0);exit()
ans = 0
for i in range(n-K):
    ans += sort_dic[i][1]
print(ans)

Measured memory_bytes: 128408
import sys

N, K, Q = [int(i) for i in input().split()]
t = { k + 1: K for k in range(N) }
for _ in range(Q):
    A = int(input())
    t[A] += 1
for n in range(N):
    if t[n + 1] - Q > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 15084
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int arr[] = new int[N];
		Arrays.fill(arr, 0);
		for(int i=0; i<2*M; i++){
			int a = sc.nextInt();
			for(int j=1; j<=N; j++){
				if(a==j){
					arr[j-1]++;
				}
			}
		}
		for(int i=0; i<N; i++){
			System.out.println(arr[i]);
		}
	}
}

Measured memory_bytes: 22100
cal_list = []

while True:
    val = list(input().split())
    if val[1] == '?':
        break
    else:
        cal_list.append(val)

for CALC in cal_list:
    x, y = int(CALC[0]), int(CALC[2])
    if CALC[1] != '/':
        eval('print(x' + CALC[1]+ 'y)')
    else:
        eval('print(x' + CALC[1]+ '/y)')


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  int cnt = 0;
  while (N--) {
    int t; cin >> t;
    cnt += t & 1;
  }
  if (cnt & 1) cout << "NO" << endl;
  else cout << "YES" << endl;
}

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

using namespace std;

const int N = 1e5 + 5;

struct Node {
    int dist, idx, type;

    Node (int dist = 0, int idx = 0, int type = 0): dist(dist), idx(idx), type(type) {}
};

int n, m;
map <int, int> dist[N];
vector <pair <int, int> > g[N];
deque <Node> dq;

int main(){
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        g[u].push_back({w, v});
        g[v].push_back({w, u});
    }

    for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());

    dq.push_back(Node(0, 1, 0)); dist[1][0] = 0;
    while (!dq.empty()) {
        Node val = dq.front(); dq.pop_front();
        int d = val.dist, u = val.idx, last = val.type;
        if (d != dist[u][last]) continue;

        if (!dist[u].count(0) || dist[u][0] > d) {
            dist[u][0] = d;
            dq.push_front(Node(dist[u][0], u, 0));
        }

        if (!last) {
            for (auto v: g[u]) {
                if (!dist[v.second].count(v.first) || dist[v.second][v.first] > d + 1) {
                    dist[v.second][v.first] = d + 1;
                    dq.push_back(Node(dist[v.second][v.first], v.second, v.first));
                }
            }
        }
        else {
            int pos = lower_bound(g[u].begin(), g[u].end(), make_pair(last, 0)) - g[u].begin();
            while (pos < g[u].size() && g[u][pos].first == last) {
                int v = g[u][pos].second;
                if (!dist[v].count(last) || dist[v][last] > d) {
                    dist[v][last] = d;
                    dq.push_front(Node(dist[v][last], v, last));
                }
                pos++;
            }
        }
    }

    printf("%d", !dist[n].count(0) ? -1 : dist[n][0]);
    return 0;
}


Measured memory_bytes: 37376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1()
{
    int x; cin >> x;

    bool f = false;
    for(int i = 1; i <= 1000; i++) {
        if(x >= 100*i && x <= 105*i) {
            f = true;
            break;
        }
    }

    if(f) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

}

int main()
{
    solve1();
}

Measured memory_bytes: 3620
alphabet = [0]*26
i = 0;
for j in range(97,123):
	alphabet[i] = chr(j)
	i += 1
al_count = [0]*26
while True :
	try :
		words = raw_input().lower().split()
		for k in words :
			for l in list(k):
				if l=='a':
					al_count[0] += 1
				elif l=='b':
					al_count[1] += 1
				elif l=='c':
					al_count[2]+=1	
				elif l=='d':
					al_count[3] += 1
				elif l=='e':
					al_count[4]+=1
				elif l=='f':
					al_count[5] += 1
				elif l=='g':
					al_count[6]+=1
				elif l=='h':
					al_count[7] += 1
				elif l=='i':
					al_count[8]+=1
				elif l=='j':
					al_count[9] += 1
				elif l=='k':
					al_count[10]+=1	
				elif l=='l':
					al_count[11] += 1
				elif l=='m':
					al_count[12]+=1	
				elif l=='n':
					al_count[13] += 1
				elif l=='o':
					al_count[14]+=1
				elif l=='p':
					al_count[15] += 1
				elif l=='q':
					al_count[16]+=1
				elif l=='r':
					al_count[17] += 1
				elif l=='s':
					al_count[18]+=1
				elif l=='t':
					al_count[19] += 1
				elif l=='u':
					al_count[20]+=1
				elif l=='v':
					al_count[21]+=1
				elif l=='w':
					al_count[22] += 1
				elif l=='x':
					al_count[23]+=1
				elif l=='y':
					al_count[24] += 1
				elif l=='z':
					al_count[25]+=1
	except :
		break
for i in range(26):
	print '%c : %d' %(alphabet[i],al_count[i])

Measured memory_bytes: 6460
a = int(input())
l = list(map(int,input().split()))

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    if ans < min(ans,abs(le-ri)):
        print(ans)
        break
    else:
        ans = min(ans,abs(le-ri))
else:
    print(ans)

Measured memory_bytes: 24800
#include<stdio.h>

int main(){
    int n,i,num,a,j,id;
    int A[101][101];
    scanf("%d",&n);
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d%d",&id,&num);
        for(j=0;j<num;j++){
            scanf("%d",&a);
            A[id][a]++;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(j!=n-1)printf("%d ",A[i+1][j+1]);
            else printf("%d",A[i+1][j+1]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2052
def main():
    a, b, c = (int(i) for i in input().split())
    def trial_division(n):
        """
        nの約数のセットをO(sqrt(n))で求める
        """
        divs = set()
        for i in range(1,int(n**0.5)+1):
            if n % i == 0:
                divs.add(i)
                if i != n//i:
                    divs.add(n//i)
        return divs

    c_div = trial_division(c)
    ans = 0
    for x in range(a,b+1):
        if x in c_div:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i =0;i<n;i++)
		cin>>h[i];
	vector<int> dp(n,INT_MAX);
	dp[0]=0;
	for(int i =0;i<n-1;i++)
	{
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		if(i<n-2)
			dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int color[100]={};
  for(int i=0;i<n;i++){
    int a;cin>>a;
    if(a>=3200)color[8]++;
    else color[a/400]++;
  }
  int mi=0,ma=0;
  for(int i=0;i<8;i++){
    if(color[i]){mi++;ma++;}
  }
  if(mi==0)mi++;
  cout<<mi<<" "<<ma+color[8]<<endl;
  return 0;
}


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


int main(void)
{
    long k,cnt=0,ans=0;
    char s[100];
    scanf("%s",s);
    scanf("%ld",&k);
    long len=strlen(s);
    int a=0;
    for(int i=1;i<len;i++)
    {
        if(s[i-1]==s[i])
        {
            if(a==0)
            {
                cnt++;
                a=1;
            }else{
                a=0;
            }
        }else{
            a=0;
        }
    }
    if(s[0]!=s[len-1])
    {
        ans=cnt*k;
    }else{
        int key=1;
        for(int i=1;i<len;i++)
        {
            if(s[i]==s[i-1])
            {
                key++;
            }else{
                break;
            }
        }
        if(key==len){
            ans=len*k/2;
        }else{
            long sum=0,j=0,i=len-1;
            while(s[0]==s[j]&&j<len)
            {
                j++;
                sum++;
            }
            while(s[len-1]==s[i]&&i>=0)
            {
                i--;
                sum++;
            }
            ans=cnt*k+((sum+1)%2)*(k-1);
        }
    }
    
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 1696
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
row=[]
col=[]
for i in range(h):
    if "#" in a[i][:]:
        row.append(i)
b=[list(x) for x in zip(*a)]
for j in range(w):
    if "#" in b[:][j]:
        col.append(j)
for i in row:
    for j in col:
        print(a[i][j],end="")
    print("")

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main() {
const int INF=1e7;
  int n,m,l,a,b,c,d,e=0;
  cin >> n >> m;
  l=(1<<n);
  int x[l];
  fill(x,x+l,INF);
  rep(i,m){
     cin>>a>>b;
     d=0;
     rep(j,b){
        cin>>c;
        d |=1<<(c-1); 
     } 
     e|=d;
     x[d]=min(x[d],a);
  }
  if(e==l-1){
      rep(z,n){
         rep(i,l){
            if(x[i]!=INF){
               rep(j,l){
                  if(i!=j&&x[j]!=INF)
                  x[i|j]=min(x[i|j],x[i]+x[j]); 
               } 
            } 
         } 
      }
      cout<<x[l-1];
  }else{
     cout<<-1; 
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(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 sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,m,i;
        cin >> n >> m;
        int mp[n+1]={0},ans[n+1]={0};
        while(m--){
            int x;
            string y;
            cin >> x >> y;
            if(mp[x]==0){
                if(y=="WA"){
                    ans[x]++;
                }
                else{
                    mp[x]=1;
                }
            }
        }
        int a=0,b=0;
        for(i=1; i<=n; i++){
            if(mp[i]==1)a++;
            if(mp[i])
            b=b+ans[i];
        }
        cout << a << ' ' << b << '\n';
        

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll func(ll x){
    if(x == 1)return 1;
    return func(x/2) * 2 + 1;
}
main(){
    ll N;
    cin >> N;
    cout << func(N) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC142C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Dictionary<int, int> dic = new Dictionary<int, int>();
            for(int i = 0; i < a.Length; i++)
            {
                dic.Add(i + 1, a[i]);
            }

            int[] answer = dic.OrderBy(q => q.Value).Select(q => q.Key).ToArray();
            Console.WriteLine(String.Join(" ", answer));
        }
    }
}


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

int main() {
  int a,b;
  string op;
  cin >> a >> op >> b;
  int ans;

  if (op == "+"){
  	ans = a + b;
  }

  if (op == "-"){
  	ans = a - b;
  }
  cout << ans << endl;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  llong ans=0;

  int N; cin >> N;
  int T; cin >> T;
  vector<int> t(N); REP(i, N) cin >> t[i];

  ans += T;
  for (int i=1; i<N; i++) {
    llong d = t[i] - t[i-1];
    if (d <= T) {
      ans += d;
    } else {
      ans += T;
    }
  }

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N;
string S;
int SCount = 0;

int V[MAX_N][3];

int myPow(int n, int k, int mod) {
  int tmp = n;
  int ret = 1;
  while(k) {
    if (k&1) {
      ret *= tmp;
    }
    tmp *= tmp;
    k /= 2;
    ret %= mod;
    tmp %= mod; 
  }
  return ret%mod;
}

void initSet() {
  FOR(k,-1,2) {
    int K = SCount + k;
    if (K == 0) {
      REP(i,S.size()) {
        V[i][k+1] = 0;
      }
      continue;
    }
    int ret = 0;
    for (const char& c : S) {
      ret *= 2;
      if (c == '1') {
        ret++;
      }
      ret %= K;
    }
    REP(i,S.size()) {
      if (S[i] == '0') {
        V[i][k+1] = ret;
      } else {
        V[i][k+1] = (ret + K - (myPow(2,(int)S.size() - 1 - i,K))) % K;
      }
    }
  }
}

string myMod(const string& str, int k, bool useArray, bool plusToggle, int index) {
  int ret = 0;
  if (useArray) {
    ret = V[index][plusToggle ? 2 : 0];
    if (plusToggle) {
      ret += myPow(2,N-index-1,k);
      ret %= k;
    }
  } else {
    for (const char& c : str) {
      ret *= 2;
      if (c == '1') {
        ret++;
      }
      ret %= k;
    }
  }

  string retStr = "";
  while(ret) {
    if (ret%2 == 1) {
      retStr += '1';
    } else {
      retStr += '0';
    }
    ret /= 2;
  }
  reverse(retStr.begin(), retStr.end());
  return retStr;
}

bool toggle(int n) {
  S[n] = (S[n] == '0' ? '1' : '0');
  return S[n] == '1';
}

signed main()
{
  cin >> N;
  cin >> S;
  for (char s : S) {
    if (s == '1') {
      SCount++;
    }
  }

  if (SCount == 0) {
    REP(n,N) {
      cout << 1 << endl;
    }
    return 0;
  }

  initSet();

  REP(n,N) {
    bool plusToggle = false;
    if (toggle(n)) {
      SCount++;
      plusToggle = true;
    } else {
      SCount--;
    }
    
    int ans = 0;
    int k = SCount;
    string s;
    while(k) {
      ans++;
      if (ans == 1) {
        s = myMod(S, k, true, plusToggle, n);
      } else {
        s = myMod(s, k, false, plusToggle, n);
      }
      k = 0;
      for(char c : s) {
        if (c == '1') {
          k++;
        }
      }
    }
    cout << ans << endl;

    if (toggle(n)) {
      SCount++;
    } else {
      SCount--;
    }
  }
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  char a;
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a;
      if (a == '#') cnt++;
    }
  }
  cout << (cnt == H + W - 1 ? "Possible" : "Impossible") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

int main() {
	int testcases{};
	std::cin >> testcases;
	int cases[testcases]{}, cases2[testcases]{};
	for (int i {0}; i < testcases; i++) {
		std::cin >> cases[i];
		cases2[i] = cases[i];
	}
	
	std::sort (cases, cases+testcases, std::greater<int>());
	
	for (int i {0}; i < testcases; i++) {
		if (cases2[i] == cases[0]) {
			std::cout << cases[1] << "\n";
		}
		else {
			std::cout << cases[0] << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3200
n, m, x = map(int, input().split(" "))
a = input().split(" ")
sum_zero = 0
sum_n = 0
for i in range(1, x):
    if str(i) in a:
        sum_zero += 1

for i in range(x+1, n):
    if str(i) in a:
        sum_n += 1
print(min(sum_zero, sum_n))

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
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 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;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans=0;
  cin>>N>>H;
  vec v(N);
  if(N==1){
    ans+=300000;
  }
  if(N==2){
    ans+=200000;
  }
  if(N==3){
    ans+=100000;
  }
  if(H==1){
    ans+=300000;
  }
  if(H==2){
    ans+=200000;
  }
  if(H==3){
    ans+=100000;
  }
  if(N*H==1)ans=1000000;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	bool ok=true;
	if(s[0]!='1' || s[s.size()-1]!='0'){
		ok=false;
	}
	REP(i, (s.size()-1)/2){
		if(s[i]!=s[s.size()-2-i]){
			ok=false;
			break;
		}
	}
	if(!ok){
		cout<<-1<<'\n';
		return 0;
	}
	int num=0;
	FOR(i, 1, s.size()){
		if(s[i]=='1'){
			FOR(j, num+1, i+1){
				cout<<num+1<<' '<<j+1<<'\n';
			}
			cout<<num+1<<' '<<i+2<<'\n';
			num=i+1;
		}
	}
	return 0;
}


Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int dp[1005][1005];
char c[1005][1005];
int solve(){
    cin>>n>>m;
    rep(i,0,n){
        rep(j,0,m){
            dp[i][j]=1;
        }
    }
    rep(i,1,n) rep(j,1,m) cin>>c[i][j];
    rep(i,1,n){
        rep(j,1,m){
            if(i==1&&j==1) continue;
            if(c[i][j]=='.'){
                if(c[i-1][j]=='.'&&c[i][j-1]=='.'){
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M;
                }
                else if(c[i-1][j]=='.'){
                    dp[i][j]=dp[i-1][j];
                }
                else if(c[i][j-1]=='.'){
                    dp[i][j]=dp[i][j-1];
                }
                else{
                    dp[i][j]=0;
                }
            }
            else{
                dp[i][j]=0;
            }
        }
    }
    cout<<dp[n][m];
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<int, int> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)1000000000000

int main() {
  int memo[4];
  rep(i,4){memo[i]=0;}
  int N;cin>>N;
  rep(i,N){
    string s;
    cin>>s;
    if(s[0]=='A'){memo[0]++;}
    if(s[0]=='W'){memo[1]++;}
    if(s[0]=='T'){memo[2]++;}
    if(s[0]=='R'){memo[3]++;}
  }
  cout<<"AC x "<<memo[0]<<endl;
  cout<<"WA x "<<memo[1]<<endl;
  cout<<"TLE x "<<memo[2]<<endl;
  cout<<"RE x "<<memo[3]<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0; i < (n); i++)

void solve() {
  string s;
  cin >> s;
  //map<string, bool> memo;
  int sum = 0;
  bool aWin = true;
  for (int i = 1; i < s.size(); i++) {
    int v = s[i] + s[i-1] - '0'*2;
    if (v >= 10) {
      s[i-1] = '1';
      s[i] = v - 10 + '0';
      i--;
    }
    else {
      s[i] = v + '0';
    }
    //cout << i << "," << s << endl;
    aWin = !aWin;
  }
  cout << (aWin ? "Audrey wins." : "Fabre wins.") << endl;
  
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2E5+7;
const ll INF=1e9+7;
ll dp[N];
ll a[N],b[N];
int main()
{
    ll h,c;
    cin>>h>>c;
    for(ll i=1;i<=c;i++){
        cin>>a[i]>>b[i];
    }
    for(ll i=1;i<=2*h;i++){
        dp[i]=INF;
        for(ll j=1;j<=c;j++){
            dp[i]=min(dp[i],dp[max((ll)0,i-a[j])]+b[j]);
        }
    }
    ll ans=INF;
    for(ll i=h;i<=h*2;i++){
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x) 
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define fo(i, a, b) for (int i = a; i <= b; ++i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length();

    int dp[n+1][m+1];
    ii p[n+1][m+1];
    for (int j = 0; j <= m; ++j) dp[n][j] = 0;
    for (int i = 0; i <= n; ++i) dp[i][m] = 0;
    for (int i = n-1; i >= 0; --i) {
        for (int j = m-1; j >= 0; --j) {
            dp[i][j] = -1;
            if (dp[i+1][j] > dp[i][j]) dp[i][j] = dp[i+1][j], p[i][j] = ii(i+1, j);
            if (dp[i][j+1] > dp[i][j]) dp[i][j] = dp[i][j+1], p[i][j] = ii(i, j+1);

            if (s[i] == t[j] && dp[i+1][j+1]+1 > dp[i][j]) 
                dp[i][j] = dp[i+1][j+1]+1, p[i][j] = ii(i+1, j+1);
        }
    }
    //cout << dp[0][0] << '\n';
    ii x = ii(0, 0);
    while (x.fi != n && x.sc != m) {
        ii y = p[x.fi][x.sc];
        if (y.fi == x.fi+1 && y.sc == x.sc+1)
            cout << s[x.fi];
        x = y;
    }
    cout << '\n';
}



Measured memory_bytes: 105856
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>

typedef long long ll;

using namespace std;

int main(void) {
    int N, X;
    cin >> N >> X;
    vector<int> L(N, 0);
    for (int i = 0; i < N; i++) { cin >> L[i]; }
    int D = 0;

    int count = 1;
    for (int i = 0; i < N; i++) {
        D = D + L[i];
        if (D <= X)
            count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	int cnt = 0;
	rep(i,3){
		if(s.at(i) == t.at(i)) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define INF 1e9;
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, k; cin >> n >> k;
    vector<int> x(n);
    rep(i, n) cin >> x[i];

    int ans = 1e9;

    for (int i=0; i<=n-k; i++) {
        if (x[i] < 0 && x[i+k-1] > 0) {
            int m = min(-x[i], x[i+k-1]);
            ans = min(ans, -x[i]+x[i+k-1]+m);
        } else if (x[i+k-1] <= 0) {
            ans = min(ans, -x[i]);
        } else if (x[i] >= 0) {
            ans = min(ans, x[i+k-1]);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		sc.close();
		
		int ans = 0;
		int space = X - Z;
		while(true) {
			if(space < Y + Z)break;
			ans++;
			space -= Y + Z;
		}
		System.out.println(ans);
	}
}


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

using namespace std;
using ll = long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  ll n, c = 0;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  REP(i, n) {
    if (i == a[a[i] - 1] - 1) {
      c++;
      a[a[i] - 1] = -1;
      a[i] = -1;
    }
  }

  OUT(c);

  return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<vc> vcc;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define in insert
    #define sz(v) v.size()
    #define mina(a,b) (a)=min((a),(b));
    #define maxa(a,b) (a)=max((a),(b));
    const int INF = 1e9 + 5;
    
    void solve(){
        int a,b,c; cin>>a>>b>>c;
        a-=b;
        cout<<max(c-a,0);
    }
    int main(){
        int T=1;
        //cin>>T;
        for(int i = 0; i < T; i++) solve(); 
    }

Measured memory_bytes: 256
def f(n, x, a, b)
  if n == 0
    return 0 if x <= 0
    return 1
  elsif x <= 1 + a[n-1]
    return f(n-1, x-1, a, b)
  else
    return b[n-1] + 1 + f(n-1, x-2-a[n-1], a, b)
  end
end

n, x = gets.chomp.split.map(&:to_i)

a = [1]
b = [1]

n.times do |i|
  a.push(a[i] * 2 + 3)
  b.push(b[i] * 2 + 1)
end

puts f(n, x, a, b)

Measured memory_bytes: 1788
N = 0
N,M,C = map(int,input().split())
B = [input().split()]
A = [input().split() for i in range(N)]
count =0
for i in range(N):
    Sum = 0
    for j in range(M):
        Sum += int(A[i][j])*int(B[0][j])
    if Sum + C > 0:
        count += 1
print(count) 


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

c = 1
R = 0
for i in range(N+1):
    x = X[i]
    R += c
    c -= x
    mx -= x
    if c < 0:
        print(-1)
        break
    c = min(c*2, mx)
else:
    print(R)


Measured memory_bytes: 83480
#include <cstdio>
#define MAXN 55
#define INF 0x7fffffff
int a[MAXN][26];
char temp[MAXN];

int main() {
	int n, mn;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%s", temp);
		for(int j = 0; temp[j] != '\0'; j++) 
			a[i][temp[j] - 'a']++;
	}
	for(int i = 0; i < 26; i++) {
		mn = INF;
		for(int j = 0; j < n; j++) {
			if(a[j][i] == 0) {
				mn = 0;
				break;
			}
			if(a[j][i] < mn) mn = a[j][i];
		}
		for(int j = 0; j < mn; j++)
			printf("%c", i+'a');
	}	
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for(ll i=0;i<n;i++) {
    ll tmp;
    cin >> tmp;
    a[i]={tmp,i};
  }
  sort(a.rbegin(),a.rend());
  mat dp(n+1,vec(n+1));
  for(ll i=1;i<=n;i++) {
    ll id=a[i-1].second;
    ll v=a[i-1].first;
    for(ll j=0;j<i;j++) {
      dp[i][j]=max(dp[i][j],dp[i-1][j]+abs((n-1-(i-1-j))-id)*v);
      dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]+abs(j-id)*v);
    }
  }
  ll ans=0;
  for(ll i=0;i<=n;i++) {
    ans=max(ans,dp[n][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34668
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read::<usize>();
    let mut ans = 0;
    let mut sum = 0;
    for i in 1..(x + 1) {
        if sum >= x {
            break;
        }
        sum += i;
        ans += 1;
    }
    println!("{}", ans);
}


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

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

    int n; cin >> n;

    int t = (n%100)%10;

    if (t==0||t==1||t==6||t==8) cout << "pon";
    else if (t==3) cout << "bon";
    else cout << "hon";

    cout << "\n";
    

    return 0;
}

Measured memory_bytes: 3648