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

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

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

int main() {
	ll n; cin >> n;
	int a, b; cin >> a >> b;

	if ((a-b)%2) cout << "Borys" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
std::vector<string> x,y,z,r;
ll n,ans=0;
cin>>n;
string s;
for (ll i = 0; i < n; ++i)
{
  cin>>s;
  for (ll i = 0; i < s.size()-1; ++i)
  {
    if(s[i]=='A' and s[i+1]=='B')
      ans++;
  }
  if(s[0]=='B' and s[s.length()-1]=='A')
    x.pb(s);
  else if(s[0]=='B')
    y.pb(s);
  else if(s[s.length()-1]=='A')
    z.pb(s);
else r.pb(s);
}
if(z.size()>0)
{ 
    if(x.size()>0)
    {
  ans +=x.size();
  //  c(ans);
    z.pop_back();
    if(y.size()>0)
    {
      ans++;
      y.pop_back();
    }
    }
    ans +=min(z.size(),y.size());

}
else 
{
  if(x.size())
  {
ans += (x.size()-1);
if(y.size()>0)
  ans++;
}
}
c(ans);

}

signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

struct Sushi {
  ll neta;
  ll kiso;
  Sushi(ll neta, ll kiso) : neta(neta), kiso(kiso) {}
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<Sushi> s;
  REP(i, n) {
    ll t, d;
    cin >> t >> d;
    t--;
    s.push_back(Sushi(t, d));
  }
  sort(ALL(s), [](Sushi x, Sushi y) { return x.kiso > y.kiso; });
  // score[i] = ネタがi種類のときの最大値
  vector<ll> score(n + 1, -1);
  vector<ll> cnt(n, 0);
  ll cur = 0, var = 0;
  REP(i, k) {
    cur += s[i].kiso;
    cnt[s[i].neta]++;
    if (cnt[s[i].neta] == 1) {
      var++;
    }
  }
  score[var] = cur;
  ll l = k - 1, r = k;
  while (0 <= l && r < n) {
    if (cnt[s[l].neta] == 1) {
      l--;
      continue;
    }
    while (r < n && cnt[s[r].neta] > 0) {
      r++;
    }
    if (r == n) {
      break;
    }
    cnt[s[l].neta]--;
    cur -= s[l].kiso;
    cnt[s[r].neta]++;
    cur += s[r].kiso;
    var++;
    score[var] = cur;
    l--;
    r++;
  }

