akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;


int main() {
	int H, W;
	cin >> H >> W;
	int oneWord = 0;
	int twoWord = 0;
	int fourWord = 0;
	if (H % 2 == 1 && W % 2 == 1) {
		oneWord = 1;
		twoWord = H + W - 2;
		fourWord = H * W - oneWord - twoWord;
	}
	else if (H % 2 == 1) {
		twoWord = W;
		fourWord = H * W - twoWord;
	}
	else if (W % 2 == 1) {
		twoWord = H;
		fourWord = H * W - twoWord;
	}
	else {
		fourWord = H * W;
	}


	map<char, int> mp;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			char a = 0; 
			cin >> a;
			++mp[a];
		}
	}

	bool check = true;
	do {
		check = true;
		for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
			if (itr->second == 1) {
				--oneWord;
				--itr->second;
				check = false;
			}
			else if (itr->second >= 4 && fourWord != 0) {
				fourWord -= 4;
				itr->second -= 4;
				check = false;
			}
			else if (itr->second >= 2 && twoWord != 0) {
				twoWord -= 2;
				itr->second -= 2;
				check = false;
			}
		}
	} while (!check);

	if (oneWord == 0 && twoWord == 0 && fourWord == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations

N, K = map(int, input().split())
points = []
for i in range(N):
    points.append(list(map(int, input().split())))

points.sort(key=lambda p:p[0])


min_area = 10**20
for k in range(K, N+1):
    for l in range(0, N-k+1):
        points_tmp = points[l:l+k]
        points_tmp.sort(key=lambda p:p[1])
        for m in range(0, k-K+1):
            points_selected = points_tmp[m: m+K]
            ymin = points_selected[0][1]
            ymax = points_selected[-1][1]
            points_selected.sort(key=lambda p:p[0])
            xmin = points_selected[0][0]
            xmax = points_selected[-1][0]
            area = (xmax-xmin) * (ymax-ymin)
            min_area = min(area, min_area)

print(min_area)


Measured memory_bytes: 42604
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

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

	ll n;
	cin >> n;

	map<ll, ll> mp;
	REP(i, n) {
		factoring(i + 1, mp);
	}

	ll ans = 1;
	for (auto i : mp) {
		(ans *= (i.second + 1) % MOD) %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i

array = []
n.times do
  array << gets.split(" ").map(&:to_i)
end

array_shaffle =[]

array.permutation(2) do |x|
  array_shaffle << x
end

distance = 0

array_shaffle.each do |x|
  distance += Math.sqrt((x[0][0] - x[1][0])**2 + (x[0][1] - x[1][1])**2)
end

puts distance / array.size


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

int main(){
  int x,a,b,c,d;
  cin >> x >> a >> b;
  c=abs(x-a);
  d=abs(x-b);
  if(c<d){
    cout << "A" << endl;
  }
  else{
    cout << "B" << endl;
  }
}
  


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

int main() {
	int n, taro = 0, hana = 0;
	cin >> n;
	while(n--) {
		string t, h;
		cin >> t >> h;
		if(t > h) taro += 3;
		else if(t < h) hana += 3;
		else taro++, hana++;
	}
	cout << taro << ' ' << hana << '\n';
	return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 inf = 1001001001;
const int mod = 1000000007;

int main() {
    int n,m;
    cin >> n >> m;
    int ans = n*(n-1)/2;
    ans += m*(m-1)/2;
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

const ll MOD = 1e9+7;

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

ll intpow3(ll I){
    ll pow3 = 1;
    for(int i = 0; i < I; i++){
        pow3 = pow3 * 3;
    }
    return pow3;
}

ll sum_vec(vector<int> vec){
    ll ans = 0;
    for(int i = 0; i < vec.size();i++){
        ans+=vec[i];
    }
    return ans;
}

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

    string S;
    cin >> S;
    ll N = S.length();
    vector<ll> A(N+1), AB(N+1), ABC(N+1);

    A[0] = 0;
    AB[0] = 0;
    ABC[0] = 0;

    ll tmp_ht3 = 1;
    for(int i = 0; i < N; i++){
        if(S[i] == '?'){
            A[i+1]   = (3*A[i] + tmp_ht3) % MOD;
            AB[i+1]  = (3*AB[i] + A[i]) % MOD;
            ABC[i+1] = (3*ABC[i] + AB[i]) % MOD;
            tmp_ht3 = (tmp_ht3 * 3) % MOD;
        }else{
            if(S[i] == 'A'){
                A[i+1] = (A[i] + tmp_ht3) % MOD;
            }else{
                A[i+1] = A[i];
            }
            
            if(S[i] == 'B'){
                AB[i+1] = (AB[i] + A[i]) % MOD;
            }else{
                AB[i+1] = AB[i];
            }
            if(S[i] == 'C'){
                ABC[i+1] = (ABC[i] + AB[i]) % MOD;
            }else{
                ABC[i+1] = ABC[i];
            }
        }
    }

    cout << ABC[N] << endl;



    return 0;
}



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

int main() {
  int N;
  string S;
  cin >> N;
  bool Y = false;

  for (int i=0; i<N; i++) {
      cin >> S;
      if (S == "Y") {
          Y = true;
      }
  }

  if (Y) {
      cout << "Four" << endl;
  } else {
      cout << "Three" << endl;
  }
}


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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;


typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;



int main(){
	int N;
	cin>>N;
	assert(N>=100 && N<=999);
	if(N/100 == N%10) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		int p[];
		
		while (true) {
			n = sc.nextInt();
			m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}
			p = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextInt();
			}
			Arrays.sort(p);
			int sum = 0;
			for (int i = n - 1; 0 <= i; i--) {
				if ((n - i) % m != 0) {
					sum += p[i];
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 54404
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
inline long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }

long fact[303];

long dp[2][303][303];

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

  fact[0] = 1;
  rep(i,300) fact[i+1] = (i+1)*fact[i] %MOD;

  if(all_of(all(v), [](int x){return x==2;})){
    cout << fact[n-1] * mod_inv(2) %MOD << endl;
    return 0;
  }

  // dp[i][j][k] iまでj個使ってk個のサイクル外へのパス
  auto pre = dp[0];
  auto nxt = dp[1];
  fill(pre[0], pre[n], 0);
  pre[0][0] = 1;
  rep(i,n) if(v[i]>1){
    rep(j,n) rep(k,n){
      nxt[j][k] = pre[j][k];
      int pj = j-1;
      int pk = k - (v[i]-2);
      if(pj>=0 && pk>=0 && pre[pj][pk]>0){
        nxt[j][k] += pre[pj][pk] * (v[i]-1);
        nxt[j][k] %= MOD;
      }
    }
    swap(pre, nxt);
  }

  long ans = 0;
  rep(i,3,n) rep(j,1,n) if(pre[i][j]>0){
    // dbg(i,j,pre[i][j]);
    assert(n-i >= j);
    long tmp = fact[i-1] * fact[n-i-1] %MOD;
    tmp = tmp * j %MOD;
    tmp = tmp * pre[i][j] %MOD;
    ans += tmp;
  }
  ans %= MOD;

  long muls = 1;
  rep(i,n) muls = muls * fact[v[i]-1] %MOD;

  ans = ans * mod_inv(2*muls %MOD) %MOD;

  cout << ans << endl;

  return 0;
}

/*
map<vector<int>,int> ma = {
  {{2,2,2}, 1},
  {{1,2,2,3}, 1},
  {{2,2,2,2}, 3},
  {{1,1,2,2,4}, 1},
  {{1,1,2,3,3}, 2},
  {{1,2,2,2,3}, 6},
  {{2,2,2,2,2}, 12}
};
*/


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int n, m;
	cin >> n >> m;
	int t = 1800 * m + 100 * n;
	int x = t * pow(2, m);
	co(x);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

  rep(i, X / 100 + 1) {
    int temp = X - i * 100;
    if (0 <= temp && temp <= 5 * i) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    
    if(N<1200){
      System.out.println("ABC");
      return;
    }
    if(N<2800){
      System.out.println("ARC");
      return;
    }
    System.out.println("AGC");
  }
}

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

int main(){
ll n, w; cin>>n>>w;
ll wt[n], val[n];
ll i;
for(i=0;i<n;i++){
    cin>>wt[i]>>val[i];
}
ll dp[n+1][w+1];
ll j;
for(i=0;i<=n;i++){
    for(j=0;j<=w;j++){
        if(i==0||j==0) dp[i][j]=0;
    }
}
for(i=1;i<=n;i++){
    for(j=1;j<=w;j++){
        if(wt[i-1]<=j){
          dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1], dp[i-1][j]);
        }
        else{
            dp[i][j]=dp[i-1][j];
        }
    }
}
cout<<dp[n][w]<<endl;

    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    long long int n;
    cin >> n;
    long long int a[110000], sumpl[110000] = {};
    long long int summi[110000] = {};
    long long int mi = 0, pl = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i == 0)
        {
            sumpl[0] = a[i];
            summi[0] = a[i];
        }
        else
        {
            sumpl[i] = sumpl[i - 1] + a[i];
            summi[i] = summi[i - 1] + a[i];
        }
        if (i % 2 == 0)
        {
            if (sumpl[i] <= 0)
            {
                pl += -1 * sumpl[i] + 1;
                sumpl[i] = 1;
            }
            if (summi[i] >= 0)
            {
                mi += summi[i] + 1;
                summi[i] = -1;
            }
        }
        else
        {
            if (sumpl[i] >= 0)
            {
                pl += sumpl[i] + 1;
                sumpl[i] = -1;
            }
            if (summi[i] <= 0)
            {
                mi += -1 * summi[i] + 1;
                summi[i] = 1;
            }
        }
    }
    cout << (pl < mi ? pl : mi) << endl;
    return 0;
}

