akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, Q, A[100010], X[100010];
ll acc[100010], acc2[100010];
vector<ll> t, v;

signed main(){
    cin >> N >> Q;
    REP(i, N) cin >> A[i];
    REP(i, Q) cin >> X[i];
    reverse(A, A + N);
    REP(i, N) acc[i + 1] = acc[i] + A[i];
    REP(i, N) acc2[i + 1] = acc2[i] + ((i % 2 == 0) ? A[i] : 0);
    REP(i, (N - 1) / 2){
        t.push_back((A[i + 1] + A[2 * i + 2]) / 2 + 1);
        v.push_back((acc[i + 1] - acc[0]) + (acc2[N] - acc2[2 * i + 2]));
    }
    reverse(ALL(t));
    reverse(ALL(v));
    for(auto x : t) cerr << x << " ";
    cerr << endl;
    REP(i, Q){
        ll itr = upper_bound(ALL(t), X[i]) - t.begin();
        if(itr == 0) PRINT(acc[(N + 1) / 2] - acc[0]);
        else PRINT(v[itr - 1]);
    }
    return 0;
}

Measured memory_bytes: 7420
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a,b,c,d,e,f,g,h,i,j;
    cin>>a>>b;
    if(a==b)
        cout<<"Draw"<<endl;
    if(a==1&&b>1)
        cout<<"Alice"<<endl;
    else if(a>b&&b!=1)
    cout<<"Alice"<<endl;
        if(b==1&&a>1)
        cout<<"Bob"<<endl;
    else if(b>a&&a!=1)
    cout<<"Bob"<<endl;

return 0;}


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

def main():
    N, M, K = list(map(int, input().split()))

    MOD = 998244353

    class Comb:
        def __init__(self, N):
            self.fac = [1] * (N+1)
            for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

        def __call__(self, n, r):
            return self.comb(n, r)

        def comb(self, n, r):
            if r < 0 or r > n: return 0
            return (self.fac[n] * pow(self.fac[r], MOD-2, MOD)) % MOD * pow(self.fac[n-r], MOD-2, MOD) % MOD

        def permutation(self, n, r):
            if r == 0: return 1
            return self.fac[n] * pow(self.fac[n-r], MOD-2, MOD) % MOD

    comb = Comb(N)

    ans = 0

    for i in range(K+1):
        n = (comb(N-1, i) * M) % MOD * pow(M-1, N-1-i, MOD) % MOD
        ans += n
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69868
n = gets.to_i
as = n.times.map{gets.to_i}
as.unshift(0)
flag = Array.new(n+1,false)
flag[1] = true
l = as[1]
cnt = 1
flag[l] = true
loop do
  break if l == 2
  l = as[l]
  cnt += 1
  break if flag[l]
  flag[l] = true
end
puts flag[2] ? cnt : -1


Measured memory_bytes: 4020
N = int(input())

divs = [1] * (N+1)

ans = 1
for i in range(2, N+1):
    if divs[i] == 1:  # prime
        k = i
        while k <= N:
            m = k
            cnt = 1
            while m % i == 0:
                cnt += 1
                m //= i
            divs[k] *= cnt
            k += i
        ans += i*2
    else:
        ans += i*divs[i]
print(ans)

Measured memory_bytes: 145876
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //

const int MX = 5e5 + 100;



void solve(){
	int n;
	cin >> n;
	VL v(n);
	llint ans = 0;
	loop(i, n){
		cin >> v[i];
		if(i && v[i] < v[i -1]){
			ans += v[i -  1] - v[i];
			v[i] = v[i - 1];
		}
	}
	cout << ans;
}




