akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};


int main() {
	
	int n;
	cin >> n;
	vector<int> c(n);
	rep(i, n) cin >> c[i];
	sort(all(c));
	
	vector<mint> two(n+1);
	two[0] = 1;
	rep(i, n) two[i+1] = two[i] * 2;
	
	mint ans = 0;
	rep(i, n){
		int l = i, r = n-i-1;
		mint now  = two[r];
		if(r > 0) now += two[r-1] * r;
		now *= two[l];
		now *= c[i];
		ans += now;
	}
	ans *= two[n];
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main()
{
  long long int count=0,t=0,T=1000000000,nt=(t+T)/2,i,N,A,B,h[100000];
  scanf("%lld %lld %lld",&N,&A,&B);
  for(i=0;i<N;i++)
    scanf("%lld",&h[i]);
  while(1){
    count =0;
    for(i=0;i<N;i++)
      if(h[i]-B*nt > 0)
        count += (h[i]-B*nt)%(A-B) ? (h[i]-B*nt)/(A-B)+1 :(h[i]-B*nt)/(A-B);
    if(count <= nt)
      T = (t+T)/(long long int)2;
    else
      t = (t+T)/(long long int)2;
    nt =(t+T)/2;
    if(t==T-1)
      break;
  }
  printf("%d\n",T);
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
int cnt[100001];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        cnt[a]++;
    }
    int ans=0;
    for(int i=0;i<100000;i++){
        int sum=cnt[i];
        if(i!=0)sum+=cnt[i-1];
        if(i!=99999)sum+=cnt[i+1];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}

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


int main()
{
int n;
cin >> n;
long long a[3 * n];
priority_queue<long long, vector<long long>, greater<long long>> pq;
long long A[n + 1] = {};

for(int i=0;i<3*n;i++)
{
    cin >> a[i];
}
for(int i=0;i<n;i++)
{
    pq.push(a[i]);
    A[0] += a[i];
}
for(int i=n;i<2*n;i++){
    pq.push(a[i]);
    A[i -n+ 1] = A[i-n] + a[ i] - pq.top();
    pq.pop();
}
priority_queue<long long, vector<long long>> pql;
long long b[n + 1] = {};
for(int i=0;i<n;i++)
{
    pql.push(a[2 * n + i]);
    b[0] += a[2 * n + i];
}
for(int i=0;i<n;i++)
{
    pql.push(a[2 * n - 1 - i]);
    b[i + 1] = b[i] + a[2 * n - 1 - i] - pql.top();
    pql.pop();
}
long long ans = -1e18;
for(int i=0;i<=n;i++){
        ans=max(A[i]-b[n-i],ans);
    }

cout << ans << endl;

}

Measured memory_bytes: 6516
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>
#define chmin(x, y) x = min(x, y)

int main()
{
  string S;
  cin >> S;
  if (S.back() == 's')
  {
    cout << S + "es" << endl;
  }
  else
  {
    cout << S + "s" << endl;
  }
}


Measured memory_bytes: 3628
line = gets.split(' ').map(&:to_i)
N=line[0]
K=line[1]

D=[]

line = gets.split(' ').map(&:to_i)

K.times do |i|
  D[i]=line[i]
end

ans = N
ans_flag=false

(N*10-N).times do
  pre=ans
  break_flag=false
  while pre!=0
    K.times do |i|
     # print ans," ",pre," ",D[i],"\n"
     if pre%10==D[i]
       break_flag=true
       #puts ans,pre,D[i]
       break
     end
    end
    if break_flag==true
       break
    else
      pre/=10
    end
  end
  
  if break_flag==false
    break
  else 
    ans+=1
  end
end

p ans

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

int main()
{

	int N;
	cin >> N;

	if (N < 1000) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}
}






Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;

