akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    class Program
    {
        static void Main()
        {
            new Solution().process();
        }
    }

    class Solution
    {
        string n;
        string[] input;
        
        public Solution()
        {
            n = Console.ReadLine();
            input = Console.ReadLine().Split(' ');
        }       
        public void process()
        {
            int i,m;
            int c = input.Length;  ///input陣列長度

            int h;  ///判斷奇數偶數

            if (c % 2 == 1)
            {
                h = 1; 
            }
            else
            {
                h = 0;
            }

            List<string> myCollection = new List<string>();

            if (h == 1)
            {
                for (i = c - 1; i > 0; i= i-2)
                {
                    myCollection.Add(input[i]);
                }
                myCollection.Add(input[0]);

                for (i = 1; i < c-1; i = i + 2) 
                {
                    myCollection.Add(input[i]);
                }
            }
            else 
            {
                for (i = c - 1; i > 0; i = i - 2)
                {
                    myCollection.Add(input[i]);
                }
                myCollection.Add(input[0]);

                
                
                for (i = 2 ; i < c-1; i = i + 2)
                {
                    myCollection.Add(input[i]);
                }          
            }

            string answer = string.Join(" ", myCollection.ToArray());

            Console.WriteLine(answer);
        }
    }
}


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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 3e3 + 5;

ll dp1[N][N], dp2[N][N];
ll a[N];

