akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
b = list(range(n))
b.sort(key=lambda x: -a[x])

DP = [-float("inf")]*(n+1)

for i in range(n):
    if i == 0:
        DP[1] = a[b[i]]*b[i]
        DP[0] = a[b[i]]*(n-1-b[i])
    else:
        nxt = [-float("inf")]*(n+1)
        for j in range(i+2):
            if j == 0:
                nxt[j] = DP[j] + a[b[i]]*abs(n-1-i-b[i])
            else:
                nxt[j] = DP[j] + a[b[i]]*abs(n-1-(i-j)-b[i])
                nxt[j] = max(nxt[j], DP[j-1] + a[b[i]]*abs(j-1-b[i]))
        DP = nxt
print(max(DP))



Measured memory_bytes: 70796
#include <stdio.h>
 
int main(void) {
    int data[101][101] = {};
    int r, c;
    int i, j;
     
    scanf("%d %d", &r, &c);
     
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            scanf("%d", &data[i][j]);
            data[r][j] += data[i][j];
            data[i][c] += data[i][j];
            data[r][c] += data[i][j];
        }
    }
     
    for (i = 0; i <= r; i++) {
        for (j = 0; j <= c; j++)
            printf("%s%d", j ? " " : "", data[i][j]);
        puts("");
    }
     
    return 0;
}


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

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    rep(i, 0, k) {
        if(b <= a) {
            b *= 2;
        }else{
            c *= 2;
        }
    }
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
def solv(G):
  n = len(G)
  V = {0:0}
  new_V = []
  cost = 0

  while len(new_V) < n:
    u, e = min(V.items(), key=lambda x:x[1])
    V.pop(u)
    new_V.append(u)
    cost += e
    for v, e in enumerate(G[u]):
      if e < 0 or v == u or v in new_V: continue
      V[v] = min(V[v], e) if v in V else e

  return cost

n = int(input())
G = [list(map(int, input().split())) for _ in range(n)]
print(solv(G))

Measured memory_bytes: 7908
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC154
{
    class MainClass
    {

        static long[] n,s;

        public static void Main(string[] args)
        {
            n = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long k = n[1];

            double tmpans = 0;
            double tmpsum = 0;
            double nowans = 0;
            double nowsum = 0;
            double ans = 0;

            for(long i = 0;i<n[0]-k+1;i++){
                if(i==0){
                    for(long j = 0;j<k;j++){
                        nowsum +=s[j];
                        nowans = (double)(nowsum+(double)k)/2;
                        ans = nowans;
                    }
                }else{
                    tmpsum = nowsum - (double)s[i-1] + (double)s[i+k-1];
                    tmpans = (double)(tmpsum + (double)k)/2;
                    if(tmpans >= ans){
                        ans = tmpans;
                        //WriteLine("upd, {0} ",ans);
                    }
                    nowsum = tmpsum;
                    //WriteLine("nowans : {0} ",nowidx);
                }
            }
            WriteLine(ans);

        }
    }
}


Measured memory_bytes: 31580
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S[0]==S[1]&&S[2] != S[1] &&S[2]==S[3])
    cout << "Yes";
    else if(S[0]==S[2] && S[2] != S[1] &&S[1]==S[3])
    cout << "Yes";
    else if(S[0]==S[3]&&S[3] != S[1] && S[1]==S[2])
    cout << "Yes";
    else
    cout << "No";
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    int ans;
    int zero = 0;
    int one = 0;
    REP(i,s.length()){
        if(s[i]=='0') zero++;
        else one++;
    }
    ans = min(one, zero);
    print(ans*2);   
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool neg=c=='-';
	neg?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return neg?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
