akhauriyash/Code-Regression huggingface dataset:
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int sum;
    void solve()
    {
        cin>>n;
        fo(i,1,n+1)
        {
            if(i%3!=0 && i%5!=0)
                sum+=i;
        }
        cout<<sum<<endl;

    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cmath>

int n, m, x[100005];
int main()
{
	std::cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		std::cin >> x[i];
	}

	std::sort(x, x + m);

	int sum = x[m - 1] - x[0];

	for (int i = 0; i < m - 1; ++i)
		x[i] = x[i + 1] - x[i];
	x[m - 1] = 0;

	std::sort(x, x + m, std::greater<int>());

	int minus = 0;
	for (int i = 0; i < n - 1; ++i) {
		minus += x[i];
	}

	std::cout << sum - minus << std::endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin>>s;
  string t=s;
  for(int i=0;i<s.size();i++){
    if(t[i]=='b')t[i]='d';
    else if(t[i]=='d')t[i]='b';
    else if(t[i]=='p')t[i]='q';
    else if(t[i]=='q')t[i]='p';
    if(t[i]!=s[s.size()-1-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

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

long long dp[100010];

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h.at(i);

    dp[0] = 0;
    dp[1] = dp[0] + abs(h.at(1) - h.at(0));
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h.at(i) - h.at(i - 1)), dp[i - 2] + abs(h.at(i) - h.at(i - 2)));
    }

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

Measured memory_bytes: 1408
object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    for {
      i <- 0 to a
      c500 = 500*i
      if c500 <= x
      j <- 0 to b
      c100 = 100*j
      rem = x - c500 - c100
      if rem >= 0 && rem % 50 == 0 && rem / 50 <= c
//      k <- 0 to c
//      if c500 + c100 + 50*k == x
    } yield true
  }.size

  println(ans)
}

Measured memory_bytes: 27452
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		if(a == b)
			printf("%d\n",c);
		else if(a == c)
			printf("%d\n",b);
		else if(b == c)
			printf("%d\n",a);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;
typedef pair<ld,ld> ldd;
const ld pi = acosl(-1);
const int maxn = 2010;
const ll mod = 998244353;
const ll inf = 1e18;
const ld eps = 1e-10;

ll x,y;

