akhauriyash/Code-Regression huggingface dataset:
<?php
//ワーシャルフロイド（全点対最短路問題）
//スタート地点１つに対してゴールが２つ。流れるものは水
//故に、単純に $cost[$s][$g1] + $cost[$s][$g2] とするとWA
//スタート〜ある点までは合流道。ある点〜それぞれのゴールまでは二股に分かれて進むイメージ
//また、有向グラフ（一方通行）なので注意。
//と言ってもむしろ$cost[$b][$a] = $cost[$a][$b]というコピーが不要になるので楽。


$file_handle = fopen('php://stdin', "r");
//$file_handle = fopen('aoj2005_in.txt', "r");


function warshall_floyd($cost) {
	global $n;

	for ($i = 1; $i <= $n; ++$i) {
	    for ($j = 1; $j <= $n; ++$j) {
	        for ($k = 1; $k <= $n; ++$k) {
	        	//INFだったらスルー
	        	if ($cost[$j][$i]===INF || $cost[$i][$k]===INF) continue;
	            // j -> kへ行くのにiを経由した方が良いかどうか(cost)
	            $via = $cost[$j][$i] + $cost[$i][$k];
	            if ($via < $cost[$j][$k]) {
	                $cost[$j][$k] = $via;
	            }
	        }
	    }
	}
	return $cost;
}


while(1){
	//ファイル読み込み
	$info = trim(fgets($file_handle));
	$explode = explode(' ', $info);
	$n = $explode[0]; $m = $explode[1]; $s = $explode[2]; $g1 = $explode[3]; $g2 = $explode[4];
	//終了条件
	if ($n==0 && $m==0 && $s==0 && $g1==0 && $g2==0) break;
	
	//初期化
	$cost = array();

	//ワーシャルフロイド準備。
	for ($i=1; $i<=$n; ++$i){
		for ($j=1; $j<=$n; ++$j){
			if ($i === $j){
				$cost[$i][$i] = 0;
			} else {
				$cost[$i][$j] = INF;
			}
		}
	}

	//辺の情報を格納
	for ($i=1; $i<=$m; ++$i){
		$info2 = trim(fgets($file_handle));
		$explode = explode(' ', $info2);
		$a = $explode[0]; $b = $explode[1]; $c = $explode[2];
		$cost[$a][$b] = $c;
	}

	//探索。先に全点対最短路を求めておく必要がある
	$cost = warshall_floyd($cost);
	
	//最小値計算
	$min = INF;
	for($i=1; $i<=$n; ++$i){
		//どこで分岐するのが最も総コストが低いか比較
		$via = $cost[$s][$i] + $cost[$i][$g1] + $cost[$i][$g2];
		$min = min($min, $via);
	}
	
	//出力
	echo $min;
	echo PHP_EOL;
}

fclose($file_handle);

Measured memory_bytes: 9872
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int main(void)
{
  int k,t,M;
  cin >> k >> t;
  REP(i,t){
    int tmp;
    cin >> tmp;
    M=max(M,tmp);
  }
  int answer=max(0,k-(k-M)*2-1);
  cout << answer << endl;
  return 0;
}

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

typedef long long ll;

ll dfs(int n, ll x){
    if(n == 0 && x == 1)  return 1;
    if(x <= 1)  return 0;

    ll len = (1ll<<(n+2))-3;
    ll center = len/2+1;
    
    // 区間を完全に覆ってしまった時点で枝刈りをしないとdfsの呼び出しが指数的に爆発して死ぬ
    if(x == len)    return 1 + 2ll*dfs(n-1, center-2);
    
    if(x < center)          return dfs(n-1, x-1);
    else if(x == center)    return 1 + dfs(n-1, center-2);
    else if(x > center)     return 1 + dfs(n-1, center-2) + dfs(n-1, x-1-center+1);
}

int main(){
    int n;
    ll x;
    cin >> n >> x;
    cout << dfs(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int get(int n) {
	int ans = 0;
	if(n > 1) {
		for(int i = n - 1; i >=1 ;i--) {
			ans += i;
		}
	}
	return ans;
}

int main() {
	int n, m;
	while(cin >> n >> m) {
		cout << get(n) + get(m) << endl;
	} 
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long[] answer = new long[4];

            for(int i = 0; i < N; i++)
            {
                string S = Console.ReadLine();

                if(S == "AC")
                {
                    answer[0]++;
                }
                else if (S == "WA")
                {
                    answer[1]++;
                }
                else if (S == "TLE")
                {
                    answer[2]++;
                }
                else if (S == "RE")
                {
                    answer[3]++;
                }
            }

            Console.WriteLine("AC x " + answer[0].ToString());
            Console.WriteLine("WA x " + answer[1].ToString());
            Console.WriteLine("TLE x " + answer[2].ToString());
            Console.WriteLine("RE x " + answer[3].ToString());
        }
    }
}