int solve() {
	int n = in();
	for (int i = 1; i <= n; i++) {
		a[i] = Lin();
	}
	for (int i = n; i >= 1; i--) {
		for (int j = 1; j <= i; j++) {
			int r = j, c = n - i + j;
			dp1[r][c] = max(a[r] + dp2[r + 1][c], a[c] + dp2[r][c - 1]);
			dp2[r][c] = (a[r] + dp2[r + 1][c] > a[c] + dp2[r][c - 1]) ? dp1[r + 1][c] : dp1[r][c - 1];
		}
	}
	printf("%lld\n", dp1[1][n] - dp2[1][n]);
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 139776
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000000

int main(){

    int n; cin >> n;
if(n == 0 || n == 2) cout << 1 << endl;
else if(n == 1) cout << 2 << endl;
else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
from collections import deque
#幅優先探索 BFS
H, W = [int(i) for i in input().split()]
ch, cw = [int(i)-1 for i in input().split()]
dh, dw = [int(i)-1 for i in input().split()]

S = [input() for i in range(H)]
cost = [[-1]*W for i in range(H)]

q = [[0,ch,cw]]
q = deque(q)

ans = -1
while(q):
    cnt, cx, cy = q.popleft()
    if cost[cx][cy]<0:
        cost[cx][cy]=cnt
        for dx in range(-2,3):
            for dy in range(-2,3):
                if 0<=cx+dx<H and 0<=cy+dy<W and S[cx+dx][cy+dy]=='.':
                    if cost[cx+dx][cy+dy]<0:
                        if [dx,dy] in [[1,0],[-1,0],[0,1],[0,-1]]:
                            q.appendleft([cnt,cx+dx,cy+dy])
                        else:
                            q.append([cnt+1,cx+dx,cy+dy])

print(cost[dh][dw])


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int H, W = 5; 

int erase(vector<vector<int>> &board)
{
    int res = 0;

    for (int y=0; y<H; y++) {
        for (int x=0; x<W; x++) {
            if (board[y][x] == -1) continue;

            int cnt = 1;
            for (int xx=x+1; xx<W; xx++) {
                if (board[y][x] != board[y][xx]) break;
                else cnt++;
            }

            if (cnt >= 3) {
                res += cnt * board[y][x];
                for (int i=0; i<cnt; i++) {
                    board[y][x+i] = -1;
                }
            }

        }
    }
    return res;
}

bool drop(vector<vector<int>> &board)
{
    bool res = false;
    for (int x=0; x<W; x++) {
        for (int y=H-2; y>=0; y--) {
            int yy = y;
            while (yy < H-1 && board[yy][x] > 0 && board[yy+1][x] == -1) {
                swap(board[yy+1][x], board[yy][x]);
                yy++;
                res = true;
            }
        }
    }
    return res;
}

void dump(vector<vector<int>> board)
{
    cerr << "-------------" << endl;
    rep(y, H) {
        rep(x, W) {
            cout << board[y][x] << " ";
        }
        cout << endl;
    }
}

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

    while (cin >> H, H) {
        vector<vector<int>> board(H, vector<int>(W, 0));
        rep(y, H) rep(x, W) cin >> board[y][x];

        int score = 0;
        bool updated = true;
        while (updated) {
#ifdef DEBUG
            dump(board);
#endif

            updated = false;

            score += erase(board);
            updated = drop(board);

            if (!updated) break;
        }
#ifdef DEBUG
        dump(board);
#endif
        cout << score << endl;
    }
}




Measured memory_bytes: 3136
#include <stdio.h>
#include <stdbool.h>

int g[100];
int a[100][100] ;
int k, v2, check=0, cycle = 0;

void HE(int x){
int i;
g[x] = 1;
for(int i = 0; i < v2; i++){
		if(a[x][i] == 0) continue;
		if(g[i] == 1){
				cycle = 1;
				return;
		}
		if(g[i] == 0) HE(i);
}
g[x] = 2;
}

int main(){

 int e,s,t,i,j;
		scanf("%d %d", &v2,&e);
		for(i=0; i<v2;i++){
			g[i] = 0;
			for(j=0; j<v2;j++){
				a[i][j]=0;
			}
		}
	for(i=0; i<e;i++){
		scanf("%d %d", &s,&t);
		a[s][t] = 1;
	}
	for( i = 0; i < s; i++){
			if(g[i] == 0) HE(i);
			if(cycle){
					printf("1\n");
					return 0;
				}

		}
		printf("0\n");

				return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(true){
	char c[100];
	int N,B=0,A=0,p[10];
	cin>>N;
	if(N==0)break;
	for(int i=0;i<10;i++){
		p[i]=0;
	}
		for(int i=0;i<100;i++){
		cin>>c[i];
	}
	for(int i=0;i<100;i++){
		if(c[i]=='M'){
			A=i%N;
			p[A]++;
		}
		if(c[i]=='L'){
			A=i%N;
			p[A]=p[A]+B;
			p[A]++;
			B=0;
		}
		if(c[i]=='S'){
			A=i%N;
			B=B+p[A];
			B++;
			p[A]=0;
		}
		
	}
	sort(p,p+N);
	for(int i=0;i<N;i++){
		cout<<p[i]<<" ";
	}
	cout<<B<<endl;
	}
}

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

using namespace std;

typedef long long int64;

const int mod = 1e9 + 7;

int main()
{
  int64 N, M, X[100000], Y[100000];
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> X[i];
  for(int j = 0; j < M; j++) cin >> Y[j];

  int64 all = 0;
  for(int i = 0; i < N; i++) all += X[i];
  int64 all2 = 0;
  for(int i = 0; i < N; i++) {
    all -= X[i];
    all2 += (all % mod - X[i] * (N - i - 1) % mod + mod) % mod;
    all2 %= mod;
  }

  int64 ret = 0;
  all = 0;
  for(int i = 0; i < M; i++) {
    all += Y[i];
  }

  for(int i = 0; i < M; i++) {
    all -= Y[i];
    ret += (all % mod - Y[i] * (M - i - 1) % mod + mod) % mod * all2 % mod;
    ret %= mod;
  }

  cout << ret << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
mint dp[100][100];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k;
    string s;
    cin>>k>>s;
    mint ans=0;
    mint a=1,b=1;
    vector<mint> A(s.size()+k+1);
    ll m=s.size()+k;
    rep(i,s.size()+k+1){
        A[s.size()+k-i]=a*b;
        a*=25;
        b=b*(m-i)/(i+1);
    }
    rep(i,s.size()+k+1){
        if(i>=s.size()) ans+=A[i];
    }
    cout<<ans;
}

Measured memory_bytes: 19812
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i - 1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i - 1])return false;
		}
	}
	return true;
}

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}