int main() {
	fast_io;
    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}



Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000000
#define maxn 110
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
int a,b;
bool check(int x){
	int ans=0;
	while(x){
		ans+=x%10;
		x/=10;
	}
	return ans>=a&&ans<=b;
}
int main(){
	in(n);
	in2(a,b);
	int ans=0;
	FOR(i,1,n){
		if(check(i))ans+=i;
	}
	out(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    map<string,int> mp;
    int n,m;
    string s;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        mp[s]++;
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> s;
        mp[s]--;
    }
    int ans=0;
    for(auto u:mp)ans=max(ans,u.second);
    cout << ans << endl;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(N):
    w[i],v[i] = map(int,input().split())
maxi=sum(v)
    
dp=[[float("inf") for _ in range(N+1)] for _ in range(maxi+1)]
for _ in range(N+1):
    dp[0][_]=0
    
last=0
for i in range(1,N+1):
    for j in range(1,maxi+1):
        if j<v[i-1]:
            dp[j][i]=min(w[i-1], dp[j][i-1])
        else:
            tmp=w[i-1]+dp[j-v[i-1]][i-1]
            if tmp<=W:
                dp[j][i]=min(tmp, dp[j][i-1])
            else:
                dp[j][i]=dp[j][i-1]

#print(dp)
for j in range(maxi,-1,-1):
    if dp[j][-1]!=float("inf"):
        k=j
        break

ans=0
for i in range(N,0,-1):
    if dp[k][i]==dp[k-v[i-1]][i-1]+w[i-1]:
        k = k-v[i-1]
        ans += v[i-1]
print(ans)


Measured memory_bytes: 247028
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n;

/* add your algorithm here */

int main() {
  cin >> n;
  ll buc[100002];
  rep(i,100002) buc[i] = 0;
  ll a, m = -1;
  rep(i,n) {
    cin >> a;
    buc[a]++;
    m = max(m,a);
  }

  ll res = -1;
  for (ll i = 0; i <= m; ++i) {
    ll sum;
    if (i == 0) {
      sum = buc[i] + buc[i+1];
    } else {
      sum = buc[i-1] + buc[i] + buc[i+1];
    }
    res = max(res, sum);
  }

  cout << res << endl;
}


Measured memory_bytes: 1024
a = list(map(int, input().split()))
count = 0
a.sort()
count += int((a[2] - a[0])/2)
a[0] += int((a[2] - a[0])/2) * 2
a.sort()
count += int((a[2] - a[0])/2)
a[0] += int((a[2] - a[0])/2) * 2
a = list(map(lambda x:x-a[0], a))
if a == [0,0,0]:
  print(count)
elif a == [0,0,1]:
  print(count + 1)
else:
  print(count + 2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define ll	long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.141592653589793
 
int main() 
{	fastio;
	int testcases = 1;
	//cin>>testcases;
	while (testcases--) {
		int a, b; 
		cin>>a>>b;
		cout<<a*b;
		cout<<"\n";	
	}
    return 0; 
}


Measured memory_bytes: 3652
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[0].split(' ')
  const d = input[1]
  let ans = 0
  for (let m = 1; m <= input[0]; m++) {
    for (let i = 22; i <= d; i++) {
      i = `${i}`
      if (i[0] >= 2 && i[1] >= 2 && i[0] * i[1] == m) {
        ans++
      }
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)

int main(void)
{
	int n;
	cin >> n;
	vector<ll> as(n, 0);
	rep(i, n) {
		cin >> as[i];
	}
	vector<ll> ans;
	for (auto e : as) {
		auto it = upper_bound(ans.begin(), ans.end(), e, std::greater<ll>());
		if (it == ans.end()) ans.push_back(e);
		else *it = e;
	}
	cout << ans.size() << endl;
	return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int s[1<<20];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	if(n==0){
		if(m!=0)cout<<-1<<endl;
		else cout<<"0 0"<<endl;
		return 0;
	}
	if(n==1){
		if(m!=0)cout<<-1<<endl;
		else cout<<"0 0 1 1"<<endl;
		return 0;
	}
	a=1<<n;
	if(a<=m){
		cout<<-1<<endl;
		return 0;
	}
	s[0]=s[a]=m;
	for(i=0,j=0;i<a;i++){
		if(i==m)continue;
		j++;
		s[a-j]=s[a+j]=i;
	}
	array_show(s,a*2);
}


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

#define MOD 998244353

long long powm( long long x, int n )
{
	if( n == 0 ) {
		return 1;
	}
	if( n & 1 ) {
		return powm( x, n - 1 ) * x % MOD;
	}
	return powm( x * x % MOD, n / 2 ) % MOD;
}

int main() {
	int N;

	cin >> N;
	vector<int> a( N );
	int sum = 0;
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
		sum += a[i];
	}

	vector<long long> dp( sum + 1 );
	dp[0] = 1;
	for( int x = 0; x < N; x++ ) {
		for( int i = sum; i >= a[x]; i-- ) {
			dp[i] = ( dp[i] + dp[ i - a[x] ] * 2 ) % MOD;
		}
	}
	vector<long long> dp1( sum + 1 );
	dp1[0] = 1;
	for( int x = 0; x < N; x++ ) {
		for( int i = sum; i >= a[x]; i-- ) {
			dp1[i] = ( dp1[i] + dp1[ i - a[x] ] ) % MOD;
		}
	}

	long long ans = powm( 3, N );
	for( int x = 0; x < sum / 2 + 1; x++ ) {
		ans = ( ans - dp[x] * 3 % MOD + MOD ) % MOD;
	}
	if( sum % 2 == 0 ) {
		ans = ( ans + dp1[sum / 2] * 3 ) % MOD;
	}

	cout << ans << endl;

	return 0;
}


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

int n;
string s;

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

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3340
numbers = [int(i) for i in input().split()]

num1 = numbers[0]
num2 = numbers[1]

sum = 0
for i in range (2):
        
    if num1 >=num2:
        sum += num1
        num1 = num1 -1
    else:
        sum += num2
        num2 = num2-1

print (sum)



Measured memory_bytes: 2940
io = DATA.eof? ? STDIN : DATA
n=io.gets.to_i
ar=n.times.map do
  a,b=io.gets.split.map(&:to_i)
  a==b
end
chunk=ar.chunk_while{|a,b|a==b}.to_a
puts chunk.any?{|a|a.size>=3&&a[0]==true} ? "Yes" : "No"

__END__


Measured memory_bytes: 14368
program diverta_city
  implicit none
  integer(8) :: n, w(10,10) = 0_8, l = 23_8, v(10)
  integer :: i, j
  w(1,2) = 1_8
  w(2,1) = 1_8
  w(3,1) = 2_8
  w(1,3) = 2_8
  w(3,2) = 3_8
  w(2,3) = 3_8
  w(4,1) = 4_8
  w(1,4) = 4_8
  w(4,2) = 8_8
  w(2,4) = 8_8
  w(4,3) = 13_8
  w(3,4) = 13_8
  do i = 5, 10
    v(1) = 1_8
    v(2) = 2_8
    j = 2
    do while (j < i-1)
      j = j+1
      v(j) = v(j-2)+v(j-1)+1_8
    end do
    l = l-int(i-3,8)*int(i-2,8)/2_8
    do j = 1, i-1
      w(i,j) = l*v(j)
      w(j,i) = l*v(j)
    end do
    l = l*(v(i-2)+v(i-1)+1_8)-12_8
  end do
  read(*,*) n
  do i = 1, n
    write(*,'(i0)',advance='no') w(i,1)
    do j = 2, n
      write(*,'(x,i0)',advance='no') w(i,j)
    end do
    write(*,*)
  end do
end program diverta_city

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

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; }

const long long INF = 1LL << 60;

int main() {
    int n;
    long long h[100100];
    long long dp[100100];

    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];

    for (int i = 0; i < 100100; i++) dp[i] = INF;

    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


N = int(input())
A = list(map(int, input().split()))

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[(N-1)-i]))  # こっちのAは後ろからみる, iがN-1になった時はA[0]


