akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f // -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n, ans;
int a[N], s[N];
map<int, int> mp;

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]), s[i] = a[i];
	sort(s + 1, s + n + 1);
	for (int i = 1; i <= n; i++) mp[s[i]] = i;
	for (int i = 1; i <= n; i++) a[i] = mp[a[i]];
	for (int i = 1; i <= n; i++) ans += (i & 1) ^ (a[i] & 1);
	printf("%d\n", ans / 2);
	return 0;
}

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

using namespace std;

long GCD(long a, long b) {
  if (b == 0) {
    return a;
  }
  return GCD(b, a % b);  
}

int main() {
  long A, B;
  cin >> A >> B;
  
  long res = static_cast<long>(A * B / GCD(A, B));
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
	int x1,x2,x3,x4,y1,y2,y3,y4;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	x3=x2+y1-y2;
	y3=y2+x2-x1;
	x4=x1+y1-y2;
	y4=y1+x2-x1;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 998244353;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

ll dp[3005][3005];
ll dp1[3005][3005];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	ll s; cin >> s;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0][0] = 0;
	dp1[0][0] = 0;
	for (ll i = 1; i <= n; i++) {
		ll x = a[i - 1];
		dp[i][x] = i;
		for (ll sum = 0; sum <= s; sum++) {
			(dp[i][sum] += (sum >= x ? dp1[i - 1][sum - x] : 0)) %= mod;
			dp1[i][sum] = (dp1[i - 1][sum] + dp[i][sum]) % mod;
		}
	}


	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		(ans += dp[i][s] * (n - i + 1)) %= mod;
	}
	cout << ans << endl;
	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

Measured memory_bytes: 141312
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static void Main() {
        var nk = ReadInts();
        int k = nk[1];
        var xs = ReadInts();

        var max = xs.OrderByDescending(e => e).Take(k).Sum();
        Console.WriteLine(max);
    }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    VLL a(n);

    rep(i,n) cin >> a[i];
    sort(all(a));
    ll ans = a[n-1] - a[0];
    FOR(i,1,n-1) ans += abs(a[i]);
    cout << ans << endl;
    ll x = a[0]; // 引く数
    ll y = a[n-1]; //たす数
    FOR(i,1,n-1){
      if(a[i]<0){ cout << y << ' ' << a[i] << endl; y -= a[i];}
      else{ cout << x << ' ' << a[i] << endl; x -= a[i];}
    }
    cout << y << ' ' << x << endl;

    return 0;
}


Measured memory_bytes: 2688
using System;
using System.Linq;

namespace _3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int w = 0; int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int a = x[0]; a <= x[1]; a++)
            { int q = x[2];
                
                if (q % a == 0)
                {
                    w++;
                }
                else
                {
                   
                }
            }
            Console.WriteLine(w);
        }
    }
}
//?¶??????????????????????????????????????????????????????????

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int k, s;
    cin >> k >> s;

    int ans = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (z < 0 or z > k) continue;
            ans++;
        }
    }

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

Measured memory_bytes: 3616
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll n;cin>>n;
  ll sum=0;
  vector<ll>A(n);
  rep(i,n)cin>>A[i];
  rep(i,n)sum+=A[i];
  vector<ll>x(n+1,0);
  rep(i,n){
    if(i%2)x[0]-=A[i];
  }
  x[0]*=2;
  x[0]+=sum;
  x[n]=x[0];
  rep(i,n){
    x[i+1]=2*A[i]-x[i];
  }
  rep(i,n)cout<<x[i]<<endl;
  // cout<<x[0]<<endl;
  return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


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