int main() {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = 0;
	ll dx,dy;
	dx = x / 2;
	dy = y / 2;
	ans = a * x + y * b;
	if (a + b > 2 * c) {
		if (x > y) {
			

			ans=min(ans - y*(a + b - 2 * c),2*x*c);
		}
		else {
			
			ans = min(ans - x*(a + b - 2 * c),2*y*c);
		}
	}


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

ll bit[1000010];
//ll kai[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		(t += bit[i]) %= mod;
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 1000005)
	{
		(bit[i] += x) %= mod;
		i += i & -i;
	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}

void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 1000005; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N;
ll a[401];
ll dp[401][401];
bool flg[401][401];
ll sum[401];

ll saiki(ll b, ll e) {
	if (b == e) return 0;
	if (flg[b][e]) return dp[b][e];
	flg[b][e] = true;
	ll cost = INF;
	for (ll i = b; i < e; i++) {
		cost = min(cost, saiki(b, i) + saiki(i + 1, e));
	}
	return dp[b][e] = cost + sum[e] - sum[b - 1];
}

void solve() {
	cin >> N;
	rep(i, N) cin >> a[i + 1];
	rep(i, N) sum[i + 1] = sum[i] + a[i + 1];
	cout << saiki(1, N)<< endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>

/* Macro definition */
#define M 1000151        // M is prime number larger than 1,000,000

/* Prototype declaration */
int getChar(char);
long getKey(char *);
int h1(long);
int h2(long);
int hashf(long, int);
void hashInsert(char *);
int hashSearch(char *);

/* Global variable */
char T[M][13];

int main (){
  int i, n;
  char command[7], str[13];

  /* Input, Process and Output */
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%s %s", command, str);
    if( strcmp(command, "insert") == 0 ) hashInsert(str);
    else {
      if( hashSearch(str) ) printf("yes\n");
      else printf("no\n");
    }
  }
  
  return 0;
}

//Convert ascii to integer
int getChar(char c) {
  if( c == 'A' ) return 1;
  else if( c == 'C' ) return 2;
  else if( c == 'G' ) return 3;
  else if( c == 'T' ) return 4;
  else return 0;
}

//Get key from string
long getKey(char *str) {
  long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }

  return sum;
}

//Get hash value
int h1(long key) {
  return key % M;
}
int h2(long key) {
  return 1 + (key % (M - 1));
}
int hashf(long key, int i) {
  return (h1(key) + i * h2(key)) % M;
}

//Insert into array T
void hashInsert(char *str) {
  int i, j;
  long key;
  key = getKey(str);
  
  for ( i = 0; i < M; i++ ) {
    j = hashf(key, i);
    if ( strcmp(T[j], str) == 0 ) break;
    else if ( strlen(T[j]) == 0 ) {
      strcpy(T[j], str);
      break;
    }
   }
  
}

//Search for key from array T
int hashSearch(char *str) {
  int i, j;
  long key;
  key = getKey(str);
  
  for( i = 0; i < M; i++) {
    j = hashf(key, i);
    if ( strcmp(T[j], str) == 0 ) return 1;
    else if ( strlen(T[j]) == 0 ) break;
  }

  return 0;
}

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

using namespace std;

int main(void){
    
    int n;
    cin >> n;
    
    int h, m, s;
    s = n%60;
    n /= 60;
    m = n%60;
    n /= 60;
    h = n;
    cout << h << ":" << m << ":" << s << endl;
    
    
    return 0;
}


