akhauriyash/Code-Regression huggingface dataset:
def getval():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    return n,k,h 

def main(n,k,h):
    if k>=n-1:
        print(abs(h[-1]-h[0]))
    else:
        dp = [abs(h[i]-h[0]) for i in range(k)]
        for i in range(n):
            if len(dp)<n:
                dp.append(dp[i]+abs(h[i]-h[i+k]))
            for j in range(k-1):
                if i+j+1>=n:
                    break
                dp[i+j+1] = min(dp[i+j+1],dp[i]+abs(h[i]-h[i+j+1]))
        print(dp[-1])

if __name__=="__main__":
    n,k,h = getval()
    main(n,k,h)


Measured memory_bytes: 89396
def solve():
  N = int(input())
  X = input()
  bl = X.count('1')
  bitp = 0
  for i in range(N):
    bitp += int(X[i])*pow(2,N-1-i,bl+1)
    bitp %= bl+1
  bitm = 0
  if bl>1:
    for i in range(N):
      bitm += int(X[i])*pow(2,N-1-i,bl-1)
      bitm %= bl-1
  
  ans = [0]*N
  dp = [0]*(N+1)
  for i in range(1,N+1):
    dp[i] = dp[i%(bin(i).count('1'))]+1
  for i in range(N):
    if X[i]=='1':
      bl1 = bl-1
      if bl1==0:
        ans[i] = 0
        continue
      bit1 = bitm - pow(2,N-1-i,bl1)
    else:
      bl1 = bl+1
      bit1 = bitp + pow(2,N-1-i,bl1)
    ans[i] = dp[bit1%bl1]+1
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 12464
// Marcin Knapik
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type,less< int >, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef pair<ll, ll>          ii;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<vll>             vvll;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vii>             vvii;
#define pll pair<long long, long long>

#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<class T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18;
const ll N = 1e6+7;
const ll T = 1<<20;
const ld inf = 1e18;

ll n, m, q;

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

    cin >> n;

    if(n % 10 == 2 or n % 10 == 4 or n % 10 == 5 or n % 10 == 7 or n % 10 == 9){
    	cout << "hon\n";
    }else if(n % 10 == 3){
    	cout << "bon\n";
    }
    else{
    	cout << "pon\n";
    }
}   	

Measured memory_bytes: 3612
#include <iostream>
#define ll long long
using namespace std;
int n;
int ans;

void dfs(ll a,int b,int c,int d){
  if(a > n) return ;
  if(b && c && d) ans ++;
  dfs(a * 10 + 3, b + 1, c, d);
  dfs(a * 10 + 5, b, c + 1, d);
  dfs(a * 10 + 7, b, c, d + 1);
}

int main()
{
  cin>>n;
  ans = 0;
  dfs(0, 0, 0, 0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

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

			
			String X = sc.next();
			String Y = sc.next();

			int x2 = 0;
			if (X.equals("A")){
				x2 = 10;
			}else if(X.equals("B") ){
				x2 = 11;
			}else if(X.equals("C") ){
				x2 = 12;
			}else if(X.equals("D") ){
				x2 = 13;
			}else if(X.equals("E") ){
				x2 = 14;
			}else if(X.equals("F") ){
				x2 = 15;
			}

			int y2 = 0;
			if (Y.equals("A")){
				y2 = 10;
			}else if(Y.equals("B") ){
				y2 = 11;
			}else if(Y.equals("C") ){
				y2 = 12;
			}else if(Y.equals("D") ){
				y2 = 13;
			}else if(Y.equals("E") ){
				y2 = 14;
			}else if(Y.equals("F") ){
				y2 = 15;
			}
	        if(x2 < y2 ){
			    System.out.println("<");
	        }else if(x2 == y2){
			    System.out.println("=");
	        }else{
			    System.out.println(">");
	        }
		}
}


