akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];
ll A,B,N;
ll f(ll x){
	int t1 = floor((double)A*x/B);
	int t2 = A*floor((double)x/B);
	return t1-t2;
}
//
int main(){
	cin >> A>>B>>N;

	cout << (f(min(B-1,N))) << endl; 

	return 0;
}
 



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

long d[11][11];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int a = i % 10;
        if(!a)
            continue;
        int b = to_string(i)[0] - '0';
        d[a][b]++;
    }
    long r = 0;
    for(int i = 1; i < 10; i++)
        for(int j = 1; j < 10; j++)
            r += d[i][j] * d[j][i];
    cout << r << endl;
    return 0;
}


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

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		char[] vals = sc.next().toCharArray();
		int n = vals.length;
		int[] ans = new int[n + 1];
		int[] more = new int[n + 1];
		ans[n-1] = 1;
		for (int i = n - 2; i >= 0; i--) {
			more[i] = 1 + ans[i + 2];
			if (vals[i] != vals[i+1]) ans[i] = 1 + ans[i+1];
			else ans[i] = Math.max(1 + ans[i + 2], 1 + more[i+1]);
		}
		out.println(ans[0]);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 28392
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//chmaxs chmin
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; }


//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c){
    LL dp[N+5][3];
    REP(i, N+5)REP(j,3)dp[i][j]=0;
    chmax(dp[0][0], a[0]);
    chmax(dp[0][1], b[0]);
    chmax(dp[0][2], c[0]);
    FOR(i,1,N){
        chmax(dp[i][0],max(dp[i-1][1] + a[i], dp[i-1][2]+a[i]));
        chmax(dp[i][1],max(dp[i-1][0] + b[i], dp[i-1][2]+b[i]));
        chmax(dp[i][2],max(dp[i-1][0] + c[i], dp[i-1][1]+c[i]));
        }
    cout<<max(dp[N-1][2],max(dp[N-1][0],dp[N-1][1]))<<endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, std::move(a), std::move(b), std::move(c));
    return 0;
}


Measured memory_bytes: 4992
from copy import deepcopy


h, w, k = map(int, input().split())
grid = [list(input()) for _ in range(h)]

R = [format(i, "0" + str(h) + "b") for i in range(2**h)]
C = [format(j, "0" + str(w) + "b") for j in range(2**w)]

ans = 0
for r in R:
    for c in C:
        tmp = deepcopy(grid)
        for i in range(h):
            if r[i] == "1":
                for j in range(w):
                    tmp[i][j] = "R"
        for j in range(w):
            if c[j] == "1":
                for i in range(h):
                    tmp[i][j] = "R"
        cnt = 0
        for i in range(h):
            for j in range(w):
                if tmp[i][j] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)


Measured memory_bytes: 9348
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Solver {
    void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] sorted = new int[N];
        for (int i = 0; i < N; i++) {
            sorted[i] = A[i] = sc.nextInt();
        }

        Arrays.sort(sorted);
        int largest = sorted[sorted.length - 1];
        int larger = sorted[sorted.length - 2];
        System.out.println(Arrays.stream(A).map(i -> i == largest ? larger : largest).mapToObj(String::valueOf).collect(Collectors.joining("\n")));
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

Measured memory_bytes: 92312
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long t,i,j,n,a,b,c,d,ans,A,B,x,y,k,one,q,l,r;
	string s,s1,s2,s3;
	cin>>n;
	int arr[125]={0},brr[125]={0};
	cin>>s;
	    for(j=0;j<s.length();j++)
	        arr[s[j]]++;
	
	for(i=1;i<n;i++)
	{
	    cin>>s;
	    for(j=0;j<s.length();j++)
	        brr[s[j]]++;
	    for(k=0;k<125;k++)
	    {
	        arr[k]=min(arr[k],brr[k]);
	    }
	    memset(brr,0,sizeof(brr));

	}
	for(i=0;i<124;i++)
	{
	    cout<<string(arr[i],char(i));
	   //cout<<arr[i];
	}
	
	
    }

}

Measured memory_bytes: 256
import fractions
import math
n = int(input())
li = list(map(int,input().split()))

if len(list(set(li))) == 1:
    print(li[0])
