akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const ll N = 2e5 + 5, INF = 1e18;
ll n, C, h[N], dp[N];

// x = (b2 - b1) / (k1 - k2)
struct Line{
    ll k, b;
    Line(ll kk, ll bb){
        k = kk; b = bb;
    }
};

vector<Line> lines;

ld cross(Line a, Line b){ return (b.b - a.b + 0.0) / (a.k - b.k + 0.0);}

ll get(ll x, Line temp){ return temp.k * x + temp.b;}

void add(Line new_line){
    while(lines.size() > 1){
        ll last = lines.size() - 1;
        if(cross(lines[last-1], new_line) > cross(lines[last], lines[last-1])){break;}
        lines.pop_back();
    }
    lines.push_back(new_line);
}

ll ternary(ll x){
    ll L = 0, R = lines.size()-1, m1, m2, ans = INF;
    while(R - L > 3){
        m1 = L + (R - L) / 3;
        m2 = R - (R - L) / 3;
        if(get(x, lines[m1]) > get(x, lines[m2])){
            L = m1;
        }else{
            R = m2;
        }
    }
    for(ll i = L; i <= R; i++){ans = min(ans, get(x, lines[i]));}
    return ans;
}

// dp[i] = dp[j] + h[i]^2 - h[i]*h[j] + h[j]^2 + C
// dp[i] = -h[j] * h[i] + dp[j] + h[j]^2 + {h[i]^2 + C}
// y = -k * x + b

int main() {
    cin>>n>>C;
    for(ll i = 1; i <= n; i++){
        cin>>h[i];
    }
    add(Line(-2 * h[1], h[1] * h[1]));
    for(ll i = 2; i <= n; i++){
        dp[i] = ternary(h[i]) + h[i] * h[i] + C;
        add(Line(-2 * h[i], dp[i] + h[i] * h[i]));
    }
    cout<<dp[n];
	return 0;
}

Measured memory_bytes: 9200
def main():
    N = int(input())
    A = list(map(int,input().split()))
    Ans = [0]*(N + 1)
    for i in range(N-1):
        a = A[i]
        Ans[a] += 1
    print(*Ans[1:],sep="\n")
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 32248
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;

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

    int a[N];

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

    int ans = 0;

    sort(a, a + N, greater<int>());

    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            ans += a[i];
        }else{
            ans -= a[i];
        }
    }

    cout << ans << endl;
}

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

N,M = map(int,readline().split())

A = [None] * N
for i in range(N):
  A[i] = list(map(int,readline().split()))[::-1]

# 末尾についている数字をカウントするdictionary
from collections import defaultdict
counter = defaultdict(int)

# すでに消去済みのスポーツを管理する集合
removed = set()

# まず末尾の数字をカウントする
for i in range(N):
  counter[A[i][-1]] += 1
  
# 最も登場回数が大きい数字を特定する
target = max(counter, key = counter.get)

ans = max(counter.values()) # 現時点での答え

while len(removed) < M - 1:
  # targetを末尾に持っている数について、取り除く
  for i in range(N):
    if len(A[i]) == 0:
      continue
    if A[i][-1] == target:
      A[i].pop()
      counter[target] -= 1
      while len(A[i]) > 0:
        if A[i][-1] in removed:
          A[i].pop()
        else:
          counter[A[i][-1]] += 1
          break
  removed.add(target)
  
  target = max(counter, key = counter.get)
  now = max(counter.values())
  if ans > now:
    ans = now
    
print(ans)


Measured memory_bytes: 10444
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=(b);a<(c);a++)
#define PER(a,b,c) for(ll a=(b);a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ld r;
    cin >> r;
    ode(2*r*M_PI);

    return 0;
}


Measured memory_bytes: 3828
n = int(input())
a = sorted(list(map(int,input().split())))
am = a[-1]+1
div = [1]*am
ans = 0

for i in range(n-1):
  a_i = a[i]
  if div[a_i]:
    for j in range(a_i,am,a_i):
      div[j] = 0
    if a_i < a[i+1]:
      ans += 1
      
if div[-1]:ans += 1
print(ans)

Measured memory_bytes: 32292
#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;

int funcLCM(int a, int b)
{
	int rea = a;
	int reb = b;

	while (true)
	{
		if (rea > reb)
		{
			swap(rea, reb);
		}

		if (reb % rea == 0) break;

		reb = reb % rea;
	}

	int lcm = rea * a / rea * b / rea;

	return lcm;
}

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

	int lcm = a[0];

	for (int i = 1; i < n; i++)
	{
		lcm = funcLCM(lcm, a[i]);
	}
	
	cout << lcm << endl;

	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, k) = readIntegerList()
    val ans = readIntegerList().sorted().take(k).sum()
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 39460
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		divisors();

	}
	
	public static void divisors() {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int divisors = 0;
		
		for (int i = a; i <= b; i++) {
			
			if (c % i == 0) {
				divisors++;
			}
		}
		
		System.out.println(divisors);
	}
}