template<class T>inline void mset(T a,int v,int n){memset(a,v,n*sizeof(a[0]));}
const int N=110;
const lint LINF=0x7f7f7f7f7f7f7f7fll;
int mxcnt[N];
int lst[N],ls=0;
namespace T{
	const int E=::N<<1;
	int to[E],bro[E],head[N],e=0;
	inline void init(int n){
		mset(head+1,-1,n);
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],head[u]=e++;
	}
	inline void add(int u,int v){
		ae(u,v),ae(v,u);
	}
	int dep[N];
	int dfs1(int x,int fa){
		int a=x;
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])==fa)continue;
			dep[v]=dep[x]+1;
			int t=dfs1(v,x);
			if(dep[t]>dep[a]){
				a=t;
			}
		}
		return a;
	}
	bool dfs2(int x,int fa,int t){
		lst[++ls]=x;
		if(x==t)return true;
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])==fa)continue;
			if(dfs2(v,x,t))return true;
		}
		ls--;
		return false;
	}
	void dfs3(int x,int fa){
		int soncnt=0;
		for(int i=head[x],v;~i;i=bro[i]){
			if((v=to[i])==fa)continue;
			dep[v]=dep[x]+1;
			dfs3(v,x);
			++soncnt;
		}
		apmax(mxcnt[dep[x]],soncnt);
	}
}
inline lint calcans(int n){
	lint ans=1;
	for(int i=1;i<=n;i++){
		if(mxcnt[i]){
			ans*=mxcnt[i];
		}else break;
	}
	return ans;
}
int main(){
	const int n=ni;
	T::init(n);
	for(int i=1;i<n;i++){
		T::add(ni,ni);
	}
	const int a=(T::dep[1]=1,T::dfs1(1,0));
	const int b=(T::dep[a]=1,T::dfs1(a,0));
	T::dfs2(a,0,b);
	printf("%d ",(ls+1)>>1);
	lint ans=LINF;
	if(ls&1){
		const int rt=lst[(ls+1)>>1];
		mset(mxcnt+1,0,n);
		T::dep[rt]=1,T::dfs3(rt,0);
		apmin(ans,calcans(n));
		using namespace T;
		for(int i=head[rt],v;~i;i=bro[i]){
			v=to[i];
			mset(mxcnt+1,0,n);
			T::dep[rt]=1,T::dfs3(rt,v);
			T::dep[v]=1,T::dfs3(v,rt);
			apmin(ans,calcans(n)*2);
		}
	}else{
		const int rt1=lst[ls>>1],rt2=lst[(ls>>1)+1];
		mset(mxcnt+1,0,n);
		T::dep[rt1]=1,T::dfs3(rt1,rt2);
		T::dep[rt2]=1,T::dfs3(rt2,rt1);
		apmin(ans,calcans(n)*2);
	}
	printf("%lld\n",ans);
	return 0;
}


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

 int main(){

 int a,b,c,x=0;
 cin>>a>>b>>c;
 for(int i=a;i<=b;i++){
 if(c%i==0) x=x+1;
}
cout<<x<<endl;

  return 0;
  }



Measured memory_bytes: 3104
#include <iostream>

using namespace std;

