akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
//const int mod = 1000000007;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

ll powmod(ll x, ll y) {
    ll res = 1;
    for (ll i = 0; i < y; i++) {
        res = res * x % mod;
    }
    return res;
}
int main() {
    ll n;
    cin >> n;
    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << "\n";
}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int a,b,c;
	
	cin >> a >> b >> c;
	
	cout << (a-b>=c ? 0 : c-a+b) << endl;
	
	return 0;
}

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

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n, k-q);
    for(int i = 0; i < q; i++){
        int ansno;
        cin >> ansno;
        a[ansno -1]++;
    }
    for(int i = 0; i < n ; i++){
        if(a[i] > 0) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}


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

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

    int cnt[3] = {0};
    rep(i, s.size()) {
        cnt[s[i] - 'a']++;
    }

    if (max({cnt[0], cnt[1], cnt[2]}) - min({cnt[0], cnt[1], cnt[2]}) >= 2)
        cout << "NO";
    else
        cout << "YES";
    cout << endl;

    return 0;
}

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

void solve(string s){
	long long res = 0;
	int bc = 0;
	for (int i=s.length()-1; i>0; i--) {
		if (s[i-1] == 'A' && s[i] == 'C') bc=0;
		if (i-1 >= 0 && s[i-1] == 'B' && s[i] == 'A') bc=0;
		if (s[i-1] == 'B' && s[i] == 'C') bc++;
		if (s[i-1] == 'B' && s[i] == 'B') bc=0;
		if (s[i-1] == 'C' && s[i] == 'C') bc=0;
		if (s[i-1] == 'A') res += bc;
		// cout << i << " " << res << endl;
	}
	cout << res << endl;
}

int main(){	
	string s;
	cin >> s;
	solve(s);
	return 0;
}



Measured memory_bytes: 772
'use strict'

main()

function main (input) {
  readInput()
  .then(parseInput)
  .then(calc)
}

function calc (input) {
  let a = input[0]
  let b = input[1]
  let c = input[2]
  let yes = a[a.length - 1] === b[0] && b[b.length - 1] === c[0]
  let answer = yes ? 'YES' : 'NO'
  console.log(answer)
}

function parseInput (inputRaw) {
  let input = inputRaw.split(' ')
  return input
}

function readInput () {
  return new Promise((resolve) => {
    let inputArr = []
    process.stdin.resume()
    process.stdin.setEncoding('utf8')
    process.stdin.on('data', (chunk) => {
      inputArr.push(chunk)
    })
    process.stdin.on('end', () => {
      let input = inputArr.join('').trim()
      resolve(input)
    })
  })
}


Measured memory_bytes: 21448
#include <bits/stdc++.h>
         
using namespace std;
 
#define ll  long long
#define mod 1000000007
#define pb push_back
#define pie 3.141592653589
#define inf 1e9



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


    ll i,n,n2,m,t,j,l,r,pos,mpos,f=0,k,p,n1,z,q,x,y,x1,y1,x2,y2,x3,y3,x4,y4,w;

    cin>>n>>w;
    ll wt[n],ct[n];
    ll s=0;
    for(i=0;i<n;i++){
        cin>>wt[i]>>ct[i];
        s+=ct[i];
    }
    vector<ll> dp1(s+1,inf);
    dp1[0]=0;
    vector<ll> dp2(s+1,inf);
    dp2[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=1;j<=s;j++)
        {
            if(j>=ct[i])
            {
                dp2[j]=min(dp1[j],dp1[j-ct[i]]+wt[i]);

            }
            else
            {
                dp2[j]=dp1[j];
            }
        }
        dp1=dp2;

    }
    
    for(i=s;i>=0;i--)
    {
        //cout<<dp1[i]<<" ";
        if(dp1[i]<=w)
            break;
    }
    cout<<i;




  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ff(i,n) for(i=0;i<n;i++)
ll bg=1000000007;
ll gcd(ll a,ll b)
{
if(b==0)
   return a;
else
   return gcd(b,a%b);   
}
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2);	
	h=(h*h)%bg;
	if(y%2==1)
	  return (x*h)%bg;
	else
	  return h%bg;  
}
ll isp(string str) 
{ 
    // Start from leftmost and rightmost corners of str 
    int l = 0; 
    int h = str.length() - 1;
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        {  
            return -1; 
        } 
    } 
    return 1; 
} 
vector<vector<ll> >adj(300000);
void bfs(ll s,ll n,ll d[])
{
	queue<ll> q;
    ll used[n+1]={0};
    vector<ll> p(n+1);
    q.push(s);
    used[s] = 1;
    p[s] = -1;
    d[s]=0;
    while (!q.empty()) {
    ll v = q.front();
    q.pop();
    ll j;
    for (j=0;j<adj[v].size();j++) {
    	ll u=adj[v][j];
        if (used[u]==0) {
            used[u] = 1;
            q.push(u);
            d[u] = d[v] + 1;
            p[u] = v;
        }
    }
   }
}
int main()
{
	ll t;
	t=1;
	while(t--)
	{	
	   ll i,j,n,m,x;
	   cin>>n>>m;
	   ll k=(n*m+1)/2;
	   if(n==1 || m==1)
	     k=1;
	   cout<<k;
	}
return 0;
}

