akhauriyash/Code-Regression huggingface dataset:
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
   ll n,m,i,j,cc=0;
   cin>>n;
   ll ara[n+1],bra[n+1],bal[n];
   for(i=1;i<=n;i++)cin>>ara[i];
   for(i=1;i<=n;i++)cin>>bra[i];
   for(i=1;i<n;i++)cin>>bal[i];
   for(i=1;i<=n;i++){
      if(i==1){
        cc+=bra[ara[i]];
      }
      else{
        cc+=bra[ara[i]];
        if(ara[i]==ara[i-1]+1){
            cc+=bal[ara[i-1]];
        }
      }
   }
   cout<<cc<<endl;
}


Measured memory_bytes: 4992
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [usize; n]
    }
    v.sort();
    let mut ans = n;
    let mut ac = 0;
    for i in 0..n - 1 {
        ac += v[i];
        if ac * 2 < v[i + 1] {
            ans = n - i - 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#define loop(i,s,e) for(ll i = s;i < e;i++)

#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed ll;

ll v,e,g[100][100],s,t,d;

ll dd[100];
bool visited[100];
bool ngl;

void dfs(ll n) {
    loop(i,0,v){
        if(g[n][i] != 0xffffffffffff){
            if(dd[i] > dd[n] + g[n][i]) {
                dd[i] = dd[n] + g[n][i];
                if(visited[i]){ngl = true;break;}
                visited[i] = true;
                dfs(i);
                visited[i] = false;
            }
        }
    }
}

int main() {
    for(ll i = 0;i < 100;i++)for(ll j = 0;j < 100;j++) if(i!=j)g[i][j] = 0xffffffffffff;
    cin >> v >> e;
    loop(i,0,e) {cin >> s >> t >> d;g[s][t] = d;}
    loop(j,0,v) {
        loop(i, 0, 100) {
            dd[i] = 0xffffffffffff;
            visited[i] = false;
        }
        dfs(j);
    }
    if(ngl){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    loop(i,0,v)loop(j,0,v)loop(k,0,v)g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
    loop(x,0,v){loop(y,0,v){if(g[x][y]>=0x7fffffffffff)cout<<"INF";else cout<<g[x][y];if(y!=v-1)cout<<" ";}cout<<endl;}
}




Measured memory_bytes: 3172
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N, K;
vector<int> l;

int main()
{
    cin >> N >> K;
    l.resize(N);
    for (size_t i = 0; i < N; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end(), greater<int>());
    int sum = 0;
    for (size_t i = 0; i < K; i++) {
        sum += l[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>

int main(int argc, char* argv[])
{
    int x;
    
    std::cin >> x;
    
    if ((1 <= x) && (x <= 100)){
        x = std::pow(x, 3.0);
        std::cout << x << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3224
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n = I()
A = IR(n)



a_sum = sum(A)
dp1 = [0] * (a_sum + 1)
dp1[0] = 1
dp2 = [0] * (a_sum + 1)
dp2[0] = 1
for i in range(n):
    for j in range(a_sum, -1, -1):
        if j < A[i]:
            dp2[j] = dp2[j] * 2 % mod
        else:
            dp1[j] = (dp1[j] + dp1[j - A[i]]) % mod
            dp2[j] = (dp2[j] * 2 + dp2[j - A[i]]) % mod


ans = pow(3, n, mod)
for k in range((a_sum + 1) // 2, a_sum + 1):
    ans = (ans - dp2[k] * 3) % mod


if a_sum % 2 == 0:
    ans = (ans + dp1[a_sum // 2] * 3) % mod


print(ans)

Measured memory_bytes: 43116
n, m = map(int, input().split())

s = []
e = []
for _ in range(m):
  a, b = map(int, input().split())
  if a == 1:
    s.append(b)
  if b == n:
    e.append(a)

if set(s) & set(e):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 21836
#include<iostream>
#include<sstream>
#include<string>
using namespace std;

long long Fomula(string s) {
	long long sum = 0;
	int p = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '+' || i == s.size() - 1) {
			stringstream ss;
			ss << s.substr(p, i - p + 1);
			long long tmp;
			ss >> tmp;
			sum += tmp;
			p = i + 1;
		}
	}
	return sum;
}

long long Many_Fomulas(string s, int size, int step, int count) {
	if (step + 1 == size) {
		return Fomula(s);
	}
	else {
		string w;
		w = s.substr(0, step + count + 1) + "+" + s.substr(step + count + 1, s.size() - step - count - 1);
		return Many_Fomulas(s, size, step + 1, count) + Many_Fomulas(w, size, step + 1, count + 1);
	}
}

int main() {
	string s;
	cin >> s;
	cout << Many_Fomulas(s, s.size(), 0, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
int a,b;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a>>b;
	if ((a+b)&1)
		cout<<"IMPOSSIBLE";
	else 
		cout<<((a+b)>>1);
	return 0;
}


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

using namespace std;

int main()
{
    int n, s;
	while (cin >> n >> s, n || s) {
        int ans = 0;

        for (int i = 0; i < (1<<10); ++i) {
            int cnt = 0, sum = 0;

            for (int j = 0; j < 10; ++j) {
                if (i >> j & 1) {
                    sum += j;
                    cnt++;
                }
            }

            if (cnt == n && sum == s) ans++; 
        }

        printf("%d\n", ans);
    }
}

Measured memory_bytes: 1144
using static System.Console;
using System.Linq;

public class Hello
{
    public static void Main()
    {
      var l = ReadLine();
      int[] L = new int[3] {0,0,0};
      for (int i=0;i<3;i++){
      	L[i] = int.Parse(l.Split()[i]); 
      }
      WriteLine(new int[] {L[0]+L[1],L[1]+L[2],L[0]+L[2]}.Min() );    
    }
}

Measured memory_bytes: 13268
// https://atcoder.jp/contests/abc117/tasks/abc117_b
// +build ignore

package main

import (
	"fmt"
)

func main() {
	var n, l_max, l_sum int
	fmt.Scan(&n)
	ls := make([]int, n)
	for i :=0; i < n; i++{
		fmt.Scan(&ls[i])
		l_sum += ls[i]
		if ls[i] > l_max {
			l_max = ls[i]
		}
	}
	if ans := l_sum - l_max; l_max < ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
N = int(input())
s = [int(input()) for _ in range(N)]
s.sort()
ans = sum(s)
if ans % 10:
    print(ans)
else:
    for i in range(N):
        if s[i] % 10:
            ans -= s[i]
            print(ans)
            break
    else:
        print(0)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
namespace Program
{
    using namespace std;
    class Solver
    {
    private:
        const int INF = 1000000001;
        const int MIN = 0;

        int N;
        int T;

        vector<int> A;
        vector<int> Div;

        int maxIdx = 0;
        int maxVal = 0;
        int minIdx = 0;
        int minVal = 0;

    public:
        Solver()
        {
            cin.tie(0);
            ios::sync_with_stdio(false);

            cin >> N >> T;
            A.resize(N);

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

        void Solve()
        {
            int start = 0;
            int end = N;

            while (true)
            {
                if (start > N - 1) break;

                maxFromTo(start, end);
                minFromTo(start, maxIdx);

                if (minVal != INF && maxVal != MIN) Div.push_back(maxVal - minVal);
                start = maxIdx + 1;
            }

            // 降順ソート
            sort(Div.begin(), Div.end(), greater<int>());

            int ans = 1;
            int tmp = Div[0];

            for (int i = 1; i < Div.size(); i++)
            {
                if (tmp != Div[i]) break;
                ans++;
            }

            cout << ans << endl;
        }

        void maxFromTo(int s, int e)
        {
            maxVal = MIN;
            for (int i = s; i < e; i++)
            {
                if (maxVal < A[i])
                {
                    maxVal = A[i];
                    maxIdx = i;
                }
            }
        }

        void minFromTo(int s, int e)
        {
            minVal = INF;
            for (int i = s; i < e; i++)
            {
                if (A[i] < minVal)
                {
                    minVal = A[i];
                    minIdx = i;
                }
            }
        }
    };
}

int main()
{
    // メモリリーク検出
    //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF
    //    | _CRTDBG_DELAY_FREE_MEM_DF
    //    | _CRTDBG_CHECK_ALWAYS_DF
    //    | _CRTDBG_LEAK_CHECK_DF);

    // メンバ関数ポインタ取得
    void (Program::Solver::*pSolve)() = &Program::Solver::Solve;

    // コンストラクタ呼び出し
    Program::Solver obj;

    // .*演算子でアクセス
    (obj.*pSolve)();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	string s;
	int n,k;
	cin>>s>>k;
	n = s.size();
	for(int i=0;i<n;i++){
		int cgs = 'z'+1-s[i];
		if( s[i] == 'a' ) cgs = 0;
		if( k >= cgs ){
			s[i] = 'a';
			k -= cgs;
		}
	}
	if( k > 0 ){
		int rem = k % 26;
		for(int i=0;i<rem;i++){
			s[n-1]++;
			if( s[n-1] == 'z'+1 ) s[n-1] = 'a';
		}
	}cout<<s<<endl;
	return 0;
}

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

using namespace std;

int main() {

    int n, m, p, x;

    while(cin >> n >> m >> p, n | m | p) {

        int sum = 0;
        int hit = 0;

        for(int i = 1; i <= n; ++i) {
            cin >> x;
            sum += 100 * x;
            if(i == m) hit = x;
        }

        cout << (hit ? (sum * (100 - p) / 100) / hit : 0) << endl;

    }

}

Measured memory_bytes: 1160
S = input()
i = len(S) // 2 #回文にするためには、文字列の両端から合っているかチェックすれば良い

cnt = 0
for x in range(i):
    # S[-1]が一番最後の文字
    if S[x] != S[-(x + 1)]:
        cnt += 1
    
print(cnt)


Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
    long long n,i,min,max,gokei=0,a;
    
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a);
        if(i==0){
            min=a;
            max=a;
        }else{
            if(a<min){
             min=a;
            }
            if(a>max){
             max=a;
            }
        }
        gokei+=a;
    }
    printf("%lld %lld %lld\n",min,max,gokei);
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n;
ll pat[52];
ll siz[52];

int main(){
	cin>>n;
	pat[0] = 1;
	siz[0] = 1;
	FOR(i,1,n+1){
		pat[i] = pat[i-1]*2 + 1;
		siz[i] = siz[i-1]*2 + 3;
	}
	ll x;
	cin>>x;
	ll ans = 0;
	FORR(i,0,n+1){
		if(x == 0)break;
		if(x == siz[i]){
			// eat all
			ans += pat[i];
			break;
		}
		if(x == 1){
			// B
			break;
		}
		assert(i>0);
		if(x <= 1ll + siz[i-1]){
			x--;
		}else{
			ans += 1ll + pat[i-1];
			x -= 1ll + siz[i-1] + 1ll;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);}
int lcm(int a,int b){
	return a/gcd(a,b)*b;}

int main(){
	stack<int>S;
	int a,b,x;
	string s;
	while(cin>>s){
		if(s[0]=='+'){
			a=S.top();S.pop();
			b=S.top();S.pop();
			S.push(a+b);
		}
		else if(s[0]=='-'){
			a=S.top();S.pop();
			b=S.top();S.pop();
			S.push(b-a); 
		}
		else if(s[0]=='*'){
			a=S.top();S.pop();
			b=S.top();S.pop();
			S.push(a*b);
		}
		else {
			S.push(atoi(s.c_str()));
		}
	}
	cout<<S.top()<<endl;
	return 0;
}




Measured memory_bytes: 3148
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	int ans = 1;

	for(int loop = 0; loop < N; loop++){

		if(ans <= K){

			ans *= 2; //ansを足すことと同じ

		}else{

			ans += K;
		}
	}

	printf("%d\n",ans);

	return 0;
}


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

int main() {
	int N, K, ans;
	string S;
	cin >> N >> K >> S;
	pair<int, int> tmp1;
	vector<pair<int, int>> tmp2;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '0') ++tmp1.first;
		else {
			if (tmp1.first) tmp2.push_back(tmp1);
			tmp1.first = 0;
			tmp1.second = i + 1;
		}
	}
	if (tmp1.first) tmp2.push_back(tmp1);
	if (K >= tmp2.size()) ans = N;
	else {
		sort(tmp2.begin(), tmp2.end(), [](pair<int, int>& a, pair<int, int>& b)->bool { return a.second < b.second; });
		ans = tmp2[K].second;
		for (int i = 1; i < tmp2.size() - K; ++i) ans = max(ans, tmp2[K + i].second - tmp2[i - 1].first - tmp2[i - 1].second);
		ans = max(ans, N - tmp2[tmp2.size() - K - 1].first - tmp2[tmp2.size() - K - 1].second);
	}
	cout << ans;
}

Measured memory_bytes: 1020
import java.util.Scanner;

/**
 * https://abc044.contest.atcoder.jp/tasks/abc044_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		
		long ans = Math.min(K,N)*X + Math.max(0, N-K)*Y;
		System.out.println(ans);

	}

}

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

#define int long long
#define pb push_back


int dp[200005];

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


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n],sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum^=a[i];
    }
    for(int i=0;i<n;i++)
        cout << (a[i]^sum) << ' ';
}

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

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    int ma,mid,mi;
    ma=max(A,max(B,C));
    mi=min(A,min(B,C));
    mid=A+B+C-ma-mi;

    if((ma-mi)%2==(ma-mid)%2){
        cout << (2*ma-mid-mi)/2 << endl;
        return 0;
    }else {
        cout << (2*ma-mid-mi+3)/2 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  int n,d;
  cin>>n>>d;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p[i];
  int ans=0;
  for(int i=0;i<n;i++) ans+=max(0,p[i]-d);
  if(ans) cout<<ans<<endl;
  else cout<<"kusoge"<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i = 0; i < (a); i++)
#define reps(i, a, b) for(int i = (a); i < (b); i++)
#define INF 1e9
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;
double calc(double num1, double num2, string s) {
	if(s == "+") return num1 + num2;
	if(s == "-") return num1 - num2;
	if(s == "*") return num1 * num2;
	else return num1 / num2;
}
int main() {
	string str;
	while(getline(cin, str)) {
		stringstream ss(str);
		string s;
		stack<double> S;
		while(ss >> s) {
			if(s == "-" || s == "*" || s == "/" || s == "+") {
				double num1,num2;
				num2 = S.top();S.pop();
				num1 = S.top();S.pop();
				S.push(calc(num1, num2, s));
			} else {
				double num;
				sscanf(s.c_str(), "%lf", &num);
				S.push(num);
			}
		}
		printf("%.7lf\n", S.top());
	}
	return 0;
}

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

typedef long long ll;

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

    int k; cin >> k;
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}

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

const int MAXN=100;
struct Card{
	char zi;
	char num;
}C1[MAXN],C2[MAXN];

void BubbleSort(struct Card A[],int n){
			for(int i=0;i<n-1;i++){
			for(int j=0;j<n-1-i;j++){
				if(C1[j].num>C1[j+1].num){
					Card t=C1[j];
					C1[j]=C1[j+1];
					C1[j+1]=t;
				}
			}
		}
}

void SelectionSort(struct Card A[],int n){
	for(int i=0;i<n;i++){
		int p=i;
		for(int j=i;j<n;j++){
			if(C2[j].num<C2[p].num) p=j;
		}
		Card t=C2[i];
		C2[i]=C2[p];
		C2[p]=t;
	}
}
int main(){
	int n;
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>C1[i].zi>>C1[i].num;
		} 
		for(int i=0;i<n;i++){
			C2[i]=C1[i];
		} 
		BubbleSort(C1,n);
		SelectionSort(C2,n);
		for(int i=0;i<n;i++){
			if(i<n-1)
			cout<<C1[i].zi<<C1[i].num<<" ";
			else
			cout<<C1[i].zi<<C1[i].num;
		}
		cout<<endl;
		cout<<"Stable"<<endl;
		for(int i=0;i<n;i++){
			if(i<n-1)
			cout<<C2[i].zi<<C2[i].num<<" ";	
			else
			cout<<C2[i].zi<<C2[i].num;
		}
		int bo=1;
		for(int i=0;i<n;i++){
			if(C2[i].zi!=C1[i].zi){
				bo=0;
				break;
			}
		}
		cout<<endl;
		if(bo){
			cout<<"Stable"<<endl;
		}else{
			cout<<"Not stable"<<endl;	
		}
		
	}
	return 0;
} 


Measured memory_bytes: 3084
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;

    string S;
    cin >> S;

    int cnt = 0;
    int ans = 0;

    int l = 0, r = 0;
    cnt = S[0] == '0' ? 1 : 0;
    while(l < N && r < N) {
        if (cnt < K+1) {
            ans = max(ans, r - l + 1);
            ++r;
            if(S[r-1] == '1' && S[r] == '0') ++cnt;
        } else {
            ++l;
            if(S[l-1] == '0' && S[l] == '1') --cnt;
        }
    }
    
    cout << fixed << setprecision(20);
    cout << ans << endl;


}


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

int di[4] = {0, 1, 0, -1};
int dj[4] = {1, 0, -1, 0};


void dfs(int i, int j, vector<vector<bool> > &Map){

    Map[i][j] = false;
    for(int h = 0; h < 4; h++){
        int ni = i + di[h];
        int nj = j + dj[h];        
        if(Map[ni][nj]) dfs(ni, nj, Map);
    }
}

int solve(int n){

    vector<int> X;
    vector<int> Y;
    vector<int> l(n);
    vector<int> t(n);
    vector<int> r(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> l[i] >> t[i] >> r[i] >> b[i];
        l[i] *= 2 + 2;
        t[i] *= 2 + 2;
        r[i] *= 2 + 2;
        b[i] *= 2 + 2;        
        X.push_back(l[i]);
        X.push_back(r[i]);
        Y.push_back(t[i]);
        Y.push_back(b[i]);
        
        X.push_back(l[i] + 1);
        X.push_back(l[i] - 1);        
        X.push_back(r[i] + 1);
        X.push_back(r[i] - 1);        
        Y.push_back(t[i] + 1);
        Y.push_back(t[i] - 1);        
        Y.push_back(b[i] + 1);
        Y.push_back(b[i] - 1);
        
    }

    //座標の始点、終点を追加
    X.push_back(0);
    X.push_back(-1);
    X.push_back(-2);            
    Y.push_back(0);
    Y.push_back(-1);
    Y.push_back(-2);            
    X.push_back(10000000);
    Y.push_back(10000000);

    //定石
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    // X = {0, 1, 1, 4, 4, 6, 9, 9, 10, 10, 10, 10}
    // Y = {0, 1, 1, 4, 4, 5, 6, 8, 8, 10, 10, 10}


    X.erase(unique(X.begin(),X.end()),X.end());
    Y.erase(unique(Y.begin(),Y.end()),Y.end());
    // X = {0, 1, 4, 6, 9, 10}
    // Y = {0, 1, 4, 5, 6, 8, 10}        
    
    int h = lower_bound(Y.begin(),Y.end(),10000000) - Y.begin();
    int w = lower_bound(X.begin(),X.end(),10000000) - X.begin();
    
    vector<vector<bool> > Map(h + 2, vector<bool> (w + 2, true));
    for(int i = 0; i <= h + 1; i++){
        Map[i][0] = Map[i][w + 1] = false;
    }
    for(int j = 0; j <= w + 1; j++){
        Map[0][j] = Map[h + 1][j] = false;
    }

    for(int i = 0; i < n; i++){

        int _l = lower_bound(X.begin(),X.end(),l[i]) - X.begin();
        int _r = lower_bound(X.begin(),X.end(),r[i]) - X.begin();

        int _b = lower_bound(Y.begin(),Y.end(),b[i]) - Y.begin();
        int _t = lower_bound(Y.begin(),Y.end(),t[i]) - Y.begin();

        for(int i = _b; i <= _t; i++){
            Map[i][_l] = Map[i][_r] = false;
        }

        for(int j = _l; j <= _r; j++){
            Map[_t][j] = Map[_b][j] = false;
        }

    }

    int ans = 0;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(Map[i][j]){
                dfs(i, j, Map);
                ans++;
            }
            //cout << Map[i][j] << " ";
        }
        //cout << endl;
    }

    return ans;
}

int main(){

    while(1){
        int n; cin >> n;
        if(!n) break;

        cout << solve(n) << endl;
    }

    return 0;
}


Measured memory_bytes: 7316
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S,T;
  cin >> S >> T;
  bool ans = S == T.substr(0, T.length() - 1);
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		
		int Alice=0;
		int Bob=0;
		// 整数の入力
		int a = sc.nextInt();
		
		int[] card = new int[a];
		
		for(int number=0;number<card.length;number++){
			card[number] = sc.nextInt();
		}
		
		int max = 0;
		int max_number = 0;
		int next=0;
		int change=0;
		
		for(int number=0;number<card.length;number++){
			for(int number2=next;number2<card.length;number2++){
				if(max<card[number2]){
					max=card[number2];
					max_number=number2;
				}
			}
			
			change = card[next];
			card[next] = card[max_number];
			card[max_number] = change;
			
			if(next%2==0)
				Alice+=max;
			else
				Bob+=max;
			
			max=0;
			
			next++;
		}
		// 出力
            System.out.println(Alice-Bob);
	}
}


Measured memory_bytes: 21076
#!/usr/bin/env python3
import sys

MOD = 2019  # type: int

def solve(L: int, R: int):
    if R - L >= 2019:
        print(0)
        return
    L = L % 2019
    R = R % 2019
    if L >= R:
        print(0)
        return
    res = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            res = min(res, (i*j)%2019)
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(L, R)

if __name__ == '__main__':
    main()


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

typedef struct node_t {
	int key;
	struct node_t *parent;
	struct node_t *left;
	struct node_t *right;
} node;

node* newNode(int);
void print(node *);
void inorder(node *);
void preorder(node *);
void insert(int, node *);
node* find(int, node *);
int delete(int, node *);
void deleteNode(node *, node *);
void free_tree(node *);

int main(void)
{
	int i, m, k;
	char com[10];
	node *tree_root;
	
	tree_root = newNode(0);
	
	scanf("%d",&m);
	for (i=0; i<m; i++) {
		scanf("%s",com);
		if(com[0] == 'p') {
			print(tree_root->left);
		} else {
			scanf("%d",&k);
			if(com[0] == 'i') {
				insert(k, tree_root);
			} else if(com[0] == 'f') {
				if(find(k, tree_root) != NULL) {
					printf("yes\n");
				} else {
					printf("no\n");
				}
			} else if(com[0] == 'd') {
				if(delete(k, tree_root) == 0) printf("delete error!\n");
			}
		}
	}
	
	free_tree(tree_root);
	
	return 0;
}

node* newNode(int key)
{
	node *tmp;
	
	tmp = (node *)malloc(sizeof(node));
	if (tmp == NULL) exit(0);
	
	tmp->key = key;
	tmp->parent = NULL;
	tmp->left = NULL;
	tmp->right = NULL;
	
	return tmp;
}

void print(node *root)
{
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

void inorder(node *node)
{
	
	if(node->left != NULL) inorder(node->left);
	printf(" %d",node->key);
	if(node->right != NULL) inorder(node->right);
}

void preorder(node *node)
{
	printf(" %d",node->key);
	if(node->left != NULL) preorder(node->left);
	if(node->right != NULL) preorder(node->right);
}

void insert(int k, node *tree_root)
{
	node *x, *y, *z;
	
	z = newNode(k);
	y = tree_root;
	x = tree_root->left;
	while (x != NULL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if(y == tree_root || z->key < y->key) {
		y->left = z;
	} else {
		y->right = z;
	}
}

node* find(int k, node *tree_root) 
{
	node *x;
	
	x = tree_root->left;
	while (x->key != k) {
		if(x->key > k) {
			if(x->left == NULL) return NULL;
			x = x->left;
		} else {
			if(x->right == NULL) return NULL;
			x = x->right;
		}
	}
	return x;
}

int delete(int k, node *tree_root)
{
	node *x;
	
	x = find(k, tree_root);
	if(x==NULL) return 0;
	
	deleteNode(x, tree_root);
	return 1;
}

void deleteNode(node *x, node *tree_root)
{
	int isLeft;
	node *y;
	
	if(x == tree_root->left || x->key < x->parent->key) isLeft = 1;
	 else isLeft = 0;
	
	if(x->left==NULL && x->right==NULL) {
		if(isLeft) {
			x->parent->left = NULL;
		} else {
			x->parent->right = NULL;
		}
		free(x);
	} else if(x->right==NULL) {
		if(isLeft) {
			x->parent->left = x->left;
		} else {
			x->parent->right = x->left;
		}
		x->left->parent = x->parent;
		free(x);
	} else if(x->left==NULL) {
		if(isLeft) {
			x->parent->left = x->right;
		} else {
			x->parent->right = x->right;
		}
		x->right->parent = x->parent;
		free(x);
	} else {
		y = x->right;
		while(y->left!=NULL) {
			y = y->left;
		}
		x->key = y->key;
		deleteNode(y, tree_root);
	}
}

void free_tree(node *root)
{
	if(root->left != NULL) free_tree(root->left);
	if(root->right != NULL) free_tree(root->right);
	free(root);
}

Measured memory_bytes: 19364
package main

import (
	"fmt"
)

func main() {
	var S string
	var T string
	fmt.Scan(&S)
	fmt.Scan(&T)

	var r int
	for i:=0; i < len(S); i++ {
		if S[i] != T[i] {
			r += 1
		}
	}
	
	fmt.Println(r)
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  long long coc=0;
  long long conc=0;
  long long co=0;
  int f=1;
  long long con=0;
  int fn=-1;
  for(int i=0;i<n;i++){
    cin >> a[i];
    coc+=a[i];
    conc+=a[i];
    if(coc/f<=0){
      co+=fabs(f-coc);
      coc+=f-coc;
    }
    if(conc/fn<=0){
      con+=fabs(fn-conc);
      conc+=fn-conc;
    }
    // cout << coc <<" "<< conc << endl;
    swap(f,fn);
  }
  cout << min(co,con) << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
import numpy as np


def main():
    k = int(input())
    n = 50
    an = [n - 1 + (k // n) - (k % n) for _ in range(n)]
    for i in range(k % n):
        an[i] += n + 1
    print(n)
    print(*an)


main()


Measured memory_bytes: 12488
s=gets.chomp.split("")
t=gets.chomp.split("")

idx=Hash.new { |h, k| h[k] = [] }

s=s+s
s.each_with_index do |c,i|
  idx[c] << i
end
l = []
t.each do |c|
  if idx[c].size == 0
    puts -1
    exit
  end

  if l.size == 0
    prev = -1
  else
    prev = l[-1]
  end
  
  tmp = idx[c].bsearch {|x| x >  prev}
  if tmp == nil
    l << idx[c][0]
  else
    l << tmp
  end
end

prev=Float::INFINITY
cnt = 0
l.each do |v|
  if prev > v
    cnt += 1
  end
  prev = v
end
puts s.size * (cnt-1) + l[-1] + 1

Measured memory_bytes: 17020
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
int h,n;
int dp[1001];
int v[4000],cost[4000];
int ans = 1e-9;
/*
int go(int i,int sum){

        if(dp[i][sum]!=-1) return dp[i][sum];

       dp[i][sum] =min(val[i]+go(i+1,W-a[i]),go(i+1,W));
       return dp[i][sum];
}
*/
void go(int i,int x, int y ){

     ans = max(ans,x-y);
    if(i>n){
      return ;
    }
    go(i+1,v[i]+x,cost[i]+y);
    go(i+1,x,y);
    return;
}
 int main()
{
   // fast;

    int n;
    cin >> n;
    int a[n+10];
    for(int i = 1; i<=n; i++) cin >> a[i];
    int ans = 0,mx = 0;
    for(int i = 1; i<=n; i++){
        mx = max(a[i],mx);
        if(mx >a[i])continue;
         ans++;
    }
    cout << ans << '\n';

   return 0;
}


Measured memory_bytes: 256
n = int(input())
vals = map(int, input().split(" "))
cur_vals = [-1, -1, -1]

M = 1000000007
out = 1
for val in vals:
    before_val = val-1
    before_val_num = sum([1 for cur_val in cur_vals if cur_val == before_val])
    if before_val_num == 0:
        out = 0
        break
    out = (out * before_val_num) % M
    tar_i = cur_vals.index(before_val)
    cur_vals[tar_i] = val

print(out)

Measured memory_bytes: 10644
S = input()
s = S.count("S")
w = S.count("W")
e = S.count("E")
n = S.count("N")

if s == 0 and n > 0:
    print("No")
elif n == 0 and s > 0:
    print("No")
elif e == 0 and w > 0:
    print("No")
elif w == 0 and e > 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
from copy import deepcopy
inf=float('inf')
def main():
    N = int(input())
    *A, = map(int,input().split())
    Q = int(input())
    *B, = map(int,input().split())

    bit_max = 1<<N
    S = set()
    for bit in range(bit_max):
        sum_ = 0
        for i in range(N):
            if(bit & (1<<i)):
                sum_ += A[i]
        S.add(sum_)
    

    """S = set([0])
    for a in A:
        for s in deepcopy(S):
            S.add(a+s)
    """
    for q in B:
        if q in S:
            print("yes")
        else:
            print("no")

    
if __name__ == '__main__':
    main()



Measured memory_bytes: 6356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		double pi = Math.PI;
		double area = r * r * pi;
		double length = 2 * r * pi;
		System.out.printf("%f %f", area, length);
	}
}

Measured memory_bytes: 28100
#include<iostream>
#include<map>

using namespace std;
int main()
{
    int num;
    cin >> num;
  
  	int max=0;
  	map<string, int> texts;
  	for (int i=0; i<num; i++) {
      string tmp;
      cin >> tmp;
      texts[tmp]++;
      if (texts[tmp]>max) {
        max = texts[tmp];
      }
    }
 
  	
  	for (auto iter=texts.begin(); iter!=texts.end(); iter++) {
		if (iter->second==max) {
			cout << iter->first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

struct Point
{
    int x, y;
};

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

    int h, w;
    cin >> h >> w;
    vector< string > field(h);
    rep (i, h) cin >> field[i];

    queue< Point > q;
    vector< vs32 > d(h, vs32(w, 1e9));
    rep (i, h)
    {
        rep (j, w)
        {
            if (field[i][j] == '#')
            {
                q.push(Point{.x = j, .y = i});
                d[i][j] = 0;
            }
        }
    }

    int ans = 0;
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    while (!q.empty())
    {
        Point p = q.front(); q.pop();
        int y = p.y;
        int x = p.x;
        bool found = false;
        rep (i, 4)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (IN(0, h, ny) && IN(0, w, nx) && field[ny][nx] != '#' && d[ny][nx] > d[y][x] + 1)
            {
                q.push(Point{.x = nx, .y = ny});
                d[ny][nx] = d[y][x] + 1;
                ans = MAX(ans, d[ny][nx]);
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 13456
#include <stdio.h>

int main(){
    int n;
    int in;
    int sum=0;
    int i;

    scanf("%d", &n);

    for(i =0; i<n;i++){
        scanf("%d", &in);
        sum += in;
    }

    if(sum % 2 == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	int a, b;
	cin >> a >> b;
	printf("%.9f\n", a / 3.305785 * b);
	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x, s;
    
    while(scanf("%d %d", &n, &x), n > 0){
        s = 0;
        
        for(i = 1; i <= n; ++i){
            for(j = i + 1; j <= n; ++j){
                for(k = j + 1; k <= n; ++k){
                    if(i + j + k == x){
                        ++s;
                    }
                }
            }
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}


Measured memory_bytes: 2688
function main()
    n = parse(Int64, readline())
    ary = map(x -> parse(Int64, x), split(readline()))

    flag = false
    res = 0
    for ans in 0:100000000
        #println(ans, ary)
        i = 1
        for elem in ary
            if elem % 2 == 0
                ary[i] = ceil(elem / 2)
            else
                flag = true
                break
            end
            i = i + 1
        end
        if flag
            res = ans
            break
        end
    end
    println(res)
end

main()


Measured memory_bytes: 166160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n,m;
int M=2019;

int main()
{
    cin>>n>>m;
    int ans=M;
    for (ll i=n; i<=min(m,n+2019); ++i)
        for (ll j=i+1; j<=min(m,n+2019); ++j)
        {
            ll tmp=(i*j)%M;
            if (tmp<ans)
            {
                ans=tmp;
            }
        }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

flag=True # Ai<0なるiの個数が偶数か
for i in range(N):
    if A[i]<0:
        flag=not flag

S=sum([abs(Ai) for Ai in A])
m=min([abs(Ai) for Ai in A])

if flag:
    print(S)
else:
    print(S-2*m)

Measured memory_bytes: 14412
import numpy as np
import math
import collections
import fractions
import itertools

def rec(d, val, all):
    all.append(val)
    if d >= 10:
        return
    for j in range(-1, 2):
        add = val % 10 + j
        if add >= 0 and add <= 9:
            rec(d+1, val*10+add, all)

def solve():
    k = int(input())
    all = []
    for i in range(1,10):
        rec(1, i, all)
    all.sort()
    print(all[k-1])
    return 0

if __name__ == "__main__":
    solve()


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

using namespace std;

int main() {
	int W, a, b;
	scanf("%d %d %d", &W, &a, &b);
	if (a > b) {
		int aux = b;
		b = a;
		a = aux;
	}
	int aux = b - (a + W);
	if (aux < 0) aux = 0;
	printf("%d\n", aux); 
}

Measured memory_bytes: 256
import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

import javax.naming.InitialContext;
 
public class Main {
     
	static int W, H;
	static char[][] matrix;
	static String[][] dp;
	
	// a < bならTrue
	static Boolean cmp(String a, String b)
	{
		if(a.length() < b.length()) 
			return true;
		else if(a.length() > b.length())
			return false;
		
		for(int i = 0;i < a.length();i++)
		{
			if(a.charAt(i) - b.charAt(i) < 0)
				return true;
			else if(a.charAt(i) - b.charAt(i) > 0)
				return false;
		}
		
		return true;
	}
	
	// a < bならTrue
	// 最初にゼロ刈りする
		static Boolean cmp2(String a, String b)
		{
			int a0num = 0, b0num = 0;
			for(int i = 0;i < a.length();i++)
			{
				if(a.charAt(i) - '0' == 0)
					a0num++;
				else {
					break;
				}
			}
			for(int i = 0;i < b.length();i++)
			{
				if(b.charAt(i) - '0' == 0)
					b0num++;
				else {
					break;
				}
			}
			
			return cmp(a.substring(a0num), b.substring(b0num));
		}
	
	static String calc(int x, int y)
	{
		String a, b;
		if('A' <= matrix[y][x] && matrix[y][x] <= 'Z') return "";
		
		a = matrix[y][x] + dp[y][x + 1];
		b = matrix[y][x] + dp[y + 1][x];

		if(cmp(a, b))
			return b;
		else {
			return a;
		}
	}
    
    static void start()
    {
    	dp = new String[H+1][W+1];
    	
    	dp[H][W] = "";
    	for (int x = W-1; x >= 0; x--) dp[H][x] = "";
    	for (int y = H-1; y >= 0; y--) dp[y][W] = "";
    	
    	int sx = W - 1;
    	int sy = H - 1;
    	
    	while(true)
    	{
    		dp[sy][sx] = calc(sx, sy);
    		
    		for (int x = sx - 1; x >= 0; x--) dp[sy][x] = calc(x, sy);
        	for (int y = sy - 1; y >= 0; y--) dp[y][sx] = calc(sx, y);
        	
        	if(sx == 0 || sy == 0) break;
        	
        	sx--;
        	sy--;
    	}
    	
    	String max = "";
    	for (int y = 0; y < H; y++) {
    		for (int x = 0; x < W; x++) {
    			if(cmp2(max, dp[y][x])) max = dp[y][x];
    			
    			//System.out.println(dp[y][x]);
			}
		}
    	
    	//System.out.println("----------------------------------------");
    	System.out.println(max);
    	//System.out.println("----------------------------------------");
    }
     
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        
        while(true)
        {
        	W = sca.nextInt();
        	H = sca.nextInt();
        	if(W == 0) break;
        	
        	matrix = new char[H][W];
        	for (int y = 0; y < H; y++) {
        		String str = sca.next();
        		
				for (int x = 0; x < W; x++) {
					matrix[y][x] = str.charAt(x);
				}
			}
            
            start();
        }
        
    }
}

Measured memory_bytes: 80992
#include <stdio.h>

int main(void)
{
	int i,j,n;
	char suit;
	int num;
	int a[4][13];

	scanf("%d", &n);

	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 13; j++)
		{
			a[i][j] = 0;
		}
	}

	for(i = 0; i < n; i++)
	{
		scanf("%s %d", &suit,&num);
		if (suit == 'S')
		{
			a[0][num - 1] = 1;
		}
		if (suit == 'H')
		{
			a[1][num - 1] = 1;
		}
		if (suit == 'C')
		{
			a[2][num - 1] = 1;
		}
		if (suit == 'D')
		{
			a[3][num - 1] = 1;
		}
	}

	for(i = 0; i < 4; i++)
	{
		for (j = 0; j < 13; j++)
		{
			if (i == 0 && a[i][j] == 0)
			{
				printf("S %d\n", j + 1);
			}
			if (i == 1 && a[i][j] == 0)
			{
				printf("H %d\n", j + 1);
			}
			if (i == 2 && a[i][j] == 0)
			{
				printf("C %d\n", j + 1);
			}
			if (i == 3 && a[i][j] == 0)
			{
				printf("D %d\n", j + 1);
			}
		}
	}

	return 0;


}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

namespace math { namespace integer {

template<class value_type> value_type mod_mul(value_type x, value_type k, value_type m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
template<class value_type> value_type mod_pow(value_type x, value_type n, value_type mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class value_type> value_type extgcd(value_type a, value_type b, value_type& x, value_type& y) { value_type d = a; if(b != 0) { d = extgcd(b, a%b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class value_type> value_type mod_inverse(value_type x, value_type mod) { return mod_pow(x, mod-2, mod); /* use fermat */ }
template<class value_type> value_type mod_inverse_unusual_mod(value_type a, value_type mod) { value_type x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}


int main() {

  int a, b; cin >> a >> b;
  int x, y; math::integer::extgcd(a, b, x, y);
  cout << x << " " << y << endl;

  return 0;
}

Measured memory_bytes: 3116
import itertools

N = int(input())
MOD = 10**9 + 7
ACGT = ["A","C","G","T"]
dp = [ [ [ [0 for l in range(4) ] for k in range(4)] for j in range(4)] for i in range(N+1)]
dp[0][-1][-1][-1] = 1

for i,p,q,r,s in itertools.product(range(N),range(4),range(4),range(4),range(4)):
  if ACGT[q] + ACGT[r] + ACGT[s] not in {'AGC', 'GAC', 'ACG'} \
  and ACGT[p] + ACGT[r] + ACGT[s] != 'AGC' \
  and ACGT[p] + ACGT[q] + ACGT[s] != 'AGC':
    dp[i + 1][q][r][s] += dp[i][p][q][r]
    dp[i + 1][q][r][s] %= MOD   
print(sum(sum(sum(y) for y in x) for x in dp[N]) % MOD)


Measured memory_bytes: 40688
#include<bits/stdc++.h>
using namespace std;
int main(){
	cout << fixed << setprecision(12);
	double r;
	cin >> r;
	double PI = acos(-1);
	
	double area = r*r*PI;
	double cir = (r+r)*PI;

	cout << area << " " << cir << endl;

	return 0;
}


Measured memory_bytes: 3284
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int f[] = new int[N +1];
		for(int x = 1 ; x <= 100 ; ++x){
			for(int y = 1 ; y <= 100 ; ++y){
				for(int z = 1 ; z <= 100 ; ++z){
					int n = x * x + y * y + z * z + x * y + y * z + z * x;
					if(n < f.length){
						f[n]++;
					}
				}	
			}			
		}
		for(int i = 1 ; i <= N ; ++i){
			System.out.println(f[i]);
		}
	}
}

Measured memory_bytes: 38752