akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    lint N;
    cin >> N;
    if(N % 2){
        cout << 0 << endl;
        return 0;
    }
    lint ans = 0;
    N /= 2;
    while(N){
        N /= 5;
        ans += N;
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {

    	// ??\??????????????????????????????
		BufferedReader r = new BufferedReader (new InputStreamReader (System.in));
		String s = r.readLine();

		// ??\??????????????????????????????????????§??????
		String[] morse = s.split(" ");

		// ???????????????????????????????????°??????????????????
		int height = Integer.parseInt(morse[0]);
		int width = Integer.parseInt(morse[1]);

		// ??¢???????¨??????????
		int area = height*width;

		// ??¨???????¨??????????
		int rect = 2*(height+width);

		// ?????????????????????
		System.out.println(area+" "+rect);
    }
}

Measured memory_bytes: 24244
#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 <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string a;
    cin >> a;
    if (a.size() < 4)cout << "No" << endl;
    else if (a[0] == 'Y' && a[1] == 'A' && a[2] == 'K' && a[3] == 'I')cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#2
n = int(input())
visited = set()
ans = "Yes"
bef = ""
for i in range(n):
    c = str(input())
    if c in visited:
        ans = "No"
        break
    else:
        if i != 0:
            if c[0] != bef[-1]:
                ans = "No"
                break
    bef = c
    visited.add(c)
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int res = 0;
	res+=min(a,k);
	k-=min(a,k);
	k-=min(b,k);
	res-=min(c,k);
	cout << res << '\n';
}


Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] array = br.readLine().split(" ");
			int N = Integer.parseInt(array[0]);
			int C = Integer.parseInt(array[1]);

			int[] channels = new int[N];
			int[] starts = new int[N];
			int[] ends = new int[N];
			for (int i = 0; i < N; i++) {
				String[] tmp = br.readLine().split(" ");

				starts[i] = Integer.parseInt(tmp[0]);
				ends[i] = Integer.parseInt(tmp[1]);
				channels[i] = Integer.parseInt(tmp[2]);
			}
			final int[] table = new int[2 * 100_001];
			final boolean[] tmp = new boolean[2 * 100_001];
			boolean updated = false;
			for (int channel = 1; channel <= C; channel++) {
				if (updated) {
					for (int i = 0; i < tmp.length; i++) {
						tmp[i] = false;
					}
					updated = false;
				}

				for (int index = 0; index < N; index++) {
					if (channels[index] == channel) {
						for (int i = starts[index] * 2 - 1; i <= ends[index] * 2; i++) {
							tmp[i] = true;
						}
						updated = true;
					}
				}

				for (int i = 0; i < table.length; i++) {
					if (tmp[i]) {
						table[i]++;
					}
				}
			}

			int max = Integer.MIN_VALUE;
			for (int i = 0; i < table.length; i++) {
				max = Math.max(max, table[i]);
			}

			System.out.println(max);
		}
	}
}


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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
	ll n,a,b;
    cin>>n>>a>>b;
    vi h(n);
    rep(i,0,n) cin>>h[i];

    ll l = -1;
    ll r = 1e10;
    while(l+1<r){
        ll mid = (l+r)/2;
        ll totNeed = 0;
        rep(i,0,n){
            ll hi = max(0ll,(h[i]-mid*b));
            totNeed +=hi/(a-b) + (hi%(a-b)!=0);
        }
        if(totNeed>mid) l = mid;
        else r = mid;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 1024
# frozen_string_literal: true

# だるいので全探索
dishes = 5.times.map { gets.chomp.to_i }

ans = 10**9
arr = (0..4).to_a.permutation.to_a
arr.each do |a|
  t = 0
  a.each.with_index do |vi, idx|
    t += if idx < 4
           if dishes[vi] % 10 != 0
             (dishes[vi] + (10 - dishes[vi] % 10))
           else
             dishes[vi]
           end
         else
           dishes[vi]
         end
  end
  ans = [ans, t].min
end

puts ans


Measured memory_bytes: 1788
import java.util.Scanner;


// 152_b
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        String aa = "";
        String bb = "";
        for (int i = 0; i < b; i++) {
            aa += a;
        }

        for (int i = 0; i < a; i++) {
            bb += b;
        }

        if (aa.compareTo(bb) < 0) {
            out(aa);
        } else {
            out(bb);
        }

    }

    /*
     * 以下メソッド集
     */

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 20564
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 500006;

