akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

vector<vector<int> > id;

int mapping(int x, int y){
    if (x>y) swap(x, y);
    return id[x][y];
}

int main() {
    //freopen("in.txt", "r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;
    int e = n*(n-1)/2;
    vector<vector<int> > adjList(e, vector<int>()); 
    id.assign(n, vector<int>(n));
    
    int A[n][n];
    int vertex = 0;
    for (int i=0;i<n;++i){
        for (int j=i+1;j<n;++j){
            id[i][j] = vertex++;
        }
    }

    int cur, prev;
    int indegree[e];
    memset(indegree, 0, sizeof(indegree));

    for (int i=0;i<n;++i){
        for (int j=0;j<n-1;++j){
            cin>>cur;
            cur--;
            if (j>0){
                int vcur = mapping(i, cur);
                int vprev = mapping(i, prev);
                adjList[vprev].emplace_back(vcur);
                indegree[vcur]++;
            }
            prev = cur;
        }
    }

    queue<int> q;
    int day = 0;
    for (int i=0;i<e;++i){
        if (indegree[i] == 0) q.push(i);
    }
    
    int cnt = 0;
    while (!q.empty()){
        day++;
        cnt += q.size();
        queue<int> tmp;
        while (!q.empty()){
            int c = q.front();
            q.pop();
            for (auto child : adjList[c]){
                indegree[child]--;
                if (indegree[child] == 0)
                    tmp.push(child);
            }
        }
        q = tmp;
    }

    if (cnt != e) cout<<"-1"<<endl;
    else cout<<day<<endl;

    return 0;
}

Measured memory_bytes: 33536
# include <iostream>
# include <map>
using namespace std;
const int N=6;
map <char,int> a;
long long b[N];
string c;
long long s;
int n;
void work (void)
{
	int i,j,k;
	for (i=1;i<=3;i++)
	for (j=i+1;j<=4;j++)
	for (k=j+1;k<=5;k++)
	s+=b[i]*b[j]*b[k];
	cout<<s;
}
int main (void)
{
	int i;
	a['A']=1;
	a['C']=2;
	a['H']=3;
	a['M']=4;
	a['R']=5;
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>c;
		b[a[c[0]]]++;
	}
	work ();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
vector<P> G[100010];

int d[100010];

