akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int N, Y;
void input()
{
    cin >> N >> Y;
}

void solve()
{
    int ten = Y / 10000, five = (Y % 10000) / 5000, one =  (Y % 5000) / 1000;
    // cout << "first: " << ten << " " << five << " " << one << endl;
    for (int i = 0; i <= ten; ++i){
        for (int j = 0; j <= five + 2*i; ++j){
            // cout << ten-i << " " << five+2*i-j << " " << one+5*j << endl;
            if (ten + five + one + i + 4*j == N){
                cout << ten - i << " " << five + 2*i - j << " " << one + 5*j << endl;
                return;
            }
        }
    }

    cout << "-1 -1 -1 " << endl;
    return;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3656
#64 三角形

a, b, c= map(int, input().split())

import math
h = b*math.sin(math.radians(c))
cosc = math.cos(math.radians(c))

S = a*h*(1/2) 

d = math.sqrt((a-(b*cosc))**2 + h**2)

L = a + b + d

print(S)
print(L)
print(h)


Measured memory_bytes: 5708
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333
#define Mo 998244353

using namespace std;
int i,j,m,n,p,k,a[N],A[N],d;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;++i) scanf("%d",&a[i]),A[a[i]]++;
	sort(a+1,a+n+1); d=a[n]+1;
	if (n==1)
	{
			puts(a[1]==0?"Possible":"Impossible");
			return 0;
	}
	if (A[0])
	{
		 puts("Impossible");
		 return 0;
	}
	for (i=a[n];i;--i)
	{
			if (d==1) 
			{
				if (A[i]==1)
				{
					for (j=i-1;j;--j) if (A[j]) break;
					if (j) puts("Impossible");
					else 
					puts("Possible");
				}
				else 
					puts("Impossible");
				return 0;
			}
			if (d==2)
			{
				if (A[i]==2)
				{
					for (j=i-1;j;--j) if (A[j]) break;
					if (j) puts("Impossible");
					else 
					puts("Possible");
				}
				else 
					puts("Impossible");
				return 0; 
			}
			if (A[i]<2)
			{
					puts("Impossible");
					return 0;
			}
			d-=2;
	}
}


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