Measured memory_bytes: 3120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int Maxx = 1e5 + 7;
const int Inf = 1e9 + 7;
int n;
int a[Maxx];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int t = a[n] / 2;
	int min = Inf;
	int p;
	for(int i = 1; i <= n; i++) {
		if(abs(a[i] - t) <= min) {
			min = abs(a[i] - t);
			p = a[i];
		}
	}
	if(n == 2) printf("%d %d\n", a[2], a[1]);
	else printf("%d %d\n", a[n], p);
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <assert.h>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 1000005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(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 pow(int a, int b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

int cal(int n){
    if(n == 1)return 3;
    else if(n == 2)return 2;
    else if(n == 3)return 1;
    return 0;
}
int main(){
    int T, i, j, k, ca = 0, K, n, m;
    scanf("%d%d", &n, &m);
    int ans = 0;
    ans += cal(n) + cal(m);
    if(n == 1 && m == 1)ans += 4;
    ans *= 100000;
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++)
    {
        string s = v[i];
        sort(s.begin(), s.end());
        int a = stoi(s);
        sort(s.begin(), s.end(), greater<int>());
        int b = stoi(s);
        cout << b - a << "\n";
    }
    return 0;
}




Measured memory_bytes: 3108
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define lriii(a,b,c) lrii(a,b),lri(c)
#define pb push_back
#define _1 first
#define _2 second
#define ALL(s) s.begin(),s.end()
#define SZ(x) int((x).size())

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int alphabet = 26;
const double PI = 3.1415926535;
const int MAXINT = 1e5+1;

struct option{ pii pos; int take; };

int dp[3001][3001];
option op[3001][3001];
string s, t;

int solve(int i, int j){
	if( i==s.size() || j==t.size() ) return 0;
	if( dp[i][j] != -1 ) return dp[i][j];

	dp[i][j] = 0;
	op[i][j] = {{-1,-1},-1};

	int val = solve(i+1,j);
	if( val > dp[i][j] ) dp[i][j] = val, op[i][j] = {{i+1,j},0};
	val = solve(i,j+1);
	if( val > dp[i][j] ) dp[i][j] = val, op[i][j] = {{i,j+1},0};
	if( s[i]==t[j] ){
		int val = 1 + solve(i+1,j+1);
		if( val>dp[i][j] ) dp[i][j] = val, op[i][j] = {{i+1,j+1},1};
	}
	return dp[i][j];
}

int main(){
	cin >> s >> t;
	memset(dp,-1,sizeof(dp));

	int len = solve(0,0);
	//cout << len << endl;
	pii cu = {0,0};
	while( op[cu._1][cu._2].take != -1 && cu._1<s.size() && cu._2<t.size() ){
		if( op[cu._1][cu._2].take ) cout << s[cu._1];
		cu = op[cu._1][cu._2].pos;
		//cout << cu._1 << " " << cu._2 << endl;
	}
	cout << endl;
	return 0;
}
/*

*/  



Measured memory_bytes: 144788
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, m;
Int res;

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}

Int fact[1080000];
Int revfact[1080000];
Int rev[1080000];

void init(){
    Int m = MOD;
    fact[0] = 1;
    revfact[0] = 1;
    rev[0] = 0;
    rev[1] = 1;
    for(int i = 1;i < 1080000;i++){
        fact[i] = fact[i-1] * i % m;
        if(i>1)rev[i] = m / i * (m-rev[m % i]) % m;
        revfact[i] = revfact[i-1] * rev[i] % m;
    }
}

Int nCk(Int n, Int k){
    if(n < k)return 0;
    return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}



int main(){
    init();
    cin >> n >> m;
    res = mod_pow(m+1,n) * mod_pow(n+1,m) % MOD;
    for(int i = 1;i <= n;i++){
        Int tmp = nCk(n, i) * nCk(m, i) % MOD *fact[i] % MOD * mod_pow(m+1,n-i) % MOD * mod_pow(n+1, m-i) % MOD;
        if(i % 2)res -= tmp;
        else res += tmp;
        res %= MOD;
    }
    if(res < 0)res += MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 25728
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
int a[MAXN];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        int sum = 0;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d",&a[i]);
            if(a[i] % 4 == 0) sum++;
            else if(a[i] % 2 == 0) ans++;
        }
        if(sum >= (n/2)) printf("Yes\n");
        else if(ans  == (n - 2*(sum))) printf("Yes\n");
        else printf("No\n");
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n,a[2000];
	cin>>n;
	int s=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0){
				s=1;
				break;
			}
		}
	}
	if(s) cout<<"DENIED";
	else cout<<"APPROVED";
	return 0;
 } 

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N=1e5+5;
 
int n, totW;
int w[105], v[105];
int cache[105][N];
 
int dp(int idx, int val)
{
    if(val==0)
        return 0;
    if(val<0)
        return 1e15;
    if(idx==n+1)
        return 1e15;
    int &ans=cache[idx][val];
    if(ans!=-1)
        return ans;
    ans=min(dp(idx+1, val), w[idx]+dp(idx+1, val-v[idx]));
    return ans;
}
 
