akhauriyash/Code-Regression huggingface dataset:
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)

for i in range(H + W):
    factorials[i+1] = factorials[i] * (i + 1) % MOD

inv_factorials = list(map(lambda n: pow(n, MOD - 2, MOD), factorials))

def modcomb(m, n, mod):
    return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
 
total = modcomb(H + W - 2, W - 1, MOD)
 
for i in range(B):
    total -= modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD
    total %= MOD
 
print(total)

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

const int INF = 1001001001;
int min_ope[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;
    int n = s.length();
    
    fill(min_ope, min_ope + n, INF);
    bool flag = false;
    for(int i = 0; i < n-1; ++i){
        if(s[i] != s[i + 1]){
            min_ope[i] = max(i + 1, n - i - 1);
            flag = true;
        }
    }
    
    if(!flag){
        cout << n << endl;
        return 0;
    }
    
    int ans = *min_element(min_ope, min_ope + n);
    cout << ans << endl;
}

Measured memory_bytes: 848
#include <cstdio>
#include <cstring>
#include <cstdlib>
int main()
{
	char a,b;
	char c[]={'A','B','C','D','E','F'};
	while(~scanf("%s %s",&a,&b)){
		int flagx=0;
		int flagy=0;
/*		for(int i=0;i<6;i++){
			if(a==c[i])flagx=1;
			if(b==c[i])flagy=1;
		}
		if(flagx==1&&flagy==1){	*/
			if(a>b) printf(">\n");
			if(a<b) printf("<\n");
			if(a==b) printf("=\n");
		//}
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){

	int n, m;

	while (1){

		cin >> n;
		if (n == 0) break;

		for (int i = 0; i < 9; i++){
			cin >> m;
			n -= m;
		}
		cout << n << endl;
	}

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int a = -1, z;

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'A' && a == -1) {
      a = i;
    }
    else if(s[i] == 'Z') {
      z = i;
    }
  }
  cout << z-a+1 << endl;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        while(true){
        int h = input.nextInt();
        int w = input.nextInt();
        if(h==0&&w==0){
            break;
        }
        for(int n = 0; n < h; n++){
        for(int i = 0; i < w; i++){
            System.out.print("#");
        }
        System.out.println();
        }
        System.out.println();
        }
    }
}

Measured memory_bytes: 36272
///                ..:: In The Name Of God ::..
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
#include <bits/stdc++.h>

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    if(K == 1){
        cout << 0 << endl;
    }
    else cout << N-K << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;

int main(){
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl; 
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll>v;
    ll x;
    for (ll i = 0; i < n; i++) {
        cin >> x;
        v.push_back(x);
    }
    for (int i  = n - 1; i  >= 0; i = i - 2) {
        cout << v[i] << " ";
    }
    if (n % 2 == 0) {
         for (int i  = 0; i  < n; i = i + 2) {
        cout << v[i] << " ";
    }
    }
    else {
         for (int i  = 1; i < n; i = i + 2) {
            cout << v[i] << " ";
    }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int flag = 0;
    for(int i=1; i<1000; i++){
        if((b*i+c)%a==0){
            printf("YES");
            flag = 1;
            break;
        }
    }
    if(flag == 0 ) printf("NO");
    return 0;
}

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

int main() {
    int K; cin >> K;
    rep(i, K) cout << "ACL";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int> coin(m);
    for(auto&e:coin){
        scanf("%d",&e);
    }
    int INF=1<<18, MAX_N=50001;
    vector<int> dp_coin(MAX_N);
    fill(dp_coin.begin(), dp_coin.end(), INF);
    dp_coin[n]=0;
    for(int i=n;i>0;i--){
        for(int j=0;j<m;j++){
            if(i>=coin[j]){
                dp_coin[i-coin[j]]=min(dp_coin[i]+1,dp_coin[i-coin[j]]);
            }
        }
    }
    printf("%d\n",dp_coin[0]);
    return 0;
}

Measured memory_bytes: 1260
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(m)]
bc.sort(reverse=True, key=lambda x: x[1])

bcs = []
for b, c in bc:
    if len(bcs) > n: break
    bcs.extend([c]*b)

a.extend(bcs)
a.sort(reverse=True)
print(sum(a[:n]))