int main(){
	string s; cin >> s;
	cout << (s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I' ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
N=int(input())
L=[]
count=0
for i in range (N):
	L.append(input())
if len(set(L))!=N:
	print("No")
else:
	for i in range (N-1):
		if L[i][-1]!=L[i+1][0]:
			count+=1
	if count==0:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int i,j,m,n,s,w,p,max,a[10000],b[10000],c[10000],d[10000];
    while(scanf("%d",&n)!=EOF)
    {
        s=0;
        for(i=0;i<n;i++)
            scanf("%d %d",&a[i],&b[i]);
        for(i=0;i<n;i++)
            scanf("%d %d",&c[i],&d[i]);
        for(i=0;i<n-1;i++)
            for(j=0;j<n-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                p=a[j];
                a[j]=a[j+1];
                a[j+1]=p;
                p=b[j];
                b[j]=b[j+1];
                b[j+1]=p;
            }
        }
        for(i=0;i<n-1;i++)
            for(j=0;j<n-i-1;j++)
        {
            if(c[j]>c[j+1])
            {
                p=c[j];
                c[j]=c[j+1];
                c[j+1]=p;
                p=d[j];
                d[j]=d[j+1];
                d[j+1]=p;
            }
        }
        for(i=0;i<n;i++)
        {
            p=-1;
            max=-1;
            for(j=0;j<n;j++)
            {
                if(a[j]<c[i]&&b[j]<d[i]&&b[j]>max&&a[j]!=-1&&b[j]!=-1)
                {
                    max=b[j];
                    p=j;
                }
                if(a[j]>c[i])
                   break;
            }
            if(p!=-1)
            {
                s++;
                a[p]=-1;
                b[p]=-1;
            }
        }
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 256
s=input()
t=input()
sm=0
ss=[]
for i in s:
  sm+=(i=="A")*2-1
  ss.append(sm)
ss.append(0)
sm=0
ts=[]
for i in t:
  sm+=(i=="A")*2-1
  ts.append(sm)
ts.append(0)
q=int(input())
for i in range(q):
  inp=list(map(int,input().split()))
  if (ss[inp[1]-1]-ss[inp[0]-2])%3==(ts[inp[3]-1]-ts[inp[2]-2])%3:
    print("YES")
  else:
    print("NO")
  

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

ll dp[101][100001];

int main(){
  ll N,W;
  cin>>N>>W;
  ll w[N+1],v[N+1];
  for(int i=1;i<=N;i++)cin>>w[i]>>v[i];
  for(int i=1;i<=N;i++){
    for(int j=1;j<=W;j++){
      dp[i][j]=max(dp[i][j],(j<w[i] ? dp[i-1][j] : max(dp[i-1][j],dp[i-1][j-w[i]]+v[i])));
    }
  }
  cout<<dp[N][W]<<endl;
}


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

int main() { 
    string s, s_f, s_l, s_;
    cin >> s;
    int n, t, f, r = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> t;
        if(t == 1) {
            if(r) r = 0;
            else r = 1;
        } else {
            cin >> f >> s_;
            if(f == 1) {
                if(r == 0) {
                    s_f += s_;
                } else {
                    s_l += s_;
                }
            } else {
                if(r == 0) {
                    s_l += s_;
                } else {
                    s_f += s_;
                }
            }
        }
    }
    if(r == 1) {
        for(int i = s_l.size()-1; i >= 0; --i) {
            cout << s_l[i];
        }
        for(int i = s.size()-1; i >= 0; --i) {
            cout << s[i];
        }
        cout << s_f;
    } else {
        for(int i = s_f.size()-1; i >= 0; --i) {
            cout << s_f[i];
        }    
        cout << s << s_l;
    }
    cout << '\n';
    
    return 0;
}


Measured memory_bytes: 1088
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * 1 2 3 4 5 6 7 8 9
 * If I fix the two segments
 */
const int LOG = 20;
const int N = (1 << LOG) + 5;
vector <ll> tree1(N), tree2(N), cnt1(N), cnt2(N);
ll getsum(int id, vector<ll> &tree) {
	ll res = 0;
	while(id > 0) {
		res += tree[id];
		id -= (id & -id);
	}
	return res;
}
void update(int id, int val, vector<ll>&tree) {
	while(id < N) {
		tree[id] += val;
		id += (id & -id);
	}
}
int main() {
	int n;
	cin >> n;
	vector <int> A(3 * n + 1);
	pair <int, int> B[3 * n + 1];
	for (int i = 1; i <= 3 * n; i++) {
		cin >> A[i];
		B[i] = {A[i], i};
	}
	sort(B + 1, B + 3 * n + 1);
	vector <int> mp(3 * n + 1);
	for (int i = 1; i <= 3 * n; i++) {
		mp[B[i].ss] = i;
	}
	for (int i = 1; i <= 3 * n; i++) {
		update(mp[i], 1, cnt2);
		update(mp[i], A[i], tree2);
	}
	ll ans = -INF;
	for (int i = 1; i <= 3 * n; i++) {
		// remove from the 2nd segment
		update(mp[i], -1, cnt2);
		update(mp[i], -A[i], tree2);
		// add to the 1st segment
		update(mp[i], 1, cnt1);
		update(mp[i], A[i], tree1);
		
		if (i < n || i > 2 * n) continue;
		
		int rem1 = i - n;
		int taken1 = 0;
		for (int j = LOG - 1; j >= 0; j--) {
			if (getsum(taken1 + (1 << j), cnt1) <= rem1) {
				taken1 += (1 << j);
			}
		}
		ll sum1 = getsum(N - 1, tree1) - getsum(taken1, tree1);
		int rem2 = n;
		int taken2 = 0;
		for (int j = LOG - 1; j >= 0; j--) {
			if (getsum(taken2 + (1 << j), cnt2) <= rem2) {
				taken2 += (1 << j);
			}
		}
		ll sum2 = getsum(taken2, tree2);
		//cout << i << " " << sum1 << " " << sum2 << "\n";
		ans = max(ans, sum1 - sum2); 
	}
	cout << ans;
}


Measured memory_bytes: 39680
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#include <queue>
#include <stack>
#define mod 998244353
#define pb(x) push_back(x)
#define N 110000
using namespace std;
int a[N],ansp[N];
int father[N],minvalue[N],place[N];
int n,m,tot,cnt;
int v[N];
long long ans;
int getfather(int x)
{
    if (father[x]==x)return x;
    else return father[x]=getfather(father[x]);
}
void init()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)father[i]=i;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x++; y++;
        int t1=getfather(x);
        int t2=getfather(y);
        father[t1]=getfather(t2);
    }   
}
int main()
{
    init();
    int inf=1000000001;
    for(int i=1;i<=n;i++)minvalue[i]=inf;
    for(int i=1;i<=n;i++)
    {
        int u=getfather(i);
        if(!v[u])cnt++;
        v[u]=1;
        if(minvalue[u]-a[i]>0)
        {
            place[u]=i;
            minvalue[u]=a[i];
        }
    }
    for(int i=1;i<=n;i++)
    {
        int x=getfather(i);
        if(place[x]==i)ans+=a[i];
        else ansp[++tot]=a[i];
    }
    if(cnt==1)
    {
        puts("0");
        return 0;
    }
    if(tot<cnt-2)
    {
        puts("Impossible");
        return 0;
    }
    sort(ansp+1,ansp+tot+1);
    for(int i=1;i<=cnt-2;i++)ans+=ansp[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))
