akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int64 n,k; cin >> n >> k;
		int64 r = n - k;
		int64 nk = k;
		COMinit();
		for (int i = 1; i <= k; ++i) {
			//一列に並んだ赤いボールと赤いボールの間、右端、左端に青いボールを置くことを考える
			//場所の選び方はn - k + 1 C i通り
			int64 p = COM(n - k + 1, i);
			//選んだ場所に青いボールを何個選ぶかを考える
			//最低一つ割り当てる必要があるため、k - 1 C i - 1通り
			int64 q = COM(k - 1, i - 1);
			cout << (p * q) % MOD << endl;
		}
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 5120
#include <cstdio>
 using namespace std;
 int main(){
 
     long long s;
     long long c;
     long long ans;
     scanf("%lld %lld",&s,&c);
     if(s*2>c){
         ans=c/2;
     }else{
         c-=s*2;
         ans=s;
         ans+=c/4;
     }   
     printf("%lld\n",ans);
     return 0;
 }

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int i,a[110],k=0,ans=0,mx=-1;
	while(scanf("%d",&a[k])!=EOF)
	{
		ans+=a[k];
		k++;
	}
	k--;
	for(i=0;i<k;i++)
		mx=max(mx,a[i]);
	ans-=(mx+a[k]);
	int tmp=1;
	for(i=0;i<a[k];i++)
		tmp*=2;
	cout<<tmp*mx+ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;//cost, v;
typedef struct edge{
  int to, cost;
}edge;

int main(){
  int n, m, k;
  std::cin >> n >> m >> k;
  vector<int> dp(n, 1e9);
  vector<edge> g[n];
  for (int i = 0; i < m; i++) {
    int to, from, cost;
    std::cin >> to >> from >> cost;
    to--;from--;
    g[from].push_back((edge){to, cost});
    g[to].push_back((edge){from, cost});
  }
  priority_queue<pii, vector<pii>, greater<pii> > que;
  for (int i = 0; i < k; i++) {
    int a;
    std::cin >> a;
    a--;
    que.push(pii(0, a));
    dp[a] = 0;
  }
  while(not que.empty()){
    int v = que.top().second;
    int cost = que.top().first;
    que.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int nv = g[v][i].to;
      if(dp[nv] > cost + g[v][i].cost){
        dp[nv] = cost + g[v][i].cost;
        que.push(pii(dp[nv], nv));
      }
    }
  }
  double ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      bool flag = false;
      double cost;
      for (int k = 0; k < g[i].size(); k++) {
        if(g[i][k].to == j){
          flag = true;
          cost = g[i][k].cost;
        }
      }
      if(flag == false)continue;
      int diff = abs(dp[i] - dp[j]);
      double l = (cost + diff)/2.0;
      if(0 <= l and l < cost){
        ans = max(ans, min(dp[i], dp[j]) + l);
      }else{
        ans = max(ans, min(dp[i], dp[j]) + cost);
      }
    }
  }
  std::cout << ceil(ans) << std::endl;
  return 0;
}

Measured memory_bytes: 4288
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, k, q;
    cin >> n >> k >> q;
    int a[q];
    rep(i, q) { cin >> a[i]; }

    int b[n] = {};
    rep(i, q) { b[a[i] - 1]++; }
    rep(i, n) { b[i] = k - q + b[i]; }

    rep(i, n) {
        if (b[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 1408
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            int d = a/b;
            int r = a%b;
            double f = (double)a/(double)b;

            System.out.print(d+" "+r + " ");
            System.out.printf("%.5f\n",f);
		}
	}
}



Measured memory_bytes: 26448
def main():
    A, B = map(int, input().split())
    while B!= 0: 
        A, B = B, A % B 
    print(num_prime_factor(A))

