akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		double a = sc.nextDouble();
      double b = sc.nextDouble();
      double x = sc.nextDouble();

     double menseki = x/a;
      if(menseki>a*b/2){
        menseki=a*b-menseki;
        System.out.println(Math.toDegrees(Math.atan((menseki*2/a)/a)));
      }else{
        System.out.println(Math.toDegrees(Math.atan(b/(menseki*2/b))));
      }
    }

}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

// 400012- 128


void oneCase() {
    char a, b;
    cin >> a >> b;
    if (a > b) {
        cout << ">\n";
    } else if (a < b) {
        cout << "<\n";
    } else {
        cout << "=\n";
    }

}

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

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,y,i,j, sisa;
	scanf("%d %d",&n,&y);
	//1 komponen
	if(y%10000==0){
		int banyak = y/10000;
		if(banyak==n){
			printf("%d 0 0\n",banyak); return 0;
		}
	}
	if(y%5000==0){
		int banyak = y/5000;
		if(banyak==n){
			printf("0 %d 0\n",banyak); return 0;
		}
	}
	if(y%1000==0){
		int banyak = y/1000;
		if(banyak==n){
			printf("0 0 %d\n",banyak); return 0;
		}
	}

	//2 komponen
	//10 rb dan 5 rb sekalian sama 1 rb
	int banyak = y/10000;
	for(i=banyak;i>=0;i--){
		sisa = y-(i*10000);
		if(sisa%5000==0){
			int banyak2 = sisa/5000;
			if((banyak2+i)==n){
				printf("%d %d 0\n",i,banyak2); return 0;	
			}
		}
		if(sisa%1000==0){
			int banyak2 = sisa/1000;
			if((banyak2+i)==n){
				printf("%d 0 %d\n",i,banyak2); return 0;		
			}
		}
	}
	//5 rb dan 1 rb
	banyak = y/5000;
	for(i=banyak;i>=0;i--){
		sisa = y-(i*5000);
		if(sisa%1000==0){
			int banyak2 = sisa/1000;
			if((banyak2+i)==n){
				printf("0 %d %d\n",i,banyak2); return 0;
			}
		}
	}

	//3 komponen
	banyak = y/10000;
	for(i=banyak;i>=0;i--){
		sisa = y-(i*10000);

		if(sisa%1000==0){
			int banyak2 = sisa/1000;
			for(j=banyak2;j>=0;j--){
				int sisa2 = sisa-(j*1000);
				if(sisa2%5000==0){
					int banyak3 = sisa2/5000;
					if((i+j+banyak3)==n){
						printf("%d %d %d\n",i,banyak3,j); return 0;
					}
				}
				
			}
			
		}
	}
	printf("-1 -1 -1\n");
	return 0;
};

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,cnt=0,v;
  cin >> n;
  ll a[n],b[n],val[n];
  fill(b,b+n,0);
  fill(val,val+n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=n-1;i>=0;i--){
    v=0;
    for(int j=i+1;j<=n;j+=i+1){
      v+=b[j-1];
    }
    if(v%2!=a[i]){
      b[i]++;
      cnt++;
    }
  }
  cout << cnt<<endl;
  for(int i=0;i<n;i++){
    if(b[i]==1){
      cout << i+1<<" ";
    }
  }
  if(cnt>0){
    cout << endl;
  }
}


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

int main(){
	ios::sync_with_stdio(false);

	int mn = 1010, mx = -1010;
	int n, x;
	cin >> n;
	cin >> mx;
	mn = mx;
	n--;
	while (n--){
		cin >> x;
		mn = min(mn, x);
		mx = max(mx, x);
	}	
	cout << mx - mn;

	return 0;
}


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

