akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    string S; cin >> S;
    REP(i, S.size()-1){
        if(S[i] == S[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    REP(i, S.size()-2){
        if(S[i] == S[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(S[i] == S[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
        if(S[i+1] == S[i+2]){
            cout << i+2 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
const int maxn=1e6+7;
ll c,x[maxn],w[maxn],val[maxn],shun[maxn],ni[maxn],rval[maxn];
int n;
int main (){
    scanf("%d %lld",&n,&c);
    for(int i=1;i<=n;i++){
        scanf("%lld %lld",&x[i],&w[i]);
        val[i]=val[i-1]+w[i];
        shun[i]=max(shun[i-1],val[i]-x[i]);
    }
    for(int i=n;i>=1;i--){
        rval[i]=rval[i+1]+w[i];
        ni[i]=max(ni[i+1],rval[i]-c+x[i]);
    }
    ll ans=0;
    for(int i=n;i>=1;i--){
        ans=max(ans,rval[i]-2*(c-x[i])+shun[i-1]);
        ans=max(ans,ni[i]);
    }
    for(int i=1;i<=n;i++){
        ans=max(ans,val[i]-2*x[i]+ni[i+1]);
        ans=max(ans,shun[i]);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    for(int x = a;x <= b; x++){
        if(c % x == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3116
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def main():
    N, K = map(int, input().split())
    red = N - K
    blue = K

    for i in range(1, K+1):
        if i > red + 1:
            print(0)
        else:
            ans = cmb(red + 1, i)
            ans *= cmb(blue - 1, i - 1)
            print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49372
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 H, N, i;
  cin >> H >> N;
  i64 T = 0;
  REP(0, N, i) {
    i64 A;
    cin >> A;
    T += A;
  }
  cout << (T >= H ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;

signed main() {
		int a, b;
		cin >> a >> b;
		int N,bn;
		if (a == b) {
			cout << 1 << endl;
			return 0;
		}
		for (int i = 62; i >= 0; i--) {
			if ((a & 1ll << i) != (b & 1ll << i)) {
				a %= 1ll << (i + 1);
				b %= 1ll << (i + 1);
				N = 1ll << i;
				bn = i;
				break;
			}
		}
		int as = a, ae = N - 1;
		int bs = N, be = b;
		int flg = 0;
		for (int j = bn-1; j >= 0; j--) {
			if (b & 1ll << j)flg++;
			if (flg)be |= 1ll << j;
		}
		int cs = bs | as, ce = be | ae;
		int ans = be - as + 1;
		if (be < cs) {
			ans += ce - cs + 1;
		}
		else if (be < ce) {
			ans = ce - as + 1;
		}

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()

int main(){
    int r;
    cin >> r;
    cout << 2 * 3.14159265358979 * r << endl;

}

Measured memory_bytes: 3260
def main():
    n = int(input())
    A = list(map(int, input().split()))
    m = int(sum(A) / len(A) + 0.5)
    ans = float('inf')
    for i in range(m - 1, m + 2):
        ans = min(ans, sum([(a - i) ** 2 for a in A]))
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<int, int> man; // time, sat;

const int C = (1 << 16);

ll S[C];
man M[110];

int main() {
  int N;
  while (cin >> N && N) {
    // 初期化
    fill(S, S+C, 0);
    // 男の入力処理
    for (auto i=0; i<N; i++) {
      int Z;
      int L;
      cin >> Z >> L;
      int time = 0;
      for (auto j=0; j<Z; j++) {
	int s, e;
	cin >> s >> e;
	s -= 6;
	e -= 6;
	for (auto k=s; k<e; k++) {
	  time |= 1 << k;
	}
      }
      M[i] = make_pair(time, L);
    }
    // 動的計画法
    for (auto i=0; i<N; i++) {
      for (auto j=C-1; j>=0; j--) {
	if ((j & M[i].first) == 0) {
	  int dst = j | M[i].first;
	  S[dst] = max(S[dst], S[j]+M[i].second);
	}
      }
    }
    cout << S[C-1] << endl;
  }
}

Measured memory_bytes: 1668
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

bool check2(const std::vector<bool> v, int start, int goal) {
  int ng_cnt = 0;
  for (int i = start; i <= goal; ++i) {
    if (!v[i]) ++ng_cnt;
    else ng_cnt = 0;
    if (ng_cnt >= 2) return false;
  }
  return true;
}

bool check3(const std::vector<bool> v, int start, int goal) {
  int ok_cnt = 0;
  for (int i = start; i <= goal; ++i) {
    if (v[i - 1] && v[i] && v[i + 1]) return true;
  }
  return false;
}

int main() {
  int N, A, B, C, D; std::cin >> N >> A >> B >> C >> D;
  std::string S; std::cin >> S;
  std::vector<bool> v(N+1);
  for (int i = 0; i < N; ++i) {
    if (S[i] == '.') v[i + 1] = true;
    else             v[i + 1] = false;
  }

  bool success = true;

  if (C<D) {  // C < D : funuke -> sunuke
    success &= check2(v, B, D);
    success &= check2(v, A, C);
  } else {  // D < C
    success &= check2(v, B, D);
    success &= check3(v, B, D);
  }

  if (success) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,w;
    cin>>n>>w;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    vector<int> dp(w+1);

    for(int i=1;i<w+1;i++)
    {
        for(auto j:a)
        {
            if(j<=i && dp[i-j]==0)
                dp[i]=1;
        }
    }

    if(dp[w]) cout<<"First";
    else cout<<"Second";

    return 0;
}

Measured memory_bytes: 640
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210;

int a[N][N];

vector<pair<int, int>> eds[N];

void add_edge(int x, int y, int k) {
	eds[y].emplace_back(x, k);
}

int n, m;
int was[N];

int p[N];
int q[N];
int b[N][N];

bool dfs1(int v) {
	was[v] = 1;
	for (int i = 0; i < eds[v].size(); ++i) {
		auto e = eds[v][i];
		if (q[e.first] == -1) {
			q[e.first] = v;
			p[v] = i;
			return 1;
		}
	}
	for (int i = 0; i < eds[v].size(); ++i) {
		auto e = eds[v][i];
		if (!was[q[e.first]] && dfs1(q[e.first])) {
			q[e.first] = v;
			p[v] = i;
			return 1;
		}
	}
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
			--a[i][j];
			add_edge(a[i][j] / m, i, a[i][j]);
		}
	for (int i = 0; i < m; ++i) {
		fill(p, p + n, -1);
		fill(q, q + n, -1);
		for (int j = 0; j < n; ++j) {
			fill(was, was + n, 0);
			dfs1(j);
		}
		for (int j = 0; j < n; ++j) {
			b[i][j] = eds[j][p[j]].second;
			eds[j].erase(eds[j].begin() + p[j]);
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cout << b[j][i] + 1 << " ";
		cout << "\n";
	}
	for (int i = 0; i < m; ++i) {
		sort(b[i], b[i] + n);
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j)
			cout << b[j][i] + 1 << " ";
		cout << "\n";
	}
	return 0;
}




Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))

S = {}

for a in A:
    S[a] = S.get(a, 0) + 1

cnt = 0
for k, v in S.items():
    if k > v:
        cnt += v
    else:
        cnt += min(v, v - k)

print(cnt)

Measured memory_bytes: 68264
h, w = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
s = Array.new(h + 4) { Array.new(w + 4, -1) }
h.times do |j|
  gets.chomp.chars.each_with_index do |t, i|
    if t == '.'
      s[j + 2][i + 2] = 0
    end
  end
end
que = []
wqu = []
que << [c[0] + 1, c[1] + 1]
s[c[0] + 1][c[1] + 1] = 1
while que.size > 0 || wqu.size > 0
  while que.size > 0
    y, x = que.shift
    cnt = s[y][x]
    if s[y + 1][x] == 0
      s[y + 1][x] = cnt
      que << [y + 1, x]
    elsif s[y + 1][x] == -1
      wqu << [y, x]
    end
    if s[y - 1][x] == 0
      s[y - 1][x] = cnt
      que << [y - 1, x]
    elsif s[y - 1][x] == -1
      wqu << [y, x]
    end
    if s[y][x + 1] == 0
      s[y][x + 1] = cnt
      que << [y, x + 1]
    elsif s[y][x + 1] == -1
      wqu << [y, x]
    end
    if s[y][x - 1] == 0
      s[y][x - 1] = cnt
      que << [y, x - 1]
    elsif s[y][x - 1] == -1
      wqu << [y, x]
    end
  end
  while wqu.size > 0
    y, x = wqu.shift
    cnt = s[y][x]
    (y - 2).upto(y + 2) do |j|
      (x - 2).upto(x + 2) do |i|
        if s[j][i] == 0
          s[j][i] = cnt + 1
          que << [j, i]
        end
      end
    end
  end
end
puts s[d[0] + 1][d[1] + 1] - 1

Measured memory_bytes: 25156
#include <bits/stdc++.h>
using namespace std;
int seg[524288]; 
void update(int k, int a){
	k += 262143; 
	seg[k] = a; 
	while(k > 0){
		k = (k - 1) / 2; 
		seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]); 
	}
}
long long query(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return 0; 
	if(a <= l && b >= r) return seg[k]; 
	else{
		long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2); 
		long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r); 
		return max(vl, vr); 
	}
}
int main(){
	int N; cin >> N; 
	pair<int, int> R[200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> R[i].first >> R[i].second; 
		R[i].second += R[i].first; 
	}
	R[N].first = 2145141919; R[N].second = 2145141919; 
	sort(R, R+N); 
	int P = 998244353; 
	int dp[200010] = {}; // そのロボットより右(inclusive)だけの場合の数
	dp[N] = 1; 
	for(int i = 0; i <= N; i++) update(i, i+1); 
	for(int i = N-1; i >= 0; i--){
		int a = lower_bound(R, R+N+1, make_pair(R[i].second, -2145141919)) - R; 
		int it = query(i, a, 0, 0, 262144); 
		update(i, it); 
		dp[i] = dp[i+1] + dp[it];
		if(dp[i] >= P) dp[i] -= P; 
	}
	cout << dp[0] << endl; 	
}

Measured memory_bytes: 4224
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int X[5];
    rep(i,5) cin >> X[i];
    rep(i,5){
        if(X[i]==0) cout << i+1 << endl;
    }
}


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

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	int P='A'-'a';
	char l1=s1[0]+P, l2=s2[0]+P, l3=s3[0]+P;
	cout << l1 << l2 << l3 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

bool compare(const tuple<string,int,int> &a,const tuple<string,int,int> &b){
    if(get<0>(a)==get<0>(b)) return (get<1>(a)>get<1>(b));
    else return (get<0>(a)<get<0>(b));
}
int solve(){
    int n; cin>>n;
    vc<tuple<string,int,int>> v;
    for (int i = 0; i < n; ++i)
    {
        string str; int t;
        cin>>str>>t;
        v.pb(make_tuple(str,t,i+1));
    }
    sort(all(v),compare);
    for (int i = 0; i < n; ++i)
    {
        cout<<get<2>(v[i])<<"\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int ans;
string s,tmp,tmptmp;

signed main() {
    cin >> s;
    rep(i,s.size()) {
        tmp.pb(s[i]);
        if (tmp != tmptmp) {
            tmptmp = tmp;
            ans++;
            tmptmp = tmp;
            tmp.clear();
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

string s;
ll n;
vvll d;
vll am = {1, 10, 9, 12, 3, 4};
ll mod = 1000000007;

ll dp(ll pos, ll m){
    if(d[pos][m]!=-1)return d[pos][m];
    
    if(pos == n){
        return (m==5?1:0);
    }
    if(s[pos]!='?'){
        return d[pos][m] = dp(pos+1, (m + (s[pos]-'0')*am[pos%6])%13 );
    }else{
        ll ret = 0;
        rep(i, 10){
            ret += dp(pos+1, (m + (i)*am[pos%6])%13 );
        }
        return d[pos][m] = ret%mod;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    cin>>s;n = s.length();
    reverse(all(s));
    initvv(d, n+10ll, 13ll, -1ll);
    cout << dp(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 20048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    int x,y;
    cin>>x>>y;
    rep(i,101){
        rep(j,101){
            if (i+j==x && 2*i+4*j==y){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3584
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
using ll = long long;
const int N = 2e5+10;
ll arr[N];
ll dp[N][2][2];
int n;
int main() {
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> arr[i];
    for(int i = 1; i <= n; i ++) {
        if(i & 1) {
            dp[i][0][0] = dp[i-1][1][0] + arr[i];
            dp[i][0][1] = arr[i] + dp[i-1][1][1];
            dp[i][1][1] = max(dp[i-1][1][0], dp[i-1][0][0]);
        } else {
            dp[i][0][0] = arr[i] + dp[i-1][1][1];
            dp[i][1][0] = dp[i-1][0][0];
            dp[i][1][1] = max(dp[i-1][0][1], dp[i-1][1][1]);
            //cout << i << " "<<dp[i][0][0]<<"-" <<dp[i][1][0]<<"-"<<dp[i][1][1]<< endl;
        }

    }
    if(n & 1) {
        cout << max(dp[n][0][1], dp[n][1][1]) << endl;
    } else {
        cout << max(dp[n][1][0], dp[n][0][0]) << endl;
    }
    return 0;
} 

Measured memory_bytes: 11444
n=int(input())
oisisa=[int(i) for i in input().split()]

total=0
for i in range(n):
    for j in range(n):
        total+=oisisa[i]*oisisa[j]

for i in range(n):
    total-=oisisa[i]*oisisa[i]
    
print(int(total/2))
        

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
using namespace std;
int n,m,a[10008],i=0;
int tot=0;
int main() {
    cin >> n;
    cin >> m;
    for (i=1; i<=m; i++) {
        cin >> a[i];
    }
    for (i=1; i<=m; i++) {
        tot+=a[i];
    }
    if (tot<=n) {
        cout << n-tot;
    }
    else{
        cout << -1;
    }
    return 0;
}


Measured memory_bytes: 3632
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ z : expr ) ,+ ) => { { std :: cmp :: min ( $ x , min ! ( $ ( $ z ) ,* ) ) } } }

fn main() {
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: usize,
            a: [usize; n],
            s: Chars,
        }
        let mut basis = Vec::new();
        let mut flag = false;
        for i in (0..n).rev() {
            let mut e = a[i];
            for &b in &basis {
                e = min!(e, e ^ b);
            }
            if s[i] == '0' {
                if e > 0 {
                    basis.push(e);
                }
            } else {
                if e > 0 {
                    flag = true;
                }
            }
        }
        if flag {
            println!("1");
        } else {
            println!("0");
        }
    }
}


Measured memory_bytes: 2608
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define vi vector<int>
#define vii vector< vector<int> >
#define vpi vector< pair<int,int> >
#define pair <int, int> pii

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
    ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

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

template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

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

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;
const int N = 1e5 + 10 ;

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

	int n;
	cin>>n;

	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];
	
	vi v;
	for(int i=1;i<=n;i++) {
		v.pb(i);
	}

	bool oye=true;
	for(int i=0;i<n;i++) {
		if(a[i]<b[i]) {
			break;
		}
		if(a[i]>b[i]) {
			oye=false;
			break;
		}
	}

	if(!oye) {
		for(int i=0;i<n;i++) {
			swap(a[i],b[i]);
		}
	}

	int cur=0;
	int ans=0,idx1=0,idx2=0;
	do {	
		cur++;
		bool ok=true, ok1=true;	
		for(int i=0;i<n;i++) {
			if(a[i]==v[i]) {

			}
			else {
				ok=false;
				// break;
			}
			if(b[i]==v[i]) {

			}
			else {
				ok1=false;
				// break;
			}
		}
		if(!ok&&ok1) {
			ans++;
		}
		if(ok) {
			idx1=cur;
		}
		if(ok1) {
			idx2=cur;
		}
	}while(next_permutation(all(v)));

	cout<<(idx2-idx1)<<endl;

return 0 ;
}


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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)
// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  multiset<int> st;
  rep(i, n) {
    auto it = st.upper_bound(A[i]-1);
    if (it == st.begin()) st.insert(A[i]);
    else {
      it--;
      st.erase(it);
      st.insert(A[i]);
    }
  }
  cout << st.size() << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 5376
import numpy as np
import sys
n,k = map(int,input().split())
a_list = sorted(map(int,input().split()))
mod = 10**9+7
if n-k < a_list.count(0):
    print(0)
    exit()
if (sum([1 for a in a_list if np.sign(a)!=-1])==0 and k%2==1) or (k==n and len([1 for a in a_list if np.sign(a)==-1])%2==1):
    a_list.sort(key = abs)
    ans = 1
    for num in a_list[:k]:
        ans *= num
        ans %= mod
    print(ans)
    exit()
else:
    a_list.sort(key = abs,reverse = True)
    add = 1
    remove = 1
    if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
        negative_big = [num for num in a_list[:k] if np.sign(num)==-1]
        positive_big = [num for num in a_list[:k] if np.sign(num)!=-1]
        negative_small = [num for num in a_list[k:] if np.sign(num)==-1]
        positive_small = [num for num in a_list[k:] if np.sign(num)!=-1]
        
        
        if len(negative_big)==0 or len(positive_small)==0:
            remove = min(positive_big)
            add = min(negative_small)
        elif len(positive_big)==0 or len(negative_small)==0:
            remove = max(negative_big)
            add = max(positive_small)
        else:
            positive_small_max = max(positive_small)
            negative_big_max = max(negative_big)
            negative_small_min = min(negative_small)
            positive_big_min = min(positive_big)
            if positive_small_max*positive_big_min > negative_small_min*negative_big_max:
                remove = negative_big_max
                add = positive_small_max
            else:
                remove = positive_big_min
                add = negative_small_min
ans = 1
for num in a_list[:k]:
    ans *= num
    ans %= mod
    
if len([a for a in a_list[:k] if np.sign(a)==-1])%2!=0:
    ans *= add
    ans %= mod
    ans *= pow(remove, mod-2, mod)
    ans %= mod

print(ans)

Measured memory_bytes: 50120
//                                 Alisher_2211
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        # include <bits/stdc++.h>
# define  long          long long
# define  all(vc)       vc.begin(),vc.end()
# define  allr(vc)      vc.rbegin(),vc.rend()
# define  pb            push_back
# define  fi            first 
# define  se            second
# define  pi            pair <long, string>    
# define  lcm(a, b)     (a * b) / __gcd(a, b)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        using namespace std;
const long N = 100100;
void read(){freopen("input.txt" , "r" , stdin );freopen("output.txt", "w" , stdout );}
void solve(){
    string s;
    long n, m, x, a = 0, b = 0;
    cin >> n >> m;
    map <long, long> u, g;
    vector <pi> v;
    for (int i = 0; i < m; ++i){
        cin >> x >> s;
        v.pb({x, s});
        if( u[x] ) continue;
        if( s == "AC" ) u[x] = 1, a ++;
    }
    for (int i = 0; i < m; ++i){
        if( u[ v[i].fi ] == 0 ) continue;
        if( v[i].se == "AC" ) g[ v[i].fi ] = 1;
        if( g[ v[i].fi ] == 0 ) b ++;
    }
    cout << a << ' ' << b;
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
        long T = 1;
        //cin >> T;
        while( T-- ){
            solve();
            cout<<'\n';
        }
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

Measured memory_bytes: 19468
#include <stdio.h>

int main(void) {
	char s[16];
	int y = 0,i,j,sum = 0,u,p[16] = {0},q[16] = {0,2,3,4,5,6,7,2,3,4,5,6},a = 0,c;
	scanf("%s",s);
	for(i = 0;i <= 11;i++){
		if(s[11 - i] != '?'){
			p[i] = s[11 - i] - 48;
		}
		else{
			u = i;
		}
	}
	
	if(u){
		for(i = 0;i <= 9;i++){
			sum = 0;
			p[u] = i;
			for(j = 1;j <= 11;j++){
				sum+=(p[j]*q[j]);
			}
			if(sum % 11 < 2){
				c = 0;
			}
			else{
				c = 11 - sum % 11;
			}
			if(c == p[0]){
				if(y){
					a = 10;
				}
				else{
					a = i;
					y++;
				}
			}
		}
	}
	else{
		for(i = 1;i <= 11;i++){
			sum+=(p[i]*q[i]);
		}
		if(sum % 11 < 2){
			a = 0;
		}
		else{
			a = 11 - sum % 11;
		}
	}
	
	if(a != 10){
		printf("%d\n",a);
	}
	else{
		printf("MULTIPLE\n");
	}
	return 0;
}

Measured memory_bytes: 536
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 998244353
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a, 
              const pair<int,int> &b) 
{   
    if(a.ff == b.ff){
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff); 
}
int l[100003], r[100003];
vi a(100003);
int dp[100003][2];
int32_t main()
{
    // IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    int n;
    cin >>  n;

    rep(i, 0, n){
        cin >> a[i+1];
    }
    dp[0][0] = 0;
    dp[0][1] = -1000000001;
    for(int i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][0]+a[i], dp[i-1][1]-a[i]);
        dp[i][1] = max(dp[i-1][0]-a[i], dp[i-1][1]+a[i]);
    }


    

    cout << max(dp[n-1][1] -a[n], dp[n-1][0] + a[n]);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k;
   cin >> n >> k;
   vector<int> a(n);
   f(i,0,n){
      cin >> a[i];
   }
   vector<long double> val(n);
   f(i,0,n){
      val[i] = (a[i]*(a[i]+1))/2;
      val[i] /= a[i];
   }
   long double ans = 0;
   f(i,0,k){
      ans += val[i];
   }
   long double res = ans;
   f(i,k,n){
      res -= val[i-k];
      res += val[i];
      ans = max(ans,res);
   }
   cout << setprecision(14) << fixed<< ans << '\n';
   return 0;
}

Measured memory_bytes: 4992
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector< P > v;
    rep(i, n){
        int x, l;
        cin >> x >> l;
        v.emplace_back(x+l, x-l);
    }
    SORT(v);

    int ans = 0;
    int now = -IINF;
    rep(i, n){
        if(now <= v[i].second){
            ++ans;
            now = v[i].first;
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(void){
    int n;
    int num;
    long long sum_right = 0;
    long long sum_left = 0;
    long long sum = 0;
    
    cin >> n;
    
    long long a[n];
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    for(int i = 0; i < n; i++){
        if(sum - sum_left >= sum/2){
            sum_left += a[i];
            num = i;
        } else {
            sum_right += a[i];
        }
    }

    sum_left -= a[num];

    if(sum_left > sum_right){
        sum_right += a[num];
        cout << sum_right - sum_left << endl;
    } else {
        sum_left += a[num];
        cout << sum_left - sum_right << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := scanInt(), scanInt()

	fmt.Println((N-1)/(K-1) + intMin((N-1)%(K-1), 1))
}


Measured memory_bytes: 1772
N = gets.chomp.to_i
v = gets.chomp.split(" ").map(&:to_i)
v.sort!
work = 0
for i in 1..N-1 do
    if i == 1
        work = (v[i].to_f + v[i-1].to_f) / 2 
    else
        work = (work.to_f + v[i].to_f) / 2
    end
end
puts work

Measured memory_bytes: 1788
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A = LI()
    if len(list(set(A))) == 2:
        print("Yes")
    else:
        print("No")

main()



Measured memory_bytes: 8132
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }

int main(){
    ll n,m;
    in(n,m);
    out(intpow(2,m)*(m*1900+100*(n-m)));
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

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

const int maxn = 100+10;
const int maxw = 100000+10;
ll w[maxn],v[maxn],N,W;
ll dp[maxn][maxw];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> W;
	forn(i,0,N)cin >> w[i] >> v[i];
	dp[0][w[0]] = v[0];
	forn(i,1,N){
		forn(j,1,W+1){
			dp[i][j] = dp[i-1][j];
			if(j-w[i] >= 0){
				dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
			}
		}
	}
	ll res = 0;
	forn(i,0,W+1)res = max(res,dp[N-1][i]);
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

using namespace std;

using ll = long long;

int main(){
    string S;
    cin >> S;

    string hoge = "123";
    int c1 = 1;
    int c2 = 0;
    auto s1 = S[0];
    auto s2 = hoge[0];
    bool flag = false;
    for (int i = 1; i < 4; i++){
        if ( flag == false && S[i] != s1 ){
            flag = true;
            c2 = 1;
            s2 = S[i];
        }
        else if (flag == true && S[i] == s2)
            c2++;
        else if (S[i] == s1)
            c1++;
    }

    if (c1 == 2 && c2 == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {

	double n = 0, m = 0;


	cin >> n >> m;


	n -= 1;
	m -= 1;


	/*if (n <= a) {
		cout << "Yes";
	}
	else if(n > a) {
		cout << "No";
		
	}*/

	cout << n * m;


	return 0;
}

Measured memory_bytes: 3768
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	FILE *fp = stdin;
	unsigned  a, b, A[2001] = { 0 }, loopend,cnt;
	int n;
	for (a = 0; a <= 1000; a++)for (b = 0; b <= 1000; b++)A[a + b]++;
	while (~fscanf(fp, "%d", &n)) {
		cnt = 0;
		loopend = n < 1000 ? n : 1000;
		for (a = 0; a <= 2 * loopend; a++)for (b = 0; b <= 2 * loopend; b++)
			if (a+b == n)cnt+=A[a]*A[b];
			printf("%u\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#include<atcoder/all>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
using namespace atcoder;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t,n,m,a,b;
    cin>>t;
    while(t--&&cin>>n>>m>>a>>b)
        cout<<floor_sum(n,m,a,b)<<"\n";
    return 0;
}


Measured memory_bytes: 3680
package main

import (
  "fmt"
)

func reversedString(s string) string {
  r := []rune(s)
  n := len(r)
  for i := 0; i < n / 2; i++ {
    r[i], r[n-1-i] = r[n-i-1], r[i]
  }
  return string(r)
}

func main() {
  var n string; fmt.Scan(&n)
  ans := "No"
  if n == reversedString(n) {ans = "Yes"}
  fmt.Println(ans)
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll V, E, r;

    cin >> V >> E >> r;

    vector<vector<P>> graph(V);
    REP(i, E){
        ll s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back(P(t,d));
    }

    vector<bool> visited(V, false);
    vector<ll>   shortest(V, INF);
    shortest[r] = 0;

    priority_queue<P, vector<P>, greater<P>> queue;
    queue.push(P(shortest[r], r) );

    while(!queue.empty()){
        P cur = queue.top();
        ll cur_dist = cur.first;
        ll cur_node = cur.second;
        queue.pop();
        if( visited[cur_node] ){
            continue;
        }
        visited[cur_node] = true;
        for(auto const& edge : graph[cur_node] ){
            ll next_node = edge.first;
            ll distance = edge.second;
            if( shortest[next_node] > cur_dist+distance ){
                shortest[next_node] = cur_dist+distance;
                queue.push(P(shortest[next_node],next_node));
            }
        }
    }

    REP(i, V){
        if( shortest[i] == INF ) cout << "INF" << endl;
        else cout << shortest[i] << endl;
    }
}



Measured memory_bytes: 19376
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	int n;
	cin>>n;
	vlli arr(n);
	FOR(i,n)cin>>arr[i];
	sort(all(arr),greater<int>());
	int ans=0;
	if(n==0){
		cout<<0;
		return ;
	}
	ans+=arr[0];
	int i=2,j=1,time=0;
	while(i<n){
		ans+=arr[j];
		time++;
		if(time==2)j++,time=0;
		i++;
	}
	cout<<ans;
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}



Measured memory_bytes: 4728
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	min := calcDiff(s[0:3])
	for i := 1; i < len(s)-2; i++ {
		diff := calcDiff(s[i : i+3])
		if diff < min {
			min = diff
		}
	}
	fmt.Println(min)
}

func calcDiff(s string) int {
	x, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}

	diff := float64(753 - x)
	return int(math.Abs(diff))
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return ;
	}
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	sort(all(v));
	vector<int> re;
	int cnt = -1;
	int xi = 0;
	while (cnt <= v.back() + 1) {
		if (cnt != v[xi]) {
			re.push_back(cnt);
			cnt++;
		} else {
			cnt = v[xi] + 1;
			xi++;
		}
	}
	pii ans = {INF, -1};
	rep(i, re.size()) {
		int diff = abs(x - re[i]);
		if (diff < ans.first) {
			ans = {diff, i};
		}
	}
	if (ans.first == INF) cout << x << endl;
	else cout << re[ans.second] << endl;
}

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

	solve();
}



Measured memory_bytes: 3660