akhauriyash/Code-Regression huggingface dataset:
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function carry(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n = readline() |> parseInt
	a = [zeros(Int,n) for i in 1:n]
	for i in 1:n
		x = readline() |> parseInt
		a[i][i] = 1
		for j in 1:x
			p,q = readline() |> split |> parseMap
			if q == 1
				a[i][p] = 1
			else
				a[i][p] = -1
			end
		end
	end
	ct = 0
	z = zeros(Int,n)
	while z!=0
		f = 0
		ans = z[1]==1?copy(a[1]):zeros(Int,n)
		for i in 2:n
			if z[i] == 1
				tmp = copy(a[i])
				for j in 1:n
					if ans[j]==0
						ans[j] = tmp[j]
					elseif tmp[j]!=0&&tmp[j]!=ans[j]
						f = 1
					end
				end
			end
		end
		for i in 1:n
			if z[i]==0&&ans[i]==1
				f = 1
			end
		end
		if f == 0
			ct = max(ct,sum(z))
		end
		z[n] += 1
		z=carry(z,2)
	end
	println(ct)
end

main()



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

using namespace std;

#define ll long long
#define ar array

int a,b,c,d,e;


void solve(){

    cin >> a >> b >> c >> d >> e ;

    if(a == 0) cout << "1"  << endl;
    if(b == 0) cout << "2"  << endl;
    if(c == 0) cout << "3"  << endl;
    if(d == 0) cout << "4"  << endl;
    if(e == 0) cout << "5"  << endl;

}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 3516
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

const int Maxn = 100005;

string s;
bool dp[Maxn];

int main()
{
	cin >> s;
	dp[s.length()] = true;
	for (int i = s.length() - 1; i >= 0; i--) {
		if (i + 5 <= s.length() && s.substr(i, 5) == "dream")
			dp[i] |= dp[i + 5];
		if (i + 7 <= s.length() && s.substr(i, 7) == "dreamer")
			dp[i] |= dp[i + 7];
		if (i + 5 <= s.length() && s.substr(i, 5) == "erase")
			dp[i] |= dp[i + 5];
		if (i + 6 <= s.length() && s.substr(i, 6) == "eraser")
			dp[i] |= dp[i + 6];
	}
	printf("%s\n", dp[0]? "YES": "NO");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 998244353;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int n, k;
    cin>>n>>k;
    vector<pii>vec(k);
    vector<ll>dp(n+1);
    for(int i =0 ; i < k ; i++ ) cin>>vec[i].uu>>vec[i].vv;
    dp[1] = 1;
    for(int i = 2 ; i <= n ; i++ ) {
        for(auto x : vec) {

            int frm = max(0 , i - x.vv - 1);
            int to = max(0 , i - x.uu);
            dp[i] = (dp[i] + dp[to] - dp[frm])%MOD;
            if(dp[i] < 0) dp[i] += MOD;

        }
        dp[i] += dp[i-1];
        dp[i] %= MOD;
    
        // cout<<dp[i]<<"\n";
    }
    ll ans = (dp[n] - dp[n-1] + MOD )%MOD;
    cout<<ans<<'\n';

    return 0;


}

Measured memory_bytes: 4780
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int max = 0;
		for (int i = 1; i < N - 1; i++) {
			String X = S.substring(0, i);
			String Y = S.substring(i);
			int result = 0;
			int min = Math.min(X.length(), Y.length());
			for (int j = 0; j < 26 && result < min; j++) {
				char alphabet = (char) ('a' + j);
				if (X.contains(String.valueOf(alphabet)) && Y.contains(String.valueOf(alphabet))) {
					result++;
				}
			}
			max = Math.max(max, result);
		}
		System.out.println(max);
	}
}


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

int main(void) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long cand[4];
    cand[0] = a * c;
    cand[1] = a * d;
    cand[2] = b * c;
    cand[3] = b * d;
    long long ans = cand[0];
    for (int i = 1; i < 4; i++) {
        ans = max(ans, cand[i]);
    }
    printf("%lld\n", ans);
    return 0;
}


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

const int maxn = 1e3 + 3;
const double eps = 1e-6;

struct vec {
    double x, y;
    void read() {
        int u, v;
        scanf("%d%d", &u, &v);
        x = u;
        y = v;
    }
    double len() const {
        return sqrt(x * x + y * y);
    }
    double cross(const vec &other) const {
        return x * other.y - y * other.x;
    }
    vec operator-(const vec &other) const {
        return {x - other.x, y - other.y};
    }
};