Measured memory_bytes: 26404
# 経路復元

from collections import deque
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

H, W = map(int, input().split())

field = [list(input()) for i in range(H)]

queue = deque([])
seen = [[0] * W for i in range(H)]
prev_x = [[0] * W for i in range(H)]
prev_y = [[0] * W for i in range(H)]
direction = [[1, 0], [-1, 0], [0, 1], [0, -1]]


def bfs(y, x):
    queue.append([y, x])
    seen[y][x] = 1
    prev_x[y][x] = -1
    prev_y[y][x] = -1

    while len(queue) != 0:
        y, x = queue.popleft()

        for dy, dx in direction:
            next_x = x + dx
            next_y = y + dy

            if next_x < 0 or next_x >= W or next_y < 0 or next_y >= H:
                continue
            elif field[next_y][next_x] == "#":
                continue
            elif seen[next_y][next_x] != 0:
                continue
            else:
                seen[next_y][next_x] = 1
                prev_x[next_y][next_x] = x
                prev_y[next_y][next_x] = y
                queue.append([next_y, next_x])


shortest_path = [[0] * W for i in range(H)]


def path_restoration(y, x):
    shortest_path[y][x] = 1

    if prev_x[y][x] == -1 and prev_y[y][x] == -1:
        return
    else:
        next_y = prev_y[y][x]
        next_x = prev_x[y][x]
        path_restoration(next_y, next_x)


bfs(0, 0)
path_restoration(H - 1, W - 1)

ans = 0

for i in range(H):
    for j in range(W):
        if field[i][j] == "." and shortest_path[i][j] == 0:
            field[i][j] = "#"
            ans += 1

if seen[H - 1][W - 1] == 0:
    # たどりつけない場合
    print(-1)
else:
    print(ans)


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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
	
		int m[100];
		int p[100][100];
		int k;
		int l[100];
		bool man[100];
		queue<int> mannom;

		for(int i = 0; i < n; i ++){
			cin >> m[i];
			for(int j = 0; j < m[i]; j++){
				cin >> p[i][j];
			}
		}
		cin >> k;
		for(int i = 0; i < k; i++){
			cin >> l[i];
		}	//input

		//犯人捜し
		int know = 0;
		for(int i = 0; i < n; i++){	//人数
			
			for(int a = 0; a < m[i]; a++){	//知っている情報　漏えいした情報を知っている情報と比べる
				for(int j = 0; j < k; j++){	//漏えい
					if(l[j] == p[i][a]){
						know ++;
					}
				}
			}

			if(know == k){
				man[i] = true;
				know = 0;
			}else{
				man[i] = false;
				know = 0;
			}

		}

		int nom = 0;
		for(int i = 0; i < n; i++){
			if(man[i] == true){
				nom ++;
				mannom.push(i);
			}
		}

		if(nom == 1){
			cout << mannom.front()+1 <<endl;
		}else{
			cout << -1 << endl;
		}
	}
	return 0;
}

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

int main(){
  string s,t;
  cin >> s>>t;
  int ans =0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)==t.at(i)){
      ans++;
}  }
cout << ans << endl;
}



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

