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

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

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

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

vec modncrlistp,modncrlistm;

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

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

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

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

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
ll N,S;
vec v,sum;
int judge(ll K,ll x){
  ll i=lower_bound(all(v),x)-v.begin();
  K-=S-i;
  if(!i||K<=0)return 1;
  if(sum[i-1]/K>=x){
    return 1;
  }
  return 0;
}
int main(){
  ll i,N,cnt=1;
  cin>>N;
  vec a(N);
  rep(i,N)cin>>a[i];
  vsort(a);
  rep1(i,N){
    if(a[i]==a[i-1]){
      cnt++;
    }else{
      v.pb(cnt);
      cnt=1;
    }
  }
  v.pb(cnt);
  vsort(v);
  S=v.size();
  sum.resize(S);
  sum[0]=v[0];
  rep1(i,S)sum[i]=sum[i-1]+v[i];
  rep1(i,N+1){
    if(i>S){
      cout<<0<<endl;
      continue;
    }
    ll ng=N/i+1,ok=0,mid;
    while(ng-ok>1){
      mid=(ok+ng)/2;
      if(judge(i,mid)){
        ok=mid;
      }else{
        ng=mid;
      }
    }
    cout<<ok<<endl;
  }
  return 0;
}

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

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

int main(){
ll h;
cin>>h;
int count=0;
ll ans=0;
while(h>1){
  ans+=pow(2,count);
h/=2;
count++;

}
ans+=pow(2,count);
cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int maxn=5*10e5+10;
int pre[maxn],suf[maxn];
void pre_fix(string s,int p[]){
	p[0]=-1;
	int len=0,i=1;
	while(i<s.size()){
		if(s[i]==s[len] || len==-1){
			p[i+1]=len+1;
			i++,len++;
		}
		else
			len=p[len];
	}
}
int main(){
	string s1;
	while(cin>>s1){
		string s2="";
		int len=s1.size();
		for(int i=len-1;i>=0;i--)
			s2+=s1[i];
 		pre_fix(s1,pre);
		pre_fix(s2,suf);
		bool flag=true;
		for(int i=1;i<len;i++)
			if(s1[i]!=s1[i-1]){
				flag=false;
				break;
			}
		if(flag){
			printf("%d\n%d",len,1);
			continue;
		}
		if(pre[len]==0 || len%(len-pre[len]))
			printf("%d\n%d",1,1);
		else{
			printf("%d\n",2);
			int ans=0;
			for(int i=0;i<len;i++){
				int k=len-i-1;
				if(	(pre[i+1]==0 || (i+1)%(i+1-pre[i+1]) ) && (suf[k]==0 || k%(k-suf[k])))
					ans++;
			}
			printf("%d",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 7712
import java.util.*;

public class Main {

    private static final int INF = 1_000_000_000;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int Ch = sc.nextInt()-1;
        int Cw = sc.nextInt()-1;
        int Dh = sc.nextInt()-1;
        int Dw = sc.nextInt()-1;
        int[][] cost = new int[H][W];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                char c = s.charAt(j);
                if (c == '#') {
                    cost[i][j] = -1;
                } else {
                    cost[i][j] = INF;
                }
            }
        }

        boolean[][] done = new boolean[H][W];
        PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->a.cost-b.cost);
        pq.offer(new Pair(Ch,Cw,0));
        while (!pq.isEmpty()) {
            Pair p = pq.poll();
            while (p != null && done[p.i][p.j]) {
                p = pq.poll();
            }
            if (p == null) {
                break;
            }
            done[p.i][p.j] = true;
            cost[p.i][p.j] = p.cost;

            for (int v = 0; v < 4; v++) {
                int nexti = p.i + dy[v];
                int nextj = p.j + dx[v];
                if (0 <= nexti && nexti < H
                    && 0 <= nextj && nextj < W
                    && !done[nexti][nextj]
                    && cost[nexti][nextj] != -1) {
                    pq.offer(new Pair(nexti,nextj,Math.min(p.cost,cost[nexti][nextj])));
                }
            }
            for (int v = 0; v < 20; v++) {
                int nexti = p.i + d2y[v];
                int nextj = p.j + d2x[v];
                if (0 <= nexti && nexti < H
                    && 0 <= nextj && nextj < W
                    && !done[nexti][nextj]
                    && cost[nexti][nextj] != -1) {
                    pq.offer(new Pair(nexti,nextj,Math.min(p.cost+1,cost[nexti][nextj])));
                }
            }
        }

        /*
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                System.out.print(cost[i][j]);
                System.out.print(' ');
            }
            System.out.println();
        }
        */

        System.out.println(cost[Dh][Dw] != INF ? cost[Dh][Dw] : -1);
    }

    private static int[] dx = new int[] { 0, 0, 1, -1 };
    private static int[] dy = new int[] { 1, -1, 0, 0 };
    private static int[] d2x = new int[] { -2, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2,  2,  2,  1,  0, -1, -1, -1,  1, 1};
    private static int[] d2y = new int[] { -2, -1,  0,  1,  2,  2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -1,  1, -1, 1};

    private static class Pair {
        private final int i;
        private final int j;
        private final int cost;
        Pair(int i, int j, int cost) {
            this.i = i;
            this.j = j;
            this.cost = cost;
        }
    }
}


Measured memory_bytes: 68376
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 49884
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    set<int> r, w;
    forn(i, n){
        if (s[i] == 'R') r.insert(i); else w.insert(i);
    }
    int ans = 0;
    if (r.empty() || w.empty()){
        cout << "0\n";
        return;
    }
    while(true){
        int i = *w.begin(), j = *r.rbegin();
        if (i > j) break;
        w.erase(i), r.erase(j);
        w.insert(j), r.insert(i);
        ans++;
    }
    cout << ans << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 13028
import sys
input = sys.stdin.readline
N = int(input())
D, X = [int(x) for x in input().rstrip().split()]
A = []
for _ in range(N):
    A.append(int(input()))
ans = 0
for i in range(N):
    day = 1
    ans += 1
    while True:
        day += A[i]
        if day <= D:
            ans += 1
        else:
            break
print(ans + X)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,k,a[510],tot,t,cnt,b[510],i;
int main(){
	cin>>n>>k;
	for(i=0;i<n;i++) scanf("%d",&a[i]),cnt+=a[i];
	for(i=cnt;i>=2;i--)
		if(cnt%i==0){
			tot=t=0;
			for(int j=0;j<n;j++) b[j]=a[j]%i,tot+=b[j];
			sort(b,b+n);
			for(int j=1;j<=tot/i;j++) t+=i-b[n-j];
			if(t<=k) break;
		}
	cout<<i;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

ll f(ll n) {
    if (n < 2) return 0;
    return n / 5 + f(n / 5);
}

int main() {
    ll n;
    cin >> n;
    if (n & 1) {
        cout << 0 << endl;
        return 0;
    }
    n /= 2;
    ll ans = f(n);
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
    	var s = Console.ReadLine();
    	var q = int.Parse(Console.ReadLine());
    		
		for(int i = 0; i < q; i++) {
			var order = Console.ReadLine().Split(' ');
			var a = int.Parse(order[1]);
			var b = int.Parse(order[2]);
			
			switch(order[0]) {
				case "print":
					Console.WriteLine( s.Substring(a, b-a+1) );
					break;
				case "reverse":
					var c = s.Substring(a, b-a+1).ToCharArray();
					Array.Reverse(c);
					var r = new string(c);
					s = s.Substring(0, a) + r + s.Substring(b + 1);
					break;
				case "replace":
					var p = order[3];
					s = s.Substring(0, a) + p + s.Substring(b + 1);
					break;
			}
		}
    }
}

Measured memory_bytes: 9152
import itertools
n,A,B,C=map(int,input().split())
l=[int(input()) for i in range(n)]
ll=[]
for p in itertools.product(['A','B','C','Z'],repeat=n):
  ans=0
  a=0
  b=0
  c=0
  numa=0
  numb=0
  numc=0
  for i in range(n):
    if p[i]=='A':
      a+=l[i]
      numa+=1
    elif p[i]=='B':
      b+=l[i]
      numb+=1
    elif p[i]=='C':
      c+=l[i]
      numc+=1
  ans+=(abs(a-A)+abs(B-b)+abs(C-c)+(numa+numb+numc-3)*10)
  if all(nn!=0 for nn in [numa,numb,numc]):
    ll.append(ans)
print(min(ll))

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

vector<bool> p(1010, true);

// trueで初期化した配列が必要です
void eratos(int n) {
  p[0] = p[1] = false;
  for (int i = 2; i <= sqrt(n); i++)
    if (p[i])
      for (int j = i * 2; j <= n; j += i) p[j] = false;
}

int main() {
  ll n;
  cin >> n;
  eratos(1000);
  map<int, int> soi;
  for (int i = 2; i <= n; i++) {  // 何番目かの素数
    int res = 0;
    if (p[i]) {
      for (int j = i; j <= n; j *= i) {
        res += n / j;
      }
      soi[i] = res;
    }
  }

  ll ans = 1;
  for (auto x : soi) {
    ans = ans * (x.second + 1) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	a := nextInt()
	b := nextInt()
	if a > b {
		fmt.Println(0)
		return
	}
	if n == 1 && a != b {
		fmt.Println(0)
		return
	}
	maxv := a + (n-1)*b
	minv := (n-1)*a + b
	fmt.Println(maxv - minv + 1)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
fn input_trio<T: std::str::FromStr + Copy> () -> (T, T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1], arr[2])
}

fn main() {
    let (a, b, k) = input_trio::<usize>();
    let (r1, k) = if a <= k { (0, k - a) } else { (a - k, 0) };
    let r2 = if b <= k { 0 } else { b - k };
    println!("{} {}", r1, r2);
}


Measured memory_bytes: 2080
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const int MMAX = 2e6;
int L, a[MMAX];

string int2string(int n) {
  ostringstream sout;
  sout << setfill('0') << setw(L) << n;
  return sout.str();
}

int succesor(int n) {
  string str = int2string(n);

  sort(str.begin(), str.end());
  string minimum = str;

  reverse(str.begin(), str.end());
  string maximum = str;

  return stoi(maximum) - stoi(minimum);
}

void set_s(int n) {
  a[n] = succesor(a[n - 1]);
}


int floyd() {
  set_s(1);
  set_s(2);

  int m = 1;
  while (a[m] != a[2 * m]) {
    set_s(2 * m + 1);
    set_s(2 * m + 2);
    m++;
  }
  //printf("m = %d, a_m = a_2m = %d\n", m, a[m]);

  int lambda = 0;
  while (a[lambda] != a[m]) {
    lambda++; m++;
  }
  //printf("lambda = %d, m = %d, a_lambda = a_m = %d\n", 
    //  lambda, m, a[m]);

  for (int i = 2 * m; i <= lambda + 3 * m; i++) {
    set_s(i);
  }
  
  int mu = 1;

  lambda--;
  while (a[lambda + mu] != a[lambda + 2 * mu]) {
    set_s(lambda + 2 * mu + 1);
    set_s(lambda + 2 * mu + 2);
    mu++;
  }
  lambda++;
  //printf("mu = %d\n", mu);
/*
  REP(i, lambda + 2 * m) {
    cout << i << ": " << a[i] << endl;
  }*/

  cout << lambda << " " << a[lambda + mu] << " " << mu << endl;
  return max(lambda + 3 * m, 100);
}

void init(int n) {
  REP(i, n) {
    a[i] = 0;  
  }
}

int main() {
  while (cin >> a[0] >> L and L) {
    int erase = floyd();
    init(erase);
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A,B;
  cin >> A >> B;
  //for(int i=0;i<min(A.size(),B.size());i++) {
  //  if(A[i]>B[i]){
  //    cout << "GREATER" << endl;
  //    return 0;
  //  }
  //  else if(A[i]<B[i]) {
  //    cout << "LESS" << endl;
  //    return 0;
  //  } 
  int m;
  if(A.size()>B.size()) m=1;
  else if(A.size() < B.size()) m=-1;
  if(A.size()==B.size()) m=A.compare(B);
  if (m>0) cout << "GREATER" << endl;
  else if(m==0) cout << "EQUAL" << endl;
  else cout << "LESS" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int A, B, C;
	cin >> A >> B >> C;

	if (A <= C and B >= C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//2017-11-4
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

#define N (100000+5)

int n;

void Solve(int *a, int *b, LL *fa, LL *fb){
	int p = 0;
	LL tot = 0;

	For(i, 1, n){
		while(p < n && a[p+1] < b[i]) ++p, tot += fa[p];
		fb[i] = tot;
	}
}

int a[N], b[N], c[N];
LL fa[N], fb[N], fc[N];

int main(){	
	scanf("%d", &n);

	For(i, 1, n) scanf("%d", &a[i]);
	For(i, 1, n) scanf("%d", &b[i]);
	For(i, 1, n) scanf("%d", &c[i]);

	sort(a+1, a+n+1); sort(b+1, b+n+1); sort(c+1, c+n+1);

	For(i, 1, n) fa[i] = 1;
	Solve(a, b, fa, fb);
	Solve(b, c, fb, fc);
	
	LL ans = 0;
	For(i, 1, n) ans += fc[i];
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
void Maxheapify(int);

int h,X[5000000];

int main(){
  int i;
  scanf("%d",&h);

  for(i=1;i<=h;i++){
    scanf("%d",&X[i]);
  }
  for(i = h/2 ; i >=1 ; i--)Maxheapify(i);

  for(i=1;i<=h;i++){
    printf(" %d",X[i]);
  }
  printf("\n");
  return 0;
}
void Maxheapify(int x){
  int ri,le,large;
  int tmp;
  le=2*x;
  ri=2*x+1;

  if(le<=h &&X[le]>X[x])large=le;
  else large =x;

  if( ri <= h && X[ri] > X[large] )large=ri;
  if(large!=x){
    tmp=X[x];
    X[x]=X[large];
    X[large]=tmp;

    Maxheapify(large);
  }
}



Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++){
        cin >> a[i];
        v.push_back(make_pair(a[i],i));
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<n;i++){
        if(i%2!=v[i].second%2)ans++;
    }
    cout << ans/2 << endl;
}

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


int main(){
    int n, k, ans, dis;

    cin >> k >> n;

    vector<int> vec(n);
    for (int i = 0; i < n; i++) cin >> vec.at(i);
    dis = k - vec.at(n-1) + vec.at(0);
    for (int i = 1; i < n; i++) dis = max(dis, vec.at(i) - vec.at(i-1));

    cout << k -dis << endl;

}

Measured memory_bytes: 4040
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, ans;
pair<ll, ll> cnt_1[111111];
pair<ll, ll> cnt_2[111111];

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, x;
	for(i=1 ; i<=111100 ; i++) cnt_1[i].second=cnt_2[i].second=i;
	for(i=1 ; i<=n ; i++)
	{
		cin>>x;
		if(i%2==1) cnt_1[x].first++;
		else cnt_2[x].first++;
	}
	sort(cnt_1+1,cnt_1+100001); reverse(cnt_1+1,cnt_1+100001);
	sort(cnt_2+1,cnt_2+100001); reverse(cnt_2+1,cnt_2+100001);
	if(cnt_1[1].second!=cnt_2[1].second) cout<<n-cnt_1[1].first-cnt_2[1].first;
	else cout<<min(n-cnt_1[1].first-cnt_2[2].first,n-cnt_1[2].first-cnt_2[1].first);
	return 0;
}

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

int main()
{
   int n; cin >> n;
   vector<int> a(n);
  bool one=false;
  for(int i=0; i<n; i++){
    cin >> a.at(i);
    if(a.at(i)==1)one=true;
  }
  if(!one){cout << -1 << endl;return 0;}
  int ans=0;
  int p=1;
  for(int i=0; i<n; i++){
    if(a.at(i)==p){p++;}
    else{ans++;}
  }
   cout << ans << endl; 
    
   return 0;
}

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

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

int find(string str, const string& word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos; pos += word.size()) {
    ++count;
  }
  return count;
}

int main(){
    int x, a;
    cin >> x >> a;
    if( x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
program answer
  implicit none
  integer(8) :: i, N, sum, ka
  integer(8), allocatable :: A(:)
  read(*,*) N
  allocate(A(N))
  read(*,*) A

  sum=1000
  ka=0

  do i = 1, N-1
     if(A(i)<=A(i+1)) then
        ka=sum/A(i)
        sum=sum-ka*A(i)
     else
        ka=0
     end if
     sum=sum+ka*A(i+1)
     ka=0
  end do
  write(*,*) sum
  deallocate(A)
  stop
 end program answer


Measured memory_bytes: 2824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(a,j,n) for(ll i=a;i<j;i=i+n )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    ll A,B;
    cin>>A>>B;
    rep(1,10000,1){
        if(0.08*i>=A&&0.08*i<A+1&&0.1*i>=B&&0.1*i<B+1){
            cout<<i<<endl;
            break;
        }
        if(i==9999)cout<<-1<<endl;
    }
}


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

namespace ConsoleApp11
{
    class Class20
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int pare=0;
            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            for(int i = 0; i < a.Count(); i++)
            {
                if (a[a[i]-1] == i+1)
                    pare += 1;
            }
            Console.WriteLine(pare/2);
        }
    }
}


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

 using namespace std;

 int main() {
   string w;
   int i;
   string ans;
   vector<int> count(26);

   cin >> w;

   for (i = 0; i < w.length(); i++) {
     count.at((int)(w.at(i)) - 97)++;
   }

   ans = "Yes";
   for (i = 0; i < 26; i++) {
     if (count.at(i) % 2) {
       ans = "No";
       break;
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sgn(long long x)
{
	if (x < 0) return -1;
	if (x > 0) return +1;
	return 0;
}

int main()
{
	long long T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	auto C1 = A1 * T1;
	auto C2 = A2 * T2;
	auto D1 = B1 * T1;
	auto D2 = B2 * T2;

	if (C1 + C2 == D1 + D2) {
		cout << "infinity" << endl;
	}
	else if (C1 > D1 && C1 + C2 < D1 + D2) {
		auto S1 = C1 - D1;
		auto S2 = (2 * C1 + C2) - (2 * D1 + D2);
		if (S2 >= 0) {
			auto ans = S1 / (S1 - S2) * 2;
			if (S1 % (S1 - S2) != 0) {
				++ans;
			}
			cout << ans << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else if (C1 < D1 && C1 + C2 > D1 + D2) {
		auto S1 = D1 - C1;
		auto S2 = (2 * D1 + D2) - (2 * C1 + C2);
		if (S2 >= 0) {
			auto ans = S1 / (S1 - S2) * 2;
			if (S1 % (S1 - S2) != 0) {
				++ans;
			}
			cout << ans << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int num;
    scanf("%d", &num);
    int count = 0;
    
    while(num--){
        int a, b;
        scanf("%d %d", &a, &b);
        count += b - a + 1;
    }
    
    printf("%d\n", count);
    return 0;
}


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

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

fn main() {
    let n: usize = read();
    let mut reds: Vec<(i32, i32)> = vec![(0, 0); n];
    let mut blues: Vec<(i32, i32)> = vec![(0, 0); n];
    for i in 0..n {
        reds[i].0 = read();
        reds[i].1 = read();
    }
    reds.sort();
    for i in 0..n {
        blues[i].0 = read();
        blues[i].1 = read();
    }
    blues.sort();
    let mut ans = 0;
    for b in blues.iter() {
        let mut candidate = None;
        let mut maxy = 0;
        for i in 0..reds.len() {
            let r = reds[i];
            if b.0 < r.0 || b.1 < r.1 { continue; }
            if r.1 < maxy { continue; }
            candidate = Some(i);
            maxy = r.1;
        }
        if candidate != None {
            ans += 1;
            reds.remove(candidate.unwrap());
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int group(int n)
{
    if (n == 2) return 1;
    else if (n <= 7 && n % 2 == 1) return 2;
    else if (n >= 8 && n % 2 == 0) return 2;
    else return 3;
}
int main()
{
    int x, y;
    cin >> x >> y;
    if (group(x) == group(y)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[M];
		int[] d = new int[M];
		for(int i=0; i<N; i++){
			a[i]  = sc.nextInt();
			b[i]  = sc.nextInt();
		}
		for(int i=0; i<M; i++){
			c[i]  = sc.nextInt();
			d[i]  = sc.nextInt();
		}
		
		int[] ans = new int[N];
		double min = 0;
		double temp = 0;
		for(int i=0; i<N; i++){
			min = Math.abs((double)a[i]-(double)c[0])+Math.abs((double)b[i]-(double)d[0]);
			ans[i] = 0;
			for(int j=1; j<M; j++){
				temp =Math.abs((double)a[i]-(double)c[j])+Math.abs((double)b[i]-(double)d[j]);
				if(temp<min){
					min = temp;
					ans[i] = j;
				}
				
			}
		}
		
		for(int i=0; i<N; i++){
			System.out.println(ans[i]+1);
		}
		
		
	}

}


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

int main() {
    string S,T;
    cin >> S >> T;

    int l = S.size() - 1;

    for (int i=l; i>0; i--) { 
        if (S==T) {
            cout << "Yes" << endl;
            break;
        }
        string S1;
        S1=S[l];
        string S2;
        S2=S.erase(l);
        S= S1+S2;
        if (S==T) {
            cout << "Yes" << endl;
            break;
        }
        else if (S!=T && i==1) cout << "No" << endl;
    }
}

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

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] p = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = scan.nextInt();
		}
		Arrays.sort(p);
		int Sum = 0;
		int i = 0;
		for(i=0;i<N-1;i++) {
			Sum += p[i];
		}
		Sum += p[i]/2;
		System.out.println(Sum);
	}
}

Measured memory_bytes: 21844
import sys
import math
from collections import Counter
from collections import OrderedDict
def inputt():
    return sys.stdin.readline().strip()
def printt(n):
    sys.stdout.write(str(n)+'\n')
def listt():
    return [int(i) for i in inputt().split()]

def gcd(a,b): 
   return math.gcd(a,b) 
 
def lcm(a,b): 
    return (a*b) / gcd(a,b) 

def dfs(src, visit):
    count=1
    visit[src] = 1
    for nbr in dic[src]:
        if nbr==-1:
            continue
        if visit[nbr] == 0:
            count+=dfs(nbr, visit)   
    return count          


t=int(inputt())
if t==0:
    printt(1)
elif t==1:
    printt(0)

    

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

int isok(char*);
void siza(char*);

int main(void) {
	char data[100];
	while(!feof(stdin)) {
		if(fgets(data,sizeof(data),stdin)==NULL)break;
		while(!isok(data))siza(data);
		printf("%s",data);
	}
	return 0;
}

int isok(char* data) {
	if(strstr(data,"the"))return 1;
	if(strstr(data,"this"))return 1;
	if(strstr(data,"that"))return 1;
	return 0;
}

void siza(char* data) {
	int i;
	for(i=0;data[i]!=0;i++) {
		if(data[i]>='a' && data[i]<='z') {
			if(data[i]=='z')data[i]='a';
			else data[i]++;
		}
	}
}

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


typedef vector<int> vi;

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
  vi p, rank, setSize;                       // remember: vi is vector<int>
  int numSets;
public:
  UnionFind(int N) {
    setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
    p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) { 
    if (!isSameSet(i, j)) { numSets--; 
    int x = findSet(i), y = findSet(j);
    // rank is used to keep the tree short
    if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
    else                   { p[x] = y; setSize[y] += setSize[x];
                             if (rank[x] == rank[y]) rank[y]++; } } }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

ll kruskal_mst(vector <pair<ll, pair<int,int> > > &edges, int n)
{
    UnionFind ut(n);
    sort(edges.begin(), edges.end());
    int i = 0;
    ll ans = 0;

    while(ut.sizeOfSet(0) != n)
    {   
        int s1 = edges[i].second.first;
        int s2 = edges[i].second.second;

        if(!ut.isSameSet(s1, s2))
        {
            ut.unionSet(s1, s2);
            ans += edges[i].first;
        }

        i++;
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector <pair<ll, int> > x(n), y(n);

    for(int i = 0; i < n; i++)
    {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector <pair<ll, pair<int,int> > > edges;

    for(int i = 1; i < n; i++)
    {
        edges.push_back({x[i].first - x[i - 1].first, {x[i].second, x[i - 1].second}});
        edges.push_back({y[i].first - y[i - 1].first, {y[i].second, y[i - 1].second}});
    }

    cout << kruskal_mst(edges, n) <<"\n";
    return 0;
}


Measured memory_bytes: 9584
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int x;
    cin >> x;
    if (x == 0)
    {
        cout << "0";
        return 0;
    }
    string odp = "";
    while (x != 0)
    {
        int r = x % (-2);
        x /= -2;
        if (r < 0)
        {
            r += 2;
            ++x;
        }
        odp = (char) (r + '0') + odp;
    }
    cout << odp;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;
const ll MOD = 1000000007;

using namespace std;

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

int main() {
	int n, k; cin >> n >> k;

	int prv = pow(2, k);
	
	int a = (n - k) * 100;

	ll ans = ((1900 * k) + a) * prv;
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  int n, a, b;
  cin >> n >> a >> b;

  cout << min(n*a, b) << endl;
    
  return 0;
}

Measured memory_bytes: 256
x = int(input())
pf = [True]*(10**6)
for i in range(10**6):
    if i == 0 or i == 1:
        pf[i] = False
        continue
    for j in range(2, (10**6-2)//i):
        pf[j*i] = False
for i in range(10**6):
    if pf[i] and i >= x:
        print(i)
        exit()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

ll dist(P p1, P p2) {
    return abs(p1.first-p2.first) + abs(p1.second-p2.second);
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, m; cin >> n >> m;
    vector<P> a(n), b(m);
    REP(i, n) cin >> a[i].first >> a[i].second;
    REP(i, m) cin >> b[i].first >> b[i].second;
    REP(i, n) {
        ll ans = 0;
        REP(j, m) {
            if (dist(a[i], b[j]) < dist(a[i], b[ans])) {
                ans = j;
            }
        }
        cout << ans+1 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;


#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    ll res = n * (n-1) / 2 + m * (m-1) / 2;
    cout << res << "\n";
    
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n;
  int idx = 0, out = 0, f = 0, s = 0, t = 0, score = 0;
  while(true) {
    if(out == 3) {
      cout << score << endl;
      idx++;
      out = 0, f = 0, s = 0, t = 0, score = 0;
      continue;
    }
    if(idx == n) break;
    string str;
    cin >> str;
    if(str == "OUT") out++;
    else if(str == "HIT") {
      if(t) score++;
      if(s) t = 1;
      else t = 0;
      if(f) s = 1;
      else s = 0;
      f = 1;
    } else if(str == "HOMERUN") {
      if(f) score++;
      if(s) score++;
      if(t) score++;
      score++;
      f = s = t = 0;
    }
    // cout << f <<" "<< s <<" "<< t <<" "<< score << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,W = map(int,readline().split())
goods = [tuple(map(int,readline().split())) for i in range(N)]

from collections import defaultdict

d = defaultdict(int)
d[0] = 0

for (w,v) in goods:
    dnew = defaultdict(int)
    for key,value in d.items():
        dnew[key] = value
    for key,value in d.items():
        dnew[key+w] = max(dnew[key+w],d[key]+v)
    d = dnew
ans = 0
for k,v in d.items():
    if k <= W:
        ans = max(ans,v)
print(ans)



Measured memory_bytes: 10948
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, str;
    int n, len;
    vector<string> v;
    cin >> n >> len;
    while (n--)
    {
        cin >> s;
        v.push_back(s);
    }

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

    for (int i = 0; i < v.size(); i++)
    {
        str += v[i];
    }

    cout << str;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
  int A,B,C,X,cnt = 0;
  cin >> A >>B >> C >> X;
  
  for (int i = 0; i <= A; i++){
      for (int j = 0; j <= B; j++){
          if ((X - (500*i + 100*j)) /50 <= C && (X - (500*i + 100*j)) /50 >= 0){
              cnt++;
          }
      }
  }
  cout << cnt <<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
 string a;
  cin>>a;
  bool b=0;
  if(a=="AKIHABARA"||a=="KIHABARA"||a=="AKIHBARA"||a=="AKIHABRA"||a=="AKIHABAR")
    b=1;
  else if(a=="KIHBARA"||a=="KIHABRA"||a=="KIHABAR"||a=="AKIHBRA"||a=="AKIHBAR")
    b=1;
  else if(a=="AKIHBR"||a=="KIHABR"||a=="KIHBAR"||a=="KIHBRA"||a=="AKIHABR")
    b=1;
  else if(a=="KIHBR")
    b=1;
  YESNO(b);
    
}

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++)

 //実装面倒→ランレングス圧縮
int main() {
   string s;
   cin>>s;
   vector<int> ans(s.length());
   int firstR=0;//島のはじめのRのインデックス
   int firstL;//島のはじめのLのインデックス
   rep(i,s.length()-1){
       if(s[i+1]=='L'&&s[i]=='R')firstL=i+1;
       if(s[i+1]=='R'&&s[i]=='L'){
           int sima=i+1-firstR;
           if(sima%2==0){
               ans[firstL-1]=sima/2;
               ans[firstL]=sima/2;
           }
           else if(firstR%2==(firstL-1)%2){
               ans[firstL-1]=sima/2+1;
               ans[firstL]=sima/2;
           }
           else{
               ans[firstL-1]=sima/2;
               ans[firstL]=sima/2+1;
           }
           firstR=i+1;
       }
   }

   //最後だけ例外処理
   int sima=s.length()-firstR;
   if(sima%2==0){
               ans[firstL-1]=sima/2;
               ans[firstL]=sima/2;
           }
           else if(firstR%2==(firstL-1)%2){
               ans[firstL-1]=sima/2+1;
               ans[firstL]=sima/2;
           }
           else{
               ans[firstL-1]=sima/2;
               ans[firstL]=sima/2+1;
           }




   rep(i,s.length()) cout<<ans[i]<<" ";
}

//サンプルは通ったが...

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	init();
	ll K;cin>>K;
	cout<<50<<endl;
	ll nowmod=(K%50);
	if(K<50){
		ll count=0;
		//if(nowmod==0)nowmod=50;
		for(;count<nowmod;count++){
			cout<<50<<endl;
		}
		for(;count<50;count++){
			cout<<0<<endl;
		}
		return 0;
	}
	ll count=0;
	ll index=K/50;
	if(nowmod==0){
		for(;count<50;count++){
			cout<<50+index-1<<endl;
		}
		return 0;
	}
	for(;count<nowmod;count++){
		cout<<50+index<<endl;
	}
	for(;count<50;count++){
		cout<<50-nowmod+index-1<<endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long V = sc.nextLong();

		long B = sc.nextLong();
		long W = sc.nextLong();

		long T = sc.nextLong();

		long dis = Math.abs(A-B);
		long speed = V - W;

		if(speed <= 0) {
			System.out.println("NO");
		}else if((double)dis / speed <= T){
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}


	}



}


Measured memory_bytes: 35936
#include<iostream>
using namespace std;
int a[110][110];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            a[i][j] = 0;
    for(int i=0;i<n;i++){
        int u,k,v;
        scanf("%d%d",&u,&k);
        while(k--){
            scanf("%d",&v);
            a[u-1][v-1] = 1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j) printf(" ");
            printf("%d",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>

int main(){
	int X,a=0,b=0,score=0;
  	scanf("%d",&X);  	
  	a=X/500;
  	b=(X-a*500)/5;
  	score=a*1000+b*5;
  	
  	printf("%d",score);
  	
  	
  	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    
    ll N, K; cin >> N >> K;
    vector<ll> p(N);
    rep(i,N) cin >> p[i];
    vector<ll> cum(N+1);
    rep(i,N){
        cum[i+1] = cum[i] + (p[i]+1);
    }
    ll mx = 0;
    rep(i,N){
        if (i+K > N) break;
        mx = max(mx, (cum[i+K] - cum[i]));
    }
    double ans = mx;
    ans /= 2;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,a[2005][2005],ans=0;
char s[2005][2005];
int h[2005],L[2005],R[2005],st[2005],top;
void solve(){
	h[0]=h[m+1]=-1;
	for(int i=1;i<=n;i++){
		for(int p=1;p<=m;p++){
			if(a[i][p]!=a[i-1][p]) h[p]=1;
			else h[p]++;
		}
		st[top=1]=0;
		for(int p=1;p<=m;p++){
			while(top&&h[p]<=h[st[top]]) top--;
			L[p]=st[top]+1;
			st[++top]=p;
		}
		st[top=1]=m+1;
		for(int p=m;p;p--){
			while(top&&h[p]<=h[st[top]]) top--;
			R[p]=st[top]-1;
			st[++top]=p;
		}
		for(int p=1;p<=m;p++){
			ans=max(ans,h[p]*(R[p]-L[p]+2));
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++){
		for(int p=1;p<=m;p++) a[i][p]=s[i][p]=='#'?1:0;
	}
	/*for(int i=2;i<=n;i++)if(a[i][1]!=a[1][1]){
		for(int p=1;p<=m;p++) a[i][p]^=1;
	}*/
	for(int i=1;i<=n;i++){
		for(int p=1;p<m;p++) a[i][p]=a[i][p+1]^a[i][p];
	}
	m--;
	ans=max(n,m+1);
	solve();
	/*for(int i=1;i<=n;i++){
		for(int p=1;p<=m;p++) a[i][p]^=1;
	}
	solve();*/
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 19968
### main

loop do
  n = gets.to_i
  break if n == 0

  iss = n.times.map{gets.split.map(&:to_i)}.sort{|a, b| a[1] <=> b[1]}
  #p iss

  sum = 0
  ok = true

  for is in iss
    sum += is[0]
    if sum > is[1]
      ok = false
      break
    end
  end

  puts (ok ? 'Yes' : 'No')
end

Measured memory_bytes: 6112