akhauriyash/Code-Regression huggingface dataset:
package main

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

func solve() {
	n := getInt()
	m := make(map[int]int, 3)
	m[1], m[2], m[4] = 0, 0, 0
	for i := 0; i < n; i++ {
		a := getInt()
		switch {
		case a%4 == 0:
			m[4]++
		case a%2 == 0:
			m[2]++
		default:
			m[1]++
		}
	}

	ans := "Yes"
	if m[1] > 0 {
		m[1] += min(1, m[2])
		if m[4]+1 < m[1] {
			ans = "No"
		}
	}
	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int[] array2 = new int[n];
        for (int i = 0; i < n; i++) {
            array2[i] = array[i];
        }
        
        Arrays.sort(array);
        
        int highmedian = array[n/2];
        int lowmedian = array[n/2-1];
        
        
        for (int i = 0; i < n; i++) {
            if (array2[i] >= highmedian) {
                System.out.println(lowmedian);
            } else {
                System.out.println(highmedian);
            }
        }
    }
}

Measured memory_bytes: 114308
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 99999997;
const ll cons = 100000000000;
const double pi = 3.141592653589793;

ll sum[100005];
ll a[100005];

int main()
{
	int n;
	ll l;
	scanf("%d%lld", &n, &l);

	int pos = -1;

	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		sum[i] = sum[i - 1] + a[i];

		if (i > 1)
		{
			if (a[i] + a[i - 1] >= l)pos = i - 1;
		}
	}

	if (pos == -1)puts("Impossible");
	else
	{
		puts("Possible");

		for (int i = 1; i < pos; i++)
		{
			printf("%d\n", i);
		}

		for (int i = n - 1; i > pos; i--)
		{
			printf("%d\n", i);
		}

		printf("%d\n", pos);
	}

	return 0;
}

Measured memory_bytes: 2432
n= int(input())
a = list(map(int, input().split()))
g = [[0]*20 for i in range(n)]
for i in range(n):
  e = a[i]
  for j in range(20):
    g[i][j]+=e%2
    e//=2
ans=0
b =0
c =0
d= [0]*20
s=1
while(1):
  e =0
  if s ==1:
    for i in range(20):
      d[i]+=g[c][i]
      if d[i]>=2:
        e+=1
  else:
    for i in range(20):
      d[i]-=g[b-1][i]
      if d[i]>=2:
        e+=1
  if e==0 and c!=n-1:
    s=1
    c+=1
  elif e!=0:
    ans+=c-b
    s=0
    b+=1
  else:
    ans+=c-b+1
    s=0
    b+=1
    if b==n:
      break
print(ans)

Measured memory_bytes: 139884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
const int MAX_V = 15;
const int INF = 1e9;
 
int V,E;
int d[MAX_V][MAX_V];
int dp[1<<MAX_V][MAX_V];

//bitDP
//????????????v????????????????????????????????????????????£???v????????£??????????????????????????????
// = ??????0?????????????????????????????£????????????????????????0????????£?????????

int dfs(int mask,int v){
    if(mask==(1<<V)-1) return d[v][0];
    if(dp[mask][v]!=-1) return dp[mask][v];
    int res = INF;
    rep(u,V){
        if(d[v][u]==INF || (mask&(1<<u))) continue;
        res = min(res, dfs(mask|(1<<u),u)+d[v][u]);
    }
    return dp[mask][v] = res;
}

int main() {
    cin>>V>>E;
    rep(i,V)rep(j,V) d[i][j]=INF;
    rep(i,V) d[i][i]=0;
    rep(i,E){
        int s,t;
        cin>>s>>t;
        cin>>d[s][t];
    }
    memset(dp, -1, sizeof(dp));
    int res=dfs(1,0);
    cout<<(res==INF ? -1 : res)<<endl;
    return 0;
}

