akhauriyash/Code-Regression huggingface dataset:
#include <iostream>


using namespace std;

int main(){
        int n, ans=0;
        int p[21];
        cin>>n;
        for(int i=0; i<n; i++) cin>>p[i];

        for(int i=1; i<n-1; i++){
                if((p[i-1]<p[i])&&(p[i]<p[i+1])) ans++;
                else if((p[i-1]>p[i])&&(p[i]>p[i+1])) ans++;
        }

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

Measured memory_bytes: 256
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
#define Mod (int)(1e9+7)
struct Matrix{
	#define MAXC 4
	int r,c;
	LL m[MAXC+5][MAXC+5];
	void Init(int R,int C){
		r=R,c=C;
		for(int i=0;i<r;i++)
			for(int j=0;j<c;j++)
				m[i][j]=0;
		return ;
	}
	friend Matrix operator * (Matrix A,Matrix B){
		Matrix C;C.Init(A.r,B.c);
		for(int i=0;i<A.r;i++)
			for(int j=0;j<B.c;j++)
				for(int k=0;k<A.c;k++)
					C.m[i][j]=(C.m[i][j]+A.m[i][k]*B.m[k][j])%Mod;
		return C;
	}
	void Print(){
		puts("");
		for(int i=0;i<r;i++,puts(""))
			for(int j=0;j<c;j++)
				printf("%lld ",m[i][j]);
		puts("");
		return ;
	}
};
Matrix Pow(Matrix x,int y){
	Matrix ret;ret.Init(x.r,x.c);
	for(int i=0;i<ret.r;i++)
		ret.m[i][i]=1;
	while(y){
		if(y&1) ret=ret*x;
		x=x*x,y>>=1;
	}
	return ret;
}
Matrix A,B,C;
void Init(){
	A.Init(1,3),A.m[0][0]=1,A.m[0][1]=2,A.m[0][2]=1;
	B.Init(3,3);
	B.m[0][0]=1,B.m[0][1]=2,B.m[0][2]=1,
	B.m[1][0]=0,B.m[1][1]=1,B.m[1][2]=1,
	B.m[2][0]=1,B.m[2][1]=2,B.m[2][2]=2;
	C.Init(3,3);
	C.m[0][0]=1,C.m[0][1]=2,C.m[0][2]=1,
	C.m[1][0]=0,C.m[1][1]=1,C.m[1][2]=1,
	C.m[2][0]=0,C.m[2][1]=0,C.m[2][2]=1;
	return ;
}
int main(){
	int n=read(),m=read();
	Init();
	int lst=1;
	for(int i=1;i<=m;i++){
		int x=read();
		A=A*Pow(B,x-lst);
		A=A*C;
		lst=x+1;
	}
	A=A*Pow(B,n-lst);
	printf("%lld\n",A.m[0][2]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   int count=0;
   for(int i=0;i<n;i++)
   {
       if((i+1)%2==1&&arr[i]%2==1)
       {
           count++;
       }
   }
   cout<<count;
}



Measured memory_bytes: 3628
import java.util.*;
import java.io.*;

public class Main {	
	static int[][] map;
	static int N;
	static int M;
	static int Q;
	private static void solve(){
		//Implement solution here.
		N = ni();
		M = ni();
		Q = ni();
		map = new int[Q][4];
		for(int i = 0; i < Q; i++) map[i] = na(4);		
		int result = rec(new int[M + 1], 1, N);
		System.out.println(result);
	}
	
	private static int rec(int[] A, int idx, int last) {
		int result = 0;
		int[] NA = A.clone();
		

		for(int i = 0; i <= last; i ++) {			
			NA[idx] = i;
//			if(idx == 1) {
//				Arrays.stream(NA).forEach(v -> System.out.print(v + " "));
//				System.out.println();
//				System.out.println(last);
//			}
			
			if(last - i > 0) {
				if(idx < M) {
					result = Math.max(result, rec(NA, idx + 1, last - i));
				}				
			} else {
				result = Math.max(result, getScore(NA));
			}
		}
		return result;
	}
	
	private static int getScore(int[] A) {
//		Arrays.stream(A).forEach(v -> System.out.print(v + " "));
//		System.out.println();
		
		int score = 0;
		for(int j = 0; j < Q; j++) {
//			System.out.print(A[map[j][1]] + ":");
			if(getA(A,map[j][1]) - getA(A,map[j][0]) == map[j][2])score += map[j][3];
		}
//		System.out.println(score);
		return score;
	}
	
	private static int getA(int[] A, int cnt) {
		int result = 0;
		for(int i = 1; i < A.length; i++) {
			if(A[i] >= cnt) {
				result = i;
				break;
			} else {
				cnt -= A[i];
			}
		}
		return result;
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 33520
#include<bits/stdc++.h>
using namespace std;
#define int long long















using namespace std;
vector<vector<int>>rows,cols;
void gen(int n, vector<int>cur, int lim, bool r){
	if(n == lim){
		if(r) rows.push_back(cur);
		else               cols.push_back(cur);
	}
	else {
					auto copy = cur;
		copy.push_back(n);
		gen(n+1,cur,lim,r);
					gen(n+1,copy,lim,r);
	}



	
}

int32_t main(){
	int n,  m , k;
	cin >> n >> m >> k;

	gen(0,vector<int>(),n,1);   gen(0,vector<int>(),m,0);
	vector<string>grid(n);
	for(int i = 0 ;   i < n ;   i++){
		cin >> grid[i];
	}


	int res = 0;
	for(auto dum : rows){
		for(auto dee : cols){
			auto copy = grid;
			for(int i : dum){
				for(int r = 0 ; r < m ; r++)
										copy[i][r] = 'r';
			}
			for(int j : dee){
				for(int c = 0 ; c < n ; c++)
					               copy[c][j] = 'r';
			}
			int whoel = 0;
			for(string s : copy){
				whoel += count(s.begin(), s.end(), '#');
			}
			if(whoel == k)
			{res++;




			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+5,base=2002;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int fac[8005],inv[8005],n;
inline int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ans;
}
int C(int n,int m){
	return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int a[maxn],b[maxn],f[4005][4005];
int main(){
	fac[0]=inv[0]=1;
	for(int i=1;i<=8000;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[8000]=ksm(fac[8000],mod-2);
	for(int i=7999;i>=1;i--)inv[i]=1ll*(i+1)*inv[i+1]%mod;
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();
		f[base-a[i]][base-b[i]]++;
	}
	for(int i=1;i<=4002;i++){
		for(int j=1;j<=4002;j++)
		f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+f[a[i]+base][b[i]+base])%mod;
		ans=(ans-C(2*a[i]+2*b[i],2*a[i]))%mod;
	}
	ans=(ans+mod)%mod;
	ans=1ll*ans*ksm(2,mod-2)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 64512
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

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

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

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

    vector<vector<pii> > g(n+1);
    vector<int> max_cost(n+1,-LINF);

    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(b,c);
    }

    max_cost[1] = 0;

    rep(i,n * 2){
        reps(j,n){
            rep(k,g[j].size()){
                int now = j;
                if(max_cost[now] == -LINF) continue;
                int next = g[j][k].first;
                int cost = g[j][k].second;
                if(chmax(max_cost[next],max_cost[now] + cost)){
                    if(i == n*2-1 && next == n) return cout << "inf\n",0;
                }
            }
        }
    }

    cout << max_cost[n] << '\n';

    return 0;
}


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

int main() {
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2);
    int k;
    cin >> k;
    sort(a.begin(), a.end(), greater<int>());
    rep(i, k) a.at(0) = 2 * a.at(0);
    int sum = 0;
    rep(i, 3) sum += a.at(i);
    cout << sum << endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 1111111111;
  for (int i = 0; i < s.size() - 2; i++) {
    int tmp = stoi(s.substr(i, 3));
    // cout << tmp << endl;
    ans = min(ans, abs(753 - tmp));
  }
  cout << ans << endl;
  return 0;
}

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

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 endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	map<int,int> mp;
	int a, b, n, m;
	vector<int> c, d;
	
	cin>>n>>m;
	
	
	for(int i = 0; i < n; i++){
		cin>>a;
		mp[a]++;
	}
	for(int i = 0; i < m; i++){
		cin>>a;
		mp[a]++;
	}
	
	for(pair<int,int> t : mp){
		if(t.second == 2) d.push_back(t.first);
		c.push_back(t.first);
	}
	
	cout<<d.size()<<" "<<c.size()<<endl;
	
	for(int i = 0; i < d.size(); i++){
		cout<<d[i]<<endl;
	}
	for(int i = 0; i < c.size(); i++){
		cout<<c[i]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 18720
#include <stdio.h>
int main(void)
{
  int r,d,x,i;
  
  scanf("%d%d%d", &r, &d, &x);
  
  for (i=1; i<=10; i++) {
    x = r*x -d;
    printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int fa[200001],s[200001];
int find(int x)
{
	if(x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
	int n,m,x,y;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		int fx=find(x),fy=find(y);
		if(fx!=fy)
		{
			fa[fx]=fy;
		}
	}	
	for(int i=1;i<=n;i++)
	{
		s[find(i)]++;
	}
	int maxn=-1;
	for(int i=1;i<=n;i++)
		maxn=max(s[i],maxn);
	cout<<maxn<<endl;	
	return 0;		
}

Measured memory_bytes: 10512
/*
 * @Author: BilyHurington
 * @Date: 2020-03-22 20:10:41
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-22 20:14:25
 */
#include<bits/stdc++.h>
using namespace std;
int n;
char s[110];
bool check(char *s,int l,int r){
    for(int i=l;i<=r;i++){
        if(s[i]!=s[l+r-i]) return 0;
    }
    return 1;
}
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    if(check(s,1,n)&&check(s,1,(n-1)/2)&&check(s,(n+3)/2,n)) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
def main():
    #Union Find
    #locate x 
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    #merge x y
    def unite(x,y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    #x and y in same group
    def same(x,y):
        return find(x) == find(y)
    
    #number of factor of x group
    def size(x):
        return -par[find(x)]

    n,m = map(int,input().split())
    #initiarize
    #根なら-size,子なら親の頂点
    par = [-1]*n

    for i in range(m):
        X,Y,Z = map(int,input().split())
        unite(X-1,Y-1)
    
    tank = set([])
    for i in range(n):
        tank.add(find(i))
    print(len(tank))

if __name__ == '__main__':
    main()

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

typedef long long LL;
using namespace std;

const int MX=100005;
int n,Q;
LL a[MX],dt[MX],t[MX],x,cur,c;

int main(){
	cin>>n>>Q,a[++c]=n;
	for(int i=1;i<=Q;i++){cin>>x;while(c&&x<=a[c])--c;a[++c]=x;}
	t[c]=1;
	for(int i=c;i;i--){
		LL tmp=a[i],it=upper_bound(a,a+i,tmp)-a-1;
		for(;it;it=upper_bound(a,a+it,tmp)-a-1)t[it]+=(tmp/a[it])*t[i],tmp%=a[it];
		dt[1]+=t[i],dt[tmp+1]-=t[i];
	}
	for(int i=1;i<=n;i++)cout<<(cur+=dt[i])<<endl;
	return 0;
}


Measured memory_bytes: 4096
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def ans(self):
        return (len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)
l=[[] for i in range(m)]
for i in range(n):
    k=list(map(int,input().split()))
    k=k[1:]
    for j in k:
        l[j-1].append(1+i)
    
for i in range(m):
    if len(l[i])>0:
        ll=l[i][0]
        for j in range(len(l[i])-1):
            uf.union(ll,l[i][j+1])

for i in range(1,n+1):
    uf.find(i)

if uf.ans()==1:
    print('YES')
else:
    print('NO')


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

bool isPrime(int num) {
  if (num < 2)      { return false; }
  if (num == 2)     { return true; }
  if (num % 2 == 0) { return false; }

  double sqrtNum = sqrt(num);
  for ( int i = 3; i <= sqrtNum; i += 2 ) {
    if ( num % i == 0 ) { return false; }
  }

  return true;
}

int main() {
  int x;
  cin >> x;
  while ( !isPrime(x) ) { x++; }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int K, S;

signed main()
{
    cin >> K >> S;

    int ans = 0;
    for (int X=0; X<=K; X++) {
        for (int Y=0; Y<=K; Y++) {
            int Z = S - X - Y;
            if (Z < 0 || K < Z) continue;
            ans++;
        }
    }

    cout << ans << endl;
}


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

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        LevenshteinDistance solver = new LevenshteinDistance();
        solver.solve(1, in, out);
        out.close();
    }

    static class LevenshteinDistance {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final String x = in.next();
            final String y = in.next();

            out.printf("%d\n", levenshtein(x, y));
        }

        private int levenshtein(final String a, final String b) {
            final int alen = a.length();
            final int blen = b.length();

            int[][] dp = new int[alen + 1][blen + 1];
            for (int i = 0; i < alen + 1; i++) {
                dp[i][0] = i;
            }

            for (int j = 0; j < blen + 1; j++) {
                dp[0][j] = j;
            }

            for (int i = 1; i < alen + 1; i++) {
                for (int j = 1; j < blen + 1; j++) {
                    int insertion = dp[i][j - 1] + 1;
                    int deletion = dp[i - 1][j] + 1;
                    int match = dp[i - 1][j - 1];
                    int mismatch = dp[i - 1][j - 1] + 1;

                    if (a.charAt(i - 1) == b.charAt(j - 1)) {
                        dp[i][j] = Math.min(Math.min(insertion, deletion), match);
                    } else {
                        dp[i][j] = Math.min(Math.min(insertion, deletion), mismatch);
                    }
                }
            }

            return dp[alen][blen];
        }

    }
}




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

long long x[1000000];
int v[1000000];
long long c[1000000],cc[1000000];
long long cmx[1000000],ccmx[1000000];

int main()
{
	int n;
	long long C;
	scanf("%d%lld",&n,&C);
	for(int i=1;i<=n;i++) 
		scanf("%lld %d",&x[i],&v[i]);
	for(int i=1;i<=n;i++)
	{
		c[i]=c[i-1]+v[i]-(x[i]-x[i-1]);
		cmx[i]=max(cmx[i-1],c[i]);
	}
	x[n+1]=C;
	for(int i=n;i>=1;i--)
	{
		cc[n-i+1]=cc[n-i]+v[i]-(x[i+1]-x[i]);
		ccmx[n-i+1]=max(ccmx[n-i],cc[n-i+1]);
	}
	long long ans=0;
	for(int i=0;i<=n;i++)
	{
		ans=max(ans,c[i]-x[i]+ccmx[n-i]);
		ans=max(ans,cc[i]-(C-x[n-i+1])+cmx[n-i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
int32_t main(){
  fast;
  /* 
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
	*/
  int T=1; //cin>>T; 
  while(T--){

  	int n ; cin>>n; 
  	vi a(n); 

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

  	vector< vi > dp(n,vi(n,0));

  	for(int L=n-1;L>=0;L--){
  		for(int R=L;R<n;R++){
  			if(R==L){
  				dp[L][R]=a[L];
  			}
  			else{
  				dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]); 
  			}	

  		}
  	} 

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




  






  }
    


  return 0; 
} 


Measured memory_bytes: 70784
s,t=input(),input()
a,b=len(s),len(t)
DP=[[0]*(b+1) for _ in range(a+1)]
for i in range(a):
    for j in range(b):
        if s[i]==t[j]:
            DP[i+1][j+1]=DP[i][j]+1
        else:
            DP[i+1][j+1]=max(DP[i+1][j],DP[i][j+1])
ans=''
while a and b:
    if DP[a][b]==DP[a-1][b]:
        a-=1
    elif DP[a][b]==DP[a][b-1]:
        b-=1
    else:
        ans=s[a-1]+ans
        a-=1
        b-=1
print(ans)

Measured memory_bytes: 112860
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let x: i32 = sc.read();
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let pass = b - a;
    if pass > x {
        println!("dangerous");
    } else if pass <= 0 {
        println!("delicious");
    } else {
        println!("safe");
    }
}

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

int n, cnt[200003];

int main(){
	memset(cnt,0,sizeof cnt);
	cin >> n;
	for (int i=1;i<n;i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	for (int i=1;i<=n;i++) cout << cnt[i] << "\n";
}

Measured memory_bytes: 4416
# -*- coding: utf-8 -*-]

import sys

w = []
tmp = 1
for i in range(10):
    w.append(tmp)
    tmp *= 2

for line in sys.stdin:
    weight = int(line)
    parts = []
    for i in range(9, -1, -1):
        if weight == 0:
            break
        if weight >= w[i]:
            weight -= w[i]
            parts.append(w[i])
    parts.reverse()
    print " ".join(map(str, parts))

Measured memory_bytes: 6456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
  IOS();
  ll n;
  cin >> n;
  ll mx = 0;
  REP (i,n) cin >> d[i], mx = max(mx,d[i]);
  ll ans = 0;
  REP1 (T,mx) {
    ll cnt = 0;
    REP (i,n) {
      if (d[i] >= T && d[i+1] < T) cnt++;
    }
    ans += cnt;
    debug(ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func abs(v int) int {
	if v > 0 {
		return v
	}
	return -v
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if abs(a-c) <= d {
		fmt.Println("Yes")
	} else if abs(a-b) <= d && abs(c-b) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main()
{
    int n;
    cin >> n;
    int a[200004];
    int ans[200004] {0};
    int num = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = n; i > 0; i--){
        int b = i * 2;
        int w = 0;
        while(b <= n){
            w = (w + ans[b]) % 2;
            b += i;
        }
        if(w != a[i]){
            ans[i] = 1;
            num++;
        }
    }
    cout << num << endl;
    for(int i = 1; i <= n; i++){
        if(ans[i]) cout << i << endl;
    }
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>

#define PERMIT 1
#define DENY 2

using namespace std;

struct rule{
	int type;
	string srcPat;
	string destPat;
};

struct packet{
	string src;
	string dest;
	string msg;
};

bool MatchAddress(const string &pat, const string &match){
	unsigned int len = match.length();
	for(unsigned int i = 0; i < len; ++i){
		if( pat[i] != '?' && pat[i] != match[i] )
			return false;
	}
	return true;
}

int main(){
	while(true){
		int n,m;
		vector< rule > vrule;
		vector< packet > vlegpket;
		cin>>n>>m;
		if(n==0&&m==0)
			break;

		for(int i = 0; i < n; ++i){
			rule r;
			string type;
			
			cin>>type>>r.srcPat>>r.destPat;
			if(type.compare("permit")==0){
				r.type=PERMIT;
			}else{
				r.type=DENY;
			}
			vrule.push_back( r );
		}

		for(int i = 0; i < m; ++i){
			packet p;
			bool bIllegal=true;
			cin>>p.src>>p.dest>>p.msg;
			for(int j = vrule.size()-1; j >= 0; --j){
				bool bMatch=false;
				
				if( MatchAddress( vrule[j].srcPat, p.src ) && MatchAddress( vrule[j].destPat, p.dest ) )
					bMatch=true;

				if( bMatch ){
					if( vrule[j].type == PERMIT ){
						bIllegal = false;
					}
					break;
				}
			}
			if( !bIllegal ){
				vlegpket.push_back( p );
			}
		}

		cout << vlegpket.size() << endl;
		for(unsigned int i = 0; i < vlegpket.size(); ++i){
			cout << vlegpket[i].src << ' ' << vlegpket[i].dest << ' ' << vlegpket[i].msg << endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main(){
int H,W,K; cin>> H >> W >> K; K--;
  
  vector<vector<ll>> dp( H + 1, vector<ll> ( W , 0));
  
  dp[0][0] = 1;
  
  for(int i = 0; i < H ; i++){
    for(int j = 0; j < W; j++){
      // dp[i][j]からの配る遷移を考える
      //bit全探索
      for(int bit = 0; bit < 1 << ( W - 1); bit++){
        bool flag = true;
        for(int k = 0; k < W - 2; k++){ 
            if( (bit & ( 1 << k))  && ( bit & ( 1 << k + 1))){
              flag = false; }}
               
        if( !flag){ continue;} //最も内側はbit-ループ
               
            int res = j; 
          if(( bit & 1 << j ) && j < W - 1){ res = j+1;}
          else if(( bit &  1 << ( j - 1) )  && j > 0){ res = j - 1;}
               
               dp[i+1][res] += dp[i][j]; dp[i+1][res] %= MOD;}
               }
               }
               
               cout << dp[H][K] << endl; return 0;}
               
              

Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x,y,a,b,c=gsmi
pp=desc gsmi
q=desc gsmi
r=desc gsmi

px=pp[0,x]
qy=q[0,y]
sum=sum(px)+sum(qy)
while true
  break if r.size==0
  break if px.size==0&&qy.size==0

  if px.size==0
    if qy[-1]<r[0]
      sum=sum+r.shift-qy.pop
    else
      break
    end
  elsif qy.size==0
    if px[-1]<r[0]
      sum=sum+r.shift-px.pop
    else
      break
    end
  elsif px[-1] <= qy[-1]
    if px[-1]<r[0]
      sum=sum+r.shift-px.pop
    else
      break
    end
  else
    if qy[-1]<r[0]
      sum=sum+r.shift-qy.pop
    else
      break
    end
  end
end

puts sum


Measured memory_bytes: 26400
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

typedef pair<long,long> P;
long  d[55][55];

int main(int argc, char* argv[])
{
    long x,a,b;
    scanf("%ld%ld%ld", &x, &a, &b);

    printf("%ld\n", (x-a)%b);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

#define rep(X,Y) for(int (X)=0;(X)<(Y);++(X))
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define pb push_back

using namespace std;

struct edge {int to, cost, pp;};

typedef pair<int, int> P;
typedef pair<int, P> PIP;

#define MAX_V 101
#define MAX_L 101
#define INF 1000000000

vector<edge> G[MAX_V];
int d[MAX_L][MAX_V];

int l,n,m;


void dij(){
	priority_queue<PIP, vector<PIP>, greater<PIP> > q;
	
	d[l][1] = 0;
	q.push(PIP(0,P(l,1)));
	while(!q.empty()){
		PIP p = q.top();q.pop();
		int ll = p.second.first;
		int v = p.second.second;
		if(ll < 0)continue;
		if(d[ll][v] < p.first)continue;
		rep(i,G[v].size()){
			edge e = G[v][i];
			if(d[ll][e.to] > d[ll][v] + e.pp ){
				d[ll][e.to] = d[ll][v] + e.pp;
				q.push(PIP(d[ll][e.to],P(ll,e.to)));
			}
			if( ll-e.cost < 0)continue;
			if(d[ll-e.cost][e.to] > d[ll][v]){
				d[ll-e.cost][e.to] = d[ll][v];
				q.push(PIP(d[ll-e.cost][e.to],P(ll-e.cost,e.to)));
			}
		}
	}
}

void init(){
	l = n = m = 0;
	rep(i,101)G[i].clear();
	rep(i,101)rep(j,101)d[i][j] = INF;
}

	


int main(){
	while(1){
		int ans = INF;
		init();
		cin >> n >> m >> l;
		if(!n)break;
		rep(i,m){
			int a,b,d,e;
			cin >> a >> b >> d >> e;
			G[a].push_back((edge){b,d,e});
			G[b].push_back((edge){a,d,e});
		}
		dij();
		rep(i,l+1){
			ans = min(ans, d[i][n]);
		}
		cout << ans << endl;

	}
}

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

int main(){
string s;
  cin >> s;
  cout << 2018;
  rep(i, 6){
  cout << s[i+4];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string n;
    cin>>n;
    ll l=stoll(n,nullptr,10);
    if(l==10 || l==100 || l==1000 || l==10000 || l==100000){
        cout<<10<<endl;
        return 0;
    }else{
        ll sum=0;
        rep(i,n.size()) sum+=(ll)(n[i]-'0');
        cout<<sum<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll num_divisible(ll A, ll B, ll x) {
  ll num = B / x - A / x;
  if (A % x == 0) num++;
  return num;
}

int main() {
  ll A, B, C, D, lcm_CD, ans;
  cin >> A >> B >> C >> D;
  lcm_CD = C * D / gcd(C, D);
  ans = B - A + 1 - num_divisible(A, B, C) - num_divisible(A, B, D) + num_divisible(A, B, lcm_CD);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    int r, d, c;
    cin >> r >> d >> c;
    int x[11];
    x[0] = c;
    int i = 0;
    while(i <= 10){
        i++;
        x[i] = r*x[i-1]-d;
    }
    for(int i =1 ; i <= 10; i++){
        cout << x[i] << endl;
    }
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

long calc (long n, long N) {
    return (n + N / n * n) * (N / n) / 2;
}

int main() {
    long N;
    cin >> N;
    cout << calc (1L, N) - calc (3L, N) - calc (5L, N) + calc (15L, N) << endl;
    return 0;
}


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

int main(){
    int64_t A, B, C, D, Ans, L, a, b;
    int64_t X, Y, Z;
    cin >> A >> B >> C >> D;
    long long x = C * D;
    a = max(C,D);
    b = min(C,D);
    long long r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    L = x/b;

    if(A % C == 0) X = (B / C) - (A / C) + 1;
    else X = (B / C) - (A / C);
    if(A % D == 0) Y = (B / D) - (A / D) + 1;
    else Y = (B / D) - (A / D);
    if(A % L == 0) Z = B / L - A/ L + 1;
    else  Z = (B / L) - (A/L);

    Ans = B - A + 1 - X - Y + Z;
    cout << Ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();

        int m = sc.nextInt();

        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    ll x;
    cin >>  x;
    int ans = 0;
    ll m = 100;
    while(m < x){
        m *= 1.01;
        ans++;
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
int input[3];
int yakusuu = 0;
int i;

for(i = 0; i < 3; i++) {
scanf("%d", &input[i]);
}

for (i = input[0]; i <= input[1]; i++) {
if (input[2] % i == 0) yakusuu ++;
}

printf("%d\n", yakusuu);

return 0;
}


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

#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"


int MaximumProfit(vector<int>& w, vector<int>& p, int idx, int n, int remcap) {
	if (idx >= n)
		return 0;
	if (w[idx] > remcap) {
		return MaximumProfit(w, p, idx + 1, n, remcap);  // this was important....
	}
	return max(p[idx] + MaximumProfit(w, p, idx + 1, n, remcap - w[idx]), MaximumProfit(w, p, idx + 1, n, remcap));
}

int MemoisedDP(vector<int>& w, vector<int>& p, int idx, int n, int remcap, vector<vector<int> >&dp) {
	if (idx >= n)
		return 0;
	if (dp[idx][remcap] != -1) {
		return dp[idx][remcap];
	}
	if (w[idx] > remcap) {
		return dp[idx][remcap] = MemoisedDP(w, p, idx + 1, n, remcap, dp); // this was important....
	}
	return dp[idx][remcap] = max(p[idx] + MemoisedDP(w, p, idx + 1, n, remcap - w[idx], dp), MemoisedDP(w, p, idx + 1, n, remcap, dp));
}



int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> weight(n);
	vector<int> prices(n);
	for (int i = 0; i < n; i++) {
		cin >> weight[i] >> prices[i];
	}
	int cap = k;
	vector<vector<int> > knapsack(n, vector<int>(cap + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= cap; j++)
			knapsack[i][j] = -1;
	}

	// cout << MaximumProfit(weight, prices, 0, n, k) << endl;
	cout << MemoisedDP(weight, prices, 0, n, k, knapsack) << endl;

}












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

typedef long long int ll;

typedef vector<vector<ll>> mat;

const ll mod = 1e9+7;

mat base;

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

mat mul(mat a, mat b)
{
  int n = a.size();
  int nn = b.size();
  int m = b.front().size();
  mat res(n, vector<ll>(m, 0));
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)
      for(int k=0;k<nn;++k)
        add(res[i][j], a[i][k] * b[k][j] % mod);
  return res;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;
  ll k;
  cin >> n >> k;
  base = mat(n, vector<ll> (n));
  mat iden = mat(n, vector<ll> (n, 0));
  for(int i=0;i<n;++i)
    iden[i][i] = 1;
  for(auto& i: base)
    for(auto& j: i)
      cin >> j;
      
  mat a = iden;
  mat cur = base;
  for(;k;k>>=1)
  {
    if(k&1ll)
      a = mul(a, cur);
    cur = mul(cur, cur);
  }
  
  ll ans = 0;
  for(auto i: a)
    for(auto j: i)
      add(ans, j);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        List<Integer> list=new ArrayList<>();
        List<Integer> hana=new ArrayList<>();
        int count=0;
        
        for(int i=0;i<a;i++){
            int h=sc.nextInt();
            list.add(h);
            hana.add(0);
        }
        
        for(int i=0;i<a;i++){
                for(int t=0;t<list.get(i);t++){
                    if(hana.get(i)<list.get(i)){
                        hana.set(i, hana.get(i)+1);
                        if(i+1==list.size()){

                        }else{
                            if(hana.get(i+1)<list.get(i+1)){
                                for(int x=i+1;x<a;x++){
                                    if(hana.get(x)<list.get(x)){
                                        hana.set(x,hana.get(x)+1);
                                    }else{
                                        break;
                                    }
                                }
                            }
                        }
                        count+=1;
                    }else{
                        break;
                    }
                }
        }
        System.out.println(count);
        
        
    }
}


Measured memory_bytes: 21844
a,b,c,d=map(int,input().split())

import fractions

def cnt_div(n,c,d):
    #n以下の整数で，cでもdでも割り切れない数の個数
    tmp1 = n // c
    tmp2 = n // d
    tmp3 = n // (c*d//fractions.gcd(c,d)) #最大公約数
    return n-(tmp1+tmp2-tmp3)

print(cnt_div(b,c,d)-cnt_div(a-1,c,d))

Measured memory_bytes: 66540
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,x;
    cin>>k>>x;
    int l=x-k+1,r=x+k-1;
    for(int i=l;i<=r;i++) cout<<i<<(i==r?'\n':' ');
    return 0;
}


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

using namespace std;

int main() {
	char input;

	cin >> input;

	if (isupper(input)) {
		cout << 'A' << endl;
	}
	else cout << 'a' << endl;

	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
int simulate(vector<pii>cal,int index){
    cal.erase(cal.begin()+index);
    while(true){
        bool flag=false;
        rep(i,cal.size()){
            if(i==0)continue;
            if(cal[i-1].first==cal[i].first&&cal[i-1].second+cal[i].second>=4){
                rep(j,2)cal.erase(cal.begin()+i-1);
                flag=true;
                break;
            }
        }
        if(!flag)break;
    }
    int temp=0;
    rep(i,cal.size())temp+=cal[i].second;
    return temp;
}
signed main(){
    int n;
    while(cin>>n,n){
        vector<int>v(n);
        rep(i,n)cin>>v[i];
        vector<pii>cal;
        pii cnt=mp(0,0);
        rep(i,v.size()){
            if(!i)cnt=pii(v[i],1);
            else{
                if(cnt.first==v[i])cnt=mp(cnt.first,cnt.second+1);
                else{
                    cal.push_back(cnt);
                    cnt=mp(v[i],1);
                }
            }
        }
        cal.push_back(cnt);
        vector<int>cnd;
        int ans=INF;
        if(v.size()==0)return (cout<<n<<endl),0;
        rep(i,cal.size())cmin(ans,simulate(cal,i));
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3124
N,M=[int(i) for i in input().split(" ")]
cake1=[]
cake2=[]
cake3=[]
cake4=[]
cake5=[]
cake6=[]
cake7=[]
cake8=[]
for i in range(N):
    x,y,z=[int(j) for j in input().split(" ")]
    cake1.append(x+y+z)
    cake2.append(-x+y+z)
    cake3.append(x-y+z)
    cake4.append(x+y-z)
    cake5.append(-x-y+z)
    cake6.append(-x+y-z)
    cake7.append(x-y-z)
    cake8.append(-x-y-z)

cake1=sorted(cake1)[::-1]
cake2=sorted(cake2)[::-1]
cake3=sorted(cake3)[::-1]
cake4=sorted(cake4)[::-1]
cake5=sorted(cake5)[::-1]
cake6=sorted(cake6)[::-1]
cake7=sorted(cake7)[::-1]
cake8=sorted(cake8)[::-1]
print(max(sum(cake1[:M:]),sum(cake2[:M:]),sum(cake3[:M:]),sum(cake4[:M:]),sum(cake5[:M:]),sum(cake6[:M:]),sum(cake7[:M:]),sum(cake8[:M:])))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    ll n,m;
    while(cin>>n>>m){
        vl a(m);
        forn(i,m) cin>>a[i];
        ll tot = accumulate(all(a),0ll);
        ll d = n - tot;
        if(d<0){
            cout<<-1<<endl;
        }else{
            cout<<d<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3676