def num_prime_factor(n):
    
    if n == 1: return 1
    
    ret = 1
    cursor = 2
    if n % cursor == 0: 
        ret += 1
    while n % cursor == 0: 
        n = n // cursor
    
    cursor = 3
    while cursor**2 <= n:
        if n == 1: 
            return ret
        if n % cursor == 0: 
            ret += 1
        while n % cursor == 0: 
            n = n // cursor
        cursor += 2

    if n != 1: 
        ret += 1
        
    return ret

if __name__ == "__main__":
    main()

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

int power(int x, int y) {
    if (y == 0) return 1;
    if (y & 1) return (x * power(x, y - 1));
    int t = power(x, y / 2);
    return (t * t);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> ar(n);
    for(int i = 0; i < n; i++)
        cin >> ar[i];
    sort(allr(ar));
    // print(ar);
    int ans = 0;
    int k = 0;
    for(int i = 1; i < n; i++)
    {
        if(i & 1)
            k++;
        ans += ar[i - k];
    }
    cout << ans << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 4764
def examC():
    N = I()
    St = [S() for _ in range(N)]
    d = defaultdict(int)
    ans = 0
    march = ["M","A","R","C","H"]
    for s in St:
        if s[0] in march:
            d[s[0]] +=1
    if len(d)>=3:
        for comb in itertools.permutations(march):
            ans += d[comb[0]]*d[comb[1]]*d[comb[2]]
        ans //=12
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 48220
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(in.readLine());
    String s = in.readLine();
    
    if(s.length()<=k)
      System.out.println(s);
    else
      System.out.println(s.substring(0,k) + "...");
  }
}