int32_t main()
{
    IOS;
   
    memset(cache, -1, sizeof(cache));
    cin>>n>>totW;
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    int ans=0;
    for(int i=1;i<=1e5;i++)
    {
        int minWt=dp(1, i);
        if(minWt<=totW)
            ans=i;
    }
    cout<<ans;
    return 0;
}

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

int main() {
	while (true) {
		int m, nmin, nmax;
		cin >> m >> nmin >> nmax;

		if (m == 0 && nmin == 0 && nmax == 0)
			break;

		int P[200];
		for (int i = 0;i < m;i++) {
			cin >> P[i];
		}

		int gap = -1;
		int n = -1;

		for (int i = nmin;i <= nmax;i++) {
			int g = P[i - 1] - P[i];

			if (gap <= g) {
				gap = g;
				n = i;
			}
		}
		cout << n << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(a + b - n, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
  To be updated after "Accept".

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#include <map>
#define debug(...) fprintf(stderr, __VA_ARGS__)

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

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

inline ll mul (ll a, ll b, ll c) {
	return __int128(a) * b % c;
}

ll power (ll x, ll k, ll mod) {
	ll res = 1;
	while (k) {
		if (k & 1) res = mul(res, x, mod);
		x = mul(x, x, mod);
		k >>= 1;
	}
	return res;
}

bool miller (ll n, int p) {
	ll x = n - 1, test = power(p, x, n);
	if (test != 1) return 0;
	while (!(x & 1) and test == 1) {
		x >>= 1;
		test = power(p, x, n);
		if (test != 1 and test != n - 1) return 0;
	}
	return 1;
}

bool is_prime (ll n) {
	int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
	for (int p : prime) if (n == p) return 1;
	for (int p : prime) if (n % p == 0) return 0;
	for (int p : prime) if (!miller(n, p)) return 0;
	return 1;
}

ll gcd (ll a, ll b) {
	if (!b) return a;
	return gcd(b, a % b);
}

ll nxt (ll x, ll c, ll n) {
	ll res = mul(x, x, n) + c;
	return res >= n ? res - n : res;
}

ll porllard (ll n) {
	if (n == 4) return 2;
	ll c = (rand() * (ll(RAND_MAX) + 1) + rand()) % n;
	ll a = nxt(rand(), c, n), b = nxt(a, c, n);
	while (a != b) {
		ll g = gcd(n, std::abs(a - b));
		if (g > 1 and g < n) return g;
		a = nxt(a, c, n);
		b = nxt(b, c, n);
		b = nxt(b, c, n);
	}
	return porllard(n);
}

std::map<ll, int> get;
void factor (ll n, int coe) {
	if (n == 1) return;
	if (is_prime(n)) return get[n] += coe, void();
	ll d = porllard(n);
	int k = 0;
	while (n % d == 0) n /= d, ++ k;
	factor(n, coe);
	factor(d, coe * k);
}

par pr[100];
ll ans;
void dfs (int i, ll d, ll c, ll n, ll K, ll mod) {
	if (!i) {
		if (d & 1 and !(n / d & 1)) return;
		ll g = power(K, (d + 1) >> 1, mod);
		ll h = d & 1 ? d : d >> 1;
		ans += mul(mul(g, h, mod), c, mod);
		return;
	}
	for (int k = 0; k <= pr[i].second; k ++) {
		dfs(i - 1, d, k == pr[i].second ? c : c * (1 - pr[i].first), n, K, mod);
		d *= pr[i].first;
	}
}

int main () {
	ll n = read, K = read, mod = 1000000007;
	get.clear();
	factor(n, 1);
	int pp = 0;
	for (par p : get)
		pr[++ pp] = p;
	ans = 0;
	dfs(pp, 1, 1, n, K, mod);
	ans %= mod;
	if (ans < 0) ans += mod;
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	
	

	char input[16];
	cin >> input;
	
	char right[] = "CODEFESTIVAL2016";
	int counter = 0;
	
	for(int i = 0; right[i]!='\0'; i++){
		if(right[i]!=input[i]){ 
			counter++;
			} 
	}
	
	cout << counter;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(void){
    std::string s;
    std::cin>>s;
    for(unsigned int i=0;i<s.size();i++){
        if(i%2==0){
            std::cout<<s[i]<<std::flush;
        }
    }
    std::cout<<std::endl;
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

int main(){
  cout<<fixed<<setprecision(9);
  double n,x;
  cin>>n>>x;
  cout<<n/x<<endl;
  return 0;
}


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

using namespace std;

double x[4],y[4];
int main(void){
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])){
		
		if(x[0]>x[2]){
			swap(x[1],x[3]);
			swap(y[1],y[3]);
			swap(y[0],y[2]);
			swap(x[0],x[2]);
		}
		
		if(x[1]<x[2])printf("NO\n");
		else{
			if(y[0]>y[3] || y[2]>y[1])printf("NO\n");
			else printf("YES\n");
		}
	}
}

Measured memory_bytes: 1040
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int n;
	while (cin >> n, n)
	{
		int t[32][32];
		rep (i, n)
		{
			cin >> t[i][n];
			rep (j, n)
				cin >> t[i][j];
		}

		const int INF = 1 << 29;
		static int dp[1 << 16];
		fill_n(dp, 1 << n, INF);
		dp[0] = 0;
		for (int s = 1; s < 1 << n; ++s)
		{
			for (int i = 0; i < n; ++i)
			{
				if (!(s >> i & 1))
					continue;

				int e = t[i][n];
				for (int j = 0; j < n; ++j)
					if ((s ^ 1 << i) >> j & 1)
						min_swap(e, t[i][j]);

				min_swap(dp[s], dp[s ^ 1 << i] + e);
			}
		}

		cout << dp[(1 << n) - 1] << endl;
	}
}

Measured memory_bytes: 1124
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		int v;
		int[] coins = { 500, 100, 50, 10, 5 };
		while ((v = in.nextInt()) != 0) {
			int oturi = 1000 - v;
			int n = 0;
			for (int i = 0; i < 5 && oturi != 0; i++) {
				n += oturi / coins[i];
				oturi %= coins[i];
			}
			n += oturi;
			System.out.println(n);
		}
		in.close();
	}
}

