akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9+7;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
 
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
} 

void solve(){
    
    int n, k;
    cin >> n >> k;

    vi arr(n);
    rep(i, 0, n){
        cin >> arr[i];
    }

    for(int i=k; i<n; i++){
        if(arr[i] > arr[i-k]){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }

}          

int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

Measured memory_bytes: 4840
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;

void sort(int* rep) {
	bool flg = true;
	int temp;

	do{
		flg = false;
		if (rep[0] < rep[1]) {
			temp = rep[0];
			rep[0] = rep[1];
			rep[1] = temp;
			flg = true;
		}
		if (rep[1] < rep[2]) {
			temp = rep[1];
			rep[1] = rep[2];
			rep[2] = temp;
			flg = true;
		}
	} while (flg);
}




int main() {

	const int SIZE = 10;
	int a[3] = { 0,0,0 };

	cin >> a[0] >> a[1] >> a[2];
	sort(a);

	int value;
	for (int i = 3; i < SIZE; i++) {
		cin >> value;

		if (a[2] < value) {
			a[2] = value;
			sort(a);
		}
	}

	for (int i = 0; i < 3; i++) {
		printf("%d\n", a[i]);

	}


//	system("pause");
	return 0;
}


Measured memory_bytes: 3208
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX 100
using namespace std;

int H,W;
//grid[0][i],grid[MAX+1][i],grid[i][0],grid[i][MAX+1]は番兵
char grid[MAX+3][MAX+3];

void dfs(int row,int column,char mark){
	if(grid[row][column] == mark){
		grid[row][column] = 'x';
		for(int i=-1;i <= 1;i++){
			if(i == 0)continue;
			else dfs(row+i,column,mark);//南北
		}
		for(int j = -1;j <= 1;j++){
			if(j == 0) continue;
			else dfs(row,column+j,mark);//東西
		}
	}
}


void solve(){
	int cnt = 0;
	char mark;
	for(int i = 1;i <= H;i++){
		for(int j = 1;j <= W;j++){
			if(grid[i][j] != 'x'){
				mark = grid[i][j];
				cnt++;
				dfs(i,j,mark);
			}
		}
	}
	printf("%d\n",cnt);
}

int main() {
	char mark;
	scanf("%d %d",&H,&W);

	while(!(H == 0 && W == 0)){
		/***下準備**********/
		for(int i = 0; i <= H+1;i++){
			for(int j = 0;j <= W+1;j++){
				grid[i][j] = 'x';//xは探索済を表す
 			}
		}

		for(int h = 1;h <= H;h++){
			for(int w = 1;w <= W;w++){
				cin >>grid[h][w];//1文字ずつ読み込み
			}
		}
		/*********************/

		solve();
		scanf("%d %d",&H,&W);
	}
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}

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

int dis[10];
int n, k;
string s;
bool flg = false;
bool lst = false;

int fnc(int pos, int chk)
{
    for (int i = pos; i < 10; i++) {
        if (!dis[ i ]) return i;
    }

    lst = true;
    for (int i = 0; i < pos; i++) {
        if (chk == -1 && i == 0) continue;
        if (!dis[i]) return i;
    }
}

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

    for (int i = 0; i < k; i++) {
        int tmp;
        cin >> tmp;
        dis[tmp] = 1;
    }

    int MN = 15;
    for (int i = 0; i < 10; i++) {
        if (dis[i]) continue;
        MN = min(i, MN);
    }

    vector<int> ans;

    for (int i = 0; i < (int)s.length(); i++) {

        if (flg) ans.push_back(MN);//  cout << MN;
        else if (dis[ s[i] - '0' ]) {
            ans.push_back( fnc( s[i] - '0' , 0) );
            flg = true;

            if (lst) {
                ans.pop_back();
                if (!ans.size()) {
                    lst = false;
                    int tt = fnc(s[i] - '0', -1);

                    ans.push_back(tt);
                    if (lst) ans.push_back(MN);
                } else {
                    int pv = ans.back();
                    ans.pop_back();
                    lst = false;
                    int tt = fnc(pv+1, -1);
                    ans.push_back(tt);
                    ans.push_back(MN);
                    if (lst) ans.push_back(MN);
                }
            }
        }

        else ans.push_back(s[i] - '0');
    }

    for (auto x : ans) cout << x;
}