else:
    if len(li) == 1:
        print(li[0])
        exit()
    tmp_gcd = fractions.gcd(li[0],li[1])
    if len(li)>2:
        for i,l in enumerate(li):
            if i == 0 or i == 1:
                continue
            gc = fractions.gcd(tmp_gcd,l)
            tmp_gcd = gc
    print(tmp_gcd)

Measured memory_bytes: 16496
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(x) cout << x << endl;
using namespace std;
int main()
{
    ll x;
    cin >> x;
    put(1000 * (x / 500) + 5 * ((x % 500) / 5))
    return 0;
}

Measured memory_bytes: 3608
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>
//#include <ctime>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 20;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}



int main() {
    setIO();

    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);

    ll i = x / d;
    i = min(i, k);
    ll nx = x - i*d;
    if ((k-i)%2 == 1) nx -= d;
    ll ans = abs(nx);

    cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	int ans=m;
	for(int i=0;i<=n-m;i++){
		int p=0;
		for(int j=0;j<m;j++){
			if(s[i+j]!=t[j]) p++;
		}
		ans=min(ans,p);
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
 
}

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

int solve(int a, int b){
  return abs(a-b);
}

int main(){
  int N,ans=0; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);

  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      ans = max({ans,solve(a.at(i),a.at(j))});
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long llong;

vector<pair<llong, llong>> robot;
llong N;

bool cmp_terminate(pair<llong, llong> r1, pair<llong, llong> r2){
    return r1.first + r1.second < r2.first + r2.second;
}

int main(){
    scanf("%lld", &N);
    robot.resize(N);
    llong x, l;
    for(int i=0;i<N;i++){
        scanf("%lld %lld", &x, &l);
        robot[i] = make_pair(x, l);
    }
    sort(robot.begin(), robot.end(), cmp_terminate);

    llong now_t = -10000000000;
    llong num = 0;
    for(int i=0;i<N;i++){
        if(now_t <= robot[i].first - robot[i].second){
            now_t = robot[i].first + robot[i].second;
            num += 1;
        }else{
            continue;
        }
    }

    printf("%lld\n", num);

    return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "blist"

using namespace std;

const int maxn = 1e5 + 69;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if(fopen(task".in", "r")){
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int x;
    cin >> x;
    if(x == 0) cout << 1;
    if(x == 1) cout << 0;


}
/*
10 3
11 4
12 5
*/


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer M = nextInt(sc);
        System.out.println(24-M+24);
        sc.close();
    }

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

}



Measured memory_bytes: 23252
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;

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

	int x;
	cin >> x;
	
	if (x == 7 || x == 5 || x == 3) cout << "YES" << endl;
	else cout << "NO" << endl;
	
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

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

  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll> A(n+2),B(m+2);
  ll x;
  rep(i,n){
    cin>>x;
    A[i+1]=A[i]+x;
  }
  rep(i,m){
    cin>>x;
    B[i+1]=B[i]+x;
  }
  A[n+1]=1e10;
  B[m+1]=1e10;
  
  int i=0,j=0;
  while(j+1<=m && B[j+1]<=k) j++;
  int ans=j;
  while(i+1<=n && A[i]<=k){
    i++;
    while(j>=0 && A[i]+B[j]>k) j--;
    if(ans<i+j) ans=i+j;
  }
  
  cout<<ans<<endl;

  return 0;
}

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