int main()
{
	int n;
	cin>>n;
	int h[n+10];
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=n-1;i>0;i--)
		if(h[i]<h[i-1])h[i-1]--;
	for(int i=0;i<n-1;i++)
		if(h[i]>h[i+1]){
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

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

typedef long long ll;
const int N = 2e2 + 9, M = 9e2 + 9, OO = 0x3f3f3f3f;
const double EPS = 0.00000000001;
const int mod = 1000000000+7;


int n, w[N], mn = OO;

int s1(int t){
	int s = 0;
	for(int i = 0 ; i <= t ; ++i) s += w[i];
	return s;
}

int s2(int t){
	int s = 0;
	for(int i = t+1 ; i < n ; ++i) s += w[i];
	return s;
}

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

	scanf("%d", &n);
	for(int i = 0 ; i < n ; ++i) scanf("%d", w+i);
	for(int t = 0 ; t < n ; ++t) mn = min(mn, abs(s1(t)-s2(t)));
	printf("%d\n", mn);


	return 0;
}


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

struct UnionFind {
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y); //rank?
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int x){
        if(data[x] < 0) return x;
        return data[x] = root(data[x]); //経路圧縮
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return (-data[root(x)]);
    }
};

int n, m, k;
vector<vector<int>> fr(101010, vector<int>(0)), bl(101010, vector<int>(0));


int main()
{
    cin >> n >> m >> k;
    UnionFind uf(101010);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        fr[a].emplace_back(b);
        fr[b].emplace_back(a);
        uf.unite(a, b);
    }
    rep(i, k)
    {
        int c, d;
        cin >> c >> d;
        bl[c].emplace_back(d);
        bl[d].emplace_back(c);
    }

    for (int i = 1; i <= n; i++)
    {
        int res = uf.size(i) - 1;
        res -= fr[i].size();
        for(auto x : bl[i])
        {
            if(uf.same(i, x))
            {
                res--;
            }
        }
        printf("%d\n", res);
    }

    return 0;
}