Measured memory_bytes: 2816
cards = [[False for y in range(13)] for x in range(4)]
suit2num = {"S": 0, "H": 1, "C": 2, "D": 3}
num2suit = {"0": "S", "1": "H", "2": "C", "3": "D"}

n = int(input())
for i in range(n):
    s, n = input().split()
    cards[suit2num[s]][int(n) - 1] = True

for i in range(4):
    suit = num2suit[str(i)]
    for j in range(13):
        if cards[i][j] == False:
            print(suit + " " + str(j + 1))



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;



void ABC142E()
{
	int N, M;
	cin >> N >> M;
	vi a(M+1);
	vector<vector<int> > c(M+1);
	vi x(M + 1);
	for (int i = 1; i <= M; ++i)
	{
		int b;
		cin >> a[i] >> b;
		c[i].resize(b);
		for (int j = 0; j < b; ++j)
		{
			cin >> c[i][j];
			x[i] |= (1 << (c[i][j]-1));
		}

	}
	vvl dp(M+1, vl(1 << N, 1000000000));
	dp[0][0] = 0;
	for (int i = 1; i <= M; ++i)
	{
		for (int j = 0; j < (1 << N); ++j)
		{
			dp[i][j] = dp[i - 1][j];
		}
		for (int j = 0; j < (1 << N); ++j)
		{
			int k = j | x[i];
			dp[i][k] = min(dp[i][k], dp[i - 1][j] + a[i]);
		}
	}
	ll y = dp[M][(1 << N) - 1];
	if (y == 1000000000)
		cout << "-1" << endl;
	else
		cout << dp[M][(1 << N) - 1] << endl;
}int main()
{
	ABC142E();
	return 0;
}