int main() {

    int n;

    while(cin >> n, n) {
        vector< pair< double, string > > ans;
        for(int i = 0; i < n; i++) {
            string str;
            int p, a, b, c, d, e, f, s, m;
            cin >> str >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            int t = a + b + c + (d + e) * m;
            int cnt = f * m;
            ans.push_back(make_pair(-(cnt * s - p) / (double)t, str));
        }

        sort(ans.begin(), ans.end());
        for(int i = 0; i < n; i++) {
            cout << ans[i].second << endl;
        } cout << "#" << endl;
    }
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
//#include <vector> 


int main(int argc, char* argv[])
{
    long a, b, c;
    scanf("%ld %ld %ld", &a, &b, &c);

    if(a+b>=c-1) {
        printf("%d\n", b+c);
    }
    else {
        printf("%d\n", a + b + 1 + b);
    }

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  long int h,a,i;
  scanf("%ld",&h);
  scanf("%ld",&a);
  for(i=0; ;i++)
  {
    h=h-a;
    if(h<=0 )
    {
      printf("%ld",(i+1));
      break;
  	}
  }
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    ll k;
    cin >> k;
    ll kosuu = 0;
    ll start = 0;
    vector<ll> v;//keta,suuzi
    for(ll i = 1;i<10;i++) {
        v.push_back(i);
        kosuu++;
        if(kosuu == k) {
            cout << i;
            return 0;
        }
    }
    while (1){
        for(ll i = start;i < v.size();i++) {
            if(v[i]%10 == 0) {
                kosuu++;
                v.push_back(v[i]*10);
                if(kosuu == k) {
                    cout << v[i]*10;
                    return 0;
                }
                kosuu++;
                v.push_back(v[i]*10+1);
                if(kosuu == k) {
                    cout << v[i]<<1;
                    return 0;
                }
            } else if(v[i]%10 == 9) {
                kosuu++;
                v.push_back(v[i]*10+8);
                if(kosuu == k) {
                    cout << v[i]<< 8;
                    return 0;
                }
                kosuu++;
                v.push_back(v[i]*10+9);
                if(kosuu == k) {
                    cout << v[i]<< 9;
                    return 0;
                }
            } else {
                kosuu++;
                v.push_back(v[i]*10+(v[i]%10)-1);
                if(kosuu == k) {
                    cout << v[i]<<(v[i]%10)-1;
                    return 0;
                }
                kosuu++;
                v.push_back(v[i]*10+(v[i]%10));
                if(kosuu == k) {
                    cout << v[i]<<(v[i]%10);
                    return 0;
                }
                kosuu++;
                v.push_back(v[i]*10+(v[i]%10)+1);
                if(kosuu == k) {
                    cout << v[i]<<(v[i]%10)+1;
                    return 0;
                }
            }
            start = v.size();
        }
    }
}



Measured memory_bytes: 1400
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h[i];

    for(int i = n-1; i > 0; i--)
    {
        if(h[i]-h[i-1] < -1)
        {
            cout<<"No\n";
            return 0;
        }
        else if(h[i]-h[i-1] == -1)
        {
            h[i-1]--;
        }
    }

    cout<<"Yes\n";

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner

object Main {
  def isNum(ch: Char): Boolean = {
    val ret = ch match {
      case '0' => true
      case '1' => true
      case '2' => true
      case '3' => true
      case '4' => true
      case '5' => true
      case '6' => true
      case '7' => true
      case '8' => true
      case '9' => true
      case _ => false
    }
    return ret
  }
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a, b = sc.nextInt()
    val s = sc.next()
//    println(s)
    var f = true
    for(i <- 0 until a) {
      f = isNum(s(i))
//      println(i)
    }
    if(f) {
//      println("Yes")
    } else {
      println("No")
      return
    }
    f = if(s(a)!='-') {
      false
    } else {
      true
    }
    if(f) {
//      println("Yes")
    } else {
      println("No")
      return
    }
//    println(a + " " + b)
    for(i <- a+1 until a+b+1) {
      f = isNum(s(i))
//      println(i)
    }
    if(f) {
      println("Yes")
    } else {
      println("No")
    }
  }
}


Measured memory_bytes: 25544
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=nxt();
    int n=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    vector <int> dist(n);
    for(int i=0;i<n-1;i++)
        dist[i]=v[i+1]-v[i];
    dist[n-1]=k-v[n-1]+v[0];
    int m=INT_MIN;
    for(int i=0;i<n;i++)
        m=max(m,dist[i]);
    cout<<k-m<<endl;

    
    
    return 0;   
}


 
 


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 102
#define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;
int n;
struct matrix{
	vector< vector < int > > m ;
	matrix() {
		m.resize(n , vector < int > (n));
	}
	matrix operator * (const matrix &b){
		matrix a = matrix();
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ;j < n ; j++)
				for(int k = 0 ; k < n ; k++)
					a.m[i][j] = (a.m[i][j] + m[i][k] * b.m[k][j] ) % mod;  

		return a;
	}

};


signed main(){
  fast;
  int k , ans = 0;
  cin >> n >> k;
  vector < vector < int > > a (n , vector < int > (n));
  for(int i = 0 ; i < n ; i++)
  	for(int j = 0 ; j < n ; j++)
  		cin >> a[i][j];


  matrix r  = matrix();
  r.m = a;
  
  matrix res = matrix();
  for(int i = 0 ; i < n ; i++)
  	res.m[i][i] = 1;

  while(k > 0 ){
  	if(k % 2 == 1)
  		res = (res * r);

  	r = r * r;
  	k/=2;
  }

  for(int i = 0 ; i < n  ; i++)
  	for(int j = 0 ; j < n ; j++){
  		ans += res.m[i][j];
  		ans %= mod;
  	}

  	cout <<  ans << endl;

  


}	

Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
current =0
cost =[]
a.append(0)
for i in range(n):
    cost.append(abs(a[i]-current))
    current=a[i]
cost.append(abs(current))
costTotal = sum(cost)
current =0
for i in range(n):
    print(costTotal-cost[i]-cost[i+1]+abs(a[i+1]-current))
    current=a[i]

