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


public class Main {
	
	class Field {
		int[][] ary;
		int len;
		int point;
		public Field(int[][] ary) {
			this.ary = ary;
			this.len = ary.length;
		}
		
		boolean update() {
			boolean changed = erase();
			fall();
			return changed;
		}
		
		boolean erase() {
			int buf = -1;
			boolean changed = false;
			for(int i=len-1; i>=0; i--) {
				int cnt = 0;
				for(int j=0; j<=5; j++) {
					if(j == 5) {
						//テヲツ慊ォテ・ツーツセ
						if(cnt >= 3 && buf != 0) {
							backerase(i,j,cnt);
							changed=true;
						}
					} else if(ary[i][j] != buf) {
						if(cnt >= 3 && buf != 0) {
							backerase(i,j,cnt);
							changed=true;
						}
						buf = ary[i][j];
						cnt = 1;
					} else {
						cnt++;
					}
				}
			}
			return changed;
		}
		
		void backerase(int i, int j, int cnt) {
			int pt = cnt * ary[i][j-1];
			while(cnt != 0) {
				ary[i][j-cnt] = 0;
				cnt--;
			}
			point += pt;
		}
		
		boolean fall() {
			boolean falled = false;
			for(int i=len-1; i>=0; i--) {
				for(int j=0; j<5; j++) {
					if(ary[i][j] == 0) {
						if(fallcolumn(i,j)) falled = true;
					}
				}
			}
			return falled;
		}
		
		boolean fallcolumn(int y, int j) {
			for(int i=y; i>=0; i--) {
				if(ary[i][j] != 0) {
					ary[y][j] = ary[i][j];
					ary[i][j] = 0;
					return true;
				}
			}
			return false;
		}
		
	}
	
	public Main() {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			int h = scanner.nextInt();
			if(h == 0) break;
			int[][] ary = new int[h][5];
			for(int i=0;i<h;i++) {
				for(int j=0; j<5; j++) {
					ary[i][j] = scanner.nextInt();
				}
			}
			Field f = new Field(ary);
			while(f.update()){}
			System.out.println(f.point);
		}
		scanner.close();
	}
	
	public static void main(String[] args) {
		new Main();
	}

}

Measured memory_bytes: 49840
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = []

for i in range(n):
    count = 0
    for j in range(i,n):
        count += a[j]
        l.append(count)

ans = 0
for i in range(44,-1,-1):
    x = 1<<i
    check = ans+x
    count = 0
    for j in l:
        if (check&j) == check:
            count += 1
    if count >= k:
        ans += x
print(ans)


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  auto p = minmax_element(begin(a), end(a));
  cout << *p.second - *p.first << endl;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second > b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

P A[100010], B[100010];

int n, H;

void solve() {
	int cnt = 0;
	sort(A, A + n, greater<P>());
	sort(B, B + n, greater<P>());
	sort(B, B + n, cmp);

	int i = 0;
	while (H > 0 && A[0].fir < B[i].sec && i < n) {
		H -= B[i++].sec;
		cnt++;
	}
	if (H <= 0) {
		cout<< cnt <<endl;
		return;
	}

	cnt += (H % A[0].fir == 0 ? H / A[0].fir : H / A[0].fir + 1);
	cout<< cnt <<endl;

	return;
}

