akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7;//998244353 ;

ll l[200020],r[200020];

int main(){
  int n,k;
  cin >> n >> k;
  ll a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  deque<ll> que;
  rep(i,n)que.push_back(a[i]);
  /*
  l[0]=a[0];
  rep(i,n){
    l[i+1]=l[i];
    l[i+1]*=a[i+1];
    l[i+1]%=mod;
  }
  r[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
    r[i]=r[i+1];
    r[i]*=a[i];
    r[i]%=mod;
  }
  */
  ll ans=1;
  if(a[n-1-(k-1)]==0){
    cout << 0 << endl;
    return 0;
  }
  if(a[0]>=0 || (k%2 && a[n-1]<0)){
    rep(i,k){
      ans*=a[n-1-i];
      ans%=mod;
      ans+=mod;
      ans%=mod;
    }
    cout << ans << endl;
    return 0;
  }
  int cnt=0;
  while(cnt+1<k){
    ll x=que.at(0),y=que.at(1);
    ll t=(x*y);
    int sz=que.size();
    ll a=que.at(sz-1);
    ll b=que.at(sz-2);
    ll s=(a*b);
    if(t>=s){
      t%=mod;
      ans*=t;
      ans%=mod;
      que.pop_front();
      que.pop_front();
    }else{
      s%=mod;
      ans*=s;
      ans%=mod;
      que.pop_back();
      que.pop_back();
    }
    cnt+=2;
//    cout << ans << endl;
  }
//  cout << cnt << endl;
//  cout << que.front() << ' ' << que.back() << endl;
  if(cnt!=k){
    ans*=(que.back());
    ans%=mod;
    ans+=mod;
    ans%=mod;
  }
  ans+=mod;
  ans%=mod;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 6668
import os, sys, re, math

(N, D) = [int(n) for n in input().split()]
X = []
for i in range(N):
    X.append([int(n) for n in input().split()])

result = 0
for i in range(N):
    for j in range(i + 1, N):
        d = math.sqrt(sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)]))
        if d.is_integer():
            result += 1

print(result)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
int main(){
	string s;
	cin>>s;
	if(s=="Sunny"){
		cout<<"Cloudy"<<endl;
	}else if(s=="Cloudy"){
		cout<<"Rainy"<<endl;
	}else if(s=="Rainy"){
		cout<<"Sunny"<<endl;
	}
	return 0;
}

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

int main()
{
	long long n;
	cin>>n;
	queue<long long>q;
	for(long long i=1;i<=9;i++)
		q.push(i);
	while(!q.empty())
	{
		long long k=q.front();
		q.pop();
		n--;
		if(n==0)
		{
			cout<<k<<endl;
			break;
		}
		for(long long i=(k%10)-1;i<=(k%10)+1;i++)
		{
			if(i<0||i>=10)
				continue;
			q.push(k*10+i);
		}
	}

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    
    long count = 0;
		if((B-A)%2!=0) {
			if(A-1<=N-B) {
				count += A;
				count += (B-A-1)/2;
				System.out.println(count);
			}else{
				count += N-B+1;
				count += (B-A-1)/2;
				System.out.println(count);
			}
		}else {
			System.out.println((B-A)/2);
		}
	}
}
      
    

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int a,b,c;

