akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <fstream>

using namespace std;
typedef pair<int,int> pii;


int h,w,s;
pii dp[32][32][32][32];
int field[32][32];
int sumTbl[32][32];
int fSum[32][32][32][32];
int allSum;

pii dfs(int minx,int miny,int maxx,int maxy){
	if(dp[minx][miny][maxx][maxy].first!=-1)return dp[minx][miny][maxx][maxy];
	int sum=fSum[minx][miny][maxx][maxy];
	// »ÝÌé`Ìùva
//	for(int i=miny;i<=maxy;i++){
//		if(minx==0)sum+=sumTbl[i][maxx];
//		else sum+=sumTbl[i][maxx]-sumTbl[i][minx-1];
//	}
	//sum=fSum[minx][miny][maxx][maxy];
	pii res(1,sum);
	// yÌÇ±©Åª
	for(int i=miny;i<maxy;i++){
		// ªµ½ç»ê¼êÌÌæÌaðßA»ê¼êÌaªðð½·©²×é
		int sum1=fSum[minx][miny][maxx][i];
		int sum2=fSum[minx][i+1][maxx][maxy];
//		for(int j=miny;j<=i;j++){
//			if(minx==0)sum1+=sumTbl[j][maxx];
//			else sum1+=sumTbl[j][maxx]-sumTbl[j][minx-1];
//		}
//		for(int j=i+1;j<=maxy;j++){
//			if(minx==0)sum2+=sumTbl[j][maxx];
//			else sum2+=sumTbl[j][maxx]-sumTbl[j][minx-1];
//		}
		// ðð½·
		if(allSum-sum1<=s&&allSum-sum2<=s){
			// »ê¼êÌßèlðæ¾
			pii p1=dfs(minx,miny,maxx,i);
			pii p2=dfs(minx,i+1,maxx,maxy);
			if(res.first<p1.first+p2.first){
				res.first=p1.first+p2.first;
				res.second=min(p1.second,p2.second);
			}
			else if(res.first==p1.first+p2.first)
				res.second=max(res.second,min(p1.second,p2.second));
		}
	}
	for(int i=minx;i<maxx;i++){
		// ªµ½ç»ê¼êÌÌæÌaðßA»ê¼êÌaªðð½·©²×é
		int sum1=fSum[minx][miny][i][maxy];
		int sum2=fSum[i+1][miny][maxx][maxy];
//		int sum1=0;
//		int sum2=0;
//		for(int j=miny;j<=maxy;j++){
//			if(minx==0)sum1+=sumTbl[j][i];
//			else sum1+=sumTbl[j][i]-sumTbl[j][minx-1];
//		}
//		for(int j=miny;j<=maxy;j++)sum2+=sumTbl[j][maxx]-sumTbl[j][i];
		// ðð½·
		if(allSum-sum1<=s&&allSum-sum2<=s){
			// »ê¼êÌßèlðæ¾
			pii p1=dfs(minx,miny,i,maxy);
			pii p2=dfs(i+1,miny,maxx,maxy);
			if(res.first<p1.first+p2.first){
				res.first=p1.first+p2.first;
				res.second=min(p1.second,p2.second);
			}
			else if(res.first==p1.first+p2.first)
				res.second=max(res.second,min(p1.second,p2.second));
		}
	}
	return dp[minx][miny][maxx][maxy]=res;
}

int main(){
	while(cin>>h>>w>>s&&(h|w|s)){
		allSum=0;
		for(int i=0;i<32;i++)
			for(int j=0;j<32;j++)
				for(int k=0;k<32;k++)
					for(int l=0;l<32;l++)dp[i][j][k][l].first=dp[i][j][k][l].second=-1;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>field[i][j];
				allSum+=field[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(j==0)sumTbl[i][j]=field[i][j];
				else sumTbl[i][j]=sumTbl[i][j-1]+field[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=i;k<h;k++){
					for(int l=j;l<w;l++){
						fSum[j][i][l][k]=0;
						// s²ÆÉÁZ
						for(int m=i;m<=k;m++){
							if(j!=0)fSum[j][i][l][k]+=sumTbl[m][l]-sumTbl[m][j-1];
							else fSum[j][i][l][k]+=sumTbl[m][l];
						}
					}
				}
			}
		}

		pii res=dfs(0,0,w-1,h-1);
		cout<<res.first<<" "<<s-(allSum-res.second)<<endl;
	}
	return 0;
}