int main() {
    scanf("%lld%lld",&x,&y);
    int cnt = 0;
    while (x <= y) {
        x *= 2;
        cnt++;
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define __ { \
	freopen("input.txt","r",stdin); \
	freopen("output.txt","w",stdout); \
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  __;
   int n;cin>>n;
   vector<int> a(n),b(n);
   for(int i=0;i<n;i++)cin>>a[i];
   	for(int i=0;i<n;i++)cin>>b[i];
   int ans=0;
   for(int i=0;i<n;i++){
   	ans+=max(0,a[i]-b[i]);
   }
   cout<<ans;
}

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

int main(){
  string s;
  int ans=0;

  cin >> s;

  for(int i=0; i<s.length()/2;i++){
  if(s[i]!=s[s.length()-1-i])ans++;

  }
//cout <<s.length();
cout << ans;
return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class myon
{
    public static void Main(string[] args)
    {
        var myon = new myon();
    }

    public myon()
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        int K = int.Parse(Console.ReadLine());

        char k = S[K -1];

        char[] output = new char[N];

        for(int i = 0;i < N;i++)
        {
            if(S[i] != k)
            {
              Console.Write("*");
                //output[i] = '*';
            }
            else
            {
              Console.Write(S[i].ToString());
                output[i] = S[i];
            }
        }

        //Console.WriteLine(S);
    }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i = 0; i < n; i++){
            ans += sc.nextLong()-1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 25444
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

int za[30][30];
vector<int> zz[30];

LL dp[(1 << 21) + 100];
void solve() {

	LL result = 0;
	int n;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> za[i][j];
		}
	}
	int all0 = (1 << n);
	for (int i = 0; i < all0; ++i) {
		int c = 0;
		for (int j = 0; j < n; ++j) {
			if (i& (1 << j)) c++;
		}
		zz[c].push_back(i);
	}
	dp[(1 << n) - 1] = 1;
	for (int i = 0; i < n; ++i) {
		for (auto x : zz[n - i]) {
			for (int j = 0; j < n; ++j) {
				if (za[i][j] == 0) continue;
				if (x & (1 << j)) {
					int nx = x ^ (1 << j);
					dp[nx] += dp[x];
					dp[nx] %= base;
				}
			}
		}
	}
	result = dp[0];
	cout << result << endl;

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 26044
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    ll n, k;
    cin >> n >> k;
    
    vector<ll> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
 
    const int mxd = 50;
    vector<vector<ll>> dp(100, vector<ll>(2, -1));
 
    dp[0][0] = 0;
    for(int d = 0; d < mxd; ++d){
        ll mask = 1ll << (mxd-d-1);
 
        int num = 0;
        for(int i = 0; i < n; ++i) if(a[i] & mask) ++num;
        
        ll xxor0 = mask*num;
        ll xxor1 = mask*(n-num);
 
        if(dp[d][1] != -1){
            dp[d+1][1] = max(dp[d+1][1], dp[d][1] + max(xxor0, xxor1));
        }
 
        if(dp[d][0] != -1){
            if(k & mask){
                dp[d+1][1] = max(dp[d+1][1], dp[d][0] + xxor0);
            }
        }
        if(dp[d][0] != -1){
            if(k & mask) dp[d+1][0] = max(dp[d+1][0], dp[d][0] + xxor1);
            else dp[d+1][0] = max(dp[d+1][0], dp[d][0] + xxor0);
        }
    }
 
    cout << max(dp[mxd][0], dp[mxd][1]) << endl;
 
    return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
#define MAX 100000
int freq[MAX+1];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int n; cin >> n;
		//mset(freq, 0);
		int sum = 0;
		FOR1(i, n){
			int x; cin >> x;
			++freq[x];
			sum += x;
		} 
		int q; cin >> q;
		FOR1(i, q){
			int b, c; cin >> b >> c;
			sum = sum - b*freq[b] + c*freq[b];
			freq[c] += freq[b];
			freq[b] = 0;

			cout << sum << "\n";
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 4428
#include<iostream>
#include<map>
#include<set>
using namespace std;
#define df 0
#define MOD 998244353
typedef long int li;

void print(const map<int,li>& mp){
  for(const auto& x:mp){
    printf("(%d %ld)",x.first,x.second);
  }
  printf("\n");
}

int main(){
  if(df) printf("*debug mode*\n");

  int n,m; cin >>n >>m;
  set<tuple<int,int,li>> road;
  for(int i=0;i<m;i++){
    int s,t,c; cin >>s >>t >>c;
    road.insert(make_tuple(s,t,c));
  }
  map<int,li> mp;
  mp[1]=0;
  for(const auto& x:road){
    if(df){
      printf("(%d,%d,%d):road\n",get<0>(x),get<1>(x),get<2>(x));
      print(mp);
    }
    auto its=mp.lower_bound(get<0>(x));
    if(its==mp.end()){
      printf("-1");
      return 0;
    }
    auto itt=mp.lower_bound(get<1>(x));
    li temp=(its->second)+get<2>(x);
    if(itt!=mp.end() && (itt->second)<temp)continue;
    mp[get<1>(x)]=temp;
    if(df){
      printf("add\n");
      print(mp);
    }
    itt=mp.lower_bound(get<1>(x));
    itt--;
    while((itt->second) > temp){
      itt=mp.erase(itt);
      itt--;
    }
    if(df){
      printf("delete\n");
      print(mp);
    }
  }
  if(mp[n]==0){
   printf("-1");
  }else{
   cout << mp[n];
  }
}

/// confirm df==0 ///


Measured memory_bytes: 12416
import java.util.Scanner;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 100000;
        for (int i = 0; i < n; i++) {
            ans *= 1.05;
            if (ans % 1000 != 0) {
                ans = ans - ans % 1000 + 1000;
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
    long long int N,K;
    cin>>N>>K;
    //long long int min =((K*(K-1))/2);
    //long long int max =((K*(2*N-K+1))/2);
    //cout<<max<<endl<<min<<endl;
    //cout<<max-min+1<<endl;
    long long int sum=0;
    while((N-K+1)*K >=0){
        sum += ((N-K+1)*K+1);
        K++;
        if(sum>1000000007){
            sum=sum%1000000007;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  int x = 0;
  vector<int> a(n);
  for (int& i : a) cin >> i, x ^= i;
  puts(x == 0 ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,d,p,q,r,m;
    cin>>a>>b;
    vector<ll>v;
    //if(a*b<=2019) cout<<a*b<<endl;
        c=0;
        for(ll i=a; i<=b;i++)
        {
            p=i%2019;
            v.push_back(p);
            c++;
            if(c==2019) break;
        }
        m=12324732842342343;
        for(ll i=0; i<v.size()-1;i++)
        {
            for(ll j=i+1; j<v.size();j++)
            {
                r=(v[i]*v[j])%2019;
                m=min(m,r);
            }
        }
        cout<<m<<endl;
}


Measured memory_bytes: 256
S = input()
K = int(input())

not_1_idx = -1
not_1_num = 1
for i, c in enumerate(S):
    if c != "1":
        not_1_idx = i
        not_1_num = c
        break
if not_1_idx >= 0:
    print(1) if K < not_1_idx + 1 else print(not_1_num)
else:
    print(not_1_num)


Measured memory_bytes: 2940
Sn = gets.chomp.split("")

k = 0

prev = Sn[0]
current = ''

k = 1
i = 1
N = Sn.length
while i < N do
	current += Sn[i]

	if prev != current then
		k = k + 1
		prev = current
		current = ''
	end

	i = i + 1
end

p k

Measured memory_bytes: 16764
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] ==s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, cnt = 0, ans = 1;
  scanf("%lld%lld", &n, &m);
  ll a[n], b[m];
  bool flg[n][m];
  for(i = 0; i < n; ++i) for(j = 0; j < m; ++j) flg[i][j] = true;
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < m; ++i) scanf("%lld", &b[i]);
  sort(a, a + n), sort(b, b + m);
  for(i = n * m; i > 0; --i) {
    ll h = lower_bound(a, a + n, i) - a, w = lower_bound(b, b + m, i) - b;
    if(h == n || w == m || (h != n - 1 && a[h + 1] == i) || (w != m - 1 && b[w + 1] == i)) {
      printf("0");
      return 0;
    }
    if(a[h] == i && b[w] == i) flg[h][w] = false;
    else if(a[h] == i) {
      ans *= m - w;
    } else if(b[w] == i) ans *= n - h;
    else ans *= (m - w) * (n - h) - (n * m - i);
    if(ans < 0) {
      printf("0");
      return 0;
    }
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1152
nmax = 8
def dfs(v, N, visited):
    all_visited=True
    for i in range(N):
        if visited[i]==False:
            all_visited=False

    if all_visited==True:
        return 1

    ret=0
    for i in range(N):
        if graph[v][i]==False:
            continue
        if visited[i]==True:
            continue

        visited[i]=True
        ret+=dfs(i,N,visited)
        visited[i]=False

    return ret

N, M = map(int, input().split())
graph = [[False]*N for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    graph[A-1][B-1]=True
    graph[B-1][A-1]=True

visited = [False]*N

visited[0]=True
print(dfs(0,N,visited))







Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  int p[10000],i,m,n,ps,pc,j,s;
  char say[101];  

  while(1){
    scanf("%d %d",&m,&n);
    if(m==0 && n==0) break;
    pc=m;
    for(i=0;i<m;i++) p[i] = 0;
    for(i=1,ps=0;i<=n;i++){
      if(pc==1) scanf("%s",say);
      else if(i%3==0){
	scanf("%s",say);
	if(i%5==0){
	  if(strcmp(say,"FizzBuzz")!=0){
	    p[ps%m]=1;
	    pc--;
	  }
	}
	else{
	  if(strcmp(say,"Fizz")!=0){
	    p[ps%m]=1;
	    pc--;
	  }
	}
      }
      else if(i%5==0){
	scanf("%s",say);
	if(strcmp(say,"Buzz")!=0){
	  p[ps%m]=1;
	  pc--;
	}
      }
      else {
	scanf("%s",say);
        s = atoi(say);
	if(s!=i){
	  p[ps%m]=1;
	  pc--;
	}
      }
      if(pc!=1){
	ps++;
	while(p[ps%m]==1) ps++;
      }
    }
    for(i=0,j=0;i<m;i++){
      if(p[i]==0){
	printf("%d",i+1);
	if(j!=pc-1) printf(" ");
	else printf("\n");
	j++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
int main()
{
    ll k,ans=0;
    cin>>k;
    rep1(a,k)
    {
        rep1(b,k)
        {
            rep1(c,k)
            {
                ans+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout<<ans;
}


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

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

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

ll w[N];
ll v[N];
ll dp[N];
int main(){
fast;
int n;
ll W;
cin>>n>>W;
for(int i=0;i<n;i++) {
    cin>>w[i]>>v[i];
}

dp[0]=0;
for(int i=1;i<=100000;i++) {
    dp[i]=INF;
}

int ans = 0;
for(int i=0;i<n;i++) {
    for(int val = 100000; val>=v[i];val--) {
        if(dp[val-v[i]]+w[i]<=W) {
            dp[val]=min(dp[val],dp[val-v[i]]+w[i]);
        }
        if(dp[val]!=INF) {
            ans=max(ans,val);
        }
    }
}

cout<<ans<<endl;

return 0;
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main()
{
    int h, w;
    cin >> h >> w;

    char g[h][w];
    queue < pair<int, int> > q;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> g[i][j];
            if (g[i][j] == '#') q.push({i, j});
        }
    }

    int ans = -1;

    while (!q.empty()) {
        int qs = int(q.size());
        ans++;

        for (int i = 0; i < qs; i++) {
            pair <int, int> x = q.front();
            q.pop();
            int now_x = x.first;
            int now_y = x.second;
            for (int j = 0; j < 4; j++) {
                int next_x = now_x + dx[j];
                int next_y = now_y + dy[j];
                if (next_x < 0 or next_x >= h or next_y < 0 or next_y >= w) continue;
                if (g[next_x][next_y] == '.') {
                    q.push({next_x, next_y});
                    g[next_x][next_y] = '#';
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 9360
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.lang.Integer ;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" " , n);
        int[] A = new int[n];
        
        for(int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }
        int count=mergeSort(A,0,n);
        printArray(A);
        System.out.println(count);
    }

    static void printArray(int[] A){
        StringBuilder sb = new StringBuilder();
        for(int k : A){
            sb.append(k + " ");
        }
        System.out.println(sb.toString().substring(0 , sb.length() - 1));
    }

    static int mergeSort(int[] A, int left, int right){
        int count=0;
        if(left+1<right){
            int mid = (left+right)/2;
            count+=mergeSort(A, left, mid);
            count+=mergeSort(A, mid, right);
            count+=merge(A, left, mid, right);
        }
        return count;
    }

    static int merge(int[] A, int left, int mid, int right){
        int count=0; //comparisons
        int n1=mid-left, n2=right-mid;
        int[] L=new int[n1+1], R=new int[n2+1];
        System.arraycopy(A, left, L, 0, n1);
        System.arraycopy(A, mid, R, 0, n2);
        L[n1]=Integer.MAX_VALUE;
        R[n2]=Integer.MAX_VALUE;
        int i=0, j=0;
        for(int k=left; k<right; k++){
            count++;
            if(L[i]<=R[j]){
                A[k]=L[i];
                i++;
            }else{
                A[k]=R[j];
                j++;
            }
        }
        return count;
    }
}



Measured memory_bytes: 160084
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

/*!* [binsearch] *!*/
/*+* 二分探索 *+*/
// judge を満たすような下限を求める
// l:[X] 定義域外部の上限
// r:[X] 定義域外部の下限
// judge:[F = X -> bool] 値 X を評価する関数
// lower:[bool] false にすると代わりに上限を求める
// eps:[X] 終了距離

template <typename X, typename F>
X BinSearch(X l, X r, F judge, bool lower = true, X eps = 1) {
    while (r - l > eps) {
        X m = (r + l) / 2;
        if (judge(m) == lower) {
            r = m;
        } else {
            l = m;
        }
    }
    return lower ? r : l;
}

int main() {
    const int INF = 1e8;
    int N;
    cin >> N;
    vector<int> A(N);
    for(int &a : A) cin >> a;
    vector2d<int> edge(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    // l |-> 長さ l の増加部分列の末項の最小値
    vector<int> tail(N + 1, INF);
    tail[0] = -INF;
    vector<int> ans(N, 0);
    // i: 頂点番号, m: 最長増加部分列の長さ
    recursive([&](auto f, int i, int m) -> void {
        int l = BinSearch(-1, m + 1, [&](int k) -> bool {
            return tail[k] < A[i];
        }, false) + 1;
        int old_tail = tail[l];
        tail[l] = A[i];
        m = max(m, l);
        ans[i] = m;
        for(int j : edge[i]) {
            if(ans[j] > 0) continue;
            f(f, j, m);
        }
        tail[l] = old_tail;
    })(0, 0);

    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

#define ff first
#define ss second
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

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

using namespace std;

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

	string s,t; cin>>s>>t;

	ll ans=0;

	f(i,0,2) if(s[i]==t[i]) ans++;

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[] = new int[n];
		int colors[] = new int[8];
		int free = 0;

		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
			if (a[i] / 400 < 8) {
				colors[a[i] / 400]++;
			} else {
				free++;
			}
		}

		int max = calcMax(free, colors);
		int min = 0;
		if (free == n) {
			min = 1;
		} else {
			min = calcMin(free, colors);
		}

		System.out.println(min + " " + max);

	}

	private static int calcMax(int count, int[] colors) {
		int max = 0;
		int newColors[] = new int[8];
		System.arraycopy(colors, 0, newColors, 0, colors.length);

		for (int i = 0; i < newColors.length; i++) {
			if (newColors[i] > 0) {
				max++;
			}
		}
		return max+count;
	}

	private static int calcMin(int count, int[] colors) {
		int min = 0;
		int newColors[] = new int[8];
		System.arraycopy(colors, 0, newColors, 0, colors.length);
		for (int i = 0; i < count; i++) {
			for (int j = 0; j < newColors.length; j++) {
				if (newColors[j] != 0) {
					newColors[j]++;
					break;
				}
			}
		}

		for (int i = 0; i < newColors.length; i++) {
			if (newColors[i] > 0) {
				min++;
			}
		}
		return min;
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <iomanip>
#include <ios>
#include <sstream>
#include <cstdio>

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <regex>
#include <utility>
#include <random>

#include <cstddef>
#include <cstdint>
#include <cfloat>
#include <limits>

#include <array>
#include <bitset>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <valarray>
#include <vector>
#include <deque>
#include <forward_list>

#define FOR(i, a, b) for(auto i{a}; i < (b); ++i)
#define RFOR(i, a, b) for(auto i{(b)-1};i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) std::begin(a), std::end(a)
#define EACH(x, xs) for (auto &x : xs)
#define CAST static_cast

template<typename T>
constexpr bool in_range(T const &l, T const &a, T const &u){ return l < a && a < u; };
constexpr double inf {std::numeric_limits<double>::infinity()};

#define FAST_TYPE
#ifdef FAST_TYPE
using i32 = std::int_fast32_t;  using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t;
#else
using i32 = std::int_least32_t;  using i64 = std::int_least64_t;
using u32 = std::uint_least32_t; using u64 = std::uint_least64_t;
#endif

using imx = std::intmax_t;
using umx = std::uintmax_t;

using namespace std;

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

  u64 n;

  cin >> n;

  vector<u64> a(n);

  for (auto& ai : a) cin >> ai;

  u64 mx = a[0];
  u64 count = 0;

  FOR (i, 1, n) {
    if (a[i-1] > a[i]) {
      count += a[i-1] - a[i];
      a[i] = a[i-1];
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int MAX = 1000005;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; 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(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


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

    COMinit();
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    sort(all(A));
    ll ans = 0;
    rep(i,N){
        //自分含め左右に何個あるか
        ll l = i+1;
        ll r = N - i;
        ll plus;
        ll minus;
        if(l < K)plus = 0;
        else{
            plus = A[i]%mod * COM(l-1,K-1)%mod;
        }
        if(r < K){
            minus = 0;
        }
        else{
            minus = A[i] * COM(r-1,K-1)%mod;
        }
        ans = ans + plus;
        chmod(ans);
        ans = ans - minus;
        chmod(ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 24448
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = int;
using ld = long double;
using uint = unsigned int;
using ull = unsigned int;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int turn = 0;
  while(true) {
    if(turn == 0) {
      c -= b;
      if(c <= 0) {
        print("Yes");
        return;
      }
    }
    else {
      a -= d;
      if(a <= 0) {
        print("No");
        return;
      }
    }
    turn ^= 1;
  }
}

int main() {
  int t; t = 1;
  while(t--) solve();
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}


void solve()
{
	string s,t;
	cin>>s;
	cin>>t;
	t.pop_back();
	if(s==t)
		cout<<"Yes";
	else
		cout<<"No";
    return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d);
    while(true){
        c -= b;
        if(c <= 0) Return("Yes");
        a -= d;
        if(a <= 0) Return("No");
    }
}


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

int main()
{
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int min = INT_MAX;
	for (int t = 1; t < n; ++t)
	{
		int sum1 = 0, sum2 = 0;
		for (int i = 0; i <= t; ++i)
			sum1 += a[i];
		for (int i = t + 1; i < n; ++i)
			sum2 += a[i];
		int dif = abs(sum1 - sum2);
		if (dif < min)
			min = dif;
	}
	cout << min;
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    string x;
    cin >> x;
    stack<char> st;
    for (int i = 0; i < x.size(); i++) {
        if (!st.empty() and st.top() == 'S' and x[i] == 'T') {
            st.pop();
            continue;
        }
        st.push(x[i]);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 644
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
       N:i64,M:i64,K:i64
    }
    // xの差で考える。
    // 1次元なら、xの差は1がM-1、2がM-2通り...。
    // 2次元なら、各差分について、N*N通り。
    let mut ans = 0i64;
    for i in 0..M {
        ans += i * (M - i) * (N * N);
    }
    for i in 0..N {
        ans += i * (N - i) * (M * M);
    }
    ans %= MOD;
    let mut fact = 1;
    for i in 1..=(K - 2) {
        fact = fact * i % MOD;
    }
    let ifactK_2 = modInv(fact);
    let mut fact = 1;
    for i in (N * M - K + 1)..=(N * M - 2) {
        fact = fact * i % MOD;
    }
    let factNM_2 = fact;
    let mut pat = factNM_2 * ifactK_2 % MOD;
    ans *= pat;
    ans = (ans + MOD) % MOD;
    println!("{}", ans);
}
fn modInv(a: i64) -> i64 {
    modPow(a, MOD - 2) % MOD
}
fn modPow(x: i64, a: i64) -> i64 {
    if a == 1 {
        x
    } else if a % 2 != 0 {
        x * modPow(x, a - 1) % MOD
    } else {
        modPow(x, a / 2).pow(2) % MOD
    }
}


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

using namespace std;

int GetCost(int x, int p) {
	return (x - p) * (x - p);
}

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

	int X[105];
	for (int i = 0; i < N; i++)
	{
		cin >> X[i];
	}

	int min_x = 0;
	for (int i = 0; i < N; i++) {
		min_x += GetCost(X[i], 1);
	}

	int res = 1;
	for (int p = 2; p <= 100; p++) {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			sum += GetCost(X[i], p);
		}
		if (sum < min_x) {
			min_x = sum;
			res = p;
		}
	}
	cout << min_x << endl;
}


Measured memory_bytes: 256
using SparseArrays

function parse_numbers(s)
    pieces = split(s, ' ', keepempty=false)
    map(pieces) do piece
        parse(Int64, piece)
    end
end

function find_max_blast(H, W, M, h, w)
    grid = sparse(append!([1, H], h), append!([1, W], w), append!([0, 0], repeat([1], M)))

    h_sum = vec(sum(grid, dims=2))
    w_sum = vec(sum(grid, dims=1))

    h_max = maximum(h_sum)
    h_sum = h_sum .== h_max
    h_ind = findall(x->x==1, h_sum)

    w_max = maximum(w_sum)
    w_sum = w_sum .== w_max
    w_ind = findall(x->x==1, w_sum)

    for i in h_ind
            for j in w_ind
                    if grid[i, j] == 0
                        return h_max + w_max
                    end
            end
    end
    return h_max + w_max - 1
end

txt = readlines();
H, W, M = parse_numbers(txt[1])
h = zeros(Int64, M)
w = zeros(Int64, M)

for i in 1:M
    h_tmp, w_tmp = parse_numbers(txt[i+1])
    global h[i] = h_tmp
    global w[i] = w_tmp
end

maxblast = find_max_blast(H, W, M, h, w)

println("$(maxblast)")

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

using namespace std;

int main(void)
{
    int eight, ten;

    cin >> eight >> ten;

    for(int i = 1; i <= 1000; i++){
        if(int(i * 0.08) == eight && int(i * 0.1) == ten){
            cout << i << endl;
            return 0;
        } 
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<string>
#include<stack>
using namespace std;

int StrtoInt(const char *s){
	int n=0;
	while (*s != '\0'){
		n *= 10;
		n += *s - '0';
		++s;
	}
	return n;
}

int main(){
	string s;
	stack<int> st;
	int x, y;

	while (cin >> s){
		if (s == "+"){
			x = st.top(); st.pop();
			y = st.top(); st.pop();
			st.push(y+x);
		}
		else if (s == "*"){
			x = st.top(); st.pop();
			y = st.top(); st.pop();
			st.push(y*x);
		}
		else if (s == "-"){
			x = st.top(); st.pop();
			y = st.top(); st.pop();
			st.push(y-x);
		}
		else if (s == "/"){
			x = st.top(); st.pop();
			y = st.top(); st.pop();
			st.push(y/x);
		}
		else
			st.push(StrtoInt(s.c_str()));
	}

	cout << st.top() << endl;
}

Measured memory_bytes: 1192
/*Author:Copyrights: S7a2a7d 
 Hardwork can always beat talent */

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define mem(arr,x) memset(arr,x,sizeof(arr))
     
#define mp make_pair
#define ff first
#define ss second
     
 const double PI = 3.1415926535897932;
 const int mod = 1e9 + 7;  
 const int inf = 1e9 + 5;
ll lcm(ll a,ll b)
{
        return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
int max(int a,int b)
{
        if(a<b)
        return b;
        return a;
}

int main()
{
    fast_io;
    int T=1;
    //cin>>T;
    while(T--)
    {    
       ll n;
       cin>>n;
       int a[n];
       rep(i,n)
       cin>>a[i];
       vector<ll int>sums(n+1,0);
       for(int i=0;i<n;i++)
       {
          sums[i+1]=(sums[i]+a[i]);
       }
       ll ans=0;
       for(int i=0;i<n;i++)
       {
          ll req=(sums[n]-sums[i+1])%mod;
          ans=ans+(ll)(a[i]*req);
          ans=ans%mod;
       }
        cout<<ans<<'\n';
    }
            
   
 }

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

void Main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x = x - 1;
    y = y - 1;
    int sum[n] = {0};
    for(int i=0; i<n-1; ++i){
        for(int j=i+1; j<n; ++j){
            int d = j - i;
            int w = abs(x - i) + 1 + abs(j - y);
            int m = min(d, w);
            // cout << i << " " << j << " " << m << endl;
            sum[m] += 1;
        }
    }
    for(int i=1; i<n; ++i){
        cout << sum[i] << endl;
    }
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;

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

	int k, a, b; cin >> k >> a >> b;
	if(a/k != b/k || a%k ==0 || b%k == 0) cout << "OK\n";
	else cout << "NG\n";
 	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#ifdef JLOCAL
#include "stress.h"
#endif
using namespace std;

#define rep(i, z, n) for (int i = (z); i < int(n); ++i)
#define repr(i, n, z) for (int i = int(n) - 1; i >= (z); --i)
#define shl(n) (1 << (n))
#define hbit(n, i) (((n) >> (i)) & 1)

#define STRESS 0
using lint = long long;

void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    set<int> a;
    int f = 0;
    rep(i, 0, n) {
        int x;
        cin >> x;
        if (x < 400) {
            a.insert(0);
        } else if (x < 800) {
            a.insert(1);
        } else if (x < 1200) {
            a.insert(2);
        } else if (x < 1600) {
            a.insert(3);
        } else if (x < 2000) {
            a.insert(4);
        } else if (x < 2400) {
            a.insert(5);
        } else if (x < 2800) {
            a.insert(6);
        } else if (x < 3200) {
            a.insert(7);
        } else {
            f++;
        }
    }

    cout << max(1, (int) a.size()) << " " << min(777777777, (int) a.size() + f);
}

int main() {
#if !defined(JLOCAL) || !STRESS
#ifdef JLOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve(cin, cout);
#else
    srand();
    for (int ti = 0; ti < 100; ti++) {
        stress::gen();
        stress::stupid();
        ifstream in("input.txt");
        ofstream out("output.txt");
        solve(in, out);
        out.flush();
        stress::check();
    }
    cout << "ok" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    OUT(n * (n-1) /2 + m * (m-1) /2)

    return 0;
}

Measured memory_bytes: 256