int n;
string s;
int bit[26][N];

void add(int *bit, int idx, int val) {
  for(int i = idx ; i <= n ; i += i & -i)
    bit[i] += val;
}

int get(int* bit, int idx) {
  int r = 0;
  for(int i = idx ; i > 0 ; i -= i & -i)
    r += bit[i];
  return r;
}

int get(int* bit, int l, int r) {
  return get(bit, r) - get(bit, l - 1);
}

int main()
{
  cin >> n >> s;
  for(int i = 0 ; i < n ; i++) {
    int cur = s[i] - 'a';
    add(bit[cur], i + 1, 1);
  }
  int q;
  cin >> q;
  while(q--) {
    int t;
    cin >> t;
    if(t == 1) {
      int idx;
      char c;
      cin >> idx >> c;
      int cur = s[--idx] - 'a';
      add(bit[cur], idx + 1, -1);
      add(bit[c - 'a'], idx + 1, 1);
      s[idx] = c;
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for(int i = 0 ; i < 26 ; i++)
        ans += get(bit[i], l, r) > 0;
      cout << ans << endl;
    }
  }
  return 0;
}


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

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll x;
    cin >> x;
    ll n = 100, m;
    for (int i = 1;; i++) {
        m = n / 100;
        n += m;
        if (n >= x) {
            cout << i << "\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define INF 1234567890ll
#define EPS (1e-7)
#define PI (acos((ld)-1.0))
#define ll long long int 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
typedef pair <int, int> pi;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << '\n'; err(++it, args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x){stringstream s; s << x; return s.str(); }
ll stl(string x){stringstream s(x); ll temp; s >> temp; return temp; }
const int MOD = 1e9 + 7;
int A[100005], B[100005], C[100005];
int dp1[100005];
int dp2[100005];
int dp3[100005];
int main()
{
	IAMSPEED
	int n; cin >> n;
	FOR(i,1,n) cin >> A[i] >> B[i] >> C[i];
	dp1[1]=A[1];
	dp2[1]=B[1];
	dp3[1]=C[1];
	FOR(i,2,n) {
		dp1[i]=max(dp2[i-1], dp3[i-1]) + A[i];
		dp2[i]=max(dp1[i-1], dp3[i-1]) + B[i];
		dp3[i]=max(dp1[i-1], dp2[i-1]) + C[i];
	}
	cout << max({dp1[n], dp2[n], dp3[n]});
}

Measured memory_bytes: 2560
n,m=map(int,input().split())

ans=["#"]*n
for _ in range(m):
    s,c=map(int,input().split())
    # 同じ桁に複数の指示が飛んできたら狩猟
    if not ans[s-1] in["#",c]:
        print(-1)
        exit()
    ans[s-1]=c

#　nが一桁の時の対応
if len(ans)==1:
    print(0 if ans[0]=="#" else ans[0])
    exit()
#頭の数字について
if ans[0]==0:
    print(-1)
    exit()

if ans[0]=="#":
    ans[0]=1

for num in ans:
    print(num if num!="#" else 0,end="")


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

int main(){
    int N; cin>>N;
    set<int> d;
    for(int i=0;i<N;i++){
        int tmp; cin>>tmp;
        d.insert(tmp);
    }
    int ans=0;
    ans=d.size();
    cout<<ans;
}

Measured memory_bytes: 256
N, P = map(int, input().split())

S = input()

total = 0
if P == 2 or P == 5:
	for i, s in enumerate(S):
		if int(s) % P == 0:
			total += i + 1
else:
	counts = [0] * P
	counts[0] = 1
	h = 0
	
	d = 1
	for s in reversed(S):
		m = int(s) * d % P
		h = (h + m) % P
		total += counts[h]
		counts[h] += 1
		d = (d * 10) % P

#print(counts)

print(total)


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

namespace practice
{
    class Program
    {
        static void Main(string[] args)
        {
        	var input = Console.ReadLine();
            var isDuplicated = input.Distinct().Count() == input.Length;
			
            if (isDuplicated)
            {
                Console.WriteLine("yes");
            }
            else
            {
                Console.WriteLine("no");
            }

        }
    }
}


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

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

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (auto &e: a) cin >> e;
    vector<int> b(n);
    for (auto &e: b) cin >> e;

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ll t = min(a[i], b[i]);
        ans += t;
        b[i] -= t;
        t = min(a[i+1], b[i]);
        ans += t;
        a[i+1] -= t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
function gcd(a,b){return b?gcd(b,a%b):a;}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var k = next();
  var ans = 0;
  for(var i = 1; i <= k; i++)for(var j = 1; j <= k; j++)for(var x = 1; x <= k; x++){
    var t = gcd(i,j);
    t = gcd(t,x);
    ans += t;
  }
  return ans;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<bool> v(n);
    for (int i = 0; i < n; i++)
    {
        v[i] = true;
    }
    for (int i = 0; i < m; i++)
    {
        if (h[a[i]] <= h[b[i]])
        {
            v[a[i]] = false;
        }
        if (h[a[i]] >= h[b[i]])
        {
            v[b[i]] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (v[i] == true)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4528
N,X,M=map(int,input().split())
table=[X]
visited=[-1]*M
visited[X]=1

ans=X

for i in range(N-1):
    nx=table[i]**2
    nx%=M
    if visited[nx]>0:
        first=table.index(nx)
        oneloop=i+1-first
        rest=N-i-1
        loops=rest//oneloop
        totalofoneloop=sum(table[first:])
        ans+=totalofoneloop*loops
        remain=rest%oneloop
        ans+=sum(table[first:first+remain])
        print(ans)
        exit()
    else:
        table.append(nx)
        visited[nx]=1
        ans+=nx
 

print(ans)

Measured memory_bytes: 12092
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
{
	long long int a,b,c,d,A,B,C,D;
	cin>>a>>b>>c>>d;
	A=a*c;
	B=a*d;
	C=b*c;
	D=b*d;
	A=max(A,B);
	C=max(C,D);
	cout<<max(A,C)<<endl;
	
}

Measured memory_bytes: 3584
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
ll gcd(ll n, ll m){
    if(n % m == 0) return m;
    return gcd(m, n % m);
}
int main(){
  ll a,b;
  cin>>a>>b;
  ll l=1;
  ll c=gcd(a,b);
  if(c%2==0){l++;
             while(c%2==0){c/=2;}}
  ll d=c;
  for(ll i=3;i*i<=d;i+=2){
    if(c%i==0){while(c%i==0){c/=i;}
               l++;}}
  if(c!=1){l++;}
  cout<<l<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    ll n, x;
    cin >> n >> x;
    ll y = n-x;
    if (x>y) swap(x,y);
    ll ans = n;

    while (y % x > 0){
        ll n = y/x;
        ans += 2*n*x;
        y %= x;
        swap(x,y);
    }

    ans += ((y/x)*2-1)*x;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc058/tasks/abc058_b

O = input()
E = input()

len_E = len(E)
len_O = len(O)

E_count = 0
O_count = 0

total_len = len_E + len_O

ans = ''

for t in range(1, total_len + 1):
    if t % 2 == 0:
        ans = ans + E[E_count]
        E_count += 1
    else:
        ans = ans + O[O_count]
        O_count += 1

print(ans) 

Measured memory_bytes: 3060
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

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

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    ld ave1 = 0;
    for(int i = 0; i < n; i++){
        ave1 += a[i];
    }

    ld ave2 = ave1;

    ave1 = ceil(ave1 / n);
    ave2 = floor(ave2 / n);

    int total1 = 0;
    int total2 = 0;

    for(int i = 0; i < n; i++){
        total1 += abs(ave1 - a[i]) * abs(ave1 - a[i]);
        total2 += abs(ave2 - a[i]) * abs(ave2 - a[i]);
    }

    cout << min(total1, total2) << endl;

    
}

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

using namespace std;

int main() {
    int n,k,h,count = 0;
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200010
#define INF 1e9
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
inline int read()
{
	register char cc = getchar();register int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus; 
}
signed main()
{
	char cc = getchar();
	putchar(cc + 1);
	return 0;
}

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

int main() {
    int ans = 0;
    rep(i, 4) {
        char tmp;
        cin >> tmp;
        if (tmp == '+') ++ans;
        else --ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

st_list = []
for i in range(N):
  s, t = input().split()
  t = int(t)
  st_list.append([s, t])

X = input()

for i in range(N):
  if X == st_list[i][0]:
    j = i
    break

ans = 0
for i in range(j + 1, N):
  ans = ans + st_list[i][1]

print(ans)


Measured memory_bytes: 3060
N, M = map(int, input().split())
p_list = [1 for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
   a, b = map(int, input().split())
   if e_list[a - 1] <= e_list[b - 1]:
       p_list[a - 1] = 0
   if e_list[b - 1] <= e_list[a - 1]:
       p_list[b - 1] = 0
print(sum(p_list))

Measured memory_bytes: 20880
N = int(input())
data = [[i for i in input().split()] for j in range(N)]
for i in range(N):
    data[i].append(i+1)
for j in data:
    j[1] = int(j[1])
sort_data = sorted(data)
start = sort_data[0][0]
num = [sort_data[0][2]]
for i in range(1,N):
    if sort_data[i][0] == start:
        num.append(sort_data[i][2])
    else:
        start = sort_data[i][0]
        for j in range(len(num)):
            print(num[len(num)-1-j])
        num = [sort_data[i][2]]
for j in range(len(num)):
    print(num[len(num)-1-j])  

Measured memory_bytes: 3064
import java.util.*;
    public class Main{
    	public static void main(String[] args){
        	Scanner s  = new Scanner(System.in);
          	long a = s.nextInt();
          	long mod = (long)1e9 + 7;
    		long total = 10;
          	long totalwithout = 8;
          long totalw = 9;
          	for(int i = 0;i<a-1;i++) {
              total = (total*10)%mod;
          	totalwithout = (totalwithout*8)%mod;
              totalw = (totalw*9)%mod;
            }
          long ans1 = (2*totalw - totalwithout + mod)%mod;
          long ans  = (total - ans1 + mod)%mod;
          	System.out.println(ans);	
           }
    }

Measured memory_bytes: 35652
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
A=abs
c=sum(A(j-i)for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):print(c-A(j-i)-A(k-j)+A(k-i))

Measured memory_bytes: 13924
import sys

S = input()
T = input()

changes = {}
changes_reverse = {}
for i in range(len(T)):
    #print(changes)
    if S[i] != T[i]:
        if S[i] in changes:
            if changes[S[i]] != T[i]:
                print('No')
                sys.exit(0)
        if T[i] in changes_reverse:
            if changes_reverse[T[i]] != S[i]:
                print('No')
                sys.exit(0)

        changes[S[i]] = T[i]
        changes_reverse[T[i]] = S[i]
    else:
        changes[S[i]] = T[i]
        changes_reverse[T[i]] = S[i]
        

print('Yes')
# print(changes)


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        String s = in.next();
        if (s.equals("ABC")) {
            out.println("ARC");
        } else {
            out.println("ABC");
        }
    }
}


Measured memory_bytes: 32648
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1005];
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<(a[n-1]-a[0]);
}

Measured memory_bytes: 256
N = int(input())
sum = 0
sum_a = 0
sum_b = 0
sum_ab = 0
for i in range(N):
  s = input()
  sum += s.count('AB')
  if (s[-1] == 'A' and s[0] == 'B'):
    sum_ab += 1
  elif (s[0] == 'B'):
    sum_b += 1
  elif (s[-1] == 'A'):
    sum_a += 1
alpha = 0
if (sum_a == 0 and sum_b == 0 and sum_ab > 0):
  alpha = sum_ab - 1
else:
  alpha = min(sum_a, sum_b) + sum_ab
print(sum + alpha)

Measured memory_bytes: 3064
use warnings;
    use Data::Dumper;
    
    sub GetInputData{
    
        my @array_data;
    
        my $line = <STDIN>;
    
        chomp($line);
    
        while($line ne ""){
    
           push(@array_data,$line);
    
           $line = <STDIN>;
    
           chomp($line);
    
    }
    
        return @array_data;
    
    }
    
    sub GetSpaceInputData{
    
        my @array_temp=GetInputData();
    
        my @array_buf;
    
        for(@array_temp){
    
            #戻りは配列スペース区切りを分解
            # myを先頭につける必要あり
            my @array_work=split(" ",$_);

            # リファレンスを配列に代入
            push(@array_buf,\@array_work);
        }
    
        return @array_buf;
    
    }
    
    my @arr_result = GetSpaceInputData();

    my $ab = $arr_result[0][0];
    my $bc = $arr_result[0][1];

    print $ab*$bc / 2;
    
   
 

Measured memory_bytes: 1920
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    vi v(101,0);
    int a;
    while(cin>>a) {
        v[a]++;
    }
    vi v2 = v;
    sort(v);

    rep(i,v2.size()) {
        if(v2[i]==v[100]) P(i);
    }
    return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<int> graph[N+1];
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  ll ans = N; // rootはN
  int root = 1;
  vector<int> parent(N+1, -1);
  vector<int> order;
  stack<ll> stk;
  stk.push(root);
  while (!stk.empty()) {
    int cur = stk.top();
    ll p = parent[cur];
    if (p != -1) {
      if (p > cur) {
        ans += (p-cur) * cur;
      } else {
        ans += (cur-p) * (N+1-cur);
      }
    }
    stk.pop();
    order.push_back(cur);
    for (int next : graph[cur]) {
      if (next == parent[cur]) continue;
      parent[next] = cur;
      stk.push(next);
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 18624
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void outPut_YN(bool isYes) {
	if (isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

int main()
{
	long long n;

	cin >> n;

	vector<long long> a(n);

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

	sort(a.begin(), a.end());

	for (int i = 0; i < a.size() - 1; i++) {
		if (a[i] == a[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;  
#define ll   long long int

int main()
{
	ll n , l;
	cin>>n>>l;
	vector<string>v;
	for(ll i = 0;i<n;i++)
	{
		string s;
		cin>>s;
		v.push_back(s);
	}
	sort(v.begin(),v.end());
	for(ll i  = 0 ; i<n;i++)cout<<v[i];
}


Measured memory_bytes: 3564
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a.copy()
ans=sum(a)
for k in range(n):
  for i in range(n):b[i]=min(b[i],a[i-k])
  ans=min(sum(b)+x*k,ans)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){

	double pai,r;
	double men,syu;
//	pai=3.1415926538979;
	pai=M_PI;
	cin>>r;
	men=r*r*pai;
	syu=r*pai*2;
	cout<<fixed
		<<setprecision(6)
		<<men
		<<" "
	//	<<fixed
	//	<<setprecision(6)
		<<syu
		<<endl;

	return 0;
}

Measured memory_bytes: 1288
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

var n int
var p []float64
var dp [3100][3100]float64

func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	p = make([]float64, n)
	for i := 0; i < n; i++ {
		p[i] = nextFloat()
	}

	// fmt.Println(p)
	dp[0][0] = 1.0

	for i := 0; i < n; i++ {
		for j := 0; j <= i; j++ {
			dp[i+1][j+1] += dp[i][j] * p[i]
			dp[i+1][j] += dp[i][j] * (1.0 - p[i])
		}
	}

	res := 0.0
	for j := (n + 1) / 2; j <= n; j++ {
		res += dp[n][j]
	}
	fmt.Println(res)

}


Measured memory_bytes: 74368
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <set>
#include <queue>
#include <deque>
using namespace std;
int main(){
	int n;
	cin >> n;
	if(n>=30){
		printf("Yes");
	} 
	else printf("No");
}

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


using ll = long long int;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int i, n, v, min_v, k;
    k = 0;
    cin >> n;
    min_v = n + 1;
    for(i = 0; i < n; ++i)
    {
        cin >> v;
        if (v <= min_v)
        {
            k++;
        }
        min_v = min(min_v, v);
    }
    
    cout << k;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){

        int num;
        int counter=0;
        cin>>num;
        for(int i =1;i<10;i++){
                for(int j =0;j<10;j++){
                        if (i*j == num){

                                counter =1;
                                printf("Yes");
                                return 0;

                        }



                }

        }
        if (counter ==0){
                printf("No");
        }
        return 0;

}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        int inputCount = int.Parse(Reader.ReadLine());
        int[] items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        PriorityList listZ = new PriorityList();
        PriorityList listK = new PriorityList();

        for (int i = 0; i < inputCount; i++) {
            listZ.Push(items[i]);
            listK.Push(items[inputCount * 3 - i - 1]*-1);
        }

        long[] zenhan = new long[inputCount * 3];

		zenhan[inputCount-1] = listZ.GetTotal();
        for (int i = inputCount; i < inputCount * 2;i++) {
            listZ.Push(items[i]);
            listZ.Pop();
            zenhan[i] = listZ.GetTotal();
        }
        long max = long.MinValue;
        max = zenhan[inputCount * 2 - 1] + listK.GetTotal();

		for (int i = inputCount * 2 - 1; i >= inputCount; i--) {
            listK.Push(items[i]*-1);
            listK.Pop();
            max = Math.Max(max, zenhan[i-1] + listK.GetTotal());
        }
        Console.WriteLine(max);

    }


    private class PriorityList {
        public long GetTotal() {
            return this.Total;
        }
        private long Total = 0;
        private SortedDictionary<int, int> Items = new SortedDictionary<int, int>();
        public void Push(int num) {
            if(this.Items.ContainsKey(num)) {
                Items[num]++;
            } else {
                Items.Add(num, 1);
            }
            Total += num;
		}
        public int Pop() {
            int key = Items.First().Key;
            int num = key;
            Items[key]--;
            if(Items[key]<=0) {
                Items.Remove(key);
            }
            Total -= num;
            return num;
        }

        private int GetInsertIndex(int num, int min, int max) {
            if(this.Items.Count == 0) {
                return 0;
            }
            if(num <= this.Items[min]) {
                return min;
            }
            if(num>this.Items[max]) {
                return max + 1;
            }
            if(max-min<=1) {
                return max;
            }
            int mid = (max + min) / 2;
            if(this.Items[mid] == num) {
                return mid;
            }
            if(this.Items[mid]<num) {
                return GetInsertIndex(num, mid, max);
            } else {
                return GetInsertIndex(num, min, mid);
            }
        }

    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


3
8 2 2 7 4 6 5 3 8


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 50028
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        for (int i = 0; i != 7; i++) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            System.out.println(a - (b));;

        }
    }
}



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

using namespace std;

#define ll long long
#define int ll

typedef pair<int, int> pii;
typedef pair<ll, ll> pll; 

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;  
#define sysom(message, n) cout<<message<<n<<endl;
#define all(c) c.begin(), c.end() 
#define tr(container, it )\
for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(aint(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 
#define all(c) c.begin(), c.end() 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

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

int lcm(int fir, int sec){
    return (fir*sec)/(gcd(fir, sec));
}

const int MOD = 1988;
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';

// sort(arr, arr+n, greater<int>());

const int maxN = 1e6 + 12;
// const int maxVal = pow(2, 11);

signed main(){
	string n;
	int d;
	cin>>d>>n;
	if(n=="100"){
		n = "101";
	}
	string s = "00";
	for (int i = 0; i < d; ++i){
		n+=s;
	}
	int a = stol(n);
	cout<<a<<endl;
}


Measured memory_bytes: 256
// code written by kshitij_coder
#include<bits/stdc++.h>
using namespace std;
 
#define ll int64_t
#define pii pair<ll,ll>
#define psi pair<string,ll> 
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pb push_back
#define lim 100000
#define f(k) k.first
#define s(k) k.second
#define bcnt __builtin_popcount
#define endl "\n"
#define PI 3.1415926535

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const{ 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

ll power(ll a,ll b){ ll ans = 1; ll k = a;while(b > 0){ if(b & 1){ ans *= k; ans %= MOD; } k = (k*k)%MOD; b = b >> 1;} return ans;}

// ll ncr(ll n,ll r,ll*arr){
//     if(r==0) return 1;
//     ll res = 1;
//     return (arr[n]*(power(arr[n-r],MOD-2))%MOD*(power(arr[r],MOD-2))%MOD)%MOD;
// }

ll gcd(ll a,ll b){ if(a == 0) return b; if(b == 0) return a; return gcd(b,a%b); }
ll add_mod(ll a,ll b,ll m){return ((a%m) + (b%m))%m;}
ll sub_mod(ll a,ll b,ll m){return ((a%m) - (b%m) + m)%m;}
ll mul_mod(ll a,ll b,ll m){return ((a%m)*(b%m))%m;}
void print(double val,int k){ cout<<fixed<<setprecision(k)<<val<<endl;}
ll toint(string s) {stringstream ss; ss << s; ll x; ss >> x; return x;}

void solve(){
    int n;
    cin >> n;
    
    ll ans = 0;
    
    ll a = 0,b = 0,c = 0;
    
    for(int i = 1;i<=n;i++){
        int x,y,z;
        cin >> x >> y >> z;
        
        int d = x + max(b,c);
        int e = y + max(a,c);
        int f = z + max(a,b);
        a = d;b = e;c = f;
    }
    
    cout<<max(a,max(b,c))<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
    return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

class Node {
public:
    vector<int> neighbors;
    vector<int> weights;

    Node() {
        neighbors.clear();
        weights.clear();
    }

    Node(vector<int> neighbors, vector<int> weights) {
        int s = neighbors.size();
        this->neighbors.resize(s);
        this->weights.resize(s);
        for(int i = 0;i < s;i++) {
            this->neighbors[i] = neighbors[i];
            this->weights[i] = weights[i];
        }
    }
};

vector<int> Dijkstra(vector<Node> nodes, int start) {
    vector<int> cost;
    vector<bool> visited;
    cost.resize(nodes.size());
    visited.resize(nodes.size());

    fill(ALL(cost), IINF);
    fill(ALL(visited), false);

    cost[start] = 0;
    visited[start] = true;

    int size = nodes[start].neighbors.size();
    for(int i = 0;i < size;i++) {
        int v = nodes[start].neighbors[i];
        int w = nodes[start].weights[i];
        cost[v] = w;
    }
    for(int i = 0;i < nodes.size() - 2;i++) {
        int min_cost = IINF;
        int min_index;
        for(int j = 1;j <= nodes.size() - 1;j++) {
            if(!visited[j] && cost[j] < min_cost) {
                min_index = j;
                min_cost = cost[j];
            }
        }

        cost[min_index] = min_cost;
        visited[min_index] = true;
        int size = nodes[min_index].neighbors.size();
        for(int j = 0;j < size;j++) {
            int v = nodes[min_index].neighbors[j];
            int w = nodes[min_index].weights[j];
            cost[v] = min(cost[v], cost[min_index] + w);
        }
    }
    return cost;
}

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r;
    r.resize(R);
    REP(i, R)cin >> r[i];
    vector<Node> nodes;
    nodes.resize(N + 1);
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        nodes[a].neighbors.push_back(b);
        nodes[a].weights.push_back(c);
        nodes[b].neighbors.push_back(a);
        nodes[b].weights.push_back(c);
    }

    vector<Node> rg;
    rg.resize(R + 1);
    REP(i, R) {
        int index = distance(r.begin(), find(ALL(r), r[i]));
        vector<int> cost = Dijkstra(nodes, r[i]);
        REP(j, R) {
            if(i == j)continue;
            int ij = distance(r.begin(), find(ALL(r), r[j]));
            rg[index + 1].neighbors.push_back(ij + 1);
            rg[index + 1].weights.push_back(cost[r[j]]);
        }
    }

    vector<int> vr;
    vr.resize(R + 1);
    REP(i, R + 1) {
        vr[i] = i;
    }

    int mind = IINF;
    do {
        int d = 0;
        FOR(i, 1, R) {
            vector<int> cost = Dijkstra(rg, vr[i]);
            d += cost[vr[i + 1]];
        }
        mind = min(d, mind);
    }while(next_permutation(vr.begin() + 1, vr.end()));
    cout << mind << endl;
    return 0;
}


Measured memory_bytes: 1592
#include <stdio.h>

int main(){
  int i, n;
  int a, b, c;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &a, &b, &c);
    a *= a;
    b *= b;
    c *= c;

    if (a + b == c || b + c == a || c + a == b)
      puts("YES");
    else
      puts("NO");
  }

  return 0;
}

Measured memory_bytes: 580
#l==0 P
#l==n B+bg(l-1)+P+bg(l-1)+B
#f(n,x) returns the number of bans below x layers

#a[i] returns the size of level i burger -> a[0]=1
#b[i] returns the numbers of patties in level i burger -> b[0]=1

n,x=map(int,input().split())
a,p=[1]*(n+1),[1]*(n+1)
for i in range(n):
    a[i+1]=2*a[i]+3
    p[i+1]=2*p[i]+1

def f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=a[n-1]+1:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(n,x))

Measured memory_bytes: 3064
n1 = int(input())
n2 = tuple(map(int, input().split(" ")))

ans = True
max_value = n2[0]
max_index = 0
for i in range(n1):
    if max_value < n2[i]:
        max_value = n2[i]
        max_index = i
    if max_value - n2[i] >= 2:
        ans = False

if ans == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14408
use proconio::input;

fn main() {
    input! {
        mut takahashi_hp: i64,
        takahashi_atk: i64,
        mut aoki_hp: i64,
        aoki_atk: i64,
    }

    loop {
        aoki_hp -= takahashi_atk;
        if aoki_hp <= 0 {
            println!("Yes");
            return;
        }

        takahashi_hp -= aoki_atk;
        if takahashi_hp <= 0 {
            println!("No");
            return;
        }
    }
}


Measured memory_bytes: 2172