akhauriyash/Code-Regression huggingface dataset:
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

patterns = itertools.permutations(list(range(1, N+1)), N)
p_i = 0
q_i = 0
for i, ptn in enumerate(patterns):
  p_same = True
  q_same = True
  for j, num in enumerate(ptn):
    if P[j] != num:
      p_same = False
    if Q[j] != num:
      q_same = False
  if p_same:
    p_i = i
  if q_same:
    q_i = i
print(abs(p_i-q_i))

Measured memory_bytes: 73892
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		long ans = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int l = 1; l <= k; l++) {
					ans += gcd(gcd(i, j), l);
				}
			}
		}
		System.out.println(ans);
	}
	public static int gcd(int a, int b) {
		int na = Math.max(a, b);
		int nb = Math.min(a, b);
		if(na % nb != 0) {
			return gcd(nb, na % nb);
		}else return nb;
	}
} 


Measured memory_bytes: 35920
#include <bits/stdc++.h>
using namespace std;
#define ll long long


const int N = 3e5 + 20;
const double pi = 3.141592653;
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fast();
//cout<<fixed<<setprecision(6);
    ll a;
    cin>>a;
    cout<<a*(a+1)/2;

}

























Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		
		int aa = a % 10;
		int bb = b % 10;
		int cc = c % 10;
		int dd = d % 10;
		int ee = e % 10;
      
      if(aa == 0){
        aa += 10;
      } if(bb == 0){
        bb += 10;
      }if(cc == 0){
        cc += 10;
      } if(dd == 0){
        dd += 10;
      } if(ee == 0){
        ee += 10;
      }
		int min = 10;
		if(min > aa){
		    min = aa;
		}if(min > bb){
		    min = bb;
		}if(min > cc){
		    min = cc;
		}if(min > dd){
		    min = dd;
		}if(min > ee){
		    min = ee;
		}
      int aaa = 0;
      int bbb = 0;
      int ccc = 0;
      int ddd = 0;
      int eee = 0;
      
      	if(a%10 != 0){
		 aaa =(int)Math.ceil(a / 10.0)*10;
        }else{
         aaa = a;
        }
      if(b%10 != 0){
		bbb = (int)Math.ceil(b / 10.0)*10;
        }else{
         bbb = b;
        }
      if(c%10 != 0){
		 ccc = (int)Math.ceil(c / 10.0)*10;
        }else{
         ccc = c;
        }
      if(d%10 != 0){
		 ddd = (int)Math.ceil(d / 10.0)*10;
        }else{
         ddd = d;
        }
      if(e%10 != 0){
		 eee = (int)Math.ceil(e / 10.0)*10;
        }else{
         eee = e;
        }
		int ans = aaa + bbb + ccc + ddd + eee - 10 + min;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35704
#include<stdio.h>

int gcd(int a,int b){
  if(a==b){
    return a;
  }
  else if(a>b){
    return gcd(b,a);
  }
  else{
    return gcd(a,b-a);
  }
}