right.reverse()  # indexが小さいほうが多くの数字を考慮した最大公約数になっている


gcd_list = [gcd(left[i], right[i+1]) for i in range(N)]

print(max(gcd_list))


Measured memory_bytes: 14052
x,y = map(int, input().split())

mod = 10**9+7

def choose(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

n = (2*x-y)/3
m = (y-n)/2

if n >= 0 and m >= 0 and int(n)*10 == n*10 and int(m)*10 == m*10:
    ans = choose(int(m+n), int(m))
else:
    ans = 0
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
using ll = long long ;

int main(){
	ll n ; cin >> n ;
	ll mx ;
	for(int i=sqrt(n);i>0;i--){
		if(n%i==0){
			mx = n/i ;
			break ;
		}
	}
	string s = to_string(mx) ;
	cout << s.size() << endl ;
}



Measured memory_bytes: 256
n = int(input())
cnt = 0
flag = False
for _ in range(n):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
    else:
        cnt = 0
    #print(cnt)
    if cnt == 3:
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

int N, M;
typedef pair<int, i_i> iii;
map<i_i, int> mp;
int S[50000], D[50000], C[50000];
vector<iii> paths[500];
vector<iii> que;
vector<iii> rest;

bool ans[50000];

bool dfs(int now, int from, int destination, int cost) {
    if(now == destination) return true;
    for(auto tmp : paths[now]) {
        int to = tmp.first;
        int nowcost = tmp.second.first;
        int e = tmp.second.second;
        if(to == from) continue;
        if(dfs(to, now, destination, cost)) {
            if(nowcost == cost) {
                ans[e] = false;
            }
            return true;
        }
    }
    return false;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> S[i] >> D[i] >> C[i];
        S[i]--;
        D[i]--;
        mp[{S[i], D[i]}] = i;
        que.push_back({C[i], {S[i], D[i]}});
    }
    UnionFind uni(N);
    sort(que.begin(), que.end());
    for(auto tmp : que) {
        int s = tmp.second.first;
        int t = tmp.second.second;
        if(uni.merge(tmp.second.first, tmp.second.second)) {
            paths[s].push_back({t, {tmp.first, mp[{s, t}]}});
            paths[t].push_back({s, {tmp.first, mp[{s, t}]}});
            ans[mp[{s, t}]] = true;
        } else {
            rest.push_back(tmp);
        }
    }
    /*
    for(int i = 0; i < M; i++) {
        if(ans[i]) cerr << i << " ";
    }
    cerr << endl;
    */
    for(auto tmp : rest) {
        dfs(tmp.second.first, -1, tmp.second.second, tmp.first);
    }
    int ansnum = 0;
    int anscost = 0;
    for(int i = 0; i < M; i++) {
        if(ans[i]) {
            ansnum++;
            anscost += C[i];
        }
    }
    cout << ansnum << " " << anscost << endl;
    return 0;
}