Measured memory_bytes: 14044
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if (i * j == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 24148
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#define MAX_N 100
#define INF 10000000

using namespace std;

int a, b;

void solve() {
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
}

int main() {
	cin >> a >> b;
	solve();
	return 0;
}

Measured memory_bytes: 256
// 2018/12/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, m, t, p;
		cin >> n >> m >> t >> p;

		if(n==0 && m==0 && t==0 && p==0)
			break;

		int Ori[64][64] = { {0} };
		for(int y=0; y<m; y++){
			for(int x=0; x<n; x++){
				Ori[y][x] = 1;
			}
		}

		for(int i=0; i<t; i++){
			int d, c;
			cin >> d >> c;

			if(d==1){
				for(int x=0; x<c; x++){
					for(int y=0; y<m; y++){
						Ori[y][2*c-1-x] += Ori[y][x];
						Ori[y][x] = 0;
					}
				}

				for(int x=0; x<n; x++){
					for(int y=0; y<m; y++){
						Ori[y][x] = Ori[y][x+c];
						Ori[y][x+c] = 0;
					}
				}
			}
			else{
				for(int y=0; y<c; y++){
					for(int x=0; x<n; x++){
						Ori[2*c-1-y][x] += Ori[y][x];
						Ori[y][x] = 0;
					}
				}

				for(int y=0; y<m; y++){
					for(int x=0; x<n; x++){
						Ori[y][x] = Ori[y+c][x];
						Ori[y+c][x] = 0;
					}
				}
			}
/*
			for(int y=0; y<m; y++){
				for(int x=0; x<n; x++){
					cout << Ori[y][x];
				}
				cout << endl;
			}
*/
		}

		for(int i=0; i<p; i++){
			int x, y;
			cin >> x >> y;

			cout << Ori[y][x] << endl;
		}
	}

	return 0;
}



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

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

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

int main() {
    cin>>N;
    vec a(N), ord(N);
    rep(i,N) cin>>a[i];
    rep(i,N) ord[i] = i;
    sort(ALL(ord), [&](int x, int y){
        return a[x] > a[y];
    });
    mat dp(N + 1, vec(N + 1, -INF));
    dp[0][0] = 0;
    rep(i,N){
        //cout<<i<<' '<<ord[i]<<endl;
        rep(j,N){
            chmax(dp[i+1][j+1], dp[i][j] + a[ord[i]] * abs(j - ord[i]));
            chmax(dp[i+1][j], dp[i][j] + a[ord[i]] * abs(N - (i + 1 - j) - ord[i]));
            //cout<<dp[i][j]<<' ';
        }
        //cout<<endl;
    }
    ll ans = 0;
    rep(j,N + 1) chmax(ans, dp[N][j]);
    cout<<ans<<endl;
}

Measured memory_bytes: 34680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define N 100002

using namespace std;

int main()
{
	long int a,b,c,res,n,i,j;
	int in[N];
	
	memset(in,0,sizeof(in));
	
	while (1==scanf("%ld",&n))
	{
		res=0;
		in[0]=0;
		
		for (i=1;i<=n;i++)
		{
			scanf("%d",&in[i]);
		}
		
		for (i=0,j=1;j<=n;i++,j++)
		{
			res=res+abs(in[i]-in[j]);
		}
		
		res=res+labs(in[n]);
		
		for (i=2;i<=n+1;i++)
		{
			a=in[i-2];
			b=in[i-1];
			c=in[i];
			
			if (n+1==i)
			{
				c=0;
				b=in[i-1];
				a=in[i-2];
			}
			
			if (b<=a&&a<=c)
			{
				printf("%ld\n",res-2*(a-b));
			}
			
			else if (a<=c&&c<=b)
			{
				printf("%ld\n",res-2*(b-c));
			}
			
			else if (b<=c&&c<=a)
			{
				printf("%ld\n",res-2*(c-b));
			}
			
			else if (c<=a&&a<=b)
			{
				printf("%ld\n",res-2*(b-a));
			}
			
			else
			{
				printf("%ld\n",res);
			}
		}
	}
	
	return 0;
 } 

Measured memory_bytes: 1664
//E.H//
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int h,w;
char arr[105][105]; 
int memo[105][105];
int f(int x,int y){
    if(x==h && y==w){
        return arr[h][w]=='#';
    }
    if(memo[x][y]!=-1) return memo[x][y];
    int res=100000000;
    if(arr[x][y]=='.'){
        if(x<h){
            res=min(res,f(x+1,y));
        }
        if(y<w){
            res=min(res,f(x,y+1));
        }

    }
    else{
        if(x<h){
            res=min(res,f(x+1,y)+ ((arr[x+1][y]=='.') ? 1:0));
        }
        if(y<w){
            res=min(res,f(x,y+1)+ ((arr[x][y+1]=='.') ? 1:0));
        }
    }
    return memo[x][y]=res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>arr[i][j];
        }
    }
    memset(memo,-1,sizeof(memo));
    cout<<f(1,1)<<endl;
}

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