  ll ans = 0;
  FOR(i, 1, n + 1) {
    if (score[i] != -1) {
      score[i] += i * i;
      ans = max(ans, score[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// const ll MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
// const ll PRIME = 1e9 + 7;
// typedef pair<int,pair<int,int> >  ppi;

void solve()
{
    int n;
    cin >> n;
    int a[n];
    int mx[n];
    int m = 0;
    fr(i, n)
    {
        cin >> a[i];
        if (m < a[i])
        {
            m = a[i];
        }
        mx[i] = m;
    }
    int ans=0;
    fr(i,n)
    {
        ans+=mx[i]-a[i];
    }
    cout<<ans;
}
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 6760
#include <iostream>
using namespace std;
typedef long long ll;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
const int MAX = 510000;
const int MOD = 1e9+7;


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

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

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

int main() {
    // 前処理
    COMinit();

    // 計算例
    // cout << COM(10, 3) << endl;

    int n,k;
    cin >> n >> k;

    REP(i, 1, k+1) {
        // if (i > k || n-k < i-1 ) break;
        // ll kuroamari = COM(k-1, i-1);
        // ll siroamari = COM(w+1, i);
        ll ans = ((COM(k-1, i-1)%MOD) * (COM(n-k+1, i)%MOD))%MOD;

        // 計算例
        cout << ans << endl;

    }
}

Measured memory_bytes: 12160
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  unsigned long long result = 0;
  unsigned long long maxTall = 0;
  unsigned long long A;
  
  cin >> maxTall;
  for(int i = 0; i < N -1 ; i++)
  {
    cin >> A;
    if(maxTall > A)
    {
      result += (maxTall - A);
    }
    if(maxTall < A)
    {
      maxTall = A;
    }
  }
  
  cout << result;
  
  return 0;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner( System.in );

        int health = Integer.parseInt(scan.next()); 
        int varN   = Integer.parseInt(scan.next());
        ArrayList<Integer> attack = new ArrayList<Integer>();
        for(int i=0; i<varN; i++){
            attack.add( Integer.parseInt( scan.next() ) );
        }

        boolean flag = false;

        for(int i=0; i<varN; i++){
            health -= attack.remove(0);

            if(health <= 0){
                flag = true;
                break;
            }
        }

        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

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

int main() {
  while(true){
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op == '+') cout << a+b << endl;
    if(op == '-') cout << a-b << endl;
    if(op == '*') cout << a*b << endl;
    if(op == '/') cout << a/b << endl;
    if(op == '?') return 0;
  }
}



Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    long long n;
    scanf("%lld",&n);
    long long n1=n;
    int count=0,a[20],ans;
    bool nine=false;
    while (n1!=0){
        a[count]=n1%10;
        n1/=10;
        count++;
    }
    ans=a[count-1];
    for (int i=1; i<count; i++){
        if (nine==true){
            ans+=9;
        } else if (a[count-1-i]==9){
            ans+=9;
        } else {
            ans+=8;
            nine=true;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n, x, y, ans[2005];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>n>>x>>y;
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			int mn=j-i;
			mn=min(abs(x-i)+1+abs(y-j), mn);
			mn=min(abs(y-i)+1+abs(x-j), mn);
			ans[mn]++;
		}
	}
	for(int i=1; i<=n-1; i++) printf("%d\n", ans[i]);
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	int z[100001]={0};
	for(int i=2;i<100000;i++){
		if(i%2==0&&i!=2){
			goto end;
		}
		else if(i%3==0&&i!=3){
			goto end;
		}
		else{
			for(int j=1;j<pow(i,0.5)/6+3;j++){
				if(i%(6*j-1)==0&&i!=6*j-1){
					goto end;
				}
				if(i%(6*j+1)==0&&i!=6*j+1){
					goto end;
				}
			}
		}
		z[i]=1;
		end:;
	}
	int m;
	double a,b;
	while(cin>>m>>a>>b){
		if(m==0&&a==0&&b==0) break;
		int s=pow(m,0.5),p,q;
		double ab,pqm=0;
		ab=a/b;
		while(s*s/ab>=pqm||s>1){
			if(z[s]==1){
				double qq=min(s/ab,100000.00);
				for(int i=s;i<=qq;i++){
					if(z[i]==1){
						double pq=s*i;
						if(pq>pqm&&pq<=m){
							p=s;
							q=i;
							pqm=max(pq,pqm);
						}
					}
				}
			}
			s--;
		}
		cout<<p<<" "<<q<<endl;
	}
    return 0;
}

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

bool prime[100001];

int main()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i * i <= 100000; i++){
		for (int j = i * i; j <= 100000; j += i){
			prime[j] = false;
		}
	}
	
	long long m;
	int a, b;
	while (scanf("%lld %d %d", &m, &a, &b), m){
		long long rp = 0, rq = 0;
		for (long long p = 0; p <= m; p++){
			if (!prime[p]) continue;
			for (long long q = p; p * q <= m; q++){
				if (!prime[q]) continue;
				double l = (double)a / (double)b;
				double r = (double)p / (double)q;
				long long maxi = (long long)rp * rq;
				long long mul = (long long)p * q;
				if (l <= r && maxi <= mul){
					rp = p;
					rq = q;
				}
			}
		}
		printf("%lld %lld\n", rp, rq);
	}
}

Measured memory_bytes: 1296
#include<bits/stdc++.h>
 
using namespace std;
#define ll  long long
#define ld  long double
 
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5 + 5;
int main() {
  int n;cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
      cin>>arr[i];
  }
  int ans=INT_MAX;
  for(int i=1;i<=100;i++)
  {
      int p=i;
      int sum=0;
      for(int j=0;j<n;j++)
      {
          sum+=(pow(arr[j]-p,2));
      }
      ans=min(ans,sum);
  }
  cout<<ans<<endl;
    return 0;
}

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

ll solve() {
    ll N;
    string s;
    map<string, int> c;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        cin >> s;
        c[s]++;
    }
    int m = 0;
    for ( auto p : c ) {
        m = max(m, p.second);
    }
    for ( auto p : c ) {
        if ( p.second == m ) {
            cout << p.first << "\n";
        }
    }
    return 0;
}

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

Measured memory_bytes: 25216
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)

cur, prev = [0]*3, [0]*3

for _ in range(N):
    a, b, c = geta(int)
    prev, cur = cur, prev
    cur[0] = max(prev[1], prev[2]) + a
    cur[1] = max(prev[2], prev[0]) + b
    cur[2] = max(prev[0], prev[1]) + c


print(max(cur))


Measured memory_bytes: 48856
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, K;