int main(){
	cin.sync_with_stdio(false);
  cin>>a>>b>>c;
  rep(i,61){
    int st=(a+b)*i,ed=(a+b)*i+a;
    for(int j=0;j<10000;j++){
      if(st<=j*60+c&&j*60+c<=ed){
        cout<<j*60+c<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll D,i,j,t,ans=0;cin>>D;
  vector<ll>c(26),LAST(26,0);
  vector<vector<ll>>s(D,vector<ll>(26));
  REP(i,26)cin>>c.at(i);
  REP(i,D)REP(j,26)cin>>s.at(i).at(j);
  REP(i,D){
    cin>>t;LAST.at(t-1)=i+1;
    ans+=s.at(i).at(t-1);
    REP(j,26)ans-=c.at(j)*(i+1-LAST.at(j));
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,p,q;
	cin>>n;
	if(n==2){
		cin>>p>>q;
		cout<<max(p,q)<<" "<<min(p,q);
		return 0;
	}
	vector<int> a(n);
	for(auto&& c:a)cin>>c;
	sort(a.begin(),a.end());
	p=a[n-1];
	for(auto&& c:a)c-=p/2;
	sort(a.begin(),a.end());
	q=distance(a.begin(),lower_bound(a.begin(),a.end(),0));
	cout<<p<<" "<<a[!q?q:(abs(a[q-1])<abs(a[q])?q-1:q)]+p/2<<endl;
	return 0;
}


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

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

    int n, m, ans = 0;
    cin >> n >> m;
    vector<set<int>> s(m);
    vector<int> p(m);
    rep(i, m)
    {
        int k;
        cin >> k;
        rep(j, k)
        {
            int t;
            cin >> t;
            s[i].insert(t);
        }
    }
    rep(i, m) cin >> p[i];

    for (int bit = 0; bit < (1 << n); bit++)
    {
        vector<int> q(m, 0);
        rep(i, n)
        {
            if (!(bit & (1 << i)))
                continue;
            rep(j, m)
            {
                if (s[j].count(i + 1) == 1)
                    q[j] ^= 1;
            }
        }
        if (p == q)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math

from decimal import Decimal, ROUND_HALF_UP


def quantize(f):
    return int(Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))


def check(n, numbers):
    average = sum(numbers) / n
    average = quantize(average)
    costs = [int(math.pow(n - average, 2)) for n in numbers]
    return sum(costs)


def main():
    N = int(input())
    numbers = list(map(int, input().split()))
    print(check(n=N, numbers=numbers))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        int n = a[N-1];
        int r = 0;
        int min_target = 0;
        int target = -1;
        for (int i = 0; i < N - 1; i++) {
            target = a[i];
            if (n / 2 < a[i]) {
                target = n - a[i];
            }
            if (min_target < target) {
                min_target = target;
                r = a[i];
            }
        }
        System.out.printf("%d %d\n", n, r);
    }
}


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

int main() {
    int n, q; long long m;
    scanf("%d%lld%d", &n, &m, &q);
    vector<int> uf(n);
    for (int i = 0; i < n; ++i) uf[i] = i;

    function<int(int)> Find = [&](int x) {
        if (x == uf[x]) return x;
        return uf[x] = Find(uf[x]);
    };

    vector<pair<int, int>> e;
    for (int i = 0; i < q; ++i) {
        int u, v, c; scanf("%d%d%d", &u, &v, &c);
        if (c == 0) uf[Find(u)] = Find(v);
        else e.emplace_back(u, v);
    }
    for (int i = 0; i < e.size(); ++i) {
        if (Find(e[i].first) == Find(e[i].second)) {
            puts("No");
            return 0;
        }
    }
    int k = 0;
    for (int i = 0; i < n; ++i) if (Find(i) == i) ++k;
    long long km = 1LL * k * (k - 1) / 2 + n - k;
    if (m == n - 1) {
        if (e.empty()) puts("Yes");
        else puts("No");
    } else {
        if (m <= km) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 1784
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 305;

LL N, K;

int main()
{
	while(scanf("%lld %lld", &N, &K) != EOF)
	{
		LL ans = 0;
		if(K == 0) ans = N * N;
		else {
			for(LL b = K + 1; b <= N; b++) {
				ans += (b - K) * (N / b) + max(0LL, (N % b - K + 1));
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
   
    ll r  = ll(1e18)+5;
    
    ll l = 0;
    while(l+1 <r){
        ll mid = (r+l)/2;
        ll num = mid;
        for(int i=0;i<N;i++){
            num -= num%A[i];
        }
        if(num>2){
            r = mid;
        }else{
            l = mid;
        }
    }
    ll num = r-1;
    for(int i=0;i<N;i++){
        num -= num%A[i];
    }
    if(num != 2){
        cout << -1 <<endl;
        return 0;
    }
    ll large = r-1;
    r = large;
    l = 0;
    while(l + 1 < r){
        ll mid = (r+l)/2;
        // cerr <<"mid=" << mid << endl;
        ll num = mid;
        bool ok = true;
        for(int i=0;i<N;i++){
            // cerr <<"num=" <<num << endl; 
            if(num < A[i]){
                ok = false;
                break;
            }
            num = (num/A[i]) *A[i];
        }
        if(ok){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << r << " "<<large << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	int x,a,b,c,d; cin >> x;
	vector<P>ok;
	int cnt[105]={};
	int cnt2[105]={};
	for(int i=0;i<x;i++)
	{
		scanf("%d:%d-%d:%d",&a,&b,&c,&d);
		ok.pb(mp(a*60+b,c*60+d));
	}
	int n; cin >> n;
	for(int i=0;i<n;i++)
	{
		int m; cin >> m;
		for(int j=0;j<m;j++)
		{
			scanf("%d:%d-%d:%d",&a,&b,&c,&d);
			for(int k=0;k<x;k++)
			{
				if(a*60+b<=ok[k].fi&&ok[k].sc<=c*60+d)
				{
					cnt[k]++;
				}
			}
		}
	}
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int m; cin >> m;
		for(int j=0;j<m;j++)
		{
			scanf("%d:%d-%d:%d",&a,&b,&c,&d);
			for(int k=0;k<x;k++)
			{
				if(a*60+b<=ok[k].fi&&ok[k].sc<=c*60+d)
				{
					cnt2[k]++;
				}
			}
		}
	}
	int res = 0;
	for(int i=0;i<x;i++)
	{
		res += min(cnt[i],cnt2[i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;
const ll infll=1e15;

int ans[500][500];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r,c,k;
    cin>>r>>c>>k;

    char ara[500][500];
    set<int>emprow;
    bool ase=0;

    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
        {
            cin>>ara[i][j];
            if(ara[i][j]=='#')
                ase=1;
        }

        if(!ase)
            emprow.insert(i);
        ase=0;
    }

    int fol=0,cur=1;

    for(int i=0; i<r; i++)
    {
        if(!emprow.count(i))
        {

            for(int j=0; j<c; j++)
            {

                if(ara[i][j]=='#')
                {
                    fol++;

                    if(fol!=cur)
                        cur++;
                }

                ans[i][j]=cur;

            }

            cur++;

        }
    }


    if(!emprow.empty())
    {

        int pos=-1;

        for(int i=0; i<r; i++)
        {
            if(!emprow.count(i))
            {
                for(int j=i-1; j>pos; j--)
                    for(int k=0; k<c; k++)
                        ans[j][k]=ans[i][k];

                pos=i;
            }
        }

        if(pos!=r-1)
        {
            for(int j=r-1; j>pos; j--)
                for(int k=0; k<c; k++)
                    ans[j][k]=ans[pos][k];
        }
    }


    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
        {
            cout<<ans[i][j]<<" ";
        }

        cout<<"\n";
    }



    return 0;
}


Measured memory_bytes: 1536
// C - Special Trains
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<tuple<int,int,int>> CSF;
	int c,s,f;
	rpz(i, N-1){
		cin>>c>>s>>f;
		CSF.emplace_back(c,s,f);
	}

	rpz(i, N-1){
		int ans = 0;
		tie(c,s,f) = CSF[i];
		ans = s + c;
		rp(j, i+1, N-1){
			int c2,s2,f2; tie(c2,s2,f2) = CSF[j];
			ans = max((ans + f2 - 1) / f2 * f2, s2) + c2;
		}
		cout<< ans <<endl;
	}
	cout<< 0 <<endl;
}

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

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

    string s;
    cin>>s;
    if(s=="KIHBR" || s=="KIHBRA" || s=="KIHBAR" || s=="KIHBARA" || s=="KIHABR" || s=="KIHABRA" || s=="KIHABARA" || s=="AKIHBR" || s=="AKIHBRA" || s=="AKIHBAR" || s=="AKIHBARA" || s=="AKIHABR" || s=="AKIHABRA" || s=="AKIHABAR" || s=="AKIHABARA")cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

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

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

    int flag = 0;
    ll ans = 0;

    pair<ll ,ll> p[n + 1];
    p[n].first = a[n];
    p[n].second = a[n];
    for(int i = n - 1; i >= 0; i--){
        p[i].first = p[i + 1].first / 2 + a[i];
        if(p[i + 1].first % 2 != 0){
            p[i].first++;
        }

        p[i].second = p[i + 1].second + a[i];
    }

    ll q = 1;
    for(int i = 0; i <= n; i++){
        if(p[i].first > q){
            flag = 1;
            break;
        }else{
            if(p[i].second <= q){
                ans += p[i].second;
                q = p[i].second * 2;
            }else{
                ans += q;
                q -= a[i];
                q *= 2;
            }
        }
    }

    if(flag == 1){
        ans = -1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5976
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#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) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;

    ll ans = INF;
    FOR(a, -100, 101) {
        ll cost = 0;
        REP(n, N) {
            cost += (A[n] - a) * (A[n] - a);
        }
        chmin(ans, cost);
    }

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

Measured memory_bytes: 256
<?php
  
$t = explode(' ', trim(fgets(STDIN)));

$xd = abs($t[2]-$t[0]);
$yd = abs($t[3]-$t[1]);
$px = $t[2];
$py = $t[3];

if ($t[2] > $t[0] && $t[3] >= $t[1]){
  $pxs = $px-$yd;
  $pys = $py+$xd;
  $pxt = $pxs-abs($pys-$py);
  $pyt = $pys-abs($pxs-$px);
} else if ($t[2] <= $t[0] && $t[3] > $t[1]){
  $pxs = $px-$yd;
  $pys = $py-$xd;
  $pxt = $pxs+abs($pys-$py);
  $pyt = $pys-abs($pxs-$px);
} else if ($t[2] < $t[0] && $t[3] <= $t[1]){
  $pxs = $px+$yd;
  $pys = $py-$xd;
  $pxt = $pxs+abs($pys-$py);
  $pyt = $pys+abs($pxs-$px);
} else if ($t[2] >= $t[0] && $t[3] < $t[1]){
  $pxs = $px+$yd;
  $pys = $py+$xd;
  $pxt = $pxs-abs($pys-$py);
  $pyt = $pys+abs($pxs-$px);
}

echo $pxs." ".$pys." ".$pxt." ".$pyt;
  
?>

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

// input
int N;
long long h[100010];

// DP table
long long dp[100010];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // initialize
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // initial condition
    dp[0] = 0;

    // loop
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // answer
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 200000;
int A[maxn + 1];
int B[maxn + 2];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i += 1) cin >> A[i];
    for(int i = 0; i < K; i += 1){
        if(all_of(A + 1, A + N + 1, [&](const int& x){return x == N;})) break;
        fill(B + 1, B + N + 1, 0);
        for(int i = 1; i <= N; i += 1){
            B[max(i - A[i], 1)] += 1;
            B[min(i + A[i], N) + 1] -= 1;
        }
        fill(A + 1, A + N + 1, 0);
        for(int i = 1; i <= N; i += 1) A[i] = A[i - 1] + B[i];
    }
    for(int i = 1; i <= N; i += 1) cout << A[i] << " ";
    return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  for (char c : s) {
    if (c == 'R') {
      ++cnt;
    } else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  cout << max(ans, cnt) << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 3608
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    if n == 1:
        b = a[0] // 2
        print((m-b)//(2*b) + 1)
        exit()
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    b = lcm_group(a)
    for i in a:
        if (b//i) % 2 == 0:
            print(0)
            exit()

    print((m-b//2)//b + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14628
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
    
    int n;
    
    cin>>n;
    
    ll ans = 0;
    for(int i=1;i<=n;++i) if(i%3 && i%5) ans+=i;
    
    cout<<ans<<endl;
    
    return 0;
}


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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

void solve() {
    int x;
    cin >> x;
    cout << !x;
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


Measured memory_bytes: 3636
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] V = new int[N];
		for (int i=0;i<N;i++) {
			V[i]=sc.nextInt();
		}

		long ans=0L;
		for (int i=0;i<Math.min(N,K)+1;i++) {
			for (int j=0;j<Math.min(N,K)-i+1;j++) {
				long value=0L;
				Queue<Integer> pq = new PriorityQueue<Integer>();
				for (int k=0;k<i;k++) {
					value+=V[k];
					pq.add(V[k]);
				}
				for (int k=N-1;k>N-j-1;k--) {
					value+=V[k];
					pq.add(V[k]);
				}
				for (int k=0;k<K-i-j;k++) {
					if (pq.isEmpty()) {
						break;
					}
					int tmp=pq.remove();
					if (tmp<0) {
						value-=tmp;
					} else {
						break;
					}
				}
				ans=Math.max(ans,value);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23760
///In the name of ALLAH

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'

const int mx = 1e5+123;
int h[mx], n, k;
int dp[mx];

int solve ( int i )
{
    if ( i == n ) return 0;
    if ( dp[i] != -1 ) return dp[i];

    int ret = 2e9;

    for ( int j = 1; j <= k; j++ ) {
        if ( i+j <= n ) ret = min ( ret,  abs ( h[i] - h[i+j] ) + solve ( i+j ) );
    }

    return dp[i] = ret;
}


int main()
{

    cin >> n >> k;
    for ( int i = 1; i <= n; i++ ) cin >> h[i];

    memset ( dp, -1, sizeof ( dp ) );
    cout << solve ( 1 ) << endl;

    return 0;
}

Measured memory_bytes: 12168
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = zeros(Int,n+1)
	for i in 1:n
		b[i+1] = b[i]+a[i]
	end
	k = b[n+1]
	for i in 1:n-1
		k = min(k,abs(b[n+1]-b[i+1]-b[i+1]))
	end
	println(k)
end
main()

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};


//-----------------------------------------------------------------------------

int x,y,z;

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

	cin>>x>>y>>z;
	if(x<y+z+z) cout<<0<<endl;
	else {
		x-=y+z+z;
		cout<<1+(x/(y+z))<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
#include<queue>
#include<utility>
using namespace std;

#define lld long long
#define P pair<lld,lld>

int main(){
    lld N;
    lld A[200005];
    lld cnt[200005];
    bool maxf[200005];
    bool maxf2[200005];
    vector<P> p_array;
    memset(cnt,0,sizeof(cnt));
    memset(maxf,false,sizeof(maxf));
    memset(maxf2,false,sizeof(maxf2));
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
        cnt[A[i]]++;
    }
    lld ans = 0;
    for (int i = 0; i < N; i++) {
        if(cnt[i] > 1){
            ans += (cnt[i])*(cnt[i]-1)/2;
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans - ((cnt[A[i]])*(cnt[A[i]]-1)/2) + ((cnt[A[i]]-1)*(cnt[A[i]]-2)/2) << endl;
    }
}

Measured memory_bytes: 6144
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int main(){
	int c[3][3];
	rep(i,3){
		rep(j,3){
			cin >> c[i][j];
		}
	}
	int a[3];
	int b[3];
	a[0]=0;
	b[0]=c[0][0];
	b[1]=c[0][1];
	b[2]=c[0][2];
	a[1]=c[1][0]-b[0];
	a[2]=c[2][0]-b[0];

	bool ans = (a[1]+b[1]==c[1][1] && a[1]+b[2]==c[1][2] && a[2]+b[1]==c[2][1] && a[2]+b[2]==c[2][2]);

	(ans)? cout << "Yes" <<endl:cout << "No" <<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int A = Integer.parseInt(br.readLine());

        int num1 = N%500;
        int out2 = num1/1;
        String j;
        if(out2 <= A){
            j = "Yes";
        }else{
            j = "No";
        }
        System.out.println(j);

    }
}


Measured memory_bytes: 21204
#include<stdio.h>

int main(){
  
  int N,M;
  scanf("%d %d",&N,&M);
  int sum = 0;

  int A[M];
  for(int i=0; i<M; i++){
    scanf("%d",&A[i]);
    sum += A[i];
  }

  if(N >= sum){
    printf("%d",N-sum);
  }else{
    printf("-1");
  }

  return 0;

}

Measured memory_bytes: 1764
mod=1000000007
n,k=gets.split.map(&:to_i)
l=[nil]
n.times do
  l << []
end
(n-1).times do
  a,b=gets.split.map(&:to_i)
  l[a] << b
  l[b] << a
end
v=[0]*(n+1)
v[1]=1
c=k
kk=k-1
s=[]
[1].each do |ss|
  l[ss].each do |lss|
    v[lss]=1
    s << lss
    c=c*kk%mod
    kk-=1
  end
end
while s!=[]
  z=[]
  s.each do |ss|
    kk=k-2
    l[ss].each do |lss|
      if v[lss]==0
        v[lss]=1
        z << lss
        c=c*kk%mod
        kk-=1
      end
    end
  end
  s=z.dup
end
puts c


Measured memory_bytes: 25612
N = int(input())
A = list(map(int,input().split()))

c = [0 for j in range(20)]

l = 0

ans = 0

for r,a in enumerate(A):
    
    for j in range(20):
        c[j] += (a>>j)&1
    
    while sum(c[j] < 2 for j in range(20)) != 20:

        b = A[l]
        for j in range(20):
            c[j] -= (b>>j)&1
        l += 1
    
    ans += (r-l+1)

print(ans)


Measured memory_bytes: 77900
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

#define double long double

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

i64 N;
vector<double> X, Y;
double len(i64 i, i64 j) {
  double dx = X[i] - X[j];
  double dy = Y[i] - Y[j];
  return dx * dx + dy * dy;
}
int main() {
  cin >> N;
  X.resize(N);
  Y.resize(N);
  cout << fixed << setprecision(10);
  rep(i,0,N) cin >> X[i] >> Y[i];
  double ans = 1e18;
  if(N == 2) {
    double ox = (X[0] + X[1]) / 2;
    double oy = (Y[0] + Y[1]) / 2;
    double dx = ox - X[0];
    double dy = oy - Y[0];
    ans = dx * dx + dy * dy;
  }
  rep(i,0,N) {
    rep(j,i + 1, N) {
      double ox = (X[i] + X[j]) / 2;
      double oy = (Y[i] + Y[j]) / 2;
      double dx = ox - X[i];
      double dy = oy - Y[j];
      double r = dx * dx + dy * dy;
      bool OK = true;
      rep(ii,0,N) {
        dx = ox - X[ii];
        dy = oy - Y[ii];
        double ri = dx * dx + dy * dy;
        if(r < ri) OK = false;
      }
      if(OK) {
        ans = std::min(ans, r);
      }
    }
  }
  rep(i,0,N) {
    rep(j,i + 1,N) {
      rep(k,j + 1, N) {
        double I = len(j, k);
        double J = len(i, k);
        double K = len(i, j);
        double Ic = I * (J + K - I);
        double Jc = J * (I + K - J);
        double Kc = K * (I + J - K);
        double ox = (Ic * X[i] + Jc * X[j] + Kc * X[k]) / (Ic + Jc + Kc);
        double oy = (Ic * Y[i] + Jc * Y[j] + Kc * Y[k]) / (Ic + Jc + Kc);
        double dx, dy;
        double r = (ox - X[i]) * (ox - X[i]) + (oy - Y[i]) * (oy - Y[i]);
        double s = (ox - X[j]) * (ox - X[j]) + (oy - Y[j]) * (oy - Y[j]);
        double t = (ox - X[k]) * (ox - X[k]) + (oy - Y[k]) * (oy - Y[k]);
        r = std::max({ r, s, t });
        bool OK = true;
        rep(ii,0,N) {
          dx = ox - X[ii];
          dy = oy - Y[ii];
          double ri = dx * dx + dy * dy;
          if(r < ri) OK = false;
        }
        if(OK) {
          ans = std::min(ans, r);
        }
      }
    }
  }
  cout << fixed << setprecision(10);
  cout << sqrt(ans) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n){
        if(p[i] != i + 1)
            ++ans;
    }
    if(ans <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


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

int main() {
  long long h, cnt = 0, sum = 0;
  cin >> h;
  
  while (h != 0) {
    h /= 2;
    sum += pow(2, cnt);
    cnt++;
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<Pll> prime_factorize(ll N) {
    vector<Pll> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int n;
map<ll, int> sisuu;

ll rec(map<ll, int> ::iterator p, ll mul)
{
    if (p == sisuu.end())
    {
        if (mul == 1) return 1;
        else return 0;
    }
    ll ans = 0;
    rep(i, p->second + 1)
    {
        if (mul % (i + 1) != 0) continue;
        p++;
        ans += rec(p, mul / (i + 1));
        --p;
    }
    return ans;
}

int main()
{
    cin >> n;
    Rep(i, 2, n + 1)
    {
        auto ps = prime_factorize(i);
        for (auto it : ps) sisuu[it.first] += it.second; // second = 指数の数
    }
    cout << rec(sisuu.begin(), 75) << endl;
}

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

// https://yamakasa.net/atcoder-abc-127-c/
// http://drken1215.hatenablog.com/entry/2019/06/11/103300


int main(void) {
    int n, m;
    cin >> n >> m;
    int *l, *r;
    l = new int[m];
    r = new int[m];

    for(int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i];
    }

    int lb = l[0];
    int rb = r[0];
    
    for(int i = 1; i < m; ++i) {

        if (l[i] > lb) {
            lb = l[i];
        }

        if (r[i] < rb) {
            rb = r[i];
        }

        if(lb>rb) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << rb - lb + 1 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
 
int sortfnc(const void *a,const void *b){
    if(*(unsigned long long int*)a == *(unsigned long long int*)b){return 0;}
    if(*(unsigned long long int*)a > *(unsigned long long int*)b){return -1;}
    return 1;
}
 
unsigned long long int nCr(unsigned long long int n,unsigned long long int r){
	unsigned long long int i,res = 1;
	for(i = 1;i <= r;i++){
		res*=(n-i+1);
		res/=i;
	}
	return res;
}
 
unsigned long long int ssearch(unsigned long long int x,unsigned long long int a[]){
	unsigned long long int i,r = 0;
	for(i = 0;i <= 63;i++){if(a[i] == x){r++;}}
	return r;
}
 
int main(void){
	unsigned long long int n,a,b,v[64]={0},i,f=0,r=0,sv,usv,nv,p,rvpc,rvpm,prr;
	scanf("%llu%llu%llu",&n,&a,&b);
	for(i = 0;i < n;i++){scanf("%llu",&v[i]);}
	qsort(v,n,sizeof(long long),sortfnc);
	i = 0;
	sv = 0;
	while(1){
		nv = v[i];
		sv+=v[i];
		if(i != 0 && v[i] == v[i-1]){usv++;}else{usv = 1;}
		if(i != 0 && v[i] != v[i-1]){f++;}
		i++;
		if(b < i){break;}
		if(a < i && f >= 1){break;}
		if(a <= i){
			if(a == i){rvpc = sv;rvpm = i;}
			p = nCr(ssearch(nv,v),usv);
			r+=p;
		}
	}
	prr = rvpc % rvpm;
	prr*=100000000000;
	prr/=rvpm;
	printf("%llu.%011llu\n%llu\n",rvpc/rvpm,prr,r);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define eb emplace_back
#define MP make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define all(v) (v).begin(), (v).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define tr(c,it) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n) for(lli i=0;i<(n);i++)
#define inc(i,a,b) for(lli i=a;i<=b;i++)
#define dec(i,a,b) for(lli i=a;i>=b;i--)
#define fr2(i,n) for(int i=0;i<(n);i++)
#define inc2(i,a,b) for(int i=a;i<=b;i++)
#define dec2(i,a,b) for(int i=a;i>=b;i--)
#define ymin(a,b)  (a=min((a),(b)))
#define ymax(a,b)  (a=max((a),(b)))
#define sz(x) (lli)(x).size()
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<lli,lli> plli;
typedef vector<lli> vlli;
typedef vector<int> vi;
//typedef  vector<vector<lli> >ncr(1001,vector<lli>(1001,0))
typedef vector<plli> vplli;
long long MOD=1000000009;
double startTime;
double getCurrentTime()
{
	return ((double)clock()-startTime)/CLOCKS_PER_SEC;
}

lli pwr(lli x,lli n)
{
	lli res=1;
	for(; n!=0;n>>=1)
	{
		if(n&1)
			res=(res*x)%MOD;
		x=(x*x)%MOD;
	}
	return res;
}
lli inver(lli num)
{
	return pwr(num,MOD-2);
}
lli findncr(lli n,lli r)
{
	r=min(r,n-r);
	if(n==0||n==1||r==0)
		return 1;
	lli numer=1;
	for(lli i=n;i>=n-r+1;i--)
		numer=(numer*i)%MOD;
	lli den=1;
	for(lli i=2;i<=r;i++)
		den=(den*i)%MOD;
	den=inver(den);
	lli res=(numer*den)%MOD;
	return res;
}
lli gcd(lli a,lli b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	// 	#ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS
	int n;
	cin>>n;
	vector<int>vec1(n+1,0);
	vector<int>vec2(n+1,0);
	vector<int>vec3(n+1,0);
	for(int i=1;i<=n;i++)
		cin>>vec1[i]>>vec2[i]>>vec3[i];
	vector<vector<lli> >dp(n+1,vector<lli>(4,0));
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=vec1[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=vec2[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=vec3[i]+max(dp[i-1][0],dp[i-1][1]);

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




Measured memory_bytes: 8448
import sys
import math
input = sys.stdin.readline


a, b= (int(i) for i in input().split())  
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

ans = ""
if a!=b:
    if a < b:
        for i in range(b):
            ans += str(a)
    else:
        for i in range(a):
            ans += str(b)
    print(ans)
else:
    if a < b:
        for i in range(a):
            ans += str(b)
    else:
        for i in range(b):
            ans += str(a)
    print(ans)


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

bool used[100009];
int N, A, B, L[1 << 18], R[1 << 18];

int main() {
	cin >> A >> B >> N;
	for (int i = 0; i < N; i++) {
		cin >> L[i] >> R[i];
		for (int j = L[i]; j < R[i]; j++) used[j] = true;
	}

	int ret = 0;
	for (int i = A; i < B; i++) {
		if (used[i] == true) ret = 1;
	}
	cout << ret << endl;
	return 0;
}


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

typedef pair<int,int> P;

int main(){
	int h[6],w[6];
	map<P,int> mp;
	map<int,int> mpp;
	for(int i = 0;i < 6;i++){
		cin >> h[i] >> w[i];
		if(h[i] > w[i]) swap(h[i],w[i]);
		mp[P(h[i],w[i])]++;
		mpp[h[i]]++;
		mpp[w[i]]++;
	}
	bool flag = true;
	if(mp.size() >= 4) flag = false;
	if(mpp.size() >= 4) flag = false;
	if(mpp.size() == 2){
		int same = 0;
		for(int i = 0;i < 6;i++){
			if(w[i] == h[i]) same++;
		}
		if(same != 2) flag = false;
		if(mp.size() != 2) flag = false;
	}else if(mpp.size() == 3){
		if(mp.size() != 3) flag = false;
		for(auto it = mp.begin();it != mp.end();it++){
			if(it->first.first == it->first.second) flag = false;
			if(it->second != 2) flag = false;
		}
	}
	if(flag) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}

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

//#define DEBUG

using namespace std;

const uint32_t MAX_K = 1000000;
uint64_t free_pow[MAX_K + 1];
uint64_t restrict_pow[MAX_K + 1];

const uint64_t MOD = 1000000007;


template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


uint64_t power_s(uint32_t a, uint32_t p, uint64_t M){
    if( p < 3){
        uint64_t ans = 1;
        while(p--){
            ans =  (ans * a) % M;
        }
        return ans;
    }else{
        uint64_t half_ans = power_s(a, p/2, M);
        uint64_t ans = (half_ans * half_ans) % M;
        if( p % 2 == 1){
            ans = ( a * ans) % M;
        }
        return ans;
    }
}

 
void compute_pow(){
    uint64_t free = 1;
    uint64_t restrict = 1;
    free_pow[0] = free;
    restrict_pow[0] = restrict;
    for(uint32_t expo = 1 ; expo <= MAX_K ; expo++ ){
        free = free * 26;
        restrict = restrict * 25;
        if( free >= MOD){
            free = free % MOD;
        }
        if(restrict >= MOD){
            restrict = restrict % MOD;
        }
        free_pow[expo] = free;
        restrict_pow[expo] = restrict;
    }
}
 
void solve(){
 
    uint32_t K;
    cin >> K;
    std::string S;
    cin >> S;
    uint32_t last_position = S.size();
    K = K + S.size();
    uint64_t count = 0;

    compute_pow();
    uint64_t reposition_choices = 1;
 
    for(; last_position <= K ; last_position++){
        uint64_t last_choices = free_pow[K -last_position];
        uint64_t completion_choices = restrict_pow[last_position - S.size()];
        uint64_t overall_choices = last_choices * reposition_choices;
        if( overall_choices >= MOD){
            overall_choices = overall_choices % MOD;
        }
        overall_choices = overall_choices * completion_choices;
        if(overall_choices >= MOD){
            overall_choices = overall_choices % MOD;
        }
        count = (count + overall_choices) % MOD;

        reposition_choices = reposition_choices * last_position ;
        if(reposition_choices >= MOD){
            reposition_choices = reposition_choices % MOD;
        }

        uint64_t inverse_modulo = power_s(last_position + 1 - S.size(), MOD - 2, MOD);

        reposition_choices = reposition_choices * inverse_modulo;
        if(reposition_choices >= MOD){
            reposition_choices = reposition_choices % MOD;
        }
    }
    cout << count << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 19824
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	long long int a, b;
	cin >> a >> b;
	vector<long long int> v;
	for(long long int i = 2; i * i <= a; i++){
		if(a % i == 0){
			v.push_back(i);
		}
		while(a % i == 0){
			a /= i;
		}
	}
	if(a != 1) v.push_back(a);
	long long int ans = 1;
	for(long long int i = 0; i < v.size(); i++){
		if(b % v[i] == 0) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
s = list(map(int, input()))

now = 1
cnt = 0
nums = []

for i in range(n):
    if s[i] == now: cnt+=1
    else:
        nums.append(cnt)
        now = 1 - now  # 0, 1の切り替え
        cnt = 1  # カウントを始める

if cnt != 0: nums.append(cnt)

# 計算しやすさのため、1の個数-0の個数...1の個数という配列が欲しい
if (len(nums) % 2 == 0): nums.append(0)

add = 2 * k + 1
tmp_sum = 0

left = 0
right = 0

ans = 0

for i in range(0, len(nums), 2):

    next_left = i
    next_right = min(i + add, len(nums))

    while left < next_left:
        tmp_sum -= nums[left]
        left+=1

    while right < next_right:
        tmp_sum += nums[right]
        right+=1

    ans = max(tmp_sum, ans)

print(ans)




Measured memory_bytes: 4768
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long

   
 


void solve()
{
   int n,x,t;
   cin>>n>>x>>t;
   int y=0;
   if(n%x)
   {
       y=n/x+1;
   }
   else y=n/x;
   
   cout<<y*t;
   
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}


Measured memory_bytes: 3640
main = input >>= return . factorial >>= output

input :: IO (Int)
input = getLine >>= return . read

output :: Int -> IO ()
output = putStrLn . show

factorial :: Int -> Int
factorial n = factorial' n 1
    where
    factorial' 1 r = r
    factorial' n r = factorial' (n-1) (n*r)

Measured memory_bytes: 3620
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Feb  9 21:00:01 JST 2020
 **/

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

signed main() {
    Int n, K;
    cin >> n >> K;
    vector<Int> p(n);
    REP(i, n) cin >> p[i];
    Int ma = -1, acc = 0;
    REP(i, n) {
        acc += p[i] + 1;
        if (i - K >= 0) acc -= p[i - K] + 1;
        chmax(ma, acc);
    }
    cout << double(ma) / 2 << endl;
}


Measured memory_bytes: 1792