akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
	long long x,a,b,n,ans;
	
	void work()
	{
		scanf("%lld%lld",&n,&x);
		ans=n;
		a=min(x,n-x);
		b=max(x,n-x);
		while(a)
		{
		    ans+=(b/a)*2*a;
			if(!(b%a))
			{		
				ans-=a;
				break;
			}
			else
			{
				long long tmp=a;
				a=b%tmp;
				b=tmp;
			}
		}
		printf("%lld",ans);
	}
	
}

int main()
{
	zzc::work();
	return 0;
} 

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#define N 10
using namespace std;

int main(){
    double  n;
    while(cin >>n){
        double ans = n, b = n;
        for(int i = 2; i <= N; i++){
            double tmp;
            if(i % 2 == 0){
                tmp = (b * 2);
            } else{
                tmp = (b / 3);
            }
            ans += tmp;
            b = tmp;
        }
        printf("%f\n", ans);
    }
    return 0;
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  int a = 0;
  for (int i = 0; i + 1 < N; ++i) if (S[i] != S[i+1]) ++a;
  cout << N - 1 - max(a - K*2, 0) << endl;
}

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

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

using namespace std;

int main(){
	int h,n; scanf("%d%d",&h,&n);
	rep(i,n){
		int a; scanf("%d",&a);
		h-=a;
	}
	puts(h<=0?"Yes":"No");
	return 0;
}


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

#define ll long long
#define endl "\n"

void solve() {
  string a;
  cin >> a;
  if (a[a.size() - 1] != 's') {
    a = a + 's';
  } else {
    a = a + "es";
  }
  cout << a << endl;
}

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


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

using namespace std;

const long long MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < 60; i++) {
    long long k = (long long)1 << i;
    long long cnt = 0;
    for (int j = 0; j < n; j++) {
      if (k & a[j]) cnt++;
    }
    long long s = 1LL << i;
    s %= MOD;
    cnt = cnt * (n - cnt) % MOD;
    ans += s * cnt % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

    public class Program
    {
        public static void Main(string[] args)
        {
            new B().test();
        }
    }

	public class B
	{
		public void test()
		{
			// N人とK種類
			var inputNK = CommonRead.ReadIntL();

			//人数合計
			var execMan = 0;

			var setMan = new List<int>();
			var setOk = new List<List<int>>();

			var man = new HashSet<int>();

			//d数文繰り返す
			for (var repeatD = 0; repeatD < inputNK[1]; repeatD++)
			{
				// 種類
				setMan.Add(CommonRead.ReadInt());

				var temp = CommonRead.ReadIntL();
				// 配った人
				setOk.Add(temp);
				temp.ForEach(i => man.Add(i));
			}



			Console.WriteLine(inputNK[0] - man.Count());


		}
	}


static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}


Measured memory_bytes: 28748
#include <bits/stdc++.h>
using namespace std;
using uint = uint32_t;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * n; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)


struct Edge{ uint32_t to, id; };
typedef vector<vector<Edge>> Graph;
// ??????????????????
struct Bridge {
#define PB push_back
	typedef uint32_t T;
	typedef vector<T> vt;
	explicit Bridge(const Graph & g) : v2cmp(g.size()) {
		T n = g.size(), k = 0;
		vt ord(n, 0), low(n), stk;
		function<void(T, T, T)> f = [&](T c, T p, T id) {
			ord[c] = low[c] = ++k;
			stk.PB(c);
			for (auto e : g[c]) {
				if (!ord[e.to]) {
					f(e.to, c, e.id);
					low[c] = min(low[c], low[e.to]);
				} else if (e.id != id) {
					low[c] = min(low[c], ord[e.to]);
				}
			}
			if (low[c] == ord[c]) {
				if (p != n) bridge.PB({ id, min(c, p), max(c, p) });
				component.PB({});
				T v; do {
					v2cmp[v = stk.back()] = component.size() - 1;
					stk.pop_back();
					component.back().PB(v);
				} while (v != c);
			}
		};
		for (T i = 0; i < n; ++i) if (!ord[i]) f(i, n, T(-1));
	}
	// BridgeEdge : u < v ?????????????????????
	// v2cmp[v]   : ?????? v ????±?????????????????????????????????????????????????
	struct BridgeEdge { T id, u, v; };
	vt v2cmp;
	vector<BridgeEdge> bridge;
	vector<vt> component;
};

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	uint n, m; cin >> n >> m;
	Graph g(n);
	REP(i, m){
		uint s, t; cin >> s >> t;
		g[s].push_back({t, i});
		g[t].push_back({s, i});
	}
	Bridge brid(g);
	sort(ALL(brid.bridge), [](Bridge::BridgeEdge l, Bridge::BridgeEdge r) {
		if (l.u != r.u) return l.u < r.u;
		return l.v < r.v;
	});
	for (auto b : brid.bridge) {
		cout << b.u << " " << b.v << endl;
	}
}