int main(void){
    
    scanf("%d %d", &N, &K);
    
    int ans = 1;
    for(int i = 0; i < N; ++i){
        ans = (ans + K < ans * 2) ? ans + K : ans * 2;
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
S = input()

def is_palindrome(s):
  return s == s[::-1]

def is_strong_palindrome(s):
  return is_palindrome(s) \
    and is_palindrome(s[:(len(s) - 1) // 2]) \
    and is_palindrome(s[(len(s) + 3) // 2 - 1:])

if is_strong_palindrome(S):
  print('Yes')
else:
  print('No')
  

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

#define MAX_L 16
int table[MAX_L + 1][MAX_L + 1];
bool wall[MAX_L + 1][MAX_L + 1];
int a, b, n;

int main(){
	while(1){
		scanf("%d%d", &a, &b);
		if(a == 0 && b == 0) return 0;
		scanf("%d", &n);
		
		int in_x, in_y;
		
		memset(wall, 0, sizeof(wall));
		for(int i = 0; i < n; i++){
			scanf("%d%d", &in_x, &in_y);
			wall[in_x][in_y] = true;
		}
		
		memset(table, 0, sizeof(table));
		
		table[1][1] = 1;
		for(int y = 1; y <= b; y++){
			for(int x = 1; x <= a; x++){
				if(wall[x][y] || (x == 1 && y == 1)) continue;
				table[x][y] = table[x - 1][y] + table[x][y - 1];
			}
		}
		
		printf("%d\n", table[a][b]);
	}
}

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

const string button[] = {
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz",
};

void solve() {
	string line;
	cin >> line;
	char pre = '0';
	int count = -1;
	for (unsigned i = 0; i < line.size(); ++i) {
		if (line[i] == '0') {
			int key = pre - '0';
			if (key == 0) continue;
			int index = count % button[key].size();
			cout << button[key][index];
			count = -2;
		}
		count++;
		pre = line[i];
	}
	cout << endl;
}

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

Measured memory_bytes: 1212
#include <cstdio>
#define N 100005
#define ll long long
#define mod 1000000007
ll inv[N * 2] = {1};
ll s[N * 2]; 
ll quickPow(ll a, ll b) {
	a %= mod;
	ll res = 1;
	while(b) {
		if(b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}
void init () {
	s[0] = 1;
	for(int i = 1; i < N * 2; i++) s[i] = s[i-1] * i % mod;
	inv[N * 2 - 1] = quickPow(s[N * 2 - 1], mod-2);
	inv[0] = 1;
	for(int i = N * 2 - 2; i > 0; i--)
		inv[i] = (inv[i+1] * (i+1)) % mod;
}
ll C (ll m, ll n) {
	if(m < 0 || n < 0) return 1;
	return s[m] * inv[n] % mod * inv[m-n] % mod;
}

int main () {
	ll H, W, A, B, ans = 0;
	scanf("%lld %lld %lld %lld", &H, &W, &A, &B);
	init();
	for(int i = B+1; i <= W; i++) {
		ans += (C(H-A+i-2, i-1) % mod) * (C(W+A-i-1, A-1) % mod) % mod;
		ans = (ans + mod) % mod;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
typedef long long ll;
ll dp[305][305][305], MOD; 
int main()
{
	// freopen("AGC024-E.in", "r", stdin); 
	int n, k;
	scanf("%d%d%lld", &n, &k, &MOD); 
	dp[0][0][0] = 1; 
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j < k; j++)
		{
			for (int p = i; p >= 0; p--)
			{
				if (p)
					(dp[i][j][p - 1] += dp[i][j][p]) %= MOD; 
				else
					(dp[i][j + 1][i] += dp[i][j][p]) %= MOD; 
				(dp[i + 1][j][p] += dp[i][j][p] * (p + 1)) %= MOD; 
			}
		}
	}
	printf("%lld\n", dp[n][k][n]);
	return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> map(H);
    vector<vector<int>> flag(H,vector<int>(W));
    vector<int> Hdelete(H);

    for(int i=0;i<H;i++){
        cin >> map[i];
    }

    for(int i=0;i<H;i++){
        int cnt =0;
        for(int j=0;j<W;j++){
            if(map[i][j]=='.') cnt++;
        }
        if(cnt==W){
            Hdelete[i]=1;
            for(int j=0;j<W;j++){
                flag[i][j]=1;
            }
        }
    }

    for(int j=0;j<W;j++){
        int cnt =0;
        for(int i=0;i<H;i++){
            if(map[i][j]=='.') cnt++;
        }
        if(cnt==H){
            for(int i=0;i<H;i++){
                flag[i][j]=1;
            }
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(flag[i][j]==0) cout << map[i][j];
        }
        if(Hdelete[i]==0) cout << endl;
        
    }
    
}

Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("O2") 
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double

    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int INF = 1e15;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    char ch;
    void solve()
    {
        cin>>ch;
        if(isupper(ch))
            cout<<"A"<<endl;
        else
            cout<<"a"<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
buster = 0
for i in range(n):
    if a[i] >= b[i]:
        buster += b[i]
    elif a[i] + a[i+1] > b[i]:
        buster += b[i]
        a[i+1] = a[i+1] + a[i] - b[i]
    else:
        buster += (a[i] + a[i+1])
        a[i+1] = 0
print(buster)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    for(ll i=1;i<=k;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            for(ll l=1;l<=k;l++)
            {
                sum+=__gcd(i,__gcd(j,l));
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
__attribute__((always_inline)) __inline__
long long max(long long x,long long y) {
	return x>y?x:y;
}
typedef struct {int w,s,v;}node;
int cmp(const void *a,const void *b){
	return (((node*)a)->w+((node*)a)->s)-(((node*)b)->w+((node*)b)->s);
}
node b[1005];
long long dp[20005],ans;
int main(n)
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d%d%d",&b[i].w,&b[i].s,&b[i].v);
	qsort(b,n,sizeof(node),cmp);
	for (int i=0;i<n;i++) for (int j=b[i].s;j>=0;j--)
		dp[j+b[i].w]=max(dp[j+b[i].w],dp[j]+b[i].v);
	for (int i=0;i<=20000;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  map<int,ll> w;
  vector<int> v(n);
  int a;
  rep(i,n){
    cin >> a;
    v.at(i) = a; 
    if(!(w.count(a))) w[a]=1;
    else w[a] = w.at(a) + 1;
  }
  ll ans = 0;
  for(auto p:w){
    if(p.second>=2){
      ans += p.second*(p.second-1)/2;
    }
  }
  rep(i,n){
    if(w.at(v.at(i))>=2) cout << ans - w.at(v.at(i)) + 1 << endl;
    else cout << ans << endl;
  }
}


Measured memory_bytes: 10240
#include <stdio.h>

int main()
{
    int a, b, k;
    
    do{
    	scanf("%d %d", &a,&b);
    	if(a==0 && b==0)
    	break;

    k = 1;

    for(int i=1; i<=a; i++)
    {
        for(int j=1; j<=b; j++)
        {
            if(k == 1)
            {
                printf("#");
            }
            else
            {
                printf(".");
            }

            k *= -1;
        }
        printf("\n");

        if(b % 2 == 0)
        {
            k *= -1;
        }
    	
	}
    	printf("\n");
    }while(a!=0 && b!=0);
}


   


Measured memory_bytes: 1968
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    for(int i = 1; i < n; i++){
        if(s[i] != s[i - 1]) ans++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import numpy as np
n=int(input())
a=list(map(int,input().split()))
if sum(a)%((n*(n+1))//2):
    print("NO")
else:
    d=sum(a)//((n*(n+1))//2)
    c=[a[(i+1)%n]-a[i]for i in range(n)]
    for i in c:
        if i-d>0 or (i-d)%n:
            print("NO")
            break
    else:
        print("YES")

Measured memory_bytes: 31928
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
//Leap Year
public class Main{
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean f = true;
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if((a|b)==0)break;
            if(!f)System.out.println();
            f = false;
            List<Integer> l = new ArrayList<Integer>();
            for(int i=a;i<=b;i++){
                if(i%4==0&&(i%100!=0||i%400==0))l.add(i);
            }
            if(l.isEmpty())System.out.println("NA");
            else for(int i:l)System.out.println(i);
        }
    }
}


Measured memory_bytes: 27540
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[514][514];
int mdp[514][514];
int sum[514][514]; // 1^j + 2^j+ ... i^j mod inf;
int modpow(int x,int k){
	// x ^ k mod inf
	if(x==0)return 0;
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
signed main(){
	int n,c;
	cin>>n>>c;
	vector<int> a,b;
	a.pb(1);b.pb(1);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		b.pb(x);
	}
	for(int i=0;i<=400;i++){
		for(int j=0;j<=400;j++){
			mdp[i][j] = modpow( i, j );
		}
	}
	for(int i=1;i<=400;i++){
		for(int j=0;j<=400;j++){
			sum[i][j] = sum[i-1][j] + mdp[i][j];
			sum[i][j] %= inf;
		}
	}
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=c;j++){
			for(int k=0;k<=j;k++){
				dp[i][j] += (  dp[i-1][k] * ( sum[b[i]][j-k] - sum[a[i]-1][j-k] + inf ) )%inf;
				dp[i][j] %= inf;
			}
		}
	}
	cout<<dp[n][c]<<endl;
	return 0;
}

Measured memory_bytes: 6016
import sys
from collections import deque


diff = deque()

N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
    print(0)
    exit()

X.sort()

for i in range(len(X)-1):
    diff.append(X[i+1]-X[i])

diff = list(diff)
diff.sort()

for i in range(N-1):
    diff.pop()

print(sum(diff))


Measured memory_bytes: 14340
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int t1, t2;
  int64 a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if (a1 < b1) {
    swap(a1, b1);
    swap(a2, b2);
  }
  if (a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2) {
    cout << "infinity\n";
  } else if (a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2) {
    cout << "0\n";
  } else {
    int64 d = b1 * t1 + b2 * t2 - a1 * t1 - a2 * t2;
    int add = (a1 * t1 - b1 * t1) % d != 0;
    cout << (a1 * t1 - b1 * t1) / d * 2 + add << '\n';
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,j,sum=0;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a>>b;
        for (j=a;j<=b;j++)
        sum++;
    }
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;


int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	
	cout << b + min(c, a + b + 1) << endl;

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int n;
    int a, b;
    cin >> n >> a >> b;
    if((b-a)%2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
const int N=100001;
using namespace std;
int main(){
    int n,x[N],y[N],t[N];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>t[i]>>x[i]>>y[i];
    for(int i=1;i<=n;i++)
        if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0)
        {
            cout<<"No";
            return 0;   
        }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
  int n, x;
  cin >> n >> x;

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

  int d = 0, cnt = 1;
  for (int i = 0; i < n; i++) {
    d = d + ls[i];
    if (d > x) {
      break;
    }

    cnt++;
  }

  cout << cnt << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string lower = "abcdefghijklmnopqrstuvwxyz";

void Main(){
    // string S;
    char s;
    cin >> s;
    bool is_u = false;
    for(auto c:upper){
        if(c == s){
            is_u = true;
        }
    }
    if(is_u){
        cout << "A" <<endl;
    }else{
        cout << "a" <<endl;

    }



}

int main(){
    Main();
}

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    vector<int> v{0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    cin >> x >> y;
    if (v[x] == v[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl

int main() {
	// your code goes here
	ll t;
	t=1;
	while(t--)
	{
	    ll n,m;
	    cin>>n>>m;
	    char M[n][m];
	    for(ll i=0;i<n;i++)
	    {
	        for(ll j=0;j<m;j++)
	        {
	            cin>>M[i][j];
	        }
	    }
	    ll frow=0;
	    ll fcol=0;
	    ll T[n][m];
	    for(ll i=0;i<n;i++)
	    {
	        if(M[i][0]=='#')
	        {
	        T[i][0]=0;
	        fcol=1;
	        }
	        else if(fcol ==1)
	        T[i][0]=0;
	        else
	        T[i][0]=1;
	    }
	    for(ll j=0;j<m;j++)
	    {
	        if(M[0][j]=='#')
	        {
	        T[0][j]=0;
	        frow=1;
	        }
	        else if(frow==1)
	        T[0][j]=0;
	        else
	        T[0][j]=1;
	    }
	    for(ll i=1;i<n;i++)
	    {
	        for(ll j=1;j<m;j++)
	        {
	            if(M[i][j]=='#')
	            T[i][j]=0;
	            else
	            T[i][j]=(T[i-1][j]+T[i][j-1])%MOD;
	        }
	    }
	    /*for(ll i=0;i<n;i++)
	    {
	        for(ll j=0;j<m;j++)
	        {
	            cout<<T[i][j]<<" ";
	        }
	        cout<<"\n";
	    }
	    */
	    cout<<T[n-1][m-1];
	}
	return 0;
}


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


int main()
{
	long long n,cnt=0,j=0;
	cin>>n;
	long long arr[n+10],brr[n+10];
	for(long long i=0;i<n;i++)
	{
		cin>>arr[i];
		brr[i]=i+1;
	}
	for(long long i=0;i<n;i++)
	{
		if(brr[j]==arr[i])
		{
			j++;
			cnt++;
		}
	}
	if(cnt==0)cout<<"-1";
	else cout<<n-cnt;
}

Measured memory_bytes: 3328
n,x = map(int,input().split())

li = [1]
li2 = [1]

for i in range(n):
    li.append(3+2*li[-1])
    li2.append(1+2*li2[-1])

ans = 0

for i in range(n):
    x -= 1
    if x >= li[-2-i]:
        x -= li[-2-i]
        ans += li2[-2-i]
    else:
        continue
    if x > 0:
        x -= 1
        ans += 1
    else:
        break
    if x >= li[-2-i]:
        x -= li[-2-i]
        ans += li2[-2-i]
    else:
        continue

print(ans)


Measured memory_bytes: 3188
require("fs").readFileSync("/dev/stdin",'utf8').trim().split(/\s/).map(function(i){j=i.split(',');for(s=0,m=n=10;m--;)j[m]=s-=j[m];for(s*=j[11]/(-j[11]-j[n]);j[--n]>=-s;);console.log(++n);})

Measured memory_bytes: 7644
#include<stdio.h>
#include<math.h>
int Prime(int);
int main(){
  int a,i,n,ju,count=0;
  scanf("%d",&n);
  if(n<0||n>10000)fprintf(stderr,"errer n\n");
  for(i=0;i<n;i++){
    scanf("%d",&a);
    ju=0;
    if(a==2)ju=1;
    else if(a%2!=0)ju=Prime(a);
    else continue;
    if(ju==1)count++;
  }
  printf("%d\n",count);
  return 0;
}


int Prime(int a){
  int i,ju=1;
  for(i=3;i<=sqrt(a);i++){
    if(a%i==0){
      ju=0;
      break;
    }
  }
  return ju;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    UnionFind uf(n);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    map<int, vector<ll>> mp;
    int cnt = 0;
    rep(i, n) {
        mp[uf.root(i)].push_back(a[i]);
        if (uf.root(i) == i) cnt++;
    }
    if(cnt==1) {
        cout << 0 << endl;
        return 0;
    }
    cnt -= 2;

    ll ans = 0;
    vector<ll> vec;
    for (auto &p : mp) {
        auto &v = p.second;
        sort(all(v));
        rep(i, sz(v)) {
            if (i == 0)
                ans += v[i];
            else
                vec.push_back(v[i]);
        }
        // cout << ans << endl;
    }
    sort(all(vec));
    if (sz(vec) < cnt) {
        cout << "Impossible" << endl;
        return 0;
    }
    rep(i, cnt) {
        ans += vec[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 12416
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define inf 1000000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct node{
	int x,y;
	int cost;
	int dir;
	int fuel;
};
struct cmp{
	bool operator()(const node& n , const node & m)const{
		if(n.cost!=m.cost){return n.cost<m.cost;}
		else{
			if(n.fuel!=m.fuel){return n.fuel>m.fuel;}
			return mp(n.dir,mp(n.x,n.y))<mp(m.dir,mp(m.x,m.y));
		}
	}
};
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize;LLONG_MAX
signed main()
{
	speed
	//global var
	int n,m,k;cin>>n>>m>>k;
	int x, y,a , b;cin>>x>>y>>a>>b;
	--x;--y;--a;--b;
	
	vector<string> inp(n);
	vector<vector<vector<int>>> cost(n,vector<vector<int>>(m,vector<int>(4,inf)));
	vector<vector<vector<bool>>> vis(n,vector<vector<bool>>(m,vector<bool>(4,0)));
	for (int i = 0; i < n; ++i)
	{
		cin>>inp[i];
	}
	if(mp(x,y)==mp(a,b)){cout<<0<<"\n";return 0;}
	

	set<node, cmp> st;
	node curr;
	curr.x=x;curr.y=y;curr.cost=0,curr.dir=0,curr.fuel=0;//seed
	st.insert(curr);
	
	while(!st.empty()){
		auto pres=*st.begin();
		st.erase(st.begin());
		
		if(vis[pres.x][pres.y][pres.dir]){continue;}

		//cout<<pres.x<<' '<<pres.y<<" "<<pres.dir<<" "<<pres.fuel<<" "<<pres.cost<<"\n";
		
		vis[pres.x][pres.y][pres.dir]=1;
		cost[pres.x][pres.y][pres.dir]=pres.cost;
		if(pres.fuel!=0){
			int nx=pres.x+dx[pres.dir];
			int ny=pres.y+dy[pres.dir];
			if(nx>=0 and nx<n and ny>=0  and ny<m and inp[nx][ny]=='.'){
				node nxt=pres;
				nxt.x=nx;nxt.y=ny;nxt.fuel--;
				st.insert(nxt);
			}
		}
		for(int _=0;_<4;++_){
			node nxt=pres;

			nxt.x+=dx[_];nxt.y+=dy[_];
			if(!(nxt.x>=0 and nxt.y>=0 and nxt.x<n and nxt.y<m and inp[nxt.x][nxt.y]=='.')){continue;}
			nxt.dir=_;nxt.cost++;nxt.fuel=k-1;
			st.insert(nxt);
		}
	}
	int ans=inf;
	for(int _=0;_<4;++_){
		ans=min(ans,cost[a][b][_]);
	}
	if(ans==inf){
		cout<<-1<<"\n";
	}
	else{
		cout<<ans<<"\n";
	}

}

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

typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 2010;

ll fac[MAXN*MAXN], ifac[MAXN*MAXN];

inline ll qpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1LL) res = res * a % MOD;
		b >>= 1, a = a * a % MOD;
	}
	return res;
}

int n, k;
ll dp[MAXN][MAXN];

inline ll binom(int x, int y) {
	return fac[x]*ifac[y]%MOD*ifac[x-y]%MOD;
}

inline void update(ll &cur, ll val) {
	cur = cur+val;
	if(cur >= MOD) cur -= MOD;
}

int main() {

	int i, j;
	scanf("%d%d", &n, &k);
	if(k == 1) {
		printf("1\n");
		return 0;
	}
	fac[0] = 1;
	for(i = 1; i <= n*k; i++) fac[i] = fac[i-1]*i%MOD;
	ifac[n*k] = qpow(fac[n*k], MOD-2);
	for(i = n*k; i >= 1; i--) ifac[i-1] = ifac[i]*i%MOD;
	dp[n][n] = 1;
	for(i = n; i >= 0; i--) {
		for(j = n; j >= i; j--) {
			if(i == 0 && j == 0) continue;
			if(i != 0) update(dp[i-1][j], dp[i][j]);
			if(j != i) {
				update(dp[i][j-1], dp[i][j]*binom(j*(k-1)+i-1, k-2)%MOD);
			}
		}
	}
	printf("%lld\n", dp[0][0]*fac[n]%MOD);
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll beki(ll x, ll y){
	if(y==0) return 1;
	return x*beki(x, y-1);
}

ll rec(ll n, ll x){
	ll bek = beki(2, n+1);
	ll res;
	if(n==0 && x==1) res = 1;
	else if(x==1) res = 0;
	else if(x>1 && x<=1+(bek-3)) res = rec(n-1, x-1);
	else if(x==1+(bek-3)+1) res = beki(2, n);
	else if(x>1+(bek-3)+1 && x<=(2*(bek-3)+2)) res = (beki(2, n) + rec(n-1, x-bek+1));
	else if(x==2*(bek-3)+3) res =  2*(beki(2, n) - 1)+1;
	return res;
}

int main(){
	ll N, X;
	cin >> N >> X;
	cout << rec(N, X) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}


Measured memory_bytes: 256
#include <string>
#include<cctype>
#include<cstdio>
using namespace std;
typedef string::const_iterator State;
class ParseError {};

int expression(State &begin);

int number(State &begin){
  int ret=0;

  while(isdigit(*begin)){
    ret*=10;
    ret+=*begin-'0';
    begin++;
  }
  return ret;
}


int factor(State &begin){
  if(*begin=='('){
    begin++;
    int ret = expression(begin);
    begin++;
    return ret;
  }else{
    return number(begin);
  }
}

int term(State &begin){
  int ret = factor(begin);

  for(;;){
    if(*begin=='*'){
      begin++;
      ret*=factor(begin);
    }else if(*begin=='/'){
      begin++;
      ret/=factor(begin);
    }else{
      break;
    }
  }
  return ret;
}

int expression(State &begin){
  int ret=term(begin);

  for(;;){
    if(*begin=='+'){
      begin++;
      ret +=term(begin);
    }else if(*begin=='-'){
      begin++;
      ret-=term(begin);
    }else{
      break;
    }
  }
  return ret;
}

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    char s[105];
    scanf("%s",s);
    string S(s);

    State begin=S.begin();
    int ans=expression(begin);
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;

typedef struct W{
    int index;
    long dur;
    long start;
    long end;
} Work;

int main(){
    int n;
    cin >> n;
    vector<Work> w(n,{0,0,0,0});
    for(int i = 0;i < n;++i){
        cin >> w[i].dur >> w[i].end;
        w[i].index = i;
        w[i].start = w[i].end - w[i].dur;
    }

    sort(w.begin(),w.end(),[] (const Work& lhs, const Work& rhs) {
        if(lhs.end == rhs.end){
            return lhs.dur < rhs.dur;
        }
        return lhs.end < rhs.end;
    });

    long e = 0;
    for(int i = 0;i < n;++i){
        if(w[i].start < e){
            cout << "No" << endl;
            return 0;
        }
        else{
            e += w[i].dur;
        }
    }
    cout << "Yes" << endl;
}





Measured memory_bytes: 6528
N, M, X, Y = map(int, input().split())

x = list(map(int, input().split()))

y = list(map(int, input().split()))

dif = min(y) - max(x)

if dif > 0 and min(y) > X and max(x) < Y:
  print('No War')
else:
  print('War')

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p,l,r;};
struct Node T[MAX];
int n;

void preParse(int);
void inParse(int);
void postParse(int);

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      root=i;
    }
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

void preParse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}
void postParse(int u){
  if(u==NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}



Measured memory_bytes: 2104
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int,int>> vii;

class FenwickTree {
private:
    vector<int64_t> ft;
public:
    FenwickTree(int64_t n) {
        ft.assign(n + 1, 0);
    }
    int64_t rsq(int64_t b) {
        int sum = 0;
        for (; b; b -= (b & (-b))) {
            sum += ft[b];
        }
        return sum;
    }
    int64_t rsq(int64_t a, int64_t b) {
        if (a > b) return 0;
        return rsq(b) - rsq(a - 1);
    }
    void update(int64_t a, int64_t v) {
        for ( ; a < (int)ft.size(); a += (a & (-a))) {
            ft[a] += v;
        }
    }
    //NOTE: when using range update, rsq(x) is point query, unlike normally
    void update(int64_t a, int64_t b, int64_t v) {
        update(a, v);
        update(b + 1, -v);
    }
};

class arc068E {
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        
        vector<pair<int,int>> souv(N);
        for (int i = 0; i < N; ++i) {
            in >> souv[i].first >> souv[i].second;
        }
        sort(souv.begin(), souv.end(), [](const pair<int,int> &lhs, const pair<int,int> &rhs) {
            return (lhs.second - lhs.first) > (rhs.second - rhs.first);
        });
        
        FenwickTree ft(M+10);
        for (int i = 0; i < N; ++i) {
            //out << souv[i].first << " " << souv[i].second << endl;
            ft.update(souv[i].first, souv[i].second, 1);
        }
        
        vector<int> ans(M);
        int j = 0;
        for (int i = M; i >= 1; --i) {
            //cout << "-> " << i << ": ";
            
            while (j < N && souv[j].second - souv[j].first + 1 > i) {
                //cout << "rem: " << souv[j].first << "," << souv[j].second << "; ";
                ft.update(souv[j].first, souv[j].second, -1);
                ++j;
            }
            
            int64_t k = i, res = 0;
            while (k <= M) {
                res += ft.rsq(k);
                k += i;
            }
            //cout << res << " + " << j << endl;
            ans[i-1] = res + j;
        }
        for (int i = 0; i < M; ++i) {
            out << ans[i] << endl;
        }
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	arc068E solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

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

using namespace std;

long long N, x;
vector<long long> a1, a2;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long ans0 = 0;
	cin >> N >> x;
	for(int i=0; i<N; i++){
		long long v;
		cin >> v;
		if(v > x){
			ans0 += (v - x);
			v = x;
		}
		a1.push_back(v);
		a2.push_back(v);
	}
	a1.push_back(0);
	a2.push_back(0);

	long long ans1 = ans0;
	for(int i=1; i<N; i+=2){
		long long v = min(x - a1[i - 1], x - a1[i + 1]);
		if(a1[i] > v){
			ans1 += (a1[i] - v);
			a1[i] = v;
		}
	}

	long long ans2 = ans0;
	for(int i=1; i<N; i++){
		long long d = x - a2[i - 1];
		if(a2[i] > d){
			ans2 += (a2[i] - d);
			a2[i] = d;
		}
	}
	printf("%lld\n", min(ans1, ans2));

	return 0;
}

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

int main(void){
    int N, D;
    double res_d;
    int res_i;
    cin >> N >> D;
    res_d = (double)N/(2*D+1);
    res_i = N/(2*D+1);
    if(res_d != (double)res_i)
        cout << res_i + 1 << endl;
    else
        cout << res_i << endl;
    return 0;
}


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

ll a, b; 

int gcd(int a, int b) {
  if(b==0) return a;
  return gcd(b, a%b);
}

int main() {
  cin >> a >> b;
  ll tmp = a*b;
  ll ans = tmp/gcd(a,b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
int a[100005];
void FixDown(int a[],int k,int n)
{
    int i,t=a[k];
    while(2*k+1<n)
    {
        i=2*k+1;
        if(i<n-1&&a[i]<a[i+1]) i++;
        if(a[i]>t)
        {
            a[k]=a[i];
            k=i;
        }
        else break;
    }
    a[k]=t;
}
void HeapSort(int a[],int n)
{
    int i;
    for(i=(n-2)/2;i>=0;i--)
        FixDown(a,i,n);
}
int main()
{
    int n,m,i;
    long long ans=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    HeapSort(a,n);
    for(i=0;i<m;i++)
    {
        a[0]/=2;
        FixDown(a,0,n);
    }
    for(i=0;i<n;i++)
        ans+=a[i];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 760
def solve():
    while 1:
        n , x = map(int, input().split())
        if n == 0 and x == 0:
            return 0
        
        counter = 0
        for i in range(1, n+1):
            for j in range(i+1, n+1):
                k = x - i - j
                if j < k and k <= n:
                    counter += 1
        print(counter)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 5596
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void)
{
    long double A,B,H,M;

    cin >> A >> B >> H >> M;
    
    long double lang = (H + M/60.0)/12*360; 

    long double xA = A*sin((lang/180*M_PI));
    long double yA = A*cos((lang/180*M_PI));

    
     double xB = B*sin((M/60.0*2.0*M_PI));
    double yB = B*cos((M/60.0*2.0*M_PI));
    double dist = sqrt((xA-xB)*(xA-xB) + (yA-yB)*(yA-yB));
    cout << fixed << setprecision(20) << dist << endl;
    return 0;
}

Measured memory_bytes: 4104