int main(void){
	cin>>n>>H;
	for (int i = 0; i < n; i++) {
		cin>>A[i].fir>>A[i].sec;
		B[i].fir = A[i].fir;
		B[i].sec = A[i].sec;
	}

	solve();
	
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n, k;

  cin >> n >> k;

  int c = 0;

  for (int i = 1; i <= n; i+=2){
    c++;
  }

  cout << (c >= k ? "YES" : "NO") << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
s = x
cnt = 0
if s > sum(a):
    print(N-1)
elif (s >= a[0] and s <= sum(a)):
    for i in range(N):
        if s >= a[i]:
            cnt += 1
            s -= a[i]
    print(cnt)
else:
    print(0)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	c := make([]int, N)
	for i := 0; i < M; i++ {
		a, b := ReadInt()-1, ReadInt()-1
		c[a]++
		c[b]++
	}
	for i := 0; i < N; i++ {
		fmt.Println(c[i])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

int main(){
  long long n,k,m=1e9+7;
  cin>>n>>k;
  int ans=1;
  for(int i=0;i<n;i++)ans=ans*k%m,k--;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>

int main(){
    int grid[3][3], b, verify[3][3]={0}, n;

    for(int i = 0; i < 3; i++){ 
        for(int j = 0; j < 3; j++){
            scanf("%d", &grid[i][j]);
        }                            
    }

    scanf("%d",&n);
    for(int k = 0; k < n; k++){
        scanf("%d",&b);

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(grid[i][j] == b)
                {
                    verify[i][j] = 1;
                }
            }
        }
    }
    if(verify[0][0] + verify[1][1] + verify[2][2] == 3 || verify[0][2] + verify[1][1] + verify[2][0] == 3){
        printf("Yes\n");
        return 0;
    }
    for(int i = 0; i < 3; i++){
        if(verify[i][0] + verify[i][1] + verify[i][2] == 3 || verify[0][i] + verify[1][i] + verify[2][i] == 3){

            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");

    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <deque> 

int main() {
  std::string S;
  long int Q;
  std::cin >> S;
  std::cin >> Q;
  std::vector<long int> T(Q);
  std::vector<long int> F(Q);
  std::vector<char> C(Q);
  for(int i=0; i<Q; ++i) {
    std::cin >> T[i];
    if(T[i]==2) {
      std::cin >> F[i];
      std::cin >> C[i];
    }
  }

  std::deque<char> dqc(S.size());
  for (int i=0; i<S.size(); ++i) { dqc[i] = S[i]; }

  int dir = 1; // 1:order -1:reverse
  for(int i=0; i<Q; ++i) {
    if(T[i] == 1) {
      dir *= -1;
    }
    else if(T[i] == 2) {
      if(F[i] == 1 && dir == 1) dqc.push_front(C[i]);
      else if(F[i] == 2 && dir == 1) dqc.push_back(C[i]);
      else if(F[i] == 1 && dir == -1) dqc.push_back(C[i]);
      else if(F[i] == 2 && dir == -1) dqc.push_front(C[i]);
    }
  }

  if (dir == 1) {
    for (const auto c : dqc) std::cout << c;
  }
  else if (dir == -1) {
    for (int i = dqc.size()-1; i>=0; --i) std::cout << dqc[i];
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
int dp[41][401][401];
int main(){
  int n;double ma, mb;cin>>n>>ma>>mb;
  vector<int> a(n), b(n), c(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  fill(dp[0][0], dp[41][0], INF);
  dp[0][0][0]=0;
  for(int i=0;i<n;i++){
  	for(int ca=0;ca<=40;ca++){
      for(int cb=0;cb<=40;cb++){
         dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
         dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
      }
    }
  }
  int ans = INF;
  for(int ca=0;ca<=40;ca++){
    for(int cb=0;cb<=40;cb++){
      if(ca+cb==0)continue;
      if(ca*mb==cb*ma){
      	ans=min(ans, dp[n][ca][cb]);
      }
    }
  }
  if(ans==INF)ans=-1;
  cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> que;
    for(int i = 0; i < n; i++){
        int a; cin >> a; que.push(a);
    }

    for(int i = 0; i < m; i++){
        int cur = que.top(); que.pop();
        que.push(cur / 2);
    }
    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += que.top(); que.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 892
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int  a, b;
    cin >> a >> b;
    if(a*b%2 == 0){
        cout << "Even";
    }
    else
    {
        cout << "Odd";
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m, d;
  cin >> n >> m >> d;
  long double ans = 0.0;
  long double prob;
  if (d == 0)
  {
    prob = 1.0 / n;
  }
  else
  {
    prob = (2.0 * (n - d)) / pow(n, 2);
  }
  ans = prob * (m - 1);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

// 隣り合う2項はm-1通り存在する．期待値の線形性からm-1通りそれぞれについて差の絶対値がdである確率を求めて足し上げれば答えが求まる．1からnまでの整数のペア(a, b)の差の絶対値がdである確率を求める．d = 0であるとき条件を満たすペアは(1, 1), ..., (n, n)のn通りである．d/=0でるとき，条件を満たすペアは(1, d + 1), ..., (n - d, n)と(d + 1, 1), ...,(n, n - d)の2(n - d)個である．よって確率2(n - d)/n^2である．


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}

ll power(ll a,ll b)
{
	ll p=1;
	while(b)
	{
		if(b&1)
			p=mul(p,a);
		a=mul(a,a);
		b/=2;
	}
	return p;
}

ll nCr(ll n,ll r)
{
	ll ans=1;
	ll i,num=1,den=1;
	for(i=n-r+1;i<=n;i++)
		num=mul(num,i);
	for(i=1;i<=r;i++)
		den=mul(den,i);
	return mul(num,power(den,M-2));
}

int main()
{
	fastio;
	ll t;
	cin>>t;
	while(t--)
	{
		ll n,i,j;
		cin>>n;
		ll ans=0;
		for(j=0;j<=11;j++)
		{
			if((n-5-j)%2)
				continue;
			ll x = (n-5-j)/2;
			ans=add(ans,mul(nCr(15+x,15),nCr(11,j)));
		}
		cout<<ans<<endl;
	}
    return 0;
}





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

void run(void){
  int n;
  scanf("%d",&n);
  int *p=(int *)calloc(n+2,sizeof(int));
  int i;
  for(i=1;i<=n;i++){
    scanf("%d",p+i);
  }
  int cnt=0;
  for(i=1;i<=n;i++){
    if(p[i]==i){
      cnt++;
      p[i+1]=i;
    }
  }
  printf("%d\n",cnt);
}

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

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>

// #define INT_MAX 2147483647
// #define LL_MAX 9223372036854775807

using namespace std;
#define i64  long long

void solve(void)
{

  vector<int> vec;
  int count= 0;
  while(true)
  {
    int a,b;
    char opp;
    cin>>a>>opp>>b;
    if(opp == '+')
    vec.push_back(a+b);
    else if( opp == '-')
    vec.push_back(a-b);
    else if( opp == '*')
    vec.push_back(a*b);
    else if(opp == '/')
    vec.push_back(a/b);
    else
    {
      break;
    }
    count++;
    
  }
  for (int i = 0; i < count; i++)
  {
    cout<<vec[i]<<endl;
  }
  
  return;
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	vector<int>v(n); rep(i, 0, n)cin >> v[i];
	int sum(0);
	rep(i, 0, n)sum += v[i];
	cout << sum / n << endl;
	return 0;
}

Measured memory_bytes: 3136
import queue

H,W = map(int, input().split())
#world = [[c for c in input()] for _ in range(H)]
whiteCount = 0

world = []
for i in range(H):
    row = [c for c in input()]
    world.append(row) 
    whiteCount += len([c for c in row if c == '.'])

minRoot = whiteCount + 1

def bfs(x, y, depth):
    if x == W - 1 and y == H - 1:
        return min(minRoot, depth)

    depth = depth + 1
    appendPosition(x + 1, y, depth)
    appendPosition(x - 1, y, depth)
    appendPosition(x, y + 1, depth)
    appendPosition(x, y - 1, depth)

    return minRoot

def appendPosition(newX, newY, depth):
    if newX < 0 or newY < 0 or newX >= W or newY >= H or world[newY][newX] == '#':
        return

    newPosition = (newX,newY)
    if newPosition in visitedPosition:
        return

    q.put((newX, newY, depth))
    visitedPosition.add(newPosition)

q = queue.Queue()
q.put((0,0,1))
visitedPosition = set()
visitedPosition.add((0,0))

while q.empty() == False:
    position = q.get()
    minRoot = min(minRoot, bfs(*position))

if whiteCount < minRoot:
    print(-1)
else:
    print(whiteCount - minRoot)

Measured memory_bytes: 4208
import java.util.Scanner;

//公舎の入居者数

public class Main {
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		
		//配列
		int[][][] array = new int[4][3][10];
        //入居者数
        int num = sc.nextInt();
        //座標など入力
        for(int i=0;i<num;i++){
            //座標
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            //座標に入力する数値
            int d = sc.nextInt();
            
            array[a-1][b-1][c-1] += d;
        }
        //表示
        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<10;k++){
                    System.out.print(" "+array[i][j][k]);
                }
                 System.out.println();
            }
            if(i!=3){
                 System.out.println("####################");
            }
        }
      sc.close();
	}
}


Measured memory_bytes: 28988
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {

	int M, D; 
	cin >> M >> D;

	int ans = 0;

	for (int m = 1; m <= M; ++m) {
		for (int d = 10; d <= D; ++d) {
			int d_1 = d % 10, d_10 = d / 10;
			if (d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m) {
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int count = 0;
    for (; !(b > a); count++)
        b *= 2;
    for (; !(c > b); count++)
        c *= 2;

    if (k >= count)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> grid(h);
  rep(i,h){
    string in;
    cin >> in;
    grid[i] = in;
  }
  int n = h+w;
  int cnt=0;
    //----- bit 全探索 ------
    //ここで2^n-1個のbit列を列挙
    for (int bit = 0; bit < (1 << n); ++bit) {
        vector<int> vec(n);
        auto now_grid = grid;
        //ここで、列の各位が1かをみる
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)) {
            //もし1だったら何か処理
            //今回はbit列を表示させる
            vec[i]=1;
            }

        }
        //0がえらばれた場所の#の数を数える
        // 行 0~h-1
        // 列 h~h+w
        rep(i,n){
          if(vec[i]==1){
            if(i>=0&&i<h){
                //たて
                rep(j,w){
                  now_grid[i][j] = '.';
                }
            }
            if(i>=h){
                //よこ
                rep(j,h){
                  now_grid[j][i-h] = '.';
                }
            }
          }
        }
        int c=0;
        rep(i,h){
          rep(j,w){
            if(now_grid[i][j]=='#') c++;
          }
        }
        if(c==k) cnt++;
    }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3612
import collections
n = int(input())
a = sorted(list(map(int, input().split())))

cnt = collections.Counter(a)
l1 = 0
l2 = 0

for i in cnt.keys():
    if cnt[i] >= 4:
        l1 = i
        l2 = i
    elif cnt[i] >= 2:
        l1, l2 = i, l1
print(l1 * l2)

Measured memory_bytes: 99740
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:print(n-(a[0][1]+b[0][1]))
else:print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))

Measured memory_bytes: 65004
a = STDIN.gets.split
n = a[0].to_i
k = a[1].to_i

p = 0.0

for i in 1..n do
  c = 1
  t = 0
  while i*c < k do
    c <<= 1
    t += 1
  end
  p += (0.5**t) / n
end

puts p


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

const int N = 201;
int n, ar[N];

void solve() {
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>ar[i];
        ar[i] = ar[i] & (~ar[i] +1);
    }
    int mn=1e9+1;
    for(int i=0;i<n;i++)
        mn = min(mn, ar[i]);
    cout<<log2(mn)<<endl;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <set>

int main()
{
    uint64_t N, K;
    std::cin >> N >> K;
    std::map<uint64_t, uint64_t> A;

    for (size_t n = 0; n < N; ++n)
    {
        uint64_t a;
        std::cin >> a;
        A[n + 1] = a;
    }

    std::set<uint64_t> al;
    std::vector< uint64_t> R(N);
    R[0] = 1;
    al.insert(1);
    uint64_t i = 1;
    uint64_t s = 1;
    uint64_t j = 0;
    while (true) {
        i = A[i];
        if (!al.insert(i).second)
        {
            auto c = std::find(R.begin(), R.end(), i);
            j = std::distance(R.begin(), c);
            break;
        }
        R[s] = i;
        ++s;
    }

    if (K < s) {
        std::cout << R[K] << std::endl;
    }
    else {
        uint64_t t = j + ((K <= j) ? 0 : ((K - j) % (s - j)));
        std::cout << R[t] << std::endl;
    }


    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int k = 0;
  for(int i = 0;i < n;i++){
    if(i == 0){
      k++;
    }
    if(0 < i){
      if(a.at(i - 1) < a.at(i)){
        k++;
      }
    }
  }
  cout<<k<<endl;
  }

Measured memory_bytes: 3160
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> X(N);
  int m = 0;
  for(int i = 0; i < N; i++){
    cin >> X.at(i);
    m = max(X.at(i), m);
  }
  
  //iは集会する場所
  int64_t sum = 0;
  int64_t mi = 10000000;
  for(int i = 0; i <= m; i++){
    //jは住人がいる座標
    for(int j = 0; j < N; j++){
      sum += (X.at(j) - i) * (X.at(j) - i);
    }
    mi = min(mi, sum);
    sum = 0;
  }
  
  cout << mi << endl;

  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 16 20:49:48 2018
ABC100B
@author: maezawa
"""

#a = int(input())
#b = int(input())
d, n = list(map(int, input().split()))

if d == 0:
    if n < 100:
        print(n)
    else:
        print(n+1)
else:
    if n < 100:
        print(100**d*n)
    else:
        print(100**d*(n+1))
#    print(100**d*n)

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

#define rep(i,j,k) for(int i=j;i<=k;i++)
#define derep(i,j,k) for(int i=j;i>=k;i--)
#define pic(i,j) for(int i=lin[j];i;i=e[i].next)

long long i1,i2;char ch;
inline long long read()
{
	i1=i2=ch=0;
	while(!isdigit(ch)) i1|=ch=='-',ch=getchar();
	while(isdigit(ch))  i2=(i2<<1)+(i2<<3)+(ch^48),ch=getchar();
	return i1? -i2:i2;
}

long long a,b,c;

int main()
{
	a=read(),b=read(),c=read();
	long long ans=a+b+b+1;
	if(ans>c+b) ans=c+b;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
from collections import deque
MOD = 10**9+7

def bfs(start, g, visited, k):
    q = deque([start])
    visited[start] = 0
    ans = k
    first_flag = True
    while q:
        curr_node = q.popleft()
        i = 0
        for next_node in g[curr_node]:
            if visited[next_node] >= 0: continue
            if first_flag: 
                ans *= (k-(i+1))
            else:
                ans *= (k-(i+2))
            ans%=MOD
            visited[next_node] = visited[curr_node] + 1
            q.append(next_node)
            i+=1
        first_flag = False
    return ans


n, k = map(int, input().split()) 
g = [ [] for _ in range(n+1)]
visited = [-1] * (n+1)
for i in range(n-1):
    a, b = map(int, input().split()) 
    g[a].append(b)
    g[b].append(a)

ans = bfs(1, g, visited, k)
print(ans)

Measured memory_bytes: 92592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int k=10001;
  cin >> n;
  vector<unsigned short> A(n+1);
  vector<unsigned short> B(n+1);
  int C[10005];
  for(int i=0;i<10005;i++)C[i]=0;
  for(int j=1;j<=n;j++){
    cin >> A[j];
    C[A[j]]++;
  }
  //cout << 1 << endl;
  for(int i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(int j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  
  for(int i=1;i<=n;i++){
    if(i-1)cout << " ";
    cout << B[i];
  }
  cout << endl;
  return 0;
}

  

Measured memory_bytes: 10764
class UnionFind():
  def __init__(self, n=10**6):
    self.n=n
    self.root=[-1]*(n+1)
    self.rnk=[0]*(n+1)
  def find(self, x):
    if(self.root[x]<0):
      return x
    else:
      self.root[x]=self.find(self.root[x])
      return self.root[x]
  def unite(self, x, y):
    x=self.find(x)
    y=self.find(y)
    if(x==y):return 
    elif(self.rnk[x] > self.rnk[y]):
      self.root[x]+=self.root[y]
      self.root[y]=x
    else:
      self.root[y]+=self.root[x]
      self.root[x]=y
      if(self.rnk[x]==self.rnk[y]):
        self.rnk[y]+=1
  def same(self, x, y):
    return self.find(x)==self.find(y)
  def count(self, x):
    return -self.root[self.find(x)]
n,m=map(int,input().split())
uf=UnionFind(n)
a=[0]*m
b=[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
c=[1]*(n+1)
ans=[]
nm=n*(n-1)//2
for i in range(m-1,-1,-1):
  ans+=[nm]
  x,y=a[i],b[i]
  if uf.same(x,y):continue
  nm-=uf.count(x)*uf.count(y)
  uf.unite(x,y)
print(*ans[::-1],sep='\n')

Measured memory_bytes: 91676
#include<stdio.h>

int main(){
  int i,j,n,A[100][100]={0},k,a,u;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&a);
      A[u-1][a-1]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0) printf(" ");
      printf("%d",A[i][j]);
    }
    printf("\n");
  }
   
  return 0;    
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int h[n];
    rep(i, 0, n) {
        cin >> h[i];
    }
    vector<vector<int>> g(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    rep(i, 0, n) {
        bool ok = true;
        for (auto j : g[i]) {
            if (h[i] <= h[j]) {
                ok = false;
            }
        }
        ans += ok;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8716
H, n = map(int, input().split())

A = [0] * n
B = [0] * n
for i in range(n):
    A[i], B[i] = map(int, input().split())

dp = [float("inf")] * (H + max(A))
dp[0] = 0
for i in range(H):
    for a, b in zip(A, B):
        if dp[i] + b < dp[i+a]:
            dp[i+a] = dp[i] + b
print(min(dp[H:]))

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

#define min(a,b) ((a)<(b)?(a):(b))

int main() {
    int Q;

    cin >> Q;
    while (Q--) {
        int c, a, n, count;
        cin >> c >> a >> n;

        count = min(c, min(a, n));
        c -= count; a -= count; n -= count;

        if (a > 0 && c >= 2) {
            if (a * 2 <= c) {
                count += a;
                c -= a * 2;
            }
            else {
                count += c / 2;
                c %= 2;
            }
        }

        if (c >= 3) {
            count += c / 3;
        }

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

Measured memory_bytes: 1160
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let H = read![[usize]];

    let mut h = vec![0; N];
    let mut t = 0;

    for l in 0..N {
        loop {
            let mut r = l;
            while r < N && h[r] < H[r] {
                h[r] += 1;
                r += 1;
            }
            if r == l {
                break;
            }
            t += 1;
        }
    }

    println!("{}", t)
}


Measured memory_bytes: 4352
def prime_factorize(n):
    # 素因数分解して素数と1の集合を作る
    a = {1}
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a


A, B = map(int, input().split())
cds = prime_factorize(A) & prime_factorize(B)
print(len(cds))

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

int main() {
    string s; cin >> s;
    vector<char> op(3);
    for (int bit = 0; bit < (1 << 3); bit++) {
        int sum = s[0] - '0';
        for (int i = 0; i < 3; i++) {
            if (bit & (1 << i)) {
                sum += s[i+1] - '0';
                op[i] = '+';
            } else {
                sum -= s[i+1] - '0';
                op[i] = '-';
            }
        }
        if (sum == 7) {
            cout << s[0];
            for (int i = 0; i < 3; i++) {
                cout << op[i] << s[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<char,ll> P;

vector<P>A,B,C;
void input(vector<P> &a){
  int num;
  char ch;
  while(cin>>ch,ch!='$'){
    cin>>num;
    a.push_back(P(ch,num));
  }
}

bool check(int i){
  int n = A.size();
  int m = B.size();
  if(i+m>n) return 0;

  if(A[i].first!=B[0].first||A[i].second<B[0].second)return 0;

  if(m == 1) return 1;

  int j = 0;
  for(j++,i++;j<m-1;j++,i++)
    if(A[i].first!=B[j].first||A[i].second!=B[j].second)return 0;
  
  if(A[i].first!=B[j].first||A[i].second<B[j].second)return 0;
  
  return 1;
}

void mergePush(vector<P> &res,P a){
  int c = a.second;
  char ch = a.first;
  if(c == 0)return;
  if(res.size() && res.back().first == ch)res.back().second+=c;
  else res.push_back(P(ch,c));
}

vector<P> solve(){
  vector<P> res;
  int n = A.size();
  int m = B.size();
  int l = C.size();
  int flg = 0;
  for(int i=0;i<n;i++){
    if(!check(i)||flg++){mergePush(res,A[i]);continue;}
    A[i].second -= B[0].second;
    if(m == 1) for(int j=0;j<l;j++) mergePush(res,C[j]);
    else {
      mergePush(res,P(A[i].first,A[i].second));   
      for(int j=0;j<l;j++) mergePush(res,C[j]);
      A[i+m-1].second -= B.back().second;
    }
    i+=m-2;
  }
  return res;
}


int main(){
  input(A),input(B),input(C);
  vector<P> ans = solve();
  for(P a:ans) cout<<a.first<<" "<<a.second<<" ";
  cout<<"$"<<endl;
  return 0;
}

Measured memory_bytes: 3208
/************************************************************
	> File Name: e.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 22 Dec 2019 11:03:25 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int main(void){
	IOS;
	ll n,ans=0,p=10;
	cin>>n;
	if(n&1){
		cout << "0" << endl;
		return 0;
	}
	while(p<=n){
		ans += (n/p);
		p *= 5;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define forl(i,a,n) for(   int  i=a;i<n;i++)
#define rfor(i,n,a) for(   int  i=n;i>=a;i--)
#define fore(i,a,n) for(   int  i=a;i<=n;i++)
//---------------------------------------------------------------------
 int main()
{
   int n;
   int m;
   cin>>n;
   cin>>m;
   cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

/*
OXOXOX
XOXOXO
*/

 
template<typename T>
struct BinaryIndexedTree{
   vector<T> data;
   BinaryIndexedTree(int sz){
       data.assign(sz+1, 0);
   }
   // 区間[0,k]の合計 sum(v[0]~v[k])
   T sum(int k){
       T ret=0;
       for(++k;k>0;k-=(k&-k)) ret+=data[k];
       return ret;
   }
   // v[a]+=x
   void add(int k,T x){
       for(++k;k<data.size();k+=(k&-k)) data[k]+=x;
   }
   // wを超える最小のv[i]のiを返す(0indexedのを返す)(data上のindexを返したいならreturn x+1)
   int lower_bound(T w){//T?
       if(w<=0) return 0;
       //左右どっちに行くか考える
       int x=0,r=1;
       while(r<data.size()) r<<=1;
       for(int k=r;k>0;k>>=1){
           if(x+k<=data.size()&&data[x+k]<w){
               //左部分を引いて右へ，再起っぽい
               w-=data[x+k];
               x+=k;
           }
       }
       // return x+1;
       return x;
   }
};
 
 
//転倒数を求める
ll inversion_number(vector<int> v){
    int n=v.size();
    if(n<=1){
        return 0;
    }
    int vmax=*max_element(ALL(v));
    BinaryIndexedTree<ll> bit(vmax+1);
    ll ret=0;
    rep(i,n){
        ret+=bit.sum(vmax)-bit.sum(v[i]);
        bit.add(v[i],1);
    }
    return ret;
}


int n;
vector<int> a,b;
ll ans=LINF;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n;
    a.resize(n);b.resize(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        if(i%2==1) swap(a[i],b[i]);
    }
    bool f=false;
    int half=n/2;
    if(n%2) half++;
    rep(bit,(1<<n)){
        if(__builtin_popcount(bit)!=half){
            continue;
        }
        vector<pair<int,int>> A,B;
        rep(i,n){
            if((bit>>i)&1)  A.push_back(make_pair(a[i],i));
            else            B.push_back(make_pair(b[i],i));
        }
        vector<pair<int,int>> v;
        sort(ALL(A));sort(ALL(B));
        int ai=0,bi=0;
        rep(i,n){
            if(i%2==0){
                v.push_back(A[ai]);
                ai++;
            }else{
                v.push_back(B[bi]);
                bi++;
            }
        }
        bool sorted=true;
        rep(i,n-1){
            if(v[i].first>v[i+1].first)sorted=false;
        }
        vector<int> is(n);
        if(sorted){
            //転倒数を求める
            rep(i,n) is[i]=v[i].second;
            chmin(ans,inversion_number(is));
        }
    }
    if(ans>=LINF)   cout<<-1<<endl;
    else            cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(),a.end());
  rep(i,n){
    if(a[n-1] != b[i])
      cout << a[n-1] << endl;
    else if(a[n-2] != b[i])
      cout << a[n-2] << endl;
    else
      cout << b[i] << endl;
  }
}

Measured memory_bytes: 3200
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> heights = new ArrayList<Integer>();
		for (int i = 0 ; i < 10 ; i++) {
			heights.add(sc.nextInt());
		}
		Collections.sort(heights);
		Collections.reverse(heights);
		for (int i = 0 ; i < 3 ; i++) {
			System.out.println(heights.get(i));
		}
	}
}

Measured memory_bytes: 17176
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

struct UF {
  vector<int> par; // parent
  vector<int> sizes;
  UF(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; ++i) {
      par[i] = i;
    }
  }
  int root(int x) {
    if (x == par[x]) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};

int n, m;
vvi g;
vi color;

bool bipartite_graph(int s) {
  color[s] = 1;
  deque<int> stk;
  stk.push_back(s);
  while (!stk.empty()) {
    int u = stk.front();
    stk.pop_front();
    for (int v : g[u]) {
      if (color[v] > 0) {
        if (color[u] == color[v]) {
          return false;
        }
        continue;
      }
      color[v] = 3 - color[u];
      stk.push_back(v);
    }
  }
  return true;
}

set<int> roots;

int main() {
  scanf("%d %d", &n, &m);
  g.resize(n);
  UF uf(n);
  color.assign(n, 0);
  {
    int u, v;
    rep (i, m) {
      scanf("%d %d", &u, &v);
      u -= 1;
      v -= 1;
      g[u].push_back(v);
      g[v].push_back(u);
      uf.unite(u, v);
    }
  }
  rep (i, n) {
    roots.insert(uf.root(i));
  }
  ll bocchi = 0;
  ll bipartite = 0;
  ll other = 0;
  for (int u : roots) {
    if (uf.size(u) == 1) {
      bocchi += 1;
    } else if (bipartite_graph(u)) {
      bipartite += 1;
    } else {
      other += 1;
    }
  }

  ll ans = 0;
  ans += bocchi * (bocchi + 2 * (n - bocchi));
  ans += 2 * bipartite * bipartite;
  ans += other * (other + 2 * bipartite);
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 9728
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x, h, m, s;
    scanf("%d",&x);
    s=x%3600%60;
    m=x%3600/60;
    h=x/3600;
    printf("%d:%d:%d\n",h, m, s);
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <list>

using namespace std;

#include <iostream>
#include <vector>
using namespace std;

int main(){
  long long N;
  cin >> N;

  double log = log2(N);

  log = floor(log+1);

  int p = static_cast<int>(log);

  long long x = pow(2,p) -1;

  cout << x << endl;

  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

if H%3==0 or W%3==0:
    print(0)
else:
    vals = []
    if H>=3:
        vals.append((H//3+1)*W-(H//3)*W)
    for i in range(3):
        x = (W//3+i)*H
        vals.append(max(abs(x-(W-W//3-i)*(H//2)), abs((W-W//3-i)*(H//2)-(W-W//3-i)*(H//2+H%2)), abs(x-(W-W//3-i)*(H//2+H%2))))

    H, W = W, H
    if H>=3:
        vals.append((H//3+1)*W-(H//3)*W)
    for i in range(3):
        x = (W//3+i)*H
        vals.append(max(abs(x-(W-W//3-i)*(H//2)), abs((W-W//3-i)*(H//2)-(W-W//3-i)*(H//2+H%2)), abs(x-(W-W//3-i)*(H//2+H%2))))
    print(min(vals))

Measured memory_bytes: 38384
//
#define _USE_MATH_DEFINES
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
#define PI  3.1415926535
//
#include <iomanip>
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ;

    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    using ld = double;
    ld hd = ld(H / ld(12.0) + ld(M) / (ld(60.0)* ld(12.0))) *ld(2.0) * ld(M_PI);
    ld md = ld(M / ld(60.0)) * ld(2.0) * ld(M_PI);
    ld ax = ld(A) * cos(hd);
    ld ay = ld(A) * sin(hd);
    ld bx = ld(B) * cos(md);
    ld by = ld(B) * sin(md);
    ld dx = ax - bx;
    ld dy = ay - by;
    ld len = sqrtl(dx * dx + dy * dy);
    cout << std::setprecision(16) << len;
    return 0;
}

Measured memory_bytes: 3528
L=int(input());n=len(str(bin(L)))-3;e=[];h=2**n
for i in range(1,n+1):
  e+=[(i,i+1,0),(i,i+1,2**(n-i))]
  if 2**(n-i)&L:e+=[(1,i+1,h)];h+=2**(n-i)
print(n+1,len(e))
for v in e:print(*v)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
    // Your code here!
    int n;
    
    scanf("%d",&n);
    
    while(n>=4){
        if(n%7==0){
            n=0;
            printf("Yes\n");
            break;
        }
        else if(n%4==0){
            n=0;
            printf("Yes\n");
            break;
        }
        else n=n-4;
    }
    if(n!=0) printf("No\n");
    return 0;
}

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

int ctoi(const char c){
    if('0' <= c && c <= '9')
        return (c-'0');
    return -1;
}

int main(){
    string N;
    cin >> N;
    
    int l, X = 0, sum = 0;
    l = N.length();
    // 各位の和
    for(int i=0;i<l;i++){
        X = X*10;
        X += ctoi(N[i]);
        sum += ctoi(N[i]);
    }

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

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
}

Measured memory_bytes: 55560
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e4 + 5;
vector<int> g[N];
int c[N], ans[N];
bool used[N];

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

    int n;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    sort(c, c + n);
    reverse(c, c + n);

    queue<int> q;
    q.push(0);
    used[0] = true;

    int k = 0;
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        ans[node] = c[k++];
        for (int to : g[node]) {
            if (!used[to]) {
                used[to] = true;
                q.push(to);
            }
        }
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) {
        sum += ans[i];
    }

    cout << sum << "\n";
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    cout << "\n";

    return 0;
}

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

int main(){ 
  string s;
  cin >> s;
  int n = sz(s);
  string ans = "";
  for (int i = 0; i < n; i++) ans += 'x';
  cout << ans << endl;
  return 0;
} 

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

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

#define MOD 1000000007

using namespace std;

int main(){
	int k,x;
	
	cin >> k >> x;
	
	for(int i=x-k+1; i<x+k; i++){
		cout << i;
		if(i!=x+k-1)	cout << " ";
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int abs(int x){
    return x >= 0 ? x : -x;
}


int main(){
    int n,k; cin >> n >> k;
    int h[n],d[n];

    rep(i,n){
        cin >> h[i];
        d[i] = 0;
    } 

    rep(i,n) d[i] = INF;
    
    d[0] = 0;
    for(int i= 1 ; i < n ; i++){
        for(int j=i-k ; j<i ; j++){
            if(j < 0) continue;
            d[i] = min(d[i] , abs(h[i] - h[j])+d[j]);
        }
    }

    cout << d[n-1] << endl;
}


Measured memory_bytes: 1024