Measured memory_bytes: 32384
#include<bits/stdc++.h>
using namespace std;
int k,f;
string s,t;
int main(){
	cin>>s>>t;
	if(s.size()!=t.size()-1){
		cout<<"No";
	}
	else{
		for(k=0;k<s.size();k++){
			if(s[k]!=t[k]) {
				f=1; 
			}
		}
		if(f==0) cout<<"Yes";
		else cout<<"No";
	}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;
ll fact[int(1e5)+2];

ll power(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b&1)
			ans = ans*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return ans;
}

ll modInverse(ll a)
{
	return power(a,mod-2);
}

void _fact()
{
	fact[0] = 1;
	for(ll i = 1; i<=int(1e5)+1; i++)
		fact[i] = i*fact[i-1]%mod;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n+1];
	_fact();
	int l = -1;
	map<int,int> m;
	for(int i = 0 ; i<n+1; i++)
	{
		cin>>a[i];
		if(m[a[i]]==1)
			l = i;
		m[a[i]]++;
	}
	ll b[n+2];
	int x = a[l], y =-1;
	for(int i = 0; i<l; i++)
		if(a[i]==x)
		{
			y = i;
			break;
		}
	x = l-y+1;
	for(int i = 1;i <=n; i++)
		b[i] = (fact[n+1]*modInverse(fact[n+1-i]))%mod*modInverse(fact[i])%mod;
	b[n+1] = 1;
	for(int i = 0;i<=n+1-x;i++)
		b[i+1] = (b[i+1]-((fact[n+1-x]*modInverse(fact[n+1-x-i])%mod)*modInverse(fact[i])%mod)+mod)%mod;

	for(int i = 1; i<=n+1; i++)
		cout<<b[i]<<endl; 
	return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string>