Measured memory_bytes: 12000
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

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


    int a;
    cin >> a;
    int mx = 0;
    int cur = a;
    int first = a;
    repeat(i, n - 1) {
        cin >> a;
        mx = max(mx, a - cur);
        cur = a;
    }

    mx = max(mx, k - cur + first);

    cout << k - mx;
    
    return 0;
}


Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		int cnt = 0;
		char last = 'x';
		for (char c : S.toCharArray()) {
			if (c != last) {
				cnt++;
			}
			last = c;
		}

		System.out.println(cnt - 1);
	}
}


Measured memory_bytes: 13264
#include<bits/stdc++.h>
#define MAXV 100010
#define MAXLV 20
using namespace std;

vector<int> e[MAXV];
int n,root=0;

int parent[MAXLV][MAXV];
int depth[MAXV];

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<e[v].size();i++){
    if(e[v][i]!=p)dfs(e[v][i],v,d+1);
  }
}

void init(){
  dfs(root,-1,0);
  for(int k=0;k+1<MAXLV;k++){
    for(int v=0;v<n;v++){
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
    }
  }
}

int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAXLV;k++){
    if((depth[v]-depth[u])>>k&1){
      v=parent[k][v];
    }
  }
  if(u==v)return u;
  for(int k=MAXLV-1;k>=0;k--){
    if(parent[k][u]!=parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  }
  return parent[0][u];
}