int main(){
  int a,b;

  while(scanf("%d %d",&a,&b)!=EOF){
    int x=gcd(a,b);
    int y=(a/x)*b;

    printf("%d %d\n",x,y);
  }

  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

class DisjoinSet{
    public:
        vector<int> p,r;
        
        DisjoinSet(){}
        DisjoinSet(int size){
            r.resize(size,0);
            p.resize(size,0);
            for(int i=0;i<size;i++) makeSet(i);
        }

        void makeSet(int x){
            p[x]=x;
            r[x]=0;
        }

        bool same(int x,int y){
            return findSet(x)==findSet(y);
        }

        void unite(int x,int y){
            link(findSet(x),findSet(y));
        }

        void link(int x,int y){
            if(r[x]>r[y]) p[y]=x;
            else{
                p[x]=y;
                if(r[x]==r[y]) r[y]++;
            }
        }

        int findSet(int x){
            if(x!=p[x]) p[x]=findSet(p[x]);
            return p[x];
        }
};

int main(){
    int n,m;
    cin>>n>>m;
    map<int,int> k;
    DisjoinSet ds=DisjoinSet(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        ds.unite(a,b);
    }
    for(int i=0;i<n;i++){
        int s=ds.findSet(i);
        k[s]++;
    }
    int ans=0;
    for(auto p:k){
        ans=max(ans,p.second);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13796
#l=list(map(int, input().split()))
a,b=map(int, input().split())
#l=list(map(int, input().split()))
#n = int(input())
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1



ans = 1
temp1 = divisor(a)
temp2 = divisor(b)
hoge = []
if len(temp1) < len(temp2):
    hoge = temp1
    hoge2 = temp2
else:
    hoge = temp2
    hoge2 = temp1

temp = []
for i in hoge:
    if i in hoge2:
        temp.append(i)

#print (temp)
for i in temp:
    if is_prime(i):
        ans += 1

print (ans)



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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  if ((A == 0) && (B == 0)) {
    rep(i, 0, H) {
      rep(j, 0, W) {
        cout << 1;
      }
      cout << endl;
    }
    return 0;
  } else if (B == 0) {
    rep(i, 0, H) {
      rep(j, 0, W) {
        if (j < A) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
      cout << endl;
    }

    return 0;
  } else if (A == 0) {
    rep(i, 0, H) {
      rep(j, 0, W) {
        if (i < B) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
      cout << endl;
    }

    return 0;
  } else {
    rep(i, 0, H) {
      rep(j, 0, W) {
        if (i < B && j < A) {
          cout << 1;
        } else if (i >= B && j >= A) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
      cout << endl;
    }
    return 0;
  }
};


Measured memory_bytes: 1280
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

  for (size_t i = 0; i < s.size(); ++i) {
    bool m = true;
    for (size_t j = 0; j < p.size(); ++j) {
      int k = j + i;
      if (j + i >= s.size()) {
        k = j + i - s.size();
      }
      if (s[k] != p[j]) {
        m = false;
        break;
      }
    }
    if (m) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1160
fun main() {
    val n = readLine()!!.toInt()
    val (d, x) = readLine()!!.split(' ').map { it.toInt() }
    val s = (0 until n)
            .map {
                val a = readLine()!!.toInt()
                (d - 1) / a + 1
            }
            .sum()
    println(s + x)
}


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

int main() {
  int n,x,t;

  cin >> n >> x >> t;

  cout << (n + (x - 1)) /x * t << endl;
  return 0;
}

Measured memory_bytes: 3620
a, b, k = map(int, input().split())
li = []
for i in range(a, a + k):
    if b < i:
        break
    li.append(i)
for i in range(b - k + 1, b + 1):
    if i < a:
        continue
    li.append(i)
li = list(set(li))
li.sort()
for num in li:
    print(num)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b;

int main(){
	cin>>a>>b;
	if(a>b) swap(a,b);
	cout<<string(b,(char)('0'+a))<<endl;
}

Measured memory_bytes: 256
N = None
M = None
S = []
P = []

if __name__ == "__main__":
    N, M = map(int, input().split())
    for _ in range(M):
        row = list(map(int, input().split()))[1:]
        S.append(row)
    P = list(map(int, input().split()))
    ans = 0
    for bit in range(1<<N):
        on_switches = []
        light = 0
        for i in range(N):
            if bit>>i&1:
                on_switches.append(i)
        for i in range(M):
            cnt = 0
            for s in S[i]:
                for on_switch in on_switches:
                    if s==on_switch+1:
                        cnt += 1
            if cnt%2==P[i]:
                light += 1
        if light==M:
            ans += 1
    print(ans)

Measured memory_bytes: 9056
def binary_search_low(ls, v):
    """
    ・基準(v)より小さい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok+1
    
def binary_search_high(ls, v):
    """
    ・基準(v)より大きい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return len(ls) - ok


n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0

for b in B:
    a_count = binary_search_low(A,b)
    b_count = binary_search_high(C, b)
    ans += a_count*b_count

print(ans)




Measured memory_bytes: 28376
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
		// System.err.println(System.currentTimeMillis() - t);
	}

	public void run() {
		Scanner sc = new Scanner();
		int K = sc.nextInt();
		int N = sc.nextInt();
		solve(K, N);
	}

	void solve(int K, int N) {
		if (K % 2 == 0) {
			int[] ans = new int[N];
			ans[0] = K / 2;
			for (int i = 1; i < N; ++i)
				ans[i] = K;
			for (int i = 0; i < N; ++i) {
				System.out.print(ans[i] + (i == N - 1 ? "\n" : " "));
			}
		} else {
			int[] cur = new int[N];
			Arrays.fill(cur, (K + 1) / 2);
			int p = N - 1;
			for (int q = 0; q < N / 2; ++q) {
				if (cur[p] == 1)
					--p;
				else if (p == N - 1)
					--cur[p];
				else {
					--cur[p];
					while (p + 1 < N) {
						++p;
						cur[p] = K;
					}
				}
			}

			for (int i = 0; i <= p; ++i) {
				System.out.print(cur[i] + (i == N - 1 ? "\n" : " "));
			}
		}
	}

	class Scanner {
		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 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());
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 53192
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
void solve(){
ll n=0,k=0,ans=0,r=0,m=0,x=0,y=0,z=0,d=0;
cin>>x>>k>>d;
r=abs(x)/d;
if(r>=k){
	cout<<abs(abs(x)-k*d);
}
else{
	if((k-r)%2==0)
	cout<<abs(abs(x)-r*d);
	else{
		cout<<min(abs(abs(x)-r*d-d),abs(abs(x)-r*d+d));
	}
}
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
   //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	while(1){
		cin >> n >> m;
		if(n + m == 0) break;
		vector<int> a(n), b(m);
		int sa = 0, sb = 0;
		rep(i, 0, n){
			cin >> a[i];
			sa += a[i];
		}
		rep(i, 0, m){
			cin >> b[i];
			sb += b[i];
		}
		sort(all(a));
		sort(all(b));
		int ansa = INF, ansb = 0;
		rep(i, 0, n){
			rep(j, 0, m){
				if(sa - a[i] + b[j] == sb + a[i] - b[j]){
					if(a[i] + b[j] <= ansa + ansb){
						ansa = a[i];
						ansb = b[j];
					}
				}
			}
		}
		if(ansa == INF) cout << -1 << endl;
		else cout << ansa << ' ' << ansb << endl;
	}
}


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

int main() {
	int n, y; cin >> n >> y;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n-i; j++) {
			int sum = i * 10000 + j * 5000 + (n - i - j) * 1000;
			if (sum == y) {
				cout << i << ' ' << j << ' ' << (n - i - j) << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  vector<vector<int64_t>> G(N);
  for(int i=0; i<N-1; i++){
    int64_t a, b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);
  }
  
  vector<int64_t> C(N);
  for(int i=0; i<N; i++){
    cin >> C.at(i);
  }
  sort(C.rbegin(),C.rend());
  
  vector<int64_t> ans(N);
  vector<bool> seen(N,false);
  queue<int> Q;
  int cnt = 0;
  Q.push(0);
  seen.at(0) = true;
  ans.at(0) = C.at(cnt);
  while(Q.size()){
    int x = Q.front();
    Q.pop();
    for(int i=0; i<G.at(x).size(); i++){
      if(!seen.at(G.at(x).at(i))){
        cnt++;
        ans.at(G.at(x).at(i)) = C.at(cnt);
        seen.at(G.at(x).at(i)) = true;
        Q.push(G.at(x).at(i));
      }
    }
  }
  int M = 0;
  for(int i=1; i<N; i++){
    M += C.at(i);
  }
  cout << M << endl;
  for(int i=0; i<N; i++){
    cout << ans.at(i) << endl;
  }
}

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

int main() {
	int n, m;
	cin >> n >> m;
	int count_ball[100000];
	for (int i = 0; i < n; ++i)count_ball[i] = 1;
	bool red[100000] = { false };
	red[0] =  true;
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		if (red[x]) {
			--count_ball[x];
			++count_ball[y];
			red[y] = true;
			if (count_ball[x] == 0) {
				red[x] = false;
			}
		}
		else {
			--count_ball[x];
			++count_ball[y];
		}
	}
	int ans = 0;
	for (bool i : red) {
		ans += i ? 1 : 0;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4072
#include "bits/stdc++.h"
using namespace std;


int main() {
	int x;
	cin >> x;

	int t;
	int d = 0;
	for (t = 1; t <= x; t++) {
		for (int i = 1; i <= t; i++) {
			if (++d == x) {
				break;
			}
		}
		if (d == x) {
			break;
		}
	}
	cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>



int main(){
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    int arr[n], cost[n];
    for (int i = 0 ; i < n ; ++i){
        cin >> arr[i];
        cost[i] = INT_MAX;
    }
    cost[0] = 0;
    for (int i = 1 ; i < n ; ++i){
        for (int j = 1 ; j <= k ; ++j){
            if (i-j>=0)
                cost[i] = min(cost[i], cost[i-j]+abs(arr[i]-arr[i-j]));
            else
                break;
        }
    }
    cout << cost[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans = 0, found = 0, now = 1;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int cur;
        cin >> cur;
        if (cur == now) {
            found = 1;
            ++now;
        }
        else ++ans;
    }
    if (!found) {
        cout << -1 << endl;
    } else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//                                    ∴In the name of God∴
//                     ✫✗⚡😳😳😄😄😝😝😁😁😎😎😛😛😄😄😮😮⚡✗✫
//                                       H.Pouya  ◠?◠
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<bitset>
#include<iostream>
#include<algorithm>
using namespace std;
typedef short int ss;
typedef long double dd;
typedef long long int ll;
#define give_up return 0;
#define mix(x,y) x*pow(10,y)+10
const ll hp1=999998727899999;
const ll hp2=1012345678901;
const int hp3=2147483647;
const int maxn=mix(2,5);
int main()
{
    string s;
    cin>>s;
    int bk=0;
    for(int i=0;i<s.size();i++)
        if(s[i]=='o')
            bk++;
    if(7<bk+15-s.size())
        s="YES";
    else
        s="NO";
    cout<<s;
    give_up
}
//  🙄


Measured memory_bytes: 256
import Data.List
import Data.Tuple
import Data.Bits
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
import Debug.Trace

solve :: Int -> String
solve n = unlines $ map (unwords . map show) $ solve0 n

solve0 :: Int -> [[Int]]
solve0 n = take n $ tail $ unfoldr f $ VU.toList getTable
  where f [] = Nothing
        f xs = Just (take n (tail lst1), lst2)
          where (lst1, lst2) = splitAt 512 xs

prime9 = [2,3,4,5,7,9,11,13,17]
irr9 = concat $ zipWith (\p q -> [p,q]) ls1 (reverse ls2)
  where (ls1, rest) = splitAt 256 $ foldr op [2..] prime9
          where op p rem = filter (\x -> x `mod` p /= 0) rem
        ls2 = take 256 rest

bitPs :: Int -> Int
bitPs i = product $ zipWith (hat i) [0..8] prime9
  where
    hat :: Int -> Int -> Int -> Int
    hat i j x | testBit i j = x
              | otherwise   = 1

enc :: (Int,Int) -> Int
enc (y,x) = y*512+x

dec :: Int -> (Int,Int)
dec i = divMod i 512

getTable :: VU.Vector Int
getTable = VU.create $ do
  table <- VUM.new (512*512)
  t_irr9 <- VUM.new 512
  forM_ (zip [0..] irr9) $ \(i,x) -> VUM.write t_irr9 i x
  forM_ [0..511] $ \u -> do
    forM_ [0..255] $ \v -> do
      let v' = 2*v + (if u `mod` 2 == 0 then 0 else 1)
      c <- VUM.read t_irr9 ((u + v') `div` 2)
      VUM.write table (enc (u,v')) (c * (bitPs u))
  forM_ [1..509] $ \s -> do
    used <- VUM.replicate 512 0
    forM_ (get_ijs s) $ \(i,j) -> do
      c1 <- VUM.read t_irr9 s
      c2 <- VUM.read t_irr9 (s+1)
      let t1 = (i-1) .|. i .|. (i+1)
      d <- VUM.read used t1
      VUM.write used t1 (d+1)
      VUM.write table (enc (i,j)) (c1*c2*(d+1)*(bitPs t1) + 1)
  return table

-- (i,j) \in get_ijs s <-> i+j = 2s+1, 1 <= i,j <= 510
get_ijs :: Int -> [(Int,Int)]
get_ijs s = zipWith (,) is js
  where (is,js) | s <= 255 = ([1..2*s], [2*s,2*s-1..1])
                | otherwise = ([2*s-509..510], [510,509..2*s-509])

tmain :: String -> String
tmain cont =
  let [n] = map read $ words cont
  in solve n

main = putStr . tmain =<< getContents


Measured memory_bytes: 9980
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
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);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}

bool paralell(P a, P b, P c, P d){
  auto check=[](P a, P b, P c, P d){
    b = P(b.first - a.first, b.second - a.second);
    d = P(d.first - c.first, d.second - c.second);
    //b.second / b.first == d.second / d.first;
    return b.second * d.first == d.second * b.first;
  };
  return check(a, b, c, d) || check(a, b, d, c);
}

int n;

vector<P> A;

int used[1<<16], mem[1<<16];
int dfs(int bit){
  if(used[bit]++) return mem[bit];
  
  int res = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if((bit >> i & 1) || (bit >> j & 1)) continue;
      int cnt = 1;
      int nbit = bit | (1<<i) | (1<<j);
      for(int k=0;k<n;k++)
	for(int l=k+1;l<n;l++){
	  if((nbit>>k&1) || (nbit>>l&1)) continue;
	  if(!paralell(A[i], A[j], A[k], A[l])) continue;
	  nbit |= (1<<k) | (1<<l);
	  cnt++;
	}
      Max(res, dfs(nbit) + cnt * (cnt - 1) / 2);
    }
  }
  return mem[bit] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  cin>>n;
  A.resize(n);
  cin>>A;

  int ans = dfs(0);
  cout<<ans<<endl;  
  return 0;
}



Measured memory_bytes: 3696
import math


n = int(input())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

#p=1
x_y_1 = [abs(x[i] - y[i]) for i in range(n)]
D_1 = sum(x_y_1)
print(float(D_1))
#p=2
x_y_2 = [abs(x[i] - y[i])**2 for i in range(n)]
D = sum(x_y_2)
D_2 = pow(D, 1/2)
print(D_2)

#p=3
x_y_3 = [abs(x[i] - y[i])**3 for i in range(n)]
D = sum(x_y_3)
D_3 = pow(D, 1/3)
print(D_3)

#p=infty
D_inf = max(x_y_1)
print(float(D_inf))


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


#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back


using namespace std;

const int INF = 2e9;
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef NICK
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    int mx = -INF;
    int d = -1;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        mx = max(t, mx);
        if (d == -1) {
            d = t;
        } else {
            d = gcd(d, t);
        }
    }
    if (k <= mx && k % d == 0) {
        cout << "POSSIBLE\n";
    } else {
        cout << "IMPOSSIBLE\n";
    }
    
    return 0;
}           
            








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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	map<int, int> mp;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		mp[x]++;
	}
	int ans = 0;
	for(auto x : mp){
		if(x.second >= x.first)ans += x.second - x.first;
		else ans += x.second;
	}
	cout<<ans<<endl;

	return 0;
}

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


int main() {
    int N;
    std::cin >> N;

    std::vector<std::vector<std::pair<int,int>>> linked_list(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        std::cin >> u >> v >> w;
        u--; v--;
        linked_list[u].emplace_back(std::make_pair(v, w));
        linked_list[v].emplace_back(std::make_pair(u, w));
    }

    std::vector<int> output(N, -1);
    std::queue<std::tuple<int, int, int>> que; // before, after, weight
    output[0] = 0;
    que.push(std::make_tuple(0, 0, 0));
    while (!que.empty()) {
        auto q = que.front();
        que.pop();
        int before = std::get<0>(q);
        int after = std::get<1>(q);
        int weight = std::get<2>(q);
        output[after] = (output[before] + weight) % 2;
        for (auto next: linked_list[after]) {
            if (output[next.first] == -1) {
                que.push(std::make_tuple(after, next.first, next.second));
            }
        }
    }

    for (int i = 0; i < N; i++) {
        std::cout << output[i] << std::endl;
    }
}


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

namespace AOJ
{
  class Problem0030
  {
    static void Main()
    {
      foreach (var ns in ReadNumbers())
      {
        if (ns[0] == 0 && ns[1] == 0)
          break;
        Console.WriteLine(Combination(Enumerable.Range(0, 10), ns[0], false).Where(c => c.Sum() == ns[1]).Count());
      }
    }

    static IEnumerable<int[]> ReadNumbers()
    {
      string line;
      while (!string.IsNullOrEmpty(line = Console.ReadLine()))
      {
        var sp = line.Split(' ');
        var result = new[] { 0, 0 };
        if (!string.IsNullOrEmpty(sp[0]))
          result[0] = int.Parse(sp[0]);
        if (!string.IsNullOrEmpty(sp[1]))
          result[1] = int.Parse(sp[1]);
        yield return result;
      }
    }

    static IEnumerable<T[]> Combination<T>(IEnumerable<T> elements, int n, bool isRepeated)
    {
      if (n == 1)
      {
        foreach (var el in elements)
          yield return new T[] { el };
      }
      else
      {
        foreach (var atom in elements)
        {
          var temp = elements.SkipWhile(x => !x.Equals(atom)).ToList();
          if (!isRepeated)
            temp.Remove(atom);
          var comb = Combination(temp, n - 1, isRepeated);
          foreach (var e in comb)
            yield return (new T[] { atom }).Concat(e).ToArray();
        }
      }
    }
  }
}

Measured memory_bytes: 10664
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[2020],S;
bitset<4400000> B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	B[0]=1;
	FOR(i,N) {
		cin>>A[i];
		S+=A[i];
		B |= B<<A[i];
	}
	
	for(i=(S+1)/2;i<=S;i++) if(B[i]) return _P("%d\n",i);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2048
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N

    for i in range(1,N):
        left[i] = max(A[i], left[i-1])
    for i in reversed(range(0,N-1)):
        right[i] = max(A[i], right[i+1])

    for i in range(N):
        if i == 0:
            print(right[1])
        elif i == N-1:
            print(left[N-2])
        else:
            print(max(left[i-1], right[i+1]))


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16712
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 1000000 + 9;
ll n,ans,mod=1e9+7,mem[N][2][2];

ll dp(int i ,int p1, int p2)
{
    if(i>n)
    {
        if(p1&&p2)return 1;
        return 0;
    }
    ll&ret=mem[i][p1][p2];
    if(~ret)return ret;

    ret=0;
    ret+=dp(i+1,1,p2);
    ret+=dp(i+1,p1,1);
    ret%=mod;
    ret+=(8*dp(i+1,p1,p2))%mod;
    ret%=mod;
    return ret;
}
 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        if(n==1)cout<<0<<endl;
        else{
            memset(mem,-1,sizeof mem);
            cout<<dp(1,0,0)<<endl;
        }



return 0;
}


Measured memory_bytes: 128516
# input
N, M = map(int, input().split())

# process
ans = []

t = 1
for _ in range(M//2):
    ans.append((t, M-t+1))
    t += 1

t = M+1
for _ in range(-(-M//2)):
    ans.append((t, M*3+2-t))
    t += 1

# output
[print(a, b) for a, b in ans]


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	int n;
	cin >> n;
	VI t(n), v(n);
	REP(i, n)cin >> t[i];
	REP(i, n)cin >> v[i];
	REP(i, n) {
		t[i] *= 2;
		v[i] *= 2;
	}
	VI d(40010, 10000000);
	int s = 0;
	d[0] = 0;
	REP(i, n) {
		d[s] = min(d[s], v[i]);
		REP(j, t[i]) {
			s++;
			d[s] = min(d[s], v[i]);
		}
	}

	d[s] = min(d[s], 0);
	FOR(i, 1, s + 1)d[i] = min(d[i], d[i - 1] + 1);
	for (int i = s - 1; i >= 0; i--)d[i] = min(d[i], d[i + 1] + 1);
	
	double res = 0;
	REP(i, s)res += d[i] + d[i + 1];
	cout <<fixed<<setprecision(10)<< res/8 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();

        int N = fs.nextInt(); int K = fs.nextInt();

        int[] ar = fs.readArray(N);
        Arrays.sort(ar);

        int sum = 0;
        for (int i = 0; i<K; i++) {
            sum +=ar[i];
        }
        System.out.println(sum);







    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

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

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

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
    }

}



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

ll INF = 1e8;
int main(){
    int h,w;
    cin>>h>>w;
    queue<P> que;
    vector<vector<int>> d(h,vector<int>(w,INF));
    for(int i=0; i<h; i++){
        string a;
        cin>>a;
        for(int j=0; j<w; j++){
            if(a[j]=='#'){
                que.push(P(i,j));
                d[i][j]=0;
            }
        }
    }
    vector<int> dx={1,-1,0,0};
    vector<int> dy={0,0,1,-1};
    while(!que.empty()){
        P q=que.front();que.pop();
        int y=q.first,x=q.second;
        for(int i=0; i<4; i++){
            int ny=y+dy[i],nx=x+dx[i];
            if(ny<0||h<=ny||nx<0||w<=nx||d[ny][nx]!=INF)continue;
            d[ny][nx]=d[y][x]+1;
            que.push(P(ny,nx));
        }
    }
    int M=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            M=max(M,d[i][j]);
        }
    }
    cout<<M;
    return 0;
}

Measured memory_bytes: 20532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){
    if(b%a==0) return a;
    else return gcd(b%a,a);
}
int main(void){
    ll a,b;
    cin>>a>>b;
    cout<<a/gcd(a,b)*b<<endl;

}


