akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

struct SegmentTree {
private:
    ll n;
    vector<ll> node;
    //int nとvector<int> nodeの2つを変数に持つ

public:
    //初期化処理
    SegmentTree(vector<ll> v) {
        ll sz = v.size(); //vは扱う配列の長さ
        n = 1; while(n < sz) n *= 2; //nはvの配列を入れるために必要なseg treeの葉の数
        node.resize(2*n-1, 0); //segtreeでは全部で2n-1の配列が必要 ★演算によって単位元を変える
        for(int i=0; i<sz; i++) node[i+n-1] = v[i]; //segtreeの葉の部分に扱う配列を埋め込む
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]); //★演算によって変える場所　segtreeを作る(注目しているnode iの子ノードを見て二項演算をして、node iの値を決定する)
    }

    void update(ll x, ll val) {
        x += (n - 1); //配列のx番目の要素を更新しようとするとき、segtreeで対応する要素はx+n-1番目である
        node[x] = val; //segtree上で値を更新
        while(x > 0) { //葉から根に向かってsegtreeの要素を更新していく
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]); //★演算によって変える
        }
    }

    ll getmax(ll a, ll b, ll k=0, ll l=0, ll r=-1) {
        //求めたいのは区間[a,b)の中で演算しつづけた結果(たとえばこの区間の最小値)
        //自分がいるノードのindex(何階にいるか？)
        //ノードkは元の配列でいうとどの区間をカバーしているか？
        if(r < 0) r = n; //最初に呼び出す時はノードk=0はsegtreeの根なので区間は[0,n)を指す
        if(r <= a || b <= l) return 0; //今のノードが求める区間と無関係の場合は、最終的な答えに影響しない単位元(最小値を求めたい場合は単位元はINF)を返す 演算によって変える
        if(a <= l && r <= b) return node[k]; //今見ている区間[l,r)が答えを求めたい区間[a,b)に完全に含まれるなら、この区間について演算し続けた結果(=node[k];例えば最小値)を返す

        //上記に当てはまらない場合
        //kの子ノードを見に行って、再帰的に処理を行う k=0の場合はノード1と2を見る
        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2); //kの子ノード(left)の子孫のうち、求めたい区間に含まれる要素について演算し続けた結果を返す
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r); //kの子ノード(right)の子孫のうち、求めたい区間に含まれる要素について演算し続けた結果を返す
        return max(vl, vr); //演算によって変える場所 子ノードの子孫のうち、演算しつづけた結果を返す
    }
};

int main(){
    ll n ; cin >> n;
    vector<ll> h(n),a(n);
    rep(i,n){
        cin >> h.at(i);
        h.at(i)--;
    }
    rep(i,n) cin >> a.at(i);

    vector<ll> lst(n,0);
    SegmentTree tree(lst);

    rep(i,n){
        ll mxm = tree.getmax(0,h.at(i));
        tree.update(h.at(i),mxm+a.at(i));
    }

    ll ans = 0;
    rep(i,n){
        ans = max((ans),(tree.getmax(i,i+1)));
    }
    cout << ans << endl;    
}

Measured memory_bytes: 10624
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#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>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

    ll a[100010];
int main(void){
    ll n;
    ll ans=0;
    cin >> n;
    REP(i, n){
        ll tmp;
        cin >> tmp;
        a[tmp]++;
    }

    ll dnum=0;
    REP(i, 100010){
        if(a[i] > 1){
            dnum  += a[i] -1;
        }
    }

    if(dnum % 2){
        dnum +=1;
        ans = n-dnum;
    }else{
        ans = n-dnum;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int N=sc.nextInt(),M=sc.nextInt(),a[]=new int[N],b[]=new int[N],c[]=new int[M],d[]=new int[M];
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
        }
        for(int i=0;i<M;i++){
            c[i]=sc.nextInt();
            d[i]=sc.nextInt();
        }
        for(int i=0;i<N;i++){
            Pair dis = new Pair(-1,Integer.MAX_VALUE);
            for(int j=0;j<M;j++){
                int e=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
                if(dis.b>e){
                    dis.a=j;
                    dis.b=e;
                }
            }
            System.out.println(dis.a+1);
        }
    }
}
class Pair{
    int a,b;
    public Pair(int a,int b){
        this.a=a;
        this.b=b;
    }
}