Measured memory_bytes: 36276
#include<cstdio>
using namespace std;
const int maxn=1e5+2;
int n,l,pos;
int a[maxn];
int main(){
	scanf("%d%d",&n,&l);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i-1]+a[i]>=l) pos=i-1;
	}
	if (!pos) printf("Impossible\n");
	else{
		printf("Possible\n");
		for (int i=1;i<pos;i++) printf("%d\n",i);
		for (int i=n-1;i>=pos;i--) printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1152
N, M = map(int, input().split())
l = []
r = []
for i in range(M):
    L, R = map(int, input().split())
    l.append(L)
    r.append(R)
m = min(r) - max(l)
if m < 0:
    print(0)
else:
    print(m + 1)

Measured memory_bytes: 16744
#include<iostream>
using namespace std;
int main()
{
    int N,n=0;
    cin>>N;
    for(int i=1;i<=N;i+=2)
    {
        int divisor=0;
        for(int j=1;j<=N;j++)
        {
            if(i%j==0)
            {
                divisor++;
            }
        }
        if(divisor==8)
        {
            n++;
        }
    }
    cout<<n<<endl;
    return 0;
}



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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


int main() {
    string s;
    int w;
    cin >> s >> w;
    for (int i = 0; i < s.size(); i += w) {
        cout << s[i];
    }
    cout << endl;
}


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

typedef long long ll;

int main(){    
    ll A,B,C;
    cin >> A >> B >> C;
    if(A == B && B == C){
        if(A%2 == 0){
            cout << -1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        int ans = 0;
        ll A1,B1,C1;
        while(A%2==0 && B%2 == 0 && C%2 == 0){
            A1 = (A+B)/2;
            B1 = (A+C)/2;
            C1 = (B+C)/2;
            ans += 1;
            A = A1;
            B = B1;
            C = C1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

vector<string> getGroups(string s) {
    vector<string> ret;
    string t = "";
    int index = 0;
    while (s[index] != ':')t += s[index++];
    ret.push_back(t);
    t = "";
    index++;
    while (s[index] != '.') {
        if (s[index] == ',') {
            ret.push_back(t);
            t = "";
        } else {
            t += s[index];
        }
        index++;
    }
    if (t.size() > 0) ret.push_back(t);

    return ret;
}

void bfs(map<string, vector<string>> &M, set<string> &S, map<string, bool> &B, string key) {
    if (B[key]) return;
    if (M[key].size() == 0) S.insert(key);
    else {
        auto next = M[key];
        B[key] = true;
        for (int i = 0; i < next.size(); i++) bfs(M, S, B, next[i]);
    }
}

int main() {

    while (true) {

        int N;
        cin >> N;

        if (N == 0) break;

        vector<string> groups(N);
        for (int i = 0; i < N; i++) cin >> groups[i];

        map<string, vector<string>> M;
        for (int i = 0; i < N; i++) {
            auto ret = getGroups(groups[i]);
            for (int j = 1; j < ret.size(); j++) M[ret[0]].push_back(ret[j]);
        }

        string key = getGroups(groups[0])[0];
        set<string> S;
        map<string, bool> B;

        bfs(M, S, B, key);

        cout << S.size() << endl;

    }

    return 0;
}












































































Measured memory_bytes: 3440
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;

struct Data{
    int dep,lastmove[2];
    stack<int> s[3];
};
bool memo[14348908] = {};

int int_pow(int n,int m){
    int ans = 1;
    while(m--){
        ans *= n;
    }
    return ans;
}

int main(){
    int hoge,n;
    while(cin>>hoge>>n,n || hoge){
        for(int i=0;i<14348908;i++) memo[i] = false;
        Data q_c,q_d,first;
        int m,input,nt,cup,cntempty,state;
		bool flag;
        int situ[2] = {-1,1};
        queue<Data> q;
        for(int i=0;i<3;i++){
            cin>>m;
            for(int j=0;j<m;j++){
                cin>>input;
                first.s[i].push(input);
            }
        }
        first.dep = 0;first.lastmove[0] = -1;first.lastmove[1] = -1;
        q.push(first);
        flag = false;
        while(!q.empty()){
            q_c = q.front();
            q.pop();
            /*if(q_c.dep%1000 == 0){
                printf("%d\n",q_c.dep);
            }*/
            //for(int i=0;i<3;i++) printf("%d ",!q_c.s[i].empty());
            //puts("");
            if(q_c.dep == n) break;
            cntempty = 0;
            for(int i=0;i<3;i++){
                if(!q_c.s[i].empty()){
                    if(i == 1){
                        cntempty = 0;
                        break;
                    }
                    cntempty++;
                }
            }
            if(cntempty == 1){
                printf("%d\n",q_c.dep);
                flag = true;
                break;
            }
            q_d = q_c;
            state = 0;
            for(int i=0;i<3;i++){
                while(!q_d.s[i].empty()){
                    cup = q_d.s[i].top();
                    q_d.s[i].pop();
                    state += i*int_pow(3,cup-1);
                }
            }
            if(memo[state]) continue;
            memo[state] = true;
            //printf("%d\n",state);
            for(int i=0;i<3;i++){
                for(int j=0;j<2;j++){
                    nt = i+situ[j];
                    if(nt<0 || 3<=nt) continue;
                    q_d = q_c;
                    if((q_c.lastmove[1]==i && q_c.lastmove[0]==nt)
                       || q_d.s[i].empty()) continue;
                    cup = q_d.s[i].top();
                    q_d.s[i].pop();
                    if(!q_d.s[nt].empty() && cup < q_d.s[nt].top()) continue;
                    q_d.s[nt].push(cup);
                    q_d.dep++;
                    q_d.lastmove[0] = i;q_d.lastmove[1] = nt;
                    q.push(q_d);
                }
            }
        }
        if(!flag) printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 15236
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
vector<ll>v[100005];
ll dp[100005][2],n,arr[200005];

ll dfs(ll x,ll y,ll parent)
{
	ll i,sum=1;
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(v[x].size()==1&&v[x][0]==parent)
		return 1;
	if(y==0)
	{
		for(i=0;i<v[x].size();i++)
		{
			if(v[x][i]!=parent)
				sum=(sum*dfs(v[x][i],1,x))%MOD;
		}
	}	
	if(y==1)
	{
		for(i=0;i<v[x].size();i++)
		{
			if(v[x][i]!=parent)
				sum=(sum*((dfs(v[x][i],0,x)+dfs(v[x][i],1,x))%MOD))%MOD;
		}
	}
	dp[x][y]=sum%MOD;
	return sum%MOD;
}

int main()
{
	ll i,a,b;
	boost
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(i=1;i<n;i++)
	{
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	cout<<(dfs(1,0,0)+dfs(1,1,0))%MOD;
	return 0;
}

Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <algorithm>
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 MaxNum = 0;
    for (int i = 0; i < N; i++)
    {
        //MaxNumを使い回すことで計算を抑える
        MaxNum = max(MaxNum, A[i]);
        int Bi = MaxNum;
        ans += Bi - A[i];
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 3960
import sys
input = sys.stdin.readline

n, m = [ int(v) for v in input().split() ]
num = [ int(v)-1 for v in input().split() ]
parent_list = [ i for i in range(n) ]

def root(x):
    while parent_list[x] != x:
        parent_list[x] = parent_list[parent_list[x]]  
        x = parent_list[x]   
    return x

for i in range(m):
    a, b = [ int(v)-1 for v in input().split() ]
    ra, rb = root(a), root(b)
    if ra != rb:
        parent_list[ra] = rb
        
ans_list = []
for i, v in enumerate(num):
    if root(i) == root(v):
        ans_list.append(True)
    else:
        ans_list.append(False)

print(ans_list.count(True))


Measured memory_bytes: 62044
#include<iostream>

using namespace std;

int main()
{
	int week,money = 100000;
	cin >> week;

	for(int ix = 0;ix != week;++ix){
		money *= 1.05;
		money += money%1000!=0 ? 1000: 0;
		money -= money%1000;
	}
	cout <<money<<endl;

	return 0;	
}

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


typedef long long ll;
int N, A[101010];
//-----------------------------------------------------------------
bool chk(int idx) {
	queue<int> que;
	rep(i, 0, N) if (i != idx) que.push(A[i]);

	ll size = A[idx];
	while (!que.empty()) {
		int q = que.front();
		que.pop();

		if (size * 2 < q) return false;
		size += q;
	}

	return true;
}
//-----------------------------------------------------------------
int sol() {
	sort(A, A + N);

	if (chk(0)) return N;

	int lo = 0, hi = N;
	while (lo + 1 != hi) {
		int mi = (lo + hi) / 2;
		if (chk(mi)) hi = mi;
		else lo = mi;
	}

	return N - hi;
}
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &A[i]);
	
	cout << sol() << endl;
}

Measured memory_bytes: 1096
#include<stdio.h>

int main(){

	int a, b;

	scanf("%d %d", &a, &b);

	if (a < b){

		printf("a < b\n");
	}
	if (a > b){

		printf("a > b\n");

	}
	if (a==b){

		printf("a == b\n");

	}

	return 0;

}


Measured memory_bytes: 2104
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;
int n,m;
vector<vector<int>> G,GG;
vector<int> dp;

int solve(int i){
    if(dp[i]!=-1)return dp[i];
    int res = 0;
    for(auto k:G[i])res=max(res,solve(k)+1);
    dp[i] = res;
    return res;
}


int main(int argc, char const *argv[]) {
    cin>>n>>m;
    m += n-1;
    G = vector<vector<int>>(n);
    GG = vector<vector<int>>(n);
    dp = vector<int>(n,-1);
    for(int i=0;i<m;++i){
        int u,v;cin>>u>>v;
        u--;
        v--;
        G[u].push_back(v);
        GG[v].push_back(u);
    }
    int res = 0;
    for(int i=0;i<n;++i)res = max(res,solve(i));
    vector<int> ress(n,0);
    for(int i=0;i<n;++i){
        int mi = 1ll<<30;
        for(int k:GG[i])if(mi>dp[k]){
            mi=dp[k];
            ress[i] = k+1;
        }
    }
    for(int i=0;i<n;++i)cout<<ress[i]<<endl;
    return 0;
}


Measured memory_bytes: 15744
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String S;
        char[] ch = new char[11];
        
        S = sc.next();
        ch = S.toCharArray();
        for(int i=0;i<4;i++){
        	System.out.print(ch[i]);
        }
        System.out.print(" ");
        for(int i=4;i<12;i++){
        	System.out.print(ch[i]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 10064
n = int(input())
mod = 1000000007
def pow(a,n):
    if n == 0:
        return 1
    if n % 2 == 0:
        tmp = pow(a, n//2)
        return (tmp * tmp) % mod
    else:
        tmp = pow(a, n//2)
        return (a * tmp ** 2) % mod

all_pos = pow(10, n)
no_9 = pow(9, n)
no_0 = no_9
no_90 = pow(8,n)

ans = (all_pos - no_9 - no_0 + no_90) % mod
print(ans)


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int max = 0, min = 1e9;

    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        if(max < x) max = x;
        if(min > x) min = x;
    }cout << max - min;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
typedef long long ll;
int L[2000][2000];
int R[2000][2000];
int U[2000][2000];
int D[2000][2000];
int h,w;

int main() {
  cin >> h >> w;
  vector<string> MAP(h);
  rep(i,h) cin >> MAP[i];

  rep(i,h) {
    rep(j,w) {
      if (MAP[i][j] == '#') continue;
      if (j==0) L[i][j] = 1;
      else L[i][j] = L[i][j-1] + 1;
      if (i==0) U[i][j] = 1;
      else U[i][j] = U[i-1][j] + 1;
    }
  }
  repr(i,h-1) {
    repr(j,w-1) {
      if (MAP[i][j] == '#') continue;
      if (j==w-1) R[i][j] = 1;
      else R[i][j] = R[i][j+1] + 1;
      if (i==h-1) D[i][j] = 1;
      else D[i][j] = D[i+1][j] + 1;
    }
  }
  int ans = 0;
  rep(i,h) rep(j,w) {
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
  }
  cout << ans;
}


Measured memory_bytes: 66816
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE

	sc2(x,y);
	if((abs(x-y))%2!=0)pr("IMPOSSIBLE");
	else pr(min(x,y)+(abs(x-y))/2);
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 764
import numpy as np

h, w, m = map(int, input().split())

x_list = [0 for i in range(w)]
y_list = [0 for i in range(h)]

target = [set() for i in range(h)]

for i in range(m):
    hi, wi = map(int, input().split())
    y_list[hi-1] += 1
    x_list[wi-1] += 1
    target[hi-1].add(wi-1)


y_max = max(y_list)
y_max_list = np.where(np.array(y_list) == y_max)[0]
x_max = max(x_list)
x_max_list = np.where(np.array(x_list) == x_max)[0]

minus = True

for y in y_max_list:
    for x in x_max_list:
        if x in target[y]:
            continue
        else:
            minus = False
            break

if minus:
    print(y_max + x_max - 1)
else:
    print(y_max + x_max)


Measured memory_bytes: 132932
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final int[] cards = new int[n];

        for (int i = 0; i < n; i++) {
            cards[i] = scanner.nextInt();
        }

        Arrays.sort(cards);
        final Cs[] cs = new Cs[m];
        final Main d = new Main();

        for (int i = 0; i < m; i++) {
            cs[i] = d.new Cs(scanner.nextInt(), scanner.nextInt());
        }

        Arrays.sort(cs, Comparator.reverseOrder());

        int counter = 0;

        for(int i = 0;i<m;i++){
            final int c = cs[i].getNum();
            final int ati = cs[i].getAtai();
            boolean f = false;
            for(int j = 0;j<c;j++){
                if (counter >= n || cards[counter] >= ati) {
                    f = true;
                    break;
                }

                cards[counter] = ati;
                counter++;
            }
            if(f){
                break;
            }
        }

        long result = 0;
        for (final int card : cards) {
            result += card;
        }

        System.out.println(result);
    }

    class Cs implements Comparable<Cs> {
        private final int num;
        private final int atai;

        public Cs(final int num, final int atai) {
            this.num = num;
            this.atai = atai;
        }

        public int getNum() {
            return num;
        }

        public int getAtai() {
            return atai;
        }

        @Override
        public int compareTo(final Cs cs) {
            return this.atai - cs.atai;
        }
    }
}


Measured memory_bytes: 91868
#include <stdio.h>

int main(void) {
	int D, N;
	int answer = 1;
	int i;
	if (scanf("%d%d", &D, &N) != 2) return 1;
	for (i = 0; i < D; i++) answer *= 100;
	printf("%d\n", (N == 100 ? 101 : N) * answer);
	return 0;
}


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

int main(){
  int64_t S;
  cin >> S;

  int64_t L= int64_t(sqrtl(S));
  assert(L*L <= S);

  int64_t x0,y0,x1,y1,x2,y2;
  if(S==L*L){
    x0= 0; y0= 0;
    x1= L; y1= 0;
    x2= 0; y2= L;
  }
  else if(S <= L*L+ L){
    x0= 0; y0= 1;
    x1= L; y1= 0;
    x2= S- L*L; y2= L+1;
  }
  else{
    x0= 0;   y0= 0;
    x1= L+1; y1= 1;
    x2= (L+1)*(L+1)- S; y2= L+1;
  }

  cout << x0 <<" "<< y0 <<" "<< x1 <<" "<< y1 <<" "<< x2 <<" "<< y2 << endl;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int main() {

	FAST;

	string s;
	cin >> s;
	int ans = 0, cur = 0;
	for (int i = 0; i < 3; i ++) {
		if (s[i] == 'R') cur ++;
		else {
			ans = max(ans, cur);
			cur = 0;
		}
	}
	ans = max(ans, cur);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}



int main(){
    // Failed to predict input format
    ll N,K;
    cin >>N>>K;
    vector<ll> A(N);
    for (long long i = 0; i < N; i++) {
        cin >>A[i];
    }
    // vout(A);
    vector<bool> visit(N);
    vector<ll> v;
    ll cur=0;
    // v[0]=1;
    // visit[0]=true;
    if(K<=N){
        for (long long i = 0; i < K; i++) {
            cur=A[cur]-1;
        }
        cout << cur+1 << endl;
        return 0;
    }
    while(1){
        if(visit[cur]==true){
            break;
        }
        v.push_back(cur);
        visit[cur]=true;
        cur=A[cur]-1;
    }
    // ll inter=cur;
    auto it=find(all(v), cur);
    ll inter=distance(v.begin(), it);
    ll to_inter=inter;
    ll from_inter=v.size()-to_inter;
    // debg(to_inter);
    // debg(from_inter);
    // vout(v);
    if(to_inter==0){
        // K-=to_inter;
        ll r=K%from_inter;
        cout << v[r]+1 << endl;
    }else{
        K-=to_inter;
        // debg(K);
        ll r=(K)%from_inter;
        // debg(r);
        // vector<ll> t=vector(v.begin()+to_inter, v.end());
        // vout(t);
        cout << v[to_inter+r]+1 << endl;
        // cout << t[r]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	string t=s;
	reverse(t.begin(),t.end());
	if(s==t)
	{
		string e="";
		for(int i=0;i<n/2;i++)
		{
			e+=s[i];
		}
		string e2=e;
		reverse(e2.begin(),e2.end());
		if(e2==e)
		{
			string y="";
			n+=3;
			for(int i=n/2-1;i<n-3;i++)
			{
				y+=s[i];
			}
			string y2=y;
			reverse(y2.begin(),y2.end());
			if(y2==y)
			{
				cout<<"Yes";
			}
			else
			{
				cout<<"No";
			}
		}
		else
		{
			cout<<"No";
		}
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()

using namespace std;

int main()
{
	fio
	int TC;
	//cin>>TC;
	TC=1;
	while(TC--)
	{
		int n;
		cin>>n;
		std::vector<string> v(n);
		set<string> unique;
		for (int i = 0; i < n; ++i)
		{
			cin>>v[i];
			if(unique.find(v[i])==unique.end())
				unique.insert(v[i]);
		}
		cout<<unique.size()<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 25012
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		long h=gInt(),w=gInt();
		System.out.println(h==1||w==1?1:(h*w+1)/2);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return (cur+d==to)||(d<0^cur+d<to);
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
typedef long long int lli;
int main(void)
{
    lli n,a,b;

    scanf("%lld %lld %lld",&n,&a,&b);
    lli sa;
    sa=llabs(a-b);
    
    if(sa%2==0){
        printf("%lld\n",sa/2);
    }
    else if(a==1||b==1){
        printf("%lld\n",sa/2+1);
    }
    else if(a==n||b==n){
        printf("%lld\n",sa/2+1);
    }
    else{
        lli ans=0;
        if(a>b){
            while(1)printf("よごれつちまつた悲しみに\n");
        }
        else{
            if(n-b>a-1){
                ans+=a-1;
                ans++;
                b-=a;
                ans+=(b-1)/(lli)2;
                printf("%lld\n",ans);
            }
            else{
                ans+=n-b;
                ans++;
                a+=n-b+(lli)1;
                ans+=llabs(n-a)/(lli)2;
                printf("%lld\n",ans);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

int main()
{
	INT n, m;
	cin >> n >> m;
	vector<UINT> a(n);
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	
	vector<pair<UINT, UINT>> bc(m);

	for (size_t i = 0; i < m; i++)
	{
		UINT b, c;
		cin >> b >> c;
		bc[i] = make_pair(b, c);
	}
	sort(bc.begin(), bc.end(), [](pair<UINT, UINT>p, pair<UINT, UINT>q) {return p.second > q.second; });

	INT ai = 0;
	for (size_t bci = 0; bci < m; bci++)
	{
		for (size_t bi = 0; bi < bc[bci].first; bi++, ai++)
		{
			if (a[ai] >= bc[bci].second)
			{
				goto end;
			}
			a[ai] = bc[bci].second;
		}
	}
end:;
	UINT ans = 0;
	for (UINT i = 0; i < a.size(); i++)
	{
		ans += a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
key = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(key[int(input())-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long g(long long x,long long y){return x*y?g(y%x,x):x+y;}
int main(){
    long long a,b;
    scanf("%lld %lld",&a,&b);
    printf("%lld",a*b/g(a,b));
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = (0, 0, 1, -1)
dy = (1, -1, 0, 0)
seen = [[False] * w for _ in range(h)]

numb = 0
numw = 0


def dfs(x, y):
    global numb, numw
    seen[x][y] = True
    if s[x][y] == '#':
        numb += 1
    else:
        numw += 1
    for di in range(4):
        nx = x + dx[di]
        ny = y + dy[di]
        if (nx < 0 or nx >= h or ny < 0 or ny >= w):
            continue
        if s[x][y] == s[nx][ny]:
            continue
        if seen[nx][ny]:
            continue
        dfs(nx, ny)


ans = 0
for x in range(h):
    for y in range(w):
        if seen[x][y]:
            continue
        if s[x][y] == '.':
            continue
        numb = 0
        numw = 0
        dfs(x, y)
        ans += numb * numw
print(ans)


Measured memory_bytes: 149492
S = input()
T = input()

n = len(T)
m = len(S)
L = []
R = []
for i in range(m-n+1):
    L.append(S[i:i+n:1])
count = 0
for word in L:
    for i in range(len(word)):
        if word[i] == T[i]:
            count += 1
    R.append(count)
    count = 0
print(n - max(R))


Measured memory_bytes: 68008
w,h,n = map(int,input().split())
left,right,up,down = 0,w,0,h

for _ in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        left  = max(left,x)
    if a == 2:
        right = min(right,x)
    if a == 3:
        up   = max(up,y)
    if a == 4:
        down = min(down,y)

w = max(0,right-left)
h = max(0,down-up)

print(w*h)


Measured memory_bytes: 3064
import sys
import numpy as np
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
c=[ca[i][0] for i in range(n)]
a=np.array([ca[i][1:] for i in range(n)])

#たっせいできるか
ans=10**9
if min(np.sum(a, axis=0))<x:
  print(-1)
  sys.exit()
for i in range(2**n):
  l=list(bin(i)[2:].zfill(n))
  #print(l)
  a_sum=np.array([0]*m)
  cost=0
  for j in range(n):
    if l[j]=='1':
      a_sum+=a[j]
      cost+=c[j]
  #print(a_sum)
  if min(a_sum)>=x:
    ans=min(ans,cost)
print(ans)

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

int main(){
  int n,m,a;
  cin >> n >> m;
  vector<int> v(m),d(m-1);
  r(i,m){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  r(i,m-1)d.at(i)=v.at(i+1)-v.at(i);
  sort(d.begin(),d.end());
  ll ans;
  r(i,m-n)ans+=d.at(i);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    map<ll, ll> mp;
    vll a(n);
    for (int i = 1; i <= n; i++) {
        mp[i] = 0;
    }
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll sum = 0;
    for (auto elem : mp) {
        ll num = elem.second;
        sum += num * (num - 1) / 2;
    }

    rep(i, n) {
        ll num = a[i];
        cout << sum - mp[num] * (mp[num] - 1) / 2 + (mp[num] - 1) * (mp[num] - 2) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 16640
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    (n > 999)? P("ABD") : P("ABC");
    
	return  0;
}

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

const ll INF = (1LL << 60);

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<ll> sum(2, 0), cnt(2, 0);
  REP(i, 0, N) {
    if(A[i] >= 0) {
      sum[i % 2] += A[i];
      cnt[i % 2]++;
    }
  }

  if(cnt[0] == 0 && cnt[1] == 0) {
    ll x = -INF, arg;
    REP(i, 0, N) {
      if(x < A[i]) {
        x = A[i];
        arg = i;
      }
    }

    vector<ll> op;
    for(ll i = N - 1; i >= 0; i--) {
      if(i > arg) {
        op.push_back(i);
      }
    }
    REP(i, 0, arg) op.push_back(0);

    cout << x << endl;
    cout << N - 1 << endl;
    for(ll i : op) cout << i + 1 << endl;
  } else {
    ll p;
    if(cnt[0] > 0 && cnt[1] > 0) p = sum[0] >= sum[1] ? 0 : 1;
    else if(cnt[0] > 0) p = 0;
    else if(cnt[1] > 0) p = 1;

    ll l = N, r = -1;
    REP(i, 0, N) {
      if(i % 2 == p && A[i] >= 0) {
        l = min(l, i);
        r = max(r, i);
      }
    }

    vector<ll> op;
    for(ll i = A.size() - 1; i >= 0; i--) {
      if(i > r) {
        op.push_back(i);
        A.erase(A.begin() + i);
      }
    }
    REP(i, 0, l) {
      op.push_back(0);
      A.erase(A.begin());
    }
    REP(i, 0, A.size()) {
      if(i % 2 == 0 && A[i] < 0) {
        op.push_back(i);
        A[i] = A[i - 1] + A[i + 1];
        A.erase(A.begin() + (i + 1));
        A.erase(A.begin() + (i - 1));
        i--;
      }
    }
    REP(i, 0, A.size() / 2) op.push_back(1);

    cout << sum[p] << endl;
    cout << op.size() << endl;
    for(ll i : op) cout << i + 1 << endl;
  }
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, x;
int l[101010];

int main(){
    cin >> n >> x;
    int d = 0;
    for(int i = 1;i <= n;i++){
        cin >> l[i];
        d += l[i];
        if(d > x){
            cout << i << endl;
            return 0;
        }
    }
    cout << n + 1 << endl;
}

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

ans = sum(b)

for i in range(n-1):
    if a[i] == a[i+1] - 1:
        ans += c[a[i]-1]

print(ans)


Measured memory_bytes: 3060