int main(){
	int y[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	int N, M; cin >> N >> M;

	vector<int> A(M);
	vector<int> dp(N+1, -2);
	dp[0] = 0;
	for(int i=0; i<M; ++i){
		cin >> A[i];
	}
	sort(A.begin(), A.end(), greater<int>());

	for(int i=0; i<=N; ++i){
		for(auto num : A){
			if(i - y[num] >= 0){
				dp[i] = max(dp[i-y[num]]+1, dp[i]);
			}
		}
	}

	int cnt = N;
	priority_queue<int> answer;
	while(cnt > 0){
		for(int i=0; i<M; ++i){
			if(cnt - y[A[i]] >= 0 && dp[cnt - y[A[i]]] == dp[cnt] - 1){
				cnt -= y[A[i]];
				cout << A[i];
				break;
			}
		}
	}cout << endl;
}


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

using Double = double;
using Point = complex<Double>;
const Double EPS = 1e-8;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
namespace std {
  bool operator<(const Point a, const Point b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

Double dot(const Point &a, const Point &b){ return a.X*b.X + a.Y*b.Y; }
Double cross(const Point &a, const Point &b){ return a.X*b.Y - a.Y*b.X; }

// AB からみて AC がどの方向にあるか
int ccw(const Point &a, const Point &b, const Point &c){
  const Point db = b - a;
  const Point dc = c - a;
  if(cross(db,dc) >  EPS) return +1;  // ccw
  if(cross(db,dc) < -EPS) return -1;  // cw
  if(dot(db,dc)   < -EPS) return +2;  // c--a--b on line
  if(norm(db) < norm(dc)) return -2;  // a--b--c on line or a==b
  return 0;                           // a--c--b on line or a==c or b==c
}

vector<Point> circlesPointsRadius(const Point &a, const Point &b, const Double r){
  vector<Point> cs;
  Point abH = (b-a)*0.5;
  Double d = abs(abH);
  if(d == 0 ) return {a};
  if(d > r) return {};
  Double dN = sqrt(r*r - d*d);
  Point n = abH * Point(0,1) * (dN / d);
  cs.push_back(a + abH + n);
  if(dN > 0) cs.push_back(a + abH - n);
  return cs;
}

Point p[20];
vector<int> nexts[20];
int dp[1<<15];

bool check(int n, int m, double r){
  rep(i,n){
    nexts[i].clear();
    rep(j,n){
      auto vc = circlesPointsRadius(p[i], p[j], r);
      for(auto &c : vc){
        int mask = 0;
        rep(k,n) if(abs(c-p[k]) < r + EPS) mask |= (1<<k);
        nexts[i].push_back(mask);
      }
    }
    if(nexts[i].size()==0) nexts[i].push_back(1<<i);
    // dbg(r,i,nexts[i]);
  }

  fill(dp, dp + (1<<n), 12345678);
  dp[0] = 0;
  rep(mask, 1<<n) if(dp[mask]>=0){
    rep(i,n) if((mask>>i)%2==0){
      for(auto &nm : nexts[i]){
        dp[mask|nm] = min(dp[mask|nm], dp[mask] + 1);
      }
    }
  }
  return dp[(1<<n) - 1] <= m;
}

double solve(){
  int n,m;
  cin>>n>>m;
  rep(i,n){
    Double x,y;
    cin>>x>>y;
    p[i] = {x,y};
  }

  if(n==m) return 0;

  double l=0, r=2e5;
  rep(_,100){
    double mid = (l+r)/2.0;
    if(check(n,m,mid)) r = mid;
    else l = mid;
  }
  return (l+r)/2.0;
}

int main(){
  printf("%.10f\n", solve());

  return 0;
}



Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

int main(int argc, char **argv)
{
    ll L;
    cin >> L;
    ll t = L * L * L;

    printf("%f\n", (double)t / (double)(3.0 * 3.0 * 3.0));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int md = 998244353;

void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

int mul(int a, int b) {
  return ((ll)a * b) % md;
}

int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> f(n + 1), rf(n + 1);
  f[0] = 1;
  for (int i = 1; i <= n; ++i) f[i] = mul(f[i - 1], i);
  rf[n] = power(f[n], md - 2);
  for (int i = n - 1; i >= 0; --i) {
    rf[i] = mul(rf[i + 1], i + 1);
  }
  auto C = [&] (int n, int k) {
    return mul(f[n], mul(rf[n - k], rf[k]));
  };
  vector <int> p2(n + 1);
  p2[0] = 1;
  for (int i = 1; i <= n; ++i) p2[i] = mul(p2[i - 1], 2);
  int ans = 1;
  for (int i = 0; i < n; ++i) ans = mul(ans, 3);
  for (int cnt = n / 2 + 1; cnt <= n; ++cnt) {
    int cur = mul(C(n, cnt), p2[n - cnt]);
    sub(ans, mul(cur, 2));
  }
  cout << ans << '\n';
}



Measured memory_bytes: 117504
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007

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

	ll N,W;
	cin>>N>>W;
	VI v(N);
	VI w(N);
	REP(i,N)cin>>v[i]>>w[i];
	int dp[101][100001]={0};
	for(int i=N-1;i>=0;i--){
		REP(j,W+1){
			if(j<w[i])
				dp[i][j]=dp[i+1][j];
			else
				dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
		}
	}
	cout<<dp[0][W]<<endl;
	
	return 0;
}


Measured memory_bytes: 42680
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int H, W;
    cin>>H>>W;
    vector<string> arr(H);
    for(int i=0;i<H;++i){
        cin>>arr[i];
    }
    int ansnum = 0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(arr[i][j]=='.')ansnum++;
        }
    }
    queue<pair<int, int> > que;
    queue<int> numque;
    que.push(make_pair(0, 0));
    numque.push(1);
    map<pair<int, int>, int> past;
    pair<int, int> state;
    int num;
    int x, y;
    int ans = -1;
    while(!que.empty()){
        state = que.front();que.pop();
        num = numque.front();numque.pop();
        x = state.se;
        y = state.fi;
        if((x==W-1) & (y==H-1)){
            ans = num;
            break;
        }
        if(past[make_pair(y, x)]>0)continue;
        past[make_pair(y, x)] = 1;
        if(x-1>=0){
            if((arr[y][x-1]=='.') & (past[make_pair(y, x-1)]==0)){
                que.push(make_pair(y, x-1));
                numque.push(num+1);
            }
        }
        if(x+1<W){
            if((arr[y][x+1]=='.') & (past[make_pair(y, x+1)]==0)){
                que.push(make_pair(y, x+1));
                numque.push(num+1);
            }
        }
        if(y-1>=0){
            if((arr[y-1][x]=='.') & (past[make_pair(y-1, x)]==0)){
                que.push(make_pair(y-1, x));
                numque.push(num+1);
            }
        }
        if(y+1<H){
            if((arr[y+1][x]=='.') & (past[make_pair(y+1, x)]==0)){
                que.push(make_pair(y+1, x));
                numque.push(num+1);
            }
        }
    }
    if(ans==-1)cout<<-1<<endl;
    else cout<<ansnum-ans<<endl;
}



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