Measured memory_bytes: 36056
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq;
    int tmp=0;
    for (int i=1;i<=999;i++) {
        tmp+=i;
        deq.emplace_back(tmp);
    }
    int a,b;
    cin>>a>>b;
    for (int j=0;j<deq.size()-1;j++) {
        if (deq[j]-a==deq[j+1]-b) {
            cout<<deq[j]-a<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-3;
const int MAXN = 1e5 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;



int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int a,b,k;
    scanf("%d%d%d",&a,&b,&k);
    if((b-a+1) <= 2*k) {
        for(int i=a; i<=b; i++)
            printf("%d\n",i);
    }
    else {
        for(int i=a; i<a+k; i++)
            printf("%d\n",i);
        for(int i=b-k+1; i<=b; i++)
            printf("%d\n",i);
    }
    return 0;
}


Measured memory_bytes: 256
def nibungi_search(arr, a)
  return false if arr.size <= 1 && arr.last != a
  mid = (arr.size/2).floor
  n = arr[mid]

  if a == n
    return true
  elsif a > n
    nibungi_search(arr[mid..-1], a)
  else
    nibungi_search(arr[0..mid-1], a)
  end
end

loop do
  n = gets.to_i
  break if n == 0

  arr = gets.split(' ').map(&:to_i).sort
  _q = gets.to_i
  q_arr = gets.split(' ').map(&:to_i)

  count = 0
  q_arr.each do |a|
    count += 1 if nibungi_search(arr, a)
  end
  puts count
end

Measured memory_bytes: 22660
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  string s;cin>>s;
  bool flag=false;
  if(s=="hi")flag=true;
  if(s=="hihi")flag=true;
  if(s=="hihihi")flag=true;
  if(s=="hihihihi")flag=true;
  if(s=="hihihihihi")flag=true;
  
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
typedef struct Data{
    long long b,c;
}data;
int cmp(const void *a,const void *b){
  long long *A = (long long *)a;
  long long *B = (long long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}
int cmpb(const void *a,const void *b){
  long long A = ((data *)b)->c;
  long long B = ((data *)a)->c;
  if (A > B) return 1;
  if (A < B) return -1;
  return 0;
}
int main(){
    long long n,m,i,j;
    scanf("%lld%lld",&n,&m);
    long long a[n],sum=0;
    data num[m];
    rep(i,0,n) scanf("%lld ",&a[i]);
    qsort(a,n,sizeof(long long),cmp);
    rep(i,0,m) scanf("%lld %lld",&num[i].b,&num[i].c);
    qsort(num,m,sizeof(data),cmpb);
    i=0;
    rep(j,0,m){
        while(num[j].b>0){
            if(a[i]<num[j].c){
                sum+=num[j].c;
                num[j].b--;
                i++;
            }
            else break;
        }
    }
    rep(i,i,n)sum+=a[i];
    printf("%lld",sum);
}

Measured memory_bytes: 4084
#include <cstdio>
#include <algorithm>
#include <bitset>
#define MAXN 50005
#define MAXBS 70005
using namespace std;
bitset<MAXBS> bs;
int a[MAXN];
int main(void){
    int n,k;
    int ll,rr;
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++){
        scanf("%d",a+i);
    }
    sort(a+1,a+n+1);
    //Min Necessary:[ll,rr]
    ll=0,rr=n+1;
    while (rr>ll){
        int mid=(ll+rr)>>1;
        int necessary=0;
        if (a[mid]>=k){
            rr=mid;
            continue;
        }
        bs.reset(); // bs=0
        bs[0]=1; // bs[0]=1;
        for (int i=1;i<=n;i++)
            if (i!=mid)
                bs|=(bs<<a[i]);
        for (int i=k-1;i>=k-a[mid];i--){
            if (bs[i]){
                necessary=1;
                break;
            }
        }
        if (necessary)
            rr=mid;
        else
            ll=mid+1;
    }
    printf("%d",ll-1);
    return 0;
}

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

const int MAX_N = 2e5 + 10;
string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	cout << 700 + (s[0] == 'o') * 100 + (s[1] == 'o') * 100 +(s[2] == 'o') * 100 << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

vec idy={1,0,-1,0};
vec idx={0,1,0,-1};

const ll N=5000;
mat c(N,vec(N));
mat al(N,vec(N,1));
ll n;

void dfs(ll y, ll x, ll v) {
  for(ll i=0;i<4;i++) {
    ll ny=y+idy[i];
    ll nx=x+idx[i];
    c[y][x]=v;
    if(ny>-1&&nx>-1&&ny<n&&nx<n&&v+al[y][x]<c[ny][nx]) {
      dfs(ny,nx,v+al[y][x]);
    }
  }
}

int main() {
  cin >> n;
  vec p(n*n);
  for(ll i=0;i<n*n;i++) {
    ll y=i/n;
    ll x=i%n;
    c[y][x]=min({y,x,n-1-y,n-1-x});
  }
  for(ll i=0;i<n*n;i++) {
    cin >> p[i];
    p[i]--;
  }
  ll ans=0;
  for(ll i=0;i<n*n;i++) {
    ll y=p[i]/n;
    ll x=p[i]%n;
    ans+=c[y][x];
    al[y][x]=0;
    dfs(y,x,c[y][x]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 411488
#include<stdio.h>

char s1[100000] = {'\0'};
char s2[100000] = {'\0'};

int main()
{
    int i;
    int j = 1;
    char tmp;

    scanf("%s", s1);

    s2[0] = s1[0];

    for(i = 1; s1[i]; i++){
        if(s1[i] != s2[j - 1]){
            s2[j] = s1[i];
            j++;
        }
    }
  
    printf("%d\n", j - 1);


    return 0;
}

Measured memory_bytes: 384
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

int main() {
    int x;
    int tmp_res;
    int tmp_div;
    int sum_div;
    int sum_res;
    int ans=0;
    cin >> x;
    tmp_res = x%100;
    tmp_div = x/100;
    for(int j=0; tmp_res-j>=0; j++){ // 101
        for(int k=0; tmp_res-j-2*k>=0; k++){ // 102
            for(int l=0; tmp_res-j-2*k-3*l>=0; l++){ // 103
                for(int m=0; tmp_res-j-k-3*l-4*m>=0; m++){ // 104
                    for(int n=0; tmp_res-k-l-4*m-5*n>=0; n++){ // 105
                        sum_div = j+k+l+m+n;
                        sum_res = j+2*k+3*l+4*m+5*n;
                        if(sum_div<=tmp_div && sum_res==tmp_res){
                            ans = 1;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
hist = [0 for i in range(4001)]
for i in range(1001):
    for j in range(1001):
        hist[i + j] += 1

for line in sys.stdin:
    ans = 0
    n = int(line)
    for i in range(min(n, 2000) + 1):
        ans += (hist[i] * hist[n-i])
    print(ans)


Measured memory_bytes: 5640
def main():
    n = int(input())
    x = input()

    c1 = x.count('1')
    c1p, c1m = c1 + 1, c1 - 1
    sp = sum(pow(2, n - i - 1, c1p) for i, c in enumerate(x) if c == '1')
    sm = None
    if c1m > 0:
        sm = sum(pow(2, n - i - 1, c1m) for i, c in enumerate(x) if c == '1')

    A = [0] * n
    for i in range(n):
        nx = None
        if x[i] == '0':
            nx = (sp + pow(2, n - i - 1, c1p)) % c1p
        else:
            if sm is None:
                continue

            nx = (sm - pow(2, n - i - 1, c1m)) % c1m

        A[i] += 1

        while nx > 0:
            nx %= format(nx, 'b').count('1')
            A[i] += 1

    for a in A:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79756
#include <cstdio>
int P[100000],T[100000];
int main() {
    int N,R,L,PT=0,n1=0;
    scanf("%d %d %d",&N,&R,&L);
    for(int i=0;i<R;i++) {
        int d,t,x;
        scanf("%d %d %d",&d,&t,&x); d--;
        P[d]+=x;
        if(x>0) {
            if(P[d]>P[n1]||(P[d]==P[n1]&&n1>d)) {
                T[n1]+=t-PT+1;
                PT=t;
                n1=d;
            }
        }
        if(x<0) {
            if(d!=n1) continue;
            int n2=n1,p2=P[d];
            for(int j=N-1;j>=0;j--) {
                if(p2<=P[j]) {n2=j,p2=P[j];}
            }
            if(n2!=n1) {
                T[n1]+=t-PT+1;
                PT=t;
                n1=n2;
            }
        }
    }
    T[n1]+=L-PT+1;
    int ans_n=0,ans_t=0;
    for(int i=0;i<N;i++) {
        if(ans_t<T[i]) {
            ans_t=T[i];
            ans_n=i;
        }
    }
    printf("%d\n",ans_n+1);
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  char prev = '$';
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    char s; cin >> s;
    if (s == prev) continue;
    cnt++;
    prev = s;
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, K;
ll h[100001], dp[100001];

void init()
{
}

void solve()
{
    dp[1] = 0;
    FOR(i, 2, N+1){
        dp[i] = LINF;
        FOR(j, 1, K+1){
            if(i-j <= 0) break;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[N] << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    FOR(i, 1, N+1) cin >> h[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    map<int,int> mp,mp2;
    for(int i=2;i<=n;i++){
        int x=i;
        for(int j=2;j<=sqrt(x);j++){
            while(x%j==0){
                mp[j]++;
                x/=j;
            }
        }
        if(x>1)mp[x]++;
    }
    for(auto p:mp){
        ll x=p.second;
        rep(i,x+1)mp2[i]++;
    }
    ll res=0;
    res+=mp2[74];
    res+=(mp2[4]*(mp2[4]-1)*(mp2[2]-2))/2;
    //cout<<res<<endl;
    res+=(mp2[2]-1)*mp2[24];
    res+=mp2[14]*(mp2[4]-1);
    cout<<res<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long

unordered_map<ll,std::vector<ll>> graph;

unordered_map<ll,ll> vis,dp;


ll solve(ll start)
{
    if(vis[start]==1){
        return dp[start];
    }
    
    for(ll i=0;i<graph[start].size();i++)
    {
        dp[start] = max(dp[start], solve(graph[start][i]) + 1);    
    }
    vis[start]=1;
    return dp[start];
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll v,e;
    cin>>v>>e;
    ll ans = -1;
    
    for(ll i=0;i<e;i++)
    {
        ll a,b;cin>>a>>b;
        graph[a].push_back(b);
    }
    
    // cout<<solve(3)<<endl;
    
    for(ll i=1;i<=v;i++)
    {
        ans = max(ans,solve(i));
    }
    cout<<ans<<endl;
    
    
	return 0;
}

Measured memory_bytes: 20004
fn main() {
    let _ = read_vec::<i32>();
    let s = read_vec::<i32>();
    let _ = read_vec::<i32>();
    let t = read_vec::<i32>();
    println!("{}", t.iter().filter(|i| s.contains(i)).count());
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
int N;
int a[100003], b[100005], c[100003], dp[100004][3];

int rec(int pos, int prev) {
	if(pos >= N) {
		return 0;
	}
	if(dp[pos][prev] != -1)
		return dp[pos][prev];
	int ans = -1;
	if(prev!=0) {
		ans = max(ans, a[pos] + rec(pos + 1, 0));
	}
	if(prev!=1) {
		ans = max(ans, b[pos] + rec(pos + 1, 1));
	}
	if(prev!=2) {
		ans = max(ans, c[pos] + rec(pos + 1, 2));
	}
	dp[pos][prev] = ans;
	return ans;
}

int main() {
	scanf("%d",&N);
	for(int i=0;i<N;++i){
		scanf("%d %d %d",&a[i], &b[i], &c[i]);
	}
	memset(dp, -1, sizeof(dp));
	int ans = max(b[0] + rec(1, 1), c[0] + rec(1, 2));
	printf("%d", max(a[0] + rec(1, 0), ans));
	return 0;
}

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


int main()
{
	int a,b,c,d=0;
	
	cin>>a>>b>>c;
	a = a-b;
	if(c-a <=0)
		cout<<"0"<<endl;
	else
		cout<<c-a<<endl;

	return 0;
}




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

ll x[1001],y[1001];
int n;
int main(){
    cin>>n;
    rep(i,n) cin>>x[i]>>y[i];
    int c;
    c=abs(x[0]+y[0])%2;
    FOR(i,1,n){
        if(abs(x[i]+y[i])%2!=c){
            c=-1;
            break;
        }
    }
    if(c==-1){
        cout<<-1<<endl;
        return 0;
    }
    if(c==1){
        cout<<31<<endl;
        rep(i,31) cout<<(1<<(30-i))<<" ";
        cout<<endl;
    }
    else{
        cout<<32<<endl;
        cout<<1<<" ";
        rep(i,31) cout<<(1<<(30-i))<<" ";
        //cout<<1<<endl;
    }
    rep(i,n){
        ll tu=x[i]+y[i],tv=x[i]-y[i];
        string ans;
        if(c==0) ans+="R",--tu,--tv;
        for(int i=30;i>=0;--i){
            ll tmp=1<<i;
            if(tu>=0&&tv>=0){
                ans+="R";
                tu-=tmp,tv-=tmp;
            }
            else if(tu<0&&tv<0){
                ans+="L";
                tu+=tmp,tv+=tmp;
            }
            else if(tu>=0&&tv<0){
                ans+="U";
                tu-=tmp,tv+=tmp;
            }
            else if(tu<0&&tv>=0){
                ans+="D";
                tu+=tmp,tv-=tmp;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

int neighs[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
map<pair<int,int>,int> d;

const int MAX = 1000;

char t[MAX][MAX];
int h,w;
int cnt = 0;

inline bool is_valid(int x, int y) {
    return (x>=0&&x<h&&y>=0&&y<w);
}

void print() {
    cout << '\n';
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << t[i][j] << ' ';
        }
        cout << '\n';
    }
    cout << '\n';
}
void solve() {
    cin >> h >> w;
    queue<pair<int,int>> q;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> t[i][j];
            if (t[i][j] == '.')
                ++cnt;
            else {
                q.push(make_pair(i,j));
                d.insert(make_pair(make_pair(i,j),0));
            }
        }
    }

    while (!q.empty()) {
        pair<int,int> next = q.front();
        q.pop();
        for (auto p : neighs) {
            int x = next.first + p[0];
            int y = next.second + p[1];
            if (is_valid(x,y) && t[x][y] == '.') {
                t[x][y] = '#';
               // print();
                pair<int,int> neigh = make_pair(x,y);
                q.push(neigh);
                d[neigh] = d[next] + 1;
               
            }
        }
    }

    int mx = 0;
    for (auto p : d) {
        mx = max(mx,p.second);
    }

    cout << mx << '\n';

}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
	#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

	#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

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

const int MAXN = 300000 + 10;

struct Point {
    int x, y, z;
    Point() {}
    Point(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
    bool operator < (const Point &rhs) const {
        return x < rhs.x || (x == rhs.x && y < rhs.y) || (x == rhs.x && y == rhs.y && z < rhs.z);
    }
} P[MAXN];

map<int, int> best[MAXN];
int dp[MAXN], ret;

int r(int &a, int &b) {
    static const int C = ~(1u << 31), M = (1 << 16) - 1;
    a = 36969 * (a & M) + (a >> 16);
    b = 18000 * (b & M) + (b >> 16);
    return (C & ((a << 16) + b)) % 1000000;
}

inline bool check(const map<int, int> &mp, int x, int y) {
    auto it = mp.lower_bound(x);
    return it != mp.begin() && (-- it)->second < y;
}

int query(int x, int y) {
    int left = 0, right = ret;
    while (left < right) {
        int mid = (left + right + 1) >> 1;
        if (check(best[mid], x, y)) left = mid;
        else right = mid - 1;
    }
    return left;
}

void update(map<int, int> &mp, int x, int y) {
    auto it = mp.upper_bound(x);
    if (it != mp.begin() && (-- it)->second <= y) return;
    it = mp.lower_bound(x);
    while (it != mp.end() && it->second >= y) mp.erase(it ++);
    mp[x] = y;
}

int main() {
    int N, M, A, B;
    while (scanf("%d%d%d%d", &M, &N, &A, &B) == 4 && (N + M)) {
        for (int i = 0; i < M; ++ i) {
            scanf("%d%d%d", &P[i].x, &P[i].y, &P[i].z);
        }
        N += M;
        for (int i = M; i < N; ++ i) {
            P[i].x = r(A, B);
            P[i].y = r(A, B);
            P[i].z = r(A, B);
        }
        for (int i = 0; i <= N; ++ i) best[i].clear();
        sort(P, P + N);
        ret = 0;
        for (int i = 0, j; i < N;) {
            for (j = i; j < N && P[i].x == P[j].x; ++ j) dp[j] = query(P[j].y, P[j].z) + 1;
            for (; i < j; ++ i) {
                update(best[dp[i]], P[i].y, P[i].z);
                ret = max(ret, dp[i]);
            }
        }
        printf("%d\n", ret);
    }
    return 0;
}

Measured memory_bytes: 24380
S = input()
s_list = [int(s) for s in S]
n = len(s_list)
s_first = s_list[0]
cnt1 = 0
cnt2 = 1
if s_first == 0:
    for i in range(1, n):
        if (i % 2 == 1) & (s_list[i] == 0):
            cnt1 += 1
        if (i % 2 == 0) & (s_list[i] == 1):
            cnt1 += 1
        if (i % 2 == 1) & (s_list[i] == 1):
            cnt2 += 1
        if (i % 2 == 0) & (s_list[i] == 0):
            cnt2 += 1
    print(min(cnt1, cnt2))
else:
    for i in range(1, n):
        if (i % 2 == 1) & (s_list[i] == 1):
            cnt1 += 1
        if (i % 2 == 0) & (s_list[i] == 0):
            cnt1 += 1
        if (i % 2 == 1) & (s_list[i] == 0):
            cnt2 += 1
        if (i % 2 == 0) & (s_list[i] == 1):
            cnt2 += 1
    print(min(cnt1, cnt2))

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

int main() {
   double W, H, x, y, fl=0; cin >> W >> H >> x >> y;
   if (x == W / 2 && y == H / 2) fl = 1;
   cout << W * H / 2 << ' ' << fl << endl;
}

 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 5*1e8;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){ }
  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }
  bool same(int x,int y){return find(x)==find(y);}
  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

inline int MSB(int x){ return x>0?31-__builtin_clz(x):-1; }

struct LCA{
  vector<vi> par,w;
  vi depth;
  int ln;
  
  LCA(void){}
  LCA(const vector<vi> &t, const vi weight, int root){
    int n = t.size(); ln = MSB(n)+1;
    depth.resize(n); par.resize(ln,vi(n));
    w.resize(ln,vi(n)); w[0] = weight;

    stack< pair<int,int> > s;
    s.push(make_pair(root,-1));
    while(s.size()){
      int v = s.top().first, p = s.top().second; s.pop();
      par[0][v] = p;
      depth[v] = ((p<0)?0:(depth[p]+1));

      for(int u : t[v]){
	if(u != p)s.push(make_pair(u,v));
      }
    }

    rep(k,ln-1)rep(v,n){
      if(par[k][v]<0){
	par[k+1][v] = -1;
	w[k+1][v] = INF;
      }else{
	par[k+1][v] = par[k][par[k][v]];
	w[k+1][v] = min(w[k][v], w[k][par[k][v]]);
      }
    }
  }

  inline int min_lca(int u, int v){
    int res = INF;
    if(depth[u] > depth[v])swap(u,v);
    rep(k,ln){
      if((depth[v]-depth[u])>>k & 1){
	res = min(res, w[k][v]);
	v = par[k][v];
      }
    }

    if(u==v)return min(res, w[0][u]);
    for(int k = ln-1;k>=0;k--){
      if(par[k][u] != par[k][v]){
	res = min(res, min(w[k][u], w[k][v]));
	u = par[k][u];
	v = par[k][v];
      }
    }
    return min(res, min(w[1][u], w[1][v]));
  }
  inline int dep(int v){ return depth[v]; }
};

int main(){
  int n,m,k,Q;
  scanf("%d%d%d%d",&n,&m,&k,&Q);
  vector< vector<pii> > g(n);
  rep(i,m){
    int a,b,l;
    scanf("%d%d%d",&a,&b,&l); a--; b--;
    g[a].push_back(pii(b,l));
    g[b].push_back(pii(a,l));
  }

  vi dis(n,INF);
  priority_queue<pii> q;
  rep(i,k){
    int f;
    scanf("%d",&f); f--;
    dis[f] = 0;
    q.push(pii(0,f));
  }

  while(q.size()){
    pii p = q.top(); q.pop();
    int d = -p.first, v = p.second;
    if(dis[v] < d)continue;
   
    for(pii nxt : g[v]){
      int u = nxt.first, cost = d+nxt.second;
      if(dis[u] > cost){
	dis[u] = cost;
	q.push(pii(-cost,u));
      }
    }
  }

  vector<pii> order(n);
  rep(i,n)order[i] = pii(dis[i],i);

  sort(all(order)); reverse(all(order));
  UnionFind uf(n);

  vector<vi> tree(n);
  rep(i,n){
    int v = order[i].second;
    vector<pii> nxt;
    for(pii p : g[v]){
      int u = p.first;
      nxt.push_back(pii(dis[u],u));
    }
    sort(all(nxt)); reverse(all(nxt));
    for(pii p : nxt){
      int u = p.second;
      if(dis[u] < dis[v])break;
      if(!uf.same(v,u)){
	tree[u].push_back(v);
	tree[v].push_back(u);
	uf.unite(v,u);
      }
    }
  }
 
  LCA query(tree, dis, 0);
  rep(i,Q){
    int u,v;
    scanf("%d%d",&u,&v); u--; v--;
    printf("%d\n",query.min_lca(u,v));
  }
}

Measured memory_bytes: 31464
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from collections import defaultdict

def resolve():
    it = map(int, sys.stdin.read().split())
    V, E, r = next(it), next(it), next(it)

    inf = float("inf")

    dp = [inf] * V
    dp[r] = 0

    dx = defaultdict(list)
    for si, ti, di in zip(it, it, it):
        dx[si].append((ti, di))

    sx, tx = {r,}, set()
    while sx:
        for si in sx:
            for ti, di in dx[si]:
                d1 = dp[ti]
                d2 = dp[si] + di
                if d1 > d2:
                    dp[ti] = d2
                    tx.add(ti)
        sx, tx = tx, set()

    ans = []
    print(*["INF" if x == inf else x for x in dp], sep="\n")



if __name__ == "__main__":
    resolve()



Measured memory_bytes: 186120
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

//ABC169D

/*
 //ABC169C
 int main(void) {
 long long n, k, t;
 double b;
 scanf("%lld %lf", &n, &b);
 b=b*100;
 t=b;
 k=n*t;
 printf("%lld", k/100);
 return 0;
 }
 */

//ABC169B
int main(void) {
  long long n, k, i, cou, tmp=1;
  scanf("%lld", &n);
  long long a[n], num=1;

  for(i=0; i<n; i++){
    scanf(" %lld", &a[i]);
    if(a[i]==0){
      printf("0");
      return 0;
    }
  }
  for(i=0; i<n; i++){

    if(1e18/num<a[i]){
      printf("-1");
      return 0;
    }

    num*=a[i];

    if(num>1000000000000000000){
      printf("-1");
      return 0;
    }
  }
  printf("%lld", num);
  return 0;
}

Measured memory_bytes: 2460
//え？
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
inline int getintA() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}
char dn[1300000], *di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
int N;
int A[200001];
int E[400001], ne[400001], he[200001], it[200001];
int V[200001], v;
int S[200001], s;

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

	N = getint();
	rep1(i, N) A[i] = getintA();
	int k = 1;
	rep(i, N - 1) {
		int u = getint(), v = getint();
		E[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		E[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	V[v++] = 2000000000;
	S[s++] = 1;
	while (s) {
		int p = S[s - 1];
		if (p > 0) {
			S[s - 1] = -p;
			if (V[v - 1] < A[p]) {
				it[p] = v;
				swap(V[v++], A[p]);
				for (auto to = he[p]; to; to = ne[to]) {
					if (he[E[to]] > 0) {
						S[s++] = E[to];
					}
				}
			}
			else {
				it[p] = lower_bound(V, V + v, A[p]) - V;
				swap(V[it[p]], A[p]);
				for (auto to = he[p]; to; to = ne[to]) {
					if (he[E[to]] > 0) {
						S[s++] = E[to];
					}
				}
			}
			he[p] = -v;
		}
		else {
			s--;
			p = -p;
			V[it[p]] = A[p];
			v -= !A[p];
		}
	}

	rep1(i, N) putint(-he[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 10124
N=int(input())
str_list = input().split(' ')
H = [int(x) for x in str_list]
max_count = 0
count=0
for ii in range(len(H)-1):
    if H[ii] >= H[ii+1]:
        count += 1
    else:
        count = 0
    if max_count < count:
        max_count = count
    #if max_count + ii > len(H):
    #    break
print(max_count)

Measured memory_bytes: 14224
# coding: utf-8
# Your code here!

n, a, b, k = map(int, input().split())
MOD = 998244353

inv = [0] * ( n + 1)
inv[1] = 1
for i in range(2, n + 1):
    inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD

nCr = [0] * ( n + 1)
nCr[0] = 1
for i in range(1, n+1):
    nCr[i] = (nCr[i-1] * (n - i + 1) * inv[i]) % MOD

result = 0
maxA = min(n, k//a)
for i in range(maxA + 1):
    if ( k - a * i) % b == 0:
        j = ( k - a * i) // b
        if j <= n:
            result += (nCr[i] * nCr[j]) % MOD
if result == 0:
    print(1)
else:
    print(result % MOD)

Measured memory_bytes: 26720
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	string n;
	cin >> n;
	string ans = "No";
	rep(i, 3) if (n[i] == '7') ans = "Yes";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i, j, s, t; cin >> N; int x[N], y[N]; double M=0, ans;
for(i=0; i<N; i++){cin >> x[i] >> y[i];} 
for(i=0; i<N; i++){ for(j=i; j<N; j++){ 
  s=x[i]-x[j], t=y[i]-y[j];
  M+=sqrt(s*s+t*t);
}}
ans=2*M/N;
cout << setprecision(15) << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i,j,bit;
    long long ans=0,tmp;
    for(i=0;i<pow(2,s.length()-1);i++){
        bit=i;
        tmp=0;
        for(j=0;j<s.length();j++){
            tmp+=s[j]-'0';
            if(bit&1==1){ans+=tmp; tmp=0;}
            else if((s.length()-1)!=j)tmp*=10;
            bit=bit>>1;
        }
        ans+=tmp;

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

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

int main(void)
{
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d[i];

	vector<int> bucket(101);

	for (int i = 0; i < 101; i++)
	{
		bucket[i] =0 ;
	}

	for (int i = 0; i < n; i++)
	{
		bucket[d[i]]++;
	}

	int cnt = 0;
	for (int i = 0; i < 101; i++)
	{
		if(bucket[i] > 0) cnt++;
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
X,K,D = map(int,input().split())

seki = K * D
amari = X % D

if 0 <= (X-seki) or (X+seki) <= 0 : # 原点を含まない
    result = min(abs(X-seki),abs(X+seki))
else : # 原点を含む
    if X >= 0 :
        if K%2 == 0 :
            if ((abs(X)-amari)/D) % 2 == 0 :
                #print("a")
                result = amari
            else :
                #print("b")
                result = abs(amari-D)
        else :
            if ((abs(X)-amari)/D) % 2 == 1 :
                #print("c")
                result = amari
            else :
                #print("d")
                result = abs(amari-D)
    else :
        amari = abs(X)%D
        if K%2 == 0 :
            if ((abs(X)-amari)/D) % 2 == 0 :
                #print("e")
                result = amari
            else :
                #print("f")
                result = abs(-amari+D)
        else :
            if ((abs(X)-amari)/D) % 2 == 1 :
                #print("g")
                result = amari
            else :
                #print("h")
                result = abs(-amari+D)
    
print(result)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 

using namespace std;
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,i;
    cin>>n;
    vi a;
    vi b;
    for(i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        a.pb(x+y);
        b.pb(x-y);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    n=a.size();
    int ans=abs(a[n-1]-a[0]);
    n=b.size();
    ans=max(ans,abs(b[n-1]-b[0]));
    cout<<ans;
}

Measured memory_bytes: 6684
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (x, y, z) = {
        let nums = get_line()
            .split_whitespace()
            .map(|n| n.parse().unwrap())
            .collect::<Vec<i64>>();
        (nums[0], nums[1], nums[2])
    };
    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(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(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

char d[50][50];
const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dp[50][50];

int main(){

	int r, c;
	cin >> r >> c;

	int sy, sx, gy, gx;
	
	rep(y, r)rep(x, c){
		cin >> d[y][x];
		if (d[y][x] == 'S'){
			sy = y, sx = x;
		}
		if (d[y][x] == 'G'){
			gy = y, gx = x;
		}
	}

	queue<P> q;
	q.push(P(sy, sx));
	rep(i, 50)rep(j, 50)dp[i][j] = INF;
	dp[sy][sx] = 0;

	while (q.size()){
		int y = q.front().first, x = q.front().second;
		q.pop();

		rep(i, 4){
			int ty = y + dy[i], tx = x + dx[i];
			if (cheak(tx, ty, c, r) && d[ty][tx] != 'x' && d[ty][tx] != '#'){
				if ((d[ty][tx] == '.' || d[ty][tx] == 'G')&& dp[ty][tx] > dp[y][x] + 2){
					dp[ty][tx] = dp[y][x] + 2;
					q.push(P(ty, tx));
				}
				if (d[ty][tx] == 'o' && dp[ty][tx] > dp[y][x] + 1){
					dp[ty][tx] = dp[y][x] + 1;
					q.push(P(ty, tx));
				}
			}
		}

		rep(i, 4){

			int lim = 4;

			For(j,1, 4){
				int ty = y + dy[i] * j, tx = x + dx[i] * j;
				if (!cheak(tx, ty, c, r) || d[ty][tx] == '#'){
					lim = j; break;
				}
			}

			For(j, 1, lim){
				int ty = y + dy[i] * j, tx = x + dx[i] * j;
				if (dp[ty][tx] > dp[y][x] + 2 + j){
					dp[ty][tx] = dp[y][x] + 2 + j;
					q.push(P(ty, tx));
				}
			}
		}
	}

	cout << dp[gy][gx] << endl;

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <math.h>
using namespace std;
//---------------------------------------
bool check_sosu(int x);
//---------------------------------------

int main(void)
{
	int num;
	int num_sosu = 0;
	
	cin >> num;
	
	for(int i = 0; i < num; i++){
	 int a;
	 cin >> a;
	 if(check_sosu(a)){  //check_sosu(a)????´???°??????true
	 	num_sosu++;
	 }
	}
	
	cout << num_sosu << endl;
	 
	return 0;
}
//--------------------------------------------
bool check_sosu(int x)
{
	int amari_zero_num = 0;
	
	for(int i = 1; i <= sqrt(x); i++){
		int amari = x % i;
		if(!amari){
			amari_zero_num++;
		}
	}
	if(amari_zero_num == 1){
		return true;
	}
	return false;

}

Measured memory_bytes: 3048
N = int(input())
A = [int(input()) for i in range(N)]

tmp = A.copy();
tmp.sort()
max1_A = tmp[-1];
max2_A = tmp[-2];
max_count = A.count(max1_A);

# 最大値が複数ある場合
if max_count > 1:
  for i in range(N):
    print(max1_A)
# 最大値が1つある場合
else:
  for i in range(N):
    if A[i] < max1_A:
      print(max1_A)
    else:
      print(max2_A)
      break
  for j in range(i+1,N):
    print(max1_A)

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    vector<int> b(0),c(0);
    int o;
    rep(i,n){
        cin >> o;
        if (a.at(i)==0) b.push_back(o);
        else c.push_back(o);
    }
    if (b.size()==0 || c.size()==0) {cout << 0 << endl;return 0;} 
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    cout << b.at(0)+c.at(0) << endl;

}



Measured memory_bytes: 3164
import sys
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
u = min(len(s), len(t))
for i in range(min(len(s), len(t))):
    if s[i] < t[i]:
        print('Yes')
        sys.exit()
    if s[i] > t[i]:
        print('No')
        sys.exit()
if s[0:u] == t[0:u] and len(s) < len(t):
    print('Yes')
elif s[0:u] == t[0:u] and len(s) >= len(t):
    print('No')

Measured memory_bytes: 3064
#include <iostream>

using namespace std; 
int main(){
int a,b;
cin >>a >>b;
if(a==1){
    if(b==2)cout <<"3";
    else cout <<"2"; 
}
if(a==2){
if(b==1) cout <<"3";
else cout <<"1"; 
}
if(a==3){
    if(b==1) cout <<"2";
    else cout <<"1";
}
return 0;
}

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

struct fastio {
	char s[100000];
	int it, len;
	fastio(): it(0), len(0) {}
	char get() {
		if (it >= len)
			len = fread(s, 1, 100000, stdin), it = 0;
		return s[it++];
	}
} _buff;

int n;
long long s[20][20];
char c2[200000], c5[200000];
int getnum();

int main() {
	n = getnum();
	for (int i = 0; i < n; ++i) {
		char c = _buff.get();
		while (!isdigit(c)) c = _buff.get();

		long long t = 0;
		char f = 0;
		while (isdigit(c) || c == '.') {
			if (c == '.') {
				f = 1;
				c = _buff.get();
				continue;
			}
			t = t * 10 + c - '0';
			if (f) --c2[i], --c5[i];
			c = _buff.get();
		}
		while (~t & 1) t >>= 1, ++c2[i];
		while (t % 5 == 0) t /= 5, ++c5[i];
		c2[i] = min(c2[i], (char)9); c5[i] = min(c5[i], (char)9);
		++s[9 - c2[i]][9 - c5[i]];
	}
	for (int i = 1; i <= 18; ++i)
		s[0][i] += s[0][i - 1], s[i][0] += s[i - 1][0];

	for (int i = 1; i <= 18; ++i)
		for (int j = 1; j <= 18; ++j)
			s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
	
	long long ans = 0;
	for (int i = 0; i < n; ++i)
		ans += s[9 + c2[i]][9 + c5[i]] - (c2[i] >= 0 && c5[i] >= 0);
	assert(~ans & 1);
	printf("%lld\n", ans >> 1);
	return 0;
}

int getnum() {
	int ret = 0;
	char c = _buff.get();
	while (!isdigit(c)) c = _buff.get();
	while (isdigit(c)) {
		ret = ret * 10 + c - '0';
		c = _buff.get();
	}
	return ret;
}



Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


vector<char> s;
void f(int v, int w, char c) {
    int x = c-'a'+1;
    rep(i, x+1) {
        s[v-1] = 'a'+i;
        if (v==w) {
            rep(j, w) cout << s[j];
            cout << endl;
        }
        else {
            f(v+1, w, max(s[v-1], c));
        }
    }
}

int main(){
    int n;
    cin >> n;
    s.resize(n);
    
    f(1, n, 'a'-1);
    
    
    
    return 0;
}


Measured memory_bytes: 1536
object Main {
  def main(args: Array[String]): Unit = {
    val count = scala.collection.mutable.Map[Char, Int]()
    val in = io.Source.stdin.getLines.mkString("")
    for(c <- in if c.isLetter) count(c.toLower) = count.getOrElse(c.toLower, 0) + 1
    for(c <- 'a' to 'z') println(s"$c : ${count.getOrElse(c, 0)}")
  }
}



Measured memory_bytes: 45048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int a,b,c,K;
  cin >> a >> b >> c >> K;
  while (b<=a) {
    b*=2; K--;
  }
  while (c<=b) {
    c*=2; K--;
  }
  if (K>=0) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3576