Measured memory_bytes: 3528
from collections import Counter
N = int(input())
A = [int(hoge) for hoge in input().split()]
kazu = [0] * (100001)
for a in A:
    kazu[a] += 1
S = sum(A)
C = Counter(A)
Dic = dict(C)
Q = int(input())
for q in range(Q):
    B,C = [int(hoge) for hoge in input().split()]
    K = kazu[B]
    S += K*(C-B)
    kazu[B] = 0
    kazu[C] += K
    print(S) 

Measured memory_bytes: 94684
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
typedef vector<vp> vvp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
  char x,y;cin>>x;
  if(x=='A'){y='T';}
  if(x=='T'){y='A';}
  if(x=='G'){y='C';}
  if(x=='C'){y='G';}
  cout<<y<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N, X;
  int m[100];
  int i, j, k;
  int min = 2000;
  int count = 0;
  scanf("%d %d", &N, &X);
  for(i = 0; i < N; i++){
    scanf("%d", &m[i]);
  }
  for(i = 0; i < N; i++){
    if(m[i] < min){
      min = m[i];
    }
  }
  for(i = 0; i < N; i++){
    X -= m[i];
    count++;
  }
  count += X/min;
  printf("%d\n", count);
  return 0;
}


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

using namespace std;

void solve(int z, int x[], int y[]) {
    int cntX = 1, cntY = 1;
    do {
        cntX++;
    } while (next_permutation(x, x+z));
    do {
        cntY++;
    } while (next_permutation(y, y+z));
    int X = z-cntX, Y = z-cntY;
    cout << abs(X-Y) << "\n";
}