int main() {
    int h,a;
    cin >> h >> a;
    int ans;
    ans = (h+a-1)/a;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int n, m, w[100005];

int main() {
	scanf("%d%d", &n, &m);
	for(int u, v, i = 1; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		w[u] ^= 1;
		w[v] ^= 1;
	}
	
	for(int i = 1; i <= n; ++i) if(w[i]) return puts("NO"), 0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 512
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;d] = reads int
    let a = (n + 2 * d) / (2 * d + 1)
    printfn "%i" a
    0

Measured memory_bytes: 11996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    string s; cin>>s;
    ll k; cin>>k;
    ll cnt1=0;
    rep(i,0,s.size()){
        if(s[i]=='1'){
            cnt1++;
        }else break;
    }
    if(k<=cnt1) cout<<1<<endl;
    else cout<<s[cnt1]<<endl;
}

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

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int min_b = *min_element(b.begin(), b.end());
    int max_a = *max_element(a.begin(), a.end());
    int ans = 0;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = make_pair(min_b - a[i] + 1, b[i] - max_a + 1);
    }
    sort(p.begin(), p.end());
    int m2 = (int)1.01e9;
    for (int i = 0; i < n - 1; i++) {
        m2 = min(m2, p[i].second);
        ans = max(ans, p[i + 1].first + m2);
    }
    for (int i = 0; i < n; i++) {
        int cur = b[i] - a[i] + 1;//此时包含两个端点的边在计算时一定小于等于最终答案，所以不用特别处理
        cur += max(0, min_b - max_a + 1);
        ans = max(ans, cur);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  int n,i,j;
  ll mask;
  static ll a[300000];
  const ll mod=1e9+7;

  ll tmp[61]={};
  ll bitsum[61]={};

  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }

  mask=1;
  for(j=0;j<61;j++){
    if(a[0]&mask){
      tmp[j]++;
    }
    mask=mask<<1;
  }
  for(i=1;i<n;i++){
    mask=1;
    for(j=0;j<61;j++){
      if(a[i]&mask){
        bitsum[j]+=i-tmp[j];
      }
      else{
        bitsum[j]+=tmp[j];
      }
      mask=mask<<1;
    }

    mask=1;
    for(j=0;j<61;j++){
      if(a[i]&mask){
        tmp[j]++;
      }
      mask=mask<<1;
    }
  }

  ll ans=0;
  mask=1;
  for(i=0;i<61;i++){
    ans+=(bitsum[i]%mod)*(mask%mod);
    ans%=mod;
    mask=mask<<1;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2560
n = int(input())
s = [int(input()) for _ in range(n)]
score = sum(s)
ans = float('inf')
if score % 10 == 0:
  for i in s:
    if i%10 != 0:
      ans = min(ans, i)
  if ans == float('inf'):
    ans = 0
    score = 0
  score -= ans
print(score)


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

#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
using ll = long long;

ll lcm(ll a,ll b){
	
	return (a*b)/(__gcd(a,b));
}

void solve() 
{ 
ll n;
cin>>n;
ll i=10;
ll ans=0;
if(n%2){
	cout<<0;
	return ;
}
while((n/i)>0){
	
	ans=ans+n/i;
	i=i*5;
}
cout<<ans;

}
 

int main(){


		solve();
		cout<<endl;
	
					
}
		

	

		

 



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



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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    ll n,m,ans=1,mod=1e9+7;
    cin>>n>>m;

    if(abs(n-m)>1){
        cout<<0<<endl;
    }else if(abs(n-m)<=1){
        for(int i=1;i<=n;i++){
            ans=(ans*i)%mod;
        }
        for(int i=1;i<=m;i++){
            ans=(ans*i)%mod;
        }

        if(n==m) ans=(ans*2)%mod;

        cout<<ans<<endl;
    }
    
}


Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

int P, Q, R;