Measured memory_bytes: 7296
let n, m, x = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let a_s = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = for i = 0 to m - 1 do if a_s.(i) > x then (Printf.printf "%d\n" @@ min i @@ m - i; exit 0) done; print_endline "0"

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
main(){

	int n;
	int ans=0;
	cin >> n;
	string a,b,c;
	cin >> a >> b >> c;

	for(int i=0;i<n;i++){
		if(a[i]==b[i] && a[i]==c[i]){
			continue;
		}else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]){
			ans++;
		}else{
			ans+=2;
		}
	}

	cout << ans <<endl;

}



Measured memory_bytes: 256
a=list(input())
b=list(input())
c=['']*1000000
j=0
z=1
e=''
for i in range(0,len(a)):
  c[j]+=a[i]
  j+=2
for i in range(0,len(b)):
  c[z]+=b[i]
  z+=2
for i in range(len(a)+len(b)):
  e+=c[i]
print(e)
  

Measured memory_bytes: 10868
#include <stdio.h>
#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)
int main(){
	
	int i,j,n,m,sai;
	int a[1000],up[1000],down[1000];
	int h=0,k=0,maxup,maxdown;
	
	scanf("%d",&n);
	rep(i,n){ 
	scanf("%d",&m);
	rep(j,m){
	scanf("%d",&a[j]);
	}
		rep(j,m-1){
			sai = a[j+1] - a[j];
			if(sai>0){
			if(k==0){
				maxup = sai;
			}else{
				if(sai>maxup){
					maxup = sai;
				}
			}
			k++;
			}else if(sai<0){
				if(h==0){
					maxdown = sai;
				}else{
					if(sai<maxdown){
						maxdown = sai;
					}
				}
				h++;
			}
		}
		
		printf("%d %d\n",maxup,-1*maxdown);
		maxup=0,maxdown=0;
		k=0,h=0;
	}
}

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

#define Max(a,b) max({a,b})
#define Min(a,b) min({a,b})
#define rep(i,m,n) for(int (i)=(m);(i)<(int)(n);(i)++)
#define len(n) n.size()
#define print(n) cout << (n) << endl;


// s.substr(i,n)

typedef long long ll;

using namespace std;

//char a = 65;
long long int inf = 1000000007;
int n,m,a,b,c,d,cou,co;
long long int lla,llb,llc;
double k;
const ll LINF = 1e18;
char num = 65;
string s,t;
int lis[20];
/*
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
*/

int main(){
    
    
    cin >> a >> b;
    cout << (a+b)/2 << endl;
    

    return 0;
}


Measured memory_bytes: 3136
N,Wl=map(int,input().split())
W=[]
V=[]
for i in range(N):
	w,v=map(int,input().split())
	W.append(w)
	V.append(v)
dp=[[0]*(Wl+1) for i in range(N+1)]
for i in range(N):
	for j in range(Wl+1):
		if j<W[i]:
			dp[i+1][j]=dp[i][j]
		else:
			dp[i+1][j]=max(dp[i][j],dp[i][j-W[i]]+V[i])
print(dp[N][Wl])

Measured memory_bytes: 120300
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int n, m;
vector<vector<int>> adj;
vector<int> tp, dp;
vector<bool> vis;

void dfs(int s)
{
    vis[s] = true;
    F0R(i, sz(adj[s]))
    {
        if(!vis[adj[s][i]]) 
        {
            dfs(adj[s][i]);
        }
    }
    tp.pb(s);
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    dp.assign(n, 0);
    vis.assign(n, 0);
    adj.assign(n, vector<int>());
    F0R(i, m)
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
    }
    F0R(i, n) if(!vis[i]) dfs(i);
    reverse(tp.begin(), tp.end());
    F0R(i, n)
    {
        int x = tp[i];
        F0R(j, sz(adj[x]))
        {
            dp[adj[x][j]] = max(dp[adj[x][j]], dp[x] + 1);
        }
    }
    int res = 0;
    F0R(i, n) if(dp[i] > res) res = dp[i];
    cout << res;
    return 0;
}

