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

const int N = 105, K = 1e5+5, MOD = 1e9+7;
int dp[N][K], dpprefix[N][K], a[N], prefix[N];
//dp[i][j] the number of ways such that we used j candies among first i children

int32_t main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 1; i <= n; i++) {
    scanf("%d", a+i);
    prefix[i] = a[i] + prefix[i-1];
  }

  dp[0][0] = 1;
  for (int i = 0; i <= k; i++)
    dpprefix[0][i] = 1;

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= std::min(prefix[i], k); j++) {
      int l = std::max(0, j-a[i]);
      dp[i][j] = (dpprefix[i-1][j] - dpprefix[i-1][l] + dp[i-1][l]) % MOD;
      if (dp[i][j] < 0)
        dp[i][j] += MOD;
      /*
      for (int l = std::max(0, j-a[i]); l <= j; l++)
        dp[i][j] = (dp[i][j] + dp[i-1][l]) % MOD;
      */
    }

    dpprefix[i][0] = dp[i][0];
    for (int j = 1; j <= k; j++)
      dpprefix[i][j] = (dp[i][j] + dpprefix[i][j-1]) % MOD;
  }

  /*for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++)
      printf("%d ", dp[i][j]);
    puts("");
  }*/

  printf("%d\n", dp[n][k]);
  return 0;
}


Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
const int N = 18;

int n;
int a[N][N];

