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

int n, k, a[100010], pos, ans = 2147483647;

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] == 1) pos = i;
    }
    for (int i = 1; i <= k; i++)
    {
        if (pos - i + 1 <= 0 || pos + k - i > n) continue;
        int s = (pos - i) / (k - 1) + ((pos - i) % (k - 1) != 0) + (n - pos - (k - i)) / (k - 1) + ((n - pos - (k - i)) % (k - 1) != 0);
        ans = min(ans, s);
    }
    printf("%d\n", ans + 1);
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0&&c>0){
  a-=d;
    c-=b;
    if(c<=0){
cout<<"Yes"<<endl;
      break;
    }
    else if(a<=0){
      cout<<"No"<<endl;
      break;
    }
  }
}
 

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9) cout << a* b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;

const int dataset_MAX = 1201,num_MAX=1001;
int sum[dataset_MAX];


int main(){
	int dataset = 0;
	for (;;dataset++){
		char num[num_MAX];
		sum[dataset] = 0;
		cin >> num;
		int i = 0;
		for (;i<(unsigned int)strlen(num); i++){
			sum[dataset] += num[i] - '0';
		}
		if (num[0] == '0')break;
	}
	for (int i = 0; i < dataset; i++){
		cout << sum[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
constexpr long N = 300000;
constexpr long mod = 998244353;

long mpow(long a, long p){
    long x=a;
    long y=1;
    while(p>0){
        if((p&1)==1){
            y=x*y%mod;
        }
        x=x*x%mod;
        p>>=1;
    }
    return y;
}

long minv(long a){
    return mpow(a, mod-2);
}

long fact[4*N+1];
void init_fact(){
    long t=1;
    fact[0]=1;
    for(long i=1; i<=N; i++){
        t=t*i%mod;
        fact[i]=t;
    }
}

long mcomb(long n, long r){
    return fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
}

int main(void){
    long n, a, b, k;
    scanf("%ld %ld %ld %ld", &n, &a, &b, &k);
    init_fact();
    long sum = 0;
    for(long i=0; i<=n; i++){
        if(k-a*i>n*b){
            continue;
        }else if(k-a*i<0){
            break;
        }
        long q=(k-a*i)/b;
        long m=(k-a*i)%b;
        if(m==0){
            sum = (sum+mcomb(n,i)*mcomb(n,q))%mod;
        }
    }
    if(sum==0)sum++;
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <map>
#include <string>

int main() {
  std::string s;
  std::cin >> s;

  size_t i = 0;
  auto e = s.length();
  std::string prev = "";
  int k = 0;

  while (i < e) {
    std::string ts = "";
    while (true) {
      ts += s[i];
      i++;
      if (prev != ts) {
        prev = ts;
        k++;
        break;
      }
      if (i == e) {
        break;
      }
    }
  }

  std::cout << k << std::endl;
  return 0;
}

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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a,b;
    a = x2-x1;
    b = y2-y1;
    cout << x2-b << " " << y2+a << " " << x2-b-a << " " << y2+a-b;
}

Measured memory_bytes: 256
n = gets.to_i
a = []
max = [0]
n.times do
  a << gets.to_i
end
b = a.sort
if b[-1] == b[-2]
  n.times{p b[-1]}
else
  for i in 0...n
    if a[i] == b[-1]
      p b[-2]
    else
      p b[-1]
    end
  end
end

Measured memory_bytes: 8224
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long total=0;
    for (int i=1;i<=n;i++) {
      if (i%3!=0&&i%5!=0) {
        total+=i;
      }
    }

    System.out.println(total);
  }
}


Measured memory_bytes: 27132
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<String, Integer> words = new HashMap<String, Integer>();
			int n,m;
			n = scanner.nextInt();

			String s = "";
			// blue card input
			for (int i = 0; i < n; i++) {
				s = scanner.next();
				if (words.containsKey(s)) {
					words.put(s, words.get(s) + 1);
				} else {
					words.put(s, 1);
				}
			}
			// red card input
			m = scanner.nextInt();
			for (int i = 0; i < m; i++) {
				s = scanner.next();
				if (words.containsKey(s)) {
					words.put(s, words.get(s) - 1);
				} else {
					words.put(s, -1);
				}
			}
			// result output
			int max = -999;
			for (Entry<String, Integer> ent : words.entrySet()) {
				if (ent.getValue() > max) {
					max = ent.getValue();
				}
			}
			System.out.println(max < 0 ? 0 : max);

		}
	}
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll n,x;
  cin>>n>>x;
  if(n>2*x-2){
    co("YES");
  }
  else{
    co("NO");
  }
}


