akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

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

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll dp[3001][3001][4];

void solve() {
    int r, c, k;
    cin >> r >> c >> k;
    vector<vector<ll>> a(r + 1, vector<ll>(c + 1, 0));
    for (int i = 0; i < k; ++i) {
        int rr, cc;
        ll v;
        cin >> rr >> cc >> v;
        a[rr][cc] = v;
    }
    for (int i = 1; i <= r; ++i) {
        for (int j = 1; j <= c; ++j) {
            dp[i][j][0] = max(dp[i][j][0], *max_element(dp[i - 1][j], dp[i - 1][j] + 4));
            dp[i][j][1] = max(dp[i][j][1], *max_element(dp[i - 1][j], dp[i - 1][j] + 4) + a[i][j]);
            dp[i][j][0] = dp[i][j - 1][0];
            for (int x = 1; x < 4; ++x) {
                dp[i][j][x] = max({dp[i][j][x], dp[i][j - 1][x], dp[i][j - 1][x - 1] + a[i][j]});
            }
        }
    }
    cout << *max_element(dp[r][c], dp[r][c] + 4) << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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

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

int originalMerge(vector<int> &as, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> l(n1 + 1), r(n2 + 1);

    int i, j, cnt;
    rep(i, n1) l[i] = as[left + i];
    rep(i, n2) r[i] = as[mid + i];
    l[n1] = INT_MAX;
    r[n2] = INT_MAX;
    i = 0; j = 0; cnt = 0;
    for (int k = left; k < right; ++k) {
        if (l[i] <= r[j]) {
            as[k] = l[i];
            i++;
        }
        else {
            as[k] = r[j];
            j++;
        }
        cnt++;
    }
    return cnt;
}

int mergeSort(vector<int> &as, int left, int right) {
    int cnt = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        cnt += mergeSort(as, left, mid);
        cnt += mergeSort(as, mid, right);
        cnt += originalMerge(as, left, mid, right);
    }
    return cnt;
}

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    int ans = mergeSort(as, 0, n);
    rep(i, n - 1) cout<<as[i]<<" ";
    cout<<as[n - 1]<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 6724
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    cin >> S;
    reverse(ALL(S));

    // 1, 10, 9, 12, 3, 4 ....
    VEC(int) Offset(6, 0), Marks(6, 0);
    FOR(i, 0, S.size())
        if (S[i] == '?')
            Marks[i % 6]++;
        else
            Offset[i % 6] = (Offset[i % 6] + S[i] - '0') % 13;

    const int MOD = 1000000007;
    VEC(VEC(int)) Dp(20011, VEC(int)(13, 0));
    Dp[0][0] = 1;
    FOR(i, 0, 20009) {
        FOR(rem, 0, 13) {
            FOR(d, 0, 10) {
                int& tmp = Dp[i + 1][(rem + d) % 13];
                tmp += Dp[i][rem];
                tmp %= MOD;
            }
        }
    }

    VEC(int) Coeffs {1, 10, 9, 12, 3, 4};
    VEC(int) Table[13][13];
    FOR(a, 0, 13)
        FOR(b, 0, 13)
            Table[a * b % 13][a].push_back(b);

    int ret = 0;

    FOR(r0, 0, 13)
        FOR(r1, 0, 13)
            FOR(r2, 0, 13)
                FOR(r3, 0, 13)
                    FOR(r4, 0, 13)
                        FOR(r5, 0, 13)
                            {
                                VEC(int) R{r0, r1, r2, r3, r4, r5};
                                int rem = 0;
                                FOR(i, 0, 6)
                                    rem = (rem + Coeffs[i] * (Offset[i] + R[i])) % 13;
                                // rem + (Offset[5] + r5) * Coeff[5] == 5
                                // (r5 + off5) * cff[5] = 5 - rem
                                if (rem == 5) {
                                    lint prod = 1;
                                    FOR(i, 0, 6)
                                        prod = prod * Dp[Marks[i]][R[i]] % MOD;

                                    ret = (ret + prod) % MOD;
                                }
                            }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
int const max_n = 52;
vector<int> g[max_n];
bool used[max_n];
int c;
void dfs(int s, int from, int to) {
  used[s] = true;
  for(int i=0;i<g[s].size();i++) {
    int nd = g[s][i];
    if(used[nd]) continue;
    if(s == from && nd == to) continue;
    if(s == to && nd == from) continue;
    dfs(nd, from, to);
  }
  return;
}