signed main()
{
	cin >> P >> Q >> R;
	int a = P + Q;
	int b = Q + R;
	int c = P + R;
	int m = min(a, min(b, c));
	cout << m << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 

int main(){
    set_combi();
    LL n,a,b,c;cin >> n >> a >> b >> c;
    LL ans = 0;
    for (LL i = 0; i < n; i++) {
        ans += combi(n+i-1,i)*fpow(a,n)%mod*fpow(b,i)%mod*fpow(fpow(a+b,n+i),mod-2)%mod*(n+i)%mod;
        ans += combi(n+i-1,i)*fpow(a,i)%mod*fpow(b,n)%mod*fpow(fpow(a+b,n+i),mod-2)%mod*(n+i)%mod;
    }
    cout << ans*(a+b+c)%mod*fpow(a+b,mod-2)%mod << endl;
    return 0;
}


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

int main(void){
    string str;
    string o, p;
    int a, b, q, i;
    
    cin >> str;
    cin >> q;

    for(i = 1; i <= q; i++){
        cin >> o;
        if(o == "print"){
            cin >> a >> b;
            cout << str.substr(a, b - a + 1) << endl;
        }
        else if(o == "reverse"){
            cin >> a >> b;
            string moji = str.substr(a, b - a + 1);
            reverse(moji.begin(), moji.end());
            str.replace(a, b - a + 1, moji);
        }
        else{
            cin >> a >> b >> p;
            str.replace(a, b - a + 1, p);
        }
    }
}


Measured memory_bytes: 3200
fact = [0]*1010
for i in range(1, 1010): fact[i] = fact[i-1]+i

n, k, *a = map(int, open(0).read().split())
a = list(map(lambda x:fact[x]/x, a))
ans = tmp = sum(a[:k])
for i in range(n-k):
    tmp -= a[i]
    tmp += a[i+k]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	string s,t;
	cin>>n>>s>>t;
	int i;
	for(i=n; i>0; i--)
		if(s.substr(n-i,n)==t.substr(0,i))
			break;
	cout<<2*n-i<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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 h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<vector<int>> s(h, vector<int>(w));

  rep(i, h) rep(j, w) {
    if((i < b && j < a) || (i >= b && j >= a)) s[i][j] = 1;
    else s[i][j] = 0; 
  }

  rep(i, h) {
    rep(j, w) cout << s[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 7500
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n >= 'A' && n <= 'Z')
        cout << 1 << '\n';
    else if (n >= 'a' && n <= 'z')
        cout << 2 << '\n';
    else
        cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int n, x, y, z;

pair<bool, vector<int>> process(vector<int> prev, int num)
{
	prev.pb(num);
	bool flag = 0;
	int start = 0;
	while (!flag)
	{
		flag = 1;
		int pos = 1;
		int sum = 0;
		for (int i = start; i < prev.size(); i++)
		{
			sum += prev[i];
			if (pos == 1)
			{
				if (sum > x)
				{
					flag = 0;
				}
				else if (sum == x)
				{
					sum = 0;
					pos = 2;
				}
			}
			else if (pos == 2)
			{
				if (sum > y)
				{
					flag = 0;
				}
				else if (sum == y)
				{
					sum = 0;
					pos = 3;
				}
			}
			else
			{
				if (sum > z)
				{
					flag = 0;
				}
				else if (sum == z)
				{
					return {1, prev};
				}
			}
		}
		if (start == prev.size())
		{
			break;
		}
		if (!flag)
		{
			start++;
		}
	}
	vector<int> updated;
	for (int i = start; i < prev.size(); i++)
	{
		updated.pb(prev[i]);
	}
	return {0, updated};
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x >> y >> z;
	map<vector<int>, ll> m[n + 1];
	ll dp[n + 1];
	dp[0] = 0;
	vector<int> temp;
	m[0][temp] = 1;
	for (int i = 1; i <= n; i++)
	{
		dp[i] = 10 * dp[i - 1];
		for (auto it = m[i - 1].begin(); it != m[i - 1].end(); it++)
		{
			it->second %= mod;
			vector<int> prev = it->first;
			for (int num = 1; num <= 7; num++)
			{
				auto p = process(prev, num);
				if (p.first)
				{
					dp[i] += it->second;
				}
				else
				{
					m[i][p.second] += it->second;
				}
			}

			for (int num = 8; num <= 10; num++)
			{
				vector<int> temp;
				m[i][temp] += it->second;
			}
		}
		dp[i] %= mod;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 70784
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    int n, a, b, c;
    scan(n, a, b, c);
    int ans = n - (a + b - c);
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 2480
N, T = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda ab: ab[0])

# dp[i][j] := i番目の料理までから選んだときの、j分後における満足度の最大値
# dp[i][j] := max(dp[i - 1][j - A] + B, dp[i - 1][j])
dp = [[0] * (T + 1) for _ in range(N + 1)]
ans = 0
for i in range(1, N + 1):
    a, b = AB[i - 1]
    for j in range(T + 1):
        if j == T:
            a = 1
        if j - a < 0:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j - a] + b, dp[i - 1][j])

print(dp[N][T])


Measured memory_bytes: 116952
import sys
from collections import defaultdict
def input():
	return sys.stdin.readline()[:-1]

MOD = 1e9+7
n, x = map(int, input().split())
s = list(map(int, input().split()))
s.sort(reverse=True)
dp = defaultdict(int)
dp[x] = 1
for i in range(n):
	ss = s[i]
	dpp = defaultdict(int)
	for key, value in dp.items():
		dpp[key] += (n-1-i) * value
		dpp[key%ss] += value
	for key in dpp.keys():
		dpp[key] %= MOD
	dp = dpp
ans = 0
for key, value in dp.items():
	ans += value * key
	ans %= MOD
print(int(ans))

Measured memory_bytes: 5288
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

//????????????????????¨????????????????????????

//????????¨????§???????(Point?????????)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b))<EPS)
class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a*x, a*y); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double Abs() { return sqrt(norm()); }
	double norm() { return x*x, y*y; }

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS;
	}
};