Measured memory_bytes: 8828
from collections import defaultdict

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

d = defaultdict(int)
for a in A:
    d[a] += 1

for i in range(1, N + 1):
    if d[i] > Q - K:
        print('Yes')
    else:
        print('No')

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define y1 dhwjdshg

using namespace std;

const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, m;
    cin >> n >> m;
    if (n > m)
        swap(n, m);
    if (n == 1 && m == 1)
        cout << 1 << "\n";
    else if (n == 1)
        cout << max(0LL, m - 2) << "\n";
    else
        cout << (n * m - n * 2 - m * 2 + 4) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
    ll n; cin >> n;
    ll odd = 0, mod4 = 0;
    rep(i, n) {
        ll a; cin >> a;
        if (a%2) odd++;
        if (a%4 == 0) mod4++;
    }
    if (odd-1 < mod4) cout << "Yes" << endl;
    else if (odd-1==mod4 && n==odd+mod4) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	int sum = k;
    int add=k-1;
	for (int i = 0; i < n-1; ++i) {
		sum = sum * add;
	}
		cout << sum << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i]=map(int,input().split())
ans=float('inf')
for i1 in range(n):
    for i2 in range(i1+1,n):
        for j1 in range(n):
            for j2 in range(j1+1,n):
                a,b=sorted([x[i1],x[i2]])
                c,d=sorted([y[j1],y[j2]])
                cnt=0
                for i in range(n):
                    if a<=x[i]<=b and c<=y[i]<=d:
                        cnt+=1
                if cnt>=k:
                    ans=min(ans,(b-a)*(d-c))
print(ans)

Measured memory_bytes: 58716
#include <cstdio>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;

pair<int, int> a[200001];

int main() {
    int n;
    long long ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i].first, &a[i].second);
        ans += a[i].second;
        a[i].first -= a[i].second;
    }
    sort(a + 1, a + n + 1);
    int mi = INT_MAX;
    if (!a[1].first) putchar('0');
    else {
        for (int i = 1; i <= n; i++)
            if (a[i].first > 0) mi = min(mi, a[i].second);
        printf("%lld", ans - mi);
    }
    return 0;
}

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

// using namespace std;
// typedef long long ll;

// #define rep(i, n) for (int i = 0; i < (n); i++)
// #define rep2(i, a, b) for (int i = (a); i < (b); ++i)
// #define all(a) (a).begin(), (a).end()
// #define all2(a, b) (a).begin(), (a).begin() + (b)
// #define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

//     vector<int> vec(N);
//     rep(i, N) cin >> vec[i];

//     bool flag = true;
//     rep(i, N)
//     {
//         if (vec[i] % 2 == 0)
//         {
//             if (vec[i] % 3 != 0 || vec[i] % 5 != 0)
//             {
//                 flag = false;
//             }
//         }
//     }

//     cout << (flag ? "APPROVED" : "DENIED") << endl;

