akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  vl idx(n + 1, -1);
  rep(i, n) {
    ll p;
    cin >> p;
    idx[p] = i;
  }
  set<ll> s;
  set<ll, greater<ll> > s2;
  ll ans = 0;
  for (ll p = n; p >= 1; p--) {
    // cout << p << endl;
    ll i = idx[p];
    s.insert(i);
    s2.insert(i);
    chrono::system_clock::time_point start, end;
    // start = chrono::system_clock::now();
    // set<ll>::reverse_iterator rit = s.find(i);
    set<ll>::iterator it = s.find(i);
    set<ll>::iterator rit = s2.find(i);
    // end = chrono::system_clock::now();
    // cout << static_cast<double>(
    //             chrono::duration_cast<chrono::microseconds>(end - start)
    //                 .count() /
    //             1000.0)
    //      << endl;
    // ;
    set<ll>::iterator a = s2.end(), b = s2.end();
    set<ll>::iterator c = s.end(), d = s.end();
    if (rit != s2.end()) b = ++rit;
    if (b != s2.end()) a = ++rit;
    c = ++it;
    if (c != s.end()) d = ++it;
    ll p1 = 0, p2 = 0, p3 = 0, p4 = 0;
    if (b == s2.end()) {
      p1 = i + 1;
    } else {
      p1 = i - *b;
    }
    if (c == s.end()) {
      p2 = n - i;
    } else {
      p2 = *c - i;
    }
    if (a == s2.end()) {
      if (b == s2.end()) {
        p3 = 0;
      } else {
        p3 = *b + 1;
      }
    } else {
      p3 = *b - *a;
    }
    if (d == s.end()) {
      if (c == s.end()) {
        p4 = 0;
      } else {
        p4 = n - *c;
      }
    } else {
      p4 = *d - *c;
    }

    // cout << p << ":" << p1 << "," << p2 << "," << p3 << "," << p4 << endl;
    ans += p * (p1 * p4 + p2 * p3);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10368
#include <algorithm>
#include <atcoder/dsu>
#include <iostream>
#include <vector>

using namespace std;

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

    int N, M;
    cin >> N >> M;

    auto comps = atcoder::dsu(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        comps.merge(u, v);
    }

    int n_comp = comps.groups().size();
    int ans = ((n_comp == 1) ? 0 : n_comp - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8788
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	map<int, int> mp;
	rep(i,n){
		int a;
		cin >> a;
		mp[a-1]++;
		mp[a]++;
		mp[a+1]++;
	}
	for(auto p : mp){
		chmax(ans, p.second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
signed main()
{
	int n,a,b;
	__builtin_scanf("%d%d%d",&n,&a,&b);
	int x=(a-b<0)?-(a-b):a-b;
	if (x&1) __builtin_printf("Borys");
	else __builtin_printf("Alice");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
#define MOD 1000000007;

/*
    Ball and Boxes 2
    人間、教室、ひとりまで(ソープランド形式)
*/

int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = 1;

    rep(i,n){
        ll ii = i;
        ans *= k-ii;
        ans %= MOD;
    }

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



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

vector<vector<int>>adj;
bool vis[200005];
int cl=0;
int cr=0;

void dfs(int v){
	vis[v]=1;
	if(v<=100000){
		cl++;
	}
	else{
		cr++;
	}
	for(auto u:adj[v]){
		if(vis[u]==1){
			continue;
		}
		dfs(u);
	}
}

main() {
	int tot=0;
	int n;
	cin>>n;
	adj.resize(200005);
	for(int i=1; i<=n; i++){
		int x,y;
		cin>>x>>y;
		adj[x].pb(100000+y);
		adj[100000+y].pb(x);
	}
	
	for(int i=1; i<=100000; i++){
		if(vis[i]==0){
			dfs(i);
			tot+=(cl*cr);
			cl=0;
			cr=0;
		}
	}
	cout<<tot-n;
	return 0;
}

Measured memory_bytes: 13008
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=16000+10,maxn=2000000+10,inf=0x3f3f3f3f;

int main()
{
    ll s,a,b,c=0,d;scanf("%lld",&s);
    ll x=sqrt(s);
    while(x*x<s)x++;
    if(x*x-s>=x)
    {
        a=x;
        b=x*x-x-s;
        if(b)c=1;
        d=x-1;
    }
    else
    {
        a=d=x;
        b=x*x-s;
        if(b)c=1;
    }
    printf("0 0 %lld %lld %lld %lld\n",a,b,c,d);
    return 0;
}
/********************

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


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

using Graph = vector<vector<pair<int, int>>>;

vector<bool> seen;
vector<int> color;

void dfs(const Graph &G, int v, int cl)
{
    color[v] = cl;

    for(auto next_v : G[v])
    {
        if(color[next_v.first] != -1) continue;
        if(next_v.second % 2 == 0)
        {
            dfs(G, next_v.first, cl);
        }
        else
        {
            dfs(G, next_v.first, 1 - cl);
        }
        
    }

}

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

    Graph G(n);
    color.assign(n,-1);

    for(int i=0; i < n-1; ++i)
    {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        G.at(u).push_back(make_pair(v, w));
        G.at(v).push_back(make_pair(u, w));
        
    }

    color.at(0) = 1;
    dfs(G, 0, 1);


    for(int i = 0; i < n; ++i)
    {
        cout << color.at(i) << endl;
    }

    return 0;
}



Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 500005;
const int INF = 1e9;
const int MOD = 998244353;

class TaskD {
private:

public:
	void solveOne(int it){
		int n, k;
		cin >> n >> k;
		vector<int> x(k), y(k);
		for(int i = 0; i < k; i++) {
			cin >> x[i] >> y[i];
		}
		vector<int> dp(n, 0), sum(n, 0);
		dp[0] = sum[0] = 1;
		for(int i = 1; i < n; i++) {
			for(int index = 0; index < k; index++) {
				int le = max(0, i - y[index]);
				int ri = i - x[index];
				if(ri < 0) {
					continue;
				}
				int val = sum[ri] - (le > 0? sum[le-1]:0);
				val = (val + MOD) % MOD;
				dp[i] += val;
				dp[i] %= MOD;
			}
			sum[i] = dp[i];
			sum[i] += sum[i-1];
			sum[i] %= MOD;
		}
		cout << dp[n-1] << endl; 

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 4840
#define R(x)if(r>x)r=x;
main(r,T,a,b,c,d,e,A,B,C){for(;scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&A,&B,&C)>7;printf("%d\n",r)){
	r=a*A+b*B+c*C;
	if(C>=d){
		R(a*A+b*B+e*C)
	}else{
		R(a*A+b*B+e*d)
		if(B+C>=d){R(a*A+b*(B+C-d)+e*d)}
		else if(A+B+C>=d){R(a*(A+B+C-d)+e*d)}
		else{R(e*d)}
	}
}exit(0);}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
using namespace std;
int main ()
{
  int n;
  scanf("%d",&n);
  int h,m,s;
  h = n/3600;
  n = n-h*3600;
  m = n/60;
  s = n-m*60;
  printf("%d:%d:%d\n",h,m,s);
  return 0 ;
}


Measured memory_bytes: 3212
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll k[10008],s[10007];

int main() {
    ll N,L[20007],C=0,T=0;
    cin >> N;
    rep(i,N){
        cin >> L[i];
    }
    sort(L,L+N);
    rep(i,N){
        T=0;
        REP(j,L[i]+1,4000){
            T+=s[j];
        }
        C+=T;
        rep(j,4000){
            s[j+L[i]]+=k[j];
        }
        k[L[i]]++;
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int sum(int n){
    int sum=0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int ans=0;
    for(int k=1;k<=n;k++){
        if(a <= sum(k) && sum(k) <= b) ans += k;
    }
    cout << ans << endl;
}

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

const int NOT_VISITED = -1;

const char WALL = '#';
const char PATH = '.';

queue<pair<int, int>> q_path, q_wall;

int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};

void bfs(int& cnt, bool flip, maze& m, vector<vector<int>>& dist) {
  int h = m.size(), w = m.front().size();
  auto& q = !flip ? q_path : q_wall;
  auto& q_next = !flip ? q_wall : q_path;

  while (!q.empty()) {
    int ch = q.front().first, cw = q.front().second;
    q.pop();

    for (int k = 0; k < 2; ++k) {
      int nh = ch + dh[k], nw = cw + dw[k];
      if (nh < 0 || h <= nh || nw < 0 || w <= nw)
        continue;
      if ((!flip && m[nh][nw] == WALL) || (flip && m[nh][nw] == PATH)) {
        if (dist[nh][nw] == NOT_VISITED) {
          q_next.emplace(nh, nw);
          dist[nh][nw] = cnt + 1;
        }
        continue;
      }

      if (dist[nh][nw] == NOT_VISITED) {
        q.emplace(nh, nw);
        dist[nh][nw] = cnt;
      }
    }
  }
  if (dist[h - 1][w - 1] == NOT_VISITED)
    ++cnt;
}

int main() {
  int h, w;
  cin >> h >> w;

  maze m(h);
  for (auto& x : m)
    cin >> x;

  int cnt = 0;
  bool flip = false;
  vector<vector<int>> dist(h, vector<int>(w, NOT_VISITED));

  if (m[0][0] == WALL) {
    cnt = 1;
    flip = true;
  }

  dist[0][0] = cnt;
  if (!flip)
    q_path.emplace(0, 0);
  else
    q_wall.emplace(0, 0);

  auto& goal = dist[h - 1][w - 1];

  while (goal == NOT_VISITED) {
    bfs(cnt, flip, m, dist);
    flip = !flip;
  }

  cout << (goal + 1) / 2 << endl;
}

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

int main() {
	long long n,m;
	cin>>n>>m;
	if(n==1){
		if(m==1){
			cout<<1<<endl;
		}else{
			cout<<m-2<<endl;
		}
	}else if(m==1){
		cout<<n-2<<endl;
	}else{
		cout<<(n-2)*(m-2)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n;
    cin >> n;
    if(n < 1000){
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>

int main()
{
    int N;
    std::cin >> N;
    if((N%10==2)||(N%10==4)||(N%10==5)||(N%10==7)||(N%10==9))
    {
      std::cout << "hon" << std::endl;
    }

    else if((N%10==0)||(N%10==1)||(N%10==6)||(N%10==8))
    {
        std::cout<<"pon"<<std::endl;
    }
    
    else
    {
        std::cout<<"bon"<<std::endl;
    }
}


Measured memory_bytes: 3632
import bisect

def main():
    buf = input()
    N = int(buf)
    withdrawal = []
    withdrawal += [int(6 ** x) for x in range(10)]
    withdrawal += [int(9 ** x) for x in range(10)]
    withdrawal = list(sorted(withdrawal))
    stack = [[N, 0]]
    best = 999
    while stack:
        current = stack.pop()
        if current[1] > best:
            continue
        if current[0] == 0:
            if current[1] < best:
                best = current[1]
            continue
        point = bisect.bisect_right(withdrawal, current[0])
        stack.append([current[0]-withdrawal[point-1], current[1]+1])
        stack.append([current[0]-withdrawal[point-2], current[1]+1])
    print(best)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

ll dp[2001][2001];

void makecomb_dp(int n){
    for(int i=0;i<2000+1;i++){
        for(int j=0;j<2000+1;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<n+1;i++){
        dp[i][0]=1;
        dp[i][i]=1;
    }
    for(int i=2;i<n+1;i++){
        for(int j=1;j<i;j++){
            dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MAX;
        }
    }
    dbg{
        for(int i=0;i<=5;i++){
            cout <<dp[5][i]<<" ";
        }
        cout <<endl;
    }
}

ll conbination(int n,int k){
    return dp[n][k];
}

int main(){
    ll ans,n,k;
    cin >>n>>k;
    makecomb_dp(n);
    for(int i=0;i<k;i++){
        ans=(conbination(n-k+1,i+1)*conbination(k-1,i))%MAX;
        cout <<ans<<endl;
    }



    return 0;

}

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

using namespace std;

int main(int argc, char const *argv[]) {
        int row, col;
        int table[101][101] = {0};
        cin >> row >> col;
        for(int i = 0; i < row; i++) {
                for(int j = 0; j < col; j++) {
                        cin >> table[i][j];
                        table[i][col] += table[i][j];
                        table[row][j] += table[i][j];
                        table[row][col] += table[i][j];
                }
        }
        for(int i = 0; i <= row; i++) {
                for(int j = 0; j <= col; j++) {
                        if(j) cout << " ";
                        cout << table[i][j];
                }
                cout << endl;
        }
        return 0;
}



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

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());

            int priceTotal = 0;
            int priceMax = 0;

            for (int i = 0; i < count; ++i)
            {
                int price = int.Parse(Console.ReadLine());

                priceTotal += price;

                if (price > priceMax)
                {
                    priceMax = price;
                }
            }

            priceTotal -= priceMax / 2;

            Console.WriteLine(priceTotal);
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  std::string s, t;
  std::cin >> s >> t;
  for (int i = int(s.length()) - t.length(); i >= 0; --i) {
    bool is_valid = true;
    for (int j = 0; j < int(t.length()); ++j) {
      if (s[i + j] != '?' and s[i + j] != t[j]) {
        is_valid = false;
        continue;
      }
    }
    if (is_valid) {
      for (int j = 0; j < int(t.length()); ++j) {
        s[i + j] = t[j];
      }
      for (int j = 0; j < int(s.length()); ++j) {
        if (s[j] == '?') s[j] = 'a';
      }
      std::cout << s << std::endl;
      return 0;
    }
  }
  std::cout << "UNRESTORABLE" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
int p[20005],a[20005],b[20005];
cin>>n;
rep(i,0,n-1)cin>>p[i];
int d=2*n;
a[0]=1;
rep(i,1,n-1)a[i]=a[i-1]+d;
rep(i,0,n-1)b[n-1-i]=a[i];
rep(i,0,n-1)
{
	b[p[i]-1]+=i;
}
rep(i,0,n-1)
{
	ol(a[i]);os;
}
on;
rep(i,0,n-1)
{
	ol(b[i]);os;
}
return 0;
}


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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main(void){
    int a,b,c,d,sum=0;
    string I;
    cin >> I;
    a = ctoi(I[0]);b=ctoi(I[1]);c=ctoi(I[2]);d=ctoi(I[3]);
    char A[2] = {'+','-'};
    sum = a;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                sum = a;
                if(A[i]== '+') sum+=b;
                else sum-=b;
                if(A[j] == '+') sum += c;
                else sum -= c;
                if(A[k] == '+') sum += d;
                else sum -= d;
                if(sum == 7) {
                    
                    cout<<a<<A[i]<<b<<A[j]<<c<<A[k]<<d<<"=7";
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

b = [[] for _ in range(n)]
for i in range(n):
    b[i] = [i for i in range(max(0,a[i]-1),a[i]+2)]


def dfs(i,v,n):
    if i==n:
        if v==0:
            return 1
        else:
            return 0
    else:
        res = 0
        for j in b[i]:
            res += dfs(i+1,v*(j%2),n)

        return res
    
    
ans = 0
ans = dfs(0,1,n)
print(ans)

Measured memory_bytes: 9128
import java.util.*;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n,i,j;
		String s;
		ArrayList<Integer> H = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13));
		ArrayList<Integer> D = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13));
		ArrayList<Integer> C = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13));
		ArrayList<Integer> S = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13));
		n = sc.nextInt();

		for(i=0;i<n;i++){
			s = sc.next();
			if(s.equals("H")){
				H.remove(H.indexOf(sc.nextInt()));
			}
			else if(s.equals("D")){
				D.remove(D.indexOf(sc.nextInt()));
			}
			else if(s.equals("S")){
				S.remove(S.indexOf(sc.nextInt()));
			}
			else if(s.equals("C")){
				C.remove(C.indexOf(sc.nextInt()));
			}
		}
			for(j=0;j<S.size();j++){
				if(S.equals(null)){
					break;
				}
				System.out.println("S "+S.get(j));
			}
			for(j=0;j<H.size();j++){
				if(H.equals(null)){
					break;
				}
				System.out.println("H "+H.get(j));
			}
			for(j=0;j<C.size();j++){
				if(C.equals(null)){
					break;
				}
				System.out.println("C "+C.get(j));
			}
			for(j=0;j<D.size();j++){
				if(D.equals(null)){
					break;
				}
				System.out.println("D "+D.get(j));
			}
	}

}



Measured memory_bytes: 26208
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        a[i] += a[i - 1];
    }
    ll mindiff = INF;
    for (int i = 0; i < n; ++i) {
        ll right = a[n - 1] - a[i];
        ll left  = a[i];
        chmin(mindiff, abs(right - left));
    }
    cout << mindiff << "\n";
    return 0;
}

Measured memory_bytes: 1792
int d[4],e[9],f,k;
char s[30];
int f2(void){
	int a,b;
	a=e[f++];
	if(a<10){
		s[k++]=a+'0';
	}
	else{
		int b,c;
		s[k++]='(';
		b=f2();
		s[k++]=a;
		c=f2();
		s[k++]=')';
		a=a-'+'?a-'-'?b*c:b-c:b+c;
	}
	return a;
}
int f1(int op,int num,int i){
	int j;
	if(i==7){
		f=k=0;
		if(f2()==10){
			s[k]=0;
			puts(s);
			return 1;
		}
		return 0;
	}
	if(op){
		for(j=0;j<3;j++){
			e[i] = "+-*"[j];
			if(f1(op-1,num+1,i+1))return 1;
		}
	}
	if(num||i==6){
		for(j=0;j<4;j++){
			if(e[i]=d[j]){
				d[j]=0;
				if(f1(op,num-1,i+1))return 1;
				d[j]=e[i];
			}
		}
	}
	return 0;
}

int main(void){
	for(;scanf("%d%d%d%d",d,d+1,d+2,d+3),f=*d;)
		if(!f1(3,0,0))puts("0");
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int n;
	cin >> n;
	cout << (n % 10 == 9 || n / 10 == 9 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 764
N = int(input())
D = [0] + list(map(int, input().split()))
Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)]

# ある都市間の時差の取りうる値は2種類のみ
# 先ずはそれを全列挙
candidates = []
for i in range(N+1):
  for j in range(i+1, N+1):
    di, dj = D[i], D[j]
    diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj)
    candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]])
    Diffs[i][j] = [diff1, diff2]

# 上で全列挙した時差に関して、その時差が全体の最小値となり得るかどうかを確認していく
# 最小値となり得るかどうかを確認したい時差の値をdiffとすると、
# 任意の2都市間の時差がdiff以上となる必要があり、そのような時間の設定方法があるかどうかを確認する
# 矛盾するかどうかは都市を2色で塗り分ける要領で確認できる
ans = 0
for idx1, idx2, diff, c in candidates:
  conditions = [-1] * (N+1)
  if c == 0:
    conditions[idx1] = conditions[idx2] = 0
  else:
    conditions[idx1] = 0; conditions[idx2] = 1
  res = True
  for i in range(N+1):
    for j in range(i+1, N+1):
      if idx1 == i and idx2 == j:
        continue
      diff1, diff2 = Diffs[i][j]
      if diff1 < diff and diff2 < diff:
        res = False
        break
      elif diff1 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = 0; conditions[j] = 1
        elif c1 < 0:
          conditions[i] = 1 - c2
        elif c2 < 0:
          conditions[j] = 1 - c1
        else:
          if c1 == c2:
            res = False
            break
      elif diff2 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = conditions[j] = 0
        elif c1 < 0:
          conditions[i] = c2
        elif c2 < 0:
          conditions[j] = c1
        else:
          if c1 != c2:
            res = False
            break
    else:
      continue
    break
  if res:
    ans = max(ans, diff)

print(ans)

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

using namespace std;




int main(){

	int n; cin >> n;

	vector < pair <int, int> > a(n);

	for(int i = 0; i < n; i++){
		cin >> a[i].first >> a[i].second;
	}

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

	map < pair <int, int>, int> m;


	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			m[make_pair(a[j].first - a[i].first, a[j].second - a[i].second)] = 0;
		}
	}


	for(auto &it : m){
		set < pair <int, int> > used;
		for(int i = 0; i < n; i++){
			if(used.find(make_pair(a[i].first - it.first.first, a[i].second - it.first.second)) == used.end()){
				it.second++;
			}
			used.insert(a[i]);
		}
	}

	int record = 1e9;
	for(auto it : m){
		record = min(record, it.second);
	}

	cout << (record == 1e9 ? 1 : record) << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

struct mint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 mod= 1e9+7;
    mint(const i64 a_=0): a(a_){}
    mint inv(){
        i64 t=1, n= mod - 2, x=a;
        while(n){
            if(n&1) (t*=x)%=mod;
            (x*=x)%=mod;
            n>>=1;
        }
        mint ret(t);
        return ret;
    }
    bool operator==(const mint &x){return a==x.a;}
    bool operator!=(const mint &x){return a!=x.a;}
    mint operator+(const mint &x){
        mint ret;
        ret.a=a+x.a;
        if(ret.a>mod) ret.a-=mod;
        return ret;
    }
    mint operator-(const mint &x){
        mint ret;
        ret.a=a-x.a;
        if(ret.a<0) ret.a+=mod;
        return ret;
    }
    mint operator*(const mint &x){
        mint ret;
        ret.a=a*x.a%mod;
        return ret;
    }
    mint operator/(mint &x){
        mint ret;
        ret.a=a*x.inv().a%mod;
        return ret;
    }
    mint operator^(lint n){
        mint ret=1, x=a;
        while(n){
            if(n&1) (ret.a*=x.a)%=mod;
            (x.a*=x.a)%=mod;
            n>>=1;
        }
        return ret;
    }
    mint &operator+=(const mint &x){
        a+=x.a;
        if(a>=mod) a-=mod;
        return *this;
    }
    mint &operator-=(const mint &x){
        a-=x.a;
        if(a<0) a+=mod;
        return *this;
    }
    mint &operator*=(const mint &x){
        (a*=x.a)%=mod;
        return *this;
    }
    mint &operator/=(mint &x){
        (a*=x.inv().a)%=mod;
        return *this;
    }
    mint &operator^=(lint n){
        lint ret=1;
        while(n){
            if(n&1) (ret*=a)%=mod;
            (a*=a)%=mod;
            n>>=1;
        }
        a=ret;
        return *this;
    }
};

int main(){
    mint m;
    lint n;
    scanf("%lld%lld", &m.a, &n);
    m^=n;
    printf("%lld\n", m.a);
}


Measured memory_bytes: 3216
N, A, B, K = gets.split.map(&:to_i)
Mod = 998244353
num = 0
fact_mod = Array.new(N+1){1}
inv_mod = Array.new(N+1){1}

def power_mod(n,r,p)
  if r < 0
    retrn false
  end
  n = n % p
  if n == 0
    0
  elsif r == 0 || n == 1
    1
  elsif r % 2 == 0
    (power_mod(n*n, r/2, p)) % p
  else
    (n * power_mod(n, (r-1), p)) % p
  end
end

def cnt_mod(n,r,p,f,inv)
  if n < 0 || r < 0 || r > n
    0
  else
    ((f[n] * inv[r]) % p * inv[n-r]) % p
  end
end

for i in 2..N do
  fact_mod[i] = (fact_mod[i-1] * i) % Mod
end

inv_mod[N] = power_mod(fact_mod[N], Mod - 2, Mod)

for i in 1...N do
  inv_mod[N-i] = inv_mod[N-i+1] * (N-i+1) % Mod
end

for i in 0..[(K/A).floor,N].min do
  k = K - A * i
  if k % B == 0 && k/B <= N
    a = i
    b = k / B
    cnt = cnt_mod(N, a, Mod, fact_mod, inv_mod) * cnt_mod(N, b, Mod, fact_mod, inv_mod)
    num += cnt
  end
end

puts num % Mod

Measured memory_bytes: 6524
#include<bits/stdc++.h>
using namespace std;
int a[85];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	long long v=1000;
	for(int i=1;i<n;i++){
		if(a[i-1]<a[i]){
			long long x=v/a[i-1];
			v=v-x*a[i-1]+x*a[i];
		}
	}
	printf("%lld",v);
} 

Measured memory_bytes: 3824
#include <stdio.h>
int main(void) {
	int i = 0, n;
	double x = 0, y = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%lf", &y);
		x = x + (1 / y);
	}

	printf("%lf\n",1/x);


	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<set>
#include<string>
using namespace std;
set<string> memo;

void flatRound(string& xai)
{
	char t=xai[2];
	xai[2]=xai[1];
	xai[1]=xai[3];
	xai[3]=xai[4];
	xai[4]=t;
	memo.insert(xai);
}

void northRound(string& xai)
{
	char t=xai[0];
	xai[0]=xai[1];
	xai[1]=xai[5];
	xai[5]=xai[4];
	xai[4]=t;
}

void eastRound(string& xai)
{
	char t=xai[0];
	xai[0]=xai[3];
	xai[3]=xai[5];
	xai[5]=xai[2];
	xai[2]=t;
}

void allRoundIn(string xai)
{
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<4;j++)
		{
			flatRound(xai);
		}
		eastRound(xai);
	}
	northRound(xai);
	for(int i=0;i<4;i++)
	{
		flatRound(xai);
	}
	northRound(xai);
	northRound(xai);
	for(int i=0;i<4;i++)
	{
		flatRound(xai);
	}
}

void setData(int n)
{
	char text[8];
	string xai = "000000";
	int redundancy=0;
	memo.clear();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<6;j++)
		{
			scanf("%s",text);
			xai[j]=text[0];
		}
		if(memo.find(xai)==memo.end())
		{
			allRoundIn(xai);
		}
		else
		{
			redundancy++;
		}
	}
	printf("%d\n",redundancy);
}

int main()
{
	int n;
	while(1)
	{
		scanf("%d",&n);
		if(n==0) break;
		setData(n);
	}
}

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d);
	
	
	rep (i, d) t[i] = rand()%n + 1;
	int ans = -1;
	int cnt = 0;
	while(1) {
		// 局所探索法
		cnt++;
		if(cnt > 200000) break;
		vector<int> old = t;
		const int CH = rand()%5 + 1; // CH箇所変える
		rep(i, CH) {
			int nd = rand()%d;
			int nq = rand()%n + 1;
			t[nd] = nq;
		}
		
		// 点数の再計算
		vector<int> nlast(n);
		ll now = 0;
		rep(i, d) {
			now += s[i][t[i]];
			nlast[t[i]-1] = i+1;
			rep(j, n) {
				now -= c[j] * (i+1-nlast[j-1]);
			}
		}
		
		// 良くなれば更新
		if(now > ans) {
			ans = now;
		} else {
			t = old;
		}
	}
	
	rep(i, d) printf("%d\n", t[i]);
	return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	std::string s;

	std::cin >> s;

	int end = s.length() - 1;
	int ans = 0;

	for (int i = 0; i <= end; i++)
	{
		if (s[i] != s[end]) {
			ans++;
		}
		end--;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for(ll i=0;i<3;i++){
		if(s[i]==t[i]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        String y = sc.next();
        int k = 0;
        int i = 0;
        String ans = "";
        while(true){
            if(k%2==0){
                if(x.length()<=i)break;
                ans+=x.charAt(i);
            }else{
                if(y.length()<=i)break;
                ans+=y.charAt(i);
                i++;
            }
            k++;
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

int main(){
  int N;
  string S;
  cin >>N>>S;
  
  string T;
  string ans;
  if(N%2!=0){
    ans = "No";
  }else{
    rep(i,N/2) T += S.at(i);
    if(S==T+T){
      ans ="Yes";
    }else ans = "No";
  }
    
  cout << ans<< endl;
}

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

int main(){

	int sum, top, front, right, n, tmp;
	string op;
	map<string, int> mp;
	
	mp.insert(make_pair("North", 1));
	mp.insert(make_pair("East", 2));
	mp.insert(make_pair("South", 3));
	mp.insert(make_pair("West", 4));
	mp.insert(make_pair("Right", 5));
	mp.insert(make_pair("Left", 6));
	
	while(cin >> n){
		if(n == 0) break;
		
		sum = 1;
		top = 1;
		front = 2;
		right = 3;
		
		for(int i=0; i<n; i++){
			cin >> op;
			switch(mp[op]){
 				case 1: tmp = top; top = front; front = 7 - tmp; break;
				case 2: tmp = top; top = 7 - right; right = tmp; break;
				case 3: tmp = top; top = 7 - front; front = tmp; break;
				case 4: tmp = top; top = right; right = 7 - tmp; break;
				case 5: tmp = front; front = right; right = 7 - tmp; break;
				case 6: tmp = front; front = 7 - right; right = tmp; break;
			}
			sum += top;
		}
		
		cout << sum << endl;
	}
	
	return 0;

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int n,m;
long long dp[1009][1009];
long long mod = 1000000007;
string s[1009];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>s[i];
	for(int i=0;i<n;i++) if(s[i][0] == '#') break; else dp[i][0] = 1;
	for(int i=0;i<m;i++) if(s[0][i] == '#') break; else dp[0][i] = 1;
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(s[i][j] == '#') continue;
			dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
}


Measured memory_bytes: 9216
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>MARCH(5);
	string m = "MARCH";
	rep(i, n) {
		char s[10];
		scanf("%s",&s);
		rep(j, 5) {
			if (s[0] == m[j]) {
				MARCH[j]++;
				j = 5;	
		    }
	    }
	}
	int i = 1;
	ll ans = 0;
	while (i < pow(2, 5)) {
		int count = 0;
		ll tmp = 1;
		rep(k, 5) {
			if (i&(1 << k)) {
				count++;
				tmp *= MARCH[k];
			}
		}
		if (count == 3) {
			ans += tmp;
		}
		i++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
# count the size of the component to which a node belongs to 
# subtract all the direct friendship and direct blockships
# subtract 1 itself
import sys
import os
sys.setrecursionlimit(1000000)
from collections import defaultdict
adj = defaultdict(list)
adj1=defaultdict(list)
szc = [ 0 for i in range(300000)]
which =[0 for i in range(300000)]
vis = [0 for i in range(300000)]
tot =0
def dfs1(u):
	global tot
	vis[u]=1
	which[u]=tot
	szc[tot]=szc[tot]+1
	for i in adj[u]:
		if vis[i]==1:
			continue
		dfs1(i)
def main():
	global tot
	n , m , k = map(int, input().split())
	bk =[0 for i in range(n+1)]
	fd =[0 for i in range(n+1)]
	for i in range(m):
		x, y = map(int ,input().split())
		adj[x].append(y)
		adj[y].append(x)
		fd[x]=fd[x]+1
		fd[y]=fd[y]+1
	for i in range(k):
		x, y = map(int , input().split())
		adj1[x].append(y)
		adj1[y].append(x)
	for i in range(1, n+1):
		if vis[i]!=1:
			tot = tot+1
			dfs1(i)
	ans=[]
	for i in range(1, n+1):
		res = szc[which[i]]
		res = res-fd[i]
		res = res-1
		for j in adj1[i]:
			if which[j]==which[i]:
				res =res -1
		ans.append(res)
	print(*ans)
		
if __name__=="__main__":
	main()

Measured memory_bytes: 393164
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

#define V 100001
vector<int> G[V],rG[V],v;
bool u[V];
int n,cmp[V];
  
void add_edge(int x,int y){G[x].push_back(y);rG[y].push_back(x);}
void dfs(int x){u[x]=1;rep(i,G[x].size())if(!u[G[x][i]])dfs(G[x][i]);v.push_back(x);} 
void rdfs(int x,int k){u[x]=1;cmp[x]=k;rep(i,rG[x].size())if(!u[rG[x][i]])rdfs(rG[x][i],k);}
int scc() {
  mem(u);v.clear();rep(i,n)if(!u[i])dfs(i);mem(u);
  int k=0;rrep(i,v.size())if(!u[v[i]])rdfs(v[i],k++);return k;
}

void Main() {
  int m;
  cin >> n >> m;
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    add_edge(x,y);
  }
  scc();
  set<int> s;
  rep(i,n) s.in(cmp[i]);
  pr(!(s.size()==n));
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 6036
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    ll n,k,s;
    cin >> n >> k >> s;
    rep0(i, n - 1){
        if(i < k){
            cout << s << " ";
        }else{
            if(s == 1){
                cout << 2 << " ";
            }else{
                cout << s - 1 << " ";
            }
        }
    }
    if(k == n){
        cout << s << endl;
    }else{
        if(s == 1){
            cout << 2 << endl;
        }else{
            cout << s - 1 << endl;
        }
    }
    return 0;
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 15, M = 1010;

int n, m, k;
int f[N][M];
char g[N][M];

bool check(int n, int l, int r)
{
	for (int i = 1; i <= n; i ++ )
		if (f[i][r] - f[i][l - 1] > k)
			return false;
	return true;
}

int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < n; i ++ ) cin >> g[i] + 1;
	
	int res = 0x3f3f3f3f;
	for (int t = 0; t < 1 << (n - 1); t ++ )
	{
		int cnt = 0, row = 1;
		bool flag = true;
		memset(f, 0, sizeof f);
		
		for (int i = 0; i < n; i ++ )
		{
			for (int j = 1; j <= m; j ++ )
			{
				f[row][j] += g[i][j] - '0';
				if (f[row][j] > k)
				{
					flag = false;
					break;
				}
			}
			if ((t >> i) & 1) row ++ , cnt ++ ;
		}
		if (!flag) continue;
		
		for (int i = 1; i <= row; i ++ )
			for (int j = 1; j <= m; j ++ )
				f[i][j] += f[i][j - 1];
		
		for (int i = 1; i <= m; i ++ )
		{
			int j = i;
			while (j <= m && check(row, i, j)) j ++ ;
			
			if (j <= m) cnt ++ ;
			i = j - 1;
		}
		res = min(res, cnt);
	}
	cout << res << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans;
  if(n % (a + b) > a) ans = n / (a + b) * a + a;
  else ans = n / (a + b) * a + n % (a + b);
  cout << ans << endl;
}

Measured memory_bytes: 256