//?????????????????¨????§???????????????????????????????
typedef Point Vector;

//?§????p1??¨??????p2?????????
struct Segment { Point p1, p2; };

//??????
typedef Segment Line;

//???
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

//????§???¢
typedef vector<Point> Polygon;

//????????????a??¨b?????????
double dot(Vector a, Vector b) {
	return a.x*b.x + a.y*b.y;
}

//????????????a??¨b?????????
double cross(Vector a, Vector b) {
	return a.x*b.y - a.y*b.x;
}

//????????????a??¨b?????´?????????
bool isOrtogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}
bool isOrtogonal(Point a1, Point a2, Point b1, Point b2) {
	return isOrtogonal(a1 - a2, b1 - b2);
}
bool isOrtogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 -s2.p1), 0.0);
}

//????????????a??¨b???????????????
bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
	return isParallel(a1 - a2, b1 - b2);
}
bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

int main() {
	int n;
	cin >> n;
	Vector v1, v2, v3, v4;
	double x, y;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		v1 = { x,y };
		cin >> x >> y;
		v2 = { x,y };
		cin >> x >> y;
		v3 = { x,y };
		cin >> x >> y;
		v4 = { x,y };
		if (isParallel(v1, v2, v3, v4))cout << 2 << endl;
		else if (isOrtogonal(v1, v2, v3, v4))cout << 1 << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;


int main(){
    ll n,m; cin >> n >> m;
    ll l,hl; l=hl=1;
    int fun;
    rep(i,n){
        ll a; cin >> a;
        l=lcm(l,a);
        hl=lcm(hl,a/2);
        int tmp=0;
        while(a%2==0){
            tmp++;
            a/=2;
        }
        if(i==0) fun=tmp;
        else if(fun!=tmp || hl>m){
            cout << 0 << endl;
            return 0;
        }
    }
    if(m<hl) cout << 0 << endl;
    else cout << ((m-hl)/l)+1 << endl;
return 0;
}


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

int main(){
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  if (A>=K) {
    cout << K <<endl;
  }else if(A+B>=K){
    cout << A <<endl;
  }else{
    cout << A-K+(A+B) <<endl;
  }
}

Measured memory_bytes: 3636
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<Pll>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, 101) {
		sum = 0;
		rep(j, n) {
			if (sum < 0) {
				f = 1;
				break;
			}
			sum += a[j];
			sum -= i;
		}
		if (sum >= 0 && f == 0) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int tyoucount = 0;
		int hisicount = 0;
		while(sc.hasNext()){
			String[] input = sc.next().split(",");
			int hen1 = Integer.valueOf(input[0]);
			int hen2 = Integer.valueOf(input[1]);
			int taikakusen = Integer.valueOf(input[2]);
			if(taikakusen*taikakusen == hen1*hen1 + hen2*hen2){
				tyoucount++;
			}else if(hen1 == hen2){
				hisicount++;
			}
		}
		System.out.printf("%d\n%d\n",tyoucount,hisicount);
		sc.close();
	}
}

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

using namespace std;

