akhauriyash/Code-Regression huggingface dataset:
from math import ceil
N,K = map(int,input().split())
A=list(map(int,input().split()))


low=0
high=10**9+1

while low<=high:
    mid=(low+high)//2
    if mid==0:
        print(1)
        exit()

    cnt=0
    for a in A:
        if a<=mid:
            continue
        v=ceil(a/mid)
        cnt+=v-1

    if cnt<=K:
        high=mid-1
    else:
        low=mid+1
print(low)


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll mod = 998244353;

const ll MAX = 3000000;
ll f[MAX], inv[MAX], finv[MAX];

void init() {
	inv[1] = 1;
	for (int i = 2; i < MAX; i++)
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
  f[0] = f[1] = finv[0] = finv[1] = 1;
  for (int i = 2; i < MAX; i++)
    f[i] = (f[i - 1] * i) % mod, finv[i] = (finv[i - 1] * inv[i]) % mod;
}

ll binom(ll n, ll k) {
  return (((f[n] * finv[n - k]) % mod) * finv[k]) % mod;
}

int n, m;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> m;
  init();
  ll res = 0;
  for (int i = 0; i <= n && i <= m; i++) {
    if ((3 * m - i) % 2 == 0) {
      res = (res + binom(n, i) * binom((3 * m - i) / 2 + n - 1, n - 1)) % mod;
    }
  }
  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    res = (res - (n * binom(3 * m - i + n - 2, n - 2)) % mod + mod) % mod;
  }
  cout << res << "\n";
}


Measured memory_bytes: 70528
n = int(input())
s = {}
for i in range(n):
    si = "".join(sorted(input()))
    if si in s:
        s[si] += 1
    else:
        s[si] = 1
ans = 0
for x in s:
    ans += s[x]*(s[x]-1)//2
print(ans)


Measured memory_bytes: 17848
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int A, B, C;
  cin >>  A >>B>>C;
  int a[3];
  a[0]=abs(A-B);
  a[1]=abs(B-C);
  a[2]=abs(C-A);

  sort(a, a+3);
  cout << a[0]+a[1] << endl;


  return 0;
}


Measured memory_bytes: 256
while True:
    n, m = map(int, input().split())
    if n == 0:
        break

    N, M = zip(*[[x.strip("*") if i == 0 else int(x) for i, x in enumerate(input().split())] for _ in range(n)])

    print(sum([M[i] for b in [input() for _ in range(m)] for i, x in enumerate(N) if b.endswith(x)]))

Measured memory_bytes: 7740
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double ans = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
	printf("%.8f\n", ans);
	return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : "\n"); return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : "}\n"); return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vi p(N); rep(i,N) cin >> p[i];
  vi num(N); int ma = 1;
  vi ind(N);
  rep(i,N){
    p[i]--; ind[p[i]] = i;
  }
  num[N-1] = 1;
  RREP(i,N-1,1){
    if(ind[i-1]<ind[i]) num[i-1] = num[i] + 1;
    else num[i-1] = 1;
    chmax(ma,num[i-1]);
  }
  cout << N-ma << endl;
  return 0;
}


Measured memory_bytes: 2560
N=int(input())
A=list(set(list(map(int,input().split()))))

if min(A)==1:
  print(1)
  exit()

while len(A)>1:
  monster_min = A.pop(A.index(min(A)))
  for i in range(len(A)):
    A[i] %= monster_min
  A.sort()
  for i in A[:]:  
    if i == 0: A.remove(i)
    else: continue
  A.append(monster_min)

print(A[0])


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