Measured memory_bytes: 5696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    string s;
    ll k , ans = 0 , tmp = 0;
    cin >> s >> k;
    ll n = s.size();
    ll a = 1;
    for(int i = 0; i < n; i++) {
        if(s[i] == s[i + 1]){
            a++;
        }
        else{
          	if(a == 1) a--;
            ans += a / 2;
          	tmp++;
          	a = 1;
        }
    }
  	if(tmp == 1){
          cout << n * k / 2 << endl;
    }
    else if(s.front() == s.back()) {
      	ll M = 0, N = 0;
        for(int i = 0; i < n; i++) {
            M++;
            if(s[i] != s[i + 1]) break;
        }
        for(int i = n - 1; i >= 0; i--) {
            N++;
            if(s[i] != s[i - 1]) break;
        }
        cout<<ans * k - (k - 1) * ((M / 2) + (N / 2) - (M + N) / 2) << endl;;
    }
  	else{
          cout << ans * k<<endl;
      }
}


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

int main(){
    string s;
    cin>>s;
    int c=0;
    if(s[0] == 'A')
        c++;
    else{
        cout<<"WA";
        return 0;
    }
    int cc = 0;
    int pos = -1;
    for(int i=2;i<s.length()-1;i++){
        if(s[i] == 'C'){
            cc++;
            pos = i;
        }
    }
    if(cc == 1)
        c++;
    else{
        cout<<"WA";
        return 0;
    }
    for(int i=0;i<s.length();i++){
        if(i == 0 || i == pos)
            continue;
        if(s[i] >= 'A' && s[i] <= 'Z'){
            cout<<"WA";
            return 0;
        }
    }
    cout<<"AC";
    return 0;
}


Measured memory_bytes: 256
// AOJ ITP1_9_D Transformation
// 2018.4.30 bal4u

#include <stdio.h>

char str[1005];
char p[1005];

int main()
{
	int q, a, b;
	char op[10], *x, *y, c;
	
	scanf("%s%d", str, &q);
	while (q--) {
		scanf("%s%d%d", op, &a, &b);
		if (op[2] == 'i') {             // print
			b++, c = *(str+b), *(str+b) = 0, puts(str+a), *(str+b) = c;
		} else if (op[2] == 'v') {      // reverse
			x = str+a, y = str+b;
			while (x < y) {
				c = *x, *x = *y, *y = c;
				x++, y--;
			}
		} else {                        // replace
			scanf("%s", p);
			x = str+a, y = p;
			while (*y) *x++ = *y++;
		}
	}
	return 0;
}



