akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=3005,mod=1e9+7;
int add(int x,int y)
{
    x+=y;
    if(x>=mod)
        x-=mod;
    return x;
}
int sub(int x,int y)
{
    x-=y;
    if(x<0)
        x+=mod;
    return x;
}
int mul(int a,int b)
{
    return ((ll)a*b)%mod;
}
int powmod(int x,int k) {int ans=1;for(;k;k>>=1,x=mul(x,x))if(k&1)ans=mul(ans,x);return ans;}
int inv(int i)
{
    return powmod(i,mod-2);
}
int dp[N];
const int l=2e5+5;
int fact[l];
int ways(int x,int y,int a,int b)
{
    x=abs(x-a);
    y=abs(y-b);
    int ans=mul(fact[x+y],inv(fact[x]));
    ans=mul(ans,inv(fact[y]));
    return ans;
}
vector<int> r[N];
vector<pair<int,int> > block;
int main()
{
    fact[0]=1;
    fact[1]=1;
    for(int i=2;i<l;i++)
        fact[i]=mul(fact[i-1],i);
    int n,m,k;
    scanf("%i %i %i",&n,&m,&k);
    block.pb({1,1});
    block.pb({n,m});
    for(int i=0;i<k;i++)
    {
        int x,y;
        scanf("%i %i",&x,&y);
        block.pb({x,y});
    }
    sort(all(block));
    n=block.size();
    dp[n-1]=1;
    //cout << block << endl;
    for(int i=1;i<n;i++)
    {
        dp[i]=ways(1,1,block[i].f,block[i].s);
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(block[j].f>=block[i].f&&block[j].s>=block[i].s)
            {
                dp[j]=sub(dp[j],mul(dp[i],ways(block[i].f,block[i].s,block[j].f,block[j].s)));
            }
        }
    }
    printf("%i\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define INF 1e9

typedef struct{
  char suit;
  int num;
  
}Card;

int partition(Card [], int, int);
void quicksort(Card [], int, int);
void mergesort(Card [], int, int);
void merge(Card [], int, int, int);
void Compare_and_Print(Card [], Card [], int);

Card Left[MAX/2+2];
Card Right[MAX/2+2];

int main()
{
  int i;
  int n;
  char str[15];
  Card A[MAX]={};
  Card B[MAX]={};
  
  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%s%d", str, &A[i].num);
    A[i].suit = str[0];
    //A[i].suit = s;
    //A[i].num = atoi(str);
    //printf("A(suit, num) = (%c,%d)\n",A[i].suit, A[i].num);
    B[i] = A[i];
    //printf("B(suit, num) = (%c,%d)\n",B[i].suit, B[i].num);
  }
  
  quicksort(A, 0, n-1);
  mergesort(B, 0, n);

  Compare_and_Print(A, B, n);
  
  return 0;
}

void merge(Card A[], int l, int mid, int r)
{
  int i,k;
  
  int n1 = mid - l;
  int n2 = r - mid;

  for(i = 0;i < n1;i++) Left[i] = A[l+i];
  for(i = 0;i < n2;i++) Right[i] = A[mid+i];
  Left[n1].num = Right[n2].num = INF;

  int ii=0,jj=0;
  for(k = l;k < r;k++){
    if(Left[ii].num <= Right[jj].num) A[k] = Left[ii++];
    else A[k] = Right[jj++];
  }
}