/*
321
8
0 1 2 3 4 5 6 7
*/


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

int d[30];
int main(){
    int w,n; scanf("%d%d",&w, &n);
    rep(i,w) d[i]=i+1;
    rep(i,n){
        int a,b; scanf("%d,%d",&a,&b);a--;b--;
        swap(d[a],d[b]);
    }
    rep(i,w) cout << d[i] << endl;
    return 0;
}



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

int main(){
    int cnt;
    cnt = 0;
    string T;
    string word;
    cin >> T;
    while(true){
        cin >> word;
        if(word == "END_OF_TEXT") break;
        for(int i=0; i< word.length(); i++){
            if(word[i]>='A' && word[i] <= 'Z') word[i] += 'a' -'A';
        }
        if(word == T) cnt++ ;
    }
    cout << cnt << endl;
    return 0;
}


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

int isPrime(int p){
    if (p < 2) return 0;
    else if (p == 2 || p == 3) return 1;
    else if (p & 1){
        int i = 3;
        while (i * i <= p){
            if (p % i == 0) return 0;
            i += 2;
        }
        return 1;
    }else return 0;
}

int main(){
    int N, count = 0, s;
    cin >> N;
    for (int i = 0; i < N; i ++) {
        cin >> s;
        count += isPrime(s);
    }
    cout << count << endl;
    return 0;
}


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

