akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=998244353;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        p[i]={a[i],b[i]};
    }
    sort(p,p+n);

    for(int i=0;i<n;i++){
        a[i]=p[i].first;
        b[i]=p[i].second;
    }
    set<pair<int,int>> st;
    for(int i=0;i<n;i++){
        st.insert({b[i],i});
    }
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        auto it=st.lower_bound({a[i],-1});
        if(st.end()==it){
            cout<<"No"<<endl;
            return 0;
        }
        if(prev(st.end())==it){
            if((*it).second!=i){
                st.insert({b[i],(*it).second});
                st.erase({b[i],i});
                b[(*it).second]=b[i];
                cnt++;
            }
            st.erase(it);
        }
        else{
            st.erase({b[i],i});
        }
        if(n-2<cnt){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 6528
n = int(input())
dp = [[0, 0, 0] for _ in range(n + 1)] #dp[i日目][abcどれをやる]
dp[0][0], dp[0][1], dp[0][2] = map(int,input().split())
for i in range(1, n):
    a,b,c = map(int,input().split())
    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
    dp[i][1] = max(dp[i - 1][2] + b, dp[i - 1][0] + b)
    dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)

print(max(dp[n - 1]))

Measured memory_bytes: 59808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	if(n == 0){
		cout << 1 << "\n";
	}else{
		cout << 0 << "\n";
	}
  return 0;
} 





Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>

