akhauriyash/Code-Regression huggingface dataset:
<?php 
$n = trim(fgets(STDIN));
$l = explode(" ", trim(fgets(STDIN)) );

$count = 0;
for($i = 0; $i < count($l); $i++){
    for($j = $i; $j < count($l); $j++){
        for($k = $j; $k < count($l); $k++){
            $a = (int)$l[$i];
            $b = (int)$l[$j];
            $c = (int)$l[$k];
            # 3辺ともに異なる長さ
            if( $a == $b || $b == $c || $c == $a ){
                continue;
            }
            # 三角形が成り立つか判定
            if( (($a + $b) <= $c) || (($a + $c) <= $b) || (($b + $c) <= $a) ){
                continue;
            }
            $count++;            
        }
    }
}
print $count;

Measured memory_bytes: 16312
import heapq
from collections import defaultdict
from functools import lru_cache
from bisect import bisect_right
while True:
    N, M, C, S, G = map(int, input().split())
    if N == M == C == S == G == 0:  # 駅の数、路線の数10000、鉄道会社の数20、出発駅、目的地駅
        break
    #E = [[[] for _ in range(N + 1)] for _ in range(C + 1)]
    D = [[[float("inf")] * (N + 1) for _ in range(N + 1)] for _ in range(C + 1)]
    CE = [set() for _ in range(C+1)]
    for _ in range(M):
        x, y, d, c = map(int, input().split())  # d<=200
        D[c][x][y] = min(D[c][x][y], d)
        D[c][y][x] = min(D[c][x][y], d)
        CE[c].add(x)
        CE[c].add(y)

    P = list(map(int, input().split()))  # <= 50
    Q = []
    R = []
    for _ in range(C):
        Q.append(list(map(int, input().split())) + [1 << 30])
        R.append(list(map(int, input().split())))

    cum_fare = []
    for c_ in range(C):
        fare_ = [0]
        res = 0
        q_p = 0
        for q, r in zip(Q[c_][:-1], R[c_][:-1]):
            res += (q - q_p) * r
            q_p = q
            fare_.append(res)
        cum_fare.append(fare_)

    @lru_cache(maxsize=None)
    def fare(d_, c_):
        if d_==float("inf"):
            return float("inf")
        c_ -= 1
        idx = bisect_right(Q[c_], d_)
        #print(c_, idx, cum_fare[c_], R[c_])
        return cum_fare[c_][idx] + (R[c_][0] * d_ if idx==0 else (d_ - Q[c_][idx-1]) * R[c_][idx])


    DD = [[float("inf")] * (N + 1) for _ in range(N + 1)]
    for c in range(1, C + 1):
        D_ = D[c]
        l = list(CE[c])
        for k in l:
            for i in l:
                for j in l:
                    d_ = D_[i][k] + D_[k][j]
                    if D_[i][j] > d_:
                        D_[i][j] = d_
        # print(D_)
        for i in l:
            for j in l:
                DD[i][j] = min(DD[i][j], fare(D_[i][j], c))
    # print(DD)
    dist = defaultdict(lambda: float("inf"))
    q = []
    start = S
    dist[start] = 0
    heapq.heappush(q, (0, start))
    while len(q) != 0:
        prob_cost, v = heapq.heappop(q)
        # print(prob_cost, v)
        if dist[v] < prob_cost:
            continue
        if v == G:
            print(prob_cost)
            break
        for u, c in enumerate(DD[v]):
            if dist[u] > dist[v] + c:
                dist[u] = dist[v] + c
                heapq.heappush(q, (dist[u], u))
    else:
        print(-1)



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

using namespace std;

