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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

ll inf = mod - 7;

void solve()
{
	inf *= inf;
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (auto& e : a)
		cin >> e;
	sort(a.begin(), a.end());
	ll p = 1;
	if (a[0] == 0)
	{
		cout << 0;
		return;
	}
	for (auto& e : a)
	{
		if (e > inf / p)
		{
			cout << -1 << '\n';
			return;
		}
		p *= e;
		if (p > inf)
		{
			cout << -1 << '\n';
			return;
		}
	}
	cout << p << '\n';
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll a[1000010];

void solve(){

    long double r;
    long double PI=3.14159265358979323846;
    cin >> r;
    cout << 2*r*PI << endl;

}

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


Measured memory_bytes: 3800
<?php
$numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
$n = intval($numbers[0]);
$q = intval($numbers[1]);

// print $n;
// print $q;
// $a[]; //一次元配列
// $a[][]; //要素　$aの値　インデックスではない。
$a = []; //二次元配列
for ($i = 0; $i < $n; $i++){
    $a[] = [];
}

for($i = 0; $i < $q; $i++){
    $numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
    if (intval($numbers[0]) === 0){
        $a[intval($numbers[1])][] = $numbers[2];
    } else if (intval($numbers[0]) === 1){
        if (count($a[intval($numbers[1])]) != 0 ){
            $result = $a[intval($numbers[1])][count($a[intval($numbers[1])]) - 1];
            // $result = array_pop($a[intval($numbers[1])]);
            print $result;
            print "\n";
        }

    } else {
        if (count($a[intval($numbers[1])]) != 0 ){
            array_pop($a[intval($numbers[1])]);
        }
    }
}


Measured memory_bytes: 44868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, M, P;
ll V_MAX = 2600;
ll E_MAX = 5100;
struct edge {
    ll from;
    ll to;
    ll cost;
};
vector<edge> G(E_MAX);
vector<vector<ll>> GG(V_MAX);
vector<vector<ll>> GGG(V_MAX);
vector<ll> d(V_MAX);
vector<ll> pre(V_MAX);
vector<bool> r(V_MAX);
vector<bool> rr(V_MAX);

void reach(ll v){
    for (ll next_v : GG[v]){
        if(r[next_v] == true) continue;
        r[next_v] = true;
        reach(next_v);
    }
}
void rreach(ll v){
    for (ll next_v : GGG[v]){
        if(rr[next_v] == true) continue;
        rr[next_v] = true;
        rreach(next_v);
    }
}

bool search(ll v){
    fill(ALL(d), -INF);
    fill(ALL(pre), -1);
    d[v] = 0;
    ll cnt = 0;
    bool update;
    while(true){
        update = false;
        for (ll i = 0; i < M; i++) {
            edge e = G[i];
            if(d[e.from] + e.cost > d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                pre[e.to] = e.from;
                if((r[e.to] || r[e.from]) && (rr[e.to] || rr[e.from])){
                    update = true;
                }
            }
        }
        if(update == false) break;
        cnt++;
        if(cnt >= N){
            printf("-1\n");
            return true;
        }
    }
    return false;

}

int main(){
    cin >> N >> M >> P;
    ll a, b, c;
    G.resize(N);
    GG.resize(N);
    for (ll i = 0; i < M; i++) {
        cin >> a >> b >> c;
        a--; b--;
        G[i].from = a;
        G[i].to = b;
        G[i].cost = c - P;
        GG[b].push_back(a);
        GGG[a].push_back(b);
    }
    fill(ALL(r), false);
    fill(ALL(rr), false);
    reach(N-1);
    rreach(0);


    if(search(zero)){
        return 0;
    }
    else{
        ll tmp = N-1;
        ll cnt = 0;
        while(tmp != 0){
            tmp = pre[tmp];
            cnt++;
        }
        printf("%lld\n", max(d[N-1], zero));
    }



}

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

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    int p[3] = {}; 
    int turn = 0;
    while(p[turn] < s[turn].length()){
        int next = s[turn][p[turn]] - 'a';
        p[turn]++;
        turn = next;
    }
    cout << (char)(turn + 'A') << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	int ng = -1, ok = n;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		bitset<5010> dp;
		dp[0] = 1;
		rep(i, n) if (i != mid && a[i] <= 5000) dp |= (dp << a[i]);
		bool flag = false;
		for (int i = max(0LL, k - a[mid]); i < k; i++) if (dp[i]) flag = true;
		if (flag) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;

double cross_product(xy_t a, xy_t b) {
  return (conj(a) * b).imag();
}

const double eps = 1e-11;
double x[4], y[4];
int N;
int main() {
  cin >> N;
  for (int t = 0; t < N; ++t) {
    for (int i = 0; i < 4; ++i) {
      cin >> x[i] >> y[i];
    }
    xy_t a[2] = {
      xy_t(x[0], y[0]) - xy_t(x[1], y[1]),
      xy_t(x[2], y[2]) - xy_t(x[3], y[3])
    };
    bool p = abs(cross_product(a[0], a[1])) < eps;
    cout << (p ? "YES" : "NO") << endl;
  }
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define INF             1e9
#define INFL            1e19
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cout << endl;
#define HOISE           cout << "hoise" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cout << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

#define MASK(x)         for(int i = 0; i < 8; i++){ if(x&(1<<i)){ cout << i << " "; } } cout << endl;

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pff;

const int MAX = 200000 + 2;
const int MAXLOG = log2(MAX) + 2;
const int MAXN = 1e6 + 2;
const int MOD = 1000000007;
const double PY = acos(-1.0);

int main()
{
//    READ;
//    WRITE;
    FASTIO;

    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 3; i++){
        if(i!=a and i!=b){
            cout << i;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String W = in.nextLine();
		W = W.toLowerCase();
		int ans = 0;
		while(in.hasNext()) {
			String s = in.nextLine();
			if(s.equals("END_OF_TEXT")) break;
			s = s.toLowerCase();
			String sp[] = s.split(" ");
			for(int i=0;i<sp.length;i++) {
				if(sp[i].equals(W)) ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26212
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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; }


int n,m,a[1010],b[1010];
int dp[10101];

int main(){
	cin >> m >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	
	for(int i = 0; i < 10101; i++) dp[i] = INF;
	dp[m] = 0;
	
	for(int i = m; i >= 0; i--){
		for(int j = 0; j < n; j++){
			chmin(dp[max(0,i-a[j])], dp[i]+b[j]);
		}
	}
	
	cout << dp[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())
sumans = 0
for i in range(N+1):
    nn = i
    nnsum = 0
    while nn > 0:
        a = nn%10
        nn = int(nn/10)
        nnsum += a
    if(nnsum <= B and nnsum >= A):
        sumans += i
        
print(sumans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 100005
using namespace std;
typedef long long ll;
int main()
{
    int n,a[105]={0},ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        if(i%2&&a[i]%2)
        ans++;
    cout<<ans;
    return 0;
}

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

int main(void)
{
  int n, before;
  cin >> n;
  bool allSame = true;
  vector<int> l(n/2), r(n/2);
  unordered_map<int, int> lc, rc;
  for (int j=0; j < n/2; ++j) {
    cin >> l[j] >> r[j];
    lc[l[j]] += 1;
    rc[r[j]] += 1;
  }
  before = l[0];
  for (int j=1; j < l.size(); ++j) {
    if (l[j] != before) allSame = false;
  }
  if (allSame) {
    for (int j=0; j < r.size(); ++j) {
      if (r[j] != before) allSame = false;
    }
  }
  if (allSame) {
    cout << n/2 << endl;
    return 0;
  }
  
  if (n == 2) {
    if (l[0] == r[0]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  
  vector<tuple<int, int>> lrank, rrank;
  for (auto itr=lc.begin(); itr != lc.end(); ++itr) {
    lrank.push_back(make_tuple(itr->second, itr->first));
  }
  for (auto itr=rc.begin(); itr != rc.end(); ++itr) {
    rrank.push_back(make_tuple(itr->second, itr->first));
  }
  sort(lrank.rbegin(), lrank.rend());
  sort(rrank.rbegin(), rrank.rend());
  int l1, l1c, l2, l2c, r1, r1c, r2, r2c;
  tie(l1c, l1) = lrank[0];
  tie(l2c, l2) = lrank[1];
  tie(r1c, r1) = rrank[0];
  tie(r2c, r2) = rrank[1];
  if (l1 == r1) {
    if (l1c == r1c) {
      if (l2c > r2c) {
        cout << (n/2-l2c)+(n/2-r1c) << endl;
      } else {
        cout << (n/2-l1c)+(n/2-r2c) << endl;
      }
    } else if (l1c > r1c) {
      cout << (n/2-l1c)+(n/2-r2c) << endl;
    } else {
      cout << (n/2-l2c)+(n/2-r1c) << endl;
    }
  } else {
    cout << (n/2-l1c)+(n/2-r1c) << endl;
  }
}



Measured memory_bytes: 5908
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)

flag_h = True
flag_v = True
h, v = 0, 0

for i in A:
    if flag_h:
        if h == i:
            flag_h = False
        else:
            h = i
    elif flag_v:
        if v == i:
            flag_v = False
        else:
            v = i

if not (flag_v and flag_h):
    print(h * v)
else:
    print(0)

Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main () {
	
	
	int n;
	while (cin >> n) {
		bool flag = 0;
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				if (n == i * j) {
					printf("Yes\n");
					flag = 1;
					break;
				}
			}
			if (flag) break;
		}
		if (flag == 0) printf("No\n");
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

const int mod = 1e+9 + 7;
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	long long N;
	cin>>N;
	long long sum = 0;
	for(long long K=1; K<=N; K++)
	{
		sum += (N/K)*(2*K + ((N/K)-1)*K) / 2;
	}
	cout<<sum<<endl;
}

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

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

	auto solve = [](const auto &f, int64_t n, int m, int index = 0, int64_t x = 0, bool a = false, bool b = false, bool c = false) -> int {
		if (index == m)
		{
			return (a & b & c & (x <= n));
		}
		return (a & b & c & (x <= n)) + (f(f, n, m, index + 1, 10 * x + 3, a | true, b, c) + f(f, n, m, index + 1, 10 * x + 5, a, b | true, c) + f(f, n, m, index + 1, 10 * x + 7, a, b, c | true));
	};

	cout << solve(solve, n, to_string(n).size()) << endl;

	return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

std::vector<std::string> split(std::string str, char del) {
    int first = 0;
    int last = str.find_first_of(del);

    std::vector<std::string> result;

    while(first < str.size()) {
        std::string subStr(str, first, last - first);

        result.push_back(subStr);

        first = last + 1;
        last = str.find_first_of(del, first);

        if(last == std::string::npos) {
            last = str.size();
        }
    }

    return result;
}

int N;
VL A;

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        if(i) {
            ans = gcd(ans, IN());
        } else {
            ans = IN();
        }
    }
    cout << ans << "\n";
}


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

int main()
{
  long long int q1, b, c1, c2, q2;
  while (cin >> q1 >> b >> c1 >> c2 >> q2) {
    if (q1 == 0)
      break;

    long long int aizu = min(b/c1, q2);
    b -= aizu * c1;
    long long int chicken = b / c2;
    b -= chicken * c2;

    if (aizu+chicken < q1 && c1 > c2) {
      while (aizu > 0 && aizu+chicken < q1) {
	--aizu;
	b += c1;
	long long int new_chicken = b / c2;
	b -= new_chicken * c2;
	chicken += new_chicken;
      }
    }

    if (aizu <= 0LL || aizu+chicken < q1)
      cout << "NA" << endl;
    else
      cout << aizu << " " << chicken << endl;
  }
  return 0;
}

Measured memory_bytes: 0
def b163(n, m, al):


    return n - sum(al) if n - sum(al) >= 0 else "-1"

def main():
    n , m = map(int, input().split())
    al = list(map(int, input().split()))
    print(b163(n, m, al))

if __name__ == '__main__':
    main()

Measured memory_bytes: 10116
import sys
import math

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, ns().split()))
ns = lambda: stdin.readline()

a, b, x = na()

ans = 0

V45 = (a*a*b)/2.0
if x >= V45:
    ans = math.degrees(math.atan( 2 * (a * a * b - x) / (a * a * a)))
else:
    ans = math.degrees(math.acos((2*x)/math.sqrt( (4*x*x) + (a*a*b*b*b*b))))
print(ans)


Measured memory_bytes: 3064
import fractions
N,X = map(int,input().split())
x=sorted(list(map(int,input().split())))
x.append(X)
x.sort()
L=[0]*N
ans = L[0]
for i in range(N):
    L[i] = x[i+1]-x[i]
for i in range(N):
    ans = fractions.gcd(ans,L[i])
#print(x,L)
print(ans)

Measured memory_bytes: 88432
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    ans = 0
    tmp = 1
    while N > 1:
        ans += tmp
        tmp *= 2
        N //= 2
    ans += tmp
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10772
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
int main() {
	int n;
	while(cin >> n) {
		vector<int> v;
		rep(i,10) {
			if(1<<i & n) v.push_back(1<<i);
		}
		cout << v[0];
		rep2(i,1,v.size()) {
			cout << " " << v[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpTest
{
    class Program
    {
        static int Min(int x, int y) => x < y ? x : y;
        static int Max(int x, int y) => x > y ? x : y;

        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] tmpA = Console.ReadLine().Split();
            SortedDictionary<int, int> dic = new SortedDictionary<int, int>();
            for (int i = 0; i < tmpA.Length; ++i)
            {
                dic[int.Parse(tmpA[i])] = i;
            }
            Console.WriteLine(string.Join(" ", dic.Select(kvp => kvp.Value + 1)));
            /*foreach (int val in dic.Values)
            {
                Console.Write(val + 1);
            }
            Console.WriteLine();*/
        }
    }
}


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

using namespace std;

int main(){
  int N, T;
  cin >> N >> T;
  vector<int> c(N), t(N);
  for(int i=0;i<N;i++){
    cin >> c[i] >> t[i];
  }
  vector<int> filtered_c;
  for(int i=0;i<N;i++){
    if(t[i]<=T){
      filtered_c.push_back(c[i]);
    }
  }
  if(filtered_c.size()==0){
    cout << "TLE" << endl;
  }else{
    cout << *min_element(filtered_c.begin(),filtered_c.end()) << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

void display(int data[], int n);
void insertionSort(int data[], int n);

int main(){
	
	int data[N];
	int i, n;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		
		scanf("%d", &data[i]);
		
	}
	
	display(data, n);
	
	insertionSort(data, n);
	
	return 0;
	
}


void display(int data[], int n){
	
	int i;
	for(i=0; i<n; i++){
		if(i>0){
			printf(" ");
		}
		printf("%d", data[i]);
	}
	
	printf("\n");
	
	return;
}



void insertionSort(int data[], int n){
	
	int i, j, temp;
	
	for(i=1; i<n; i++){
		
		j = i;
		temp = data[j];
		
		while(j>0 && temp < data[j-1]){
			
			data[j] = data[j-1];
			j--;
			
		}
		data[j] = temp;
		display(data, n);
	}
	
}

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

int main(int argc, char const *argv[])
{
    int N, L;
    cin >> N >> L;
    N += 1;

    vector<int> taste(N);
    int full_taste = 0;
    for (int i = 1; i < N; i++)
    {
        taste.at(i) = L + i - 1;
        full_taste += taste.at(i);
    }

    vector<int> abs_diff(N, 0);
    vector<int> lack_taste(N, 0);
    int temp;
    for (int i = 1; i < N; i++)
    {
        temp = taste.at(i);
        taste.at(i) = 0;

        for (int j = 1; j < N; j++)
        {
            lack_taste.at(i) += taste.at(j);
        }
        abs_diff.at(i) = abs(full_taste - lack_taste.at(i));
        taste.at(i) = temp;
    }

    int minimum = abs_diff.at(1);
    int location = 1;
    for (int i = 2; i < N; i++)
    {
        if (abs_diff.at(i) < minimum)
        {
            minimum = abs_diff.at(i);
            location = i;
        }
    }
    cout << lack_taste.at(location) << endl;

    return 0;
}

Measured memory_bytes: 256
# A - DDCC Finals
def main():
    X, Y = map(int, input().split())
    prize_table = {1: 300000, 2: 200000, 3: 100000}
    prize = 0
    for rank in (X, Y):
        if rank in prize_table:
            prize += prize_table[rank]
    if X == Y and X == 1:
        prize += 400000
    print(prize)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	static int mai,n;
	static int ue[]=new int[201];
	static int sita[]=new int[201];
	static int hade[]=new int[201];
	static int kion[]=new int[201];
	static int m[][] = new int[201][201];
	static int qq[][] = new int[201][201];
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		mai = in.nextInt();
		for(int i=1;i<=n;i++)kion[i]=in.nextInt();
		for(int i=0;i<mai;i++){
			sita[i]=in.nextInt();
			ue[i]=in.nextInt();
			hade[i]=in.nextInt();
		}
		for(int i=0;i<200;i++)
			for(int k=1;k<200;k++)m[i][k]=0;//mの初期化
		for(int day=1;day<=n;day++){
			if(day==1){//1日目の初期値
				for(int i=0;i<mai;i++){
					if(kion[day]<sita[i]||kion[day]>ue[i]){
						m[i][day]=-1;
						continue;
					}
				}
				continue;//1日目終わったら2日目へ
			}
			for(int i=0;i<mai;i++){//一枚ずつそれぞれのベストを入力していく
				if(kion[day]<sita[i]||kion[day]>ue[i]){
					m[i][day]=-1;
					continue;
				}
				int max=-1;
				for(int k=0;k<mai;k++){//1日前のベスト
					if(m[k][day-1]==-1)continue;//1日前のmが温度超えてたりしたら無視。
					int wrk=Math.abs(hade[k]-hade[i]);//1日前のk枚目の服との絶対値+m[k][day-1]の最大値を求める。
					if(max<wrk+m[k][day-1]){
						max=wrk+m[k][day-1];
					}
				}
				m[i][day]=max;
			}
		}
		int max=-1;
		for(int i=0;i<mai;i++){
			if(max<m[i][n])max=m[i][n];
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 26324
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

MOD=10**9+7
N=gets.to_i
S=get_nsp
kind=S.tally
ans=1
kind.each do|k,v|
    ans*=(v+1)
    ans%=MOD
end
ans-=1
ans+=MOD if ans<0
puts ans


Measured memory_bytes: 19228
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll num[555555];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,q;cin>>n>>k>>q;
  for(int i=0;i<q;i++){
    ll a;cin>>a;
    num[a-1]++;
  }
  for(int i=0;i<n;i++){
    ll hoge=k-q+num[i];
    if(hoge>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#define _GLIBCXX_DEBUG

#include <iomanip>
using namespace std;

template<typename T> vector<T> range(T begin, T end, T stride = 1) {
    vector<T> vec;
    for (T i = begin; i < end; i += stride) {
        vec.push_back(i);
    }
    return vec;
}

template<typename T> T factorial(T in) {
    long long ans = 1;
    for (int i=2; i < in + 1; ++i) ans *= i;
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> v = range(0, n);
    vector<int> x(n), y(n);
    for (int i=0; i < n; ++i) cin >> x[i] >> y[i];
    double sum = 0;
    do {
        for (int i=0; i<n-1; i++) {
            sum += sqrt((x[v[i+1]] - x[v[i]]) * (x[v[i+1]] - x[v[i]]) + (y[v[i+1]] - y[v[i]]) * (y[v[i+1]] - y[v[i]]));
        }
    } while(next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(15) << sum / factorial(n) << endl;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> par,depth;
int find(int v)
{
    if(v==par[v])
    return v;
    return par[v]=find(par[v]);
}
void merge(int a,int b)
{
    if(depth[a]<depth[b])
    swap(a,b);
    par[b]=a;
    depth[a]+=depth[b];
}

int main()
{
    int n,m;
    cin>>n>>m;
    par=vector<int>(n+1);
    for(int i=0;i<=n;i++)
    par[i]=i;
    depth.assign(n+1,0);
    int res=n-1;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        x=find(x);
        y=find(y);
        if(x!=y)
        {
            res--;
            if(res==0)
            {
                cout<<"0";
                return 0;
            }
            merge(x,y);
        }
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 4008
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int l,n,s;
  while(cin>>n&&n){
    s=n>1;
    l=(int)sqrt(n)+1;
    for(i=2;i<l;i++){
      if(n%i==0){
	s+=i;
	if(i*i!=n)
	  s+=n/i;
      }
    }
    if(0){
    }else if(s<n){
      cout<<"deficient number"<<endl;
    }else if(s>n){
      cout<<"abundant number"<<endl;
    }else{
      cout<<"perfect number"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
n,k=map(int,input().split())
if k%2==1:
  print((n//k)**3)
else:
  j=n//(k//2)
  if j %2==0:
    print(2*((j//2)**3))
  else:
    print(((j//2)**3)+((j//2+1)**3))
          


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

void die() {
    cout << "No" << endl;
    exit(0);
}

int main() {
    string s;
    cin >> s;
    set<char> symb(s.begin(), s.end());
    if (symb.count('N') && !symb.count('S')) die();
    if (symb.count('S') && !symb.count('N')) die();
    if (symb.count('E') && !symb.count('W')) die();
    if (symb.count('W') && !symb.count('E')) die();
    cout << "Yes" << endl;
    return 0;
}


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

int main(void){
    char s[101];
    scanf("%s", s);
    int i;
    int cnt=0;
    size_t len=strlen(s);
    for(i=0;i<len/2;i++){
        if(s[i]!=s[len-1-i]){
            cnt++;
        }
    }
    printf("%d\n",cnt );
    return 0;
}


Measured memory_bytes: 128
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)
parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  n, k = readint()
  a = Vector{int}(undef,n)
  a .= readint()

  kita = falses(n)

  K = zeros(int,n+1)
  s = 1
  t = 1

  B = zeros(int,n)
  B[1] = 1
  K[1] = 1

  c = 0
  for i in 1:n
    t = a[s]

    K[i+1] = t 
    kita[s] = true
    #B[t] = i+1
    if kita[t]
      x = B[t]
      y = i

      #println(x, y, K )
      if k <= y
        println(K[k+1])
      else 
        println(K[x+ (k-i)%(y-x+1)])
      end
      return  
    else
      B[t] = i+1    
    end
    s = t
  end
end

main()

Measured memory_bytes: 233020
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int h,w,n;
string s[1000];
int sx,sy;
int d[1000][1000];

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

struct state{
	int x,y,level;
};

int main(){
	cin>>h>>w>>n;
	REP(i,h){
		cin>>s[i];
		REP(j,w){
			if(s[i][j]=='S'){
				sx = j; sy = i;
			}
		}
	}
	queue<state> que;
	que.push((state){sx,sy,1});
	REP(i,h)REP(j,w)d[i][j]=INF;
	d[sy][sx]=0;
	while(!que.empty()){
		state st = que.front(); que.pop();
		if(st.level==n+1){
			cout<<d[st.y][st.x]<<endl;
			break;
		}
		if(st.level+'0'==s[st.y][st.x]){
			int nt = d[st.y][st.x];
			queue<state>().swap(que);
			que.push((state){st.x,st.y,st.level+1});
			REP(i,h)REP(j,w)d[i][j]=INF;
			d[st.y][st.x]=nt;
			//dbg(nt);
			continue;
		}
		REP(i,4){
			int nx = st.x+dx[i], ny=st.y+dy[i];
			if(nx>=0&&nx<w&&ny>=0&&ny<h&&s[ny][nx]!='X'&&d[ny][nx]==INF){
				que.push((state){nx,ny,st.level});
				d[ny][nx]=d[st.y][st.x]+1;
				//dbg(d[ny][nx]);
				//dbg(nx);dbg(ny);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 7980
#include<stdio.h>
#define Num 50
int main(){
    int M[Num],F[Num],R[Num];
    int i;
    int m,f,r;
    
    for(i=0;i<Num;i++){
        scanf("%d %d %d",&M[i],&F[i],&R[i]);
    }
    
    for(i=0;i<Num;i++){
        m=M[i];
        f=F[i];
        r=R[i];
        if(m==-1 && f==-1 &&r==-1){
            break;
        }
        if(m==-1 || f==-1){
            printf("F\n");
            
    }else if(m+f>=80){
        printf("A\n");
    }else if(m+f<80 && m+f>=65){
        printf("B\n");
    }else if(m+f<65 && m+f>=50){
        printf("C\n");
    }else if(m+f<50 &&m+f>=30){
        if(r>=50){
            printf("C\n");
        }else{
            printf("D\n");
        }
        
        }else if(m+f<30){
            printf("F\n");
        }
    
    }
    return 0;
}


Measured memory_bytes: 2140
n, k = map(int, input().split())
mod = 1000000007

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

if k >=n:
  L = 2*n-1
  ansbunsi =1
  for j in range(n-1):
    ansbunsi = ansbunsi*L%mod
    L -= 1
  ansbunbo = 1
  L = n - 1
  for j in range(n-1):
    ansbunbo = ansbunbo*L%mod
    L -= 1
  ansbunbo = modinv(ansbunbo)
  print(ansbunsi*ansbunbo%mod)

else:
  kaijou = [1, 1]
  for j in range(2, k+n+1):
    kaijou.append(kaijou[-1]*j%mod)
  
  ans = 0

  for m in range(k+1):
    ansbunsi = kaijou[n]*kaijou[n-1]%mod
    ansbunbo = kaijou[m]*kaijou[n-m]%mod
    ansbunbo = ansbunbo*kaijou[n-m-1]%mod
    ansbunbo = ansbunbo*kaijou[m]%mod
    ansbunbo = modinv(ansbunbo)
    ans += ansbunbo*ansbunsi
    ans %= mod
  
  print(ans)

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

#define ll long long
#define mod 1000000007
#define pll pair<string,pair<int,int> >
#define pdd pair<long double,long double>
#define mp make_pair
#define pb push_back
#define pf push_front
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >p;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    string s;
    vector<int>arr(n);
    vector<pll>ans(n);
    int a;
    for(int i=0;i<n;i++){
        cin>>s>>a;
        ans[i]=mp(s,mp(a,i));
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            string s1=ans[i].first,s2=ans[j].first;
            if(s1==s2){
                ll a1=ans[i].second.first;
                ll a2=ans[j].second.first;
                if(a2>a1){
                    pll temp=ans[j];
                    ans[j]=ans[i];
                    ans[i]=temp;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i].second.second+1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define MOD 1000000007

int main() {
    int n, i;
    long long int sum = 0;
    if(scanf("%d", &n)) {
        for(i=1;i<=n;i++) {
            if(i%3 == 0 || i%5 == 0)
                continue;
            sum += i;
        }
        printf("%lld", sum);
    }
    return 0;
}

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

int main(){
  int b,r,g,c,s,t;

  while(cin >> b >> r >> g >> c >> s >> t){
    int m = 100; // Ã£ÂÂ¡Ã£ÂÂÃ£ÂÂ«
    if(t == 0) return 0;
    m += -3*b + 15*b + 5*b*13;
    t -= b + 5*b;
    m += -3*r + 15*r + 3*r*13;
    t -= r + 3*r;
    m += -3*g + 7*g;
    t -= g;
    m += -c;
    t -= c;
    m += -3*s;
    t -= 2*s;
   m += -3*t;
	
    cout << m << endl;
  }

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    while (true)
    {
        int n;
        int a[10000];
        cin >> n;
        if (n == 0)
            break;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int ans = 10000000;
        for (int i = 1; i < n; i++)
        {
            ans = min(ans, a[i] - a[i - 1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main (){
  int H,W;
  cin >> H >>W;
  vector<char> vec(H*W);
  for (int i=0;i<vec.size();i++){
    cin >> vec.at(i);
  }
  for (int i=0;i<W+2;i++){
    cout <<'#';
  }
  cout << endl;
  
  for (int i=0;i<H;i++){
    cout <<'#';

    for (int j=0;j<W;j++){
      cout <<vec.at(i*W+j);
    }
    cout <<'#' <<endl;
  }
  
  
  for (int i=0;i<W+2;i++){
    cout <<'#';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        string S;
        cin >> S;

        for (int i = 0; i < S.size(); i++)
        {
                if (S[i] == S[i + 1])
                {
                        cout << i +1<< ' ' << i + 2 << endl;
                        return 0;
                }
                else if (S[i] == S[i + 2] && i + 2 < S.size())
                {
                        cout << i+1 << ' ' << i + 3 << endl;
                        return 0;
                }
        }

        cout << "-1 -1" << endl;
        return 0;
}

Measured memory_bytes: 512
#include <stdio.h> 
#include <ctype.h>

 int main(void){ 
     int count[26]={0}; 
     char ch; 
     int i, n; 
 
 
     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             n=ch-'a'; 
         }else if(isupper(ch)){ 
             n=ch-'A'; 
         }else{ 
             continue; 
        } 
         count[n]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2036
#include <stdio.h>

int main(void)
{
    int N, R;
        scanf("%d %d", &N, &R);
    if(N<10) {
        int a = R + (100 * (10 - N));
            printf("%d\n",a);
    }
    else {
        int b = R;
            printf("%d\n",b);
    }
    return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, C;
  cin >> A >> B >> C;
  ll m = (A - 1) * B + C, M = (A - 1) * C + B;
  cout << max(0ll, M - m + 1) << "\n";
}


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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

// ll bfs(vs s, ll y, ll x)
// {
//     queue<ll, ll> q;
//     q.push(make_pair(y, x));
//     vb pass()
// }
ll h, w;

ll bfs(vs path, ll y, ll x)
{
    //初期化
    queue<pll> q;
    q.push(make_pair(y, x));
    vllll pass(h, vll(w, 0));
    vllll cnt(h, vll(w, 0));
    pass[y][x] = 1;
    cnt[y][x] = 0;

    ll m = 0;
    while (!q.empty())
    {
        pll p = q.front();
        q.pop();
        rep(i, 0, 4)
        {
            ll ny = p.first + dy[i], nx = p.second + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w)
                continue;
            if (!pass[ny][nx] && path[ny][nx] == '.') //spが未到達時の処理
            {
                q.push(make_pair(ny, nx));
                pass[ny][nx] = 1;
                cnt[ny][nx] = cnt[p.first][p.second] + 1;
                m = max(m, cnt[ny][nx]);
            }
        }
    }
    return m;
}

int main(void)
{
    cin >> h >> w;
    vs s(h);
    rep(i, 0, h) cin >> s[i];

    ll ans = 0;
    rep(i, 0, h)
    {
        rep(j, 0, w) if (s[i][j] == '.') ans = max(ans, bfs(s, i, j));
    }
    cout << ans << endl;
}

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

int main(){
  ll h, w;
  cin >> h >> w;
  ll ans = LLONG_MAX;
  rep(i, 2){
    for(int j = 1; j < h; ++j){
      ll s1 = j * w;
      ll s2 = (h - j) / 2 * w;
      ll s3 = h * w - s2 - s1;
      ll mi = min(s1, min(s2, s3));
      ll ma = max(s1, max(s2, s3));
      ans = min(ans, abs(ma - mi));
      
      s2 = (h - j) * (w / 2);
      s3 = h * w - s2 - s1;
      mi = min(s1, min(s2, s3));
      ma = max(s1, max(s2, s3));
      ans = min(ans, ma - mi);
    }
    swap(h, w);
  }
  cout << ans << endl;
}

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

typedef long long int lld;
lld MAX = numeric_limits<lld>::max();

/*
g++ -std=c++11 g-longest.cpp -o k
*/
int main() {
    int i;
    int N, M, x, y;
    cin >> N >> M;
    // edges of graph
    vector<vector<int>> f(N);
    // reversed edges of graph
    vector<vector<int>> b(N);
    vector<int> n_incoming(N);
    vector<int> m;
    // l[i] length of longest path to node i
    vector<int> l(N);

    for(i = 0; i < M; i++) {
        cin >> x >> y; x--; y--;
        f[x].push_back(y);
        b[y].push_back(x);
        n_incoming[y] += 1;
    }
    
    queue<int> q;
    for(i = 0; i < N; i++) {
        if(n_incoming[i] == 0) q.push(i);
    }

    while(!q.empty()) {
        i = q.front(); q.pop();
        m.push_back(i);
        for(int j : f[i]) {
            n_incoming[j]--;
            if(n_incoming[j] == 0) q.push(j);
        }
    }

    int longest = 0;
    for(i = 0; i < N; i++) {
        int j = m[i];
        l[j] = 0;
        for(int k : b[j]) {
            l[j] = max(l[j], l[k] + 1);
        }
        longest = max(l[j], longest);
    }
    cout << longest << endl;

    return 0;
}
/*
samples

5 8
5 3
2 3
2 4
5 2
5 1
1 4
4 3
1 3

out: 3

4 5
1 2
1 3
3 2
2 4
3 4

out: 3

6 3
2 3
4 5
5 6

out: 2

9 12
4 5
3 6
5 6
2 9
2 5
5 8
3 5
6 8
2 4
5 7
7 9
1 3

out: 4

*/


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

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

    int n;
    cin >> n;

    int pay=(n+999)/1000;
    cout << pay*1000-n;


    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
	string str;
	cin >> str;
	int a = str[0] - '0';
	int l = str.length();
	int sum;
	for( int i=1; i<l; i++){
		sum += str[i] - '0';
	}
	if( sum == 9*(l-1) ){
		cout << a+9*(l-1) << endl;
	} else if ( l == 1 ){
		cout << a << endl;	
	} else {
		cout << a+9*(l-1)-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

using vvvi = vector<vvi>;

void solve() {
  int n, a;
  cin >> n >> a;
  vi x(n + 1);
  loop(i, 1, n + 1) cin >> x[i];
  int w = n * 50;
  vvvi dp(n + 1, vvi(n + 1, vi(w + 1)));
  dp[0][0][0] = 1;
  loop(i, 1, n + 1) rep(j, n + 1) rep(k, w + 1) {
    if (k < x[i]) {
      dp[i][j][k] = dp[i - 1][j][k];
    } else if (j >= 1) {
      dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
    }
  }
  int c = 0;
  loop(i, 1, n + 1) c += dp[n][i][i * a];
  cout << c << endl;
}


Measured memory_bytes: 52224
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long double ldouble;
ldouble calc(ldouble r,ldouble w){
  return sqrt(r*r+(w/(2*r))*(w/(2*r)));
}
signed main(){
  int d,n,b;
  cin>>d>>n>>b;
  int p[n];
  ldouble h[n];
  for(int i=0;i<n;i++) cin>>p[i]>>h[i];
  ldouble INF=1e10;
  ldouble ans=INF;
  for(int i=1;i<=b+1;i++){
    ldouble w=(double)d/i;
    ldouble l=0,r=INF;
    for(int k=0;k<2000;k++){
      ldouble x=(l+r)/2;
      ldouble y=w/(2*x);
      //cout<<x<<" "<<y<<endl;
      bool f=1;
      for(int j=0;j<n;j++){
	ldouble ax=p[j];
	while(ax>=w) ax-=w;
	ldouble ay=(-1.0/(2*x*x)*(ax*ax))+((y/x)*ax);
	f&=(h[j]<=ay);
      }
      if(f) l=x;
      else r=x;
    }
    //cout<<i<<":"<<w<<" "<<r<<endl;
    ans=min(ans,calc(r,w));
    l=0;
    for(int k=0;k<20;k++){
      ldouble m1=l+(r-l)/3;
      ldouble m2=l+(r-l)/3*2;
      ldouble t1=calc(m1,w);
      ldouble t2=calc(m2,w);
      ans=min(ans,t1);
      ans=min(ans,t2);
      //cout<<m1<<":"<<t1<<endl;
      //cout<<m2<<":"<<t2<<endl;
      if(t1<t2) r=m2;
      else l=m1;
    }
  }
  printf("%.12Lf\n",ans);
  return 0;
}

Measured memory_bytes: 3288
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int r; cin >> r;
  cout << 3 * r * r << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N, A, B, C, D;
	int i;
	int count1 = 0;
	int count2 = 0;

	scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);

	char masu[N];

	for (i = 0;i < N;i++) {
		scanf("%s", &masu[i]);
	}

	if (C < D) {
		for (i = A-1;i <= C-3;i++) {
			if (masu[i] == '#'&& masu[i+1]=='#'){
				printf("No\n");
                return 0;
			}
		}

		for (i = B-1;i <= D - 3;i++) {
			if (masu[i] == '#' && masu[i + 1] == '#') {
				printf("No\n");
                return 0;
			}
		}
	    printf("Yes\n");
		return 0;
	}
	else {
		for (i = A-1;i <= C - 3;i++) {
			if (masu[i] == '#' && masu[i + 1] == '#') {
				printf("No\n");
                return 0;
			}
		}
		for (i = B - 2;i <= D - 2;i++) {
			if (masu[i] == '.' && masu[i + 1] == '.' && masu[i + 2] == '.') {
				printf("Yes\n");
                return 0;
			}
		}
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 384