akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
        int n,x,i,c=1,s=0;
        scanf("%d%d",&n,&x);
        int a[n];
        for(i=0;i<n;i++)
                scanf("%d",&a[i]);

        for(i=0;i<n;i++){
                s+=a[i];
                if(s<=x)c++;
                else break;
        }
        printf("%d\n",c);
}


Measured memory_bytes: 128
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy

from bisect import bisect_left as bl

N,X=map(int,input().split())
x=list(map(int,input().split()))

y=[]
for i in range(N):
    y.append(abs(x[i]-X))
ans=y[0]
for i in y:
    ans=gcd(ans,i)
print(ans)


Measured memory_bytes: 88852
/*input
level
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

bool is_palindrome(string s)
{
	int l = 0;
	int r = s.size() - 1;
	while(l <= r)
	{
		if(s[l] != s[r]) return 0;
		l++;
		r--;
	}
	return 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    int n = s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0, (n - 1)/2)) && is_palindrome(s.substr((n + 3)/2 - 1, (n - 1)/2))) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define N 100001
#define INF 1e9


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    
    
    ll n , i ;
    cin >> n  ;
    ll a[ n ] ;
    for(i=0 ; i<n ; i++){
        cin >> a[ i ] ;
    }
    ll idx = 0 , num = 0 , ans = 0 ;
    for(i=0 ; i<n ; i++){
       while(idx<n && (num^a[ idx ]) == (num + a[ idx ]) ){
           num += a[ idx++ ] ; 
       }
       // cout << idx-i <<endl ;
       ans += idx-i ;
       if(i==idx)idx++ ;
       else num-=a[ i ] ;
    }
    cout << ans ;
    return 0 ;
    
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {// Main
    public static void main(String[] args){
    	Scanner in = new Scanner(System.in);
    	int N = in.nextInt();
    	int A = in.nextInt();
    	int B = in.nextInt();
    	String S = in.next();
    	char[] input = S.toCharArray();
    	int passed = 0;
    	int oversea = 0;
    	for(int i=0; i<N; i++){
    		if(input[i]=='a'){
    			if(passed<A+B){
    				System.out.println("Yes");
    				passed++;
    				continue;
    			}
    		}else if(input[i]=='b'){
    			if(passed<A+B && (oversea<B)){
    				System.out.println("Yes");
    				passed++;
    				oversea++;
    				continue;
    			}
    		}
    		System.out.println("No");
    	}
    	in.close();
    }
}

Measured memory_bytes: 23240
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a1 = sc.nextInt();
    int a2 = sc.nextInt();
    int a3 = sc.nextInt();
    sc.close();

    if (a1 + a2 + a3 >= 22) System.out.println("bust");
    else System.out.println("win");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10003],d[10003],n,sol,x;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i)
    {
        cin>>x;
        sol+=x;
    }
    for(int i=1;i<n;++i) cin>>d[i];
    for(int i=1;i<n;++i)
    {
        if(a[i]+1==a[i+1]) sol+=d[a[i]];
    }
    cout<<sol;
    return 0;
}


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

int main(void) {
    int w;
    int n;
    int place;
    std::cin >> w >> n;
    std::vector<std::pair<int, int> > cource(n);

    std::vector<int> result(w, 0);

    int a;
    int b;
    char temp;

    for (int i = 0; i < n; i++) {
        std::cin >> cource[i].first >> temp >> cource[i].second;
    }


    for (int i = 1; i <= w; i++) {
        place = i;
        for (int j = 0; j < n; j++) {
            if (cource[j].first == place) {
                place = cource[j].second;
            } else if(cource[j].second == place) {
                place = cource[j].first;
            }
        }
        result[place - 1] = i;
    }

    for (int i = 0; i < w; i++) {
        std::cout << result[i] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3004
#include<stdio.h>
int main(void)
{
	int D[5],E[5];
	for (int i = 0; i < 5; i++)
		scanf("%d", &D[i]);
	for (int i = 0; i < 5; i++) {
		E[i] = D[i] % 10;
		//printf("%d\n", E[i]);
	}
	int L[5];
	int min = E[0];
	

	for (int i = 0; i < 5; i++) {
		if (E[i] == 0)
			L[i] = 10;
		else
			L[i] = E[i];
	}

		for (int i = 0; i < 4; i++) {
			if (min > L[i + 1]) {
				min = L[i + 1];

			}
		}

		/*for (int i = 0; i < 5; i++) {
			L[i] = E[i];
	}*/
	
	//printf("%d\n", min);
	int F[5];

	for (int i = 0; i < 5; i++) {
		if (E[i] == 0) {
			F[i] = D[i];
		}
		else
			F[i] = D[i] - L[i] + 10;
	}

	if (E[0] == 0 && E[1] == 0 && E[2] == 0 && E[3] == 0 && E[4] == 0)
		printf("%d", D[0] + D[1] + D[2] + D[3] + D[4]);
	else
		printf("%d", F[0]+F[1]+F[2]+F[3]+F[4] - 10 + min);

	return 0;
	

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<typename T> T minimum(T head, T tail) { return std::min(head, tail); }
template<typename Head, typename... Tail> Head minimum(Head head, Tail... tail) {
  return std::min(head, minimum(tail...));
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  //std::ostringstream oss;
  //oss << "ABC" << N;
  //std::string ans = oss.str();

  char r, g, b;
  std::cin >> r >> g >> b;

  ll x = r * 100 + g * 10 + b;
  if (x % 4 == 0) print("YES");
  else print("NO");

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n,m;
    ArrayList<int[]> list;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            //a, b, w
            list = new ArrayList<int[]>();
            for(int i=0; i<m; i++){
                int a = sc.nextInt(), b = sc.nextInt();
                int w = sc.nextInt();
                int[] tmp = {a-1,b-1,w};
                list.add(tmp);
            }

            Collections.sort(list, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });

            int ans = Integer.MAX_VALUE;
            for(int i=0; i<m && m-i>=n-1; i++){
                ans = Math.min(ans, kruskal(list.get(i)[2]));
            }

            if(ans==Integer.MAX_VALUE) ans = -1;
            System.out.println(ans);
        }
    }

    int kruskal(int min){
        int idx = 0;
        init();
        while(list.get(idx)[2]<min) idx++;

        int res = 0;
        for(int i=idx;i<m; i++){
            int[] ab = list.get(i);
            if(!same(ab[0],ab[1])){
                unite(ab[0],ab[1]);
                res = ab[2];
            }
        }

        boolean same = true;
        for(int i=1; i<n; i++){
            if(!same(0,i)) same = false;
        }

        if(same) return res-min;
        else return Integer.MAX_VALUE;
    }

    int[] par, rank;
    void init(){
        par = new int[n];
        rank = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x] = y;
        else{
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    boolean same(int x, int y){
        return find(x)==find(y);
    }

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

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;


#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

	
//////////////////////////////code//////////////////////////////

int n,k;

vi arr;

int dp[2][100005];

int sol(int i,int j)
{
   // deb(i,j);
    
    if(dp[i][j]!=-1)
    return dp[i][j];
    
    int a1 = 0,a2 = 1;
    
    if(i&1)
    {
        for(int k=0;k<n;k++)
        {
          if(j-arr[k]>=0)
          a1 = max(a1,sol(!i,j-arr[k]));
        }
        
        return dp[i][j]=a1;
    }
    else
    {
        for(int k=0;k<n;k++)
        {
            if(j-arr[k]>=0)
            a2 = min(a2,sol(!i,j-arr[k]));
        }
        
        return dp[i][j]=a2;
    }
}

void solve()
{
   // cout << "-------------------" << "\n";
    
    cin>>n>>k;
    
    arr = vi(n);
    
    for(int i=0;i<n;i++) cin>>arr[i];
    
    sort(all(arr));
    
    
    memset(dp,-1,sizeof(dp));
    
    if(sol(1,k))
    db("First")
    else
    db("Second")
    
  
 

  //  cout << "-------------------" << "\n";

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

    int t = 1;
    //cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


Measured memory_bytes: 9880
//??§????????£?????¢?????°??????????¬??????¨??£????????? -> ?????£????????????
//[????????°]?????????????????????????????\??????????????????????????? -> [????????°]?????????????????????????????§??????????????°????°?????????????????????????
//????????£?????¢?????°???????????§?????????????????§???[???????????£?????¢?????°]?????¶??????????????????????????????
#include <iostream>
using namespace std;

int dp[1000001];
int dpOdd[1000001];

int main() {
	int i, j;
	
	for (i = 0; i < 1000001; i++) dp[i] = 1145141919;
	for (i = 0; i < 1000001; i++) dpOdd[i] = 1145141919;
	dp[0] = 0;
	dpOdd[0] = 0;
	
	for (i = 0; i < 1000001; i++) {
		for (j = 1; i + j * (j + 1) * (j + 2) / 6 < 1000001; j++) {
			int num = j * (j + 1) * (j + 2) / 6;
			dp[i + num] = min(dp[i + num], dp[i] + 1);
			if (num % 2 == 1) {
				dpOdd[i + num] = min(dpOdd[i + num], dpOdd[i] + 1);
			}
		}
	}
	
	int n;
	while (cin >> n) {
		if (n == 0) break;
		cout << dp[n] << " " << dpOdd[n] << endl;
	}
	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	vector<int> dish,gains,more;
	for(int i=0;i<n;i++){
		int a;cin>>a; a--;
		dish.pb(a);
	}
	for(int i=0;i<n;i++){
		int b;cin>>b;
		gains.pb(b);
	}
	for(int i=0;i<n-1;i++){
		int c;cin>>c;
		more.pb(c);
	}
	
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=gains[dish[i]];
		if(i>0&&dish[i]==dish[i-1]+1){
			ans+=more[dish[i-1]];
		}
	}
	cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,ans,too;
pa a[500010];
int main(){
	cin>>n;
	FOR(i,1,n){
		int x,y;
		getint(x),getint(y);
		a[i]=mp(x+y,x-y);
	}
	sort(a+1,a+n+1);
	too=a[1].fi;
	ans=1;
	FOR(i,2,n) if (a[i].se>=too){
		++ans;
		too=a[i].fi;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,m,k; cin >> n >> m >> k;
    vector<vector<int>> to(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    vector<vector<int>> ng(n);
    rep(i,k){
        int c,d; cin >> c >> d;
        c--; d--;
        ng[c].pb(d);
        ng[d].pb(c);
    }
    vector<int> ans(n,0);
    vector<bool> vis(n,0);
    queue<int> q;
    set<int> q2;
    vis[0]=1;
    int kou=-1;
    q.push(0);
    q2.insert(0);
    int cnt=0;
    
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(auto u:to[v]){
            if(vis[u]) continue;
            vis[u]=1;
            q.push(u);
            q2.insert(u);
            cnt++;
        }
        if(q.empty()){
            //cout << "UI";
            for(auto fro:q2){
                ans[fro]=cnt;
                for(auto x:ng[fro]){
                    if(q2.find(x)!=q2.end()){
                        //cout << "UI";
                        ans[fro]--;
                    }
                }
            }
            q2.clear();
            kou++;
            while(vis[kou]&&kou<n){
                kou++;
            }
            if(kou >= n) break;
            q.push(kou);
            q2.insert(kou);
            vis[kou]=1;
            cnt=0;
        }
    }
    rep(i,n){
        ans[i]-=to[i].size();
        cout << max(0,ans[i]) <<" ";
    }
}


Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

int main() {
  int k,x;
  cin >> k >> x;
  for (int i = x-k+1;i <= x+k-1;i++) cout << i << endl;
}

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

using namespace std;

int main() {
  string str;
  while(getline(cin, str)) {
    for(int i = 0; i < str.length(); i++) {
      if(str[i] == '@') {
	i++;
	int num = (int)str[i] - (int)'0';
	i++;
	for(int j = 0; j < num; j++) {
	  cout << str[i];
	}
      } else {
	cout << str[i];
      }
    }
    cout << endl;
  }
  return 0;
}

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

// L>Rのとき1を, L=Rのとき2を, L<Rのとき3を返す関数
int LeftOrRight(int, int, int, int);

int main()
{
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  int ans = LeftOrRight(a, b, c, d);

  if(ans == 1)
    cout<<"Left"<<endl;
  else if(ans == 2)
    cout<<"Balanced"<<endl;
  else
    cout<<"Right"<<endl;

  return 0;
}

int LeftOrRight(int a, int b, int c, int d)
{
  if(a+b>c+d)
    return 1;
  else if(a+b==c+d)
    return 2;
  else
    return 3;
}


Measured memory_bytes: 256
// g++ hello.cpp -o hello & hello
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void test();

int main()
{
//freopen("input.in","r",stdin);freopen("output.in","w",stdout);
int t=1;
//   cin>>t;
for(int i=1;i<=t;i++)
{    
//	cout<<"Case #"<<i<<": ";
	test();
cout<<endl;
}
return 0;
}
void test() 
{ll n;
cin>>n;
ll k;
cin>>k;
ll arr[n]={};
for(int i=0;i<n;i++)
cin>>arr[i];
ll ans[n]={};
ans[0]=0;
ans[1]=abs(arr[1]-arr[0]);
for(int i=2;i<n;i++)
{ans[i]=INT_MAX;
   for(int i1=1;i1<=k;i1++)
   {if(i>=i1){
   ans[i]=min(ans[i],abs(arr[i]-arr[i-i1])+ans[i-i1]);
   } }
}

cout<<ans[n-1];
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){

    int x, y, i;

    for(i=0; i<=3000; i++){
        scanf("%d", &x);
        scanf("%d", &y);
        
        if(x==0&&y==0)
            break;
        else if(x >= y)
             printf("%d %d\n", y,x);
        else if(x <= y)
             printf("%d %d\n", x,y);
    }
             
        return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  vector<double> pp(1001);
  for (int i = 1; i < 1001; ++i) {
    pp.at(i) = (((double(i) * (double(i) + 1.0)) / 2.0)) / double(i);
  }

  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  int t_p;
  cin >> t_p;
  p.at(0) = pp.at(t_p);
  REPI(i, 1, N) {
    cin >> t_p;
    p.at(i) = p.at(i - 1) + pp.at(t_p);
  }

  // for (double d : p) {
  //   cout << d << ",";
  // }
  // cout << endl;

  double ans = p.at(K - 1);
  REPI(i, K, N) { ans = max(ans, p.at(i) - p.at(i - K)); }

  cout << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n, m, x, c[15], a[15][15];
ll mini;
int main() {
    IOS; cin >> n >> m >> x;
    for(int i=1; i<=n; ++i) {
        cin >> c[i];
        for(int j=1; j<=m; ++j) {
            cin >> a[i][j];
        }
    }
    mini = (ll)2e17;
    bool promena=false;
    for(int mask=0; mask<(1<<12); ++mask) {
        ll cena=0LL;
        ll algos[15]={0LL};
        for(int j=0; j<12; ++j) {
            if(mask&(1<<j)) {
                cena += (ll)c[j+1];
                for(int k=1; k<=m; ++k) {
                    algos[k] += (ll)a[j+1][k];
                }
            }
        }
        bool moze=true;
        for(int k=1; k<=m; ++k) {
            if(algos[k]<(ll)x) {moze=false; break;}
        }
        if(moze) {
            promena=true;
            mini=min(mini,cena);
        }
    }
    if(promena) cout << mini;
    else cout << -1;
    return 0;
}


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

int main(){
	int n, i, count, niji, max, min, rate[100],lank[9];
	max = 0; 
	max = 0;
	count = 0;
	niji = 0;

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

	for (i = 0; i < 9; i++) {
		lank[i] = 0;
	}
	for (i = 0; i < n; i++) {
		if (rate[i] < 400) {
			lank[0] = lank[0] + 1;
		}
		else if (rate[i] < 800) {
			lank[1] = lank[1] + 1;
		}
		else if (rate[i] < 1200) {
			lank[2] = lank[2] + 1;
		}
		else if (rate[i] < 1600) {
			lank[3] = lank[3] + 1;
		}
		else if (rate[i] < 2000) {
			lank[4] = lank[4] + 1;
		}
		else if (rate[i] < 2400) {
			lank[5] = lank[5] + 1;
		}
		else if (rate[i] < 2800) {
			lank[6] = lank[6] + 1;
		}
		else if (rate[i] < 3200) {
			lank[7] = lank[7] + 1;
		}
		else if (3200 <= rate[i]) {
			lank[8] = lank[8] + 1;
			niji = niji + 1;
		}
	}

	//レート３２００が一人もいないとき
	if (lank[8]==0) {
		for (i = 0; i < 8; i++) {
			if (lank[i] > 0) {
				count++;
			}
		}
		max = count;
		min = count;
	}

	else {
		for(i = 0; i < 8; i++) {
			if (lank[i] > 0) {
				count++;
			}
		}
		min = count;
		if (min < 1) {
			min++;
		}
		max = min + niji;
		if (max > n) {
			max = n;
		}
	}

	cout << min << " " << max << endl;

	return 0;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next smallest submask

void we_r_done(){cout<<"NO"; exit(0);}

void debug(bool ok , string mssg)
{
    if(ok)return;
    cout<<mssg;
    exit(0);
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    string s;
    cin>>s;

    int n = s.size();

    if(n%2 == 0){
        if(s[0] != s[n-1]) cout<<"Second";
        else cout<<"First";
    }
    else{
        if(s[0] == s[n-1]) cout<<"Second";
        else cout<<"First";
    }

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


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

using namespace std;

#define sz(c) ((int)c.size())
#define	pb push_back

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

constexpr int MAX_N = 100'074;
constexpr int SIGMA = 30;
constexpr ll INF = 1'000'000'000LL;
constexpr ll P = 9'982'443'53;
constexpr double PI = 3.14159265359;
constexpr double TO_RAD = PI/180.;
constexpr long double EPS = 1e-6;

ll A[MAX_N], mx[MAX_N];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	for(int i = 0; i <= n; i++){
		cin >> A[i];
	}
	
	mx[n] = A[n];
	for(int i = n-1; i >= 0; i--){
		mx[i] = A[i] + mx[i+1];
	}

	ll total = 0;
	ll v = 1;
	for(int i = 0; i <= n; i++){
		if(v < mx[i]){
			total += v;
			if(A[i] > v){
				cout << "-1\n";
				return 0;				
			}
			v -= A[i];
			v *= 2;
		}
		else {
			v = mx[i];
			total += v;
			if(A[i] > v){
				cout << "-1\n";
				return 0;				
			}
			v -= A[i];
			v *= 2;
		}
	}

	cout << total << "\n";
	return 0;
}

Measured memory_bytes: 5200
n = gets.chomp
h = gets.chomp.split(' ').map(&:to_i)

ans = 0
tmp = 0

1.upto(h.size - 1) do |i|
  if h[i - 1] < h[i]
    ans = tmp if tmp > ans

    tmp = 0
  else
    tmp += 1
  end
end
ans = tmp if tmp > ans

puts ans

Measured memory_bytes: 9604
X = int(input())

#A**5,B**5でとり得る可能性のある数をあらかじめリストで用意する

N = [i**5 for i in range(10000)]
 
#A,Bで別々の数を扱うので、変数はi,jの２種を用意する

for i in range(10000):
	for j in range(10000):

#リストから２つの数を抽出し、Xになるか計算を繰り返す
#Xは正の整数であるため、Aが負になる可能性は除外

		if N[j] - N[i] == X:
			print(j, i)
			exit()

#Bが負の場合、符号が変わる可能性があるため、もう１パターン計算

		if N[j] + N[i] == X:
			print(j, -i)
			exit()

Measured memory_bytes: 9464
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            checked
            {
                var n = cin.ReadInt;
                var m = cin.ReadInt;
                WriteLine((n <= 8 && m <= 8) ? "Yay!" : ":(");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadIntArrays(long N, out int[] A, out int[] B, out int[] C) { A = new int[N]; B = new int[N]; C = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; C[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}


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

int main(){
    string o, e;
    cin >> o >> e;
    rep(i, e.size()){
        cout << o[i] << e[i];
    }
    if(o.size()-e.size()==1){
        cout << o[o.size()-1];
    return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    double a,b,x;
    cin >> a >> b >> x;
    if( x <= a * a * b / 2){
        double h = x / (a * b / 2);
        double theta = atan(h / b) / pi * 180;
        cout << fixed << setprecision(10) <<  90 - theta << endl;
    }
    else{
        x = a * a * b - x;
        double h = x / (a * a / 2);
        double theta = atan(h / a) / pi * 180;
        cout << fixed << setprecision(10) <<  theta << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
#define pi 3.1415926535897
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a;
	rep(i, 5){
		cin >> a;
		if(!a){
			cout << i + 1 << endl;
			break;
		}
	}
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
typedef long long ll;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

ll n,A,B;
int main(){
   scanf("%lld%lld%lld",&n,&A,&B);
   if((B-A)%2 == 0){
      printf("%lld\n",(B-A)/2);
   } else {
      printf("%lld\n",min((B+A-1)/2,(2*n-B-A+1)/2));
   }
   return 0;
}


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

int intcmp(void *a, void *b);

int main(){
    int N, x, pos;
    scanf("%d %d", &N, &x);

    int a[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }

    qsort(a, N, sizeof(int), intcmp);

    for(pos = 0; (pos < N) && (x > 0); pos++){
        x -= a[pos];
    }
    if(x != 0){
        pos--;
    }
    printf("%d\n", pos);
    return 0;
}

int intcmp(void *a, void *b){
    return *(int*)a - *(int*)b;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    map<int,int> M;
    int n,m;
    cin>>n>>m;
    int a;
    for(int i=0;i<n;++i)cin>>a,M[a]++;
    while(m--){
        int b,c;
        cin>>b>>c;
        int cur=0;
        while(!M.empty()&&b&&c>M.begin()->first){
            int used=min(b,M.begin()->second);
            M.begin()->second-=used;
            b-=used;
            if(M.begin()->second==0){
                M.erase(M.begin());
            }
            cur+=used;
        }
        if(cur)M[c]+=cur;
    }
    int64_t ans=0;
    for(auto e:M){
        ans+=1LL*e.first*e.second;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<char> c(N);
  for (int i = 0; i < N; i++) {
    cin >> c.at(i);
  }
  int R = count(c.begin(), c.end(), 'R');
  int result = 0;
  for (int i = 0; i < R; i++) {
    if (c.at(i) == 'W') {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MOD 1000000007

int main() {
  ll ans = 0;
  ll n;
  ll b[60];
  cin >> n;
  ll temp;
  REP(i, 60){
    b[i] = 0;
  }
  REP(i, n){
    cin >> temp;
    int j = 0;
    while(temp>0){
      b[j] += temp % 2;
      temp /= 2;
      j += 1;
    }
  }

  ll d = 1;
  REP(i, 60){
    ll x = b[i];
    //cout << x << endl;
    ans = (ans + ((x * (n-x) % MOD) * d)) % MOD;
    d = d * 2 % MOD;
    //cout << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);

  REP(i,n) cin >> v[i];
  REP(i,n) cin >> c[i];

  int ans = 0;

  REP(i,n){
    if(v[i] - c[i] > 0) ans += v[i]- c[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
score = []
while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
    score.append([m, f, r])
 
for mc, fc, rc in score:
    if mc == -1 or fc == -1:
        print('F')
    elif mc + fc >= 80:
        print('A')
    elif mc + fc >= 65:
        print('B')
    elif mc + fc >= 50 or rc >= 50:
        print('C')
    elif mc + fc >= 30:
        print('D')
    else:
        print('F')

Measured memory_bytes: 6724
#include<iostream>
#include<bitset>
using namespace std;

bitset<50001> pt;

void MakeTable(int n){
  pt.reset();
  pt.set(2);
  
  int i;
  for(i=3;i<=n;i+=2)pt.set(i);
  
  i = 3;
  while(i*i<=n){
    for(int j=3*i;j<=n;j+=2*i)pt.reset(j);
    do{i+=2;}while(!pt[i]);
  }
}

int main(){
  int n,ans;
  MakeTable(50000);

  while(1){
    cin >> n;
    if(!n)break;

    ans = 0;
    for(int i=0;i<=n/2;i++)
      if(pt[i] && pt[n-i])ans++;
    cout << ans << endl;
  }
}
	

Measured memory_bytes: 868
import numpy as np
import math
N, M = [int(num) for num in input().split()]
# M = float(M)
A, B = [], []
for n in range(N):
  a_i, b_i = [int(num) for num in input().split()]
  A.append(a_i)
  B.append(b_i)

A_sort_index = np.argsort(A)
total_val = 0
for index in A_sort_index:
  if M < B[index]:
    total_val += M * A[index]
    break
  else:
    total_val += A[index] * B[index]
    M -= B[index]

print (total_val)


  


Measured memory_bytes: 21612
a=input()
if a=="SUN":
  print(7)
if a=="MON":
  print(6)
if a=="TUE":
  print(5)
if a=="WED":
  print(4)
if a=="THU":
  print(3)
if a=="FRI":
  print(2)
if a=="SAT":
  print(1)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt = 0;
  vector<string> r = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for(auto x : r){
    if(s == x){
      cout<<7 - cnt<<endl;
      return 0;
    }
    cnt++;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque
n = int(input())
a = sorted(deque(map(int, input().split())))

ans = a.pop()
if n % 2 == 0:
    l = (n-2)//2
else:
    l = (n-2)//2+1

for i in range(l):
    if n % 2 == 1 and i == l-1:
        ans += a.pop()
    else:
        ans += a.pop()*2
print(ans)

Measured memory_bytes: 31480
#include <bits/stdc++.h>
using namespace std;
struct restaurant
{
  int i;
  string s;
  int p;
};

bool cmp(const restaurant &a, const restaurant &b)
{
  if (a.s != b.s)
  {
    return a.s < b.s;
  }
  return a.p > b.p;
}

int main()
{
  int n;
  cin >> n;
  vector<restaurant> r(n);
  for (int i = 0; i < n; i++)
  {
    r[i].i = i + 1;
    cin >> r[i].s >> r[i].p;
  }
  sort(r.begin(), r.end(), cmp);
  for (int i = 0; i < n; i++)
  {
    cout << r[i].i << endl;
  }
  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    h, w = list(map(int, input().split()))
    board = [input() for i in range(h)]
    count = sum([board[i].count('#') for i in range(h)])

    # See:
    # https://www.youtube.com/watch?v=6ZP8JyGsQBs
    if count == (h + w - 1):
        print('Possible')
    else:
        print('Impossible')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  ll n, ww;
  cin >> n >> ww;
  vll w(n), v(n);
  for (ll i = 0; i < n; i++) cin >> w[i] >> v[i];
  vll dp(100001, 0);
  vector<vll> check(100001, vll(0));
  vll x(n, 0);
  check[0] = x;
  for (ll i = 1; i <= ww; i++) {
    dp[i] = dp[i - 1];
    ll memo = -1;
    for (ll j = 0; j < n; j++) {
      if (i < w[j]) continue;
      if (check[i - w[j]][j] == 1) continue;
      if (dp[i] < dp[i - w[j]] + v[j]) {
        dp[i] = dp[i - w[j]] + v[j];
        memo = j;
      }
    }
    if (memo != -1) {
      check[i] = check[i - w[memo]];
      check[i][memo] = 1;
    }
    else check[i] = check[i - 1];
  }
  cout << dp[ww] << endl;
}

Measured memory_bytes: 83072
#include <stdio.h>

int main()
{
	int n,m;
	int i,j,sum = 0;
	
	scanf("%d %d",&n,&m);
	
	if(n == 1&&m == 1)
	sum = 0;
	else if(n == 0)
	for(i = m - 1;i > 0;i--)
		sum += i;
	else if(m == 0)
	for(i = n - 1;i > 0;i--)
		sum += i;
	else 
	{
		for(i = n - 1;i > 0;i--)
			sum += i;
		for(j = m - 1;j > 0;j--)
			sum += j;
	}
	
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 128
/*
 * atcoder/abc159/a.cpp
 */

// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <cstring>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

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


struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  Point operator + (Point v) { return Point(x + v.x, y + v.y); }
  Point operator - (Point v) { return Point(x - v.x, y - v.y); }
  bool operator == (const Point &v) const {
    return x == v.x && y == v.y;
  }
  bool operator< (const Point &p1) const {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}


vector<Int> slice(vector<Int> &vec, int s, int t) {
  return vector<Int>(vec.begin()+s, vec.begin()+t);
}

vector<Int> trim(vector<Int> &vec, int n) {
  auto init = slice(vec, 0, n);
  auto tail = slice(vec, n+2, vec.size());
  init.insert(init.end(), tail.begin(), tail.end());
  return init;
}


Int N, M;

void input() {
  cin >> N >> M;
}

void solve() {
  cout << (N * (N-1) / 2) + (M * (M-1) / 2) << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,c = inm()
x = []
v = []
for i in range(n):
    xx,vv = inm()
    x.append(xx)
    v.append(vv)
l1 = [0]*n
l2 = [0]*n
r1 = [0]*n
r2 = [0]*n
acc = 0
for i in range(n):
    acc += v[i]
    l1[i] = max(l1[i-1], acc-x[i])
    l2[i] = max(l2[i-1], acc-2*x[i])
acc = 0
for i in range(n-1,-1,-1):
    acc += v[i]
    r1[i] = max(r1[(i+1)%n], acc-(c-x[i]))
    r2[i] = max(r2[(i+1)%n], acc-2*(c-x[i]))

ddprint(l1)
ddprint(l2)
ddprint(r1)
ddprint(r2)
mx = 0
for i in range(n):
    mx = max([mx, l1[i]+(r2[i+1] if i<n-1 else 0), \
                  r1[i]+(l2[i-1] if i>0 else 0)])
print(mx)


Measured memory_bytes: 69592
lefts = ['q','w','e','r','t','a','s','d','f','g','z','x','c','v','b']

while(True):
  strs = input()
  if strs == '#':
    break
  side_pre = 0
  side_now = 0
  mv_cnt = 0
  for i in range(len(strs)):
    c = strs[i]
    if strs[i] in lefts:
      side_now = 1
    else:
      side_now = -1
    if side_pre == 0:
      side_pre = side_now
    if side_now != side_pre:
      mv_cnt += 1
    side_pre = side_now
  print(mv_cnt)


Measured memory_bytes: 5568
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a>b){
		printf("Alice\n");
	}
	else if(a<b){
		printf("Bob\n");
	}
	else{
		printf("Draw\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<string> A(n);
    REP(i, n) cin >> A[i];
    int m; cin >> m;
    vector<string> B(m);
    REP(i, m) cin >> B[i];
    int ans = 0;
    auto calc = [&](string s){
        int buf = 0;
        for(string t : A){
            if(t == s) buf++;
        }
        for(string t : B){
            if(t == s) buf--;
        }
        return buf;
    };
    for(string t : A) ans = max(ans, calc(t));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;

	int h, a;
	cin >> h >> a;
	if (h % a == 0) cout << h / a << endl;
	else cout << h / a + 1 << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int main(){
	int n,cnt=0;
	cin>>n;
	set<int> people;
	set<int>::iterator it;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		it=people.find(t);
		if(it!=people.end())
			people.erase(it);
		else
			people.insert(t);
	}
	cout<<people.size();
    
	return 0;
}

Measured memory_bytes: 4864