int main() {
    int n;
    cin >> n;
    typedef pair<int, int> pa;
    vector<pa> v;
    for(int i = 0, a, b; i < n; i++) {
        cin >> a >> b;
        v.emplace_back(b, a);
    }
    sort(v.begin(), v.end());
    int s = 2e9;
    for(int i = n - 1; i >= 0; i--) {
        s = min(s, v[i].first);
        if(s - v[i].second < 0) {
            cout << "No\n";
            return 0;
        }
        s = s - v[i].second;
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 2420
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >> S; 
	map<string, int> mp;
	mp["SUN"] = 7; 
	mp["MON"] = 6; 
	mp["TUE"] = 5; 
	mp["WED"] = 4; 
	mp["THU"] = 3;	
	mp["FRI"] = 2;
	mp["SAT"] = 1;
	cout << mp[S]<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int cnt=0,cnt1=0;
	string s;
	cin>>s;
	
	for(ll i=0;i<3;i++){
		
		if(s[i]=='A' ||s[i]=='a' ){
			cnt++;
		}else if(s[i]=='B'||s[i]=='b'){
			cnt1++;
		}
	}
	if(cnt>0 && cnt1>0){
		cout<<"Yes"<<endl;
	}else{
	cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const ll MAX_N=1e9;
int L;
ll pw(ll n,int m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
		}
		n*=n;
		m>>=1;
	}
	return ret;
}

int main(){
	L=-1;
	REP(k,10){
		cout<<"? 1";
		REP(i,k){
			cout<<0;
		}
		cout<<endl;
		char res;
		cin>>res;
		if (res=='N'){
			L=k;
			break;
		}
	}
	if (L==-1){
		REP(k,10){
			cout<<"? 2";
			REP(i,k){
				cout<<0;
			}
			cout<<endl;
			char r;
			cin>>r;
			if (r=='Y'){
				cout<<"! 1";
				REP(i,k){
					cout<<0;
				}
				cout<<endl;
				break;
			}
		}
	}else{
		ll lb=pw(10,L-1)-1,ub=pw(10,L)-1;
		while(ub-lb>1){
			ll mid=(lb+ub)>>1;
			cout<<"? "<<mid<<"0"<<endl;
			char r;
			cin>>r;
			if (r=='Y'){
				ub=mid;
			}else{
				lb=mid;
			}
		}
		cout<<"! "<<ub<<endl;
	}
	return 0;
}

Measured memory_bytes: 716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] a=new int[3][3];
		int count=0;
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		int n=sc.nextInt();
		int[] b=new int[n];
		for(int i=0;i<n;i++) {
			b[i]=sc.nextInt();
		}
		for(int k=0;k<n;k++) {
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					if(b[k]==a[i][j])a[i][j]=0;
				}
			}
			int sum=0;
			for(int i=0;i<3;i++) {
				sum+=a[i][0]+a[i][1]+a[i][2];
				if(sum==0)count++;
				sum=0;
			}
			for(int i=0;i<3;i++) {
				sum+=a[0][i]+a[1][i]+a[2][i];
				if(sum==0)count++;
				sum=0;
			}
			if(a[0][0]==a[1][1] && a[1][1]==a[2][2]&&a[1][1]==0)count++;
			if(a[0][2]==a[1][1] && a[1][1]==a[2][0]&&a[1][1]==0)count++;
		}
		if(count!=0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 21712
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n, k;
    cin >> n >> k;
    int a[55];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int sum = 0;
    for(int i = n - 1; i >= n - k; i--){
        sum += a[i];
    }
    cout << sum;
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


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

int main() {

    int N, M;
    cin >> N >> M;

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

    int count = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] >= 0.25/M * sum) {
            count++;
        }
    }

    if (count >= M) cout << "Yes" << endl;
    else  cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3624
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(N,
				(p1, p2) -> {
					return p2 - p1;
				});
		long ans = 0;
		for (int i = 0; i < N; i++) {
			int t = sc.nextInt();
			ans += t;
			pq.add(t);
		}
		for (int i = 0; i < M; i++) {
			int t = pq.poll();
			int half = t >> 1;
			ans -= t - half;
			pq.add(half);
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 29624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  int a, b, c;
  cin >> a >> b>> c;
  string ans = "No";
  if (c>=a && c<=b) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push
#define fi first
#define se second
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int unsigned lliu;
typedef long long int lli;
typedef pair<lli,lli> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;

int main(){__
    int bingo[3][3];
    forn(i, 3)
        forn(j, 3)
            cin>>bingo[i][j];
    int n;
    cin>>n;
    vi v(n);
    forn(i, n){
        cin>>v[i];
    }
    sort(v.begin(), v.end());
    int suma;
    forn(i, 3){
        suma=0;
        forn(j, 3){
            if(binary_search(v.begin(), v.end(), bingo[i][j]))
                suma++;
        }
        if(suma==3){
            cout<<"Yes\n";
            exit(0);
        }
    }
    forn(i, 3){
        suma=0;
        forn(j, 3){
            if(binary_search(v.begin(), v.end(), bingo[j][i]))
                suma++;
        }
        if(suma==3){
            cout<<"Yes\n";
            exit(0);
        }
    }
    suma=0;
    forn(i, 3)
        if(binary_search(v.begin(), v.end(), bingo[i][i]))
            suma++;
    if(suma==3){
        cout<<"Yes\n";
        exit(0);
    }
    if(binary_search(v.begin(), v.end(), bingo[2][0]) && 
        binary_search(v.begin(), v.end(), bingo[1][1]) && binary_search(v.begin(), v.end(), bingo[0][2])){
           cout<<"Yes\n";
        exit(0);    
        }
    cout<<"No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
char s[N];
int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {puts("Yes"); break; }
        a -= d;
        if (a <= 0) {puts("No"); break; }
    }
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

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

int main()
{
	int n;
	cin>>n;
	
	vector<ll >v(n);
	ll x=0;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		x^=v[i];
	}
	for(int i=0;i<n;i++)
		cout<<(x^v[i])<<endl;
	return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef vector< bool > vb;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in(a,b) ( (b).find(a) != (b).end())


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

	int n;
	cin >> n;

	vector < double > p(n);
	rep(i, n) cin >> p[i];

	vector< double> dp(n+1);
	dp[0] = 1.0;

	rep(coini, n) {
		for (int j = coini+1; j > 0; j--) {
			dp[j] += dp[j-1] * p[coini];
			dp[j-1] *= (1.0 - p[coini]);
		}
	}

	double sol = 0.0;
	repr(i, n/2+1, n+1) sol += dp[i];

	cout << setprecision(10) << sol;
}