Measured memory_bytes: 25052
#include <bits/stdc++.h>
using namespace std;
long long int jrr[100000];
long long int jump(long long int i,long long int n,long long int arr[])
{
	if(i>=n-1)
	return 0;
	else if(jrr[i]!=-1)
	return jrr[i];
	else
    {   // cout<<arr[i]<<" i"<<endl;
    	jrr[i]=min(abs(arr[i+1]-arr[i])+jump(i+1,n,arr),
    	abs(arr[i+2]-arr[i])+jump(i+2,n,arr));
    	return jrr[i];
    }
	
}

int main() {
	// your code goes here
	long long int n;
	cin>>n;
	long long int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	memset(jrr,-1,sizeof(jrr));

	cout<<jump(0,n,arr);
	return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d; cin>>a>>b>>c>>d;
if((a>=0&&b>=0&&c>=0&&d>=0)||(a<0&&b>=0&&c>=0&&d>=0)||(a>=0&&b>=0&&c<0&&d>=0)) cout << b*d;
else if((a>=0&&b>=0&&c<0&&d<0)||(a<0&&b<0&&c>=0&&d>=0)) cout << max(b*c,a*d);
else cout << max(a*c,b*d);
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> s2t(26, -1), t2s(26, -1);
	rep(i, s.size()){
		int ss = s[i] - 'a', tt = t[i] - 'a';
		if(s2t[ss] == -1 || s2t[ss] == tt) s2t[ss] = tt;
		else{
			cout << "No" << endl;
			return 0;
		}
		if(t2s[tt] == -1 || t2s[tt] == ss) t2s[tt] = ss;
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
// Copyright 2020 Tsutomu ISHIKAWA
// Author: Tsutomu ISHIKAWA

#include <iostream>
using namespace std;
int main() {
    int n;
    int a, sum;
    std::cin >> n;
    sum = 0;
    for (int i = 1; i < n; i++) {
        a = (n-1) / i;
        sum += a;
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  auto sa = suffix_array(S);
  auto lcp = lcp_array(S, sa);
  long ans = N - sa.at(0);
  for (int i = 0; i + 1 < N; i++) {
    ans += N - sa.at(i + 1) - lcp.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 15668
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        System.out.println((x-a) % b);
    }
}


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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    ll N = 0;
    ll ans = 0;
    cin >> N;
    for (ll i = 0; i <= N; ++i)
    {
        if (!(i % 3 == 0 || i % 5 == 0))
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    map<string,int> m;
    rep(i,n) {
      string s;
      int x;
      cin >> s >> x;
      m[s]=x;
    }
    cin >> n;
    map<string, vector<string> > m2;
    rep(i,n) {
      string s;
      cin >> s;
      int k;
      cin >> k;
      vector<string> v(k);
      rep(j,k) cin >> v[j];
      m2[s]=v;
    }
    while(1) {
      bool update=false;
      tr(it,m2) {
	vector<string> v=it->S;
	int sum=0;
	rep(i,v.size()) sum+=m[v[i]];
	if(m[it->F]>sum) {
	  update=true;
	  m[it->F]=sum;
	}
      }
      if(!update) break;
    }
    string s;
    cin >> s;
    pr(m[s]);
  }
  return 0;
}


Measured memory_bytes: 1232
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Scanner(System.in)
    val n = s.nextInt()
    val m = s.nextInt()
    val c = s.nextInt()
    val bs = ArrayBuffer[Int]()
    (0 until m).foreach { _ =>
      bs += s.nextInt()
    }
    var res = 0
    (0 until n).foreach { _ =>
      val as = ArrayBuffer[Int]()
      (0 until m).foreach { _ =>
        as += s.nextInt()
      }
      if ((as zip bs).map(t => t._1 * t._2).sum + c > 0) {
        res += 1
      }
    }
    println(res)
  }
}


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