const int MAX=100000;

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

inline void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid -left;
  int n2 = right -mid;
  for(i=0; i<n1; i++) L[i] = A[left+i];
  for(i=0; i<n2; i++) R[i] = A[mid+i];
  L[n1].value = R[n2].value = 2000000000;
  i = j = 0;
  for(k = left; k < right; k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

inline void merge_sort(struct Card A[], int n, int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    merge_sort(A, n, left, mid);
    merge_sort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

inline int partiton(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for ( j=p; j<r; j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

inline void quick_sort(struct Card A[], int n, int p, int r){
  int q;
  if(p < r){
    q = partiton(A, n, p, r);
    quick_sort(A, n, p, q-1);
    quick_sort(A, n, q+1, r);
  }
}

int main() {
    ios::sync_with_stdio(false);
    int n, v;
    struct Card A[MAX], B[MAX];
    char chr;
    bool is_stable = true;

    cin >> n;

    for(int i=0; i<n; i++){
      cin >> chr >> v;
      A[i].suit = B[i].suit = chr;
      A[i].value = B[i].value = v;
    }

    merge_sort(A, n, 0, n);
    quick_sort(B, n, 0, n-1);

    for(int i=0; i<n; i++){
      if(A[i].suit != B[i].suit) is_stable = false;
    }

    if(is_stable) cout << "Stable\n";
    else cout << "Not stable\n";
    for(int i=0; i<n; i++){
      cout << B[i].suit << " " << B[i].value << "\n";
    }


}

Measured memory_bytes: 3552
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector<T> >;

int main() {
  vector<int> results;

  while (true) {
    int count;
    cin >> count;
    if (count == 0) { break; }
    vi point(count);
    for (int i = 0 ; i < count ; i++) {
      cin >> point[i];
    }
    //sort(point.begin(), point.end());
    int max_point = -1;
    int min_point = 1001;
    int ave = 0;
    for (int i = 0 ; i <= point.size()-1 ; i++) {
      ave += point[i];
      if (max_point < point[i]) {
        max_point = point[i];
      }
      if (min_point > point[i]) {
        min_point = point[i];
      }
    }
    ave -= (max_point + min_point);
    ave /= (count-2);
    results.push_back(ave);
  }

  for (int i = 0 ; i < results.size() ; i++) {
    printf("%d\n", results[i]);
  }

  return 0;
}

Measured memory_bytes: 3172
N, M = list(map(int, input().split()))

re = {}
city = {}
for i in range(M):
    p, y = list(map(int, input().split()))
    city['{}_{}'.format(p,y)] = i

    if p in re:
        re[p].append(y)
    else:
        re[p] = [y]

ret = [''] * M
for k, v in sorted(re.items()):
    y = sorted(v)
    for i in range(len(y)):
        ret[city['{}_{}'.format(k,y[i])]] = '{:0=6}{:0=6}'.format(k, i+1)

for i in range(M):
    print(ret[i])

Measured memory_bytes: 55276
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val MAX = 100000

  val(n, k) = readLine()!!.split(" ").map { it.toLong() }

  val table = LongArray(MAX+1)
  (0L until n).forEach {
    val(a, b) = readLine()!!.split(" ").map { it.toInt() }
    table[a] += b.toLong()
  }

  tailrec fun rec(acc: Long, i: Int, t: Long): Int {
    val v = acc + table[i]
    if(v >= t) return i
    return rec(v, i+1, t)
  }

  val ans = rec(0L, 0, k)
  println(ans)
}

Measured memory_bytes: 55620
x = int(input())
if x>= 400 and x<= 599:
  print(8)
if x>= 600 and x<= 799:
  print(7)
if x>= 800 and x<= 999:
  print(6)
if x>= 1000 and x<= 1199:
  print(5)
if x>= 1200 and x<= 1399:
  print(4)
if x>= 1400 and x<= 1599:
  print(3)
if x>= 1600 and x<= 1799:
  print(2)
if x>= 1800 and x<= 1999:
  print(1)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const int INF = 1e9 + 10;
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	reverse(a.begin(), a.end());
	vector<int> v(N + 1, INF);
	for (int i = 0; i < N; ++i) {
		*upper_bound(v.begin(), v.end(), a[i]) = a[i];
	}
	int res = lower_bound(v.begin(), v.end(), INF) - v.begin();
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    if ( s. size() < 4) {
        cout << "No";
        return 0;
    }
    string a = "YAKI";
    string b;
    for ( int i = 0; i < 4; i++) {
        b += s[i];
    }
    if ( a == b) {
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {

	N, X, Y := ReadInt(), ReadInt(), ReadInt()
	c := make(map[int]int)
	for i := 1; i < N; i++ {
		for j := i + 1; j <= N; j++ {
			d := Min(
				Abs(j-i),
				Abs(X-i)+1+Abs(j-Y),
			)
			c[d]++
		}
	}
	for k := 1; k < N; k++ {
		fmt.Println(c[k])
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

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 }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2084
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a=new int[5];
		int an=0;
		int kk=9;
		for(int i = 0; i<5; i++){
			a[i]=sc.nextInt();
			if(a[i]%10!=0 && a[i]%10<=kk){
				kk=a[i]%10;
				an=a[i];
			}
		}
		int ans=0;
		int count=0;
		for(int i = 0; i<5; i++){
			if(a[i]==an && count==0){
				count++;
				continue;
			}
			if(ans%10!=0){
				ans+=10-ans%10;
				ans+=a[i];
			}else{
				ans+=a[i];
			}
		}
		if(ans%10!=0){
				ans+=10-ans%10;
				ans+=an;
		}else{
				ans+=an;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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;
  string S;
  cin >> S;
  int E[303030],W[303030];
  REP(i,N){
    if(S[i] == 'E') E[i]++;
    else W[i]++;
  }
  REP(i,N){
    W[i] += W[i-1];
    E[i] += E[i-1];
  }
  int ans = INF;
  REP(i,N){
    int sum = 0;
    if(i) sum += W[i-1];
    sum += E[N-1] - E[i];
    ans = min(ans,sum);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());

  int w = 0;
  while (w < S.size() - 1 && S[w] != 'W') {
    w++;
  }

  int ans = 0;
  for (int b = w + 1; b < S.size(); b++) {
    if (S[b] != 'B') {
      continue;
    }

    ans += b - w;
    w++;
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 720
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}


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


    vector<deque<ll>> vv(10);

    rep(i,9){
        vv[i].push_front(i+1);
    }
    if(k<=9){
        cout<<k<<endl;
        return 0;
    }
    k-=9;
    int t=0;

    while(k>0){


        deque<ll> v = vv[t];
//        cout<<t<<endl;
//
//        rep(ii,vv.size()){
//            cout<<vv[t][ii]<<" ";
//        }
//        cout<<endl;


        int vsize= v.size();
        for(int i=0;i<vsize;i++){

            ll vk = v.front();
            v.pop_front();
            ll vs=vk%10;


            if(vs==0){
                rep(ti,2){
                    k--;
                    v.push_back(ll(vk*10+ti));
                    if(k==0){
                        cout<<vk*10+ti<<endl;
                        return 0;
                    }
                }
            }else if(vs==9){
                for(int ti=1;ti>=0;ti--){
                    k--;
                    v.push_back(ll(vk*10+vs-ti));
                    if(k==0){
                        cout<<vk*10+vs-ti<<endl;
                        return 0;
                    }
                }
            }else{

                for(int ti=-1;ti<2;ti++){
                    k--;
                    v.push_back(ll(vk*10+vs+ti));
                    if(k==0){
                        cout<<vk*10+vs+ti<<endl;
                        return 0;
                    }
                }
            }
        }
        vv[t]=v;

        t++;
        if(t>=9){
            t=0;
        }


    }







return 0;
}


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

int main() {
  int n,x,t;
  cin >> n >> x >> t;

  int times = n / x;
  if (n % x != 0) times++;

  cout << times * t << endl;
}


Measured memory_bytes: 3636
object Main extends App {
	
	val NK = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val A = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var S = new Array[Int](NK(0))
	
	var ans = 0

	for(i<-A){
		S(i-1) = S(i-1) + 1
	}

	S = S.filter(_ != 0).sorted

	val temp = S.size - NK(1)

	println(S.dropRight(S.size - temp).sum)


}


Measured memory_bytes: 54776
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n,m;
  cin >> n >> m;
  vector<P> key;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    int s = 0;
    rep(j,b){
      int c;
      cin >> c;
      c--;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }

  vector<int> dp(1<<n,INF);
  dp[0] = 0;
  rep(i,1<<n){
    rep(j,m){
      int s = i | key[j].first;
      int cost = dp[i] + key[j].second;
      chmin(dp[s],cost);
    }
  }
  int ans = dp.back();
  if(ans==INF){
    puts("-1");
    return 0;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e15 + 5;
double PI = 3.14159265358979323846;

void solve() {

    int n;
    cin >> n;
    vl a(n+1);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    vvl dp(n+1,vl(n+1,0));

    // dp[i][j] = minimum possible in range [i....j]

    for(int i = 2;i <= n;i++){
        int r = 1;
        int c = i;
        while(c <= n){
           
            ll temp = inf;
            ll s = 0;
            for(int j = r;j <= c;j++){
                s+= a[j];
            }
            for(int j = r;j < c;j++){
                temp = min(temp,dp[r][j]+dp[j+1][c]+s);
            }
            dp[r][c] = temp;
            r++;c++;
        }
    }

    cout << dp[1][n] << endl;


}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 4520
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)

int main(void){
  int n;
  double ans=0;
  scanf("%d",&n);
  double a[n];
  FOR(n)scanf("%lf",&a[i]);
  FOR(n-1){
    for(int j=0;j<n-1;j++){
      if(a[j]>a[j+1]){
      	double t=a[j];
      	a[j]=a[j+1];
        a[j+1]=t;
      }
    }
  }
  FOR(n)if(i)a[i]=(a[i-1]+a[i])/2.0;
  printf("%.10lf\n",a[n-1]);
  return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, K;

ll solve(ll N);

int main()
{
    cin >> N >> K;
    cout << solve(N) << endl;
}

ll solve(ll N)
{
    if (N == 1)
    {
        return 2;
    }
    return min(solve(N - 1) * 2, solve(N - 1) + K);
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;


int main(){
    int X;
    cin >> X;
    vector<bool> dp(X+1,false);
    dp[0]=true;

    for(int i=1;i<=X;i++){
        for(int k=100;k<=105;k++){
            if(i-k >= 0 && dp[i-k]){
                dp[i] = true;
                break;
            }
        }
    }
    if(dp[X]){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  double a[n];
  double ans = 0;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n - 1) a[i + 1] = (a[i + 1] + a[i]) / 2;
  cout << a[n - 1] << endl;

  return 0;
}

Measured memory_bytes: 3808
eval"N,K,S,T,*A="+`dd`.split*?,
A.select!{1>~_1&S|_1&~T}
c=[1]*51
c.map{$*<<c[K]-1
t=0
c.map!{t+t=_1}}
p (S..T).sum{|u|~u&S|u&~T<1?A.map{_1&u}.tally.sum{$*[_2]}*(1-('%b'.%u-S).count(?1)%2*2):0}

Measured memory_bytes: 14540
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
template<class T>
struct Edge {
    int src, to;
    T cost;

    Edge (int to, T cost):
        src(-1), to(to), cost(cost) {};
    Edge (int src, int to, T cost):
        src(src), to(to), cost(cost) {};

    operator int() const {
        return to;
    };
};

template <class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using UnWeightedGraph = vector<vector<int> >;
//===

llong n;
queue<llong> d0, d1, d2;
vector<llong> color;
UnWeightedGraph g;
llong cnt[2];

void dfs(llong u, llong par, llong c) {
    cnt[c]++;
    color[u] = c;
    for (auto v:g[u]) {
        if (v == par) continue;
        dfs(v, u, c ^ 1);
    }
}

int main() {
    cin >> n;
    color.resize(n + 1);
    g.resize(n + 1);
    for (int i = 0; i < n - 1; i++) {
        llong a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) d0.push(i);
        if (i % 3 == 1) d1.push(i);
        if (i % 3 == 2) d2.push(i);
    }

    dfs(1, -1, 0);
    if (cnt[0] > (n / 3) && cnt[1] > (n / 3)) {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 1 && !d1.empty()) {
                cout << d1.front() << ' ';
                d1.pop();
            }
            else if (color[i] == 0 && !d2.empty()) {
                cout << d2.front() << ' ';
                d2.pop();
            }
            else {
                cout << d0.front() << ' ';
                d0.pop();
            }
        }
    }
    else if (cnt[0] <= (n / 3)) {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 0) {
                cout << d0.front() << ' ';
                d0.pop();
            }
            else {
                if (!d1.empty()) {
                    cout << d1.front() << ' ';
                    d1.pop();
                }
                else if (!d2.empty()) {
                    cout << d2.front() << ' ';
                    d2.pop();
                }
                else {
                    cout << d0.front() << ' ';
                    d0.pop();
                }
            }
        }
    }
    else {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 1) {
                cout << d0.front() << ' ';
                d0.pop();
            }
            else {
                if (!d1.empty()) {
                    cout << d1.front() << ' ';
                    d1.pop();
                }
                else if (!d2.empty()) {
                    cout << d2.front() << ' ';
                    d2.pop();
                }
                else {
                    cout << d0.front() << ' ';
                    d0.pop();
                }
            }
        }
    }

    cout << endl;
    
    return 0;
}