Measured memory_bytes: 384
import java.io.IOException;
import java.util.Scanner;

public class Main {
	/**
	 * Iterate through each line of input.
	 */
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
      	
		System.out.println(n+(n*n)+(n*n*n));
    }
}

Measured memory_bytes: 35808
#include <bits/stdc++.h>
#define INF 99999999999

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll cost[n];
	fill(cost, cost+n, INF);
	cost[0] = 0;
	int h[n];
	for(int i = 0; i < n; i++){
		cin >> h[i];
		if(i)cost[i] = cost[i-1]+abs(h[i]-h[i-1]);
		if(i>1)cost[i] = min(cost[i], cost[i-2]+abs(h[i]-h[i-2]));
	}
	cout << cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

struct P {
    int p[8][8];
};

const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int h, w, c;

bool contain(int y, int x) {
    return y >= 0 && y < h && x >= 0 && x < w;
}

P change(int col, P curr) {
    queue<pii> que;
    que.emplace(0, 0);
    int used[8][8] = {};
    used[0][0]++;
    while (!que.empty()) {
        int y, x;
        tie(y, x) = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (contain(ny, nx) && curr.p[ny][nx] == curr.p[y][x] && !used[ny][nx]) {
                que.emplace(ny, nx);
                used[ny][nx]++;
            }
        }
    }
    P res = curr;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (used[i][j]) {
                res.p[i][j] = col;
            }
        }
    }
    return res;
}