#define int long long
#define pb emplace_back
#define f(i,n) for(int i=0 ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	int a[n];
	f(i,n)  cin >> a[i];
	int ans = 0;
	for(int i =1 ; i<n-1 ; i++)
	{
		if((a[i]>a[i-1] && a[i]<a[i+1]) || (a[i]<a[i-1] && a[i]>a[i+1]))
			ans++;
	}
	cout << ans;
}







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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  for (int i = 1; i <= B; i++) {
    if (i*A % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

ll power(ll a,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1)
            res=res*a;
        n=n/2;
        a=a*a;
    }
    return res;
}
int main()
{
    ll n,k;
    cin>>n>>k;
    cout<<k*power(k-1,n-1)<<"\n";
}


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else 
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------


void solve()
{
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++)
  {
  	 cin>>s[i];
  }
  int cnt1 = 0,cnt2 = 0,cnt3 = 0,cnt4 = 0;
  for(int i=0;i<n;i++)
  {
  	  if(s[i] == "AC")
  	  {
  	  	cnt1++;
  	  }
  	  else if(s[i] == "WA")
  	  {
  	  	 cnt2++;
  	  }
  	  else if(s[i] == "TLE")
  	  {
  	  	 cnt3++;
  	  }
  	  else if(s[i] == "RE")
  	  {
  	  	 cnt4++;
  	  }
  }
  cout<<"AC"<<" x "<<cnt1<<endl;
  cout<<"WA"<<" x "<<cnt2<<endl;
  cout<<"TLE"<<" x "<<cnt3<<endl;
  cout<<"RE"<<" x "<<cnt4<<endl;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
    
}

Measured memory_bytes: 6660
#include<stdio.h>

int main(void){

	int w,sum=0;
	
	for(;;){
		scanf("%d",&w);
		if(w == -1 ) break;
		sum = 0;
		if(w<11){
			sum += 1150;
		}else if(w <21){
			sum += 1150 + (w-10) * 125;
		}else if(w <31){
			sum += 1150 + 10 * 125 + (w-20) *140;
		}else if(30<w){
			sum += 1150 + 10 * 125 + 10 * 140 + (w-30) *160;
		}
	
	printf("%d\n",4280 - sum);
	}
	
	
	return 0;
}

Measured memory_bytes: 600
n = int(input())

A = [[0]*n for _ in range(n)]

for _ in range(n):
    tmp = list(map(int, input().split()))
    u = tmp[0]
    vs = tmp[2:]
    for v in vs:
        A[u-1][v-1] = 1
        
for i in range(n):
    print(' '.join(map(str, A[i])))