int main()
{
	int N, M;

	cin >> N >> M;

	vector<int> table(M, 0);
	for (int i = 0; i < N; i++)
	{
		int K;
		cin >> K;

		for (int j = 0; j < K; j++)
		{
			int a;
			cin >> a;
			a--;

			table[a]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < M; i++)
	{
		if (table[i] == N)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

int main() {
  string str[] = chomp(readln).split(" ");
  int a = to!(int)(str[0]);
  int b = to!(int)(str[1]);
  if(a<b) writeln("a < b");
  else if(a==b) writeln("a == b");
  else writeln("a > b");

  return 0;
}

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

int main() {
    int n, k, s;
    int A = 1000000000;
    scanf("%d %d %d", &n, &k, &s);
    if (s != A) {
        for (int i = 0; i < n; i++) {
            if (i < k)
                printf("%d ", s);
            else
                printf("%d ", s + 1);
        }
    }
    else {
        for (int i = 0; i < n; i++) {
            if (i < k)
                printf("%d ", s);
            else
                printf("%d ", A - 1);
        }
    }
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            String N = sc.next();

            long[][] dp = new long[2][N.length() + 1];
            dp[0][0] = 0;
            dp[1][0] = 1;

            for (int i = 0; i < N.length(); i++) {
                int n = N.charAt(i) - '0';

                dp[0][i + 1] = Math.min(dp[0][i] + n, dp[1][i] + 10 - n);
                dp[1][i + 1] = Math.min(dp[0][i] + n + 1, dp[1][i] + 10 - n - 1);
            }

            System.out.println(dp[0][N.length()]);
        }
    }

}


Measured memory_bytes: 53124
def main():
    mod = 10 ** 9 + 7

    def choose(n, a, mod=mod):
        x, y = 1, 1
        for i in range(a):
            x = x * (n - i) % mod
            y = y * (i + 1) % mod
        return x * pow(y, mod - 2, mod) % mod

    x, y = map(int, input().split())

    q, r = divmod(x + y, 3)
    if r != 0:
        print(0)
        return

    # b:=(+2,+1)
    d = x * 2 - y
    if d < 0 or d % 3 != 0:
        print(0)
        return

    b = d // 3
    if q < b:
        print(0)
        return
    res = choose(q, min(b, q - b), mod)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	string ans = "";
	for(int i = 0; i < n; i++){
		ans += s[i];
	}
	cout << ans;
	return 0;
}

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

ll l=998244353;

int main() {
  ll n; cin>>n;
  vector<ll> v(100000,0);
  ll d0;
  rep(i,n){
    ll d; cin>>d;
    if(i==0)d0=d;
    v[d]++;
  }
  ll i=100000-1;
  while(v[i]==0){
    v.erase(v.begin()+i);
    i--;
  }
  n=v.size();
  ll ans=1;
  rep(j,n-1){
    rep(k,v[j+1]){
      ans*= v[j];
      ans%=l;
    }
  }
  if(v[0] !=1||d0!=0){ans=0;}
 
  cout<<ans<<endl;
}



Measured memory_bytes: 4020
#include <stdio.h>