//     return 0;
// }

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

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

    vector<int> ck(26, 0);
    rep(i, s.size())
    {
        ck[s[i] - 'a']++;
    }

    rep(i, 26)
    {
        if (ck[i] == 0)
        {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int l;
void f(int n,int a[20]){//kakunou
  int i;
  for(i=0;i<l;n/=3)a[i++]=n%3;
}
int g(int a[20]){
  int n=0,i;
  for(i=l;i;i--)n=n*3+a[i-1];
return n;
}
int zMIN(int a,int b){
  if(b==0)return a;
  if(a==0||a>b)return b;
  return a;
}
int main(){
  int i,j,k,n,a[20];
  char s[20];
  while(scanf("%s",s),s[1]){
    int d[60000]={0};
    for(l=n=0;s[l];l++){
      if(s[l]=='r')n=n*3+0;
      if(s[l]=='g')n=n*3+1;
      if(s[l]=='b')n=n*3+2;
    }
    d[n]=1;
    for(i=n=0;i<l;i++)n=n*3+2;//printf("%d\n",n);
    for(i=0;i<25;i++){
      for(j=0;j<=n;j++){
    if(d[j]==0)continue;
    for(k=1;k<l;k++){
      f(j,a);
      a[k]=a[k-1]=(6-a[k]-a[k-1])%3;
      d[g(a)]=zMIN(d[g(a)],d[j]+1);
    }
      }
    }
    d[0]=zMIN(d[0],zMIN(d[n/2],d[n]));
    if(d[0])printf("%d\n",d[0]-1);
    else    printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 788
n = int(input())

'''
x / y = a ... b -> ay * b = x を今回の問題に当てはめ,N//m = N mod m = kとすると
km + k = N -> N = k(m + 1)となり
k と m + 1 はNの約数となる
また、N mod m < mより
k < mとなり
k < N ** 0.5 
'''
ans = 0
for i in range(1, int(n**.5)+1):
    if n % i or i >= n // i - 1:
        continue
    ans += n // i - 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int rcount[4004];
int gcount[4004];
int bcount[4004];

int main(){
  	int n;
	string s;
	cin >> n >> s;
  	int rc,gc,bc;
  	rc = 0; gc = 0; bc = 0;
  	for(int i = n-1; i >= 0 ; i--) {
    	if(s[i] == 'R')
          	rc++;
      	else if (s[i] == 'G')
          	gc++;
      	else
          	bc++;
		rcount[i] = rc;
      	gcount[i] = gc;
      	bcount[i] = bc;
    }
	bool R, G, B;
  	long count = 0;
  	for(int i = 0; i < n-3 ; i++) {
    	R = G = B = false;
      	if(s[i] == 'R')
          	R = true;
      	else if (s[i] == 'G')
          	G = true;
      	else
          	B = true;
      	for(int j = i+1; j < n-1; j++) {
        	if(s[j] == 'R' && !R) {
            	if(G) {
                // Bをcheck
                  	count += max(((s[2*j-i] == 'B') ? bcount[j+1] -1 : bcount[j+1]), 0);
                } else {
                // Gをcheck
                	count += max(((s[2*j-i] == 'G') ? gcount[j+1] -1 : gcount[j+1]), 0);
                }
            }
          	if(s[j] == 'G' && !G) {
            	if(R) {
                // Bをcheck
                  	count += max(((s[2*j-i] == 'B') ? bcount[j+1] -1 : bcount[j+1]), 0);
                } else {
                // Rをcheck
                	count += max(((s[2*j-i] == 'R') ? rcount[j+1] -1 : rcount[j+1]), 0);
                }
            }
          	if(s[j] == 'B' && !B) {
            	if(G) {
                // Rをcheck
                  	count += max(((s[2*j-i] == 'R') ? rcount[j+1] -1 : rcount[j+1]), 0);
                } else {
                // Gをcheck
                	count += max(((s[2*j-i] == 'G') ? gcount[j+1] -1 : gcount[j+1]), 0);
                }
            }
        }
    }
  	cout << count << endl;
}


Measured memory_bytes: 3656
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    K = int(input())
    x = 7 % K
    for i in range(1, K+1):
        if x == 0:
            print(i)
            return
        x = (x*10+7) % K
    print(-1)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 62860
#include <iostream>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    Int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') {
        cout << a + b << endl;
    } else if (op == '-') {
        cout << a - b << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#define INF 100000

void MCO(int);

int A[100][100],p[100];

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

  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    A[i][i] = 0;
  }

  MCO(n);

  printf("%d\n",A[1][n]);

  return 0;
}

void MCO(int n)
{
  int b,i,j,k,l;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      A[i][j] = INF;
      for(k=i;k<j;k++){
	b = A[i][k] + A[k+1][j] + (p[i-1])*(p[k])*(p[j]);
	if(A[i][j]>b) A[i][j] = b;
      }
    }
  }
}

  
	
    



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	public static final int[] PRICE = {6000,4000,3000,2000};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<4;i++) {
			int t = sc.nextInt();
			int n = sc.nextInt();
			System.out.println(PRICE[t-1] * n);
		}
	}

}

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;

  rep(i,N){
      cin >> A[i];
      sum += A[i];
  }
  ll X1 = 0;
  for(int i = 0;i<N;i++){
     if(i%2 == 1){
      sum -= 2*A[i];
     }
  }
  X1 = sum;

  vector<ll> X(N);
  X[0] = X1;
  for(int i = 0;i<N-1;i++){
      X[i+1] = 2*A[i] - X[i];
  }
  rep(i,N){
      cout << X[i] << " ";
  }
  cout << endl;
  
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m,k;
string s,t;
ll a[100005],b[100005];

int main() {
  cin >> n;
  rep(i,n) cin >> a[i] >> b[i];
  ll ans=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=ans;
    if(a[i]%b[i]) ans+=b[i]-a[i]%b[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39268
#include <bits/stdc++.h>
using namespace std;
#define MAXN 505
int f[MAXN][MAXN],a[MAXN];



int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b<10)
        cout<<a+b<<endl;
    else
        cout<<"error"<<endl;


    return 0;
}


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