Measured memory_bytes: 12280
def show (nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else :
            print(nums[i])
 
n=int(input())
nums=list(map(int,input().split()))
show(nums)
for i in range(1,n):
    v=nums[i]
    j=i-1
    while (j>=0 and nums[j]>v):
        nums[j+1]=nums[j]
        j-=1
    nums[j+1]=v
    show(nums)


Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    using T = pair<int, int>;
    vector<T> v(M);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        v[i].first = a;
        v[i].second = b;
    }
    // 開始が遅いものから選ぶ
    sort(v.begin(), v.end(), [](T &a, T &b) {
        return a.first > b.first;
    });
    int count = 0;
    while (!v.empty())
    {
        ++count;
        auto i = v.begin()->first;
        v.erase(remove_if(v.begin(), v.end(), [&i](T &p) { return p.first <= i && i < p.second; }), v.end());
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> brick(N);
  for(int i = 0; i < N; i++) {
    cin >> brick.at(i);
  }
  int a = 1;
  for(int i = 0; i < N; i++) {
    if(brick.at(i) == a) {
      a++;
    }
  }
  if(a == 1) {
    cout << -1 << endl;
  }
  else {
    cout << N - a + 1 << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

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

  int acc = accumulate(s.begin(), s.end(), 0);
  sort(s.begin(), s.end());

  rep(i, 0, n + 1) {
    if (acc % 10) {
      cout << acc << endl;
      return 0;
    }
    if (s[i] % 10 && i < n)
      acc -= s[i];
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
template<class T=ll> 
T in(){T x;cin>>x;return (x);}
template<class T> 
void print(T &x){cout<<x<<"\n";}
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x"="<< (x) << "\n"
#define dbgv(x) cerr<<#x<<"\n";reps(y,x){cerr<<y<<" ";}cerr<<"\n"

inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}

int main(){
  ll n=read(),a=read(),b=read(),ans=1e9,c=a-b;
  vector<ll> h(n);
  rep(i,n){
    h[i]=read();
  }
  ll left=1,right=1e9,mid,cnt=0;
  while (right!=left+1) {
    mid =(right+left)/2;
    cnt=0;
    rep(i,n){
      ll temp=h[i]-b*mid+c-1;
      if(temp>0){
        cnt+=temp/c;
      }
    }
    if(cnt<mid){
      right=mid;
    }else left=mid;
  }
  cnt=0;
  rep(i,n){
    ll temp=h[i]-b*right+c-1;
    if(temp>0){
      cnt+=temp/c;
    }
  }
  ans=min(ans,max(cnt,right));
  cnt=0;
  rep(i,n){
    ll temp=h[i]-b*left+c-1;
    if(temp>0){
      cnt+=temp/c;
    }
  }
  ans=min(ans,max(cnt,left));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 4001;
void ADD(LL& x,LL v){
    x=(x+v)%MOD;
}
LL dp0[SIZE][SIZE];
LL CC[SIZE][SIZE];
LL C(int x,int y){
    if(x<y||y<0)return 0;
    if(!y)return 1;
    LL res=CC[x][y]-CC[x][y-1];
    if(res<0)res+=MOD;
    return res;
}
void build(){
    REP(i,SIZE){
        CC[i][0]=1;
        REPP(j,1,i+1){
            CC[i][j]=CC[i-1][j-1];
            ADD(CC[i][j],CC[i-1][j]);
        }
    }
    REPP(i,1,SIZE){
        REPP(j,1,SIZE){
            ADD(CC[i][j],CC[i][j-1]);
        }
    }
    REPP(A,1,2001){
        dp0[A][0]=dp0[0][A]=1;
        REPP(B,1,2001){
            dp0[A][B]=CC[B-1][min(B-1,A)];
        }
    }
    REPP(A,1,2001)REPP(B,1,2001){
        ADD(dp0[A][B],dp0[A-1][B]);
    }
}
int main(){
    LL an=1;
    build();
    DRII(A,B);
    REPP(AA,1,A+1){
        REPP(BB,0,min(B-1,AA)+1){
            //printf("[%d,%d]=%lld,%lld\n",AA,BB,C(B-1,BB),dp0[AA-BB][BB]);
            ADD(an,C(B-1,BB)*dp0[AA-BB][BB]);
        }
    }
    cout<<an<<endl;
    return 0;
}


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

int main()
{
        double x1,y1,x2,y2,x3,y3;
        double xp,yp;
        double xv1,yv1,xv2,yv2,xvp,yvp;
        double t,u;

        while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
                xv1 = x2 - x1;
                yv1 = y2 - y1;
                xv2 = x3 - x1;
                yv2 = y3 - y1;
                xvp = xp - x1;
                yvp = yp - y1;

                t = (xvp*yv2-yvp*xv2)/(xv1*yv2-xv2*yv1);
                u = (yvp*xv1-xvp*yv1)/(xv1*yv2-xv2*yv1);

                if(0.0 < t && 0.0 < u && 0.0 < t+u && t+u < 1.0){
                        cout << "YES" << endl;
                }else{
                        cout << "NO" << endl;
                }
        }

        return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;
#define all(x) x.begin(),x.end()
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
  int A[3];
  string ans="Yes";
  for(int i=0;i<3;i++){
    A[i]=read();
    if(A[i]<=0||(i>0&&A[i]!=A[i-1]))ans="No";
  }
  printf("%s\n", ans.c_str());
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)
const ll MAX = 3234566667;
vector<ll> ans(0);

void dfs(ll i) {
    ans.push_back(i);
    if (i > MAX) return;
    ll dig = i;
    while (dig >= 10) dig %= 10;
    if (dig > 0) dfs(i * 10 + dig - 1);
    if (dig < 9) dfs(i * 10 + dig + 1);
    dfs(i * 10 + dig);
}

int main() {
    int k; cin >> k;
    for (int i = 1; i < 10; i++) dfs(i);
    sort(ans.begin(), ans.end());
    cout << ans[k - 1] << endl;
}


Measured memory_bytes: 7036
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	string S; cin >> S;
	int a = 0, b = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') a++;
		else b++;
	}

	cout << 2 * min(a,b)<< endl;
}


Measured memory_bytes: 512
x, n = map(int, input().split())
p = list(map(int, input().split()))


pn = [0] * 105
nn = [0] * 105


