akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
		while(true)
		{
			int h = scan.nextInt();
			int w = scan.nextInt();
			
			if(h == 0 && w == 0)
			{
				break;
			}
			else
			{
				new DataSet(h,w);
			}
		}
	}
	
	static class DataSet
	{
		int height;
		int width;
		int[][] grid;
		
		public DataSet(int h, int w)
		{
			height = h;
			width = w;
			
			grid = new int[width][height];
			
			for(int y = 0; y < height; y++)
			{
				for(int x = 0; x < width; x++)
				{
					grid[x][y] = scan.nextInt();
				}
			}
			
			int highestCapacity = 0;
			
			for(int pondH = 3; pondH <= height; pondH++) //including borders
			{
				for(int pondW = 3; pondW <= width; pondW++)
				{
					for(int y1 = 0; y1 <= height - pondH; y1++)
					{
						for(int x1 = 0; x1 <= width - pondW; x1++)
						{
							//Aaaand a to-be pond is set!
							
							int x2 = x1 + pondW - 1;
							int y2 = y1 + pondH - 1;
							int capacity = 0;
							boolean overflow = false;
							
							//check lowest terrain in border
							int lowborel = 100; //lowestBorderElevation
							for(int xT = x1; xT <= x2; xT++)
							{
								lowborel = Math.min(lowborel, grid[xT][y1]);
								lowborel = Math.min(lowborel, grid[xT][y2]);
							}
							for(int yT = y1+1; yT <= y2-1; yT++)
							{
								lowborel = Math.min(lowborel, grid[x1][yT]);
								lowborel = Math.min(lowborel, grid[x2][yT]);
							}
							
							//count capacity inside, quit if any inside tile is higher than
							//lowest terrain in border.
							for(int yT = y1+1; yT <= y2-1 && !overflow; yT++)
							{
								for(int xT = x1+1; xT <= x2-1 && !overflow; xT++)
								{
									int curel = grid[xT][yT];
									
									if(curel >= lowborel)
									{
										//water overflow. quit.
										capacity = 0;
										overflow = true;
									}
									else
									{
										capacity += lowborel - curel;
									}
								}
							}
							
							highestCapacity = Math.max(highestCapacity, capacity);
						}
					}
				}
			}
			System.out.println(highestCapacity);
		}
	}
}



Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
int h,w;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
char s[59][59];
bool ans=true;
signed main(){
    cin>>h>>w;
    rep(i,h)s[i][0]='.';
    rep(i,w)s[0][i]='.';
    rep(i,h){
        rep(j,w){
            cin>>s[i+1][j+1];
        }
    }
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                bool ne=false;
                rep(k,4){
                    if(s[i+dx[k]][j+dy[k]]=='#')ne=true;
                }
                if(ne==false)ans=false;
            }
        }
    }
    if(ans)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1000000007;
ll mod(ll x){
        return ((x%M + M)%M);
    }
ll add(ll a, ll b){
        return mod(mod(a)+mod(b));
    }
ll mul(ll a, ll b){
        return mod(mod(a)*mod(b));
    }
ll minu(ll a, ll b){
        return mod(mod(a)-mod(b));
    }