int main()
{
  int q,u,v,k,c;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>c;
      e[i].push_back(c);
    }
  }
  init();
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>u>>v;
    cout<<lca(u,v)<<endl;
  }
  return 0;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  string s[h];
  for (int i = 0; cin >> s[i]; ++i) {
  }
  int result = h * w;
  for (int i = 0; i < 1 << (h - 1); ++i) {
    bitset<32> bits(i);
    int current = 0, block[h], count[h] = {};
    for (int j = 0, k = 0; j < h; ++j) {
      block[j] = k;
      if (bits[j]) {
        ++current;
        ++k;
      }
    }
    for (int c = 0; c < w; ++c) {
      for (int r = 0; r < h; ++r) {
        count[block[r]] += s[r][c] - '0';
      }
      for (int r = 0; r < h; ++r) {
        if (count[r] > k) {
          ++current;
          fill(count, count + h, 0);
          for (int r = 0; r < h; ++r) {
            count[block[r]] += s[r][c] - '0';
          }
          break;
        }
      }
      for (int r = 0; r < h; ++r) {
        if (count[r] > k) {
          current = h * w;
        }
      }
    }
    result = min(result, current);
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 256
# Grand Garden
N = int(input().strip())
h = list(map(int, input().strip().split()))

def mizu(h, s):
	for k in range(s, len(h)):
		if h[k] > 0:
			h[k] -= 1
		else:
			break
	return h
	
def find_start(h):
	s = 0
	for k in range(len(h)):
		if h[k] > 0:
			s = k
			break
	return s

def is_finish(h):
	if sum(h) == 0:
		return True
	else:
		return False

count = 0
while True:
	if is_finish(h):
		break
	s = find_start(h)
	h = mizu(h, s)
	count += 1

print(count)

Measured memory_bytes: 3064
s = input()

n = len(s)

strong = True
for i in range(n//2):
    if s[i] != s[n-1-i]:
        strong = False
        break

if strong:
    for i in range(((n-1)//2)//2):
        if s[i] != s[(n-1)//2-1-i]:
            strong = False
            break

if strong:
    for i in range(n):
        l = ((n+3)//2-1)+i
        r = n-1-i
        if l < r:
            if s[l] != s[r]:
                strong = False
                break
        else:
            break

if strong:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
// In The Name Of God

#include<bits/stdc++.h>
#define rep(I,Q) for(int I=1;I<=(Q);I++)
#define err(I)   cerr<<#I<<" : "<<I<<"\n"
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5+22 ;

int n;

ll f(ll x,ll y)
{
	if(x%3==0) return 0;
	ll r=y;
	for(int i=1;i<=x;i++)
	{
		ll e1=i*y,e2,e3,mx,mn;
		e2=(y/2)*(x-i);
		e3=((y+1)/2)*(x-i);
		mx=max(e1,max(e2,e3));
		mn=min(e1,min(e2,e3));
		r=min(r,mx-mn);
	}
	return r;
}


int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll H,W;
	cin>>H>>W;
	ll r=f(H,W);
	r=min(r,f(W,H));
	cout<<r;

	 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    string T;
    cin>>S>>T;
    N = S.size(); M = T.size();
    ll ans = M;
    rep(i, N - M + 1){
        ll temp = 0;
        rep(j, M) temp += S[i + j] != T[j];
        ans = min(ans, temp);
    }
    cout<<ans<<endl;
}

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

struct Vector{
	double x,y,z;
	Vector(double x,double y,double z):x(x),y(y),z(z){}
};

double norm(Vector v){
	return v.x*v.x+v.y*v.y+v.z*v.z;
}
double abs(Vector v){
	return sqrt(norm(v));
}

Vector operator-(Vector a,Vector b){
	return Vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y+a.z*b.z;
}
double cross(Vector a,Vector b){
	return abs(Vector(a.x*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x));
}

int main(){
	double m,t;cin>>m>>t;t*=60;
	m=m/180*M_PI;
	double speed=2*M_PI/2500000;
	double speed2=2*M_PI/7200;
	double R=380000,r=1900;
	double cnt=0;
	for(int i=0;i<t;i++){
		double theta=m+speed*i;
		double theta2=(M_PI/2)+speed2*i;
		double Ex=0,Ey=0,Ez=0;
		double Mx=R*cos(theta),My=R*sin(theta),Mz=0;
		double Kx=Mx+r*cos(theta2),Ky=My,Kz=r*sin(theta2);
		Vector E(Ex,Ey,Ez),M(Mx,My,Mz),K(Kx,Ky,Kz);
		if(dot(E-K,M-K)<0)continue;
		double dist=abs(cross(K-E,M-E)/abs(K-E));
		if(dist<=1800){
			cnt+=1;
		}
	}
	printf("%.5lf\n",cnt/60);
}



Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;


int main(void){
    ll N;
    cin>>N;
    vector<ll> d(N);
    rep(i,N) cin>>d.at(i);
    sort(d.begin(),d.end());
    cout<<d.at(N/2)-d.at(N/2-1)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#define N 10000

int is_prime(int x)
{
    int flag = 1; 
    int t = (int)sqrt(x)+1;
    for (int i = 2; i < t; i++)
    {
        if (!(x%i)) 
        {
            flag = 0;break;
        }
    }
    return flag;
}
int main()
{
    int n;
    int a[N];
    int cnt = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a+i);
        cnt += is_prime(a[i]);
    }
    printf("%d\n", cnt);
    return 0;

}



Measured memory_bytes: 2696
n, l = (int(_) for _ in input().split())
mi = 100000
ans = 0

for i in range(n):
    fla = l + i
    if abs(fla) < mi:
        minus = False
        mi = abs(fla)
        if abs(fla) != fla:
            minus = True
    ans += fla

if ans < 0:
    if minus:
        print(ans + mi)
    else:
        print(ans - mi)
else:
    print(ans - mi)

    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int L;
  cin >> L;
  double v = pow(L,3);
  double ans;
  ans = double(v/27);
  cout << fixed << setprecision(10);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
def main():

    h,w = map(int,input().split())
    l = [list(input()) for i in range(h)]

    c1 = [[0 for i in range(w)] for i in range(h)]
    c2 = [[0 for i in range(w)] for i in range(h)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if c1[i][j] == 0:
                n = 0
                k = i
                while k < h:
                    if l[k][j] == ".":
                        n +=1
                        k += 1
                    else:
                        break
                for r in range(i,k):
                    c1[r][j] = n
                
            if c2[i][j] == 0:
                n = 0
                k = j
                while k < w:
                    if l[i][k] == ".":
                        n +=1
                        k += 1
                    else:
                        break
                for r in range(j,k):
                    c2[i][r] = n


            ans = max(ans,c1[i][j]+c2[i][j])
    print(ans-1)
if __name__ == "__main__":
    main()

Measured memory_bytes: 251656
#include<stdio.h>
int main()
{
    int a,b,h;
    int r;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&h);
    if(h%2==0)
    {
        r = (a+b)*(h/2);
        if(a==b && b==h && a==h)
        {
            printf("%d\n",r);
            //printf("In this case, a parallelogram is given, which is also a trapezoid.\n");

        }
        else
        {
            printf("%d\n",r);
            //printf("When the lengths of the upper base, lower base, and height are %d, %d,and %d, respectively, the area of the trapezoid is (%d+%d)*%d/2=%d\n",a,b,h,a,b,h,r);

        }


    }
    else
        printf("Enter an even number.\n");


}


Measured memory_bytes: 128
N = int(input())
C = [-1]
for _ in range(N):
  a = int(input())
  s = 0
  t = len(C) - 1
  if a > C[0]:
    C[0] = a
    continue
  if C[-1] >= a:
    C.append(a)
    continue
  while t - s > 1:
    m = (t + s) // 2
    if a > C[m]:
      t = m
    else:
      s = m
  C[t] = a
print(len(C))

Measured memory_bytes: 7064
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int r = sc.nextInt();
		if(r < 1200) {
			System.out.println("ABC");
		}else if(r < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    string S = in<string>();
    int now = 0;
    int maxa = 0;
    REP(i,N){
        if(S[i] == 'I'){
            now++;
        }else{
            now--;
        }
        maxa = max(now,maxa);
    }
    cout << maxa << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
bool ans[200];
int main()
{  fast

int n,k;
cin>>n>>k;
for(int i=0;i<k;i++)
{
	int x;
	cin>>x;
	while(x--)
	{
		int y;
		cin>>y;
		ans[y]=true;
	}
}
int cnt=0;
for(int i=1;i<=n;i++)
if(!ans[i])
cnt++;
cout<<cnt;
}


Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

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

 
    private void cal() throws IOException 
    {
	st = new StringTokenizer(br.readLine());
	int a = Integer.parseInt(st.nextToken());
	int b = Integer.parseInt(st.nextToken());

	int x, y;
	if ( a > b ) {
	    x = a; y = b;
	} else {
	    x = b; y = a;
	}

	while( y > 0 ) {
	    int temp = x;
	    x = y;
	    y = temp % y;
	}

	System.out.println(x);

	
	

    }

}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    vector<P> pairs(M);
    rep(i, N) cin >> A[i];
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(b, a);
    }
    sort(A.begin(), A.end());
    sort(pairs.begin(), pairs.end(), greater<P>());
    int cur = 0;
    rep(i, M) {
        int r = pairs[i].second;
        while(r && cur < N && A[cur] < pairs[i].first) {
            A[cur] = pairs[i].first;
            --r;
            ++cur;
        }
    }
    int64 ans = accumulate(A.begin(), A.end(), 0LL);
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int ans = 0;
    for(int i=1, p=0, x;i<=n;i++){
        scanf("%d",&x);
        if(x>=p){
            ans++;
            p=x;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<4;i++){
        switch(s[i]){
            case '+': 
                ans++;
                break;
            case '-':
                ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N=int(input())
H=list(map(int,input().split()))

for i in range(N-1,1,-1):
    if H[i-1]-1 > H[i]:
        print("No")
        sys.exit(0)
    if H[i-1]-1 == H[i]:
        H[i-1]=H[i-1]-1

print("Yes")
        

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 1e5 + 3;
ll dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    int n,c,w,v; cin >> n >> c;
    ll ans = 0;

    for(int i = 0; i < n; i++) {
        cin >> w >> v;
        for(int j = c; j-w >= 0; j--) {
            dp[j] = max(dp[j], dp[j-w] + v);
            ans = max(ans,dp[j]);
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size
        self.total = 0

    def add(self, i, w):
        x = i + 1
        self.total += w
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res


def inv_cnt(seq):
    n = len(seq)
    bit = BIT(n)
    cnt = 0
    for i in range(n - 1, -1, -1):
        cnt += bit.sum(seq[i] - 1)
        bit.add(seq[i], 1)
    return cnt


n = I()
A = LI()
B = LI()
ans = INF
for odd_ind in combinations(range(n), n // 2):
    even_ind = set(range(n)) - set(odd_ind)
    odd_list = []
    even_list = []
    whole_num_list = []
    whole_idx_list = []
    for i in odd_ind:
        if i % 2:
            odd_list += [(A[i], i)]
        else:
            odd_list += [(B[i], i)]
    for j in even_ind:
        if j % 2:
            even_list += [(B[j], j)]
        else:
            even_list += [(A[j], j)]
    even_list.sort(reverse=1)
    odd_list.sort(reverse=1)
    while even_list or odd_list:
        x, idx = even_list.pop()
        whole_num_list += [x]
        whole_idx_list += [idx]
        if odd_list:
            x, idx = odd_list.pop()
            whole_num_list += [x]
            whole_idx_list += [idx]
    if whole_num_list == sorted(whole_num_list):
        ans = min(ans, inv_cnt(whole_idx_list))

if ans == INF:
    print(-1)
else:
    print(ans)




Measured memory_bytes: 49372
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int x;cin >> x;
    if(x == 0)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

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

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

		String aa = sc.next();
		int N = Integer.parseInt(aa);

		String bb = sc.next();
		int L = Integer.parseInt(bb);

		String[] S = new String[N];
		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
		}
		
		Arrays.sort(S);
		
		for (int i = 0; i < N; i++) {
			System.out.print(S[i]);
		}
		
	}

}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A*B <= C*D) {
    cout << C*D;
  }
  else if (A*B > C*D) {
    cout << A*B;
  }

  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
}



int main() {

    IO; 
	
  	ll n;
    cin>>n;
    vector<ll> a(n+1);
    a[0]=0;
    map<ll,ll> m;
    for(ll i=0;i<n;i++){
        cin>>a[i+1];
        m[a[i+1]]++;
    }
    
    
    if(n%2){
        if(m[0]!=1){
            cout<<0<<endl;
            return 0;
        }
    }
    m.erase(0);
    bool flag=true;
    ll limit=0;
    if(n%2){
        limit=2;
    }
    else{
        limit=1;
    }
    for(ll i=limit;i<=n-1;i+=2){
        if(m[i]!=2){
            flag=false;
            break;
        }
    }
    if(!flag){
        cout<<0<<endl;
        return 0;
    }
    ll cnt=0;
    cnt=m.size();
    ll ans=1;
    for(ll i=1;i<=n/2;i++){
        ans*=2;
        ans%=mod;
    }
    cout<<ans<<endl;

}

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

int n;

int main(){
    scanf("%d",&n);
    int flag=0;
    for(int i=0;i<=n/4;i++)if(!((n-i*4)%7))flag=1;
    if(flag)printf("Yes");else printf("No");
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= a + k - 1; i++) {
		if (i <= b) cout << i << endl;
	}
	for (int i = b - k + 1; i <= b; i++) {
		if (i > a + k - 1) cout << i << endl;
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"

	//"math/rand"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	t := intSliceScanner(d)
	for i, _ := range t {
		t[i]--
	}
	calcScore(t, c, s, d)
}
func calcScore(schedule []int, c []int, s [][]int, d int) {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
		fmt.Println(score)
	}
	//return score
}


Measured memory_bytes: 1924
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll dp[3][111];
ll N;
ll a[3][111];

int main(void) {
    ll i, j;
    cin >> N;
    
    for(i=1; i<=2; i++) {
        for(j=1; j<=N; j++) {
            cin >> a[i][j];
        }
    }
    
    for(i=1; i<=2; i++) {
        for(j=1; j<=N; j++) {
            dp[i][j]=a[i][j]+max(dp[i-1][j], dp[i][j-1]);
        }
    }
    
    pr(dp[2][N]);
    
}















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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<string> ls;
    set<string> used;
    for(int i=0;i<s.size();i++){
        string t;
        for(int j=0;j+i<s.size()&&j<k;j++){
            t += s[i+j];
            if(!used.count(t)){
                ls.push_back(t);
                used.insert(t);
            }
        }
    }
    sort(ls.begin(),ls.end());
    cout << ls[k-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;
    N = S.size();
    ll ans1=0,ans2=0;
    rep(i,N){
        if(i%2 == 0){
            if(S[i]=='0'){
                ans1++;
            }
        }else{
            if(S[i]=='1'){
                ans1++;
            }
        }
    }

    rep(i,N){
        if(i%2 == 0){
            if(S[i]=='1'){
                ans2++;
            }
        }else{
            if(S[i]=='0'){
                ans2++;
            }
        }
    }
    
    cout << min(ans1,ans2) << endl;


    return 0;
    

}

Measured memory_bytes: 3772
def main():
    N,M = map(int, input().split())
    AB = []
    for i in range(N):
        A,B =  map(int, input().split())
        AB.append((A,B))
    AB.sort()
    coin = 0

    for i in range(N):
        temp = min(M,AB[i][1])
        coin += temp * AB[i][0]
        M -= temp
        if M==0:
            break


    print(coin)


if __name__ == '__main__':
    main()



Measured memory_bytes: 79120
import math

inputdata = input().split()
datax1 = float(inputdata[0])
datax2 = float(inputdata[2])
datay1 = float(inputdata[1])
datay2 = float(inputdata[3])

print( math.sqrt( math.pow(datax2-datax1,2) + math.pow(datay2 - datay1,2)))


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c;
  d=max(a,max(b,c));
  e=min(a,min(b,c));
  f=a+b+c-d-e;
  cout << abs(d-f)+abs(f-e) << endl;
}
    


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import numpy as np

MOD = 10**9 + 7

N,M = map(int,input().split())
S = np.array(list(input().rstrip()),dtype='U1')
LR = [[int(x) for x in input().split()] for _ in range(M)]

cnt_0 = (S=='0').cumsum()
cnt_1 = (S=='1').cumsum()
canuse_0 = cnt_0
canuse_1 = cnt_1
for L,R in LR:
    canuse_0[L-1] = max(canuse_0[L-1],cnt_0[R-1])
    canuse_1[L-1] = max(canuse_1[L-1],cnt_1[R-1])
np.maximum.accumulate(canuse_0,out=canuse_0)
np.maximum.accumulate(canuse_1,out=canuse_1)

# 1を使った個数で
dp = np.zeros(N+1,dtype=np.int64)
dp[0] = 1
for i in range(N):
    prev = dp
    dp = np.zeros(N+1,dtype=np.int64)
    # i番目を置いた後で、1の個数の範囲
    left = max(0,(i+1)-canuse_0[i])
    right = canuse_1[i]
    # 0を使う
    dp[left:right+1] += prev[left:right+1]
    # 1を使う
    left = max(1,left)
    dp[left:right+1] += prev[left-1:right]
    dp %= MOD

answer = dp.sum()
print(answer)

Measured memory_bytes: 12936
N=int(input())
A=list(map(int,input().split()))
B=[-1*A[i]+(i+1) for i in range(N)]
C=[A[i]+(i+1) for i in range(N)]
b={}
c={}
for i in range(N):
    if B[i] in b:
        b[B[i]]+=1
    else:
        b[B[i]]=1
for i in range(N):
    if C[i] in c:
        c[C[i]]+=1
    else:
        c[C[i]]=1
ans=0
for k in c.keys():
    if k in b:
        if k==0:
            a0+=1
        else:
            ans+=b[k]*c[k]
print(ans)

Measured memory_bytes: 63052
#include <algorithm>
#include <cmath>
#include<stdio.h>
#include <functional>
#include <fstream>
#include <limits>
#include <sstream>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include<map>
using namespace std;
using ll = long long;
const int N = 1000005;
long long a[N],b[N],dp[N][4],c[N],n,k;
long long solve(int i,int cant){     
     if(dp[i][cant]!=-1)return dp[i][cant];
     if(i==n)return 0;
     if(cant==0){
            long long h=max(solve(i+1,3)+a[i],solve(i+1,1)+b[i]);
            dp[i][cant]=max(h,solve(i+1,2)+c[i]);
           
     }
     else if(cant==3)  dp[i][cant]=max(solve(i+1,1)+b[i],solve(i+1,2)+c[i]);
     else if(cant==1) dp[i][cant]=max(solve(i+1,3)+a[i],solve(i+1,2)+c[i]);
     else  dp[i][cant]=max(solve(i+1,3)+a[i],solve(i+1,1)+b[i]);
     return dp[i][cant];
      
       
}
int main(){
        #ifdef MANSOUR
        freopen("input.txt", "r", stdin);
        #endif
       cin>>n;
        for (int i = 0; i < N; ++i)
        {
                for (int j = 0; j< 4; ++j)
                {
                        dp[i][j]=-1;
                }
        }
       for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
        cout<<solve(0,0);




}

Measured memory_bytes: 44672
#include<cstdio>
int h,w,a,b;
int main() {
	scanf("%d %d %d %d",&h,&w,&a,&b);
	for(int i=1;i<=h;i++,puts(""))
		for(int j=1;j<=w;j++)
			printf("%d",(i<=b)^(j<=a));
	return 0;
}


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

#define int int64_t
#define loop(i,s,e) for(int i=s;i<e;++i)
#define vi vector<int>
#define pb push_back
#define max(x,y) ((x>y)?x:y)
#define min(x,y) ((x>y)?y:x)

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	if(a == 0) cout << 1;
	if(b == 0) cout << 2;
	if(c == 0) cout << 3;
	if(d == 0) cout << 4;
	if(e == 0) cout << 5;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3604
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    i=bisect.bisect_right(S,x)
    j=bisect.bisect_right(T,x)
    d=INF
    for s in [S[i-1],S[i]]:
        for t in [T[j-1],T[j]]:
            d1=abs(s-x)+abs(s-t)
            d2=abs(t-x)+abs(s-t)
            d=min(d,d1,d2)
    print(d)

Measured memory_bytes: 12804
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <set> 
#define maxn 2000005
typedef long long ll;
using namespace std;
int arr[maxn];
int main()
{
    int k,x;
    scanf("%d%d",&k,&x);
    for(int i=max(x-k+1,-1000000);i<=min(1000000,x+k-1);i++)
    	printf("%d ",i);
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    if (r<=x&&r<=y&&w-r>=x&&h-r>=y) System.out.println("Yes");
    else System.out.println("No");
  }
}


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

typedef pair<int, int> ii;
typedef long long ll;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    long long ans = 0;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        ans -= 1LL * min(u, v) * (n - max(u, v) + 1);
    }
    #ifdef DEBUG
    cout << ans << "\n";
    #endif
    for(int l = 1; l <= n;l ++){
        ans += 1LL * (n - l + 1) * (n - l  + 2) / 2;
    }
    cout << ans;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][]data = new int[N+1][N+1];
		int[][]judge = new int[N+1][N+1];
		int inf = 21001;
		for(int i = 0 ; i<N+1; i++){
			for(int j = 0 ; j<N+1; j++){
				if(i == j)data[i][j] = 0;
				else{
					data[i][j] = inf;
					judge[i][j] = inf;
				}
				
			}
		}
		for(int i = 0 ; i<M; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			data[l][r] = v;
			data[r][l] = v;
			judge[r][l] = v;
			judge[l][r] = v;
		}		
		for(int k = 1; k<=N; k++){
			for(int i = 1; i<=N; i++){
				for(int j = 1; j<=N; j++){
					judge[i][j] = Math.min(judge[i][k] + judge[k][j] , judge[i][j]);
				}
			}
		}
		long res = 0;
		for(int i = 1; i<=N; i++){
			for(int j = i; j<=N; j++){
				if(judge[i][j] != data[i][j] && data[i][j] != inf)res++;
	//			System.out.print(judge[i][j]);
			}
		//	System.out.println();
		}
		
	/*	for(int i = 0 ; i<N+1; i++){
			System.out.println(Arrays.toString(data[i]));
		}
		System.out.println("- - - - - - - - - - -");
		for(int i = 0 ; i<N+1; i++){
			System.out.println(Arrays.toString(judge[i]));
		}*/
		
		System.out.println(res);
	}
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    int res=0;
    for(int i=0;i<k;i++) res+=a[i];
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
 
