akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;

int main(){
	int n,W,w[200],sum[201] = {},res = 0;
	static int dp[2][201][10001] = {};
	dp[0][0][0] = 1;
	cin >> n >> W;
	for(int i = 0;i < n;i++) cin >> w[i];
	sort(w,w + n);
	for(int i = 0;i < n;i++) sum[i + 1] = sum[i] + w[i];
	if(sum[n] <= W){
		cout << 1 << endl;
		return 0;
	}
	for(int i = 1;i <= n;i++){
		int now = i % 2,prev = (i + 1) % 2;
		for(int j = 1;j < i;j++){
			for(int k = 0;k <= W;k++){
				if(k - w[i - 1] >= 0) dp[now][j][k] = (dp[prev][j][k - w[i - 1]] + dp[prev][j][k]) % MOD;
				else dp[now][j][k] = dp[prev][j][k];
			}
		}
		for(int j = 0;j <= W;j++){
			dp[now][i][j] = dp[prev][0][j];
		}
		if(sum[i] <= W) dp[now][0][sum[i]] = 1;
		for(int j = 0;j <= n;j++){
			for(int k = 0;k <= W;k++) dp[prev][j][k] = 0;
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = W - w[i - 1] + 1;j <= W;j++){
			//cout << i << " " << j << " " << dp[n][i][j] << " " << endl;
			res = (res + dp[n % 2][i][j]) % MOD;
		}
	}
	cout << res << endl;
	return 0;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

vector<int64_t>divisor(int64_t n) {
  vector<int64_t>ret;
  for(int64_t i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n)ret.push_back(n/i);
    }
  }
  sort(begin(ret),end(ret));
  return ret;
}

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

  int64_t N,M;
  cin>>N>>M;
  auto v=divisor(M);
  int64_t ans=1;
  for(auto it:v){
    if(N<=M/it)ans=max(ans,it);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3656
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  
  if(S=="abc"){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]float64, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	q := make([]float64, n+1, n+1)

	q[1] = p[0]
	q[0] = 1 - p[0]
	// fmt.Println(q)

	for i := 1; i < n; i++ {
		for j := i + 1; j > 0; j-- {
			q[j] = q[j]*(1-p[i]) + q[j-1]*p[i]
		}
		q[0] = q[0] * (1 - p[i])
		// fmt.Println(q)
	}

	result := float64(0)
	for i := n/2 + 1; i <= n; i++ {
		result += q[i]
	}
	fmt.Println(result)
}


Measured memory_bytes: 768
a = input().split()
list_dist = []
for i in range(int(a[0])):
    b = input().split()
    b = [int(i) for i in b]
    list_dist.append(b)


count = 0
for i in range(int(a[0])):
    for u in range(i):
        list_kari = [list_dist[i][t]-list_dist[u][t]
                     for t in range(len(list_dist[i]))]
        num = sum([i ** 2 for i in list_kari])
        num = num**0.5
        if num.is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064
# C - Skill Up

from itertools import chain, combinations

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
    row = list(map(int, input().split()))
    assert len(row) == 1 + m
    c.append(row[0])
    a.append(row[1:])