Measured memory_bytes: 256
n,a,b = gets.chomp.split.map(&:to_i)
f = 0
bf = 0

gets.chomp.split('').each{|x|
    if x == 'a'
        if f < a+b
            f += 1
            puts 'Yes'
        else
            puts 'No'
        end
    elsif x == 'b'
        if f < a+b && bf < b
            f += 1
            bf += 1
            puts 'Yes'
        else
            puts 'No'
        end
    else
        puts 'No'
    end
}


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

int main(void) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    complex<int> c1(x1, y1), c2(x2, y2), rot(0, -1), c3 = rot * (c1 - c2) + c2, c4 = rot * (c2 - c3) + c3;
    cout << c3.real() << " " << c3.imag() << " " << c4.real() << " " << c4.imag() << endl;
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n,k;cin>>n>>k;
  vector<int64_t> A(n);
  for(int i=0;i<n;++i)cin>>A[i];
  for(int i=0;i<n;++i)A[i]*=2;
  auto ok=[&](int64_t x){
    int64_t c=0;
    for(int i=0;i<n;++i){
      if(A[i]%x==0)c+=A[i]/x-1;
      else c+=A[i]/x;
    }
    return c<=k;
  };
  int64_t l=1,r=2e9;
  while(l<r){
    int64_t mid=(l+r)>>1;
    if(ok(mid)){
      r=mid;
    }else{
      l=mid+1;
    }
  }
  if(l%2==0)cout<<l/2;
  else cout<<(l+1)/2;
  
  return 0;
}
//2020.08.02 20:31:43


