akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 1000005

int n;
vector<int> G[MAX_N];
int M[MAX_N],L[MAX_N];

int C[MAX_N];

ll size[MAX_N];
ll num[MAX_N];

bool f(const int &a,const int &b){
  return ( num[a] < num[b]);
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&M[i],&L[i]);
    if(L[i]!=-1)G[L[i]].push_back(i);
  }
  queue<int> Q;
  for(int i=0;i<n;i++){
    C[i]=G[i].size();
    if(C[i]==0)Q.push(i);
  }
  ll ans=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    int parent=L[pos];
    size[pos]++;
    if(parent!=-1)size[parent]+=size[pos];
    num[pos]+=M[pos];
    if(parent!=-1)num[parent]+=num[pos];
    C[parent]--;
    if(C[parent]==0)Q.push(parent);
    sort(G[pos].begin(),G[pos].end(),f);
    
    ll v=0;
    for(int i=0;i<(int)G[pos].size();i++){
      ans+=v;
      v+=num[ G[pos][i] ];
    }
  }
  
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 83236
Infinity = 1000000

def dijkstra graph, s
  n = graph.size
  dist = Array.new(n, Infinity)
  visited = Array.new(n, false)
  dist[s] = 0
  loop do
    min = -1
    sd = Infinity
    n.times do |i|
      if (! visited[i]) && dist[i] < sd
        min = i
        sd = dist[i]
      end
    end
    break if min == -1
    visited[min] = true
    graph[min].each do |node|
      newLen = dist[min] + 1
      if(newLen < dist[node])
        dist[node] = newLen
      end
    end
  end
  dist
end

#ネットワーク取得
n = $stdin.gets.to_i
graph = Array.new(n).map{Array.new}
n.times do
  input = $stdin.gets.split(" ").map(&:to_i)
  input[1].times do |t|
    graph[input[0] - 1] << input[t + 2] - 1
  end
end

#パケット処理
$stdin.gets.to_i.times do
  s, d, v = $stdin.gets.split(" ").map(&:to_i)
  dist = dijkstra(graph, s - 1)
  if dist[d - 1] + 1 <= v
    puts dist[d - 1] + 1
  else
    puts "NA"
  end
end

Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
char n;
bool a1,a2;
int main(){
    while(n!='\n'){
        scanf("%c",&n);
        if(!a1&&n=='C') a1=1;
        else if(a1&&n=='F') {cout<<"Yes";return 0;}}
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  K--;

  char c = S[K];
  rep(i, N) {
    if (S[i] != c)
      S[i] = '*';
  }
  cout << S << endl;
}

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

const int inf = 1e9 + 7;

int main(){
	int r, c, k;
	cin >> r >> c >> k;
	vector<vector<long long>> grid(r + 1, vector<long long> (c + 1)), final(r + 1, vector<long long>(c + 1));
	vector<vector<vector<long long>>> dp(r + 1, vector<vector<long long>>(c + 1, vector<long long>(4)));
	for(int i = 0; i < k; i++){
		int ri, ci, vi;
		cin >> ri >> ci >> vi;
		grid[ri][ci] = vi;
	}
	for(int i = 1; i <= r; i++){
		for(int j = 1; j <= c; j++){
			long long x = *max_element(dp[i - 1][j].begin(), dp[i - 1][j].end());
			for(int k = 2; k < 4; k++){
				dp[i][j][k] = max(dp[i][j - 1][k - 1] + grid[i][j], dp[i][j - 1][k]);
			}
			dp[i][j][1] = max({dp[i][j - 1][1], dp[i][j - 1][0] + grid[i][j], grid[i][j] + x});
			dp[i][j][0] = max(dp[i][j - 1][0], x);
			/*cout << '{';
			for(int k = 0; k < 4; k++){
				cout << dp[i][j][k] << ' ';
			}
		cout << "} ";*/
		}//cout << endl;
	}
	long long ans = 0;
	for(int i = 0; i < 4; i++){
		ans = max(ans, dp[r][c][i]);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 777564
#include <bits/stdc++.h>
using namespace std;
char s[2][2]={'R','Y','G','B'};
char so(int i,int j,int k){
	int a=i+j,b=i-j;
	a+=2027,b+=2027;
	a/=k,b/=k;
	a=a&1,b=b&1;
	return s[a][b];
}
int main(){
	int n,m,k,i,j;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++) 
			printf("%c",so(i,j,k));
		printf("\n");
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	bool flag = false;
	for (ll h = 1; h <= 3500&&!flag; h++) {
		for (ll n = 1; n <= 3500; n++) {
			ll u = N * n * h, d = 4 * h * n - N * n - N * h;
			if (d > 0 && u % d == 0 ) {
				cout << h << " " << n << " " << u / d << endl;
				flag = true;
				break;
			}
		}
	}

}

Measured memory_bytes: 3636
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int ans = 0;
		String S = sc.next();
		long K = sc.nextLong();
		int length = S.length();
		int serial = 0;
		for (int i = 0; i < length; i++) {
			if (S.charAt(i) == '1') {
				serial++;
			} else {
				break;
			}
		}
		if (serial == 0) {
			ans = Character.getNumericValue(S.charAt(0));
		} else if (serial >= K) {
			ans = 1;
		} else {
			ans = Character.getNumericValue(S.charAt(serial));
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace codefestival_2016_qualA_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0; i < n; i++)
            {
                if (i + 1 == a[a[i] - 1])
                {
                    ans++;
                }
            }Console.Write(ans/2);
        }
    }
}