print(min((sum(c[i] for i in s) for s in powerset(range(n))
           if all(sum(a[i][j] for i in s) >= x for j in range(m))),
          default=-1))


Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define int long long int
const int INF = 1000000007;
using namespace std;
void solve() {
   int l, r;
   cin >> l >> r;   
   if(l*r % 2019 == 0) {
       cout << '0' << '\n';
       return ;
   } 
    else if(r-l >= 2018){
        cout << '0' << '\n';
    }
    else {
        int mn = INT_MAX;
        for(int i=l;i<r+1;i++) {
            for(int j=i+1;j<r+1;j++) {
                mn = min(mn, (i*j)%2019);
            }
        }
        cout << mn << '\n';
    }
    return ;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>

class dinic
{
private:
	struct edge
	{
		int to;
		long long cap;
		int rev;
		edge(int t_, long long c_, int r_) :to(t_), cap(c_), rev(r_) {}
	};
	std::vector<std::vector<edge> >G;
	std::vector<int>level, iter;
	//source??????BFS?????????
	void bfs(int s_)
	{
		fill(level.begin(), level.end(), -1);
		std::queue<int>que;
		level[s_] = 0;
		que.push(s_);
		while (!que.empty())
		{
			int v = que.front(); que.pop();
			for (int i = 0; i < G[v].size(); ++i)
			{
				edge &e = G[v][i];
				if (e.cap > 0 && level[e.to] < 0)
				{
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}
	//DFS??§?¢?????????????????????????????????????
	long long dfs(int v_, int t_, long long f_)
	{
		if (v_ == t_)return f_;
		for (int &i = iter[v_]; i < G[v_].size(); ++i)
		{
			edge &e = G[v_][i];
			if (e.cap > 0 && level[v_] < level[e.to])
			{
				long long d = dfs(e.to, t_, std::min(f_, e.cap));
				if (d > 0)
				{
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
public:
	//vec=????????°
	dinic(int vec_) :G(vec_), level(vec_), iter(vec_)
	{}
	//from??????to?????????cap???????????????
	void add_edge(int from_, int to_, long long cap_)
	{
		G[from_].push_back(edge(to_, cap_, G[to_].size()));
		G[to_].push_back(edge(from_, 0ll, G[from_].size() - 1));
	}
	//Dinic?????§?????°???????????????source??????sink?????§????????§??????????¨??????????
	//???????¨???????O(V^2*E)
	long long max_flow(int source_, int sink_)
	{
		int flow = 0;
		for (;;)
		{
			bfs(source_);
			if (level[sink_] < 0)return flow;
			fill(iter.begin(), iter.end(), 0);
			for (;;)
			{
				long long f = dfs(source_, sink_, LLONG_MAX);
				if (f > 0)flow += f;
				else break;
			}
		}
		return flow;
	}
};

#include <iostream>
using namespace std;

int main()
{
	int v, e;
	cin >> v >> e;
	dinic water(v);
	for (int i = 0; i < e; ++i)
	{
		int s, t, c;
		cin >> s >> t >> c;
		water.add_edge(s, t, c);
	}
	long long ans = water.max_flow(0, v - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3168
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N;
	scanf("%d", &N);

	printf("%d", N / 3);


}

Measured memory_bytes: 128
s=input()
s=s[::-1]
n=len(s)
count=[0]*2019
count[0]=1
num,d=0,1

for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1

ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)

  

Measured memory_bytes: 9276
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define ff first
#define pb push_back
#define ss second
#define maxn 30005
using namespace std;

int n, v1[maxn], v2[maxn], v3[maxn];
vector<int> v;

int main(){
    string s;
    cin >> n;
    cin >> s;
    for(int i=0;i<n;i++){
        int x = s[i] - '0' + 1;
        v.pb(x);
    }
    v2[n-1] = 1;
    v3[v[n-1]-1] = 1;
    for(int i=n-2;i>=0;i--){
        v2[i] = v2[i+1];
        if (v3[v[i] - 1] == 0) {
            v2[i]++;
            v3[v[i] - 1] = 1;
        }
    }
    for (int j = 1; j < 3; j++) {
        memset(v3, 0, sizeof v3);

        v1[n - 1] = 0;

        for (int i = n - 2; i >= 0; i--) {

            v1[i] = v1[i + 1];
            v1[i] = v1[i] + v2[i + 1];
            v1[i] = v1[i] - v3[v[i] - 1];
            v3[v[i] - 1] = v2[i + 1];
        }
        //v2 = v1;
        for(int i=0;i<=n;i++){
            v2[i] = v1[i];
        }
    }
    cout << v1[0] << endl;




    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int y, m, d;
  char s1, s2;
  cin >> y >> s1 >> m >> s2 >> d;

  if (m > 4) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
}

Measured memory_bytes: 256
N, M =map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]

A.sort(key=lambda a:a[1])
last = -1
ans = 0
for a in A:
    if last < a[0]:
        last = a[1] - 1
        ans += 1
print(ans)


Measured memory_bytes: 29084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    const int K = 2;
    vector<vector<int>> dp(n+1, vector<int>(K + 1, -1));
    
    dp[0][0] = 0;
    rep(i, n) {
        for(int j = 0; j <= K; j++) {
            if(dp[i][j] == -1) {
                continue;
            }
            for(int k = 1; k <= K && i + k <= n; k++) {
                if( j != k || s.substr(i - j, j) != s.substr(i, k) ) {
                    dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= K; j++) {
        ans = max(ans, dp[n][j]);
    }

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

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

const double pi=acos(-1);
struct node{int x,y;}a[200010];
int n,tot,X,Y,sx,sy,tx,ty,b[200010],ans;

bool cmp(node x,node y){return x.x<y.x;}

void work()
{
	scanf("%d %d %d %d %d",&sx,&sy,&tx,&ty,&n);
	if (sx>tx)  X=1,sx=1e8-sx,tx=1e8-tx;
	if (sy>ty)  Y=1,sy=1e8-sy,ty=1e8-ty;
	for (int i=1,x,y; i<=n; i++)
		{
			scanf("%d %d",&x,&y);
			if (X)  x=1e8-x;
			if (Y)  y=1e8-y;
			if ((sx<=x)&&(x<=tx)&&(sy<=y)&&(y<=ty))  a[++tot]=(node){x,y};
		}
	if ((sx==tx)||(sy==ty))
		printf("%.15lf",100.0*(tx-sx+ty-sy)+(10*pi-20)*tot),exit(0);
	sort(a+1,a+tot+1,cmp);
	for (int i=1,x; i<=tot; i++)
		{
			x=lower_bound(b+1,b+ans+1,a[i].y)-b;
			b[x]=a[i].y,ans=max(ans,x);
		}
	printf("%.15lf",100.0*(tx-sx+ty-sy)+(5*pi-20)*ans+(ans>min(tx-sx,ty-sy))*5*pi);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 2560
import sys

STEP = 2

def insert_sort(array, step, cnt):
    for i in range(step, len(array)):
        v = array[i]
        j = i - step
        while (j >= 0) and (array[j] > v):
            array[j + step] = array[j]
            j = j - step
            cnt += 1
        array[j + step] = v
    return cnt

def shell_sort(array):
    cnt = 0
    v = int(len(array)/STEP)
    step_list = []
    while v > 0:
        step_list.append(v)
        v = int(v/STEP)
    if len(step_list) == 0:
        step_list.append(1)
    for step in step_list:
        cnt = insert_sort(array, step, cnt)
    return (cnt, step_list)

def list_to_string(array):
    s = ""
    for n in array:
        s += str(n) + " "
    return s.strip()

def main():
    num = int(sys.stdin.readline().strip())
    array = [int(sys.stdin.readline().strip()) for i in range(0, num)]
    c = shell_sort(array)
    print str(len(c[1]))
    print list_to_string(c[1])
    print str(c[0])
    for n in array:
        print str(n)

if __name__ == "__main__":
    main()

Measured memory_bytes: 77820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
bool isgusu(string s) {
	int n = s.size();
	string x = s.substr(0, n/2);
	string y = s.substr(n/2, n/2);
	return x == y;
} 
int main() {
	string s; cin >> s;
	rep(i, s.size()) {
		string ss = s.substr(0, s.size()-i-1);
		int l = ss.size();
		if (l % 2 != 0) continue;
		if (isgusu(ss)) {
			cout << l << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#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++)
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a > b){
    rep(i,a) cout << b;
  }else if(b > a){
    rep(i,b) cout << a;
  }else{
    rep(i,a) cout << a;
  }
  
  return 0;
}

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

int main() {
  int x,y,z;
  int a,b,c,d;
  cin >> x >> y >> z;
  
  //AとBchange
  a = x;
  b = y;
  x = b;
  y = a;
  
  //AとCchange
  c = x;
  d = z;
  x = d;
  z = c;
  
  cout << x <<" "<< y << " "<< z <<endl;
}



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

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int x = ni();

        long ans = 2;

        for (int i = 0; i < x; i++) {
            ans++;
            ans *= 2;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8276
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
using namespace std;

unsigned short vis[1 << 24];
char c[16][20];
bool wall[256];
int tm0;

inline bool check(int u, int v){
	for(int i = 0; i < 24; i += 8){
		int p1 = v >> i & 255;
		if(p1){
			int j = i == 16 ? 0 : i + 8;
			if(wall[p1]){ return false; }
			int p2 = (v >> j % 24) & 255;
			if(p1 == p2){ return false; }
			if(
				p1 == (u >> j % 24 & 255) &&
				p2 == (u >> i % 24 & 255)
			){
				return false;
			}
		}
	}
	return true;
}

int solve(int start, int goal){
	const int dif[5] = {0, -1, 1, -16, 16};

	queue<int> q;
	q.push(start);
	q.push(-1);
	int tm = tm0 + 1;
	vis[start] = tm;
	while(1){
		int u = q.front();
		q.pop();
		if(u < 0){
			q.push(-1);
			++tm;
		}
		else{
			for(int i1 = u & 255 ? 4 : 0; i1 >= 0; --i1)
			for(int i2 = u >> 8 & 255 ? 4 : 0; i2 >= 0; --i2)
			for(int i3 = u >> 16 ? 4 : 0; i3 >= 0; --i3){
				int v = u + dif[i1] + (dif[i2] << 8) + (dif[i3] << 16);
				if(vis[v] > tm0){ continue; }
				if(check(u, v)){
					if(v == goal){ return tm; }
					vis[v] = tm;
					q.push(v);
				}
			}
		}
	}
}

int main(){
	int w, h;
	while(scanf("%d%d%*d ", &w, &h), w){
		for(int i = 0; i < h; ++i){
			fgets(c[i], 20, stdin);
		}

		int goal = 0;
		int start = 0;
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				if(c[i][j] == '#'){
					wall[i << 4 | j] = true;
				}
				else{
					wall[i << 4 | j] = false;
					if(isupper(c[i][j])){
						goal |= (i << 4 | j) << (c[i][j] - 'A') * 8;
					}
					else if(islower(c[i][j])){
						start |= (i << 4 | j) << (c[i][j] - 'a') * 8;
					}
				}
			}
		}

		int tm = solve(start, goal);
		printf("%d\n", tm - tm0);

		tm0 = tm + 1;
		if(tm0 > 55000){
			memset(vis, 0, sizeof vis);
			tm0 = 0;
		}
	}
}

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

using namespace std;

int leftW[300000], rightE[300000];
int main()
{
	int n;
	cin >> n;
	string str;
	cin >> str;

	for (int i = 1; i < n; ++i)
		leftW[i] = leftW[i-1] + (str[i-1] == 'W');
	for (int i = 1; i < n; ++i)
		rightE[n-i-1] = rightE[n-i] + (str[n-i] == 'E');
	int ans = leftW[0]+rightE[0];
	for (int i = 1; i < n; ++i)
		if (leftW[i] + rightE[i] < ans)
			ans = leftW[i] + rightE[i];

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

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << "i" << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll h,w; cin >> h >> w;
    ll cnt = 0;
    rep(i,h){
        string s; cin >> s;
        rep(j,w){
            if(s.at(j)=='#') cnt++;
        }
    }
    if(cnt==h+w-1){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#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;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long  ll;
typedef unsigned long long  ull;
#define lp(i,n)      for(int i=0;i<n;i++)
#define lpi(i,j,n)   for(int i=j;i<n;i++)
#define lpd(i,j,n)   for(int i=j;i>=n;i--)
#define MP           make_pair
#define clr(v, d)    (memset(v, d, sizeof(v)))
#define all(v)     (v.begin()),(v.end())
#define N 200005
const double pi = acos(-1);

ll n,t,m,k;

ll ans;
ll mod = 1e9 +7;
ll dp[23][(1<<21) +9];
ll a[25][25];

ll solve(int idx, int mask){
  
  if(idx == n)return mask == ((1<<n) -1);
  ll& ret =dp[idx][mask];
  if(ret!= -1)return ret;
  ret= 0;
  lp(i,n){
    if(a[idx][i] && !(mask & (1<<i) )){
      (ret+= solve(idx+1,mask ^ (1<<i)) ) %= mod;
    }
  }
  return ret;
}




int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("e.txt","r",stdin); 
// freopen("e_out.txt","w",stdout); 
cout.precision(12);
cin>>n;
lp(i,n)lp(j,n)cin>>a[i][j];
memset(dp,-1, sizeof(dp));

cout<<solve(0,0);

  
}
  
 



// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 380416
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int i, count;
  string str;
  cin >> str;
  
  count = 0;
  for(i = 0; i < str.size()/2; i++){
    if(str[i] != str[str.size()-(i+1)]) count++;
  }
  cout << count << endl;
  
  return 0;
}

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

int N;
int L[200];

int main() {
    int total = 0;
    cin >> N;
    for (int i = 0; i < 2 * N; i++) {
        cin >> L[i];
    }
    sort(L, L + 2 * N);
    for (int i = 0; i < 2 * N; i += 2) {
        total += min(L[i], L[i + 1]);
    }
    cout << total;
}

Measured memory_bytes: 3664
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

n,m = map(int, input().split())
dinic = Dinic(n)
for _ in range(m):
    v,u,c = map(int, input().split())
    dinic.add_edge(v,u,c)

print(dinic.flow(0, n-1))


Measured memory_bytes: 6244
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll n; cin >> n;
	vector<ll> a(n); rep(i, n) cin >> a[i];

	stack<ll> s;
	queue<ll> q;

	if (n % 2 == 0) {
		for(int i =0; i <= n-1;i+=2){
			q.push(a[i]);
			s.push(a[i + 1]);
		}
	}
	else {
		for (int i = 0; i <= n - 1; i += 2) {
			if (i == n - 1) {
				s.push(a[i]);
				break;
			}
			s.push(a[i]);
			q.push(a[i + 1]);
		}
	}

	while (s.size()) {
		cout << s.top() << ' ';
		s.pop();
	} 
	while (q.size()) {
		cout << q.front() << ' ';
		q.pop();
	}
}

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

int main()
{
	int n, c, m = 0;
	cin >> n >> c;
	for (int i = 0; i < c; i++) {
		int p;
		cin >> p;
		m += p;
	}
	if (m % (n + 1) > 0)
		cout << m / (n + 1) + 1 << endl;
	else
		cout << m / (n + 1) << endl;
	return 0;
}


Measured memory_bytes: 3100
#%%
import numpy as np
#%%

N,M,C = map(int, input().split())
Bs = np.array(list(map(int, input().split())))
ans = 0

for _ in range(N):
    As = np.array(list(map(int, input().split())))
    if np.sum(As * Bs) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 21520
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (a > c) swap(a, c);
    if (b > c) swap(b, c);
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,D;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>X.at(i).at(j);
    }
  }
  int count = 0;
  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      int squareSUM = 0;
      for(int k = 0;k < D;k++){
       int a = X.at(j).at(k) - X.at(i).at(k);
         squareSUM += a * a;
      }
      for(int m = 1;m<=160;m++){
        if(squareSUM == m*m){
          count++;
          break;
        }
      }
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef unsigned long long int ll;
#define INF LLONG_MAX

int main(){

    fastio ;

    ll n;
    vector<vector<ll>> dp(405 , vector<ll>(405));
    vector<ll> a(405);
    vector<ll> prefix(405);

    cin >> n;
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
        if(i != 1) prefix[i] = prefix[i-1]+a[i];
        else prefix[i] = a[i];
    }

    // OPTIMAL SUB-PROBLEM :

    // dp[i][j] = minimum cost required to change from i...j

    // BASE CASE :

    // RECURSIVE RELATION :

    for(ll s = 1; s <= n-1; s++){
        for(ll i = 1; i <= n-s; i++){
            ll j = i+s;
            dp[i][j] = INF;

            for(ll l = i; l <= j-1; l++){
                dp[i][j] = min(dp[i][j] , dp[i][l] + dp[l+1][j] + prefix[j]-prefix[i-1]);
            }
        }
    }

    // OPTIMAL SOLUTION :

     cout << dp[1][n];

}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
string getLCS(string &s, string &t, int len)
{
    string LCS="";
    int i=0,j=0;
    while(len>0)
    {
        if(s[i]==t[j])
        {
            LCS+=s[i];
            i++,j++;
            len--;
        }
        else
        {
            if(dp[i][j+1]>dp[i+1][j])
            {
                j++;
            }
            else{
                i++;
            }
        }
    } 
    return LCS;
}
int getlen(string &s, string &t, int i, int j)
{
    if(i>=s.size() || j>=t.size())
    { 
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    if(s[i]==t[j])
    {
       return  dp[i][j] = 1 + getlen(s,t,i+1,j+1);
    }
    else
    {
        return dp[i][j] = max(getlen(s,t,i,j+1),getlen(s,t,i+1,j));
    }
}
string solve(string s, string t)
{
    memset(dp,-1,sizeof(dp));
    int len = getlen(s,t,0,0);
    return getLCS(s,t,len);

}
int main() {
    string s,t;
    cin>>s>>t;
    cout<<solve(s,t);
}


Measured memory_bytes: 39196
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

int main(){
    long long int n, k;
    cin >> n >> k;

    long long int ans = 0;
    for(long long int i=k; i<=n+1; i++){
        long long int first = (0+i-1) * i / 2;
        long long int last  = (n+(n-i+1)) * i / 2;
        ans += last - first + 1;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 13;
int n, a[maxN], arr[maxN], ans;

bool cmp (int i, int j) {
    return a[i] < a[j];
}

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

    iota(arr, arr + n, 0);
    sort(arr, arr + n, cmp);

    for (int i = 0; i < n; i++) {
	if (i % 2 != arr[i] % 2)
	    ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
  int n,i,j,add,count,itmp;
  for(;;)
    {
      count=0;
      scanf("%d",&n);
      if(n==0){break;}
      for(i=1;i<=(n/2);i++)
	{
	  /*printf("i=%d",i);*/
	  add=i;
	  itmp=i;
	  for(j=1;i<=n;j++)
	    {
	      /*printf("j=%d ",j)*/;
	      add = add+1;
	      itmp=itmp+add;
	      if(itmp==n){count=count+1;}
	      /*printf("add=%d i=%d\n",add,itmp);*/
	      if(j==n){break;}
	    }
	}
      printf("%d\n",count);
    }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

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

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

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

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,mon=1000;
    cin>>n;
    int mn=MOD,mx=0,b=false;
    rep(i,n){
        int a;
        cin>>a;
        if(a<mx){
            mon+=(mon/mn)*(mx-mn);
            mn=a;
            mx=0;
        }
        else if(mn>=a){
            mn=a;
        }
        else{
            mx=a;
        }
    }
    if(mx!=0)
        mon+=(mon/mn)*(mx-mn);
    cout<<mon<<endl;
}


Measured memory_bytes: 3652
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        int n, k;
        scanf("%d %d", &n, &k);
        V ok(n, 0);
        rep(i, 0, k){
                int d;
                scanf("%d", &d);
                rep(j, 0, d){
                        int tmp;
                        scanf("%d", &tmp);
                        ok[tmp-1]++;
                }
        }
        int ans = 0;
        rep(i, 0, n) ans += (ok[i]==0);
        printf("%d\n", ans);
        return 0;
}

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

void swap(int* a, int* b){

    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int main(){

    int x, y, z;

    scanf("%d %d %d", &x, &y, &z);

    swap(&x,&y);
    swap(&x,&z);

    printf("%d %d %d", x, y, z);

   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
int n,k;
cin >> n >> k ;

int num = 0;



    while(n  > 0) {
        n = n / k;
        num++;

    }   


cout << num << endl;

return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	cout<<fixed<<setprecision(7);
	int s ,n, ma = -1*INF, temp = -1*INF;
	int f[110][10][2], p[110][10] = {};
	
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= 5; j++){
			cin>>f[i][j][0]>>f[i][j][1];
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= 10; j++){
			cin>>p[i][j];
		}
	}
	// cout<<(1<<10)<<" "<<((1<<11)>>10)<<endl;
	for(int i = 1; i <= (1<<10)-1; i++){
		int sum = 0;
		for(int j = 1; j <= n; j++){//cout<<j<<" ";
			int count = 0;
			for(int k = 1; k <= 10; k++){
				int te = i>>(k-1);
				// cout<<(te&1);
				if((te&1)&&f[j][(k+1)/2][(k+1)%2]) count++;
			}//cout<<endl;
			sum += p[j][count];
		}
		ma = max(sum, ma);
	}

	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 256
// ????????°????????????????????????????????????????±???????O(|V|^2)?:cycledetectDirected()
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

// ????????°????????§??°
#define MAX_V 100000
// ??°????????????????????°
int V;
vector <int> graph[MAX_V];
bool vis[MAX_V];
// ?????????????????????????????????????????????
vector <int> list;
// ??\????¬???°
int indeg[MAX_V];

// ??\????¬???°???0???????????????????????????????????¢?´¢??????????????°???????¨?????????????????¬???°???1?????????????????\????????°???0???????????°???????????????????????????????§?
void topologicalsort() {
  memset(indeg, 0, sizeof(indeg));
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      int p = graph[i][j];
      indeg[p]++;
    }
  }

  // queue????????§?????????push?????????????????????????????????????????????????????????
  for (int i = 0; i < V; i++) {
    if (indeg[i] == 0 && !vis[i]) {
      queue<int> que;
      que.push(i);
      list.push_back(i);
      vis[i] = true;
      while (!que.empty()) {
	int p = que.front(); que.pop();

	for (int j = 0; j < graph[p].size(); j++) {
	  int np = graph[p][j];
	  indeg[np]--;
	  if (vis[np]) continue;
	  if (indeg[np] == 0) {
	    vis[np] = true;
	    que.push(np);
	    list.push_back(np);
	  }
	}
      }
    }
  }
}

int main() {
  int E;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
  }
  topologicalsort();

  for (int i = 0; i < list.size(); i++) {
    cout << list[i] << endl;
  }
}

Measured memory_bytes: 4468
from operator import itemgetter, attrgetter
n = int(input())
sp = [[i+1] + list(input().split()) for i in range(n)]

for s in sp:
  s[2] = int(s[2])
sp = sorted(sp, key=lambda x: (x[1], -x[2]))
for s in sp:
  print(s[0])



Measured memory_bytes: 3060
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define INF 1050000000;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        int N;
        cin >> N;
        vector<int> h(N);
        rep(i, N)
        {
                cin >> h[i];
        }

        int dp[100000 + 10];
        rep(i,100010){
                dp[i] = INF;
        }
        dp[0] = 0;
        for (int i = 0; i < N; i++)
        {
                dp[i + 1] = min(dp[i + 1], dp[i]+abs(h[i+1]-h[i]));
                dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
        }

        cout << dp[N - 1] << endl;
        return 0;
}

Measured memory_bytes: 1024
N=int(input())
a=list(map(int,input().split()))

b=[0]*N
b[0]=a[0]
for i in range(1,N):
    b[i]=b[i-1]+a[i]

x=[0]*N
y=[0]*N
z=[0]*N
for j in range(N):
    x[j]=b[j]
    y[j]=b[-1]-b[j]
    z[j]=abs(x[j]-y[j])

print(min(z[:-1]))

Measured memory_bytes: 40748
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  long n, m;
  readf("%s %s\n", &n, &m);

  auto res = n * m;
  res -= 2 * (n + m - 2);
  res.abs.writeln;
}


Measured memory_bytes: 256
//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 <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

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

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// functions and classes
using Edge = pair<ll, ll>;

ll calc_seq9(ll n, ll k) {
	if (n < k) {
		return 0LL;
	}

	ll res = 1LL;
	for (ll i = 0; i < k; ++i)
	{
		res *= 9LL;
		res *= n - i;
	}
	for (ll i = 0; i < k; ++i)
	{
		res /= i + 1LL;
	}

	return res;
}

ll calc(string n, ll k, vector<vector<ll>>& dp) {
	if (dp[n.size()][k] != -1) {
		return dp[n.size()][k];
	}
	if (k == 0) {
		return 1LL;
	}
	if (n.size() == 0) {
		return 0LL;
	}
	
	ll top_digit = (ll)(n[0] - '0');
	ll res = 0LL;
	if (top_digit >= 1) {
		res += calc_seq9(n.size() - 1, k);
		res += calc_seq9(n.size() - 1, k - 1) * (top_digit - 1);
		res += calc(n.substr(1), k - 1, dp);
	}
	else {
		res += calc(n.substr(1), k, dp);
	}

	dp[n.size()][k] = res;

	return res;
}

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

	string N;
	ll K;
	cin >> N >> K;

	vector<vector<ll>> dp(N.size() + 1);
	for (ll i = 0; i < dp.size(); ++i)
	{
		dp[i] = vector<ll>(K + 1, -1LL);
		dp[i][0] = 1LL;
	}

	ll res = 0LL;
	res = calc(N, K, dp);

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if(discrete) else 10**-8
    if((not left)^f(r)): return r if(left) else r+1
    elif(left^f(l)): return l-1 if(left) else l
    while(r-l>eps):
        h=(l+r)//2 if(discrete) else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if(not discrete) else l if(left) else r

def resolve():
    n,m,v,p=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()

    # どの i までが採用されるかを二分探索
    def check(i):
        # プラスするのは vm ポイント
        # 0 から i までは +m する
        # n-p+1 から n-1 までは +m する
        rest=(v-(i+1)-(p-1))*m
        s=A[i]+m
        for j in range(i+1,n-p+1):
            if(s<A[j]): return False
            rest-=s-A[j]

        return rest<=0

    print(n-bisection(0,n-1,check,left=False))
resolve()

Measured memory_bytes: 62800
#include <stdio.h>
#include <math.h>
int max(int a, int b) {
    if (a>b)
        return a;
    else
        return b;
}
int main(void){
  int a,b,c,k;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  printf("%d",a+b+c+max(a,(max(b,c))*pow(2,k))-max(a,(max(b,c))));
  return 0;                    
}


Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N,K = readline() |> split |> parseArray

  b=binomial(N-1,2)
  if K>b
    println(-1)
    return
  end

  M=N-1+(b-K)
  println(M)

  for i in 2:N
    println("1 $i")
  end
  # for i in 2:min(M-N+2,N)
  #   println("$i $(i%N+1)")
  # end
  # for i in 2:min(M-2N+3,N)
  #   println("$i $((i+1)%N+1)")
  # end

  for j in 1:M÷(N-1)+1
    for i in 2:min(M-j*(N-1)+1,N)
      # println("$i $((i+j-1)%N+1)")
      println("$i $(i+j+(i+j>N?-N+1:0))")
    end
  end
end

main()


Measured memory_bytes: 113052
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int A = 0, Z = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      A = i;
      break;
    }
  }
  for (int i = s.size() - 1; i > A - 1; i--) {
    if (s.at(i) == 'Z') {
      Z = i;
      break;
    }
  }
  cout << Z - A + 1 << endl;
}

Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetString();

            if (N.EndsWith("2")
                || N.EndsWith("4")
                || N.EndsWith("5")
                || N.EndsWith("7")
                || N.EndsWith("9"))
            {
                Console.WriteLine("hon");
                return;
            }

            if (N.EndsWith("0")
                || N.EndsWith("1")
                || N.EndsWith("6")
                || N.EndsWith("8"))
            {
                Console.WriteLine("pon");
                return;
            }

            if (N.EndsWith("3"))
            {
                Console.WriteLine("bon");
                return;
            }
        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 26204
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll a,b,k;
  cin >> a >> b >> k;
  if(a<=k){
    k-= a;
    a = 0;
    cout << 0<<" "<<max(0ll,b-k);
    cout << endl;
  }else{
    cout << a-k<<" "<<b<<endl;
  }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  int32 mx = 0,s = 0;
  REP(i,n){
    int32 l;
    cin >> l;
    mx = max(mx,l);
    s += l;
  }
  Yes(2*mx < s);
  return 0;
}

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