Measured memory_bytes: 2044
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int inf=0x3f3f3f3f;
int ans=inf;
char s[205];int n,vis[205];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	rep(i,0,25){
		int tt=inf;
		rep(t,0,n){
			memset(vis,0,sizeof(vis));
			rep(j,1,n)
				if(s[j]-'a'==i){
				for(int k=max(1,j-t);k<=j;k++)vis[k]=1;
				}
			int op=1;
			rep(j,1,n-t)if(!vis[j])op=0;
			if(op){tt=t;break;}
		}
		ans=min(ans,tt);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#define MAX_N 110000
#define INF 1000000000
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
vector<ll> G[MAX_N];
ll ad[MAX_N],td[MAX_N];
void a_dfs(ll v,ll c){
  if(ad[v]<=c){
    return;
  }
  ad[v] = c++;
  for(auto nv:G[v]){
    a_dfs(nv,c);
  }
}
void t_dfs(ll v,ll c){
  if(td[v]<=c){
    return;
  }
  if(c>=ad[v]){
    return;
  }
  td[v] = c++;
  for(auto nv:G[v]){
    t_dfs(nv,c);
  }
}
signed main(){
  ll n,u,v,ans=0;
  cin >> n >> u >> v;
  u--;
  v--;
  ll a,b;
  fill(ad,ad+MAX_N,INF);
  fill(td,td+MAX_N,INF);
  for(int i=0;i<n-1;i++){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  a_dfs(v,0);
  t_dfs(u,0);
  bool can=false;
  for(auto nv:G[u]){
    if(nv!=v){
      can = true;
      break;
    }
  }
  if(!can){
    cout <<0<<endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    if(td[i]!=INF&&G[i].size()==1){
      ans = max(ans,ad[G[i][0]]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 10368
#include <iostream>

using namespace std;

int main() {
    int N;
    cin>>N;
    int arr[N];
    
    for(int i=0;i<N;i++){
        arr[i] = 0;
    }
    int ai;
    for(int i=1;i<N;i++){
        cin>>ai;
        arr[ai-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<arr[i]<<endl;
    }
}

Measured memory_bytes: 4412
n=int(input())
ls=[0]*n
for i in range(n):
    ls[i]=input()
numab=0
sA=0
sB=0
sBA=0
for i in range(n):
    sb=""
    for j in ls[i]:
        if sb=="A":
            if j=="B":
                numab+=1
        sb=j
    if ls[i][0]=="B":
        if ls[i][-1]=="A":
            sBA+=1
        else:
            sB+=1
    if ls[i][-1]=="A" and ls[i][0]!="B":
        sA+=1
ans=0
if sA!=0 and sB!=0:
    ans=sBA+1+min(sA-1,sB-1)
elif sA==0 and sB!=0:
    ans=sBA
elif sB==0 and sA!=0:
    ans=sBA
else:
    ans=sBA-1
if ans<0:
    ans=0
ans+=numab
#print(numab,sB,sA,sBA)
print(ans)


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

using namespace std;

#define MAX_P 234567
typedef long long ll;
const ll MOD = ((1e9) + 7);

ll fact[MAX_P]; 

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    ll d = a;
    if (b != 0) {
	d = extgcd(b, a%b, y, x);
	y -= (a / b) * x;
    } else {
	x = 1; y = 0;
    }
    return d;
}

ll mod_inverse(ll a, ll m)
{
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

ll mod_fact(ll n, ll p, ll &e)
{
    e = 0;
    if (n == 0) return 1LL;
    ll res = mod_fact(n/p, p, e);
    e += n/p;
    if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}

ll mod_comb(ll n, ll k, ll p)
{
    if (n < 0 || k < 0 || n < k) return 0LL;
    ll e1, e2, e3;
    ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
    if (e1 > e2 + e3) return 0LL;
    return a1 * mod_inverse(a2 * a3 % p,p) % p;
}

void make_table()
{
    fact[0] = 1;
    for (ll i = 1; i < MAX_P; i++) {
        fact[i] = fact[i-1] * i;
        fact[i] %= MOD;
    }
}

int main()
{
    make_table();
    
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll res = 0;
    for (int i = 0; i < H - A; i++) {
        res += mod_comb(i + B - 1, B - 1, MOD) *
               mod_comb((H - i) + (W - B) - 2, W - B - 1, MOD);
        res %= MOD;        
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <math.h>

using namespace std;

bool isPrime(int &num){
    if(num == 2){
        return true;
    }else if(num % 2 == 0){
        return false;
    }else{
        int numHalf = sqrt(num);
        for(int i=3 ; i <= numHalf;i += 2){
            if(num % i == 0){
                return false;
            }
        }
    }
    return true;
}

int main(){
    int N;
    int ans = 0;
    cin >> N;
    for(int i=0;i<N;i++){
        int val;
        cin >> val;
        if(isPrime(val)) ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
int n,k,m,i,j,K[105][105],he=0;
int main(){
	int ans[1005];
	scanf("%d%d",&n,&k);
	for(i=1;i<=k;i++){
		scanf("%d",&K[i][0]);
		for(j=1;j<=K[i][0];j++){
			scanf("%d",&K[i][j]);
			ans[K[i][j]]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(ans[i]!=1) he++;
	}
	printf("%d",he);
	return 0; 
}

Measured memory_bytes: 1768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll =  long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }


	// 標準入出力
	struct inp {
		size_t sz;
		inp(size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one
}

int main() {

	ll a, b, c;
	cin >> a >> b >> c;

	ll lhs = 4 * a * b;
	ll rhs = c - a - b;
	if (rhs < 0) {
		Cout("No");
		return 0;
	}
	rhs *= rhs;
	if (lhs < rhs) {
		Cout("Yes");
	}
	else Cout("No");

	return 0;
}

Measured memory_bytes: 256
N = int(input())
*p, = map(int, input().split())
ans = 0
for i in range(1, N-1):
    if p[i-1] >= p[i] and p[i] >= p[i+1]:
        ans += 1
    elif p[i+1] >= p[i] and p[i] >= p[i-1]:
        ans += 1

print(ans)

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	LL N, M;
	cin >> N >> M;
	if(N==1 and M==1) cout << 1 << endl;
	else if(N==1) cout << M-2 << endl;
	else if(M==1) cout << N-2 << endl;
	else cout << (N-2)*(M-2) << endl;

	return 0;
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int n;
  cin >> n;
  float tmp = ceil(n / 1000.0);

  //   cout << tmp << endl;
  cout << tmp * 1000 - n << endl;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;

    ll co = 0;
    ll cx = 0;

    for (int i = 0; i < s.size(); i++) {
      if (s.at(i) == 'o') co++;
      else cx++;
    }

    if (co + cx <= 7) {
        cout << "YES" << endl;
        exit(EXIT_SUCCESS);
    }

    if ((15 - cx - co) + co >= 8) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,x,ans;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x<=k/2)	ans+=x*2;
        else	ans+=(k-x)*2;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l_ = [int(input()) for _ in range(N)]

def make_length(cur,A_,B_,C_,cost):
  if cur == N:
    if min(A_,B_,C_) > 0:
      return abs(A-A_)+abs(B-B_)+abs(C-C_) + cost
    else:
      return 1000000
  a_use = make_length(cur+1,A_+l_[cur],B_,C_,cost+10)
  b_use = make_length(cur+1,A_,B_+l_[cur],C_,cost+10)
  c_use = make_length(cur+1,A_,B_,C_+l_[cur],cost+10)
  not_use = make_length(cur+1,A_,B_,C_,cost)
  return min(a_use,b_use,c_use,not_use)

print(make_length(0,0,0,0,-30))



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
string s;
int k;
set<string> strs;
int main(){
	cin >> s;
	cin >> k;

	for(int i = 0;i < s.size();i++){
		string tmp  = "";
		for(int j = 0;j < 5;j++){
			if(i + j >= s.size())continue;
			tmp += s[i+j];
			strs.insert(tmp);
		}
	}

	set<string>::iterator it = strs.begin();
	k-=1;
	while(k--)it++;
	cout << *it << endl;
	return 0;
					 
}

Measured memory_bytes: 1664
N, M = map(int,raw_input().split())
gra = [set() for n in range(N)]
ins = [0] * N

start = set(range(N))
for m in range(M) :
  x, y = map(int,raw_input().split())
  gra[x-1].add(y-1)
  ins[y-1] += 1
  start.discard(y-1)

mem = [None for n in range(N)]
q = list(start)
for i in q : mem[i] = 0

longest = 0
while q :
  cur = q.pop(0)
  for nxt in gra[cur] :
    ins[nxt] -= 1
    if ins[nxt] == 0 :
      mem[nxt] = mem[cur] + 1
      longest = max(longest, mem[nxt])
      q.append(nxt)

print longest

Measured memory_bytes: 66904
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;

  ll n2 = 2 * n;
  ll midl = (n2 - 2) / 2 + 2;
  ll cnt = 0;
  ll tt;
  REP(i, 1, n + 1) {
    ll s = (k - i % k) % k;
    if (s * 2 % k == 0) {
      tt = (n - s) / k + (s % k == 0 ? 0 : 1);
      cnt += tt * tt;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
from itertools import *
N,Y = map(int,input().split())
if 10000*N < Y:
  print(-1,-1,-1)
  exit()
for i in range(N):
  for j in range(N-i):
    k = N-i-j
    for xyz in permutations([i,j,k],3):
      x,y,z = xyz
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z)
        exit()
print(-1,-1,-1)

Measured memory_bytes: 40940
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    d, x = MII()
    aa = [II() for _ in range(n)]
    cnt = x
    for a in aa:
        cnt += -(-d//a)
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)==1)\
    {
        int x,res=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            while(x%2==0)
            {
                x/=2;
                res++;
            }
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 256
S=input()
ans = [0] * len(S)
last_R=[0] * len(S)
tmp = 0
for i in range(len(S)):
    if S[i] == "R":
        tmp = i
    last_R[i] = tmp
first_L=[0] * len(S)
tmp = 0
for i in reversed(range(len(S))):
    if S[i] == "L":
        tmp = i
    first_L[i] = tmp
for i in range(len(S)):
    if S[i] == "L":
        R_index = last_R[i]
        if (i - R_index) % 2 == 1:
            ans[R_index+1] += 1
        else:
            ans[R_index] += 1
    if S[i] == "R":
        L_index = first_L[i]
        if (L_index - i) %2 == 1:
            ans[L_index-1] += 1
        else:
            ans[L_index] += 1
ans = map(str, ans)
print(" ".join(ans))

Measured memory_bytes: 53872
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
 double a;
  cin>>a;
  int b=floor(sqrt(a))*floor(sqrt(a));
out(b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char c;cin>>c;
    cout<<char(c+1)<<endl;
}



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

int main() {
    int N, W; cin >> N >> W;
    ll w[N], v[N];
    ll maxv = 0;
    for (int i=0; i<N; i++){
        cin >> w[i] >> v[i];
        maxv = max(maxv, v[i]);
    }
    maxv = maxv*N;
    ll INF = 1E12;
    ll dp[N+1][maxv+1];
    for (int i=0; i<=N; i++){
        dp[i][0] = 0;
        for (int j=1; j<=maxv; j++){
            dp[i][j] = INF;
        }
    }
    for (int i=0; i<N; i++){
        for (int j=0; j<=maxv; j++){
            if (j+v[i] > maxv){
                continue;
            }
            else{
                dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j] + w[i]);
            }
        }
        for (int j=0; j<=maxv; j++){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for (int i=0; i<=maxv; i++){
        if (dp[N][i] <= W){
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 79104
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def io_generator():
	return input()

def iil(a_io):
	return map(int, a_io().split())


#+++++++++++++++++++


def main(io):
	a,b,x=iil(io)
	
	for i in range(10):
		x=a*x-b
		print(x)
	
	return

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	ret = main(io)
	if ret is not None:
		print(ret)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
#mitsui f
import sys
import math
import collections
#sys.setrecursionlimit(100000)

#n=int(input())

tmp = input().split()
t1,t2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
a1,a2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
b1,b2 = list(map(lambda a: int(a), tmp))

if(a1*t1+a2*t2==b1*t1+b2*t2):
	print("infinity")
	sys.exit()
diff=(a1*t1+a2*t2)-(b1*t1+b2*t2)


if(diff>0):
	c1=a1-b1
	c2=a2-b2
else:
	c1=b1-a1
	c2=b2-a2

if(c1>0):
	print("0")
	sys.exit()

diff=c1*t1+c2*t2
pitch=c1*t1*-1

ans=pitch//diff*2+1
if(pitch%diff==0):
	ans-=1
print(ans)


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

#define int long long
#define ld long double
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

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

	int x,y;
	cin>>x>>y;
	if (x*4<y){
		cout<<"No"<<endl;
		return 0;
	}
	if (x*2>y){
		cout<<"No"<<endl;
		return 0;
	}
	for (int i=0; i<100; i++){
		for (int j=0; j<100; j++){
			if (i*2+j*4==y){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 3000;
const int mod = 1e9+7;
const int maxf = 2e5+5;

int h, w, n;
ll f[maxf];

int fpow(ll a, ll b){
	a%=mod;
	ll res = 1;
	while (b>0){
		if (b&1) res = res*a%mod;
		a = a*a%mod;
		b>>=1;
	}
	return ll(res%mod);
}
void facts(){
	f[0] = 1;
	forr(i, 1, maxf) f[i] = ll((i*f[i-1])%mod);
}

int mul(ll a, ll b){return ll((a*b)%mod);}
int sub(int a, int b){return rmod((a-b), mod);}
int add(int a, int b){return (a+b)%mod;}

int inv(int n){ return fpow(n, mod-2);}
int comb(int n, int k){
	if (k == 0 or n == k or n == 0) return 1;
	int ans = f[n] * inv(f[k])%mod * inv(f[n-k])%mod;
	return ans%mod;
}
inline bool topleft(pii &a, pii &b){
	if (a.first<=b.first and a.second<=b.second) return true;
	else return false;
}
int fx(int n, int m){
	return comb(m+n-2, n-1); // 6, 4
}
/*
FORMULA:
Formas de hacer (0, 0) -> (n, m)
avanzando solo hacia la derecha o hacia abajo
binomial de((m+n-2), (n-1)):
	(m+n-2)!/((n-1)!(m-1))!
*/
int dp[maxn+1];
vector<pii> rc;


/* KSAHDFKJAHSDKFJH
int solve(){
	int dp[n+1][n+1];
	forn(i, n+1){
		forn(j, i){
			dp[i][j] = fx(rc[i].first, rc[i].second);
			if(topleft(rc[j], rc[i])){
				int px = rc[i].first - rc[j].first;
				int py = rc[i].second - rc[j].second;
				dp[i][j] = rmod(sub(dp[i][j], mul(dp[i-1][j], fx(px+1, py+1))), mod);
			}
		}
	}
	return dp[n][n];
}
*/
int solver(){
	forn(i, n+1){
		int aux = fx(rc[i].first, rc[i].second);
		forn(j, i) {
			if (topleft(rc[j], rc[i])){
				int px = rc[i].first - rc[j].first;
				int py = rc[i].second - rc[j].second;
				/*
					si en el punto j terminaban k caminos,
					desde j hasta i habrán k*fx(i.x-j.x, i.y-j.y) caminos
					pero todos estos caminos pasan por al menos uno de los
					puntos prohibidos P con indice menor a i
				*/
				aux = sub(aux, mul(dp[j], fx(px+1, py+1)));
			}
		}
		dp[i] = aux;
	}
	return dp[n];
}


bool comp(pii a, pii b){
	if (a.first == b.first) return a.second<b.second;
	return a.first<b.first;
}
int main() {
	facts();
	memset(dp, -1, sizeof(dp));
	scanf("%d%d%d", &h, &w, &n);
	rc.resize(n+1);
	int auxa, auxb;
	forn(i, n){
		scanf("%d%d", &auxa, &auxb);
		rc[i] = {auxa, auxb};
	}
	rc[n] = {h, w};
	sort(rc.begin(), rc.end(), comp);
	//for(auto&p: rc) cout << p.first << " " <<p.second << "\n";
	cout << solver();
	//cout << fx(3,5);
	//printf("%d %d %d\n", fx(3, 5), fx(2, 3), fx(3, 1));
	//printf("%d\n", fx(3,5)-fx(3, 3)-fx(1,5));
	return 0;
}

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

int main(){
  int A,B;
  cin>>A;
  cin>>B;
  int a,b,c,d;
  a=A+B;
  b=A-B;
  c=A*B;
  d=a;
  if(b>a){
    d=b;
    if(c>b){
      d=c;
    }
  }else if(c>a){
    d=c;
  }
  cout<<d;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct Point{
  double x,y;
};

void koch(int n, struct Point a, struct Point b){
  if(n == 0)
    return;
  struct Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1, t, b);
}

int main(){
  struct Point a,b;
  int n;

  scanf("%d",&n);
  if(n < 0 || n > 6)
    exit(1);

  a.x = 0.0;
  a.y = 0.0;
  b.x = 100.0;
  b.y = 0.0;

  printf("%.8f %.8f\n",a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n",b.x, b.y);

  return 0;
}


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

int64_t k;

void solve() {
    queue<int64_t> q;
    for (int64_t i = 1; i <= 9; i++) {
        q.push(i);
    }

    int64_t ans;
    for (int64_t i = 1; i <= k; i++) {
        ans = q.front();
        q.pop();
        if (ans % 10 != 0) {
            q.push(10 * ans + (ans % 10) - 1);
        }
        q.push(10 * ans + (ans % 10));
        if (ans % 10 != 9) {
            q.push(10 * ans + (ans % 10) + 1);
        }
    }

    cout << ans << endl;
}

int main() {
    cin >> k;
    solve();
}

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

using namespace std;

int dp[1001][1001];

int main()
{
	string t, b;
	cin >> t >> b;
	dp[0][0] = 1;
	for (int i = 0; i < t.size(); i++)
		for (int j = 0; j < b.size() + 1; j++)
		{
			if (t[i] == b[j])
				dp[i + 1][j + 1] = dp[i][j];
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= 1000000007;
		}
	cout << dp[t.size()][b.size()] % 1000000007 << endl;

	return 0;
}



Measured memory_bytes: 7104
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const db P = asin(sqrt(2.0)/2)*4;
int main(){
	int n;cin >> n;

	cout << n * 2 * P << endl;
	return 0;
}

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

bool isPalindrome(string s){
    int n = s.length();
    for(int i = 0; i <= n/2; i++){
        if(s[i] != s[n-1-i])    return false;
    }
    return true;
}

int main(){
    string s;
    cin >> s;

    string p = "";
    for(char x : s) if(x != 'x')    p += x;

    if(!isPalindrome(p)){
        cout << -1 << endl;
        return 0;
    }

    int len = p.length();
    int ans = 0, l = 0, r = s.length()-1;
    for(int i = 0; i <= len/2; i++){
        int a = 0, b = 0;
        while(s[l] != p[i]) l++, a++;
        while(s[r] != p[len-1-i])   r--, b++;
        ans += abs(b-a);
        l++, r--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    while(q--){
        int k; cin >> k;
        ll d = 0, m = 0, dm = 0, dmc = 0;
        rep(i,n){
            if(i >= k){
                if(s[i-k] == 'D'){ d--; dm -= m; }
                else if(s[i-k] == 'M') m--;
            }
            if(s[i] == 'D') d++;
            else if(s[i] == 'M'){ dm += d; m++; }
            else if(s[i] == 'C') dmc += dm;
        }
        cout << dmc << endl;
    }
    return 0;
}

Measured memory_bytes: 5316
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
  
N = int(input())
nums = make_divisors(N)
if len(nums) %2 == 1:
  print((nums[-1]-1)*2)
  exit()
else:
  print(nums[-1]-1+nums[-2]-1)

Measured memory_bytes: 39152
import java.util.Scanner;
public class Main {

	static long mod = 1_000_000_007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt();
		int a[] = new int[N + 1];
		for ( int i = 1; i <= N; i++ ) {
			a[i] = in.nextInt();
		}
		in.close();

		long dp[][] = new long[N + 1][K + 1];
		dp[0][0] = 1;

		for ( int n = 1; n <= N; n++ ) {
			for ( int k = 0; k <= K; k++ ) {
				if ( k == 0 ) {
					dp[n][k] = 1;

				} else {
					dp[n][k] = (dp[n][k - 1] + dp[n - 1][k]) % mod;

				}

				if ( a[n] < k ) {
					dp[n][k] = (dp[n][k - 1] + dp[n - 1][k] - dp[n - 1][k - a[n] - 1]) % mod;

				}

				if ( dp[n][k] < 0 ) dp[n][k] += mod;
			}
		}
		// System.out.println((dp[N][K] + mod)% mod);
		// long ans = dp[N][K] % mod;
		System.out.println(dp[N][K] % mod);
	}
}


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

int main(void){
    long long N;cin>>N;
    vector<string>S(N);for(long long i=0;i<N;i++)cin>>S[i];
    sort(S.begin(),S.end());
    long long times=1;
    long long tmp=1;
    for(long long i=1;i<N;i++){
        if(S[i]==S[i-1]){
            tmp++;
        }
        else{
            times=max(times,tmp);
            tmp=1;
        }
    }
    times=max(times,tmp);
    tmp=1;
    for(long long i=0;i<N;i++){
        if(i>0){
            if(S[i]==S[i-1]){
            tmp++;
            }
            else{
                tmp=1;
            }
        }
        if(tmp==times){
            cout<<S[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 9600
import math
a, b, h, m = map(int, input().split())
t_a = 0.5*(h*60+m)
t_b = 6*m
t = (t_a - t_b)
if t > 180:
    t = 360 - t
c = math.cos(t*2*math.pi/360.0)
print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * c), end="")


Measured memory_bytes: 9440
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			int[] map = new int[n];
			int[] th = new int[m];
			for(int i=0;i<n;i++) map[i] = sc.nextInt();
			for(int i=0;i<m;i++) th[i] = sc.nextInt();

			int now = 0;
			int idx = 0;
			int ans = 0;
			while(now < n - 1){
				ans++;
				now += th[idx++];
				if(now >= n - 1) break;
				now += map[now];
				if(now < 0) now = 0;
			}

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

Measured memory_bytes: 12000
/*
	################
	# Avi Kasliwal #
	# Noob Coder:( #
	################
*/

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

#define int long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)


#define deb(x) cout << "#x " << x << "\n"


#define newline cout << "\n"
#define yes cout << "Yes" << "\n"
#define no cout << "No" << "\n"
#define Yes cout << "YES" << "\n"
#define No cout << "NO" << "\n"


#define fixDeci(num, places) std::cout << std::fixed << std::setprecision(places) << num << '\n'
#define setBits(x) __builtin_popcount(x)
#define zerobits(x) __builtint_ctzll(x)
#define MOD 1000000007

#define rep(i, s, e) for (i = s; i < e; i++)
#define repr(i, s, e) for (i = s; i >= e; i--)

// GCD Function
int GCD(int a, int b) {
	if (b == 0) {
		return a;
	} else {
		return GCD(b, a % b);
	}
}

// LCM Function
int LCM(int a, int b) {
	int gcd = GCD(a, b);
	return (max(a, b) / gcd)*(min(a, b));
}

/*int p[100000001];
void Sieve() {
	p[0] = p[1] = 0;
	p[2] = 1;
	for (int i = 4; i < 100000000; i += 2) {
		p[i] = 0;
	}
	for (int i = 3; i * i < 100000000; i++) {
		if (p[i] == 1) {
			for (int j = i*i; j < 100000000; j += i) {
				p[j] = 0;
			}
		}
	}
}*/

int32_t main () {

	IOS; int i, j;

	/*######## Code Here ##########*/
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	
	int t; t = 1;
	while (t--) {
		int n; cin >> n;
	    int abc[n][3];
	    
	    for (int i = 0; i < n; i++) {
	        for (int j = 0; j < 3; j++) {
	            cin >> abc[i][j];
	        }
	    }
	    
	    
	    int H[n][3];
	    H[0][0] = abc[0][0];
	    H[0][1] = abc[0][1];
	    H[0][2] = abc[0][2];
	    
	    for (int row = 1; row < n; row++) {
	        for (int col = 0; col < 3; col++) {
	            int m_happ = INT_MIN;
	            for (int prev_day = 0; prev_day < 3; prev_day++) {
	                if (col == prev_day) {
	                    continue;
	                } else {
	                    int hap = abc[row][col] + H[row - 1][prev_day];
	                    if (hap > m_happ) {
	                        m_happ = hap;
	                    }
	                }
	            }
	            H[row][col] = m_happ;
	        } 
	    } 
	    
	    int ans = INT_MIN;
	    
	    for (int i = 0; i < 3; i++) {
	        if (H[n - 1][i] > ans) {
	            ans = H[n - 1][i];
	        }
	    }
	    
	    cout << ans << "\n";
	}

	return 0;
}

/*Timus : 294930IX */

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    ll N, T;
    cin >> N >> T;
    
    ll ans = 0LL;
    ll old_t = 0LL;
    rep(i, N) {
        ll t; cin >> t;
        ans += min(t - old_t, T);
        old_t = t;
    } 
    ans += T;

    cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;
 
int main(){
    int ans=0;
    string s;
    while(cin>>s){
        rep(i,0,s.size()){
            if(s[i]-'0'>=0 && s[i]-'0'<10){
                rep(j,i,s.size()){
                    if(s[j]-'0'<0 || s[j]-'0'>=10 || j == s.size() - 1){
                    	if(j == s.size() - 1) j++;
                        ans+=atoi(s.substr(i,j-i).c_str());
                        //cout<<atoi(s.substr(i,j-i).c_str())<<endl;
                        i = j ;
                        break;
                    }
                }
            }
        }
    }
    o(ans);
}

Measured memory_bytes: 1196
s = input()
if (int(s[:2])<=12)&(int(s[:2])>=1):
  if (int(s[2:])<=12)&(int(s[2:])>=1):
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif (int(s[2:])<=12)&(int(s[2:])>=1):
    print("YYMM")
else:
  print("NA")

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

int main() {
  string ans;
  int Q;
  cin >> ans >> Q;
  bool rev = false;
  int L = ans.length();

  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) rev ^= 1;

    if (t == 2) {
      if (ans.length() == L && rev == 1) {
        reverse(ans.begin(), ans.end());
        rev = 0;
      }
      int f;
      string c;
      cin >> f >> c;

      if (f == 1) {
        if (rev == false)
          ans.insert(0, c);
        else
          ans += c;
      } else {
        if (rev == false)
          ans += c;
        else
          ans.insert(0, c);
      }
    }
  }

  if (ans.length() == L && rev == 1) {
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
  }

  if (!rev) {
    cout << ans << endl;
  } else if (rev == 1) {
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }

  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

    bool is_union(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        return ra == rb;
    }
};

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

    UnionFind uf(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.connect(x, y);
    }

    set<int> roots;
    rep(i, n) roots.insert(uf.root(i));
    cout << roots.size() << endl;


}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main()
{
    ll r;
    double pi = 3.14159265358979323846;
    cin >> r;
    double ans = 2.0 * pi * r ;
    cout << ans << "\n";
 
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long LL;
const int64_t INF=1e18+1;
const int mod = 1000000007;

int T;
map<LL,LL>s;
LL N,a,b,c,d;
LL dfs(LL n){
  	if(n==0)return s[0]=0;
    if(n==1)return s[1]=d;
	if(s[n]>0)return s[n];
	if(1e18/n<=d){s[n]=1e18;}
    else{s[n]=n*d;}
	s[n]=min(s[n],dfs(n/2)+a+(n%2)*d);
	s[n]=min(s[n],dfs(n/3)+b+(n%3)*d);
	s[n]=min(s[n],dfs(n/5)+c+(n%5)*d);
	s[n]=min(s[n],dfs((n+1)/2)+a+(2-n%2)*d);
	s[n]=min(s[n],dfs((n+2)/3)+b+(3-n%3)*d);
	s[n]=min(s[n],dfs((n+4)/5)+c+(5-n%5)*d);
	return s[n];
}

int main(){
  cin>>T;
  for(int i=0;i<T;i++){
    cin>>N>>a>>b>>c>>d;
    s.clear();
    cout<<dfs(N)<<endl;
  }
  return 0;                       
}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  auto b = a;
  sort(ALL(a));
  int minv = a[n/2-1];
  int maxv = a[n/2];
  rep(i,n) {
    if (b[i] < maxv) cout << maxv << endl;
    else cout << minv << endl;
  }
}


Measured memory_bytes: 3712
using System;

namespace ConsoleApp1
{
    class Program
    {
  
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int cnt = 0;
            int ans = 0;
            for (int i = 1; i <= N; i = i + 2)
            {
                for (int j = 1; j <= i; j = j + 2)
                    if (i % j == 0)
                        cnt++;

                if (cnt == 8)
                    ans++;
                cnt = 0;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092