Measured memory_bytes: 17168
//Name: Black-and-White
//Level: 1
//Category: 実装
//Note:

/**
 * 縦、横、斜めそれぞれについて、同じ文字が1列に並んでいるか、並んでいればどの文字かを判定する。
 */
#include <iostream>
#include <string>
#include <array>

using namespace std;

array<string,3> field;
char check_inner(int r, int c, int dr, int dc) {
    if(field[r][c] == field[r+dr][c+dc] && field[r][c] == field[r+dr*2][c+dc*2]) {
        return field[r][c];
    }
    return 0;
}

string check() {
    // Row
    for(int r = 0; r < 3; ++r) {
        char c = check_inner(r, 0, 0, 1);
        if(c != 0 && c != '+') return string()+c;
    }

    // Col
    for(int c = 0; c < 3; ++c) {
        char cc = check_inner(0, c, 1, 0);
        if(cc != 0 && cc != '+') return string()+cc;
    }

    // Diag
    {
        char c = check_inner(0, 0, 1, 1);
        if(c != 0 && c != '+') return string()+c;
    }
    {
        char c = check_inner(0, 2, 1, -1);
        if(c != 0 && c != '+') return string()+c;
    }
    return "NA";
}

bool solve() {
    for(int i = 0; i < 3; ++i) {
        cin >> field[i];
        if(field[i] == "0") return false;
    }

    cout << check() << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

template <typename T>
void scanInt(T &x) {
    bool neg = false;
    register int c = getchar_unlocked();
    x = 0;
    for (; (c < 48 || c > 57) && (c != '-'); c = getchar_unlocked());
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; c > 47 && c < 58; c = getchar_unlocked())
        x = (x << 1) + (x << 3) + c - 48;
    if (neg)
        x *= -1;
}

template <typename T>
void printInt(T n) {
    if (n < 0) {
        n = -n;
        putchar_unlocked('-');
    }
    int i = 21;
    char output_buffer[21];
    do {
        output_buffer[--i] = (n % 10) + '0';
        n /= 10;
    } while (n);
    do {
        putchar_unlocked(output_buffer[i]);
    } while (++i < 21);
}