Measured memory_bytes: 5040
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vvl V(1LL << 18);
  REP(i, 1LL << N) {
    ll x;
    cin >> x;
    V[i] = {x, 0};
  }
  REP(i, N) REP(x, 1LL << N) {
    if (x & (1 << i)) {
      V[x].push_back(V[x ^ (1LL << i)][0]);
      V[x].push_back(V[x ^ (1LL << i)][1]);
      sort(ALL(V[x]));
      reverse(ALL(V[x]));
      V[x].resize(2);
    }
  }
  ll ma = 0;
  FOR(k, 1, 1LL << N) {
    ma = max(ma, V[k][0] + V[k][1]);
    cout << ma << endl;
  }

  return 0;
}


Measured memory_bytes: 23680
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

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

    if((n+1)/2>=k){
        cout<<"YES"<<endl;
    }
	else{
        cout<<"NO"<<endl;
    }
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  for (int i=0;i<N;i++){
    cin >> x.at(i);
    cin >> u.at(i);
  }
  double S=0;
  for (int i=0;i<N;i++){
    if (u.at(i)=="JPY"){
      S+=x.at(i)*1;
    }
    else{
      S+=x.at(i)*380000.0;
    }
  }
  cout << S << endl;
}


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

int main() {
  int n,x;
  cin >> n >> x;
  int count = 0;
  int l;
  for (int i = 0; i <= x && count <= n;){
    cin >> l;
    i += l;
    count++;
  }
  printf("%d\n",count);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) cin >> s[i];

    int ans = 0;
    rep(i, n) ans += s[i];
    sort(s.begin(), s.end());
    if (ans%10==0) {
        rep(i, n) {
            int now = ans - s[i];
            if (now%10!=0) {
                cout << now << endl;
                return 0;
            }
        }
    }
    else {
        cout << ans << endl;
        return 0;
    }
    
    cout << 0 << endl;
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
bool comp(pair<ll, pll> a, pair<ll, pll> b) {
	if (a.first != b.first)return a.first < b.first;
	return a.second.first*a.second.second < b.second.first * b.second.second;
}
bool comp2(pair<ll, pll> a, pair<ll, pll> b) {
	return a.second.first*a.second.second < b.second.first * b.second.second;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n, w, d;
		cin >> n >> w >> d;
		if (!w)break;
		vector<pair<ll, pll>> v;
		v.push_back({ 0,{w,d} });
		REP(i, n) {
			int p, s;
			cin >> p >> s;
			auto a = v[p - 1];
			v.erase(v.begin() + p - 1);
			int W = a.second.first, D = a.second.second;
			s %= 2 * (W + D);
			if (s < W) {
				v.push_back({ i + 1,{s,D} });
				v.push_back({ i + 1,{W - s,D} });
			}
			else if (s < W + D) {
				v.push_back({ i + 1,{W,s-W} });
				v.push_back({ i + 1,{W,W+D-s } });
			}
			else if (s < 2*W +  D) {
				v.push_back({ i + 1,{s-W-D,D} });
				v.push_back({ i + 1 ,{2*W+D-s,D} });
			}
			else {
				v.push_back({ i + 1,{W,s-2*W-D} });
				v.push_back({ i + 1,{W,2*W+2*D-s} });
			}
			sort(ALL(v), comp);
		}
		sort(ALL(v), comp2);
		REP(i, v.size()) {
			cout << v[i].second.first*v[i].second.second;
			if (i != v.size() - 1)cout << " ";
			else cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3124
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	int a[26] = {0};
	for ( int i = 0; i < n; i++)
	{
		for ( int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			a[x-'a'] ++;
		}
	}
	if ( n % 2 == 0 and m % 2 == 0)
	{
		for ( int i = 0; i < 26; i++)
		{
			if ( a[i] % 4)
			{
				cout << "No\n";
				return 0;
			}

		}
		cout << "Yes\n";
		return 0;
	}
	int cnt = 0,cnt2=0;
	for ( int i = 0; i < 26; i++ )
	{
		if ( a[i] % 4 == 0)
			continue;
		if ( a[i] % 2 == 0)
			cnt ++;
		else
		{
			cnt2 ++;
			//return 0;
		}
	}
	if ( n % 2 == 0 and m % 2)
	{
		if ( cnt <= n / 2 and cnt2 == 0)
			cout << "Yes";
		else
			cout << "No";
		return 0;
	}
	if ( m % 2 == 0 and n % 2)
	{
		if ( cnt <= m / 2 and cnt2 == 0)
			cout << "Yes";
		else
			cout << "No";
		return 0;
	}
	if ( cnt  <= n / 2 + m / 2 and cnt2 <= 1)
		cout << "Yes";
	else
		cout << "No";
		
	return 0;
}


Measured memory_bytes: 256
import sys
#a = []
#for l in sys.stdin:
#    a.append(int(l))
a = int(input())
if a % 10 == 3:
   print('bon')
elif a % 10 == 0 or a % 10 == 1 or a % 10 == 6 or a % 10 == 8:
   print('pon')
else:
   print('hon')

Measured memory_bytes: 9048
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int N=1e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
map<ll,int>mp;ll s[N],sum;int sz[N],id[N],n;
void dfs(int u,int fa,int dis){
	sum+=dis;
	go(u)if(v!=fa)dfs(v,u,dis+1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%lld",&s[i]),id[i]=i,sz[i]=1,mp[s[i]]=i;
	sort(id+1,id+1+n,[](const int &x,const int &y){return s[x]>s[y];});
	fp(i,1,n-1){
		R int u=id[i];
		if(!mp.count(s[u]-n+(sz[u]<<1)))return puts("-1"),0;
		R int v=mp[s[u]-n+(sz[u]<<1)];
		if(s[v]>=s[u])return puts("-1"),0;
		add(u,v),add(v,u),sz[v]+=sz[u];
	}
	dfs(id[n],0,0);
	if(sum!=s[id[n]])return puts("-1"),0;
	fp(u,1,n)go(u)if(u<v)printf("%d %d\n",u,v);
	return 0;
}

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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	ll all = 1, invalid = 1;
	for(int i = 0; i < n; ++i){
		all *= 3;
		invalid *= (a[i] % 2 == 0 ? 2 : 1);
	}
	const ll valid = all - invalid;
	cout << valid << endl;
	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

int n;
string s1, s2;
ll ans;
const ll mod = 1000000007;

int main() {
	cin >> n >> s1 >> s2;
	repi(i, 0, n) {
		if (i == 0) {
			if (s1[i] == s2[i]) ans = 3;
			else ans = 6;
		}
		else {
			if (s1[i] == s1[i - 1] && s2[i] == s2[i - 1]) continue;
			if (s1[i] == s2[i]) {
				if (s1[i - 1] == s2[i - 1]) ans *= 2;
				else ans *= 1;
			}
			else {
				if (s1[i - 1] == s2[i - 1]) ans *= 2;
				else ans *= 3;
			}
		}
		ans %= mod;
	}
	wrln(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  vector<int64_t>B(N);
  for(int i=0;i<N;i++){
  int64_t a,b;
    cin>>a>>b;
    A.at(i)=a;
    B.at(i)=b;
  }reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  int64_t ans=0;
  for(int i=0;i<N;i++){
    A.at(i)+=ans;
 ans+=((B.at(i)+A.at(i)-1)/B.at(i))*B.at(i)-A.at(i);
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main(){
    int N, K, point;
    double ans = 0.0;
    std::cin >> N >> K;
    
    for(auto i = 1; i <= N; i++){
        point = i;
        double tmp = 1.0;
        while(point >= 1 && point <= K - 1){
            tmp *= 0.5;
            point *= 2; 
        }
        ans += tmp;
    }   

    ans /= (double)N;

    printf("%.10lf\n", ans);

    return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll a0,a1,a2;
  cin >> a0 >> a1 >> a2;
  a0 += a1+a2;
  if(a0>=22){
    cout << "bust\n";
  }else{
    cout <<"win\n";
  }
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		// 計算
		long result = 0;
		long s = n/k;
		long t = 0;
		if(k%2 == 0) t = (n+(k/2))/k;
		result += s*s*s + t*t*t;
		
		// 出力
		System.out.println(result);
	}
}


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

public class AtCoder_158_A
{
    public static void Main()
    {
        string str = Console.ReadLine();
        if (str[0] == str[1] && str[1] == str[2])
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13140
<?php
  $n = trim(fgets(STDIN));
  $k = trim(fgets(STDIN));
  $x = explode(" ",trim(fgets(STDIN)));
  
  $total = 0;
  for($i=0; $i<$n; $i++){
    $a = $x[$i]+$x[$i];
    if($k > $x[$i]){
      $b = ($k-$x[$i])*2;
    }else{
      $b = ($x[$i]-$k)*2;
    }
    $total += min($a,$b);
  }
 echo $total."\n";

Measured memory_bytes: 4604
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        sc.close();

        List<Long> list = new ArrayList<>();
        Map<Long, Boolean> map = new HashMap<>();
        long lnum = -1;
        long newnum = N;
        long min = 1000000000000000000L; 

        lnum = N % K;
        while(lnum > Math.abs(lnum - K)){
            lnum = Math.abs(lnum - K);
        }

        if(lnum <= Math.abs(lnum - K)){
            System.out.println(lnum);       
        }
        

    }
    
}

       

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    int n,i,j,a[240];
    scanf("%d",&n);
    for(i=0; i<n; i++)scanf("%d",&a[i]);
    int k=1;
    int c,ma=9999999;
    for(i=0; i<n; i++)
    {
        c=0;
        while(a[i]>0)
        {
            if((a[i]&1)==0)
            {
                c++;
                a[i]=a[i]>>1;
            }
            else break;
        }
        if(ma>c)ma=c;
    }
    printf("%d\n",ma);

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
from bisect import bisect_left
from itertools import accumulate

# https://betrue12.hateblo.jp/entry/2019/10/20/001106

N = int(input())
A = list(map(int, input().split()))
a = list(Counter(A).values())
a.sort()
b = list(accumulate(a))
length = len(a)

for i in range(1, N + 1):
    if i == 1:
        print(b[-1])
    elif len(a) < i:
        print(0)
    else:
        n = b[-1] // i
        for j in reversed(range(1, n + 1)):
            t = bisect_left(a, j)
            if j * i <= b[t - 1] + (length - t) * j:
                print(j)
                break

Measured memory_bytes: 39256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int n;
	cin>>n;
	string s[n];
	msi mp;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		if(mp[s[i]]){
			ans+=mp[s[i]];
		}
		mp[s[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 14500
input()
s=list(map(int,input().split()))
a,b=s[:2]
while b:a,b=b,a%b
if len(s)-2:
 b=s[2]
 while b:a,b=b,a%b
[print(x)for x in range(1,a+1)if a%x==0]


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

int main() {
    int N; cin >> N;
    int pt=0, px=0, py=0;
    for (int i = 0; i < N; i++)
    {
        int t, x, y; cin >> t >> x >> y;
        int diff = (t-pt) -  abs(x-px) - abs(y-py);
        //cout << diff << endl;
        if(!(diff >= 0 && diff%2==0)){
            cout << "No" << endl;
            return 0;
        }
        pt = t; px = x; py = y;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
# C - Sum of gcd of Tuples (Easy)
from math import gcd


def main():
    K = int(input())
    gcd_three = lambda x, y, z: gcd(gcd(x, y), z)
    ans = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                ans += gcd_three(i, j, k)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 69780
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
#define f first
#define s second
#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i<= n; i++)
#define MOD 1000000007
const int MAX = 2123;
int n, x, y;
int tc;
int dist[MAX];
int ans[MAX];
vector<int> adj[MAX];

void bfs(int fonte){
	fr(i, n+2){
		dist[i] = -1;
	}
	queue<int> fila;
	fila.push(fonte);//Insere a fonte na fila
	dist[fonte]=0;//Iniciando a distancia da fonte como zero	

	int aux;
	while(!fila.empty()){
		aux=fila.front();//Pega o primeiro elemento da fila
		fila.pop();//Apaga o primeiro elemento da fila
	
		for(auto viz:adj[aux]){
			if(dist[viz]!=-1)//Se foi visitado, não adiciona na fila
				continue;
			
			dist[viz]=dist[aux]+1;
			fila.push(viz);
		}
	}

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x >> y;

	frr(i, n-1){
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}
	adj[y].push_back(x);
	adj[x].push_back(y);

	bfs(1);
	frr(i, n){
		bfs(i);
		for(int j = i+1; j <= n; j++){
			ans[dist[j]]++;
		}
	}

	for(int i = 1; i < n; i++){
		cout << ans[i] << "\n";
	}
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
import java.util.List;
//List<String> color = new ArrayList<>();
//int[] n = new int[k];

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		List<Integer> p1 = new ArrayList<>();
		List<Integer> p2 = new ArrayList<>();
		List<Integer> p3 = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int t = stdIn.nextInt();
			if (t <= a) 
				p1.add(t);
			else if (t > b)
				p3.add(t);
			else
				p2.add(t);
		}

		int m1 = p1.size();
		int m2 = p2.size();
		int m3 = p3.size();
		int ans = Math.min(m1, Math.min(m2, m3));
		System.out.println(ans);

	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	const long int a=1000000007;
    int prime[n+1];
    int i, j;

    for (i = 2; i <= n; i++) {
      prime[i] = 1;
    }
    for (i = 2; i <= n; i++) {
      if (prime[i]) {
        for (j = i*2; j <= n; j += i) {
          prime[j] = 0;
        }
      }
    }
    for (i = 2; i <= n; i++) {
      if (prime[i]) {
        prime[i] = 0;
        for (j = i; j <= n; j *= i) {
          prime[i] += n/j;
        }
      }
    }
	int ans=1;
	int tmp;
	for(i=2; i<=n; i++){
		if(prime[i] != 0) {
			tmp = (ans*((prime[i]+1)%a))%a;
			ans = tmp;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N], ans;
map < int, int > cnt;

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    scanf("%d", a + i);
    cnt[a[i]]++;
  }
  sort(a + 1, a + 1 + n);
  for(int i = n; i >= 1; --i){
    if(cnt[a[i]] == 0) continue;
    cnt[a[i]]--;
    int p = 0;
    while((1 << p) <= a[i]){
      ++p;
    }
    if(cnt[(1 << p) - a[i]]){
      ans++;
      cnt[(1 << p) - a[i]]--;
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 19712
#include <iostream>
#include <vector>

using namespace std;

class BIT {
public:
	BIT(int n) : a(n) {}

	void add(int p, long long num)
	{
		while (p < a.size()) {
			a[p] += num;
			p |= p + 1;
		}
	}

	/* i から j までの和 */
	long long sum(int i, int j)
	{
		long long s = 0, t = 0;
		i--;
		while (i >= 0) {
			s += a[i];
			i = (i & (i + 1)) - 1;
		}
		while (j >= 0) {
			t += a[j];
			j = (j & (j + 1)) - 1;
		}
		return t - s;
	}

private:
	vector<long long> a;
};

int main()
{
	int n, q;
	cin >> n >> q;
	BIT b(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		b.add(i, a);
	}
	for (int i = 0; i < q; i++) {
		int p, q, r;
		cin >> p >> q >> r;
		if (p == 1) {
			cout << b.sum(q, r - 1) << endl;
		} else {
			b.add(q, r);
		}
	}

	return 0;
}

Measured memory_bytes: 8208
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
import std.ascii;
 
void main() {
    int r, c; readf("%d %d\n", &r, &c);
    string[] F = new string[r];
    foreach (ref L; F) L = readln.chomp;

    const INF = int.max / 2;
    const C = 100_000_007;

    int[immutable(int[])][10][10] memo;
    int dfs(int y, int x, int[] u) {
        if (y == r) return u.all!"a == 0";
        if (x == c) return dfs(y + 1, 0, u);
        //writeln([y, x], " ", u);
        if (F[y][x] == '.') return dfs(y, x + 1, u);
        if (u in memo[y][x]) return memo[y][x][u];
        assert(F[y][x].isDigit);
        int v = F[y][x] - '0';
        //writeln(v, " ", u[x]);
        int[] u1 = u.dup;
        v -= u1[x];
        u1[x] = 0;
        if (v < 0 || 4 < v) return 0;
        int ret = 0;
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j <= 2; j++) {
                if (i + j != v) continue;
                int[] u2 = u1.dup;
                if (j != 0) {
                    foreach (k; x + 1 .. c) {
                        if (F[y][k].isDigit) {
                            u2[k] += j;
                            goto found;
                        }
                        if (u[k]) break;
                    }
                    continue;
                }
                found: u2[x] = i;
                ret = (ret + dfs(y, x + 1, u2)) % C;
            }
        }
        return memo[y][x][cast(immutable)u] = ret;
    }

    writeln(dfs(0, 0, (new int[c])));
    const D = false;
    static if (D) {
        foreach (i; 0 .. r) {
            foreach (j; 0 .. c) {
                writeln(i, " ", j, " ", memo[i][j]);
            }
        }
    }

}

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

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

  vector<int64_t> l(n + 1);
  l.at(0) = 2;
  l.at(1) = 1;
  for (int i = 2; i < n + 1; i++) {
      l.at(i) = l.at(i - 2) + l.at(i - 1);
  }

  cout << l.at(n) << endl;
}

Measured memory_bytes: 256
let s = read_line ()
let cnt = Array.make 2 0
let f c =
  let i = Char.code c - Char.code '0' in
  cnt.(i) <- cnt.(i) + 1
let _ =
  String.iter f s;
  min cnt.(0) cnt.(1) * 2 |> Printf.printf "%d\n"

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int maho[15][15];

int main() {
	int n;
	for(;n=in();){
		int x=n/2,y=n/2+1;
		int i;
		memset(maho,0,sizeof(maho));
		for(i=1;i<=n*n;i++){
			while(maho[y][x]){
				x--;y++;
				if(x==-1)x=n-1;
				if(y==n)y=0;
			}
			maho[y][x]=i;
			x++;y++;
			if(x==n)x=0;
			if(y==n)y=0;
		}
		int xx,yy;
		for(yy=0;yy<n;yy++){
			for(xx=0;xx<n;xx++){
				printf("%4d",maho[yy][xx]);
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import math
k = int(input())
ans = 0
ans1 = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        ans1 = math.gcd(i, j)
        for m in range(1, k + 1):
            ans += math.gcd(ans1, m)

print(ans)


Measured memory_bytes: 9188
import java.util.Scanner;

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

		while(true){
			int datalen = sc.nextInt();
			if(datalen == 0){
				break;
			}

			int sum1 = 0;
			int max = 0, min = 1000000;
			for(int i = 0; i < datalen; i++){
				int t = sc.nextInt();
				sum1 = sum1 + t;
				if (t > max){
					max = t;				
				}
				if (t < min){
					min = t;
				}
			}

			int sum2 = sum1 - max - min;
			int d = sum2 % (datalen - 2);

			System.out.println((sum2 - d) / (datalen - 2));
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static const int N = 100000;
static const int NIL = -1;

// 連結成分(Connected Components)

vector<int> G[N];
int color[N] = { NIL };

void depthFirstSeach(int u, int colorGroup)
{
    color[u] = colorGroup;
    //頂点vにつながっている頂点v
    for (int i = 0; i < G[u].size(); i++)
    {
        int v = G[u][i];
        if (color[v] == NIL)
            depthFirstSeach(v, colorGroup);
    }
}


int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    // 1行目は、ユーザー数n, 関係の数m
    int n, m;
    cin >> n >> m;
    // 2行目から、友達関係をm個
    for (int i = 0; i < m; i++)
    {
        int s, t; // sとtが友達
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    // init color
    for (int i = 0; i < n; i++)
        color[i] = NIL;

    int colorGroup = 1;
    for (int u = 0; u < n; u++)
    {
        // 色がついていないノード(color=NIL)に色を付ける。
        // 深さ優先探索で、たどり着けるところまで色を付ける。
        // これをNILがなくなるまで続けることで色分けできる。
        if (color[u] == NIL) depthFirstSeach(u, colorGroup++);
    }

    // 質問の数q
    int q;
    cin >> q;
    for (int i = 0; i< q; i++)
    {
        int qs, qt; // qsからqtにたどり着けるか?
        cin >> qs >> qt;
        cout << ((color[qs] == color[qt]) ? "yes" : "no") << endl;
    }

    return 0;
}


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

const int maxn = 410;
int n, ans, link[maxn];
bool vis[maxn];
pair<int, int> p1[maxn], p2[maxn];
vector<int> G[maxn];

bool match(int x) {
    for (int i = 0; i < G[x].size(); i++) {
        if (!vis[G[x][i]]) {
            vis[G[x][i]] = true;
            if (link[G[x][i]] == -1 || match(link[G[x][i]])) {
                link[G[x][i]] = x;
                return true;
            }
        }
    }
    return false;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &p1[i].first, &p1[i].second);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &p2[i].first, &p2[i].second);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (p2[j].first > p1[i].first && p2[j].second > p1[i].second) {
                G[i].push_back(j + n);   
            }
        }
    }
    memset(link, -1, sizeof(link));
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));
        ans += match(i);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s.compare("ABC") == 0){
        cout<<"ARC"<<endl;
    }else{
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>           // printf(), scanf()

using namespace std;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
};

struct Segment
{
	Point p1, p2;
};

typedef Point Vector;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

Point
project(Segment s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base * r;
}

Point
reflect(Segment s, Point p)
{
	return p + (project(s, p) - p) * 2.0;
}

int
main(int argc, char **argv)
{
	Segment s;
	Point p, q;

	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &s.p1.x, &s.p1.y, &s.p2.x, &s.p2.y, &p.x, &p.y) != EOF)
	{
		q = reflect(s, p);
		printf("%.6f %.6f\n", q.x, q.y);
	}

	return 0;
}

Measured memory_bytes: 2728
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	char s[13];
	cin >> s;
	rep(i, 4) {
		cout << s[i];
	}
	cout << " ";
	rep(i, 8) {
		cout << s[i + 4];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
class PriorityQueue
  def initialize()
    @heap = []
    @node_num = 0
  end

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if (@heap[par] > x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !(@heap[a] >@heap[b])
      break if x > @heap[a]
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
q = PriorityQueue.new()
a.each do |ai|
    q << ai
end
m.times do
    max_n = q.pop()
    q << (max_n / 2)
end
ans = 0
n.times do
    ans += (q.pop)
end
p ans


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 2e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int road[N];
int rail[N];

map<int, int> mp[N];

int par(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}

void sset(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

int main()
{
  int n;
  cin>>n;
  repn(i, 0, n) road[i] = rail[i] = i;
  int k, l;
  cin>>k>>l;
  while(k--)
  {
    int a, b;
    cin>>a>>b;
    int spa = par(a, road);
    int spb = par(b, road);
    sset(b, spa, road);
  }
  while(l--)
  {
    int a, b;
    cin>>a>>b;
    int spa = par(a, rail);
    int spb = par(b, rail);
    sset(b, spa, rail);
  }
  repn(i, 1, n)
  {
    int sproad = par(i, road);
    int sprail = par(i, rail);
    mp[sproad][sprail]++;
  }
  repn(i, 1, n)
  {
    int sproad = par(i, road);
    int sprail = par(i, rail);
    cout<<mp[sproad][sprail]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 27520
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll dp[100010][2]; int x[509][509]; int c[509][509];
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	cin >> n;
	cin >> s; map<char,ll> mp;
	for (char i = 'a'; i <= 'z'; i++) {
		mp[i] = 0;
	}
	rep(i, n) {
		mp[s[i]]++;
	}
	ll res = 1;
	for (char i = 'a'; i <= 'z'; i++) {
		if (mp[i] != 0) {
			mp[i]++;
			res *= mp[i];
			res %= ma;
		}
	}
	cout << res - 1 << endl;
}




Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 5e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;

double rad(double degree) {
	return PI / 180.0 * degree;
}

int main() {
	int i, j;
	double a, b, x;
	scanf("%lf%lf%lf", &a, &b, &x);
	if (x == a * a * b) {
		printf("0");
		return 0;
	}
	double l = 0.0;
	double r = 90.0 - 1e-7;
	double ans = -1.0;
	while (l <= r) {
		double m = (l + r) / 2.0;
		double h1 = b * sin(rad(m));
		double h2 = a * sin(rad(90.0 - m));
		double ck;
		if (h1 >= h2) ck = a * a * b - (a * a * a) / (2 * tan(rad(m)));
		else ck = (a * b * b) / (2 * tan(rad(90.0 - m)));
		if (x >= ck) {
			ans = m;
			l = m + 1e-7;
		}
		else r = m - 1e-7;
	}
	printf("%.7lf", 90.0 - ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

int main(void){
    int p,q,r,sum1,sum2,sum3,sum4;
    std::cin >> p >> q >> r;
    sum1 = p+q;
    sum2 = q+r;
    sum3 = p+r;
    sum4 = q+p;
    std::cout << std::min(sum1, std::min(sum2, std::min(sum3, sum4))) << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    K, A, B = map(int, input().split())
    if (B - A) <= 2:
        answer = 1 + K
    else:
        cookie = A
        cnt = A - 1
        money = (K - cnt) // 2
        hit = (K - cnt) % 2
        cookie += money * (B - A)
        cookie += hit
        answer = cookie
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 25 01:41:52 2019

@author: yuta
"""
     
def shift(n,s):
    a = [0]*int(n)
    for i in range(0,int(n)):
        count = 0
        b = int(s[i])
        while b % 2 == 0:
            count += 1
            b = b/2
        a[i] = count
    print(min(a))            

kosuu = input()
seisuu = input().split()
shift(kosuu,seisuu)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {


	
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		StringTokenizer st1 = new StringTokenizer(br.readLine());
		
		int n = Integer.parseInt(st1.nextToken());
		int m = Integer.parseInt(st1.nextToken());
		
		PriorityQueue<Long> pq = new PriorityQueue<>((x,y)-> x > y ? -1 : x < y ? 1 : 0);
		
		st1 = new StringTokenizer(br.readLine());
		
		for(int i = 0 ; i < n ; i++)
		{
			long tmp = Long.parseLong(st1.nextToken());
			pq.add(tmp);
		}
		
		
		for(int i = 1 ; i <= m ; i++)
		{
			pq.add(pq.poll()/2);
			//out.println(pq);
		}
		
		long sum = 0l;
		
		while(!pq.isEmpty())
			sum += pq.poll();
		
		out.println(sum);
		out.flush();
		out.close();
	}
	
	
	


}


Measured memory_bytes: 46456
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll dp[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,K;
    cin>>N>>K;
    ll h[N];
    rep(i,0,N) cin>>h[i];
    rer(i,N-1,0){
        ll res=1e10;
        rep(j,1,K+1){
            ll t=(i+j<N?dp[i+j]+abs(h[i+j]-h[i]):1e10);
            res=min(res,t);
        }
        dp[i]=res;
    }
    cout <<dp[0]<<"\n";
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	int x = x2;
	int y = y2;
	int dx = x2 - x1;
	int dy = y2 - y1;

	REP(i,2){
		swap(dx,dy);
		dx = -dx;
		x += dx;
		y += dy;
		if(i == 0) cout << x << ' ' << y << ' ';
		if(i == 1) cout << x << ' ' << y << endl;;
	}

	// cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
	return 0;

}


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

int a[100005];
int main()
{
    int n,k;
    cin>>n>>k;
        for (int i = 0; i < n; i++)
        {
            cin>>a[i];
        }
        if (n == k)
            cout<<"1"<<endl;
        else
        {
            n-=k;
            k--;
            int sum;
            if (n%k != 0)
                sum = 1;
            else sum = 0;
            sum = sum+(n/k)+1;
            cout<<sum<<endl;
        }
    return 0;
}








Measured memory_bytes: 640