akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int a[45];
int b[45];
int c[45];

int dp[45][405][405];

int min(int x,int y){
	if(x<y){return x;}
	else{return y;}
}

int main(){

	int N,Ma,Mb;

	scanf("%d %d %d",&N,&Ma,&Mb);

	int i,j,k;

	for(i=0;i<N;i++){
	scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}

	for(i=0;i<=40;i++){
		for(j=0;j<=400;j++){
			for(k=0;k<=400;k++){
				dp[i][j][k]=114514;
			}
		}
	}

	dp[0][0][0]=0;

	for(i=0;i<N;i++){
		for(j=0;j<=400;j++){
			for(k=0;k<=400;k++){
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				if(j+a[i]<=400&&k+b[i]<=400){
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
				}
			}
		}
	}

	int ans=114514;

	for(i=1;;i++){
		if(Ma*i>400||Mb*i>400){break;}
		for(j=0;j<=N;j++){
		ans=min(ans,dp[j][Ma*i][Mb*i]);
		}
	}

	if(ans==114514){printf("-1\n");}
	else{printf("%d\n",ans);}

	return 0;
}

Measured memory_bytes: 26752
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k
ti di

k n 10^5
ti n
di 10^9
 */
typedef pair<ll,int> P; //d,t
int n,k;
P ps[100000];
bool af[100000];
ll alt[100000];

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

  REP(i,n){
    int t;
    ll d;
    cin>>t>>d;
    t--;
    ps[i] = P(d,t);
  }

  sort(ps,ps+n,greater<P>());

  int tnum=0;
  int cnt=1;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  REP(i,n){
    if(i<k){
      alt[0] += ps[i].first;
    }

    if(!af[ps[i].second]){
      af[ps[i].second] = true;
      if(i>=k){
        if(!que.empty()){
          ll q = que.top();
          que.pop();
          alt[cnt] = alt[cnt-1] - q + ps[i].first;
          LOG("alt[%d]=%lld\n", cnt, alt[cnt]);
          cnt++;
        }
      } else {
        tnum++;
      }
    } else {
      if(i<k)
        que.push(ps[i].first);
    }
  }

  ll ans=0;
  REP(i,cnt){
    ans = max(ans, pow(tnum+i,2) + alt[i]);
    LOG("%lld\n",alt[i]);
  }

  cout<< ans <<endl;

  return 0;
}


Measured memory_bytes: 2556
using System;

namespace _136c
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] H = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            bool flag = true;
            // bool minus_flag = false;
            if( N == 1){
                
            }else{
                for(int i = 1; i <N ; i++){
                    if(H[i] < H[i-1]){
                        flag = false;
                    }else if(H[i] > H[i-1]){
                        H[i] -= 1;
                    }
                }
            }
            Console.WriteLine(flag?"Yes":"No");
        }
    }
}


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

double p[3005];
double dp[3005][3005];
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> p[i];

  dp[0][0] = 1;

  for(int i = 0; i < n; i++) {
    
    for(int j = 0; j <= i; j++) {
      dp[i+1][j+1] += p[i] * dp[i][j];
      dp[i+1][j] += (1 - p[i]) * dp[i][j];
    }
  }

  double ans = 0;

  for(int i = 1; i <= n; i++) {
    if(i >= n / 2 + 1) ans += dp[n][i];
  }

  cout << fixed << setprecision(10) <<   ans << endl;
}


Measured memory_bytes: 68992
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]

    ans = 1
    a = K
    while N >= a:
        a *= K
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e17;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,ans,a,b,c,d,e,h,r,l,q;
ll k;
ll x[500005], y[500005], z[500005];
char s[500005], t[500005];



int main(){
    cin >> h >> n;
    for(ll i=0;i<n;i++){
        cin >> a;
        sum += a;
    }
    Yes(sum >= h);
    return 0;
}


















Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    int ans = 0;
    int p = 0;
    for(int i = 0; i < (n - 1); i++) {
      if(h[i] >= h[i + 1]) {
        p++;
      } else {
        ans = Math.max(ans, p);
        p = 0;
      }
    }
    ans = Math.max(ans, p);
    System.out.println(ans);
  }
}