Measured memory_bytes: 19200
#include <iostream>
#include <bitset>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
using namespace std;
int main(){
	int x, y;
	scanf("%d%d", &x, &y);
	printf("%d", (x + (y / 2)));
	return 0;
}

Measured memory_bytes: 256
/* ex 9_2
   hangan2020 */

#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
   //追加する分の領域を確保
   node *new = calloc(1, sizeof(node));
   if(new == NULL) exit(1);
   new->elem = elem;
   new->next = *first;
   *first = new;
}

//スタックからデータを取り出す
void pop(node **first){
   char elem;
   node *tmp = *first;
   if(tmp == NULL) exit(1);
   elem = tmp->elem;
   *first = tmp->next;
   //取り出したノードのメモリを解放
   free(tmp);
}

int main(void){
   char cube_input[SIZE]; 
   int i = 0;
   int remove_count = 0;
   node *first = NULL;
   //printf("%p\n", first);

   scanf("%s", &cube_input);

   while(cube_input[i] != '\0'){
      //printf("cube_input[%d]: %c\n", i, cube_input[i]);
      if(first == NULL){
         push(&first, cube_input[i]);
         i++;
      }else{
         push(&first, cube_input[i]);
         //printf("%p\n", first);
         //printf("first elem: %c", first->elem);
         if(first->elem != first->next->elem){
            //printf("got here\n");
            //printf("first->elem: %c\n", first->elem);
            //printf("first>next>elem: %c\n", first->next->elem);
            pop(&first);
            pop(&first);
            remove_count++;
            remove_count++;
         }
         i++;
      }
      //printf("got through if\n");
   }

   printf("%d", remove_count);

   return 0;

}