int main(){
	/*input*/
	char s[4];	cin >> s;
	/*calculation*/
	bool state = true;	//true:Good false:Bad
	for(int i = 0; i < 3; i++){
		if(s[i] == s[i+1]){
			state = false;
			break;
		}
	}
	/*output*/
	if(state){
		cout << "Good" << endl;
	}else{
		cout << "Bad" << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <iostream>

using namespace std;

int main(void) {
	int a, b;
	char s[10];
	cin >> a;
	cin >> b;
	cin >> s;
	if (s[a] != '-') {
		cout << "No" << endl;
		return 0;
	}
	for (int i=0;i<strlen(s);i++) {
		if (i == a) continue;
		if (s[i] == '-') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

const int N = 20 + 3;

int n, d;
bool vis[N];

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

  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(!vis[i]) {
      ++ans;
      for(int j = i; j <= min(n, i + 2 * d); ++j) {
        vis[j] = true;
      }
    }
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
can = True
t,x,y = 0,0,0

for i in range(n):
    t_,x_,y_ = map(int,input().split())
    dt = t_ - t
    dist = abs(x-x_) + abs(y-y_)
    if dt < dist:
        can = False
    else:
        if (dist-dt) % 2 != 0:
            can = False
    t,x,y = t_,x_,y_

print("Yes" if can else "No")

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

typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
	int a, b;
	cin >> a >> b;
	cout << (b % a == 0 ? a + b : b - a) << endl;
}


Measured memory_bytes: 256