akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int X, Y;
    cin >> X >> Y;
    for(int i=0;i<X+1;++i){
        if (2 * i + 4 * (X - i) == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL M,K; cin >> M >> K;
    if(M == 0){
        if(K == 0) cout <<"0 0" << endl;
        else cout << -1 << endl;
    }
    else if(M ==1){
        if(K == 0) cout <<"0 0 1 1" << endl;
        else cout << -1 << endl;
    }
    else{
        if(LL(pow(2,M))-1 < K) cout << -1 << endl;
        else{
            cout << K << " ";
            for(LL i=0; i < LL(pow(2,M)); i++){
                if(i != K) cout << i << " ";
            }
            cout << K << " ";
            for(int i = LL(pow(2,M))-1; i >= 0; i--){
                if(i != K) cout << i << " ";
            }
        }
        cout << endl;
    }
}

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

class Donald {
public:
	string mark;
	int cardNum;
};
int main()
{
	int n;
	cin >> n;
	vector<Donald> S;
	vector<Donald> H;
	vector<Donald> C;
	vector<Donald> D;

	for (int i = 0; i < n; i++) {
		Donald dnald;
		cin >> dnald.mark 
			>> dnald.cardNum;

		if (dnald.mark == "S") {
			S.push_back(dnald);
		}
		else if (dnald.mark == "H") {
			H.push_back(dnald);
		}
		else if (dnald.mark == "C") {
			C.push_back(dnald);
		}
		else if (dnald.mark == "D") {
			D.push_back(dnald);
		}
		else { exit(1); }
	}
	vector <string> m = {"S","H","C","D"};

	//トランプの数字１つ１つに対して判定する
	for(int i=0; i<m.size();i++){
		for (int j = 1; j < 14; j++) {
			if (m[i] == "S") {
				for (int k = 0; k < S.size(); k++) {
					if (j == S[k].cardNum) {
						break;
					}
					if (k == S.size() - 1) {
						cout << m[i] << " " << j << endl;
					}
				}
			}
			if (m[i] == "H") {
				for (int k = 0; k < H.size(); k++) {
					if (j == H[k].cardNum) {
						break;
					}
					if (k == H.size() - 1) {
						cout << m[i] << " " << j << endl;
					}
				}
			}
			if (m[i] == "C") {
				for (int k = 0; k < C.size(); k++) {
					if (j == C[k].cardNum) {
						break;
					}
					if (k == C.size() - 1) {
						cout << m[i] << " " << j << endl;
					}
				}
			}
			if (m[i] == "D") {
				for (int k = 0; k < D.size(); k++) {
					if (j == D[k].cardNum) {
						break;
					}
					if (k == D.size() - 1) {
						cout << m[i] << " " << j << endl;
					}
				}
			}
		}
	}
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define ll  long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#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*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b,c,ans=0;
    cin>>a>>b>>c;
    ll arr[3];
    arr[0]=a,arr[1]=b,arr[2]=c;
    sort(arr,arr+3);
    if(a%2==0)
    {
         cout<<0<<endl;
    }
    else if(b%2==0)
    {
       cout<<0<<endl;
    }
    else if(c%2==0)
    {
       cout<<0<<endl;
    }
    else {    
        ll temp=1ll*arr[0]*1ll*arr[1];
        cout<<temp<<endl;
    } 
}
return 0;
}

Measured memory_bytes: 256
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = [-x for x in a]
heapq.heapify(a) 
ans =0
for i in range(m):
  b = a[0]
  c = (-1)*b //2
  heapq.heappop(a) 
  heapq.heappush(a, c*(-1)) 
print(sum(a)*(-1))

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

#define REP(i,n) for(i=0;i<n;i++)

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int sx = iin(), sy = iin(), tx = iin(), ty = iin();
    int i;
    REP(i,(ty - sy)) cout('U');
    REP(i,(tx - sx)) cout('R');
    REP(i,(ty - sy)) cout('D');
    REP(i,(tx - sx)) cout('L');
    cout('L');
    REP(i,(ty - sy + 1)) cout('U');
    REP(i,(tx - sx + 1)) cout('R');
    cout('D');
    cout('R');
    REP(i,(ty - sy + 1)) cout('D');
    REP(i,(tx - sx + 1)) cout('L');
    cout('U');
    cout('\n');
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll k;
  cin>>k;
  ll x=100;
  for(ll i=1;i<1000000000000000000;i++){
    x+=x/100;
    if(x>=k){cout<<i<<endl;return 0;}
  }
}

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