using namespace std;

int main(){
    
    string s;
    cin>>s;
    int l = s.size();
    for(int i=1;i<l;i++){
        if(s[i]==s[i-1]){
            cout<<i<<" "<<i+1;
            return 0;
        }        
    }
    for(int i=2;i<l;i++){
        if(s[i]==s[i-2])
        {
            cout<<i-1<<" "<<i+1;
            return 0;
        }
    }
    cout<<"-1"<<" "<<"-1";
    return 0;
}

Measured memory_bytes: 512
A,B,C,D=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

lcm_=lcm(C,D)
answer=B-A+1-(B//C-A//C)-(B//D-A//D)+(B//lcm_-A//lcm_)
if A%C==0:
    answer-=1
if A%D==0:
    answer-=1
if answer<=-1:
    print(0)
else:
    if A%C==0 and A%D==0:
        print(answer+1)
    else:
        print(answer)


Measured memory_bytes: 61940
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 2e5+10;
int n, k, l;
map<LL, int> num;
int fa[3][maxn];
LL Find (int x, int mod) {
    if (fa[mod][x] == x) return x;
    else return fa[mod][x] = Find (fa[mod][x], mod);
}
void Comb (int x, int y, int mod) {
    fa[mod][Find(x, mod)] = Find (y, mod);
}
LL id (int x) {
    return Find(x,0) * 1e6 + Find (x, 1);
}
int main (void) {
    scanf ("%d%d%d", &n, &k, &l);
    for (int i = 1; i <= n; i++) {
        fa[0][i] = i;
        fa[1][i] = i;
    }
    for (int i=  0; i < k; i++) {
        int a, b;
        scanf ("%d%d", &a, &b);
        Comb (a, b, 0);
    }
    for (int i = 0; i < l; i++) {
        int a, b;
        scanf ("%d%d", &a, &b);
        Comb (a, b, 1);
    };
    for (int i=  1; i <= n; i++) {
        num[id(i)]++;
    }
    for (int i = 1; i <= n; i++) {
        printf ("%d", num[id(i)]);
        if (i != n) printf (" ");
        else printf ("\n");
    }
    return 0;
}


Measured memory_bytes: 13568
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    r, _ := strconv.Atoi(arr[0])
    D, _ := strconv.Atoi(arr[1])
    x, _ := strconv.Atoi(arr[2])
    var retval int

    for i := 0; i< 10; i++ {
        retval = r * x - D
        fmt.Println(retval)
        x = retval
    }
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-2][1]-lin2[-1][1])
        else:
            print(n-lin[-1][1]-lin2[-2][1])

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])

Measured memory_bytes: 15900
a, b, c, x, y = [int(i) for i in input().split()]

p = [a * x + b * y, c * max(x, y) * 2]
if x != y:
    if x > y:
        p.append(c * y * 2 + a * (x-y))
    else:
        p.append(c * x * 2 + b * (y-x))