bool isOddNo(int n) {
    int Count = 0;
    while (n > 0) {
        n /= 10;
        Count++;
    }
    return Count & 1;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    bool flag = true;
    for (int i = 0; i < n-1; i++) {
        int pos = i;
        while (i < n-1 && v[i] >= v[i+1])
            i++;
        if (pos != i && v[pos] - v[i] > 1) {
            flag = false;
            break;
        }
    }
    (flag) ? cout << "Yes\n" : cout << "No\n";
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i,j) for(int i=0;i<(j);i++)

int A,B;
int a[5100],b[5100];
vector<int>c[1024];

int main(){
  scanf("%d%d", &A,&B);
  rep(i,A){
    scanf("%d",a+i);
    c[a[i]].push_back(i);
  }
  rep(i,B) scanf("%d",b+i);
  int res = 0;
  rep(i,B){
    int pos = -1, j;
    for(j=i;j<B;j++){
      vector<int>::iterator it = upper_bound(c[b[j]].begin(), c[b[j]].end(), pos);
      if(it == c[b[j]].end()) break;
      pos = *it;
    }
    res = max(res, j-i);
  }

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

Measured memory_bytes: 1160
x = int(input())
flg = 0
ans1 = 0
ans2 = 0
for i in range(-200,200):
    for j in range(i,200):
        if j ** 5 + i ** 5 == x:
            flg = 1
            ans1 = j
            ans2 = -i

        elif j ** 5 - i ** 5 == x:
            flg = 1
            ans1 = j
            ans2 = i
        if flg:
            break
    if flg:
        break
print(ans1,ans2)


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

int main(int argc, char const *argv[]) {
    int a;
    cin >> a;
    int b = a/100;
    int c = a%100;

    if (1 <= b && b <= 12) {
        if (1 <= c && c <= 12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    } else {
        if (1 <= c && c <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
  }
 
  z->parent = y;
  if(y == NIL) {
    root = z;  
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else y->right = z;
}
 
 
void inorder(Node u){
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
 
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!= NIL){
    preorder(u->left);
  }
  if(u->right!= NIL){
    preorder(u->right);
  }
   
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    int Ruisekiwa[n];
    cin >> a[0];
    Ruisekiwa[0] = a[0]%m;
    for(int i = 1; i <= n-1; i++) {
        cin >> a[i];
        Ruisekiwa[i] = (Ruisekiwa[i-1] + a[i])%m;
    }
    sort(Ruisekiwa, Ruisekiwa+n);

    int t = Ruisekiwa[0];
    int k = 0;
    int c[n];   //Ruisekiwaの小さい数から順にそれぞれ何個ずつ含まれているかをc[n]に入れる
    rep(i, n) {
        c[i] = 0;
    }   

    rep(i, n) {
        if(t < Ruisekiwa[i]) {
            t = Ruisekiwa[i];
            k++;
            c[k]++;
        } 
        else {
            c[k]++;
        }
    }

    ll ans = 0;

    if(Ruisekiwa[0] == 0) {
        ans += c[0];
    }

    rep(i, n) {
        if(2 <= c[i]) {
            ans += (ll)c[i]*(c[i]-1)/2;
        }
    }

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

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

#define ll long long 
using namespace std;



main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	map<ll,ll> mp;
	multimap<ll,ll>mp1;
	ll test,n,w,i,j,area,flag=0,a1[200],d=0,m=INT_MAX,amt,r,a2[200],x,y,k,K,I,m1,m2,m3,o,o1,o2,o3,dp[200][100001];
	
	cin>>n>>w;
	for(i=1;i<=n;++i){
		cin>>a1[i];
		cin>>a2[i];
		}
	
	for(i=0;i<=w;++i)
		dp[0][w]=0;
	for(i=0;i<=n;++i)
		dp[i][0]=0;
	for(i=1;i<=n;++i){
		for(j=1;j<=w;++j){
			if(j-a1[i]>=0)
				dp[i][j]=max(a2[i]+dp[i-1][j-a1[i]],dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];}}
		
		
	cout<<dp[n][w]<<endl;
	
	}
		
	





Measured memory_bytes: 80128
N, M = map(int, input().split())
S = input()

ans = []

now_pos = N

while now_pos > 0:
    next_pos = max(0, now_pos - M)
    for i in range(M):
        if S[next_pos + i] == "0":
            ans.append(now_pos - (next_pos + i))
            now_pos = next_pos + i
            break
    else:
        print(-1)
        exit()

print(" ".join(map(str, ans[::-1])))


Measured memory_bytes: 50740
// Problem :
// 			C - Walking Takahashi
//
//
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
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 deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */
typedef long long int ll;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
	 ll x,k,d; cin >> x >> k >> d;
     x = abs(x);

     if(x/k < d){
     	 ll temp = (k - x/d);
     	 if(temp%2==0)
     	 	cout << (x%d);
     	 else
     	 	cout << (d-(x%d));
     }
     else{
     	 cout << (x - (k*d));
     }
}

int main(){
    IOS;
    solve();
}


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

using namespace std;

#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

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

const int N = 200200;
const int mod = 1e9 + 7;

ll n, a[N], pref[N], ans = 1e18;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	fo(i, n)
		cin >> a[i];
	ll sum = 0;
	fo(i, n)
		pref[i] = pref[i - 1] + a[i];
	for(int i = n; i > 1; --i)
	{
		sum += a[i];
		ll res = abs(sum - pref[i - 1]);
		ans = min(ans, res);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3456
import sys
a=[1]*500000
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*((499999-i*i//2)//i+1)
for e in map(int,sys.stdin):print([e-1,sum(a[:(e+1)//2])][e>3])


Measured memory_bytes: 14896
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string t = "CODEFESTIVAL2016";
  int ans = 0;
  for(int i = 0; i < 16; i++){
    if(s[i] != t[i]) ans++;
  }
  cout << ans << endl;  
  return 0;
}

Measured memory_bytes: 256
import sys
N=int(input())
H=list(map(int,input().split()))
for i in range(1,N):
    if H[i-1]<=H[i]:
        pass
    elif H[i-1]==H[i]+1:
        H[i]+=1
    else:
        print("No")
        sys.exit()
print("Yes")

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

int main() {
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(),v.end());
  if (v[2] == v[1] + v[0]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        if (h == 1 | w == 1) { Console.WriteLine(1); goto exit; }
        long ans = ((long)h * w + 1) / 2L;
        Console.WriteLine(ans);
    exit:;
    }
}

Measured memory_bytes: 13140
<?php
$n=trim(fgets(STDIN));
$i=0;
while($i<$n){
  list($x[],$y[])=explode(" ",trim(fgets(STDIN)));
  ++$i;
}
$ans=0;
$i=0;
while($i<$n){
  $j=$i+1;
  while($j<$n){
    $ans+=2*(sqrt(pow($x[$j]-$x[$i],2)+pow($y[$j]-$y[$i],2)));
    ++$j;
  }
  ++$i;
}
echo sprintf('%.7f',$ans/$n),PHP_EOL;

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 500007 , mo = 998244353;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

lint jc[_],rjc[_];

inline void fuck(int n=_-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}

inline lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}

int n,m;

int main()
{
	n=ty(),m=ty();
	if(n>m)swap(n,m);

	fuck();

	lint ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+C(n,i)*C(m,i)%mo*jc[i]%mo*powa(n+1,m-i)%mo*powa(m+1,n-i)%mo*(i&1?mo-1:1)%mo)%mo;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 8064
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vll> vl2d;
typedef vector <vi> vi2d;
typedef vector <char> vc;
typedef vector <bool> vb;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <long,long> ml;
typedef map <string,string> mss;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define foreach(x,arr) for(auto& x:arr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000LL
#define MOD 1000000007
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<"\n"; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define forch(ch,str) for(char& c : str)
#define FILL(a,b) memset(a,b,sizeof(a))
//Swift related stuff
#define append push_back
#define nil nullptr
#define guard(_condition) if (bool(_condition)){}
#define count size()
#define let const auto
#define var auto
#define startsWith(str) rfind(str, 0)
#define prq priority_queue
#define tostr(argument) to_string(argument)
#define alphabet "abcdefghijklmnopqrstuvwxyz"

int main() {
    ll n;
    cin>>n;
    cout<<(n%2 == 0 ? (n/2)-1 : n/2)<<endl;
    return 0;
}

Measured memory_bytes: 3596