int gcd(int a, int b) { return((a%b==0?b:gcd(b,a%b))); }
int main() {
  int n;
  cin >> n;
  vector<int> a(n);

  for(int i=0;i<n;i++) cin >> a[i];

  vector<int> gcd_1(n);
  vector<int> gcd_2(n);
  gcd_1[0] = a[0];
  gcd_2[0] = a[n-1];
  for(int i=1;i<n;i++) {
    gcd_1[i] = gcd(gcd_1[i-1], a[i]);
    gcd_2[i] = gcd(gcd_2[i-1], a[n-i-1]);
  }

  int ans = 0;

  for(int i=0;i<n;i++) {
    int g = 0;
    if(i == 0) g = gcd_2[n-2];
    else if(i == n-1) g = gcd_1[n-2];
    else {
      g = gcd(gcd_1[i-1], gcd_2[n-i-2]);
    }

    if(g > ans) ans = g;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <map>
using namespace std;

map<int, long long> mp1;
map<long long, int> mp2;

int main() {
    int x;
    scanf("%d", &x);
    for (int i = -120; i <= 120; ++i) mp1[i] = 1ll * i * i * i * i * i, mp2[mp1[i]] = i;
    for (int i = -120; i <= 120; ++i)
        if(mp2[x + mp1[i]]) {
            printf("%d %d", mp2[x + mp1[i]], i);
            break;
        }
    return 0;
}


Measured memory_bytes: 3344
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <iostream>
#include <queue>
#include <math.h>
#include <algorithm>
#include <fstream>

using namespace std;
typedef long long ll;


int main(void) {
	/**/
	int count = 0, n;
	double sum=0;
	cin >> n;
	vector<double> a(n);


	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());
	while(a.size()> 1) {
		a[1] = (a[0] + a[1]) / 2.0;
		a.erase(a.begin());
		sort(a.begin(), a.end());
	}
	cout << a[0];
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
static constexpr int square(int x) {
 return x * x;
}
int main() {
 int n;
 scanf("%d", &n);
 std::vector<int> x(n, 0);
 if (n == 0) {
  printf("0\n");
  return 0;
 }
 for (int& xi : x) {
  scanf("%d", &xi);
 }
 std::sort(x.begin(), x.end());
 int ret = 0x7fffffff;
 for (int p = x.front(); p <= x.back(); ++p) {
  int tmp = std::accumulate(x.begin(), x.end(), 0, [p](int sub, int xi) { return sub + square(xi - p); });
  if (tmp < ret) {
   ret = tmp;
  }
 }
 printf("%d\n", ret);
 return 0;
}

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

int main(void) {
  int A, B;
  scanf("%d %d", &A, &B);
  int max = A-B;
  if (A+B >= max) {
    max = A+B;
  } 
  if (A*B >= max) {
    max = A*B;
  }
  printf("%d", max);
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    string res;
    for(int i=1;i<(S.size()-1);i++){
        res += S[i];
    }
    cout << S[0] << res.size() << S[S.size()-1] << endl;
}

Measured memory_bytes: 256
//AtCoder ABC064 B - Traveling AtCoDeer Problem
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N;
    cin>>N;
    vector<ll> atbl(N);
    for(auto&& a:atbl){
        cin>>a;
    }
    sort(atbl.begin(),atbl.end());
    ll ans=0;
    for(int i=1;i<atbl.size();++i){
        ans+=atbl[i]-atbl[i-1];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//Connection and Disconnection

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<char, int>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;int k;cin>>s>>k;
    vector<p>t;
    t.pb(mp(s[0],1));
    rep(i,1,s.size()){
        if(s[i]==s[i-1]){
            t[t.size()-1.].second++;
        }else{
            t.pb(mp(s[i],1));
        }
    }
    int ans = 0;
    if(t.size()==1){
        ans = t[0].second*k/2;
    }else if(t[0].first==t[t.size()-1].first){
        int  c = (t[0].second+t[t.size()-1].second)/2;
        ans += c*(k-1);
        ans += t[0].second/2+t[t.size()-1].second/2;
        rep(i,1,t.size()-1){
            int c = t[i].second/2;
            ans += c*k;
        }
    }else{
        rep(i,0,t.size()){
            int c = t[i].second/2;
            ans += c*k;
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3612
from collections import deque
n,k,q=map(int,input().split())
a=deque([k-q]*n)
for i in range(q):
    point=int(input())
    a[point-1] += 1
for _ in range(len(a)):
  if a.popleft() > 0:
      print("Yes")
  else:
      print("No")

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

int main()
{
    int n, k;
    std::string s;
    cin >> n >> s >> k;
    for (int i = 0; i < n; i++)
    {
        if (s[k - 1] != s[i])
        {
            s[i] = '*';
        }
    }
    std::cout << s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
int a[200001];
llong sum[200001];
int xs[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
        xs[i] = xs[i - 1] ^ a[i];
	}
	llong ans = 0;
	for (int i = 1; i <= n; ++i) {
        int s = i, e = n;
        while (s < e) {
            int m = (s + e + 1) / 2;
            if ((sum[m] - sum[i - 1]) != (xs[m] ^ xs[i - 1])) e = m - 1;
            else s = m;
        }
        ans += s - i + 1;
	}
	printf("%lld\n", ans);
	return 0;
}


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

class RangeIndex {
public:
	RangeIndex(int n) {
		m_indexes.resize(n);
		for (auto &row : m_indexes) {
			row.resize(n, 0);
		}
	}

	int getTrainsNum(const int p, const int q) {
		return m_indexes[p - 1][q - 1];
	}

	void addTrains(const std::vector<std::pair<int, int>> &trains) {
		for (const auto &train : trains) {
			addTrain(train.first, train.second);
		}
	}

private:
	std::vector<std::vector<int>> m_indexes;

	void addTrain(const int l, const int r) {
		for (int i = 0; i <= (l - 1); ++i) {
			for (int j = (r - 1); j < static_cast<int>(m_indexes.size()); ++j) {
				++m_indexes[i][j];
			}
		}
	}
};

void outputResult(const int n, const std::vector<std::pair<int, int>> &trains,
	const std::vector<std::pair<int, int>> &ranges) {
	RangeIndex index(n);
	index.addTrains(trains);
	for (const auto &range : ranges) {
		std::cout << index.getTrainsNum(range.first, range.second) << std::endl;
	}
}

int main() {
	int n, m, q;
	std::cin >> n >> m >> q;
	std::vector<std::pair<int, int>> trains(m);
	for (int i = 0; i < m; ++i) {
		int l, r;
		std::cin >> l >> r;
		trains[i] = std::make_pair(l, r);
	}
	std::vector<std::pair<int, int>> ranges(q);
	for (int i = 0; i < q; ++i) {
		int l, r;
		std::cin >> l >> r;
		ranges[i] = std::make_pair(l, r);
	}
	outputResult(n, trains, ranges);
	return 0;
}

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

string S;
set<char> st;
int main() {
	cin>>S;
	for(int i=0; i< S.size(); i++){
		st.insert(S[i]);
	}
	
	if(st.size() == S.size()) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
using namespace std;
int main()
{
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT

    ll r, g, b, k;
    cin >> r >> g >> b >> k;
    ll tot = 0;
    while(g<=r)
        g *= 2, tot++;
    while(b<=g)
        b *= 2, tot++;
    if(tot <= k) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT
}
/**
    1. LOOK SPECIAL CASE N = 1.
    2. LOOK FOR OVERFLOW.
    3. LOOK FOR OUT OF BOUNDS.
**/


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#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>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<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()
{
	for(int n,x;cin>>n>>x && n|x;){
		int m=2*n-1;
		if(x==1 || x==m)
			cout<<"No"<<endl;
		else if(m==3){
			cout<<"Yes"<<endl;
			cout<<"1\n2\n3"<<endl;
		}
		else{
			vi res(m,-1);
			res[n-2]=1;
			res[n-1]=x;
			res[n]=m;
			deque<int> a;
			repi(i,1,m+1) if(1<i && i!=x && i<m) a.push_back(i);
			if(2<x){
				res[n+1]=2; a.pop_front();
				rep(i,n-2){res[i]=a[0]; a.pop_front();}
				repi(i,n+2,m){res[i]=a[0]; a.pop_front();}
			}
			else if(x<m-1){
				res[n-3]=m-1; a.pop_back();
				rep(i,n-3){res[i]=a[0]; a.pop_front();}
				repi(i,n+1,m){res[i]=a[0]; a.pop_front();}
			}
			cout<<"Yes"<<endl;
			rep(i,m) cout<<res[i]<<endl;
		}
	}
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
  vector<int> v(3);
  rep (i,3){
    cin >> v.at(i);
  }
  sort(all(v));
  cout << v.at(2)-v.at(0);
 


}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int A,B;
	cin>>A>>B;
	if(A*B%2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static int n;
	public static void main(String ards[])
	{
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		dfs(0, "");
	}
	
	public static void dfs(int c, String str){
		if(str.length() == n){
			System.out.println(str);
			return;
		}
 
		for(char i = 0; i < c + 1; i++){
			String str2 = str + String.valueOf((char)('a' + i));
			dfs(Math.max(c, i+1), str2);
		}
	}
}

Measured memory_bytes: 79580
#include<stdio.h>

int main(){
  char s1[3], s2[3];
  
  scanf("%s %s", s1, s2);
  
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]){
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  unsigned long long N, k, m;
  k = 5;
  m = 0;
  cin >> N;
  if(N % 2 == 1){
    cout << 0;
  }
  else{
    N = N / 2;
    while((N-(N%k)) / k != 0){
      m += (N-(N%k)) / k;
      k *= 5;
    }
    cout << m;
  }
  return 0;
}

Measured memory_bytes: 256
// #include <iostream>
// #include <fstream>
// #include <cstdio>
// #include <set>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <cstdlib>
// #include <queue>
// #include <string>
// #include <map>
// #include <unordered_map>
// #include <cstring>
// #include <numeric>
// #include <stack>
// #include <iomanip>
// #include <chrono>

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

#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define setinf(mark) memset(mark,0x3f,sizeof(mark))
#define setneg(mark) memset(mark,-1,sizeof(mark))



#ifndef strange
#define trace(...)
// #define endl '\n'
#define start_routine() 
#define end_routine()
#endif
typedef long long ll;   
//__gcd


const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
#define PI 3.141592653589793238
#define mod 1000000007


#define F first 
#define S second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define trav(a,x) for(auto &a:x)
#define pii pair<int,int>

#define pb push_back
#define int long long

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)

#define sz(x) (int)(x).size()
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<vi> vii;
#define vp vector <pii>
int x;
void solve(){
    int a,b,c,d;
  	cin>>a>>b>>c>>d;
  cout<<max(a*c,max(a*d,max(b*c,b*d)))<<"\n";
}


signed main(){
    int t=1;
    start_routine();
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(NULL);
    cout<<fixed<<setprecision(10);
    
    
    // cin>>t;
    
    fr(i,1,t) {
		// cout<<"Case #"<<i<<": ";
		solve();
	}

    end_routine();
    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <stdlib.h>


int main()
{
    int i;

    //??\???
    int n;
    scanf("%d", &n);
    int R[n];
    for( i = 0; i < n; ++i )
        scanf("%d", &R[i]);

    //min???????°???????????????????max????????¶
    int min = R[0], max = R[1] - R[0];
    for( i = 1; i < n; ++i ){
        max = max < R[i] - min ? R[i] - min : max;
        min = min > R[i] ? R[i] : min;
    }

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 1376
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
using namespace std;
int main(){
    long long sum=0;
    int N;
    cin>>N;
    int K;
    cin>>K;
    vector<int>H(N);
    for(int i=0;i<N;i++)cin>>H[i];
    sort(H.begin(),H.end());
    if(N>K){
    for(int i=0;i<K;i++)H[N-1-i]=0;
    for(int i=0;i<N-K;i++)sum+=H[i];}
    cout<<sum;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

char ca[5][10][10]={
	{
		"abcc",
		"abdd",
		"eefg",
		"hhfg"
	},
	{
		"abbcc",
		"aii.d",
		"h..jd",
		"h..je",
		"ggffe"
	},
	{
		"abb..f",
		"a.c..f",
		"ddcee.",
		"..gijj",
		"..gi.k",
		"hh.llk"
	},
	{
		"abb.f..",
		"a.c.f..",
		"ddcee..",
		"..gi.jj",
		"..gi.kk",
		"hh...op",
		"...llop"
	}
};

char cs[1100][1100];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	if(n<3){
		cout<<-1<<endl;
		return 0;
	}
	if(n==3){
		for(i=0;i<3;i++){
			ca[2][i][3]='\0';
			cout<<ca[2][i]<<endl;
		}
		return 0;
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)cs[i][j]='.';
	}
	for(i=0;i<n;i+=4){
		if(n-i==5){
			for(j=0;j<5;j++){
				for(k=0;k<5;k++)cs[i+j][i+k]=ca[1][j][k];
			}
			break;
		}
		if(n-i==6){
			for(j=0;j<6;j++){
				for(k=0;k<6;k++)cs[i+j][i+k]=ca[2][j][k];
			}
			break;
		}
		if(n-i==7){
			for(j=0;j<7;j++){
				for(k=0;k<7;k++)cs[i+j][i+k]=ca[3][j][k];
			}
			break;
		}
		for(j=0;j<4;j++){
			for(k=0;k<4;k++)cs[i+j][i+k]=ca[0][j][k];
		}
	}
	for(i=0;i<n;i++){
		cout<<cs[i]<<endl;
	}
}

Measured memory_bytes: 2304
(stdin => {
  // Define Function
  const sortArray = f => (...args) => args.sort(f)
  const ascendNumber = (a, b) => a - b
  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const [a, b, c] = Array.from(inputs[0].split(' '), Number)

  // display
  console.log(sortArray(ascendNumber)(a, b, c).join(' '))

})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15148
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
using pii = pair<int, int>;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pii> a(n), b(n);
    int Lmax = 0, Rmin = 1e9, max_len = 0;
    REP(i, n) {
        int L, R;
        cin >> L >> R;
        R++;
        a[i] = {L, R};
        Lmax = max(Lmax, L);
        Rmin = min(Rmin, R);
        max_len = max(max_len, R - L);
    }
    REP(i, n) {
        b[i] = {max(a[i].second - Lmax, 0LL), max(Rmin - a[i].first, 0LL)};
    }
    sort(ALL(b), [](const pii &x, const pii &y) {
        return (x.first == y.first && x.second > y.second) || x.first < y.first;
    });
    int ans = max(Rmin - Lmax, 0LL) + max_len;
    int minb = 1e9;
    REP(i, n) {
        if (i > 0)
            ans = max(ans, 0LL + b[i].first + minb);
        minb = min(minb, b[i].second);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

struct IoSetup {
	IoSetup() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int N, M;
ll A[100005];

void solve() {
	vector<ll> sum(N + 1, 0);
	rep (i, N) sum[i + 1] = sum[i] + A[i];
	map<ll, int> mp;
	rep (i, N + 1) mp[sum[i] % M]++;
	ll ans = 0;
	for (auto x: mp) ans += (ll)x.se * (x.se - 1) / 2;
	cout << ans << endl;
}

int main() {
	cin >> N >> M;
	rep (i, N) cin >> A[i];
	solve();
	
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    while (cin >> N, N) {
        vector<string> w(N);
        vector<int> p(N), s(N);
        for (int i = 0; i < N; i++) {
            cin >> w[i] >> p[i];
            s[i] = w[i].size();
        }
        
        string str;
        cin >> str;
        
        int M = str.size();
        vector<int> dp1(M + 1, -1);
        dp1[0] = 0;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (i + s[j] > M) continue;
                bool poss = 1;
                for (int k = 0; k < s[j]; k++) {
                    if (str[i + k] != w[j][k]) {
                        poss = 0;
                        break;
                    }
                }
                if (poss) {
                    dp1[i + s[j]] = max(dp1[i + s[j]], dp1[i] + p[j]);
                }
            }
        }

        int mn = dp1[M];                
        vector<int> dp2(mn + 1, (1 << 29));
        dp2[0] = 0;
        for (int i = 0; i < mn; i++) {
            for (int j = 0; j < N; j++) {
                if (i + p[j] > mn) continue;
                dp2[i + p[j]] = min(dp2[i + p[j]], dp2[i] + s[j]);
            }
        }
        
        static int tc = 1;
        cout << "Case " << tc++ << ": " << dp2[mn] << endl;
    }        
    return 0;
}

Measured memory_bytes: 3192
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

@njit((i8, ), cache=True)
def fact_table(N):
    inv = np.empty(N, np.int64)
    inv[0] = 0
    inv[1] = 1
    for n in range(2, N):
        q, r = divmod(MOD, n)
        inv[n] = inv[r] * (-q) % MOD
    fact = np.empty(N, np.int64)
    fact[0] = 1
    for n in range(1, N):
        fact[n] = n * fact[n - 1] % MOD
    fact_inv = np.empty(N, np.int64)
    fact_inv[0] = 1
    for n in range(1, N):
        fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
    return fact, fact_inv, inv

@njit((i8[::1], ), cache=True)
def main(A):
    # key：サイクルに選んだ個数、(d-2)の和
    # value：選んでいないもの：1/(d-1)!、選んだもの：1/(d-2)! の積の和
    N = len(A)
    U = N + 10
    dp = np.zeros((U, U), np.int64)
    dp[0, 0] = 1
    fact, fact_inv, inv = fact_table(10**3)
    if np.all(A == 2):
        return fact[N - 1] * inv[2] % MOD
    for d in A:
        newdp = np.zeros_like(dp)
        # 選ばない場合の遷移
        newdp += dp * fact_inv[d - 1] % MOD
        # 選ぶ場合の遷移
        if d >= 2:
            newdp[1:, d - 2:U] += dp[:-1, 0:U + 2 - d] * fact_inv[d - 2] % MOD
        dp = newdp % MOD
    ret = 0
    for n in range(3, N + 1):
        for a in range(N + 1):
            x = a * fact[n - 1] % MOD * fact[N - n - 1] % MOD
            x = x * inv[2] % MOD * dp[n, a] % MOD
            ret += x
    return ret % MOD

A = np.array(read().split(), np.int64)[1:]
print(main(A))

Measured memory_bytes: 109636