print(min(p))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(c < a){
		swap(a, c);
		swap(b, d);
	}
	if(b < c) cout << 0 << endl;
	else cout << min(b - c, d - c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 2000000
#define MOD 1000000007
#define endl "\n"
map <lli, lli> cycle;
lli N,K;
lli arr[MAX];
lli cp;
lli modul;
lli powa(lli k){
    lli mask = 1;
    for(lli i = 0; i<k; i++)
        mask *= 2;
    return mask;
}
void DFS1(lli n, lli k){
    if(cycle[n]){
        cp = n;
        modul =  k - cycle[n];
    }
    else{
        cycle[n] = k;
        DFS1(arr[n], k+1);
    }

}
void DFS(lli n, lli k){
   // cout<<n<<endl;
    if(n == cp){
        k %= modul;
      //  cout<<"Now K is "<<k<<" "<<modul<<endl;
    }
    
    if(k == 0){
        cout<<n;
        return;
    }
    else{
        DFS(arr[n], k-1);
    }

}
int main(){
  //  ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
    lli t;
    t = 1;
    
    while(t--){
        cin>>N>>K;
        for(lli i = 1; i<=N; i++)
            cin>>arr[i];
        DFS1(1, 1);
       // cout<<cp<<" "<<modul<<endl;
        DFS(1,K);    
    }

}

Measured memory_bytes: 36016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  vector<string> S(N);
  int result = 1;
   for(int a = 0;a < N;a++)cin >> S.at(a);
  
  sort(S.begin(),S.end());
  for(int a = 1;a < N;a++){
    if(S.at(a-1) != S.at(a))result++;
  }

  cout << result << endl;
}

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

using namespace std;

int K;
pair<int, int> golf(int x, int y) {
  if (x < 0) {
    auto p = golf(-x, y);
    return {-p.first, p.second};
  }
  if (y < 0) {
    auto p = golf(x, -y);
    return {p.first, -p.second};
  }
  if (x > y) {
    auto p = golf(y, x);
    return {p.second, p.first};
  }
  if (x+y >= 2*K) {
    return {x, y-K};
  }
  if (x+y == K)
    return {0, 0};
  auto r = K-(x+y)/2;
  return {-r, x+y+r-K};
}

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

  cin>>K;
  int X,Y; cin>>X>>Y;
  if (abs(X+Y)%2 == 1 and K%2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int, int>> moves;
  moves.emplace_back(X, Y);
  while (moves.back().first or moves.back().second) {
    moves.push_back(golf(moves.back().first, moves.back().second));
  }

  std::cout << moves.size()-1 << endl;
  for (int i = moves.size()-2; i >= 0; i--) {
    auto p = moves[i];
    cout << p.first << ' ' << p.second << endl;
  }

  return 0;
}


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

int main(){
	int ans=-1;
	int n;
	cin>>n;
	for(double i=1;i<=n;i++){
		if(i*1.08>=n&&i*1.08<n+1) ans=i;
		else if(i*1.08>=n+1) break;
	}
	if(ans>0) cout<<ans<<endl;
	else cout<<":(";
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef struct Music
{
	char Name[100];
	int Length;
}MUSIC,*PMUSIC;
MUSIC arr[1000];
int Check(char string[],int a)
{
	for(int i=0;i<a;i++)
	{
		if(strcmp(arr[i].Name,string)==0)
		{
			return i;
		}
	}
}
int main()
{
	int a;
	scanf("%d",&a);
	int S=0;
	for(int i=0;i<a;i++)
	{
		scanf("%s %d",arr[i].Name,&arr[i].Length);
		S+=arr[i].Length;
	}
//	printf("%d",S);
	char string[1024];
	scanf("%s",string);
	int b=Check(string,a);
	for(int i=0;i<=b;i++)
	{
		S-=arr[i].Length;
	}
	printf("%d",S);
	return 0;		
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			int[][] map = new int[10][10];
			
			for(int i=0;i<10;i++){
				map[0][i] = Integer.valueOf(s.substring(i,i+1));
			}
			
			for(int i=1;i<10;i++){
				for(int j=0;j<10-i;j++){
					map[i][j] = (map[i-1][j] + map[i-1][j+1])%10;
				}
			}
			
			System.out.println(map[9][0]);

		}
	
	}	
}

Measured memory_bytes: 17144
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#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;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &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 VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(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};