Measured memory_bytes: 30708
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    Long k = sc.nextLong();
    Long count = 0l;
    for(Long i = k;i<=n+1;i++){
      Long mi = i * (i-1) / 2;
      Long ma = i * (n-i+1 + n)/2;
      count += ma - mi +1;
      //System.out.println(i +"個のとき " + (ma - mi + 1));
    }
    count = count % 1000000007;
    System.out.println(count);
  }
}


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

using namespace std;
const long long MAXN = 1e6+5;
multiset<long long> s1;
long long pref[MAXN];
long long suff[MAXN];
long long sum;
long long arr[MAXN];
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=3*n;i++){
        cin>>arr[i];
    }
    for(long long i=1;i<=n;i++){
        s1.insert(arr[i]);
        sum+=arr[i];
    }
    pref[n] = sum;
    for(long long i=n+1;i<=2*n;i++){
        s1.insert(arr[i]);
        sum+=arr[i];
        if(s1.size()>n){
            sum-=(*(s1.begin()));
            s1.erase(s1.begin());
        }
        pref[i] = sum;
       
    }
    sum = 0;
    s1.clear();
    for(long long i=3*n;i>2*n;i--){
        s1.insert(arr[i]);
        sum+=arr[i];
    }
    suff[2*n+1] = sum;
    for(long long i=2*n;i>n;i--){
        s1.insert(arr[i]);
        sum+=arr[i];
        if(s1.size()>n){
            sum-=(*(s1.rbegin()));
            s1.erase(--s1.end());
        }
        suff[i] = sum;
    }
    long long ans = -1e18;
    for(long long i=n;i<=2*n;i++){
        ans = max(ans,pref[i]-suff[i+1]);
        //cout<<pref[i]<<" "<<suff[i+1]<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 15104
#
# abc157 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
1 7
3 2
1 7"""
        output = """702"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 2
2 1
2 3"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 1
1 0"""
        output = """-1"""
        self.assertIO(input, output)


def resolve():
    N, M = map(int, input().split())
    SC = [list(map(int, input().split())) for _ in range(M)]
    SC = set(map(tuple, SC))
    SC = list(set(SC))
    SC.sort()

    ans = -1
    for i in range(10**N):
        si = str(i)
        if len(si) != N:
            continue
        for sc in SC:
            s, c = sc
            if si[s-1] != str(c):
                break
        else:
            ans = i
            break

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"unicode/utf8"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	numStr := nextLine()
	num, _ := strconv.ParseInt(numStr, 10, 64)
	n := uint64(utf8.RuneCountInString(numStr))
	var count int64
	for i := 0; i < 1<<(n-1); i++ {
		var lastIndex uint64
		var isCalc bool
		for j := uint64(0); j < n-1; j++ {
			if (1 & (i >> j)) == 1 {
				ammount, _ := strconv.ParseInt(numStr[lastIndex:j+1], 10, 64)
				count += ammount
				lastIndex = j + 1
				isCalc = true
			}
		}
		if isCalc {
			ammount, _ := strconv.ParseInt(numStr[lastIndex:], 10, 64)
			count += ammount
		}
	}
	count += num
	fmt.Println(count)
}


Measured memory_bytes: 640
N,K=map(int,input().split())
P=list(map(int,input().split()))

s=(sum(P[:K])+K)/2
ans=s

for i in range(1,N-K+1):
    ans=max(ans,s-(P[i-1]+1)/2+(P[i+K-1]+1)/2)
    s=s-(P[i-1]+1)/2+(P[i+K-1]+1)/2
print(ans)
    

Measured memory_bytes: 25060
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
  if(input[0]<=5) console.log(0)
  else if(input[0]<13) console.log(input[1]/2)
  else console.log(input[1])
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import Control.Monad
import Data.Array.IO

main :: IO ()
main = do
  [n, m] <- (map read . words) <$> getLine :: IO [Int]
  counts <- newArray (1, n) 0 :: IO (IOArray Int Int)
  replicateM_ m $ do
    [a, b] <- (map read . words) <$> getLine :: IO [Int]
    incr counts a
    incr counts b

  mapM_ print =<< getElems counts

incr array i = do
  c <- readArray array i
  writeArray array i (c + 1)


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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll a,b,c,ans=INF;
int main()
{
    fast_io;
    cin>>a>>b>>c;
    ans=min(ans,a+b);
    ans=min(ans,a+c);
    ans=min(ans,b+c);
    cout<<ans<<endl;
    return 0;
}


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

vector<string> strings;

int solve(string str,char x){
    //cout << str << " " << x << endl;
    if(x=='a'){
        strings.push_back(str);
        return 1;
    }
    int most_left=str.size();
    for(int i=0;i<str.size();i++){
        if(str.at(i)==x){
            most_left=i;
            break;
        }
    }
    //cout << most_left << endl;
    int ans=0;
    if(most_left==str.size()){
        ans+=solve(str,x-1);
        for(int i=0;i<str.size();i++){
            if(str.at(i)==(x-1)){
                string new_str=str;
                new_str.at(i)=x;
                ans+=solve(new_str,x-1);
            }
        }
    }else if(most_left<str.size()){
        //cout << "most_left<str.size() " << str << " " << x << " " << most_left << endl;
        int count=0;
        for(int i=0;i<most_left;i++){
            //cout << "i=" << i << " str.at(i)=" << str.at(i) << " x-1=" << (char)(x-1) << endl;
            if(str.at(i)==(x-1)){
                count++;
                string new_str=str;
                new_str.at(i)=x;
                //cout << "new_str " << new_str << endl;
                ans+=solve(new_str,x-1);
            }
        }
        if(count==0) return 0;
    }
    //cout << str << " " << x << " " << ans << endl;
    return ans;
}

int main(){
    string s;
    cin >> s;
    while(s.at(0)!='#'){
        strings=vector<string>(0);
        cout << solve(s,'z') << endl;
        sort(strings.begin(),strings.end());
        if(strings.size()<=10){
            for(int i=0;i<strings.size();i++){
                cout << strings.at(i) << endl;
            }
        }else if(strings.size()>10){
            for(int i=0;i<5;i++){
                cout << strings.at(i) << endl;
            }
            for(int i=5;i>0;i--){
                cout << strings.at(strings.size()-i) << endl;
            }
        }
        cin >> s;
    }
}


Measured memory_bytes: 4260
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
      
    if(A*N <= B){
         System.out.println(A*N);
    }else{      
         System.out.println(B);
    }
}
}

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

int main()
{
	int temp;
	int number = 0;
	for (int i = 0; i < 3; ++i)
	{
		cin >> temp;
		number *= 10;
		number += temp;
	}

	if (number % 4 == 0) cout << "YES";
	else cout << "NO";


	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);
		int N = in.nextInt();
		int A = in.nextInt();
		int B = in.nextInt();
		if ((N == 1 && B != A) || A > B) {
			System.out.println(0);
		} else {
			long min = B - A;
			long max = min * (N - 1);
			System.out.println(max - min + 1l);
		}
		in.close();
	}
}

Measured memory_bytes: 21588
#include <iostream>
using namespace std;
int main(){
  int s[6];
  int p[6][6] = {{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
  int a,b,n;
 
  for(int i=0;i<6;i++) cin>>s[i];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=0;j<6;j++){
      if(a==s[j]) a=j;
      if(b==s[j]) b=j;
    }
    cout<<s[p[a][b]-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <math.h>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int max_4, max_7;
  max_4 = N / 4;
  max_7 = N / 7;
  for (int i = 0; i <= max_4; i++) {
    for (int k = 0; k <= max_7; k++) {
      int sum = 4 * i + 7 * k;
      if (sum == N) {
        cout << "Yes" << endl;
        return 0 ;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
/*
 * Created by Dipta Das on 09-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    vector<int> ar(n);
    int diff = INT_MAX;
    for (int i = 0; i < n; ++i) cin >> ar[i];
    for (int i = 0; i < n; ++i) {
        int sum1 = 0, sum2 = 0;
        for (int j = 0; j <= i; ++j) sum1 += ar[j];
        for (int j = i+1; j < n; ++j) sum2 += ar[j];
        diff = min (diff, abs(sum1 - sum2));
    }

    cout << diff << endl;



    return 0;
}



Measured memory_bytes: 256
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n;
double p[3003],dp[3003][3003],ans;
int main()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> p[i];

	dp[1][1] = p[1];
	dp[1][0] = 1-p[1];

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

	for (int i = 1; i <= n; i++)
		if (i >= n - i)
			ans += dp[n][i];
	printf("%.15f\n",ans);
	return 0;
}

/*


*/

Measured memory_bytes: 68992
/* You can't connect the dots looking forward 
   you can only connect them looking backwards. */

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define N 307

int test;

int n,m;

int grid[N][N];

int il[N],zly[N];
VI g[N],G[N];

bool check(int mid){
    FOR(i,1,n){
        g[i] = G[i];
    }

    FOR(i,1,m){
        zly[i] = 0;
    }

    while(1){
        bool czy = false;

        FOR(i,1,m){
            il[i] = 0;
        }

        FOR(i,1,n){
            if (g[i].size()==0)
                return false;

            il[g[i].back()]++;

            if (il[g[i].back()]>mid){
                czy = true;zly[g[i].back()]=1;

                FOR(j,1,n){
                    while(g[j].size() && zly[g[j].back()]){
                        g[j].pop_back();
                    }

                    if (g[j].size()==0)
                        return false;
                }

                break;
            }
        }

        if (czy)
            continue;

        return true;
    }

    return false;
}

void solve()
{
    cin >> n >> m;

    FOR(i,1,n){
        FOR(j,1,m){
            int x;
            cin >> x;
            G[i].pb(x);
        }
        reverse(G[i].begin(),G[i].end());
    }

    int l = 1,r = n+1;

    while(l!=r){
        int mid = (l+r)/2;

        if (check(mid)){
            r = mid;
        }else{
            l = mid + 1;
        }
    }

    cout << l;

    return;
}

int32_t main()
{
    boost

    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)

	res, cnt := 0, 0
	for _, c := range s {
		if c == 'A' || c == 'C' || c == 'G' || c == 'T' {
			cnt += 1
			if cnt > res {
				res = cnt
			}
		} else {
			cnt = 0
		}
	}

	fmt.Println(res)
}

Measured memory_bytes: 512
#include<cstdio>

const int N = 65555;
int prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};

int main()
{
    int n;
    for(long i=2; i<(2<<16); i++)
    {
        if(!isNotPrime[i])
            prime[num_prime++]=i;
        for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
        {
            isNotPrime[i * prime[j]] = 1;
            if( !(i % prime[j] ) )
                break;
        }
    }
    while(~scanf("%d",&n),n)
    {
        int cnt = 0;
        for(int i=2; i<= n/2; i++)
                 if(!isNotPrime[i] && !isNotPrime[n-i])
                      cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1540
#include <stdio.h>

int gcd(int a, int b){
  int r = a % b;
  while(r > 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int gcd_array(int n,int *a){
  if(n == 1) return a[0];
  else return gcd(gcd_array(n-1,a),a[n-1]);
}
  

int main(){
  int n;
  scanf("%d\n",&n);
  int a[n];
  for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
  int maxgcd = gcd_array(n,a);
  printf("%d\n",maxgcd);
  return 0;
}

Measured memory_bytes: 2176
import sys
n = int(input())
h_ls = [int(i) for i in sys.stdin.readline().split()]
cnt = 0
for i in range(1,101):
    flg = True
    for j in range(n):
        h = h_ls[j]
        if not h:
            flg = True
        else:
            h_ls[j] -= 1
            if flg:
                flg = False
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  cin>>s;
  if(s[5]=='1'){
    cout<<"TBD"<<endl;
  }else{
    int c=s[6]-'0';
    if(c>=5){
      cout<<"TBD"<<endl;
    }else{
      cout<<"Heisei"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
struct Card{
  char s;
  int v;
};
struct Card L[N], R[N];
void merge(struct Card [], int , int , int );
void mergeSort(struct Card [], int , int ); 
int partition(struct Card [], int , int );
void quickSort(struct Card [], int , int );
int main(){
  int n, i, v;
  struct Card A[N], B[N];
  char s[10];
  int flag=1;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%s %d",s,&v);
    A[i].s = s[0];
    B[i].s = s[0];
    A[i].v = v;
    B[i].v = v;
  }
  mergeSort(A, 0, n);
  quickSort(B, 0, n-1);
 
  for (i=0;i<n;i++ ){
    if (A[i].s!=B[i].s) {
       flag=0;
    }
  }
  if(flag==1){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }
  for (i=0;i<n;i++){
    printf("%c %d\n",B[i].s,B[i].v);
  }
  return 0;
}
void merge(struct Card A[], int left, int mid, int right){
  int i,j,k,n1,n2;  
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1].v=1000000000;
  R[n2].v=1000000000;
  i=0;
  j=0;
  for (k=left;k<right;k++){
    if (L[i].v<=R[j].v){
      A[k]=L[i];
      i++;
    }
    else {
      A[k]=R[j];
      j++;
    }
  }
}
void mergeSort(struct Card A[], int left, int right ){
  int mid;
  if (left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
void quickSort(struct Card A[], int p, int r){
  int q;
  if (p<r){
    q = partition(A,p,r);
    quickSort(A,p,q - 1);
    quickSort(A,q + 1,r);
  }
}
int partition(struct Card A[], int p, int r){
  int i, j;
  struct Card change, x;
  x=A[r];
  i=p-1;
  for (j=p;j<=r-1;j++){
    if (A[j].v<=x.v){
      i++;
      change=A[i];
      A[i]=A[j];
      A[j]=change;
    }
  }
  change=A[i+1];
  A[i+1]=A[r];
  A[r]=change;
  return i+1;
}

Measured memory_bytes: 2960
#include<stdio.h>
int main()
{
  int t,i,e;
  while(1){
  scanf("%d",&t);
  if(t==0)break;
  for(i=0;i<9;i++){
    scanf("%d",&e);
      t=t-e;
  }
  printf("%d\n",t);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int n,w;
vector<int> weight(100),value(100);
vector<vector<int>> s(4);
ll ans = 0;

void dfs(ll totw=0, ll totv=0, int loop=0) {
  if (w < totw) return;
  if (4 <= loop) { chmax(ans, totv); return; }

  ll nw=totw, nv=totv;
  int nl=loop+1;
  dfs(nw, nv, nl); // 選択しない
  for (int v: s[loop]) {
    nw += weight[0] + loop;
    nv += v;
    dfs(nw, nv, nl);
  }
}

int main() {
  IOS;
  cin >> n >> w;
  REP(i,n) cin >> weight[i] >> value[i];

  REP(i,n) s[weight[i]-weight[0]].push_back(value[i]);
  REP(i,4) sort(s[i].begin(), s[i].end(), greater<int>());

  dfs();
  COUT(ans);
  return 0;
}


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

using namespace std;

int main()
{
    long long int i,j,n;
    cin >> n;
    if(n<=1)
     cout << 0 <<endl;
    vector<long long int>h(n);
    for(i=0;i<n;++i)
    cin >> h[i];
    vector<long long int>dp(n);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;++i){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout <<dp[n-1]<<endl;

    return 0;
}

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

public class Program
{

    public void Proc()
    {
        SetPrimeList();
        int queryCount = int.Parse(Reader.ReadLine());
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < queryCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            ans.AppendLine((this.PrimeCount[inpt[1]]-this.PrimeCount[inpt[0]-1]).ToString());
        }
        Console.Write(ans.ToString());
    }

    private const int MaxNum = 100000;

    private int[] PrimeCount = new int[MaxNum+1];
    private List<int> PrimeList = new List<int>();

    private void SetPrimeList() {
        bool[] flag = new bool[MaxNum+1];
        Dictionary<int, bool> primeDic = new Dictionary<int, bool>();
        for (int i = 2; i <= MaxNum; i++) {
            if(flag[i]) {
                continue;
            }
            for (int j = 1; j * i <= MaxNum; j++) {
                flag[i * j] = true;
            }
            primeDic.Add(i, true);
            if(primeDic.ContainsKey((i+1)/2)) {
                PrimeList.Add(i);
            }
        }
        for (int i = 0; i <= MaxNum; i++) {
            
        }

        int cnt = 0;
        int idx = 0;
        int nextPrime = PrimeList[0];
        for(int i = 0; i <= MaxNum; i++) {
            if(i>=nextPrime) {
                cnt++;
                idx++;
                if(idx>=this.PrimeList.Count) {
                    nextPrime = 9999999;
                } else {
                    nextPrime = this.PrimeList[idx];
                }
            }
            this.PrimeCount[i] = cnt;
        }
    }

    public class Reader
    {
        private 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
13 13
7 11
7 11
2017 2017

";
    }

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


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1010101010

using namespace std;

int main(){
  string s;cin>>s;
  reverse(s.begin(), s.end());
  s+='0';
  int n=s.size();
  
  int dp[n+1][2];
  rep(i, n+1)rep(j, 2)dp[i][j]=INF;
  dp[0][0]=0;
  
  rep(i, n)rep(j, 2){
    int x=s[i]-'0'+j;
    
    if(x<10)dp[i+1][0] = min(dp[i+1][0], dp[i][j]+x);
    if(x>0)dp[i+1][1] = min(dp[i+1][1], dp[i][j] + (10-x));
  }
  
  cout<<dp[n][0]<<endl;

  return 0;
}


Measured memory_bytes: 12120
W,H,N=map(int, input().split())
X= [list(map(int, input().split())) for i in range(N)]

S = [[0 for j in range(W)] for i in range(H)]

for k in range(N):
  if X[k][2]==1:
    for i in range(H):
      for j in range(X[k][0]):
        S[i][j]=1
    #print(S,'1') 
  elif X[k][2]==2:
    for i in range(H):
      for j in range(X[k][0],W):
        S[i][j]=1
    #print(S,'2') 
  elif X[k][2]==3:
    for i in range(X[k][1]):
      for j in range(W):
        S[i][j]=1
    #print(S,'3') 
  elif X[k][2]==4:
    for i in range(X[k][1],H):
      for j in range(W):
        S[i][j]=1
    #print(S,'4') 
z=0
for i in range(H):
  z+=S[i].count(0)
print(z)

Measured memory_bytes: 3188
n=int(input())
a=list(map(int,input().split()))

r=10**9+5
l=-1
import copy
while(r-l>1):
	ans=[0]*n
	rain=(r+l)//2
	initrain = rain
	for i in range(n):
		rain = a[i]-rain
	if rain > initrain:
		l=initrain
	elif rain < initrain:
		r=initrain
	else:
		ans = initrain
		break
ret = [0]*n
ret[0] = ans
for i in range(1,n):
	ret[i] = a[i-1] - ret[i-1]

print(" ".join([str(x*2) for x in ret]))

Measured memory_bytes: 82788
import sys
import os

def file_input():
    f = open('ABC154/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,K=map(int, input().split())
    p=list(map(int, input().split()))

    max=0
    maxi=0
    for i in range(K):
        max+=p[i]
    sum=max
    for i in range(1,N-K):
        sum=sum-p[i]+p[i+K]
        if sum>=max:
            max=sum
            maxi=i+1

    # print(maxi)
    out=0
    for i in range(maxi,maxi+K):
        out+=((1+p[i])*p[i]/2)/p[i]
        # print(out)

    print(out)

if __name__ == '__main__':
    main()


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

using namespace std;

#define int int64_t

signed main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    if(x % y == 0) {
        cout << -1 << endl;
    } else {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace V0093{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var from = sr.Next<int>();
            var to = sr.Next<int>();
            while(true){
                Enumerable
                    .Range(from, to - from + 1)
                    .Where(DateTime.IsLeapYear)
                    .Select(x => x.ToString())
                    .DefaultIfEmpty("NA")
                    .ToList()
                    .ForEach(Console.WriteLine);


                if((from = sr.Next<int>()) == 0 & (to = sr.Next<int>()) == 0) break;
                Console.WriteLine();
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }
    }
}

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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    string s;
    cin >> a >> s;
    if(a<3200) cout << "red" << endl;
    else cout << s << endl;
    
	return 0;
}


Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))

def main():
  x=aint()
  n,i=100,0
  while n<x:
    n=floor(1.01*n)
    i+=1
  print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 64336
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    string S; cin >> S;
    int front2 = (S[0] - '0') * 10 + (S[1] - '0'), back2 = (S[2] - '0') * 10 + (S[3] - '0');
    bool MMYY = false;
    bool YYMM = false;
    if(0 < front2 && front2 <= 12) MMYY = true;
    if(0 < back2 && back2 <= 12) YYMM = true;
    if(MMYY && YYMM)
        cout << "AMBIGUOUS";
    else if(MMYY)
        cout << "MMYY" << endl;
    else if(YYMM)
        cout <<"YYMM" << endl;
    else
        cout << "NA" << endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Popular Vote
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int m4 = m * 4;
  
  int asum = 0;
  for (int i = 0; i < n; i++) scanf("%d", as + i), asum += as[i];

  int c = 0;
  for (int i = 0; i < n; i++)
    if (as[i] * m4 >= asum) c++;

  if (c >= m) puts("Yes");
  else puts("No");
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    if (s=="Sunny") cout<<"Cloudy\n";
    if (s=="Cloudy") cout<<"Rainy\n";
    if (s=="Rainy") cout<<"Sunny\n";
    return 0;
}


Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
l = [str(0) for i in range(n)]
key = list(c.keys())
for i in range(len(list(c.keys()))):
    l[key[i]-1] = str(c[key[i]])
print('\n'.join(l))

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   int H, W, h, w;
   cin >> H >> W >> h >> w;
   if (H % h == 0 && W % w == 0) {
      cout << "No\n";
      return 0;
   }
   cout << "Yes\n";
   for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
         if (i % h == h - 1 && j % w == w - 1) {
            cout << -3750 * (h * w - 1) - 1 << " ";
         } else {
            cout << 3750 << " ";
         }
      }
      cout << "\n";
   }
}


Measured memory_bytes: 1664
n=int(input())
p=list(map(int,input().split()))
a=1
c=0
while True:
    f=0
    x=p[a-1]
    y=p[a]
    z=p[a+1]
    if y>x and z>y:
        f=1
    if y>z and x>y:
        f=1
    if f==1:
        c=c+1
    a=a+1
    if a==n-1:
        break
print(c)
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int a,b,c;cin>>a>>b>>c;
    if(a%2 || b%2 || c%2){
        cout<<0<<endl;
    }else if(a==b && b==c){
        cout<<-1<<endl;
    }else{
        int ans=0;
        while(!(a%2 || b%2 || c%2)){
            int a1,b1,c1;
            a1=a;
            b1=b;
            c1=c;
            a+=c1/2+b1/2;
            b+=c1/2+a1/2;
            c+=b1/2+a1/2;
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
int p[N],a[N],b[N];
struct node{int l,r,mid,mn;}s[N<<2];
void build(int di,int l,int r)
{
    s[di].l=l,s[di].r=r,s[di].mid=l+r>>1,s[di].mn=1e9;
    if(l==r)return;
    build(di<<1,l,s[di].mid),build(di<<1|1,s[di].mid+1,r);
}
void ins(int di,int x,int v)
{
    if(s[di].l==s[di].r){s[di].mn=v;return;}
    if(x<=s[di].mid)ins(di<<1,x,v);
    else ins(di<<1|1,x,v);
    s[di].mn=min(s[di<<1].mn,s[di<<1|1].mn);
}
int qry(int di,int l,int r)
{
    if(l<=s[di].l&&s[di].r<=r)return s[di].mn;
    else if(r<=s[di].mid)return qry(di<<1,l,r);
    else if(l>s[di].mid)return qry(di<<1|1,l,r);
    return min(qry(di<<1,l,r),qry(di<<1|1,l,r));
}
struct edge{int to,nxt;}e[N<<1];
int head[N],tot=1;
void adde(int x,int y){e[tot]=(edge){y,head[x]};head[x]=tot++;}
priority_queue<int,vector<int>,greater<int> >q;
int n,rd[N];
void topo()
{
    for(int i=1;i<=n;i++)
        for(int j=head[i];j;j=e[j].nxt)rd[e[j].to]++;
    for(int i=1;i<=n;i++)if(!rd[i])q.push(i);
    int tt=0;
    while(!q.empty())
    {
        int u=q.top();q.pop(),b[++tt]=u;//cout<<u<<endl;
        for(int i=head[u];i;i=e[i].nxt)
            if(!(--rd[e[i].to]))q.push(e[i].to);
    }
}
int main()
{
    int k;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){int x;scanf("%d",&x),a[x]=i;}
    //for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    //cout<<endl;
    build(1,1,n);
    for(int i=n;i>=1;i--)
    {
        int x=qry(1,max(1,a[i]-k+1),a[i]);
        //cout<<x<<endl;
        if(x>=1&&x<=n)adde(a[i],a[x]);
        x=qry(1,a[i],min(n,a[i]+k-1));
        //cout<<x<<endl;
        if(x>=1&&x<=n)adde(a[i],a[x]);
        ins(1,a[i],i);
    }
    topo();
    for(int i=1;i<=n;i++)p[b[i]]=i;
    for(int i=1;i<=n;i++)printf("%d\n",p[i]);
}


Measured memory_bytes: 50816
cube = [list(map(int, input().split())) for i in range(3)]
a = True
x = [0] * 3
y = [0] * 3
x[0] = 0
y[0] = cube[0][0] - x[0]
y[1] = cube[0][1] - x[0]
y[2] = cube[0][2] - x[0]
x[1] = cube[1][0] - y[0]
x[2] = cube[2][0] - y[0]
for i in range(3):
    for j in range(3):
        if not (x[i] + y[j] == cube[i][j]):
            a = False
if a:
    print("Yes")
else:
    print("No")

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

using namespace std;
const int maxn = 18;
const int maxState = 1 << 18;
int f[maxState][maxn];
vector<int> a, b;
int n;
int calc(int mask, int pre, int cnt) {
    //cnt = __builtin_popcount(mask)
    if (cnt == n) return 0;
    int &res = f[mask][pre];
    if (res != -1) return res;
    res = 1e9;
    //(mask, pre) -> (mask | (1 << x), x)
    int pre_num = a[pre];
    if ((pre - cnt) % 2 == 0)
        pre_num = b[pre];
    int cnt_bigger = 0;
    for (int x = n - 1; x >= 0; --x) if ((mask >> x & 1) == 0) {
        //pre <= cur
        int cur_num = b[x];
        if ((x - cnt) % 2 == 0)
            cur_num = a[x];
        if (pre_num <= cur_num) 
            res = min(res, calc(mask | (1 << x), x, cnt + 1) + cnt_bigger);
    }
    else
        ++cnt_bigger;
    return res;
}
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.resize(n); b.resize(n);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    memset(f, 255, sizeof(f));
    int res = 1e9;
    for (int i = 0; i < n; ++i)
        res = min(res, calc(1 << i, i, 1));
    if (res > 1e8) 
        res = -1;
    cout << res;
    return 0;
}

Measured memory_bytes: 18688
N = int(input())
x = []
y = []
for i in range(N):
    x1, y1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
import math
def distance(x,y,i,j):
    d = math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    return d
def length(x,y):
    l = 0
    for i in range(0,N):
        for j in range(0,N):
            l = l + distance(x,y,i,j)
    return l / N
print(length(x,y))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int a, b, c, x, y;

void solve() {
  int cost = 0;
  if (a + b > 2 * c) {
    if (x > y) {
      cost = y * 2 * c + (x - y) * a;
    } else {
      cost = x * 2 * c + (y - x) * b;
    }
    cost = min(cost, max(x, y) * 2 * c);
  } else {
    cost = x * a + y * b;
  }
  cout << cost << endl;
}

int main() {
  cin >> a >> b >> c >> x >> y;
  solve();
}


Measured memory_bytes: 256
import heapq
X, Y, Z, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A.sort(reverse = True)
A.append(-10**20)
B.sort(reverse = True)
B.append(-10**20)
C.sort(reverse = True)
C.append(-10**20)

Q = []
heapq.heapify(Q)
heapq.heappush(Q, (-(A[0]+B[0]+C[0]), 0, 0, 0))
count = 0
fin = {}
while count < K:
    value, a, b, c = heapq.heappop(Q)
    if (a, b, c) not in fin:
        fin[(a, b, c)] = 1
        print(-value)
        heapq.heappush(Q, (-(A[a+1]+B[b]+C[c]), a+1, b, c))
        heapq.heappush(Q, (-(A[a]+B[b+1]+C[c]), a, b+1, c))
        heapq.heappush(Q, (-(A[a]+B[b]+C[c+1]), a, b, c+1))
        count += 1



Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			if (isIncreasing(a)) {
				System.out.println(0);
				return;
			}
			int maxValue = 0, maxIndex = 0;
			int minValue = Integer.MAX_VALUE, minIndex = 0;
			for (int i = 0; i < a.length; i++) {
				if (a[i] > maxValue) {
					maxValue = a[i];
					maxIndex = i + 1;
				}
				if (a[i] < minValue) {
					minValue = a[i];
					minIndex = i + 1;
				}
			}
			if ((maxValue <= 0) || (minValue >= 0)) {
				System.out.println(n - 1);
				// すべてが負の数か正の数の場合
				printSteps(n, (maxValue <= 0));
			} else {
				int fromIndex = (Math.abs(maxValue) > Math.abs(minValue)) ? maxIndex : minIndex;
				System.out.println(2 * n - 1);
				printAddSteps(n, fromIndex);
				printSteps(n, (fromIndex == minIndex));
			}
		}
	}

	/**
	 * @param a 入力配列
	 * @return 入力配列は単調増加かどうか
	 */
	static boolean isIncreasing(int[] a) {
		for (int i = 1; i < a.length; i++) {
			if (a[i] < a[i - 1]) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 長さnの数列の計算ステップを出力する
	 * 
	 * @param n       数列の長さ
	 * @param reverse 逆順かどうか
	 */
	private static void printSteps(int n, boolean reverse) {
		if (reverse) {
			IntStream.range(1, n).map(i -> n - i).forEach(i -> System.out.println((i + 1) + " " + i));
		} else {
			IntStream.range(1, n).forEach(i -> System.out.println(i + " " + (i + 1)));
		}
	}

	/**
	 * 数列のすべてにindexの数字を足す計算ステップを出力する
	 * 
	 * @param n     数列の長さ
	 * @param index 加算もととなるindex
	 */
	private static void printAddSteps(int n, int index) {
		IntStream.rangeClosed(1, n).forEach(i -> System.out.println(index + " " + i));
	}
}


Measured memory_bytes: 29012
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int  main()
{


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x;
	cin >> n >> x;
	int a;
	int count = 1;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{

		cin >> a;
		sum += a;
		if (sum <= x)
			count++;
		else
			break;
	}
	cout << count;

}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t,sum=0;
	cin>>n>>t;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i);
		if(i>0){
			if(v.at(i)-v.at(i-1)<t){
				sum+=v.at(i)-v.at(i-1);
			}else{
				sum+=t;
			}
		}
	}
	sum+=t;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long int dp[11][11][11];
long int n,m,q;
long int ans=0;
void fun(long int ind,long int val,long int sum,vector<int> a)
{
    if(ind==n)
    {
        ans=max(ans,sum);
        return ;
    }
    if(val>m)
    return ;
    vector<int> b=a;
    for(long int i=val;i<=m;i++)
    {
        long int ss=sum;
         b.push_back(i);
         for(long int j=0;j<ind;j++)
         {
            ss+=dp[ind][j][i-b[j]];
         }
         fun(ind+1,i,ss,b);
         b.pop_back();
    }
}
int main()
{
   long long int x;
   cin>>x;
   for(long long int i=-1000;i<=1000;i++)
   {
       for(long long int j=-1000;j<=1000;j++)
       {
           if(i*i*i*i*i-j*j*j*j*j==x)
           {
               cout<<i<<" "<<j;
               return 0;
           }
       }
   }
   
}


Measured memory_bytes: 3628
import sys
import math
N, H = map(int, input().split())

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)
max_a = max(a)
Strong_b = [b_i for b_i in b if b_i > max_a]

if sum(Strong_b) >= H:
	Strong_b = sorted(Strong_b, reverse = True)
	for i in range(N):
		H -= Strong_b[i]
		if H <= 0:
			print(i+1)
			sys.exit()

H -= sum(Strong_b)
num_attack = len(Strong_b) + math.ceil(H/max_a)
print(num_attack)

Measured memory_bytes: 12936
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b; cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
map=[[ int(0) for i in range(w)] for j in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='#':
			map[i][j]='#'
		else:
			for k in range(-1,2):
				for p in range(-1,2):
					if 0<=i+k and i+k<h and 0<=j+p and j+p<w and s[i+k][j+p]=='#':
						map[i][j]+=1
			map[i][j]=str(map[i][j])
for i in range(h):	
	print(''.join(map[i]))

Measured memory_bytes: 3188
if __name__ == '__main__':
    s = input()
    # s = 'Atcoder'
    if s[0] != 'A':
        print('WA')
        exit(0)

    if s[2:-1].count('C') != 1:
        print('WA')
        exit(0)

    c_index = s.find('C')
    s_sub = ""
    for i, c in enumerate(s):
        if i == 0 or i == c_index:
            continue
        s_sub += c

    if not s_sub.islower():
        print('WA')
        exit(0)

    print('AC')


Measured memory_bytes: 3060