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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll n , k;
int sz[maxn];
ll num [maxn];

int main(){
    migmig
    cin >> n >> k;
    for(int i = 1 ; i <= k ; i ++){
        num[i] = pw(k/i , n);
    }
    ll ans = 0;
    for(ll i = k ; i >= 1 ; i --){
        for(int j = i+i ; j <= k ; j += i){
            num[i] = (num[i] - num[j] + 100LL*mod)%mod;
        }
        ans = (ans + (num[i]*i)%mod )%mod;
    }
    cout << ans;



    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.
//kuxtal jach uts chuchul u u páajtal máak jach táaj meyajilo'ob le castigadas tumen ch'aik descansos.


Measured memory_bytes: 4440
#include <iostream>
#include <stdio.h>
#include <string>


int main()
{
    std::string s,p;
    std::cin>>s>>p;
    s=s+s;

    if(s.find(p)==-1)
    {
        std::cout << "No" << std::endl;
    }
    else
    { 
        std::cout << "Yes" << std::endl;
    }
    
    return 0;
}




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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
double p[3252];
double dp[3252][3252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%lf",p+i);
  dp[0][0] = 1.0;
  REP(i,n)REP(j,i+1){
    dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
    dp[i+1][j+1] += dp[i][j] * p[i];
  }
  double ans = 0.0;
  REP(i,n+1){
    if(i > n-i)ans += dp[n][i];
  }
  printf("%.9f\n",ans);
  return 0;
}


Measured memory_bytes: 76416
#include <set>
#include <iostream>
using namespace std;
int main() {
	bool have[26];
	string s;
	cin >> s;
	for (int i = 0; i < 26; i++) have[i] = false;
	for (char i : s) have[i - 'a'] = true;
	for (int i = 0; i < 26; i++) if (!have[i]) {
		cout << char('a' + i) << endl;
		return 0;
	}
	cout << "None" << endl;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 20437;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;


int main ()
{
  prep();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 1;
  int r = n;
  int lastgood = 0;
  while (l <= r){
      int mid = (l+r)/2;
      map<string, vector<int> > mp;
      set<string> st;
      for (int i=0; i<n-mid+1; i++){
          string curs = s.substr(i, mid);
          mp[curs].push_back(i);
          st.insert(curs);
      }
      bool good = false;
      for (string ss : st){
          vector<int> v = mp.find(ss)->second;
          int frst = v[0];
          int last = v[(int)v.size()-1];
         
          if (last-frst >= mid){
              good = true;
              break;
          }
      }
      if (good){
     
          lastgood = mid;
          l = mid+1;
      }else{
          r = mid-1;
      }
  }
  cout << lastgood;
  return 0; 
}
  

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

int main() {
	int n; //何枚ずつのカードを使うか
	int a_score; //Aの得点
	int b_score; //Bの得点
	int a, b;
	int ab_score[200]; //AとBの得点を入れておく箱
	int count = 0;
	while (true) {
		a_score=0;//初期化
		b_score=0;//初期化
		cin >> n;
		if(n==0)break;
		for (int i = 0; i < n; i++) {
			cin >> a >> b; //a,bに入力させる
			if (a > b)
				a_score += a + b;
			else if (b > a)
				b_score += a + b;
			else {
				a_score += a;
				b_score += b;
			}
		}
		ab_score[count] = a_score;
		ab_score[count + 1] = b_score;
		count += 2;
	}
	for (int i = 0; i < count - 1; i+=2) {
		cout << ab_score[i] << " " << ab_score[i + 1] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string s;
    cin >> s;
    int a;
    int n = s.size();
    rep(i, n) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    int z;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int i, s;
    scanf("%d", &s);

    int h = 0, m = 0;
    for (i = 60; s >= 60; i += 60) {
        s -= 60;
        m++;
    }

    for (i = 60; m >= 60; i += 60) {
        m -= 60;
        h++;
    }

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  string s; cin>>s;
  for(auto& c: s) {
    if(c == '1') {
      c = '9';
    } else if(c == '9') {
      c = '1';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
import Data.Char
import Text.Printf

main :: IO ()
main = getLine >>= solve . fmap (\x -> ord x - ord '0')

solve :: [Int] -> IO () 
solve [a, b, c, d] = format $ head [(x, y, z) | (x, op1) <- [('+', (+)), ('-', (-))], (y, op2) <- [('+', (+)), ('-', (-))], (z, op3) <- [('+', (+)), ('-', (-))], (op3 (op2 (op1 a b) c) d) == 7]
    where
        format :: (Char, Char, Char) -> IO ()
        format (x, y, z) = printf "%d%c%d%c%d%c%d=7\n" a x b y c z d

Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);

signed main(){
    int n, t;
    cin >> n>>t;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n);
    b[0]=a[0];
    FOR(i,1,n) b[i] = min(b[i-1],a[i]);
    int mi = 0;
    rep(i,n) {
        mi = max(a[i]-b[i],mi);
    }
    set<int> s;
    rep(i,n) {
        if(a[i]-b[i]==mi) {
            s.insert(b[i]);
        }
    }
    cout << s.size() << endl;


    return 0;
}



Measured memory_bytes: 6980
from collections import deque
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

plus = deque()
minus = deque()
for i in range(N):
    plus.append(i+A[i])
    minus.append(-A[i]+i)
p = Counter(plus)
m = Counter(minus)
key = p.keys()

cnt = 0
for k in list(key):
    # print(p[k])
    cnt += p[k]*m[k]

# print(p,m)
print(cnt)

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

using namespace std;

using ll = long long;

ll n, x, d;

ll minv(ll i) {
    return (i - 1) * i / 2;
}

ll maxv(ll i) {
    return (2 * n - 1 - i) * i / 2;
}

ll hoge(ll L1, ll R1, ll L2, ll R2) {
    return R1 - L1 + 1 - max(min(R1, R2) - max(L1, L2) + 1, 0LL);
}

ll calcP() {
    ll g = __gcd(x, d);
    ll c = d / g;
    ll e = x * c / d;
    ll ans = 0;
    for (ll i = n; i >= 0; --i) {
        ll lim;
        if (i > n - c) lim = maxv(i) + 1;
        else lim = min(minv(i + c) + e, maxv(i) + 1);
        ans += max(lim - minv(i), 0LL);
    }
    return ans;
}

ll calcNP() {
    if (d == 0) return n + 1;
    ll g = __gcd(x, -d);
    ll c = -d / g;
    ll e = x * c / -d;
    ll ans = 0;
    for (ll i = n; i >= 0; --i) {
        if (i > n - c) ans += maxv(i) - minv(i) + 1;
        else ans += hoge(minv(i), maxv(i), minv(i + c) - e, maxv(i + c) - e);
    }
    return ans;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
    cin >> n >> x >> d;
    if (x == 0) {
        if (d == 0) cout << 1 << endl;
        else cout << n * (n - 1) / 2 + 1 << endl;
        return 0;
    }
    if (x < 0) {
        x = -x;
        d = -d;
    }
    cout << (d > 0 ? calcP() : calcNP())  << "\n";
	return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    for(int i = 0; i + t.size() - 1 < s.size(); i++){
        int cnt = 0;
        for(int j = 0; j < t.size(); j++){
            if(s[i+j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; ll a, b; cin >> n >> a >> b;
	vector<ll> x(n);
	for( auto &k : x ) cin >> k;
	ll sum = 0;
	for( int i = 0; i < n-1; ++i ){
		ll d = x[i+1]-x[i];
		sum += min(a*d, b);
	}
	cout << sum << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<string>
#include<stack>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    int N,i,t,a[100005],num=0;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&a[i]);
    for(i=0;i<N-1;i++)
    {
        if(a[i]==i+1)
        {
            t=a[i];
            a[i]=a[i+1];
            a[i+1]=t;
            num++;
        }
    }
    if(a[N-1]==N)
    {
        t=a[N-1];
        a[N-1]=a[N-2];
        a[N-2]=t;
        num++;
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  int mx = 0, others = 0;
  rep(i, T) {
    int a;
    cin >> a;
    chmax(mx, a);
    others += a;
  }
  others -= mx;
  cout << max(mx-others-1, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int max = 1, X, tmp;
	cin >> X;
	if (X == 1) {
		cout << X << endl;
		return 0;
	}
	else {
		for (int i = 2; i <= 100; i++) {
			for (int j = 2; j <= 1000; j++) {
				tmp = pow(i, j);
				if (tmp > X)break;
				else if (max < tmp)max = tmp;
			}
		}
	}
	cout << max << endl;

	return(0);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<ll> a(100001,0);
	ll ans = 0;
	rep(i, N)
	{
		ll tmp;
		cin >> tmp;
		if (tmp > 100000)
		{
			ans++;
			continue;
		}
		a[tmp]++;
	}

	rep1(i, 100000)
	{
		if (a[i] < i)ans += a[i];
		else { ll inc = (a[i] - (ll)i); ans += inc; }
	}
	co(ans);
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	long long l, r;
	long long a, b;
	long long i, j;
	long long lmin = 2019;

	scanf("%lld %lld", &l, &r);
	
	a = l % 2019;
	b = r % 2019;

	if (r - l >= 2019)
	{
		printf("0\n");

		return 0;
	}

	if (a > b)
	{
		for (i = a; i < b + 2019; i++)
		{
			for (j = i + 1; j <= b + 2019; j++)
			{
				if (i*j % 2019 < lmin)
				{
					lmin = i*j % 2019;
				}
			}
		}
	}

	else
	{
		for (i = a; i < b; i++)
		{
			for (j = i + 1; j <= b ; j++)
			{
				if (i*j % 2019 < lmin)
				{
					lmin = i*j % 2019;
				}
			}
		}
	}

	printf("%lld\n", lmin);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

long long int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

long long int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(void){
  //入力
  int N, M;
  string S, T;
  cin >> N >> M;
  cin >> S >> T;
  //gcdでできなければ全てできない
  bool can = true;
  long long int nm_gcd = gcd(N, M);
  long long int nm_lcm = lcm(N, M);
  long long int n_div = nm_lcm / N;
  long long int m_div = nm_lcm / M;
  for(int i = 0; i < nm_gcd; i++){
    if(S[i * m_div] != T[i * n_div]){
      can = false;
      break;
    }
  }
  if(can) cout << nm_lcm << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DP
{
    class A
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            List<int> h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

            int cost1 = 0, cost2 = 0;

            for(int i = 0; i < h.Count-1; i++)
            {
                if (i == 0) cost1 = Math.Abs(h[N - 1] - h[N - 2]);
                else
                {

                    int cost1p = Math.Abs(h[N - i] - h[N - i - 2]) + cost2;
                    int cost2p = Math.Abs(h[N - i -1] - h[N - i - 2]) + cost1;
                    int cost = Math.Min(cost1p, cost2p);

                    cost2 = cost1;
                    cost1 = cost;
                }
            }
            Console.WriteLine(cost1);
        }
    }
}


Measured memory_bytes: 17248
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  string s;
  cin >> n;

  if(n == 22) cout << "Christmas Eve Eve Eve" << endl;
  else if(n == 25) cout << "Christmas" << endl;
  else if(n == 24) cout << "Christmas Eve" << endl;
  else cout << "Christmas Eve Eve" << endl;

  
  
  return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var np = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var s = Console.ReadLine();
        var p = np[1];
        var res = 0L;
        if (p == 2 || p == 5)
        {
            for (int i = 0; i < s.Length; i++)
            {
                if ((s[i] - '0') % p == 0)
                {
                    res += i + 1;
                }
            }
            Console.WriteLine(res);
            return;
        }
        var accum = new int[s.Length + 1];
        accum[accum.Length - 1] = 0;
        var pow = 1;
        for (int i = s.Length - 1; i >= 0; i--)
        {
            accum[i] = accum[i + 1] + (s[i] - '0') * pow;
            accum[i] %= p;
            pow *= 10;
            pow %= p;
        }
        foreach (var item in accum.GroupBy(x => x))
        {
            long count = item.Count();
            res += count * (count - 1) / 2;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 23264
/*input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
*/
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

long long int arr[112345],dp[1123456]={0};
long long int pow(long long int a, long long int b, long long int mod){
	if(b==1)return a;
	if(b==0)return 1;
	long long int ret = pow(a, b/2 ,mod);
	ret = ret * ret;
	ret %= mod;
	if(b&1){
		ret=ret*a;
		ret %= mod; 
	}
	return ret;
}

int main() {
	int n;
	string s;
	long long int ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		dp[s[0]-'A']++;
	}
	vector<long long int>p;
	p.push_back(dp['M'-'A']);
	p.push_back(dp['A'-'A']);
	p.push_back(dp['R'-'A']);
	p.push_back(dp['C'-'A']);
	p.push_back(dp['H'-'A']);
	for(int i=0;i<5;i++){
		//cout<<p[i]<<endl;
		for(int j=i+1;j<5;j++){
			for(int k=j+1;k<5;k++){
				ans += p[i]*p[j]*p[k];
			}

		}
	}
	cout<<ans<<endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to, cor; };
vector<int>G[114514];
int dp[1005][1005];
string s[1005];
signed main() {
	int h, w; cin >> h >> w;
	rep(i, h)cin >> s[i];
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			if (i + 1 < h&&s[i + 1][j] != '#')dp[i + 1][j] += dp[i][j];
			if (j + 1 < w&&s[i][j + 1] != '#')dp[i][j + 1] += dp[i][j];
			dp[i + 1][j] %= mod;
			dp[i][j + 1] %= mod;
		}
	}
	cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 11904
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    println!("{}", (n + 1) / 2);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int a,b,c,d,n;
	int x,y;
	scanf("%d %d %d %d %d",&n,&a,&c,&b,&d);
	x=n/a;
	y=n/b;
	if(n%a!=0)	x++;
	if(n%b!=0)	y++;
	x*=c;
	y*=d;
	if(x<y)	printf("%d\n",x);
	else	printf("%d\n",y);
	return 0;
}


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

int main(){
  char c;
  cin >> c;
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout << "vowel" << endl;
    return 0;
  }
  cout << "consonant" << endl;
  return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    bool can = false;
    int count = 1;
    int total = a;
    int first = a % b; 
    while(!can) {
        if(total % b == c) {
            can = true;
            break;
        }
        total += a;
        int d = total % b;
        if (d == first) {
            break;
        }
        count++;
    }

    if (can) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

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


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

	int cnt = 0;
	rep(i, n) {
		int a;
		cin >> a;
		while (a%2==0) {
			cnt++;
			a /=2;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
const int MAX = pow(2,(double)15)+1;
int main(void){
  bool prime[MAX];
  vector<int> p;
  FOR(i,2,MAX) prime[i]=true;
  FOR(i,2,MAX){
    if(prime[i]){
      p.push_back(i);
      for(int k=2; i*k<=MAX; k++){
        prime[i*k]=false;
      }
    }
  }
  int n;
  while(cin>>n){
    if(n==0) break;
    int count=0;
    for(int i=0; i<p.size()&&2*p[i]<=n; i++){
      if(prime[n-p[i]]) count++;
    }
    cout<<count<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
pre = -1
for i in range(N):
    ans += B[A[i]-1]
    if pre == (A[i]-1):
        ans += C[pre-1]
    pre = A[i]

print(ans)


Measured memory_bytes: 3064
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    n,l=intLine()
    t=a=0
    m=1e9
    for i in 0:n-1
        v=abs(l+i)
        if v<m
            m=v
            t=l+i
        end
        a+=l+i
    end
    println(a-t)
end
main()

Measured memory_bytes: 169700
#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>

#define R register int
const int N = 10000;
double h[N], A, T, len = 99999999.0;
int n, ans;

int main()
{
	double x;
	scanf("%d", &n);
	scanf("%lf%lf", &T, &A);
	for (R i = 1; i <= n; ++i)
	{
		scanf("%lf", &x);
		h[i] = T - x * 0.006;
		if (h[i] > A && h[i] - A < len)
		{
			len = h[i] - A;
			ans = i;
		}
		if (h[i] <= A && A - h[i] < len)
		{
			len = A - h[i];
			ans = i;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
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 gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    int N=S.size();
    int out=0;
    for(int i=1;i<N;i++){
        out = 0;
        if((N-i)%2==1) continue;
        for(int j=0;j<(N-i)/2;j++){
            //cerr << S[j] << "\t" << S[(N-i)/2+j] << endl;
            if(S[j]==S[(N-i)/2+j]) out++;
        }
        if(out*2==N-i) break;
    }
    cout << out*2 << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <vector>
#include <iostream>

int main() {
  while (true) {
    int N, M;
    std::cin >> N >> M;
    if (N == 0 && M == 0) {
      break;
    }
    std::vector<int> C, X;
    for (int i = 0; i < M; i++) {
      int c;
      std::cin >> c;
      C.push_back(c);
    }
    for (int i = 0; i < N; i++) {
      int x;
      std::cin >> x;
      X.push_back(x);
    }
    const int kMaxErr = 255 * 255 * N;
    std::vector<int> dp(256, kMaxErr);
    dp[128] = 0;
    for (int x : X) {
      std::vector<int> new_dp(256, kMaxErr);
      for (int i = 0; i < 256; i++) {
        for (int c: C) {
          int new_val = std::max(0, std::min(255, i + c));
          int err = (new_val - x) * (new_val - x);
          new_dp[new_val] = std::min(new_dp[new_val], dp[i] + err);
        }
      }
      dp = std::move(new_dp);
    }
    int ans = kMaxErr;
    for (int err : dp) {
      ans = std::min(ans, err);
    }
    std::cout << ans << std::endl;
  }
}






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

int main(){
    string s;
    int cnt=0;
    cin >> s;

    int length = (int)s.length();

    for(int i =0; i<length; i++)
        if(s[i] == '1')
            cnt++;
    
    cout << cnt << endl;
}

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

ll h , w ;
vector<string> S(55) ;

ll minesweeper(ll i , ll j ){
  ll count = 0 ;
  if(S[i][j] == '#' )return -1 ;
  if( i-1 >= 0 && j-1 >= 0 ) if(S[i-1][j-1] == '#')count++ ;
  if( j-1 >= 0 ) if(S[i][j-1] == '#')count++ ;
  if( i-1 >= 0 ) if(S[i-1][j] == '#')count++ ;
  if( i+1 <  h && j-1 >= 0 ) if(S[i+1][j-1] == '#')count++ ;
  if( i+1 <  h && j+1 < w ) if(S[i+1][j+1] == '#')count++ ;
  if( i+1 <  h ) if(S[i+1][j] == '#')count++ ;
  if( j+1 <  w ) if(S[i][j+1] == '#')count++ ;
  if( i-1 >= 0 && j+1 < w ) if(S[i-1][j+1] == '#')count++ ;
  return count ;
}
int main() {
	cin >> h >>w ;
    rep(i,h) cin >> S.at(i) ;
    rep(i,h){
      rep(j,w){
        if( minesweeper(i,j) == -1 ) cout << '#' ;
        else cout <<  minesweeper(i,j) ;
      }
      cout <<endl ;
    }
}

Measured memory_bytes: 3624
package main

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

var s = bufio.NewScanner(os.Stdin)

const (
	MAX_PACKAGES = 100000
	MAX_TRACKS   = 100000
)

type allocation struct {
	n int
	k int
	w []int
}

func (a *allocation) check(p int) int {
	i := 0
	for j := 0; j < a.k; j++ {
		s := 0
		for s+a.w[i] <= p {
			s += a.w[i]
			i++
			if i == a.n {
				return a.n
			}
		}
	}
	return i
}

func (a *allocation) binarySearch() int {
	left, mid, right := 0, 0, MAX_PACKAGES*MAX_TRACKS
	for right-left > 1 {
		mid = (left + right) / 2
		v := a.check(mid)
		if v >= a.n {
			right = mid
			continue
		}
		left = mid
	}
	return right
}

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

	a := &allocation{}
	a.n = nextInt(s)
	a.k = nextInt(s)
	a.w = make([]int, a.n)

	for i := range a.w {
		a.w[i] = nextInt(s)
	}
	fmt.Println(a.binarySearch())
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	n, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return n
}



Measured memory_bytes: 2328
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

}


Measured memory_bytes: 22484
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e6+9;
ll sum; 
int n;

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		if(i%5==0||i%3==0) continue;
		sum+=i;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<sstream>
#include<string>
using namespace std;
 
 
 
int main(){
  string s;
  getline(cin,s);
  for(int i=0;i<s.length();i++)if(s[i] == ',' || s[i] == '.')s[i] = ' ';
  stringstream ss;
  string ans[1024];
  ss << s;
  int cnt = 0;
  while(cnt < (ss.str()).size())
    ss >> ans[cnt++];
 
  string rans;
   
  for(int i=0;i<cnt;i++){
    if(!(ans[i].size() >= 3 && ans[i].size() <= 6))continue;
    rans += " " + ans[i];
  }
  cout << rans.substr(1,rans.length()-1) << endl;
  
  return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int dp[s.length()+1][t.length()+1];
    for(int i=0; i<=s.length(); i++){
        for(int j=0; j<=t.length(); j++){
            dp[i][j]=0;
        }
    }
    int maxL=0,maxposS;
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<t.length(); j++){
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            if(s.at(i)==t.at(j)){
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
            }
            maxL=max(maxL,dp[i+1][j+1]);
        }
    }
    /*
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<t.length(); j++){
            cout << dp[i+1][j+1] << " ";
        }
        cout << endl;
    }
    */
    string ans;
    int posS=s.length(),posT=t.length();
    for(int i=maxL; i>0; i--){
        while(dp[posS-1][posT]==i){
            posS--;
        }
        while(dp[posS][posT-1]==i){
            posT--;
        }
        ans.push_back(s.at(posS-1));
        posS--;
        posT--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;






int main() {

	int n;
	cin >> n;
	
	REP(i, 50001) {
		int j = i;
		j *= 108;
		j /= 100;
		if (j == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	

}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

template<typename T>
class CompWatcher{
	T val;
	using self = CompWatcher<T>;
public:
	static unsigned long long counter;

	self& operator=(const self& rhs){
		val = rhs.val;
		return *this;
	}

	self& operator=(const T& rhs){
		val = rhs;
		return *this;
	}

	constexpr CompWatcher(const T& arg):val(arg){}
	constexpr CompWatcher(){}

	friend std::ostream& operator<<(std::ostream& os, const self& rhs){
		os << rhs.val;
		return os;
	}

	friend std::istream& operator>>(std::istream& is, self& rhs){
		is >> rhs.val;
		return is;
	}

	#define OP_DEF(op) \
	friend bool operator op (const self& lhs, const self& rhs){\
		++CompWatcher::counter;\
		return (lhs.val op rhs.val);\
	}\

	OP_DEF(==)
	OP_DEF(!=)
	OP_DEF(<)
	OP_DEF(>)
	OP_DEF(<=)
	OP_DEF(>=)
};

template<typename T>
unsigned long long CompWatcher<T>::counter;


template <typename Container>
void merge(Container& c, size_t left, size_t mid, size_t right){
	using val_t = typename Container::value_type;
	constexpr val_t inf = 1000000001;

	auto n1 = mid-left, n2 = right-mid;
	Container L,R;
	L.reserve(n1);
	R.reserve(n2);
	for(size_t i=0;i<n1;++i) L.push_back(c[left+i]);
	for(size_t i=0;i<n2;++i) R.push_back(c[mid+i]);
	L.push_back(inf);
	R.push_back(inf);

	size_t i=0,j=0;
	for(auto k=left;k<right;++k){
		if(L[i] <= R[j]){
			c[k] = L[i];
			++i;
		}
		else{
			c[k] = R[j];
			++j;
		}
	}
}


template <typename Container>
void merge_sort_core(Container& c, size_t left, size_t right){
	if(left+1 < right){
		size_t mid = (left+right)/2;
		merge_sort_core(c,left,mid);
		merge_sort_core(c,mid,right);
		merge(c,left,mid,right);
	}
}

template <typename Container>
void merge_sort(Container& c){
	merge_sort_core(c,0,c.size());
}

int main(){
	size_t n;
	std::cin >> n;

	std::vector<CompWatcher<size_t>> vec(n);

	for(auto& v : vec){
		std::cin >> v;
	}

	merge_sort(vec);
	for(size_t i=0;i<vec.size()-1;++i){
		std::cout << vec[i] << ' ';
	}
	std::cout << vec.back() << std::endl;

	std::cout << CompWatcher<size_t>::counter << std::endl;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  int sum=0;
  rep(i,M){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  if(sum>N){
    cout<<-1<<endl;
  }
  else{
    cout<<N-sum<<endl;
  }
}


Measured memory_bytes: 3652
//__professor_
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define test ll t;cin>>t;while(t--)
#define mod 1000000007
#define inf 1000000000000000001
const double pi  =3.141592653589793238463;
using namespace std;

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


	//dp[x][y]--->  x==day and y==task

	ll dp[n][3];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			dp[i][j]=-1;
		}
	}


	dp[0][0]=arr[0][0];dp[0][1]=arr[0][1];dp[0][2]=arr[0][2];


	for(ll i=1;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			if(j==0)
			{	
				dp[i][j]=max(arr[i][j]+dp[i-1][j+1],arr[i][j]+dp[i-1][j+2]);
			}
			else if(j==1)
			{
				dp[i][j]=max(arr[i][j]+dp[i-1][j-1],arr[i][j]+dp[i-1][j+1]);
			}
			else if(j==2)
			{
				
				dp[i][j]=max(arr[i][j]+dp[i-1][j-1],arr[i][j]+dp[i-1][j-2]);	
			}
			
		}

	}

	// cout<<dp[n-1][0]<<" "<<dp[n-1][1]<<" "<<dp[n-1][2]<<endl;

	ll ans=max(dp[n-1][0],dp[n-1][1]);
	ans=max(ans,dp[n-1][2]);
	cout<<ans<<endl;
	
	// for(ll i=0;i<n;i++)
	// {
	// 	for(ll  j=0;j<3;j++)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
int n,m,i,j,a[1005][1005],qx[1000005],qy[1000005],b,e,ans;
char c;
void upd(int x,int y,int z)
{
	if (x>n||x<1||y>m||y<1) return;
	if (a[x][y]>z){
		a[x][y]=z;
		qx[++e]=x;qy[e]=y;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,n) fz1(j,m) a[i][j]=n*m+1;
	b=1;
	fz1(i,n){
		scanf(" ");
		fz1(j,m){
			scanf("%c",&c);
			if (c=='#'){
				a[i][j]=0;
				qx[++e]=i;qy[e]=j;
			}
		}
	}
	while (b<=e){
		int x=qx[b],y=qy[b];b++;
		upd(x-1,y,a[x][y]+1);
		upd(x+1,y,a[x][y]+1);
		upd(x,y-1,a[x][y]+1);
		upd(x,y+1,a[x][y]+1);
	}
	fz1(i,n) fz1(j,m) ans=max(ans,a[i][j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
vector<int> grf[MAXN];
int visited[MAXN],tin[MAXN],low[MAXN];
int timer = 0, n,m;
set<int> arp;
set<pair<int,int>> brgs;

void dfs1(int u,int p=-1){
    visited[u]=true;
    tin[u]=low[u]= timer++;
    int childs=0;
    for(auto x: grf[u]){
        if(x==p){continue;}
        if( visited[x]){
            // ancestor
            low[u]=min(low[u],tin[x]);
        }
        else{
            childs++;
            dfs1(x,u);
            low[u] = min(low[u],low[x]);
            if(p!= -1 and low[x] >= tin[u]){
                arp.insert(u);
            }
        }
    }

    if( p==-1 and childs>1){
        arp.insert(u);
    }
}

void dfs2(int u,int p=-1){
    visited[u]=true;
    tin[u]=low[u]=timer++;
    for(auto x:grf[u]){
        if(x==p){continue;}
        if(visited[x]){
            // ancestor
            low[u] = min(low[u], tin[x]);
        }
        else{
            dfs2(x,u);
            low[u] = min(low[u],low[x]);
            if(low[x] > tin[u]){
                brgs.insert({min(u,x),max(u,x)});
            }
        }
    }
}

int color[MAXN]={};
bool cycle=false;
void dfs(int u){
    color[u]=1;
    for(auto nbr: grf[u]){
        if(color[nbr]==1){
            cycle=true; return;
        }
        else if(color[nbr]==0){
            dfs(nbr);
        }
    }
    color[u]=2;
}

int main() {
    // freopen("./input.txt","r",stdin);
    // freopen("./output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        grf[x].push_back(y);
    }
    for(int i=0; i<n; i++){
        if(!visited[i]){
            dfs(i);
            if(cycle){break;}
        }
    }
    if(cycle){
        cout<<1<<"\n";
    }
    else{
        cout<<0<<"\n";
    }
}


Measured memory_bytes: 5572
#include <stdio.h>
#include <algorithm>
class IO_t
{
private:
	static const int L = 1 << 16;
	char ibuf[L], *iS, *iT;
	char _getc()
	{
		if (iS == iT)
			iT = (iS = ibuf) + fread(ibuf, 1, L, stdin);
		return iS == iT ? EOF : *iS++;
	}
public:
	template <class T>
	IO_t &operator>>(T &x)
	{
		char c;
		while ((c = _getc()) < '0' || c > '9');
		for (x = 0; c >= '0' && c <= '9'; c = _getc())
			x = x * 10 + c - '0';
		return *this;
	}
} IO;
int n, fst[100001], nxt[199999], to[199999], deg[100001], F[100001];
void dfs(int u, int fa)
{
	int cnt = 0;
	for (int i = fst[u]; i; i = nxt[i])
		if (to[i] != fa)
		{
			dfs(to[i], u);
			F[u] += F[to[i]];
			if (!F[to[i]]) ++cnt;
		}
	F[u] += std::max(cnt - 1, 0);
}
int main()
{
	IO >> n;
	for (int i = 1, u, v, tot = 0; i < n; ++i)
	{
		IO >> u >> v, ++u, ++v;
		nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v;
		nxt[++tot] = fst[v]; fst[v] = tot; to[tot] = u;
		++deg[u], ++deg[v];
	}
	int rt = std::max_element(deg + 1, deg + 1 + n) - deg;
	if (n == 2 || deg[rt] == 2) return puts("1"), 0;
	dfs(rt, 0);
	printf("%d\n", F[rt]);
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string o, e;
    std::cin>>o>>e;

    int s;
    int k;
    if(o.size() > e.size()){
        s = o.size();
        k = 1;
    }else if(o.size() == e.size()){
        s = o.size();
        k = 0;
    }else{
        s = e.size();
        k = -1;
    }

    std::string ans = "";
    for(int i = 0;i < s - 1;i++){
        ans += o[i];
        ans += e[i];
    }
    if(k == 1){
        ans += o[s - 1];
    }else if(k == -1){
        ans += e[s - 1];
    }else{
        ans += o[s - 1];
        ans += e[s - 1];
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256