int main(){
	int n,l,wa,ans;
	cin>>n>>l;
	for(int i=l;i<n+l;i++){
		wa+=i;
	}
	if(n+l-1<0){
		wa-=n+l-1;
	}
	else if(n+l==0){

	}
	else if(l<0 && n+l>0){

	}
	else if(l==0){

	}
	else {
		wa-=l;
	}

	cout<<wa;
}



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

#define max(a,b) (((a) < (b)) ? (b) : (a))
#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int64_t N,A,B;
    cin >> N >> A >> B;
    
    cout << ((N /(A+B)) * A) + min(A,(N%(A+B))) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#define R register ll

namespace quick {
#define tp template<typename Type>
	namespace in {
		inline char getc() {
			static char buf[1<<21],*p1=buf,*p2=buf;
			return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
		}
		inline int read(char *s) {
			*s=getc();
			while(isspace(*s)) {*s=getc();if(*s==EOF) return 0;}
			while(!isspace(*s)&&*s!=EOF) {s++;*s=getc();}
			*s='\0'; return 1;
		}
		tp inline int read(Type &x) {
			x=0;bool k=false;char c=getc();
			while(!isdigit(c)) {k|=(c=='-');c=getc();if(c==EOF) return 0;}
			while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^48);c=getc();}
			x*=(k?-1:1); return 1;
		}
		template <typename Type,typename... Args>
		inline int read(Type &t,Args &...args) {
			int res=0;
			res+=read(t);res+=read(args...);
			return res;
		}
	}
	using in::read;
	namespace out {
		char buf[1<<21];int p1=-1;const int p2=(1<<21)-1;
		inline void flush() {
			fwrite(buf,1,p1+1,stdout);
			p1=-1;
		}
		inline void putc(const char &c) {
			if(p1==p2) flush();
			buf[++p1]=c;
		}
		inline void write(const char *s) {
			while(*s!='\0') putc(*s),s++;
		}
		tp inline void write(Type x) {
			static char buf[30];int p=-1;
			if(x<0) {putc('-');x=-x;}
			if(x==0) putc('0');
			else for(;x;x/=10) buf[++p]=x%10+48;
			for(;p!=-1;p--) putc(buf[p]);
		}
		inline void write(char c) {putc(c);}
		template <typename Type,typename... Args>
		inline void write(Type t,Args ...args) {
			write(t);write(args...);
		}
	}
	using out::write;
	using out::flush;
	tp inline Type max(const Type a,const Type b) {
		if(a<b) return b;
		return a;
	}
	tp inline Type min(const Type a,const Type b) {
		if(a<b) return a;
		return b;
	}
	tp inline void swap(Type &a,Type &b) {
		a^=b^=a^=b;
	}
	tp inline Type abs(const Type a) {
		return a>=0?a:-a;
	}
#undef tp
}
using namespace quick;

typedef long long ll;
const ll maxn=22,inf=0x3f3f3f3f3f3f3f3f;
ll n,a[maxn];
ll dfs(ll l,ll r,ll x,ll y) {
	if(r-l<=1) return 0;
	ll ans=inf;
	for(R i(l+1);i<r;i++)
		ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));
	return ans;
}

int main(void) {
	read(n);
	for(R i(1);i<=n;i++) read(a[i]);
	write(dfs(1,n,1,1)+a[1]+a[n],'\n');
	flush();
	return 0;
}

Measured memory_bytes: 2304
num = []
i = 0

while true
  ln = gets
  if ln == nil
    break
  end
  num[i] = ln.chomp
  num[i] = num[i].to_i
  i = i + 1
end

for j in 0..(i - 1)
  cnt = 0
  for a in 0..9
    for b in 0..9
      for c in 0..9
        for d in 0..9
          if a + b + c + d == num[j]
            cnt = cnt + 1
            break
          end
        end
      end
    end
  end
  puts cnt
end


Measured memory_bytes: 6864
INF = 10 ** 6

def num(k):#各数字に使用するマッチ棒の本数を返す関数
    if k == 1:
        return 2
    elif k == 7:
        return 3
    elif k == 4:
        return 4
    elif k == 2 or k == 3 or k == 5:
        return 5
    elif k == 6 or k == 9:
        return 6
    elif k == 8:
        return 7

n, m = map(int,input().split())
l = list(map(int,input().split()))
l.sort(reverse = True)
         
dp = [(-1) * INF] * (n+1)

dp[0] = 0