using namespace std;

int main(){
  string s;
  cin >> s;
  string a = "";
  int a_count = 0;
  string b = "";
  int b_count = 0;
  
  for(int i=0; i<4; i++){
    if(a == ""){
      a = s.substr(i,1);
      a_count++;
    } else if(a == s.substr(i,1)){
      a_count++;
    } else if(b == ""){
      b = s.substr(i,1);
      b_count++;
    } else if(b == s.substr(i,1)){
      b_count++;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  
  if((a_count==2) && (b_count==2)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
typedef long long ll;
const int N=200005;
int n,a[N],b[N];
using namespace std;

inline int read()
{
	char c;int x;
	while (c=getchar(),c<'0' || c>'9');x=c^'0';
	while (c=getchar(),c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x;
}
void write(int x)
{
	if (x==0) return;
	write(x/10);
	putchar((x%10)+'0');
}

int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	scanf ("%d",&n);
	int i,j,k;
	for (i=1;i<=n;i++) a[i]=read();
	for (i=1,j=n,k=1;k<=n;k++)
	if (k&1) b[i++]=a[n-k+1];
	else b[j--]=a[n-k+1];
	for (i=1;i<=n;i++) printf ("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
long long int x,y,z,k,ans,flag,l=-1,lm;
int main()
{
	scanf("%lld",&x);                                                                                                                                                          
	for(int i=1;i<=x;i++)
	{
		scanf("%lld",&y);
		if(y==0)
		{
			lm=0;
			l=-1;
			continue;
		}
		if(lm==1)
		{
			ans++;
			y--;
		}
		ans+=y/2;
		if(y%2==0)
			lm=0;
		else
			lm=1;
		
	}
	printf("%lld",ans);
}



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

using namespace std;

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

	if(a == 1 and b == 1) printf("1000000\n");
	else {
		int ans = 0;
		for(int i = 0; i < 2; i++) {
			if(a == 1) ans += 300000;
			else if(a == 2) ans += 200000;
			else if(a == 3) ans += 100000;
			swap(a, b);
		}
		printf("%d\n", ans);
	}
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int a, b, c; cin >> a >> b >> c;
    V<int> v({a, b, c});
    sort(ALL(v));
    cout << v[2] * 10 + v[1] + v[0] << endl;

    return 0;
}


Measured memory_bytes: 3608
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        if (Integer.parseInt(line[0]) % 2 == 0 || Integer.parseInt(line[1]) % 2 == 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//#include <math.h>
signed main(void) 
{
    ll k, n;
    
    ll sum = 0;
    cin >>n >>k;
    vll a(n);
    
    rep (i, n) {
        cin >>a[i];
    }
    sort(a.rbegin(), a.rend());
    rep (i, n) {
        if (i >= k) {
            
            sum += a[i];
        }
        
    }
    
    cout <<sum;
    return 0;
}

Measured memory_bytes: 4776
#include<stdio.h>
#include<stdlib.h>
#define min(p,q)((p)<(q)?(p):(q))
#define max(p,q)((p)>(q)?(p):(q))
#define chmax(p,q)(p<(q)?p=(q),1:0)
int l[100010],r[100010];
int idx[100010];
int migi[100010],hidari[100010];
int c(const void*p,const void*q){
	if(migi[*(int*)p]>migi[*(int*)q])return -1;
	return 1;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",l+i,r+i);
	for(int i=0;i<n;i++)r[i]++;
	int lmax=0,rmin=0;
	for(int i=0;i<n;i++){
		if(l[i]>l[lmax])lmax=i;
		if(r[i]<r[rmin])rmin=i;
	}

	int ans=0;
	for(int i=0;i<n;i++)if(i!=lmax)chmax(ans,r[i]-l[i]);
	ans+=max(r[rmin]-l[lmax],0);
	if(lmax==rmin){
		printf("%d",ans);
		return 0;
	}

	for(int i=0;i<n;i++){
		migi[i]=max(min(r[i],r[lmax])-l[lmax],0);
		hidari[i]=max(r[rmin]-max(l[rmin],l[i]),0);
		idx[i]=i;
	}
	qsort(idx,n,sizeof(int),c);
	for(int i=n-2;i>=0;i--)hidari[idx[i]]=min(hidari[idx[i]],hidari[idx[i+1]]);
	for(int i=0;i<n-1;i++)chmax(ans,migi[idx[i]]+hidari[idx[i+1]]);
	printf("%d",ans);
}

Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (b == 100) {
    b++;
  }
  cout << b;
  
  for (int i = 0; i < a; ++i) {
    cout << "00";
  }
  
  cout << endl;
  
  return 0;
}

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

using namespace std;

const int N = 100100;

int cnt[N];

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      cnt[x]++;
   }
   int ans = 0;
   for (int i = N - 1; i >= 0; --i) {
      cnt[i] += cnt[i + 1];
      if (cnt[i] == (n / 2)) {
         ++ans;
      }
   }
   cout << ans;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

const ll inf = (ll)2e16;
const ll maxn = (ll)5e3 + 10;

ll dp[maxn];
ll inv[maxn];
ll p[maxn];
ll n, a, b;


void solve(){
    fill(dp, dp + maxn, inf);
    cin >> n >> a >> b;
    for(ll i = 0; i < n; ++i){
        cin >> p[i];
        p[i]--;
    }
    p[n] = n;
    for(ll i = 0; i <= n; ++i){
        inv[p[i]] = i;
    }
    for(ll i = 0; i <= n; ++i){
        ll adda = 0, addb = 0;
        for(ll j = p[i] - 1; j >= -1; --j){
            if(j == -1){
                dp[i] = min(dp[i], adda * a + addb * b);
                continue;
            }
            dp[i] = min(dp[i], dp[inv[j]] + adda * a + addb * b);
            if(j != p[i]){
                if(inv[j] < i){
                    adda++;
                } else if(inv[j] > i) {
                    addb++;
                }
            }
        }
    }
    cout << dp[n] << "\n";
}

signed main(){
    srand(time(0));
    ll t = 1;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else

    #endif// DEBUG
    while(t--){
        solve();
    }
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	int A;
	int B;
	int C;
	int D;

	scanf("%d %d %d",&A,&B,&C);
    D=A+B+C;
    if(D>=22){
    	printf("bust");
    }else{
    	printf("win");
    }
    return 0;
}

Measured memory_bytes: 128
using System;


namespace ConsoleApplication48
{
    class DICE
    {
        int kari = 0;
        public void S(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[4];
            sai2[4] = sai2[5];
            sai2[5] = sai2[1];
            sai2[1] = kari;
        }
        public void N(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[1];
            sai2[1] = sai2[5];
            sai2[5] = sai2[4];
            sai2[4] = kari;
        }
        public void W(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[2];
            sai2[2] = sai2[5];
            sai2[5] = sai2[3];
            sai2[3] = kari;
        }
        public void E(int[] sai2)
        {
            kari = sai2[0];
            sai2[0] = sai2[3];
            sai2[3] = sai2[5];
            sai2[5] = sai2[2];
            sai2[2] = kari;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            //
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int d = int.Parse(input[3]);
            int e = int.Parse(input[4]);
            int f = int.Parse(input[5]);
            //???????????????????????????????????????
            DICE dice = new DICE(); 
            //????????????????????????
            string[] input2 = Console.ReadLine().Split(' ');
            //sai2??????????????????
            int[] sai2 = new int[6];
            for (int x = 0; x < 6; x++)
            {
                sai2[x] = int.Parse(input2[x]);
            }
            int count = 0;
            //n

            for (int n = 0; n < 4; n++)
            {
                dice.N(sai2);

                for (int w = 0; w < 4; w++)
                {
                    dice.W(sai2);
                    for (int s = 0; s < 4; s++)
                    {
                        dice.S(sai2);
                        for (int e2 = 0; e2 < 4; e2++)
                        {
                            dice.E(sai2);
                            
                            if (a == sai2[0] && b == sai2[1] && sai2[2] == c && sai2[3] == d && e == sai2[4] && f == sai2[5])
                            {
                                count = count + 1;
                                
                            }
                            if (count == 6)
                            {
                                break;
                            }
                            
                        }
                    }
                }
            }

            
            
           //
            if (count >= 6)
            {
                 Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

       

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll num=1, ans=0, cnt=0, sum=0;

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

  ll n, m, q, watch;
  cin >> n >> m >> q;
  vl a(q), b(q), c(q), d(q);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  if(m==1) {
    rep(i, q) if(!c[i]) ans += d[i];
    cout << ans << newl;
    return 0;
  }
  
  vl A(n+1, 1);
  while(A[0] == 1) {
    sum = 0;
    rep(i, q) if(A[b[i]]-A[a[i]] == c[i]) sum += d[i];
    chmax(ans, sum);
    
    watch = n;
    while(A[watch] == m) watch--;
    A[watch]++;
    for(ll i=n; i>watch; i--) A[i] = A[watch];
  }
  
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
    string s, p, check;
    bool a = false;

    cin >> s >> p;
    int ssize = s.size();
    rep(i, s.size())
    {
        if (s[i] == p[0])
        {
            check.clear(); //checkデータの初期化

            rep(j, p.size())
            {
                if (ssize > (i + j))
                {
                    check += s[i + j];
                }
                else if (ssize <= (i + j)) //s.size() - (i + j) <= 0は false(0以下)となってしまうので× s.sizeはunsignで入れられない。
                {
                    check += s[i + j - ssize];
                }

                if (check == p)
                {
                    a = true;
                    break;
                }
            }
        }

        if (a == true) //for(int i = 0 ; i< s.size() || a != true ; i ++)でも可能?
        {
            break;
        }
    }

    if (a == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(long i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    int x[N],y[N],a[N];
    rep(0,i,N)a[i]=i;
    rep(0,i,N){
        cin>>x[i]>>y[i];
    }
    double sum=0;
    long c=0;
    do{
        rep(0,i,N-1){
            sum+=1.0*sqrt((x[a[i+1]]-x[a[i]])*(x[a[i+1]]-x[a[i]])+(y[a[i+1]]-y[a[i]])*(y[a[i+1]]-y[a[i]]));
        }
        ++c;
    }while(next_permutation(a,a+N));
    cout<<fixed<<setprecision(10)<<1.0*sum/c<<endl;
}


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

int main(){
    int n;

    while(cin >> n, n != 0){
        int a_point = 0, b_point = 0;
        for(int i=1; i<=n; i++){
            int tmp1, tmp2;
            cin >> tmp1 >> tmp2;
            if(tmp1 > tmp2){
                a_point += tmp1 + tmp2;
            }else if (tmp1 < tmp2){
                b_point += tmp1 + tmp2;
            }else{
                a_point += tmp1;
                b_point += tmp2;
            }
        }
        cout << a_point << " " << b_point << endl;
    }
    return 0;
}

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

int main(){
	string a;
	getline (cin , a);
	for(int i=0 ; i<1200 ; i++){
		if(a[i]=='\0') break;
		if(a[i]>='a' && a[i]<='z'){
			a[i]-=0x20;
		} else if (a[i]>='A' && a[i]<='Z'){
			a[i]+=0x20;
		}
		if (a[i]==' '){
			cout << " ";
		} else {
		cout << a[i];
		}	
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int odd = 0;
		
		for(int i=1; i<=N; i++) {
			String tmp = String.valueOf(i);
			if(tmp.length() % 2 != 0) {
				odd++;
			}
		}
		System.out.println(odd);
		sc.close();
	}
}

Measured memory_bytes: 30420
import java.util.Scanner;

class Main{
	public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
		int h,w,i,j;
		for(;;){
			h=stdIn.nextInt();
			w=stdIn.nextInt();
			if(h<1&&w<1)break;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++)System.out.print("#");
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 35604
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()


ll N;
vector<ll> ANS;
ll a;

//にぶたん
//右にあるもののうち一番左を求める
int searchRight(){
	int l = 0, m, r = N - 1;
	//isTrue()はbool型関数, 右側ならtrue, 左側ならfalse
	if(ANS[l] < a/*isTrue(l)*/)return l;//全部右にある
	if(ANS[r] >= a/*!istrue(r)*/)return -1;//ひとつも右にない
	while(true){
		m = (l + r) / 2;
		if(ANS[m] < a/*isTrue(m)*/){
			if(ANS[m - 1] >= a/*!isTrue(m - 1)*/){
				return m;
			}
			r = m - 1;
		}
		else{
			l = m + 1;
		}
	}
}

int main(){

	cin >> N;
	ANS = vector<ll>(N, -1);

	for(ll i = 0; i < N; i ++){
		cin >> a;
		int pos = searchRight();
		ANS[pos] = a;
	}
	ll cnt = 0;
	for(ll i = 0; i < N; i ++){
		if(ANS[i] != -1)cnt ++;
		else break;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n, m] <- readInts
  input <- readNIntegers n
  print $ solve n m input

solve :: Int -> Int -> [[Integer]] -> Integer
solve n m input = maximum $ map gettopmsum [0 .. 7]
  where
    gettopmsum :: Int -> Integer
    gettopmsum flag = sum $ take m $ reverse $ sort $ prepro flag
    prepro flag = map (\x -> sum $ map (\y -> (fst y) (snd y)) $ zip prefuncs x) input
      where
        prefuncs = map (\x ->
          if flag .&. (bit x) /= 0
            then ((-) 0)
            else ((+) 0)
          ) [0 .. 2]

comb :: [a] -> Int -> [[a]]
comb _ 0     = [[]]
comb [] _     = []
comb (x:xs) n = map (x:) (comb xs (n-1)) ++ comb xs n

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx

while :: Monad m => m Bool -> m () -> m ()
while cond body = do
  b <- cond
  when b $ do
    body
    while cond body


Measured memory_bytes: 1532
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let s: Vec<char> = iter.next().unwrap().chars().collect();

    let mut score = 0;
    for i in 0..n - 1 {
        if s[i] == s[i + 1] {
            score += 1;
        }
    }

    let ans = std::cmp::min(score + 2 * k, n - 1);
    // let mut l: Vec<&str> = vec![];
    // let mut r: Vec<&str> = vec![];
    //
    // let first = s[0];
    // let mut left = 0;
    // let mut right = 0;
    //
    // for i in 0..(s.len()-1) {
    //     if s[i] == s[i + 1] {
    //         right += 1;
    //     } else {
    //         if s[left] == 'L'{l.push(s[])}
    //     }
    //
    //     if s[i] == s[i - 1] {
    //         if s[i] == 'L' {
    //             l.push('L')
    //         } else {
    //             r.push('R')
    //         };
    //     }
    // }

    println!("{}", ans);
}


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

int main(void){
    int n, k;
    cin >> n >> k;
    
    int i = 1;
    while (true) {
        if (n >= pow(k, i)) {
            i++;
            continue;
        }
        break;
    }
    
    cout << i << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
long long minb=10000000000,a,b,n;
bool flag;
long long ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&a,&b);
		ans+=b;
		if(a>b) {
			minb=min(b,minb);
			flag=1;
		}
		if(a!=b)
			flag=1;
	}
	if(flag)
		printf("%lld",ans-minb);
	else
		puts("0");
	
}

Measured memory_bytes: 128
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a,b,c,d,e;
  for(;;){
    cin>>a;
    if(a==0)
      break;
    cin>>b>>c>>d>>e;
    if(c*e>b){
      if(b/c+(b-b/c*c)/d<a){
	i=b/c;
	j=a-i;
	while(i>0&&i*c+j*d>b){
	  i--;
	  j++;
	}
	if(i)
	  cout<<i<<" "<<j<<endl;
	else
	  cout<<"NA"<<endl;
      }else{
	if(b/c)
	  cout<<b/c<<" "<<(b-b/c*c)/d<<endl;
	else
	  cout<<"NA"<<endl;
      }
    }else{
      if(e+(b-c*e)/d<a){
	i=e;
	j=a-i;
	while(i>0&&i*c+j*d>b){
	  i--;
	  j++;
	}
	if(i)
	  cout<<i<<" "<<j<<endl;
	else
	  cout<<"NA"<<endl;
      }else{
	if(e)
	  cout<<e<<" "<<(b-c*e)/d<<endl;
	else
	  cout<<"NA"<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
import itertools
ans=0
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    A=list(A)
    s=0
    
    for i in range(Q):
        if A[b[i]-1]-A[a[i]-1]==c[i]:
           s+=d[i]

           ans=max(ans,s)
print(ans)        
        


Measured memory_bytes: 9224
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;
    set<int> s = {A, B};

    rep(i, 1, 4){
        if(s.find(i) == end(s)){
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
t = [int(_) for _ in input().split()]
ans = T * N
if N == 1:
    ans = T
else:
    for i in range(1, N):
        if t[i] - t[i-1] < T:
            ans -= T - (t[i] - t[i-1])
print(ans)

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

int main(){
  //標準入力を受け取る
  int N;
  cin >> N;
  vector<string> vec1(N);
  for(int i = 0; i < vec1.size();i++){
    cin >> vec1.at(i);
  }
  int M;
  cin >> M;
  vector<string> vec2(M);
  for(int i = 0; i < vec2.size();i++){
    cin >> vec2.at(i);
  }
  int max = 0,c1 = 0,c2 = 0;
  for(int i = 0; i < vec1.size();i++){
    //何円プラス求める
    c1 = 0;
    c2 = 0;
    for(int j = 0;j < vec1.size();j++){
      if(vec1.at(i) == vec1.at(j)){
        c1++;
      }
    }
    //何円失うか求める
    for(int j = 0; j < vec2.size();j++){
      if(vec1.at(i) == vec2.at(j)){
        c2++;
      }
    }
    if((c1-c2) > max){
      max = c1 - c2;
    }
  }
  cout << max << endl; 
}

Measured memory_bytes: 256
<?PHP
fscanf(STDIN, "%d", $d);
$nums = explode(' ', trim(fgets(STDIN)));

$count= 0;
for($i = 1; $i < count($nums) - 1; $i++) {
  if (($nums[$i-1] < $nums[$i]) && ($nums[$i] < $nums[$i+1])) {
    $count++;
  }  else if  (($nums[$i-1] > $nums[$i]) && ($nums[$i] > $nums[$i+1])) {
    $count++;
  }
}

echo $count;

Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
using ll = long long;
using namespace std;
using pii = pair<int, int>;

int X, Y;
int main() {
	cin >> X >> Y;
	cout << X + Y / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
 int N;cin>>N;
  vector<int64_t>a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int64_t ans=0;
  for(int i=0;i<N;i++)
    if(i%2==0 && (a.at(i))%2==1)
      ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

seen = [-1] * (N + 1)
seen[1] = 1
node = [1]
while node:
    s = node.pop()
    x = seen[s]
    for t in edge[s]:
        if seen[t] == -1:
            seen[t] = 1 ^ x
            node.append(t)
        elif seen[t] == 1 ^ x:
            continue
        else:
            ans = N * (N - 1) // 2 - M
            print(ans)
            exit()

X = seen.count(1)
ans = 0
for i in range(1, N + 1):
    if seen[i] == 1:
        continue
    ans += X - len(edge[i])
print(ans)

Measured memory_bytes: 22064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


ll x[1010], y[1010], z[1010];

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = 0;
    for (int bits = 0; bits < (1<<3); bits++){
        vector<ll> vtmp;
        rep(i, n){
            ll tmp = 0;
            if (bits&(1<<0)) tmp += x[i];
            else tmp -= x[i];
            if (bits&(1<<1)) tmp += y[i];
            else tmp -= y[i];
            if (bits&(1<<2)) tmp += z[i];
            else tmp -= z[i];
            vtmp.push_back(tmp);
        }
        sort(vtmp.begin(), vtmp.end(),greater<ll>());
        ll cnt = 0;
        rep(i, m) cnt += vtmp[i];
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int a;
    cin >> a ;
    
    if (( 400 <= a) && (a <= 599)){
        cout << "8" << endl;
    }
    else if(( 600 <= a) && (a <= 799)) {
        cout << "7" << endl;
    }
    else if (( 800 <= a) && (a <= 999)) {
        cout << "6" << endl;
    }
    else if (( 1000 <= a) && (a <= 1199)) {
        cout << "5" << endl;
    }
    else if(( 1200 <= a) && (a <= 1399)) {
        cout << "4" << endl;
    }
    else if (( 1400 <= a) && (a <= 1599)) {
        cout << "3" << endl;
    }
    else if (( 1600 <= a) && (a <= 1799)) {
        cout << "2" << endl;
    }
    else if (( 1800 <= a) && (a <= 1999)) {
        cout << "1" << endl;
    }
return 0;
} 

Measured memory_bytes: 3636
n,q=map(int,input().split())
s=input()
t=[0]*n
a=0
for i in range(n-1):
    if s[i:i+2]=='AC':
        a+=1
    t[i+1]=a
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])


Measured memory_bytes: 7852
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <queue>
#include <limits.h>
#include <algorithm>
#include <deque>

using namespace std;

class flow {
private:
	class edge {
	public:
		int to;
		long long cap;
		int rev;  //逆辺がG[to]のどこにいるか
		edge(int t, int c, int r) :to(t), cap(c), rev(r) {}
		edge() :to(0), cap(0), rev(0) {}
	};
	int V;
	vector<vector<edge>>* G;
	vector<int>* lev;   //始点sからの距離
	vector<int>* iter;   //どの辺まで見たか
	//幅優先で最短距離
	void bfs(int s) {
		for (int n = 0; n < V; n++)lev->at(n) = -1;
		queue<int> que;
		lev->at(s) = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (int i = 0; i < G->at(v).size(); i++) {
				edge& e = G->at(v)[i];
				if (e.cap > 0 && lev->at(e.to) < 0) {
					lev->at(e.to) = lev->at(v) + 1;
					que.push(e.to);
				}
			}
		}
	}
	//増加パスの検索&流す
	int dfs(int v, int t, long long f) {
		if (v == t)return f;
		for (int& i = iter->at(v); i < G->at(v).size(); i++) {
			edge& e = G->at(v)[i];
			if (e.cap > 0 && lev->at(v) < lev->at(e.to)) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G->at(e.to)[e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
public:
	flow(int v) :V(v) {
		G = new vector<vector<edge>>;
		G->resize(V);
		lev = new vector<int>;
		iter = new vector<int>;
		lev->resize(V);
		iter->resize(V);
	}
	~flow() {
		delete G;
		delete lev;
		delete iter;
	}
	//辺追加
	void addEdge(int from, int to, int cap) {
		G->at(from).push_back(edge(to, cap, G->at(to).size()));
		G->at(to).push_back(edge(from, 0, G->at(from).size() - 1));
	}
	//最大流問題を解く(Dinic)
	//O(EV^2)
	static int maxFlow(flow& F, int s, int t) {
		int flowint = 0;
		for (;;) {
			F.bfs(s);
			if (F.lev->at(t) < 0)return flowint;
			int a = 0;
			for (int v = 0; v < F.V; v++)F.iter->at(v) = 0;
			int f;
			while ((f = F.dfs(s, t, LLONG_MAX)) > 0) {
				flowint += f;
			}
		}
	}
};


int N;
typedef pair<int, int> pii;
vector<pii> red, blue;
void solve() {
	cin >> N;
	flow F(2 * N + 2);
	for (int i = 1; i <= N; i++) {
		F.addEdge(0, i, 1);
		F.addEdge(i + N, 2 * N + 1, 1);
	}
	red.resize(N); blue.resize(N);
	for (int n = 1; n <= N; n++) {
		cin >> red[n - 1].first >> red[n - 1].second;
	}
	for (int n = 1; n <= N; n++) {
		cin >> blue[n - 1].first >> blue[n - 1].second;
	}
	for (int r = 0; r < N; r++) {
		for (int b = 0; b < N; b++) {
			if (red[r].first < blue[b].first && red[r].second < blue[b].second) {
				F.addEdge(r + 1, N + b + 1, 1);
			}
		}
	}
	cout << flow::maxFlow(F, 0, 2 * N + 1) << endl;
	return;
}

Measured memory_bytes: 512
import java.util.*;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int p = 0;
		
		for(int i = 0; i < n; i++)
		{
			int l = scan.nextInt();
			int r = scan.nextInt();
			 p += r - l + 1;
		}
		
		System.out.println(p);

		scan.close();
	}
}


Measured memory_bytes: 27208
def maxf(n):
    a = list(map(int, list(n)))
    for i, item in enumerate(a):
        if i == 0 and item != 9:
            if a[i+1:] == [9]*(len(a)-1):break
            a[i] -=1
            a[i+1:] = [9]*(len(a)-1)
            break
        elif item != 9:
            a[i-1] -= 1
            a[i:] = [9]*(len(a)-i)
            break
    return sum(a)

print(maxf(input()))


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  ll A, B, C;
  int X, Y;
  cin >> A >> B >> C >> X >> Y;
  priority_queue<ll, vector<ll>, greater<ll>> value;
  for (int i = 0; i <= 100000; i++) {
    ll sum = i*2*C + max(0, X-i) * A + max(0, Y-i) * B;
    value.push(sum);
  }
  cout << value.top() << endl;
}


Measured memory_bytes: 1400
#include <iostream>

using namespace std;

bool f(string s) {
    return s[0] != s[1] && s[0] != s[2] && s[1] != s[2];
}

int main() {

    string s;
    cin >> s;

    if (f(s)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

struct Testmony {
    n: usize,
    x: Vec<usize>,
    y: Vec<usize>,
}

fn read(iter: &mut std::str::SplitWhitespace) -> Testmony {
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut t = Testmony {
        n: n,
        x: vec![],
        y: vec![],
    };
    for _ in 0..n {
        let x: usize = iter.next().unwrap().parse().unwrap();
        let y: usize = iter.next().unwrap().parse().unwrap();
        t.x.push(x - 1);
        t.y.push(y);
    }
    return t;
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let v: Vec<Testmony> = (0..n).map(|_| read(&mut iter)).collect();
    let mut ans = 0;
    for b in 0..1 << n {
        let mut a = vec![0; n];
        let mut cnt = 0;
        for i in 0..n {
            a[i] = (b >> i) & 1;
            cnt += (b >> i) & 1;
        }
        if ans >= cnt {
            continue;
        }
        let mut satisfy = true;
        for i in 0..n {
            if a[i] == 1 {
                let t = &v[i];
                for j in 0..t.n {
                    if a[t.x[j]] != t.y[j] {
                        satisfy = false;
                        break;
                    }
                }
            }
        }
        if satisfy {
            ans = cnt;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
long long int cnt=0;
cin>>n;
long long int a[n+1],b[n];
for(int i=0;i<n+1;i++){
  cin>>a[i];
}
for(int i=0;i<n;i++){
  cin>>b[i];
}
long long int kkk;
for(int i=0;i<n;i++){
if(b[i]>=a[i]+a[i+1]){
  cnt = cnt + a[i]+a[i+1];
  a[i+1]=0;
}
else if(b[i]>a[i]){
cnt =  cnt + b[i];
a[i+1] = a[i+1] - (b[i]-a[i]);
}
else {
  cnt = b[i] + cnt;
}

}
cout<<cnt<<endl;
    return 0;
}


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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};

int main(){
	int n,m;cin>>n>>m;
	Fact fac(3*m+n);
	ll ans=0;
	for(int s=m%2;s<=min(n,m);s+=2){
		ll a=fac.nCr(n,s);
		ll b=fac.nCr((3*m-s)/2+n-1,n-1);
		if((3*m-s)/2>=m)(b+=MOD-fac.nCr((3*m-s)/2-m+n-1,n-1)*s%MOD)%=MOD;
		if((3*m-s)/2>=m+1)(b+=MOD-fac.nCr((3*m-s)/2-m-1+n-1,n-1)*(n-s)%MOD)%=MOD;
		(ans+=a*b)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 78336