Measured memory_bytes: 8472
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    int a,b,c,d ;
    cin>>a>>b>>c>>d ;
    int ans=b*d ;
    ans=max(ans,a*c) ;
    ans=max(ans,b*c) ;
    ans=max(ans,a*d) ;
    cout<<ans<<endl ;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define rep_sn(i,s,n) for(int i=(s);i<(s)+(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	int n, x;
	cin >> n >> x;
	vi l(n);
	rep(i, n)cin >> l[i];

	int d = 0, cnt = 1;
	rep(i, n) {
		d += l[i];
		if (d <= x)cnt++;
	}

	cout << cnt << endl;

}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto nm = readNums!int;
  auto ks = new int[][](nm[1]);

  foreach(i; 0 .. nm[1]){
    ks[i] ~= readNums!int;
  }

  auto p = readNums!int;
  int cnt;

  for(int i = 0; i < 1<<nm[0]; i++){
    int[] search;
    for(int j = 0; j < nm[0]; j++){
      if(i & (1 << j)){
        search ~= j + 1;
      }
    }
    for(int j = 0; j < nm[1]; j++){
      int c;
      for(int k = 1; k <= ks[j][0]; k++){
        if(canFind(search, ks[j][k])){
          c++;
        }
      }
      if(c % 2 != p[j]) break;
      if(j == nm[1]-1) {
        cnt++;
      }
    }
  }

  writeln(cnt);
}


Measured memory_bytes: 316
#include <iostream>

using namespace std;

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

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

    if(b-a +1 >= k){
        cout<<"OK"<<endl;
    }
    else{
        for(int i = a;i<=b;i++){
            if(i % k == 0){
                cout<<"OK"<<endl;
                break;
            }
            if(i == b){
                cout<<"NG"<<endl;
            }
        }
    }
}


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