#define PI ((double)3.141592653589793238)

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    double r;
    cin >> r;
    cout << 2 * PI * r;

    return 0;

}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint a(N);
    REP(i,N) cin>>a[i];

    vint cnt(40);
    REP(i,40) REP(j,N){
        if(a[j]>>i&1) cnt[i]++;
    }

    K++;

    int ans=0;
    REP(i,40){
        if(~K>>i&1) continue;

        int sum=(1LL<<i)*cnt[i];
        REP(j,i)
            sum+=(1LL<<j)*max(cnt[j],N-cnt[j]);
        for(int j=i+1;j<40;j++){
            if(K>>j&1)
                sum+=(1LL<<j)*(N-cnt[j]);
            else
                sum+=(1LL<<j)*cnt[j];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;

}


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

int n,dp[100001];
int main(){
	
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	if(n==2){
		cout<<abs(arr[1]-arr[0])<<endl;
		return 0;
	}
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll A, B;

    cin >> A >> B;

    cout << (B % A ? B - A : A + B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf llONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 10;

pair < ll, ll > a[N], tmp;
ll c[N];
ll dp[100];

bool cmp(pair < ll, ll > A, pair < ll, ll > B) {
    return A.fir * (B.sec + 1) > B.fir * (A.sec + 1);
}

void solve() {

    int n; ll T;
    scanf("%d %lld", &n, &T);
    int cnt1 = 0, cnt2 = 0;
    rep(i, 1, n) {
        scanf("%lld %lld", &tmp.fir, &tmp.sec);
        if(tmp.fir == 0) c[++ cnt2] = tmp.sec + 1;
        else a[++ cnt1] = tmp;
    }

    sort(c + 1 , c + cnt2 + 1);
    sort(a + 1, a + cnt1 + 1, cmp);

    rep(i, 1, 30) dp[i] = T + 1;
    dp[0] = 0;
    rep(i, 1, cnt2 ) c[i] += c[i - 1];

    rep(i, 1, cnt1 ) {
        dep(j, 1, 30) {
            dp[j] = min(dp[j], (a[i].fir + 1) * (dp[j - 1] + 1) + a[i].sec);
        }
    }

    int ans = 0;
    rep(i, 0, 30) {
        if(dp[i] > T) continue;
        int add = 0;
        if(cnt2) add = upper_bound(c + 1, c + cnt2 + 1, T - dp[i]) - c - 1;
        ans = max(ans, i + add);
    }
    printf("%d\n", ans);
    return ;
}
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

double f(double x, double l, double r, double v) {
	if (l <= x && x <= r) {
		return v;
	}
	else if (x < l) {
		return v + l - x;
	}
	else {
		return v - r + x;
	}
}

int main() {
	int N;
	double v[102] = { 0 }, t[102] = { 0 }, s[102] = { 0 };
	cin >> N;
	REP(i, N) {
		cin >> t[i];
	}
	REP(i, N) {
		cin >> v[i];
	}
	REP(i, N) {
		s[i + 1] = s[i] + t[i];
	}
	
	double dt = 0.5, ans = 0, v1 = 0, v2;
	vector<double> vec;
	REP(i, (int)s[N] * 2) {
		REP(j, N) {
			double y = f((double)(i + 1)*dt, s[j], s[j + 1], v[j]);
			vec.push_back(y);
		}
		vec.push_back(f((double)(i + 1)*dt, 0, 0, 0));
		vec.push_back(f((double)(i + 1)*dt, s[N], s[N], 0));
		double tmp = 1000000;
		REP(k, vec.size()) {
			if (tmp > vec[k]) {
				tmp = vec[k];
			}
		}
		if (tmp >= v1) {
			v2 = v1 + min(tmp - v1, dt);
		}
		else {
			v2 = v1 - min(dt, v1 - tmp);
		}
		ans += (v1 + v2)*0.25;
		//cout << i << " " << v1 << " " << v2 << " " << ans << endl;
		v1 = v2;
		vec.clear();

	}


	cout << fixed;
	cout << setprecision(5) << ans << endl;


	return 0;
}

Measured memory_bytes: 256
// finish date: 2018/04/28

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    vs SS(N);
    rep(i, N) {
        cin >> SS[i];
    }
    int ans = 0;
    rep(k, N) {
        rep(i, N) {
            FOR(j, 1, N - i) {
                if (SS[(k + i) % N][(i + j) % N] != SS[(k + i + j) % N][i]) goto outer;
            }
        }
        ans += N;
        outer:;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        cout << 'x' ;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define PI 3.14159265

int main(){
    double a=0.0, b=0.0, C=0.0;
    double S=0.0;
    double X,Y;
    double c=0.0, L=0.0, h=0.0;
    
    scanf("%lf %lf %lf",&a, &b, &C);  

    S = 0.5 * a*b * sin(C*PI/180);
    c = sqrt((a*a+b*b) - 2*(a*b) * cos(C*PI/180));
    L = a+b+c;
    h = 2*S/a;
    //https://qiita.com/watarumohawk/items/ec17b12ddf8451636d8c
    
    
    printf("%f\n",S);
    printf("%f\n",L);
    printf("%f\n",h);
    
return 0;
}


Measured memory_bytes: 2960
#include<iostream>
#include<map>
using namespace std;
string s;
map<char,string>B;
map<string,char>A;
main()
{A["101"]=' ';
A["000000"]='\'';
A["000011"]=',';
A["10010001"]='-';
A["010001"]='.';
A["000001"]='?';
A["100101"]='A';
A["10011010"]='B';
A["0101"]='C';
A["0001"]='D';
A["110"]='E';
A["01001"]='F';
A["10011011"]='G';
A["010000"]='H';
A["0111"]='I';
A["10011000"]='J';
A["0110"]='K';
A["00100"]='L';
A["10011001"]='M';
A["10011110"]='N';
A["00101"]='O';
A["111"]='P';
A["10011111"]='Q';
A["1000"]='R';
A["00110"]='S';
A["00111"]='T';
A["10011100"]='U';
A["10011101"]='V';
A["000010"]='W';
A["10010010"]='X';
A["10010011"]='Y';
A["10010000"]='Z';
B['A']="00000";
B['B']="00001";
B['C']="00010";
B['D']="00011";
B['E']="00100";
B['F']="00101";
B['G']="00110";
B['H']="00111";
B['I']="01000";
B['J']="01001";
B['K']="01010";
B['L']="01011";
B['M']="01100";
B['N']="01101";
B['O']="01110";
B['P']="01111";
B['Q']="10000";
B['R']="10001";
B['S']="10010";
B['T']="10011";
B['U']="10100";
B['V']="10101";
B['W']="10110";
B['X']="10111";
B['Y']="11000";
B['Z']="11001";
B[' ']="11010";
B['.']="11011";
B[',']="11100";
B['-']="11101";
B['\'']="11110";
B['?']="11111";
	while(getline(cin,s))
	{
		string t="";
		for(int i=0;i<s.size();i++)t+=B[s[i]];
		for(int i=0;i<t.size();)
		{
		    int j=1;
		    for(;i+j<=t.size()&&A[t.substr(i,j)]==0;j++);
		    if(i+j<=t.size())cout<<A[t.substr(i,j)];
		    i+=j;
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll vecerase(ll a,ll *v,ll size,int k,ll b){
    ll cnt=0;
    ll tmp=0;
    if(k==1){
          for(int i=0;i<size;i++){
          if(v[i]%a==0)
          cnt++;}
          return cnt;
    }

    if(k==0) {
        for (int i = 0; i < size; i++){
            if(v[i]%a==0&&v[i]%b==0)
                cnt++;
        }
        return cnt;
    }

}
ll greatest(ll a, ll b, ll c){
    ll tmp=-1;
    if(a>tmp)
        tmp=a;
    if(b>tmp)
        tmp=b;
    if(c>tmp)
        tmp=c;

    return tmp;
}
ll comp(ll a[],ll memo[],ll n){
    if(memo[n]==-1){
        ll k=((abs(a[n]-a[n-1])>abs(a[n]-a[n-2]))?2:1);
        ll yav=(min(abs(a[n]-a[n-1]),abs(a[n]-a[n-2])));
        return yav+comp(a,memo,n-k);
    }
    else if(memo[n]!=-1)
        return memo[n];
}

int main() {
    ll n;
    cin>>n;
    ll a[n];
    ll memo[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        memo[i]=-1;
    memo[0]=0;
    memo[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        memo[i]=min(memo[i-1]+abs(a[i]-a[i-1]),memo[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<memo[n-1]<<endl;
    }



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int n, m; cin >> n >> m;
    map<int, set<int> > mp;
    V<P<int, int> > v(m);
    for(int i = 0; i < m; i++){
        int p, y; cin >> p >> y;
        mp[p].insert(y);
        v[i] = make_pair(p, y);
    }

    map<int, int> mp2;
    for(auto p : mp){
        int i = 1;
        for(auto s : p.second){
            mp2[s] = i;
            i++;
        }
    }

    for(int i = 0; i < m; i++){
        printf("%06d%06d", v[i].first, mp2[v[i].second]);
        cout << "\n";
    }


    return 0;
}


Measured memory_bytes: 22712
N,T = map(int,input().split())
src = list(map(int,input().split()))
minv = src[0]
maxp = ans = 0
for i in range(1,N):
    profit = src[i] - minv
    if profit == maxp:
        ans += 1
    elif profit > maxp:
        maxp = profit
        ans = 1
    minv = min(minv, src[i])

print(ans)

Measured memory_bytes: 15020
n = int(input())
r = [0] * n
for i in range(n):
    r[i] = int(input())
    
minr = r[0]
r[0] = r[1] - r[0]
for i in range(1,n):
    x = r[i] - minr
    if r[i] < minr:
        minr = r[i]
    r[i] = x
    
s = max(r)
print(s)


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

int main(){
  int d,t,s;
  int ans = 0;
  cin >> d >> t >> s;
  ans = t*s;
  
  if(ans >= d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
    
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>

#include<vector>

using namespace std;

int main(){
    int x;
    cin >> x;
    if(x==2)
    {
        cout << x << endl;
        return 0;
    }
    vector<int> primelist;
    vector<bool> isprime(x+1, true);
    isprime[0] = isprime[1] = false;
    for (int i = 0; i * i < x; i += 1)
    {
        if(isprime[i]==true)
        {
            int j = 2 * i;
            while (j <= x)
            {
                isprime[j] = false;
                j = j + i;
            }
            
        }
    }
    for (int i = 0; i < x; i++)
    {
        if(isprime[i]){
            primelist.push_back(i);
        }
    }
    bool f = true;
    int i = x;
    while(f)
    {
        for(int p :primelist)
        {
            if(i%p == 0)
            {
                f = true;
                break;
            }
            else
            {
                f = false;
            }
        
        }
        i++;
    }
    i--;
    cout << i << endl;
    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int d, t, s;
	cin >> d >> t >> s;
	cout << ((s*t >= d) ? "Yes" : "No") << "\n";
	
	return 0;
}


Measured memory_bytes: 3608
import itertools
n = int(input())
A  = tuple(map(int,input().split()))
B  = tuple(map(int,input().split()))
Z = list(itertools.permutations(range(1,n+1)))
a = 0
b = 0
for i,z in enumerate(Z):
  #print(z,A)
  if(z == A):
    a = i+1
  if(z == B):
    b = i+1
print(abs(a-b))

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

#define ll long long
#define v vector

const ll INF = 1e18;

ll digSum(ll b, ll n) {
    if(n < b) return n;
    else return digSum(b, n/b) + (n % b);
}

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

    ll n, s;
    cin >> n >> s;
    if(s == n) cout << n+1 << endl;
    else if(s > n) cout << -1 << endl;
    else {
        ll ans = INF;
        for(ll i = 2; i*i <= n; i ++) {
            if(digSum(i, n) == s) {
                cout << i << endl;
                return 0;
            }
        }
        ll toFac = n - s;
        for(ll i = 1; i*i <= toFac; i ++) {
            if(toFac % i) continue;
            ll canBe = toFac/i;
            if(((canBe + 1) > sqrt(n)) && (digSum(canBe+1, n) == s)) {
                ans = min(ans, canBe+1LL);
            } 
        }
        cout << ((ans != INF) ? ans : -1) << endl;
    }
}

Measured memory_bytes: 256
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define debug(x) cout<<#x<<": "<<x<<endl
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rfor(i, st, en) for(ll i=st; i>=en; i--)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define printv(x) For(i, 0, x.size()){cout<<x[i]<<" ";} cout<<endl;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007

vi adj[200005];

signed main(){
	fast
	int n, qq;
	cin>>n>>qq;
	int a, b;
	For(i, 1, n){
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	vi vals(n+1, 0);
	For(i, 0, qq){
		cin>>a>>b;
		vals[a]+=b;
	}
	queue<int> q;
	vi vis(n+1, 0);
	vi ans(n+1, 0);
	q.push(1);
	vis[1]=1;
	ans[1]=vals[1];
	while(!q.empty()){
		int p = q.front();
		q.pop();
		For(i, 0, adj[p].size()){
			int node = adj[p][i];
			if(!vis[node]){
				ans[node] = ans[p]+vals[node];
				q.push(node);
				vis[node]=1;
			}
		}
	}
	For(i, 1, n+1){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
    return 0;
}
    



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

int main() {
	int x,a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b)) {
		cout << 'B' << endl;
	}
	else {
		cout << 'A' << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return input().rstrip()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    s = SR(n)
    d = defaultdict(int)
    for si in s:
        d[si] += 1
    item = list(d.items())
    item.sort(key=lambda x: x[1], reverse=True)
    m = item[0][1]
    ans = []
    for i, v in item:
        if v == m:
            ans.append(i)
        else:
            break
    ans.sort()
    print("\n".join(ans))
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 119880
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <math.h>
#include <bitset>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

typedef long long ll;

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

ll n, W;

ll w[100], v[100], d[1000000], mx;

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

	for (int i = 0; i < n; i++)
	{
		scanf ("%lld%lld", &w[i], &v[i]);
	}

	ll sum = 0;

	for (int i = 0; i < n; i++)
		for (int j = W; j >= 0; j--)
		{
			if (j + w[i] <= W)
			{
				d[j + w[i]] = max (d[j + w[i]], d[j] + v[i]);
				mx = max (mx, d[j + w[i]]);
			}
		}

	cout << mx;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[110],n,m,k;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	 {
	   scanf("%d",&m);
	   if(m>=a[k]) a[++k]=m;
	 }
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define LL          long long
# define pr          pair
# define mkp         make_pair
# define lowbit(x)   ((x)&(-x))
# define PI          acos(-1.0)
# define INF         0x3f3f3f3f3f3f3f3f
# define eps         1e-8
# define MOD         1000000007

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
# define MX 100005
/**************************/
int n,m;
vector<int> G[MX];
int clo[MX];

bool check()
{
    bool ok=0;
    for (int i=1;i<=n;i++)
    {
        if (G[i].size()>=2)
        {
            if (ok) return 1;
            ok=1;
        }
    }
    return 0;
}

int dfs(int p,int s,int pre)
{
    clo[p] = s%2+1;
    for (int i=0;i<G[p].size();i++)
    {
        int v = G[p][i];
        if (v==pre) continue;
        if (!clo[v])
        {
            if (!dfs(v,s+1,p))
                return 0;
        }
        else if(clo[v]==clo[p]) return 0;
    }
    return 1;
}

int bipartite()
{
    memset(clo,0,sizeof(clo));
    if (!dfs(1,1,-1)) return 0;
    return 1;
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for (int i=1;i<=n;i++) G[i].clear();

        for (int i=1;i<=m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            G[x].push_back(y);
            G[y].push_back(x);
        }
        if (!check())
            printf("0\n");
        else if (!bipartite())
            printf("%lld\n",(LL)n*(n-1)/2-m);
        else
        {
            LL b=0,w=0;
            for (int i=1;i<=n;i++)
            {
                if (clo[i]==1) b++;
                else w++;
            }
            printf("%lld\n",b*w-m);
        }
    }
    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int> 
#define vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 1005
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;


int dfs(char a,char b,map<char,int> visited,map<char,vector<char>> graph){
    if (b==a)return 1;
    visited[a]=1;
    for (auto x:graph[a]){
        if (!visited[x]){
            if(x==b)return 1;
            dfs(x,b,visited,graph);
        }
        
    }
    return 0;

}


int main(){
    string s;
    cin>>s;
    if (s=="RRR")cout<<3<<"\n";
    else if ((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R') )cout<<"2\n";
    else if (s[0]=='R' || s[1]=='R' || s[2]=='R')cout<<"1\n";
    else cout<<"0\n";

       
       
    
    }


Measured memory_bytes: 3632
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<limits>
using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//grobal変数


int main() {
	int n,m,size,cnt=0;
	string s;
	bool flag;
	cin >> n >> m;
	for (int i = n; i <= m; i++) {
		flag = true;
		s=to_string(i);
		size = s.size();
		for (int i = 0; i < (size / 2); i++) {
			if (s[i] != s[size - i-1]) {
				flag=false;
			}
		}
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll N, T;
ll t[200005];
int main()
{
  cin >> N >> T;
    for(ll i = 0; i < N; i++)
    {
      cin >> t[i];
    }
    ll rt = T;
    for(ll i = 1; i < N; i++)
    {
      rt += min(T, t[i] - t[i - 1]);
    }
    cout << rt << endl;
  return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	char s[10];
	sf("%s", s);
	puts((int)s[0] < (int)'a' ? "A" : "a");

	return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        final Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        final Integer[] heights = Arrays.stream(scanner.nextLine().split(" "))
                .map(Integer::parseInt)
                .toArray(Integer[]::new);

        int max = -1;
        int count = 0;
        for (int i = 0; i < heights.length; i++) {
            if (max <= heights[i]) {
                count++;
            }

            max = Math.max(max, heights[i]);
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 28872
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)



int main() {
	int N, M;
	cin >> N >> M;
	int X[100000];
	int Y[100000];
	int color[100000] = { 0 };
	int num[100000] = { 0 };
	int i;
	rep(i, 0, N)num[i] = 1;
	rep(i, 0, M)
		cin >> X[i] >> Y[i];

	color[0] = 1;
	rep(i, 0, M) {
		int x = X[i]-1;
		int y = Y[i]-1;
		num[x] -= 1;
		num[y] += 1;
		if (color[x] == 1)
			color[y] = 1;
		if (num[x] == 0) {
			color[x] = 0;
		}
	}
	int ans = 0;
	rep(i, 0, N) {
		ans += color[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
short t[5000][5000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,k;
	int i,j;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)for(j=0;j<n;j++)t[i][j]=-1;
	for(i=0;i<k;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		t[a-1][b-1]=max(t[a-1][b-1],c);
	}
	for(i=0;i<n-1;i++){
		for(j=0;j<n;j++){
			if(t[i][j]>0){
				t[i+1][j]=max(t[i+1][j],t[i][j]-1);
				if(j<n-1)t[i+1][j+1]=max(t[i+1][j+1],t[i][j]-1);
			}
		}
	}
	int ans=0;
	for(i=0;i<n;i++)for(j=0;j<n;j++)if(t[i][j]>=0)ans++;
	printf("%d\n",ans);
	return 0;
}
		

Measured memory_bytes: 49856
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<int> p(m), y(m);
    vector<vector<pair<int, int> > > v(n);
    for(int i=0; i<m; ++i){
        cin >> p[i] >> y[i];
        v[p[i]-1].push_back(make_pair(y[i], i));
    }
    for(int i=0; i<n; ++i){
        sort(v[i].begin(), v[i].end());
        for(unsigned j=0; j<v[i].size(); ++j){
            y[v[i][j].second] = j + 1;
        }
    }

    for(int i=0; i<m; ++i){
        printf("%06d%06d\n", p[i], y[i]);
    }

    return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main()
{
    int n{};
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    
    vector<vector<int>> dp(3,vector<int>(n));
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];

    for(int i=1;i<n;i++)
    {
        dp[0][i] = a[i] + max(dp[1][i-1],dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1],dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1],dp[1][i-1]);
    }
    int ans = max(dp[0][n-1], max(dp[1][n-1],dp[2][n-1]));
    cout<<ans;
    return 0;
}

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

typedef signed long long ll;
const int MX = 105;
int A[MX];

int main() {
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A + 3);
    cout << A[0] + A[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int A,B,C,D,E,F;

  cin >> A >> B >> C >> D >> E >> F ;

  int a=100*A,b=100*B;

  vector<int> water(0),sugar(0);

    for(int i=0;a*i<=F;i++){
      for(int j=0;b*j<=F;j++){
        water.push_back(a*i+b*j);       
      }                          
    }

    for(int i=0;C*i<=F;i++){
      for(int j=0;D*j<=F;j++){  
        sugar.push_back(C*i+D*j);       
      }                          
    }

    double conmax=0;

    int w=100,s=1;

    for(int i=0;i<water.size();i++){
      for(int j=0;j<sugar.size();j++){

        if(water.at(i)==0&&sugar.at(j)==0) continue;

        if(water.at(i)+sugar.at(j)<=F && sugar.at(j)<=water.at(i)*E/100.0){//Fを越えてないか　溶け残りがないか

          double con = 100.0*sugar.at(j)/(water.at(i)+sugar.at(j));   // ここをint計算しててハマった。100.0などを紛れ込ませてdoubleに変換

          if(con >= conmax) {                        
             w = water.at(i)+sugar.at(j); s = sugar.at(j);
             conmax = con;
          }

        }    

      }
    }  

  cout << w << " " << s <<endl;
 
  return 0;
}

Measured memory_bytes: 2420
# Union Find
# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        # x < y にする
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合に属するかの判定
def same(x, y):
    return find(x) == find(y)


n, m = map(int, input().split())
par = [-1] * n

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

for _ in range(m):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

print(sum(same(i, l[i] - 1) for i in range(n)))

Measured memory_bytes: 21224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define for(i,a,b) for(ll i=a;i<b;i++)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  int k=s.size();
  int i=0;
  ll cnt=0;
  ll pre_a=0;
  while(i<k-2){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      cnt++;
      s[i]='B';
      s[i+1]='C';
      s[i+2]='A';
      cnt +=pre_a;
      i++;
    }
    else{
      if(s[i]=='A'){
        pre_a++;
      }
      else{
        pre_a=0;
      }
    }
      i++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	card := map[string]int{}

	for i := 0; i < n; i++ {
		str := nextLine()
		if _, ok := card[str]; ok {
			card[str]++
		} else {
			card[str] = 1
		}
	}

	m := nextInt()

	for i := 0; i < m; i++ {
		str := nextLine()
		if _, ok := card[str]; ok {
			card[str]--
		} else {
			card[str] = -1
		}
	}

	// fmt.Println(card)

	max := math.Inf(-1)
	for _, v := range card {

		if max < float64(v) {
			max = float64(v)
		}
	}

	if max < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(max)
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
const int N=300010;
int n,a[N],b[N];
bool chk(int l,int r)
{
	int tl=0,tr=0;
	for(int i=l;i<=r;i++)if(b[i]<l||b[i]>r)return 0;
	for(int i=l;i<=r;i++)
		if(b[i]<i)
			if(tl>b[i])return 0;else tl=b[i];
		else if(b[i]>i)
			if(tr>b[i])return 0;else tr=b[i];
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),a[i]=(b[i]==i);
	for(int i=2;i<n;i++)if(!a[i-1]&&!a[i]&&!a[i+1]){puts("No");return 0;}
	for(int i=1;i<=n;i++)if(a[i]==0)
	{
		int x=1,l=i,r=i;
		while((a[r]^x)&&r<=n)r++,x^=1;
		r--;
		if(!chk(l,r)){puts("No");return 0;}
		i=r;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll mod = 1e9 + 7;

ll dp[100010][4];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[n][3] = 1;
  dp[n][2] = 0;
  dp[n][1] = 0;
  dp[n][0] = 0;
  string ss = "ABC";
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '?') {
      dp[i][3] = dp[i + 1][3] * 3;
    } else {
      dp[i][3] = dp[i + 1][3];
    }
    dp[i][3] %= mod;
    for (int j = 2; j >= 0; j--) {
      if (s[i] == '?') {
        dp[i][j] += dp[i + 1][j] * 3;
      } else {
        dp[i][j] += dp[i + 1][j];
      }
      dp[i][j] %= mod;
      if (s[i] == '?' || s[i] == ss[j]) {
        dp[i][j] += dp[i + 1][j + 1];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int k = 1;
    int sum = 0;
    while(sum < n) {
        sum += k;
        k++;
    }

    for(int i = 1; i < k; i++) {
        if(i == sum-n) {
            continue;
        }
        cout << i << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0].split(" ")[0];
    const K = ~~arg[0].split(" ")[1];
    
    console.log((N - K) + 1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */
//文字列中の一文字⇒数字の時は s[i]-'0'
int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(long long int *a, long long int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

long long int cmp( const void *p, const void *q ) {
    return *(long long int*)p - *(long long int*)q;
}//ちいさい順
//qsort(a,n,sizeof(long long int),cmp);


int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);
//char s[n][11]

long long int GCD(long long int a, long long int b){
  long long int L=a,S=b;
  while(1){
    if(S>L){
      L=S+L;
      S=L-S;
      L=L-S;
    }
    if(L%S==0){
      return S;
    }
    L=L%S;
  }
  
}

long long int LCM(long long int a, long long int b){
  return a*b/(GCD(a,b));
}

int main (void)
{
	long long int n,i,min,k,a[5],max,j=1,count[5];
for(i=0;i<4;i++){
  scanf("%lld",&a[i]);
}  
count[0]=a[0]*a[2];
  count[1]=a[1]*a[2];
  count[2]=a[0]*a[3];
  count[3]=a[1]*a[3];
  
  max=count[0];
  for(i=0;i<4;i++){
   // printf("%lld\n",count[i]);
    if(max<=count[i]){
      max=count[i];
} 
  }
  
  printf("%lld",max);
return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

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

	vec A(N + 1), B(N);

	REP(i, N + 1) {
		cin >> A[i];
	}
	REP(i, N) {
		cin >> B[i];
	}

	ll ans = 0;
	REP(i, N) {
		if (A[i] >= B[i]) {
			ans += B[i];
			A[i] -= B[i];
			continue;
		} else {
			ans += A[i];
			B[i] -= A[i];
			if (B[i] > A[i + 1]) {
				ans += A[i + 1];
				A[i + 1] = 0;
				continue;
			} else {
				ans += B[i];
				A[i + 1] -= B[i];
				continue;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

bool fploop(int a){
	if(a%5!=1)return false;
	for(int i=2;i<a;i++){
		if(a%i==0)return false;
	}
	return true;
}
int main(){
	int n,count=0;
	cin>>n;
	for(int i=11;count<n;i++){
		if(fploop(i)){
			cout<<i<<" ";
			count++;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1e9+7;
const int INF=1001001001;

int main() {
  int N,W;
  cin>>N>>W;
  vector<int>w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  vector<vector<int>>dp(105,vector<int>(100005,INF));
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<100005;j++){
      if(dp[i][j]+w[i]<=W){
        chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
      }
      chmin(dp[i+1][j],dp[i][j]);
    }
  }
  int m=0;
  for(int i=100000;i>=0;i--){
     if(dp[N][i]!=INF){cout<<i<<endl;return 0;}
  }
  return 0;  
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    //lint a,b,c;
    //cin >> a>>b>>c;
    vector<lint> v(3);
    REP(i, 3)
    cin >> v[i];
    lint j = 0;

    while (true)
    {
        REP(i, 3)
        {
            if (v[i] % 2 == 1)
            {
                cout << j << "\n";
                return 0;
            }
        }
        j++;
        lint tmp=0;
        REP(i,3){
            tmp += v[i];
        }
        tmp /= 2;
        REP(i, 3)
        {
            v[i]= tmp-v[i]/2;
        }
        

        if(v[0]==v[1]&&v[1]==v[2]){
            cout << -1<< "\n";
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m,X,Y;cin>>n>>m>>X>>Y;
    int abc=1;
    vector<int>x(n),y(m);
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int i=0;i<m;i++)
        cin>>y[i];
    for(int i=X+1;i<=Y;i++){
        abc=1;
        for(int j=0;j<n;j++){
            if(x[j]>=i)
                abc=0;
        }
        for(int j=0;j<m;j++){
            if(y[j]<i)
                abc=0;
        }
        if(abc==1){
            cout<<"No War"<<endl;
            return 0;
        }
    }
    cout<<"War"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(c > b + a) {
			System.out.println(b + b + a + 1);
		}else {
			System.out.println(b + c);
		}
	}
}


Measured memory_bytes: 23892
n, m = [int(el) for el in input().split(' ')]
X = [int(el) for el in input().split(' ')]
X = sorted(X)

if m <= n:
	print(0)
else:
	D = [0]*(m-1)
	for i in range(0, m-1):
		D[i] = X[i+1] - X[i]
	D = sorted(D)
	if n == 1:
		print(sum(D))
	else:
		print(sum(D[:-n+1]))

Measured memory_bytes: 13832
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n + 2);
    rrep(i, n) cin >> A[i];
    A[0] = 0;
    A[n + 1] = 0;
    ll ans = 0;
    rrep(i, n + 1) {
        ans += abs(A[i] - A[i - 1]);
    }
    ll tot;
    rrep(i, n) {
        tot =  ans - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]);
        cout << tot << endl;
    }

    return 0;
}

Measured memory_bytes: 2048
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("");
        int size = s.length;
        int hug = 0;
        for(int i=0; i<size;i++){
            if(s[i].equals(s[size-1-i])){
                continue;
            }
            else{
                s[i] = s[size-1-i];
                hug++;
            }
        }

        System.out.println(hug);
    }
}


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

using namespace std;

int main () {
    int k;
    cin >> k;
    if (k <= 9) {
        printf ("%d\n", k);
        return 0;
    }

    queue<long long> que;
    for (int i = 1; i < 10; i++)
        que.push(i);
    long long cnt = 9;
    while (cnt < k) {
        long long x = que.front();
        que.pop();
        if (x % 10 != 0) {
            cnt++;
            que.push(10 * x + (x % 10) - 1);
        }
        if (cnt == k)
            break;
        
        // case 2
        cnt++;
        que.push(10 * x + (x % 10));
        if (cnt == k) 
            break;
        
        // case 3
        if (x % 10 != 9) {
            cnt++;
            que.push(10 * x + (x % 10) + 1);
        }
    }
    printf ("%lld\n", que.back());
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  int Y = 0;


  cin >> N;
	rep(i,N){
		char op[2];
		cin >> op;

		if (strcmp(op, "Y") == 0 && Y != 1){
			Y = 1;
			}
		}
	if (Y == 0){
		cout << "Three" << endl;
	}
	else{
		cout << "Four" << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections


Edge = collections.namedtuple("Edge", "start end weight")


class UnionFind(object):

    def __init__(self, number_of_nodes):  # ?????????
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))

    def root(self, node):  # ???????±???????
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r  # ????????§???
            return r

    def in_the_same_set(self, node1, node2):  # ????????????????±??????????
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):  # ?±??????????????????????
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


# Kruskal????????????????°???¨?????¨????±???????
def compute_mst_kruskal(max_v, edges):
    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(max_v)
    mst = []
    for edge in edges:
        if not uf.in_the_same_set(edge.start, edge.end):
            uf.unite(edge.start, edge.end)
            mst.append(edge)
    return mst


def main():
    max_v, max_e = map(int, input().split())
    edges = [Edge(*map(int, input().split())) for _ in range(max_e)]
    mst = compute_mst_kruskal(max_v, edges)
    print(sum(edge.weight for edge in mst))


if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int res = 0;
  for (int i = (S.size() - 1) / 2; i > 0; --i) {
    for (int j = 0; j < i; ++j) {
      if (S[j] != S[i + j]) break;
      if (j + 1 == i) res = i;
    }
    if (res > 0) break;
  }
  cout << 2 * res << endl;
}

Measured memory_bytes: 256