long long u[1 << N];
long long dp[1 << N];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int x = 0; x < (1 << n); ++x)
    {
        for (int i = 0; i < n; ++i)
        {
            if (!(x & (1 << i)))
                continue;
            for (int j = i + 1; j < n; ++j)
            {
                if (!(x & (1 << j)))
                    continue;
                u[x] += a[i][j];
            }
        }
    }
    for (int x = 0; x < (1 << n); ++x)
    {
        for (int y = x; y; y = (y - 1) & x)
        {
            int z = (x ^ y);
            dp[x] = max(dp[x], u[y] + dp[z]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 1; i < n; i++)
using namespace std;
typedef long long ll;

#define array_sort_asc(array,size) sort(array, array+size);
#define array_sort_desc(array,size) sort(array, array+size,greater<>());

int main() {
    // 入力部
    int n;
    cin >> n;

    int b[n-1];
    REP(i,n-1) cin >> b[i];

    // ロジック部
    int sum = b[0];
    REP1(i,n){
        if(i==n-1){
            sum = sum + b[i-1];
        }
        else{
            sum = sum + min(b[i-1],b[i]);
        }
    }


    cout << sum << endl;
}

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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//Debug
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "("+to_string(p.fi)+", "+to_string(p.se)+")";}
template <typename A>
string to_string(A v) {
	if(v.begin()==v.end()) return "";
	return accumulate(++v.begin(), v.end(), "{"+to_string(*v.begin()),
			[](const string& a, auto b){ return a + ", " + to_string(b);})+"}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) false
#endif


double PI=3.141592653589793;

const int mx=1<<18,mvn=1e5;
map<int,int> proc[mx];
int va[mx],w[mx];


void solve(){
	int n,q;
	cin >> n;
	int bs=11;
	forse(i,1,n+1) cin >> va[i] >> w[i];
 
	forse(i,1,n+1){

		if(i>=(1<<bs)) break;
		map<int,int> cur;

		if(i==1){
			cur[0]=0;
			cur[w[i]]=va[i];
			proc[i]=cur;
			continue;
		}
 
		cur=proc[i/2];
		for(auto v:proc[i/2]){
			int vn=v.fi+w[i],val=v.se+va[i];
			if(vn<=mvn) cur[vn]=max(cur[vn],val);
		}
		int bval=-1;
		for(auto v:cur){
			if(v.se<=bval) continue;
			bval=v.se;
			proc[i][v.fi]=v.se;
		}	
	}
 
//	forse(i,1,n+1){
//		debug(i,proc[i]);
//	}
 
	cin >> q;
	while(q--){
		int v,l;
		cin >> v >> l;
		int pr=v,out=0;

		vector<pii> pro;
		while(pr>=(1<<bs)){
			pro.pb({w[pr],va[pr]});	
			pr/=2;
		}

		forn(ind,(1<<sz(pro))){
			int vsm=0,wsm=0;
			forn(j,sz(pro)){
				if(ind&(1<<j)){
					vsm+=pro[j].se;
					wsm+=pro[j].fi;
				}
			}
			if(l<wsm) continue;
			out=max(out,vsm+(--proc[pr].upper_bound(l-wsm))->se);
		}

		cout << out << '\n';
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 135148
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
#define SZ(x) ((ll).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, n) for(ll i = 0; i < n; i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}
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; }

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

  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<ll>>;
Graph G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar(ll n, ll pre){
    for(auto next_n: G[n]){
      if(next_n==pre) continue;
      par[next_n]=n;
      mkpar(next_n, n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};

map<pair<ll,ll>,ll> mp;
void dfs(ll n, ll pre, ll num){
  num=1;
  for(auto next_n: G[n]){
    if(next_n==pre) continue;
    ll b=next_n, m=n, mm=n, p=pre;
    if(b<m) swap(b,m);
    if(pre>mm) swap(pre,mm);
    if(num==mp[make_pair(pre,mm)]) num++;
    mp[make_pair(m,b)]=num;
//    cout<<"nexn:"<<next_n<<" num:"<<num<<endl;
    dfs(next_n, n, num++);
  }
}
//出力順番みだれる。どうしよう。
//DFSじゃなくてBFSかな
//ううむ、DFSで深さ覚えとくか
//親の色だけ拾えればいいの
//1-2 1-3 2-4 だったら、2=1 3=2 をナンバリング 4=2 2が1なので
//UnionFindみたいなやつで親子関係つける
//mapで色付け管理か
//出発地点渡して、DFSで親子関係つくっていくのか
//mkpar作れた･･･ひとしお
//入力値の右側だけみりゃいいのか
//1,3/2,3のとき3かぶりじゃん。やっぱmap管理か
int main(){
  ll N; cin>>N;
  G.assign(N+1,vector<ll>());
  vector<pair<ll,ll>> H(N);
  for(int i=0; i<N-1; i++){
    ll a,b; cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    H[i]=make_pair(a,b);
  }
  UnionFind tree(N);
  tree.mkpar(1,1);
  dfs(1,1,1);
  ll mm=0;
  for(int i=0; i<N-1; i++) mm=max(mm,mp[H[i]]);
  cout<<mm<<endl;
  for(int i=0; i<N-1; i++) cout<<mp[H[i]]<<endl;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 4) --> {1,2,3,4}
// rep(i, 4, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int sum = 0;
    while (n!=0)
    {
        n = n/k;
        sum++;
    }
    cout << sum;
    return 0;
}

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

using namespace std;

__int128_t gcd(__int128_t a, __int128_t b) {
    if (b == 0) return a;
    return gcd(b,a%b);
}

__int128_t lcm(__int128_t a, __int128_t b) {
    __int128_t X = a*b;
    return X/gcd(a,b);
}

__int128_t parse(string s) {
    __int128_t b = 1, ret = 0;
    for (int i=s.size()-1;i>=0;i--) {
        ret += (s[i]-'0')*b;
        b *= 10;
    }
    return ret;
}

int main(void) {
    int N;
    __int128_t X;
    vector<__int128_t> T(110,0);
    cin >> N;
    for (int i=0;i<N;i++) {
        string s;
        cin >> s;
        T[i] = parse(s);
    }

    if (N == 1) X = T[0];
    else {
        X = lcm(T[0],T[1]);
        for (int i=2;i<N;i++) {
            X = lcm(X,T[i]);
        }
    }
    deque<int> Q;
    while (X) {
        Q.push_front(X%10);
        X /= 10;
    }
    if (Q.empty()) Q.push_back(0);
    for (int i=0;i<Q.size();i++) cout << Q[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());

        List<Integer> pList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            pList.add(Integer.parseInt(sc.nextLine()));
        }

        pList.sort(Collections.reverseOrder());
        pList.set(0, pList.get(0) / 2);

        int sum = 0;
        for(Integer p: pList) {
            sum += p;
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 21972
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

ll gcd(ll a, ll b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<int> xs(n); cin >> xs;
    xs.push_back(x);
    sort(xs.begin(), xs.end());
    int ans = xs[1] - xs[0];
    for(int i = 0; i < n; i++){
        ans = gcd(ans, xs[i + 1] - xs[i]);
    }
    cout << ans << '\n';
}


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

#define MOD 1000000007

int main()
{
    long long n, k;
    scanf("%lld%lld", &n, &k);
    int a[n];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }

    long long ans = 0;
	for(int i = 0; i < n; i++)
    {
		for (int j = i + 1; j < n; j++)
		{
			if (a[i] > a[j])
			{
				ans += k * (k + 1) / 2;
				ans %= MOD;
			}
			else if(a[i]<a[j])
			{
				ans += k * (k - 1) / 2;
                ans %= MOD;
			}
		}
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int dp[3005][3005],a[3005][3005],ans,ansi,ansj;
vector<char>vec;
void dfs(int x,int y)
{
	if(x<0||y<0)return;
	if(a[x][y]==0)
	{
		vec.push_back(s[x]);
		dfs(x-1,y-1);
	}
	else if(a[x][y]==1)dfs(x-1,y);
	else dfs(x,y-1);
}
int main()
{
	cin>>s>>t;
	s=' '+s;
	t=' '+t;
	for(int i=1;i<s.size();i++)for(int j=1;j<t.size();j++)
	{
		if(s[i]==t[j])
		{
			dp[i][j]=dp[i-1][j-1]+1;
			a[i][j]=0;
			if(dp[i][j]>ans)
			{
				ansi=i;
				ansj=j;
				ans=dp[i][j];
			}
		}
		else if(dp[i-1][j]>=dp[i][j-1])
		{
			dp[i][j]=dp[i-1][j];
			a[i][j]=1;
		}
		else
		{
			dp[i][j]=dp[i][j-1];
			a[i][j]=2;
		}
	}
	dfs(ansi,ansj);
	for(int i=vec.size()-2;i>=0;i--)cout<<vec[i];
} 

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 200010
#define K 100010
vi T(K), X(K), Y(K);
vi par1(N); //親
vi ran1(N); //木の深さ
vi par2(N);
vi ran2(N);

			   //n要素で初期化
void init1(int n) {
	int i;
	for (i = 0; i < n; i++) {
		par1[i] = i;
		ran1[i] = 0;
	}
}

//木の根を求める
int find1(int x) {
	if (par1[x] == x) {
		return x;
	}
	else {
		return par1[x] = find1(par1[x]);
	}
}

//xとyの属する集合を併合
void unite1(int x, int y) {
	x = find1(x);
	y = find1(y);
	if (x == y) {
		return;
	}
	if (ran1[x]<ran1[y]) {
		par1[x] = y;
	}
	else {
		par1[y] = x;
		if (ran1[x] == ran1[y]) {
			ran1[x]++;
		}
	}
}

//xとyが同じ集合に属するか否か
bool same1(int x, int y) {
	return find1(x) == find1(y);
}

void init2(int n) {
	int i;
	for (i = 0; i < n; i++) {
		par2[i] = i;
		ran2[i] = 0;
	}
}

//木の根を求める
int find2(int x) {
	if (par2[x] == x) {
		return x;
	}
	else {
		return par2[x] = find2(par2[x]);
	}
}

//xとyの属する集合を併合
void unite2(int x, int y) {
	x = find2(x);
	y = find2(y);
	if (x == y) {
		return;
	}
	if (ran2[x]<ran2[y]) {
		par2[x] = y;
	}
	else {
		par2[y] = x;
		if (ran2[x] == ran2[y]) {
			ran2[x]++;
		}
	}
}

//xとyが同じ集合に属するか否か
bool same2(int x, int y) {
	return find2(x) == find2(y);
}

int main() {
	int n, k, l, i, j;
	cin >> n >> k >> l;
	init1(n);
	init2(n);
	int p, q;
	for (i = 0; i < k; i++) {
		cin >> p >> q;
		unite1(p - 1, q - 1);
	}
	for (i = 0; i < l; i++) {
		cin >> p >> q;
		unite2(p - 1, q - 1);
	}
	vector<pii> v(n);
	map<pii, int> mp;
	for (i = 0; i < n; i++) {
		v[i] = make_pair(find1(i), find2(i));
		mp[v[i]]++;
	}

	for (i = 0; i < n; i++) {
		cout << mp[v[i]] << " ";
	}
	return 0;
}

Measured memory_bytes: 17920
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0]+x[1])
a = abs(L[0][0]-L[-1][0])+abs(L[0][1]-L[-1][1])
L.sort(key=lambda x: x[0]-x[1])
b = abs(L[0][0]-L[-1][0])+abs(L[0][1]-L[-1][1])
print(max(a, b))


Measured memory_bytes: 117096
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let x: u64 = input();
    if x < 600 {
        println!("8");
    } else if x < 800 {
        println!("7");
    } else if x < 1000 {
        println!("6");
    } else if x < 1200 {
        println!("5");
    } else if x < 1400 {
        println!("4");
    } else if x < 1600 {
        println!("3");
    } else if x < 1800 {
        println!("2");
    } else {
        println!("1");
    }
}


Measured memory_bytes: 2140
#include<iostream>
#include<memory.h>
using namespace std;
long long gcd(long long a,long long b)
{     if(a==0||b==0) return a+b;
      if(a>b){
      	return gcd(b,a%b);
	  }
	  else return gcd(a,b%a);
}

int main(){
	int n;
    while(cin>>n){
		long long dp[101];
		memset(dp,0,sizeof(dp));
		cin>>dp[0]; 
		long long cnt=dp[0];
		for(int i=1;i<n;i++){
			cin>>dp[i];
			if(cnt%dp[i]==0) continue;
			else if(dp[i]%cnt==0) cnt=dp[i];
			else cnt=cnt/gcd(cnt,dp[i])*dp[i];
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 256
A,B,H,M=map(int, input().split())
import math

m=M/60*math.pi*2
h=H/12*math.pi*2+m/12
if m>=h:
    alpha=m-h
else:
    alpha=h-m
ans=pow(B,2)+pow(A,2)-2*B*A*math.cos(alpha)
print(math.sqrt(ans))

Measured memory_bytes: 9564
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
ll qpow(ll n,ll k)
{
    ll ans=1;
    assert(k>=0);
    n%=mod;
    while(k>0)
    {
        if(k&1)
            ans=(ans*n)%mod;
        n=(n*n)%mod;
        k>>=1;
    }
    return ans%mod;
}
int main()
{
    fast;
    int n, k;
    cin>>n>>k;
    int arr[n+1];
    ll dp[k+1][n+1];
    ll cum[k+1][n+1];
    REP1(i, n) cin>>arr[i];
    dp[0][0] = 1;
    cum[0][0] = 1;
    REP(i, k+1){
      REP(j, n+1){
        if(i==0) {
          dp[i][j] = 1;
          cum[i][j] = 1;
        }
        else if(j==0) {
          dp[i][j] = 0;
          cum[i][j] = 0;
        }
        else{
          dp[i][j] = 0;
          /*
          REP(k, arr[j]+1){
            if(i>=k) sum += dp[i-k][j-1];
            else break;
            sum %= mod;
          }
          */
          ll right = i;
          ll left = i - min(i, arr[j]);
          ll cumSum = cum[right][j-1];
          if(left>0) {
            if(cumSum<cum[left-1][j-1]) cumSum+=mod;
            cumSum -= cum[left-1][j-1];
          }
          dp[i][j] = cumSum;
        }
        if(i>0) {
          cum[i][j] = cum[i-1][j] + dp[i][j];
          cum[i][j] %= mod;
        }
        else cum[i][j] = dp[i][j];
      }
    }
    cout<<dp[k][n]<<'\n';
    return 0;
}


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

vector<ll> x;
vector<ll> y;
int N;

void init()
{
	cin >> N;
	rep(i, N) {
		x.PB(GET<int>());
		y.PB(GET<int>());
	}
}

vector<ll> res;

void calc(ll a, ll b)
{
	ll s = 0;
	ll t = 0;
	string x;
	rrep(i, res.size()) {
		ll l = res[i];
		if (abs(a-s) > abs(b-t)) {
			if (a > s) {
				s += l;
				x += 'R';
			} else {
				s -= l;
				x += 'L';
			}
		} else {
			if (b > t) {
				t += l;
				x += 'U';
			} else {
				t -= l;
				x += 'D';
			}
		}
	}
	cout << x << endl;
}

void solve()
{
	int f = (abs(x[0]) + abs(y[0])) % 2;
	rep(i, N) {
		if (f != (abs(x[i]) + abs(y[i])) % 2) {
			cout << -1 << endl;
			return;
		}
	}
	if (f == 0) res.PB(1);
	{
		ll t = 1;
		rep(i, 39) {
			res.PB(t);
			t *= 2;
		}
	}
	cout << res.size() << endl;
	rrep(i, res.size()) {
		if (i == 0) {
			cout << res[i] << endl;
		} else {
			cout << res[i] << " ";
		}
	}
	rep(i, N) {
		calc(x[i], y[i]);
	}
}





Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
i = 0
ans = 0
for A, B in AB:
    if (A | K) == K:
        ans += B
while (1 << i) <= K:
    if K >> i & 1:
        tmp = 0
        for A, B in AB:
            if A >> i & 1:
                continue
            if ((A | K) >> (i+1)) == (K >> (i+1)):
                tmp += B
        ans = max(ans, tmp)
    i += 1
print(ans)

Measured memory_bytes: 58508
#include <cmath>
#include <iostream>

using namespace std;

#define RPT(i, n) for (int i = 1; i <= (n); i++)

int N, A[16], x[16][16] = {{0}}, y[16][16] = {{0}};
int ans;

int ExtractKeta(int p, int keta) { return ((p >> keta) & 1); }

bool IsConsistent(int p)
{
    RPT(i, N)
    {
        if (!((1 << (i - 1)) & p)) continue;
        RPT(j, A[i])
        if (ExtractKeta(p, x[i][j] - 1) != y[i][j]) {
            return false;
        }
    }
    return true;
}

int CountOne(int x)
{
    int ret = 0;
    int cur = x;
    RPT(i, 32)
    {
        if (cur & 1) ret++;
        cur = cur >> 1;
    }
    return ret;
}

int main()
{
    cin >> N;
    RPT(i, N)
    {
        cin >> A[i];
        RPT(j, A[i]) cin >> x[i][j] >> y[i][j];
    }

    ans = 0;
    for (int p = 1; p < (1 << N); p++)
        if (IsConsistent(p)) ans = max(ans, CountOne(p));

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


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

using namespace std;

typedef long long ll;

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

void read() {};

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

void print() {};

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


int main() {
  string s; cin >> s;
  int n = s.length();
  print(string(n, 'x'));
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]

# 最大値のインデックス
i1 = np.argmax(a)
temp = a[i1]
a[i1] = 0
# ２番目の最大値のインデックス
i2 = np.argmax(a)
a[i1] = temp


for i in range(n):
  if i == i1:
    print(a[i2])
  else:
    print(a[i1])
  

Measured memory_bytes: 24392
#include<iostream>
using namespace std;
int main(){
	int n;
	int m;
	cin>>n;
	int*time=new int[n+1];
	for(int i=1;i<n+1;i++){
		cin>>time[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		int ans=0;
		for(int j=1;j<n+1;j++){
			if(a==j){
				ans+=b;
			}else{
				ans+=time[j];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APayment solver = new APayment();
        solver.solve(1, in, out);
        out.close();
    }

    static class APayment {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            if (n % 1000 == 0) {
                out.println(0);
            } else {
                out.println(1000 - (n % 1000));
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

string gene(int n){
    string s = "";
    REP(i,3){
        s += (n - n%(int)pow(10,2-i))/(int)pow(10,2-i) + '0';
        n %= (int)pow(10,2-i);
        if(n < 0)n = 0;
    }
    return s;
}

int main() {
    int n;
    string s;
    cin >> n >> s;

    int count = 0;
    REP(i,1000){
        string target = gene(i);
        // cout << target << endl;
        int index = 0;
        REP(j,n){
            if(target[index] == s[j])index++;
            if(index == 3){
                count++;
                break;
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int waru(int x){
	int i=0;
	while(x%2 == 0){i++;x/=2;}
	return i;
}

int main(void){
	int N;
	scanf("%d",&N);
	int A[N],i,x=40,y;
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
		y = waru(A[i]);
		if(y < x){
			x = y;
		}
	}
	printf("%d",x);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector< vector< lli > > x(N, vector< lli >(3));
  REP(i, N) { cin >> x[i][0] >> x[i][1] >> x[i][2]; }
  vector< vector< lli > > sumList(8, vector< lli >(N));

  REP(j, N) {
    REP(i, BIT(3)) {
      lli sum = 0;
      REP(k, 3) {
        if (BIT(k) & i) {
          sum += x[j][k];
        } else {
          sum -= x[j][k];
        }
      }
      sumList[i][j] = sum;
    }
  }
  lli ansMax = -INF;
  REP(i, 8) {
    sort(ALL(sumList[i]));
    reverse(ALL(sumList[i]));
    lli ansTmp = 0;
    REP(j, M) { ansTmp += sumList[i][j]; }
    // cout <<ansTmp<<"\n";
    ansMax = max(ansMax, ansTmp);
  }
  cout << ansMax << "\n";
}

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

int main() {
  int N;
  cin >> N;
  if(N == 22){
    cout << "Christmas Eve Eve Eve" << endl;
    return 0;
  }
  else if(N == 23){
    cout << "Christmas Eve Eve" << endl;
    return 0;
  }
  else if(N == 24){
    cout << "Christmas Eve" << endl;
    return 0;
  }
  cout << "Christmas" << endl;
}


Measured memory_bytes: 3552
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	double a=0,b=0;
	a=sc.nextInt();
	b=sc.nextInt();
	System.out.println((int)(Math.ceil((b-1)/(a-1))));

	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s; cin>>s;
	sort(s.begin(), s.end());
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]){
		cout<<"Yes";
	}
	else cout<<"No";
  return 0;
}


Measured memory_bytes: 256
while(n=gets.to_i)>0
ans=[b=[x=0,0]]
p=ans*n
n.times{w=0;m=gets
n.times{|j|h,w=p[j][0]+1,w+1;m[j]==?*&&h=w=0
ans[j]=[h,s=[h,w,p[j-1][1]+1].min]
x<s&&x=s}
p,ans=ans,[b]}
p x
end

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

int main(){
  int A,B,C,X;
  cin >>A>>B>>C>>X;
  int count=0;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(500*i+100*j+50*k==X){
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = 998244353ll;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 4005;

int k, n;
ll f[N], inv[N], dp[N][N], s[N][N];

inline ll bp(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = res * a % mod;
		a = sqr(a) % mod;
		b >>= 1;
	}
	return res;
}

inline ll c(int n, int k) {
	return f[n] * inv[n - k] % mod * inv[k] % mod;
}

inline ll calc(int sum, int cnt) {
	if (cnt <= 0) return (sum == 0 ? 1 : 0);
	return c(sum + cnt - 1, cnt - 1);
}

inline void add(ll &x, ll y) {
	x += y;
	if (x >= mod)
		x -= mod;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;

	f[0] = inv[0] = 1;

	for (int i = 1; i < N; i++) {
		f[i] = f[i - 1] * i % mod;
		inv[i] = bp(f[i], mod - 2);
	}

	cin >> k >> n;

	dp[0][0] = s[0][0] = 1;

	for (int i = 0; i <= n; i++) {
		s[i][0] = 1;
		for (int j = 1; j <= k; j++) {
			if (j)
				add(dp[i][j], dp[i][j - 1]);
			if (i) {
				add(dp[i][j], s[i - 1][j - 1]);
				add(dp[i][j], s[i - 1][j - 1]);
				add(s[i][j], s[i - 1][j]);
			}
			add(s[i][j], dp[i][j]);
		}
	}

	for (int i = 2; i <= k + k; i++) {
		ll ans = 0;
		int cnt = 0;
		for (int j = 1; j < i - j; j++)
			cnt += (i - j <= k);
		int tot = cnt + cnt + (!(i & 1));
		if (i & 1) {
			for (int j = 0; j <= n; j++) {
				ans = (ans + dp[j][cnt] * calc(n - j, k - tot)) % mod;
			}
		}
		else {
			for (int j = 0; j <= n; j++) {
				ans = (ans + dp[j][cnt] * calc(n - j, k - tot)) % mod;
				if (j < n)
					ans = (ans + dp[j][cnt] * calc(n - j - 1, k - tot)) % mod;
			}
		}
		cout << ans << "\n"; 
	}

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 126592
#include<iostream>


using namespace std;
int main(void){
    while(1){
    int a;
	int n;
	int c=0;
	cin>>a;
    if(a==0)break;
	int count=0;
	for(n=1000-a;n!=0;c++){
        if(n>=500)n-=500;
        else if(n>=100)n-=100;
        else if(n>=50)n-=50;
        else if(n>=10)n-=10;
        else if(n>=5)n-=5;
        else if(n>=1)n-=1;
    }
    cout << c << endl;

    }
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
vector<int> v[100010];
int d[100010];
bool visit[100010];
vector<int> tp;
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (!visit[xi]) dfs(xi);
	}
	tp.push_back(x);
}
void tpsort()
{
	for (int i=0;i<n;i++)
	{
		if (visit[i]) continue;
		dfs(i);
	}
	reverse(tp.begin(),tp.end());
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(y);
	}
	fill(d,d+n,0);
	tpsort(); 
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=0;j<v[x].size();j++)
			d[v[x][j]]=max(d[v[x][j]],d[x]+1);
	}
	cout <<*max_element(d,d+n);
	return 0;
}

Measured memory_bytes: 8188
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
map<int,int> m;
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		int a;
		cin>>a;
		m[a]++;
	}
	for(P p:m){
		if(p.S>=p.F)ans+=p.S-p.F;
		else ans+=p.S;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6272
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {

	int n, m; cin >> n >> m;

	int a[1000], b[1000], c[1000], dist[100][100];

	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) {
				dist[i][j] = 0;
			}
			else {
				dist[i][j] = INF;
			}
		}
	}

	for (int i = 0; i < m; i++) {
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	int ans = m;
	
	for (int i = 0; i < m; i++) {
		bool shortest = false;
		for (int j = 0; j < n; j++) {
			if (dist[j][a[i]] + c[i] == dist[j][b[i]])shortest = true;
		}

		if (shortest == true) {
			ans--;
		}
	}

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

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

typedef long long ll;
 
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> m(10, vector<int>(10));
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      cin >> m[i][j];
    }
  }
  for(int k=0; k<10; k++){
    for(int i=0; i<10; i++){
      for(int j=0; j<10; j++){
        m[i][j] = min(m[i][j], m[i][k]+m[k][j]);
      }
    }
  }
  int ans = 0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      int a; cin >> a;
      if(a==-1) continue;
      ans += m[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	}
}

Measured memory_bytes: 59396
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<LL> A(N, 0), sum(N+1, 0);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) sum[i+1] = sum[i] + A[i];

    vector<vector<LL>> dp(N, vector<LL>(N+1, MOD * MOD));
    for(int i=0; i<N; i++) dp[i][i+1] = 0;
    for(int d=2; d<=N; d++) {
        for(int i=0; i+d<=N; i++) {
            int j = i+d;
            for(int m=i+1; m<j; m++) {
                dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j]);
            }

            dp[i][j] += sum[j] - sum[i];
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }


    }
    cout << dp[0][N] << endl;

    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;


int main()
{
	int n,r;
	scanf("%d%d",&n,&r);
	int ans;
	if(n<10)
	{
		ans=r+(10-n)*100;
	}
	else ans=r;
	printf("%d",ans);
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;

    int sum = 0;
    rep(1, n+1) {
        sum += (l + i - 1);
    }

    int flavor, diff = 1e9, ans;
    rep(1, n+1) {
        flavor = sum - (l + i - 1);
        if (abs(sum - flavor) < diff) {
            diff = abs(sum - flavor);
            ans = flavor;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CFlipFlipAndFlip {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        ll res = -1;
        if (n > m) {
            swap(n, m);
        }
        if (m == 1) {
            res = 1;
        } else if (n == 1) {
            res = m - 2;
        } else {
            res = (ll) (n - 2) * (m - 2);
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CFlipFlipAndFlip solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int main() {
    long long n, m, ret = 1;
    std::cin >> n >> m;
    const auto mod = 1000000007ll;

    std::vector<long long> fact(101010), inv(101010);
    fact[0] = 1;
    for (auto i = 1; i <= 101010 - 1; i++) fact[i] = fact[i - 1] * i % mod;
    inv[101010 - 1] = inverse(fact[101010 - 1], mod);
    for (auto i = 101010 - 1; i > 0; i--) inv[i - 1] = inv[i] * i % mod;

    std::deque<long long> ps;
    auto lim = std::sqrt(m);
    auto m2 = m;
    for (auto i = 2ll; i <= lim;) {
        if (m % i == 0) ps.push_back(i);
        while (m % i == 0) m /= i;

        if (i == 2) i = 3;
        else i += 2;
    }
    if (m > 1) ps.push_back(m);
    // for (auto a : ps) std::cout << a << " ";
    // std::cout << std::endl;
    m = m2;
    for (auto p : ps) {
        auto e = 0ll;
        while (m % p == 0) {
            m /= p;
            e++;
        }
        // std::cout << m << " " << p << " " << e << std::endl;
        ret = ret * (fact[e + n - 1] * inv[e] % mod * inv[n - 1] % mod) % mod;

        if (p == 2) p = 3;
        else p += 2;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;
    int a,b,c;
    repr(i,1,3510) {
        repr(j,1,3510) {
            ll k=4*i*j-n*i-n*j;
            if (k>0) {
                ll kk=n*i*j;
                if (kk%k==0) {
                    a=i;
                    b=j;
                    c=kk/k;
                }
            } 
        }
    } 
    cout << a << ' ' << b << ' ' << c << endl;

    return 0; 
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,used[100010] = {};
ll A[100010],B[100010];
int main(){
	cin >> N;
	vector<pair<ll,int>> v,u;
	for(int i=1;i<=N;i++){
		cin >> A[i] >> B[i];
		v.push_back({A[i]+B[i],i});
	}
	sort(v.rbegin(),v.rend());
	int l = 0;
	ll ans = 0;
	int cnt = 0;
	while(l<N){
		ans += A[v[l].second];
		l++;
		if(l<N){
			ans -= B[v[l].second];
		}
		l++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3444