akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef pair<int,int> pii;
static const int INF = 1ll<<60;

int dp[2][2][2][2001][2001];
int N,M;
string S,T;


int solve(int n1,int n2,int p,int s,int t){
    if(dp[n1][n2][p][s][t]!=-1)return dp[n1][n2][p][s][t];
    if(s>N||t>M){
        return -INF;
    }
    if(s==N&&t==M){
        if(p==0)return -INF;
        else return 0;
    }
    int res=0;
    int sx,tx;
    {
        if(s==N)sx=p;
        if(t==M)tx=p;
        if(S[s]=='I')sx=1;
        if(S[s]=='O')sx=0;
        if(T[t]=='I')tx=1;
        if(T[t]=='O')tx=0;
    }
    if(n1==0&&n2==0){
        if(p!=sx&&p!=tx){
            res+=max(solve(0,0,p,s+1,t),
                    max(solve(0,0,p,s,t+1),
                        max(solve(1,0,sx,s+1,t)+1,
                            max(solve(0,1,tx,s,t+1)+1,res))));
        }
        else if(p!=sx&&p==tx){
            res+=max(solve(0,0,p,s+1,t),
                    max(solve(0,0,p,s,t+1),
                        max(solve(1,0,sx,s+1,t)+1,res)));
        }
        else if(p==sx&&p!=tx){
           res+=max(solve(0,0,p,s+1,t),
                   max(solve(0,0,p,s,t+1),
                           max(solve(0,1,tx,s,t+1)+1,res)));
        }
        else{
            res+=max(solve(0,0,p,s+1,t),
                   max(solve(0,0,p,s,t+1),res));
        }
    }

    else if(n1==0&&n2!=0){
        if(p!=sx&&p!=tx){
            res+=max(solve(0,n2,p,s+1,t),
                        max(solve(1,n2,sx,s+1,t)+1,
                            max(solve(0,n2,tx,s,t+1)+1,res)));
        }
        else if(p!=sx&&p==tx){
            res+=max(solve(0,n2,p,s+1,t),
                        max(solve(1,n2,sx,s+1,t)+1,res));
        }
        else if(p==sx&&p!=tx){
           res+=max(solve(0,n2,p,s+1,t),
                        max(solve(0,n2,tx,s,t+1)+1,res));
        }
        else{
            res+=max(solve(0,n2,p,s+1,t),res);
        }
    }

    else if(n1!=0&&n2==0){
        if(p!=sx&&p!=tx){
            res+=max(solve(n1,0,p,s,t+1),
                        max(solve(n1,0,sx,s+1,t)+1,
                            max(solve(n1,1,tx,s,t+1)+1,res)));
        }
        else if(p!=sx&&p==tx){
            res+=max(solve(n1,0,p,s,t+1),
                        max(solve(n1,0,sx,s+1,t)+1,res));
        }
        else if(p==sx&&p!=tx){
           res+=max(solve(n1,0,p,s,t+1),
                        max(solve(n1,1,tx,s,t+1)+1,res));
        }
        else{
            res+=max(solve(n1,0,p,s,t+1),res);
        }
    }
    else {
        if(p!=sx&&p!=tx){
            res+=max(solve(n1,n2,sx,s+1,t)+1,
                    max(solve(n1,n2,tx,s,t+1)+1,res));
        }
        else if(p!=sx&&p==tx){
            res+=max(solve(n1,n2,sx,s+1,t)+1,res);
        }
        else if(p==sx&&p!=tx){
           res+=max(solve(n1,n2,tx,s,t+1)+1,res);
        }
        else if(p==0)return -INF;
    }
    return dp[n1][n2][p][s][t]=res;
}


signed main(){
    memset(dp,-1,sizeof(dp));
    cin>>N>>M;
    cin>>S>>T;
    cout<<solve(0,0,0,0,0)<<endl;
}

Measured memory_bytes: 253880
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    // Here your code !
    
    long long int n,m;
    
    cin >> n >> m;
    
    if(m <= 1){
        cout << 0 << endl;
        return 0;
    }
    
    if( n*2 >= m ){
        cout << min(n,m/2) << endl;
    }else{
        cout << n + (m-n*2)/4 << endl;
    }
    
}


Measured memory_bytes: 256
N = int(input())
l = [str(input())]
for i in range(N-1):
  w = str(input())
  if w in l:
    print('No')
    exit()
  elif l[-1][-1] != w[0]:
    print('No')
    exit()
  else:
    l.append(w)