int main() {
  ll n,x;
  cin >> n >> x;
  if(x==2*n-1||x==1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  vector<ll> a(2*n-1);
  set<ll> al;
  a[n-1]=x;
  a[n-2]=1;
  a[n]=2*n-1;
  al.insert(x);
  al.insert(1);
  al.insert(2*n-1);
  if(n>2) {
    if(x!=2*n-2) {
      a[n-3]=2*n-2;
      al.insert(2*n-2);
    }
    else {
      a[n+1]=2;
      al.insert(2);
    }
  }
  ll temp=1;
  for(ll i=0;i<2*n-1;i++) {
    while(al.count(temp)) {
      temp++;
    }
    if(a[i]==0) {
      a[i]=temp;
      temp++;
    }
  }
  for(ll i=0;i<2*n-1;i++) {
    cout << a[i] << endl;
  }
}

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

int main(){
  int n;
  while(true){
    cin >> n;
    if(n == 0)
      break;

    vector<string> f(n);
    for(int i=0; i<n; i++)
      cin >> f[i];

    int num = 0;
    bool flag = false;
    bool r = false, l = false;
    for(int i=0; i<n; i++){
      if(f[i] == "ru")
        r = true;
      if(f[i] == "rd")
        r = false;
      if(f[i] == "lu")
        l = true;
      if(f[i] == "ld")
        l = false;

      if(flag){
        if(!r && !l){
          flag = !flag;
          num++;
        }
      }else{
        if(r && l){
          flag = !flag;
          num++;
        }
      }
    }

    cout << num << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3052
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	string s;
	cin >> s;
	if(s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
		
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int top(ll x){
  if(x<=9){return x;}
  else{ return top(x/10);}
}

int main(){
  ll N; cin>>N;
  ll c[10][10]; FILL2(c,10,10,0);
  for(int i=1;i<=N;++i){
    ++c[top(i)][i%10];
  }
  ll ans = 0;
  for(int i=1;i<=9;++i){
    for(int j=1;j<=9;++j){
      ans += c[i][j]*c[j][i];
    }
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define MOD 1000000007
long long int dp[105][100005] ; 
int solve(int n,int k,int arr[]){
   if(n==1 && k<=arr[n] && k>=0){
       return 1 ; 
   }else if(n==1 && k>arr[n]){
       return 0 ; 
   }
    if(dp[n][k]!=-1){
        return dp[n][k]%MOD ;
    }
    long long int ways = 0 ; 
    for(int i =0 ; i<=arr[n] ; i++){
        ways+= (solve(n-1,k-i,arr))%MOD ; 
    }
    return dp[n][k] = ways%MOD ; 
}
 int solve_bottomup(int n,int k,int arr[]){
    //this has much better time complexity . 
    for(int j=0 ; j<=k ;j++){
        dp[1][j] = (j>arr[1])? 0 : 1 ; 
    } //covers the base cases . 
    for(int i = 2 ; i<=n ; i++){
        for(int j =0 ; j<=k ; j++){
            if(j==0){
                dp[i][j] = dp[i-1][j] ; 
            }else{
                dp[i][j] =(MOD+ dp[i][j-1]+dp[i-1][j]-( (j-arr[i]-1>=0) ? dp[i-1][j-arr[i]-1] : 0) )%MOD ; 
            }
        }
    }
return dp[n][k] ; 
}
int main(){
    int n,k ; cin>>n>>k ; 
    int arr[n+1] ; arr[0] = 0; 
    for(int i  = 1; i<=n ; i++){
        cin>>arr[i] ; 
    }
    memset(dp,-1,sizeof(dp)) ; 
    cout<<solve_bottomup(n,k,arr) ; 
}

Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	int N;
	cin >> N;
	cout << (N+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }

        int ans = 0;
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            if (binarySearch(s, n, t) >= 0)
                ans++;
        }

        System.out.println(ans);
    }


    // 二分探索
    static int binarySearch(int[] a, int n, int key) {
        int left = 0;
        int right = n;
        while (left < right) {
            int mid = (left + right) / 2;
            if (a[mid] == key)
                return mid;
            else if (a[mid] < key)
                left = mid + 1;
            else
                right = mid;
        }
        return -1;
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 47840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int x;
  cin >> x;
  if (x < 1200)
    out("ABC");
  else
    out("ARC");
}
int main(void) { solve(); }

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD=1e9+7;



int main(){
	int N,M;
	cin>>N>>M;
	int S[2010], T[2010];
	rep1(i,N)cin>>S[i];
	rep1(j,M)cin>>T[j];
	
	ll dp[2010][2010];
	ll sm[2010][2010];
	dp[0][0]=1;
  	sm[0][0]=1;
	rep1(i,N){
		dp[i][0]=0;
		sm[i][0]=1;
	}
	rep1(j,M){
		dp[0][j]=0;
		sm[0][j]=1;
	}
	rep1(i,N)rep1(j,M){
		if(S[i]==T[j]) dp[i][j]=sm[i-1][j-1];
		else dp[i][j]=0;
		sm[i][j]=(dp[i][j]+sm[i][j-1]+sm[i-1][j]-sm[i-1][j-1]+MOD)%MOD;
	}
/*
  	rep(i,N+1){
      	rep(j,M+1){
        	cout<<dp[i][j]<<" ";
        }
      	cout<<endl;
    }
  	cout<<endl;
  	rep(i,N+1){
      	rep(j,M+1){
        	cout<<sm[i][j]<<" ";
        }
      	cout<<endl;
    }
*/     
	cout<<sm[N][M];
	
}

Measured memory_bytes: 31744
//template---{{{
#include <bits/stdc++.h>

using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main()
{
    int num[3];
    int K;

    cin >> num[0] >> num[1] >> num[2];
    cin >> K;

    int i;
    sort(num, num + 3);

    REP(i, K) num[2] *= 2;

    cout << num[0] + num[1] + num[2] << endl;

    return (0);
}

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

using namespace std;

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


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

	ll n;
	cin >> n;

	vector<pll> v(n);
	rep(i, n){
		cin >> v[i].first;
		v[i].second = i;
	}

	sort(v.begin(), v.end(), greater<pll>());

	ll dp[n+1][n+1];
	rep(i, n+1) rep(j, n+1) dp[i][j] = 0;

	rep(x, n) rep(y, n){
		int idx = x + y;
		if(idx >= n) continue;

		ll val = v[idx].first;
		ll p = v[idx].second;
		if(p >= x) chmax(dp[x+1][y], dp[x][y] + val * (p - x));
		if(n-1-y >= p) chmax(dp[x][y+1], dp[x][y] + val *(n - 1 - y - p));
	}

	ll ans = 0;
	rep(i, n + 1) chmax(ans, dp[i][n-i]);
	cout << ans << endl;
}


Measured memory_bytes: 34956
// ABC120_D
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input(sunippets: inpv, inpn)
    ll N, L;
    cin >> N >> L;
    vector<string> vec(N);
    REP(i, N) cin >> vec[i];
    sort(vec.begin(), vec.end());
    // calculation
    REP(i, N) {
        cout << vec[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int a = n;
    int z = 0;
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'A')
        a = min(a, i);
        if(s.at(i) == 'Z')
        z = max(z, i);
    }
    cout << z - a + 1 << endl;
    return 0; 
}

Measured memory_bytes: 640
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	a = Array{Int}(2,n)
	for i in 1:n
		a[:,i] = readline() |> split |> parseMap
	end
	k = 0
	for i in 0:n-1
		if (a[1,n-i]+k)%a[2,n-i]>0
			k += (a[2,n-i]-(a[1,n-i]+k)%a[2,n-i])
		end
	end
	println(k)
end

main()

Measured memory_bytes: 163120
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[2010];
int main()
{
	ll N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++)cin >> A[i];
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (A[i] > A[j]) {
				if (i < j) {
					ans = (ans + (K * (K + 1) / 2)) % mod;
				}
				else {
					ans = (ans + (K * (K - 1) / 2)) % mod;
				}
			}
			
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int T = sc.nextInt();
		final int H = sc.nextInt();
		
		final int L = sc.nextInt();
		
		int[] ts = new int[N];
		int[] hs = new int[N];
		for(int i = 0; i < N; i++){
			ts[i] = sc.nextInt();
			hs[i] = sc.nextInt();
		}
		
		int store_t = T;
		int store_h = H;
		int cur_p = 0;
		
		while(true){
			boolean abort = false;
			int break_number = 0;
			
			for(int i = 0; i < N; i++){
				//System.out.println((i + 1) + " " + cur_p + " " + store_t + " " + store_h);
				
				//no money
				if(ts[i] == 0 && hs[i] == 0){
					abort = true;
					break_number = i;
					break;
				}
				
				//pay
				if(ts[i] > 0){
					ts[i]--;
					store_t++;
					cur_p += 10;
				}else if(hs[i] > 0){
					hs[i]--;
					store_h++;
					cur_p += 100;
				}
				
				//over limit
				if(store_t > L){
					abort = true;
					break_number = i;
					break;
				}
				
				//retrun money
				if(cur_p >= 90){
					final int rest = cur_p - 90;
					
					final int rest_h = rest / 100;
					final int rest_t = (rest % 100) / 10;
					
					final int t_to_h = Math.max((store_t - rest_t) / 10, 0);
					
					final int h_ret = Math.max(rest_h - t_to_h, 0);
					final int t_ret = Math.max(rest_h - h_ret, 0) * 10 + rest_t;
					
					//final int h_ret = rest / 100;
					//final int t_ret = rest % 100;
					
					//not return
					if(h_ret > store_h || t_ret > store_t){
						abort = true;
						break_number = i;
						break;
					}
					
					//System.out.println(cur_p + " : " + store_t + " " + store_h + "=>" + (store_t - t_ret) + " (" + t_ret + "(" + rest_t + ")"+  ")" + " " + (store_h - h_ret) + "(" + h_ret + " : "  + rest_h + ")");
					
					//remove_store
					store_t -= t_ret;
					store_h -= h_ret;
					//return
					ts[i] += t_ret;
					hs[i] += h_ret;
					//cur_p
					cur_p = 0;
				}
			}
			
			if(abort){
				System.out.println(break_number + 1);
				break;
			}
		}
	}
}