ll power(ll a, ll b){
    ll res=1;
    while(b>0){
        if(b&1) res=mul(res,a);
        b = b>>1;
        a=mul(a,a);
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    if(n==1){
        cout<<"0";
        return 0;
    }
    ll ans = minu(add(power(10LL,n),power(8LL,n)),mul(2LL,power(9LL,n)));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3608
a,b,k = map(int,input().split())
n = 0
def func(a,b,n):
    if n%2 == 0:
        if(a%2)==1:
            a-=1
        b += a/2
        a -= a/2
        return a,b
    else :
        if(b%2)==1:
            b-=1
        a += b/2
        b -= b/2
    return a,b
for k in range(k):
    a,b=func(a,b,n)
    n += 1
print(int(a),int(b))

Measured memory_bytes: 3064
def main():

    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = min(a) + min(b)
    for _ in range(M):
        x, y, c = map(int, input().split())
        ans = min(ans, a[x-1] + b[y-1] - c)
    return ans

if __name__ == '__main__':
    print(main())


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

using namespace std;

long long P_is_not_2_5(long long N, long long P, const string& S) {
    map<long long, long long> residual;
    residual.insert(make_pair(0LL, 1LL));
    long long pow10 = 1;
    long long curr = 0LL;
    for (long long i = N - 1; i >= 0; --i) {
        curr += pow10 * (long long)atoi(S.substr(i, 1).c_str());
        curr %= P;
        if (residual.count(curr) == 0) {
            residual.insert(make_pair(curr, 0LL));
        }
        residual[curr] += 1;
        pow10 *= 10;
        pow10 %= P;
    }
    long long ans = 0;
    for (auto it : residual) {
        long long n = it.second;
        if (n >= 2) {
            ans += n * (n - 1) / 2;
        }
    }
    return ans;
}

long long P_is_2_or_5(long long N, long long P, const string& S) {
    long long ans = 0LL;
    for (long long i = 0; i < N; ++i) {
        long long c = (long long)atoi(S.substr(i, 1).c_str());
        if (c % P == 0) {
            ans += i + 1;
        }
    }
    return ans;
}

void Main() {
    long long N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    long long ans = 0LL;
    if (P == 2LL || P == 5LL) {
        ans = P_is_2_or_5(N, P, S);
    }
    else {
        ans = P_is_not_2_5(N, P, S);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

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

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

int main() {
	int a, b; scanf("%d%d", &a, &b);

	std::string A(b, (char)(a + '0'));
	std::string B(a, (char)(b + '0'));
	
	printf("%s\n", std::min(A, B).c_str());
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int INF = 1<<29;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする



int main(){
	char w[105];
	cin>>w;
	int n=strlen(w);
	int i;
	int a[27];
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++){
		a[w[i]-'a']+=1;
	}
	int x=0;
	for(i=0;i<26;i++){
		if(a[i]%2!=0){
			 x=1;
			 break;
		}
	}
	if(x==0)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int w, n, col[31];
	scanf("%d", &w);
	scanf("%d", &n);
	for (int i = 1; i <= w; i++){
		col[i] = i;
	}
	for (int i = 0; i < n; i++){
		int a, b;
		scanf("%d,%d", &a, &b);
		int tmp = col[a];
		col[a] = col[b];
		col[b] = tmp;
	}
	for (int i = 1; i <= w; i++){
		printf("%d\n", col[i]);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N= 2e5+10, mod = 1e9+7;
int n,a,b,c,fac[N],ifac[N];
inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}

struct cp{
	double x,y;
	cp(double _x=0,double _y=0){x=_x,y=_y;}
	inline cp operator + (const cp &p)const{
		return (cp){x+p.x,y+p.y};
	} 
	inline cp operator - (const cp &p)const{
		return (cp){x-p.x,y-p.y};
	}
	inline cp operator * (const cp &p)const{
		return (cp){x*p.x-y*p.y,x*p.y+y*p.x};
	}
	inline cp operator * (const double &p)const{
		return (cp){x*p,y*p};
	}
};

const double pi=acos(-1);
vector<int>pos;
vector<cp>w;
inline int init(int n){
	int lim=1,lg=0;
	while (lim<n) lim<<=1,++lg;
	pos.resize(lim),w.resize(lim);
	FOR(i,0,lim) pos[i]=(pos[i>>1]>>1)|((i&1)<<(lg-1));
	for (int i=1;i<n;i<<=1){
		w[i]=(cp){1,0};
		FOR(j,1,i) w[i+j]=(cp){cos(j*pi/i),sin(j*pi/i)};
	}
	return lim;
}
inline void DFT(vector<cp>&a,int n){
	a.resize(n);
	FOR(i,0,n) if (i<pos[i]) swap(a[i],a[pos[i]]);
	for (int i=1;i<n;i<<=1)
		for (int j=0;j<n;j+=i<<1)
			for (int k=0;k<i;k++){
				cp x=a[j+k],y=w[i+k]*a[i+j+k];
				a[j+k]=x+y,a[i+j+k]=x-y;
			}
}
inline void IDFT(vector<cp>&a,int n){
	DFT(a,n),reverse(&a[1],&a[n]);
	FOR(i,0,n) a[i].x=a[i].x/n+0.5;
}
inline poly Mul(poly p,poly q){
	int n=siz(p),m=siz(q),mod=1e9+7;
	vector<cp>a(n),A(n),b(m),B(m);
	FOR(i,0,n){
		int x=p[i];
		a[i].x=x>>15,A[i].x=x&((1<<15)-1);
	}
	FOR(i,0,m){
		int x=q[i];
		b[i].x=x>>15,B[i].x=x&((1<<15)-1);
	}
	int lim=init(n+m);
	DFT(a,lim),DFT(A,lim),DFT(b,lim),DFT(B,lim);
	vector<cp>f(lim),g(lim),h(lim);
	FOR(i,0,lim) f[i]=a[i]*b[i],g[i]=a[i]*B[i]+A[i]*b[i],h[i]=A[i]*B[i];
	IDFT(f,lim),IDFT(g,lim),IDFT(h,lim);
	poly ans;
	FOR(i,0,n+m-1) ans.pb((((ll)(f[i].x)%mod<<30)+((ll)(g[i].x)%mod<<15)+((ll)(h[i].x)%mod))%mod);
	return ans;
}

int main(){
	n=read(),a=read(),b=read(),c=read();
	int p=1ll*a*power(a+b,mod-2)%mod,q=1ll*b*power(a+b,mod-2)%mod,r=1ll*c*power(100,mod-2)%mod;
	poly P(n+1),Q(n+1);
	fac[0]=1;
	For(i,1,2*n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[2*n]=power(fac[2*n],mod-2);
	Dow(i,2*n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	FOR(i,0,n) P[i]=1ll*power(p,i)*ifac[i]%mod;
	FOR(i,0,n) Q[i]=1ll*power(q,i)*ifac[i]%mod;
	P=Mul(P,Q);
	int ans=0;
	For(i,0,2*n-2) ans=(ans+1ll*fac[i]*P[i])%mod;
	printf("%d\n",1ll*ans*power((1-r+mod)%mod,mod-2)%mod);
}

Measured memory_bytes: 42288
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>
#include <ext/rope>

#define F1(x,y,z) for(int x=y;x<z;x++)
#define F2(x,y,z) for(int x=y;x<=z;x++)
#define F3(x,y,z) for(int x=y;x>z;x--)
#define F4(x,y,z) for(int x=y;x>=z;x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second

#define MAX 100005
#define AMAX 1500
#define MOD 1000000007

#define f(c,d) ((1<<(c))*(d))

using namespace std;
using namespace __gnu_cxx;

int n,ans;
pair<int,int> x[MAX];

int main(){
	scanf("%d",&n);
	F1(a,0,n){
		scanf("%d",&x[a].first);
		x[a].second=a;
	}
	sort(x,x+n);
	F1(a,0,n)if(a%2!=x[a].second%2)ans++;
	printf("%d\n",ans/2);
	#ifdef LOCAL_PROJECT
    system("pause");
    #endif
    return 0;
}


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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight = int;

struct Edge {
  int src, dst;
  Weight weight;
  int cost;
  Edge(int src, int dst, Weight weight, int cost = 0)
      : src(src), dst(dst), weight(weight), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, c;
  while (cin >> n >> m >> c, n) {
    vector<vector<int>> flag(n, vector<int>(m, 1e9));
    Graph g(n);
    for (int i = 0; i < m; ++i) {
      int f, t, cc;
      cin >> f >> t >> cc;
      g[f - 1].emplace_back(f - 1, t - 1, cc);
    }
    deque<Edge> q;
    for (q.emplace_back(-2, 0, 0, 0); !q.empty();) {
      Edge e = q.front();
      if (e.dst == n - 1) {
        cout << e.cost << endl;
        goto BREAK;
      }
      q.pop_front();
      for (auto ge : g[e.dst]) {
        if (flag[ge.dst][e.cost + 1] > e.weight) {
          q.emplace_back(ge.src, ge.dst, e.weight, e.cost + 1);
          flag[ge.dst][e.cost + 1] = e.weight;
        }
        if (ge.weight + e.weight > c) continue;
        if (flag[ge.dst][e.cost] > ge.weight + e.weight) {
          q.emplace_front(ge.src, ge.dst, ge.weight + e.weight, e.cost);
          flag[ge.dst][e.cost] = ge.weight + e.weight;
        }
      }
    }
    cout << "impossible" << endl;
  BREAK:;
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> number(n);
  for (int i = 0; i < n; i++) {
    cin >> number[i];
  }
  for (int j = n - 1; j >= 0; j--) {
    cout << number[j];
    if (j != 0) {
      cout << " ";
    }
  }
  cout << endl;
}


Measured memory_bytes: 3112
n, m = gets.chomp.split(" ").map(&:to_i)
max_l = 0
min_r = n + 1
m.times do |i|
  l, r = gets.chomp.split(" ").map(&:to_i)
  max_l = l if l > max_l
  min_r = r if min_r > r
end
puts [min_r - max_l + 1, 0].max


Measured memory_bytes: 1916
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = Integer.valueOf(scan.next());
        int b = Integer.valueOf(scan.next());
        int r = 0;
        while (b != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        System.out.println(a);
        scan.close();
    }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    V<int> row(300010, 0), col(300010, 0);
    map<P<ll, ll>, int> mp;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        row[x]++;
        col[y]++;
        mp[{x, y}]++;
    }

    int mr = 0, mc = 0;
    for (int i = 1; i < 300010; i++) {
        mr = max(mr, row[i]);
        mc = max(mc, col[i]);
    }

    V<int> r, c;
    for (int i = 1; i < 300010; i++) {
        if (mr == row[i]) r.push_back(i);
        if (mc == col[i]) c.push_back(i);
    }

    int ans = mr + mc - 1;
    for (auto rr : r) {
        for (auto cc : c) {
            if (!mp[{rr, cc}]) {
                cout << ans + 1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 27508
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,m,i,j,cc=0;
    cin>>n>>m;
    ll ara[n];ll bra[n];
    for(i=0;i<n;i++){cin>>ara[i],bra[i]=abs(m-ara[i]);}
    sort(bra,bra+n);
    for(i=1;i<n;i++){
        if(bra[i]%bra[0] != 0){
            cc=1;break;
        }
    }
    if(cc==1){
         for(i=bra[0];i>=2;i-=1){
                ll l=0;
            for(j=0;j<n;j++){
                if(bra[j]%i != 0){
                  l=1;  break;
                }
            }
         if(l==0){
            cout<<i<<endl;
            return 0;
         }
        }
        cout<<1<<endl;
    }
    else{
        cout<<bra[0]<<endl;
    }

return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if ( (a+b)/2 *2 < (a+b)){
    cout << (a+b)/2 +1 << endl;
  }
  else{
    cout << (a+b)/2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;  
  cin >> N;

  int sum = 0;
  int size = N.size();
  for(int i = 0; i < size; i++){

    int temp = int(N[i]) - 48;
  	sum += temp;
  }

  if(sum % 9 == 0)
	cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3720
#include <iostream>
using namespace std;
int main(){
    int n,x;
    while(1){
        cin>>n>>x;
        if(n+x==0)return 0;
        int cnt=0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(x-i-j>j&&x-i-j<=n){
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3112
import sys
import heapq
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = []
    for i in range(N):
        a, b = map(int, input().split())
        if a <= M:
            ab.append([a, b])
    ab = sorted(ab, key=lambda x: (x[0], x[1]))
    # print(ab)
    q = []
    j = 0
    ans = 0
    for i in range(M):
        # 候補の追加
        while j < len(ab):
            a, b = ab[j]
            if a <= i+1:
                heapq.heappush(q, (-b, a))
            else:
                break
            j += 1
        # 最大のものを取り出す
        if len(q) > 0:
            b, a = heapq.heappop(q)
            # print("day", M-i-1, "->", -b)
            ans += -b
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 29824
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  ll A, B;
  std::cin >> A >> B;

  if (A >= 13) print(B);
  else if (A >= 6 && A <=12) print(B/2);
  else print(0);

  return 0;
}


Measured memory_bytes: 256
from itertools import combinations

n,m,x = map(int, input().split())
a = []
c = []
for i in range(n):
    cc, *aa = map(int, input().split())
    a.append(aa)
    c.append(cc)

ans = float("inf")
q = list(range(n))
for i in range(1, n+1):
    for l in combinations(q, i):
        state = [0]*m
        score = 0
        for j in l:
            score += c[j]
            for k in range(m):
                state[k] += a[j][k]
        if all(j>=x for j in state):
            ans = min(ans, score)

if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 69080
#include <stdio.h>
#import <Foundation/Foundation.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    int A, B;
    scanf("%d %d", &A, &B);
    int result = (int)((float)(B-1) / (A-1));
    if (result < (float)(B-1) / (A-1)) {
        result ++;
    }
    printf("%d", result);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a[11451], b[11451], c[11451];
vector<int> e[11451];
vector<int> mu;
pair<int,int> ta[11451];
int ans;
int answ[11451];
bool bl[11451];

signed main() {
	cin >> n;
	rep(i, n - 1) {
		cin >> a[i] >> b[i];
		e[a[i]].push_back(b[i]);
		e[b[i]].push_back(a[i]);
		ta[a[i]] = { ta[a[i]].first + 1,a[i] };
		ta[b[i]] = { ta[b[i]].first + 1,b[i] };
	}
	rep(i, n) {
		cin >> c[i];
		mu.push_back(c[i]);
	}
	sort(all(mu));
	rep(i, mu.size() - 1) {
		ans += mu[i];
	}
	cout << ans << endl;
	sort(ta, ta + n + 1);
	queue<int> que;
	que.push( ta[n].second);
	answ[ta[n].second] = mu[n - 1];
	bl[ta[n].second] = true;
	int cnt = 1;
	while (que.size()) {
		int rin = que.front();
		que.pop();
		if (rin != ta[n].second)cnt++;
		bl[rin] = true;
		answ[rin] = mu[n - cnt];
		rep(i, e[rin].size()) {
			if (!bl[e[rin][i]]) {
				que.push(e[rin][i]);
			}
		}
	}
	rep(i, n - 1)cout << answ[i + 1] << " ";
	cout << answ[n] << endl;
}

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

int main(){
    ll n;
    cin>>n;
    ll k=3500;
    ll kw;
    bool f=false;
    for(int i=1;i<=k;i++){
        for(int j=i;j<=k;j++){
            if(4*i*j-n*j-i*n<=0) continue;
            ll w;
            if((n*i*j)%(4*i*j-n*j-i*n)==0){
                w=(n*i*j)/(4*i*j-n*j-i*n);
                cout<<i<<" "<<j<<" "<<w;
                f=true;
                break;
            }
        }
        if(f==true) break;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for(int i=0; i<N; i++) cin >> T[i];
    sort(T.begin(), T.end());

    int ans = 0;
    int cnt = 0;
    int lim = 0;
    for(int i=0; i<N; i++){
        if(T[i] > lim || cnt == C){
            cnt = 1;
            ans++;
            lim = T[i] + K;
        }else
            cnt++;
    }
    cout << ans << endl;

    return 0;
}

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

int main(void) {
	int m, n;
	int sum, sub, mul;
	int ans = -10000;

	cin >> m;
	cin >> n;

	sum = m + n;
	sub = m - n;
	mul = m * n;

	ans = max(ans, sum);
	ans = max(ans, sub);
	ans = max(ans, mul);
	
	cout << ans << '\n';

	return 0;
}

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

int main() {
        int a, b;
        cin >> a >> b;
        if ((a+b)/2 == (a+b+1)/2) {
                cout << (a+b)/2 << endl;
        } else {
                cout << (a+b+1)/2 << endl;
        }
}


Measured memory_bytes: 256
// ABC106_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    string S;
    ll K;
    cin >> S >> K;
    
    // calculation
    if (S.length() == 1) {
        cout << S << "\n";
    } else {
        ll len;
        if (S.length() >= K) len = K;
        else len = S.length();  // K が文字列よりも大きいとき
        
        REP(i, len) {
            if (S[i] != '1') {
                cout << S[i] << "\n";
                return 0;
            }
        }
        
        // 文字列に 1 以外の数字が現れなかった時
        cout << 1 << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	ll a,b,c;
	cin>>a>>b>>c;
	if(a>=b&&a>=c) {
		b*=c;
		cout<<(a-a/2)*b-a/2*b;
	} else if(b>=a&&b>=c) {
		a*=c;
		cout<<(b-b/2)*a-b/2*a;
	} else {
		b*=a;
		cout<<(c-c/2)*b-c/2*b;
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define all(a)      a.begin(),a.end()
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        100005
#define LOG         30
#define mod         1000000007
using namespace std;

vector<ll> vi[MAXN];
ll dp[MAXN];
ll vis[MAXN],deg[MAXN];


 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i,x,y,mx=0;
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>x>>y;
        vi[x].pb(y);
        deg[y]++;
    }
    queue<ll> qe;
    for(i=1;i<=n;i++){
        if(deg[i]==0){
            qe.push(i);
        }
    }
    vector<ll> vi1;
    while(!qe.empty()){
        ll node=qe.front();
        qe.pop();
        vi1.pb(node);
        for(auto x:vi[node]){
            if(!vis[x]){
                deg[x]--;
                if(deg[x]==0){
                    qe.push(x);
                }
            }
        }
    }
    for(auto j:vi1){
        for(auto x:vi[j]){
            dp[x]=max(dp[x],dp[j]+1);
        }
    }
    // for(auto x:vi1){
    //     cout<<x<<" ";
    // }
    // cout<<endl;
    for(i=1;i<=n;i++){
        mx=max(mx,dp[i]);
        //cout<<dp[i]<<" ";
    }
    cout<<mx;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	string s;
	cin >> s;
	map<char,int> ma;
	FOR(i,0,4)ma[s[i]]++;
	if(ma.size()==2&&ma[s[0]]==2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

using P = pair<int,int>;
const P INF = {-1,-1};

signed main(){

  int n,m; cin >> n >> m;
  vector<P> v;
  SegmentTree<int> segnum(vector<int>(m+1,0),0,[&](int x,int y){
    return x + y;
  });
  for(int i = 0; i < n; i++){
    int a,b; cin >> a >> b;
    if(a > m) continue;
    v.push_back({a-1,b});
    segnum.add(a-1,1);
  }
  sort(v.begin(),v.end(),[&](P x, P y){
    return x.first < y.first;
  });

  vector<P> v2;
  for(int i = 0; i < v.size(); i++){
    v2.push_back({v[i].second,i});
  }

  SegmentTree<P> seg(v2,INF,[&](P x,P y){
    return max(x,y);
  });
  int ans = 0;
  for(int i = 0; i < m; i++){
    int right = segnum.getval(0,i+1);
    P res = seg.getval(0,right);
    //cout << right << " " << res << endl;
    if(res == P(-1,-1)) continue;
    else {
      ans += res.first;
      seg.update(res.second,{-1,-1});
    }
  }
  cout << ans << endl;

  return 0;
}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  scanf("%d",&n);
  string songs[n], start_song;
  int song_length[n];
  REP(i,n) cin >> songs[i] >> song_length[i];
  cin >> start_song;
  int ans = 0;
  bool flag = false;
  REP(i,n) {
    if(flag) ans += song_length[i];
    if(songs[i] == start_song) flag = true;
  }
  cout << ans;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
// vector<int> dx={0,1,-1,0};
// vector<int> dy={1,0,0,-1};

struct edge{int to; int cost;};
vector<vector<edge>> graph(0);
vector<int> d(0);
const int MAX_dist=1e9;

void init(int n){
    graph.resize(n);
    d.resize(n,MAX_dist);
}

void dijkstra(int s){
if(d.size()==0){cout<<"You Should init"<<endl;return;}
    priority_queue<P, vector<P>, greater<P>> que;
    d[s]=0;
    que.emplace(0,s);
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,graph[v].size()){
            edge e=graph[v][i];
            if(d[e.to]>d[v]+e.cost){
            d[e.to]=d[v]+e.cost;
            que.emplace(d[e.to],e.to);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w,Ch,Cw,Dh,Dw;
    cin>>h>>w>>Ch>>Cw>>Dh>>Dw;
    Ch --;
    Cw --;
    Dh --;
    Dw --;
    vector<vector<char>> a(h,vector<char>(w));
    rep(i,h)rep(j,w) cin>>a[i][j];

    init(h*w);
    //左右に行く
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#') continue;
            if(j!=0 && a[i][j-1]=='.') graph[i*w+j].push_back({i*w+j-1,0});
            if(j!=w-1 && a[i][j+1]=='.') graph[i*w+j].push_back({i*w+j+1,0});
        }
    }
    // //上下に行く
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#') continue;
            if(i!=0 && a[i-1][j]=='.') graph[i*w+j].push_back({i*w+j-w,0});
            if(i!=h-1 && a[i+1][j]=='.') graph[i*w+j].push_back({i*w+j+w,0});
        }
    }

    rep(i,h)rep(j,w){
        if(a[i][j]=='#') continue;
        for(int k=-2;k<=2;k++){
            if(i+k<0 || i+k>=h) continue;
            for(int l=-2;l<=2;l++){
                if(k==0 && l==0) continue;
                if(j+l<0 || j+l>=w) continue;
                if(a[i+k][j+l]=='#') continue;
                graph[i*w+j].push_back({(i+k)*w+(j+l),1});
            }
        }
    }

    dijkstra(Ch*w+Cw);
    if(d[Dh*w+Dw]==MAX_dist) cout<<-1<<endl;
    else cout<<d[Dh*w+Dw]<<endl;    
    // rep(i,25) cout<<d[i]<<" ";
    // cout<<endl;
}/*
./problem.exe
*/


Measured memory_bytes: 113968
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int power(int x,int y){int ret=1;do{if(y&1)ret=1ll*ret*x%mod;x=1ll*x*x%mod;}while(y>>=1);return ret;}
int f[5111],invf[5111];

vector<int>g[5111];
int n,fa[5111],sz[5111],mx[5111];
void dfs(int x,int f=0)
{
	fa[x]=f;sz[x]=1;
	for(auto v:g[x])if(v!=f){dfs(v,x);sz[x]+=sz[v];mx[x]=max(mx[x],sz[v]);}
	mx[x]=max(mx[x],n-sz[x]);
}

int dp[5111],tsz;
void add(int v)
{
	for(int i=tsz;i>=0;i--)
	{
		for(int j=1;j<=v;j++)
			dp[i+j]=(dp[i+j]+1ll*dp[i]*f[v]%mod*invf[v-j]%mod*f[v]%mod*invf[j]%mod*invf[v-j])%mod;
	}
	tsz+=v;
}
int main()
{
	f[0]=invf[0]=1;for(int i=1;i<5111;i++){f[i]=1ll*i*f[i-1]%mod;invf[i]=power(f[i],mod-2);}
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);g[v].pb(u);
	}
	dfs(1);
	int rt=min_element(mx+1,mx+n+1)-mx;
	for(int i=1;i<=n;i++)if(mx[rt]==mx[i]&&rt!=i)
	{
		printf("%d\n",1ll*f[n/2]*f[n/2]%mod);
		return 0;
	}
	dp[0]=1;add(n-sz[rt]);
	for(auto v:g[rt])if(v!=fa[rt])add(sz[v]);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(i&1)ans=(ans-1ll*dp[i]*f[n-i]%mod+mod)%mod;
		else ans=(ans+1ll*dp[i]*f[n-i])%mod;
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin >> n;
  ll res = 0;
  map<string, int> table;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    auto it = table.find(s);
    if (it != table.end()) {
      res += it->second;
      it->second++;
    } else {
      table[s] = 1;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 11136
import numpy as np

n = int(input())
ps = list(map(float, input().split()))

dp = [np.zeros(n + 1) for _ in range(n)]

for i, p in enumerate(ps):
    if i == 0:
        dp[i][0] = 1-p
        dp[i][1] = p
    else:
        dp[i][0] = dp[i-1][0] * (1-p)
        dp[i][1:i+1] = dp[i-1][:i] * p + dp[i-1][1:i+1] * (1-p)
        dp[i][i+1] = dp[i-1][i] * p

l = dp[-1]

print(l[len(l)//2:].sum())


Measured memory_bytes: 81348
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int n;
    cin>>n;
    int h[n];
    rep(i,n)cin>>h[i];
    int ans=0;
    rep(i,n)
    {
        bool flag=true;
        rep(j,i)
        {
            if(h[i]<h[j])flag=false;
        }
        if(flag)ans++;
        
    }
    cout<<ans;

}

Measured memory_bytes: 256
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
    private static String print(List<Integer> list) {
        String result;
        result = "";
        for (int index = 0;index<list.size();index++) {
            if(index == 0) {
                result+=String.format("%d",list.get(index));
            }else{
                result+=String.format(" %d",list.get(index));
            }
        }
        return result;
    }
    private static void InsertSort(List<Integer> A,int N) {
        System.out.println(print(A));
        for(int n = 1;n<N;n++) {
            Integer v = A.get(n);
            Integer j = n - 1;
            while (j >= 0 && A.get(j) > v) {
                A.set(j + 1, A.get(j));
                j--;
                A.set(j + 1, v);
            }
            System.out.println(print(A));
        }
    }
    public static void main(String[] args) {
        List<Integer> IntList = new ArrayList<Integer>();
        Scanner sc;
        sc = new Scanner(System.in);

        int n = sc.nextInt();

        for(int i =0;i<n;i++) {
            IntList.add(Integer.parseInt(sc.next()));
        }

        InsertSort(IntList,n);


    }
}


Measured memory_bytes: 56684
#include<iostream>
using namespace std;
int main(){
    int x,n,min;
    int c=0;
    cin >> n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i;j<n;j++){
            if(b[j]<b[min]){
                min=j;
            }
        }
        if(min!=i){
            x=b[i];
            b[i]=b[min];
            b[min]=x;
            c++;
        }
            
    }for(int i=0;i<n;i++){
        cout << b[i];
        if(i!=n-1)cout <<" ";
    }
    cout << endl << c << endl;
}


Measured memory_bytes: 3092
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	n := nextInt()
	a := nextInts(n)
	a = append([]int{0}, a...)
	num := make([]int, n+1)
	val := make([]int, n+1)
	var top, ans, sum int
	for i := 1; i <= n; i++ {
		now := 1
		for a[i] <= val[top] {
			sum -= num[top] * val[top]
			now += num[top]
			top--
		}
		sum += now * a[i]
		top++
		num[top] = now
		val[top] = a[i]
		ans += sum
	}
	fmt.Println(ans)
}

// need use h := &IntHeap{}, heap.Push(h, n) and heap.Pop(h)
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}
func (h *IntHeap) erase(x int) bool {
	for i := 0; i < h.Len(); i++ {
		if (*h)[i] == x {
			heap.Remove(h, i)
			return true
		}
	}
	return false
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[i].b
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define Fr(i, x, y) for (int i = (x); i < (y); ++i)
using namespace std;
typedef long long ll;

const int N = 200000 + 5;
int n, a[N], b[N], nd[N];
struct node {
	int bmx, bmn, rmx, rmn;
	node() { bmx = rmx = 0xcfcfcfcf; bmn = rmn = 0x3f3f3f3f; }
	void reset() {  bmx = rmx = 0xcfcfcfcf; bmn = rmn = 0x3f3f3f3f; }
	void add(int x, int y) {
		bmx = max(bmx, x);
		bmn = min(bmn, x);
		rmx = max(rmx, y);
		rmn = min(rmn, y); 
	}
	ll get() { return (ll)(bmx - bmn) * (rmx - rmn); }
}chance[N][41];

ll solve() {
	F(i, 1, n) {
		for (int k = 1; k <= 5; ++k) chance[i][k].reset();
		int t =  nd[i];
		F(j, 1, 5) {
			node cp = chance[i - 1][j];
			cp.add(a[t], b[t]);
			for (int k = 5; k >= 1; --k)
				if (chance[i][k].get() > cp.get()) {
					for (int lst = 1; lst < k; ++lst) chance[i][lst] = chance[i][lst + 1];
					chance[i][k] = cp;
					break;
				}
			cp = chance[i - 1][j];
			cp.add(b[t], a[t]);
			for (int k = 5; k >= 1; --k)
				if (chance[i][k].get() > cp.get()) {
					for (int lst = 1; lst < k; ++lst) chance[i][lst] = chance[i][lst + 1];
					chance[i][k] = cp;
					break;
				}
		}
	}
	
	ll ans = 0x3f3f3f3f3f3f3f3fll;
	for (int i = 1; i <= 5; ++i) ans = min(ans, chance[n][i].get());
	return ans;
}
int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	F(i, 1, n) {
		cin >> a[i] >> b[i];
		nd[i] = i;
	}
	ll ans = 0x3f3f3f3f3f3f3f3fll;
	F(k, 1, 30) {
		random_shuffle(nd + 1, nd + n + 1);
		ans = min(ans, solve());
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 134100
def argsort(a):
    return list(map(lambda z: z[1], sorted(zip(a, range(len(a))))))

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

a = argsort(P)
left = [i for i in range(N)]
right = [i for i in range(N)]
result = 0
for i in range(1, N):
    k = a[i - 1]
    extend_left = k - 1 >= 0 and P[k - 1] < i
    extend_right = k + 1 < N and P[k + 1] < i
    if extend_left and extend_right:
        L = left[k - 1]
        R = right[k + 1]
    elif extend_left:
        L = left[k - 1]
        R = k
    elif extend_right:
        R = right[k + 1]
        L = k
    else:
        L = k
        R = k
    right[L] = R
    left[R] = L
    if L - 1 >= 0:
        if L - 2 >= 0 and P[L - 2] < i:
            LL = left[L - 2]
        else:
            LL = L - 1
        result += ((L - 1) - LL + 1) * (R - k + 1) * i;
    if R + 1 < N:
        if R + 2 < N and P[R + 2] < i:
            RR = right[R + 2]
        else:
            RR = R + 1
        result += (RR - (R + 1) + 1) * (k - L + 1) * i;
print(result)

Measured memory_bytes: 24036
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	H, W = map(int, input().split(" "))
	A = []
	for _ in range(H):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		A.append(tmp)
	
	ans = []
	for i, val in enumerate(A):
		if i != len(A)-1:
			for j, vol in enumerate(val):
				if vol % 2 == 1:
					A[i][j] -= 1
					A[i+1][j] += 1
					tmp = "{} {} {} {}".format(i+1, j+1, i+2, j+1)
					ans.append(tmp)
		else:
			for j, vol in enumerate(val):
				if vol % 2 == 1:
					if j != len(A[i])-1:
						A[i][j] -= 1
						A[i][j+1] += 1
						tmp = "{} {} {} {}".format(i+1, j+1, i+1, j+2)
						ans.append(tmp)
		
	print(len(ans))
	for i in ans:
		print(i)
		
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 16620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        int n,x;
        cin>>n>>x;
        if(n==0&&x==0) return 0;
        ll ans=0;
        rep1(i,n)rep1(j,n)rep1(k,n){
            if(i!=j&&j!=k&&k!=i&&i+j+k==x) ans++;
        }
        cout<<ans/6<<"\n";
    }
}


Measured memory_bytes: 3232
using System;

class Program
{
  public static void Main(string[] args)
  {
    int[] num = new int[2];
    string[] tmp = Console.ReadLine().Split(' ');
    for(int i = 0;i < 2;i++){
      num[i] = int.Parse(tmp[i]);
    }
    Console.WriteLine("{0} {1}",num[0]*num[1],2*(num[0]+num[1]));
  }
}

Measured memory_bytes: 9140
#include<algorithm>
#include<cstdio>
#define LL long long
using namespace std;
int n,sl,fh,a[20];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void chkmin(LL &x,LL y) {if(y<x) x=y;}
LL dfs(int l,int r,int x,int y)
{
	if(r-l<=1) return 0;
	LL res=1e18;
	for(int i=l+1;i<r;++i)
		chkmin(res,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+1ll*a[i]*(x+y));
	return res;
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	printf("%lld\n",a[1]+a[n]+dfs(1,n,1,1));
	return 0;
}

Measured memory_bytes: 128