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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll r;

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

  cin>>r;
  cout<<r*r<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

vector<long long> enum_divisors(long long N)
{
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i)
    {
        if (N % i == 0)
        {
            res.push_back(i);
            if (N / i != i)
                res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
int main()
{
    ll N;
    ll ans = 0;
    cin >> N;
    vector<ll> A(N + 1);
    vector<ll> B(N);
    for (int i = 0; i <= N;i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N;i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < N;i++)
    {
        if(A[i] > B[i]){
            A[i] -= B[i];
            ans += B[i];
        }
        else if(A[i] == B[i]){
            A[i] = 0;
            ans += B[i];
        }
        else{
            B[i] -= A[i];
            ans += A[i];
            A[i] = 0;

            if(A[i+1] <= B[i]){
                ans += A[i + 1];
                A[i + 1] = 0;
            }
            else{
                ans += B[i];
                A[i + 1] -= B[i];
            }
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
std::priority_queue<ll> q0;
std::priority_queue<ll, std::vector<ll>, std::greater<ll>> q1;
int l[maxn], r[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n; cin >> n; ll ans = 0, t0 = 0, t1 = 0;
	rep(i, 1, n) {
		cin >> l[i] >> r[i];
		if(i == 1) {
			q0.push(l[i]), q1.push(l[i]);
		} else {
			t0 -= r[i] - l[i], t1 += r[i - 1] - l[i - 1];
			int v0 = q0.top() + t0, v1 = q1.top() + t1;
			if(l[i] < v0) {
				ans += std::abs(v0 - l[i]);
				q1.push(v0 - t1); q0.pop();
				q0.push(l[i] - t0); q0.push(l[i] - t0);
			} else if(v1 < l[i]) {
				ans += std::abs(v1 - l[i]);
				q0.push(v1 - t0); q1.pop();
				q1.push(l[i] - t1); q1.push(l[i] - t1);
			} else {
				q0.push(l[i] - t0);
				q1.push(l[i] - t1);
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 2796
#include<iostream>
#include<sstream>
using namespace std;int n;int r(int a,int b,string s){a||cout<<s;for(int i=a<b?a:b;i>0;i--){stringstream t;t<<i<<(a-i?" ":"\n");r(a-i,i,s+t.str());}}main(){for(;cin>>n,n;)r(n,n,"");}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,L,R,a[maxn],b[maxn];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	reverse(b+1,b+1+n);
	for (int i=1;i<=n;i++)
		if (a[i]==b[i])
		{
			if (!L) L=i;
			R=i;
		}
	if (L)
	{
		int head=1,x=a[L];
		bool sol=true;
		for (int i=L;i<=R;i++)
		{
			while (head<=n && (a[head]==x || b[head]==x)) head++;
			if (head>n)
			{
				sol=false;
				break;
			}
			swap(b[head++],b[i]);
		}
		if (!sol)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	for (int i=1;i<n;i++) printf("%d ",b[i]);
	printf("%d\n",b[n]);
	return 0;
}


Measured memory_bytes: 5352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
ll MOD = pow(10, 9) + 7;

int getX(ll num, int d){
    int tmp = num >> d;
    return (tmp % 2);
}
ll powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

int main() {

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    ll ans = 0;
    REP(i, 60){
        ll tmp0 = 0, tmp1 = 0;
        for(auto iter : A){
            int tmp = getX(iter, i);
            tmp == 0 ? tmp0++ : tmp1++;
        }
        ll x = powmod(2, i, MOD);
        x = (x * tmp0) % MOD;
        x = (x * tmp1) % MOD;
        ans = (ans + x) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	int sum =-201;
	if(a+b>sum)
	  sum =a+b;
	if(a-b>sum)
	  sum =a-b;
	if(a*b>sum)
	  sum =a*b;
	printf("%d",sum);
	return 0;
 } 

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var dg = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var D = (int)dg[0];
        var G = dg[1];
        var list = new List<long[]>();
        for (int i=0;i<D;++i)
        {
            var pc= Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
            list.Add(new long[2] { pc[0], pc[1] });
        }
        var ans = long.MaxValue;
        for (int i = 0; i < (Math.Pow(2, D)); i++)
        {
            var count = 0L;
            var total = 0L;
            for (int j = 0; j < D; j++)
            {
                if ((1 & i >> j) == 1) {
                    count += list[j][0];
                    total += list[j][0] * 100 * (j + 1) + list[j][1];
                }
            }
            if (total < G)
            {
                for (int j = D - 1; 0 <= j; --j)
                {
                    if ((1 & i >> j) == 0)
                    {
                        var add = (G-total) / ((j + 1) * 100);
                        if (add <= list[j][0])
                        {
                            count+=add;
                            total += add * 100 * (j + 1);
                            if (G <= total)
                            {
                                ans = Math.Min(ans, count);
                                break;
                            }
                        }
                    }
                }
            }
            else ans=Math.Min(ans,count);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
h,w = map(int,input().split())
s=[]
dx=[1,0,-1,0,1,-1,-1,1]
dy=[0,1,0,-1,1,1,-1,-1]
for i in range(h):
    s.append(list(input()))
for y in range(h):
    for x in range(w):
        if(s[y][x]=="."):
            num = 0
            for d in range(8):
                nx = x+dx[d]
                ny = y+dy[d]
                if(nx<0 or w<=nx):
                    continue
                if(ny<0 or h<=ny):
                    continue
                if(s[ny][nx] == "#"):
                    num+=1
            s[y][x] = str(num)
for i in range(h):
    print("".join(s[i]))

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

#define MOD 1000000007
#define ll long long int 
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

template <typename T>
void printvec(vector<T>& vec)
{
    for(int i=0;i<vec.size();++i){
        cout<<vec[i]<<" ";
    }
    cout<<endl;

}

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
int main()
{   
    int n;cin>>n;

    int height[n+1], dp[n+1];

    for (int i = 0; i < n; ++i)
    {
      cin>>height[i+1];
    }

    dp[1] = 0;
    dp[2] = abs(height[2]-height[1]);

    for (int i = 3; i <= n; ++i)
    {
      dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]), dp[i-2]+abs(height[i]-height[i-2]));
    }

    cout<<dp[n];

    return 0;
}


Measured memory_bytes: 1024
import sys


#input
lines = [x.strip() for x in sys.stdin.readlines()]

def slv(lines):
    ans = 0
    s = int(lines[0].split()[1])
    k = int(lines[0].split()[0])

    for x in range(0,k+1):
        #print(x)
        for y in range(0,k+1):
            #print(x+y)
            if s-x-y <= k and s-x-y >= 0:
                ans += 1
            
    return ans

if __name__ == "__main__":
    print(slv(lines))

Measured memory_bytes: 3060
k,n=map(int,input().split())
a=list(map(int,input().split()))
unchi = [0]*n
for i in range(n-1):
	unchi[i] = a[i+1] - a[i]
unchi[n-1] = a[0] - a[n-1] + k
print(k-max(unchi))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
int MOD,p,a;
vector<int> fact, fact_inv, inv;
void init_nCk(int n){
  fact.resize(n+5);
  fact_inv.resize(n+5);
  inv.resize(n+5);
  fact[0]=fact[1]=1;
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for (int i=2;i<n+5;i++){
    fact[i]=fact[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
}
int nCk(int n,int k){
  assert(!(n<k));
  assert(!(n<0||k<0));
  return fact[n]*(fact_inv[k]*fact_inv[n-k]%MOD)%MOD;
}
int pow(int x,int y){//x^yを返す
  int tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
int main(){
  cin>>p;
  MOD=p;
  vector<int> a1(0);
  vector<int> ans(p);
  for(int i=0;i<p;i++){
    cin>>a;
    if(a==1){a1.push_back(i);}
  }
  init_nCk(p-1);
  for(int i=0;i<(int)a1.size();i++){
    ans.at(0)++;
    a=1;
    for(int j=p-1;j>=0;j--){
      ans.at(j)-=nCk(p-1,j)*a-p*p;
      ans.at(j)%=p;
      a*=-1*a1.at(i);
      a%=p;
    }
  }
  for(int i=0;i<p;i++){
    cout<<ans.at(i);
    if(i<p-1){cout<<" ";}
  }
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	ll k; cin >> k;
	cout << 50 << endl;
	for (int i = 0; i < 50; i++) {
		int val=0;
		if (i < k % 50) val = 1;
		cout << (49-i)+(k/50)+val;
		if (i != 49) cout << " ";
		else cout << endl;
	}
}


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

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << "a == b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a < b" << endl;
  }
}



Measured memory_bytes: 3100
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int n;
    cin >> n;
    vector<int> A(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    vector<vector<int>> graph(n);
    for (int i = 0; i + 1 < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }


    vector<int> sizes(n, 0);

    const long long INF = 1LL << 60;
    vector<vector<long long>> dp1(n);
    vector<vector<long long>> dp2(n);

    auto update = [&](vector<long long>& A, vector<long long>& B, vector<long long>& C, bool ok) {
        int n = A.size();
        int m = B.size();
        vector<long long> res (n + m - 1, INF);

        for (int i = 0; i < n; ++i) {
            if (A[i] >= INF) {
                continue;
            }
            for (int j = 0; j < m; ++j) {
                if (i + j - 1 >= 0) {
                    if (B[j] < INF) {
                        res[i + j - 1] = min(res[i + j - 1], A[i] + B[j]);
                    }
                    if (ok && C[j] < INF) {
                        res[i + j - 1] = min(res[i + j - 1], A[i] + C[j]);
                    }
                }
                if (B[j] < INF) {
                    res[i + j] = min(res[i + j], A[i]);
                }
                if (C[j] < 0) {
                    res[i + j] = min(res[i + j], A[i]);
                }
            }
        }
        return res;
    };


    function<void(int,int)> dfs = [&](int u, int p) {
        sizes[u] = 1;
        dp1[u].resize(sizes[u] + 1, INF);
        dp1[u][1] = A[u] > 0 ? A[u] : INF;
        dp2[u].resize(sizes[u] + 1, INF);
        dp2[u][1] = A[u];

        for (auto v : graph[u]) {
            if (v == p) {
                continue;
            }
            dfs(v, u);
            sizes[u] += sizes[v];
            dp1[u] = update(dp1[u], dp1[v], dp2[v], false);
            dp2[u] = update(dp2[u], dp1[v], dp2[v], true);
        }
        assert(dp1[u].size() == sizes[u] + 1);
        assert(dp2[u].size() == sizes[u] + 1);
    };

    dfs(0, -1);


    int res = n;
    for (int i = 1; i <= n; ++i) {
        if (dp1[0][i] < INF || dp2[0][i] < 0) {
            res = i - 1;
            break;
        }
    }

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

Measured memory_bytes: 164480
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    /*
    int t,n;
    cin>>t;
    loop(t1,1,t+1)
    {
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    string t;
    cin>>t;
    string ans = "";
    int n = t.length();
    loop(i,0,n)
    {
        if(t[i] != '?') ans += t[i];
        else
        {
            if((i && ans[i-1] == 'P')) ans += 'D';
            else if(i+1 < n && t[i+1] != 'P') ans += 'P';
            else ans += 'D';
        }
    }

    //int ans = tot - k;

    cout<<ans<<'\n';

    /*
    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3844
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int c[100005];

int  main() {

	int a[100010], ans[100010];

	fill(a, a + 100005, 1);
	a[0] = 0;
	a[1] = 0;

	for (int i = 2; i <= sqrt(100005); i++) {
		if (a[i] == 1) {
			for (int j = 2; i*j < 100005; j++) {
				a[i*j] = 0;
			}
			
		}
	}
	for (int i = 2; i <= 100005; i++) 
		if (a[i] && a[(i + 1) / 2])c[i]++;

	for (int i = 2; i <= 100005; i++)c[i] += c[i - 1];

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		cout << c[r] - c[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

DIV = 10**9+7

def mod_inv_prime(a,mod = DIV):
    return pow(a,mod-2,mod)

def mod_inv(a,b):
    r = a
    w = b
    u = 1
    v = 0
    while w!=0:
        t = r//w
        r -=t*w
        r,w = w,r
        u -= t*v
        u,v = v,u
    return (u%b+b)%b

def ncr(n,r, mod =DIV):
	r = min(r,n-r)
	ret = 1
	for i in range(1,r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N, M,K = ints_raw()
    ans = 0
    for d in range(1,N):
        ans =(ans+d*(N-d)*M*M)%DIV
    for d in range(1,M):
        ans =(ans+d*(M-d)*N*N)%DIV
    return (ans*ncr(N*M-2,K-2))%DIV

if __name__ =="__main__":
    print(main())


Measured memory_bytes: 40916
#include <bits/stdc++.h>
using namespace std;
const int mod  = 1e9+7;
// string grid[1001];
int dp[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int h,w;
  cin >> h >> w;
  h--; w--;
  for(int i=0;i<=1000;i++)
      dp[i] = 0;
  dp[1] = 1;
  string grid;
  for(int row=0;row<=h;row++) {
    cin >> grid;
    for(int col = 1;col<=w+1;col++) {
      if (grid[col-1] == '.') {
        dp[col] = (dp[col] + dp[col-1])%mod;
        // cerr << row << ' ' << col << '\n';
      } 
      else if (grid[col-1] == '#')
        dp[col] = 0;  
    }
  }
  //   for(int j=0;j<=1000;j++)

  // for(int row = h;row>=0;row--) {
    // cerr << "Row: " << row << '\n';
    // for(int i=0;i<=w;i++) cerr << dp[i] << ' ';
    // cerr << '\n';
  // }
  // for(int i=0;i<=h;i++) {
  //   for(int j=0;j<=w;j++) {
  //     cerr << dp[i][j] << ' ';
  //   }
  //   cerr << '\n';
  // }
  cout << dp[w+1];
  return 0;
}

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

const int MAX = 2e5 + 5;

int main() {
  int n, p, t[MAX], freq[MAX];
  string s;
  cin >> n >> p >> s;

  ll ans = 0;
  if (10 % p == 0) {
    rep(i,n) if ((s[i]-'0') % p == 0) ans += i+1;
  } else {
    reverse(s.begin(), s.end());
    int pw = 1;

    freq[0] = 1;
    for(int i = 0; i < n; i++) {
      int d = s[i] - '0';
      t[i] = (t[i - 1] + (pw * d) % p) % p;
      pw = pw * 10 % p;

      ans += freq[t[i]];
      freq[t[i]]++;
    }
  }

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


Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x){return power(x, MOD - 2);}
//const bool is_in = container.find(element) != container.end();
map<ll,ll> mp;

void factorize(ll n) 
{ 
    ll count = 0,i;   
    while (!(n % 2)) 
	{ 
        n>>=1; 
        count++; 
    } 
    if(count) 
        mp[2]+=count; 
    for (i=3;i<=sqrt(n);i+=2) 
	{ 
        count = 0; 
        while(n % i == 0) 
		{ 
            count++; 
            n=n/i; 
        } 
        if (count) 
            mp[i]+=count; 
    }  
    if(n>2) 
        mp[n]++; 
} 

int main()
{
	ll n,i;
	cin>>n;
	if(n==1)
	{
		cout<<0;
		return 0;	
	}
	factorize(n);
	ll ans = 0;
	vector<ll> v = {1,3,6,10,15,21,28,36,45,55,66};
	for(auto x : mp)
	{
		ll d = x.s;
		for(i=0;i<v.size();i++)
		{
			if(d>=v[i] && d<v[i+1])
			{
				ans+=(i+1);
				break;
			}
		}
	}
	cout<<ans;
}




Measured memory_bytes: 3724
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>

using namespace std;
int main() {
	vector<int> a(3);
	lp(i, 3)
		cin >> a[i];
	sort(a.begin(), a.end());
	cout << (a[2] * 10 + a[1]) + a[0] << endl;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if(x1 == 0) cout << 1 << endl;
    if(x2 == 0) cout << 2 << endl;
    if(x3 == 0) cout << 3 << endl;
    if(x4 == 0) cout << 4 << endl;
    if(x5 == 0) cout << 5 << endl;


    return 0;
}


Measured memory_bytes: 3592
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
  
    ll k,i,j,z,sum=0;
    cin>>k;
    for(i=1;i<=k;i++)
    {
    	for(j=1;j<=k;j++)
    	{
    		for(z=1;z<=k;z++)
    		{
    			sum += __gcd(i,__gcd(j,z));
    		}
    	}
    }
    cout<<sum;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    string s; cin >> s;
    int n = s.size();
    vector<int> ans(n,0);

    for(int i=0;i+1<n;i++){
        if(s[i] == 'R' and s[i+1] == 'L'){
            int r = 0;
            int l = 0;
            int j = i;
            while(j>=0 and s[j]=='R'){
                r++;
                j--;
            }
            j = i+1;
            while(j<n and s[j]=='L'){
                l++;
                j++;
            }

            int rc = (r+1)/2 + l/2;
            int lc = l+r-rc;
            ans[i] = rc;
            ans[i+1] = lc;
        }
    }
    for(auto v : ans){
        cout << v << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int n;
vector<string> s;
vector<int> color;

bool dfs(int v, int c) {
  color[v] = c;
  for (int i = 0; i < n; i++) {
    if (s[v][i] == '1') {
      if (color[i] == c)
        return false;
      if (color[i] == 0 && !dfs(i, -c))
        return false;
    }
  }
  return true;
}

bool is_bipartite() { return dfs(0, 1); }

int main() {
  cin >> n;
  s.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  color.assign(n, 0);
  if (!is_bipartite()) {
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int>> dis(n, vector<int>(n, 1 << 29));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s[i][j] == '1') {
        dis[i][j] = 1;
      }
    }
    dis[i][i] = 0;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      ans = max(ans, dis[i][j]);
    }
  cout << ans + 1 << endl;
}


Measured memory_bytes: 512
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

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

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let hw: Vec<usize> = util::gets();
    let h = hw[0];
    let w = hw[1];
    let _n: usize = util::get();
    let a: Vec<usize> = util::gets();

    let mut grid = vec![vec![0; w]; h];
    let mut x: isize = 0;
    let mut y: isize = 0;
    let mut d: isize = 1;
    for (i, &n) in (1..).zip(a.iter()) {
        for _ in 0..n {
            grid[y as usize][x as usize] = i;
            x += d;
            if x < 0 {
                x = 0;
                y += 1;
                d *= -1;
            } else if x >= w as isize {
                x = w as isize - 1;
                y += 1;
                d *= -1;
            }
        }
    }

    for line in &grid {
        println!(
            "{}",
            line.iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll H,W;
vector<string> table;

void solve() {
    cin >> H >> W;
    table.resize(H);
    rep(i,H) cin >> table[i];

    vector<vector<int>> row(H,vector<int>(W,0));
    vector<vector<int>> col(H,vector<int>(W,0));

    rep(i,H) {
        int start = 0;
        rep(j,W){
            if (table[i][j]=='#'){
                for (int n=start;n<j;n++){
                    row[i][n] = j-start;
                }
                start = j+1;
                continue;
            }
            if (j==W-1){
                for (int n=start;n<W;n++){
                    row[i][n] = W-start;
                }
            }
        }
    }

    rep(j,W){
        int start = 0;
        rep(i,H) {
            if (table[i][j]=='#'){
                for (int n=start;n<i;n++){
                    col[n][j]=i-start;
                }
                start = i+1;
                continue;
            }
            if (i==H-1){
                for (int n=start;n<H;n++){
                    col[n][j]=H-start;
                }
            }
        }
    }

    int ans =0;

    rep(i,H) {
        rep(j,W) {
            ans = max(ans,row[i][j]+col[i][j]-1);
        }
    }

    cout << ans;

	return;
}

int main() {

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 35712
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main
{
	static void merge(int arr[], int l, int m, int r) 
    { 
        int n1 = m - l + 1; 
        int n2 = r - m; 
        int L[] = new int [n1]; 
        int R[] = new int [n2]; 
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
        int i = 0, j = 0; 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
    static void sort(int arr[], int l, int r) 
    { 
        if (l < r) 
        { 
            int m = (l+r)/2; 
            sort(arr, l, m); 
            sort(arr , m+1, r); 
            merge(arr, l, m, r); 
        } 
    } 
    public static int lowerBound(int[] array, int length, int value) 
	{
        int low = 0;
        int high = length;
        while (low < high) 
        {
            final int mid = (low + high) / 2;
            //checks if the value is less than middle element of the array
            if (value <= array[mid]) 
            {
                high = mid;
            } 
            else 
            {
                low = mid + 1;
            }
        }
        return low;
    }
	public static int upperBound(int[] array, int length, int value) 
	{
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
    static long power(long n,long m)
    {
    	if(m==0)
    		return 1;
    	long ans=1;
    	while(m>0)
    	{
    		ans=ans*n;
    		m--;
    	}
    	return ans;
    }
    static int BinarySearch(int arr[], int x) 
    { 
        int l = 0, r = arr.length - 1; 
        while (l <= r) { 
            int m = l + (r - l) / 2; 
            if (arr[m] == x) 
                return m; 
            if (arr[m] < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return -1; 
    } 
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
	    String s=br.readLine();
        String str[]=s.split(" ");
        int n=Integer.parseInt(str[0]);
        int m=Integer.parseInt(str[1]);
		for(int i=n;i<=m;i++)
	    {
			if(i%t==0)
	        {
				System.out.println("OK");
				return;
	        }
	    }
		System.out.println("NG");
	}
}


Measured memory_bytes: 32324
# 貪欲法 + 山登り法 + スワップ操作 + アニーリング
import time
s__ = time.time()
limit = 1.9
#limit = 10

from numba import njit
import numpy as np

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8(i8, i8[:], f8)', cache=True)
def loop(mxsc, ts, tmpr):
    it = 50
    rds = np.random.randint(0, 4, (it,))
    rdd = np.random.randint(1, d, (it,))
    rdq = np.random.randint(1, 26, (it,))
    rdx = np.random.randint(1, 12, (it,))
    for i in range(it):
        bk1 = 0
        bk2 = 0
        if rds[0] == 0:
            # trailing
            di = rdd[i]
            qi = rdq[i]

            bk1 = ts[di]
            ts[di] = qi
        else:
            # swap
            di = rdd[i]
            xi = rdx[i]
            if di + xi >= d:
                xi = di - xi
            else:
                xi = di + xi
            
            bk1 = ts[di]
            bk2 = ts[xi]
            ts[di] = bk2
            ts[xi] = bk1

        sc = total_satisfaction(ts, d)

        delta = sc - mxsc
        if delta > 0:
            #print('d>0', mxsc, '->', sc)
            mxsc = sc
        else:
            # Random < e^(Δ/T) の場合も更新
            exp = np.exp(delta / tmpr)
            #if i == 0:print('delta=', delta, 'tmpr=', tmpr, exp)
            r = np.random.random()
            if r <= exp:
                #print('d<0', mxsc, '->', sc, delta, tmpr, exp)
                mxsc = sc
            else:
                # 戻す
                if rds[0] == 0:
                    ts[di] = bk1
                else:
                    ts[di] = bk1
                    ts[xi] = bk2

    return mxsc

@njit('i8[:]()', cache=True)
def greedy():
    ts = np.array([0] * d, dtype=np.int64)
    for i in range(d):
        mx = -1e10
        mxt = None
        for t in range(1, 26+1):
            ts[i] = t
            s = total_satisfaction(ts, i + 1)
            if s > mx:
                mx = s
                mxt = t
        ts[i] = mxt
    return ts

ts = greedy()
#ts = np.random.randint(1, 26, (d,)).astype(np.int64)
mxsc = total_satisfaction(ts, d)
mxbk = mxsc

# annealing vars
t0 = 2e3
t1 = 6e2

s_ = time.time()
mxsc = loop(mxsc, ts, t0)
e_ = time.time()

consume = s_ - s__
elapsed = e_ - s_
#print('consume:', consume)
#print('elapsed:', elapsed)

if consume < limit:
    lp = int((limit - consume) / elapsed)
    for i in range(lp):
        t = i / lp
        tmpr = np.power(t0, 1 - t) * np.power(t1, t)
        mxsc = loop(mxsc, ts, tmpr)
        #print(mxsc)

for t in ts:    print(t)
#print(mxbk, mxsc)
#print(time.time() - s__)
#print(mxsc)


Measured memory_bytes: 123224
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> P(N),Q(N);
  for(int i=0; i<N; i++){
    cin >> P[i];
  }
  for(int i=0; i<N; i++){
    cin >> Q[i];
  }
  vector<int> X(N);
  for(int i=1; i<=N; i++){
    X[i-1] = i;
  }
  int a,b;
  int cnt=0;
  do{
    cnt++;
    bool canP,canQ;
    canP = canQ = true;
    for(int i=0; i<N; i++){
      if(P[i] != X[i]){
        canP = false;
      }
      if(Q[i] != X[i]){
        canQ = false;
      }
    }
    if(canP){
      a = cnt;
    }
    if(canQ){
      b = cnt;
    }
  }while(next_permutation(X.begin(),X.end()));
  cout << abs(a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    ll a[200010]; INITA(a, 0, 200000, 0);
    ll c[200010]; INITA(c, 0, 200000, 0);

    REP(i, n) {
        cin >> a[i];
        c[a[i]]++;
    }
    ll tot = 0;
    FOR(i, 1, n) {
        if (c[i] != 0) {
            tot += c[i] * (c[i] - 1) / 2;
        }
    }
    REP(i, n) {
        cout << tot - (c[a[i]] - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;


int mass[10];
int N;
int A,B,C;vector<int> vec;
int ans = 1e9;
int calc(){
    int _A = 0,_B = 0,_C = 0;
    int w = 0;
    for(int a = 0;a < N;a++){
  //      cout<<mass[a]<<" ";
        if(mass[a] == 1)_A += vec.at(a);
        if(mass[a] == 2)_B += vec.at(a);
        if(mass[a] == 3)_C += vec.at(a);
        if(mass[a] == 0)w++;
    }
 //   cout<<endl;
    if(_A == 0 || _B == 0 || _C == 0)return 1e9;
    return abs(_A-A)+abs(B-_B)+abs(C-_C)+((N-w)-3)*10;
}
int rekkyo(int i){
    if(N == i){
        ans = min(ans,calc());
        return 0;
    }
    mass[i] = 0;rekkyo(i+1);
    mass[i] = 1;rekkyo(i+1);
    mass[i] = 2;rekkyo(i+1);
    mass[i] = 3;rekkyo(i+1);
}
int main(){
    cin >> N;
    cin >> A >> B >> C;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    rekkyo(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n, m;
	std::cin >> n >> m;

	int food[31] = {};
	int k;
	int a;
	int sum = 0;

	for (int i = 0; i < n; i++) {
		std::cin >> k;
		for (int j = 0; j < k; j++) {
			std::cin >> a;
			food[a]++;
			if (food[a] == n)
				sum++;
		}
	}

	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long ans = 0;
    int a = 0;
    set<int> x;
    for (int i = 0; i < 20; i++) {
        if ((1 << i) & A[0]) {
            x.insert(i);
        }
    }
    for (int l = 0; l < N; l++) {
        a = max(l, a);
        for (int i = 0; i < 20; i++) {
            if ((1 << i) & A[l]) {
                x.insert(i);
            }
        }
        for (int r = a+1; r < N; r++) {
            bool f = 1;
            for (int i = 0; i < 20; i++) {
                if ((1 << i) & A[r]) {
                    if (x.find(i) != x.end()) {
                        f = 0;
                        break;
                    }
                }
            }
            if (f == 0) {
                break;
            }
            a++;
            for (int i = 0; i < 20; i++) {
                if ((1 << i) & A[r]) {
                    x.insert(i);
                }
            }
        }
        for (int i = 0; i < 20; i++) {
            if ((1 << i) & A[l]) {
                x.erase(i);
            }
        }
        ans += a-l+1;
    }
    cout << ans << endl;
}

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

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


void fio()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | FUNCTIONS | --------------------------------------///

/*
const int N = 2e5 + 5;

vector<int> adj[N];
bool visited[N];
//int val[N];
int depth[N];
//int parent[N];

void dfs(int v)
{
	visited[v] = true;
	for (int u : adj[v])
	{
		if (!visited[u])
		{
			//parent[u] = v;
			depth[u] = depth[v] + 1;
			dfs(u);
		}
	}
}
*/

// left shift << multiply by 2
// right shift >> divide by 2

///----------------------------- | START FROM HERE | --------------------------------------///

//#define int long long //change int main to int32_t main


void solve()
{
	int n; cin >> n;
	int h[n + 5];
	fr0(i, n) cin >> h[i + 1];
	int dp[n + 5];
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	dp[3] = abs(h[3] - h[1]);
	fr(i, 4, n + 1)
	{
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n] << nl;


}





int main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	//fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	//TIME(start, end);
	return 0;
}




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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int x, y;
    scanf("%d %d", &x, &y);

    if(y > x) {
        swap(x,y);
    }
    int z;
    while(true) {
        z = x%y;
        if (z == 0){
            printf("%d\n",y);
            return 0;
        }
        x = y;
        y = z;
    }
}


Measured memory_bytes: 3192
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    return gcd of a,b
    ユークリッド
    """
    a,b =max(a,b),min(a,b)
    while b:
        a, b = b, a % b
    return a



K = int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        i_j = gcd(i,j)
        for k in range(1,K+1):
            ans+=gcd(i_j,k)
print(ans)



Measured memory_bytes: 68808
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define INF 2e10
typedef long long llong;
using namespace std;

int main(){
	int a,b,q;
	cin>>a>>b>>q;
	llong s[100002],t[100002];
	for(int i=1;i<=a;++i) cin>>s[i];
	for(int i=1;i<=b;++i) cin>>t[i];
	s[0]=-INF,s[a+1]=INF;
	t[0]=-INF,t[b+1]=INF;
	
	REP(i,q){
		llong x;
		cin>>x;
		
		auto itr_s=lower_bound(s,s+a+1,x);
		auto itr_t=lower_bound(t,t+b+1,x);
		
		llong ans=INF; 
		ans=min(ans,max(*itr_s,*itr_t)-x);//最適の神社と寺がともに東にある時.
		ans=min(ans,x-min(*(itr_s-1),*(itr_t-1)));//最適の神社と寺がともに西にある時.
		ans=min(ans,*(itr_t)-*(itr_s-1)+min(x-*(itr_s-1),*(itr_t)-x));//西に神社、東に寺.
		ans=min(ans,*(itr_s)-*(itr_t-1)+min(x-*(itr_t-1),*(itr_s)-x));//西に寺、東に神社.
		
		cout<<ans<<endl;
	}
}//解説参考.

Measured memory_bytes: 2816
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0);def f(i)r=0;H[i].map{|e|f e}.sort.map{|e|r=[r,e].max+1};r end;H=Hash.new{|h,k|h[k]=[]};2.upto(gets.to_i){|i|H[gets.to_i]<<i};p f 1

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

int main() {
  string S;
  cin >> S;
  for(int i = 0; i < ((S.size() - 1) / 2); i++) {
    if(S.at(i) != S.at(S.size() - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  string S2 = S.substr(0, (S.size() - 1) / 2);
  for(int i = 0; i < S2.size(); i++) {
    if(S2.at(i) != S2.at(S2.size() - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  string S3 = S.substr((S.size() + 3) / 2 - 1);
  for(int i = 0; i < S3.size(); i++) {
    if(S3.at(i) != S3.at(S3.size() - 1 - i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
ans = 0
index = 0
C = sorted(AB,key = lambda x:x[0])
while M > 0:
    if C[index][1] < M:
        ans += C[index][1]*C[index][0]
        M -= C[index][1]
        index += 1
    else:
        ans += M*C[index][0]
        M = 0
print(ans)

Measured memory_bytes: 30824