int main() {
  c = 0;
  int n, m;
  cin >> n >> m;
  vector<int> from(m), to(m);
  for(int i=0;i<m;i++) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
    from[i] = a;
    to[i] = b;
  }
  int cnt = 0;
  for(int i=0;i<m;i++) {
    for(int j=0;j<n;j++) used[j] = false;
    dfs(0, from[i], to[i]);
    bool flag = false;
    for(int j=0;j<n;j++) {
      if(!used[j]) {
        flag = true;
        break;
      }
    }
    if(flag)
      cnt++;
  }
  cout << cnt << endl;

}



Measured memory_bytes: 256
import scala.io.Source.stdin

object Main extends App {
  for(s<-stdin.getLines) {
    var t:String = s
    while(!t.contains("this") && !t.contains("the") && !t.contains("that")) {
      t = t map { c => if(c.toInt >= 97 && c.toInt <= 121) (c.toInt+1).toChar else if(c==122) 'a' else c }
    }
    println(t)
  }
}

Measured memory_bytes: 43740
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m,r;
    cin>>n>>m>>r;
    int dp[n][n];
    int inf=500000000;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dp[i][j]=0;
            else dp[i][j]=inf;
        }
    }
    vector<int> s(r);
    for(int i=0;i<r;i++){
        cin>>s[i];
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        dp[a][b]=c;
        dp[b][a]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    /*for(int i=0;i<n;i++){
        cout<<endl;
        for(int j=0;j<n;j++){
            cout<<dp[i][j];
        }
    }
    */
    //vector<int> v;
    //for(int i=0;i<r;i++)v.push_back(s[i]-1);
    int ans=inf;
    sort(s.begin(),s.end());
    do{
        int sm=0;
        for(int i=0;i<r-1;i++){
            sm+=dp[s[i]-1][s[i+1]-1];
            //cout<<ans<<endl;
        }
        ans=min(ans,sm);
    }
    while(next_permutation(s.begin(),s.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define x first

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 

struct node
{
	int num,l,r,ls,rs;
	node(int _l,int _r)
	{
		num=0;
		l=_l;
		r=_r;
	}
};

vector<node> T;
vector<ll> d;

int make(int l,int r)
{
	int id=T.size();
	T.push_back(node(l,r));
	T[id].ls=(l+1==r?-1:make(l,(l+r)/2));
	T[id].rs=(l+1==r?-1:make((l+r)/2,r));
	return id;
}

void update(int id,int l,int r,int t)
{
	if(l==r||T[id].l>=r||T[id].r<=l)
		return ;
	if(T[id].l>=l&&T[id].r<=r)
	{
		T[id].num+=t;
		return ;
	}
	int mid=(T[id].l+T[id].r)>>1;
	if(l<mid)
		update(T[id].ls,l,r,t);
	if(r>mid)
		update(T[id].rs,l,r,t);
	int mi=min(T[T[id].ls].num,T[T[id].rs].num);
	T[id].num+=mi;
	T[T[id].ls].num-=mi;
	T[T[id].rs].num-=mi;
}

ll gettot(int id)
{
	if(id==-1) return 0; 
	if(T[id].num>0)
		return d[T[id].r]-d[T[id].l];
	return gettot(T[id].ls)+gettot(T[id].rs);
}

int main()
{
	T.reserve(50000);
	int n;
	scanf("%d",&n);
	set<int> s;
	priority_queue<pip,vector<pip>,greater<pip> > pq; 
	for(int i=0;i<n;i++)
	{
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		s.insert(y1);s.insert(y2);
		pq.push(make_pair(x1,make_pair(y1,y2)));
		pq.push(make_pair(x2,make_pair(y2,y1)));
	}
	map<int,int> y;
	d.clear();
	for(set<int>::iterator it=s.begin();it!=s.end();it++)
	{
		y[*it]=d.size();
		d.push_back(*it);
	}
	make(0,d.size()-1);
	ll ans=0;
	while(true)
	{
		pip t=pq.top();pq.pop();
		if(pq.empty()) break;
		if(t.second.first<t.second.second)
			update(0,y[t.second.first],y[t.second.second],1);
		else
			update(0,y[t.second.second],y[t.second.first],-1);
		ans+=gettot(0)*(pq.top().x-t.x);
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define nl '\n'
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void f()
{
  int y,m,d;
  char a,b;
  cin>>y>>a>>m>>b>>d;
  if(m>4)
    cout<<"TBD\n";
  else
    cout<<"Heisei\n";
}

int main()
{
    su;
    f();
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
const unsigned int mod = 1e9+7;
const int mx=100005;

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout); 
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int a,b;cin >> a >>b;
	cout << max(max(a+b,a-b),a*b);

}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
bool isprime(int num){
  if(num<2) return false;
  else if(num==2) return true;
  else if(num%2==0) return false;
  double sqrtNum=sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int ans[55];
  int p=0;
  for(int i=1;i<=55555;i++){
    if(p==55){
      break;
    }
    if(isprime(i)==true&&i%5==1){
      ans[p]=i;
      p++;
    }      
  }
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()

ans = ["No"] * N
kaigai = 0
cnt = 0
for i in range(N):
    if S[i] == "a":
        if cnt < A + B:
            ans[i] = "Yes"
            cnt += 1

    elif S[i] == "b":
        if cnt < A+B and kaigai < B:
            ans[i] = "Yes"
            kaigai += 1
            cnt += 1

for i in ans:
    print(i)


Measured memory_bytes: 4784
/* */
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
const int MAX_LEN = 1010;
#define GETLINE(x) fgets(x,MAX_LEN,stdin);
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
ll n,a,b,ans,sum,k,f;
ll v[55];
ll c[55][55];
void comb(){
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++){
			if(i==0 || i==j)c[i][j]=1;
			else c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
}
int main () { 
	scanf("%lld %lld %lld",&n,&a,&b);
	comb();
	for(int i=0;i<n;i++)
		scanf("%lld",&v[i]);
	sort(v,v+n);
	reverse(v,v+n);
	for(int i=0;i<a;i++)sum+=v[i];
	 f=1;
	for(int i=1;i<n;i++)if(v[i]==v[0])f++;
	if(f>=a){
		printf("%Lf\n",(long double)v[a-1]);
		for(int i=a;i<=min(b,f);i++)
			ans+=c[f][i];
		printf("%lld\n",ans);
		return 0;
	}
	printf("%Lf\n",(long double)sum/a);
	f=0,k=0;
	for(int i=0;i<n;i++)if(v[i]==v[a-1]){
		f++;
		if(i<a)k++;
	}
	printf("%lld\n",c[f][k]);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>

using namespace std;

typedef complex<double> xy_t;
double x[4], y[4];
int n;
const double eps = 1e-11;

double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

int main(void){

	cin >> n;

	for(int i = 0; i < n; i++){
		for (int j = 0; j < 4; ++j){
			cin >> x[j] >> y[j];
		}
		

		xy_t a[2] = {
			xy_t(x[0], y[0]) - xy_t(x[1], y[1]),
			xy_t(x[2], y[2]) - xy_t(x[3], y[3])
		};

		bool p = abs(cross_product(a[0], a[1])) < eps;
		cout << (p ? "YES" : "NO") << endl;
	}
	
	
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	vector<vector<int>> a(3, vector<int>(3));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	set<int> st;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		st.insert(x);
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			if (st.count(a[i][j])) {
				a[i][j] = 1;
			} else {
				a[i][j] = 0;
			}
		}
	}
	for (int i = 0; i < 3; ++i) {
		bool ok = true;
		for (int j = 0; j < 3; ++j) {
			if (a[i][j] == 0) {
				ok = false;
			}
		}
		if (ok) {
			cout << "Yes\n";
			return 0;
		}
	}
	for (int j = 0; j < 3; ++j) {
		bool ok = true;
		for (int i = 0; i < 3; ++i) {
			if (a[i][j] == 0) {
				ok = false;
			}
		}
		if (ok) {
			cout << "Yes\n";
			return 0;
		}
	}
	if (a[0][0] == 1 && a[1][1] == 1 && a[2][2] == 1) {
		cout << "Yes\n";
		return 0;
	}
	if (a[0][2] == 1 && a[1][1] == 1 && a[2][0] == 1) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
 	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    vector<long> a(n);
    long i;
    long min=MOD;
    long max=-MOD;
    long imin=0, imax=0;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
        if(min>a[i]) {
            min=a[i]; imin=i;
        }
        if(max<a[i]) {
            max=a[i]; imax=i;
        }
    }

    if(abs(max)>=abs(min)) {
        printf("%ld\n", 2*n-2);
        for(i=0; i<n; i++) {
            if(i!=imax) {
                printf("%ld %ld\n", imax+1, i+1);
            }
        }
        for(i=0; i<n-1; i++) {
            printf("%ld %ld\n", i+1, i+2);
        }
    }
    else {
        printf("%ld\n", 2*n-2);
        for(i=0; i<n; i++) {
            if(i!=imin) {
                printf("%ld %ld\n", imin+1, i+1);
            }
        }
        for(i=n-1; i>0; i--) {
            printf("%ld %ld\n", i+1, i);
        }
    }
    
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

dp(i,,,,,)残りiのときの最大値

----解説ここまで---- */



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

	LL N, M; cin >> N >> M;
	VI mc({ INF,2,5,5,4,5,6,3,7,6 });
	VI useindex(M);
	vector<string>usestr(M);
	FOR(i, 0, M) {
		cin >> useindex[i];
		usestr[i] = to_string(useindex[i]);
	}

	// 5*10^8
	vector<string>dp(N + 1,"");
	VI dpcheck(N + 1, 0);
	// maximize

	// a < b  ? 
	auto f = [](const string&a, const string&b) {
		if (SZ(a) != SZ(b)) {
			return SZ(a) < SZ(b);
		}
		else {
			FOR(i, 0, SZ(a)) {
				if (a[i] == b[i])continue;
				else return a[i] < b[i];
			}
		}
		return false;
	};
	dp[N] = "";
	dpcheck[N] = 1;
	FORR(left, N, 0 - 1) {
		if (!dpcheck[left])continue;
		FOR(i, 0, M) {
			int nx = left - mc[useindex[i]];
			if (nx >= 0) {
				string S = dp[left] + usestr[i];
				if (f(dp[nx], S)) {
					dp[nx] = S;
					dpcheck[nx] = 1;
				}
			}
		}
	}
	string ans = dp[0];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 43776
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int b[26];
signed main() {
	string s;
	int n;
	cin >> s;
	n = s.size();
	for (int i = 0; i < n; i++) {
		b[(int)s[i] - 'a']++;
	}
	int sum = 1;
	for (int i = 1; i < n; i++) {
		sum += i;
	}
	for (int i = 0; i < 26; i++) {
		sum -= ((b[i] * (b[i] - 1)) / 2);
	}
	cout << sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
    int N,Ans=0;
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        int t;
        scanf("%d",&t);
        while(t%2==0){
            t/=2;
            Ans++;
        }
    }
    printf("%d",Ans);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

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

  int res = N;
  for (int i = 0; i <= N; i++) {
    int cc = 0;
    int t = i;
    while (t > 0) cc += t % 6, t /= 6;
    t = N - i;
    while (t > 0) cc += t % 9, t /= 9;
    if (res > cc) res = cc;
  }

  cout << res << endl;

  return 0;
}


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

int32_t   main(){
     int n,x,t;
     cin>>n>>x>>t;
    if(n%x==0){
        cout<<t*(n/x);
    }   else{
        cout<<t*((n/x)+1);
    }
    return 0;

}


// x  = -7   d = 2    k =3 

// fact = x/d = 3 ; 

// k-=fact ;

// x= x- fact*d;

Measured memory_bytes: 3588
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {
	S := p.Next()
	m := make(map[rune]int)
	for _, s := range S {
		v, ok := m[s]
		if ok {
			m[s] = v + 1
		} else {
			m[s] = 1
		}
	}
	if len(m) != 2 {
		p.Printfln("No")
		return
	}
	for _, v := range m {
		if v != 2 {
			p.Printfln("No")
			return
		}
	}
	p.Printfln("Yes")
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

ll as[100005];
ll dp[100005];

int main() {
  int n,m;cin >> n >> m;
  rep(i,n) {dp[i]=0;as[i]=1;}
  rep(i,m) {int a;cin >> a;as[a-1]=0;}
  dp[0]=(as[0]==0?0:1);
  
  if(as[1])dp[1]=dp[0]+1;
  else dp[1]=0;

  for(int i=2;i<n;i++){
    if(!as[i])continue;
    dp[i]=(dp[i-1]+dp[i-2])%mod;
  }
  cout << dp[n-1];
}

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

using namespace std;

typedef long long ll;

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

    int n;
    cin >> n;

    string S;
    cin >> S;

    map<char, set<int>> M;
    for (int i = 0; i < n; i ++) {
        M[S[i]].emplace(i);
    }

    ll ans = (ll)(M['R'].size() * M['G'].size() * M['B'].size());

    for (auto g : M['G']) {
        for (auto r : M['R']) {
            if (M['B'].count(2*g-r))
                ans --;
            if (M['B'].count(2*r-g))
                ans --;
            if ((r+g) % 2 == 0 && M['B'].count((r+g)/2))
                ans --;
        }
    }

    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 3728
n = int(input())
s = int(input())
def f(b, n):
  if n < b:
    return n
  return f(b, n//b) + n%b
if n == s:
  print(n+1)
  exit()
U = int(n**0.5)+100
for b in range(2, U+1):
  if f(b, n) == s:
    print(b)
    exit()
for p in range(U-1, 0, -1):
  if (n-s)%p:
    continue
  b = (n-s)//p + 1
  if b < 2:
    continue
  if f(b, n) == s:
    print(b)
    exit()
print(-1)

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

#define ll                      long long int
#define i(a,n)                  int a=n
#define l(a,n)                  ll a=n
#define d(a,n)                  double a=n
#define s(a)                    string a
#define c(a)                    ll a, cin>>a
#define cd(a)                   double a, cin>>a
#define cs(a)                   string a, cin>>a
#define ci(a)                   cin>>a
#define co(a)                   cout<<a
#define cos(a)                  cout<<a<<" ";
#define con(a)                  cout<<a<<endl
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i]
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define T                       ll t=1; cin>>t; while(t--)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;

using namespace std;

int main()
{
    fast;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll red=0,white=0;
    f(i,n) if(s[i]=='R') red++;
    f(i,red) if(s[i]=='W') white++;
    con(white);
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM 
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3732
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define BIG 1000007
int min(int a,int b){
    if(a<b) return a;
    else return b;
}
int main(){
    int N,Ma,Mb;
    scanf("%d %d %d",&N,&Ma,&Mb);
    int a[42],b[42],c[42];
    for(int i=0;i<N;i++)
        scanf("%d %d %d",a+i,b+i,c+i);
    int DP[42][402][402];
    memset(DP,BIG,sizeof(DP));
  	DP[0][0][0] = 0;
    DP[0][a[0]][b[0]] = c[0];
    for(int i=1;i<N;i++){
        for(int j=0;j<402;j++){
            for(int k=0;k<402;k++){
                if(j-a[i]<0 || k-b[i]<0)
                    DP[i][j][k] = DP[i-1][j][k];
                else
                     DP[i][j][k]= min(DP[i-1][j][k],DP[i-1][j-a[i]][k-b[i]]+c[i]);

            }
        }
    }
    int ans = BIG;
    for(int i=1;i*Ma<402 && i*Mb<402;i++){
        ans = min(ans,DP[N-1][i*Ma][i*Mb]);
    }
    if(ans == BIG) printf("-1");
    else printf("%d",ans);
}

Measured memory_bytes: 28248
///-BISMILLAHIR RAHMANIR RAHIM-///
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define pb push_back
#define scn(n) scanf("%lld",&n)
#define pi acos(-1)
#define ll long long
#define llu unsigned long long
#define mod 1000000007
int main()
{
    string s,p;
    cin>>s>>p;
    s=s+s;
    if(s.find(p)!=-1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 7;
double a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cout << fixed << setprecision(9);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; ++ i){
		double x; cin >> x; x = (1 + x) / 2;
		a[i] = a[i - 1] + x;
	}
	double ans = 0;
	for(int i = 1; i <= n - m + 1; ++ i) ans = max(ans, a[i + m - 1] - a[i - 1]);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
void BubbleSort(int arr[], int n, int& cnt);

int main(void)
{
	int N;
	int arr[105];
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> N;
	int cnt = 0;
	for (int i = 0; i != N; ++i)
		scanf("%d", &arr[i]);
	BubbleSort(arr, N, cnt);
	
	for (int i = 0; i != N - 1; ++i)
		printf("%d ", arr[i]);
	printf("%d\n", arr[N - 1]);
	printf("%d\n", cnt);
	//system("pause");
	return 0;
}

void BubbleSort(int arr[], int n, int& cnt)
{
	bool flag = true;;
	for (int i = 0; flag && i < n - 1; ++i)
	{
		flag = false;
		for (int j = 0; j < n - i - 1; ++j)
		{
			if (arr[j] > arr[j + 1])
			{
				flag = true;
				swap(arr[j], arr[j + 1]);
				++cnt;
			}
		}
	}
}

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


int main()
{
	int n,d,cnt=0;
	int a[15][15];
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=d;++j)
			scanf("%d",&a[i][j]);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) {
			int sum=0;
			for(int k=1;k<=d;++k) sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			if((int)sqrt(sum)*(int)sqrt(sum)==sum) cnt++;
		}
	cout<<cnt;
}

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

const int MOD = 1e9 + 7;

int main(){
	
	int n;
	cin >> n;
	bool a[n][n];
	rep(i,n){
		rep(j,n){
			cin >> a[i][j];
		}
	}
	
	vector<ll> dp(1<<n);
	dp[0] = 1;
	rep(S,1<<n){
		rep(j,n){
			if( ((S>>j) & 1) && a[__builtin_popcount(S)-1][j] ){
				dp[S] = ( dp[S] + dp[S & ~(1<<j)] ) % MOD;
			}
		}
	}
	
	cout << dp.back() << endl;
	return 0;
}

Measured memory_bytes: 16768
import sys

count = 0
asum = 0
bsum = 0
for line in sys.stdin:
  count += 1
  l = list(map(int,line.split(",")))
  asum += l[0]*l[1]
  bsum += l[1]
bave = int(bsum / count + 0.5)

print(asum)
print(bave)

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


int main()
{
	stringstream ss;
    // 入力
    int N,X;
  	cin>>N>>X;
    int m[N];
    int mmin=-1;
    for(int i=0;i<N;i++){
    	cin>>m[i];
        X-=m[i];
        if(mmin>m[i] || mmin==-1) mmin=m[i];
    }
    int num=X/mmin;
    num+=N;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 2e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FAIL {printf("NO\n"); return 0;}

int N;
int A[MAXN];
int dp[MAXN];
int C[MAXN];

void addmod(int &a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);

	int j = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] != A[j]) A[++j] = A[i];
	}

	N = j+1;

	//for (int i = 0; i < N; i++) printf("%d ", A[i]);
	//printf("\n");

	dp[0] = 1;
	C[A[0]] = 1;
	for (int i = 1; i < N; i++) {
		addmod(C[A[i]], dp[i-1]);
		addmod(dp[i], C[A[i]]);
	}

	printf("%d", dp[N-1]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
  speed;
  
  string s;
  ll n,w=0,r=0;
  cin>>n>>s;
  
  r=count(s.begin(),s.end(),'R');

  for(int i=0;i<r;i++)
  {
     if(s[i]=='W')
       w++;
  }
  cout<<w;
  return 0;
}
  
  

Measured memory_bytes: 3764
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Pair[] pairs1 = new Pair[n];
    Pair[] pairs2 = new Pair[n];
    Map<Pair, Integer> map = new HashMap<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      Pair p = new Pair(a, b);
      pairs1[i] = p;
      pairs2[i] = p;
      int current = map.getOrDefault(p, 0);
      map.put(p, current + 1);
    }
    Arrays.sort(pairs1, (o1, o2) -> o2.c - o1.c);
    Arrays.sort(pairs2, (o1, o2) -> o2.c - o1.c);
    int pairs1Index = 0;
    int pairs2Index = 0;
    long total1 = 0;
    long total2 = 0;
    boolean isTurnList1 = true;
    for (int i = 0; i < n; i++) {
      if (isTurnList1) {
        for (;;) {
          Pair pair = pairs1[pairs1Index];
          pairs1Index += 1;
          int current = map.get(pair);
          if (current <= 0) continue;
          map.put(pair, current - 1);
          total1 += (long) pair.a;
          break;
        }
      } else {
        for (;;) {
          Pair pair = pairs2[pairs2Index];
          pairs2Index += 1;
          int current = map.get(pair);
          if (current <= 0) continue;
          map.put(pair, current - 1);
          total2 += (long) pair.b;
          break;
        }
      }
      isTurnList1 = !isTurnList1;
    }
    System.out.println(total1 - total2);
  }

  private static class Pair {
    private final int a;
    private final int b;
    private final int c;

    private Pair(int a, int b) {
      this.a = a;
      this.b = b;
      this.c = a + b;
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Pair pair = (Pair) o;
      return a == pair.a &&
              b == pair.b;
    }

    @Override
    public int hashCode() {
      return Objects.hash(a, b);
    }
  }
}