Measured memory_bytes: 20236
#include <algorithm>
#include <cstdio>
#include <vector>
#include <functional>

using namespace std;

vector<int> books[10];
vector<int> sell[10];
int dp[11][2001];

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	
	for(int i = 0; i < n; i++){
		int a,b;
		scanf("%d%d",&b,&a);
		books[a-1].push_back(b);
	}
	
	for(int i = 0; i < 10; i++) sort(books[i].begin(),books[i].end(),greater<int>());
	
	for(int i = 0; i < 10; i++){
		sell[i].push_back(0);
		for(int j = 0,j_n = min(k,(int)books[i].size()); j < j_n; j++){
			sell[i].push_back(books[i][j]+sell[i][j]+2*j);
		}
	}
	
	for(int i = 0; i < 10; i++){
		for(int j = 0,j_n = sell[i].size(); j <= k; j++){
			for(int l = 0; l<=k; l++){
				dp[i+1][l] = max(max(dp[i+1][l],dp[i][l]),l>=j&&j<j_n?dp[i][l-j]+sell[i][j]:0);
			}
		}
	}
	
	printf("%d\n",dp[10][k]);
	
	return 0;
}

Measured memory_bytes: 880
import java.util.Collections;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		CardGameForTwo solver = new CardGameForTwo();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class CardGameForTwo {

		private int n;
		private Stack a;
		private int output;

		private Scanner scanner;

		public CardGameForTwo() {
			scanner = new Scanner(System.in);
			a = new Stack();
			output = 0;
		}

		public void readInput() {
			n = scanner.nextInt();
			for(int i=0; i<n; i++) {
				a.push(scanner.nextInt());
			}
		}

		public  void solve() {
			Collections.sort(a);
			int alice = 0;
			int bob = 0;
			while(!a.isEmpty()) {
				alice += (int) a.pop();
				if(a.isEmpty()) {
					break;
				}
				bob += (int) a.pop();
			}
			output = alice - bob;
		}
		public void writeOutput() {
			System.out.println(output);
		}

	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<time.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define lson l,mid,pos<<1
#define rson mid+1,r,pos<<1|1
using namespace std;

const int maxn=200000+3;
//const int maxm=2000+5;
const ll mod=1e9 + 7;
//const int inf=0x3f3f3f3f;
//const double PI=acos(-1);
//const double eps=1e-8;
//int dir[4][2]={0,1,1,0,0,-1,-1,0};
//const ll INF = 0x3f3f3f3f3f3f3f3fLL;
//ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll inv(ll b){if(b==1) return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int a[15][5];
int n;

int main()
{
    scanf("%d", &n);
    int x;
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        if(x%2==0)
            cnt++;
    }
    if(cnt == 0)
        printf("%d\n",fpow(3,n)-1);
    else
    printf("%d\n",fpow(3,n)-fpow(2,cnt));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,h,w; scanf("%d %d %d",&n,&h,&w);
	long long ans = 0;
	for(int i=0;i<n;i++){
		int a,b; scanf("%d %d",&a,&b);
		ans += (long long)min(a/h,b/w);
	}
	printf("%lld",ans);
	return 0;
}

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

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