Measured memory_bytes: 20064
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,a[N];

int main() {
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1); int mx1=0,mx2=0;
	for (int i=1;i<=n;++i) {
		int j=i;
		while (j<n&&a[i]==a[j+1]) ++j;
		if (j-i+1>=4) mx1=mx2=a[i];
		else if (j-i+1>=2) mx2=mx1,mx1=a[i];
		i=j;
	}
	printf("%lld\n",1ll*mx1*mx2);
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = long long;

void Main() {
    ll r, d, x;
    cin >> r >> d >> x;

    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        long a = readInt();
        long b = readInt();
        long c = readInt();
        long d = readInt();

        long res = Math.max(a * c, a * d);
        long res2 = Math.max(b * c, b * d);
        System.out.println(Math.max(res, res2));
    }
}


Measured memory_bytes: 32588
#include<stdio.h>
#include<stdlib.h>
#define MAX(x, y) (((x) > (y)) ? (x) : (y))

int main() {

	unsigned short *A, *B;//, *C;

	int n, i, max=(1<<30)*-1;
	scanf("%d", &n);

	A = (unsigned short*)malloc(sizeof(short) * n + 1);
	B = (unsigned short*)malloc(sizeof(short) * n + 1);

	for (i = 0; i < n; i++) {
		scanf("%hu", &A[i+1]);
	}

	for (i = 1; i <= n; i++) max = MAX(max, A[i]);
	int C[max+1] = {0};

//	C = (unsigned short*)malloc(sizeof(short) * max + 1);
//	for (i = 0; i <= max; i++) C[i] = 0;

	for (i = 0; i < n; i++) C[A[i+1]]++;
	for (i = 1; i <= max; i++) C[i] += C[i-1];

	for (i = n; i >= 1; i--) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	printf("%d", B[1]);
	for (i = 2; i <= n; i++) {
		printf(" %d", B[i]);
	}
	printf("\n");

	free(A);
	free(B);
	return 0;
}


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

int main() {
	int n;
	int histgram[8] = {0};
	cin >> n;
	for(int i = 0; i < n; i++) {
		double tmp;
		cin >> tmp;
		if(tmp < 165) histgram[0]++;
		else if(tmp < 170) histgram[1]++;
		else if(tmp < 175) histgram[2]++;
		else if(tmp < 180) histgram[3]++;
		else if(tmp < 185) histgram[4]++;
		else histgram[5]++;
	}
	for(int i = 0; i < 6; i++) {
		cout << i + 1 << ":";
		for(int j = 0; j < histgram[i]; j++)
			cout << "*";
		cout << endl;
	}
}

Measured memory_bytes: 1232
S = input()

first_two = int(S[:2])
last_two = int(S[-2:])

if first_two == 0 or first_two > 12:
    if last_two == 0:
        print('NA')
    elif last_two <= 12:
        print('YYMM')
    else:
        print('NA')
