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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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

class SegTree {
    ll n;
    vll dat;

    // change if min
    const ll DEF = 0;

    ll _query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) return DEF;
        if (a <= l && r <= b) return dat[k];

        ll vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
        ll vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
        return change(vl, vr);
    }

public:

    SegTree(ll _N) {
        n = 1;
        while (n < _N) n *= 2;
        dat.resize(n * 2 - 1);
        REP(i, n * 2 - 1) dat[i] = DEF;
    };

    // change if min
    inline ll change(ll a, ll b) {
        return max(a, b);
    }

    void update(ll k, ll a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = change(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    ll query(ll a, ll b) {
        return _query(a, b, 0, 0, n);
    }
};


auto solve() {
    int N;
    cin >> N;
    auto seg = SegTree(N);

    vi h(N), a(N);
    for (auto &&e:h) {
        cin >> e;
        --e;
    }
    for (auto &&e:a) cin >> e;

    REP(i, N) {
        ll below = seg.query(0, h[i]);
        seg.update(h[i], below + a[i]);
    }

    return seg.query(0, N + 1);
}


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

//    cout << (solve() ? "First" : "Second") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==5&&b==5&&c==7)||(a==5&&c==5&&b==7)||(b==5&&c==5&&a==7))
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <assert.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#define F first
#define S second
#define qq queue
#define dq deque
#define vc vector
#define INF ((int)(2e9))
#define LINF ((int)(1e18))
#define pb push_back
#define mp make_pair
#define _tp template
#define _tyn typename
#define pf push_front
#define itor iterator
#define mp make_pair
#define sint short int
#define ull unsigned long long
#define pq priority_queue
#define pii pair<int,int>
#define uint unsigned int
#define ll long long
#define B cout << "BreakPoint\n";
#define read(_nowans) scanf("%d",&_nowans)
#define ms(_data) memset(_data,0,sizeof(_data))
#define fin(_filename) freopen(_filename,"r",stdin)
#define fout(_filename) freopen(_filename,"w",stdout)
#define read2(_nowans1,_nowans2) scanf("%d %d",&_nowans1,&_nowans2)
#define msn(_data,_nowans) memset(_data,_nowans,sizeof(_data))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define read3(_nowans1,_nowans2,_nowans3) scanf("%d %d %d",&_nowans1,&_nowans2,&_nowans3)
using namespace std;
_tp<_tyn T>void mymax( T &_a , T _b ){ if( _a < _b ) _a = _b; }
_tp<_tyn T>void mymin( T &_a , T _b ){ if( _a > _b ) _a = _b; }
void print( int _x ){ printf("%d\n",_x); }
_tp<_tyn T>void print( T _data[] , int _size ){
	for( int i = 1 ; i <= _size ; i++ )
		cout << _data[i] << " ";
	cout << endl;
}
#define MOD ((ll)(1e9+7))
#define MAXN 45
#define MAXMASK
 
int n , x , y , z;
int cutmask;
 
// 5 7 5
// isban: 10000 1000000 10000
struct State{
	int bt;
	State(){
		bt = 0;
	}
	State( int bti ){
		bt = bti;
	}
	bool isban(){
		int ls = bt;
		ls >>= z-1;
		if( !( ls & 1 ) ) return 0;
		ls >>= y;
		if( !( ls & 1 ) ) return 0;
		ls >>= x;
		if( !( ls & 1 ) ) return 0;
		return 1;
	}
	State addnum( int num ){
		State ret = State( bt );
		ret.bt <<= num;
		int add = 1 << (num-1);
		ret.bt |= add;
		return ret;
	}
	void print(){
		cout << "[State] " << bitset<20>(bt) << endl;
	}
	State cut(){
		int ft = ( bt & cutmask );
		return State( ft );
	}
};
 
ll mem[MAXN][1<<18];
ll dfs( int pos , State nowst ){
	if( nowst.isban() ) return 0LL;
	if( pos == n + 1 ) return 1LL;
 
	if( mem[pos][nowst.bt] != -1 ) return mem[pos][nowst.bt];
 
	ll ret = 0LL;
	for( int i = 1 ; i <= 10 ; i++ ){
		ret += dfs( pos + 1 , nowst.addnum(i).cut() );
		if( ret >= MOD ) ret -= MOD;
	}
 
	return mem[pos][nowst.bt] = ret;
}
 
int main(){
	//fin( "E.txt" );
	while( scanf("%d %d %d %d",&n,&x,&y,&z) != EOF ){
		msn( mem , -1 );
 
		cutmask = 0;
		for( int i = 0 ; i < x + y + z ; i++)
			cutmask |= ( 1 << i );
 
		ll u = 1LL;
		for( int i = 1 ; i <= n ; i++ ){
			u *= 10LL;
			u %= MOD;
		}
 
		u -= dfs( 1 , State(0) );
		u = (u+MOD) % MOD;
		printf("%lld\n",u);
	}
 
	return 0;
}

Measured memory_bytes: 92416
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
 int a[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  int b[n];
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  bool appear[3][3];
  for(int i = 0; i < 3; i++){
  	for(int j = 0; j < 3; j++){
      appear[i][j] = false;
      for(int k = 0; k < n; k++){
        if(a[i][j] == b[k]){
          appear[i][j] = true;
        }
      }
    }
  }
  string ans = "No";
  for(int i = 0; i < 3; i++){
    if(appear[i][0] && appear[i][1] && appear[i][2]){
      ans = "Yes";
    }
  }
  for(int i = 0; i < 3; i++){
    if(appear[0][i] && appear[1][i] && appear[2][i]){
      ans = "Yes";
    }
  }
  if(appear[0][0] && appear[1][1] && appear[2][2]){
    ans = "Yes";
  }
  if(appear[0][2] && appear[1][1] && appear[2][0]){
    ans = "Yes";
  }
  cout << ans;
}

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



/*int ryuka(int N){
  int L0 = 2,L1 = 1,sum = 0;
  if (N == 0)
    return L0;
  else if (N == 1)
    return L1;
  else {
    return ryuka(N-1) + ryuka(N-2);
    }
  }*/


int main(){
int N,L0 = 2,L1 = 1;
long long a[100];
cin >> N;
a[0] = 2;
a[1] = 1;

for(int i = 2;i <= N;i++){
        a[i] = a[i-1] +a[i-2];    
}


cout << a[N] << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
ary = gets.split(" ").map(&:to_i)
ary_flag = Array.new(ary.max + 1, 0)
ary_clu = Array.new(ary.max + 1, 0)
ary_clu_1 = Array.new(ary.max + 1, 0)
ary_sort = ary.group_by(&:itself).map{|k, v| [k, v.count]}.sort_by{|k,n| -n}

ary_sort.each do |x|
  if ary_flag[x[0]] == 0
    ary_flag[x[0]] = 1
    ary_clu[x[0]] = (1..x[1]).to_a.combination(2).size
    ary_clu_1[x[0]] = (1..(x[1] - 1)).to_a.combination(2).size
  end
end

sum = ary_clu.inject(:+)

ary.each do |x|
  puts sum - ary_clu[x] + ary_clu_1[x]
end


Measured memory_bytes: 47068
import java.util.*;
import java.io.*;
class Main
{

	public static void main(String args[])throws IOException
	{
		int a,b ;
		Scanner sc=new Scanner(System.in);
		
		a=sc.nextInt();
		b=sc.nextInt();
      	if((Math.abs(a-b))%2==0)
			System.out.println(Math.min(a,b)+(Math.abs(a-b))/2);
		else
			System.out.println("IMPOSSIBLE");
		
	}
}

Measured memory_bytes: 21716
n,t=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ab.insert(0,(0,0))
dp=[[0]*t for _ in range(n+1)]
for i in range(1,n+1):
    a,b=ab[i]
    if a<t:
        dp[i][a]=max(dp[i-1][a],b)
    for j in range(t):
        if dp[i-1][j]==0:
            continue
        if j+a<t:
            dp[i][j+a]=max(dp[i][j+a],dp[i-1][j]+b)
        dp[i][j]=max(dp[i-1][j],dp[i][j])
ans=0
p=[j for i,j in ab]
for i in range(1,n):
    ans=max(ans,max(dp[i])+max(p[i+1:]))
ans=max(ans,max(dp[n]))
print(ans)


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

vector<int> ans;

void pout(int n, int k) {
  for (int i = 0; i < k; i++) {
    ans.push_back(n);
  }
}

int block(const string& S, int i) {
  int r = 0, l = 0;
  for (; i < S.size() && S.at(i) == 'R'; i++, r++);
  for (; i < S.size() && S.at(i) == 'L'; i++, l++);
  int p1 = r / 2;
  int p2 = r - p1;
  int q1 = l / 2;
  int q2 = l -q1;
  pout(0, r - 1);
  pout(p2 + q1, 1);
  pout(p1 + q2, 1);
  pout(0, l - 1);
  return i;
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  string S; cin >> S;
  for (int i = 0; i < S.size(); i = block(S, i));
  for (int i = 0; i < ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans.at(i);
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 1096
MOD = 10**9+7

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

Sn = pow(2,n,MOD) - 1
if a > b:
    a,b = b,a
Xa, Xb = 1,1
Ya, Yb = 1,1
for i in range(b):
    if i < a:
        Xa = ( Xa * (n-i) ) % MOD
        Ya = ( Ya * pow((a-i),MOD-2, MOD)) % MOD
    Xb = ( Xb * (n-i) ) % MOD
    Yb = ( Yb * pow((b-i),MOD-2, MOD)) % MOD

ans = Sn - Xa*Ya % MOD - Xb*Yb % MOD
while ans < 0:
    ans += MOD
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){

int n, i,k[3];

scanf("%d", &n);

i=2;
while(n){
 k[i]=n%10;
 n=n/10;
 i--;
}
for(i=0; i<3; i++){
 if(k[i]==1)
  k[i]=9;
 else if(k[i]==9)
  k[i]=1;
}
for(i=0; i<3; i++){
 printf("%d", k[i]);
}
printf("\n");


return 0;
}


Measured memory_bytes: 128
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val k = readLong()

    val runLengthS = runLengthEncode(s)
    if (runLengthS.size == 1) {
        println(s.length * k / 2)
        return
    }

    var ansForS = 0
    for (run in runLengthS) {
        ansForS +=  run.length / 2
    }

    val runLengthSS = runLengthEncode(s + s)
    var ansForSS = 0
    for (run in runLengthSS) {
        ansForSS += run.length / 2
    }

    val diff = ansForSS - ansForS
    println(ansForS + diff * (k - 1))
}

data class RunLength<T>(val value: T, val length: Int)

/** O(s.length) */
//fun runLengthEncode(s: String): List<RunLength<Char>> {
//    if (s.isEmpty()) return emptyList()
//
//    val runLengthList = mutableListOf<RunLength<Char>>()
//    var currentChar = s.first()
//    var length = 1
//    for (c in s.substring(1)) {
//        if (c == currentChar) {
//            length++
//        } else {
//            runLengthList += RunLength(currentChar, length)
//            currentChar = c
//            length = 1
//        }
//    }
//    runLengthList += RunLength(currentChar, length)
//
//    return runLengthList
//}

//fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(mutableListOf<RunLength<Char>>()) { acc, value ->
//    if (acc.isNotEmpty() && acc.last().value == value) {
//        acc.last().length++
//    } else {
//        acc += RunLength(value, 1)
//    }
//    acc
//}

fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(listOf<RunLength<Char>>()) { acc, value ->
    if (acc.isNotEmpty() && acc.last().value == value) {
        acc.dropLast(1) + acc.last().copy(length = acc.last().length + 1)
    } else {
        acc + RunLength(value, 1)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 33772
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    tmp = []
    prev = 0
    for j in range(1, len(S)):
        if (i >> (j-1)) % 2 == 1:
            if len(S[prev:j]) != 0:
                tmp.append(int(S[prev:j]))
                prev = j
    if len(S[prev:]) != 0:
        tmp.append(int(S[prev:]))
    else:
        print(prev)
    ans += sum(tmp)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;

int dp[100001][17], power[17];
int f(int l, int r) {
    int m = log2(r - l + 1);
    return max(dp[l][m], dp[r - power[m] + 1][m]);
}

int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    for (int i = 0; i < n; i++) dp[i][0] = a[i];
    power[0] = 1;
    for (int i = 1; i < 17; i++) power[i] = power[i - 1] * 2;

    for (int j = 1; j < 17; j++) {
        for (int i = 0; i < n; i++) {
            if (i + power[j] <= n)
            dp[i][j] = max(dp[i][j - 1], dp[i + power[j - 1]][j - 1]);
        }
    }

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        int l = i + 1, r = n - 1, mid;
        int r1 = n, r2 = n, l1 = -1, l2 = -1;
        while (l <= r) {
            mid = (l + r) / 2;
            if (f(i + 1, mid) > a[i]) {
                r1 = mid;
                r = mid - 1;
            }

            else {
                l = mid + 1;
            }
        }

        l = r1 + 1, r = n - 1;
        while (l <= r) {
            mid = (l + r) / 2;
            if (f(r1 + 1, mid) > a[i]) {
                r2 = mid;
                r = mid - 1;
            }

            else {
                l = mid + 1;
            }
        }

        l = 0, r = i - 1;
        while (l <= r) {
            mid = (l + r) / 2;
            if (f(mid, i - 1) > a[i]) {
                l2 = mid;
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }

        l = 0, r = l2 - 1;
        while (l <= r) {
            mid = (l + r) / 2;
            if (f(mid, l2 - 1) > a[i]) {
                l1 = mid;
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }

//        cout << l1 << ' ' << l2 << ' ' << r1 << ' ' << r2 << '\n';

        ans += a[i] * ((ll) (r2 - r1) * (i - l2) + (ll) (l2 - l1) * (r1 - i));

    }

    cout << ans;

}


Measured memory_bytes: 7296
#include<cstdio>
#include<iostream>
using namespace std;
string str[10] = {
	"0111111","0000110","1011011","1001111","1100110",
	"1101101","1111101","0100111","1111111","1101111"
};
string func(string now, int index) {
	string ret = "";
	for(int i = 0; i < 7; i++) ret += (now[i] != str[index][i]) + '0';
	return ret;
}
int main() {
	int n;
	while(cin >> n,n != -1) {
		string now = "0000000";
		for(int i = 0; i < n; i++) {
			int a;
			cin >> a;
			cout << func(now, a) << endl;
			now = str[a];
		}
	}
	return 0;
}

Measured memory_bytes: 1200
fun main (args:Array<String>){
    val testCase = readLine()!!.toInt()
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0

    for (i in 1..testCase){
        var judge = readLine()!!
        when{
            judge == "AC" -> {ac++}
            judge == "WA" -> {wa++}
            judge == "TLE" -> {tle++}
            judge == "RE" -> {re++}
        }
    }
    println("AC x ${ac}")
    println("WA x ${wa}")
    println("TLE x ${tle}")
    println("RE x ${re}")
}

Measured memory_bytes: 58328
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <complex>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)

double const pi = acos(-1);
typedef complex<int> P;
char a[128][128];
int n;

void solve(){
    rep(i,n+4){
        rep(j,n+4){
            if(i*j==0 || (n+3-i)*(n+3-j)==0)a[i][j]='#';
            else a[i][j]=' ';
        }
        a[i][n+4]='\0';
    }

    P d(-1,0), p(n+1,2);
    while(1){
        a[p.real()][p.imag()]='#';
        int y=p.real(), x=p.imag();
        if(a[y+2*d.real()][x+2*d.imag()]=='#')d/=P(0,1);
        if(a[y+2*d.real()][x+2*d.imag()]=='#')break;
        p+=d;
        int c=0;
        rep(i,4){
            int ny=(p+d).real(), nx=(p+d).imag();
            if(a[ny][nx]=='#')c++;
            d*=P(0,1);
        }
        if(c>1)break;
    }
}

int main(){
    int d;cin>>d;
    rep(x,d){
        cin>>n;
        solve();
        rep(i,n){
            rep(j,n)cout<<a[i+2][j+2];
            cout<<endl;
        }
        if(x+1!=d)cout<<endl;
    }
}

Measured memory_bytes: 1168
a,b,c,d=input()
for i in range(2**3):
    op=["-","-","-"]
    for j in range(3):
        if (i>>j&1):
            op[j]="+"
    if eval(a+op[0]+b+op[1]+c+op[2]+d)==7:
        print(a+op[0]+b+op[1]+c+op[2]+d+"=7")
        exit()

Measured memory_bytes: 9068
#include <stdio.h>

#define BUFFER_MAX 1024
#define APEXES_NUM 4

typedef struct {
     double x;
     double y;
} Point;



int FuncJudgeCross(const Point *bp, const Point *ep, const Point *p1, const Point *p2)
{
     Point  line[3];
     double temp[2];

     line[0].x = ep->x - bp->x;
     line[0].y = ep->y - bp->y;

     line[1].x = p1->x - bp->x;
     line[1].y = p1->y - bp->y;

     line[2].x = p2->x - bp->x;
     line[2].y = p2->y - bp->y;
     
     temp[0] = line[0].x * line[1].y - line[0].y * line[1].x;
     temp[1] = line[0].x * line[2].y - line[0].y * line[2].x;
     return ( temp[0] * temp[1] > 0.0 ) ? 1 : -1;
}

int main(void)
{
     char  buf[BUFFER_MAX];
     Point apexes[APEXES_NUM];

     while (fgets(buf, 1023, stdin) != NULL) {
          sscanf(buf, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
                 &(apexes[0].x), &(apexes[0].y),
                 &(apexes[1].x), &(apexes[1].y),
                 &(apexes[2].x), &(apexes[2].y),
                 &(apexes[3].x), &(apexes[3].y));

          if (FuncJudgeCross(&apexes[0], &apexes[2], &apexes[1], &apexes[3]) * FuncJudgeCross(&apexes[1], &apexes[3], &apexes[0], &apexes[2]) > 0.0) {
               puts("YES");
          } else {
               puts("NO");
          }
     }
     
     return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, A[N], B[N], C[N], id[N], dsu[N];
long long dp[N], sum[N];
bool vis[N];
vector<int> G[N];
int Find(int x) { return x == dsu[x] ? x : dsu[x] = Find(dsu[x]); }
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &A[i], &B[i]);
		C[i] = max(A[i] - B[i], 0);
		id[i] = i;
		dsu[i] = i;
		vis[i] = false;
	}
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	sort(id + 1, id + 1 + n, [](int i, int j) {
		return C[i] < C[j];
	});
	for (int i = 1; i <= n; i++) {
		int u = id[i];
		vis[u] = true;
		sum[u] = B[u];
		vector<int> sons;
		for (int v : G[u]) {
			if (!vis[v] || Find(u) == Find(v)) continue;
			int rv = Find(v);
			sons.push_back(rv);
			sum[u] += sum[rv];
			dsu[rv] = u;
		}
		dp[u] = sum[u] + C[u];
		for (int v : sons) {
			dp[u] = min(dp[u], sum[u] - sum[v] + max(dp[v], 1ll * C[u]));
		}
	}
	printf("%lld\n", dp[id[n]]);
	return 0;
}

Measured memory_bytes: 9852
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int n, m;
int a[1000], b[1000], c[1000], dist[100][100];


int main()
{
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}
	rep(i, n) rep(j, n) {
		if (i == j) dist[i][j] = 0;
		else dist[i][j] = INF;
	}
	rep(i, m) {
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	rep(k, n) rep(i, n) rep(j, n) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
	int ans = m;
	rep(i, m) {
		bool shortest = false;
		rep(j, n) {
			if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
				shortest = true;
			}
		}
		if (shortest) {
			ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		
		if (a >= b && a >= c) {
			System.out.println(b + c);
		} else if (b >= a && b >= c) {
			System.out.println(a + c);
		} else {
			System.out.println(b + a);			
		}
	} 
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b) cout << c;
  else if(b==c) cout << a;
  else cout << b;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  long n,a[5],time[6],min[5],minnum[5];//time[i] : 全員がi+1に着く時間
  scanf("%ld\n",&n);//min[i] : a[0],...,a[i]のmin
  for(int i = 0; i < 5; ++i){
    scanf("%ld\n",&a[i]);
  }
  min[0] = a[0];
  minnum[0] = 0;
  for(int i = 1; i < 5; ++i){
    if(a[i] <= min[i-1]){
      min[i] = a[i];
      minnum[i] = i;
    }
    else{
      min[i] = min[i-1];
      minnum[i] = minnum[i-1];
    }
  }
  
  /*
  i-1(s)からmin[i]ずつ流入
  n(s)には1 + (n-1)min[i]
  time[i-1] = ceil((N-1+min[i-1])/min[i-1])
  minnumでなければtime+1でok
  minnumならtimeとは無関係
  */
  
  time[0] = 0;
  time[1] = (n + a[0] - 1) / a[0];// ceil
  for(int i = 2; i < 6; ++i){
    if(minnum[i-1] != i-1) time[i] = time[i-1] + 1;
    else{
     time[i] = i - 1 + (n + a[i-1] - 1) / a[i-1];
    }
  }
  printf("%ld\n",time[5]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define NB 100001
#define PB push_back
int abs(int a) {
	if(a<0) return -a;
	return a;
}

ll DP[NB];
vector<int> LS[NB];
bitset<NB> vis;
bitset<NB> indegz;
ll rec(int x) {
	if(vis[x] == 1) return DP[x];
	vis[x] = 1;
	ll mi = 0;
	for(unsigned int i = 0; i < LS[x].size(); ++i) {
		mi = max(mi, rec(LS[x][i]));
	}
	DP[x] = mi + 1;
	return mi + 1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,m,f,t;
	cin>>n>>m;
	for(int i = 0; i < m; ++i) {
		cin>>f>>t;
		LS[f].PB(t);
		indegz[t] = 1;
	}
	for(int i = 1; i <= n; ++i) {
		if(indegz[i] == 0) {
			rec(i);
		}
	}
	
	ll mo = -1;
	for(int i = 1; i <= n; ++i) {
		mo = max(DP[i], mo);
	}
	cout<<mo - 1<<"\n";
	return 0;
}


Measured memory_bytes: 14492
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N;
    cin >> N;
    vector<ll> arr(N, 0);
    for(int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    if (N == 2) {
        cout << arr[1] - arr[0] << endl;
        cout << arr[1] << " " << arr[0] << endl;
        return 0;
    }
    ll mul = arr[0] *arr.back();
    if (mul >= 0) {
        if (arr[0] >= 0) {
            cout << accumulate(arr.begin(), arr.end(), 0) - arr[0]*2 << endl;
            for(int i = 1; i < N-1; i++) {
                cout << arr[0] << " " << arr[i] << endl;
                arr[0] -= arr[i];
            }
            cout << arr.back() << " " << arr[0] << endl;
        } else if (arr.back() <= 0) {
            cout << llabs(accumulate(arr.begin(), arr.end(), 0)) + arr.back() * 2 << endl;
            for(int i = 0; i < N-1; i++) {
                cout << arr.back() << " " << arr[i] << endl;
                arr.back() -= arr[i];
            }
        }
    } else {
        int first_pos = -1;
        for(int i = 0; i < N; i++) {
            if (arr[i] >= 0) {
                first_pos = i;
                break;
            }
        }
        ll neg = accumulate(arr.begin(), arr.begin()+first_pos, 0);
        ll ans = accumulate(arr.begin(), arr.end(), 0) - neg*2;
        cout << ans << endl;
        for(int i = first_pos; i < N-1; i++) {
            cout << arr[0] << " " << arr[i] << endl;
            arr[0] -= arr[i];
        }
        for(int i = 0; i < first_pos; i++) {
            cout << arr.back() << " " << arr[i] << endl;
            arr.back() -= arr[i];
        }
    }
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int h = 0, w = 0, d = 0;
  cin >> h >> w >> d;
  vector<vector<int>> in(h, vector<int>(w));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin >> in.at(i).at(j);
    }
  }
  vector<pair<int, int>> pla(h*w+1);
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      pla.at(in.at(i).at(j)) = make_pair(i, j);
    }
  }
  
  vector<int> dis(h*w+1);
  for (int i=1; i<=d; i++) {
    dis.at(i) = 0;
    int cur = i + d;
    while (cur <= h * w) {
      int magic = abs(pla.at(cur).first - pla.at(cur-d).first) + abs(pla.at(cur).second - pla.at(cur-d).second);
      dis.at(cur) = dis.at(cur-d) + magic;
      cur += d;
    }
  }
  
  int q = 0;
  cin >> q;
  vector<int> ans(q);
  int l = 0, r = 0;
  for (int i=0; i<q; i++) {
    cin >> l >> r;
    ans.at(i) = dis.at(r) - dis.at(l);
  }
  for (int x : ans) {
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
H, W = map(int, input().split())
s = [input() for h in range(H)]

# Number of white cells
white_cells = sum([s[h].count(".") for h in range(H)])

# h,w
record = [[[0,0]]]
li = []
if s[1][0] == ".":
    li.append([1,0])
if s[0][1] == ".":
    li.append([0,1])
record.append(li)

count = 1
while True:
    if record[count] == []:
        print(-1)
        break
    li = []
    for p in record[count]:
        h = p[0]
        w = p[1]
        next_to_p = []
        if h > 0 and s[h-1][w] == "." and [h-1, w] not in record[count-1] + li:
            next_to_p.append([h-1, w])
        if w > 0 and s[h][w-1] == "." and [h, w-1] not in record[count-1] + li:
            next_to_p.append([h, w-1])
        if h < H-1 and s[h+1][w] == "." and [h+1, w] not in record[count-1] + li:
            next_to_p.append([h+1, w])
        if w < W-1 and s[h][w+1] == "." and [h, w+1] not in record[count-1] + li:
            next_to_p.append([h, w+1])
        li = li + next_to_p
    if [H-1, W-1] in li:
        print(white_cells - count - 2)
        break
    record.append(li)
    count += 1


Measured memory_bytes: 3188
def fibonacci(f, n):
    if n == 0 or n == 1:
        f[n] = 1
        return f[n]
    if f[n]:
        return f[n]
    f[n] = fibonacci(f, n - 2) + fibonacci(f, n - 1)
    return f[n]

n = int(input())
f = [None for i in range(n + 1)]
print(fibonacci(f, n))

Measured memory_bytes: 7788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	int n; cin >> n;
	int p[60], pp[60];
	for (int i = 0; i < n; i++) {
		int num; cin >> num;
		p[i] = num; pp[i] = num;
	}
	sort(pp, pp + n);
	int c = 0;

	
	for (int i = 0; i < n; i++) {
		if (p[i] != pp[i]) { c++; }
		if (c > 2) { cout << "NO" << endl; return 0; }
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{int A,B,C;
	scanf("%d%d%d",&A,&B,&C);
			if((A==5&&B==5&&C==7)||(A==5&&B==7&&C==5)||(A==7&&B==5&&C==5))
				printf("YES");
				else
				printf("NO");

	return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

class Main {
	public static void main(String[] args){

		//?????°??£?¨?
		HashMap<String,Integer> hm = new HashMap<String,Integer>();
		ArrayList<String> naga = new ArrayList<String>();

		String suu;
		//String[] naga = new String[1000];
		String toridasi;		//??????
		int youso;
		int saidai = 0;
		int ookii = 0;
		String ookiina = null;
		int saizu;
		String saidai2 = null;


		Scanner sc = new Scanner(System.in);		//?????????????????§??\?????????

		while(sc.hasNext()){
			String a = sc.next();		//??????????????°a?????\??????
			naga.add(a);		//??????naga?????\??????
		}

//		String hako = sc.nextLine();		//1???????????????
//		String[] kari = hako.split(" ");		//1????????\?????????naga?????\??????


		//??????????????????????????????
		for(int x = 0; x < naga.size(); x++){

			toridasi = naga.get(x);		//??????????????????????????????
			if(hm.containsKey(toridasi)){		//??????????????????????????£??????
				youso = hm.get(toridasi);		//????´????????????????
				youso  = youso + 1;		//?¶????
				hm.put(toridasi,youso);		//?¶???????value?????\??????
				if(saidai < youso){		//???????????°??????youso???????????§????????£??????
					saidai = youso;		//youso???saidai?????\??????
					saidai2 = toridasi;		//???????????\??????
				}else{
					hm.put(toridasi,1);
				}
			}else{		//???????????????????????£??????
				hm.put(toridasi,1);
			}
		}

			//????????°??????????????????
			for(int i = 0; i < naga.size(); i++){
				suu = naga.get(i);
				saizu = suu.length();

				if(ookii < saizu){		//??????ookii??????saizu?????§????????£??????
					ookiina = naga.get(i);
					ookii = saizu;
				}
			}


			//????????????????????????????????¨??? //????????°????????????????????¨???

			System.out.println(saidai2 + " " + ookiina);
	}
}

Measured memory_bytes: 26360
#include <bits/stdc++.h>
 
#define INF 100100100
#define MOD 1000000007
 
using namespace std;
using ll = long long;
using ull = unsigned long long ;
 
int main(){
   int N, K;
   string S;
   cin>>N>>S>>K;
   
   for(int i=0; i<N; i++) {
       if(S[K-1]!=S[i]) {
           S[i] = '*';
       }
   }
   
   cout<<S<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stack>

using namespace std;




int main() {
  stack<int> slope_down;
  stack<pair<int, int> > slope_up;
  int now = 0, left = 0;
  int pool_area = 0, puddle_area = 0;
  int pools[10000];
  int pool_num;
  
  char ground;

  while (cin >> ground) {
    switch (ground) {
      case '\\':
        slope_down.push(now);
        break;
      case '/':
        if (slope_down.size() > 0) {
          left = slope_down.top();
          slope_down.pop();
          puddle_area = now - left;
          pool_area += puddle_area;

          while (slope_up.size() > 0 && slope_up.top().first > left) {
            puddle_area += slope_up.top().second;
            slope_up.pop();
          }
          slope_up.push(make_pair(left, puddle_area));
        }

        break;
      case '_':
        break;
      default:
        break;
    }
    now ++;
  }
  cout << pool_area << endl;

  pool_num = slope_up.size();
  for (int i = 0; i < pool_num; i ++) {
    pools[i] =  slope_up.top().second;
    slope_up.pop();
  }
  cout << pool_num;
  if (pool_num == 0) cout << endl;
  else cout << " ";

  for (int i = pool_num - 1; i >= 0; i --) {
    cout << pools[i];
    if (i == 0) cout << endl;
    else cout << " ";
  }

  return 0;
}



Measured memory_bytes: 3232
#include <cstdio>
#define MAX 1145140
#define INF 1145141919
using namespace std;
int n;
int A[MAX];
int L[MAX / 2], R[MAX / 2];
int cnt;
void merge(int left,int right,int mid) {
	int n1 = mid - left;
	int n2 = right - mid;
	int i;
	for (i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	L[n1] = INF;
	for (i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	R[n2] = INF;
	int j = 0, k = 0;
	for (i = left; i < right; i++) {
		cnt++;
		if (L[j] < R[k]) {
			A[i] = L[j];
			j++;
		}
		else {
			A[i] = R[k];
			k++;
		}
	}

}
void mergeSort(int left,int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(mid,right);
		mergeSort(left,mid);
		merge(left,right,mid);
	}
}
int main() {
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d",&A[i]);
	}
	mergeSort(0,n);
	for (i = 0; i < n; i++) {
		if (i)printf(" ");
		printf("%d", A[i]);
	}
	printf("\n%d\n", cnt);
}


Measured memory_bytes: 6600
#include <iostream>

using namespace std;

int calc(int fromx, int fromy, int tox, int toy)
{
    int cnt = 0;

    while (fromx != tox || fromy != toy) {
        if (fromx < tox && fromy < toy) {
            fromx++;
            fromy++;
        } else if (fromx > tox && fromy > toy) {
            fromx--;
            fromy--;
        } else if (fromx > tox && fromy < toy) {
            fromx--;
        } else if (fromx < tox && fromy > toy) {
            fromx++;
        } else if (fromx == tox) {
            if (fromy < toy) {
                fromy++;
            } else {
                fromy--;
            }
        } else if (fromy == toy) {
            if (fromx < tox) {
                fromx++;
            } else {
                fromx--;
            }
        }
        
        cnt++;
    }

    return cnt;
}

int main()
{
    int w, h, n; cin >> w >> h >> n;

    int a, b; cin >> a >> b;

    int cnt = 0;

    for(int i = 1; i < n; ++i) {
        int x, y; cin >> x >> y;
        
        cnt += calc(a, b, x, y);  
        
        a = x, b = y;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int N = 0;
vector<int> vec;
 
int tree(int A1[], int A2[], int index1, int index2, int cnt){
    cout << index1 << " " << index2 <<" cnt: " << cnt << endl;
    if(index1==N-1 && index2==1){
        vec.push_back(cnt);
        cout << "goal " << index1 << " " << index2 << "A2"<< endl;
        return 0;
    }
    if(index1<N-1) tree(A1, A2, index1+1, index2, cnt+A1[index1+1]);
    if(index2 == 0 ) tree(A1, A2, index1, index2+1, cnt+A2[index1]);

    return 0;
}


int main(){
    int n;
    cin>>n;
    N = n;
    int A1[n], A2[n];
    rep(i, n) cin >> A1[i];
    rep(i, n) cin >> A2[i];
    int ans = 0;
    int ma = -100000000;
    rep(i, n){
        rep(j, i+1){
            ans += A1[j];
        }
        ans += A2[i];
        REP(j, i+1, n) ans += A2[j];
        ma = max(ans, ma);
        ans = 0;
    }
    cout << ma << endl;

    return 0;
}


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

using namespace std;

int main(){
	int n,f=1,s;
	cin >> n;
	vector<string> w;
	string t;
	for(int i=0;i<n;i++){
		cin >> t;
		w.push_back(t);
	}
	for(int i=1;i<n;i++){
		if(w[i][0] != w[i-1][w[i-1].size()-1]){
			f = 0;
		}
	}

	if(f == 0){
		cout << "No" << endl;
		return 0;
	}

	s = w.size();

	sort(w.begin(),w.end());
	w.erase(unique(w.begin(),w.end()),w.end());
	if(s != w.size()){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
hash = {'10' => '00', '11' => '01', '00' => '10', '01' => '11'}
puts ("%b" % (n + ('10' * 64).to_i(2))).chars.each_slice(2).map { |s| s.join.gsub(/../, hash) }.join.gsub(/^0*(.+$)/, '\1')

Measured memory_bytes: 1916
#include <iostream>
#include <set>

using namespace std;

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

  set<int> as;
  while (as.insert(s).second) s = s % 2 ? 3 * s + 1 : s >> 1;

  cout << as.size() + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bucnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

double dot_product(compd a, compd b, compd c) {
	compd s = b - a, t = c - a;
	return s.real()*t.real() + s.imag()*t.imag();
}

double cross_product(compd a, compd b, compd c) {
	compd s = b - a, t = c - a;
	return s.real()*t.imag() - s.imag()*t.real();
}

double dist(compd a, compd b) {
	return sqrt((a.real() - b.real())*(a.real() - b.real()) + (a.imag() - b.imag())*(a.imag() - b.imag()));
}

double Ldist(compd s, compd t, compd p) {
	compd l = t - s;	p -= s;
	compd rot = abs(l) / l;
	l *= rot;	p *= rot;
	if (p.real() < eps)	return dist(0, p);
	if (l.real() - eps < p.real())	return dist(l, p);
	return abs(p.imag());
}

compd getCompd() {
	double a, b;	cin >> a >> b;
	return compd(a, b);
}

int main() {
	while (true) {
		int n;	cin >> n;
		if (n == 0)	break;
		compd s = getCompd(), t = getCompd();
		ld left = 0, right = 1024;
		rep(i, n) {
			vector<compd> a(4);
			a[0] = getCompd();	a[2] = getCompd();
			a[1] = compd(a[0].real(), a[2].imag());
			a[3] = compd(a[2].real(), a[0].imag());
			double h;	cin >> h;
			left = 0;
			right += eps;
			//?????????????????????????????????
			bool is_inside = true;
			rep(j, 4) {
				is_inside &= (dot_product(a[j], a[(j + 1) % 4], s) > eps);
				is_inside &= (dot_product(a[j], a[(j + 1) % 4], t) > eps);
			}
			if (is_inside)	right = 0;
			//?????????????????????????????????
			bool crossed = false;
			rep(j, 4) {
				if (cross_product(s, t, a[j])*cross_product(s, t, a[(j + 1) % 4]) > -eps)	continue;
				if (cross_product(a[j], a[(j + 1) % 4], s)*cross_product(a[j], a[(j + 1) % 4], t) > -eps)	continue;
				crossed = true;
			}
			if (crossed)	right = 0;
			rep(j, 100) {
				double mid = (left + right) / 2.0;
				double height = mid - min(mid, h);
				double r = sqrt(mid*mid - height*height);
				bool ok = true;
				rep(k, 4) {
					ok &= (Ldist(s, t, a[k]) > r + eps);
					ok &= (Ldist(a[k], a[(k + 1) % 4], s) > r + eps);
					ok &= (Ldist(a[k], a[(k + 1) % 4], t) > r + eps);
				}
				if (ok)	left = mid;
				else	right = mid;
			}
		}
		printf("%.15Lf\n", left + eps);
	}
	return 0;
}

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

int main(){
  long N, K;
  cin >> N >> K;
  if(K==0){
    cout << N*N << endl;
    return 0;
  }
  long count=0;
  for(int i=K+1; i<=N; i++){
    long num = N/i;
    count += num*(i-K);
    num = N- num*i;
    if(num>=K){
      count+=num-K+1;
    }
  }
  cout << count << endl;
  return 0;
}

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int64_t N;
    int64_t A[2][3];

    cin >> N;
    for(int i=0; i<2; i++) for(int j=0; j<3; j++) cin >> A[i][j];

    for(int t=0; t<2; t++){
        vector<int64_t> dp(N+5001, 0);
        for(int i=0; i<N; i++){
            for(int j=0; j<3; j++){
                int64_t use = A[t][j], gain = A[1-t][j];
                chmax(dp[i+use], dp[i] + gain - use);
            }
            chmax(dp[i+1], dp[i]);
        }
        N += dp[N];
    }
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 195712
//
//  main.c
//  ITP1_3_B
//
//  Created by k16031kk on 2018/05/18.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x=0, count=0;
    scanf("%d", &x);
    while(x!=0) {
        count++;
        printf("Case %d: %d\n",count, x);
        scanf("%d",&x);
    }
    
    return 0;
}



Measured memory_bytes: 2032
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        string ans = "x";
        if(inpt.Sum() == 15) {
            ans = "+";
        } else if(inpt[0] * inpt[1] == 15) {
            ans = "*";
        }
        Console.WriteLine(ans);

    }



    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


4 114 11


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13396
N , K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

T = {0: 0}

for i in range(N):
    T.update({i + 1: A[i]})

i = 1

MOD_ = 0

VISIT = [0] * (N+1)

for j in range(K):
    i = T[i]

    if VISIT[i] != 0:
        K0 = VISIT[i] 
        MOD_ = j+1 - VISIT[i] 
        break

    VISIT[i] = j+1


if MOD_ !=0:
    i = T[i]
    if ((K - K0 - 1) % MOD_ ) != 0:
        for j in range((K-K0-1) % MOD_ ):
            i = T[i]


print (i)

Measured memory_bytes: 39992
#include <iostream>

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

using namespace std;

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

    int a[100][100], b[100];

    rep(i, n) rep(j, m) cin >> a[i][j];
    rep(i, m) cin >> b[i];

    rep(i, n) {
        auto ans = 0;
        rep(j, m) ans += a[i][j] * b[j];
        cout << ans << "\n";
    }
    return 0;
}




Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  ll n,d,a;
  cin >> n >> d >> a;
  vector<pair<ll,ll>> xh(n);
  vector<ll> x(n);
  vector<ll> h(n);

  rep(i,n){ cin>>xh[i].F>>xh[i].S; }
  sort(xh.begin(),xh.end());
  rep(i,n){ h[i]=xh[i].S; x[i]=xh[i].F; }
  
  vector<ll> imos(n+1);
  ll ans=0;
  ll cnt=0;
  rep(i,n){
    ll bomb = x[i]+2*d;
    int safe = upper_bound(x.begin(),x.end(),bomb)-x.begin();
    ll ncnt = max(0LL, (h[i]+a-1)/a -imos[i]);
    
    ans += ncnt;
    imos[i] += ncnt;
    imos[safe] -= ncnt;
    imos[i+1] += imos[i];
  }
  
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,len;
  string tmp,ans;
  vector<string> s;
  bool f;
  int a[10],g[10][10],hoge;

  for(int i=0;i<10;i++)a[i] = i;
  
  while(cin >> n,n){
    s.resize(n);
    for(int i=0;i<n;i++)cin >> s[i];

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(s[i].size() < s[j].size() )swap(s[i],s[j]);
      }
    }

    for(int i=0;i<s.size();i++){
      for(int j=i+1;j<s.size();j++){
	if(i==j)continue;
	for(int k=0;k<s[i].size()-s[j].size();k++){
	  if(s[i].substr(k,s[j].size()) == s[j]){
	    s.erase(s.begin()+j);
	    j--;
	    break;
	  }
	}
      }
    }

    n = s.size();
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j)g[i][j] = 0;
	else{
	  len = min(s[i].size(), s[j].size());
	  for(int k=len;k>=0;k--){
	    f = true;
	    for(int l=0;l<k;l++){
	      if(s[i][(int)s[i].size()-k+l] != s[j][l]){
		f = false;
		break;
	      }
	    }
	    if(f){
	      g[i][j] = k;
	      break;
	    }
	  }
	}
      }
    }

    len = -1;
    ans = "";
    sort(a,a+n);

    do{
      hoge = 0;
      for(int i=1;i<n;i++)hoge += g[a[i-1]][a[i]];
      
      if(len<hoge){
	len = hoge;
	tmp = s[a[0]];
	for(int i=1;i<n;i++){
	  hoge = g[a[i-1]][a[i]];
	  tmp += s[a[i]].substr(hoge,(int)s[a[i]].size()-hoge);
	}
	ans = tmp;
      }else if(hoge == len){
	tmp = s[a[0]];
	for(int i=1;i<n;i++){
	  hoge = g[a[i-1]][a[i]];
	  tmp += s[a[i]].substr(hoge,(int)s[a[i]].size()-hoge);
	}
	if(tmp<ans)ans = tmp;
      }
    }while(next_permutation(a,a+n));
    cout << ans << endl;
  }
}

Measured memory_bytes: 1224
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;
import std.functional;

auto readInts() {
        return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
        return readInts()[0];
}
auto readLongs() {
        return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
        return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    long n, a;
    readlnTo(n, a);
    auto x = readLongs();
    long calc(long i, long j, long k) {
        if(j == 0 && k == 0) {
            return 1;
        }
        if(i < 0 || j < 0 || k < 0) {
            return 0;
        }
        return memoize!calc(i-1, j, k) + memoize!calc(i-1, j-1, k-x[i]);
    }
    long ans;
    foreach(i; iota(1, n+1)) {
        ans += calc(n-1, i, i*a);
    }
    writeln(ans);
}



Measured memory_bytes: 71548