B = [0 for k in range(100002)]

for k in A:
    B[k] += 1

ans = 0
for k in range(1,100001):
    ans = max(ans,B[k-1]+B[k]+B[k+1])

print(ans)

Measured memory_bytes: 13964
def main():
    n = int(input())
    if n % 2 == 0:
        ans = []
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        if n >= 6:
            ans.append([1, n//2])
            ans.append([1, n//2+1])
            ans.append([n, n//2])
            ans.append([n, n//2+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)
    else:
        ans = []
        n -= 1
        for i in range(1, n//2):
            ans.append([i, i+1])
            ans.append([i, n-i])
            ans.append([n-i+1, i+1])
            ans.append([n-i+1, n-i])
        ans.append([1, n+1])
        ans.append([n, n+1])
        if n >= 4:
            ans.append([n//2, n+1])
            ans.append([n//2+1, n+1])
        print(len(ans))
        for p, q in ans:
            print(p, q)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int n, m;
vector<vector<int>> g;
ll dp[101010];

// まず1つの頂点について求める
ll dfs(int v, int p) {
    ll res = 1;
    for(const auto &u : g[v]) {
        if(u != p) {
            (res *= (dfs(u, v) + 1) % m) %= m;
        }
    }
    return dp[v] = res;
}

ll ans[101010];

// 次に任意の頂点について求める
void dfs2(int v, int p) {
    int sz = g[v].size();
    ans[v] = dp[v];
    vector<ll> lsum(sz + 1, 1), rsum(sz + 1, 1);
    for(int i = 0; i < sz; i++) {
        (lsum[i + 1] *= (lsum[i] * (dp[g[v][i]] + 1) % m)) %= m;
    }
    for(int i = sz - 1; i >= 0; i--) {
        (rsum[i] *= (rsum[i + 1] * (dp[g[v][i]] + 1) % m)) %= m;
    }
    for(int i = 0; i < sz; i++) {
        int u = g[v][i];
        if(u != p) {
            ll pre = lsum[i] * rsum[i + 1] % m;
            ll tmp1 = dp[v], tmp2 = dp[u];
            dp[v] = pre;
            (dp[u] *= (dp[v] + 1)) %= m;
            dfs2(u, v);
            dp[v] = tmp1;
            dp[u] = tmp2;
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    g.resize(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(0, -1);
    dfs2(0, -1);
    for(int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 20864
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int bsUpperNums(vector<int>& v, int target) {
  int ret = -1;

  int l = 0, u = v.size() - 1;
  while (l <= u) {
    int m = (l + u) / 2;

    if (target < v[m]) {
      u = m - 1;
    } else {
      ret = max(m, ret);
      l = m + 1;
    }
  }

  return v.size() - (ret + 1);
}

int bsUpperMin(vector<int>& v, int target) {
  int ret = v.size();

  int l = 0, u = v.size() - 1;
  while (l <= u) {
    int m = (l + u) / 2;

    if (target < v[m]) {
      ret = min(ret, m);
      u = m - 1;
    } else {
      l = m + 1;
    }
  }

  return ret;
}

void readN(int n, vector<int>& v) {
  int val;

  for (int i = 0; i < n; i++) {
    cin >> val;
    v[i] = val;
  }
}

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

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  readN(n, a);
  readN(n, b);
  readN(n, c);

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  vector<int> bcComb(n);

  for (int i = 0; i < n; i++) {
    int res = bsUpperNums(c, b[i]);
    bcComb[i] = res;
  }

  vector<unsigned long long> bcTotal(n);

  bcTotal[n - 1] = bcComb[n - 1];
  for (int i = n - 2; 0 <= i; i--) {
    bcTotal[i] += bcComb[i] + bcTotal[i + 1];
  }

  unsigned long long ret = 0;

  for (int i = 0; i < n; i++) {
    int idx = bsUpperMin(b, a[i]);
    if (idx == b.size())
      continue;

    ret += bcTotal[idx];
  }

  cout << ret;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  while(k){
    if(a%2==1)a--;
    a/=2;
    b+=a;
    k--;
    if(k==0)break;
    if(b%2==1)b--;
    b/=2;
    a+=b;
    k--;
    if(k==0)break;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;
void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif // DBG
}


void solve() {
	int n, p[200001], index[200001];
	scanf("%d", &n);
	p[0] = 0;
	for (int i = 1; i <= n; i++)
		scanf("%d", p + i);
	index[0] = 0;
	for (int i = 1; i <= n; i++)
		index[p[i]] = i;
	int score = 1, carry = 1;
	for (int i = 2; i <= n; i++) {
		if (index[i - 1] < index[i]) {
			carry++;
			score = max(score, carry);
		}
		else {
			carry = 1;
		}
	}
	printf("%d\n", n - score);
}

Measured memory_bytes: 1664
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
using namespace std;

bool a[100][100];
int w, h, n, x, y, m, i, j, c;

int main()
{
    sf("%d%d%d", &w, &h, &n);
    while (n--) {
        sf("%d%d%d", &x, &y, &m);
        switch (m) {
            case 1:
                for (i = 0; i < x; i++) {
                    for (j = 0; j < h; j++) {
                        a[i][j] = 1;
                    }
                }
                break;
            case 2:
                for (i = x; i < w; i++) {
                    for (j = 0; j < h; j++) {
                        a[i][j] = 1;
                    }
                }
                break;
            case 3:
                for (i = 0; i < w; i++) {
                    for (j = 0; j < y; j++) {
                        a[i][j] = 1;
                    }
                }
                break;
            case 4:
                for (i = 0; i < w; i++) {
                    for (j = y; j < h; j++) {
                        a[i][j] = 1;
                    }
                }
                break;
        }
    }
    for (i = 0; i < w; i++) {
        for (j = 0; j < h; j++) {
            if (a[i][j] == 0) c++;
        }
    }
    pf("%d\n", c);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
//i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >> n;
    string v;
    while(n>0) {
        char c = 'a'-1;
        int rem = n%26;
        n /=26;
        if (!rem) {
            rem = 26;
            --n;
        }
        c = c + rem;
        v += c;
    }

    reverse(v.begin(), v.end());

    cout << v << endl;
    return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
T LCM(T a, T b) {
	return a / GCD(a, b) * b;
}
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	string s, t, g;
	cin >> s >> t >> g;

	cout << char(s[0] - 0x20) << char(t[0] - 0x20) << char(g[0] - 0x20) << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;


int _=[](){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

int main() {
    int n,w;
    cin>>n>>w;
    vector<pair<ll,ll>> v;
    for(int i=0;i<n;i++)
    {
        ll w1,v1;
        cin>>w1>>v1;
        v.push_back(make_pair(w1,v1));
    }
    vector<vector<ll>> answer(n+1,vector<ll>(w+1,0));
    
    for(int i=1;i<=n;i++)
        for(int j=0;j<=w;j++)
            {
                ll value = v[i-1].second, weight = v[i-1].first;
                if(j<weight)    answer[i][j] = answer[i-1][j];
                else    answer[i][j] = max(answer[i-1][j], answer[i-1][j-weight]+value);
                
            }
    cout<<answer[n][w]<<endl;
}

Measured memory_bytes: 80256
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	s, t = rll()[0], rll()[0]
	m, n = len(s), len(t)
	dp = [[0 for __ in range(n)] for _ in range(m)]
	dp[0][0] = 1 if s[0] == t[0] else 0
	for r in range(1, m):
		dp[r][0] = max(dp[r-1][0], 1 if s[r] == t[0] else 0)
	for c in range(1, n):
		dp[0][c] = max(dp[0][c-1], 1 if s[0] == t[c] else 0)
	for r in range(1, m):
		for c in range(1, n):
			dp[r][c] = max(dp[r-1][c], dp[r][c-1])
			if s[r] == t[c]:
				dp[r][c] = max(dp[r][c], 1 + dp[r-1][c-1])
	ans = deque()
	r, c = m-1, n-1
	while r >= 0 and c >= 0:
		if s[r] == t[c]:
			ans.appendleft(s[r])
			r -= 1
			c -= 1
		else:
			U = dp[r-1][c] if r > 0 else NINF
			L = dp[r][c-1] if c > 0 else NINF
			if L >= U:
				c -= 1
			else:
				r -= 1
	print("".join(x for x in ans))
	stdout.close()

if __name__ == "__main__":
	main()

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

int main(void)
{
	char s[13];
	int i;
	scanf("%s",s);
	
	for(i=0;i<4;i++){
		printf("%c",s[i]);
	}
	
	printf(" ");
	
	for(i=4;i<12;i++){
		printf("%c",s[i]);
	}
	
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
//  .:::.   .:::.
// :::::::.:::::::
// :::::::::::::::
// ':::::::::::::'
//   ':::::::::'
//     ':::::'
//       ':'
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
using namespace std;
ll dp[100001];
int main()
{
    FIO;
    ll t, q, maxx, n, k, i, j, k1, k2, k3, x, flag, ans, sum, cnt, prev;
    cin>>n>>k;
    vll v(n);
    rep(i,0,n)
    {
        cin>>v[i];    
    }
    FILL(dp, INF, ll);
    dp[0] = 0;
    rep(i,0,n)
    {
        rep(j,1,k + 1)
        {
            if( i - j >= 0)
            {
                dp[i] = min(dp[i],dp[i-j] + abs(v[i] - v[i-j]) );
                // cout<<dp[i-j] + abs(v[i] - v[i-j])<<" ";
            }
        }
        // cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
    return 0;    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(void){
  int n;
  cin>>n;
  vector<int> p(n);
  vector<int> s(n);

  r(i,n){
    cin>>p.at(i);
  }
  s=p;
  sort(p.begin(),p.end());
  int cnt=0;
  r(i,n){
    if(p.at(i)!=s.at(i))cnt++;
  }
  if(cnt>2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;




  return 0;
}


Measured memory_bytes: 256
s=input()

r=len(s)

if r%2==0:
  n=0
  for i in range(int(r/2)):
    if s[i]!=s[r-i-1]:
      n=n+1
  print(n)
else:
  n=0
  for i in range(int((r-1)/2)):
    if s[i]!=s[r-i-1]:
      n=n+1
  print(n)
    
      

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> cake(T);
    rep(i, T) cin >> cake[i];
    int ma = 0, sum = 0;
    rep(i, T) {
        sum += cake[i];
        ma = max(ma, cake[i]);
    }
    cout << max(0, ma - (sum - ma + 1)) << endl;
    return 0;
}

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

# 作れるか判定
def check(goal,ac,bd):
    flag = 0
    for x in range(int(goal//ac)+1):
            if (goal-ac*x)%bd == 0 : flag = 1 ; break
    return flag

# 水W、砂糖Sをまわす
anss = []
for w in range(100,f+1,100):
    for s in range(1,f-w+1):
        if check(w,100*a,100*b) and check(s,c,d) and s<=((w*e)/100):
            conc = 100*s/(w+s) # concentration
            anss.append([conc,w,s])

anss.sort(reverse=1)
if anss: w,s = anss[0][1],anss[0][2]
else: w,s = 100*a,0
print(w+s,s)


Measured memory_bytes: 45788
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	cout << in() / 3 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <cmath>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

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

    vvi x(n);
    for (int i = 0; i < n; i++)
    {
        vi p(d);
        for (int j = 0; j < d; j++)
        {
            cin >> p[j];
        }
        x[i] = p;
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int d2 = 0;
            for (int k = 0; k < d; k++)
            {
                d2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int d = sqrt(d2);
            if (d * d == d2)
            {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

string makestr(int L, string s, string t){

  int p = s.size();
  int q = t.size();
  int tt = 0;
  
  while(L%p){
    L -= q;
    tt++;
  }

  string ans;

  while(L){
    L -= p;
    ans += s;
  }

  while(tt--){
    ans += t;
  }

  return ans;
}

int main(){
  int L;
  string s,t;
  int m,n;

  cin >> L >> s >> t;

  string a = makestr(L, s, t);
  string b = makestr(L, t, s);

  assert(a.size() == L);
  assert(b.size() == L);
  
  cout << min(a,b) << endl;
  
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  int K;
  cin >> K;
  long long s = 0;
  vector<int> r(K);
  int cnt = 0;

  while(1) {
    cnt++;
    int rest = (s*10+7)%K;
    if(rest == 0) {
      cout << cnt << endl;
      return 0;
    }

    if(r[rest] != 0) {
      cout << -1 << endl;
      return 0;
    }

    r[rest]++;
    s = (s*10+7)%K;
  }


}


Measured memory_bytes: 7064
N = int(input())

x = [0] * N
u = [0] * N

for i in range(N):
    x[i], u[i] = input().split()
    x[i] = float(x[i])
    
for i in range(N):
    if u[i] == "BTC":
        x[i] = x[i] * 380000.0
        
print(sum(x))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, x, y;
    cin >> n;
    x = 800 * n;
    y = n / 15 * 200;
    cout << x - y << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	char a[20];
	int i;
	cin >> a;
	a[5]=' ';
	a[13]=' ';
	for(i=0;i<5;i++)
	{
		cout << a[i];
	}
	cout << ' ';
	for(i=6;i<13;i++)
	{
		cout << a[i];
	}
	cout << ' ';
	for(i=14;i<19;i++)
	{
		cout << a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007



void Solve()
{
	ll n;
	cin>>n;
	
	string s;
	cin>>s;
	
	v(ll) r,g,b;
	
	f(i,0,n-1)
	{
		if(s[i]=='R')r.pub(i);
		if(s[i]=='G')g.pub(i);
		if(s[i]=='B')b.pub(i);
	}
	ll ans=0;
	
	fe(x,r)
	{
		fe(y,g)
		{
			if(y>x)
			{
			ll dif=y-x;
			auto x1= ub(b,y);
			if(x1!=b.E)
			{
				ans += ( b.sz-(x1-b.B));
				if( y+dif<=n-1 && s[y+dif]=='B')ans--;	
				
			}
			}
		}
		
		fe(y,b)
		{
			if(y>x)
			{
			ll dif=y-x;
			auto x1= ub(g,y);
			if(x1!=g.E)
			{
				ans += ( g.sz-(x1-g.B));
				if( y+dif<=n-1 && s[y+dif]=='G')ans--;	
			}
		}
		}		
	}
	
	fe(x,g)
	{
		fe(y,r)
		{
			if(y>x)
			{
			ll dif=y-x;
			auto x1= ub(b,y);
			
			if(x1!=b.E)
			{
				ans += ( b.sz-(x1-b.B));
				if(y+ dif<=n-1 && s[y+dif]=='B')ans--;	
			}
		}
		}
		
		fe(y,b)
		{
			if(y>x)
			{
				
			ll dif=y-x;
			auto x1= ub(r,y);
			if(x1!=r.E)
			{
				ans += ( r.sz-(x1-r.B));
				if(y+ dif<=n-1 && s[y+dif]=='R')ans--;	
			}
		}
		}		
	}
	
	fe(x,b)
	{
		fe(y,g)
		{
			if(y>x)
			{
			ll dif=y-x;
			auto x1= ub(r,y);
			if(x1!=r.E)
			{
				ans += ( r.sz-(x1-r.B));
				if( y+dif<=n-1 && s[y+dif]=='R')ans--;	
			}
		}
		}
		
		fe(y,r)
		{
			if(y>x)
			{
			ll dif=y-x;
			auto x1= ub(g,y);
			if(x1!=g.E)
			{
				ans += ( g.sz-(x1-g.B));
				if( y+dif<=n-1 && s[y+dif]=='G')ans--;	
			}
		}
		}		
	}
	
	cout<<ans;
	
}


signed main() 
{
	speed		
		
	ll q=1;	
	//cin>>q;	
	
	while(q--)	
	Solve();	
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 3700
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main2():
    numbers=[]
    N = int(input())
    numbers=list(map(int,input().split()))
    n=1

#条件が1<=n<=200kのため1から順に数えてlist内を調査した場合の最大値+1をnに記入
    for x in numbers:
        if x ==n:
            n+=1

#条件から+1まで数えてしまうため、nを+1して調整
    answer = N - n +1

    if answer==N:
        answer=-1
    print(answer)

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    buffer=[0]
    for i in range(1,n+1):
        search_range=numbers[i-1:]
        out_range=len(numbers[:i-1])
        if i not in search_range and len(buffer)==1:
            print(-1)
            exit()
        elif i not in search_range or i==n:
            break
        else:
            index=search_range.index(i)
            buffer.append(index-sum(buffer))
    print(sum(buffer))

if __name__=="__main__":
    main2()

Measured memory_bytes: 32404
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i];
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[a[i] - 1];
    if (a[i] == a[i - 1] + 1) ans += c[a[i - 1] - 1];
  }
  cout << ans << endl;
  return 0;
}

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

vector<int> l_seq;

int main() {
    int N, K, l;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> l;
        l_seq.push_back(l);
    }
    sort(l_seq.begin(), l_seq.end());
    reverse(l_seq.begin(), l_seq.end());
    int ans = 0;
    for (int i = 0; i < K; i++) ans += l_seq[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)	for(int i=0;i<n;i++)
using namespace std;
void print(vector< long long int > &v){
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //write your code here
		int h, w;
		cin>> h>> w;
		vector<string> v(h,"");
		rep(i, h)	cin>>v[i];
		vector<vector<long long int > > dp(h, vector<long long int > (w,0));
		rep(i,h){
			if(v[i][0]=='.')
				dp[i][0]=1;
			else
				break;
		}
		rep(i,w){
			if(v[0][i]=='.')
				dp[0][i]=1;
			else
				break;
		}
		for(int i=1;i<h;i++){
			for(int j=1;j<w;j++){
				if(v[i][j]=='.'){
					int up = (v[i-1][j]=='.')?dp[i-1][j]:0;
					int left = (v[i][j-1]=='.')?dp[i][j-1]:0;
					dp[i][j]= (up%1000000007+left%1000000007)%1000000007;
				}
			}
		}
		cout<<dp[h-1][w-1]<<endl;

    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <stack>
#include <cassert>
using namespace std;

int N;
string S;

int main(){
    while(cin >> N && N){
        stack<char> op;
        stack<int> num;
        for(int i=0;i<N;i++){
            cin >> S;
            while(S.size()<=op.size()){
                int t = num.top(); num.pop();
                op.pop();
                int s = num.top(); num.pop();
                if(op.top()=='+') s += t;
                else s *= t;
                num.push(s);
            }
            if(S[op.size()]=='+'){
                op.push('+'); num.push(0);
            }else if(S[op.size()]=='*'){
                op.push('*'); num.push(1);
            }else{
                int t = S[op.size()]-'0';
                if(num.empty()) num.push(t);
                else{
                    int s = num.top(); num.pop();
                    if(op.top()=='+') s += t;
                    else s *= t;
                    num.push(s);
                }
            }
        }
        while(!op.empty()){
            int t = num.top(); num.pop();
            op.pop();
            if(num.empty()){
                num.push(t); break;
            }
            int s = num.top(); num.pop();
            if(op.top()=='+') s += t;
            else s *= t;
            num.push(s);
        }
        assert(num.size()==1);
        cout << num.top() << endl;
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    LL n, a, b;
    cin >> n >> a >> b;
    LL tot = a + b;
    LL sec = n / tot;
    LL rem = n % tot;
    LL ans = (sec * a) + (a > 0 ? min(a, rem) : 0);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void) {
    int h, m, s, cur_sec, remaining;
    while (scanf("%d%d%d", &h, &m, &s) == 3 &&
           h != -1 && m != -1 && s != -1) {
        cur_sec = h * 3600 + m * 60 + s;
        remaining = 2 * 3600 - cur_sec;
        printf("%02d:%02d:%02d\n",
               remaining / 3600,
               (remaining % 3600) / 60,
               remaining % 60);
        remaining *= 3;
        printf("%02d:%02d:%02d\n",
               remaining / 3600,
               (remaining % 3600) / 60,
               remaining % 60);
    }

    return 0;
}

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

typedef long long ll;
typedef double keytype;

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main(){
    int n, m, x;
    int a[100];

    scanf("%d %d %d", &n, &m, &x);
    for(int i = 0; i < m; ++i){
        scanf("%d", &a[i]);
    }

    int cnt_down = 0, cnt_up = 0;
    for(int i = 0; i < m; ++i){
        if(x > a[i]) cnt_down++;
        else cnt_up++;
    }

    if(cnt_down < cnt_up) printf("%d\n", cnt_down);
    else printf("%d\n", cnt_up);

    return 0;
}


Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>

using namespace std;

char arr[100];

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

    scanf("%s", arr);
    if(arr[0] == 'Y' && arr[1] == 'A' && arr[2] == 'K' && arr[3] == 'I')
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
// C - Vacation
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi ha(N+1), hb(N+1), hc(N+1); // a:海,b:山,c:家
	vi da(N+1), db(N+1), dc(N+1); // dp
	rp(day, 1, N+1) cin>>ha[day]>>hb[day]>>hc[day];
	rp(day, 1, N+1){ // day 今日
		da[day] = ha[day] + max(db[day-1], dc[day-1]);
		db[day] = hb[day] + max(dc[day-1], da[day-1]);
		dc[day] = hc[day] + max(da[day-1], db[day-1]);
	}
	cout<< max({da[N], db[N], dc[N]}) <<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int n, k;
vector < vector<int> > g;
vector<int> mt;
vector<char> used;


bool try_kuhn (int v) {
    if (used[v])
        return false;
    used[v] = true;
    for (size_t i=0; i<g[v].size(); ++i) {
        int to = g[v][i];
        if (mt[to] == -1 || try_kuhn (mt[to])) {
            mt[to] = v;
            return true;
        }
    }
    return false;
}

bool prime(int x) {
    if (x <= 2) return false;
    for (int i = 2; i * i <= x; ++i)
        if (x % i == 0)
            return false;
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    set<int> a;
    forn(i, 0, n) {
        int x;
        cin >> x;
        if (a.count(x)) a.erase(x);
        else a.insert(x);
        ++x;
        if (a.count(x)) a.erase(x);
        else a.insert(x);
    }
    g.resize(n);
    vector<int> odds, evens;
    for (int x : a) {
        if (x % 2) odds.eb(x);
        else evens.eb(x);
    }
    n = odds.size(), k = evens.size();
    forn(i, 0, n) forn(j, 0, k) if (prime(abs(odds[i] - evens[j]))) {
        g[i].eb(j);
    }
    mt.assign (k, -1);
    int cnt = 0;
    for (int v=0; v<n; ++v) {
	used.assign (n, false);
	if (try_kuhn (v)) ++cnt;
    }
    int ans = cnt;
    int restO = n - cnt, restE = k - cnt;
    assert(restO % 2 == restE % 2);
    ans += restO / 2 * 2;
    ans += restE / 2 * 2;
    if (restO % 2) ans += 3;
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner scan = new Scanner(System.in);

        while(true){
            int h = scan.nextInt();
            int w = scan.nextInt();
            if(h ==0 && w == 0){
                break;
            }
            for(int i = 0;i<h;i++){
                for(int j= 0;j<w;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }

    }


}



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

using namespace std;

int main(){
        long long l[100];
        l[0]=2;l[1]=1;
        for(int i=2;i<100;i++){
                l[i]=l[i-1]+l[i-2];
        }
        int N;
        cin>>N;
        cout<<l[N]<<endl;
        return 0;
}


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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight = long long;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};

auto operator<(const Edge &e, const Edge &f) {
  if (e.weight != f.weight)
    return e.weight > f.weight;
  else if (e.src != f.src)
    return e.src < f.src;
  else
    return e.dst < f.dst;
}

bool flags[101][101] = {};

using Edges = vector<Edge>;
using Graph = vector<Edges>;
//経路復元可能
void dijkstra(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev) {
  priority_queue<Edge> q;
  dist[s] = 0;
  for (q.emplace(-2, s, 0); !q.empty();) {
    Edge e = q.top();
    q.pop();
    if (prev[e.dst] != -1)
      continue;
    prev[e.dst] = e.src;
    if (e.src != -2) {
      flags[e.src][e.dst] = true;
      flags[e.dst][e.src] = true;
    }
    // if(prev[t]!=-1)return;
    for (auto ge : g[e.dst]) {
      if (dist[ge.dst] > e.weight + ge.weight) {
        dist[ge.dst] = e.weight + ge.weight;
        q.emplace(ge.src, ge.dst, e.weight + ge.weight);
      }
    }
  }
}

int main() {
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int s, t, d;
    cin >> s >> t >> d;
    --s;
    --t;
    g[s].emplace_back(s, t, d);
    g[t].emplace_back(t, s, d);
  }
  for (int i = 0; i < n; ++i) {
    vector<Weight> dist(n, INF64); //ここまでの距離が入る
    vector<int> prev(n, -1);       //最短路の親が入る
    dijkstra(g, i, dist, prev);
  }
  int ans = 0;
  for (const auto &es : g) {
    for (const auto &e : es) {
      if (flags[e.src][e.dst] == 0)
        ans += 1;
    }
  }
  cout << ans / 2 << endl;
}
// be checked by AOJ(GRL-1-A).

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const int MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

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

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



int main(){
    cin >> K >> N;
    ll d[N], a[N];
    REP(i,N) cin >> a[i];
    REP(i,N){
        if(i != N-1) d[i] = a[i+1] - a[i];
        else d[i] = K + a[0] - a[i];
    }
    ll ans = K;
    for(int i = 0; i < N; ++i){
        ans = min(K - d[i], ans);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
using namespace std;
int main()
{
  int n,m=0;
  cin>>n;
  for(int i=1;i<10;++i){
    for(int j=1;j<10;++j){
      if(n==i*j)m=1;
    }
  }
  if(m==0)cout<<"No"<<endl;
  else if(m==1)cout<<"Yes"<<endl;
  
  return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> v(H,vector<char>(W));
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      cin >> v.at(i).at(j);
    }
  }
  
  vector<char>A(W+2,'#');
  
  for(int i=0; i<W+2; i++) {
    cout << A.at(i);
  }
  cout << endl;
  
  for(int i=0; i<H; i++) {
    cout << '#';
    for(int j=0; j<W; j++) {
      cout << v.at(i).at(j);
    }
    cout << '#' << endl;
  }
  
  for(int i=0; i<W+2; i++) {
    cout << A.at(i);
  }
}

Measured memory_bytes: 256