int n;
vec a[maxn], d;
double r;

double dist(auto A, auto B) {
    return (A - B).len();
}

double cross(auto A, auto B, auto C) {
    return (B - A).cross(C - A);
}

void MiniDiscWith2vec(vec p, vec q, int n) {
    d.x=(p.x+q.x)/2.0;
    d.y=(p.y+q.y)/2.0;
    r=dist(p,q)/2;
    double c1,c2,t1,t2,t3;
    for(int k=1;k<=n;k++) {
        if(dist(d,a[k])<=r) continue;
        if(fabs(cross(p,q,a[k])) > eps) {
            c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0;
            c2=(p.x*p.x+p.y*p.y-a[k].x*a[k].x-a[k].y*a[k].y)/2.0;
            d.x=(c1*(p.y-a[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-a[k].y)-(p.x-a[k].x)*(p.y-q.y));
            d.y=(c1*(p.x-a[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-a[k].x)-(p.y-a[k].y)*(p.x-q.x));
            r=dist(d,a[k]);
        } else {
            t1=dist(p,q);
            t2=dist(q,a[k]);
            t3=dist(p,a[k]);
            if(t1>=t2&&t1>=t3) {
                d.x=(p.x+q.x)/2.0;
                d.y=(p.y+q.y)/2.0;
                r=dist(p,q)/2.0;
            } else if(t2>=t1&&t2>=t3) {
                d.x=(a[k].x+q.x)/2.0;
                d.y=(a[k].y+q.y)/2.0;
                r=dist(a[k],q)/2.0;
            } else {
                d.x=(a[k].x+p.x)/2.0;
                d.y=(a[k].y+p.y)/2.0;
                r=dist(a[k],p)/2.0;
            }
        }
    }
}

void MiniDiscWithvec(vec pi,int n) {
    d.x=(pi.x+a[1].x)/2.0;
    d.y=(pi.y+a[1].y)/2.0;
    r=dist(pi,a[1])/2.0;
    for(int j=2;j<=n;j++) {
        if(dist(d,a[j])<=r) continue;
        else {
            MiniDiscWith2vec(pi,a[j],j-1);
        }
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        a[i].read();
    r=dist(a[1],a[2])/2.0;
    d.x=(a[1].x+a[2].x)/2.0;
    d.y=(a[1].y+a[2].y)/2.0;
    for(int i=3;i<=n;i++) {
        if(dist(d,a[i])<=r)continue;
        else MiniDiscWithvec(a[i],i-1);
    }
    printf("%.8lf\n", r);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n,a;
    cin >> n >> a;
    if(n % 500 <= a) cout << "Yes";
    else cout << "No";
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  double sum = 0;
  rep(i, n) {
    cin >> x[i];
    cin >> u[i];
  }
  rep(i, n) {
    if(u[i] == "BTC") {
      sum += x[i]*380000.0;
    }
    sum += x[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define N 55
#define LL long long
#define int long long
using namespace std;
int n,d,x,alsz;
int co[N],fa[N],sz[N];
int w[N];
int bk[N*N*N*N];
inline void getans(int len,int cost,const int m=alsz*d){
	if(cost>x)return;
	for(int i=m;i>=len;--i)bk[i]=min(bk[i],bk[i-len]+cost);
}

inline void work1(int tal,const int m){
	memset(bk,0x3f,sizeof(int)*(m+1));
	bk[0]=0;
	for(int i=1;i<=n;++i){
		int al=tal;
		for(int j=0;(1<<j)<=al;++j){
			al-=1<<j;int len=(1<<j)*sz[i],cost=min(1ll+x,(1ll<<j)*co[i]);
			getans(len,cost,m);
		}
		int len=al*sz[i],cost=min(1ll+x,1ll*al*co[i]);
		getans(len,cost,m);
	}
}
int a[N];
inline bool cmp(const int &a,const int &b){
	return 1ll*sz[a]*co[b]>1ll*sz[b]*co[a];
}
inline void work2(){
	int m;
	if(d>n){d-=n;work1(n,m=alsz*n);}
	else {work1(d,m=alsz*d);d=0;}
	for(int i=1;i<=n;++i)a[i]=i;sort(a+1,a+n+1,cmp);
	int ans=0;
	for(int i=m,mi=x+1,j=1,sum=0,al=0;~i;--i){
		if(bk[i]>=mi||x-sum<bk[i])continue;
		mi=bk[i];
		while(a[j]>1&&x-sum-bk[i]>1ll*co[a[j]]*(a[j]==1?x:d)){
			al+=sz[a[j]]*d;
			sum+=co[a[j]]*d;
			++j;
		}
		ans=max(ans,(x-sum-bk[i])/co[a[j]]*sz[a[j]]+al+i);
	}
	cout<<ans<<endl;
}
main(){
	scanf("%lld%lld%lld",&n,&x,&d);
	scanf("%lld",&co[1]);
	for(int i=2;i<=n;++i)scanf("%lld%lld",&co[i],&fa[i]);
	for(int i=n;i;--i){
		++sz[i];
		sz[fa[i]]+=sz[i];co[fa[i]]+=co[i];
		co[fa[i]]=min(co[fa[i]],x+1);
		alsz+=sz[i];
	}
	work2();
	return 0;
}
/*
3 100 10
15
10 1
20 1

*/

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n;
    cin >> n;
    int sum = 0;
    vt<int> a(n);
    int k;
    read(k, a);
    
    sort(all(a), greater<int>());
    
    FOR(k) {
        sum += a[i];
    }
    print(sum);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        //write("Case #", i + 1, ": ");
        solve();
        
    }
    
}



Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int pulse[20000];
int dp[2][256];

int main(){
	int n,m;
	int book[16];
	while(scanf("%d%d",&n,&m),n|m){
		rep(i,m)scanf("%d",&book[i]);
		rep(i,n)scanf("%d",&pulse[i]);
		rep(i,256)dp[0][i]=dp[1][i]=INT_MAX;
		
		dp[0][128] = 0;
		rep(i,n){
			int cur = i%2;
			int next = (i+1)%2;
			rep(j,256)if( dp[cur][j]!=INT_MAX ){
				rep(k,m){
					int d = j+book[k];
					if( d<0 )d=0;
					if( d>255 )d=255;
					dp[next][d] = min(dp[next][d], dp[cur][j]+(pulse[i]-d)*(pulse[i]-d));
				}
			}
			rep(j,256)dp[cur][j]=INT_MAX;
		}
		int ans = INT_MAX;
		rep(i,256)ans=min(ans,dp[n%2][i]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 960
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		int w = Integer.parseInt(in.nextLine());

		for (int i = 0; i < line.length(); i = i + w) {
			System.out.print(line.charAt(i));
		}
		System.out.println("");
		in.close();
	}

}


Measured memory_bytes: 23124
using System;
using System.Linq;
using  System.Collections.Generic;
class Program
{
static void Main(string[] args){
var t = new int[]{3,5,7};
var d = long.Parse(Console.ReadLine());
var c = d.ToString().ToCharArray();
Func<long, int> tfs = null;
        tfs = n => (n>d)?0:t.Sum(i=> tfs(n *10+i))+(t.All(i=> n.ToString().Contains(((char)('0'+i)).ToString()))?1:0);
Console.WriteLine(tfs(0));
}
}

Measured memory_bytes: 17476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	string s;
	while(cin >> s)
	{
		bool ok = false;
		for(int i = 0; i < 10; ++i)
		{
			vector<string> input;
			string temp;
			for(int j = 0; j < s.size(); ++j)
			{
				if(s[j] == '+' || s[j] == '=')
				{
					input.push_back(temp);
					temp = "";
					continue;
				}
				if(s[j] == 'X')
				{
					temp += '0' + i;
				}
				else
				{
					temp += s[j];
				}
			}
			input.push_back(temp);

			while(input[1].size() > input[0].size())
			{
				input[0]  = "0" + input[0];
			}
			while(input[0].size() > input[1].size())
			{
				input[1]  = "0" + input[1];
			}
			input[0] = "0" + input[0];
			input[1] = "0" + input[1];
			string calcTemp;
			for(int j = input[0].size() - 1; j >= 0; --j)
			{
				int t = (input[0][j] - '0') + (input[1][j] - '0');
				if(t >= 10)
				{
					input[0][j - 1] += 1;
					t -= 10;
				}
				calcTemp += '0' + t;
			}
			reverse(calcTemp.begin(), calcTemp.end());
			string calc;
			if(calcTemp[0] == '0')
			{
				for(int j = 1; j < calcTemp.size(); ++j)
				{
					calc += calcTemp[j];
				}
			}
			else
			{
				calc = calcTemp;
			}
			if(calc == input[2])
			{
				cout << i << endl;
				ok = true;
			}
		}
		if(!ok)
		{
			cout << "NA" << endl;
		}
	}
}

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

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main(){
    int n,x;
    cin>>x>>n;
    vector<int> used(102);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        used[a]=true;
    }
    int now=INT_MAX,ret;
    for(int i=0;i<102;i++){
        if(used[i])continue;
        if(abs(i-x)<now){
            ret=i;
            now=abs(i-x);
        }
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

pair<long long, long long> process(long long d, long long c)
{
    if (c == 1)
        return { d, 0 };
    if (c % 2) {
        auto p = process(d, c - 1);
        long long x = d + p.first;
        if (x >= 10)
            return { x / 10 + x % 10, 2 + p.second };
        else
            return { x, 1 + p.second };
    }
    else {
        auto p = process(d, c / 2);
        long long x = p.first + p.first;
        if (x >= 10)
            return { x / 10 + x % 10, 2 + 2 * p.second };
        else
            return { x, 1 + 2 * p.second };
    }
}

int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }
    long long m;
    cin >> m;
    long long ans = -1;
    long long x = 0;
    for (long long i = 0; i != m; ++i) {
        long long d, c;
        cin >> d >> c;
        auto ret = process(d, c);
        ans += ret.second;
        x += ret.first;
        ++ans;
        if (x >= 10) {
            ++ans;
            x = x / 10 + x % 10;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int const nmax = 200000;
int const modulo = 1000000007;
int v[1 + nmax], freq[1 + nmax];
int dp[1 + nmax];

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i <= n; i++)
    cin >> v[i];
  dp[0] = 1;
  for(int i = 1;i <= n; i++){
    dp[i] = dp[i - 1];
    if(0 < freq[v[i]] && freq[v[i]] < i - 1)
      dp[i] += dp[freq[v[i]]];
    if(modulo <= dp[i])
      dp[i] -=  modulo;
    freq[v[i]] = i;
  }
  cout << dp[n];
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdint>
#include <string>

int main() {
	std::string s;
	uint64_t k;
	std::cin >> s >> k;
	for (uint32_t i = 0;i < s.size();i++) {
		if ((s[i] != '1') || (i + 1 == k)) {
			std::cout << s[i] << "\n";
			return 0;
		}
	}
}


Measured memory_bytes: 256
from heapq import heappush, heappop

INF = 10 ** 12

V, E, r = map(int, input().split())

graph = [[] for _ in range(V)]
dist_all = [INF] * V
dist_all[r] = 0
for i in range(E):
  start, end, dist1 = map(int, input().split())
  graph[start].append([end, dist1])
  
q = []
heappush(q, (0, r))

while q:
  dist, node = heappop(q)
  for to, cost in graph[node]:
    if(dist_all[to] > dist + cost):
      dist_all[to] = dist + cost
      heappush(q, (dist+cost, to))
  
for i in range(V):
  if(dist_all[i] == INF):
    print('INF')
  else:
    print(dist_all[i])


Measured memory_bytes: 97984
K = int(input())
k = K-1
numbers = [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(numbers[k])

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#include<stdlib.h>
#define ll long long
int a[200010];
int book[200010];
int main()
{
    int n,k,t=0;
    memset(book,0,sizeof(book));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    book[0]=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
           book[t]++;
        else
        {
            t++;
            book[t]++;
        }
    }
    sort(book,book+t+1);
    int sum=0,cnt=1;
    for(int i=t; i>=0; i--)
    {
        if(cnt<=k)
        {
            sum=sum+book[i];
            cnt++;
        }
    }
    printf("%d\n",n-sum);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;

int n, m;
long long L;
string s, t;
map <long long, char> a;

int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	cin >> s;
	cin >> t;
    L = 1LL * m * n / __gcd(m, n);
    for (int i = 0; i < n; i++)
        a[1LL * i * L / n + 1] = s[i];
    for (int i = 0; i < m; i++)
        if (a[1LL * i * L / m + 1] != '\0' && a[1LL * i * L / m + 1] != t[i])
        {
            cout << -1;
            return 0;
        }
    cout << L;
	return 0;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    set<int>s;
    int a;
    rep(i,N){
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main(){
   int a;
    string s,t;
    cin >> a;
    cin >> s >> t;
    for(int i = 0; i < a; i++){
        cout << s[i]<<t[i];
    }
    return 0;  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(void){
	while (1) {
		int n; cin >> n;
		if (!n) break;

		map<char, char> trans;
		for (int i = 0; i < n; i++) {
			char c, c2; cin >> c >> c2;
			trans[c] = c2;
		}

		int m; cin >> m;
		for (int i = 0; i < m; i++) {
			char b; cin >> b;

			if (trans[b]) b = trans[b];

			cout << b;
		}

		cout << endl;
	}
}
 

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
const int maxn = 30001;
int len, ans, ae, bb, both;
string s[maxn];
int cnt(const string &a){
	int res = 0;
	for(int i = 1;i < a.size();++i){
		res += (a[i] == 'B' and a[i - 1] == 'A');
	}
	return res;
}
int main(){
	// ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> len;
	for(int i = 0;i < len;++i){
		cin >> s[i];
		if(s[i][0] == 'B')++bb;
		if(s[i].back() == 'A')++ae;
		if(s[i][0] == 'B' and s[i].back() == 'A'){
			--bb;--ae;++both;
		}
		ans += cnt(s[i]);
	}
	if(both){
		if(ae){
			ans += both;
		}
		else if(bb){
			ans += both;
		}
		else{
			cout << both - 1 + ans << '\n';
			return 0;
		}
	}
	cout << ans + min(ae, bb) << '\n';
}


Measured memory_bytes: 1024
s = input()
K = int(input())
part_list = []
# o(n^2)
for i in range(len(s)):
    for j in range(i+1,i+6):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)


Measured memory_bytes: 5068
#include <iostream>
#define BUILDING 4
#define FLOOR 3
#define ROOM 10
using namespace std;
int main() {
    int n;
    cin >> n;
    int i;
    int b, f, r, v;
    int num[BUILDING][FLOOR][ROOM] = {0};
    for(i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        num[b-1][f-1][r-1] += v;
    }
    int j, k;
    for(i = 0;; i++){
        for(j = 0; j < FLOOR; j++){
            for(k = 0; k < ROOM; k++){
                cout << ' ' << num[i][j][k];
            }
            cout << endl;
        }
        if(i == BUILDING - 1) break;
        cout << "####################" << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
int main(void){
  char s[11];
  scanf("%s",&s);
  int c=0,max=0;
  for(int i=0;i<strlen(s);i++){
	if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C')
    c++;
    else {if(c>max)max=c;
          c=0;
         }
  }
  if(c>max)max=c;
  printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args)throws IOException {
		FastReader sc = new FastReader();
		PrintWriter pw = new PrintWriter(System.out);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double h = sc.nextDouble();
		double m = sc.nextDouble();
		double hour = 0.5 * (h * 60.0 + m);
		double minutes = 6.0 * m;
		double angle = Math.abs(hour - minutes);

		//System.out.println(Math.cos(angle));
		double ans = (a * a + b * b) - ((2.0 * a * b) * Math.cos(Math.toRadians(angle)));
		System.out.printf("%.20f", Math.sqrt(ans));


	}
}





class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new
		                        InputStreamReader(System.in));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException  e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
}

Measured memory_bytes: 34724
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, P;

  std::cin >> A >> P;
  
  std::cout << (A * 3 + P) / 2 << std::endl;

  return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

string s;
int n;
void solve() {
    cin >> n;
    cin >> s;

    auto m = sz(s);
    rep(i, m) {
        auto v = s[i] - 'A';
        v = (v + n) % 26;
        s[i] = v + 'A';
    }

    cout << s << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
list_all = list()
list_name = list()
list_number = list()

for n in range(N):
  par = input()
  pars = par.split(' ')
  list_all.append([n+1,pars[0],int(pars[1])])
  list_name.append(pars[0])
list_unique = sorted(list(set(list_name)))

for name in list_unique:
  l = list()
  for elem in list_all:
    if elem[1] == name:
      l.append([elem[2],elem[0]])
  l = sorted(l, reverse=True)
  for tmp in l:
    list_number.append(tmp[1])

for num in list_number:
  print(num)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int ar[12]={1,2,1,3,1,3,1,1,3,1,3,1};
    int a,b;
    cin>>a>>b;
    if(ar[a-1]==ar[b-1])cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

long long gcd(long long a, long long b)
{
	while (b != 0) {
		long long t = b;
		b = a % b;
		a = t;
	}
	return a;
}

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


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, t, x, g, i, ans;
	cin >> n;
	vector<long long> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	g = a[0];
	for (i = 1; i < n; i++) {
		g = lcm(g, a[i]);
		//cout << a[i] << " " << g << "\n";
	}
	////ans = 1;
	////for (i = 0; i < n; i++) ans = ans * (a[i] / g);
	ans = g;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
import java.math.BigDecimal;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();



        System.out.print(n+n*n+n*n*n);
    }
}


Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i;
    string str,ans;
    cin>>str;
    for(i=0; i<str.length(); i++){
        if(str[i]=='0'){
            ans+="0";
        }else if(str[i]=='1'){
            ans+="1";
        }else if(str[i]=='B'){
            if(!ans.empty())    ans.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    long long ans=1;
    int report[100001]={0};
    cin >> N;
    rep(i,N) {
        long long a;
        cin >> a;
        report[a]++;
    }
    for(long long i=1-N%2; i<=N; i=i+2 ){
        if(i==0){
            if(report[0]!=1){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(report[i]!=2){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    for(int i=0; i<N/2; i++){
        ans*=2;
        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++)
		cout<<i<<" ";
	return 0;
}

Measured memory_bytes: 256
# div2019D - DivRem Number
from math import sqrt


def divisors(n: int) -> set:
    # Compute divisors of a number.
    divs = set()
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divs.add(i)
            divs.add(n // i)
    return divs


def main():
    N = int(input())
    divs = divisors(N)
    ans = 0
    for m in divs:
        if m == 1:
            continue
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const double PI=3.14159265358979323846;

int main(){
 double a, b, x;
 cin >> a >> b >> x;
 double rest = a*a*b - x;
 double ans;
 double h = 2*rest/(a*a);
 if(h <= b){
        double sha = sqrt(a*a + h*h);
        ans = asin(h/sha);
        printf("%.6f\n", 180*ans/PI);
 }else{
     h = 2*x/(b*a);
     double sha = sqrt(b*b + h*h);
     ans = asin(h/sha);
     printf("%.6f\n", 90 - 180*ans/PI);
 }

}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
ll mod=1e9+7;
int main(){
	int n;
	cin >>n;
	int i=1;
	ll ans=1;
	while(i <= n){
		ans*=i;
		ans%=mod;
		i++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char str[5];
	while(gets(str)!=NULL)
	{
		if((str[0]!=str[1])&&(str[1]!=str[2])&&(str[2]!=str[0]))
		printf("Yes\n");
		else
		printf("No\n");
	}
	return 0;
}

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

int time_seq[105];

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    time_seq[A] += 1;
    time_seq[B] -= 1;
    time_seq[C] += 1;
    time_seq[D] -= 1;
    for (int i = 1; i < 105; i++) time_seq[i] += time_seq[i - 1];
    int ans = 0;
    for (int i = 0; i < 105; i++) {
        if (time_seq[i] == 2) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define rep1(i,s,e) for(int i=s;i<e;i++)
#define rep2(i,s,e,c) for(int i=s;i>=e;i--)
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pfn() printf("\n")
#define pfs() printf(" ")
#define sfi(x) scanf("%d",&x)
#define sfi1(x,y) scanf("%d%d",&x,&y)
#define sff(x) scanf("%lf",&x)
#define sfl(x) scanf("%lld",&x)
#define memset1(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 50;
ll ans[MAX];
vector<ll> Next[MAX];
ll gc[MAX];
struct node{
	int index;
	int v;
	void init(int _index,int _v){
		index=_index;
		v=_v;
	}
}p,p1;
int main(){
	int n,q;
	sfi1(n,q);
	memset1(ans);
	memset1(Next);
	for(int i=0;i<n-1;i++){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		Next[a].push_back(b);
	}
	memset1(gc);
	rep(i,1,q){
		ll x,v;
		scanf("%lld%lld",&x,&v);
		gc[x]+=v;
	}
	queue<node> que;
	p.init(1,gc[1]);
	que.push(p);
	while(!que.empty()){
		p=que.front();
		que.pop();
		ans[p.index]=p.v;
		for(int i=0;i<Next[p.index].size();i++){
			int next_index=Next[p.index][i];
			p1.init(next_index,p.v+gc[next_index]);
			que.push(p1);
		}
	}
	for(int i=1;i<=n;i++){
		printf("%lld",ans[i]);
		if(i<n) printf(" ");
		else pfn();
	}
	return 0;
}

Measured memory_bytes: 16512
n = int(input())
work = [[int(j) for j in input().split(" ")] for i in range(n)]
work = sorted(work,key = lambda x:(x[1],x[0]))

time = 0
for work_time, limit_time in work:
    time += work_time
    if time > limit_time:
        print("No")
        break

else:
    print("Yes")

Measured memory_bytes: 55384
import java.io.IOException;
import java.util.*;

public class Main {
    public static int map[][]=new int[11][11];
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int D=sc.nextInt();
        for(int i=0;i<N;i++){
            for(int j=0;j<D;j++){
                map[i][j]=sc.nextInt();
            }
        }
        int ans=0;

        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                double test=0;
                for(int l=0;l<D;l++){
                    test+=make_double(map[i][l],map[j][l]);
                }
                test=Math.sqrt(test);
                double test2=Math.floor(test);
                if(test==test2)
                    ans++;
            }
        }
        System.out.println(ans);

    }

    public static double make_double(int x,int y){
        double ans=(x-y)*(x-y);
        return ans;
    }


}

Measured memory_bytes: 22996
import math
a, b, x = list(map(float, input().split()))
y = 2 * x / (a * b)
if y > a:
  y = 2 * (a * a * b - x) / (a * a)
  a = math.atan(y / a)
else:
  a = math.atan(b / y)
print(a / math.acos(-1.0) * 180)

Measured memory_bytes: 3188
//1933-
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000
#define FIND 1
#define END 2

vector<int> V[100];
priority_queue<pair<int,int> > PQ;//distance,id
int d[100];
int StateNode[100] = {};

void BFS(pair<int,int> p){
    if(d[p.second] <= -p.first) {
        PQ.pop();
        if(!PQ.empty()) BFS(PQ.top());
        return;
    }
    d[p.second] = -p.first;
    PQ.pop();
    
    REP1(k,V[p.second].size()){
        if (StateNode[V[p.second][k]] == 0 || (StateNode[V[p.second][k]] == FIND && -p.first+1)) {
            PQ.push(make_pair(p.first-1,V[p.second][k]));
            StateNode[V[p.second][k]] = FIND;
        }
    }
    
    if(!PQ.empty()) BFS(PQ.top());
}

int main(){
    INT(N);
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to-1);
        }
        d[i] = INF;
    }
    
    PQ.push(make_pair(0,0));
    BFS(PQ.top());
    
    REP1(i,N){
        if (d[i] != INF) {
            printf("%d %d\n",i+1,d[i]);
        }else{
            printf("%d %d\n",i+1,-1);
        }
    }
    
    return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <bitset>
#include <vector>
#include <stdio.h>
#include <cstring>
using namespace std;

int main(){
    char ch[100];
    //char ch_cp[100];
    int K;
    cin>>K;
    cin>>ch;
    int n=strlen(ch);
    //cout<<n<<endl;
    if(n<=K){
        cout<<ch<<endl;
    }else{
        for(int i=0;i!=K;++i){
            printf("%c",ch[i]);
        }
        cout<<"."<<"."<<"."<<endl;
    }
   
}



Measured memory_bytes: 3644
N = gets.to_i
as = gets.split.map(&:to_i)
N.times do |i|
    as[i] -= i+1
end

as.sort!

if N%2==0
    med = (as[N/2-1] + as[N/2])/2
else
    med = as[N/2]
end

ans = 0
N.times do |j|
    ans += (med-as[j]).abs
end
puts ans


Measured memory_bytes: 17536
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
using namespace std;

const int maxn=10000+10;
int a[maxn];

typedef long long ll;

int main()
{
	int n;
	while(scanf("%d",&n) && n)
	{
		ll sum=0;
		rep(i,1,n) scanf("%d",a+i),sum+=a[i];
		sort(a+1,a+n+1);
		
		int ans=0;
		rep(i,1,n) if(1ll*a[i]*n <= sum) ++ans;
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3232
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t[n+1],x[n+1],y[n+1];
    t[0]=x[0]=y[0]=0;
    for(int i=0;i<n;i++)
    {
        cin>>t[i+1]>>x[i+1]>>y[i+1];
    }
    
    for(int i=0;i<n;i++)
    {
        int dt=t[i+1]-i[t];
        int dx=x[i+1]-x[i];
        int dy=y[i+1]-y[i];
        int d=abs(dx)+abs(dy);
        if(dt%2==0)
        {
            if(d%2==0&&d<=dt)
            {}
            else
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        else
        {
            if(d%2==1&&d<=dt)
            {}
            else
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define repm(i, n, m)  for(int i = n; i < m; ++i)
#define Repm(i, n, m)  for(int i = n; i <= m; ++i)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repn(i, n) repm(i, 1, n)
#define mod 1000000000+7

int main(){
    int k, x; cin >> k >> x;
    Repm(i, x-k+1, x+k-1)    cout << i << " ";
    cout << endl;

    return 0;
}


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

int N, cnt[4];
double dp[MAXN + 3][MAXN + 3][MAXN + 3];

double solve(int cnt1, int cnt2, int cnt3) {
    if (cnt1 + cnt2 + cnt3 == 0)
        return 0;

    if (dp[cnt1][cnt2][cnt3] > -1)
        return dp[cnt1][cnt2][cnt3];

    double result = 1;
    if (cnt1 > 0)
        result += ((1.0 * cnt1)/N) * solve(cnt1 - 1, cnt2, cnt3);

    if (cnt2 > 0)
        result += ((1.0 * cnt2)/N) * solve(cnt1 + 1, cnt2 - 1, cnt3);

    if (cnt3 > 0)
        result += ((1.0 * cnt3)/N) * solve(cnt1, cnt2 + 1, cnt3 - 1);

    result = result * (1.0 * N)/(cnt1 + cnt2 + cnt3); //If after rolling dice we end up at the same state

    return dp[cnt1][cnt2][cnt3] = result;
}

int main() {
    cin >> N;

    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;

        cnt[a] += 1;
    }

    memset(dp, -1, sizeof(dp));

    printf("%.10lf\n", solve(cnt[1], cnt[2], cnt[3]));
}


Measured memory_bytes: 221168
class Node:
    def __init__(self, num, left,  right):
        self.id = num
        self.left = left
        self.right = right
        self.parent = -1
        self.brother = -1
        if self.left== -1 and self.right==-1:
        	self.child = 0
        elif self.left != -1 and self.right!=-1:
        	self.child = 2
        else:
        	self.child = 1
        self.depth = 0
        self.height = 0
        self.type = None

    def show_info(self):
        print('node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}'.format(self.id, self.parent, self.brother, self.child, self.depth, self.height, self.type))

def SetNode(I_Line):
	L = list(map(int, I_Line.split()))
	num = L[0]
	left = L[1]
	right = L[2]
	node = Node(num, left, right)
	T[num] = node
	if left != -1:
		T[-1] -= left
	if right != -1:
		T[-1] -= right

def setPBD(i,p,b,d): #??????????????????
    node = T[i]
    node.parent = p
    node.brother = b
    node.depth = d
    if node.parent == -1:
        node.type = "root"
    elif node.child == 0:
        node.type = "leaf"
    else:
        node.type = "internal node"
    if node.left != -1:
        setPBD(node.left, i, node.right, node.depth + 1)
    if node.right != -1:
        setPBD(node.right, i, node.left, node.depth + 1)

def setH(i): #??????????????????
    node = T[i]
    if node.left == -1:
        leftheight = 0
    else:
        leftheight = setH(node.left) + 1
    if node.right == -1:
        rightheight = 0
    else:
        rightheight = setH(node.right) + 1
    node.height = max(leftheight, rightheight)
    return node.height

n = int(input())
T = [None] * n
T.append(int(n * (n-1)/2))
for i in range(n):
    x = input()
    SetNode(x)

root = T[-1]
setPBD(root, -1, -1, 0)
setH(root)
T.pop()
for i in T:
    i.show_info()

Measured memory_bytes: 7760
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  V a(n), b(n);
  cin >> a >> b;

  priority_queue<P> pq;
  rep(i, n) if (a[i] < b[i]) pq.emplace(b[i], i);
  ll ans = 0;

  while (!pq.empty()) {
    auto [y, j] = pq.top(); pq.pop();
    int s = b[(j-1+n)%n] + b[(j+1)%n];
    int m = (y-s)/s + 1;
    chmin(m, (y-a[j])/s);

    if (m <= 0) {
      cout << -1 << '\n';
      return 0;
    }
    ans += m;
    b[j] -= s*m;
    if (a[j] < b[j]) pq.emplace(b[j], j);
  }

  bool ok = true;
  rep(i, n) if (a[i] != b[i]) ok = false;
  cout << (ok ? ans : -1) << '\n';
  return 0;
}


Measured memory_bytes: 6904