// using ll = long long;
// using P = pair<int, int>;

int main() {
    int N;
    cin >> N;

    int X;
    cin >> X;

    int m[110];
    rep(i, N) cin >> m[i];

    // 一個ずつ作った場合の消費質量
    int sum1 = 0;
    rep(i, N) sum1 += m[i];

    // 余った素の質量
    int rest = X - sum1;

    // 昇順にソート
    sort(m, m + N);

    // 残りの材料からもっとも消費質量が少ないドーナツを作れる個数
    int rest_count = rest / m[0];

    cout << N + rest_count << endl;
    return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);

		System.out.println(a - b + 1);

	}

}

Measured memory_bytes: 21332
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

const int MAX_N = 200005;
struct UnionFind{
    int par[MAX_N];
    int rank[MAX_N];
    int N;
    UnionFind() : N(0) {}
    UnionFind(int N){
        Init(N);
    }
    ~UnionFind(){}

    void Init(int N_){
        N = N_;
        REP(i,N){
            par[i] = -1;
            rank[i] = 0;
        }
    }
    int Root(int child){
        if(par[child] < 0) return child;
        else return par[child] = Root(par[child]);
    }
    void Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[y] += par[x];
            par[x] = y;
        }else{
            par[x] += par[y];
            par[y] = x;
            if(rank[x] == rank[y]) ++ rank[x];
        }
    }
    bool Same(int x, int y){
        return Root(x) == Root(y);
    }
    // その頂点から辿り着ける頂点の数（自身も含む）
    int Size(int x){
        return -par[Root(x)];
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind a(N), b(N);
  REP(i,K){
    int p, q;
    cin >> p >> q;
    --p;
    --q;
    a.Unite(p, q);
  }
  REP(i,L){
    int p, q;
    cin >> p >> q;
    --p;
    --q;
    b.Unite(p, q);
  }
  map<pair<int, int>, int > mp;
  REP(i,N){
    mp[{a.Root(i), b.Root(i)}]++;
  }
  REP(i,N){
    if(i) cout << ' ';
    cout << mp[{a.Root(i), b.Root(i)}];
  }
  return 0;
}


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