void func(vvl &G, vl &A, ll s, ll par, ll p, ll K) {
  AUTO(i, G[s]) {
    if (i != par) {
      A[i] = p;
      p--;
      func(G, A, i, s, K - 2, K);
    }
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  ll ans = 1;
  cin >> N >> K;
  vvl G(N + 1);
  vl A(N, 1);
  REP(i, N - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  A[0] = K;
  func(G, A, 0, -1, K - 1, K);
  REP(i, N) {
    ans *= A[i];
    ans %= MOD;
  }
  cout << ans << endl;

  //*6
  return 0;
}


Measured memory_bytes: 13568
import sys
input = sys.stdin.readline
import math


def read():
    N = int(input().strip())
    X = input().strip()
    return N, X


def bitdiv(N:int, X:str, d:int):
    q = 0
    for i in range(N):
        q <<= 1
        q |= int(X[i])
        p, q = divmod(q, d)
    return q


def solve(N, X):
    BP = [0 for i in range(N)]
    BM = [0 for i in range(N)]

    c = X.count("1")
    

    # 2^k mod (c+1) を高速に求める
    qp = bitdiv(N, X, c+1)
    BP[N-1] = 1 % (c+1)
    for i in range(N-2, -1, -1):
        BP[i] = (BP[i+1] * 2) % (c+1)
    
    # 2^k mod (c-1) を高速に求める
    if c > 1:
        qm = bitdiv(N, X, c-1)
        BM[N-1] = 1 % (c-1)
        for i in range(N-2, -1, -1):
            BM[i] = (BM[i+1] * 2) % (c-1)

    for i in range(N):
        q = 0
        ans = 0
        if X[i] == "0":
            # X_i \equiv (X + 2^i)
            q = (qp + BP[i]) % (c+1)
            ans += 1
        elif X[i] == "1" and c > 1:
            # X_i \equiv (X - 2^i)
            q = (qm - BM[i]) % (c-1)
            ans += 1
        else:
            q = 0
            ans = 0
        while q > 0:
            q %= (bin(q).count("1"))
            ans += 1
        print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 25300
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

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

using namespace std;

int i,j,m,n,p,k,f[N],a[N];

int main()
{
		scanf("%d",&n);
		memset(f,60,sizeof(f));
		f[1]=0; 
		for (j=1;j<=n;++j) scanf("%d",&a[j]);
		for (i=2;i<=n;++i)
		{
				f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
		}
		printf("%d\n",f[n]); 
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

struct UF {
  vector<int> p;
  UF(int n) : p(n,-1) {}
  int rt(int x) { return p[x]<0 ? x : p[x]=rt(p[x]); }
  bool cat(int x, int y) {
    x=rt(x); y=rt(y);
    if(x==y) return false;
    if(p[x]<p[y]) swap(x,y);
    p[y]+=p[x];
    p[x]=y;
    return true;
  }
};

int main() {
  for(int tci = 0; ; tci++) {
    int n,m; scanf("%d%d", &n, &m);
    if(n==0) break;
    vector<pair<int,pair<int,int> > > edges(m);
    for(int i = 0; i < m; i++) {
      int a,b,c; scanf("%d%d%d", &a, &b, &c);
      edges[i] = make_pair(c,make_pair(a,b));
    }
    sort(edges.begin(), edges.end());
    UF uf(n);
    long long cost_sum = 0;
    for(int i = 0; i < m; i++) {
      if(uf.cat(edges[i].second.first, edges[i].second.second)) {
        cost_sum += edges[i].first;
      }
    }
    printf("%lld\n", cost_sum);
  }
  return 0;
}

Measured memory_bytes: 1032
#include<stdio.h>
#include<string.h>
#define MAX 1000000
int can[MAX+1];

int main(){
	int n,a,b,ans,i;
	while(scanf("%d %d %d",&n,&a,&b),n||a||b){
		memset(can,0,sizeof(can));
		can[0]=1;
		ans=0;
		for(i=0;i<=n;i++){
			if(can[i]){
				if(i+a<=n)can[i+a]=1;
				if(i+b<=n)can[i+b]=1;
			}
			else ans++;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 4940
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main(){
    int n; //n:スイッチの個数
    int m; //m:電球の個数

    cin >> n >> m;
    int ans = 0;

    vector<vector<int>> data(m);

    for(int i = 0; i < m; i++){
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int a; cin >> a; a--;
            data[i].push_back(a);
        }
    }

    vector<int>check(m);
    for(int i = 0; i < m; i++){
        cin >> check[i];
    }

    for(int i = 0; i < (1 << n); i++){
        bool flag = true;
        bitset<10> bs(i);
       // int cnt1 = bs.count(); //ビットの1の数
        //cout << "i:" << i << endl;
        //cout << "cnt1:" << cnt1 << endl;
        
        for(int j = 0; j < m; j++){ //電球をそれぞれ見ていく！
            int on = 0;
            /* if(data[j].size() < cnt1){ //それぞれの電球についてるスイッチの数よりビットの1が多くたってる場合
                flag = false;
                break;
            } */

            for(int l = 0; l < n; l++){
                if(((i >> l) & 1) == 1 && vector_finder(data[j],n-l-1) == 1){ //ビット1が立っている
/*                     if(vector_finder(data[j],n-l-1) == 0){
                        cout << "j:" << j << "l:" << l << endl;
                        flag = false;
                    }else{
                        on++;
                    } */
                    on++;
                    
                }
            }
            //cout << "on:" << on << endl;
            if(flag){
                if(!(on % 2 == check[j]))flag = false;
            }

       }

       if(flag)ans++;


    }

    cout << ans << endl;

}

Measured memory_bytes: 3620
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        S: chars
    }
    let p = (S[0] as u32 - '0' as u32) * 10 + (S[1] as u32 - '0' as u32);
    let n = (S[2] as u32 - '0' as u32) * 10 + (S[3] as u32 - '0' as u32);

    match (p, n) {
        (1...12, 1...12) => println!("AMBIGUOUS"),
        (1...12, _) => println!("MMYY"),
        (_, 1...12) => println!("YYMM"),
        (_, _) => println!("NA"),
    }
}

Measured memory_bytes: 4352
n = gets.to_i
c = gets.split(" ").map(&:to_i)

d = 0
for i in 0..n-1
  mini = i
  for j in i..n-1
    if c[j] < c[mini]
      mini = j
    end
  end
  if i != mini
    c[i],c[mini] = c[mini], c[i]
    d += 1
  end
end

puts c.join(" ")
puts "#{d}"



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

#define rep(i,a,n)   for(int i=a;i<n;i++)
#define repe(i,a,n)  for(int i=a;i<=n;i++)
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vc>  vcc;
#define fast   ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)


#define mod 1000000007
#define nl "\n"


int main()
{  fast;
  int n;
  cin>>n;
  vector<vector<int> > a(n,vector<int>(2,0));
  for(int i=0;i<n;i++)
  {
      cin>>a[i][0]>>a[i][1];
  }
   bool flag=false;
    for(int i=0;i<n-2;i++)
    {   int j;
           for( j=i;j<i+3;j++)
        {
           if(a[j][0]!=a[j][1])
               break;
        }
        if(j==i+3)
      {
          flag=true;
        break;
      }
       }

    cout<<(flag?"Yes":"No")<<endl;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,a[101],b[101],z;
	while(true){
	cin>>n>>m;
	if(n==0&&m==0)
		break;
	for(int i=0;i<m;i++)
		a[i]=0;
	for(int i=0;i<m;i++)
		b[i]=i+1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>z;
			a[j]+=z;
		}
	}
	for(int i=0;i<m-1;i++){
		for(int j=m-1;j>i;j--){
			if(a[j]>a[j-1]){
				int tmp=a[j];
				a[j]=a[j-1];
				a[j-1]=tmp;
				tmp=b[j];
				b[j]=b[j-1];
				b[j-1]=tmp;
			}
		}
	}
	for(int i=0;i<m-1;i++)
		cout<<b[i]<<" ";
	cout<<b[m-1]<<endl;
	}
    return 0;
}
 

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5 + 5;
int  ans[N];
int main() {
	IO
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	ans[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++){
		ans[i] = min(abs(h[i - 2] - h[i]) + ans[i-2] , abs(h[i-1] - h[i]) + ans[i - 1]);
	}
	cout << ans[n - 1];
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=998244353;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int a[maxn];
int Sheryang(){
    int n=read;
    for(int i=1;i<=n;i++){
        a[i]=read;
    }
    sort(a+1,a+1+n);

    int GCD=0;
    for(int i=1;i<=n;i++){
        GCD=__gcd(GCD,a[i]);
    }

    cout<<GCD<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
	}
	int BS = 0;
	rep(i, N) {
		BS += B[i];
	}
	vector<int>sum(N,BS);
	rep(i, N) {
		rep(j, i+1) {
			sum[i] += A[j];
		}
		rep(j, i) {
			sum[i] -= B[j];
		}
	}
	sort(sum);
	reverse(sum);
	cout << sum[0] << endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int i,z=0,b[101],a[101],k,n;

while(~scanf("%d",&n))
  {
  for(i=0;i<101;i++)
   b[i]=0;
   z=0;
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(i=0;i<n;i++)
   b[a[i]]++;
   for(i=0;i<101;i++)
   if(b[i]>0) {
   z++;
   }
    printf("%d\n",z);
} }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    priority_queue<int>pq;
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        pq.push(a);
    }
    while(m--){
        int cur=pq.top();
        pq.pop();
        cur/=2;
        pq.push(cur);
    }
    while(!pq.empty()){
        sum+=pq.top();
        pq.pop();
    }
    cout<<sum<<endl;



    return 0;
}