print('Yes')

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {FIN

	int n, i, a, b, c;
	cin >> n;
	
	vvi dp(n + 1, vi(3));
	for (i = 0; i < n; i++) {
		cin >> a >> b >> c;
		dp[i + 1][0] = a + max(dp[i][1], dp[i][2]);
		dp[i + 1][1] = b + max(dp[i][0], dp[i][2]);
		dp[i + 1][2] = c + max(dp[i][0], dp[i][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << "\n";

	return 0;
}

Measured memory_bytes: 8688
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int W, a, b;

int main() {
  cin >> W >> a >> b;
  int ar = a + W;
  int br = b + W;
  if (b > ar) {
    cout << b - ar;
  } else if (br < a) {
    cout << a - br;
  } else {
    cout << 0;
  }
}


Measured memory_bytes: 3568
def add_i1():
	abc[i1]+=1
	abc[i2]-=1
	res[i]=i1
	return

n,*abc=map(int,input().split())
ip=[0]*n
dic={0:"A",1:"B",2:"C"}
for i in range(n):
	tmp=input()
	if tmp=="AB":
		ip[i]=[0,1]
	elif tmp=="BC":
		ip[i]=[1,2]
	else:
		ip[i]=[0,2]
ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
	ans="No"
elif s==1:
	for i in range(n):
		i1=ip[i][0]
		i2=ip[i][1]
		ABC=[abc[i1],abc[i2]]
		if ABC==[0,0]:
			ans="No"
		elif ABC==[0,1]:
			add_i1()
			'''
			abc[i1]+=1
			abc[i2]-=1
			res[i]=i1
			'''
		else:
			abc[i1]-=1
			abc[i2]+=1
			res[i]=i2
else:
	i1=ip[0][0]
	i2=ip[0][1]
	if [abc[i1],abc[i2]]==[0,0]:
		ans="No"
	else:
		for i in range(n):
			i1=ip[i][0]
			i2=ip[i][1]
			if abc[i1]==0:
				abc[i1]+=1
				abc[i2]-=1
				res[i]=i1
			elif abc[i2]==0:
				abc[i1]-=1
				abc[i2]+=1
				res[i]=i2
			elif i+1<n and ip[i+1]!=ip[i]:
				c=list(set(ip[i])&set(ip[i+1]))[0]
				if i1==c:
					abc[i1]+=1
					abc[i2]-=1
					res[i]=i1
				else:
					abc[i1]-=1
					abc[i2]+=1
					res[i]=i2
			else:
				abc[i1]+=1
				abc[i2]-=1
				res[i]=i1
print(ans)
if ans=="Yes":
	for i in range(n):
		print(dic[res[i]])

Measured memory_bytes: 18660
#include<stdio.h>

int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	//scanf("%d",&b);
	//scanf("%d",&c);
		
	if(x - r >= 0 && x + r <=W){
		if(y - r >= 0 && y + r <= H){
			puts("Yes");
			}
		else{
		puts("No");
			}
			}
	else{
		puts("No");
		}
	return 0;
}

Measured memory_bytes: 584
# ABC109D - Make Them Even
def main():
    H, W, *A = map(int, open(0).read().split())
    A, ans = [list(a) for a in zip(*[iter(A)] * W)], []
    for i in range(H):  # move left to right
        for j in range(W - 1):
            if A[i][j] & 1:
                A[i][j + 1] += 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  # move up to down
        if A[i][W - 1] & 1:
            A[i + 1][W - 1] += 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 21588
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
  int n,m,a[10000];
  int s=0;
  scanf("%d %d",&n,&m);
  long int i;
  for(i=0;i<n;i++)
  {
    scanf("%d ",&a[i]);
    s=s+a[i];
  }
  
  
  int p,s1=0;
  p=ceil(1.0*s/(4*m));
  for(i=0;i<n;i++)
  {
    if(a[i]>=p)
    {
      s1=s1+1;
  
  if(s1>=m)
  {
    printf("Yes");
      break;
  }
    }
  }
 
  if(s1<m)
    printf("No");
  
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int time;
	cin>>time;
	int ball[10];
	vector<int> line1;
	vector<int> line2;
	for(int i2=0;i2<time;++i2){
		for(int i=0;i<10;++i){
			cin>>ball[i];
		}
		line1.push_back(ball[9]);
		for(int i=8;i>=0;--i){
			if(line1.back()>ball[i])line1.push_back(ball[i]);
			else if(line2.empty()||line2.back()>ball[i])line2.push_back(ball[i]);
			else {
				cout<<"NO"<<endl;
				goto NO;
			}
		}
		cout<<"YES"<<endl;
NO:;
		line1.clear();
		line2.clear();
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};

int main() {
	while (true) {
		string s;
		cin >> s;
		if (s[0] == '#')break;

		map<string, int> ss;
		ss.emplace("", 0);
		for (int i = 0; i < s.size(); i++) {
			map<string, int>next;
			for (auto itr = ss.begin(); itr != ss.end(); itr++) {
				int num = 1 << (s[i] - 'a');
				if (num == 1 || (itr->second & num) > 0) {
					next.emplace(itr->first + s[i], itr->second);
				}
				if (num < (1 << 25) && (itr->second & (num << 1)) == 0) {
					next.emplace(itr->first + (char)(s[i] + 1),
						itr->second + (num << 1));
				}
			}
			ss = next;
		}

		vector<string> res;
		for (auto itr = ss.begin(); itr != ss.end(); itr++) {
			res.emplace_back(itr->first);
		}
		sort(res.begin(), res.end());
		cout << res.size() << endl;
		if (res.size() < 10) {
			for (int i = 0; i < res.size(); i++) {
				cout << res[i] << endl;
			}
		}
		else {
			for (int i = 0; i < 5; i++) {
				cout << res[i] << endl;
			}
			for (int i = res.size() - 5; i < res.size(); i++) {
				cout << res[i] << endl;
			}
		}
	}
}


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

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int sum=0;
	while(K>0){
	    for (int i=0; i<A; i++){
	        sum++;
	        K--;
	        if (K==0) cout << sum << endl;
	    }
	    for (int j=0; j<B; j++){
	        K--;
	        if (K==0) cout << sum << endl;
	    }
	    for (int k=0; k<C; k++){
	        sum--;
	        K--;
	        if (K==0) cout << sum << endl;
	    }
	}
}

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

int n, m;
int t[100002];
const P INF(-1,-1);

bool check(int idx) {
	if (idx == 0) return t[0] > t[1];
	if (idx == n-1) return t[n-2] < t[n-1];
	return t[idx-1] < t[idx] && t[idx] > t[idx+1];
}

P getNext(int idx) {
	if (idx < 0 || n <= idx || !check(idx)) return INF;
	return P(t[idx], idx);
}

signed main()
{
	while (cin >> n >> m) {
		rep(i,n) cin >> t[i];

		int now = 0;
		priority_queue<P> q;
		rep(i,n) if (check(i)) q.push(P(t[i], i));

		while (!q.empty()) {
			P p = q.top(); q.pop();

			int plus = m - (p.first + now);
			if (plus > 0) {
				now += plus;
			} else {
				plus = 0;
			}

			t[p.second] = 0;
			P left = getNext(p.second - 1);
			P right = getNext(p.second + 1);

			if (left != INF) {
				left.first -= now;
				q.push(left);
			}

			if (right != INF) {
				right.first -= now;
				q.push(right);
			}
		}

		cout << now << endl;
	}
}

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  a[n-1]/=2;
  int sum=0;
  
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); ++i)