int main()
{
    int n;
    cin >> n;

    int a[n], b[n];
    for (int i=0; i<n; i++)
        cin >> a[i];
    for (int i=0; i<n; i++)
        cin >> b[i];

    if (lexicographical_compare(a, a+n, b, b+n)) {
        solve(n, a, b);
    }
    else {
        solve(n, b, a);
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<set>
using namespace std;
const int MAXN=500000+10;
int n,k,A[MAXN],P[MAXN],Indegree[MAXN],to[MAXN<<1],nex[MAXN<<1],beg[MAXN],Ans[MAXN],cnt,e;
priority_queue<int> q;
set<int> tmp1,tmp2;
inline void read(int &x)
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<3)+(data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
inline void insert(int x,int y)
{
	to[++e]=y;
	nex[e]=beg[x];
	beg[x]=e;
}
inline void toposort()
{
	while(!q.empty())
	{
		int x=q.top();
		q.pop();
		Ans[++cnt]=x;
		for(register int i=beg[x];i;i=nex[i])
		{
			Indegree[to[i]]--;
			if(!Indegree[to[i]])q.push(to[i]);
		}
	}
}
int main()
{
	read(n);read(k);
	for(register int i=1;i<=n;++i)
	{
		read(P[i]);
		A[P[i]]=i;
	}
	for(register int i=1;i<k-1;i++)tmp1.insert(P[i]);
	for(register int i=1;i<=n;i++)
	{
		if(i+k-1<=n)tmp1.insert(P[i+k-1]);
		tmp1.erase(P[i-1]);
		tmp2.insert(P[i]);
		if(i>k)tmp2.erase(P[i-k]);
		set<int>::iterator cur=tmp1.upper_bound(P[i]);
		if(cur!=tmp1.end())insert(A[*cur],i),Indegree[i]++;
		cur=tmp2.upper_bound(P[i]);
		if(cur!=tmp2.end())insert(A[*cur],i),Indegree[i]++;
	}
	for(register int i=1;i<=n;++i)
		if(!Indegree[i])q.push(i);
	toposort();
	for(register int i=1;i<=n;++i)A[Ans[i]]=n-i+1;
	for(register int i=1;i<=n;++i)printf("%d\n",A[i]);
	return 0;
}


Measured memory_bytes: 44544
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    deque<int> q;
    int n;cin>>n;
    if(n%2==0){
        rep(i,n){
            int a;
            cin>>a;
            if(i%2==0)q.push_back(a);
            else q.push_front(a);
        }
    }else{
        rep(i,n){
            int a;
            cin>>a;
            if(i%2==0)q.push_front(a);
            else q.push_back(a);
        }        
    }

    rep(i,n){
        cout<<q[i]<<" ";
    }
}

Measured memory_bytes: 4484
def binary_search array, key
  #puts "#{key} in #{array.join ','}?"
  pivot = array.size / 2
  targets = array.dup
  loop do
    # ??????????????????????????????
    #sleep 0.1
    #puts "#{targets.join(',')} ??? #{pivot}????????? #{targets[pivot]}"
    if targets.size == 1 && targets[0] != key
      return nil
    elsif targets[pivot].nil?
      return nil
    elsif targets[pivot] == key
      # bingo
      return pivot
    elsif targets[pivot] > key
      #pivot?????????????????????
      targets = targets[0..(pivot - 1)]
      pivot = targets.size / 2
    elsif targets[pivot] < key
      targets = targets[(pivot + 1)..targets.size]
      pivot = targets.size / 2
    else
      return nil
    end
  end
end

def main size, array, keys_size, keys
  puts keys.select{|key|
    binary_search array, key
  }.size

end

size, array, keys_size, keys = STDIN.read.split(/\n/)
array = array.split(' ').map{|n|n.to_i}
keys = keys.split(' ').map{|n|n.to_i}

main(size, array, keys_size, keys)

Measured memory_bytes: 22772
import itertools
import datetime
from heapq import heapify,heappush,heappop



N=input()
a=[]
a=map(int, raw_input().split())
a1=a[:N]
#print a1


heapify(a1)

l1=[]
sum_a1=sum(a1)
l1.append(sum_a1)



# Max
for i in range(N,2*N):
	if a[i]>a1[0]:
		sum_a1=sum_a1+a[i]-a1[0]
		heappop(a1)
		heappush(a1, a[i])

	l1.append(sum_a1)

 

l2=[]
a2=[ -x for x in a[2*N:]]
heapify(a2)
sum_a2=-1*sum(a2)
l2.append(sum_a2)

# Min
for i in reversed(range(N,2*N)):
	if a[i]<-1*a2[0]:
		sum_a2=sum_a2+a[i]-(-1*a2[0])
		heappop(a2)
		heappush(a2,-1*a[i])
	l2.append(sum_a2)


ans=[]
for i in range(N+1):
	heappush(ans, -1*(l1[i]-l2[N-i]))

print ans[0]*-1



Measured memory_bytes: 28920
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int a[100002];
int main()
{
	int n,sum=1,g;
	bool b=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	} 
	g=a[0];
	if (g==2)
	{
		cout<<sum;
		b=1;
	} 
	if(!b)
	{
		for(int j=0;j<n;j++)
		{
			g=a[g-1];
			sum++;
			if(g==2)
			{
				cout<<sum;
				b=1;
				break;	
			}
		}
	}
	
	if(!b)
	cout<<-1;
return 0;
}



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