for pp in p:
    a = pp - x
    if a > 0:
        pn[a] = 1
    elif a < 0:
        nn[-a] = 1
    else:
        pn[0] = nn[0] = 1

for i in range(101):
    if nn[i] == 0:
        print(x-i)
        exit(0)
    if pn[i] == 0:
        print(x+i)
        exit(0)


Measured memory_bytes: 9200
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 00:27:57 2020

@author: Kanaru Sato
"""
a,b,c = list(map(int,input().split()))

diff = [a-b, b-c, c-a]

flag = 0

if diff[0]*diff[1]*diff[2] == 0:
    if abs(diff[0])+abs(diff[1])+abs(diff[2]) != 0:
        flag = 1

if flag == 0:
    print("No")
else:
    print ("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  vi cnt(N,0);
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }
  rep(i,N) {
    if(cnt[i]&1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 3720
# /usr/bin/python
# -*- coding: utf-8 -*-



N,M = map(int, input().split())
csum = [0]*(N+2)
for _ in range(M):
  l,r = map(int, input().split())
  csum[l] += 1
  csum[r+1] -= 1

for i in range(1,N+2):
  csum[i] += csum[i-1]
print(csum.count(M))


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

int read() {
    int x=0,f=1,ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
#define REP(i,e,s) for(register int i=e; i<=s; i++)

#define MXAN (10000+10)

int s[MXAN],q;

int main () {
    int n=read(),t;
    REP(i,1,n) s[i]=read();
    t=read();
    int ans=0;
    REP(i,1,t) {
        q=read();
        REP(i,1,n)if(q==s[i]) {ans++;break;}
    }

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


Measured memory_bytes: 3248
H, W, A, B = map(int, input().split())
maze = [['0'] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if (i < B and j >= A) or (i >= B and j < A):
            maze[i][j] = '1'

for i in range(H):
    for j in range(W):
        print(maze[i][j], end="")
    print()


Measured memory_bytes: 15348
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ma = max(a)
    diff = 100000000000000
    ans = 0
    for aa in a:
        t = abs(ma//2-aa)
        if ma != aa and diff > t:
            diff = t
            ans = aa
    print(ma,ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14052
#include <cstdio>
#include <cstdlib>

int As[100008];
int Bs[100008];
int Cs[100008];
int ids[100008];
int cmp(const void *a,const void *b) {
	int ida = *(int *)a;
	int idb = *(int *)b;
	if(Cs[ida] > Cs[idb]) return -1;
	if(Cs[ida] < Cs[idb]) return 1;
	return 0;
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		scanf("%d%d",&As[i],&Bs[i]);
		Cs[i]=As[i]+Bs[i];
		ids[i]=i;
	}
	qsort(ids,N,sizeof(int),cmp);
	long long sol=0;
	for(int i=0;i<N;i++) {
		int idx = ids[i];
		if(i%2) {
			sol-=Bs[idx];
		} else {
			sol+=As[idx];
		}
	}
	printf("%lld\n",sol);
	return 0;
}


Measured memory_bytes: 2172
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
const int N=55;
//Code begin....

int a[N];
VI v;

int Sol(int x){
    v.clear();
    v.pb(0);
    FOR(i,1,12) {
        if (x&(1<<i)) {
            if (a[i]==0) return 0;
            else if (a[i]==1) v.pb(i);
            else v.pb(i), v.pb(24-i);
        }
        else {
            if (a[i]==1) v.pb(24-i);
            else if (a[i]>1) return 0;
        }
    }
    sort(v.begin(),v.end());
    int ma=100;
    for (int i=1; i<v.size(); ++i) ma=min(ma,v[i]-v[i-1]);
    return ma==100?0:min(ma,24-ma);
}
int main ()
{
    int n, x, ma=0;
    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",&x), ++a[x];
    FOR(i,1,11) ma=max(ma,a[i]);
    if (a[0]||a[12]>1||ma>2) {puts("0"); return 0;}
    int top=(1<<13)-1;
    int ans=0;
    FOR(i,0,top) {
        if (i&1) continue;
        ans=max(ans,Sol(i));
    }
    FOR(i,1,12) if (a[i]) {ans=min(ans,i); break;}
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n==3) {
		printf("2\n1 3\n2 3");
	}
	else if(n==4) {
		printf("4\n1 2\n1 3\n4 2\n4 3");
	}
	else if(n&1) {
		printf("%d\n",4*(n/2-1)+4);
		for(int i=1;i<=n/2-1;++i) {
			printf("%d %d\n",i,n-1-i);
			printf("%d %d\n",i,i+1);
			printf("%d %d\n",n-i,n-i-1);
			printf("%d %d\n",n-i,i+1);
		}
		printf("%d %d\n",n,n/2);
		printf("%d %d\n",n,n/2+1);
		printf("%d %d\n",n,1);
		printf("%d %d\n",n,n-1);
	}
	else {
		printf("%d\n",2*n);
		for(int i=1;i<n/2;++i) {
			printf("%d %d\n",i,n-i);
			printf("%d %d\n",i,i+1);
			printf("%d %d\n",n-i+1,n-i);
			printf("%d %d\n",n-i+1,i+1);
		}
		printf("%d %d\n",n/2,1);
		printf("%d %d\n",n/2,n);
		printf("%d %d\n",n/2+1,1);
		printf("%d %d\n",n/2+1,n);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a+b>=10?"error":to_string(a+b));    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<=n;i++)
typedef long long ll;
using namespace std;
int main()
{
   string N;
   cin >> N;
   ll ans = 0;
   rep(i,0,N.length()){
     if(N[i]=='2')++ans;
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<vector<pii>> v(n);
	rep(i,n) {
		int a;
		cin >> a;
		int x, y;
		rep(j,a) {
			cin >> x >> y;
			x--;
			v[i].push_back(pii(x, y));
		}
	}
	int ans = 0;
	rep(bit, (1 << n)) {
		bool b = true;
		int t = 0;
		rep(i, n) {
			if (!(bit & (1 << i))) continue;
			t++;
			for (auto p: v[i]) {
				if ((bool)(bit & (1 << p.first)) != p.second) b = false;
			}
		}
		if (b) ans = max(ans, t);
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            if (S[0] == S[1] && S[1] == S[2])
            {
                WriteLine("No");
            }
            else
            {
                WriteLine("Yes");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

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

    int res = 0;
    rep(i, n) {
        res += i;
    }
    rep(i,m) res += i;

    cout << res << endl;
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;



int main(){
    sync
  //  file();
   	int n,k;
   	cin>>n>>k;
   	vector<ll> dp(k+1);
   	dp[0] = 1;
   	forn(i,n){
   		int x;
   		cin>>x;
   		vector<int> fake(k+1);
   		for(int j=k;j>=0;--j){
   			int l = j+1;
   			int r = j+min(x,k-j)+1;
   			if(l<r&&l<=k){
   				fake[l]+=dp[j];
   				fake[l]%=mod;
   				if(r<=k){
   				fake[r]-=dp[j];
   				fake[r]+=mod;
   				fake[r]%=mod;
   			}
   			}
   		}
   		ll pre = 0;
   		fore(lel,0,k){
   			pre+=fake[lel];
   			pre%=mod;
   			dp[lel]+=pre;
   			dp[lel]%=mod;
   		}
   	}
   	cout<<dp[k]<<endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
int x[100005];
ll fact[100005];
ll MOD = 1000000007;

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res % MOD;
}

ll comb(ll n, ll k) {
	if (n < k) return 0;
	ll res = fact[n] % MOD;
	res = res * mod_pow(fact[k], MOD-2) % MOD;
	res = res * mod_pow(fact[n-k], MOD-2) % MOD;
	return res % MOD;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	int l, r;
	fill(x, x+n+1, 0);
	for (int i = 1; i <= n+1; i++) {
		int a;
		cin >> a;
		if (x[a]) {
			l = x[a];
			r = i;
		}
		x[a] = i;
	}
	fact[0] = 1;
	fact[1] = 1;
	for (int i = 1; i <= n; i++) fact[i+1] = (i+1) * fact[i] % MOD;

	for (int i = 1; i <= n+1; i++) {
		ll ans = comb(n+1, i) - comb(n+l-r, i-1);
		if (ans < 0) ans += MOD; 
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
a,b,c,x,y = map(int, input().split())

if a>= c*2 and b >= c*2:
    print(max(x,y)*c*2)

elif a>= c*2 and x>=y :
    print(x*c*2)

elif b >= c*2 and y>=x:
    print(y*c*2)

elif a + b < c*2:
    print(a*x+b*y)
    
elif a+b >= c*2:
    if x > y:
        print(y*c*2+(x-y)*a)
    else:
        print(x*c*2+(y-x)*b)

Measured memory_bytes: 9184
#include<stdio.h>
  int main(void)
{
   int a,b,c,x,cnt=0;
   scanf("%d %d %d",&a,&b,&c);
   for(x = a;x <=b;x++)
   {
    if(c%x==0)
        cnt++;
   }
   printf("%d\n",cnt);
   return 0;

}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  bool ok = true;
  ll sum = accumulate(all(a), 0);
  rep(i, m) if(a[i] * 4 * m < sum) ok = false;
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=1e6;
    int N;
    int w[n], h[n];
    for(int i=0;i<n;i++){
        cin >> h[i] >> w[i];
        if(h[i]==0 && w[i]==0){
            N=i;
            break;
        }
    }
    
    for(int k=0;k<N;k++){
        for(int i=0;i<h[k];i++){
            for(int j=0;j<w[k];j++){
                if((i+j)%2==0)cout << "#";
                else if((i+j)%2==1) cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
 
using namespace std;
 
int mod=1e9+7;
 
int main()
{
    int n,k;
    cin >> n >> k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int dp[n+1][k+1];
    dp[0][0]=1;
    for(int i=1;i<=k;i++)  
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        int sums[k+1];
        sums[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)
        {
            sums[j]=(sums[j-1]+dp[i-1][j])%mod;  
        }
        for(int j=0;j<=k;j++)
        {
            int tr=sums[j];  
            int unreachable=j-a[i]-1; 
            if(unreachable>=0)
            {
                tr=(tr-sums[unreachable]+mod)%mod; 
            }
            dp[i][j]=tr;
        }
    }
  	cout << dp[n][k];
    return 0;
}


Measured memory_bytes: 40064
n = int(input())
a = list(map(int, input().split()))

com = a[0]
flag = 0
count = 1
for i in range(1, n):
    if flag == 1:
        if com > a[i]:
            flag = 0
            count += 1
    elif flag == -1:
        if com < a[i]:
            flag = 0
            count += 1
    else:
        if com < a[i]:
            flag = 1
        elif com > a[i]:
            flag = -1
    com = a[i]
print(count)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
        x=x*r-d;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 256
import sys
sys.stdin.readline

n = int(input())
a = []
for _ in range(n):
    sa = input().strip()
    tmp = 0
    for i in range(len(sa)):
        if sa[i] == '.':
            break
        tmp = tmp * 10 + int(sa[i])
    i += 1
    for j in range(i, i + 9):
        if j < len(sa):
            tmp = tmp * 10 + int(sa[j])
        else:
            tmp *= 10
    a.append(tmp)

div25 = [[0, 0] for _ in range(n)]
for i, _a in enumerate(a):
    while _a % 2 == 0:
        div25[i][0] += 1
        _a //= 2
    while _a % 5 == 0:
        div25[i][1] += 1
        _a //= 5

div25.sort(key=lambda x: (-x[1], -x[0]))

plot = [[0 for _ in range(45)] for _ in range(20)]
ans = 0
for d25 in div25:
    rem2, rem5 = max(0, 18 - d25[0]), max(0, 18 - d25[1])
    for j in range(rem5, 20):
        for k in range(rem2, 45):
            ans += plot[j][k]
    plot[d25[1]][d25[0]] += 1
print(ans)

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

long long diff(long long a, long long b){
	if(a>b)
		return a-b;
	else
		return b-a;
}

long long solve(long long arr[], long long n,int k){
	int dp[n];
	dp[0]=0;
	dp[1]=diff(arr[1],arr[0]);
	for(int i=2;i<n;i++){
		long long ans=INT_MAX;
		for(int j=1;j<=k;j++){
			if(i-j>=0)
				ans = min(ans,diff(arr[i],arr[i-j])+dp[i-j]);
			else
				break;
		}
		dp[i]=ans;
	}
	return dp[n-1];
}

int main(int argc, char **argv)
{
	long long N;
	int k;
	cin>>N>>k;
	long long arr[N];
	for(int i=0;i<N;i++){
		cin>>arr[i];
	}
	cout<<solve(arr,N,k)<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
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 dbg(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define dbg(x...)
#endif
#define endl "\n"
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define ROF(i, a, n) for (ll i = a; i >= n; i--)
#define all(x) (x).begin(), (x).end()
#define dline cout << "///REACHED///\n";

typedef long long ll;

const ll MOD = 1e+9 + 7;
const ll INF = 1e9+5;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 4e+5 + 7;

vector<vector<ll>> work;;
vector<vector<ll>> dp;
ll maxOtherTwo(int i,int day){
	if(i==1){
		return max(dp[day][1],dp[day][2]);
	}
	if(i==2){
		return max(dp[day][2],dp[day][0]);
	}
	return max(dp[day][1],dp[day][0]);
	
}


ll n;
void solve(){
	cin>>n;
	work.resize(n,(vector<ll>(3,0)));
	dp.resize(n,vector<ll>(3,0));
	FOR(i,0,n){
		cin>>work[i][0]>>work[i][1]>>work[i][2];
	}
	dp[0]=work[0];
	FOR(i,1,n){
		FOR(j,0,3){
			// if(i+1<n and i-1>=0)
			dp[i][j] = /* max ele such that its not jth work on previous dp  + currwork*/ work[i][j]+maxOtherTwo(j+1, i-1);
		}
	}
	// dbg(dp);
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 14220
#include<cstdio>
#include<vector>
#include<string>
#include <iostream> 
 
using namespace std;
 
int main(){
  string st;
  int i;
  string week[7];
  
  week[0]="SUN";
  week[1]="MON";
  week[2]="TUE";
  week[3]="WED";
  week[4]="THU";
  week[5]="FRI";
  week[6]="SAT";
 
  
  cin >> st;
  for(i=0;week[i]!=st;i++);
   
  cout << 7-i;
    
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 k;
  cin >> k;
  vi64 a(50, 49);
  rep(i, 50) a[i] += k / 50;
  rep(i, k % 50) {
    rep(j, 50) if (i != j) a[j]--; else a[j] += 50;
  }
  cout << 50 << endl;
  rep(i, 50) {
    if (i == 49) cout << a[i] << endl;
    else cout << a[i] << " ";
  }
  return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
MOD = 1000000007

def f(n):
    ans = 1
    for i in range(1,n+1):
        ans*=i
        ans%=MOD
    return ans

sum = 0
if -2<n-m<2:
    if n<m:
        n,m = m,n
    sum = f(n)*f(m)*2**(m-n+1)
    sum %= MOD
print(sum)


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

int N;
long long Y;

void solve() {
  bool f = false;
  for(int i = (Y / 10000); i >= 0; i--) {
   int k = (Y - 10000 * i) / 1000;
   if((k - N + i) % 4 == 0 && k - 5 * (k - N + i) / 4 >= 0 && (k - N + i) / 4 >= 0) {
     int j = (k - N + i) / 4;
     k = k - 5 * (k - N + i) / 4;
     cout << i << " " << j << " " << k << endl;
     f = true;
     break;
   }
   if(f) break;
  }
  if(f == false) cout << -1 << " " << -1 << " " << -1 << endl;
}


int main() {
  cin >> N >> Y;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const ll MAX_N = 3005;

// dp[i][j] .. longest common substring in [0,i) and [0,j)
ll dp[MAX_N][MAX_N];

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  string s;
  string t;
  cin >> s;
  cin >> t;
  ll n = s.size();
  ll m = t.size();
  rep(i, n) rep(j, m) {
    if (s[i] == t[j]) {
      chmax(dp[i+1][j+1], dp[i][j]+1);
    } else {
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  string ans;
  ll i = n;
  ll j = m;
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i-1][j]) {
      --i;
    } else if (dp[i][j] == dp[i][j-1]) {
      --j;
    } else { // Here, s[i-1] == t[j-1]
      ans += s[i-1];
      --i;
      --j;
    }
  }
  reverse(all(ans));

  rep(i, ans.size()) {
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, P; cin >> N >> P;
  int odd = 0, even = 0;
  REP(i, N) {
    int a; cin >> a;
    if (a % 2 == 0) even++;
    else odd++;
  }

  if (odd == 0) {
    cout << (P==0 ? (ll)pow(2, even) : 0) << endl;
  } else {
    cout << (ll)pow(2, N-1) << endl;
  }
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.push_back({a,b});
    }
    sort(v.begin(), v.end());
    int res = m;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int buy = min(res, v[i].second);
        ans += (ll)buy * v[i].first;
        res -= buy;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
typedef  struct{
	double x,y;
}coord;

int main(){
	coord  vPolygon[3],pPoint;
	while(cin >> vPolygon[0].x >> vPolygon[0].y){
		for (int i=1;i<3;i++) cin >> vPolygon[i].x >> vPolygon[i].y;
		cin >> pPoint.x >> pPoint.y;
		int count= 0;
		for (int i=0;i<3;i++){
			if ( ((vPolygon[i%3].y <= pPoint.y)&&(pPoint.y < vPolygon[(i+1)%3].y))
				|| ((vPolygon[(i+1)%3].y <= pPoint.y)&&(pPoint.y < vPolygon[i%3].y)) ){
				double vt = (pPoint.y - vPolygon[i%3].y)/(vPolygon[(i+1)%3].y - vPolygon[i%3].y);
			if (pPoint.x < vPolygon[i%3].x + ( vt * ( vPolygon[(i+1)%3].x - vPolygon[i%3].x) )){
				++count;
			}
		}
	}
	cout << ((count&1)?"YES":"NO") << endl;
}
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define ll long long
#define pi 3.1415926535897
#define io  ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
int br[1000006];
int main(){
                int n;
                cin>>n;
                int ar[n];
                for(int i = 0 ; i<n-1;i++){
                    cin>>ar[i];
                }
                for(int i = 0 ; i<n-1;i++){
                    br[ar[i]]+=1;
                }
                for(int i = 1 ; i<=n;i++){
                   cout<<br[i]<<endl;
                }
return 0;
}


Measured memory_bytes: 5084
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, a, b = map(int, readline().split())
    x = list(map(int, readline().split()))

    l = (b + a - 1) // a
    ans = 0
    for i in range(n-1):
        diff = x[i + 1] - x[i]
        if diff >= l:
            ans += b
        else:
            ans += a * diff

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin >> n;
    long long a[100000+1] = {};
    long long sum = 0;
    for(int i =0; i < n ; i++)
    {
        int x; cin >> x;
        sum+=x;
        a[x]++;
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++)
    {
        long long b, c;
        cin >> b >> c;
        if(!a[b])
        {
            cout << sum << endl;
        }
        else
        {
            sum = sum - a[b]*b + a[b]*c;
            a[c] = a[c] + a[b];
            a[b] = 0;
            cout << sum << endl;
        }
    }
    return 0;

}


Measured memory_bytes: 4380