void mergesort(Card A[], int left, int right)
{
  if( left+1 < right ){
    int mid = (right + left)/2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void quicksort(Card A[], int p, int r)
{
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

int partition(Card A[], int p, int r)
{
  int i,j;
  int x;
  Card temp;
  
  x = A[r].num;
  i = p-1;
  for(j = p; j < r;j++){
    if(A[j].num <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  
  return i+1;
}

void Compare_and_Print(Card A[], Card B[], int n)
{
  int i;
  int judge = 1;

  for(i=0;i < n;i++){
    if(A[i].suit != B[i].suit){
      judge = 0;
    }
  }
  if(judge == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  for(i = 0;i < n;i++){
    printf("%c %d\n",A[i].suit, A[i].num);
  }
}



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

int64_t f(int n, int* a) {
	int64_t s = a[0];
	int64_t c = 0;
	for (int i = 1; i < n; i++) {
		int64_t t = s + a[i];
		if (s < 0 && t <= 0) {
			c += 1 - t;
			t = 1;
		} else if (s > 0 && t >= 0) {
			c += 1 + t;
			t = -1;
		}
		s = t;
	}
	return c;
}

int main() {
	int n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int a0 = a[0];
	int64_t c = INT64_MAX;
	if (a0 < 0) {
		a[0] = a0;
		c = min(c, f(n, a));
	} else {
		a[0] = -1;
		c = min(c, f(n, a) + 1 + a0);
	}
	if (a0 > 0) {
		a[0] = a0;
		c = min(c, f(n, a));
	} else {
		a[0] = 1;
		c = min(c, f(n, a) + 1 - a0);
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 640
# http://hos.ac/slides/20130319_enumeration.pdf
class CombP
  P = 10**9 + 7
  def initialize(n)
    @inv = Array.new(n, 0)
    self.inv(n)
    @fac = Array.new(n, 0)
    @facInv = Array.new(n, 0)
    self.fact(n)
  end
  def inv(n)
    @inv[1] = 1
    (2..n).each do |i|
      @inv[i] = P - ((P / i) * @inv[P % i]) % P
    end
  end
  def fact(n)
    @fac[0] = 1
    @facInv[0] = 1
    (1..n).each do |i|
      @fac[i] = (@fac[i-1] * i) % P
      @facInv[i] = (@facInv[i-1] * @inv[i]) % P
    end
  end
  def choose(n, k)
    if !(0 <= k && k <= n)
      return 0
    end
    return (((@fac[n] * @facInv[k]) % P) * @facInv[n - k]) % P
  end
end

if $0 == __FILE__
  n = gets.chomp.to_i
  a = gets.chomp.split(" ").map(&:to_i)

  aa = Array.new(n+2)
  n_dup_i = Array.new()
  a.each_with_index do |e, i|
    if aa[e].nil?
      aa[e] = i
    else
      n_dup_i = [aa[e], i]
    end
  end
  d = n_dup_i[1] - n_dup_i[0]

  combp = CombP.new(n+2)

  (1..(n+1)).each do |i|
    puts (combp.choose(n + 1, i) - combp.choose(n-d, i - 1)) % CombP::P
  end

end



Measured memory_bytes: 15372
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int H, W;
	for (;;){
		cin >> H >> W;
		if (W == 0 && H == 0){
			break;
		}
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
	}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define mkp make_pair
#define fi first
#define se second
int n,k;
typedef long long ll;
typedef pair<ll,ll> pll; 
priority_queue <pll> q;
vector <pll> res;
map <ll,int> mp;
ll ans=0,num=0;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		ll t,d;cin>>t>>d;
		q.push(mkp(d,t));
	}
	for (int i=1;i<=k;i++)
	{
		pll aw=q.top();
		q.pop();
		mp[aw.se]++;
		num+=aw.fi;
		res.push_back(aw);
	}
	ll sz=mp.size();
	ans=num+sz*sz;
	reverse (res.begin(),res.end());
	for (int i=0;i<k;i++)
	{
		if (mp[res[i].se]==1) continue;
		while (!q.empty())
		{
			pll aw=q.top();
			q.pop();
			if (mp[aw.se]==0)
			{
            	num=num-res[i].fi+aw.fi;
            	sz++;
            	ans=max(ans,num+sz*sz);
 				mp[res[i].se]--;mp[aw.se]++;
 				res[i]=aw;
 				break;
            }
		}
	}
	cout<<ans;
}

Measured memory_bytes: 7280
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
mi, ami = float("inf"), -1
for i, h in enumerate(H, 1):
    t = abs(T - 0.006 * h - A)
    if t < mi:
        mi = t
        ami = i
print(ami)


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

int main() {
    int N;
    cin >> N;
    map<ll, int> cnt;
    ll A, ans = 0;
    rep(i, N) {
        cin >> A;
        ans += cnt[i - A];
        cnt[A + i]++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

    int n;
    cin>>n;

    int d=n%10;
    if(d==2 or d==4 or d==5 or d==7 or d==9)
        cout<<"hon"<<endl;
    else if(d==0 or d==1 or d==6 or d==8)
        cout<<"pon"<<endl;
    else cout<<"bon"<<endl;

    return 0;
}

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

const ll INF = 1LL << 60;

ll W, H, a, b;
int main() {
    cin >> W >> H >> a >> b;

    long double ans = (double)W * H / 2;

    bool judge = (W == 2 * a && H == 2 * b);

    printf("%.10Lf %d\n", ans, judge);
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))

mod = 998244353

from collections import Counter, deque

def solve(N,D):
    if D[0]!=0:
        return 0
    c = Counter(D)
    if c[0]>1:
        return 0
    ans = 1
    m = max(D)
    for i in range(1,m):
        # if c[i]==0:
        #     ans = 0
        #     continue
        ans *= pow(c[i],c[i+1],mod)
        ans %= mod
    return ans

print(solve(N,D))

Measured memory_bytes: 18936
#include <iostream>

using namespace std;

const long long MOD = 998244353;
long long fa[200001],in[200001];

long long fp(long long a, long long b){
	if(b==0)return 1;
	long long res = fp(a,b/2);
	res = (res*res)%MOD;
	if(b%2) res= (res*a)%MOD;
	return res;
}

long long cho(long long x, long long i){
	long long res  =fa[x];
	res = (res*in[i])%MOD;
	return (res*in[x-i])%MOD;
}
int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	long long n,m,k;
	cin>>n>>m>>k;
	fa[0] = 1;
	for(long long i = 1;i<=n;i++)fa[i] = (i*fa[i-1])%MOD;
	in[n] = fp(fa[n],MOD-2);
	for(long long i = n-1;i>=0;i--)in[i] = ((i+1)*in[i+1])%MOD;
	long long ba = (fp(m-1,n-k-1) * m)%MOD;
	long long res = 0;
	for(;k>=0;k--){
		//cout<<k<<' '<<ba<<' '<<cho(n-1,k)<<endl;
		res = (res + ba * cho(n-1,k))%MOD;
		ba = (ba*(m-1))%MOD;
	}
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 6284
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
typedef long long ll;


struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a){
        return mint(v) *= a;
    }

    mint operator+(mint a){
        return mint(v) += a;
    }

    mint operator-(mint a){
        return mint(v) -= a;
    }

    mint pow(long long k){
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};


int main(){
    ll n, m;
    cin >> n >> m;

    vector<bool> broken(n + 2, false);
    for(int i = 0; i < m; ++i){
        int ai;
        cin >> ai;
        broken.at(ai) = true;
    }

    vector<mint> dp(n + 2, 0);
    dp.at(n) = 1;
    for(ll i = n - 1; i >= 0; --i){
        if(broken.at(i)){ continue; }

        if(!broken.at(i + 1) && !broken.at(i + 2)){
            dp.at(i) = dp.at(i + 1) + dp.at(i + 2);
        }else if(!broken.at(i + 1) && broken.at(i + 2)){
            dp.at(i) = dp.at(i + 1);
        }else if(broken.at(i + 1) && !broken.at(i + 2)){
            dp.at(i) = dp.at(i + 2);
        }
    }
    cout << dp.at(0).v << endl;
    return 0;
}


Measured memory_bytes: 1024
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]
X = [0,w]
Y = [0,h]
for x,y,a in xya:
    if a == 1:
        X[0] = max(X[0], x)
    elif a == 2:
        X[1] = min(X[1], x)
    elif a == 3:
        Y[0] = max(Y[0], y)
    else:
        Y[1] = min(Y[1], y)
if X[0] >= X[1] or Y[0] >= Y[1]: print(0)
else: print(abs(X[0]-X[1])*abs(Y[0]-Y[1]))

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

using namespace std;

int main()
{
	int data[10];

	for (int i = 0; i < 10; i++) cin >> data[i];

	sort(data, data + 10);

	for (int i = 9; i >= 7; i--) cout << data[i] << endl;

	return (0);
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
 
int main() {
    string n;
	int x;
	cin >> n;
    if ( n == "111") {
      x = 3;
    }else if(n == "000"){
      x = 0;
    }else if(n == "100" || n == "010" || n== "001"){
      x = 1;
    }else{
      x = 2;
    }
	cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n, m;
int x[100010], y[100010];
signed main() {
    cin >> n >> m;
    rep(i,0,n) cin >> x[i];
    rep(i,0,m) cin >> y[i];

    int sx = 0, sy = 0;
    rep(i,1,n) sx = madd(sx, mmul(mmul(n-i, i), x[i] - x[i-1]));
    rep(i,1,m) sy = madd(sy, mmul(mmul(m-i, i), y[i] - y[i-1]));

    int ans = 1;
    ans = mmul(ans, sx);
    ans = mmul(ans, sy);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [A[i]-B[i] for i in range(n)]

plus = []
minus = []

for i in range(n):
    if C[i]>0:
        plus.append(C[i])
    elif C[i]<0:
        minus.append(C[i])

plus.sort(reverse=True)
f = sum(minus)
if f == 0:
    print(0)
    exit()

for i in range(len(plus)):
    f += plus[i]
    if f>=0:
        print(i+1+len(minus))
        break
else:
    print(-1)


Measured memory_bytes: 19068
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
	vl a(n);
	rep(i,n) cin >> a[i];
	rep(i,n){
		if(a[i]%2 == 0){
			if(a[i]%3 != 0 && a[i]%5 != 0){
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
}

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

int D, G;
//vector<int> p(D), c(D);
vector<int> p(20), c(20);

int ans = 1e9;

void rec(int sum, int counter, int i, vector<bool> D_bool) {
  if (i == D) {
    if (sum >= G) {
      ans = min(ans, counter);
    }
    else {
      int j = D - 1;
      rrep(k,D-1) {
        if (!D_bool.at(k)) {
          j = k;
          break;
        }
      }
      
      for (int l = 0; l < p.at(j)-1 && sum < G; l++) {
        sum += 100*(j+1);
        counter++;
      }

      if (sum >= G) ans = min(ans,counter);
     
    }
  }
  else {
    D_bool.at(i) = false;
    rec(sum, counter, i+1, D_bool);
    
    D_bool.at(i) = true;
    rep(j,p[i]) {
      sum += 100*(i+1);
      counter++;
    }
    sum += c.at(i);
    rec(sum, counter, i+1, D_bool);
  }
}

int main() {
  cin >> D >> G;
  rep(i,D) cin >> p.at(i) >> c.at(i);
  
  vector<bool> vec_bool(D, false);
  
  rec(0,0,0,vec_bool);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> cell(h, vector<char>(w));
	rep(i, 0, h) rep(j, 0, w) cin >> cell[i][j];

	vector<bool> y(h, false);
	vector<bool> x(w, false);
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (cell[i][j] == '#') {
				y[i] = true;
				x[j] = true;
			}
		}
	}

	rep(i, 0, h) {
		rep(j, 0, w) {
			if (y[i] && x[j]) cout << cell[i][j];
		}
		if (!y[i]) continue;
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
struct edge{int to;ll cap;int rev;};
int main(){
    ll N;
    vector<ll> dp;
    cin>>N;
    dp.resize(N);
    rep(i,N) cin>>dp[i];
    if(N < 3) cout<<abs(dp[1]-dp[0])<<endl;
    else {
        vector<ll> cost(N,inf);
        cost[0] = 0;
        cost[1] = abs(dp[1]-dp[0]);
        REP(i,2,N) cost[i] = min(cost[i-1] + abs(dp[i]-dp[i-1]),cost[i-2] + abs(dp[i]-dp[i-2]));
        // rep(i,N) cout<<cost[i]<<endl;
        cout<<cost[N-1]<<endl;

    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

// 奇数の人は奇数、偶数の人は偶数番目にはいる

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> L(N);
  FOR(i,0,N) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  ll ans = 0;
  FOR(i,0,N) {
    FOR(j,0,N) {
      if (i == j) continue;
      int a = L[i];
      int b = L[j];
      int mxi = lower_bound(L.begin(), L.end(), a + b) - L.begin();
      int mni1 = upper_bound(L.begin(), L.end(), a - b) - L.begin();
      int mni2 = upper_bound(L.begin(), L.end(), b - a) - L.begin();
      int mni = max(mni1, mni2);
      ans += mxi - mni;
      if (i < mxi && i >= mni) ans--;
      if (j < mxi && j >= mni) ans--;
    }
  }
  cout << ans / 6 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int N,M;cin>>N>>M,N|M;){
		vvi a(M+1,vi(1261));
		int r; cin>>r;
		rep(i,r){
			int t,n,m,s;cin>>t>>n>>m>>s;
			if(s==0)
				a[m][t]--;
			else
				a[m][t]++;
		}
		repi(i,1,M+1) repi(j,541,1261)
			a[i][j]+=a[i][j-1];
		int q; cin>>q;
		rep(i,q){
			int ts,te,m; cin>>ts>>te>>m;
			int res=0;
			repi(j,ts,te)
				res+=!!a[m][j];
			cout<<res<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 47000
import numpy as np
n = int(input())

x =[]
for i in range(n):
    x1, y1 = [i for i in input().split()]
    x.append(x1+"{0:04d}".format(100-int(y1)))

for i in range(len(x)):
    print(np.argsort(x)[i]+1)

Measured memory_bytes: 12500
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  int a_max = 0;
  for (int i = 0; i < T; i++)
  {
    cin >> a[i];
    if (a_max < a[i])
      a_max = a[i];
  }
  cout << max(0, (a_max - 1) - (K - a_max)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    if(s[2]==s[3] && s[4] == s[5])cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
    
 return 0;   
}
  
  
  
  


Measured memory_bytes: 256
require 'pp'

N,A,B,C = readline.chomp.split.map(&:to_i)

L = Array.new(N)
N.times {|i| L[i] = readline.chomp.to_i }

INF = 100000000

def dfs(cur, a, b, c)
  if cur == N
    if a>0 and b>0 and c>0
      return (a-A).abs+(b-B).abs+(c-C).abs-30
    else
      return INF
    end
  end

  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+L[cur], b, c)+10
  ret2 = dfs(cur+1, a, b+L[cur], c)+10
  ret3 = dfs(cur+1, a, b, c+L[cur])+10
  [ret0,ret1,ret2,ret3].min
end

puts dfs(0,0,0,0)


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

char a[101][101];
bool r[101], c[101];

int main(){
    int h, w;
    cin >> h >> w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++) cin >> a[i][j];
    }
    
    //cout << "ANS" << endl;

    for(int i=0; i<h; i++){
        bool flagR = false;
        for(int j=0; j<w; j++) if(a[i][j] == '#') flagR = true;
        if(flagR) r[i] = true;
    }

    for(int i=0; i<w; i++){
        bool flagC = false;
        for(int j=0; j<h; j++) if(a[j][i] == '#') flagC = true;
        if(flagC) c[i] = true;
    }

    for(int i=0; i<h; i++){
        bool flag = false;
        for(int j=0; j<w; j++)
        if(r[i]&&c[j]){
            cout << a[i][j];
            flag = true;
        }
        if(flag) cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
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 ll INF=1LL<<60;

ll k,a,b;

int main(){
    cin>>k>>a>>b;
    ll ans;
    if(a>=b || b-a==1){
        ans=k+1;
    }
    else{
        ll now=1;
        while(k>0){
            if(now<a){
                now++;
                k--;
            }
            else if(k>1){
                now=now-a+b;
                k-=2;
            }
            else if(k=1){
                now++;
                k--;
            }
        }
        ans=now;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	int a,b;
	cin >>a >> b;
	if(a+b == 15){
		cout << '+' <<endl;
	}
	else if(a*b == 15 ){
		cout << '*' <<endl;
	}
	else{
		cout <<'x' <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;	cin>>s;
	bool OK=true;
	for(int i=0;i<s.size();i++)
		if(s[i]!=s[s.size()-1-i])
			OK=false;
	int x1=(s.size()-1)/2 , x2=(s.size()+3)/2;
	for(int i=0;i<x1;i++)
		if(s[i]!=s[x1-1-i])
			OK=false;
	for(int i=x2-1 , j=0;i+j<s.size();j++)
		if(s[i+j]!=s[s.size()-1-j])
			OK=false;
	if(OK)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    


  int main(){
     lint n,k;
     cin>>n>>k;
     lint a[n];
     lint d[n+1];
     rep(i,n)cin>>a[i];
     rep(i,n+1)d[i]=0;
     lint count=0;
     rep(j,min(k,(lint)300)){

         fill(d,d+n+1,0);
     rep(i,n){
         d[max((lint)0,i-a[i])]++;
          d[min(n,i+a[i]+1)]--;
        }

     
        rep(i,n){
            d[i+1]+=d[i];
           a[i]=d[i];
        }
     }
     rep(i,n)cout<<a[i]<<" ";
     }
     

  
 
  
      
      
    
 
  
          
  

Measured memory_bytes: 6764
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let [a, b, c, d] = lines[0].split(' ').map( _ => parseInt(_))
    let ans = BigInt(a) * BigInt(c)
    
    if(BigInt(a) * BigInt(d) > ans) {
        ans = BigInt(a) * BigInt(d)
    }

    if(BigInt(b) * BigInt(c) > ans) {
        ans = BigInt(b) * BigInt(c)
    }

    if(BigInt(b) * BigInt(d) > ans) {
        ans = BigInt(b) * BigInt(d)
    }

    console.log(String(ans));

});

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  
  
  long long ans = 0, x = n;
    if(n >= b-1) x = b-1;
    ans = floor(a*x / b) - a*floor(x/b);
    
  cout << ans << endl;
}


Measured memory_bytes: 3612
I=lambda:list(map(int,input().split()))
s=list(input())
t=list(input())
ans=len(t)
for i in range(len(s)-len(t)+1):
	temp=s[i:i+len(t)]
	te=0
	for j in range(len(t)):
		if temp[j]!=t[j]:
			te+=1
	ans=min(te,ans)
print(ans)


Measured memory_bytes: 67768
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	if e-a <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 1768
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<ext/rope>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e4 + 5;
using namespace std;
using __gnu_cxx::crope;

int main()
{
	string s;
	cin >> s;
	if(s.size() == 3) reverse(all(s));
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
vector<int> vertexs[200000];
int n, k;
pair<int,int> dfs(int now) {
	int maximum_cnt = 1;
	int ans = 0;
	for (int i = 0;i < vertexs[now].size();++i) {
		pair<int, int> wow = dfs(vertexs[now][i]);
		if (now != 1 && wow.second == k) {
			ans++;
		}
		else {
			maximum_cnt = max(maximum_cnt, wow.second + 1);
		}
		ans += wow.first;
	}
	return make_pair(ans, maximum_cnt);
}
int main() {
	cin >> n >> k;
	int ans = 0;
	REP(i, n) {
		int a;
		cin >> a;
		if (i == 0) {
			if (a != 1) ans++;
		}
		else {
			vertexs[a].push_back(i + 1);
		}
	}
	cout << ans + dfs(1).first << endl;
	return 0;
}

Measured memory_bytes: 14336
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: u8 = sc.next();
    let s: String = sc.next();
    let ans = s
        .as_bytes()
        .iter()
        .map(|c| ((c - b'A' + n) % 26 + b'A') as char)
        .collect::<String>();
    println!("{}", ans);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
mod = 10**9+7
N,K = map(int,input().split())
dp = [[[0]*(K+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 1

for i in range(1,N+1):
    for j in range(N+1):
        for k in range(K+1):
            if k-2*j >= 0:
                dp[i][j][k] = (2*j+1)*dp[i-1][j][k-2*j]
                if j != N:
                    dp[i][j][k] += (j+1)**2*dp[i-1][j+1][k-2*j]
                if j != 0:
                    dp[i][j][k] += dp[i-1][j-1][k-2*j]
            dp[i][j][k] %= mod

print(dp[N][0][K])

Measured memory_bytes: 95324
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

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


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  std::vector<int> A(3);
  std::cin >> A[0];
  std::cin >> A[1];
  std::cin >> A[2];

  std::sort(A.begin(), A.end());

  std::cout << (A[1]-A[0] + A[2]-A[1]) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

int n,a,b,c;
vector<int>l;

int rec(int i,int suma=0,int sumb=0,int sumc=0){
    if(i==n){
        if(suma&&sumb&&sumc)return abs(suma-a)+abs(sumb-b)+abs(sumc-c);
        else return 1e5;
    }
    int res0=rec(i+1,suma,sumb,sumc);
    int res1=rec(i+1,suma+l[i],sumb,sumc)+(suma!=0?10:0);
    int res2=rec(i+1,suma,sumb+l[i],sumc)+(sumb!=0?10:0);
    int res3=rec(i+1,suma,sumb,sumc+l[i])+(sumc!=0?10:0);
    int res=min({res0,res1,res2,res3});
    return res;
}

void solve(){
    cin>>n>>a>>b>>c;
    l.resize(n);
    int ans=1e5;
    rep(i,n)cin>>l[i];
    rep(i,4)chmin(ans,rec(0));
    cout<<ans<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define REP(a,b,c) for(int a=b;a<c;a++)
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
vp getFactorization(lli x) 
{ 
    vector<lli> ret; 
    while(x%2==0){
    	ret.pb(2);
    	x/=2;
    }
    for(lli i=3;i<=sqrt(x);i+=2){
    	while(x%i==0){
    		ret.pb(i);
    		x=x/i;
    	}
    }
    if(x>2)ret.pb(x);
    vp tem;
    lli c=1;
    for(lli i=0;i<ret.size();i++){
    	if(i!=ret.size()-1 && ret[i]==ret[i+1])c++;
    	else {
    		tem.pb(mp(ret[i],c));
    		c=1;
    	}


    }
    return tem; 
} 
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli a,b;
    cin>>a>>b;
    lli x=__gcd(a,b);
    vp ani=getFactorization(x);
    cout<<ani.size()+1;




 	return 0;
 }

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

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

    int A, B;

    cin >> A >> B;

    if (A + B >= A - B && A + B >= A * B){
        cout << A + B;
    } else if (A - B >= A + B && A - B >= A * B){
        cout << A - B;
    } else {
        cout << A * B;
    }

}

Measured memory_bytes: 256
from itertools import permutations
n, m, r = map(int, input().split())
goals = list(map(int, input().split()))
goals = [g-1 for g in goals]

g = [[pow(10, 16)] * n for i in range(n)]

for i in range(m):
    a, b , c = map(int,input().split())
    a-=1; b-=1
    g[a][b] = c
    g[b][a] = c

for i in range(n):
    for s in range(n):
        for t in range(n):
            g[s][t] = min(g[s][t], g[s][i] + g[i][t])

ans = float('inf')
for p in permutations(goals):
    cost = 0
    for s,t in zip(p[:-1], p[1:]):
        cost += g[s][t]
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 74936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int array[] = new int[n];

		int val = 0;

		for (int l = 0; l < n-1; l++) {
			val = sc.nextInt();
			array[val-1] = array[val-1]+1;
		}

		for(int l:array) {
			System.out.println(l);
		}

	}


}


Measured memory_bytes: 66824
#include <algorithm>
#include <iostream> //標準入出力
#include <fstream>  //ファイルでの入出力
#include <vector>
#include <set>
#include <functional>
#include <string>
#include <utility> //pair
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define MAX 1000000
#define pair(a) pair<a,a>

ll binary_search(vector<ll>& s,ll key){
    auto isOK = [&](ll index){
        if(s[index] > key) return true;
        else return false;
    };

    ll ng=-1,ok=s.size();
    while(abs(ok-ng) > 1){
        ll mid = (ok+ng)/2;
        if(isOK(mid)) ok = mid;
        else ng = mid;
    };

    return ok;
}
void _main(){
    ll n; cin >> n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    vector<ll> atob(n),btoc(n);
    ll out = 0;
    rep(i,n)  atob[i] = binary_search(b,a[i]);
    rep(i,n)  btoc[i] = binary_search(c,b[i]);
    rep(i,n){
        for (ll j = atob[i]; j < n; j++)
        {
            out += (n-btoc[j]);
        }
    }
        
    cout << out << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

Measured memory_bytes: 6840
#include<stdio.h>
#define MAX 250

typedef struct{
  int parent;
  int right;
  int left;
}Roll;

int main(){
  int n,i;
  int Heap[MAX];
  Roll Tree[MAX];

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&Heap[i]);
  for(i=1;i<=n;i++){
    if(i!=1) Tree[i].parent=Heap[i/2];
    else Tree[i].parent=2000000001;
    if(2*i<=n) Tree[i].left=Heap[2*i];
    else Tree[i].left=2000000001;
    if(2*i+1<=n) Tree[i].right=Heap[2*i+1];
    else Tree[i].right=2000000001;
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,Heap[i]);
    if(Tree[i].parent!=2000000001)printf("parent key = %d, ",Tree[i].parent);
    if(Tree[i].left!=2000000001)printf("left key = %d, ",Tree[i].left);
    if(Tree[i].right!=2000000001)printf("right key = %d, ",Tree[i].right);
    printf("\n");
  }
  return 0;
}
  

Measured memory_bytes: 604
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = []
for i,a in enumerate(A):
    k = 0
    for c in A[i:]:
        k += c
        B.append(k)

ans = 0
for i in range(40,-1,-1):
    C = []
    for b in B:
        if b&(1<<i):
            C.append(b)
    if len(C) >= K:
        B = C
        ans += 2**i
print(ans)

Measured memory_bytes: 27696
import static java.lang.System.*;

import java.util.*;

public class Main {
	
	
	void run(){
		while(true){
			int s=sc.nextInt(),n=sc.nextInt(), t = sc.nextInt();
			String week = sc.next(), time = sc.next();
			int p = sc.nextInt(), m = sc.nextInt();
			if(s==0 && n==0 && t == 0)return;
			
			int count = 0;
			int w = 60*24*7;
			if (week.equals("All") && time.equals("All")){
				count = m;
			} else {

				if (!week.equals("All")) {
					int b;
					if (time.equals("All") || time.equals("Day")) {
						if (time.equals("All")) b = 1440;
						else b = 720;
						for (int begin = 0; begin < w; begin++) {
							int c = 0;
							for (int i = 0; i < m; i++) {
								if ((begin +i*t)%w <= b && (begin +i*t+s)%w < b) {
									c++;
								}
							}
							count = Math.max(count, c);
						}
					} else {
						b = 360;
						for (int begin = 0; begin < w; begin++) {
							int c = 0;
							for (int i = 0; i < m; i++) {
								if (((begin +i*t)%w <= b && (begin +i*t+s)%w < b) || (1080 <=(begin +i*t)%w && (begin +i*t)%w < b+1080 && (begin +i*t+s)%w < b+1080 && 1080 < (begin +i*t+s)%w)) {
									c++;
								}
							}
							count = Math.max(count, c);
						}
					}
				} else {
					int b;
					if (time.equals("All")) b = 1440;
					else b = 720;
					for (int begin = 0; begin < w; begin++) {
						int c = 0;
						for (int i = 0; i < m; i++) {
							boolean flag = false;
							for (int j = 0; j < 7; j++) {
								if (1440*j <= (begin +i*t)%w && (begin +i*t)%w < b+1440*j &&
										1440*j <= (begin +i*t+s)%w && (begin +i*t+s)%w < b+1440*j) {
									flag = true;
									break;
								}
							}
							if (flag)
								c++;
						}
						count = Math.max(count, c);
					}
				}
			}
			
			out.printf("%.10f\n", 1.0-Math.pow((double)(p-1)/p, n*count));
		}
	}
	
	public static void main(String[]_){
		new Main().run();
		out.flush();
		out.close();
	}
	
	static Scanner sc=new Scanner(in);


}

Measured memory_bytes: 22912
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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(){
    ll k,n;cin >> k >>n;
    vl p(n);
    rep(i,n)cin >> p[i];
    ll ans=INF/10;
    rep(i,n){
        if(i==0){
            ll x=min(p[n-1]-p[0],k-(p[i+1]-p[i]));
            chmin(ans,x);
        }
        if(i>0&&i<n-1){
            ll x=min(k-(p[i+1]-p[i]),k-(p[i]-p[i-1]));
            chmin(ans,x);
        }
        if(i==n-1){
            ll x=min(k-(p[i]-p[i-1]),p[i-1]-p[0]);
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 1792