Measured memory_bytes: 20820
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
ll asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int main(){
    static int n,a[500000],q,x[500000],y[500000],ac[500000];
    static int check_n=0,check[500000]={};

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        ac[i]=a[i];
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++)scanf("%d %d",&x[i],&y[i]);

    qsort(ac,n,sizeof(int),asc);
    for(int i=0;i<n;i++){
        if(a[i]==ac[i]){
            check[i]=1;
            check_n++;
        }
    }

    if(check_n==n){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<q;i++){
  
        swap(&a[x[i]-1],&a[y[i]-1]);

        if(a[x[i]-1]==ac[x[i]-1]){
            if(check[x[i]-1]==0){
                check_n++;
                check[x[i]-1]=1;
            }
        }else{
            if(check[x[i]-1]==1){
                check_n--;
                check[x[i]-1]=0;
            }
        }
        if(a[y[i]-1]==ac[y[i]-1]){
            if(check[y[i]-1]==0){
                check_n++;
                check[y[i]-1]=1;
            }
        }else{
            if(check[y[i]-1]==1){
                check_n--;
                check[y[i]-1]=0;
            }
        }
        
        if(check_n==n){
            printf("%d\n",i+1);
            return 0;
        }

        
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 7676
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];

  sort(a, a+3);
  int count = 3;
  if(a[0] == a[1]){
    --count;
  }
  if(a[1] == a[2]){
    --count;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	double weight;
	while(cin >> weight)
	{
		if(weight <= 48.00)
		{
			cout << "light fly" << endl;
		}
		else if(weight <= 51.00)
		{
			cout << "fly" << endl;
		}
		else if(weight <= 54.00)
		{
			cout << "bantam" << endl;
		}
		else if(weight <= 57.00)
		{
			cout << "feather" << endl;
		}
		else if(weight <= 60.00)
		{
			cout << "light" << endl;
		}
		else if(weight <= 64.00)
		{
			cout << "light welter" << endl;
		}
		else if(weight <= 69.00)
		{
			cout << "welter" << endl;
		}
		else if(weight <= 75.00)
		{
			cout << "light middle" << endl;
		}
		else if(weight <= 81.00)
		{
			cout << "middle" << endl;
		}
		else if(weight <= 91.00)
		{
			cout << "light heavy" << endl;
		}
		else
		{
			cout << "heavy" << endl;
		}
	}
}

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

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

int main(){
  int N,K,count=0;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int H;
    cin >> H;
    if(H>=K){
      count++;
    }
  }
  cout << count << endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, x); }
template<class T, class U> void init(vector<T> &v, U x, size_t n, size_t m...) { v=vector<T>(n); for(auto& a : v) init(a, x, m);}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n;
    cin >> n;
    cout << (1000 - n%1000)%1000 << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



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

using namespace std;