int pn(int n, int c)
{
    return n & c ? -1 : 1;
}
char kigou(int n)
{
    return n < 0 ? '-' : '+';
}
int main()
{
    string s;
    cin >> s;
    vector<int> n(4);
    for (int i = 0; i < 4; i++)
    {
        n[i] = s[i] - '0';
    }
    int uhen = 7 - n[0];
    for (int i = 0; i < 8; i++)
    {
        int sahen = n[1] * pn(i, 4) + n[2] * pn(i, 2) + n[3] * pn(i, 1);
        if (sahen == uhen)
        {
            cout << n[0]
                 << kigou(pn(i, 4)) << n[1]
                 << kigou(pn(i, 2)) << n[2]
                 << kigou(pn(i, 1)) << n[3]
                 << "=7\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 50000

int main(){
  int n,m,i,j,k,ans[N];
  for(i=0; i<N; i++)
    ans[i]=-1;

  while(1){
    scanf("%d",&n);scanf("%d",&m);
    if(n==0 && m==0)
      break;
    else{
      int item[n],temp,max=0;
      for(i=0;i<n;i++)
        scanf("%d",&item[i]);

      for(i=0;i<n-1;i++){
        for(j=i+1;j<n; j++){
          temp = item[i]+item[j];
          if(temp<=m && temp>max)
            max = temp;
        }
      }
      ans[k]=max;
      k++;
    }
  }

  for(i=0;i<N;i++){
    if(ans[i]>0)
      printf("%d\n",ans[i]);
    else if(ans[i]==0)
      printf("NONE\n");
    else
      break;
  }
  return 0;
}


Measured memory_bytes: 2040
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

long long powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    lint N;
    cin >> N;
    lint A[N];
    lint kaijyou=1;
    for(int i=1;i<N;i++) kaijyou=(kaijyou*i)%MOD;
    lint kaisave=kaijyou;
    rep(i,N) cin >> A[i];
    lint sum[N+1]={};
    rep(i,N) sum[i+1]=sum[i]+A[i];
    lint summod[N+1];
    rep(i,N+1) summod[i]=sum[i]%MOD;
    lint ans=0;
    rep(i,N-1){
        ans=(ans+((A[i+1]-A[i])*kaijyou)%MOD)%MOD;
        kaijyou=(kaijyou+kaisave*powmod(i+2,MOD-2))%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
	char c=getchar();ll f=1,x=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
	return x*f;
}
#define mod 1000000007
#define maxn 100010
#define inf (1<<30)
int a[3]={3,5,7};
ll n;
ll ans=0;
void dfs(int d,ll x,bool f1,bool f2,bool f3,bool f){
	if(x>n)return ;
	if(!d){
		if(x<=n)ans+=f1&f2&f3;
		return ;
	}
	if(!f)dfs(d-1,x,f1,f2,f3,0);
	dfs(d-1,x*10+3,1,f2,f3,1);
	dfs(d-1,x*10+5,f1,1,f3,1);
	dfs(d-1,x*10+7,f1,f2,1,1);
}
int main(){
	in(n);
	dfs(10,0,0,0,0,0);
	cout<<ans<<endl;
}
//5*5*3


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

int main(){
  string S; cin >> S;
  if(S=="Sunny"){
    cout << "Cloudy" << endl;
  }
  if(S=="Cloudy"){
    cout << "Rainy" << endl;
  }
  if(S=="Rainy"){
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void show_3multiple(int num);

int main(void)
{
    int num;
    
    cin >> num;
    show_3multiple(num);
    
    return 0;
}

void show_3multiple(int num)
{
    int checkNum;
    for(int i = 1; i <= num; ++i) {
        checkNum = i;
        if(i % 3 == 0) {
            cout << ' ' << i << flush;
        } else {
            while(checkNum) {
                if(checkNum % 10 == 3) {
                    cout << ' ' << i << flush;
                    break;
                }
                checkNum /= 10;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3108
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,u,v,m,i,j;cin>>n>>u>>v>>m;
	vector<int>ut(n);
	vector<int>vt(n);
	vector<int>uy(n);
	vector<int>vy(n);
	if(n==1&&u>1){u=9999;}
	if(n==1&&v>1){v=9999;}
	int uq=0,vq=0,uw=0,vw=0;
	static pair<int,int> aaa[1000000];
	static pair<int,int> bbb[1000000];
	for(i=0;i<1000000;i++){aaa[i]=mp(-1,-1);bbb[i]=mp(-1,-1);}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			int x;cin>>x;x--;
			aaa[x]=mp(i,j);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			int x;cin>>x;x--;
			bbb[x]=mp(i,j);
		}
	}
	while(m--){
		int x;cin>>x;x--;
		if(aaa[x]!=mp(-1,-1)){
			ut[aaa[x].fir]++;if(ut[aaa[x].fir]==n){u--;}
			uy[aaa[x].sec]++;if(uy[aaa[x].sec]==n){u--;}
			if(aaa[x].fir==aaa[x].sec){uq++;if(uq==n){u--;}}
			if(aaa[x].fir+aaa[x].sec==n-1){uw++;if(uw==n){u--;}}
		}
		if(bbb[x]!=mp(-1,-1)){
			vt[bbb[x].fir]++;if(vt[bbb[x].fir]==n){v--;}
			vy[bbb[x].sec]++;if(vy[bbb[x].sec]==n){v--;}
			if(bbb[x].fir==bbb[x].sec){vq++;if(vq==n){v--;}}
			if(bbb[x].fir+bbb[x].sec==n-1){vw++;if(vw==n){v--;}}
		}
		if(u<=0&&v<=0){cout<<"DRAW"<<endl;return 0;}
		if(u<=0){cout<<"USAGI"<<endl;return 0;}
		if(v<=0){cout<<"NEKO"<<endl;return 0;}
	}
	cout<<"DRAW"<<endl;
	return 0;
}



Measured memory_bytes: 18728
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$answer = '';

$array = [];
$sum = 0;

for ($i = 0; $i < $n; ++$i) {
    $array[] = $sc->nextInt();
}

for($i=0;$i<$n-1;$i++){
    for($j=$i+1;$j<$n;$j++){
        $sum += $array[$i]*$array[$j];
    }
}

echo $sum.PHP_EOL;


Measured memory_bytes: 16168
/*
TASK: <Task>
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define EPS 1e-9
#define ALL(x) (x).begin(),(x).end()
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define FOR(i,st,ed) for(int (i)=(st);(i)<(ed);(i)++)
typedef pair<int,int> PII;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long LL;

int N,M,T;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	int i,j,k;
	string s;
	cin >> s;
	cout << s.substr(0,s.find_last_of("FESTIVAL")-7) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	
	ll n;
	cin>>n;
	
	ll ar[n];
	for(int i=0;i<n;i++){
		cin>>ar[i];
	}
	
	int cnt = 0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(ar[i]==ar[j]){
				continue;
			}
			for(int k=j+1;k<n;k++){
				if(ar[i]==ar[k]||ar[k]==ar[j]){
					continue;
				}
				if(ar[i]+ar[j]>ar[k]&&ar[j]+ar[k]>ar[i]&&ar[k]+ar[i]>ar[j]){
					cnt++;
				}
			}
		}
	}
	cout<<cnt;
				
	return 0;
}

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

class unionfind {
  vector<int> par;
  
public:
  unionfind(int n) {
    for (int i = 0; i < n; i++) par.push_back(i);
  }
  
  int find(int n) {
    if (par.at(n) == n) return n;
    return par.at(n) = find(par.at(n));
  }
  
  void merge(int m, int n) {
    par.at(find(m)) = find(n);
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> ans(n, -1);
  unionfind t(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    t.merge(a, b);
    ans.at(a)--;
    ans.at(b)--;
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if (t.find(c) == t.find(d)) {
      ans.at(c)--;
      ans.at(d)--;
    }
  }
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s.at(t.find(i))++;
  }
  for (int i = 0; i < n; i++) {
    ans.at(i) += s.at(t.find(i));
  }
  for (int i = 0; i < n; i++) {
    cout << ans.at(i);
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}


Measured memory_bytes: 2552
let bin_search x (a : int array) n =
  let rec doit l r =
    if l >= r then false
    else
      let m = (l + r) / 2 in
      if x = a.(m) then true
      else if x < a.(m) then doit l m
      else doit (m + 1) r in
  doit 0 n

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let read_seq () = read_line () |> split_on_char ' ' |> List.map int_of_string in
  let n = read_int () in
  let s = read_seq () |> Array.of_list in
  let _ = read_int () in
  let t = read_seq () in
  List.fold_left (fun acc e -> acc + (if bin_search e s n then 1 else 0)) 0 t
  |> Printf.printf "%d\n"

Measured memory_bytes: 16924
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>
#include <random>
#include <valarray>
//#include <fstream>
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;


long long int nCr(long long int n,long long int r) 
{ 
    if(n<2)
        return 0;

    long long ans=1;
    for(long long int i=n-r+1;i<=n;i++)
        ans*=i;

    return ans;
} 

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

    long long int ans=0;
    
    ans+=(nCr(n,2)/2);
    ans+=(nCr(m,2)/2);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

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

using namespace std;

int main(){
    long long x,y; cin >> x >> y;
    int count = 0;
    while(y >= x) {
        y >>= 1;
        count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 764
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main(){

	int n, m;
	int ff[30] = { 0 };

	cin >> n >> m;

	rep(i, n) {
		int k; cin >> k;
		rep(j, k) {
			int a; cin >> a;
			ff[a - 1]++;
		}
	}
	int ans = 0;
	rep(i, m) {
		if (ff[i] == n)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
d_list = list(map(int,input().split()))
m = int(input())
t_list = list(map(int,input().split()))
d_list.sort()
t_list.sort()
i = 0
j = 0
while True: #mについて
    if j == m:
        print("YES")
        exit()
    elif i == n:
        print("NO")
        exit()
    if t_list[j] == d_list[i]:
        j += 1
        i += 1
    else:
        i += 1

Measured memory_bytes: 127572
def examA():
    N = I()
    ans = ((N+1)//2)/N
    print(ans)
    return

def examB():
    N, K = LI()
    H = [I()for _ in range(N)]
    H.sort()
    ans = inf
    for i in range(N-K+1):
        cur = H[i+K-1]-H[i]
        if ans>cur:
            ans = cur
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    C = Counter(A)
    base = 0
    for c in C.values():
        base += c*(c-1)//2
    #print(C)
    #print(base)
    for i in range(N):
        ans[i] = base - (C[A[i]]-1)
    for v in ans:
        print(v)
    return

def examD():
    N, K = LI()
    X = LI()
    L = []; R = [0]
    for x in X:
        if x<0:
            L.append(-x)
        else:
            R.append(x)
    L.append(0)
    L = L[::-1]
    ans = inf
    for i in range(len(L)):
        if len(R)<=K-i:
            continue
        cur = min(L[i] * 2 + R[K - i], L[i] + R[K - i] * 2)
        # print(cur)
        if ans > cur:
            ans = cur
    print(ans)
    return

def examE():
    N, M = LI()
    X = [LI()for _ in range(N)]
    ans = 0
    for i1 in [-1,1]:
        for i2 in [-1,1]:
            for i3 in [-1,1]:
                curX = [0]*N
                for i in range(N):
                    curX[i] = X[i][0]*i1+X[i][1]*i2+X[i][2]*i3
                curX.sort(reverse=True)
                cur = sum(curX[:M])
                if ans<cur:
                    ans = cur
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 4592
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n;
    cin>>n;
    vi a(n);
    ll k;
    cin>>k;
    rep(i,0,n)cin>>a[i],a[i]--;
    vi cnt(n,-1);
    int c=0;
    int nxt=0;
    vi visit;
    while(cnt[nxt]==-1){
        visit.push_back(nxt+1);
        cnt[nxt]=c++;
        nxt=a[nxt];
    }
    //最初に町1に行くのは移動としてカウントされない
    if(k<visit.size()){
        cout<<visit[k]<<endl;
    }
    else{
        ll epi=cnt[nxt];
        k-=epi;
        ll loop=visit.size()-epi;
        k%=loop;
        cout<<visit[k+epi]<<endl;
    }
    return 0;
}




Measured memory_bytes: 5872
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int n, m;
int sx, sy;
int ex, ey;
vector<string> s;
vector<vector<int>> id;

const int mxid = 1e6 + 5;

inline bool valid(int i, int j){
	return (i >= 0 && j >= 0 && i < n && j < m && s[i][j] == '.');
}

vector<pair<int, int>> wut[mxid];

void go(int x, int y, int it){
	if(!valid(x, y) || (id[x][y] != -1)) return;
	wut[it].push_back({x, y});
	id[x][y] = it;
	go(x + 1, y, it);
	go(x, y + 1, it);
	go(x - 1, y, it);
	go(x, y - 1, it);
}

vector<pair<int, int>> goTo(int i, int j){
	int tx = i - 2, ty = j - 2;
	vector<pair<int, int>> can;
	for(int ox = 0; ox < 5; ++ox){
		for(int oy = 0; oy < 5; ++oy)
			can.push_back({tx + ox, ty + oy});
	}
	return can;
}

vector<int> adj[mxid];
bool vis[mxid];

void dfs(int cur){
	if(vis[cur])
		return;
	vis[cur] = 1;
	for(auto p : wut[cur]){
		auto possi = goTo(p.f, p.s);
		for(auto could : possi){
			if(!valid(could.f, could.s)) continue;
			if(id[could.f][could.s] != cur){
				adj[cur].push_back(id[could.f][could.s]);
				adj[id[could.f][could.s]].push_back(cur);
				dfs(id[could.f][could.s]);
			}
		}
	}
}

int bfs(int N){
	list<pair<int, int>> trck;
	vector<bool> done(N);
	int st = id[sx][sy];
	int goal = id[ex][ey];
	trck.push_back({st, 0});
	done[0] = 1;
	while(!trck.empty()){
		auto cur = trck.front();
		trck.pop_front();
		if(cur.f == goal)
			return cur.s;
		for(auto nxt : adj[cur.f]){
			if(!done[nxt]){
				done[nxt] = 1;
				trck.push_back({nxt, cur.s + 1});
			}
		}
	}
	return -1; 
}

int main(){
    fastio();

    cin >> n >> m >> sx >> sy >> ex >> ey;
    -- sx; -- sy;
    -- ex; -- ey;
    s.resize(n);
    id.resize(n, vector<int>(m, -1));
    for(int i = 0; i < n; ++i)
    	cin >> s[i];

    int it = 1;
    for(int i = 0; i < n; ++i){
    	for(int j = 0; j < m; ++j)
    		if(id[i][j] == -1){
    			go(i, j, it);
    			++ it;
    		}
    }

    int N = it - 1;
    //total no of nodes
    for(int i = 0; i < N; ++i){
    	if(!vis[i]){
    		dfs(i);
    	}
    }


    cout << bfs(N);




    return 0;
}

/*

4 4
1 1
4 4
..#.
..#.
.#..
.#..

*/

Measured memory_bytes: 132172
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100000;
const int MAX_N = 1005;


const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int h,w;
string c[MAX_N];


int main(){
    cin >> h >> w;
    rep(i,h){
        cin >> c[i];
    }

    queue<P> que;
    vector<vector<int> > dist(h,vector<int>(w,-1));
    rep(i,h){
        rep(j,w){
            if(c[i][j] == '#'){
                que.push(make_pair(i,j));
                dist[i][j] = 0;
            }
        }
    }

    while(!que.empty()){
        P current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();

        rep(dir,4){
            int nx = x + dx[dir];
            int ny = y + dy[dir];
            if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
            if(dist[nx][ny]== -1){
                dist[nx][ny] = dist[x][y]+1;
                que.push(make_pair(nx,ny));
            }
        }
    }
    int ans =0;
    
    rep(i,h){
        rep(j,w){
            ans = max(ans,dist[i][j]);
        }
    }

    cout << ans <<endl;

}

Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  vint SUM(n);
  int sum = 0;
  rep(i,n){
    sum += A[i];
    SUM[i] = sum;
  }
  int ans = 1;
  for(int i = n-2;i >= 0;i--){
    if(SUM[i]*2 >= A[i+1]) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int A, B;
    int sum = 0;
    cin >> A >> B;
    for(int i = 0; i < 2; i++) {
        if(A > B) {
            sum += A;
            A -= 1;
        }else {
            sum += B;
            B -=1;
        }
    }
    cout << sum << endl;
    

    return 0;
}

Measured memory_bytes: 256
#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<int, int> 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 digits(ll n){
	if(n == 0) return 1;
	int res = 0;
	while(n > 0){
		n /= 10;
		res++;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> s(m);
	vector<char> c(m);
	rep(i,m) cin >> s[i] >> c[i];
	rep(i,1000){
		if(digits(i) != n) continue;
		bool yes = true;
		string t = to_string(i);
		rep(j,m){
			if(t[s[j]-1] != c[j]){
				yes = false;
				break;
			}
		}
		if(yes){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

struct UnionFind
{
    vector<int> parents;
    vector<int64_t> distance_to_parent;

    UnionFind(int n) : parents(n), distance_to_parent(n)
    {
        for (int i = 0; i < n; i++)
        {
            parents.at(i) = -1;
            distance_to_parent.at(i) = 0;
        }
    }

    bool is_root(int x)
    {
        return parents.at(x) < 0;
    }

    int size(int x)
    {
        return -parents.at(find(x));
    }

    int find(int x)
    {
        if (is_root(x))
            return x;
        int px = parents.at(x);
        parents.at(x) = find(parents.at(x));
        distance_to_parent.at(x) += distance_to_parent.at(px);
        return parents.at(x);
    }

    bool can_unite(int x, int y, int d)
    {
        int rx = find(x), ry = find(y);
        if (rx != ry)
            return true;
        int dx = distance_to_parent.at(x), dy = distance_to_parent.at(y);
        return dy - dx == d;
    }

    void unite(int x, int y, int d)
    {
        assert(can_unite(x, y, d));
        int rx = find(x), ry = find(y);
        if (rx == ry)
            return;
        int dx = distance_to_parent.at(x), dy = distance_to_parent.at(y);
        int rd = d + dx - dy;
        if (rd < 0)
        {
            swap(rx, ry);
            rd = -rd;
        }
        parents.at(rx) -= size(ry);
        parents.at(ry) = rx;
        distance_to_parent.at(ry) = rd;
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);
    int Li, Ri, Di;
    for (int i = 0; i < M; i++)
    {
        cin >> Li >> Ri >> Di;
        Li--;
        Ri--;
        if (!tree.can_unite(Li, Ri, Di))
        {
            cout << "No" << endl;
            return 0;
        }
        tree.unite(Li, Ri, Di);
    }
    for (int i = 0; i < N; i++)
    {
        if (tree.distance_to_parent.at(i) > 1e9)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s;
	cin>>s;
	ll i,j,k,l,n=s.length();
	l=0; k=0;
	for(i=0;i<n;i++){
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
			k++;
		}
		else k=0;
		if(k>l) l=k;
	}
	cout<<l;
	return 0;
}


Measured memory_bytes: 256
N, K, Q = [int(item) for item in input().rstrip().split()]

q = [K-Q] * N

for i in range(Q):
    a = int(input().rstrip())
    q[a-1] += 1

for _q in q:
    if _q > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 6596
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	vector<int> H(h),W(w);//各行、各列に含まれる要素数
	set<pair<int, int>> data;//爆破対象の配置
	int temp0, temp1;
	int max_h = 0, max_w = 0;
	rep(i, m) {
		cin >> temp0;
		temp0--;
		H[temp0]++;//各行の要素数をプラス
		if (H[temp0] > max_h) {//もしその行が最大の要素数ならmax_hにとる
			max_h = H[temp0];
		}
		cin >> temp1;
		temp1--;
		W[temp1]++;//各列の要素数をプラス
		if (W[temp1] > max_w) {//もしその行が最大の要素数ならmax_wにとる
			max_w = W[temp1];
		}
		data.insert({ temp0,temp1 });//爆破対象の格納
	}
	
	vector<int> H_max, W_max;
	for (int i = 0; i < h; i++) {//行iが最大の要素数ならH_maxに格納
		if (H[i] == max_h)
			H_max.push_back(i);
	}
	for (int i = 0; i < w; i++) {//列iが最大の要素数ならW_maxに格納
		if (W[i] == max_w)
			W_max.push_back(i);
	}
	//最大の要素数を持つ行と列の交点に爆破対象がないものを探す
	rep(i,H_max.size()){
		rep(j, W_max.size()) {
			if (data.count({H_max[i],W_max[j] }))//交点に爆破対象があれば探索続行
				continue;
			else {
				cout << max_h + max_w << endl;//交点に爆破対象が無ければ探索終了

				return 0;
			}
		}
	}
	cout << max_h + max_w - 1 << endl;

	return 0;
}

Measured memory_bytes: 23808
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b.sort(key = lambda x : x[1], reverse = True)
a.sort()
i = 0
j = 0
c = 1
ans = sum(a)
while True:
    if i >= m:
        break
    for _ in range(b[i][0]):
        if j >= n:
            c = 0
            break
        if a[j] < b[i][1]:
            ans += b[i][1] - a[j]
            j += 1
        else:
            c = 0
            break
    i += 1
    if c == 0:
        break
print(ans)

Measured memory_bytes: 32972
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

int a,b,c,x,y;

int main() {
	scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
	int ans=0;
	if(c*2<a+b) {
		ans+=2*c*min(x,y);
		if(x<y) {
			swap(x,y);
			swap(a,b);
		}
		if(a>2*c) {
			ans+=2*c*(x-y);
		}
		else {
			ans+=a*(x-y);
		}
	}
	else {
		ans=a*x+b*y;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc089/tasks/abc089_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, m[5] = {0}, r = 0;
char I, S[10];

void add(int a, int b, int c)
{
  r += m[a] * m[b] * m[c];
}

int main()
{
  cin >> N;
  REP(i, N)
  {
    cin >> S;
    I = S[0];
    if (I == 'M')
      m[0]++;
    else if (I == 'A')
      m[1]++;
    else if (I == 'R')
      m[2]++;
    else if (I == 'C')
      m[3]++;
    else if (I == 'H')
      m[4]++;
  }

  REP(i, 5)
  {
    FOR(j, i + 1, 5)
    {
      FOR(k, j + 1, 5)
      {
        add(i, j, k);
      }
    }
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll i = 0; i < n; i++)
#define FORN(i, a, b) for (ll i = a; i < b; i++)
#define FORE(i, l) for (auto i : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) n.begin(), n.end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    cout << (1000 - (n % 1000)) % 1000 << '\n';
}



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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int h,w;cin>>h>>w&&h|w;){
		vs grid(h+2,string(w+2,'#'));
		rep(i,h){
			string s; cin>>s;
			rep(j,w)
				grid[i+1][j+1]=s[j];
		}
		rep(i,h+2) cout<<grid[i]<<endl;
	}
}


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

constexpr int M = 700;

struct Query {
    int l, r, id;
};

void solve() {
    int n, q;
    std::cin >> n >> q;

    std::vector<int> xs(n);
    for (auto& x : xs) {
        std::cin >> x;
        --x;
    }

    std::vector<Query> ts(q);
    for (int i = 0; i < q; ++i) {
        auto& t = ts[i];
        std::cin >> t.l >> t.r;
        --t.l, --t.r;
        t.id = i;
    }

    std::sort(ts.begin(), ts.end(),
              [&](Query lhs, Query rhs) {
                  if (lhs.l / M != rhs.l / M) {
                      return lhs.l / M < rhs.l / M;
                  } else {
                      return lhs.r < rhs.r;
                  }
              });

    std::vector<int> cnt(n, 0);
    int num = 0;

    auto add = [&](int x) { if (cnt[x]++ == 0) ++num; };
    auto remove = [&](int x) { if (--cnt[x] == 0) --num; };

    std::vector<int> ans(q);
    int l = 0, r = -1;

    for (auto t : ts) {
        while (l < t.l) remove(xs[l++]);
        while (l > t.l) add(xs[--l]);
        while (r < t.r) add(xs[++r]);
        while (r > t.r) remove(xs[r--]);
        ans[t.id] = num;
    }

    for (auto a : ans) std::cout << a << "\n";
}

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

    solve();

    return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

char s[MAXN];

int ind[MAXN];

void solve(){
	scanf("%s", &s[0]);
	int n = strlen(s);
	REP(i, 0, n) {
		ind[s[i]] = i + 1;
	}
	if (n < 26) {
		REPN(i, 'a', 'z') {
			if (ind[i] == 0) {
				s[n] = i;
				break;
			}
		}
	} else {
		int pos = n - 2;
		for(; pos >= 0; pos--) {
			if (s[pos] < s[pos + 1]) {
				int mn = s[pos + 1];
				REP(j, pos + 2, n) {
					if (s[j] > s[pos] && s[j] < mn) {
						mn = s[j];
					}
				}
				s[pos] = mn;
				s[pos + 1] = 0;
				break;
			}
		}
		if (pos == -1) {
			printf("-1\n");
			return;
		}
	}
	printf("%s\n", s);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
      let mut iter = $s.split_whitespace();
      let mut next = || { iter.next().unwrap() };
      input_inner!{next, $($r)*}
  };
  ($($r:tt)*) => {
      let stdin = std::io::stdin();
      let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
      let mut next = move || -> String{
          bytes
              .by_ref()
              .map(|r|r.unwrap() as char)
              .skip_while(|c|c.is_whitespace())
              .take_while(|c|!c.is_whitespace())
              .collect()
      };
      input_inner!{next, $($r)*}
  };
}

macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

  ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
      let $var = read_value!($next, $t);
      input_inner!{$next $($r)*}
  };
  ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
      let mut $var = read_value!($next, $t);
      input_inner!{$next $($r)*}
  };
}

macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
      ( $(read_value!($next, $t)),* )
  };

  ($next:expr, [ $t:tt ; $len:expr ]) => {
      (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  };

  ($next:expr, chars) => {
      read_value!($next, String).chars().collect::<Vec<char>>()
  };

  ($next:expr, usize1) => {
      read_value!($next, usize) - 1
  };

  ($next:expr, $t:ty) => {
      $next().parse::<$t>().expect("Parse error")
  };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
  input!{
    n:i64,
  }
  let mut ans = n;
  for i in 1..10000001 {
    if n % i == 0 {
      let j = n / i;
      ans = min(ans,i-1 + j-1);
    }
  }
  println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
  if x == 2 {return true;}
  if x < 2 || x % 2 == 0 {return false;}
  let mut j = 3;
  while j <= (x as f64).sqrt() as i64 {
      if x % j == 0 {
          return false;
      }
      j += 2;
  }
  true
}


Measured memory_bytes: 4352
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
      	String t = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<n; i++) sb.append(s.charAt(i)).append(t.charAt(i));
        System.out.println(sb);
    }
}

Measured memory_bytes: 27008