Measured memory_bytes: 4752
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.size()-7;
	for(int i=0;i<s.size()-n+1;i++){
		string s2=s.substr(0,i)+s.substr(i+n);
		if(s2=="keyence"){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


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

using namespace std;

const int par = 1e9 + 7;
int N,M;
long long pat = 1,patN = 1,patM = 1;


int main(){
	scanf("%d %d",&N,&M);
	if(abs(N-M) > 1){
		pat = 0;
	}else{
		if(N == M){
			for(int i = N; i >= 2;i--){
				patN *= i;
				patN = patN % par;
			}
			pat = (patN * patN * 2) % par; 
		}else{
			for(int i = N; i >= 2;i--){
					patN *= i;
					patN = patN % par;
				}
			for(int i = M; i>= 2; i--){
				patM *= i;
				patM = patM % par;
			}
			pat = (patN * patM) % par;
		}
	}
	
	printf("%lld\n",pat);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define MAX 101

int n;
Graph G(MAX);
vector<bool> seen(MAX, false);
vector<int> d(MAX), f(MAX);
int timer = 1;

void dfs(const Graph &G, int v)
{
  seen.at(v) = true;
  d.at(v) = timer++;
  int next_v;
  for (int i = 0; i < G.at(v).size(); i++)
  {
    next_v = G.at(v).at(i);
    if (seen.at(next_v))
    {
      continue;
    }
    dfs(G, next_v);
  }
  f.at(v) = timer++;
}

int main()
{
  cin >> n;
  int k, u, v;
  for (int i = 0; i < n; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v;
      G.at(u).push_back(v);
    }
  }
  for (int v = 1; v <= n; v++)
  {
    if (seen.at(v))
    {
      continue;
    }
    dfs(G, v);
  }
  for (int i = 1; i <= n; i++)
  {
    cout << i << " " << d.at(i) << " " << f.at(i) << endl;
  }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
vector<int> search2(map<int, vector<int>> &g, int u, int n)
{
    deque<pair<int, int>> que;
    que.clear();
    map<int, bool> used;
    used.clear();
    que.push_back({u, 0});
    vector<int> ret(n, -1);
    while (!que.empty())
    {
        int cur = que.front().first, cost = que.front().second;
        que.pop_front();
        if (used[cur] == true)
        {
            continue;
        }
        ret[cur] = cost;
        used[cur] = true;

        for (auto x : g[cur])
        {
            que.push_back({x, cost + 1});
        }
    }
    return ret;
}

int main()
{
    int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    map<int, vector<int>> g;
    g.clear();

    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        //cerr << "*" << a << b << endl;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto udist = search2(g, u, n);
    auto vdist = search2(g, v, n);
    int ans = -1;
    rep(i, n)
    {
        if (udist[i] > vdist[i])
        {
            continue;
        }
        int cur = vdist[i];
        if (g[i].size() == 1)
            cur -= 1;

           ans = max(ans, cur);
    }

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

Measured memory_bytes: 18432
#include <stdio.h>

int main() {
	int s, d, b;
	bool depan = false, belakang = false;
	scanf("%d", &s);
	d = s / 100;
	b = s % 100;
	if ((0 < d) && (d < 13))
		depan = true;
	if ((0 < b) && (b < 13))
		belakang = true;
	if (depan && belakang)
		puts("AMBIGUOUS");
	else if (depan)
		puts("MMYY");
	else if (belakang)
		puts("YYMM");
	else
		puts("NA");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	vector<ll> TPN, TPN_ODD;

	//pre_calc
	int cnt = 1;
	do{
		TPN.pb(cnt * (cnt + 1) * (cnt + 2) / 6);
		if((cnt * (cnt + 1) * (cnt + 2) / 6)%2 == 1){
			TPN_ODD.pb(cnt * (cnt + 1) * (cnt + 2) / 6);
		}
		cnt ++;
	}while(cnt * (cnt + 1) * (cnt + 2) / 6 <= 1000000);
	int TPNSize = TPN.size(), TPN_ODDSize = TPN_ODD.size();

	//cout << "TPNSize = " << TPNSize << endl;
	//cout << "TPN_ODDSize = " << TPN_ODDSize << endl;

	vector<ll> V1(1000001), V2(1000001);
	V1[0] = 0;
	for(ll i = 1; i < 1000001; i ++){
		ll ret = 100;
		for(ll j = 0; j < TPNSize && TPN[j] <= i; j ++){
			ret = min(ret, 1 + V1[i - TPN[j]]);
		}
		V1[i] = ret;
	}
	V2[0] = 0;
	for(ll i = 1; i < 1000001; i ++){
		ll ret = 100;
		for(ll j = 0; j < TPN_ODDSize && TPN_ODD[j] <= i; j ++){
			ret = min(ret, 1 + V2[i - TPN_ODD[j]]);
		}
		V2[i] = ret;
	}

	//solve
	while(true){
		int N;
		cin >> N;
		if(N == 0)break;

		cout << V1[N] << " " << V2[N] << endl;
	}

	return 0;
}


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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION

ll n;
vll a;
vb been;

ll gcd(ll x, ll y) {
    while (x != 0 && y != 0) {
        if (x > y)
            swap(x, y);
        ll c = y/x;
        y -= c*x;
    }
    return max(x, y);
}

ll gcdall() {
    ll x = a[0];
    rep(i, 1, n) {
        x = gcd(x, a[i]);
    }
    return x;
}

void solve() {
    cin >> n;
    read(a, n, 0);
    been.resize(1e6 + 1, 0);

    bool pairwise = 1;
    for (ll x : a) {
        if (been[x]) {
            pairwise = 0;
            break;
        }
        for (ll d = 2; d * d <= x; d++) {
            if (x % d == 0) {
                if (been[d] || been[x / d]) {
                    pairwise = 0;
                    break;
                }
            }
        }
        for (ll d = 2; d * d <= x; d++) {
            if (x % d == 0) {
                been[d] = been[x / d] = 1;
            }
        }
        if (x != 1)
            been[x] = 1;
        if (pairwise == 0)
            break;
    }

    bool setwise = gcdall() == 1;

    if (pairwise) {
        cout << "pairwise coprime\n";
    }
    else if (setwise) {
        cout << "setwise coprime\n";
    }
    else {
        cout << "not coprime\n";
    }
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 11064
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vvi txy(n, vector<int>(3));

    cin >> txy[0][0] >> txy[0][1] >> txy[0][2];

    FOR(i, 1, n)
    {
        int tmp;
        REP(j, 3)
        {
            cin >> tmp;
            txy[i][j] = tmp - txy[i-1][j];
        }
    }

    REP(i, n)
    {
        int t = txy[i][0];
        int dst = txy[i][1] + txy[i][2];
        if(t < dst)
        {
            cout << "No" << endl;
            return 0;
        }
        if(t % 2 != abs(dst) % 2)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;




}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int tmp = 1;
  for (int i = 0; i < N; i++)
  {
    if(tmp+K<=tmp*2){
      tmp = tmp + K;
    }else{
      tmp = tmp * 2;
    }
  }
  cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a);
	rep(i, a) {
		cin >> p[i];
	}
	vector<ll> q(b);
	rep(i, b) {
		cin >> q[i];
	}
	vector<ll> r(c);
	rep(i, c) {
		cin >> r[i];
	}
	sort(ALL(p),greater<ll>());
	sort(ALL(q), greater<ll>());
	sort(ALL(r), greater<ll>());
	int i = x - 1;
	
	int j = y - 1;
	int k = 0;
	//cout << i << "," << j << "," << k << endl;
	while (1) {
		if ((k<c&&i>=0&&p[i] < q[j])||j<0) {
			if (p[i] < r[k]) {
				i--;
				k++;
			//	cout << "r" << p[i] << "," << r[k] << endl;
			}
			else {
				break;
			}
		}
		else if ((k < c && j >= 0 && p[i] >= q[j]) || i < 0) {
			if (q[j] < r[k]) {
		//		cout << "g" << q[j] << "," << r[k] << endl;
				j--;
				k++;
				
			}
			else {
				break;
			}
		}
		else {
			break;
		}
	}
	ll ans = 0;
	//cout << i << endl;
	rep(I, i+1) {
		ans += p[I];
		//cout << p[I] << " ";
	}
	//cout << endl;
	//cout << j << endl;
	rep(J, j+1) {
		ans += q[J];
		//cout << q[J] << " ";
	}
	//cout << endl;
	//cout << k << endl;
	rep(K, k) {
		ans += r[K];
		//cout << r[K] << " ";
	}
	//cout << endl;
	cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,x,s=0;
	cin>>n;
	while(n!=0)
	{
		x=n%10;
		n=n/10;
		if(x==2)
			s++;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

solve wbs hbs w h css = length [(i,j) | i <- [0..h-1], j <- [0..w-1], hbs!!i == 0, wbs!!j == 0, ((css !! i) !! j) == '#'] 

main = do
    [h,w,k] <- map read . words <$> getLine :: IO [Int]
    css <- replicateM h getLine
    print $ length [ (hbs, wbs) | hbs <- replicateM h [0,1], wbs <- replicateM w [0,1], (solve wbs hbs w h css) == k]


Measured memory_bytes: 4600
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<=b && b<=c){
        cout << a << " " << b << " " << c << endl;
    }else if(a<=c && c<=b){
        cout << a << " " << c << " " << b << endl;
    }else if(b<=a && a<=c){
        cout << b << " " << a << " " << c << endl;
    }else if(b<=c && c<=a){
        cout << b << " " << c << " " << a << endl;
    }else if(c<=a && a<=b){
        cout << c << " " << a << " " << b << endl;
    }else if(c<=b && b<=a){
        cout << c << " " << b << " " << a << endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

int main(){
  int N; cin >> N;
  int a[N]; rep(i,N) cin >> a[i];

  deque<int> DQ;

  if (N%2==0){
    for (int i=0;i<N;i++){
      if (i%2==0) DQ.push_back(a[i]);
      else DQ.push_front(a[i]);
    }
  } 
  else {
    for (int i=0;i<N;i++){
      if (i%2==1) DQ.push_back(a[i]);
      else DQ.push_front(a[i]);
    }
  }
  
  rep (i,N) {
    cout << DQ.front(); DQ.pop_front();
    if (i!=N-1) cout << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3840
import sys
def input():
	return sys.stdin.readline().strip()


N, M = list(map(int, input().split()))
AB = []
for i in range(M):
	AB.append(list(map(int, input().split())))

shima = [dict() for i in range(N)]
for i in range(N):
	shima[i]["size"] = 1
	shima[i]["parent"] = -1

huben_list = []
huben = N*(N - 1)//2

def parent(n, shima):
	x = n
	while shima[x]["parent"] != -1:
		x = shima[x]["parent"]
	return x

while len(AB) > 0:
	huben_list.append(huben)
	a, b = AB.pop()
	a -= 1
	b -= 1
	a_par = parent(a,shima)
	b_par = parent(b,shima)
	if a_par != b_par:
		huben -= shima[a_par]["size"]*shima[b_par]["size"]
		if shima[a_par]["size"] > shima[b_par]["size"]:
			shima[b_par]["parent"] = a_par
			shima[a_par]["size"] += shima[b_par]["size"]
		else:
			shima[a_par]["parent"] = b_par
			shima[b_par]["size"] += shima[a_par]["size"]


for i in range(M - 1 , -1, -1):
	print(huben_list[i])

Measured memory_bytes: 100572
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, L; cin >> N >> L;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    range(i, 0, N - 1) {
        lint sum_2 = a_list.at(i) + a_list.at(i + 1);
        if (sum_2 >= L) {
            cout << "Possible" << "\n";
            range(j, 0, i) cout << j + 1 << "\n";
            reversed_range(j, i + 1, N - 1) cout << j + 1 << "\n";
            cout << i + 1 << "\n";
            return 0;
        }
    }
    cout << "Impossible" << "\n";
}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a >= b && b >= c && c < a){
printf("%d %d %d\n",c,b,a);
}
else if(a <= b && b >= c && a <= c){
printf("%d %d %d\n",a,c,b);
}
else if(a > b && b < c && a < c){
	printf("%d %d %d\n",b,a,c);
}
else if(a > b && b < c && a > c ){
printf("%d %d %d\n",b,c,a);
}
else if(a < b && b > c && c < a){
printf("%d %d %d\n",c,a,b);
}
else if(a < b && b < c && a < c){
printf("%d %d %d\n",a,b,c);
}
return 0;
}

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

int main(){
    string s;
    cin >> s;
    int _max = 0,tmp = 0;

    for(int i=0; i<s.length(); i++){
        if(tmp != 0){
            tmp++;
            if(s[i] == 'Z'){
                _max = max(_max, tmp);
            }
        }else if(tmp == 0 && s[i] == 'A'){
            tmp++;
        }
    }
    cout << _max << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M; cin >> N >> M;
    ll K; cin >> K;
    vecl A(N),B(M);
    REP(i,N) cin >> A[i];
    REP(i,M) cin >> B[i];
    ll ans = 0;
    vecl cumA(N+1),cumB(M+1);
    REP(i,N) {
        cumA[i+1] = cumA[i] + A[i];
    }
    REP(i,M) {
        cumB[i+1] = cumB[i] + B[i];
    }
    for(ll i = 1; i <= N; i++) {
        ll l = 0;
        ll r = M+1;
        if(cumA[i] > K) continue;
        while(r-l > 1) {
            ll mid = (r+l)/2;
            if(cumB[mid] > K-cumA[i]) r = mid;
            else l = mid;
        }
        chmax(ans,i+l);
    }
    for(ll i = 1; i <= M; i++) {
        ll l = 0;
        ll r = N+1;
        if(cumB[i] > K) continue;
        while(r-l > 1) {
            ll mid = (r+l)/2;
            if(cumA[mid] > K-cumB[i]) r = mid;
            else l = mid;
        }
        //cout << l << " " << r << endl;
        chmax(ans,i+l);
    }
    cout << ans << endl;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> py(m);
  vector<vector<ll>> p(n + 1);
  vector<ll> hash(100000000);
  ll a, b;
  for(i = 0; i < m; i++){
    cin >> a >> b;
    p[a].push_back(b);
    py[i] = make_pair(a, b);
  }
  
  for(i = 1; i < n + 1; i++){
    sort(ALL(p[i]));
  }   
  
  ll buf;
  for(i = 0; i < m; i++){
    buf = lower_bound(ALL(p[py[i].first]), py[i].second) - p[py[i].first].begin();
    cout << setfill('0') << setw(12) << py[i].first * 1000000 + buf + 1 << endl;
  }
     
    
  
  
  return 0;
}

Measured memory_bytes: 789760
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:4
*Problem:Symmetric Grid
*Date:2018-4-21
*Algorithm:kawatea's Solution
*Stats:Unknown*/

bool debug=false;

int n,m;
string s[15];
string ss[15];
int a[15],b[15];

void cardTime(){
	while(clock()<=1990){}
}
              
void dfs2(int pos,bool mid){
	if(pos==m){
      cardTime();
		puts("YES");
		exit(0);
	}
	if(b[pos]!=-1){
		dfs2(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<m;i++){
		if(b[i]!=-1){
			continue;
		}
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][i]) break;
		}
		
		
		if(j==n){
			b[pos]=i;
			b[i]=pos;
			dfs2(pos+1,mid);
			b[pos]=-1;
			b[i]=-1;
		}
	}
	
	if(!mid){
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][pos]) break;
		}
		
		if(j==n){
			b[pos]=pos;
			dfs2(pos+1,true);
			b[pos]=-1;
		}
	}
}