Measured memory_bytes: 3864
import sys
input = sys.stdin.readline
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))

H,W=MI()
A=[LI() for _ in [0]*H]
B=[LI() for _ in [0]*H]

G=[[set() for i in range(W)] for j in range(H)]
G[0][0].add(0)

for h in range(H):
    for w in range(W):
        d=A[h][w]-B[h][w]
        for a in G[h][w]:
            if h!=H-1:
                G[h+1][w].add(abs(a+d))
                G[h+1][w].add(abs(a-d))
            if w!=W-1:
                G[h][w+1].add(abs(a+d))
                G[h][w+1].add(abs(a-d))

res=set()
d=A[H-1][W-1]-B[H-1][W-1]
for a in G[H-1][W-1]:
    res.add(abs(a+d))
    res.add(abs(a-d))

res=sorted(list(res))
print(min(res))

Measured memory_bytes: 539820
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(D, N):
    if N == 100:
        N += 1
    if D == 0:
        return N

    return N * (100**D)


def main():
    D, N = read_int_n()
    print(slv(D, N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6220
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
      cin>>a[i];
    ll dp[n+1][k+1];
    mset(dp,0);
    dp[0][0] = 1;
    for(int i=1;i<=n;i++)
    {
      ll sum[k+1];
      sum[0] = dp[i-1][0];
      for(int j=1;j<=k;j++)
      {
          sum[j] =(sum[j-1]+dp[i-1][j]%MOD)%MOD;
      }
      for(int j=0;j<=k;j++)
      {
        ll fg = j - a[i] -1;
        ll tr = sum[j];
        if(fg>=0)
          tr = (tr-sum[fg] + MOD)%MOD;
        dp[i][j] = tr;
      }
    }
    cout<<dp[n][k];


    
    
    return 0;
}

Measured memory_bytes: 80000
#include <cstdio>
#include <algorithm>
#include  <queue>
using namespace std;
struct Node {
    int a;
    long long b;
}node[100005];
bool cmp(Node x, Node y) {
    return x.a < y.a;
}
int main() {
    int n, m;
    scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++) {
        scanf("%d%lld",&node[i].a,&node[i].b);
    }
    sort(node,node+n,cmp);
    priority_queue<long long> que;
    int j = 0;
    long long ans = 0;
    for (int i = 1; i <= m; i++) {
        while (node[j].a <= i && j < n)
            que.push(node[j++].b);
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

  int N, K;
  cin >> N >> K;
  if (K == 1) cout << 0 << endl;
  else cout << N-K << endl;
}


Measured memory_bytes: 892