for i in range(2,n+1):
    can = []
    for x in l:
        if i-num(x)>=0:
            can.append(dp[i-num(x)]+1)
    if can == []:
        dp[i] = (-1) * INF
    else:
        dp[i] = max(can)
        
#print(dp)

anslist = [0] * dp[n]

left = n

for j in range(dp[n],0,-1):#jは桁数
    if j == 1:
        for x in l:
            if num(x) == left:
                anslist[j-1] = x
                break
    else:
        for x in l:
            if dp[left-num(x)] == j - 1:
                anslist[j-1] = x#j桁目は10^(j-1)の位
                left = left-num(x)
                break
            
    #print([j,x,left])
#print(anslist)
            
            
ans = 0

for j in range(0,dp[n]):
    ans = ans + anslist[j] * (10 ** j)

print(ans)
         
    

Measured memory_bytes: 3444
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1
#define PI 3.14159265359
#define mod 1000000007

const long long INF = 1000000000;

int main(){
    long long x;
    cin >> x;
    int count = 0;
    long long p = 100;
    while(p < x){
        p += p / 100;
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ship1 = set([])
ship2 = set([])
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        ship1.add(b)
    elif b == N:
        ship2.add(a)

if ship1 & ship2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 18892
n=int(input())
li = list(map(int,input().split()))



s = 0
total = 0
for i in range(n):
  total +=  li[i]
m = 10000
for i in range(n):
  s += li[i]
  a,b = total-s , s
  if abs(a-b) < m :
    m = abs(a-b)
  else :
    break

print(m)  

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

int main(){
  string S,T;
  int count=0,size=0;
  string s,t;
  cin >> S;
  cin >> T;
  
  size = S.size();
  
  
  
  for (int i = 0; i <= size-1;i++){
    s = S[i];
    t = T[i];
    //cout<<i<<s<<t<<endl;
    if(s!=t){
      //cout << i<<"で違う"<<endl;
      
      count++;
       }
 
  }
  
  cout << count << endl;
}

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

int main() {
    int N, M, count;
    cin >> N >> M;
    int A[N];
    
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    double sum_div = accumulate(A, A+N, 0.0)/double(4*M);

    count = 0;
    for (int i=0; i<N; i++) {
        if (A[i]>=sum_div) {
            count++;        
        }
    }

    if (count>=M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = a; i < (int)(b); ++i)

using namespace std;

int32_t main() {
    int n, c;
    cin >> n >> c;
    int w[n + 1], u[n + 1];
    FOR(i, 1, n + 1) {
        cin >> w[i] >> u[i];
    }
    int d[n + 1][c + 1];
    FOR(i, 0, n + 1) {
        d[i][0] = 0;
    }
    FOR(i, 0, c + 1) {
        d[0][i] = 0;
    }
    FOR(i, 1, n + 1) {
        FOR(j, 1, c + 1) {
            d[i][j] = max(d[i - 1][j - w[i]] + u[i], d[i - 1][j]);
            if (j - w[i] < 0) {
                d[i][j] = d[i - 1][j];
            }
        }
    }
    cout << d[n][c];
    return 0;
}

Measured memory_bytes: 82468
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
  int n,l;
  cin >> n >> l;
  string s[101];
  for(int i=0; i<n; i++){
    cin >> s[i];
  }
  sort(s,s+n);
  for(int i=0; i<n; i++){
    cout << s[i];
  }
  cout << "\n" ;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> H(N, true);
  for (int i = 0; i < K; i++) {
    int D;
    cin >> D;
    for (int j = 0; j < D; j++) {
      int A;
      cin >> A;
      A--;
      H.at(A) = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (H.at(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
long long min(long long a,long long b){
	return a<b?a:b;
}
int main(void){
	long long a,b,c,n,m;
	scanf("%lld %lld %lld",&a,&b,&c);
	if((a%2==1)&&(b%2==1)&&(c%2==1)){
		n=min(a*b,min(b*c,c*a));
		printf("%lld\n",n);
	}
	else{
		puts("0");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/rope>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;
using namespace __gnu_cxx;

const double g=10.0,eps=1e-7;
const int N=100+10,maxn=100000+10,inf=0x3f3f3f;

int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s.substr(i,2)=="AC")
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}
/*******************

********************/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    int n, k, r, s, p;
    string t;
    map<char,int>mp;
    cin >> n >> k >> mp['s'] >> mp['p'] >> mp['r'] >> t;
    vector<vector<char>>v(k);
    rep(i, n){
        v[i%k].push_back(t.at(i));
    }
    int ans = 0;
    rep(i, k){
        char pre = v[i][0];
        int count = 1;
        for (int j = 1; j < v[i].size(); j++) {
            if (pre != v[i][j]) {
                ans += mp[pre]*(int)((count + 1)/2);
                count = 0;
            }
            pre = v[i][j];
            count++;
        }
        ans += mp[pre]*(int)((count + 1 + 1e-5)/2);
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8168
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

typedef struct Node{
  int value;
  Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void insert(int k){
  Node *y = NIL, *x = root, *z;

  z = (Node *)malloc(sizeof(Node));
  z->value = k;
  z->left = z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->value < x->value) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->value < y->value) y->left = z;
  else y->right = z;
}

Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}

Node* treeMinimum(Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node* treeSuccessor(Node *x){
  Node *y;

  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void Delete(Node *z){
  Node *x, *y;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->value = y->value;
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key;
  string command;

  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key;
      insert(key);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }else if(command == "find"){
      cin >> key;
      if(find(root, key)) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(command == "delete"){
      cin >> key;
      Delete(find(root, key));
    }
  }

  return 0;
}



Measured memory_bytes: 21756
// modular binary exponation
#include<iostream>

using namespace std;
#define ll long long
ll int mod,tavan,paye;


ll int bsq(ll int x,ll int n,ll int mod)// (x^n)%mod
{
  if(n==0)
    return 1;
  if(n==1)
    return x%mod;
  ll int saven=bsq(x,n/2,mod);
  if(n%2==1)
    return (x*((saven*saven)%mod))%mod;
  return (saven*saven)%mod;
}

ll int mod_inv(ll int n,ll int primeMod)//GCD(n , PrimeMod)=1
{
  return bsq(n,primeMod-2,primeMod);
}
int main()
{
  mod=1e9+7;
  cin>>paye>>tavan;
  cout<<bsq(paye,tavan,mod)<<endl;//bsq test
  //  ll int a,b,primeMod;
  //cin>>a>>b>>primeMod;
  //cout<<(a*mod_inv(b,primeMod))%primeMod<<endl;// a/b % primMod
  
  return 0;
}

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

bool check(vector<int> n) {
    bool check = true;
    for(int i=0;i<n.size();i++) {
        if(n[i] % 2 != 0) {
            check = false;
        }
    }
    return check;
}

int main() {
    int N;
    cin >> N;
    vector<int> nums(N);
    for(int i=0;i<N;i++) {
        cin >> nums[i];
    }
    int count = 0;
    for(;check(nums);){
        for(int i=0;i<N;i++) {
            nums[i] /= 2;
        }
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    double ans=0;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        ans+=1/(double)tmp;
    }
    cout << 1/ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>	
using namespace std;
#define ll long long 
vector<vector<int>> l(100001);
//int used[100001][100001];
int col[100001];
const int MAX = 510000;
const int MOD = 1000000007;

//(ll& l, ll n)
//(vector<long long>& l, ll n)
ll binary_search(vector<long long>& l, ll n){
  ll mx = l.size();
  ll mi = 0;
  ll h = 0;  
  while(mi < mx && l[mi] < n){
    h = (mi + mx)/2;
    //cout << mi << " " << mx << " " << h << " " << l[h] << " " << n <<endl;
    if(l[h] != n){
      if(l[h] > n){
        mx = h;
      }else{
        mi = h+1;
      }
    }else{
      break;
    }
    
  }
  
  //存在するかどうかとインデックス（存在しない場合は小さい方のインデックス）を返す 
  //存在しない場合は返り値の２項目が1
  //cout << h << endl;
  return h;
 
}
int main() {
  int n,m,k;
  cin >> n >> m >> k;
  int a[n],b[m];
  ll al[n+1];
  vector<ll> bl(m+1);
  al[0] = 0;
  bl[0] = 0;
  
  for(int i = 0;i<n;i++){
    cin >> a[i];
    al[i+1] = a[i]+ al[i];
    
  }
  
  for(int i = 0;i<m;i++){
    cin >> b[i];
    bl[i+1] = b[i]+ bl[i];
  }
  //cout << bl.begin();
  int mx = -1;
  //int b = 0;
  int j = 0;
  for(int i = 0;i < n+1;i++){
    if(al[n-i] <= k){
      j = binary_search(bl,k-al[n-i]);
      //cout << k-al[n-i] <<" " << j <<  endl;
      //while(al[n-i] + bl[j]<=k){
      //  if(j == m || al[n-i] + bl[j+1]>k){break;}
      //  j+=1;
      //}
      mx = max(mx,n-i + j);
      
      //cout << n-i << " " << al[n-i] << " " << j << " " << bl[j] << " " << al[n-i] + bl[j]  <<endl;
    }
  }
  //cout << bl[113897] <<endl;
  
  cout << mx;
}

Measured memory_bytes: 10368
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	long long n;
	cin>>n;
	long long res = (n+1)*n/2;
	long long t = n/3;
	long long r = (t*3 + 3) * t / 2;
	res-=r;
	t = n/5;
	r = (t*5 + 5) * t / 2;
	res-=r;
	t = n/15;
	r = (t*15 + 15) * t / 2;
	res+=r;
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int a[510][510];
long long f[510][510];
long long g[510][510];
long long dp[510][510];
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(i==j)continue;
			scanf("%d",&a[i][j]);
		}
	//f
	for(int i=1;i<n;i++)
		for(int j=n-1;j>=i;j--)
			f[i][j]=f[i][j+1]+a[j+1][i];
	for(int i=1;i<n;i++)
		for(int j=1;j<n;j++)
			f[i][j]+=f[i-1][j];
	//g
	for(int i=1;i<n;i++)
		for(int j=i;j<n;j++)
			g[i][j]=g[i][j-1]+a[i][j+1];
	for(int i=n-1;i>=1;i--)
		for(int j=2;j<n;j++)
			g[i][j]+=g[i+1][j];
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<i;j++)
		{
			dp[i][j]=1e18;
			for(int k=0;k<=j;k++)
			{
				if(k&&k==j)continue;
				dp[i][j]=min(dp[i][j],dp[j][k]+g[j+1][i-1]+f[j][i]-f[k][i]);
			}
		}
	long long ans=1e18;
	for(int i=0;i<n;i++)
		ans=min(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll x;
    cin >> x;
    ll answer = 0;
    answer += (x/500)*1000;
    x-=(x/500)*500;
    answer += (x/5)*5;
    cout << answer << endl;
    return 0;
}

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

using namespace std;

void rotate(int xs[], int s, int t)
{
    int v = xs[t];
    for(int i = t; i > s; i--)
    {
        xs[i] = xs[i-1];
    }
    xs[s] = v;
    return;
}

void insert(int xs[], int idx)
{
    for(int i = 0; i < idx; i++)
    {
        if(xs[i] > xs[idx])
        {
            rotate(xs, i, idx);

        }
    }
}

void printArr(int xs[], int arr_len)
{
    for(int j = 0; j < arr_len-1; j++)
    {
        cout << xs[j] << ' ';
    }
    cout << xs[arr_len-1] << '\n';
}

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    for(int i = 0; i < n; i++)
    {
        insert(arr, i);
        printArr(arr, n);
    }
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void) {
	int N,i;
  double a;
  cin>>N;
  vector<double> v(N);
  for(i=0;i<N;i++){
    cin>>a;
    v[i]=a;
  }
  sort(v.begin(), v.end());
   for(i=1;i<N;i++){
    v[i]=(v[i]+v[i-1])/2;
  } 
  cout<<v[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	H := intSliceScanner(n)
	ans := -1
	tmp := 0
	for i := 1; i < n; i++ {
		if H[i] <= H[i-1] {
			tmp++
		} else {
			ans = larger(ans, tmp)
			tmp = 0
		}
	}
	ans = larger(ans, tmp)
	fmt.Println(ans)
}


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

int main(){
  int N,cnt=0;
  string s;
  cin>>N>>s;
  cnt=count(s.cbegin(), s.cend(), 'R');
  if(N-cnt<cnt){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
s = int(input())
def f(n):
  if n%2 == 0:
    return n//2
  else:
    return 3*n+1
a = [s]
i=1
while(1):
  i+=1
  x=f(a[-1])
  if (x in a):
    print(i)
    exit()
  a.append(x)

Measured memory_bytes: 3060
n = input()
in_list = list(map(int, input().split()))

odd_included = False
counter = 0

for i in range(len(in_list)):
    if in_list[i] % 2 != 0:
        odd_included = True

    while odd_included == False:
        for i in range(len(in_list)):
            if in_list[i] % 2 != 0:
                odd_included = True
                break
            if odd_included == False:
                in_list[i] = in_list[i] / 2
        if odd_included == False:
            counter += 1

print(counter)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(){
	char s[100000];
	scanf("%s",s);
	int l=strlen(s);
	int g=0,p=0,res=0;
	for(int i=0;i<l;i++){
		if(s[i]=='g'){
			if(p<g){
				res++;
				p++;
			}
			else{
				g++;
			}
		}
		else if(s[i]=='p'){
			if(p<g){
				p++;
			}
			else{
				g++;
				res--;
			}
		}
	}
	printf("%d",res);
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

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

    int N, M; cin >> N >> M;
    vi A(N); REP(i, N) cin >> A[i];
    vi B(M), C(M); REP(i, M) cin >> B[i] >> C[i];

    priority_queue<pii> pq;
    REP(i, N) {
        pq.push(pii(A[i], 1));
    }

    REP(i, M){
        pq.push(pii(C[i], B[i]));        
    }

    ll ans = 0;
    int num = 0;
    while(num < N) {
        pii hi = pq.top(); pq.pop();
        int d = hi.second;
        if (num + d > N) {
            d = N - num;
        }
        ans += ((ll)hi.first) * d;
        num += d;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll com = A[0];
    queue<ll> q;
    int cnt = 1;
    for (int i = 1; i < N; i++)
    {
        ans += com;
        q.push(A[i]);
        cnt++;
        if(cnt==2){
            cnt = 0;
            com = q.front();
            q.pop();
        }
    }
    cout << ans << endl;
}

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

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

long long H, W, C;

int main() {
	cin >> H >> W >> C;
	long long R = gcd(H, W);
	cout << H * W / R / R * C << endl;
	return 0;
}


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

int main(){  
	string w;
	cin >> w;
	vector<char> alphabets;
	vector<int> alphabets_num;
	bool beautiful = true;
	for(int i = 0; i < w.size(); i++){
		bool ok = true;
		for(int j = 0; j < alphabets.size(); j++){
			if(w[i] == alphabets[j]){
				ok = false;
				alphabets_num[j]++;
				break;
			}
		}
		if(ok){
			alphabets.push_back(w[i]);
			alphabets_num.push_back(1);
		}
	}
	for(int i = 0; i < alphabets.size(); i++){
		if(alphabets_num[i] % 2 == 1){
			beautiful = false;
			break;
		}
	}
	if(beautiful){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
s = str(input())
border = a + b
cou = 0
ans = 0
for i in range(n):
    if s[i] == "c":
        print("No")
    elif s[i] == "b":
        if cou < a + b:
            if ans + 1 <= b:
                ans += 1
                cou += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        if cou < a + b:
            cou += 1
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli b = 0, h, k, n, w, ans = 0, count = 0, tmp = 1;
  string s, t;
  cin >> n;
  repe(i, 1, n)
  {
    b = i;
    while (b % 2 == 0)
    {
      b /= 2;
      count++;
    }
    if (count > ans)
    {
      ans = count;
      tmp = i;
    }
    count = 0;
  }
  cout << tmp << endl;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    input! {
        a:i32
    }
    println!("{}", a + a * a + a * a * a);
}


Measured memory_bytes: 2136
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef long long LL;

double calc( int n, double value, int k, double p ) {
    return value * (int)( n - n % k ) * p + ( n % k ) * value;
}

LL solve( int n ) {
    LL res = INT_MAX;
    int W[3] = { 200, 300, 500 };
    int V[3] = { 380, 550, 850 };
    int K[3] = { 5, 4, 3 };
    double P[3] = { 0.8, 0.85, 0.88 };
    for ( int a = 0; a < 100; ++ a ) {
        for ( int b = 0; b < 100; ++ b ) {
            for ( int c = 0; c < 100; ++ c ) {
                int sumW = W[0] * a + W[1] * b + W[2] * c;
                if ( sumW != n ) continue;
                res = min( res,
                           (LL)(calc( a, V[0], K[0], P[0] )
                           + calc( b, V[1], K[1], P[1] )
                            + calc( c, V[2], K[2], P[2] )));
            }
        }
    }
    return res;
}

int main() {
    int n;
    while ( cin >> n && n ) {
        cout << solve( n ) << endl;
    }
    return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, m, a[N], b[N], fa[N], cnt;
int get(int x){return fa[x] == x? x : fa[x] = get(fa[x]);}
int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) fa[i] = i;
    for(int i = 1; i <= m; i++)
    {
    	cin >> a[i] >> b[i];
    	int ga = get(a[i]), gb = get(b[i]);
    	fa[gb] = ga;
	}
	for(int i = 1; i <= n; i++) if(get(i) == i) cnt++;
	cout << cnt - 1 << endl;
	return 0;
}


Measured memory_bytes: 4784
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		//int n = Integer.parseInt(sc.next());
		String[] s = sc.next().split("");
		
		int ans = 0;
		for(int i = 0 ; i < s.length ; i++) {
			ans += Integer.parseInt(s[i]);
		}
		
		if(ans % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
	}

}




Measured memory_bytes: 55636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  ll a=tx-sx,b=ty-sy;
  string ans="";
  rep(i,b){
      ans.pb('U');
  }
  rep(i,a){
      ans.pb('R');
  }
  rep(i,b){
      ans.pb('D');
  }
  rep(i,a){
      ans.pb('L');
  }
  ans.pb('L');
  rep(i,b+1){
      ans.pb('U');
  }
  rep(i,a+1){
      ans.pb('R');
  }
  ans.pb('D');
  ans.pb('R');
  rep(i,b+1){
      ans.pb('D');
  }
  rep(i,a+1){
      ans.pb('L');
  }
  ans.pb('U');
  print(ans);
}



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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef vector<int> vi;
typedef vector<long long int> vl;
#define pb push_back
#define mp make_pair

ll expm(ll x, ll y, ll mod){
	ll ans = 1;
	while(y>0){
		if(y%2==1) ans*=x, ans%=mod, y--;
		else x*=x, x%=mod, y/=2;
	}
	return ans%mod;
}

ll exp(ll x, ll y){
	return expm(x,y,LLONG_MAX);
}

void shift(vector<int>& dp1, vector<int>& dp2){
	for(int i = 0; i < dp2.size(); i++) {
		dp2[i] = dp1[i];
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);

	int n;
	cin >> n;	
	vector<vector<int> > points(n, vector<int>(3, 0));

	for(int i = 0; i < n; i++) 
		cin >> points[i][0] >> points[i][1] >> points[i][2];

	vector<int> dp1(3, 0), dp2(3, 0);

	// dp1[a] = max(dp2[(a + 1) % 3], dp2[(a + 2) % 3]) + points_for_a
	for(int i = n - 1; i >= 0; i--) {
		for(int j = 0; j < 3; j++) {
			int best_remaining_score =  max(dp2[(j + 1) % 3], dp2[(j + 2) % 3]);
			dp1[j] = best_remaining_score + points[i][j];
		}

		shift(dp1, dp2); //copy dp1 to dp2
	}

	int ma = 0;
	for(int i = 0; i < 3; i++) 
		ma = max(ma, dp2[i]);

	cout << ma << endl;
	return 0;
}



Measured memory_bytes: 8744
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for i in range(n):
    x=input()
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
print("AC x",dic["AC"])
print("WA x",dic["WA"])
print("TLE x",dic["TLE"])
print("RE x",dic["RE"])


Measured memory_bytes: 9420
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const int inf = (1 << 30);
const int MOD = 1000000007;
int dx[4] = { 0,-1,0,1 }, dy[4] = { 1,0,-1,0 };
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
ll d[300][300],d2[300][300]; int v, n, c, e, u;
const  ll INF = (1LL << 32);
void warshall_floyd(int n) {
    rep(k, n) { 
        rep(i, n) {
            if (d[i][k] == INF) continue;
            rep(j, n) {
                if (d[k][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
void wf(int n) {
    rep(k, n) {
        rep(i, n) {
            if (d2[i][k] == INF) continue;
            rep(j, n) {
                if (d2[k][j] == INF) continue;
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }
}
int main() {
    int n, m, l,a,b,c,q,s,t; cin >> n >> m >> l;
    Fill(d, INF); Fill(d2, INF);
    rep(i, m) {
        cin >> a >> b >> c;
        if (c <= l) {
            d[a - 1][b - 1] = c;
            d[b - 1][a - 1] = c;
        }
    }
    warshall_floyd(n);
    rep(i, n) {
        rep(j, n) {
            if (d[i][j] <= l) {
                d2[i][j] = 1;
            }
        }
    }wf(n);
    cin >> q;
    rep(i, q) {
        cin >> s >> t;
        if (d2[s - 1][t - 1] == INF) cout << -1 << endl;
        else {
            cout << d2[s - 1][t - 1] - 1 << endl;
        }
    }
}

Measured memory_bytes: 1920
from sys import stdin
import sys
import math

[A, B, C, D, E, F] = list(map(int, stdin.readline().rstrip().split()))

## F
# F >= 100 * A * a + 100 * B * b + C * c + D * d

## E
# C * c + D * d <= (100 * A * a + 100 * B * b) * E / 100
# 100 * (C * c + D * d) <= (100 * A * a + 100 * B * b) * E
# 100 * (C * c + D * d) / (100 * A * a + 100 * B * b) <= E


maximum_ratio = 0
max_a = 0
max_b = 0
max_c = 0
max_d = 0

for a in range(F // (100 * A) + 1):
    for b in range(F // (100 * B) + 1):
        for c in range(F // 2 // C + 1):
            for d in range(F // 2 // D + 1):
                if 100 * A * a + 100 * B * b + C * c + D * d <= F:
                    if 0 == (100 * A * a + 100 * B * b):
                        continue

                    sugar_ratio = 100 * (C * c + D * d) / (100 * A * a + 100 * B * b)
                    if E >= sugar_ratio and maximum_ratio <= sugar_ratio:
                        maximum_ratio = sugar_ratio
                        max_a = a
                        max_b = b
                        max_c = c
                        max_d = d
                else:
                    break

print("%d %d" % (100 * A * max_a + 100 * B * max_b + C * max_c + D * max_d, C * max_c + D * max_d))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void prime_factorization(vector<int> &P, ll N) {
    for(ll i = 2; i * i <= N; i++) {
        if(N % i == 0) {
            ll ex = 0;
            while(N % i == 0) {
                ex++;
                N /= i;
            }
            P.at(i) += ex;
        }
    }
    if(N != 1) P.at(N)++;
}

int main() {
    ll N; cin >> N;
    ll ans = 1;
    vector<int> prime(N+1,1);
    for(int i = 2; i <= N; i++) {
        prime_factorization(prime,i);
    }
    for(auto x:prime) {
        ans *= x;
        ans %= 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		String[] tmpArray = input.split(" ");
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		
		String posStr = br.readLine();
		
		String ptnStr = "\\d{"+a+"}-\\d{"+b+"}";
		
		if(Pattern.matches(ptnStr, posStr)){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
//		String[] postal = posStr.split("-", -1);
////		Pattern p = Pattern.compile("[\\d]++");
////		Matcher m = p.matcher(arg0)
//		boolean available = false;
//		if(posStr.charAt(a) != '-'){
//			available = false;
//		}
//		else if(postal.length != 2){
//			available = false;
//		}
//		
////		else if(!postal[1].equals("-")){
////			available = false;
////		}
//		else if(postal[0].length() == a && Pattern.matches("\\d++", postal[0])
//			&& postal[1].length() == b && Pattern.matches("\\d++", postal[1])){
//			available = true;
//		}
//		
//		if(available){
//			System.out.println("Yes");
//		}
//		else {
//			System.out.println("No");
//		}
	}

}


Measured memory_bytes: 21332
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <vector>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L


const int N = 2e5 + 5;

 
int vis[N];


int32_t  main() {

	IOS;

 
	long double a, b, h, m;

	cin >> a >> b >> h >> m;


	long double tmp1 = h * 5 + m / 60 * 5;
	//cout << tmp1 << endl;
	long double diff = abs(tmp1 - m);

	long double degree = diff * 6.0;
	//cout << degree << endl;
	long double rad = (degree * PI) / 180;

	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
		b) * cosl(rad);

	cout << fixed << showpoint << setprecision(20) << sqrt(rsq) << endl;

}

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

int binarySearch(int S[],int n,int key){
  int left=0,right = n,mid;
  while(left < right){
    mid = (right + left)/2;
    if(S[mid]==key)return true;
    else if(key<S[mid])right = mid;
    else left = mid+1;
  }
  return false;
}
int main(){
  int n,S[100000],q,ans=0,key;
  cin>>n;
  for(int i=0;i<n;i++)cin>>S[i];
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>key;
    if(binarySearch(S,n,key))ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector < long long > vll;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef vector < int > vi;
#define deb(x) cout << #x << " : " << x << endl
#define deb2(x , y) cout << #x << " : " << x << " , "<< #y << " : " << y << endl
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define s(n) cin >> n
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) ((b)+((a) - (b))/2)
#define INF (1e9 + 7)
#define endl '\n'

void solve() {
	int n;
	cin>>n;
	vll h(n),arr(n);
	rep(i,n){
		cin>>h[i];
	}
	arr[0]=0;
	arr[1]=abs(h[1]-h[0]);
	reps(i,2,n){
		arr[i]=min(arr[i-1]+abs(h[i]-h[i-1]),arr[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<arr[n-1];
}

int main() {
	csl;
	int testcase=1;
//	cin >> testcase;
	for (int i = 0; i < testcase; i++) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 4768