int main() {
    int X,Y;
    cin>>X>>Y;
    int res = 0;
    if(X==1 && Y==1) {
        res += 400000;
    }
    if(X == 1) {
        res += 3e5;
    }
    if(X == 2) {
        res += 2e5;
    }
    if(X==3) {
        res+=1e5;
    }
    if(Y == 1) {
        res += 3e5;
    }
    if(Y == 2) {
        res += 2e5;
    }
    if(Y==3) {
        res+=1e5;
    }
    cout<<res;
}


Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int N, s[200009]; long long x[200009], ss[200009];
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> x[i] >> s[i]; x[N] = 1LL << 60;
	for (int i = 0; i < N; i++) ss[i + 1] = s[i] + ss[i];
	long long ret = 0, rm = 1LL << 60;
	for (int i = 0; i < N; i++) {
		rm = min(rm, ss[i] - x[i]);
		ret = max(ret, ss[i + 1] - rm - x[i]);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4096
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

//unionFind
class unionFind {
private:
	int* p;   //親配列のポインタ
	int* rank;
	int N;   //要素数
	int* check;   //同値な要素の数
public:
	unionFind(int);   //コンストラクタ
	int parent(int);   //親要素を返す
	void unit(int, int);   //2要素をつなぐ
	int operator[](int);   //parentの省略形
	~unionFind();
	int size(int n);   //頂点nと同値な要素数を返す
};

unionFind::unionFind(int n) {
	N = n;
	p = new int[N];
	rank = new int[N];
	for (int i = 0; i < N; i++) {
		p[i] = i;
		rank[i] = 0;
	}
	check = new int[N];
	for (int n = 0; n < N; n++)check[n] = 1;
	return;
}

int unionFind::parent(int n) {
	if (n < 0 || n >= N)return -1;
	if (p[n] == n)return n;   //自分が一番上の親
	return p[n] = parent(p[n]);   //つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) {
	return parent(n);
}

void unionFind::unit(int x, int y) {
	x = parent(x), y = parent(y);
	if (x == y)return;   //根が同じだから何もせずに帰る
	int sum = check[x] + check[y];
	if (rank[x] < rank[y])p[x] = y;
	else {
		p[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
	check[x] = sum;
	check[y] = sum;
	return;
}

unionFind::~unionFind() {
	delete(p);
	delete(rank);
	delete(check);
	return;
}

int unionFind::size(int n) {
	return check[parent(n)];
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M, K;
	cin >> N >> M >> K;
	unionFind UF(N);
	VVI fri(N);
	for (int n = 0; n < M; n++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		UF.unit(a, b);
		fri[a].push_back(b);
		fri[b].push_back(a);
	}
	VVI block(N);
	for (int k = 0; k < K; k++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		block[a].push_back(b);
		block[b].push_back(a);
	}
	for (int n = 0; n < N; n++) {
		int ans = UF.size(n);
		for (int ene : block[n]) {
			if (UF[n] == UF[ene])ans--;
		}
		for (int ene : fri[n]) {
			if (UF[n] == UF[ene])ans--;
		}
		cout << ans-1 << " ";
	}
	cout << "\n";
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	string S; cin >> S;
	bool ans = true;

	REP(i,S.length()){
		if(S[i] == 'L' and i % 2 == 0) ans = false;
		else if(S[i] == 'R' and i % 2 == 1) ans = false;
	}
	
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256
// E - Knapsack 2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

#define NMAX 100
#define VMAX 1'000 * NMAX
#define WMAX 1'000'000'000
ll INF = 1e+18;
ll N,W;
int weights[NMAX+1]; // 重さ
int values[NMAX+1]; // 価値
ll dp[NMAX+1][VMAX+1]; // [i][j]: 品番iまでで価値の和jのときの重さの和の最小 (初期値 0)

int main(){
	cin>>N>>W;
	rp(i, 1, N+1) cin>>weights[i]>>values[i]; // i:[i,N]
	rp(j, 1, VMAX+1) dp[0][j] = INF; // 初期値 INF
	rp(i, 1, N+1){ // 品番 i:[1,N]
		int wi = weights[i], vi = values[i];
		rp(j, 0, VMAX+1){ // 価値 j:[0,100000]
			dp[i][j] = dp[i-1][j];
			if(0 <= j-vi)
				chmin(dp[i][j], dp[i-1][j - vi] + wi);
		}
	}
	int ans = 0;
	rp(v, 0, VMAX+1) if(dp[N][v]<=W) chmax(ans, v);
	cout<< ans <<endl;
}


Measured memory_bytes: 79232
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			int min = 400000001; 
			int ans = 0;
			for(int j = 0; j < m; j++) {
				int dis = Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
				//System.out.println(dis);
				if(min > dis) {
					min = dis;
					ans = j+1;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 36068
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 2e5+10;
int A[SIZE][2],C[SIZE],no_use[SIZE],idx[SIZE];
struct Union_Find{
    int d[SIZE],num[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,num[i]=1;
    }
    int find(int x){
        return (x!=d[x])?(d[x]=find(d[x])):x;
    }
    bool uu(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        num[y]+=num[x];
        d[x]=y;
        return 1;
    }
}U;
int main(){
    DRII(N,Q);
    U.init(N);
    priority_queue<PII>qq;
    REP(i,Q){
        RIII(A[i][0],A[i][1],C[i]);
        qq.push(MP(-C[i],i));
    }
    int v=1;
    LL an=0;
    while(v<N){
        PII me=qq.top();qq.pop();
        if(U.uu(A[me.S][0],A[me.S][1])){
            an+=C[me.S];
            v++;
            no_use[me.S]=0;
        }
        else no_use[me.S]++;
        if(no_use[me.S]<5){
            A[me.S][idx[me.S]]++;
            if(A[me.S][idx[me.S]]==N)A[me.S][idx[me.S]]=0;
            C[me.S]++;
            idx[me.S]^=1;
            qq.push(MP(-C[me.S],me.S));
        }
    }
    return 0*printf("%lld\n",an);
}


Measured memory_bytes: 7408
#include<iostream>
#define rep(i,n) for(int i=0; i<n;i++)

using namespace std;

int main(){
  int N; cin >> N;
  int monsters[N]; rep(i,N+1) cin >> monsters[i];
  int heros[N]; rep(i,N) cin >> heros[i];
  long ans = 0;
  rep(i,N){
    int left = min(monsters[i],heros[i]);
    ans += left;
    monsters[i] -= left;heros[i] -= left;
    int right = min(monsters[i+1],heros[i]);
    ans += right;
    monsters[i+1] -= right;heros[i] -= right;
  }
  cout << ans << endl;
  
}

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

int main(void){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int h = ty-sy, w = tx-sx;
    rep(i,h)cout<<'U';
    rep(i,w)cout<<'R';
    rep(i,h)cout<<'D';
    rep(i,w+1)cout<<'L';
    rep(i,h+1)cout<<'U';
    rep(i,w+1)cout<<'R';
    cout<<"DR";
    rep(i,h+1)cout<<'D';
    rep(i,w+1)cout<<'L';
    cout<<"U"<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#include <bits/stdc++.h>
using namespace std;
int sum(vector<int> s){return accumulate(s.begin(),s.end(),0);}
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int n = 3;
    vector<vector<int>> a(3,vector<int>(3));
    rep(i,3)rep(j,3)cin >> a[i][j];
    //rep(i,3)p(a[i]);
    vector<int> x(3);
    vector<int> y(3);
    rep(i,n)y[i] = a[0][i] - x[0];
    rep(i,n)x[i] = a[i][0] - y[0];
    bool flag = true;
    rep(i,n)rep(j,n){
        if(x[i] + y[j] != a[i][j]){
            flag = false;
        }
    }
    if(flag)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

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

int main()
{
    int N, i;
    char S;
    string ans = "Three";

    scanf("%d", &N);

    REP(i, N)
    {
        scanf("%c", &S);

        switch (S)
        {
        case ' ':
            --i;
            break;
        case 'Y':
            ans = "Four";
            goto output;
        default:
            break;
        }
    }

output:
    printf("%s\n", ans.c_str());

    return 0;
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

/*
class Node {
public:
  int num;
  int index;
  bool operator<(const Node& b) const {
    if(num < b.num) return (num < b.num);
    else return index > b.index;
  }

  Node(){
    num=0; index=0;
  }
  Node(int n, int i) : num(n), index(i){
  }
};
*/

int main(){

  string s;
  cin >> s;

  if(s.size() >= 4 && s[0] == 'Y' && s[1] =='A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

void print1d(const vector<int>& vec) {
    for (auto val : vec) {
        cout << val << " ";
    }
    cout << endl;
}

void print2d(const vector<vector<int>>& vec) {
    for (auto row : vec) {
        for (auto val : row) {
            cout << val << " ";
        }
        cout << endl;
    }
}

void solve() {
    int n;
    cin >> n;

    vi arr(n + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    vi L(n + 1, 0), R(n + 1, 0);

    for (int i = 1; i <= n; i++) {
        L[i] = i - arr[i];
        R[i] = i + arr[i];
    }

    map<int, int> mp;
    for (int i = 1; i <= n; i++) {
        mp[L[i]]++;
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        cnt += mp[R[i]];
        if (L[i] == R[i])
            cnt--;
    }

    cout << cnt << endl;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
#endif
    crap;

    solve();

    return 0;
}

Measured memory_bytes: 30660