Measured memory_bytes: 59624
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    if (n >= m){
      System.out.println(0);
      return;
    }

    long[] g = new long[m];
    for (int i=0;i<m;i++){
      g[i] = scan.nextLong();
    }
    Arrays.sort(g);

    long[] g1 = new long[m-1];
    for (int j=0;j<m-1;j++){
      g1[j] = g[j+1]-g[j];
    }

    Arrays.sort(g1);
    long sum = g[m-1]-g[0];

    for (int k=0;k<n-1;k++){
      sum -= g1[m-2-k];
    }

    System.out.println(sum);
  }
}


Measured memory_bytes: 61204
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }

        a[i][n - 1] = i;
    }

    queue<int> que;
    for (int i = 0; i < n; i++) {
        que.push(i);
    }

    vector<int> idx(n, 0);

    int res = 0;
    while (!que.empty()) {
        res++;

        queue<int> que_next;
        vector<bool> pushed(n, false);

        while (!que.empty()) {
            int p = que.front();
            que.pop();

            int q = a[p][idx[p]];
            if (p == a[q][idx[q]] && !pushed[p] && !pushed[q]) {
                pushed[p] = true;
                pushed[q] = true;

                if (idx[p] < n - 1) {
                    que_next.push(p);
                    idx[p]++;
                }

                if (idx[q] < n - 1) {
                    que_next.push(q);
                    idx[q]++;
                }
            }
        }

        que = que_next;
    }

    res--;

    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (idx[i] < n - 1) {
            ok = false;
        }
    }

    cout << (ok ? res : -1) << endl;
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double xp = sc.nextDouble();
			double yp = sc.nextDouble();

			// 三角形ABCの面積
			double s = TriangleArea(x3 - x1, y3 - y1, x2 - x1, y2 - y1);
			double s1 = TriangleArea(xp - x1, yp - y1, x2 - x1, y2 - y1);
			double s2 = TriangleArea(xp - x1, yp - y1, x3 - x1, y3 - y1);
			double s3 = TriangleArea(xp - x2, yp - y2, x3 - x2, y3 - y2);

			// System.out.println((xp - x2) + " " + (yp - y2) + " " + (x3 - x2)
			// + " " + (y3 - x2));

			if (-0.001 < s - (s1 + s2 + s3) && s - (s1 + s2 + s3) < 0.001) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
		sc.close();

	}

	double TriangleArea(double x1, double y1, double x2, double y2) {

		double s = ((x1 * y2) - (x2 * y1)) * 0.5;
		if (s <= 0) {
			s *= -1;
		}

		return s;
	}

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

}

Measured memory_bytes: 21420
import java.util.Scanner
import java.io.PrintWriter

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val pw = new PrintWriter(System.out)

    val n = sc.nextInt()
    val s = sc.next()
    val sb = new StringBuilder
    for (i <- 0 until s.length) {
      sb.append(('A' + (s(i) - 'A' + n) % 26).toChar)
    }
    pw.println(sb)

    pw.flush()
  }
}

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

using namespace std;

#define int long long

int n, pw10[19], nDig, ans;

bool ok(int a, int b, int mod) { return ( ( (a % mod) + mod) % mod) == ( ( (b % mod) + mod) % mod); }

int bt(int pos, int d) {
    int ret = 0;
    if(pos == nDig / 2 + 1) {
        return (d == 0) * (nDig % 2 ? 10 : 1);
    }
    for (int sub = -9; sub < 10; ++ sub) {
        if( ok(d, sub * 9 * pw10[pos - 1], 9 * pw10[pos]) ) {
            d -= sub * (pw10[nDig - pos] - pw10[pos - 1]);
            int temp = 10 - abs(sub);
            if(pos == 1) temp --;
            ret += bt(pos + 1, d) * temp;
            d += sub * (pw10[nDig - pos] - pw10[pos - 1]);
        }
    }
    return ret;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;

    pw10[0] = 1; for (int i = 1; i < 19; ++i) pw10[i] = 10 * pw10[i - 1];
    for (int i = 1; i <= 18; ++i) nDig = i, ans += bt(1, n);

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c;
  cin>>a>>b;
  c=a*(a+1)/2+(b-1)*a;
  if(b<0&&a+b>0)cout<<c;
  else if(b<0)cout<<c-b-a+1;
  else cout<<c-b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<ll>x(N),y(N),h(N);
    REP(i,N){
        cin>>x[i]>>y[i]>>h[i];
    }
    for(int cx=0;cx<=100;cx++){
        for(int cy=0;cy<=100;cy++){
            int H=-1;
            int Hmax=2e9;
            bool flg=true;
            for(int i=0;i<N;i++){
                int d=abs(cx-x[i])+abs(cy-y[i]);
                if(h[i]>0){
                    int H2=h[i]+d;
                    if(H>0&&H!=H2){
                        flg=false;
                        break;
                    }
                    else{
                        H=H2;
                    }
                }
                else{
                    Hmax=min(Hmax,d);
                }
            }
            if(flg&&H<=Hmax){
                cout<<cx<<" "<<cy<<" "<<H<<endl;;
                return 0;
            }
        }
    }
}


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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i<n; i++) {
        cin >> a[i];
    }
    int ans = INT_MAX;
    for(int i = 1; i<=100; i++) {
        int curr = 0;
        for(int j = 0; j<n; j++) {
            curr += (abs(a[j] - i) * abs(a[j] - i));
        }
        ans = min(ans, curr);
    }
    cout << ans;
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
UNDEF = -1