void dfs(int pos,bool mid){
	if(pos==n){
		dfs2(0,!m%2);
		return;
	}
	if(a[pos]!=-1){
		dfs(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<n;i++){
		if(a[i]!=-1){
			continue;
		}
		if(ss[i]!=ss[pos]){
			continue;
		}
		
		a[i]=pos;
		a[pos]=i;
		
		dfs(pos+1,mid);
		
		a[pos]=-1;
		a[i]=-1;
	}
	
	if(!mid){
		a[pos]=pos;
		dfs(pos+1,true);
		a[pos]=-1;
	}
}

int main(int argc,char* argv[]){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cin>>s[i];
		ss[i]=s[i];
		sort(ss[i].begin(),ss[i].end());
	}
	
	memset(a,-1,sizeof(a));
	memset(b,-1,sizeof(b));
	
	dfs(0,!n%2);
	
  	cardTime();
	puts("NO");
	
	//Atcoder is just a fuck
	return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    val sArray = readLine()
        ?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.toIntArray()
        ?: intArrayOf()
    readLine()
    val tArray = readLine()
        ?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.toIntArray()
        ?: intArrayOf()
    var cnt = 0
    tArray.forEach { t ->
        for (s in sArray) {
            if (t == s) {
                cnt++
                break
            }
        }
    }
    println(cnt)
}