int solve(int lev, P curr) {
    if (lev == 4) {
        curr = change(c, curr);
        queue<pii> que;
        que.emplace(0, 0);
        int used[8][8] = {};
        used[0][0]++;
        while (!que.empty()) {
            int y, x;
            tie(y, x) = que.front();
            que.pop();
            for (int i = 0; i < 4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (contain(ny, nx) && curr.p[ny][nx] == curr.p[y][x] && !used[ny][nx]) {
                    que.emplace(ny, nx);
                    used[ny][nx]++;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                res += used[i][j];
            }
        }
        return res;
    }
    int res = 0;
    for (int i = 1; i <= 6; i++) {
        if (i == curr.p[0][0]) continue;
        P next = change(i, curr);
        res = max(res, solve(lev + 1, next));
    }
    return res;
}

int main() {
    while (cin >> h >> w >> c, h) {
        int p[8][8];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> p[i][j];
            }
        }

        P curr;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                curr.p[i][j] = p[i][j];
            }
        }
        cout << solve(0, curr) << endl;
    }
}


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

using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

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

char c[2010][2010];
vector<ll>a, p;

ll f(ll n, ll x) {
	if (n == 0) {
		if (x <= 0)return 0;
		else return 1;
	}
	else if (x <= a[n - 1] + 1) {
		return f(n - 1, x - 1);
	}
	else {
		return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
	}
}

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	ll target = a[0] / 2;
	ll target2 = (a[0] + 1) / 2;
	ll ans = 0;
	ll dist = INF;
	rep(i, n) {
		if (abs(a[i] - target) + abs(a[i] - target2) <= dist) {
			ans = a[i];
			dist = abs(a[i] - target) + abs(a[i] - target2);
		}
	}
	cout << a[0] << " " << ans << endl;
	return 0;
}


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