Measured memory_bytes: 4948
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int d[N];
  int i, j;
  int kaifuku,goukei;
  for(i=1; i<=N; i++){
    
    cin >> d[i];
  }
  for(i=1; i<=N-1;i++){
    for(j=i+1;j<=N;j++){
      kaifuku=d[i]*d[j];
      goukei+=kaifuku;
    }
  }
  cout << goukei << endl;
 
}

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

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


Measured memory_bytes: 256
// author:-*mdragneell*

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pi  pair<int,int>
#define pl  pair<ll,ll>

int const N=100005;
ll min(ll x,ll y) { if(x<y) return x; else return y; }
ll max(ll x,ll y) { if(x>y) return x; else return y; }

ll cache[N];
ll n,k,a[N];

ll sol(ll k)
{
    if(k==0) return 0;
    if(cache[k]!=-1) return cache[k];

    cache[k]=0;

    for(int i=0;i<n;i++){
        if(k<a[i]) break;
        cache[k]|=(sol(k-a[i])==0);
    }
    return cache[k];

}

int main()
{
        ll i,j;
        cin>>n>>k;

        memset(cache,-1,sizeof(cache));

        for(i=0;i<n;i++)
            cin>>a[i];

        if(sol(k)) cout<<"First"<<endl;
        else cout<<"Second"<<endl;


}