Measured memory_bytes: 33536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		sc.close();

		int count = 1;
		if(N <= 26) {
			int ans = (int) N - 1;
			System.out.println((char)('a' + ans));
			return;
		}

		long checkDigits = N;
		for(int i = 1; ;i++) {
			checkDigits -= (int) Math.pow(26, i);
			if(checkDigits > 0) {
				count++;
			}else {
				break;
			}
		}

		StringBuffer sb = new StringBuffer();
		while(N > 0) {
			long mod =  N % 26;
			if (mod == 0) {
                N--;
                mod = 25;
            } else {
                mod--;
            }
			sb.append((char)('a' + mod));
			N /= 26;
		}
		System.out.println(sb.reverse().toString());
	}

}

Measured memory_bytes: 35700
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    a = 0
    b = 0
    tmp = []
    for i in range(len(A)):
        if s % 2 != 0:
            if a >= (s // 2) - 1 or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
        else:
            if a >= (s // 2) or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
    ans1 = abs(a-b)
    ans2 = abs((a-tmp[-1]) - (b+tmp[-1]))
    print(min(ans1, ans2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    vector<bool> d(k+1, false);
    for(int i = 0; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(i >= a[j] && !d[i-a[j]]) d[i] = true;
        }
    }
    if(d[k]) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 256
import sys
from math import gcd
input = sys.stdin.readline
def main():
    K = int(input())
    total = 0
    for a in range(1,K+1):
        for b in range(1,K+1):
            tmp = gcd(a,b)
            for c in range(1,K+1):
                total+=gcd(tmp,c)
    print(total)
if __name__ == '__main__':
    main()

Measured memory_bytes: 70108
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}
signed main() {
	my_io();
	vector<int>v(6);
	for (int i = 0; i < 6; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < 6; i++) {
		int count = 0;
		for (int j = 0; j < 6; j++) {
			if (v[i] == v[j]) {
				count++;
			}
		}
		if (count >= 3) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}



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

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

	if (s.size() < t.size()) {
		std::cout << "UNRESTORABLE" << std::endl;
		return 0;
	}

	for (int i = s.size() - t.size(); i >= 0; --i) {
		bool isOK = true;
		for (int j = 0; j < t.size(); ++j) {
			if (s[i + j] != '?' && s[i + j] != t[j]) {
				isOK = false;
				break;
			}
		}

		if (isOK) {
			for (int j = 0; j < s.size(); ++j) {
				if (j < i || i + t.size() <= j)
					std::cout << (s[j] == '?' ? 'a' : s[j]);
				else
					std::cout << t[j - i];
			}
			std::cout << std::endl;

			return 0;
		}
	}

	std::cout << "UNRESTORABLE" << std::endl;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int item_v[100],item_w[100];
    rep(i,n){
        cin>>item_v[i]>>item_w[i];
    }
    
    int dp[101][10100]={};
    for(int i=1;i<=n;i++){
        dp[i][0] = dp[i-1][0];
        rep(j,10001){
            dp[i][j] = dp[i-1][j];
            if( j-item_w[i-1]>=0 ){
                dp[i][j] = max( dp[i][j] , dp[i][j-item_w[i-1]] + item_v[i-1] );
            }
        }
    }
    int maximum = -1;
    rep(j,m+1){
        maximum = max( maximum , dp[n][j] );
    }
    cout<<maximum<<endl;
}

Measured memory_bytes: 5152
#include<stdio.h>

int main(){
	int a[3],b[3];
	int i,c;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
		if(a[i]<0){
			a[i]=-a[i];
		}
	}

	if(a[0]>a[1]){
		c=a[0];
		a[0]=a[1];
		a[1]=c;
	}
	if(a[1]>a[2]){
		c=a[2];
		a[2]=a[1];
		a[1]=c;
	}
	if(a[0]>a[1]){
		c=a[0];
		a[0]=a[1];
		a[1]=c;
	}
	if(a[1]>a[2]){
		c=a[2];
		a[2]=a[1];
		a[1]=c;
	}

	printf("%d",a[2]-a[0]);
}

Measured memory_bytes: 128
#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>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
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;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
pair<ll,ll> f(ll x) {
	pair<ll, ll>ht;
	ll head = 0;
	ll tail = x % 10;
	while (x != 0) {
		if (x <= 9)head = x;
		x /= 10;
	}
	ht = make_pair(head,tail);
	return ht;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	if (n == 1) {
		cout << (a == b ? 1 : 0) << endl;
	}
	else if (b < a) {
		cout << 0 << endl;
	}
	else {
		cout << abs((n - 1) * b + a - ((n - 1) * a + b))+1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);

int main(){
	double a,b,x;
	cin >> a >> b >> x;
	double y = a * a * b * 0.5;
	if(x > y){
		double s = 2 * b - (2 * x / a / a);
//		cout << s << endl;
		double jd = 90 - atan (a / s) * 180 / PI;
		printf("%.10f\n",jd);
	}
	else{
		if(x == y) cout << 45.000000 << endl;
		else{
			double h = 2 * x / a / b;
			double jd = 90 - atan(h / b) * 180 / PI;
			printf("%.10f\n",jd);
		}
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue
  elif up == 1:
    if tmp < before:
      count += 1
      up = 0
      before = tmp
    else:
      before = tmp
  elif down == 1:
    if tmp > before:
      count += 1
      down = 0
      before = tmp
    else:
      before = tmp
count += 1
print(count)
      


Measured memory_bytes: 14436
fn main() {
    let ans = read::<String>().chars().filter(|&x| x == '1').count();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int K;
    cin >> K;
    vector<ll> a;
    rep(i, 9) a.push_back(i + 1);
    while(1){
        if(a.size() >= K){          
            cout << a[K - 1] << endl;
            return 0;
        }
        K -= a.size();
        vector<ll> old;
        swap(a, old);
        for(ll x : old){
            for(int i = -1; i <= 1; i++){
                int d = x % 10 + i;
                if(d < 0 || d > 9)continue;
                ll n = x * 10 + d;
                a.push_back(n);
            }
        }
    }
    
}

Measured memory_bytes: 1712
<?php

    // AtCoder Beginner Contest 164
    // C - gacha

    $n = in();
    $result = [];
    for ($i = 0; $i < $n; $i++) {
        $s = in();
        $result[$s] = true;
    }
    out(count($result));


    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


Measured memory_bytes: 31952
public class Main {


  private static void solve() {
    int n = ni();
    int[][] p = ntable(n, 3);
    long[][] dp = new long[n + 1][3];

    for (int i = 0; i < n; i ++) {
      dp[i + 1][0] = Math.max(dp[i][1], dp[i][2]) + p[i][0];
      dp[i + 1][1] = Math.max(dp[i][0], dp[i][2]) + p[i][1];
      dp[i + 1][2] = Math.max(dp[i][0], dp[i][1]) + p[i][2];
    }
    
    long ret = 0;
    for (int i = 0; i < 3; i ++) {
      ret = Math.max(ret, dp[n][i]);
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using namespace std;


int main()
{
	long long A, B, K;

	cin >> A >> B >> K;

	if (B - A + 1 <= 2 * K)
	{
		for (int i = A; i <= B; ++i)
		{
			cout << i << endl;
		}
	}
	else
	{
		for (int i = A; i < A + K; ++i)
		{
			cout << i << endl;
		}
		for (int i = B - K + 1; i <= B; i++)
		{
			cout << i << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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






int main(){
    int N, M; std::cin >> N >> M;
    std::vector<int> P(M), Y(M);
    std::vector<std::map<int, int>> mp(N);

    for(int i(0); i < M; ++i){
        std::cin >> P[i] >> Y[i];
        --P[i];
        mp[P[i]][Y[i]] = 1;
    }
    for(int i(0); i < N; ++i){
        int j(1);
        for(auto &x: mp[i]){
            x.second = j;
            ++j;
        }
    }
    for(int i(0); i < M; ++i){
        int v(P[i]);
        std::cout << std::setfill('0');
        std::cout << std::setw(6) << v + 1;

        std::cout << std::setw(6) << mp[v][Y[i]] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 12288
#include <cstdlib>
#include <iostream>
#include <random>
#include <vector>
using namespace std;

int n, k;

string generate() {
	static mt19937 engine;
	static uniform_int_distribution<char> rng('0', '1');

	string res;
	for(int i = 0; i < n; ++i)
		res += rng(engine);

	return res;
}

bool check(const string& s, const vector<vector<int>>& cards) {
	static const int lower = n / 8;
	static const int upper = lower * 3;
;
	for(int i = 0; i < k; ++i) {
		int sum = 0;
		for(int j = 0; j < n / 2; ++j) {
			sum += s[cards[i][j]] - '0';
		}

		if(sum < lower || sum > upper)
			return false;
	}

	return true;
}

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

	cin >> n >> k;

	vector<vector<int>> cards(k, vector<int>(n / 2));
	for(int i = 0; i < k; ++i) {
		for(int j = 0; j < n / 2; ++j) {
			cin >> cards[i][j];
			--cards[i][j];
		}
	}

	string ans;
	for(;;) {
		ans = generate();
		if(check(ans, cards)) break;
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

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

using namespace std;

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

typedef long long ll;
ll const INF = 1LL<<50;

int main() {
  int N;
  while(cin >> N && N)
  {
    N+=2;
    int p[N], t[N];
    p[0] = t[0] = 0;
    REP(i, 1, N-1) {
      cin >> p[i] >> t[i];
    }
    p[N-1] = 0, t[N-1] = 1<<29;
    
    ll dp[4], next[4];
    rep(_, 4) dp[_] = INF;
    dp[0] = 0;
    bool good = 1;
    rep(i, N-1) {
      rep(_, 4) next[_] = INF;
      int p1 = p[i], p2 = p[i+1];
      int t1 = t[i], t2 = t[i+1];
      rep(j, 4) {
        if(dp[j] == INF) continue;
        if(j < 3 && abs(p2-p1)*(j+1) <= t2-t1) {
          next[j+1] = min(next[j+1], dp[j]+abs(p2-p1));
        }
        if(p1*(j+1)+p2 <= t2-t1) {
          next[1] = min(next[1], dp[j]+p1+p2);
        }
      }
      bool ng = 1;
      rep(j, 4) {
        if(next[j] < INF) ng = 0;
      }
      if(ng) {
        cout << "NG " << i+1 << endl;
        good = 0; break;
      }
      rep(j, 4) { dp[j] = next[j]; }
    }
    if(good) {
      ll k = INF;
      rep(i, 3) { k = min(k, dp[i]); }
      cout << "OK " << k << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156