int main(){
    int N, get_count = 0;
    cin >> N;
    vector<int> card(N);
    vector<int> player_point(2, 0);
    for(int i = 0;i < N;i++){
        cin >> card[i];
    }
    
    int get_player = 0;
    while(N != get_count){
        int max_i = 0;
        for(int i = 0;i < N;i++){
            max_i = (card[i] > card[max_i]) ? i : max_i;
        }
        player_point[get_player % 2] += card[max_i];
        card[max_i] = 0;
        get_player++;
        get_count++;
    }
    
    cout << player_point[0] - player_point[1] << endl;
    
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    p=sort([parseInt(readline()) for i in 1:n])
    println(sum(p[1:n-1])+div(p[n],2))
end
main()

Measured memory_bytes: 170532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
//ate
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
void yes() { cout << "Yay!\n"; }
void no() { cout << ":(\n"; }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;
    ll x = 0, y = 0;
    FOR(i, 0, n)y += a[i];
    ll ans = LLINF;
    FOR(i, 0, n) {
        x += a[i];
        y -= a[i];
        chmin(ans, abs(x - y));
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W; cin>>H>>W;
    map<char,int> mp;
    rep(h,0,H)rep(w,0,W){
        char c; cin>>c;
        mp[c]++;
    }

    int cntT2=0,cntOdd=0;
    for(auto m:mp){
        cntOdd+=m.second%2;
        if(m.second%4>1) cntT2++;
    }

    string ans="Yes";
    if(H%2 && W%2){
        if(cntOdd>1 || cntT2>W/2+H/2) ans="No";
    }else if(H%2 || W%2){
        if(cntOdd>0 || cntT2>(H%2)*W/2+(W%2)*H/2) ans="No";
    }else{
        if(cntOdd>0 || cntT2>0) ans="No";
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


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

    int M, D;
    cin >> M >> D;
    int res = 0;

    auto ok = [&](int m, int d) {
        string s = to_string(d);
        if (s.length() == 2) {
            int a = s[0] - '0';
            int b = s[1] - '0';
            if (a * b == m && a > 1 && b > 1) {
                return true;
            }
        }
        return false;
    };

    for (int i = 1; i <= M; ++i) {
        for (int j = 1; j <= D; ++j) {
            if (ok(i, j)) {
                ++res;
            }
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll n;
    cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    int cnt = 0; 
    ll cal = 10;
    ll ans = 0;
    while(n>=cal){
        ans += n/cal;
        cal *= 5;
        cnt++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s; cin >> s;
    if (s == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    FOR(i, 0, s.size()-1) {
        FOR(j, i, s.size()-1) {
            string tmp = s.substr(0, i) + s.substr(j, s.size()-j);
            if (tmp == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5+7;
typedef long long ll;
const ll mod=998244353;
ll d[MAX];
ll quick(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int main(){
    int n;
    while(~scanf("%d", &n)){
        memset(d,0,sizeof(d));
        int pos=0,val,flag=1;
        for(int i=0;i<n;i++){
            //int val;
            scanf("%d", &val);
            d[val]++;
            pos=max(pos,val);
            if(i>0){
                if(val==0) flag=0;
            }else{
                if(val!=0) flag=0;
            }
        }
        if(!flag){
            cout<<0;
            return 0;
        }
        ll ans=1,cnt=1;
        for(int i=1;i<=pos;i++){
            
            ans=(ans%mod)*(quick(cnt,d[i])%mod)%mod;
            cnt=d[i];
        }
        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;

    vector<complex<double>> points;
    vector<pair<double, li>> args;
    for (int i = 0; i < n; ++i) {
        li x, y;
        cin >> x >> y;
        complex<double> p(x, y);
        points.emplace_back(p);
        args.emplace_back(arg(p), i);
    }

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

    double ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            complex<double> sum = 0;
            if (j <= i) {
                for (int k = 0; k < j; ++k) {
                    sum += points[args[k].second];
                }
                for (int k = i; k < n; ++k) {
                    sum += points[args[k].second];
                }
            } else {
                for (int k = i; k < j; ++k) {
                    sum += points[args[k].second];
                }
            }
            ans = max(ans, abs(sum));
        }
    }

    cout << setprecision(24) << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

	int ans = 0;

	for (int i = 0; i < N - 1; i++) {
		if (p[i] == i + 1) {
			int temp = p[i];
			p[i] = p[i + 1];
			p[i + 1] = temp;
			ans++;
		}
	}

	if (p[N - 1] == N) {
		ans++;
	}

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

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int N, res;
vector<int> L;

int main() {
    cin >> N;
    for (int i=0; i<N; i++) {
        int l;
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(), L.end());
    for (int i=0; i<N-2; i++) {
        for (int j=i+1; j<N-1; j++) {
            for (int k=j+1; k<N; k++) {
                if (L[k]>=L[i]+L[j]) break;
                res++;
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;
			PriorityQueue<Man> que = new PriorityQueue<Man>();
			
			for(int i=0;i<n;i++) {
				int w = sc.nextInt();
				que.add(new Man(true, w, sc.nextInt()));
				que.add(new Man(false, w, sc.nextInt()));
			}
			boolean flg = true;
			int w=0;
			for(;!que.isEmpty();) {
				Man man = que.remove();
				w += man.on? man.w:-man.w;
				if(w>150) {
					flg = false;
					break;
				}
			}
			if(flg) System.out.println("OK");
			else System.out.println("NG");
		}
	}
	
	class Man implements Comparable<Man> {
		boolean on;
		int w;
		int t;
		Man(boolean on, int w, int t) {
			this.on = on;
			this.w = w;
			this.t = t;
		}
		
		@Override
		public int compareTo(Man o) {
			// TODO 自動生成されたメソッド・スタブ
			if(t==o.t) return on? 1:-1;
			return t-o.t;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    set<int> st;
    rep(i,n) {
        int x;
        cin >> x;
        st.insert(x);
    }
    int ans = st.size() - (st.size() % 2 == 0);
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200100];
int b[200100];
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b,b+N);
	int num=0;
	for(int i=0;i<N;i++)
	{
		if(a[i]==b[N-1]) num++;
	}
	if(num>1)
	{
		for(int i=0;i<N;i++)
		{
		   printf("%d\n",b[N-1]);
	    }
	}
	 else
	 {
	 	for(int i=0;i<N;i++)
		{
		if(a[i]!=b[N-1])
		{
			printf("%d\n",b[N-1]);
		}
		else printf("%d\n",b[N-2]);
	   }
	 }
	return 0;
}

Measured memory_bytes: 3072
#n, *d = map(int, open(0).read().split())
# dream dreamer erase eraser 
n=int(input())

def f(a,b):
    return max(len(str(a)),len(str(b)))
m=10000
for a in range(1,10**10):
    if n%a==0:
        m=min(f(a,n//a),m)
    if n<a or n//a<a:
        break
print(m)

Measured memory_bytes: 9104
using System;
using System.Collections.Generic;
using System.Linq;
using console=System.Console;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            args=new string[3];
            args[0] = console.ReadLine();
            if(args[0].Count()==26)
            {
                 args[1] = ((char)(25 - args[0].Skip(1).Zip(args[0],(a,b)=>a-b).Reverse().TakeWhile(i=>i<0).Count())).ToString();
                 
                 console.WriteLine((args[1][0]==0)?"-1":(string.Join("",args[0].Take(args[1][0]).Select((v,i)=>i==args[1][0]-1?args[0].Last(c=>c>args[0][args[1][0]-1]):v))));
            }
            else
                console.WriteLine(args[0] +(char)('a'+ args[0].OrderBy(c=>c).Where((c,i)=>c-i=='a').Count()));
        }
    }
}

Measured memory_bytes: 13396
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    LL n;
    while (cin >> n)
    {
        LL* p = new LL[n + 5],pj=0;
        for (LL i = 0; i < n; i++)
        {
            cin >> p[i];
            pj += p[i];
        }
        LL k = pj / n,k1=k+1,ans1=0,ans=0;
        
        
        for (LL i = 0; i < n; i++)
        {
            ans =ans+ (p[i] - k )* (p[i] - k);
            ans1 = ans1 + (p[i] - k1) * (p[i] - k1);
        }
        cout << min(ans,ans1) << '\n';
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        string s;
    ll k;
    cin >> s >> k;
    ll n = s.length();
    if (n == 1)
    {
        cout << k / 2 << "\n";
        return 0;
    }
    ll g=0;
    rep (i,0,n)
    {
        if (s[i]==s[i+1])
        {
            g++;
        }
    }
    if (g==n-1)
    {
        cout<<(n*k)/2<<"\n";
        return 0;
    }
    ll ans = 0;
    bool ab = false;
    rep(i, 0, n - 1)
    {
        if (s[i] == s[i + 1])
        {
            ans++;
            i++;
        }
    }
    ll xd=0;
    rev (i,n,1)
    {
        if (s[i]==s[i-1])
        {
            xd++;
        }
        else
        {
            bb;
        }
    }
    ll xd2=0;
    rep (i,0,n-1)
    {
        if (s[i]==s[i+1])
        {
            xd2++;
        }
        else 
        {
            bb;
        }
    }
    if (xd2%2==1&&xd2!=0)
    {
        ab=true;
    }
    if (xd!=0&&xd%2==1)
    {
        ab=true;
    }
    if (s[0]!=s[n-1])
    {
        ab=true;
    }
    if (ab)
    {
        cout << ans * k << "\n";
        return 0;
    }
    else
    {
        cout<<ans*k+k-1<<"\n";
        return 0;
    }
}


Measured memory_bytes: 256
n=int(input())
s=sorted([int(input()) for i in range(n)])
s_sum=sum(s)
if s_sum%10==0:
  for i in range(n):
    if s[i]%10!=0:
      s_sum-=s[i]
      break
    if i==n-1:
      s_sum=0
print(s_sum)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    for(int i = 0;i<100;i++){
    	for(int j = 0;j<100;j++){
        	if(n == i*4+j*7){
            	cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3612
T=int(input())
for TT in range(T):
    a,b,c,d=map(int,input().split(' '))
    l,x,y=(a+b)//(min(a,b)+1),0,0
    if a*l<=b:
        y=a+b
    elif b*l<=a:
        x=a+b
    else:
        x,y=(a*l-b)//(l-1),(b*l-a)//(l-1)
    out=""
    for i in range(c,d+1):
        if i<=x:
            out+="AB"[i%(l+1)==0]
        elif a+b-i+1<=y:
            out+="BA"[(a+b-i+1)%(l+1)==0]
        else:
            out+="AB"[a-x+x//(l+1)-y//(l+1)==0]
    print(out)

Measured memory_bytes: 48984
#include <iostream>
#include <ios>
#include <vector>
#include <queue>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;

constexpr int INF = 1 << 30;

void read_graph(int n, vector<vector<pair<int, int>>> & Es){
    int u, k, v, c;
    while (n--){
        cin >> u >> k;
        while(k--){
            cin >> v >> c;
            Es[u].push_back(pair<int, int>(v, c));
        }
    }
}

void dijkstra(int start, const vector<vector<pair<int, int>>> & Es, vector<int> & dist){
    priority_queue<pair<int, int>, vector< pair<int, int> >, greater<pair<int, int> > > pq;
    pq.emplace(0, start);
    int d, u, v, c;
    while(!pq.empty()){
        tie(d, u) = pq.top();
        pq.pop();
        if (dist[u] < d) continue;
        dist[u] = d;
        for (auto p : Es[u]){
            tie(v, c) = p;
            if (d + c < dist[v]){
                dist[v] = d + c;
                pq.emplace(d + c, v);
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    vector< vector< pair<int, int> > > Es(n);
    vector<int> dist(n, INF);
    
    read_graph(n, Es);
    dijkstra(0, Es, dist);
    
    for (int i = 0; i != n; ++i){
        cout << i << ' ' << dist[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;

struct Item {
    ll w, v;
};

int main() {
    int N; cin >> N;
    ll W; cin >> W;
    vector<Item> I(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> I[i].w >> I[i].v;
    }
    vector<vector<ll>> dp(N + 1, vector<ll>(100000 + 1, INF));  
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 100000; j++) {
            if (j - I[i].v >= 0) chmin(dp[i][j], dp[i - 1][j - I[i].v] + I[i].w); //選ぶ
            chmin(dp[i][j], dp[i - 1][j]); //選ばない
        }
    }
    int ans = 0;
    for (int j = 0; j <= 100000; j++) {
        if (dp[N][j] <= W) ans = j;
    }

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

Measured memory_bytes: 80256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var S = StrArr();

            for (int i = 0; i < N; i++) {
                Console.Write(S[0][i] + "" + S[1][i] + "");
            }
            Console.WriteLine();
        }
    }

    class MyMath {
        public static long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if(n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while(divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

set<int> was;

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

    while (true) {
        if (n < k) {
            cout<<min(n, k-n)<<endl;
            break;
        } else {
            n = n % k;
        }
    }


    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
map<ll,ll> val;
ll a[200009];
ll n,k;
int main()
{
	FAST
	#ifdef ayk_16
    freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	cin>>n>>k;
	ll x;
	ll sum=0;
	val[0]++;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>x;
		sum+=x;
		sum--;
		sum+=k;
		sum%=k;
		a[i]=sum;
		if(i>=k)
			val[a[i-k]]--;
		ans+=val[sum];
		val[sum]++;
	}
	cout<<ans;
}

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

using namespace std;
typedef long long ll;

#define MAX 100001

vector<int> P[MAX];
int path[MAX], p;
bool vis[MAX];

void dfs(int v) {
    if(!vis[v]) path[p++] = v;
    vis[v] = true;
    for(int next : P[v]) {
        if(!vis[next]) {
            dfs(next);
            break;
        }
    }
}

int main(void) {
    int n, m, a, b;
    scanf("%d%d", &n, &m);
    for(int i=0; i<m; i++) {
        scanf("%d%d", &a, &b);
        P[a-1].emplace_back(b-1);
        P[b-1].emplace_back(a-1);
    }

    dfs(0);
    reverse(path, path+p);
    dfs(0);

    printf("%d\n", p);
    for(int i=0; i<p; i++) printf("%d ", path[i]+1);
    printf("\n");
    return 0;
}

Measured memory_bytes: 6784
# https://atcoder.jp/contests/abc047/tasks/arc063_b
#
# 高橋くんが利益を上げる状況は街iで安く仕入れてi+jで高く売ること
# min と maxの差が最大になる点がいくつ存在するかをカウントすれば良い
#


import sys
from collections import Counter
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


N, T = read_ints()
A = read_ints()


# minの点を覚えておく
# 各点に足して差を出す(その点を使うと達成可能な利益)
# minはちゃんと更新
scores = []
mi = 10**9 + 7
for a in A:
    mi = min(mi, a)
    scores.append(a - mi)

ans = Counter(scores)
print(ans[max(scores)])


Measured memory_bytes: 68116