int main (){
  int H, W;

  //for(int k = 0; k < 300; k++){
  while(true){
    cin >> H >> W;
    if((H == 0)&&(W == 0)) break;
    for(int i = 0; i < H; i ++){
      for(int j = 0; j < W; j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

class dice
{
    int left, right, top, bottom, front, back;

public:
    void turn(char op);
    void getdice(int t, int f, int r, int l, int ba, int bo);
    void disptop();
    void dispright();
    void dispfront();
    void dispall();
    void moveto(int target1, int target2);
};

void dice::turn(char op)
{
    int tmp;
    if (op == 'E')
    {
        tmp = top;
        top = left;
        left = bottom;
        bottom = right;
        right = tmp;
    }
    else if (op == 'W')
    {
        tmp = top;
        top = right;
        right = bottom;
        bottom = left;
        left = tmp;
    }
    else if (op == 'N')
    {
        tmp = top;
        top = front;
        front = bottom;
        bottom = back;
        back = tmp;
    }
    else if (op == 'S')
    {
        tmp = top;
        top = back;
        back = bottom;
        bottom = front;
        front = tmp;
    }
}

void dice::getdice(int t, int f, int r, int l, int ba, int bo)
{
    left = l, right = r, top = t, bottom = bo, front = f, back = ba;
}

void dice::disptop()
{
    cout << top << endl;
}

void dice::dispright()
{
    cout << right << endl;
}

void dice::dispfront()
{
    cout << front << endl;
}

void dice::dispall()
{
    cout << top << " " << front << " " << right << " " << left << " " << back << " " << bottom << endl;
}

void dice::moveto(int target1, int target2)
{
    if (target2 == top) turn('S');
    else if (target2 == left) {
        turn('E');
        turn('S');
    }
    else if (target2 == right) {
        turn('W');
        turn('S');
    }
    else if (target2 == back) {
        turn('S');
        turn('S');
    }
    else if (target2 == bottom) turn('N');

    if (target1 == right) turn('W');
    else if (target1 == left) turn('E');
    else if (target1 == bottom) {
        turn('E');
        turn('E');
    }
}


int main()
{
    int n, t, f, r, l, ba, bo, lenop, p, q;
    dice a;
    string op;
    cin >> t >> f >> r >> l >> ba >> bo;
    a.getdice(t, f, r, l, ba, bo);
    cin >> n;
    for (int i = 0; i < n; i++)
    {   
        cin >> p >> q;
        a.moveto(p,q);
        a.dispright();
    }
    return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std; int a[500001], i, j, n;
int main() {
	for (i = 2; i < 500001; i++) {
		if (i % 7 == 1 || i % 7 == 6) {
			for (j = 2; j <= sqrt(i); j++) {
				if (a[j] == 1 && i%j==0) {
					a[i] = 0; goto E;
				}
			}
			a[i] = 1;
		E:;
		} 
	}
	while (true) {
		cin >> n;
		if (n < 2) { break; }printf("%d:", n);
		for (i = 2; i <= n;i++){
			if (a[i] == 1 && n%i == 0) { printf(" %d", i); }
		}
		cout << endl;
	}
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }
  int k=0;
  ll ans=0;
  sort(s.begin(),s.end());
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      k++;
    }
    else{
      ans +=(ll)k*(k+1)/2;
      k=0;
    }
  }
  ans +=(ll)k*(k+1)/2;
  cout << ans << endl;
}


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

const int maxn = 15;

int main()
{
    char str[maxn];
    while(scanf("%s",str) != EOF)
    {
        int len = strlen(str);
        int n = 1 << (len - 1);
        long long ans = 0;
        for(int i = 0;i < n;i++)
        {
            long long t = str[0] - '0';
            for(int j = 0;j < n;j++)
            {
                if(j == len - 1 || i & 1 << j)
                {
                    ans += t;
                    t = 0;
                    if(j == len - 1) break;
                }
                t = t * 10 + str[j + 1] - '0';
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define devugv(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debugvp(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;
typedef vector< vector < int > > vvi;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif

    int n, k; cin >> n >> k;        
    const double eps = 1e-7;
    vector<double> dice(n), expected(n);        
    double sum = 0.0, ans = 0.0;
    for(auto& x: dice) cin >> x;
    for (int i = 0; i < n; i++) {
        expected[i] = (dice[i] * (dice[i] + 1)) / 2;    
        expected[i] /= (dice[i] * 1.0);
    }    int l = 1, r = k;
    for (int i = 0; i < k; i++) sum += expected[i];
    uax(ans, sum);
    while (r < n) {
        sum -= expected[l - 1];
        sum += expected[r];
        if (sum - ans > eps) ans = sum;
        l++; r++;
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cout << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 3328
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var shougen = Enumerable.Range(0, (int)N).Select(_ => new long[N]).ToArray();
            for (var i = 0; i < N; ++i)
                for (var j = 0; j < N; ++j)
                    shougen[i][j] = -1;
            for (var i = 0; i < N; ++i)
            {
                shougen[i][i] = 1;
                var a = Sarray()[0];
                for (var j = 0; j < a; ++j)
                {
                    var xy = Sarray();
                    var x = xy[0] - 1;
                    var y = xy[1];
                    shougen[i][x] = y;
                }
            }
            var ans = 0L;
            var zentori = (1 << (int)N);
            for (var i = 0; i < zentori; ++i)
            {
                var t = i;
                var matome = Enumerable.Repeat(-1L, (int)N).ToArray();
                var flg = true;
                var cmp = new bool[N];
                for (var j = 0; j < N; ++j, t >>= 1) 
                {
                    if (0 == (t & 1))
                        continue;
                    // jが正直者か確認する
                    var q = new Queue<long>();
                    q.Enqueue(j);
                    while (q.Any())
                    {
                        var r = q.Dequeue();
                        cmp[r] = true;
                        for (var s = 0; s < N; ++s)
                        {
                            if ((matome[s] == 1 && shougen[r][s] == 0) ||
                                (matome[s] == 0 && shougen[r][s] == 1)
                                )
                            {
                                flg = false;
                                break;
                            }
                            if (shougen[r][s] == 1 && !cmp[s])
                                q.Enqueue(s);
                            if (matome[s] == -1)
                                matome[s] = shougen[r][s];
                        }
                    }
                    if (!flg)
                        break;
                }
                if (flg)
                    ans = Max(ans, matome.Count(m => m == 1));
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 17744
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 + y1 - y2
y3 = y2 + x2 - x1
x4 = x3 + y2 - y3
y4 = y3 + x3 - x2
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n, ans;

signed main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		ans += n / i - !!(n % i == 0);
	}
	cout << ans;
}

Measured memory_bytes: 3632
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

d,t,s = inpm()

ans = 'Yes'
if d > t*s:
    ans = 'No'
print(ans)

Measured memory_bytes: 31188
n=int(input())
arr=list(map(int,input().split()))
dict1={}
for i in range(n):
	try:
		dict1[arr[i]]+=1
	except:
		KeyError
		dict1[arr[i]]=1
if(0 in dict1.keys()):
	if(dict1[0]==n):
		print("Yes")
	elif(n%3==0 and dict1[0]==n//3):
		if(len(dict1)==2):
			print("Yes")
		else:
			print("No")
	else:
		print("No")
else:
	if(n%3==0 and len(dict1)==3):
		arr1=[]
		for i in dict1.keys():
			if(dict1[i]!=n//3):
				print("No")
				exit(0)
			arr1.append(i)
		#print(arr1)
		if(arr1[0]^arr1[1]==arr1[2]):
			print("Yes")
		else:
			print("No")
	else:
		print("No")

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

int main() {
    int L, R; cin >> L >> R;
    auto ZERO = [](){ cout << 0 << endl; exit(0); };
    if (R - L + 1 >= 2019) ZERO();
    int l = L % 2019, r = R % 2019;
    if (l > r) ZERO();
    int ans = 2019;
    for (int i = l; i < r; i++) for (int j = i + 1; j <= r; j++) {
        ans = min(ans, i * j % 2019);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
inp = list(map(int,input().split()))
k=int(input())
z=0
while z<=k:
    if inp[1]<=inp[0]:
        inp[1]*=2
        z+=1
    else:
        break
while z<k:
    if inp[2]<=inp[1]:
        inp[2]*=2
        z+=1
    else:
        break
flag=0
if inp[2]>inp[1] and inp[1]>inp[0]:
    if z<=k:
        flag=1
        print ('Yes')
if flag==0:
    print ('No')

Measured memory_bytes: 9196
//suhan lee,saitama university

#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <complex>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n) for(int i=0;i<n;i++)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define pb push_back 
#define pf push_front

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

int w, h;
int sx, sy, gx, gy;
int ans = 100000;
vvi field;

void rec(int x, int y, int step) {
  if (step == 10) return;
  if (ans <= step) return;
  // cout << x << ", " << y << endl;
  repn(di, 4) {
    int nx = x + dx[di];
    int ny = y + dy[di];
    if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
    if (field[ny][nx]) continue;
    while (!field[ny][nx]) {
      if (nx == gx && ny == gy) {
	ans = min(ans, step +1);
	return;
      }
      nx += dx[di];
      ny += dy[di];
      if (ny < 0 || h <= ny || nx < 0 || w <= nx) goto failed;
    }

    field[ny][nx] = 0;
    rec(nx - dx[di], ny - dy[di], step + 1);
    field[ny][nx] = 1;


  failed: {}
    
  }
}
int solve() {
  ans = 100000;
  field = vvi(h, vi(w));
  repn(y, h) repn(x,w) {
    int a;
    cin >> a;
    if (a==2) sx = x, sy = y;
    else if (a==3) gx = x, gy = y;
    else if (a == 1) field[y][x] = 1;
  }
  rec(sx, sy, 0);
  return ans > 10 ? -1 : ans;
}

int main(){

  while (cin >> w >> h, w||h) cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

class Node {
public:
    Node *lf, *rt;
    int num;
    Node(Node *l, Node *r, int n)
        : lf(l), rt(r), num(n) {}
};

int to_num(string &s, int &pos) {
    int res = 0;
    while (pos < s.size()) {
        if (s[pos] < '0' || s[pos] > '9') break;
        res = res * 10 + s[pos] - '0';
        pos++;
    }
    return res;
}

Node *decode(string &s, int &pos) {
    if (s.size() <= pos) {
        return nullptr;
    }
    if (s[pos] == ')') {
        pos++;
        return nullptr;
    }
    if (s[pos] == '(') {
        pos++;
        auto lf = decode(s, pos);
        pos++;
        int num = to_num(s, pos);
        pos++;
        pos++;
        auto rt = decode(s, pos);
        pos++;
        return new Node(lf, rt, num);
    }
    return nullptr;
}

Node *merge(Node *n1, Node *n2) {
    if (n1 == nullptr or n2 == nullptr) {
        return nullptr;
    }
    Node *lf = merge(n1->lf, n2->lf);
    Node *rt = merge(n1->rt, n2->rt);
    int num = n1->num + n2->num;
    return new Node(lf, rt, num);
}

#include <sstream>
string to_str(int num) {
    stringstream ss;
    ss << num;
    return ss.str();
}

string encode(Node *node) {
    if (node == nullptr) {
        return "";
    }
    return "(" + encode(node->lf) + ")[" + to_str(node->num) + "](" + encode(node->rt) + ")";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    Node *snode, *tnode;
    {
        int pos = 0;
        snode = decode(S, pos);
        pos = 0;
        tnode = decode(T, pos);
    }
    Node *mer = merge(snode, tnode);
    cout << encode(mer) << endl;
    return 0;
}



Measured memory_bytes: 3224
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

type Int64Slice []int64

func (a Int64Slice) Len() int {
	return len(a)
}

func (a Int64Slice) Less(i, j int) bool {

	return a[i] > a[j]
}

func (a Int64Slice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var (
	n int
	m int
	x []int64
	y []int64
	z []int64
)

func abs(a int64) int64 {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func main() {
	defer stdout.Flush()

	// readString() string
	// readInt() int
	// readIntSlice(n int) []int
	// readLengthAndSlice() []int
	n = readInt()
	m = readInt()
	x = make([]int64, n)
	y = make([]int64, n)
	z = make([]int64, n)

	for i := 0; i < n; i++ {
		x[i] = readInt64()
		y[i] = readInt64()
		z[i] = readInt64()
	}

	var ans int64

	for _, xs := range []int64{-1, 1} {
		for _, ys := range []int64{-1, 1} {
			for _, zs := range []int64{-1, 1} {
				tmp := make([]int64, n)
				for i := 0; i < n; i++ {
					tmp[i] = xs*x[i] + ys*y[i] + zs*z[i]
				}
				ts := Int64Slice(tmp)
				sort.Sort(ts)
				var ta int64
				for i := 0; i < m; i++ {
					ta += ts[i]
				}
				if ta > ans {
					ans = ta
				}
			}
		}
	}

	println(ans)
}


Measured memory_bytes: 768
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int dis[2005][2005];
int vis[2005];
vector<int> edges[2005];
int ans[2005];

int main() {
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i < n; i++) {
        edges[i].push_back(i + 1);
        edges[i + 1].push_back(i);
    }
    edges[x].push_back(y);
    edges[y].push_back(x);
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));
        dis[i][i] = 0;
        vis[i] = 1;
        int d = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int len = q.size();
            for (int j = 0; j < len; j++) {
                int cur = q.front(); q.pop();
                // printf("cur = %d\n", cur);
                for (int nxt : edges[cur]) {
                    if (!vis[nxt]) {
                        q.push(nxt);
                        dis[i][nxt] = d + 1;
                        // printf("%d %d: dis %d\n", i, nxt, d + 1);
                        vis[nxt] = 1;
                    }
                }
            }
            d++;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            ans[dis[i][j]]++;
        }
    }
    for (int k = 1; k < n; k++) {
        printf("%d\n", ans[k]);
    }
}


Measured memory_bytes: 16000
def resolve():
    a, b,c,k = map(int, input().split())

    ans = 0
    used = min(k,a)
    ans += used * 1
    k -= used
    used = min(k, b)
    k -= used
    ans += k*(-1)
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9180
import sys
def Is(): return [int(x) for x in sys.stdin.readline().split()]

N,M,Q = Is()
lis = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
    l,r = Is()
    lis[l][r] += 1

cs = [[0]*(N+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,N+1):
        cs[i][j] = cs[i][j-1] + sum(lis[i][:j+1])

for _ in range(Q): 
    p,q = Is()
    t = 0
    for i in range(p,q+1):
        t += cs[i][q] - cs[i][q-1]
    print(t)

Measured memory_bytes: 62812
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    std::vector<int> c(n);
    for (int i = 0; i < n; i++) std::cin >> c[i];
    std::sort(c.begin(), c.end());
    std::vector<int> ans(n, -1);
    std::vector<int> depth(n);
    auto dfs = [&](auto &self, int pos = 0, int prev = -1) -> void {
        for (int e : edg[pos]) {
            if (e == prev) continue;
            depth[e] = depth[pos] + 1;
            self(self, e, pos);
        }
    };
    dfs(dfs);
    std::vector<int> id(n);
    std::iota(id.begin(), id.end(), 0);
    std::sort(id.begin(), id.end(), [&](int i, int j) {
        return depth[i] > depth[j];
    });
    for (int i = 0; i < n; i++) {
        ans[id[i]] = c[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j : edg[i]) {
            sum += std::min(ans[i], ans[j]);
        }
    }
    std::cout << sum / 2 << std::endl;
    for (int i = 0; i < n; i++) std::cout << ans[i] << " \n"[i == n - 1];
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,g;
    cin>>r>>g;
    cout<<r+2*(g-r)<<endl;
}

Measured memory_bytes: 256
import itertools as itr

n = int(input())
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
ab.sort(key=lambda x: x[1])
a = [x[0] for x in ab ]
b = [x[1] for x in ab ]
finished = list(itr.accumulate(a))
ans = 'Yes'
for i in range(n):
    if finished[i] > b[i]:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 61452
def factoring(n):
    if n == 0:
        return {}
    if n == 1:
        return {}
    nOrigin = n
    n = n**0.5
    numlist = [0 for i in range(int(n) + 1)]
    numlist[0] = -1
    numlist[1] = -1

    #√√n以下の数について篩をかけていく
    t = 2
    while t < (n**0.5):
        if numlist[t] == 0:
            numlist[t] = t
            k = 2
            while t * k <= n:
                numlist[t * k] = -1
                k += 1
        t += 1

    #√√nより大きい数で、篩にかからなかった数は素数。
    while t <= n:
        if numlist[t] == 0:
            numlist[t] = t
        t += 1

    #√n以下の数で割っていく。
    result = {}
    for i in numlist:
        if i == -1:
            continue
        j = 0
        while nOrigin % i == 0:
            j += 1
            nOrigin = nOrigin / i
        if j == 0:
            continue
        else:
            result[i] = j

    if int(nOrigin) != 1:
        result[int(nOrigin)] = 1
    return result

def GCD(a, b):
    M = max(a, b)
    m = min(a, b)
    if m == 0:
        return M
    else:
        return GCD(m, M % m)


A,B=[int(i) for i in input().split(" ")]

fact=factoring(GCD(A, B))
print(len(fact)+1)


Measured memory_bytes: 13356
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
vector<int> g[101];
bool v;
bool used[101];
int ok[101];
int in[101];
int type[101];
int ans;

int dfs(int p,int c){
	used[p] = true;
	ans = max(c,ans);
	for(int i = 0 ; i < g[p].size() ; i++){
		if(!used[g[p][i]]){
			dfs(g[p][i],c+1);
		}
	}
	used[p] = false;
}

void same(int p,int t){
	if(used[p])return; else used[p] = true;
	type[t] = min(type[p],in[p]);
	ok[p] = t;
	rep(i,g[p].size())same(g[p][i],t);
}

int main(){
	int n;
	while(cin >> n && n){
		rep(i,101) g[i].clear() , in[i] = 0 , ok[i] = -1 , type[i] = 999;
		vector<int> v;
		rep(i,n){
			int a,b;
			cin >> a >> b;
			g[a].push_back(b);
			g[b].push_back(a);
			in[a]++,in[b]++;
			v.push_back(a);
			v.push_back(b);
		}
		ans = 0 ;
		sort(v.begin(),v.end());
		int C = 0;
		for(int i = 0 ; i < v.size() ; i++){
			if( (!i || v[i] != v[i-1]) && ok[v[i]] == -1){
				rep(j,101)used[j] = 0;
				same(v[i],C++);
			}
		}
		for(int i = 0 ; i < C ; i++){
			for(int j = 1 ; j <= 100 ; j++){
				if(ok[j] == i && in[j] == type[i]){
					rep(k,101)used[k] = 0;
					dfs(j,0);
				}
			}
		}
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 916
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],R[2<<17];
/*dfs1(u,p,i)
{
	dp1[u]=1;
	for(i=first[u];i;i=next[i])eb[i]-p?dfs1(eb[i],u),dp1[u]=dp1[u]*-~dp1[eb[i]]%M:0;
}*/
dfs1(u,p,i,I)
{
	dp1[u]=1;
	for(i=first[u];I=eb[i];i=next[i])I-p?dfs1(I,u),dp1[u]=dp1[u]*-~dp1[I]%M:0;
}
/*dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p,x);
	for(;i;i=next[i])
	{
		if(eb[i]!=p)dfs2(eb[i],u,L[i]*R[next[i]]%M+1);
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]-p?-~dp1[eb[i]]:1;
		make(x=next[i],p,t%M*x%M);
		R[i]=R[x]*t%M;
	}
}*/
/*
dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;i;i=next[i])eb[i]-p?dfs2(eb[i],u,R[next[i]]*x%M+1),x=x%M*-~dp1[eb[i]]%M:0;
}
*/
/**/
dfs2(u,p,x,i,I)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;I=eb[i];i=next[i])I-p?dfs2(I,u,R[next[i]]*x%M+1,0,0),x=x%M*-~dp1[I]%M:0;
}
/**/
make(i,p)
{
	if(i)make(next[i],p),R[i]=R[next[i]]*(eb[i]-p?-~dp1[eb[i]]:1)%M;
	//if(i)R[i]=(eb[i]-p?-~dp1[eb[i]]:1)%M*R[make(p=next[i],p),p]%M;
}
main(u,v)
{
	/*for(scanf("%d%d",&n,&M);~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}*/
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i]=eb[i+1]=u,ea[i+1]=eb[i]=v,i++:(n=u,M=v);
	for(;~scanf("%d%d",&u,&v);i++)i++?ea[i-1]=eb[i]=u,ea[i]=eb[i-1]=v:(n=u,M=v);
	for(;--i;first[ea[i]]=i)next[i]=first[ea[i]];
	dfs1(*R=1,0);
	dfs2(1,0,1);
	for(;i++<n;)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 11520
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
int N,D=0,H=0,G=100000,T=0; cin >> N ;
int W[100];
for(int i=0;i<N;i++){
  cin >> W[i];
  H+=W[i];
}
  T=H;
for(int i=0;i<N;i++){
  D+=W[i];
  T-=D;
G= min(G,abs(T-D));
T=H;
}
cout << G;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def countDic(str_list):
    ret = {}
    for s in str_list:
        if s in ret.keys():
            ret[s] += 1
        else:
            ret[s] = 1
    return ret

N = int(input())
s = [''] * N
for i in range(N):
    s[i] = input()
M = int(input())
t = [''] * M
for i in range(M):
    t[i] = input()

s_c = countDic(s)
t_c = countDic(t)
a = []
for k in s_c.keys():
    if k in t_c.keys():
        a.append(s_c[k] - t_c[k])
    else:
        a.append(s_c[k])
if max(a) > 0:
    print(max(a))
else:
    print(0)


Measured memory_bytes: 3064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = a[0];
        int q = a[1];
        char[] s = Console.ReadLine().ToCharArray();
        for (int i = 0; i < n-1; i ++) {
            if (s[i]=='A' && s[i+1]=='C') s[i] = 'a';
        }
        int[] t = new int[n];
        t[0] = 0;
        for (int i = 0; i < n-1; i ++) {
            if (s[i]=='a') t[i+1] = t[i]+1;
            else t[i+1] = t[i];
        }
        for(int i = 0; i < q; i ++) {
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int l = b[0]-1;
            int r = b[1]-1;
            Console.WriteLine(t[r]-t[l]);
        }
    }
}

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


using namespace std;

string str;

int main() {
  //  fstream cin("A.in");
  //  ofstream cout("A.out");
  //  int ;
    ios::sync_with_stdio(false);
    int n = 0, e = 0, s = 0, w = 0;
    cin >> str;
    for(auto it : str) {
        if(it == 'N')
            n++;
        if(it == 'S')
            s++;
        if(it == 'E')
            e++;
        if(it == 'W')
            w++;
    }
    if((n > 0 && s == 0) || (n == 0 && s > 0) || (e > 0 && w == 0) || (e == 0 && w > 0))
        cout << "No";
    else
        cout << "Yes";
    cout << endl;
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

ll order2(ll n){
  if(n%2!=0)
    return 0;    
  return 1+order2(n/2);
}

ll gcd(ll a,ll b){
  if(a<b){
    ll tmp=a; a=b; b=tmp;
  }
  ll r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  ll m,n,bunki=0,bunki2=0;
  cin>>n>>m;
  ll a[n],b[n];
  cin>>a[0];
  a[0]/=2;
  b[0]=order2(a[0]);
  rep1(i,n){
    cin>>a[i];
    a[i]/=2;
    b[i]=order2(a[i]);
    if(b[i]!=b[0]){
      bunki=1;
    }
  }
  if(bunki){
    cout<<0;
  }else{
    ll lcm=a[0];
    rep1(i,n){
      lcm/=gcd(lcm,a[i]);
      lcm*=a[i];
      if(lcm>m){
        bunki2=1;
        break;
      }
    }
    if(bunki2==1){
      cout<<0;
    }else{
      cout<<setprecision(12)<<floor(((double)m+lcm)/2/lcm);
    }
  }
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Reads();
            string s = (input[0][0].ToString() + input[1][0].ToString() + input[2][0].ToString());
            WriteLine(s.ToUpper());
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
  int N,K;
  cin >> N >> K;
  map<int,int> m;
  for(int i=0;i<K;i++){
    int n;
    cin >> n;
    m[n]=n;
  }
  int flag=1;
  while(flag){
    int n=N;
    while(n!=0){
      if(m.count(n%10)){
        flag=0;
        break;
      }
      n/=10;
    }
    if(flag==1) break;
    flag=1;
    N++;
  }
  cout << N << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define Max 2000000
#define vMax 10000
 
int main(){
  unsigned short *A, *B;
 
  int c[vMax + 1];
  int n, i, j;
  scanf("%d", &n);
 
  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);
 
  for(i = 0 ; i <= vMax ; i++) c[i] = 0;
 
  for(i = 0 ; i < n ; i++){
    scanf("%hu", &A[i + 1]);
    c[A[i + 1]]++;
  }
 
  for(i = 1 ; i <= vMax ; i++) c[i] = c[i]+ c[i - 1];
 
  for(j = 1 ; j <= n ; j++){
    B[c[A[j]]] = A[j];
    c[A[j]]--;
  }
 
  for(i = 1 ; i <= n ; i++){
    if(i > 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
 
  return 0;
}



Measured memory_bytes: 9596
from collections import defaultdict

N = int(input())
arr1 = [int(i) for i in input().split()]
arr = []
Dict = defaultdict(int)
for i in range(N):
    Dict[arr1[i]] += 1
arr = list(Dict.keys())
n = int(10 ** 6)
prime = [True for i in range(n + 10)]
for p in arr:
    if prime[p]:
        start = p+p
        for j in range(start, n + 1, p):
            prime[j] = False
count = 0
for i in arr:
    if prime[i] and Dict[i] == 1:
        count += 1
print(count)


Measured memory_bytes: 170948
cmp(long*a,long*b){return*a<*b?-1:*a>*b;}
long n,a[1<<17];
long s[1<<17],t[1<<17];
long ans;
main()
{
	scanf("%ld",&n);
	for(int i=0;i<n;i++)scanf("%ld",a+i);
	qsort(a,n,8,cmp);
	if(n%2)
	{
		for(int i=0;i<n;i++)s[i]=abs(a[i]-a[n/2]);
		qsort(s,n,8,cmp);
		ans=s[1];
		for(int i=2;i<n;i++)
		{
			ans+=s[i]*2;
		}
	}
	else
	{
		for(int i=0;i<n/2;i++)s[i]=abs(a[i]-a[n/2]);
		qsort(s,n/2,8,cmp);
		ans=s[0];
		for(int i=1;i<n/2;i++)ans+=s[i]*2;
		for(int i=n/2;i<n;i++)t[i-n/2]=abs(a[i]-a[n/2]);
		qsort(t,n-n/2,8,cmp);
		ans+=t[0];
		for(int i=1;i<n-n/2;i++)ans+=t[i]*2;
	}
	printf("%ld\n",ans);
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


const int MAX = 510000;
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;
}

int main() {
	COMinit();


	int n, k;
	cin >> n >> k;
	FOR(i,1, k+1) {
		cout << COM(n - k + 1, i)*COM(k - 1, i - 1) % mod << endl;
	}



}

Measured memory_bytes: 12160
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 1;
    REP(i,3)if(s[i]==s[i+1]){
        ans++;
        if(ans>=3){
            cout << "Yes" << endl;
            return 0;
        }
    }else{
        ans=1;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
use strict;
my $N=<>;
my $s = <>; chomp $s;
my @dat = split(/ /,$s);
my $a;
my $b;
my $shoji=1000;
for($a=0;$a<$N;$a++){
if($dat[$a]<$dat[$a+1]){$b=$b+(($shoji-($shoji%$dat[$a]))/$dat[$a]);$shoji=$shoji%$dat[$a];}
elsif($dat[$a]>$dat[$a+1]){$shoji=$shoji+($b*$dat[$a]);$b=0;}}
print "$shoji";

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

int main() {
	int p[3], j[2];
	cin >> p[0] >> p[1] >> p[2];
	cin >> j[0] >> j[1];
	
	int min = p[0] + j[0];
	for (int i = 0; i < 3; i++)
		for (int k = 0; k < 2; k++)
			if (p[i] + j[k] < min)
				min = p[i] + j[k];
			
	cout << min - 50 << endl;
	
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define BR cout<<endl;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

double expect(int x){
    double kitai,tem=0;
    for(int i=1;i<=x;i++){
        tem += i;
    }
    kitai = tem/x;
    cout << kitai << endl;
    return kitai;
    
}

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

    int co = 0, c1 = 0;

    for (int i = 0; i < s.length(); i++){
        if(s[i] == '0')co++;
        else c1++;
    }

    cout << 2 * min(co, c1) << endl;

    return 0;
}



Measured memory_bytes: 3728