int main(void) {
    int n, k, l;
    cin>>n>>k;
    vector<int> v(n);
    for (int i=0; i<n; ++i) {
        cin>>v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    int sum = 0;
    for (int i=0; i<k; ++i) {
        sum += v[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(min(K,100)):
    imos = [0]*(N+1)
    for i, ai in enumerate(A):
        imos[max(0, i-ai)] += 1
        imos[min(N, i+ai+1)] -= 1
    A = [imos[0]]
    for i in range(1, N):
        A += [imos[i]+A[i-1]]
print(' '.join(map(str, A)))

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

int main(){
	int m1, m2, d1, d2;
	int ans;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1==m2){
		ans = 0;
	}else{
		ans = 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        n = n % 10;
        if(n == 3)
        {
            WriteLine("bon");
        }
        else if(n == 0 || n == 1 || n == 6 || n == 8)
        {
            WriteLine("pon");
        }
        else
        {
            WriteLine("hon");
        }
    }
}


Measured memory_bytes: 17624
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n, m;
  long long k;
  cin>>n>>m>>k;
  long long a[n], b[m];
  REP(i, n) cin>>a[i];
  REP(i, m) cin>>b[i];
  long long sa[n], sb[m];
  REP(i, n){
    if(i == 0){
      sa[i] = a[i];
    }else{
      sa[i] = a[i] + sa[i-1];
    }
  }
  REP(i, m){
    if(i == 0){
      sb[i] = b[i];
    }else{
      sb[i] = b[i] + sb[i-1];
    }
  }
  int ans = 0;
  REP(i, n){
    long long temp = k - sa[i];
    if(temp < 0) break;
    if(temp < sb[0]){
      ans = max(ans, i + 1);
      continue;
    }
    int l = 0, r = m;//[l, r)
    while(r - l > 1){
      int mid = (l + r) / 2;
      if(sb[mid] <= temp){
        l = mid;
      }else{
        r = mid;
      }
    }
    ans = max(ans, (i + 1) + (l + 1));
  }
  REP(i, m) if(sb[i] <= k) ans = max(ans, i + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9932
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int H, S[10][5], v[10][5];

int main(void) {
  while(cin >> H, H) {
    REP(i, 0, H) REP(j, 0, 5) cin >> S[i][j];

    int p = 0, q;
    while(1) {
      q = 0;
      REP(i, 0, H) REP(j, 0, 5) v[i][j] = 0;
      REP(i, 0, H) REP(j, 0, 3) {
        if(S[i][j] == 0) continue;
        int d = 1;
        for(; j + d < 5 && S[i][j + d] == S[i][j]; d++);
        if(d >= 3) {
          REP(k, j, j + d) {
            q += S[i][k];
            S[i][k] = 0;
          }
        }
      }

      if(q == 0) break;
      p += q;

      bool b = true;
      while(b) {
        b = false;
        REP(i, 0, H - 1) REP(j, 0, 5) {
          if(S[i][j] != 0 && S[i + 1][j] == 0) {
            S[i + 1][j] = S[i][j];
            S[i][j] = 0;
            b = true;
          }
        }
      }
    }

    cout << p << endl;
  }

  return 0;
}

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

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	long long a, b, c; cin >> a >> b >> c;
	
	if(a + b + c >= 22){
		cout << "bust";
	}
	else {
		cout << "win";
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    string ans="";
    REP(i,s.size()){
        if(s[i]=='0') ans+='0';
        if(s[i]=='1') ans+='1';
        if(s[i]=='B' && ans.size()>0) ans.pop_back();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

template<typename T> class segtree {
private:
    int n,sz,h;
    vector<T> node, lazy;
    void eval(int k) {
        if(lazy[k]){
            node[k] += lazy[k];
            if(k < n) {
                lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

public:
    segtree(const vector<T>& v) : n(1), sz((int)v.size()), h(0) {
        while(n < sz) n *= 2, h++;
        node.resize(2*n, 0), lazy.resize(2*n, 0);
        for(int i = 0; i < sz; i++) node[i+n] = v[i];
        for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1];
    }
    void range(int a, int b, T x, int k=1, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            lazy[k] += (r-l)*x;
            eval(k);
        }else{
            range(a, b, x, 2*k, l, (l+r)/2);
            range(a, b, x, 2*k+1, (l+r)/2, r);
            node[k] = node[2*k] + node[2*k+1];
        }
    }
    T query(int a, int b) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = 0, res2 = 0;
        while(a < b) {
            if(a & 1) eval(a), res1 += node[a++];
            if(b & 1) eval(--b), res2 += node[b];
            a >>= 1, b >>= 1;
        }
        return res1 + res2;
    }
    void _print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n, q; cin >> n >> q;
    ll c[n]; zep(i, 0, n)cin >> c[i];
    
    vector<vector<ll>> v(q);
    zep(i, 0, q){
    	ll l, r; cin >> l >> r; l--; r--;
    	v[i] = {r, l, i};
    }
    sort(v.begin(), v.end());
    
    ll ri[n + 1]; memset(ri, -1, sizeof(ri));
    ll rb = 0;
    
    vector<int> u(n, 0), ans(q);
    segtree<int> bit(u);
    
    zep(i, 0, q){
    	ll l = v[i][1], r = v[i][0], qi = v[i][2];
    	
    	while(!(r < rb)){
    		if(ri[c[rb]] != -1){
    			bit.range(ri[c[rb]], ri[c[rb]] + 1, -1);
    		}
    		ri[c[rb]] = rb;
    		bit.range(rb, rb + 1, 1);
    		
    		rb++;
    	}
    	
    	ans[qi] = bit.query(l, r + 1);
    }
    
    zep(i, 0, q){
    	print(ans[i])
    }
    
    return 0;
}

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

int N, ans;
int main(){
  cin >> N;
  int mini = 2*N;
  for (int i = 0; i < N; i++){
    int temp;
    cin >> temp;
    mini = min(mini, temp);
    if (temp <= mini) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h> // @atoi
#include <algorithm>
using namespace std;

int ConvStrToInt(std::string checkStr)
{
	return atoi(checkStr.c_str());
}
int ConvStrToInt(char c)
{
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
std::string ConvIntToStr(int checkNum)
{
	return std::to_string(checkNum);
}

// 与えられた数値の各桁の合計の値を返す
// example) int = 34552 
//			return 19
int GetDigitSum(int n)
{
	string str = ConvIntToStr(n);
	int tmp = 0;
	while (n > 0)
	{
		tmp += n % 10;
		n /= 10;
	}
	return tmp;
}

int main(void)
{
	int value, first, last;

	cin >> value;
	std::vector<int> vCard;
	for (int i = 0; i < value; ++i)
	{
		int tmp = 0;
		cin >> tmp;
		vCard.push_back(tmp);
	}

	int valueA, valueB;

	while (vCard.empty() != true)
	{
		std::vector<int>::iterator it = std::max_element(vCard.begin(), vCard.end());
		valueA += *it;
		vCard.erase(it);

		if (vCard.empty() == true)
		{
			break;
		}

		it = std::max_element(vCard.begin(), vCard.end());
		valueB += *it;
		vCard.erase(it);
	}

	cout << std::abs(valueA - valueB) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vec;
 
#define vecc vector<vector<ll>>
#define LM LLONG_MAX
 
#define int long long int
#define P pair<ll,ll>
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
#define N 100005
#define M 105

#define MOD (ll)1000000007
 
ll dp[M][N],a[M][3];
 
ll solve(ll n,ll m)
{
      if(m==0)                  return 0;
      if(n==0 || m<0)           return 1e15;
      
      ll &ans=dp[n][m];
      
      if(ans!=1e17)        return ans;
      
      ans = min(solve(n-1,m),a[n][1]+solve(n-1,m-a[n][2]));
      
      return ans;
}
 
signed main()
{
      FAST;
      
      ll n,w,ans;
      cin>>n>>w;
      
      for(int i=0;i<M;i++)
            for(int j=0;j<N;j++)
                  dp[i][j]=1e17;
                  
      for(int i=1;i<=n;i++)
            cin>>a[i][1]>>a[i][2];
            
      for(int i=0;i<=100000;i++)
      {
            if(solve(n,i)<=w)
                  ans=i;
      }
      
      cout<<ans;
      
}

Measured memory_bytes: 82304
while gets
    n = $_.to_i
    break if n==0
    teams = Hash.new
    names = Array.new
    n.times do
        name,*team = gets.chomp.split
        team.map!(&:to_i)
        w=0
        d=0
        (n-1).times do |i|
            w+=1 if team[i]==0
            d+=1 if team[i]==2
        end
        teams[name]=w*n+d
        names << name
    end
    i=0
    ans=names.sort_by do |x|
        [-teams[x],i+=1]
    end
    puts ans
end

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

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

  if (sum % 10 != 0) {
    cout << sum << endl;
  } else {
    sort(s.begin(), s.end());
    for(int i = 0; i < n; ++i) {
      if (s[i] % 10 != 0) {
        cout << sum - s[i] << endl;
        return 0;
      }
    }
    cout << 0 << endl;
  }
  return 0;
}


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

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> num(n);
    rep(i, n) num[i] = i;
    sort(all(num),[&](int x, int y){
        return a[x] < a[y];
    });
    rep(i, n) cout << num[i]+1 << " ";
    cout << endl;
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
    string T, P;

    cin >> T >> P;

    vector<uint32_t> sa;
    for (uint32_t i = 0; i < T.length(); i++) {
        sa.push_back(i);
    }

    sort(sa.begin(), sa.end(), [T](uint32_t a, uint32_t b) {return T.substr(a, T.length()-a) < T.substr(b, T.length()-b);});

    auto itr_lb = lower_bound(sa.begin(), sa.end(), P, [T](uint32_t i, string s) {return T.substr(i, T.length()-i) < s;});
    auto itr_ub = upper_bound(itr_lb, sa.end(), P, [T](string s, uint32_t i) {return s < T.substr(i, T.length()-i).substr(0, s.length());});

    vector<uint32_t> indexes;
    for (auto itr = itr_lb; itr != itr_ub; itr++) {
        indexes.push_back(*itr);
    }

    sort(indexes.begin(), indexes.end());

    for (uint32_t index : indexes) {
        cout << index << endl;
    }

    return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
using namespace std;

const long double PI = 2*acos(0);

int main(){
	int n;cin>>n;
	for(int i =1;i<=9;i++){
		if(n%i==0){
			if(n/i<=9 && n/i > 0){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = 3.1415926535898;
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    YES(a <= x && x <= a + b);

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv(N, M, AB):
    from collections import defaultdict

    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)

    def bfs(s):
        q = deque([s])
        done = {}
        done[s] = 0
        prev = {}
        goal = None
        while q:
            u = q.popleft()
            for v in g[u]:
                if v not in done:
                    done[v] = done[u] + 1
                    prev[v] = u
                    q.append(v)
                if v == s:
                    goal = u
                    break
        if goal is  None:
            return None
        v = goal
        ans = [s]
        while v in prev:
            ans.append(v)
            v = prev[v]
        return ans

    from collections import deque
    ans = [0] * (2*N)
    for i in range(1, N+1):
        a = bfs(i)
        if a and len(ans) > len(a):
            ans = a
    if len(ans) == (2*N):
        print(-1)
        return
    print(len(ans))
    print(*ans, sep='\n')


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    slv(N, M, AB)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47964
#include <stdio.h>

int main(void)
{
	char tile[128][128];
	char log[128][128];
	int loop;
	int H, W, i, j, x, y;
	
	while (1){
		scanf("%d %d", &H, &W);
		
		if (H == 0 && W == 0){
			break;
		}
		
		for (i = 0; i < 128; i++){
			for (j = 0; j < 128; j++){
				log[i][j] = 0;
			}
		}
		x = y = 0;
		loop = 0;
		
		for (i = 0; i < H; i++){
			scanf("%s", tile[i]);
		}
		
		while (tile[y][x] != '.'){
			if (log[y][x] == 1){
				loop = 1;
				break;
			}
			
			log[y][x] = 1;
			
			switch (tile[y][x]){
				case '>':
				x++;
				break;
				
				case '<':
				x--;
				break;
				
				case '^':
				y--;
				break;
				
				case 'v':
				y++;
				break;
			}
		}
		
		if (loop == 1){
			printf("LOOP\n");
		}
		else {
			printf("%d %d\n", x, y);
		}
	}
	
	return (0);
}

Measured memory_bytes: 648
// Problem : A - Takahashikun, The Strider
// Contest : AtCoder - AtCoder Grand Contest 046
// URL : https://atcoder.jp/contests/agc046/tasks/agc046_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	// ios_base::sync_with_stdio(0); cin.tie(0);    
	int X;
	// cin>>X;
	scanf("%d",&X);
	int ans=(360*X)/__gcd(360,X);
	ans/=X;
	printf("%d",ans);
	// cout<<ans/X<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3720
#include <iostream>
#include <sstream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <string>
#include <string.h>
#include <iomanip>
#include <cmath>
#define ll long long
#define PI 3.14159265358979323846
#define lp(i, n) for (int i = 0; i < n; i++)
#define rep(i, v) for (int i = 0; i < int(v.size()); i++)
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n],tmp[n];
	lp(i,n){
		cin>>arr[i];
		tmp[i]=arr[i];
	}
	sort(tmp,tmp+n);
	reverse(tmp,tmp+n);
	lp(i,n)
	{
		if(arr[i]==tmp[0])
			cout<<tmp[1];
		else
			cout<<tmp[0];
		cout<<endl;
	}
	return 0;
}

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

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

  if (N > K){
    cout << K * X + (N - K) * Y << endl;
  }
  else
  {
    cout << N * X << endl;
  }
  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S, T;
  cin >> S >> T;
  unordered_map<char, char> mp;
  for(int i = 0; i < 26; i++) {
    mp[i + 97] = ' ';
  }
  for(int i = 0; i < (int) S.size(); i++) {
    if(mp[S.at(i)] == ' ' || mp[S.at(i)] == T.at(i)) {
      mp[S.at(i)] = T.at(i);
    }
    else{
      cout << "No" <<endl;
      return 0;
    }
  }
  for(int i = 0; i < 26; i++) {
    mp[i + 97] = ' ';
  }
  for(int i = 0; i < (int) S.size(); i++) {
    if(mp[T.at(i)] == ' ' || mp[T.at(i)] == S.at(i)) {
      mp[T.at(i)] = S.at(i);
    }
    else{
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3904
a, b, c, d = map(int, input().split())
S = []
e = c - a
f = d - b
for i in range(f):
    S.append("U")
for i in range(e+1):
    S.append("R")
for i in range(f+1):
    S.append("D")
for i in range(e+1):
    S.append("L")
S.append("U")
S.append("L")
for i in range(f+1):
    S.append("U")
for i in range(e+1):
    S.append("R")
for i in range(f+1):
    S.append("D")
for i in range(e):
    S.append("L")
ans = "".join(S)
print(ans)

Measured memory_bytes: 40432
#include <stdio.h>


int main(void){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    int N;
    scanf("%d",&N);
    int po=A;
    if(po<B)po=B;
    if(po<C)po=C;
    int ans=A+B+C-po;
    ans+=po*(1<<N);
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int N,p[51],i;
	int cnt=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&p[i]);

	}
	for(i=0;i<N;i++)
	{
		if(i!=p[i]-1)
		{
			cnt++;
		}
		if(cnt>2)
		break;
	}
	if(cnt>2)
	printf("NO");
	else
	printf("YES");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  cin >> A;
  cin >> B;
  cin >> C;
  sort(all(A));
  sort(all(B));
  sort(all(C));
  ll ans = 0ll;
  for (int i = 0; i < N; i++) {
    ll p = lower_bound(all(A), B[i]) - A.begin();
    ll q = C.end() - upper_bound(all(C), B[i]);
    ans += p * q;
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    string s;
    cin >> s;
    int N = s.size();
    s = '0' + s;

    if (s[1] != '1') {
        cout << -1 << endl;
        return 0;
    }

    vi pos;
    for (int i = 0; i <= N; i++) {
        if (s[i] != s[N-i]) {
            cout << -1 << endl;
            return 0;
        }

        if (i <= N/2 && s[i] == '1')
            pos.push_back(i);
    }

    pos.push_back(N);

    int pr = 0, nxt = 1;
    for (int i = 1; i < pos.size(); i++) {
        cout << pr + 1 << " " << nxt + 1 << "\n";
        pr = nxt++;
        for (int j = 0; j < pos[i] - pos[i-1] - 1; j++)
            cout << pr + 1 << " " << ++nxt << "\n";
    }

    assert(nxt == N);
    return 0;
}



Measured memory_bytes: 1900
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, x;
    cin >> N >> x;
    if(x == 1 || x == 2 * N - 1){
        output("No");
        return 0;
    }
    
    output("Yes");
    
    if(N == 2){
        output(1);
        output(2);
        output(3);
        return 0;
    }
    vector<int> A(2 * N - 1, 0);
    
    
    if(x <= N){
        A[N - 2] = x + 1;
        A[N - 1] = x;
        A[N] = x - 1;
        A[N + 1] = x + 2;
        int in = 1;
        rep(i, 2 * N - 1){
            if(in == x - 1) in = x + 3;
            if(A[i] == 0){
                A[i] = in;
            }
            else{
                continue;
            }
            in++;
        }
    }
    else{
        A[N - 2] = x - 1;
        A[N - 1] = x;
        A[N] = x + 1;
        A[N + 1] = x - 2;
        int in = 1;
        rep(i, 2 * N - 1){
            if(in == x - 2) in = x + 2;
            if(A[i] == 0){
                A[i] = in;
            }
            else{
                continue;
            }
            in++;
        }
    }
    rep(i, 2 * N - 1){
        output(A[i]);
    }
    
    return 0;
}

Measured memory_bytes: 2432
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

ll GCD(ll A, ll B){
  ll M = max(A, B), m = min(A, B);
  while (M % m != 0){
    ll K = m;
    m = M % m; M = K;
  }
  return m;
}

int main(){
  int N; cin >> N;
  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  vector <ll> L(N), R(N);
  L[0] = A[0]; R[N - 1] = A[N - 1];
  for (int i = 1; i < N; i++){
    L[i] = GCD(L[i - 1], A[i]);
  }
  for (int i = N - 2; i >= 0; i--){
    R[i] = GCD(R[i + 1], A[i]);
  }

  ll ans = max(R[1], L[N - 2]);

  for (int i = 1; i < N - 1; i++){
    ans = max(ans, GCD(L[i - 1], R[i + 1]));
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;



int main(){
	int n;
	cin >> n;
	vector<vector<ll>> a(n, vector<ll>(2));
	for (int i = 0; i < n; i++){
		cin >> a[i][0];
		a[i][1] = i + 1;
	}
	sort(a.begin(), a.end());

	for (int i = 0; i < n; i++){
		cout << a[i][1] << " ";
	}

	return 0;
}

Measured memory_bytes: 6400
S = gets.chomp
max_len =0
(0..S.length-1).each do |x|
  y = x
  while S[y] == 'A' || S[y] == 'C' || S[y] == 'G' || S[y] == 'T' do
    y = y + 1
  end
  max_len = y-x if max_len < y-x
end
puts max_len


Measured memory_bytes: 1788
N, M = map(int, input().split())
BIT = 2 ** N
dp =[[float("inf") for _ in range(BIT)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
    A, B = map(int, input().split())
    C = list(map(int, input().split()))
    x = sum([2 ** (c - 1) for c in C])
    for j in range(BIT):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        dp[i + 1][x|j] = min(dp[i][j] + A, dp[i + 1][x|j])

ans = dp[M][BIT - 1]
if ans != float("inf"):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 138632
#include<iostream>
using namespace std;
int main()
{
    int N,d;
    cin>>N;
    d=N%10;
    if(d==2||d==4||d==5||d==7||d==9)
        cout<<"hon\n";
    else if(d==0||d==1||d==6||d==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";

}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,m;
cin >> n>>m;
vector<vector<ll>> d(n, vector<ll>(n,INF) );
ll aa[m]={},bb[m]={},cc[m]={}; 
rep(i, m){
    ll a,b,c;
    cin >> a>>b>>c;
    a--;b--;
    d[a][b]=c;
    d[b][a]=c;
    aa[i]=a;
    bb[i]=b;
    cc[i]=c;
}
rep(i,n){
    d[i][i]=0;
}
for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);




rep(i,m){
    bool ch=0;
    rep(j,n){
    if(d[aa[i]][j]+cc[i]==d[bb[i]][j])ch=1;
    }
    if(!ch)ans++;
}

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


Measured memory_bytes: 384
A, B, C, X, Y = map(int, input().split())
if A + B > 2 * C:
    base = 2 * C * min(X, Y)
    if X >= Y:
        opt = min(A * (X - Y), 2 * C * (X - Y))
    else:
        opt = min(B * (Y - X), 2 * C * (Y - X))
    ans = base + opt
else:
    ans = A * X + B * Y
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main (int argc, char * argv[])
{
    char a[201];//山札のカードの枚数
    char b[201];
    int m;//シャッフルの回数
    int h;
    int j,k,l;
    while (1){
//        printf("文字列の入力");
        scanf("%s",a);
        if(strcmp(a, "-") == 0){
            break;
        }
//        int len = strlen(a);//文字の長さ
//        printf("シャッフルの回数");
        //シャッフルの回数の入力
        scanf("%d",&m);
      
        for(int i=0;i<m;i++){
//            printf("移動量");
            scanf("%d",&h);
            for( j=h;a[j]!='\0';j++)
                b[j-h] = a[j];
            for( k=0;k<h;k++)
                b[j-h+k] = a[k];
            for( l=0;a[l]!='\0';l++)
                a[l] = b[l];
        
        }
            printf("%s\n",a);
            
    }

    return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);
        while(true) {
            int a = sc.nextInt();
            String b  = sc.next();
            int c = sc.nextInt();
            int f=0;
            switch (b) {
    		case "+":
    			System.out.println(a+c);
    			break;
    		case "-":
    			System.out.println(a-c);
    			break;
    		case "*":
    			System.out.println(a*c);
    			break;
    		case "/":
    			System.out.println(a/c);
    			break;
    		default:
    			f=1;
    			break;
            }
            if(f==1)break;
        }
        sc.close();
    }
}



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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    ll answer = 0, min = 0;
    rep(i,0,N) {
        if (min > A[i]) answer += min - A[i];
        min = max(min, A[i]);
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4868
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    cout << ceil(N, 2 * D + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <math.h>
# include <cmath>
using namespace std;
int main()
{
	double n,d,x,y,l;
	l=0;
	double m;
	cin>>n>>d;
	for(int i=0; i<n; i++)
	{
		cin>>x>>y;
		m=sqrt(x*x+y*y);
		if(m<=d)
		{
			l=l+1;
		}
	}
	cout<<l<<endl;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if (s == u) a--;
    else b--;
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List

f x | q == 0    = r
    | otherwise = r + f q
  where
    (q, r) = x `divMod` 10

h x | (_, 0) <- x `divMod` f x = True
    | otherwise                = False

main :: IO ()
main = do
    n <- readLn :: IO Int
    if h n
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 508