elif first_two <= 12:
    if last_two == 0:
        print('MMYY')
    elif last_two <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
    

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

int main() {
    ll l; cin >> l;
    l = (l * 1000000) / 3;
    double d = (double)l/1000000;
#if 0
    double ans = 0;
    for (ll i = 1; i <= l-2; i++) {
        for (ll j = 1; j <= l-2; j++) {
            ll k = l - i - j;
            double sum = (double)i * j * k / 1000000;
            double ans = max(ans, sum);
        }
    }
#endif
    printf("%.12f", (double)d*d*d);
}

Measured memory_bytes: 256
import numpy as np
import bisect

n, m  = list(map(int, input().split()))
drinks = [list(map(int, input().split())) for _ in range(n)]

drinks.sort(key = lambda x: x[0])
prices = np.array([x[0] for x in drinks])
vols = np.array([x[1] for x in drinks])
cum_vols = np.cumsum(vols)
idx = bisect.bisect_left(cum_vols, m) #このidxは1 ~ vols[idx]を使う

#print(idx)
l = 0 if idx == 0 else sum(vols[:idx])

vols[idx] = m - l
print(np.dot(vols[:(idx+1)], prices[:(idx+1)]))


Measured memory_bytes: 38660
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
map<lli, lli> d;
set<lli> s;
int main()
{
    lli n;
    lli a[200005] = {};
    cin >> n;
    s.insert(-1);
    s.insert(n);
    lli ans = 0;
    rep(i, n)
    {
        cin >> a[i];
        d[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        s.insert(d[i]);
        auto it = s.find(d[i]);
        --it;
        lli left = *it;
        ++it;
        ++it;
        lli right = *it;
        ans += i * (d[i] - left) * (right - d[i]);
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int n;
vector<int> a;
vector<bool> dp;

int main() {
	cin >> n;
	a.resize(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	int maxa = a[n - 1];

	dp.assign(maxa+1, true);

	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			dp[a[i]] = false;
			dp[a[i+1]] = false;
		}
	}

	rep(i, n) {

		for (int j = 2 * a[i]; j <= maxa; j += a[i]) {
			if(j >= 0 && j <= maxa) dp[j] = false;
		}
	}

	int cnt = 0;
	rep(i, n) {
		if (dp[a[i]]) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3976
#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

struct UnionFind
{
    vector<int> data;
    UnionFind() {}
 
    // initialize
    UnionFind(int size) : data(size, -1) {}
 
    void unite_set(int x, int y){
        x = root(x);
        y = root(y);
        bool is_unite = (x != y);
        
        if (is_unite){
            if (data[y] < data[x]){
                swap(x, y);
            }
            data[x] += data[y];
            data[y] = x;
        }
    }
 
    bool is_same(int x, int y){
        return root(x) == root(y);
    }
 
    int root(int x){
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
 
    int size(int x){
        return -data[root(x)];
    }
};

int main()
{
    int n, m;
    int ans, a, b;
    ans = 0;
    cin >> n >> m;
    vector<int> data;
    vector<pair<int, int>> edge(m);
    data.resize(n);
    
    for (int i=0; i<n; ++i){
        data[i] = i;
    }
    for (int i=0; i<m; ++i){
        cin >> a >> b;
        edge[i] = make_pair(a, b);
    }
    for (int i=0; i<m; ++i){
        struct UnionFind d(n);
        for (int j=0; j<m; ++j){
            if(j == i){continue;}
            d.unite_set(edge[j].first-1, edge[j].second-1);
        }
        for (int j=0; j<n; ++j){
            if(j == n-1){
                if(!d.is_same(data[n-1], data[0])){
                    ans++;
                    break;
                }
            }
            else {
                if(!d.is_same(data[j], data[j+1])){
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

if abs(x) == abs(y):
    print(1)
elif abs(x) < abs(y):
    if y > 0:
        if x >= 0:
            print(abs(y) - abs(x))
        else:
            print(abs(y) - abs(x) + 1)
    else:
        if x >= 0:
            print(abs(y) - abs(x) + 1)
        else:
            print(abs(y) - abs(x) + 2)
else:
    if x < 0:
        if y <= 0:
            print(abs(x) - abs(y))
        else:
            print(abs(x) - abs(y) + 1)
    else:
        if y <= 0:
            print(abs(x) - abs(y) + 1)
        else:
            print(abs(x) - abs(y) + 2)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N, D;
    cin >> N >> D;
    vector<vi> X(N, vi(D));
    rep(i, N) {
        rep(j, D)cin >> X[i][j];
    }

    int ans = 0;
    rep(i, N)rep(j, i) {
        ll sum = 0;
        rep(k, D) {
            sum += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
        }
        int s = round(sqrt(sum));
        if (s*s == sum)ans++;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,k;
	cin>>k>>a>>b;
	if(((a-1)/k+1)*k<=b)cout<<"OK";
	else cout<<"NG";
	return 0;
}


Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,m,ans=0; cin>>n>>m;
    vector<ll> a(n,0),sum(n+1,0);
    map<ll,ll> q;
    q[0]=1;
    rep(i,n){
        cin>>a[i];
        sum[i+1]=(sum[i]+a[i])%m;
        if(q.count(sum[i+1])) q[sum[i+1]]++;
        else q[sum[i+1]]=1;
    }
    for(auto p : q){
        ans+=p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

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

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  
  int n;
  cin >> n;
  
  int max = 55555;
  int flag[max+1] = {};
  flag[0] = flag[1] = 1;
  flag[2] = 0;
  for(int i=2;i<=sqrt(max);i++){
    for(int j=2; i*j<=max;j++){
    	flag[i*j] = 1;
    }
  }
  list<int> candidate;
  for(int i=0; i<=max;i++){
    if(flag[i]==0){
      if(i%5==1) candidate.push_back(i);
    }
  }
  //cout << candidate.size() << endl;
  
  int count = 0;
  for(auto c: candidate){
    cout << c << " ";
    count++;
    if(count==n)break;
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3952
import sys
def input(): return sys.stdin.readline().strip()

def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    if V <= W:
        print("NO")
        return
    d = abs(A - B)
    v = abs(V - W)
    if d > v * T: print("NO")
    else: print("YES")

if __name__ == "__main__":
    main()


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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)2
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 100005
#define mxnn 2000005
int arr[mxn],dp[mxn];
int32_t main(){
sp;
int n,k;
cin >>n>>k;
int arr[n+1];
for(int i = 1;i<=n;i++) cin >>arr[i];
fill(dp,dp+mxn,inf);
dp[1] = 0;
for(int i = 1;i<=n;i++){
    for(int j = 1;j<=k;j++){
        if(i-j>=1){
            dp[i] = min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
    }
}
cout<<dp[n];
return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <algorithm>

void print_array(std::vector<int> list)
{
  for(int i = 0; i < list.size(); ++i){
    if(i>0) std::cout << " ";
    std::cout << list[i];
  }
  std::cout << std::endl;
}

void SelectionSort(std::vector<int> &listToSort, int &swapCounter){
    int mini;
    for (int i=0; i<listToSort.size(); i++) {
        mini = i;
        //std::cout << "entree" << mini << std::endl;
        for (int j=i; j<listToSort.size(); j++) {
            if(listToSort[j]<listToSort[mini]) {
              //  std::cout << "j:" << j << std::endl;
                mini = j;
            }
        }
                //std::cout << "sortie" << mini << std::endl;

        std::swap(listToSort[i],listToSort[mini]);
        if (i!=mini) swapCounter++;
    }
}

int main(void){

    int num;
    std::cin >> num;
    if (num>100) {
        std::cout << "list too big" << std::endl;
        return 1;
    }
    std::vector<int> list;
    for(int i = 0; i < num; i++){
    int value;
    std::cin >> value;
    list.push_back(value);
    }

    int swapNumber=0;
    
    SelectionSort(list, swapNumber);

    print_array(list);
    std::cout << swapNumber << std::endl;

    return 0;
}

Measured memory_bytes: 1224
/*
* @Author: wxyww
* @Date: 2020-03-30 08:43:56
* @Last Modified time: 2020-03-30 09:44:40
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 210;
ll read() {
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int a[N][N],b[N][N],num[N][N];
queue<int>q[N][N];
int S,T;
struct node {
	int v,nxt,w;
}e[N * N];
int head[N],ejs = 1,cur[N];
void add(int u,int v,int w) {
	e[++ejs].v = v;e[ejs].nxt = head[u];head[u] = ejs;e[ejs].w= w;
	e[++ejs].v = u;e[ejs].nxt = head[v];head[v] = ejs;e[ejs].w = 0;
}
int dep[N];
queue<int>qq;
int bfs() {
	memset(dep,0,sizeof(dep));
	dep[S] = 1;
	qq.push(S);
	while(!qq.empty()) {
		int u = qq.front();qq.pop();
		for(int i = head[u];i;i = e[i].nxt) {
			int v = e[i].v;
			if(!dep[v] && e[i].w){
				dep[v] = dep[u] + 1;
				qq.push(v);
			}
		}
	}
	return dep[T];
}

int dfs(int u,int now) {
	if(u == T) return now;
	int ret = 0;
	for(int &i = cur[u];i;i = e[i].nxt) {
		int v = e[i].v;
		if(dep[v] == dep[u] + 1 && e[i].w) {
			int k = dfs(v,min(e[i].w,now - ret));
			e[i].w -= k;
			e[i ^ 1].w += k;
			ret += k;
			if(ret == now) return ret;
		}
	}
	return ret;
}

void dinic() {
	while(bfs()) {
		memcpy(cur,head,sizeof(cur));
		dfs(S,10000000);
	}

}
int main() {
	int n = read(),m = read();
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= m;++j) {
			a[i][j] = read();
			num[i][(a[i][j] - 1) / m + 1]++;
			q[i][(a[i][j] - 1) / m + 1].push(a[i][j]);
		}
	}

	S = n + n + 1,T = S + 1;

	for(int t = 1;t <= m;++t) {
		memset(head,0,sizeof(head));
		ejs = 1;
		// puts("");
		for(int i = 1;i <= n;++i) {
			for(int j = 1;j <= n;++j) {
				if(num[i][j]) {
					// printf("%d %d\n",i,j);
					add(i,j + n,1);
				}
			}
		}
		// puts("");
		for(int i = 1;i <= n;++i) {
			add(S,i,1);
			add(i + n,T,1);
		}

		dinic();
		for(int u = 1;u <= n;++u) {
			for(int i = head[u];i;i = e[i].nxt) {
				if(!e[i].w && e[i].v > n) {
					num[u][e[i].v - n]--;
					b[u][t] = q[u][e[i].v - n].front();
					q[u][e[i].v - n].pop();
					break;
				}
			}
		}

	}


	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= m;++j)
			printf("%d ",b[i][j]);
		puts("");
	}

	for(int k = 1;k <= m;++k) {
		for(int t = 1;t <= n;++t) {
			for(int i = n;i >= 1;--i) {
				if(b[i][k] < b[i - 1][k])
					swap(b[i][k],b[i - 1][k]);
			}
		}
	}
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= m;++j)
			printf("%d ",b[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 30464
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int (i) = 0; (i) < (n); ++(i))
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n){
        if(s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3132
///*Radhe Krishna*/
import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.net.CookieHandler;
import java.nio.file.attribute.FileAttribute;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.Arrays;
import java.util.concurrent.Callable;



public class Main {
    static int mod = 1000000007;

    static 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;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
//        Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n>=30){
    System.out.println("Yes");
}
else{
    System.out.println("No");
}
       
    }
}





Measured memory_bytes: 32992
n = int(input())
Lis = sorted(list(map(int, input().split())))
c = 0

for i in range(len(Lis)):
    for j in range(len(Lis)):
        for k in range(len(Lis)):
            if i < j < k:
                if Lis[i] < Lis[j] < Lis[k]:
                    if (Lis[i] < Lis[j] + Lis[k]) and (Lis[j] < Lis[i] + Lis[k]) and (Lis[k] < Lis[j] + Lis[i]):
                        c += 1
print(c)

Measured memory_bytes: 9116
#include <iostream>
#include <queue>

using namespace std;

int main() {
    int Q, T, F, flag = 1;
    char c;
    string S;
    cin >> S >> Q;
    deque<char> q;
    for (int i = 0; i < S.size(); ++i) {
        q.push_back(S[i]);
    }
    while (Q--) {
        cin >> T;
        if (T == 1) {
            flag = !flag;
        } else {
            cin >> F >> c;
            if (F == 1) {
                if (flag) {
                    q.push_front(c);
                } else {
                    q.push_back(c);
                }
            } else {
                if (flag) {
                    q.push_back(c);
                } else {
                    q.push_front(c);
                }
            }
        }
    }
    if (flag) {
        deque<char>::iterator it = q.begin();
        for (; it != q.end(); it++) {
            cout << *it;
        }
    } else {
        deque<char>::reverse_iterator rit = q.rbegin();
        for (; rit != q.rend(); rit++) {
            cout << *rit;
        }
    }
    return 0;
}

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

int main() {

int n;
cin >> n;
int ans=0;
  rep(N,n+1)
  {  int divisornum=0;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            divisornum++;
            // 重複しないならば i の相方である N/i も 
            if (N/i != i) divisornum++;
        }
    }
    if(divisornum==8&&N%2!=0)
    ans++;
  }

printf("%d\n",ans);
return 0;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>) {
  val (n, r) = readLine()!!.split(" ").map(String::toInt)
  var innerRating = 0
  if(n >= 10) {
    innerRating = r
  }
  else {
    innerRating = r + 100*(10 -n)
  }
  
  println(innerRating)
}

Measured memory_bytes: 37748
using System;
class c
{
    static void Main()
    {
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine((a[0] - b[0]) * (a[1] - b[1]));
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

inline void max_self(ll& lhs, ll rhs)
{
    lhs = max(lhs, rhs);
}

ll a[16][16];
ll group_val[1<<16];
ll dp[1<<16];
int used[16];

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

    int n;
    cin >> n;

    rep(i,0,n) rep(j,0,n) cin >> a[i][j];

    memset(group_val, 0, (1<<n)*sizeof(ll));
    memset(dp, 0, (1<<n)*sizeof(ll));

    for (int mask = 0; mask < (1<<n); ++mask) { // O(2^n * n^2)
        int m = 0;
        for (int i = 0; i < n; ++i) {
            if (mask & (1<<i)) used[m++] = i;
        }
        for (int i = 0; i < m; ++i) {
            for (int j = i+1; j < m; ++j) {
                group_val[mask] += a[used[i]][used[j]];
            }
        }
    }

    for (int used_mask = 0; used_mask < (1<<n); ++used_mask) { // O(3^n)
        int unused_mask = ((1<<n)-1) ^ used_mask;
        for (int submask = unused_mask; submask > 0; submask = (submask-1)&unused_mask) {
            max_self(dp[used_mask|submask], dp[used_mask]+group_val[submask]);
        }
    }

    ll ans = 0;
    for (int mask = 0; mask < (1<<n); ++mask) {
        max_self(ans, dp[mask]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    lint n;
    scanf("%lld", &n);
    string s;
    while(n){
        --n;
        s += 'a' + n%26;
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << "\n";
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;

int main()
{
    int  n;
    cin >> n;
    long long int sum = 0;
    
    for(int i=1; i<=n; i++){
//        cout << i << endl;
        if(i%3==0 || i%5==0){
            continue;
        }else{
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

//#define EVEL 1

#ifndef EVEL00
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

ulli X[200010];
vector<ulli> Xs;
ulli N;
ulli med, medd;

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

	cin >> N;
	for(ulli i = 0; i < N; i++){
		cin >> X[i];
		Xs.push_back(X[i]);
	}
	sort(Xs.begin(), Xs.end());
	med = Xs[N/2];
	medd = Xs[(N/2)-1];

	for(ulli i = 0; i < N; i++){
		if(X[i] < med){
			cout << med << "\n";
		}else{
			cout << medd << "\n";
		}
	}

	return 0;
}


Measured memory_bytes: 5488
import java.util.*; 
  
public class Main{ 
  
    int n; 
    int[][] c; 
    char[] per; 
    boolean[] used; 
    int goal,ans; 
    int[] v;
  
    void solve(){ 
        Scanner sc = new Scanner(System.in); 
  
        n = sc.nextInt(); 
        c = new int[n][n]; 
        for(int i=0; i<n; i++){ 
            for(int j=0; j<n; j++){ 
                int cc = sc.nextInt(); 
                c[i][j] = cc; 
                c[j][i] = cc; 
            } 
        }

/*
	n = 3;
	c = new int[][]{{0,1,3},{1,0,8},{3,8,0}};
*/  
	v = new int[8765433];
	Arrays.fill(v,-1);
	dijkstra();

	int max = 0;
	for(int i=0; i<v.length; i++) max = Math.max(max,v[i]);
  
        System.out.println(max); 
    } 
  
    void dijkstra(){ 
        //permutation,cost 
        PriorityQueue<int[]>  
            q = new PriorityQueue<int[]>(n, new Comparator<int[]>(){ 
                    public int compare(int[] a, int[] b){ 
                        return a[1] - b[1]; 
                    } 
                }); 
  
	String sss = "";
	for(int i=1; i<=n; i++) sss += Integer.toString(i);
        q.add(new int[]{Integer.parseInt(sss),0}); 

        while(q.size()>0){ 
            int[] pp = q.poll(); 
            int perm = pp[0]; 
            int cost = pp[1]; 
  
            if(v[perm/10]!=-1) continue; 
            v[perm/10] = cost; 
  
            char[] permm = Integer.toString(perm).toCharArray(); 
  
            for(int i=0; i<n; i++){ 
                for(int j=i+1; j<n; j++){ 
                    char tmp = permm[i]; 
                    permm[i] = permm[j]; 
                    permm[j] = tmp; 
                    q.add(new int[]{Integer.parseInt(new String(permm)), cost+c[i][j]}); 
                    tmp = permm[i]; 
                    permm[i] = permm[j]; 
                    permm[j] = tmp; 
                }    
            } 
        } 
    } 
  
    public static void main(String[] args){ 
        new Main().solve(); 
    } 
} 

Measured memory_bytes: 126988
#include <math.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

ll N, ans;

int main() {
    cin >> N;

    while (N != 0) {
        ld sq = sqrt(ld(N));
        if (sq == ll(sq)) { ans = N; break; }
        N--;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int a, b;
    cin >> a >> b;
    if ((a > 9) || (b > 9)) cout << -1 << endl;
    else cout << a*b << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    
    int l, r = 0, b = 0;
    l = S.length();
    for(int i=0;i<l;i++){
        if(S[i] == '0')
            r++;
        else
            b++;
    }

    cout << l - abs(r - b) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define N 17
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template <class T> T Max(T &a,T b){return a=max(a,b);}
template <class T> T Min(T &a,T b){return a=min(a,b);}
typedef pair<string,string> P;
int n,K;
string his[N];

string getNx(const string &a, const string &str){
  string res;
  int j = 0,ch[26]={};
  
  for(char s:str)if(s!='?')ch[s-'A']++; 
  for(char s:str){
    if(j<K &&(a[j] == s ||(s == '?' && !ch[a[j]-'A'])))res = a[j++] + res;
    else res += s;
  }
  if(j < K) return "";
  return res;
}

string DP(){
  map<string,string> dp[1<<N]; // (key = current thread, value = min order)
  dp[0][string(n,'?')] = "";
  
  for(int bit=0;bit<(1<<n);bit++){ //used
    for(int i=0;i<n;i++){ // next use
      if(bit>>i&1)continue;
      for(P p:dp[bit]){
        int nbit = bit | (1<<i);
        string nsta = getNx(his[i],p.first);
        string norder = p.second + char('A'+i);
        if(nsta == "")continue;
        
        if(!dp[nbit].count(nsta)) dp[nbit][nsta] = norder;
        else Min(dp[nbit][nsta],norder);
      }
    }
  }
  string ans(50,'Z');
  for(P p:dp[(1<<n)-1])Min(ans,p.second);
  return ans;
}

signed main(){
  cin>>n>>K;
  for(int i=0;i<n;i++)cin>>his[i];
  cout<<DP()<<endl;
  return 0;
}

Measured memory_bytes: 15848
package main
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)
func main() {
  var scanner = bufio.NewScanner(os.Stdin)
  var n,s int
  var a []int
  var m []bool
  scanner.Scan()
  n,_ = strconv.Atoi(scanner.Text())
  a = make([]int,n)
  m = make([]bool,n)
  for i:=0;i<n;i++ {
    scanner.Scan()
    a[i],_ = strconv.Atoi(scanner.Text())
    a[i]--
  }
  s = 0
  for i:=0;!m[i]; {
    m[i] = true
    i = a[i]
    s++
    if i == 1 {
      fmt.Println(s)
      os.Exit(0)
    }
  }
  fmt.Println(-1)
}

Measured memory_bytes: 2048
def primediv(n):
  ans = []
  hoge = n
  for i in range(2,int(-(-n**0.5//1))+1):
    if hoge%i == 0:
      c = 0
      while hoge%i == 0:
        c += 1
        hoge = hoge//i
      ans.append([i,c])
  if hoge != 1:
    ans.append([hoge,1])
  if ans == []:
    ans.append([n,1])
  return ans


n,p = map(int,input().split())
a = primediv(p)
c = 1
for k in a:
  c *= k[0]**(k[1]//n)
print(c)

Measured memory_bytes: 3064
import math
A,B=[int(i) for i in input().split()]

a=A/0.08
b=(A+1)/0.08
c=10*B
d=10*(B+1)



if a<=c:
    if math.ceil(c)<b:
        print(math.ceil(c))
    else:
        print(-1)
else:
    if math.ceil(a)<d:
        print(math.ceil(a))
    else:
        print(-1)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            if (line == "ABC")
                Console.WriteLine("ARC");
            else
                Console.WriteLine("ABC");


        }
    }
}


Measured memory_bytes: 25788
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (a, b): (Vec<usize>, Vec<usize>) = {
        let (mut a, mut b) = (vec![], vec![]);
        for _ in 0..(N - 1) {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b)
    };
    let M: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (u, v): (Vec<usize>, Vec<usize>) = {
        let (mut u, mut v) = (vec![], vec![]);
        for _ in 0..M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            u.push(iter.next().unwrap().parse().unwrap());
            v.push(iter.next().unwrap().parse().unwrap());
        }
        (u, v)
    };

    let G = {
        let mut G = vec![std::collections::HashMap::new(); N + 1];
        for i in 0..(N - 1) {
            G[a[i]].insert(b[i], i);
            G[b[i]].insert(a[i], i);
        }
        G
    };

    let mut dp = vec![std::collections::HashSet::new(); M];
    for i in 0..M {
        let mut prev = vec![(0, 0); N + 1];
        let mut q = std::collections::VecDeque::new();
        q.push_back(u[i]);
        while let Some(j) = q.pop_front() {
            for (&x, &e) in &G[j] {
                if prev[x].0 == 0 {
                    prev[x] = (j, e);
                    q.push_back(x);
                }
            }
        }
        let mut j = v[i];
        while j != u[i] {
            dp[i].insert(prev[j].1);
            j = prev[j].0;
        }
    }

    let mut res = 0i64;
    for i in 1..(1 << M) {
        let mut x = 0;
        let mut used = vec![false; N + 1];
        let mut s = 0;
        for j in 0..M {
            if (i >> j) & 1 == 1 {
                x += 1;
                for &y in &dp[j] {
                    if !used[y] {
                        s += 1;
                    }
                    used[y] = true;
                }
            }
        }
        let d = 1i64 << (N - 1 - s);

        if x % 2 == 1 {
            res += d;
        } else {
            res -= d;
        }
    }
    let ans = (1i64 << (N - 1)) as i64 - res;
    println!("{}", ans);
}


Measured memory_bytes: 4352
import math

N = int(input())

ans1 = 0

A = '1'
B = str(N)

if len(A)>=len(B):
    ans = len(A)
else:
    ans = len(B)
    
for i in range(2,int(math.sqrt(N)+1)):
    A = i
    if N%A==0:
        B = int(N / A)
        A = str(A)
        B = str(B)
#        print(A, B)
        if len(A)>=len(B):
            ans1 = len(A)
        else:
            ans1 = len(B)
        if ans1 <= ans:
            ans = ans1
    if len(str(A))==len(str(B)):
        break
print(ans)


Measured memory_bytes: 3064