const int MAXN = 1e5 + 100;

int n, q, a[MAXN];

void gen(int N, int S, int W) {
    int g = S; 
    for(int i=0; i<N; i++) { 
        a[i] = (g/7) % 10;
        if( g%2 == 0 ) { g = (g/2); }
        else           { g = (g/2) ^ W; }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    int s,w;
    while (cin >> n >> s >> w >> q && n) {
        gen(n,s,w);
        reverse(a,a+n);

        int res = 0;
        if (q == 2 || q == 5) {
            int cnt = 0;
            forn(i,n) {
                if (a[i] % q == 0) cnt++;
                if (a[i]) res += cnt;
            }
        }
        else {
            int cum = 0, pot10 = 1;
            map<int,int> cnt; cnt[0]++;
            forn(i,n) {
                cum = cum + pot10*a[i] % q;
                if (cum >= q) cum -= q;
                pot10 = pot10*10 % q;

                if (a[i]) res += cnt[cum];
                cnt[cum]++;
            }
        }
        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 5812
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N],f[N],g[N],l[N],h[N],p[N],q[N];
// f ÖÕ½á  g Áô¸ö¹ÂÁ¢1  lÕýÔÚ¼Ó1  hÁô×Å¶à¸ö1  p¶à¸ö1¼Ó¸ö0  q 10
char s[N];
int main()
{
	cin>>n;scanf("%s",s+1);
	for(int i=1;i<=n;i++)a[i]=s[i]-'0';
	memset(g,0xcf,sizeof(g));
	memset(l,0xcf,sizeof(l));
	memset(h,0xcf,sizeof(h));
	memset(p,0xcf,sizeof(p));
	memset(q,0xcf,sizeof(q));
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
		{
			g[i]=f[i-1];
			h[i]=max(f[i-1],h[i-1])+1;
			l[i]=max(q[i-1],l[i-1])+1;
			f[i]=p[i-1];
		}
		else
		{
			p[i]=h[i-1];
			q[i]=g[i-1];
		}
		f[i]=max(f[i],max(f[i-1],l[i]));
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  
  if (k >= n)
    cout << 0 << "\n";
  else {
  vector<long> h(n);
  rep (i, 0, n) {
    cin >> h.at(i);
  }
    sort (h.begin(), h.end());
    long ans = 0;
    rep (i, 0, n-k)
      ans += h.at(i);
    cout << ans << "\n";
  }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define VJ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair()
#define vi(x) vector<int>x
#define vl vector<long long int>
#define vc vector<char>
#define max 100001 
using namespace std;


void solve(){
	int n,x,t;cin>>n>>x>>t;
	int ans=ceil(1.0*n/x);
	cout<<ans*t;
}

int main(){
	 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	 #endif
	VJ
	solve();
	return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int u, k, *v;
}T_list;
typedef struct graph{
  int d, f;
}T_graph;
int n;
T_list *lst;
T_graph *grp;
int que[100];
int p, q;
void bfs(int);
int main(){
  scanf("%d", &n);
  lst = (T_list *)malloc(sizeof(T_list) * n);
  grp = (T_graph *)malloc(sizeof(T_graph) * n);
  int i, j;
  for(i = n - 1; i >= 0; i--)
    grp[i].d = -1;
  for(i = 0; i < n; i++){
    scanf("%d %d", &lst[i].u, &lst[i].k);
    if(lst[i].k){
      lst[i].v = (int *)malloc(sizeof(int) * lst[i].k);
      for(j = 0; j < lst[i].k; j++){
    scanf("%d", &lst[i].v[j]);
  
      }
  
    }
  }
  grp[0].d = 0;
  p, q = 0;
  que[q] = 0;
  q++;
  for(p = 0; p < n; p++)
      bfs(que[p]);
  for(i = 0; i < n; i++){
    if(lst[i].k)
      free(lst[i].v);
    printf("%d %d\n", i + 1, grp[i].d);
  }
  free(grp), free(lst);
  return 0;
}
 
void bfs(int v){
  
  int i;
  for(i = 0; i < lst[v].k; i++){
    if(!(grp[lst[v].v[i] - 1].d + 1)){
      grp[lst[v].v[i] - 1].d = grp[v].d + 1;
      que[++q] = lst[v].v[i] - 1;
     
    }
  }
}

Measured memory_bytes: 600