Measured memory_bytes: 5672
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string N;
    cin >> N;
    string M(N);
    reverse(ALL(M));
    
    if (N==M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int c = 1;
    for (int i=0; i<n; i++){
        if(c * 2 >= c + k) {
            c += k;
        } else {
            c *= 2;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int A[200010],B[200010],num[200010];
int N,M,W,C,D,E,G,K,X;
int ans,ans2,sum,sum2,cnt,cnt2,Max=0,Min=INF;
string S[110],T;
vector<int> V={1},V2={1};
set<int> U;
map<int,int> H;
bool F,Q[200010];

int f(int n,int x){
	if(n==0){
		if(x<=0){
			return 0;
		}
		else{
			return 1;
		}
	}
	else if(x<=1+V[n-1]){
		return f(n-1,x-1);
	}
	else{
		return V2[n-1]+1+f(n-1,x-2-V[n-1]);
	}
}

signed main(){
	cin>>N>>X;
	REP(i,N){
		V.push_back(V[i]*2+3);
		V2.push_back(V2[i]*2+1);
	}
	cout<<f(N,X)<<endl;
	return 0;
}
//1 1
//5 3
//13 7


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

const int INF = 1000000000;

int main()
{
	int n;
	while(cin >> n){

		if(n == 0)
			break;

		int T[10][10];
		for(int i = 0;i < 10; i++){
			for(int j = 0;j < 10; j++){
				if(i == j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;	//町の数

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

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}

		for(int k = 0;k < m;k++){
			for(int i = 0;i < m;i++){
				for(int j = 0;j < m;j++){
					if(T[i][j] > T[i][k] + T[k][j]){
						T[i][j] = T[i][k] + T[k][j];
					}
				}
			}
		}
		int M[10];
		for(int i = 0;i < m;i++){
			M[i]=0;
			for(int j = 0;j < m;j++){
				M[i] += T[i][j];
			}
		}
		
		int index = 0;
		for(int i = 1;i < m;i++){
			if(M[index] > M[i]){
				index = i;
			}
		}
		cout << index << ' ' << M[index] << endl;
	}
	return 0;
}


Measured memory_bytes: 1160
#include<stdio.h>
#define mod 1000000007;
typedef long long int ll;

int main(void){
    int n,m;
    scanf("%d%d", &n,&m);
    ll check[n+1];
    for(int i=0; i<n; i++){check[i] = 0;}
    for(int i=0; i<m; i++){
        int a;
        scanf("%d", &a);
        check[a] += 1;
    }

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

    dp[0] = 1;
    if(check[1] == 1){
        dp[1] = 0;
    }else{
        dp[1] = 1;
    }

    for(int i=2; i<n+1; i++){
        if(check[i] == 1){
            dp[i] = 0;
        }else{
            dp[i] = (dp[i-1]+dp[i-2])%mod;
        }
    }

    printf("%lld\n", dp[n]);

    return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string week[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
string Week[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
string nums[7]={"seven","six","five","four","three","two","one"};

int main()
{
	string s;
	cin >> s;
	for(int i(0);i<7;++i)
	{
		if(week[i]==s)
		{
			cout << 7-i << endl;
//			cout << "It is " << Week[i] << " today, and ";
//			if(i==6)
//				cout << "tomorrow will be Sunday.";
//			else
//			{
//				cout << nums[i] << " days later, it will be Sunday";
//				if(i==0)
//					cout << " again.";
//				else
//					cout <<".";
			//}
		}
	}
	return 0;
}


Measured memory_bytes: 256
/*
@author James Fisher
@date
@version
*/

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] array = new int[n + 1];

        for(int i = 1; i <= n; i++){
            array[i] = scanner.nextInt();
        }

        for(int i = 1; i <= n; i++){
            System.out.printf("node %d: key = %d, ", i, array[i]);
            if(i/2 > 0)
                System.out.printf("parent key = %d, ", array[i/2]);
            if(2*i <= n)
                System.out.printf("left key = %d, ", array[2*i]);
            if((2*i + 1) <= n)
                System.out.printf("right key = %d, ", array[2*i+1]);

            System.out.print("\n");
        }
    }
}



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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if( (a==5 && b==7 && c==5)||(a==7 && b==5 && c==5)||(a==5 && b==5 && c==7) ) {
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  int x[n+1]={};
  int y[n+1]={};
  int h[n+1]={};

  bool flag=0;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]==0) flag=1;
  }


  if(!flag){
    for(int i=0;i<=100;i++){
      for(int j=0;j<=100;j++){
        int z=abs(x[0]-i)+abs(y[0]-j)+h[0];
        bool flag=0;
        for(int k=0;k<n;k++){
          if(h[k]!=max(0,z-abs(x[k]-i)-abs(y[k]-j))) flag=1;
        }
        if(!flag){
          cout<<i<<" "<<j<<" "<<z<<endl;
          return 0;
        }
      }
    }
  }else{
    for(int i=0;i<=200;i++){
      for(int j=0;j<=100;j++){
        for(int k=0;k<=100;k++){
          int l;
          for(l=0;l<n;l++){
            if(h[l]!=max(0,i-abs(x[l]-j)-abs(y[l]-k))) break;
          }
          if(l==n){
            cout<<j<<" "<<k<<" "<<i<<endl;
            return 0;
          }
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
require 'set'
def scan_field f
  loc_dic = {}
  f.each_with_index {|row, rowi|
    row.each_with_index {|v, coli|
      loc_dic[v] = (loc_dic[v] || [[INF, INF], [-INF, -INF]]).zip([:min, :max]).map {|(pos, p)| pos.zip([rowi, coli]).map(&p) }  unless v == '.'
    }
  }

  remain = Set.new loc_dic.keys
  unsafe = false
  until remain.empty?
    before_remain = remain.dup
    remain.each {|v|
      case scan_object f, loc_dic[v], v, remain
      when :safe
        remain.delete v
      when :unsafe
        return :unsafe
      end
    }
    return :unsafe if remain == before_remain
  end
  :safe
end

def scan_object f, loc, expect, remain
  row_range = loc[0][0]..loc[1][0]
  col_range = loc[0][1]..loc[1][1]
  row_range.each {|rowi|
    col_range.each {|coli|
      v = f[rowi][coli]
      return :unsafe if v == '.'
      return :indeterminate if v != expect && remain.include?(v)
    }
  }
  return :safe
end

INF = 2 << 32
gets.to_i.times {
  h, w = gets.split(' ').map(&:to_i)
  f = h.times.map { gets.chomp.each_char.to_a }
  puts(scan_field(f) == :safe ? 'SAFE' : 'SUSPICIOUS')
}

Measured memory_bytes: 6212
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int vis[200006];
vector<int>g[200006];
int mx,c;
void func(int n)
{
  int i;
  vis[n]=1;
  c++;
  mx=max(c,mx);
  for(i=0;i<g[n].size();i++)
  {
    if(vis[g[n][i]]==0) func(g[n][i]);
  }

}
int main()
{
  int n,i,j,x,y,k;
  cin>>n>>k;
  for(i=1;i<=k;i++) 
  {
    cin>>x>>y;
    g[x].pb(y);
    g[y].pb(x);
  }
  for(i=1;i<n;i++)
  {
    if(vis[i]==0)
    {
      c=0;
      func(i);
    }
  }
  cout<<mx<<endl;
}

Measured memory_bytes: 21504
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double pi = acos(-1);
    double th = 2.0 * pi * abs((h * 60 + m) / (60.0 * 12.0) - m / 60.0);
    if (th > pi) {
        th = 2 * pi - th;
    }
    double res = pow(b - a * cos(th), 2.0) + pow(a * sin(th), 2.0);
    res = sqrt(res);
    cout << fixed << setprecision(15) << res << newl;
}

Measured memory_bytes: 4168
n = gets.strip.to_i
array = []
n.times do
  array << gets.strip.to_s
end

hash = Hash.new(0)
array.sort.each { |word| hash[word] += 1 }

highest_count = hash.max_by {|k, v| v}[1]

output_hash = hash.select{|k, v| v == highest_count}

output_hash.keys.each do |key|
  puts key
end




Measured memory_bytes: 56140
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	while(cin>>n,n){
		string str;
		cin>>str;
		for(int i =0;i < n;i++){
			int j = 0;
			string ans="";
			while(j<str.length()){
				int cnt =1;
				while(j <str.length()-1&&str[j]==str[j+1]){
					cnt++;
					j++;
				}
				stringstream ss;
				ss <<cnt;
				ans +=ss.str();
				ans +=str[j];
				j++;
			}
			str =ans;
		}
		cout <<str<<endl;
	}

	return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    ll ans = 0;
    vector<ll> B(N-1);
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }

    ans += B[0] + B[N-2];
    for (int i = 1; i < N-1; i++) {
        ans += min(B[i], B[i-1]);
    }

    cout << ans << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#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-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
 
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int N;cin>>N;
	vector<int>A(N);
	ll sum=0;
	REP(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	ll cum=0;
	ll dif=INF;
	REP(i,N){
		cum+=A[i];
		dif=min(dif,abs(sum-cum-cum));
	}
	print(dif);
}
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 1792
/*https://atcoder.jp/contests/abc079/tasks/abc079_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	long long l[87];
	l[0] = 2, l[1] = 1;
	for (int i = 2; i <= n; i++)
		l[i] = l[i - 2] + l[i - 1];
	cout << l[n];
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    int N;
    cin >> N;
    vector<long long> L(N);
    for(int i = 0; i < N; ++i)
        cin >> L[i];
    sort(L.begin(), L.end()); // L をソートしておく (二分探索に必要)

    long long res = 0;

    // a と b を固定
    for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j) {
            // c の動ける範囲の右端を求める
            int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

            // c の動ける範囲は、[j+1, k)
            res += max(k - (j + 1), 0);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll n;
multiset <ll> st;
int main(){
	fastio;
	ll t, k, ans = 0;
	cin >> n;
	for (ll i = 0; i < n; i++) cin >> t, st.insert(t);
	while (st.size() > 1){
		auto it = st.end();
		it--; t = *it;
		st.erase(it);
		for (k = 1; k <= t; k *= 2);
		it = st.find(k - t);
		if (it != st.end()){
			st.erase(it); ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9600
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void solve(){
	int n,ans=0;
	cin >> n;
	vector<pair<int,int> > red(n),blue(n);
	for(int i = 0 ;i < n ; i++)cin>>red[i].fi>>red[i].se;
	for(int i = 0 ;i < n ; i++)cin>>blue[i].fi>>blue[i].se;
	sort(all(red));
	sort(all(blue));
	VI u(n,0);
	for(int i=0;i<n;i++){
		int mx=-1e9,tar=-1;
		for(int j=0;j<n;j++){
			if(u[j])continue;
			if(red[j].fi<blue[i].fi&&red[j].se<blue[i].se&&red[j].se>mx){
				mx = red[j].se;
				tar = j;
			}
		}
		if(tar!=-1){
			ans++;
			u[tar]=1;
		}
	} 
	cout<<ans<<endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

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

int main(){
  int c=0;
  string s;
  cin>>s;
  REP(i,4) if(s.at(i)=='+') c++;
  else c--;
  cout<<c;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(char c : s){
        if (c == '1') ans++;
    }
    cout << ans << endl;
}

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

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

vector<int> prime;
bool is_prime[1000010];
int min_factor[1000010];
int sieve(int n) {
  fill(is_prime + 2, is_prime + 1000010, true);
  min_factor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0) min_factor[j] = i;
      }
    }
  }
  return prime.size();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(1000000);
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; prime[i] <= n - prime[i]; i++) {
      ans += is_prime[n - prime[i]];
    }
    cout << ans << endl;
  }

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
const int MAX_N = 110000; 
constexpr double EPS = 1E-11;

using namespace std;

//fixed << setprecision(10)

int main() {
	int n; cin >> n;
	
	vector<int>ans(26, 100000);
	
	rep(i, n) {
		vector<int>count(26);
		string s; cin >> s;
		rep(j, s.length()) {
			rep(c, 26) {
				if (s[j] == 'a' + c) {
					count[c]++;
				}
			}
		}
		rep(k, 26) {
				ans[k] = min(ans[k], count[k]);
			}
	}
	rep(i, 26) {
		rep(j, ans[i]) {
			cout << char('a' + i);
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = 998244353;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
const int maxN = 5 * (int)1e6 + 100;
int fact[maxN], invfact[maxN], inv[maxN];
int cnk(int a, int b) {
    if (a < 0 || b < 0 || a < b) return 0;
    return mult(fact[a], mult(invfact[b], invfact[a - b]));
}
int n, m;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    fact[0] = inv[1] = fact[1] = invfact[1] = invfact[0] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(inv[mod % i], mod - mod / i);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
    int total = cnk(3 * m + n - 1, n - 1);
    int coef = mult(n, cnk(3 * m - 2 * m - 1 + n - 1, n - 1));
    total = sub(total, coef);
    int add = 0;
    for (int coef = 0; coef < m; coef++) {
        int odd = 3 * m - 2 * coef;
        add = sum(add, mult(cnk(n, odd), cnk(coef + n - 1, n - 1)));
    }
    total = sub(total, add);
    cout << total;
    return 0;
}

Measured memory_bytes: 58880
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int H,W; //ピクセルの縦と横の長さ
cin >>H >>W;
string a;

//一番上の行と下の行はWの長さ+2の#
//それ以外の各行の先頭に#、a、末尾に#を入れる
//それをH回繰り返す。その都度にaの入力受付

//一番上の#
for(int i;i<W+2;i++) cout <<"#";
cout <<endl;

//間
for(int i ; i<H;i++)
{
cin >>a;
cout <<"#" <<a <<"#" <<endl;

}

//一番下の#
for(int i;i<W+2;i++) cout <<"#";
cout <<endl;

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(75)
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll x=0;int i,n;cin>>n;vi v(n),d(n);for(i=0;i<n;i++) cin>>v[i],x^=(i<n-1?v[i]:0);
	d[n-1]=x;for(i=0;i<n-1;i++) d[i]=v[i]^x^v[n-1];
	print(d);
}



Measured memory_bytes: 6364
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<ll> > cake(N, vector<ll>(3, 0));
	for (int i = 0; i < N; i++)for (int j = 0; j < 3; j++)cin >> cake[i][j];

	ll ans = -INF_LL;
	vector<ll> tmp(N);
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < N; j++) {
			ll a = 0;
			if (i & 1)a += cake[j][0];
			else a -= cake[j][0];
			if (i & 2)a += cake[j][1];
			else a -= cake[j][1];
			if (i & 4)a += cake[j][2];
			else a -= cake[j][2];

			tmp[j] = a;
		}
		ll b = 0;
		sort(tmp.begin(), tmp.end(), greater<ll>());
		for (int j = 0; j < M; j++) b += tmp[j];
		ans = max(b, ans);
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define vi vector<int>
#define ppii pair<pii>

using namespace std;
const int maxn=1e5+5;

int n;
vi arr;
int dp[maxn];

int dfs(int pos)
{
    if(pos==n){return 0;}

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

    int ans=(1<<29);

    if(pos<n)
        ans=min(ans,dfs(pos+1) + abs(arr[pos]-arr[pos+1]));
    if(pos<n-1)
        ans=min(ans,dfs(pos+2) + abs(arr[pos]-arr[pos+2]));
    dp[pos]=ans;

    return ans;
}

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

    cin>>n;

    arr=vi(n+1);

    for(int i=1;i<=n;i++)
        cin>>arr[i];

    memset(dp,-1,sizeof dp);

    cout<<dfs(1);

    return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dp[51][2501];
int N,A;
int x[50];
signed main(){
    cin>>N>>A;
    rep(i,N)cin>>x[i];
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=i+1;j>=0;j--){
            for(int k=0;k<=2500;k++){
                if(j&&k-x[i]>=0)dp[j][k]+=dp[j-1][k-x[i]];
            }
        }
    }

    int ans=0;
    for(int i=1;i<=N;i++)ans+=dp[i][i*A];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for(int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
typedef vector<vl> vvl;

template<typename T> void maxself(T &a, T &b){a = max(a, b);};
template<typename T> void minself(T &a, T &b){a = min(a, b);};

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

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int conditions[10];
int s[10], c[10];

int main(){

	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	int limit = pow(10, n);
	for(int i = 0; i < m; i++){
		cin >> s[i] >> c[i];
	}
	int ans = INF;
	for(int i = 0; i < limit; i++){
		string str = to_string(i);
		if(str.length() == n){
			bool flag = true;
			for(int i = 0; i < m; i++){
				if(str[s[i]-1]-'0' != c[i]){
					flag = false;
					break;
				}
			}
			if(flag){
				ans = stoi(str);
				break;
			}
		}
	}
	cout << ((ans == INF) ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

int main()
{
    int L, R;
    cin >> L >> R;
    if(R - L + 1 >= 2019){
        cout << "0" << endl;
    }
    else{
        vector<int> A;
        rep(i, L, R+1)
            A.push_back(i%2019);
        int ans = inf;
        rep(i, 0, A.size())
            rep(j, i+1, A.size())
                ans = min(ans, (A[i]*A[j])%2019);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h;
  cin >> h;
  ll res = 0;
  ll tmp = 0;
  while(true){
    if(h >= 1){
      res += pow(2, tmp);
      tmp++;
      h /= 2;
    }else{
      break;
    }
  }

  cout << res << endl;


}


Measured memory_bytes: 512
import java.util.*;
import static java.lang.System.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A <= 8 && B <= 8) {
            out.print("Yay!");
        } else {
            out.print(":(");
        }
        
    }
}


Measured memory_bytes: 21716
#include <iostream>

int main(void) {
	int N;
	std::string arare;
	bool isfour = false;
	// stdin
	std::cin >> N;
	for(int i = 0; i < N; ++i) {
		std::cin >> arare;
		if(arare == "Y") {
			isfour = true;
		}
	}
	// stdout
	std::cout << (isfour ? "Four" : "Three") << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   ll n;
   cin >> n;
   string ans = "";
   while (n > 0){
      if (n % 26 == 0){
         ans += 'z';
         n--;
      }
      else ans += char('a'+(n%26)-1);
      n /= 26;
   }
   reverse(ans.begin(),ans.end());
   cout << ans << endl;
} 

Measured memory_bytes: 3620