int main () {

  int H, W;

  while (cin >> H >> W && H != 0 && W != 0){
    for (int i = 0; i < H; i++) {
      cout << "#" ;
      for (int j = 0; j < W-2; j++) {
	if (i == 0 || i == H-1) {
	  cout << "#";
	} else {
	  cout << "." ;
	}      
      }
      cout << "#\n" ;
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[105];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
        {
        	if(a[i]>a[j])
        	{
        		int k=a[j];
        		a[j]=a[i];
        		a[i]=k;
			}
		}
	}
	cout<<a[n]-a[1]<<endl;
	return 0; 
} 

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

namespace ABC133_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var LR = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var L = LR[0];
            var R = LR[1];

            long ans = (int)Math.Pow(2019, 2);
            for (long i = L; i <= R; i++)
            {
                if (i % 2019 == 0)
                {
                    ans = 0;
                    break;
                }

                long ni = i % 2019;
                for (long j = L + 1; j <= R; j++)
                {
                    if (i == j) continue;
                    if (j % 2019 == 0) break;
                    long nj = j % 2019;
                    ans = Math.Min((ni * nj) % 2019, ans);
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	string a,b,c;
  	cin>>a>>b>>c;
  	int sa=0,sb=0,sc=0;
  	while(1)
    {
     	 alice:if(sa == a.length())
                { 
		 // cout<<sa<<" "<<sb<<" "<<sc<<"in A";
                  cout<<'A';
                  return 0;
                } 
		char ch = a[sa++];
		
      		
      			if(ch == 'a')
                  		goto alice;
      			if(ch == 'b')
                  		goto bob;
      			if(ch == 'c')
                  		goto charlie;
         bob:
		if(sb == b.length())
		{
			cout<<'B';
			return 0;
		
		}  
		ch = b[sb++];
		//cout<<"In B "<<ch;
      		  if(ch == 'a')
                  goto alice;
      		  if(ch == 'b')
                  goto bob;
      		  if(ch == 'c')
      			goto charlie;
      charlie:   if(sc == c.length())
                {
			//cout<<sa<<" "<<sb<<" "<<sc<<"in C";
                 	cout<<'C';
                  	return 0;
                }
		ch = c[sc++];
		//cout<<"In C "<<ch;
      		
      		if(ch == 'a')
                	  goto alice;
      		  if(ch == 'b')
                	  goto bob;
      		  if(ch == 'c')
      			goto charlie;
    }
      
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
typedef long long int lli;
typedef pair<int,int> P;
#define F first
#define S second
const int INF=1000000000;
 
long long int dp[1001][2][2][2];
int main(){
    for(int i=0; i<1001; ++i){
        for(int j=0; j<2; ++j){
            for(int k=0; k<2; ++k){
                for(int l=0; l<2; ++l){
                    dp[i][j][k][l]=0;
                }
            }
        }
    }
    int N;
    cin >> N;
    string str;
    cin >> str;
    if(str[0]=='J'){
        for(int i=0;i<2; ++i){
            for(int j=0; j<2; ++j){
                dp[1][1][i][j]=1;
            }
        }
    } else if(str[0]=='O'){
        for(int i=0; i<2; ++i){
            dp[1][1][1][i]=1;
        }
    } else if(str[0]=='I'){
        for(int i=0; i<2; ++i){
            dp[1][1][i][1]=1;
        }
    }
 
    for(int i=2; i<=N; ++i){
        if(str[i-1]=='J'){
            dp[i][1][0][0]+=(dp[i-1][1][0][0]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][1][0]+=(dp[i-1][1][0][0]+dp[i-1][0][1][0]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][0][1]+=(dp[i-1][1][0][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][1][1]+=(dp[i-1][1][0][0]+dp[i-1][0][1][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
        } else if(str[i-1]=='O'){
            dp[i][0][1][0]+=(dp[i-1][0][1][0]+dp[i-1][1][1][0]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][1][0]+=(dp[i-1][1][0][0]+dp[i-1][0][1][0]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][0][1][1]+=(dp[i-1][0][1][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][1][1]+=(dp[i-1][1][0][0]+dp[i-1][0][1][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
        } else if(str[i-1]=='I'){
            dp[i][0][0][1]+=(dp[i-1][0][0][1]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][0][1]+=(dp[i-1][1][0][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][0][1][1]+=(dp[i-1][0][1][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
            dp[i][1][1][1]+=(dp[i-1][1][0][0]+dp[i-1][0][1][0]+dp[i-1][0][0][1]+dp[i-1][1][1][0]+dp[i-1][1][0][1]+dp[i-1][0][1][1]+dp[i-1][1][1][1])%10007;
        }
    }
    long long int ans=0;
    for(int i=0; i<2; ++i){
        for(int j=0; j<2; ++j){
            for(int k=0; k<2; ++k){
                ans+=dp[N][i][j][k]%10007;
            }
        }
    }
    cout << ans%10007 << "\n";
    return 0;
}

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

int const N = 200000;
int x[N + 1], dp[N + 1];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n + 1)scanf("%d", x + i);
	f(i, 1, n + 1)dp[x[i]] = 1 + dp[x[i] - 1];
	int an = 0;
	f(i, 1, n + 1)an = max(an, dp[i]);
	printf("%d\n", n - an);
}

Measured memory_bytes: 1792
//C - たくさんの数式
//Hiia
#include <stdio.h>
typedef long long ll;

int llruijou(long long int base,long long int exponent){long long int ii,answer=1;ii=exponent;while(ii!=0){answer=answer*base;--ii;}return answer;}//ruijou base^exponent
long long int llketasuu(long long int x){ll j=0;while(x!=0){x/=10;j++;}return(j);}

int main()
{
  ll s,ans=0;
  scanf("%lld", &s);
  ll keta=llketasuu(s);
  for(ll i=1;i<=keta;i++){
    if(i==1){
      ans+=(s%10)*llruijou(2,keta-1);
    }
    else{
      ans+=((s/llruijou(10,i-1))%10)*llruijou(2,keta-2)*((9*llruijou(5,i-1) - 1)/4);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var abc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        for(var i=0;i<3;i++)
            if (abc[i] % 2 == 0) { WriteLine(0);return; }
        Array.Sort(abc);
        WriteLine((long)abc[1] * abc[0]);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back
 
vector<int> enum_div(int n);

int main(){
    ll n,x;
    ll mul = INF;
    int d = 1;
    vecll nx;
    cin >> n >> x;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        nx.pb(tmp);
        mul = min(mul,abs(tmp-x));
    }
    vecll nxmul;
    veci ret = enum_div(mul);
    FOR(i,1,n){
        nxmul.pb(nx[i]-nx[i-1]);
    }
    REP(i,(int)ret.size()){
        bool eno = true;
        REP(j,(int)nxmul.size()){
            if(nxmul[j] % ret[i] != 0){
                eno = false;
                break;
            }
        }
        if(eno){
            d = max(d,ret[i]);
        }
    }
    cout << d << endl;
    return 0;
}

vector<int> enum_div(int n)
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
    ret.push_back(n);
	return ret;
}


Measured memory_bytes: 2548
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

    if N & 1:
        j = (N - 1) // 2
        ans = B[j] - A[j] + 1
        print(ans)
        return

    j = N // 2 - 1
    k = N // 2
    ans = (B[j] + B[k]) - (A[j] + A[k]) + 1
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 25396
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

string s;

bool check(string t){
    bool x[26]={};
    int i;
    for(i=0;i<t.size();i++){
        if(x[t[i]-'a']==0 && t[i]!='a'){
            x[t[i]-'a']=1;
            t[i]--;
        }
    }
    return s==t;
    
}

int main(void){
    int i,j;
    while(1){
        cin >> s;
        if(s[0]=='#')break;
        vector<string> v;
        int si = s.size();
        for(i=0;i<(1<<si);i++){
            string t = s;
            for(j=0;j<si;j++){
                if((i>>j)%2){
                    t[j]++;
                }
            }
            if(check(t))v.push_back(t);
        }
        sort(v.begin(),v.end());
        int vs = (int)v.size();
        cout << vs << endl;
        if(vs>10){
            for(i=0;i<5;i++)cout << v[i] << endl;
            for(i=vs-5;i<vs;i++)cout << v[i] << endl;
        }
        else for(i=0;i<(int)v.size();i++)cout << v[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 4116
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    H, W = na[0], na[1]

    a = []
    for i in range(H):
        s = input()
        if '#' in s:
            a.append(s)

    b = [0] * W
    for s in a:
        for i in range(W):
            if s[i] == '#':
                b[i] = 1

    for s in a:
        ss = ''
        for i in range(W):
            if b[i] == 1:
                ss += s[i]
        print(ss)


if __name__ == '__main__':
    main()



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

using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, ss = 0;
  vector<int> s;
  cin >> n;
  while (n--){
    int v;
    cin >> v;
    s.push_back(v);
    ss += v;
    
  }
  
  sort(s.begin(), s.end());

  if (ss % 10) {
    cout << ss << endl;
    return 0;
  }
  
  for (int i = 0; i < s.size(); i++) {
    if (s[i] % 10) {
      ss -= s[i];
      break;
    }
  }

  if (ss % 10) {
    cout << ss << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string t;
	cin >> t;
	long long ans = 0;
	vector<int> mark;
	mark.resize(n);
	for(int i = 0; i < n; ++i) {
		if(i - k < 0 || mark[i - k] == 0 || t[i] != t[i - k]) {
			mark[i] = 1;
			if(t[i] == 'p') {
				ans += s;
			}
			if(t[i] == 'r') {
				ans += p;
			}
			if(t[i] == 's') {
				ans += r;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int>P;
    const double eps = 1e-8;
    const int NINF = 0xc0c0c0c0;
    const int INF  = 0x3f3f3f3f;
    const ll  mod  = 2019;
    const ll  maxn = 1e6 + 5;
    const int N = 2e5 + 5;
     
    char s[N];
    int a[N],suf[N],n,M[2020];
     
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cin>>s+1;
    	int n=strlen(s+1);
    	int cnt=0;int base=1;
    	M[0]++;
    	for(int i=n;i>=1;i--){
    		a[i]=s[i]-'0';
    		suf[i]=(suf[i+1]+a[i]*base)%mod;
    		cnt+=M[suf[i]];
    		M[suf[i]]++;
    		base=base*10%mod;
    	}
    	cout<<cnt<<'\n';
    	return 0;
    }

Measured memory_bytes: 5344
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    int sum=1;
    cin>>a>>b;
    sum*=b;
    for(int i=2;i<=a;i++)
    {
        sum*=(b-1);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

red = [list(map(int,input().split())) for i in range(N)]
blue = [list(map(int,input().split())) for i in range(N)]

red = sorted(red, key=lambda x: x[1], reverse=True)
blue = sorted(blue, key=lambda x: x[0], reverse=False)

flg = [0 for i in range(N)]

ans = 0

for i in range(N) :
    c,d = blue[i]
    for j in range(N) :
        if flg[j] :
            continue
        
        a,b = red[j]
        
        if (a < c) and (b < d) :
            ans += 1
            flg[j] = 1
            break

print(ans)


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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;

	public static void main(String[] args) {
		int M = sc.nextInt();
		N = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < M; ++i) {
			boolean[] a = new boolean[N];
			for (int j = 0; j < N; ++j) {
				a[j] = sc.nextInt() == 1;
				if (i != 0) a[j] = !a[j];
			}
			ans += solve(a);
		}
		System.out.println(ans);
	}

	static int solve(boolean[] a) {
		int[][] dp = new int[N][N];
		for (int i = 0; i < N; ++i) {
			int cur = a[i] ? 1 : 0;
			if (i != 0) cur = 1 - cur;
			if (i != N - 1) cur = 1 - cur;
			dp[i][i] = cur;
		}
		for (int len = 1; len < N; ++len) {
			for (int left = 0; left + len < N; ++left) {
				{
					int cur = a[left] ? 1 : 0;
					if (left != 0) cur = 1 - cur;
					dp[left][left + len] = cur + dp[left + 1][left + len];
				}
				{
					int cur = a[left + len] ? 1 : 0;
					if (left + len != N - 1) cur = 1 - cur;
					dp[left][left + len] = Math.max(dp[left][left + len], cur + dp[left][left + len - 1]);
				}
			}
		}
		return dp[0][N - 1];
	}
}

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

//constant
const int inf=1<<28;

//variable
int n;
int in;
int maxi=-inf;
int mini=inf;
int sum;


int main(){

    while(cin>>n, n){
        sum=0;
        maxi=-inf;
        mini=inf;
        for(int i=0; i<n; i++){
            cin>>in;
            maxi=max(in,maxi);
            mini=min(in,mini);
            sum+=in;
        }
        //out<<maxi<<' '<<mini<<endl;
        cout<<(int)(((sum-maxi-mini)*1.0)/(n-2))<<endl;
    }

    return 0;
}

Measured memory_bytes: 2960
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	int off = 0;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		off += x != i;
	}
	cout << (off <= 2 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define EPS 1e-11

string hogehoge;

int k, r, l;
double p, e, t;

double solve(double R, double L, double T, int K){//cout<<R<<" "<<L<<" "<<K<<endl;//cin>>hogehoge;
	double H = (R+L)/2, ans = 0, P = H < t?p:1-p;
	
	if(!K){if(fabs(t-H) <= e) return 1; else return 0;}
	
	if(t-e < R && H < t+e) ans += P;
	else 
		if(t-e < H) ans += solve(R,H,H,K-1)*P;
	
	if(t-e < H && L < t+e) ans += 1-P;
	else 
		if(t+e > H) ans += solve(H,L,H,K-1)*(1-P);
	
	return ans;
	
}


signed main(){
	cout<<fixed<<setprecision(7);
	
	cin>>k>>r>>l>>p>>e>>t;
	
	cout<<solve(r,l,t,k)<<endl;
	return 0;
}


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


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

    string s;
    cin>>s;
    int m=0,e=0,w=0;
    int n=s.size();
    bool mid=false;
    bool end=false;
    for(int i=0;i<n;i++){
        if(s[i]=='m') m++;
        else if(s[i]=='e'){
            e++;
            if(m<e){
                cout<<"Rabbit"<<endl;
                return 0;
            }
            if(m==e && mid==false){
                mid=true;
            }
            
        }
        else if(s[i]=='w'){
            w++;
            if(m<w || e<w){
                cout<<"Rabbit"<<endl;
                return 0;
            }
            if(w==m && i!=n-1){
                cout<<"Rabbit"<<endl;
                return 0;
            }
        }
    }
    if(mid) cout<<"Cat"<<endl;
    else cout<<"Rabbit"<<endl;

}


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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] len = new Integer[n];
		for ( int i = 0; i < n; i++ ) {
			len[i] = in.nextInt();
		}
		Arrays.sort(len);

		int cnt = 0;
		for ( int e1 = 0; e1 < n; e1++ ) {
			for ( int e2 = e1 + 1; e2 < n; e2++ ) {

				int d = len[e1] + len[e2];
				int i = Arrays.binarySearch(len, d);
				i = i >= 0 ? i : ~i;
				while(i == n || len[i]>= d) {
					i--;
				}
				i++;
				cnt += Math.max(i - e2 - 1, 0);

				// System.out.println("e1:" + len[e1] + " e2:" + len[e2] + "  i:" + i + " cnt:" + cnt);
			}
		}
		System.out.println(cnt);
		in.close();
	}
}

Measured memory_bytes: 44268
#include<stdio.h>
#include<string.h>

int main()
{
    int a,b,c,i,j,k,cnt,s=-300;
    char a1[100][20],b1[100][20];
    scanf("%d",&a);
    i=0,j=a;
    while(j--)
    {
        scanf("%s",a1[i]);
        i++;
    }
    scanf("%d",&b);
    k=b;
    i=0;
    while(k--)
    {
        scanf("%s",b1[i]);
        i++;
    }
    for(i=0;i<a;i++)
    {
        cnt=1;
        for(j=i+1;j<a;j++)
        {
            if(strcmp(a1[i],a1[j]));
            else   cnt++;
        }
        for(j=0;j<b;j++)
        {
            if(strcmp(a1[i],b1[j]));
            else    cnt--;
        }
        s=s>cnt?s:cnt;
    }
    printf("%d\n",s>0?s:0);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	class Node {
		int key;
		Node p, l, r;
		Node(int key) {
			this.key = key;
		}
		void insert(Node z) {
			Node y = null;
			Node x = this;
			while (x != null) {
				y = x;
				if (z.key < x.key)
					x = x.l;
				else
					x = x.r;
			}
			z.p = y;
			
			if (z.key < y.key)
				y.l = z;
			else
				y.r = z;
		}
		boolean find(int key) {
			Node x = this;
			while (x != null) {
				if (key == x.key)
					return true;
				else if (key < x.key)
					x = x.l;
				else
					x = x.r;
			}
			return false;
		}
		void print() {
			this.inorder();
			System.out.println();
			this.preorder();
			System.out.println();
		}
		void preorder() {
			System.out.print(" " + this.key);
			if (this.l != null)
				this.l.preorder();
			if (this.r != null)
				this.r.preorder();
		}
		void inorder() {
			if (this.l != null)
				this.l.inorder();
			System.out.print(" " + this.key);
			if (this.r != null)
				this.r.inorder();
		}
	}
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Node t = null;
		for (int i = 0; i < n; i++) {
			String inst = scan.next();
			// set a root node
			if (i == 0) {
				int key = scan.nextInt();
				t = new Node(key);
				continue;
			}
			
			switch(inst) {
			case "insert":
				int key = scan.nextInt();
				if (DEBUG)
					System.out.println("insert: " + key);
				t.insert(new Node(key));
				break;
			case "find":
				int findKey = scan.nextInt();
				if (DEBUG)
					System.out.println("find: " + findKey);
				System.out.println(t.find(findKey) ? "yes" : "no");
				break;
			case "print":
				if (DEBUG)
					System.out.println("print");
				t.print();
				break;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 209952
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int r = sc.nextInt();
        //String s = sc.next();

        // 処理
        double out = 2 * Math.PI * r;

        // 出力
        System.out.println(out);
    }
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string S;
    cin >> S;

    V<int> ups(S.size() + 1);
    {
        int u = 0;
        per(i, S.size()) {
            if (S[i] == '1') {
                ups[i] = ups[i + 1] + 1;
                u++;
            } else {
                ups[i] = max(ups[i + 1] - 1, 0);
                --u;
            }
            chmax(ups[i], u);
        }
    }
    debug(S, ups);

    auto calc = [&](int ub) {
        int s = 0;
        int mini = 0;
        rep(i, S.size()) {
            char c = S[i];
            if (c == '1') {
                ++s;
            } else if (c == '0') {
                --s;
            } else {
                if (s + 1 + ups[i + 1] <= ub) {
                    ++s;
                } else {
                    --s;
                }
            }
            chmin(mini, s);
        }
        return ub - mini;
    };

    int maxi = 0;
    {
        int s = 0;
        for (auto c : S) {
            if (c == '1') {
                ++s;
            } else {
                --s;
            }
            chmax(maxi, s);
        }
    }
    debug(maxi);

    cout << min(calc(maxi), calc(maxi + 1)) << endl;

    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int inf = 2e9;

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

map<pair<int, int>, bool> m;
string ans;

map<pair<int, int>, bool> bio;
map<pair<int, int>, pair<int, int>> p;

void bfs(int sx, int sy, int tx, int ty) {
	m[make_pair(sx, sy)] = false;
	m[make_pair(tx, ty)] = false;
	bio.clear();
	p.clear();
	queue<pair<int, int>> q;
	p[make_pair(sx, sy)] = make_pair(inf, inf);
	bio[make_pair(sx, sy)] = true;
	q.emplace(sx, sy);
	while (!q.empty()) {
		pair<int, int> u = q.front(); q.pop();
		if (u.first == tx && u.second == ty) {
			string s;
			while (!(u.first == inf && u.second == inf)) {
				debug(u.first);
				debug(u.second);
				pair<int, int> par = p[u];
				m[u] = true;
				if (par.first > u.first) s.push_back('L');
				if (par.first < u.first) s.push_back('R');
				if (par.second > u.second) s.push_back('D');
				if (par.second < u.second) s.push_back('U');
				u = par;
			}
			for (int i = (int)s.size()-1; i >= 0; --i) {
				ans.push_back(s[i]);
			}
			return;
		}
		for (int i = 0; i < 4; ++i) {
			int vx = u.first+dx[i], vy = u.second+dy[i];
			pair<int, int> v = make_pair(vx, vy);
			if (bio[v]) continue;
			if (m[v]) continue;
			bio[v] = true;
			q.push(v);
			p[v] = u;
		}
	}
	
}

void solve() {
	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	for (int i = sy; i < ty; ++i) cout << 'U';
	for (int i = sx; i < tx; ++i) cout << 'R';
	for (int i = sy; i < ty; ++i) cout << 'D';
	for (int i = sx; i < tx; ++i) cout << 'L';
	cout << 'L';
	for (int i = sy; i < ty+1; ++i) cout << 'U';
	for (int i = sx; i < tx+1; ++i) cout << 'R';
	cout << 'D';
	cout << 'R';
	for (int i = sy; i < ty+1; ++i) cout << 'D';
	for (int i = sx; i < tx+1; ++i) cout << 'L';
	cout << 'U';
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

total = [0,0]
count = [0,0]

for i in range(2):
    for j in range(N):
        total[i] += A[j]
        if (i+j)%2 == 0:
            if total[i] >= 0:
                count[i] += abs(total[i]+1)
                total[i] = -1
        else:
            if total[i] <= 0:
                count[i] += abs(total[i]-1)
                total[i] = 1

print(min(count))

Measured memory_bytes: 14468
#include <stdio.h>
#define N 100

void printA(int *A,int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i!=n-1)printf(" ");
		else printf("\n");
	}
}

void selectionSort(int *A,int n){
	int i,j,minj;
	int tmp;
	int count = 0;
	for(i=0;i<n;i++){
		minj = i;
		for(j=i;j<n;j++){
			if(A[j]<A[minj])minj = j;
		}
		if(minj!=i){tmp = A[i];A[i]=A[minj];A[minj]=tmp;count++;}
	}
	printA(A,n);
	printf("%d\n",count);
}

int main(){
	int n;
	int i;
	int A[N];

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}

	selectionSort(A,n);

	return 0;
}

Measured memory_bytes: 1812
#include<iostream>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    fastio;
    int a,b,f=0;
    cin>>a;
    for(int i = 1;i<=9;i++)
        if((a/i)<=9 && (a%i==0))
    {
        f=1;
        cout<<"Yes";
        break;
    }
    if(f==0)
        cout<<"No";
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define lli long long int
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX1 998244353
#define MAX2 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define input(data,n,command) for(lli i=0;i<n;i++){lli tmp;cin>>tmp;data.pb(tmp);command}
#define sort(a) sort(a.begin(),a.end());
#define display(a) for(lli i = 0 ;i<a.size();i++){cout<<a[i]<<" ";} cout<<endl;
#define rep(i,n,p) for(lli i = 0;i<n;i= i +p)
#define endl "\n"

//Written By GHATAK...
/*--------------------------------------------------------------------*/
//vector<pair<lli,lli>>adj[300010];

int main()
{
    ios
    lli T=1;
    //cin>>T;
    while(T--)
    {
        //start from here
        lli n;
        cin>>n;
        lli z = sqrt(n);
        for(lli i = z;i>=1;i--)
        {
            if(n%i == 0)
            {
                lli x = n/i;
                cout<<(i-1 + x-1);
                return 0;
            }
        }
    }
    return 0;
}
/*-----------------------------------------------------------------------*/
/*
--->  reverse(vec.begin(),vec().end());
*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum += a[i];
  }
  int ave=sum/n+(sum%n>n/2), ans=0;
  for(int i=0;i<n;i++){
    ans += (a[i]-ave)*(a[i]-ave);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

signed main(){
  int a[3];rep(i,3)cin>>a[i];sort(a,a+3);
  if(a[0] == a[1] && a[1] == a[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import           Data.List.Split
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    cs <- getLine
    !w <- readLn :: IO Int
    putStrLn$solve w cs

solve w cs = map head $ chunksOf w cs



Measured memory_bytes: 764
#include <stdio.h>

int main(void){
 
  int n;
  scanf("%d",&n);
  
  double t , a;
  scanf("%lf %lf",&t,&a);
  
  int h[n+1];
  for(int i = 1;i <= n;i ++){
    scanf("%d",&h[i]);
  }
  
  double sa = 99999999;
  int ans;
  
  for(int i = 1;i <= n;i ++){
    double kion = t - h[i] * 0.006;
    if(a > kion){
      if((a-kion) < sa){
       sa = a - kion;
       ans = i;
      }
    }
    else{
      if((kion-a) < sa){
        sa= kion - a;
        ans = i;
      }
    }
  }
  
  printf("%d",ans);
  
  return 0;
}
      

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int a,b;
	char c[12];
	scanf("%d",&a);
	scanf("%s",c);
	scanf("%d",&b);
	for(int i=0;i<a;i++)
	{
		if(c[i]!=c[b-1])
		c[i]='*';
	}
	printf("%s",c);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;
int ans[1000005];
int a[200005],b[200005];
set <pair <int,int> > se;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,pos=0;
    ans[1000000]++;
    cin>>n>>m;
    f(i,1,m+1) {
        se.insert({i,0});
        ans[0]++;
    }
    f(i,1,n+1) {
        cin>>a[i]>>b[i];
        // cout<<a[i]<<" "<<b[i]<<endl;
        // for(auto j: se) {
        //     cout<<j.ff<<" "<<j.ss<<" ";
        // }
        // cout<<'\n';
        if(b[i]!=m) {
            auto itr=se.lower_bound({b[i]+2,0});
            if(itr!=se.begin()) {
                itr--;
                if((*itr).ff!=b[i]+1) {
                    int value=b[i]+1-(*itr).ff + (*itr).ss;
                    se.insert({b[i]+1,value});
                    ans[value]++;
                }
            }
        }
        auto itr=se.lower_bound({a[i],0});
        // cout<<(*itr).ff<<" "<<(*itr).ss<<endl;
        while(itr!=se.end() && (*itr).ff<=b[i] ) {
            // cout<<"kitna\n";
            auto itrtmp=itr;
            itr++;
            ans[(*itrtmp).ss]--;
            se.erase(itrtmp);
        }
        // cout<<" "<<ans[pos]<<endl;
        while(ans[pos]<=0)
        {
            pos++;
        }
        if(pos>m)
            cout<<"-1\n";
        else
            cout<<pos+i<<'\n';
    }
    
    return 0;
}

Measured memory_bytes: 20572
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

c=[[0 for i in range(W)]for j in range(H)]
for k in range(N):
    count=0
    flag=True
    for i in range(H):
        for j in range(W):
            if i%2==0:
                if c[i][j]==0:
                    if count!=a[k]:
                        c[i][j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
            else:
                if c[i][W-1-j]==0:
                    if count!=a[k]:
                        c[i][W-1-j]=k+1
                        count+=1
                    else:
                        flag=False
                        break
        if not flag:
            break
for i in range(H):
    print(*c[i])

Measured memory_bytes: 45532
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  ll N, M;
  cin >> N >> M;
  M /= 2;
  if (N >= M) {
    cout << M << endl;
  } else {
    cout << (N + M) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
function str1(x){
   x=x+"";
   while(x.length!=b)x="0"+x;
   return x;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var ab=(Arr.shift()).split(" ").map(Number);
   if(ab[0]==0 && ab[1]==0)break;
   var str=ab[0]+"";
   var b=ab[1];
   var arr=[];
   str=str1(str);
   arr.push(str);
   var i=0;
   while(true){
      i++;
      var s=str.split("");
      s.sort(function(a,b){return b-a;});
      var A=parseInt(s.join(""),10);
      var B=parseInt(s.reverse().join(""),10); 
      var C=A-B;
      var Cstr=str1(C);     
      if(arr.indexOf(Cstr)!=-1)break;
      arr.push(Cstr);
      str=Cstr; 
   }
   console.log(arr.indexOf(Cstr)+" "+parseInt(Cstr,10)+" "+(i-arr.indexOf(Cstr)));
}

Measured memory_bytes: 10064
#include <iostream>
#include <string>
int main(void)
{
	int i, j, I, J, x, y, h, w, out[52][52];
	char s[52][52];

	std::cin>>h>>w;

	for(i=0; i<h; i++){
		std::cin>>s[i];
	}

	for(y=0; y<h; y++){
		for(x=0; x<w; x++){
			if(s[y][x]=='#'){
				out[y][x]=-1;
			}else{
				out[y][x]=0;
				I=(x+1<w)?(x+1):w-1; J=(y+1<h)?(y+1):h-1;
				for(j=(y-1>=0)?(y-1):0; j<=J; j++){
					for(i=(x-1>=0)?(x-1):0; i<=I; i++){
						if(s[j][i]=='#'){
							out[y][x]++;
						}
					}
				}
			}
		}
	}

	for(y=0; y<h; y++){
		for(x=0; x<w; x++){
			if(out[y][x]==-1){
				std::cout<<"#";
			}else{
				std::cout<<out[y][x];
			}
		}
		std::cout<<"\n";
	}
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int dataSetOfNum = scan.nextInt();
		int[] dataSet = new int[3];
		int side1, side2, side3;
		
		for(int i = 0; i < dataSetOfNum; i++) {
			dataSet[0] = scan.nextInt();
			dataSet[1] = scan.nextInt();
			dataSet[2] = scan.nextInt();
			Arrays.sort(dataSet);
			
			if((Math.pow(dataSet[0], 2) + Math.pow(dataSet[1], 2)) == Math.pow(dataSet[2], 2)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
		
	}
}

Measured memory_bytes: 34008
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

void solution()
{
    int x,y;
    cin >> x >> y;
    rep(c, x+1){
        int t = x - c;
        int l = 2*c + 4*t;
        if(l==y){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;

int main(){
	int a,b;
	cin>>a>>b;
	a=(a+11)%13;
	b=(b+11)%13;
	if(a>b)cout<<"Alice"<<endl;
	else if (a==b)cout<<"Draw"<<endl;
	else cout<<"Bob"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int main() {
    int r; cin >> r; cout << r*r << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[0] * N for _ in range(N)]
for u, v in edges:
    graph[u - 1][v - 1] = 1
    graph[v - 1][u - 1] = 1

visited = [False] * N
visited[0] = True

def dfs(s):    
    if all(visited):
        return 1

    cnt = 0
    for i in range(N):
        if visited[i] or graph[s][i] != 1:
            continue
            
        visited[i] = True
        cnt += dfs(i)
        visited[i] = False
        
    return cnt

print(dfs(0))



Measured memory_bytes: 43228
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long C = N / 500;
        long D = (N-500*C)/5;
        System.out.println(1000 * C + 5 * D);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,l,r,c = 0;
    cin >> n;
    rep(i,n){
        cin >> l >> r;
        c += r-l+1;
    }
    PRINT(c);
}


Measured memory_bytes: 256