int main(){
    int n,i,j,an,key,data;
    
    scanf("%d",&n);
    
    int G[n][n];
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            G[i][j]=0;
        }
    }
    
    for(i=0;i<n;i++){
        scanf("%d",&key);
        scanf("%d",&an);
        
        for(j=0;j<an;j++){
            scanf("%d",&data);
            G[key-1][data-1]=1;
            
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(j!=0)printf(" ");
            printf("%d",G[i][j]);
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
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; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;


int main()
{
	ll n;
	cin >> n;
	vector<ll>h(n),dp(n,INF);
	rep(i, n)cin >> h[i];
	dp[0] = 0;//初期条件（dpの初項）

	for (ll i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
		if(i>1)chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n - 1] << endl;
}



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


void solve(long long N, long long A, long long B, std::vector<long long> P){
  long long lteqA = 0;
  long long gtAlteqB = 0;
  long long gtB = 0;

  for(long long i = 0; i < N; i++){
    if(P[i] <= A) lteqA++;
    if(P[i] > A && P[i] <= B) gtAlteqB++;
    if(P[i] > B) gtB++;
  }

  cout << min(lteqA, min(gtAlteqB, gtB)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
    solve(N, A, B, std::move(P));
    return 0;
}


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

int main(){
  int n;
  double t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  double min = 100000;
  int min_index = 0;
  for(int i = 0; i < n; i++){
    double ans = abs((t - h[i] * 0.006) - a);
    if(min > ans){
      min = ans;
      min_index = i + 1;
    }
  }
  cout << min_index << endl;
  return 0;
}

Measured memory_bytes: 3784
import sys

def selectionSort(x_list, y):
  a = 0
  for i in range(y):
    minj = i
    for j in range(i, y):
      if x_list[j] < x_list[minj]:
        minj = j
    x_list[i], x_list[minj] = x_list[minj], x_list[i]
    if x_list[i] != x_list[minj]:
      a += 1
  return a

y = sys.stdin.readline()
y = int(y)
 
x = sys.stdin.readline()
x_list = x.split(" ")
 
for i in range(y):
  x_list[i] = int(x_list[i])
 
a = selectionSort(x_list, y)
 
for k in range(0, y):
  print x_list[k],
print
print a

Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std ;
int main (){
    int a , b , sum = 0  ;
    cin >> a >> b ;
    int ar[a+1] ;
    for (int i = 0 ; i < a ; i ++) {
            cin >> ar[i] ;

    }
    sort(ar,ar+a) ;
    for (int i = 0 ; i < b ; i ++)
        sum += ar[i] ;
    cout << sum << endl ;
}


Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
ll n, k;
ll a[MN];
ll cur[MN];
ll nxt[MN]; //next time this num appears
ll app[MN]; //last time this appeared

ll cnt[MN];
deque<ll> in;
void sim(int loc){ //simulates starting from here
    //cout << "sim from " << loc << "\n";
    FOR(i, loc, n-1){
        ll v = a[i];
        if(cnt[v] == 0){
            in.push_back(v);
            cnt[v]++;
        } else{
            while(cnt[v] != 0){
                ll p = in.back();
                in.pop_back();
                cnt[p]--;
            }
        }
    }
    while(!in.empty()){
        ll p = in.front();
        in.pop_front();
        cout << p << " ";
    }
}

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

    memset(cur, -1, sizeof(cur));
    memset(nxt, -1, sizeof(nxt));
    memset(app, -1, sizeof(app));

    cin >> n >> k;
    F0R(i, 2*n){
        ll v;
        if(i < n){
            cin >> a[i];
            v = a[i];
        } else{
            v = a[i%n];
        }
        if(cur[v] != -1 && nxt[cur[v]] == -1) nxt[cur[v]] = i;
        if(i < n) cur[v] = i;
    }

    /*F0R(i, n){
        cout << nxt[i] << " ";
    }
    cout << "\n";*/

    ll cur = 0;
    ll on = 0;
    if(k > n*2){ //if not bf is good
        while(app[on] == -1){
            app[on] = cur;
            on = nxt[on]+1;
            while(on >= n){
                cur++;
                on -= n;
            }
        }
        ll cyc = cur-app[on];
        //cout << cyc << "\n";

        ll amt = k/cyc;
        ll res = amt*cyc+cur;
        while(res >= k) res -= cyc;
        k = k-res;
        cur = 0;
    }

    //cout << k << " " << cur << " " << on << "\n";

    while(cur < k){
        //cout << cur << " " << on << "\n";
        ll nv = nxt[on]+1;
        if(cur == k-1 && nv > n) sim(on);
        on = nv;
        while(on >= n){
            cur++;
            on -= n;
        }
    }

    return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define pb(x) push_back(x)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;
const int mx=1e5+10;
ll dhuko[mx][2],bahir[mx][2];
ll arr[mx];
int main()
{
	int n;
	cin>>n;
	loop(i,1,n)cin>>arr[i];
	int flag=0;
	dhuko[n+1][0]=2;
	dhuko[n+1][1]=2;
	for(int i=n;i>0;i--)
	{
       // cout<<dhuko[i+1][0]<<" "<<dhuko[i+1][1]<<endl;
        bahir[i][0]=(dhuko[i+1][0]/arr[i])*arr[i];
        if(bahir[i][0]<dhuko[i+1][0])bahir[i][0]+=arr[i];
        bahir[i][1]=(dhuko[i+1][1]/arr[i])*arr[i];
        //cout<<i<<" "<<bahir[i][0]<<" "<<bahir[i][1]<<endl;
        if(bahir[i][0]>dhuko[i+1][1] && bahir[i][1]<dhuko[i+1][0])
        {
            flag=1;
            break;
        }
        if(bahir[i][0]>dhuko[i+1][1])bahir[i][0]=bahir[i][1];
        else if(bahir[i][1]<dhuko[i+1][0])bahir[i][1]=bahir[i][0];

        //cout<<i<<" "<<bahir[i][0]<<" "<<bahir[i][1]<<endl;
        dhuko[i][0]=bahir[i][0];
        dhuko[i][1]=bahir[i][1]+arr[i]-1;
	}
	if(flag)cout<<-1<<endl;
	else cout<<dhuko[1][0]<<" "<<dhuko[1][1]<<endl;
	return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979

int main(void)
{
    int a, b, C;
    scanf("%d %d %d", &a, &b, &C);

    double S, L, h;

    h = b * sin(C * PI / 180);
    S = 0.5 * a * h;
    L = a + b + (sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(C * PI / 180)));

    printf("%f\n%f\n%f\n", S, L, h);
    
    return 0;
}

Measured memory_bytes: 684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<pair<int, int>> p(n);
  rep(i, n) p[i] = {a[i], i};
  sort(p.begin(), p.end());
  int ans = p[q - 1].first - p[0].first;
  set<int> s;
  s.insert(-1);
  s.insert(n);
  rep(i, n) {
    s.insert(p[i].second);
    priority_queue<int, vector<int>, greater<int>> pq;
    for (auto it = s.begin(); it != s.end(); it++) {
      auto it2 = it;
      it2++;
      if (it2 == s.end()) break;
      int left = *it + 1, right = *(it2);
      if (right - left < k) continue;
      vector<int> res;
      FOR(j, left, right) res.push_back(a[j]);
      sort(res.begin(), res.end());
      rep(j, res.size() - (k - 1)) pq.push(res[j]);
    }
    if (pq.size() < q) break;
    int res = pq.top();
    rep(i, q - 1) pq.pop();
    res = pq.top() - res;
    chmin(ans, res);
  }
  cout << ans << '\n';


  




  
  return 0;
}

Measured memory_bytes: 384
/*input
4
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 

int arr[1010][1010];

int h;
int w;



bool legal(int x, int y){
	if(x>=1&&x<=h){
		if(y>=1&&y<=w){
			if(arr[x][y]){
				return true;

			}
		}
	}
	return false;
}

int countDivisors(int n) 
{ 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 



int main() {
 	int64 n;
 	cin>>n;
 	int64 arr[n+1];
 	memset(arr,0,sizeof(arr));
 	for(int64 i = 1; i<n+1;i++){
 		int64 j = 0;
 		while(j<n+1){
 			arr[j]++;
 			j+=i;
 		}
 	}
 	int64 ans = 0;
 	rep(i,n+1){
 		ans+=i*arr[i];
 	}
 	cout<<ans<<endl;

}



 


Measured memory_bytes: 81688
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <bits/stdc++.h>
#endif



int64_t dp[100][10][11];

int64_t func(int i, int a, int b)
{
	if (i == 1) {
		if (b == 10) { return 0; }
		return 1;
	}
	if (dp[i][a][b] != -1) {
		return dp[i][a][b];
	}

	if (b != 10) {
		return dp[i][a][b] = func(i - 1, a, b) * 2;
	}

	dp[i][a][b] = func(i - 1, a, 10);
	for (int bb = 0; bb < 10; ++bb) {
		if (a != bb) {
			dp[i][a][b] += func(i - 1, a, bb);
		}
	}
	return dp[i][a][b];
}

int64_t f2(int i, int a, int b, int next)
{
	if (b == 10) {
		if (a == next) {
			return func(i - 1, a, 10);
		}
		else {
			return func(i - 1, a, next);
		}
	}
	return func(i - 1, a, b);
}


int main()
{
	using namespace std;


	int64_t N;
	while (true)
	{
		cin >> N;
		if (N == 0) {
			break;
		}
		memset(dp, -1, sizeof(dp));

		int64_t n_2 = 1;
		int k = 2;
		for (;; ++k) {
			n_2 *= 2;
			if (n_2 >= (((int64_t)(1)) << 62)) {
				break;
			}
			int64_t sum = 9 * 9 * (n_2 - 1);
			if (sum >= N)
			{
				break;
			}
			else {
				N -= sum;
			}
		}

		for (int32_t i = 1; i <= 9; i++)
		{
			func(k, i, 10);
		}

		for (int32_t i = 1; i <= 9; i++)
		{
			//std::cerr << dp[k][i][10] << endl;
		}
		//std::cerr << "==============" << endl;




		int a, b = 10;
		for (int j = 1; j <= 9; ++j)
		{
			{a = j; }
			if (dp[k][a][b] < N) {
				N -= dp[k][a][b];
			}
			else {
				cout << a;
				break;
			}
		}
		for (int32_t i = k; i >= 2; --i)
		{
			if (b == 10) {
				for (int j = 0; j <= 9; ++j)
				{
					if (f2(i, a, b, j) < N) {
						N -= f2(i, a, b, j);
					}
					else {
						if (a == j) {
							cout << j;
						}
						else {
							b = j;
							cout << j;
						}
						break;
					}
				}
			}
			else {
				if (b<a) { std::swap(a, b); }
				if (f2(i, a, b, a) < N) {
					N -= f2(i, a, b, a);
					cout << b;
				}
				else {
					cout << a;
				}
			}
		}

		cout << std::endl;
	}


}



Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
	string s;
	cin >>s;
	long long int cnt=0,ans=0;
	for (int i=s.size()-1;i>=0;--i)
		if (s[i]=='B'){
			ans+=s.size()-i-cnt-1;
			cnt++;
		}
	cout <<ans;
}

Measured memory_bytes: 640
module Main where
import           Control.Monad
import           Data.Bits
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Monoid
import Data.IORef
--import SegmentTree

data SegmentTree m = Leaf m | Node m (SegmentTree m) (SegmentTree m) deriving (Eq,Show)

val :: SegmentTree m -> m
val (Leaf v) = v
val (Node v _ _) = v




update :: (Monoid m) => SegmentTree m -> Int -> Int -> m -> SegmentTree m
update (Leaf v) _ _ x = Leaf x
update (Node v l r) size i x                                                     
    | i < n'   =   Node ((val left) `mappend` (val r)) left r
    | otherwise =   Node ((val l) `mappend` (val right)) l right
    where n' = size `div` 2
          left = update l n' i x
          right = update r n' (i-n') x




query :: (Monoid m) => SegmentTree m -> Int -> Int -> Int -> m

query (Leaf v) _ 0 1 = v
query (Node v l r) size a b
    | a >= b    = mempty
    | a == 0 && b == size   = v
    | b <= n'             = query l n' a b
    | a >= n'                = query r n' (a-n') (b-n')
    | otherwise             = (query l n' a n') `mappend` (query r n' 0 (b-n'))
    where n' = size `div` 2

resize :: Int -> Int -> Int
resize n m 
    | m < n = resize n (2*m)
    | otherwise  = m


fromList :: Monoid m => [m] -> SegmentTree m
fromList xs = 
    let n = length xs
        m = resize n 1
        plus = [mempty | i<-[1..(m-n)]] 
        xs' = xs ++ plus
    in fromList' xs' m

fromList' ::Monoid m => [m] ->  Int ->SegmentTree m
fromList' _ 0 = Leaf mempty
fromList' [x] 1 = Leaf x
fromList' xs n = Node ((val left) `mappend` (val right)) left right
    where n' = n `div` 2
          (xs1,xs2) = splitAt n' xs
          left = fromList'  xs1 n'
          right = fromList' xs2 (n-n')

get :: Monoid m => SegmentTree m -> Int ->Int -> m
get tree i size= query tree size i (i+1)




tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined
 
 
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words
 
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

newtype Gcd = Gcd Integer deriving (Show,Eq,Ord,Read)
 
--instance Semigroup Gcd where
--    Gcd x <> Gcd y = Gcd (gcd x y)
instance Monoid Gcd where
    mempty = Gcd 0
    Gcd x `mappend` Gcd y = Gcd (gcd x y)

toI :: Gcd -> Integer
toI (Gcd x) = x
 

solve :: [Integer] -> Integer
solve a =
    let n = length a
        seg = fromList $ map Gcd a :: SegmentTree Gcd
        m = resize n 1
    in maximum $ map toI [(query seg m 0 i) `mappend` (query seg m (i+1) (length a)) | i <- [0..length a ]]


main :: IO ()
main = do
    getLine
    a<- getIntList
    print $ solve a

Measured memory_bytes: 29052
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		string s1,s2;
		cin >> s1 >> s2;
		rep(i,0,n) cout<<s1[i]<<s2[i];
	}   
}     

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

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

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {
    string S;
    cin >> S;
    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    if (isupper(S[1])) {
        cout << "WA" << endl;
        return 0;
    }

    if (isupper(S[S.size()-1])) {
        cout << "WA" << endl;
        return 0;
    }

    bool Cflag = false;
    
    for (int i = 2; i < (int)S.size()-1; i++) {
        if (isupper(S[i])) {
            if (S[i] == 'C'&&Cflag == false) {
                Cflag = true;
                continue;
            }
            cout << "WA" << endl;
            return 0;
        }
    }
    if (Cflag == true) {
        cout << "AC" << endl;
    }
    else cout << "WA" << endl;
}

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> p(N);
    for (int &t: p)
        cin>>t;
    int oo = 10*N;
    vector<vector<int>> T(N, vector<int>(4, oo));
    for (int i=0; i<N; i++)
    {
        for (int j=0; j<=3; j++)
        for (int k=0; k<=3; k++)
            if (j+k >= p[i])
                T[i][k] = min(T[i][k], (i>0 ? T[i-1][j] : 0)+j+k);
    }
    cout<<*min_element(T[N-1].begin(), T[N-1].end())<<endl;
}



Measured memory_bytes: 3276
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int[] arr = new int[3];
			arr[0] = sc.nextInt();
			arr[1] = sc.nextInt();
			arr[2] = sc.nextInt();
			java.util.Arrays.sort(arr);
			
			System.out.println(arr[0] +  " " + arr[1] + " " + arr[2]);
		}
	}
}


Measured memory_bytes: 26168
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
using namespace std;


int main(){
  int n, T;
  cin >> n >> T;
  int t[n], c[n];
  for(int i=0; i<n; i++){
    cin >> c[i] >> t[i];
  }
  int min_c = 1001;
  int ans = n;
  for(int i=0; i<n; i++){
    if(min_c > c[i]){
      if(T >= t[i]){
        min_c = c[i];
        ans = i;
    }
  }
}
  if(ans < n){
    cout << c[ans] <<endl;
  }
  else{
    cout << "TLE" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> 
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> M(N);
    for (int i = 0; i < N; i++) {
        cin >> M.at(i);
    }

    sort(M.begin(), M.end());
    int ans = N;
    for (int i = 1; i < M.size(); i++) {
        if (M.at(i - 1) == M.at(i)) ans--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}

/*
void Main()
{
	ll n,m,l; ll res=0;
	cin>>n;
	VI dp(n+2,INF);
	VI h(n);
	rep(i, n) cin >> h[i];
	//初期条件はじめはコスト0
	dp[0]=0;
	//配るDP
	rep(i,n){
		//１個先のすでに計算したコストと新しく計算する1個先のコスト比較
		ll cost1=abs(h[i+1]-h[i]);
		dp[i+1]=min(dp[i+1],dp[i]+cost1);
		//2個先のすでに計算したコストと新しく計算する2個先のコスト比較
		ll cost2=abs(h[i+2]-h[i]);
		dp[i+2]=min(dp[i+2],dp[i]+cost2);
	}
	res=dp[n-1];
	cout << res << "\n";
	return;
}
*/
void Main()
{
	ll n,m,l; ll res=0;
	cin>>n;
	VI dp(n+2,INF);
	VI h(n);
	rep(i, n) cin >> h[i];
	//初期条件はじめはコスト0
	dp[0]=0;
	//貰うDP
	rep(i,n){
		//すでに計算したコストと１個前から新しく計算する今のコスト比較
		ll cost1=abs(h[i]-h[i-1]);
		dp[i]=min(dp[i],dp[i-1]+cost1);
		if(i>=2) {
			//すでに計算したコストと２個前から新しく計算する今のコスト比較
			ll cost2 = abs(h[i]-h[i-2]);
			dp[i] = min(dp[i], dp[i-2]+cost2);
		}
	}
	res=dp[n-1];//はじめが１なので
	cout << res << "\n";
	return;
}



int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 1792
# coding: utf-8
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N + 1 - i):
        if (Y - 10000*i - 5000*j) % 1000 == 0 and (Y - 10000*i - 5000*j) / 1000 == N-i-j:
            print(i, j, N-i-j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 41196
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
long long dis[10002];
bool vis[10002];
vector<int> a[10002];
vector<int> b[10002];
int n,u,k,x,t=1,w,m,s,v;
queue<int> q;
int main(){
	cin>>n;
	memset(vis,false, sizeof(vis));
	memset(dis,0x1f1f1f1f,sizeof(dis));
	for (int i=0; i<n; i++){
		cin>>u>>k;
		while (2*k--){
			  cin>>v>>w;
			  a[u].pb(v);
		      b[u].pb(w);
		}
	}
	q.push(0);
	dis[0]=0;
	while (!q.empty()){
		  x=q.front(); q.pop(); vis[x]=false;
		  for (int i=0; i<a[x].size(); i++){
		  	  if (dis[a[x][i]]>dis[x]+b[x][i]){
		  	  	  dis[a[x][i]]=dis[x]+b[x][i];
		  	  	  if (!vis[a[x][i]]){
		  	  	  	  vis[a[x][i]]=true;
		  	          q.push(a[x][i]);
                  }
			 }
		  	  
		  }
	}
    for (int i=0; i<n; i++){
		cout<<i<<' '<<dis[i]<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3732
fun main(args: Array<String>) {
    val s = readLine()!!
    var ans = 0
    var l = 0
    var r = s.lastIndex
    while (l < r) {
        if (s[l] == s[r]) {
            l++
            r--
            continue
        }

        if (s[l] == 'x') {
            l++
            ans++
            continue
        }

        if (s[r] == 'x') {
            r--
            ans++
            continue
        }

        ans = -1
        break
    }
    println(ans)
}


Measured memory_bytes: 33756
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int cnt=0,vnt=0;
  while(a>0)
  {
    a=a-d;
    cnt++;
  }
  while(c>0)
  {
    c=c-b;
    vnt++;
  }
  if(vnt>cnt)
    cout<<"No";
  else
    cout<<"Yes";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[4],n1=0,n2=0;
	for(int i=0;i<3;i++){
		cin>>a[i];
		if(a[i]==7){
			n1++;
		}else if(a[i]==5){
			n2++;
		}
	}
	if(n1==1&&n2==2){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int zo[] = {0, 1};
  for (int i = 0; i < B; i ++) {
    for (int j = 0; j < A; j ++) {
      cout << zo[0];
    }
    for (int j = A; j < W; j ++) {
      cout << zo[1];
    }
    cout << endl;
  }
  for (int i = B; i < H; i ++) {
    for (int j = 0; j < A; j ++) {
      cout << zo[1];
    }
    for (int j = A; j < W; j ++) {
      cout << zo[0];
    }
    cout << endl;
  }
}


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

int main()
{
	string s;
	cin>>s;
	int a=(s[0]%48);
	int b=(a*10)+(s[1]%48);
	int c=((s[2]%48)*10)+(s[3]%48);
	
	 if(((b>=1)&&(b<=12))&&((c>=1)&&(c<=12)))
    {
        cout<<"AMBIGUOUS";
    }
    else
    {
        if((b>=1)&&(b<=12))

        {
            cout<<"MMYY";
        }
        else if((c>=1)&&(c<=12))

        {
            cout<<"YYMM";
        }
        else
        {
            cout<<"NA";
        }
    }
}

Measured memory_bytes: 3564
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		char[] cs=sc.next().toCharArray();
		int s=0,t=cs.length-1;
		while(cs[s]!='A')++s;
		while(cs[t]!='Z')--t;
		System.out.println(t+1-s);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25684
n = int(input())
s = input()
t = input()
# print(s + t)
st = s + t
same = 0
for i in range(n):
    ok = True
    for j in range(i+1):
        if s[n-i+j-1] != t[j]:
            ok = False
        # print(i, j, ok)
    if ok:
        same = i+1
# print(same)
print(2*n - same)

Measured memory_bytes: 3060
S = input()
L = ['A', 'C', 'G', 'T']
ans = 0
for i in range(len(S)):
    for j in range(len(S) - i):
        if j == 0:
            s = S[i:]
        else:
            s = S[i:-j]
        length = 0
        for k in s:
            if k in L:
                length += 1
            else:
                length = 0
                break
        if ans < length:
            ans = length
print(ans)


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    ll H; cin >> H;
    ll cnt = 0, x = 1;;
    while (H > 0) {
        H /= 2;
        cnt += x;
        x *= 2;
    }
    cout << cnt << endl;
}


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

#print(N,H)

def chmax(dp, n, k, a):
	b = (dp[n][k]<a)
	if b: dp[n][k]=a
	return b


#dp=[[0,0,0,0,0,0] for _ in range(N+1)]
dp=[[0,0,0] for _ in range(N+1)]


for i in range(1,N+1):
	for j in range(3):
		for k in range(3):
			if j==k: continue
			chmax(dp,i,k, dp[i-1][j] + H[i][k])
	

print( max(dp[N]) )


Measured memory_bytes: 77144
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (ll K = max(0ll, sum - (N - 1) * N); K < sum + N; K++) {
    ll ks = 0;
    for (int i = 0; i < N; i++) {
      ks += (a[i] + K + 1) / (N + 1); 
    }
    if (ks == K) {
      cout << K << endl;
      break;
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<tuple<ll,ll,ll> > t;
    REP(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        t.emplace_back(a,b,-c);
    }
    vll d(n,LLINF);
    d[0] = 0;
    REP(i,n-1){
        REP(j,m){
            if(d[get<1>(t[j])]>d[get<0>(t[j])]+get<2>(t[j])){
                d[get<1>(t[j])]=d[get<0>(t[j])]+get<2>(t[j]);
            }
        }
    }
    vector<bool> updated(n,true);
    REP(i,n){
        REP(j,m){
            if(d[get<1>(t[j])]>d[get<0>(t[j])]+get<2>(t[j])){
                d[get<1>(t[j])]=d[get<0>(t[j])]+get<2>(t[j]);
                updated[get<1>(t[j])] = false;
            }
        }
    }
    if(updated[n-1]){
        ll ret = -d[n-1];
        cout << ret << endl;
    }else{
        puts("inf");
    }

    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n;
    vector<int> v(3);
    cin >> n >> v[0] >> v[1] >> v[2];

    vector<string> str(n);
    REP(i, n){
        cin >> str[i];
    }

    vector<char> ans;

    REP(i, n){
        int a = str[i][0] - 'A', b = str[i][1] - 'A';
        if(v[a] == 0 && v[b] == 0){
            cout << "No" << endl;
            return 0;
        }
        if(v[a] < v[b]){
            v[a]++;
            v[b]--;
            ans.push_back('A' + a);
        }else if(v[a] > v[b]){
            v[a]--;
            v[b]++;
            ans.push_back('A' + b);
        }else{
            if(i == n-1){
                v[a]--;
                v[b]++;
                ans.push_back('A' + b);
            }else{
                int aa = str[i+1][0] - 'A', bb = str[i+1][1] - 'A';
                bool af = false, bf = false;
                if(a == aa || a == bb) af = true;
                if(b == bb || b == aa) bf = true;
                if(af && !bf){
                    v[a]++;
                    v[b]--;
                    ans.push_back('A' + a);
                }else{
                    v[a]--;
                    v[b]++;
                    ans.push_back('A' + b);
                }
            }
        }
    }

    cout << "Yes" << endl;
    for(auto i : ans){
        cout << i << '\n';
    }

    return 0;
}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,c,d,max;
  long num[4];
  cin >> a >> b >> c >> d;
  num[0] = a*c;
  num[1] = a*d;
  num[2] = b*c;
  num[3] = b*d;
  max = num[0];
  for(int i=1;i<4;i++){
    if(max < num[i]){
      max = num[i];
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }

vector<string> grid;
ll H,W;

bool movable(ll sh,ll sw)
{
  if(sh<0||sh>=H||sw<0||sw>=W) return false;
  return true;
}  

vector<vector<ll>> table;
ll dp(ll h,ll w)
{
  if(table.at(h).at(w)<INF) return table.at(h).at(w);
  table.at(h).at(w)-=1;
  //右移動
  if(movable(h,w-1))
  {
    if(grid.at(h).at(w-1)=='.'&&grid.at(h).at(w)=='#') chmin(table.at(h).at(w),dp(h,w-1)+1);
    else chmin(table.at(h).at(w),dp(h,w-1));
  }
  //下移動
  if(movable(h-1,w))
  {
    if(grid.at(h-1).at(w)=='.'&&grid.at(h).at(w)=='#') chmin(table.at(h).at(w),dp(h-1,w)+1);
    else chmin(table.at(h).at(w),dp(h-1,w));
  }
  return table.at(h).at(w);
}  
int main() 
{
  cin>>H>>W;
  grid=vector<string>(H);
  rep(i,H)
  {
    cin>>grid.at(i);
  }
  table=vector<vector<ll>>(H,vector<ll>(W,INF));
  if(grid.at(0).at(0)=='.') table.at(0).at(0)=0;
  else table.at(0).at(0)=1;
  cout<<dp(H-1,W-1)<<endl;
  return 0;
}


Measured memory_bytes: 3668