def dfs(r, c)
	s = [r]
	$color[r] = c
	
	while not s.empty?
		u = s.pop
		$g[u].size.times do |i|
			v = $g[u][i]
			if $color[v] == UNDEF
				$color[v] = c
				s.push(v)
			end
		end
	end
end



def assignColor()
	id = 1
	$color = Array.new($n, UNDEF)
	$n.times do |u|
		if $color[u] == UNDEF
			dfs(u, id)
			id += 1
		end
	end
end



$n, m = gets.split.map &:to_i
$g = Array.new($n){ Array.new(0) }

m.times do
	s, t = gets.split.map &:to_i
	$g[s].push(t)
	$g[t].push(s)
end

assignColor()

q = gets.to_i

q.times do
	s, t = gets.split.map &:to_i
	if $color[s] == $color[t]
		puts "yes"
	else
		puts "no"
	end
end

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

using namespace std;

int main(){
  int n,nc,count=0,countc,num=0;
  cin >> n;
  nc=n;
  while(n!=0){
        n /= 10;
        count++;
    }
  countc=count;
  if(count%2==0){
   	count--;
    count=count-count/2;
    for(int i=1;i<=count;i++){
      num+=9*pow(10,((i-1)*2));
    }
    //num+=nc-pow(10,countc-1)+1;
  }else{
    count=count-count/2;
    for(int i=1;i<count;i++){
      num+=9*pow(10,((i-1)*2));
    }
    num+=nc-pow(10,countc-1)+1;
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *a=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  a[n]=0;
  int64 sum=0;
  for(i=0;i<k;i++) sum+=a[i];
  int64 l=0;
  int64 r=0;
  for(i=k;i<n;i++) if(a[i]>0) r+=a[i];
  int64 max=l+r+MAX(sum,0);;
  for(i=1;i+k-1<n;i++){
    if(a[i-1]>0) l+=a[i-1];
    if(a[i+k-1]>0) r-=a[i+k-1];
    sum+=a[i+k-1]-a[i-1];
    max=MAX(max,l+r+MAX(sum,0));
  }
  printf("%lld\n",max);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str1,str2;
  cin>>str1>>str2;
  int k=0;
  for(int i=0; i<3; i++){
    if(str1.at(i)==str2.at(i)){
      k=k+1;
    }
  }
  cout<<k;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 3;
ll i,j,k,l,s;
bool f;
ll a[N][N],c[N],m[N],d[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    rep(i,0,N) rep(j,0,N) cin>>a[i][j],m[i] = max(m[i],a[i][j]);
    rep(i,0,m[0] + 1) rep(j,0,m[1] + 1) rep(k,0,m[2] + 1){
        d[0] = i; d[1] = j; d[2] = k;
        rep(l,0,N)
            c[l] = a[0][l] - i;
        f = 1;
        for(l = 1;l < N and f;l++){
            rep(s,0,N) if(a[l][s] - d[l] != c[s]){
                f = 0;
                break;
            }
        }
        if(f){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int count=0;
    for(int i=0;i<n;i+=2){
        if(i>=n)break;
        if(a[i]%2==1)count++;
    }
cout<<count;
return 0;
}

Measured memory_bytes: 3156
#import <stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define ABS(a) ((a)>0?(a):(-(a)))

long fl(double x) {
    long n = (long)x;
    return n + (((x != n) && (x < 0)) ? -1 : 0);
}

long r(double x) {
    double n = fl(x);
    double d = x - n;
    return ((x>=0)&&(d<0.5))||((x<0)&&(d<=0.5)) ? n : n+1;
}

int main() {
    long H,W;
    scanf("%ld %ld",&H,&W);
    if (W%3==0 || H%3==0) {
        printf("0");
        return 0;
    }
    long min = MIN(H,W);
    if (H%2==0) {
        long x = r(2.0*W/3);
        min = MIN(min, ABS(H/2*x - (W-x)*H));
    }
    if (W%2==0) {
        long x = r(2.0*H/3);
        min = MIN(min, ABS(W/2*x - (H-x)*W));
    }
    if (H%2==1) {
        long n = (H-1)/2;
        for (long x=MAX(1,2.0*W/3-2);x<=MIN(W-1,2.0*W/3+2);x++) {
            min = MIN(min,MAX(ABS((W-x)*H-(n+1)*x),ABS((W-x)*H-n*x)));
        }
    }
    if (W%2==1) {
        long n = (W-1)/2;
        for (long x=MAX(1,2.0*H/3-2);x<=MIN(H-1,2.0*H/3+2);x++) {
            min = MIN(min,MAX(ABS((H-x)*W-(n+1)*x),ABS((H-x)*W-n*x)));
        }
    }
    printf("%ld",min);
}


Measured memory_bytes: 7500
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	string a;
	cin >> a;
	cout << a.substr(0, 3) << '\n';
}



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

long long N;
long long ans=0;

int main(){
	scanf("%lld",&N);
	long long n=sqrt(N);
	for(long long i=1;i<=n;i++){
		if(N%i==0){
			if(i<N/i-1) ans+=N/i-1;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

int main(){
  int n; cin >> n;
  double x;
  string u;
  double ans =0;
  for(int i=0;i<n;i++){
    cin >> x >> u;
    if( u=="JPY"){
      ans += x;
    }else if(u=="BTC"){
      ans += x*380000.0;
    }
  }
  cout << ans << endl;
}

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

const int MAX_N = 8;
std::vector<int> edge[MAX_N];
std::vector<int> visitList;

int64_t dfs(const int& x, const int& nodeNum, const int& last = -1)
{
  visitList.push_back(x);
  int64_t ret = 0;
  for (const auto& to : edge[x])
  {
    bool isVisited = false;
    for (const auto& visited : visitList)
    {
      if(to == visited)
      {
        isVisited = true;
        break;
      }
    }
    if (isVisited == true) continue;
    ret += dfs(to, nodeNum, x);
  }

  if (visitList.size() == nodeNum)
  {
    ++ret;
  }
  visitList.pop_back();
  return ret;
}

int main()
{
  int n, m;
  std::cin >> n >> m;
  for (int i = 0; i < m; ++i)
  {
    int u, v;
    std::cin >> u >> v; --u; --v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int64_t ans = dfs(0, n);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define l first
#define r second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int N=100010;
ll n,x,m;
int st[N];
ll s[N];
int main()
{
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>x>>m;
        ll l,r;
        for(ll a=x,k=1;;a=a*a%m,k++)
        {
            if(!st[a]) st[a]=k;
            else
            {
                l=st[a],r=k-1;
                break;
            }
            s[k]=s[k-1]+a;
        }
        ll len=r-l+1;
        ll res=0;
        res+=s[min(n,l-1)];
        n=max(0ll,n-l+1);
        if(n) res+=(s[r]-s[l-1])*(n/len)+(s[n%len+l-1]-s[l-1]);
        cout<<res<<'\n';
    }
    return 0;
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int n;
struct node{
    string se;
    int a;
}s[maxn];
map<string,int> mp;
string sd;
set<string> mmp;
int k=0;
bool cmp(node aa,node bb){
    if(aa.a!=bb.a) return aa.a>bb.a;
    return aa.se<bb.se;
}
int main()
{
    cin>>n;
    set<string>::iterator it;
    for(int i=0;i<n;i++){
        cin>>sd;
        mmp.insert(sd);
        mp[sd]++;
    }
    for(it=mmp.begin();it!=mmp.end();it++){
        s[k].se=*it;
        s[k].a=mp[*it];
        k++;
    }
    sort(s,s+k,cmp);
    for(int i=1;i<=k;i++){
        if(s[i].a!=s[i-1].a){
            cout<<s[i-1].se<<endl;
            break;
        }
        else cout<<s[i-1].se<<endl;
    }
    return 0;
}






Measured memory_bytes: 37760
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

template<uint32_t mod>
struct ModInt{
    uint32_t a;
    ModInt& s(uint32_t vv){
        a=vv<mod?vv:vv-mod;
        return *this;
    }
 
    ModInt(int64_t x=0){s(x%mod+mod);}
 
    ModInt& operator+=(const ModInt &x){return s(a+x.a);}
    ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
    ModInt& operator*=(const ModInt &x){
        a=uint64_t(a)*x.a%mod;
        return *this;
    }
    ModInt& operator/=(const ModInt &x){
        *this*=x.inv();
        return *this;
    }
 
    ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
    ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
    ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
    ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
    bool operator==(const ModInt &x)const{return a==x.a;}
    bool operator!=(const ModInt &x)const{return a!=x.a;}
    bool operator<(const ModInt &x)const{return a<x.a;}
 
    ModInt operator-()const{return ModInt()-*this;}
    ModInt pow(int64_t n)const{
        ModInt res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
 
    ModInt inv()const{return pow(mod-2);}
};
 
template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
    return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
    return (out<<a.a);
}
using mint=ModInt<MOD>;

int main(void)
{
    int N;
    cin >> N;
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    vector<int> c(1, C[0]);
    REP(i, N-1){
        if(C[i] != C[i+1]) c.pb(C[i+1]);
    }

    int n = c.size();

    vector<mint> dp(n+1);
    dp[0] = 1;
    map<int, mint> sm;

    REP(i, n){
        dp[i+1] = sm[c[i]] + dp[i];
        sm[c[i]] += dp[i];
    }
    pr(dp[n]);
}

Measured memory_bytes: 12020
#include <bits/stdc++.h>
#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 ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    vector<char> log(n, '@');
    rep(i, n)
    {
        if (i < k || (i >= k && log[i - k] != t[i]))
        {
            if (t[i] == 'r')
            {
                ans += p;
            }
            else if (t[i] == 's')
            {
                ans += r;
            }
            else if (t[i] == 'p')
            {
                ans += s;
            }
            log[i] = t[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
int mod = 1e9 + 7;

int add(int a, int b) {
	int ret = a + b;
	if(ret >= mod) ret -= mod;
	return ret;
}

int sub(int a, int b) {
	int ret = a - b;
	if(ret < 0) ret += mod;
	return ret;
}

int mul(int a, int b) {
	return (1LL * a * b) % mod;
}

int qpow(int a, int n) {
	if(n == 0) return 1;
	if(n % 2 == 1) return mul(a, qpow(a, n - 1));
	int x = qpow(a, n / 2);
	return mul(x, x);
}

vector<int> fac, inv;

void fac_init(int size) {
	fac.resize(size + 1);
	fac[0] = 1;
	FOR(i, 1, size) 
		fac[i] = mul(fac[i - 1], i);
	inv.resize(size + 1);
	inv[size] = qpow(fac[size], mod - 2);
	for(int i = size; i >= 1; i--)
		inv[i - 1] = mul(inv[i], i);
}

int get_bin(int n, int k) {
	assert(n >= k);
	return mul(fac[n], mul(inv[n - k], inv[k]));
}

int main() {

	int h, w, n;
	cin >> h >> w >> n;

	fac_init(h + w);

	vector<pair<int, int>> pts(n);
	for(auto &p : pts) {
		cin >> p.first >> p.second;
		p.first--, p.second--;
	}
	pts.emplace_back(h - 1, w - 1);

	sort(pts.begin(), pts.end());
	
	vector<int> dp(n + 1);
	REP(i, n + 1) {
		dp[i] = get_bin(pts[i].first + pts[i].second, pts[i].first);
		REP(j, i) {
			if(pts[j].first <= pts[i].first && pts[j].second <= pts[i].second) {
				int res = get_bin(
					pts[i].first + pts[i].second - pts[j].first - pts[j].second,
					pts[i].first - pts[j].first
				);

				dp[i] = sub(dp[i], mul(dp[j], res));
			}
		}
	}

	cout << dp[n] << "\n";
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    LL ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 3 != 0 && i % 5 != 0)  ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }






ll P[70];

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    // cout << modpow(2, inf - 1, inf) << endl;
    
    P[0] = 1;
    rep3(i, 1, 70) (P[i] = P[i - 1] * 2 % inf) %= inf;
    
    ll n;
    cin >> n;
    // n = 300000;
    vector<ll> a(n);
    // rep(i, n) a[i] = (1LL << 60) - (i + 1);
    rep(i, n) cin >> a[i];
    
    ll ans2 = 0;
    rep(i, n) (ans2 += a[i] % inf) %= inf;
    ans2 *= (n - 1);
    ans2 %= inf;
    
    ll ans = 0;
    
    vector<ll> table(70);
    rep(i, n) {
        int keta = 0;
        while (a[i]) {
            if (a[i] % 2) table[keta]++;
            keta++;
            a[i] /= 2;
        }
    }
    // rep(i, 70) cout << table[i] << " "; cout << endl;
    
    // cout << ans2 << endl;
    rep(i, 70) {
        if (table[i] >= 2) (ans += P[i + 1] * table[i] % inf * (table[i] - 1) % inf * modpow(2, inf - 2, inf)) %= inf; // 直した
    }
    
    
    // cout << ans << " " << ans2 << endl;
    
    ans2 = (ans2 - ans % inf + inf) % inf;
    while (ans2 < 0) ans2 += inf;
    cout << ans2 << endl;
}




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

#define MP make_pair
#define F first
#define S second

using namespace std;

const int N = 1e5;
long long int dp[N], a[N], b[N];

long long int wop(long long int x, long long int y) {
    long long int ret=1;
    for(;y>0;y/=2) {
        if(y&1)ret*=x;
        x*=x;
    }
    return ret;
}

int main () {
    ios::sync_with_stdio(0);
    long long int n, h;
    cin >> h >> n;
    for(int i = 0 ; i < n ; i++ ) {
        cin >> a[i] >> b[i];
    }
    memset(dp,63,sizeof(dp));
    dp[0]=0;
    for(int i = 1 ; i <= 3e4 ; i++ ) {
        for(int j = 0 ; j < n ; j++ ) {
            if(i-a[j]>=0) {
                dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
            }
        }
    }
    long long int mn=1e18;
    for(int i = h ; i <= 3e4 ; i++ ) {
        mn=min(dp[i],mn);
    }
    cout << mn;
}


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

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

using namespace std;

string s;
string x = "qwertasdfgzxcvb";

int main(){
    while(1){
        cin >> s;
        if(s == "#"){
            break;
        }

        vector<int> v;
        for(char c: s){
            v.push_back(x.find(c) != -1);
        }
        cout << unique(v.begin(), v.end()) - v.begin() - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			int ans = (a+b);
			 System.out.println(ans%2==0?ans/2:"IMPOSSIBLE");
		}
	}
}

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

int main(){
    int n;
    cin >> n;

    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll wa_upper[n];
    ll wa_under[n];
    wa_upper[0] = a[0];
    for(int i = 1; i < n; i++){
        wa_upper[i] = wa_upper[i - 1] + a[i];
    }
    wa_under[n - 1] = a[n - 1];
    for(int i = n - 2; i >= 0; i--){
        wa_under[i] = wa_under[i + 1] + a[i];
    }

    /*for(int i = 0; i < n; i++){
        cout << wa_upper[i] << " " << wa_under[i] << endl;
    }*/

    ll wa_abs = 0;
    ll ans = -1;
    for(int i = 0; i < n - 1; i++){
        wa_abs = abs(wa_upper[i] - wa_under[i + 1]);
        if(ans == -1){
            ans = wa_abs;
        }else if(ans >= wa_abs){
            ans = wa_abs;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")

int main(){
 
  //  freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
    ll a, b; cin >> a>> b;
    ll k = __gcd(a, b);
    if(k == 1) {
      cout << 1 << endl;
      return 0;
    }
    ll ans = 0;
    for(ll i = 2 ; i * i <= k ; i ++) {
      if(k % i == 0){
        ans ++;
        while(k % i == 0) k = k / i;
      }
    }


    if(k != 1) ans ++;
    cout << ans + 1<< endl;
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<ll,ll> M;

int main(){
  ll N,C=0,A;cin>>N;
  rep(i,N){
    cin >> A;
    M[A]++;
  }
  for(auto P : M){
    if(P.first<=P.second){
      C+=P.second-P.first;
    }
    else{
      C+=P.second;
    }
  }
  cout << C << endl;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x,n;
  cin>>n>>x;
  if(500*n>=x)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
multiset< ll > s;
ll n;
ll a[200005];
vector< ll > tw;
void eraseLast()
{
        auto it = s.end(); it--;
        s.erase(it);
}
ll getLast()
{
        auto it = s.end();
        it--;
        return *it;
}
int main()
{
        cin >> n;
        for(ll i=0;i<34;i++) {
                tw.pb((1LL << i));
        }
        sort(tw.begin(), tw.end());
        for(ll i=1;i<=n;i++){
                cin >> a[i];
                s.insert(a[i]);
        }
        ll ans = 0;
        ll sz = n;
        while(sz > 1) {

                ll u = getLast();
                eraseLast();
                sz--;
                auto it = *upper_bound(tw.begin(), tw.end(), u);
                ll anti = it - u;
                auto aa = s.find(anti);
                //cout <<u<<" "<< anti << endl;
                if(aa == s.end()) {
                        continue;
                }else {
                        ans += 1;
                        sz--;
                        s.erase(aa);
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 11136
#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 <unordered_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 = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
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);
    int n,a,b;
    cin >> n;
    vector<vector<ll>> g(n);
    vector<P> e;
    rep(i,n-1){
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
        e.push_back(P(a,b));
    }
    int k = 0;
    rep(i,n){
        chmax(k,(int)g[i].size());
    }
    map<P,int> color;
    queue<P> q;
    q.push(P(0,-1));
    color[P(-1,0)] = 0;
    while(!q.empty()){
        tie(a,b) = q.front();q.pop();
        int c = (color[P(min(a,b),max(a,b))])%k+1;
        for (int u:g[a]){
            if (u == b) continue;
            color[P(min(a,u),max(a,u))] = c;
            c = c%k+1;
            q.push(P(u,a));
        }
    }
    PRINT(k);
    rep(i,n-1){
        tie(a,b) = e[i];
        PRINT(color[P(min(a,b),max(a,b))]);
    }
}    


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

int main() {
  int n;
  cin >> n;
  vector<ll> s(n + 1);
  s[0] = 2;
  s[1] = 1;
  for (int i = 2; i <= n; i++) {
    s[i] = s[i - 1] + s[i - 2];
  }
  cout << s[n] << endl;
}

Measured memory_bytes: 256
from bisect import bisect
N = int(input())
L = sorted([int(_) for _ in input().split()])
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        #print(bisect(L,L[a]+L[b]-1)-b-1)
        ans += bisect(L, L[a] + L[b] - 1) - b - 1
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
  int A, B, C, D, E;
  scanf("%d",&A);
   scanf("%d",&B);
   scanf("%d",&C);
   scanf("%d",&D);
   scanf("%d",&E);

   if(A <= 0){
    
   printf("%d\n",-A*C+D+B*E);
   }
   else{
     printf("%d\n",(B-A)*E);
   }
   return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  int h[N];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    if (K <= h[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

template <class T>
void scan(T &x) {
	register char ch; x = 0;
	for (ch = getchar(); ~ch && (ch < '0' || ch > '9'); ch = getchar());
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}

const long double pi = acos(-1.), cir = 2 * pi * 10;

int n;

struct vec {
	int x, y;
	
	bool operator < (const vec &rhs) const {
		return x < rhs.x;
	}
	
	void scan() {
		::scan(x); ::scan(y);
	}
} p[200005];

int sorted[200005];

int hsh(int x) {
	return std::lower_bound(sorted + 1, sorted + n + 1, x) - sorted;
}

int xl, xr, yl, yr;

namespace BIT {
	int c[200005];
	
#define lowbit(x) ((x) & -(x))
	
	void modify(int a, int x) {
		for (int i = a; i <= n; i += lowbit(i))
			c[i] = std::max(c[i], x);
	}
	
	int query(int a) {
		int res = 0;
		for (int i = a; i > 0; i -= lowbit(i))
			res = std::max(res, c[i]);
		return res;
	}
	
	void modify2(int a, int x) {
		for (int i = a; i > 0; i -= lowbit(i))
			c[i] = std::max(c[i], x);
	}
	
	int query2(int a) {
		int res = 0;
		for (int i = a; i <= n; i += lowbit(i))
			res = std::max(res, c[i]);
		return res;
	}
}

int main() {
	scan(xl); scan(yl); scan(xr); scan(yr); scan(n);
	
	int tp = 0;
	if ((xl < xr) != (yl < yr)) tp = 1;
	
	if (xl > xr) std::swap(xl, xr);
	if (yl > yr) std::swap(yl, yr);
	
	for (int i = 1; i <= n; ++i) {
		p[i].scan();
		if (p[i].x < xl || p[i].x > xr || p[i].y < yl || p[i].y > yr) {
			--i; --n;
		}
		else {
			sorted[i] = p[i].y;
		}
	}
	
	std::sort(p + 1, p + n + 1);
	std::sort(sorted + 1, sorted + n + 1);
	
	int cnt = 0;
	if (tp == 0) {
		for (int i = 1; i <= n; ++i) {
			int t = hsh(p[i].y), tmp = BIT::query(t - 1);
			cnt = std::max(cnt, tmp + 1);
			BIT::modify(t, tmp + 1);
		}
	}
	else {
		for (int i = 1; i <= n; ++i) {
			int t = hsh(p[i].y), tmp = BIT::query2(t + 1);
			cnt = std::max(cnt, tmp + 1);
			BIT::modify2(t, tmp + 1);
		}
	}
	
	long double ans = (long double)((xr - xl) + (yr - yl)) * 100.;
	
//	std::cerr << cnt << std::endl;
	
	ans = ans - (long double)cnt * 20. + cnt * cir * 0.25;
	if (cnt == xr - xl + 1 || cnt == yr - yl + 1) ans += cir * 0.25;
	
	printf("%.15f\n", (double)ans);
	
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    ll H, W; cin>>H>>W;
    ll ans=H*W/2;
    ll ans2=ans+1;
    if(H==1 || W==1){
        cout<<"1"<<endl;
    }
    else if(H*W%2==0){
        cout<<ans<<endl;
    }else{
        cout<<ans2<<endl;
    }
}


Measured memory_bytes: 3596
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		int[] bb = new int[n];
		int m = n % 2;
		int d = n / 2;
		for(i=0;i<n;i++) {
			if((i+m)%2==1) {
				bb[d-(i+1)/2]= a[i];
			} else {
				bb[d+(i+1)/2]= a[i];
			}
		}
		PrintWriter pw = new PrintWriter(out);
		for (i = 0; i < n; i++) {
			pw.print(bb[i]);
			pw.print(" ");
		}
		pw.flush();
	}
}


Measured memory_bytes: 52488
#include <bits/stdc++.h>
using namespace std;
const int MXX = 100 + 5;

int a[MXX];
int main ()
{
    int n; cin>>n; for(int i = 1; i<=n; i++)cin>>a[i];
    int ans = 1e9;
    int sum1 = 0;
    for(int T = 1; T<=n; T++)
    {
        sum1+=a[T];
        int sum2 = 0;
        for(int i = T+1; i<=n; i++)
        {
            sum2+=a[i];
        }
        ans = min(ans, abs(sum1 - sum2));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

ll solve(ll n){
    if(n%2==1) return 0;

    ll res=0;
    n/=2;
    while(n){
      res += n/5;
      n /= 5;
    }
    return res;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;cin>>n;
    cout<<solve(n)<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N;
string S[3];
int ans=1;
int mode=0;

signed main(){
	int last=0;
	cin>>N>>S[0]>>S[1];
	REP(i,N){
		if(i==0){
			if(S[0][0]==S[1][0]){
				ans*=3;
				ans%=MOD;
				mode=0;
			}
			else{
				ans*=3*2;
				ans%=MOD;
				mode=1;
				i++;
			}
		}
		else{
			if(mode==0){
				if(S[0][i]==S[1][i]){
					ans*=2;
					ans%=MOD;
					mode=0;
				}
				else{
					ans*=2;
					ans%=MOD;
					mode=1;
					i++;
				}
			}
			else{
				if(S[0][i]==S[1][i]){
					mode=0;
				}
				else{
					mode=1;
					ans*=3;
					ans%=MOD;
					i++;
				}
			}
		}
		DEB(ans)END
	}
	cout<<ans<<endl;
	return 0;
}
/*
aaT
ccT
*/

Measured memory_bytes: 256