Measured memory_bytes: 100772
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long extgcd(long long a, long long b){
  if (b == 0){
    return 1;
  }
  else{
    long long x = 1, y = 0, u = 0, v = 1, k = a, l = b;
    long long tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
    while (l != 0){
      tmp1 = u, tmp2 = v, tmp3 = x - u * (k / l), tmp4 = y - v * (k / l);
      tmp5 = l, tmp6 = (k + l) % l;
      x = tmp1, y = tmp2, u = tmp3, v = tmp4, k = tmp5, l = tmp6;
    }
    return x;
  }
}
long long inved(long long x){
  long long a = extgcd(x, mod);
  return (a + mod) % mod;
}
vector<vector<long long>> encryptic(vector<vector<long long>> left, vector<vector<long long>> mat){
  vector<vector<long long>> cont(0, vector<long long>(5));
  for (int i=0;i<left.size();i++){
    for (int j=0;j<mat.size();j++){
      vector<long long> tm = {left.at(i).at(0) * mat.at(j).at(0)};
      for (int k=1;k<5;k++){
        tm.push_back(left.at(i).at(k) + mat.at(j).at(k));
      }
      cont.push_back(tm);
    }
  }
  return cont;
}
int main(){
  vector<int> X(6), Y(6);
  for (int i=0;i<6;i++){
    cin >> X.at(i);
  }
  for (int i=0;i<6;i++){
    cin >> Y.at(i);
  }
  vector<vector<vector<long long>>> F = {
    {
      {1, 0, 0, Y.at(5)-Y.at(4)+1, 0}, 
      {-1, 0, 0, 0, 0}
    },
    {
      {1, X.at(5)-X.at(4)+1, 0, 0, 0}, 
      {-1, 0, 0, X.at(5)-X.at(4)+1, 0}
    },
    {
      {1, 0, 0, Y.at(3)-Y.at(2)+1, 0}, 
      {-1, 0, 0, 0, Y.at(3)-Y.at(2)+1}
    },
    {
      {1, 0, X.at(3)-X.at(2)+1, X.at(3)-X.at(2)+1, 0}, 
      {-1, X.at(3)-X.at(2)+1, 0, 0, X.at(3)-X.at(2)+1}
    },
    {
      {1, 0, 0, 0, Y.at(1)-Y.at(0)+1}, 
      {-1, 0, 0, 0, 0}
    },
    {
      {1, 0, 0, 0, X.at(1)-X.at(0)+1}, 
      {-1, 0, X.at(1)-X.at(0)+1, 0, 0}
    },
    {
      {1, X.at(2)-X.at(5)-1, X.at(0)-X.at(3)-1, X.at(4)+Y.at(4)-X.at(3)-Y.at(3), X.at(2)+Y.at(2)-X.at(1)-Y.at(1)}
    }
  };
  vector<long long> fact(2000001, 1);
  vector<long long> invf(2000001, 1);
  for (int i=0;i<2000000;i++){
    fact.at(i+1) = (fact.at(i) * (i+1)) % mod;
  }
  invf.at(2000000) = inved(fact.at(2000000));
  for (int i=2000000;i>0;i--){
    invf.at(i-1) = (invf.at(i) * i) % mod;
  }
  vector<vector<long long>> Poly = {{1, 0, 0, 0, 0}};
  for (int i=0;i<7;i++){
    Poly = encryptic(F.at(i), Poly);
  }
  long long S = 0;
  for (int i=0;i<64;i++){
    vector<long long> p = Poly.at(i);
    int a = -p.at(1), b = -p.at(2), c = p.at(3), d = p.at(4);
    int s = (mod + p.at(0)) % mod;
    long long tmp = 0;
    long long M = min(b, c-a-2);
    for (int j=0;j<=M;j++){
      long long pix = j + 1;
      pix *= invf.at(j+a+2);
      pix %= mod;
      pix *= invf.at(c-j-a-2);
      pix %= mod;
      pix *= invf.at(b-j);
      pix %= mod;
      pix *= invf.at(d-b+j);
      pix %= mod;
      tmp += pix;
      tmp %= mod;
    }
    tmp *= fact.at(c);
    tmp %= mod;
    tmp *= fact.at(d);
    tmp %= mod;
    S += s * tmp;
    S = (S + mod) % mod;
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

void solve(){
    int n;
    cin >> n;
    vi a(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int rem1 = sum % n;
    int rem2 = ((sum + n - 1) / n) * n - sum;
    if(rem1 < rem2){
        sum = sum / n;
    }
    else sum = (sum + n - 1) / n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += (a[i] - sum) * (a[i] - sum);
    }
    cout << ans;
}

int main(){
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}



Measured memory_bytes: 256
using System;
class aoj
{
    static void Main()
    {
        int a=0, b=0;
        while (true)
        {
            string c = Console.ReadLine();
            if (String.IsNullOrEmpty(c)) break;
            string[] d = c.Split(',');
            int e = int.Parse(d[0]), f = int.Parse(d[1]), g = int.Parse(d[2]);
            if (e * e + f * f == g * g)
            {
                a++;
            }
            else if (e == f)
            {
                b++;
            }
        }
        Console.WriteLine(a + "\n" + b);
    }
}

Measured memory_bytes: 9180
class PriorityQueue
  attr_reader :values
 
  def initialize
    @values = [nil]
    @pos = 0
  end
 
  def push(value)
    @pos += 1
    @values[@pos] = value
 
    i = @pos
 
    while 2 <= i && @values[i] < @values[i / 2]
      @values[i], @values[i / 2] = @values[i / 2], @values[i]
      i /= 2
    end
  end
 
  def pop
    return nil if empty?
 
    ret = @values[1]
    @values[1] = @values[@pos]
    @pos -= 1
 
    i = 1
 
    loop do
      l = i * 2
      r = l + 1
 
      smallest = l <= @pos && @values[l] < @values[i] ? l : i
      smallest = r <= @pos && @values[r] < @values[smallest] ? r : smallest
 
      break if smallest == i
 
      @values[i], @values[smallest] = @values[smallest], @values[i]
 
      i = smallest
    end
 
    ret
  end
 
  def empty?
    @pos <= 0
  end
end
 
class Node
  attr_reader :id, :siblings
  attr_accessor :state
 
  def initialize(id)
    @id = id
    @siblings = []
    @distances = {}
    @state = :white
  end
 
  def add(sibling, distance)
    @siblings << sibling
    @distances[sibling.id] = distance
  end
 
  def distance_to(sibling)
    @distances[sibling.id]
  end
end
 
Pair = Struct.new(:distance, :id) do
  include Comparable
 
  def <=>(other)
    distance <=> other.distance
  end
end
 
if $PROGRAM_NAME == __FILE__
  n = gets.to_i
 
  nodes = []
 
  n.times do
    id, _, *rest = gets.chomp.split.map(&:to_i)
 
    nodes[id] ||= Node.new(id)
    node = nodes[id]
 
    rest.each_slice(2) do |sibling_id, distance|
      nodes[sibling_id] ||= Node.new(sibling_id)
      sibling = nodes[sibling_id]
      node.add(sibling, distance)
    end
  end
 
  distances = Array.new(n, Float::INFINITY)
 
  distances[0] = 0
  nodes[0].state = :gray
 
  queue = PriorityQueue.new
  queue.push(Pair.new(0, 0))
 
  until queue.empty?
    pair = queue.pop
    current = nodes[pair.id]
    current.state = :black
 
    next if distances[current.id] < pair.distance
 
    current.siblings.each do |sibling|
      next if sibling.state == :black
 
      distance = distances[current.id] + current.distance_to(sibling)
 
      if distance < distances[sibling.id]
        distances[sibling.id] = distance
        sibling.state = :gray
        queue.push(Pair.new(distance, sibling.id))
      end
    end
  end
 
  puts distances.map.with_index {|distance, id| [id, distance].join(' ') }.join("\n")
end

Measured memory_bytes: 46884
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int beg = 0, end = s.size();
  while (s[beg] != 'A')
    beg++;
  while (s[end-1] != 'Z')
    end--;
  cout << end-beg << endl;
  return 0;
}

Measured memory_bytes: 720
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll s;
    cin >> s;
    ll x1 = min(sqrtl(s) + 1, (ld)1e9);
    ll y2 = x1;
    ll y1 = 1;
    ll x2 = x1 * y2 - s;
    if (x2 == 0) {
        y1 = 0;
    }
    cout << "0 0 ";
    cout << x1 << ' ' << y1 << ' ';
    cout << x2 << ' ' << y2;
    return 0;
}

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

q=int(input())
T=list(map(int,input().split()))

#2分探索　昇順、降順になっているときに高速
def binarysearch(key,S):
    left = 0
    right = len(S)
    while left<right :
        mid = (left+right)//2
        if S[mid] == key:
            return 1
        elif key<S[mid]:
            right = mid
        elif key>S[mid]:
            left=mid+1
    return 0

count = 0
key=0
for i in range(q):
    key = T[i]
    count += binarysearch(key,S)
print(count)


Measured memory_bytes: 16708
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll mod=1e9+7,i,j;
ll n;
ll a[300005];
string x,y;
int main(){
    cin>>n;
    cin>>x>>y;
    for(i=0;i<x.size();i++){
        cout<<x[i]<<y[i];
    }
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, X, Y;

int main() {

	cin >> N >> X >> Y;
	X--;
	Y--;

	map<int, int> ans;

	rep(i, N) {
		for (ll j = i + 1; j < N; ++j) {
			ans[min(j - i, abs(i - X) + abs(j - Y) + 1)]++;
		}
	}

	rep(i, N - 1) {
		cout << ans[i + 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 384