signed main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n){
        ans += a[i] - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <stack>
#include <vector>
using namespace  std;

struct StDtl
{
  int m_iLeft;

  StDtl(int a_iLeft) :
    m_iLeft(a_iLeft)
  { }

  ~StDtl() { }
};

struct StSum
{
  int m_iLeft;
  int m_iRight;
  int m_iArea;

  StSum(int a_iLeft, int a_iRight, int a_iArea) :
    m_iLeft(a_iLeft), m_iRight(a_iRight), m_iArea(a_iArea)
  { }

  ~StSum() { }
};

void fnCrossSectAreaSet(stack<StDtl> &a_rskoDtl, vector<StSum> &a_rvoSum, int &a_riTotalArea)
{
  string sCrossSect;
  cin >> sCrossSect;

  for (int i = 0; i < sCrossSect.size(); i++)
  {
    if (sCrossSect[i] == '\\')
    {
      StDtl oDtl(i);
      a_rskoDtl.push(oDtl);
    }
    else if (sCrossSect[i] == '/')
    {
      if (a_rskoDtl.size() > 0)
      {
        int iLeft = a_rskoDtl.top().m_iLeft; a_rskoDtl.pop();
        int iSum = i - iLeft; 
        a_riTotalArea += iSum;

        while (a_rvoSum.size()  &&
               iLeft < a_rvoSum.back().m_iLeft  &&
               a_rvoSum.back().m_iRight < i       )
        {
          iSum += a_rvoSum.back().m_iArea;
          a_rvoSum.pop_back();
        }
        StSum oSum(iLeft, i, iSum);
        a_rvoSum.push_back(oSum);
      }
      else;
    }
  }
}

void  fnCrossSectAreaGet(const vector<StSum> &a_cnrvoSum, int a_iTotalArea)
{
  cout << a_iTotalArea << endl;
  cout << a_cnrvoSum.size();
  if (a_cnrvoSum.size() > 0)
  {
    cout << " ";
    for (auto itvoSum = begin(a_cnrvoSum); itvoSum != end(a_cnrvoSum); ++itvoSum)
    {
      if (itvoSum != begin(a_cnrvoSum)) cout << " ";
      cout << itvoSum->m_iArea;
    }
  }
  cout << endl;
}

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

  stack<StDtl> skoDtl;
  vector<StSum> voSum;
  int iTotalArea = 0;

  fnCrossSectAreaSet(skoDtl, voSum, iTotalArea);
  fnCrossSectAreaGet(voSum, iTotalArea);

  return 0;
}

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

int main(void){
    
    int N,M,C,count=0;
    cin >> N >> M >> C;
    vector<int> B{};
    
    for(int i=0;i<M;i++){
        int b_i;
        cin >> b_i;
        B.push_back(b_i);
    }
    
    
    for(int i=0;i<N;i++){
        int sum = 0;
        for(int j=0;j<M;j++){
            int a_i;
            cin >> a_i;
            sum += (B.at(j)*a_i);
        }
        if(sum + C > 0) count++;
    }
    
    
    cout << count << endl;
    
}

Measured memory_bytes: 3660