Measured memory_bytes: 4096
#include<iostream>
#include <math.h>       /* sin */
using namespace std;
#define PI 3.1415926535897932384626


int min(int x, int y) {  
    return (x < y)? x: y;  
}  
  
double calcAngle(double h, double m)   {  
   
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    double  angle = abs(hour_angle - minute_angle);  
  
    angle = min(360.0 - angle, angle);  
  
    return angle;  
} 

double calcSide(double angle, int a, int b) {
	double ans = (a*a*1.0);
	ans += (b*b*1.0);
	ans -= (2*a*1.0*b*1.0*cos(angle*PI/180));
	return sqrt(ans);
}	

int main() {
	
	int a, b, h, m;
	cin>>a>>b>>h>>m;

	double angle = calcAngle(1.0*h, 1.0*m);
	// cout<<angle<<endl;
	printf("%.12f\n", calcSide(angle, a, b));

}

Measured memory_bytes: 4192
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
#include <sstream>
using namespace std;
bool fel[100][100];
int w,h;
void dif(int x,int y);
int main(void){
    while(true){
        cin>>w>>h;
        if(w+h==0)break;
        for(int s=0;s<h;s++){
            for(int i=0;i<w;i++){
                cin>>fel[s][i];
            }
        }
        int cnt=0;
        for(int s=0;s<h;s++){
            for(int i=0;i<w;i++){
                if(fel[s][i]){
                    dif(i,s);
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}
void dif(int x,int y){
    fel[y][x]=0;
    for(int s=-1;s<=1;s++){
        for(int i=-1;i<=1;i++){
            int nx=x+i,ny=y+s;
            if(nx>=0&&nx<w&&ny>=0&&ny<h&&fel[ny][nx])dif(nx, ny);
        }
    }
    return;
}

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

int main(){
	int n;
	cin >> n;
  	int* h = new int[n];
  	for(int i = 0; i < n; i++)
      	cin >> h[i];
  	int* dp = new int[n];
  	dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
    	 int t1,t2;
      	 t1 = dp[i-1] + abs(h[i-1] - h[i]);
      	 t2 = dp[i-2] + abs(h[i-2] - h[i]);
     	 dp[i] = min(t1, t2);
    }
  	cout<<dp[n-1];
	return 0;
  
}


Measured memory_bytes: 1024