int main(){
  int n,x,ans=0,i,j,k;
  while(1){
    scanf("%d %d",&n,&x);
    if(n==0&&x==0){
      break;
    }
    for(i=1; i<=n; i++){
      for(j=1; j<=n; j++){
    for(k=1; k<=n; k++){
          if((i+j+k)==x&&i!=j&&j!=k&&k!=i)ans+=1;
    }
      }
    }
    printf("%d\n",ans/6);
    ans=0;
  }
  return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<iostream>
#include<vector>
using namespace std;


//条件0<N<10^18から，愚直にf(n)を計算してしまうと容量エラーになってしまうというもの．                                                                                                                       
//そもそも，f(n)の定義が二重階乗だから，各々の数字を5で割って言って，その数を足し合わせるのが良いだろう．→これだと計算量が多すぎるので，Nが10で何回割り切れるか判定し                                      
//その時，全く2を含まないパターンがあって，それがNがoddの時．この時は二重会場は奇数になって絶対に10で割れない．                                                                                             


//多少工夫しても計算量が変わらない．．．                                                                                                                                                                    
//そこで発送を変えて，5で割り切れる数，25で割り切れる数，，，とやっていく方法を考えてみよう．                                                                                                               
//この時，末尾が5のものがあるとまずいので，2だけかけて，10，50，250としていけば良い．                                                                                                                       


int g(long int n){ //入力nが奇数か偶数かを判断する．                                                                                                                                                        
  if(n%2==0){
    return 0;
  }else{
    return 1;
  }
}

int main(){
  long int N;
  cin >> N ;
  long int count=0;

  if(g(N)==1){
    cout << count <<endl;
    return 0;
  }
 if(N<10){
    cout  << count <<endl;
    return 0;
  }

  long int temp=10;
  while(temp<=N){
    count+=N/temp;
    temp=temp*5;
  }

  cout << count << endl;
  return 0;
}



Measured memory_bytes: 256
t = [0, 0, 0, 0]
for i in range(3):
    (a, b) = map(int, input().split())
    t[a-1] += 1
    t[b-1] += 1
if t.count(1)==2 and t.count(2)==2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
#include <map>
#include <ctype.h>

using namespace std;

#define loop(i,n) for (i = 0; i < n; ++i) 
#define loop2(i,k,n) for (i = k; i <= n; ++i) 
#define loopb(i,k,n) for (i = k; i >= n; --i)
#define remove_space(x) x.erase(remove(x.begin(), x.end(), ' '), x.end())
typedef long long ll;

int main(){

    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int arr[9] = {1,2,3,4,5,6,7,8,9};
    bool found = false;


    for(int i=0; i<9; i++){


    	for(int j=i; j<9; j++){
    		if(arr[i] * arr[j] == n){
    			found = true;
    			break;
    		}
    	}
    }

    if(found){
    	cout << "Yes";
    }

    else{
    	cout << "No";
    }
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    P = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        P[i] = (x, y)
    P.sort()
    cnt = {}
    for i in range(N):
        for j in range(i+1, N):
            ix, iy = P[i]
            jx, jy = P[j]
            d = (jx - ix, jy - iy)
            if d not in cnt:
                cnt[d] = 0
            cnt[d] += 1
    print(N - max(cnt.values()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 39536
import math
def check(l, x, k):
  c = 0
  for a in l:
    c += math.ceil(a/x)-1
  if c <= k:
    return True
  else:
    return False

n,k=map(int, input().split())
a = list(map(int, input().split()))

ok = max(a)
ng = 0
while abs(ok-ng)>1:
  mid = (ok+ng)//2
  if check(a, mid, k):
    ok = mid
  else:
    ng = mid

print(ok)


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

int main() {
  string s;
  cin >> s;
  if (all_of(s.begin(), s.end(), [&](char c) { return c == s[0]; })) {
    cout << s.size() << "\n";
    cout << "1\n";
    return 0;
  }
  int n = s.size();
  constexpr int kP = 1'000'000'000 + 123;
  constexpr int kQ = 7122;
  vector<int> hv(n), pw(n + 1, 1);
  for (int i = 1; i <= n; ++i) pw[i] = 1LL * pw[i - 1] * kQ % kP;
  hv[0] = s[0];
  for (int i = 1; i < n; ++i) hv[i] = (1LL * hv[i - 1] * kQ + s[i]) % kP;

  vector<int> is_cyclic(n);

  auto GetHash = [&](int p, int k) {
    if (p == 0) return hv[p + k - 1];
    return (int)((hv[p + k - 1] + kP - 1LL * pw[k] * hv[p - 1] % kP) % kP);
  };

  for (int k = 1; k <= n; ++k) {
    int h = hv[k - 1]; 
    for (int j = k; j <= n; j += k) {
      is_cyclic[j - 1]++;
      if (j + k <= n && GetHash(j, k) != h) break;
    }
  }

  if (is_cyclic[n - 1] == 1) {
    cout << "1\n";
    cout << "1\n";
    return 0;
  }

  vector<int> suffix(n);
  for (int k = 1; k <= n; ++k) {
    int h = GetHash(n - k, k);
    for (int j = n - k; j >= 0; j -= k) {
      suffix[j]++;
      if (j >= k && GetHash(j - k, k) != h) break;
    }
  }
  int ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (is_cyclic[i] == 1 && suffix[i + 1] == 1) ans++;
  }
  assert(ans > 0);
  cout << "2\n";
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 8708
def get_max_score(s_list):
    score = 0
    for s in s_list:
        score += s

    if score % 10:
        return score

    max_score = score
    s_list = sorted(s_list)
    for s in s_list:
        if (max_score - s) % 10:
            score = max_score - s
            return score

    return 0

if __name__ == '__main__':
    N = int(input())
    s_list = []
    for i in range(N):
        s_list.append(int(input()))

    ans = get_max_score(s_list)
    print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a[100], n, min,temp=0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		min = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[min]) {
				min = j;
			}
		}
		if (i != min) {
			swap(a[i], a[min]);
			temp++;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1)cout << " ";
	}
	cout <<endl << temp << endl;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n,Q;
    ll S,T;
    scanf(" %d %d %lld %lld", &n, &Q, &S, &T);

    vector<ll> a(n+1);
    rep(i,n+1) scanf(" %lld", &a[i]);

    vector<ll> b(n+1);
    ll ans=0;
    rep(i,n)
    {
        b[i] = a[i+1]-a[i];
        if(b[i]>0) ans -= S*b[i];
        else ans -= T*b[i];
    }

    while(Q--)
    {
        int l,r;
        ll x;
        scanf(" %d %d %lld", &l, &r, &x);

        ans += (b[l-1]>0?S:T)*b[l-1];
        b[l-1] += x;
        ans -= (b[l-1]>0?S:T)*b[l-1];

        ans += (b[r]>0?S:T)*b[r];
        b[r] -= x;
        b[n]=0;
        ans -= (b[r]>0?S:T)*b[r];

        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6004
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B; 
  cin >> A >> B;

  cout << A*B << "\n";


  return 0;
}

Measured memory_bytes: 3604
import numpy as np
def main():
    n = int(input())
    a  = list(map(int, input().split()))
    b  = list(map(int, input().split()))
    #print(a,b)

    total = np.sum(a)
    for i in range(n):
        
        if b[i] >= a[i]:
            a[i+1] -= (b[i]-a[i])
            a[i] = 0
            #print(a[i+1])
            if a[i+1] < 0:
                a[i+1] = 0

        elif b[i] < a[i]:
            a[i] -= b[i]

    print(total-np.sum(a))

    
    
if __name__ == '__main__':
    main()



Measured memory_bytes: 27244