bool dfs(int x, int l) {
    //cout << "*" << x << " " << l << " " << d[x] << endl;
    if(d[x] == -1) d[x] = l;
    else if(d[x] != l) return false;
    else if(d[x] == l) return true;
    for(auto e: G[x]) {
        int to = e.first;
        int add = e.second;
        if(!dfs(to, l + add)) return false;
    }
    return true;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int L[200010], R[200010], D[200010];
    bool head[200010];
    rep(i, N) head[i] = true;
    rep(i, M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
        G[L[i]].push_back({R[i], D[i]});
        head[R[i]] = false;
    }
    rep(i, N) d[i] = -1;
    rep(i, N) {
        if(head[i] && !dfs(i, 0)) {
            // cout << i << endl;
            // rep(i, N) cout << d[i] << " ";
            // cout << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, N) {
        if(d[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

class UnionFind {
    vector<int> par, treesize;
    int groups;
    
public:
    UnionFind(int n){
        rep(i, n) par.push_back(i);
        treesize = vector<int>(n,1);
        groups = n;
    }
    
    int root(int x){
        if(x == par[x]) return x;
        return par[x] = root(par[x]);
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        if(same(x,y)) return;
        int rx = root(x), ry = root(y);
        treesize[ry] += treesize[rx];
        treesize[rx] = 0;
        groups--;
        par[rx] = ry;
    }
    
    int get_size(int x){
        return treesize[root(x)];
    }
    
    int get_groups(){ return groups; }
};

signed main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    
    cout << uf.get_groups() - 1 << endl;
}

Measured memory_bytes: 5000
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;

int main() {
	string x,y;
	cin >> x>>y;
	
	if (x<y) {
	cout << "<" << endl;
	}
	else if (x==y) {
	cout << "=" << endl;
	}
	else {
	cout << ">" << endl;
	}
	return 0;
}



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

int main(){
  int n,i,min,ans;
  cin>>n;
  int a[n];
  for (i=0;i<n;i++)cin>>a[i];
  min=a[0];
  ans=a[1]-a[0];
  for (i=1;i<n;i++){
    if (a[i]<min)min=a[i];
    else if (a[i]-min>ans)ans=a[i]-min;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3888
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    ans = []
    k = I()
    for i,si in enumerate(s):
        if si == "a":
            ans.append(si)
            continue
        j = (ord("a")-ord(si))%26
        if j <= k:
            k -= j
            ans.append("a")
        else:
            ans.append(si)
    k %= 26
    ans[-1] = chr(ord(ans[-1])+k)
    print(*ans,sep="")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 55280
N = int(input())
X, Y, H = [], [], []
X_zero, Y_zero = [], []
C_x, C_y = None, None

for _ in range(N):
	x, y, h = map(int, input().split())
	if h > 0:
		X.append(x)
		Y.append(y)
		H.append(h)
	else:
		X_zero.append(x)
		Y_zero.append(y)
	
# 答え候補は(i, j)
end = 0
for i in range(0, 100 + 1):
	if end: break
	for j in range(0, 100 + 1):
		if end: break
		cur = None
		ok = 1
		for n in range(len(X)):
			if cur == None:
				cur = H[n] + abs(i - X[n]) + abs(j - Y[n])
				C_x = i
				C_y = j
			else:
				if cur != H[n] + abs(i - X[n]) + abs(j - Y[n]):
					ok = 0
					break
		if ok:
			end = 1
			for n in range(len(X_zero)):
				if not abs(i - X_zero[n]) + abs(j - Y_zero[n]) >= cur:
					end = 0
					break
			
print(C_x, C_y, cur)

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

#define ALL(a)  a.begin(),a.end()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define debug(x) cerr << #x << ": " << x << endl

using LL = long long; template<class T> using V = vector<T>;

vector<int> f(const vector<vector<int>> &g) {
	int n = SZ(g), k = 0;
	vector<int> ord(n, 0), in(n, 0);
	FOR(i, 0, SZ(g)) {
		FOR(j, 0, SZ(g[i])) {
			in[g[i][j]]++;
		}
	}
	queue<int> q;
	FOR(i, 0, n) {
		if (in[i] == 0) q.push(i);
	}
	while (q.size()) {
		int v = q.front(); q.pop();
		ord[k++] = v;
		FOR(i, 0, SZ(g[v])) {
			if (--in[g[v][i]] == 0) q.push(g[v][i]);
		}
	}
	return *max_element(in.begin(), in.end()) == 0 ? ord : vector<int>();
}

bool f2(const vector<int> &ord, const vector<vector<int>>&g) {
	int not_uniq = 0; int n = SZ(g);
	FOR(i,0, n - 1) {
		int i_to_nxi = 0;
		FOR(j, 0, SZ(g[ord[i]])) {
			if (g[ord[i]][j] == ord[i + 1])i_to_nxi = 1;
		}
		if (i_to_nxi == 0) { not_uniq = 1; }
	}
	return not_uniq;
}


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

	int N, E; cin >> N >> E;
	V<V<int>>G(N);
	FOR(i, 0, E) {
		int a, b; cin >> a >> b; a--, b--;
		G[a].push_back(b);
	}
	auto dagv = f(G);
	FOR(i, 0, N) {
		cout << dagv[i]+1 << endl;
	}
	cout << f2(dagv, G) << endl;
	return 0;
}//////////


Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++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;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int main(){
    int n;cin>>n;
    vector<int> a(n),hat(3,0);
    for(int i=0;i<n;++i) cin>>a[i];
    ll ans=1;
    for(int i=0;i<n;++i){
        ll cnt=0;
        for(int j=0;j<3;++j)if(a[i]==hat[j]) cnt++;
        ans=ans*cnt%MOD;
        for(int j=0;j<3;++j){
            if(a[i]==hat[j]){
                hat[j]++;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3752
from itertools import product

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
T = [["" for _ in range(W)] for _ in range(H)]


def num_of_mines(_i: int, _j: int) -> int:
    patterns = [
        (-1, 0), (1, 0), (0, -1), (0, 1),
        (-1, -1), (-1, 1), (1, -1), (1, 1),
    ]
    cnt = 0
    for pattern in patterns:
        y, x = _i + pattern[0], _j + pattern[1]
        if y in range(H) and x in range(W):
            c = S[y][x]
            if c == "#":
                cnt += 1
        else:
            pass
    return cnt


for i, j in product(range(H), range(W)):
    if S[i][j] == "#":
        T[i][j] = "#"
    else:
        T[i][j] = str(num_of_mines(i, j))

for column in T:
    print("".join(column))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    long long int sum=0;
    vector<long long int> T(N);
    for(int n=0; n<N; n++) {
        cin >> T[n];
        sum += T[n];
    }
    
    int M;
    cin >> M;
    for(int m=0; m<M; m++) {
        int P;
        long long int X;
        cin >> P >> X;
        cout << sum-T[P-1]+X << endl;
    }
    

    return 0;
    
}

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

int main(){

    string s;
    cin >> s;

    list<char> str;
    for (auto item : s)
        str.push_back(item);
    

    int T;
    cin >> T;
    int reverse_count = 0;
    while(T--) {

        int op;
        cin >> op;

        if (op == 1) {
            reverse_count++;
        }
        else {
            int dir;
            char item;
            cin >> dir >> item;

            if ((dir == 1 && reverse_count%2 == 0) ||
                (dir == 2 && reverse_count%2 == 1))
                str.push_front(item);
            else
                str.push_back(item);
        }

    }


    if (reverse_count&1)
        reverse(str.begin(), str.end());


    for (auto item : str)
        cout << item;
    cout << endl;

    return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

vector<int> v;

//////////一般化した二分探索

const bool LEFT = false;
const bool RIGHT = true;
bool judgeLR(int i, int key);// 左に属するか右に属するかを判断する関数。下で定義する。

int nibutanL(int size, int key) {// LEFTグループに属するうち最も右側のindexを得る
	int L = -1;
	int R = size;
	while (abs(R - L) > 1) {
		int mid = (L + R) / 2;
		if (judgeLR(mid, key) == RIGHT) R = mid;
		else L = mid;
	}
	return L;
}
int nibutanR(int size, int key) {//RIGHTグループに属するうち最も左側のindexを得る
	return nibutanL(size, key) + 1;
}

bool judgeLR(int i, int key) {
	if (v[i] <= key) {
		return LEFT;
	}
	else {
		return RIGHT;
	}
}

int main() {
	int N; cin >> N;
	int* a = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	v.clear();
	for (int i = N - 1; i >= 0; i--) {
		int s = v.size();
		if (s == 0) {
			v.push_back(a[i]);
		}
		else if (a[i] >= v[s - 1]) {
			v.push_back(a[i]);
		}
		else {
			int n = nibutanR(s, a[i]);
			v[n] = a[i];
		}
	}

	cout << v.size() << endl;
	return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define SZ(v)   ((int)((v).size()))
#define LP(c,x,n)  for(int c=x;c<n;c++)
#define LO(c,n,x)  for(int c=n;c>=x;c--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define PI ( 2 * acos(0.0))
#define EPS 1e-8
#define INF 1.0/0.0
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ReadFile freopen("delivery.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
using namespace std;
const int OO = 0x3f3f3f3f,NegOO= -1*OO,N =1e5+5,mod =998244353 ;
int n;
int arr[N];
int dp[N];
int solve(int i)
{
    if(i>=n-1)return 0;
    if(i==n-2)return abs(arr[n-1]-arr[i]);
    int &rf=dp[i];
    if(~rf)return rf;
    rf=OO;
    return rf=min(abs(arr[i+1]-arr[i])+solve(i+1),abs(arr[i+2]-arr[i])+solve(i+2));
}
int main()
{
    cin>>n;
    LP(c,0,n)cin>>arr[c];
    memset(dp,-1, sizeof(dp));
    cout<<solve(0)<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);//高速化、endlは使わない

  int K;

  cin >> K;

  if(K%2==0)
    cout << (K/2)*(K/2) << "\n";
  else
    cout << (K+1)/2*(K-1)/2 << "\n";
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		setIO();

		int N = ni();
		int[] A = nia(N);
		int[] dp = new int[N];
		Arrays.fill(dp, 1000000000);
		dp[0] = 0;
		for (int i = 0; i < N-1; i++) {
			dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(A[i+1] - A[i]));
			if (i < N-2)
				dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(A[i+2] - A[i]));
		}
		out.println(dp[N-1]);
		
		f.close();
		out.close();
	}

	static BufferedReader f;
	static PrintWriter out;
	static StringTokenizer st;

	static String rl() throws IOException {
		return f.readLine();
	}

	static int ni(StringTokenizer st) {
		return Integer.parseInt(st.nextToken());
	}

	static long nlg(StringTokenizer st) {
		return Long.parseLong(st.nextToken());
	}

	static int ni() throws IOException {
		return Integer.parseInt(rl());
	}

	static long nlg() throws IOException {
		return Long.parseLong(rl());
	}

	static StringTokenizer nl() throws IOException {
		return new StringTokenizer(rl());
	}

	static int[] nia(int N) throws IOException {
		StringTokenizer st = nl();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = ni(st);
		return A;
	}

	static void setIn(String s) throws IOException {
		f = new BufferedReader(new FileReader(s));
	}

	static void setOut(String s) throws IOException {
		out = new PrintWriter(new FileWriter(s));
	}

	static void setIn() {
		f = new BufferedReader(new InputStreamReader(System.in));
	}

	static void setOut() {
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	}

	static void setIO(String s) throws IOException {
		setIn(s + ".in");
		setOut(s + ".out");
	}

	static void setIO() {
		setIn();
		setOut();
	}
}


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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

int gcd(int a, int b);
int lcm(int a, int b);

int cost(int a, int b){
    return fabs(a - b);
}

void solve_A(){
    int n;
    cin >> n;

    int h[n];
    REP(i,n) cin >> h[i];

    int dp[n];
    dp[0] = 0;
    dp[1] = cost(h[1], h[0]);

    for(int i = 1; i < n; i++){
        dp[i + 1] = min(dp[i] + cost(h[i], h[i+1]), dp[i-1] + cost(h[i-1], h[i+1]));
    }

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

void solve_B(){ // 未完成
    int n, k;
    cin >> n >> k;

    int h[n];
    REP(i,n) cin >> h[i];

    int dp[n];
    REP(i,n) dp[i] = (int)1e7;
    
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i + j < n) chmin(dp[i+j], dp[i] + cost(h[i], h[i+j]));
        }
    }

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

void solve_C(){
    int n;
    cin >> n;

    int a[n], b[n], c[n];
    REP(i,n) cin >> a[i] >> b[i] >> c[i];

    int activity = 3;
    int dp[n+1][activity];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;

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

    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}

int main(void){
    solve_C();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

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

Measured memory_bytes: 2560
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    for (int i = 1; i <=n ; i++)
    {
        if(i%3==0 && i%5==0) continue;
        else if(i%3==0) continue;
        else if(i%5==0) continue;
        else sum+=i;
    }
    cout<<sum<<endl;
 
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}


LLI power(LLI n, LLI p, LLI m){
  LLI ret = 1;
  while(p>0){
    if(p&1) (ret *= n) %= m;
    (n *= n) %= m;
    p /= 2;
  }
  return ret;
}

LLI mod_inv(LLI n, LLI p){return power(n,p-2,p);}

template <LLI mod> class Combination{
public:
  vector<LLI> facto = {1};
  vector<LLI> ifacto = {1};

  LLI factorial(LLI i){
    if(i < 0) throw exception();
    if(facto.size() <= i) facto.resize(i+1, -1);
    if(i == 0) return facto[0] = 1;
    LLI j = i;
    for(;j>=0;--j) if(facto[j] != -1) break;
    for(LLI k=j+1; k<=i; ++k) (facto[k] = facto[k-1] * k) %= mod;
    return facto[i];
  }

  LLI factorial_inverse(LLI i){
    if(i < 0) throw exception();
    if(ifacto.size() <= i) ifacto.resize(i+1, -1);
    if(ifacto[i] != -1) return ifacto[i];
    return ifacto[i] = mod_inv(factorial(i), mod);
  }

  LLI P(LLI n, LLI k){
    if(n < k or n < 0 or k < 0) return 0;
    return (factorial(n) * factorial_inverse(n-k)) % mod;
  }

  LLI C(LLI n, LLI k){
    if(n < k or n < 0 or k < 0) return 0;
    return (P(n,k) * factorial_inverse(k)) % mod;
  }

  LLI H(LLI n, LLI k){
    return C(n+k-1, k);
  }
};


const LLI mod = 1e9+7;

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

  Combination<mod> com;

  LLI N,M,K;
  while(cin >> N >> M >> K){

    LLI ans = 0;

    {
      LLI t = 0;
      FOR(i,1,N){
	(t += (N-i)*M*M*i%mod) %= mod;
      }
      (ans += t * com.C(M*N-2,K-2) % mod) %= mod;
    }

    {
      LLI t = 0;
      FOR(i,1,M){
	(t += (M-i)*N*N*i%mod) %= mod;
      }
      (ans += t * com.C(M*N-2,K-2) % mod) %= mod;
    }

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


Measured memory_bytes: 3328
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort(reverse=True)
xmax = max(x[0], X)
y.sort()
ymin = min(y[0], Y)

if ymin - xmax > int(0):
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=8;
int n,c,l[N];
int f[505][(1<<6)+5];
double ans=0,cnt=0;
int main(){
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++) scanf("%d",&l[i]);
	sort(l,l+n);
	do{
		memset(f,0,sizeof(f));
		f[l[n-1]*n][0]=1;
		for(int i=1;i<=c*n;i++){
			int p=i%n-1;
			if(p<0) continue;
			for(int j=i;j<=c*n;j++)
				for(int s=0;s<(1<<(n-1));s++)
					if(!((s>>p)&1))
						f[min(c*n,max(j,i+l[p]*n))][s|(1<<p)]+=f[j][s];
		}
		ans+=f[c*n][(1<<(n-1))-1],cnt++;
	}while(next_permutation(l,l+n-1));
	printf("%.15lf",ans/cnt/pow(c,n-1));
	return 0;
}

Measured memory_bytes: 4404
main(){int i,j,a[10],y;for(i=0;i<=9;i++)scanf("%d",&a[i]);for(i=0;i<=8;i++)for(j=i+1;j<=9;j++){if(a[i]<a[j]){y=a[i];a[i]=a[j];a[j]=y;}}for(i=0;i<3;i++)printf("%d\n",a[i]);return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int H, W;
map<pi, bool> board;
map<pi, bool> visited;
map<pi, vector<pi> > adj;

signed main(void) {
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            char c;
            cin >> c;
            pi p = mp(i, j);
            if (c=='#') board[p] = true;
            else board[p] = false;
            visited[p] = false;
        }
    }

    rep(i, H) {
        rep(j, W) {
            pi now=mp(i, j);
            int dh[] = {1, 0, -1, 0};
            int dw[] = {0, 1, 0, -1};
            rep(k, 4) {
                if (0 <= i+dh[k] && i+dh[k] < H && 0 <= j+dw[k] && j+dw[k] < W) {
                    pi dest = mp(i+dh[k], j+dw[k]);
                    if (board[now] != board[dest]) adj[now].push_back(dest);
                }
            }
        }
    }

    int ans=0;
    rep(i, H) {
        rep(j, W) {
            pi now=mp(i, j);
            if (!visited[now]) {
                int white = 0, black = 0;
                visited[now] = true;
                stack<pi> S;
                S.push(now);
                while(!S.empty()) {
                    pi top = S.top();
                    S.pop();
                    if (board[top]) black++;
                    else white++;
                    for (auto dest : adj[top]) {
                        if (!visited[dest]) {
                            S.push(dest);
                            visited[dest] = true;
                        }
                    }
                }
                ans += black * white;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 46592
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int Q; cin >> Q;
    while (Q--) {
        int s, t, k; cin >> s >> t >> k;
        cout << count(&v[s], &v[t], k) << endl;
    }
}


Measured memory_bytes: 3100
#include<iostream>
#include<cmath>

using namespace std;

bool PrimeN (int x) {

    if (x == 1) {
        return false;
    }

    for (int i = 2; i <= sqrt(x); i++) {
        
        if (x == i) {
            // cout << x << endl;
            return true;
        }

        if (x % i == 0) {
            return false;
        }
    }

    // cout << x << endl;
    return true;

}

int main (void) {

    int n;
    int cnt = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        
        int X;
        cin >> X;

        if(PrimeN (X)) {
            cnt++;
        }

    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <map>
 #define rep(i,n) for(int i=0;i<n;i++)
 using namespace std;
  int main(){
      char x,y;
      cin >> x >> y;
      if(x<y){
          cout << '<' << endl;
      }
      else if(x>y){
          cout << '>' << endl;
      }
      else{
          cout << '=' << endl;
      }
      return 0;

  }

Measured memory_bytes: 3520
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(S: str, T: str):
    for i in range(len(S)):
        kari = S[i:]+S[:i]
        if kari == T:
            yes()
            return
    no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)


if __name__ == '__main__':
    main()


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

int main() {

    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n){
        cin >> x[i];
    }

    ll mx = INT_MAX;
    rep(i, 200){
        ll tmp = 0;
        rep(j, n){
            tmp += pow(x[j]-i, 2);
        }
        mx = min(mx, tmp);
    }
    cout << mx << endl;
    return 0;
}

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

double n;

double dp[301][301][301];


double f(int a,int b,int c){
	if(a==0 && b==0 && c==0) return 0;
	if(dp[a][b][c]!=-1) return dp[a][b][c];
	double x=a,y=b,z=c,ans=0;
	if(a>0){
		ans = ans+(x/(x+y+z))*f(a-1,b,c);
	}
	if(b>0){
		ans = ans+(y/(x+y+z))*f(a+1,b-1,c);
	}
	if(c>0){
		ans = ans+(z/(x+y+z))*f(a,b+1,c-1);
	}
	ans = ans+n/(x+y+z);
	dp[a][b][c]=ans;

	return ans;
}


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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	cin >> n;
	for(int i=0;i<301;i++){
		for(int j=0;j<301;j++){
			for(int k=0;k<301;k++){
				dp[i][j][k]=-1;
			}
		}
	}
	int a[3];
	a[0]=a[1]=a[2]=0;

	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		a[x-1]++;
	}

	cout << fixed << setprecision(10) << f(a[0],a[1],a[2]);
	
	


	
	




	
	




	

}


Measured memory_bytes: 213376
<>=~$";@c=(($H=$`-2)*($W=$'-2),(0)x9);map$H+3>($a=$`+$_%3)&$a>2&$W+3>($==$'+$_/3)&$=>2&&$c[$$a{$=}]--*$c[++$$a{$=}]++,!//..8for<>;print"@c"

Measured memory_bytes: 245504
// F - Pure
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> ans, vi, rs;
vector<vector<int> > g;

void dfs(int u, int order)
{
	if (ans.size() > 0) return;
	if (vi[u]) {
		if (rs[u]) {
			bool found = true;
			for (int i = 0; i < n; i++)
				if (rs[i] >= rs[u]) {
					int c = 0;
					for (int j = 0; j < g[i].size(); j++)
						if (rs[g[i][j]] >= rs[u]) c++;
					if (c != 1) found = false;
				}
			if (found) {
				for (int i = 0; i < rs.size(); i++)
					if (rs[i] >= rs[u]) ans.push_back(i);
			}
		}
	} else {
		vi[u] = rs[u] = order;
		for (int i = 0; i < g[u].size(); i++) dfs(g[u][i], order + 1);
		rs[u] = 0;
	}
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
	}

	vi.assign(n, 0);
	rs.assign(n, 0);
	for (int i = 0; i < n && ans.size() == 0; i++)
		if (vi[i] == 0) dfs(i, 1);

	if (ans.size() > 0) {
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++) cout << (ans[i] + 1) << endl;
	} else {
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, L, ans = 0;
    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        ans += i + L;
    }
    if (L <= 0 && L + N - 1 >= 0) {

    } else if (L > 0) {
        ans -= L;
    } else {
        ans -= L + N - 1;
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right as br
n,m,k = map(int,input().split())
a = [int(i) for i in input().split()]
sa = [0]*(n+1)
for i in range(n): sa[i+1] = sa[i]+a[i]
b = [int(i) for i in input().split()]
sb = [0]*(m+1)
for i in range(m): sb[i+1] = sb[i]+b[i]
ans = 0
for i in range(n+1):
    cnt = sa[i]
    if cnt > k: break
    ans = max(ans,br(sb,k-cnt)-1+i)
print(ans)

Measured memory_bytes: 50500
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 1e5 + 5;

int bucket1[N], bucket2[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    int x;
    int x1 = 0, x2 = 0, mx1 = 0, mx2 = 0;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(i & 1){
            bucket1[x]++;
            if(bucket1[x] > mx1){
                mx1 = bucket1[x];
                x1 = x;
            }
        }else{
            bucket2[x]++;
            if(bucket2[x] > mx2){
                mx2 = bucket2[x];
                x2 = x;
            }
        }
    }
    sort(bucket1, bucket1 + N);
    sort(bucket2, bucket2 + N);
    if(x1 != x2){
        cout << n - (mx1 + mx2);
    }else{
        cout << n - max(mx1 + bucket2[N - 2], mx2 + bucket1[N - 2]);
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 1152
import numpy as np
x, y = map(int, input().split())

if(abs(x) >= abs(y)):
    if(np.sign(x) == np.sign(y)):
        if(np.sign(x) < 0):
            print(abs(x)-abs(y))
        else:
            print(2+abs(x)-abs(y))
    else:
        if(y != 0):
            print(1+abs(x)-abs(y))
        else:
            if(x < 0):
                print(abs(x))
            else:
                print(1+abs(x))
else:
    if(np.sign(x) == np.sign(y)):
        if(np.sign(x) > 0):
            print(abs(y)-abs(x))
        if(np.sign(x) < 0):
            print(2+abs(y)-abs(x))
    else:
        if(x == 0):
            if(y > 0):
                print(abs(y))
            else:
                print(1+abs(y))
        else:
            print(1+abs(y)-abs(x))

Measured memory_bytes: 17852
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    for(int i=0; i<a.size()-1;i++){
        if(a[i]==a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	let a = vec[0].as_bytes();
	let b = vec[1].as_bytes();
	let o = if a > b {
		">"
	} else if a < b {
		"<"
	} else {
		"="
	};
	println!("{}", o);
}


Measured memory_bytes: 4352
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		Map<Integer, Integer> school = new HashMap<Integer, Integer>();
		for(int i = 1; i <= N; i++) {
			school.put(Integer.parseInt(sc.next()), i);
		}
		sc.close();

		for(int i = 1; i <= N; i++) {
			int tmp = school.get(i);
			if(i != N) {
				System.out.print(tmp + " ");
			}else {
				System.out.println(tmp);
			}
		}

	}

}

Measured memory_bytes: 59564
#include <stdio.h>
main(){
  while(1){
  int week,a,b,i,sum;
  char today[7][20]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
  int data[]={0,31,29,31,30,31,30,31,31,30,31,30};
    scanf("%d %d",&a,&b);
    if(a==0)break;
    sum=0;
    for(i=0;i<a;i++){
      sum=sum+data[i];
    }
    week=(sum+b)%7;
    printf("%s\n",today[week]);
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define int LL
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=55;
LL L[MAX_N];
void init()
{
	L[0]=1;
	For(i,1,50)
	{
		L[i]=2*L[i-1]+3;
	}
}
map <pLL,int> dp;
int dfs(int k,LL X)
{
	if(X<=0)return 0;
	if(k==0)return 1;
	if(dp.count(mp(k,X)))return dp[mp(k,X)];
	int res=0;
	res+=dfs(k-1,min(X-1,L[k-1]));
	if(X-1>L[k-1])res++;
	res+=dfs(k-1,min(X-L[k-1]-2,L[k-1]));
//	cout<<"dfs("<<k<<","<<X<<")"<<endl;
//	cout<<res<<endl;
	dp[mp(k,X)]=res;
	return res;
}
signed main()
{
	init();
	LL n,X;
	cin>>n>>X;
	cout<<dfs(n,X)<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if ((s[0] == s[1] && s[1] == s[2]) || (s[3] == s[1] && s[1] == s[2])) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int w,a,b;cin>>w>>a>>b;
    if (b>a+w)cout<<b-a-w<<endl;
    else if (b<a)cout<<a-b-w<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int H, W, D;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &D);
  int A[H][W];
  std::pair<int, int> where[90000+5];
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      scanf("%d", &A[i][j]);
      where[A[i][j]] = std::make_pair(i,j);
    }
  }
  int Q;
  scanf("%d", &Q);
  std::vector<int > L(Q), R(Q);
  for (int i=0; i<Q; i++){
    scanf("%d", &L[i]);
    scanf("%d", &R[i]);
  }
  // calc cummulateiv distance
  std::vector<long long > dist(H*W+4);
  for (int i=1; i<=D; i++){
    dist[i]=0;
    for (int j=i; j+D<=H*W; j++){
      dist[j+D]=dist[j]+abs(where[j].first-where[j+D].first)+abs(where[j].second-where[j+D].second);
    }
  }

  // evaluate
  for (int i=0; i<Q; i++){
    int ans = dist[R[i]]-dist[L[i]];
    printf("%d\n", ans);
  }
  return 0;
}


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

string s[2];

int main(){
    cin>>s[0]>>s[1];
    cout<<((s[0][0]==s[1][2]) && (s[0][2]==s[1][0]) && (s[0][1]==s[1][1]) ? "YES" : "NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * CODE
 * BY
 * VIKAS VERMA
 * 
 * $$Always Check for Constraints
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, n) for (int i = 1; k <= n; i++)
#define f_range(l, r) for (int i = l; i < r; i++)
#define jaldi ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef long long ll;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
ll a[N];
//=======================

void solve()
{
  int n;
  cin >> n;
  fo(i, n)
  {
    cin >> a[i];
  }
  ll count = 0;
  for (int i = 1; i < n; i++)
  {
    if (a[i] < a[i - 1])
    {
      ll diff = a[i - 1] - a[i];
      a[i] += diff;
      count += diff;
      ;
    }
  }
  cout << count << endl;
}

int main()
{
  jaldi
      // #ifndef ONLINE_JUDGE
      //       freopen("input.txt", "r", stdin);
      //   freopen("output.txt", "w", stdout);
      // #endif
      int t = 1;

  // cin >> t;

  while (t--)
  {
    solve();
  }

  return 0;
}

Measured memory_bytes: 51972
#include <iostream>
 
using namespace std;
 
int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (500*i+100*j+50*k==x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define INF 2<<29

int main(){
  int cnt0=0,cnt1=0;
  char s[100005];
  scanf("%s",s);
  for(int i=0;i<strlen(s);i++){
    if(s[i]=='0') cnt0++;
    else cnt1++;
  }
  printf("%d\n",strlen(s)-max(cnt0-cnt1,cnt1-cnt0));
  
  return 0;
}


Measured memory_bytes: 384
main=do
 [n,p]<-map read.words<$>getLine
 let a=f 0 2 p
 print$product$map(\(u,v)->u^(div v n))a
f c i p
 |p`mod`i==0=f(c+1)i(div p i)
 |c/=0=(i,c):f 0(i+1)p
 |i*i>p=[(p,1)]
 |otherwise=(i,c):f 0(i+1)p

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

using namespace std;

const int N = 2e5;
const int V = 1e6;
const int MOD = 998244353;

template <int _MOD> struct Mint
{
    int v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int _v) { this->v = _v; return *this; }
    Mint operator = (const long long _v) { this->v = static_cast<int>(_v%_MOD); return *this; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) { return Mint(v+b.v); }
    Mint operator - (const Mint &b) { return Mint(v-b.v); }
    Mint operator * (const Mint &b) { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) { return Mint(b.inv()*v); }
    Mint operator += (const Mint &b) { return *this = *this+b; }
    Mint operator -= (const Mint &b) { return *this = *this-b; }
    Mint operator *= (const Mint &b) { return *this = *this*b; }
    Mint operator /= (const Mint &b) { return *this = *this/b; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const { return pow(_MOD-2); }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;

int n;
mint res;
mint w[V+7], s[V+7], p[V+7];

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

    for (int i = 1; i <= V; ++i) {
        w[i] += mint(i).inv();
        for (int j = i+i; j <= V; j += i)
            w[j] -= w[i];
    }

    cin >> n;
    for (int i = 1, a; i <= n; ++i) {
        cin >> a;
        s[a] += a;
        p[a] += 1ll*a*a%MOD;
    }
    for (int i = 1; i <= V; ++i) {
        mint x, y;
        for (int j = i; j <= V; j += i)
            x += s[j], y += p[j];
        res += w[i]*(x*x-y);
    }
    res /= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 12032
#include<stdio.h>

#define N 100

int min(int a, int b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

int main(void){
    int n, p[N+1], m[N+1][N+1];
    scanf("%d", &n);

    for(int i=1; i<=n; i++){
        scanf("%d %d", &p[i-1], &p[i]);
    }
    for(int i=1; i<=n; i++){
        m[i][i]=0;
    }
    for(int l=2; l<=n; l++){
        for(int i=1; i<=n-l+1; i++){
            int j=i+l-1;
            m[i][j]=(1<<21);
            for(int k=i; k<=j; k++){
                m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }

    printf("%d\n", m[1][n]);

    return 0;
}


Measured memory_bytes: 2144