int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        int d[2][101][101];
        REP(i,2) REP(j,m+1) REP(k,m+1) {
            d[i][j][k] = (j == k ? 0 : 1e8);
        }
        int a, b, cost, time;
        REP(i,n) {
            cin >> a >> b >> cost >> time;
            d[0][a][b] = min(d[0][a][b], cost);
            d[0][b][a] = min(d[0][b][a], cost);
            d[1][a][b] = min(d[1][a][b], time);
            d[1][b][a] = min(d[1][b][a], time);
        }
        REP(k,m+1) REP(i,m+1) REP(j,m+1) {
            d[0][i][j] = min(d[0][i][j], d[0][i][k] + d[0][k][j]);
            d[0][j][i] = min(d[0][j][i], d[0][j][k] + d[0][k][i]);
            d[1][i][j] = min(d[1][i][j], d[1][i][k] + d[1][k][j]);
            d[1][j][i] = min(d[1][j][i], d[1][j][k] + d[1][k][i]);
        }
        int k, p, q, r;
        cin >> k;
        REP(i,k) {
            cin >> p >> q >> r;
            cout << d[r][p][q] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 1000000001


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

template<class T>
bool inline ChangeMinimum( T &a, T b )
{
	if( a > b ){
		a = b;
		return true;
	}
	return false;
}

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

template<class T>
class Vec3
{
	public:
		T act[3];
};

int Stair( int now, vector<ll> &H )
{
	if( H[now] >= H[now+1] ){}
	
}

int main(void) {
	
	string s,t;
	inp(s);
	inp(t);
	int Num_s = s.size();
	int Num_t = t.size();
	vector<vector<int>> Max(Num_s,vector<int>(Num_t));
	rep(i,Num_s)rep(j,Num_t)Max[i][j] = 0;
	vector<vector<int>> dp(Num_s,vector<int>(Num_t));
	vector<vector<int>> Max_i(Num_s,vector<int>(Num_t));
	vector<vector<int>> Max_j(Num_s,vector<int>(Num_t));
	for(int i=Num_s-1; i>=0; i--){
		for(int j=Num_t-1; j>=0; j--){
			if(s[i]==t[j]){
				if(i==Num_s-1 || j==Num_t-1){
					dp[i][j] = 1;
				}else{
					dp[i][j] = Max[i+1][j+1] + 1;
				}
			}else{
				dp[i][j] = 0;
			}
			if(i==Num_s-1 && j==Num_t-1){
				Max[i][j] = dp[i][j];
				Max_i[i][j] = i;
				Max_j[i][j] = j;
			}else if(i==Num_s-1){
				Max[i][j] = max(dp[i][j],Max[i][j+1]);
				if(Max[i][j]==dp[i][j]){
					Max_i[i][j] = i;
					Max_j[i][j] = j;
				}else{
					Max_i[i][j] = Max_i[i][j+1];
					Max_j[i][j] = Max_j[i][j+1];				
				}
			}else if(j==Num_t-1){
				Max[i][j] = max(dp[i][j],Max[i+1][j]);
				if(Max[i][j]==dp[i][j]){
					Max_i[i][j] = i;
					Max_j[i][j] = j;
				}else{
					Max_i[i][j] = Max_i[i+1][j];
					Max_j[i][j] = Max_j[i+1][j];					
				}				
			}else{
				Max[i][j] = max(dp[i][j],Max[i][j+1]);
				Max[i][j] = max(Max[i][j],Max[i+1][j]);
				if(Max[i][j]==dp[i][j]){
					Max_i[i][j] = i;
					Max_j[i][j] = j;
				}else if(Max[i][j]==Max[i][j+1]){
					Max_i[i][j] = Max_i[i][j+1];
					Max_j[i][j] = Max_j[i][j+1];					
				}else if(Max[i][j]==Max[i+1][j]){
					Max_i[i][j] = Max_i[i+1][j];
					Max_j[i][j] = Max_j[i+1][j];					
				}					
			}
		}
	}
	
/* 	rep(i,Num_s){
		rep(j,Num_t)cout << dp[i][j] << ","; 
		cout << endl;
	}cout << endl;
	rep(i,Num_s){
		rep(j,Num_t)cout << Max_i[i][j] << ","; 
		cout << endl;
	}cout << endl;
	rep(i,Num_s){
		rep(j,Num_t)cout << Max_j[i][j] << ","; 
		cout << endl;
	}cout << endl; */
	
	
	int ind_i = Max_i[0][0];
	int ind_j = Max_j[0][0];
	if(Max[0][0]!=0)cout << s[ind_i];
	rep(n,Max[0][0]-1){
//		cout << "ind_i : "<<ind_i<<endl;
//		cout << "ind_j : "<<ind_j<<endl;				
		int i = ind_i;
		int j = ind_j;
		ind_i = Max_i[i+1][j+1];
		ind_j = Max_j[i+1][j+1];
		cout << s[ind_i];
	}
	cout << endl;
	
//	out(ans);
	
		
}


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

public class Main {

    private static final int MOD = 1_000_000_007;

    private static int N;
    private static int M;
    private static boolean[] a;

    private static int[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt() + 1;
        M = sc.nextInt();

        a = new boolean[N];
        Arrays.fill(a, true);

        for (int i = 0; i < M; i++) {
            a[sc.nextInt()] = false;
        }

        dp = new int[N];
        dp[0] = 1;

        for (int i = 0; i < N; i++) {
            if (!a[i]) continue;

            if (i + 1 < N) {
                dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
            }
            if (i + 2 < N) {
                dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
            }
        }

        System.out.println(dp[N - 1]);
    }

}


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

int main()
{
    int n,y,p;
    cin>>n;
    for(int i=n;i>=0;i--)
   {
    y=sqrt(i);
    p=y*y;
    if(p==i)
    {
        cout<<p;
        break;
    }
   }

    return 0;
}


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

int main() {
        int k;
        cin >> k;
        vector<ll> a(9);
        rep(i,9) a[i] = i+1;
        int i = 0;
        while(1){
                if (k <= a.size()){
                        cout << a[k-1] << endl;
                        return 0;
                }
                ll n = a[i];
                ll t = n % 10;
                if (t != 0) a.push_back(n*10 + t - 1);
                a.push_back(n*10 + t);
                if (t != 9) a.push_back(n*10 + t + 1);
                i++;
        }

}

Measured memory_bytes: 4600
a, b, c = map(int, input().split())
if a > b:
    if b > c:
        print("{} {} {}".format(c, b, a))
    else:
        if a > c:
            print("{} {} {}".format(b, c, a))
        else:
            print("{} {} {}".format(b, a, c))
else:
    if a > c:
        print("{} {} {}".format(c, a, b))
    else:
        if b > c:
            print("{} {} {}".format(a, c, b))
        else:
            print("{} {} {}".format(a, b, c))
    


Measured memory_bytes: 5596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string name,type;
	int i;
	while(cin>>name>>type,type!="X"){
		if(isupper(name[0])){
			if(type=="U"){
				cout<<name<<endl;
			}else if(type=="L"){
				name[0]^=' ';
				cout<<name<<endl;
			}else{
				cout<<(char)(name[0]^' ');
				for(i=1;i<name.size();i++){
					if(isupper(name[i])){
						cout<<"_"<<(char)(name[i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}
		}else if(name.find("_")==string::npos){
			if(type=="U"){
				name[0]^=' ';
				cout<<name<<endl;
			}else if(type=="L"){
				cout<<name<<endl;
			}else{
				for(i=0;i<name.size();i++){
					if(isupper(name[i])){
						cout<<"_"<<(char)(name[i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}
		}else{
			if(type=="U"){
				cout<<(char)(name[0]^' ');
				for(i=1;i<name.size();i++){
					if(name[i]=='_'){
						cout<<(char)(name[++i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}else if(type=="L"){
				for(i=0;i<name.size();i++){
					if(name[i]=='_'){
						cout<<(char)(name[++i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}else{
				cout<<name<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
use std::io;
use std::cmp;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let (a, b, c, x, y) = {
        let i = read::<usize>();
        (i[0], i[1], i[2], i[3], i[4])
    };

    if a + b < c * 2 {
        println!("{}", x * a + y * b);
    } else {
        let ab = cmp::min(x, y);
        let only = cmp::max(x, y) * c * 2;
        if x < y {
            println!("{}", cmp::min(b * (y - ab) + 2 * ab * c, only));
        } else {
            println!("{}", cmp::min(a * (x - ab) + 2 * ab * c, only));
        }
    }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

//const ll mod = 1000000007;
int N, M;
bitset<100> bits[100];
bitset<100> Zero;
int A[100][100];
int ans;
void dfs(bitset<100> now, bitset<100> can, int vertex) {
    /*
    cerr << "-----" << endl;
    cerr << now << endl;
    cerr << can << endl;
    cerr << vertex << endl;
    cerr << "-----" << endl;
    */
    if(now.count() >= 2) {
        int score = 0;
        for(int i = 0; i < N; i++) {
            if(!now[i]) continue;
            int nowscore = 1e9;
            for(int j = 0; j < N; j++) {
                if(!now[j]) continue;
                if(i == j) continue;
                chmin(nowscore, A[i][j]);
            }
            score += nowscore;
        }
        chmax(ans, score);
    }
    for(int i = vertex; i < N; i++) {
        if(!can[i]) {
            //cerr << "ng: " << vertex << " " << i << endl;
            continue;
        }
        auto sub = now;
        sub[i] = true;
        auto sub2 = can;
        sub2 &= bits[i];
        //cerr << "ok : " << vertex << " " << i << endl;
        dfs(sub, sub2, i + 1);
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        A[a][b] = c;
        A[b][a] = c;
        bits[a][b] = true;
        bits[b][a] = true;
    }
    bitset<100> One;
    for(int i = 0; i < N; i++) One[i] = true;
    dfs(Zero, One, 0);
    cout << ans << endl;
    /*
    for(int i = 0; i < N; i++) {
        cerr << bits[i] << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include "string"
using namespace std;
int main() {
    int H,W,K;
    cin >> H >> W >> K;
    char map[H][W];
    for (int i = 0; i < H; ++i) {
        scanf("%s",map[i]);
    }

    int solutions = 0;
    for (int i = 0; i < (1 << H) - 1; ++i) {
        for (int j = 0; j < (1 << W) - 1; ++j) {
            int black = 0;
            for (int k = 0; k < H; ++k) {
                for (int l = 0; l < W; ++l) {
                    if( ( (i>>k)&1 )==0&&((j>>l)&1)==0&&map[k][l]=='#' ){
                        black++;
                    }
                }
            }
            if(black==K){
                solutions++;
            }
        }
    }
    cout << solutions;
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N;
    cin >> N;
    map<int, int> cnt;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        int n = 0;
        while (a % 2 == 0) {
            a /= 2;
            n++;
        }
        n = min(n, 2);
        cnt[n]++;
    }

    if (cnt[0] <= cnt[2]) {
        cout << "Yes" << endl;
    } else if (cnt[0] == cnt[2] + 1 && cnt[0] + cnt[2] == N) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int N;
ll M;
vector<ll> A;

bool judge(ll x) {
    ll cnt = 0;
    for (int i=0; i<N; i++) {
        cnt += N-(int)(lower_bound(A.begin(), A.end(), x-A[i])-A.begin());
    }
    return cnt>=M;
}

ll binary_search() {
    ll l = 0, r = 10000000000;
    while (l<=r) {
        ll mid = (l+r)/2;
        if (judge(mid)) l = mid+1;
        else r = mid-1;
    }
    return r;
}

int main() {
    cin >> N >> M;
    for (int i=0; i<N; i++) {
        ll Ai; cin >> Ai;
        A.push_back(Ai);
    }
    sort(A.begin(), A.end());
    
    vector<ll> acc = {0};
    for (int i=0; i<N; i++) acc.push_back(acc[acc.size()-1]+A[i]);
    
    ll border = binary_search();
    ll cnt = 0, ans = 0;
    
    for (int i=0; i<N; i++) {
        int idx = lower_bound(A.begin(), A.end(), border-A[i]+1)-A.begin();
        cnt += N-idx;
        ans += A[i]*(N-idx)+acc[N]-acc[idx];
    }
    
    ans += border*(M-cnt);
    
    cout << ans << endl;
}


Measured memory_bytes: 2548
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

int calc(int a, int b, char ope)
{
  switch(ope) {
  case '+':
    return a + b;
    break;
  case '-':
    return a - b;
    break;
  case '*':
    return a * b;
    break;
  }
}

string kakko(vector<char> ope, vector<int> val)
{
  ostringstream os;
  os << "(((" << val[0] << " " << ope[0] << " " << val[1] << ")" << " " << ope[1] << " " << val[2] << ")" << " " << ope[2] << " " << val[3] << ")";

  int result = val[0];
  for (int i = 1; i < 4; i++) {
    result = calc(result, val[i], ope[i - 1]);
  }
  if (result == 10) {return os.str();}
  else {
    ostringstream os1;
    os1 << "((" << val[0] << " " << ope[0] << " " << val[1] << ")" << " " << ope[1] << " " << "("<< val[2] << " " << ope[2] << " " << val[3] << "))";
    result = calc(calc(val[0], val[1], ope[0]), calc(val[2], val[3], ope[2]), ope[1]);
    if (result == 10) {return os1.str();}
    else {return "";}
  }
}

int main()
{
  int a[4];
  vector<int> v(4);
  char m[3];
  m[0] = '+', m[1] = '-', m[2] = '*';
  for (int i = 0; i < 4; i++) {
    v[i] = i;
  }

  while (scanf("%d %d %d %d ", a, a + 1, a + 2, a + 3) == 4) {
    if (a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0) {
      break;
    }
    sort(v.begin(), v.end());

    while (next_permutation(v.begin(), v.end())) {
      int x[3];
      for (x[0] = 0; x[0] < 3; x[0]++) {      
	for (x[1] = 0; x[1] < 3; x[1]++) {
	  for (x[2] = 0; x[2] < 3; x[2]++) {
	    vector<char> ope;
	    vector<int> val;
	    for (int i = 0; i < 3; i++) {
	      ope.push_back(m[x[i]]);
	    }
	    for (int i = 0; i < 4; i++) {
	      val.push_back(a[v[i]]);
	    }
	    string str = kakko(ope, val);
	    if (str.size() != 0) {
	      cout << str << endl;
	      goto next;
	    }
	  }
	}
      }
    }
    cout << 0 << endl;
  next:;
  }
}

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

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
typedef long long ll;

using namespace std;

void File(){
	freopen("gkk.in","r",stdin);
	freopen("gkk.out","w",stdout);
}

template<typename T>void read(T &_){
	T __=0,mul=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')mul=-1;
		ch=getchar();
	}
	while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
	_=__*mul;
}

const int maxn=2e5+10;
const int maxm=1e6+10;
int n,q,m;
ll f[maxn];
struct edge{
	int u,v;
	ll w;
	bool operator < (const edge & ano) const {
		return w<ano.w;
	}
}E[maxm];

namespace Kruskal{
	ll ans;
	int fa[maxn];
	int find(int x){return fa[x]==x ? x : fa[x]=find(fa[x]);}
	void work(){
		REP(i,0,n-1)fa[i]=i;
		sort(E+1,E+m+1);
		REP(i,1,m){
			int u=E[i].u,v=E[i].v;
			if(find(u)==find(v))continue;
			fa[find(u)]=find(v);
			ans+=E[i].w;
		}
		printf("%lld\n",ans);
	}
}

int main(){
	//File();
	read(n); read(q);
	memset(f,63,sizeof(f));
	int u,v; ll w;
	REP(i,1,q){
		read(u),read(v),read(w);
		E[++m]=(edge){u,v,w};
		f[u]=min(f[u],w+1);
		f[v]=min(f[v],w+2);
	}
	REP(i,0,2*n-1){
		int pre= !(i%n) ? n-1 : i%n-1;
		f[i%n]=min(f[i%n],f[pre]+2);
	}
	REP(i,0,n-1){
		int nex=(i+1)%n;
		E[++m]=(edge){i,nex,f[i]};
	}
	Kruskal::work();
	return 0;
}

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

using i64 = int64_t;

int main(){
    i64 n, a;
    cin >> n >> a;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 x;
        cin >> x;
        v.push_back(x);
    }
    vector<vector<vector<i64>>> dp(n+1, vector<vector<i64>>(n+1, vector<i64>(2501)));
    dp[0][0][0] = 1;
    for(int i=0;i<n;++i){
        for(int j=0;j<=n;++j){
            for(int k=0;k<=2500;++k){
                dp[i+1][j][k] += dp[i][j][k];
                if(j == n || k+v[i] > 2500)continue;
                dp[i+1][j+1][k+v[i]] += dp[i][j][k];
            }
        }
    }
    i64 ans = 0;
    for(int j=1;j<=n;++j){
        if(a*j > 2500)break;
        ans += dp[n][j][a*j];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 52224
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  
  long long X;
  cin >> X;
  long long Kin = 100;
  long long cnt = 0;
  
  while(Kin < X){
    Kin *= 1.01;
    cnt++;
  }
  
  cout << cnt << endl;
    
  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100005;
int A[N];

int main() {
  int n;
  LL ans = 0;
  S(n);
  LL sm = 0;
  rep(i,0,n) {
    S(A[i]);
    if(!A[i]) {
      ans += sm / 2;
      sm = 0;
    }
    sm += A[i];
  }
  ans += sm / 2;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>P;


int main(){
  ll A,B;
  cin>>A>>B;
  cout<<A*B;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
const int MOD=1e9+7;
ll mod (ll x){
	return (x%MOD+MOD)%MOD;
}
ll add(ll x,ll y){
	return mod(y)+mod(x);
}
ll mul(ll x,ll y){
	return mod(x)*mod(y);
}
void solve(){
	ll n;
	cin>>n;
	vector<ll>a(n+1);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<ll>pre(n+1);
	pre[0]=a[0];
	for(int i=1;i<n;i++)pre[i]=pre[i-1]+a[i];
	ll ans=0;
	for(int i=0;i<n;i++)
		ans=add(ans,mul(a[i],pre[n-1]-pre[i]));
	cout<<ans;
	

}
int main()
{
	Start;

	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout << "\n";
	}
	return 0;
} 

Measured memory_bytes: 6340
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=100011;
int main(){
  int n;
  ll c;
  ll x[maxn],v[maxn],v2[maxn];
  cin>>n>>c;
  ll amax[maxn];
  ll bmax[maxn];
  ll s=0LL;
  ll ans=-1LL;
  amax[0]=0;
  bmax[n+1]=0;
  x[0]=0LL;
  v[0]=0LL;
  x[n]=0LL;
  v[n]=0LL;
  for(int i=1;i<=n;i++){
     cin>>x[i]>>v[i];
     s+=v[i];
     amax[i]=max(amax[i-1],s-x[i]);
     ans=max(ans,amax[i]);
  }
  s=0LL;
  for(int i=n;i>=0;i--){
     s+=v[i];
     bmax[i]=max(bmax[i+1],s-(c-x[i]));
     ans=max(ans,bmax[i]);
  }
 s=0LL;
 for(int i=0;i<n;i++){
   s+=v[i];
   ans=max(ans,bmax[i+1]-2*x[i]+s);

 }
 s=0LL;
 for(int i=n;i>0;i--){
   s+=v[i];
   ans=max(ans,amax[i-1]-2*(c-x[i])+s);
 }


  cout<<ans<<endl;

  
}


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

int main(void) {
  int A, B, C, X, Y;
  cin>>A>>B>>C>>X>>Y;
  if (2*C > A+B) {
    cout<<A*X+B*Y<<endl;
    exit(0);
  }
  
  int M = max(X, Y);
  int m = min(X, Y);
  int cost1 = M*2*C;
  int cost2 = m*2*C + (M-m)*(M == X ? A:B);
  if (cost1 < cost2) cout<<cost1<<endl;
  else cout<<cost2<<endl;
  
  return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = 1; i < b+1; i++){
        int x = a*i % b;
        if(x == 0){
            cout << "NO" << endl;
            return 0;
        }
        if(c % x == 0){
            cout << "YES" << endl;
            return 0;
        }    
        }
    cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long llong;
llong st, ed, now;
int idx;

int main(){
    scanf("%lld %lld", &st, &ed);

    now = st;
    idx = 0;
    while(now <= ed){
        now = now * 2;
        idx += 1;
    }

    printf("%d\n", idx);
}

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

int main() {
    std::string S;

    std::cin >> S;

    auto dist = std::distance(S.begin(), S.end() - 1);

    if(S.at(dist) == 's') {
        S += "es";
    }
    else {
        S += 's';
    }

    std::cout << S << std::endl;

    return 0;
}


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

int main() {
    int n;
    cin>>n;
    long long a[n];
    for(int i=0 ; i<n ; i++)
    cin>>a[i];
    long long dp[n+1][n+1];
    for(int i=n-1 ; i>=0 ; i--){
        for(int j=i ; j<n ; j++){
            if(i==j)
            dp[i][j]=a[j];
            else{
                dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    int n; cin >> n; int s = 0, m = n;
    while(m > 0){
        s += m % 10;
        m /= 10;
    }
    cout << ((n%s == 0)?"Yes":"No") << endl;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
int outedge[100100];//出て行く後退辺
vector<int> G[100100];
vector<int> G2[100100];//後退辺除く

bool used[100100];
int depth[100100];
vector<pii> koutai;
vector<pii> edges;

void dfs1(int v, int p, int d) {
    //cerr << v << " " << p << endl;
    if (used[v]) {
        //cerr << " " << v << " " << p << endl;
        if (depth[v] < depth[p]) {
            //cerr << "  " << v << " " << p << endl;
            //v-pは後退辺
            koutai.emplace_back(v, p);
            //v->pとする
            outedge[v]++;
        }
        return;
    }
    used[v] = true;
    depth[v] = d;
    if (p != -1) {
        G2[v].push_back(p);
        G2[p].push_back(v);
    }
    for (int to:G[v]) {
        if (to == p)continue;
        dfs1(to, v, d + 1);
    }
}

bool dfs2(int v, int p) {
    //cerr << v << " " << p << endl;
    //v->pの場合true
    int cnt = outedge[v];
    for (int to:G2[v]) {
        if (to == p)continue;
        if (!dfs2(to, v)) {
            //子に向かう場合
            cnt++;
        }
    }
    if (cnt % 2 == 0) {
        edges.emplace_back(p, v);
        return false;
    } else {
        edges.emplace_back(v, p);
        return true;
    }
}

signed main() {
    cin >> N >> M;
    if (M % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(0, -1, 0);
    if (dfs2(0, -1)) {
        cout << -1 << endl;
        return 0;
    } else {
        for (pii k:koutai) {
            cout << k.first + 1 << " " << k.second + 1 << endl;
        }
        for (pii e:edges) {
            if (e.first != -1 && e.second != -1) {
                cout << e.first + 1 << " " << e.second + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
int a[26];

int main(){
  string s;
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>s;
    a[s[0]-'A']++;
  }
  int ans=0;
  while(1){
    int m=0;
    sort(a,a+26);
    reverse(a,a+26);
    for(int i=0;i<26;i++){
      if(a[i]==0) continue;
      m++;
      a[i]--;
      if(m==k) break;
    }
    if(m==k) ans++;
    else break;
  }
  cout<<ans<<endl;

  return 0;
}


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

const int INF = 1 << 15;

int main() {
  // input
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int ans = INF;
  rep(div, 1 << (h - 1)) {
    // divid horizontally and format data
    vector<int> id(h);
    int g = 0;
    int count[h][w];
    rep(i, h) rep(j, w) count[i][j] = 0;
    rep(i, h) {
      rep(j, w) count[g][j] += s[i][j] - '0';
      if (div >> i & 1) g++;
    }
    g++;

    // devid vertically
    int now = g - 1;
    int sum[g];
    rep(i, g) sum[i] = 0;
    rep(j, w) {
      rep(i, g) {
        if (count[i][j] > k) {
          now = INF;
          break;
        }
      }
      rep(i, g) sum[i] += count[i][j];
      rep(i, g) {
        if (sum[i] > k) {
          now++;
          rep(i, g) sum[i] = count[i][j];
        }
      }
    }
    ans = min(ans, now);
  }
  cout << ans << endl;

  return 0;
}


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

int main()
{
    int n, i, j;
    cin>>n;

    float arr[n];
    string s[n];
    float sum = 0;

    for(i=0; i<n; i++)
    {
        cin>>arr[i]>>s[i];
    }

    for(i=0; i<n; i++)
    {
        if(s[i] == "BTC")
        {
            sum = sum + arr[i]*380000;
        }
        else if(s[i] == "JPY")
        {
            sum = sum + arr[i];
        }
    }

    cout<<sum;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
    cin>>h[i];
    long long a[n];
    for(int i=0;i<n;i++) a[i]=INT_MAX;
    a[0]=0;
    
    for(int i=1;i<n;i++){
        for(int j=i-1;j>=i-k && j>=0;j--)
            a[i]=min(a[i],a[j]+abs(h[i]-h[j]));
    }
    /*
    for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
    cout<<endl;
    */
    cout<<a[n-1]<<endl;
    
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

char buf[301],left_buf[301],right_buf[301],ans[301];
int dp[301][301],memo[301][301];

void func(){

	int length,right_length;
	for(length = 0; buf[length] != '\0'; length++);

	int ans_length = 0;

	for(int left_length = 1; left_length <= length-1; left_length++){
		left_buf[left_length-1] = buf[left_length-1];
		right_length = length - left_length;
		for(int i = 0; left_length+i < length; i++){
			right_buf[i] = buf[left_length+i];
		}

		for(int a = 0; a <= length; a++){
			for(int b = 0; b <= length; b++)dp[a][b] = 0;
		}

		for(int i = 0; i < left_length; i++){
			for(int k = 0; k < right_length; k++){
				if(left_buf[i] == right_buf[k]){
					dp[i+1][k+1] = dp[i][k]+1;
					memo[i+1][k+1] = 0;
				}else{
					if(dp[i][k+1] >= dp[i+1][k]){
						dp[i+1][k+1] = dp[i][k+1];
						memo[i+1][k+1] = 1;
					}else{
						dp[i+1][k+1] = dp[i+1][k];
						memo[i+1][k+1] = -1;
					}
				}
			}
		}


		if(ans_length < dp[left_length][right_length]){
			ans_length = dp[left_length][right_length];

			stack<char> S;

			for(int i = left_length,k = right_length; i > 0 && k > 0;){

				if(memo[i][k] == 1){
					i--;
				}else if(memo[i][k] == -1){
					k--;
				}else{ //memo[i][k] == 0
					S.push(left_buf[i-1]);
					i--;
					k--;
				}
			}

			int index = 0;
			while(!S.empty()){
				ans[index++] = S.top();
				S.pop();
			}
		}
	}

	for(int i = 0; i < ans_length; i++)printf("%c",ans[i]);
	printf("\n");
}

int main(){

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3784
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int main(void) {
	int H, W;
	vector<string> S;
	vector<string> A;
	cin >> H >> W;
	S.resize(H);
	A.resize(H);
	REP(i, H) cin >> S[i];
	REP(i, H) A[i].resize(W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				A[i][j] = '#';
			}
			else {
				int cnt = 0;
				for (int k = max(0, i - 1); k < min(H, i + 2); k++) {
					for (int l = max(0, j - 1); l < min(W, j + 2); l++) {
						if (k == i && l == j) continue;
						if (S[k][l] == '#') cnt++;
					}
				}
				A[i][j] = '0' + cnt;
			}
		}
	}
	REP(i, H) cout << A[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1e7
int main(){
    int n;
    while(cin >> n,n){
        int ans = 0;
        while (true) {
            if(n ==1) break;
            if(n %2 == 1)
            { n*=3; n+=1; ans++;}
            if(n % 2 == 0)
            {n = n/2; ans++;}
        }
        cout << ans << endl;
            }
}

Measured memory_bytes: 2988
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];

	int ans = 0;

	rep(i, n) {
		if (p[i] == (i + 1)) {
			ans++;
			if (i != n - 1 && p[i + 1] == (i + 2)) i++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(X,Y) for(int X=0;X<(Y); ++X)
#define pb push_back
#define eb emplace_back

using namespace std;

typedef long long ll;

string fun(string s){
  string re;
  for(char c:s)
    if(c=='b') re+=c;
    else re+=string(c-'0','.');
  return re;
}

string zip(string s){
  string re;
  int cnt=0;
  for(char c:s){
    if(c=='.'){
      ++cnt;
    }else{
      if(cnt) re+=char('0'+cnt);
      re+='b';
      cnt=0;
    }
  }
  if(cnt) re+=char('0'+cnt);
  return re;
}

int main(){
  string s;
  while(cin>>s, s!="#"){
    s+='/';
    int n=s.size();
    int x,y,X,Y;
    cin>>y>>x>>Y>>X; --x; --y; --X; --Y;
    vector<string> mp;
    string tmp;
    for(char c:s){
      if(c=='/'){
	mp.pb(fun(tmp));
	tmp="";
      }else{
	tmp+=c;
      }
    }
    //for(string s:mp) cout<<s<<endl;
    mp[y][x]='.';
    mp[Y][X]='b';
    rep(i,mp.size()) cout<<zip(mp[i])<<"/\n"[i+1==mp.size()];
  }
  return 0;
}

Measured memory_bytes: 3164
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

if K%2 == 0:
	print((K//2)**2)
else:
	print(((K-1)//2)*(((K-1)//2)+1))


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

typedef long long ll;
const int N = 505;
int n;
ll inf, v1[N][N], v2[N][N], f[N][N];
ll get(ll v[N][N], int x1, int x2, int y1, int y2) {
  return v[x2][y2] - v[x1][y2] - v[x2][y1] + v[x1][y1];
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      scanf("%lld", &v1[j][i]);
    }
    for (int j = i + 1; j <= n; j++) {
      scanf("%lld", &v2[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      v1[i][j] = v1[i][j] + v1[i - 1][j] + v1[i][j - 1] - v1[i - 1][j - 1];
      v2[i][j] = v2[i][j] + v2[i - 1][j] + v2[i][j - 1] - v2[i - 1][j - 1];
    }
  }
  memset(f, 0x3f, sizeof f);
  inf = f[0][0];
  f[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i + !i; j++) if (f[i][j] != inf) {
      for (int k = i + 1; k <= n; k++) {
        f[k][i] = min(f[k][i], f[i][j] + get(v1, j, i, k, n) + get(v2, i, k, i, k));
      }
    }
  }
  ll ans = inf;
  for (int j = 0; j < n; j++) {
    ans = min(ans, f[n][j]);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 6272
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

main(){
  int x[100],y[100],i=0,k=0,j=0,tasu=0,hiku=0,kakeru=1,l;
  char s[101];

  while( scanf("%s",s) != EOF ){


    if ( s[0] == '+' ){
      y[k-2]=y[k-1]+y[k-2];
      k=k-2;
      k=k+1;
      //printf("%d\n",y[k-2]);
    } 
    else if ( s[0] == '-' ){
      y[k-2]=y[k-2]-y[k-1];
      k=k-2;
      k=k+1;
    }
    else if ( s[0] == '*' ){
      y[k-2]=y[k-2]*y[k-1];
      k=k-2;
      k=k+1;
    }
    else {
      y[k] = atoi(s);
      k=k+1;
      //  printf("%d  %d\n",y[k-1],k);
  }
    i=i+1;
    //printf("%d",i);
  }
  printf("%d\n",y[k-1]);
 
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  int ans = c - (a-b);
  if( ans < 0) cout << 0 << endl;
  else cout << ans << endl;
  return 0;

}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
int a[200005];
int b[200005];
using namespace std;
int main() {
	int k, n;
	cin >> k >> n;
	for (int i = 0;i < n;i++) cin >> a[i];
	int tp;
	for (int i = 0;i < n;i++) {
		if (i == 0) {
			b[i] = min(k - a[n - 1] + a[0], k - a[i + 1] + a[i]);
		}
		if (i < n - 1) {
			b[i] = min(k - a[i] + a[i - 1], k - a[i + 1] + a[i]);
		}
		if (i == n - 1) {
			b[i] = min(k - a[i + 1] + a[i], a[n - 1] - a[0]);
		}
	}
	tp = b[0];
	for (int i = 0;i < n;i++) { tp = min(tp, b[i]); }
	cout << tp << endl;
	return 0;
}

Measured memory_bytes: 1792