akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        List<Integer> x = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            x.add(Integer.parseInt(sc.next()));
        }
        sc.close();

        // 主処理
        List<Integer> minusList = x.stream().filter(i -> i < 0).collect(Collectors.toList());
        List<Integer> plusList = x.stream().filter(i -> 0 < i).collect(Collectors.toList());

        List<Integer> leftDoubleList = new ArrayList<>();
        leftDoubleList.addAll(minusList.stream().map(i -> i * 2).collect(Collectors.toList()));
        leftDoubleList.add(0);
        leftDoubleList.addAll(plusList);

        List<Integer> rightDoubleList = new ArrayList<>();
        rightDoubleList.addAll(minusList);
        rightDoubleList.add(0);
        rightDoubleList.addAll(plusList.stream().map(i -> i * 2).collect(Collectors.toList()));

        if (!x.contains(0)) {
            k++;
        }

        int firstIndex = Math.max(0, minusList.size() - k + 1);
        int lastIndex = Math.min(leftDoubleList.size() - k, minusList.size());

        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int i = firstIndex; i <= lastIndex; i++) {
            pq.add(rightDoubleList.get(i + k - 1) - rightDoubleList.get(i));
            pq.add(leftDoubleList.get(i + k - 1) - leftDoubleList.get(i));
        }
        int result = pq.peek();

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 64416
"use strict"

function main(input) {
  input = input.split("\n").map(v => v.split(/\s/).map(v => ~~v))
  const k = input[0][1]
  const minus = [0]
  const plus = [0]
  for (let i in input[1]) {
    if (input[1][i] >= 0) {
      plus.push(input[1][i])
    } else {
      minus.push(Math.abs(input[1][i]))
    }
  }
  minus.sort((a, b) => a - b)

  let ans
  if (plus.length >= k && minus.length <= 1) {
    ans = plus[k]
  } else if (minus.length >= k && plus.length <= 1) {
    ans = minus[k]
  } else if (minus.length > 1 && plus.length > 1) {
    //左右の組み合わせチェックで一番コスト低いもの

    for (let i = 1; i <= k; i++) {
      if (minus.length > i && plus.length > k - i) {
        let a = minus[i] ? minus[i] : 0

        let b = plus[k - i] ? plus[k - i] : 0

        //もどり道のコスト
        let c = minus[i] > plus[k - i] ? plus[k - i] : minus[i]

        let tmp = a + b + c

        ans = ans ? Math.min(ans, tmp) : tmp

        // console.log(ans, i, k - i, a, b, c)
      }

      // console.log(ans)
    }
  }
  console.log(ans)

  // console.log(minus, plus)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main() {
    int n;
    scanf("%d", &n);
    int64_t a, b;
    scanf("%lld%lld", &a, &b);

    vector<int64_t> s(n + 2);
    constexpr int64_t kInf = 1'000'000'000'000'000'000;
    s[0] = s[1] = -kInf;
    for (int i = 2; i < n + 2; ++i) scanf("%lld", &s[i]);

    constexpr int kMod = 1'000'000'000 + 7;
    vector<vector<int>> dp(2, vector<int>(n + 2));
    vector<vector<int>> tree((n + 2) * 4, vector<int>(2, 0));
    vector<vector<bool>> tag((n + 2) * 4, vector<bool>(2, false));

    auto Push = [&](int o, int p) {
        if (!tag[o][p]) return;
        for (int v = 1; v <= 2; ++v) {
            tree[o * 2 + v][p] = 0;
            tag[o * 2 + v][p] = true;
        }
        tag[o][p] = false;
    };

    auto Query = [&](auto self, int l, int r, int ql, int qr, int p, int o = 0) {
        if (l >= qr || ql >= r) return 0;
        if (l >= ql && r <= qr) return tree[o][p];
        Push(o, p);
        int m = (l + r) >> 1;
        return (self(self, l, m, ql, qr, p, o * 2 + 1) + self(self, m, r, ql, qr, p, o * 2 + 2)) % kMod;
    };

    auto Modify = [&](auto self, int l, int r, int x, int v, int p, int o = 0) {
        if (r - l == 1) {
            tree[o][p] += v;
            if (tree[o][p] >= kMod) tree[o][p] -= kMod;
            return;
        }
        Push(o, p);
        int m = (l + r) >> 1;
        if (x < m) self(self, l, m, x, v, p, o * 2 + 1);
        else self(self, m, r, x, v, p, o * 2 + 2);
        tree[o][p] = (tree[o * 2 + 1][p] + tree[o * 2 + 2][p]) % kMod;
    };

    auto Reset = [&](int p) {
        tree[0][p] = 0;
        tag[0][p] = true;
    };

    Modify(Modify, 0, n + 2, 0, 1, 0);
    dp[0][0] = 1;
    for (int i = 2, j = 0, k = 0; i < n + 2; ++i) {
        while (j + 1 < i && s[i] - s[j + 1] >= a) j++;
        while (k + 1 < i && s[i] - s[k + 1] >= b) k++;
        int x = Query(Query, 0, n + 2, 0, k + 1, 0);
        int y = Query(Query, 0, n + 2, 0, j + 1, 1);
        // printf("j = %d k = %d x = %d y = %d\n", j, k, x, y);
        if (s[i] - s[i - 1] < a) Reset(0);
        if (s[i] - s[i - 1] < b) Reset(1);
        Modify(Modify, 0, n + 2, i - 1, x, 1);
        Modify(Modify, 0, n + 2, i - 1, y, 0);
        // vector<vector<int>> nxt(2, vector<int>(n + 2));
        // if (s[i] - s[i - 1] >= a) {
            // for (int j = 0; j < n + 2; ++j) (nxt[0][j] += dp[0][j]) %= kMod;
        // }
        // if (s[i] - s[i - 1] >= b) {
            // for (int j = 0; j < n + 2; ++j) (nxt[1][j] += dp[1][j]) %= kMod;
        // }
        // for (int j = 0; j < n + 2; ++j) {
            // if (s[i] - s[j] >= b) (nxt[1][i - 1] += dp[0][j]) %= kMod;
            // if (s[i] - s[j] >= a) (nxt[0][i - 1] += dp[1][j]) %= kMod;
        // }
        // dp = nxt;
        // for (int j = 0; j < n + 2; ++j) {
            // printf("dp[0][%d][%d] = %d\n", i, j, Query(Query, 0, n + 2, j, j + 1, 0));
            // printf("dp[1][%d][%d] = %d\n", i, j, Query(Query, 0, n + 2, j, j + 1, 1));
        // }
    }
    int ans = (Query(Query, 0, n + 2, 0, n + 2, 0) + Query(Query, 0, n + 2, 0, n + 2, 1)) % kMod;
    printf("%d\n", ans);
    return 0;
}


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

int main()
{
   int len;
  string s;
  cin>>len;
  cin>>s;
 
  
  if(len%2!=0)
  {
    cout<<"No";
    return 0;
  }
    
  int flag=1;
  for(int i=0;i<int(len/2);i++)
  {
    if(s[i]!=s[(len/2)+i])
    {
      flag=0;
      break;
    }
  }
  if(flag==1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

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

using namespace std;

typedef long long ll;

int n;
double arr[52];
double ans;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) cin >> arr[i];
    sort(arr+1, arr+n+1);
    ans = arr[1];
    for(int i=2; i<=n; i++) ans = (ans + arr[i]) / 2;
    printf("%.8f", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

const ll M = 5070721LL;
const ll L = 14LL;

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  REP(i, strlen(str)){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
    const ll key = getKey(str);
    const ll h1val = h1(key);
    const ll h2val = h2(key);
    for(ll i = 0; ; ++i){
        const ll j = (h1val + i * h2val) % M;
        if(strlen(H[j]) == 0){
            return 0;
        }else if(strcmp(H[j], str) == 0){
            return 1;
        }
    }
}

int insert(char str[]){
    const ll key = getKey(str);
    const ll h1val = h1(key);
    const ll h2val = h2(key);
    for(ll i = 0; ; ++i){
        const ll j = (h1val + i * h2val) % M;
        if(strlen(H[j]) == 0){
            strcpy(H[j], str);
            return 0;
        }else if(strcmp(H[j], str) == 0){
            return 1;
        }
    }
    return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
        scanf("%s %s", com, str);
        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if (find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 72492
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (i+1LL - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1LL;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0; j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0] - lost + c[0] * (i + 1 - last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j] - lost + c[j] * (i + 1 - last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 60000)
    {
        ll tmpD = (ll)rand() % d;
        ll tmpN = ans[tmpD];
        ans[tmpD] = (ll)rand() % 26 + 1;

        if (score >= scorecalc(s, c, d, ans))
            ans[tmpD] = tmpN;
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b;cin>>a>>b;
    cout<<(a+b)%24<<endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100005,INF=1<<28;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> A(N);
        for(int i=0;i<N;i++) cin>>A[i];
        sort(all(A));
        
        int ans=INF;
        
        for(int i=1;i<N;i++) ans=min(ans,A[i]-A[i-1]);
        
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3144
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	int a, b, c;
	int i, j;

	while (scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		bool busy[11];
		for (i = 0; i <= 10; ++i)
			busy[i] = false;

		busy[a] = true;
		busy[b] = true;
		busy[c] = true;

		int count = 0;
		for (i = 1; i <= 10; ++i)
		{
			if (!busy[i])
			{
				busy[i] = true;
				for (j = 1; j <= 10; ++j)
				{
					if (!busy[j])
					{
						if (a + b + j <= 20)
							count++;
						else
							continue;
					}
				}

				busy[i] = false;
			}
		}

		if ((count * 100) / 42  >= 50)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	bool used[100]={};
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			int a;
			cin>>a;
			a--;
			used[a]=1;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(!used[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;
  string S; cin >> S;
  rep(i,S.size()) cout << (S[i]+N>'Z' ? (char)(S[i]+N-26) : (char)(S[i]+N));
  cout << endl;
  
  return 0;
}

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<vector<int>> s(w, vector<int>(h));
    rep(i,n) {
        int a, x, y;
        cin >> x >> y >> a;
        if(a==1) rep(nh,h) rep(nw,x) s[nw][nh]=1;
        if(a==2) rep(nh,h) for(int nw = x; nw < w; ++nw) s[nw][nh]=1;
        if(a==3) rep(nw,w) rep(nh,y) s[nw][nh]=1;
        if(a==4) rep(nw,w) for(int nh = y; nh < h; ++nh) s[nw][nh]=1;
        
    }
    int cnt = 0;
    rep(i,w)rep(j,h) if(s[i][j]==1) cnt++;
    cout << w*h-cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
/*BINH :))*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL cout<<endl
#define max 1005
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
void init(){
}
int main(){
    IO
    init();
    string s;
    cin>>s;
    int a=0,b=0;
    FOR(i,0,2)if(s[i]=='A')a++;else b++;
    if(a!=0&&b!=0)cout<<"Yes";else cout<<"No";
}



Measured memory_bytes: 256
import math

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

V = a**2*b

if x > V/2:
  Va = V - x
  res = 2*Va/(a**2)
  deg = math.atan(res/a)

else:
  Va = x
  res = 2*Va/(a*b)
  deg = math.atan(b/res)

deg = math.degrees(deg)

print(deg)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>

using namespace std;
int main(){
  long long n;
  cin >> n;

  vector<vector<int>> cnt(n, vector<int>(26, 0));
  vector<string> s(n);

  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < s[i].size(); j++){
      cnt[i][s[i][j] - 'a']++;
    }
  }
  
//  for(int i = 0; i < n; i++){
//    for(int j = 0; j < 26; j++){
//      cout << cnt[i][j] << " ";
//    }
//    cout << endl;
//  }
//  cout << endl;
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 26; j++){
      cnt[0][j] = min(cnt[0][j], cnt[i][j]);
    }
  }

//  for(int i = 0; i < n; i++){
//    for(int j = 0; j < 26; j++){
//      cout << cnt[i][j] << " ";
//    }
//    cout << endl;
//  }
//  cout << endl;

  
  for(int i = 0; i < 26; i++){
    for(int j = 0; j < cnt[0][i]; j++){
      cout << (char)(i+'a');
    }
  }
  cout << endl;

  return 0;
} 


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        a: [u8;n],
    }
    let mut c=0;
    for (i,a) in a.into_iter().enumerate() {
        if i&1==0 && a&1==1 {
            c+=1;
        }
    }
    println!("{}",c);
}

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

#define ll long long int
#define li int64_t
#define m 1000000007

int main()
{
	int n;
	cin>>n;
	li a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}	
	li prefixsum[n];
	prefixsum[0] = a[0];
	for(int i=1;i<n;i++)
	{
		prefixsum[i] = prefixsum[i-1]+a[i];
	}
	li sum =0;
	for(int i=0;i<n-1;i++)
	{
		sum+= (a[i]) * ((prefixsum[n-1]-prefixsum[i]) % m);
		sum = sum % m;
	}
	cout<<sum % m ;

}

Measured memory_bytes: 6700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    int N; cin >> N;
    int A=0,B=0,C=0;
    int S,T; cin >> S >> T;
    int D[N];
    rep(i,N) cin >> D[i];
    rep(i,N){
        if(D[i]<=S){
            A++;
        } else if(D[i]<=T){
            B++;
        } else {
            C++;
        }
    }
    cout << min({A,B,C}) << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#define MOD1 1000000007

inline void inp( long long int  &n ){n=0;int ch=getchar();int sign=1;while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getchar();}while( ch >= '0' && ch <= '9' )n = (n<<3)+(n<<1) + ch-'0', ch=getchar();n=n*sign;}
#define pi acos(-1)
#define iil pair<int,int>
#define vii vector<ii>
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define ll  long long int
#define LL long long int
#define loop2(i,n) for(ll i=1;i<=n;i++)
#define MIN(a,b) (a) < (b) ? (a) : (b)
#define MAX(a,b) (a) > (b) ? (a) : (b)
#define ABS(a) (a) > 0 ? (a) : -(a)
#define rep1(i,a,n) for(i=a;i<(n);i++)
#define pii pair< ll, ll >
#define pb push_back
#define mp make_pair
#define all(x)                  (x).begin(),(x).end()
#define OUT_RT cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define EPS 1e-7
using namespace std;
//find the holy grail in an  adventure frought with danger
//The bigger the occasion, the better the response.
// Never giving in, fighting to the end
// Look at  the limits ; Check if it is binary search
//Code till the end of contest
const int MAXN =(ll)1e6+10;


ll d,k,a,b,t;
ll f(ll x)
{
    ll curr = d;
    curr-=(k*x);
    curr = max(curr,0LL);
    ll ret = min(k*x,d)*a;
    ret+=max(0LL, (x-1)*t);
    ret+=curr*b;
    return ret;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    if(a<=0&&b>=0){
        cout<<"Zero";
        return 0;
    }
    if(a==0||b==0)
    {
        cout<<"Zero";
        return 0;
    }
    if(a<0&&b<0){
        ll countofneg = b-a+1;
        if(countofneg%2!=0){
            cout<<"Negative";
        }
        else{
            cout<<"Positive";
        }
        return 0;
    }
    if(a>0&&b>0){
        cout<<"Positive";
        return 0;
    }
    return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    ans += A - 1;
    if (A <= B) ans++;
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
function main()
	dp=zeros(Int,100001)
	for i=2:100001
		dp[i]=dp[i-1]+1
		for j=1:10
			if i>6^j
				dp[i]=min(dp[i],dp[i-6^j]+1)
			end
			if i>9^j
				dp[i]=min(dp[i],dp[i-9^j]+1)
			end
		end
	end
	println(dp[parse(Int,readline())+1])
end
main()


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

int main(){

    int a,b,c;

    cin >> a >> b >> c;

    ll ans=b;

    if(a+b>=c){
        ans+=c;
    }else{
        ans+=(a+b)+1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000
int un,vn;
vector<int> g[maxn];
int llink[maxn];
bool v[maxn];
int dfs(int x)
{
    int i;
    for(i=0;i<g[x].size();i++)
    {
        if(!v[g[x][i]])
        {
            v[g[x][i]]=1;
            if(llink[g[x][i]]==-1||dfs(llink[g[x][i]]))
            {
                llink[g[x][i]]=x;
                return 1;
            }
        }
    }
    return 0;
}

int hungary(){
    int res=0;
    memset(llink,-1,sizeof(llink));
    for(int u=1;u<=un;u++){
        memset(v,0,sizeof(v));
        if(dfs(u))res++;
    }
    return res;
}

int main(){
    int n;cin>>n;
    int a[200],b[200],c[200],d[200];
    for(int i=1;i<=n;i++){
        scanf("%d%d",a+i,b+i);
    }
    un=vn=n;
    for(int i=1;i<=n;i++){
        scanf("%d%d",c+i,d+i);
        for(int j=1;j<=n;j++){
            if(a[j]<c[i]&&b[j]<d[i]){
                g[i].push_back(j);
            }
        }
    }
    printf("%d",hungary());
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    int N, C; cin >> N >> C;
    vector<vector<int>> imos(35, vector<int>(100005, 0));
    rep(i, 0, N){
        int s, t, c; cin >> s >> t >> c;
        imos[c][s]++; imos[c][t+1]--;
    }
    rep(c, 1, C+1){
        rep(i, 1, 100005) imos[c][i] += imos[c][i-1];
    }

    int ans=0;
    rep(i, 1, 100005){
        int cnt=0;
        rep(c, 1, C+1) if(imos[c][i]!=0) ++cnt;
        chmax(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int cnt = 0;
	while (b <= a) b *= 2, cnt++;
	while (c <= b) c *= 2, cnt++;
	cout << (cnt > k ? "No" : "Yes") << endl;
	return 0;
}



Measured memory_bytes: 3648
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

template<typename T, typename U>
class SegmentTree{
    int n;
    vector<T> node;

    using F = function<T(T, T)>;
    using G = function<T(T, U)>;

    F f;
    G g;
    T en;

public:
    SegmentTree(int n_, F f_, G g_, T en_){
        init(n_, f_, g_, en_);
    }

    SegmentTree(const vector<T>& dat, F f_, G g_, T en_){
        build(dat, f_, g_, en_);
    }

    void init(int n_, F f_, G g_, T en_){
        n = 1;
        while(n < n_){
            n <<= 1;
        }
        f = f_;
        g = g_;
        en = en_;

        node.resize(n << 1);
        fill(node.begin(), node.end(), en);

        return;
    }

    void build(const vector<T>& dat, F f_, G g_, T en_){
        int n_ = (int)dat.size();

        init(n_, f_, g_, en_);

        for(int i = 0 ; i < n_ ; ++i){
            node[i + n] = dat[i];
        }

        for(int i = n - 1 ; 0 < i ; --i){
            node[i] = f(node[i << 1], node[(i << 1) | 1]);
        }

        return;
    }

    void update(int k, U x){
        k += n;
        node[k] = g(node[k], x);

        while(k >>= 1){
            node[k] = f(node[k << 1], node[(k << 1) | 1]);
        }

        return;
    }

    T get(int l, int r){
        l += n;
        r += n;

        T res = en;
        while(l < r){
            if(l & 1){
                res = f(res, node[l++]);
            }
            l >>= 1;
            if(r & 1){
                res = f(res, node[--r]);
            }
            r >>= 1;
        }

        return res;
    }
};

#include<iostream>
#include<climits>
using namespace std;

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

    int n, q, com, x, y;
    cin >> n >> q;

    SegmentTree<int, int> seg(n, [](int l, int r){ return min(l, r); }, [](int l, int r){ return r; }, INT_MAX);

    while(q--){
        cin >> com >> x >> y;
        if(com == 0){
            seg.update(x, y);
        }else if(com == 1){
            cout << seg.get(x, y + 1) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3704
def sieve(n):
    '''

    :param n:
    :return: n以下の素数のリストを返す
    '''
    prime = []
    is_prime = [True] * (n + 1) #is_prime[i] = Trueならiは素数
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
    return is_prime

import bisect
Q = int(input())
queries = [list(map(int, input().split())) for _ in range(Q)]
primehantei = sieve(10 ** 5)
like2017 = []
for i in range(10 ** 5):
    if primehantei[i] == True and primehantei[ (i + 1) // 2] == True:
        like2017.append(i)

for i in range(Q):
    li, ri = queries[i]
    print(bisect.bisect_right(like2017, ri) - bisect.bisect_right(like2017, li - 1))

Measured memory_bytes: 29180
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new Main().run();
    }

    void solve() {
        int str = in.nextInt();
        int[] input = new int[4];
        int j = 10;
        for (int i = 3; i >= 0; i--) {
            input[i] = str % j;
            str = str / j;
        }
        String[] opers = new String[]{"+", "-"};
        String result = "";
        out:
        for (int i = 0; i < 2; i++) {
            for (int k = 0; k < 2; k++) {
                for (int l = 0; l < 2; l++) {
                    int num = input[0];
                    if (i == 0) {
                        num += input[1];
                    } else {
                        num -= input[1];
                    }
                    if (k == 0) {
                        num += input[2];
                    } else {
                        num -= input[2];
                    }
                    if (l == 0) {
                        num += input[3];
                    } else {
                        num -= input[3];
                    }
                    if (num == 7) {
                        result = input[0] + opers[i] + input[1] + opers[k] + input[2] + opers[l] + input[3] + "=7";
                    }
                }
            }
        }
        System.out.println(result);

    }


    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  int P[N]; int Q[N];
  FOR(i,0,N) cin >> P[i];
  FOR(i,0,N) cin >> Q[i];
  
  
  iota(v.begin(), v.end(), 1);
  int count1 = 1;
  int Pcount;
  do{
    bool flag1 = true;
    FOR(i,0,N) {
      if (v[i] != P[i]) flag1 = false;
    }
    if(flag1) Pcount = count1;
    count1++;
  }while(next_permutation(v.begin(), v.end()));

  iota(v.begin(), v.end(), 1);
  int count2 = 1;
  int Qcount;
  do{
    bool flag2 = true;
    FOR(i,0,N) {
      if (v[i] != Q[i]) flag2 = false;
    }
    if(flag2) Qcount = count2;
    count2++;
  }while(next_permutation(v.begin(), v.end()));  
  
  cout << abs(Pcount - Qcount) << endl;
  
  return 0;
}

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

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

const int MAXN = 1e5;
const ll MOD = 1e9+7;

int n;
vector<int> adj[MAXN+10];

bool vis[MAXN+10];
ll dp1[MAXN+10], dp2[MAXN+10];

void dfs(int now)
{
    vis[now]=true;
    dp1[now]=dp2[now]=1;
    for(int nxt : adj[now])
    {
        if(vis[nxt]) continue;
        dfs(nxt);

        dp1[now]=dp1[now]*dp2[nxt]%MOD;
        dp2[now]=dp2[now]*(dp2[nxt]+dp1[nxt])%MOD;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d", &n);
    for(i=1; i<n; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1);
    printf("%lld", (dp1[1]+dp2[1])%MOD);

    return 0;
}


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

int in;

int dfs(int num) {
  if (num == in) return 1;
  else if(num > in) return 0;
  return dfs(num+1) + dfs(num+2) + dfs(num+3);
}

int main() {
  while(1) {
    cin >> in;
    if (in == 0) break;
    int out = dfs(0);
    cout << out / 10 / 365 + 1 << endl;
  }
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int ar[n];
  for(int i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(ar[1]-ar[0]);
  int temp;
  for(int i=2;i<n;i++)
  {
    temp=INT_MAX;
    int j;
    if(i-k<0)
      j=0;
    else
      j=i-k;
    for(;j<i;j++)
    {
      temp=min(temp,dp[j]+abs(ar[i]-ar[j]));
    }
    dp[i]=temp;
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max 100


float kyori(float sta,int jikan,int ma,int end,float next[]){
    if(sta + jikan <=end){
        next[0]=sta + jikan;
        return (2 * sta + jikan) * jikan /float(2);
    }
    next[0]=end;
    if(ma - sta + ma - end <= jikan) return ma * jikan - (ma - sta) * (ma -sta) /float(2) - (ma - end) * (ma - end )/float(2);
    float tim;
    tim=(end - sta + jikan )/float(2);
    return tim / float(2) * (sta + sta + tim) + (sta + tim + end) *(jikan - tim) / float(2); 
}

int main(){
    int n;
    cin >> n;
    int t[n_max+5];
    int v[n_max+5];
    REP(i,n) cin >> t[i];
    REP(i,n) cin >> v[i];
    int A[n_max+5];
    A[n-1]=0;
    REPR(i,n-2){
        A[i] = min( v[i+1] , A[i+1] + t[i+1]);
        A[i]=min(A[i] , v[i]);
    }
    float ans=0.0;
    int end;
    end=A[0];
    float sta=0;
    float next[1];
    REP(i,n){
        ans+=kyori(sta,t[i],v[i],A[i],next);
        sta=next[0];
    }
    cout << fixed << setprecision(8)<<float(ans) << endl;
}



Measured memory_bytes: 256
'use strict';
 
const main = arg => {
    const input = arg.split('\n');
    const n = input[0];
    const input2 = input[1].split(' ');
    const s = input2[0];
    const t = input2[1];
    let ans = ''
    for (let i = 0;i < n; i++) {
        ans += s.charAt(i) + t.charAt(i);
    }
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>
#include <math.h>

int main(){

  int n[1000];

  int score[1000][1000];

  int i=0;

  int a;

  while(1){

    scanf("%d",&n[i]);

    if(n[i]==0)

      break;

    for(a=0;a<=n[i]-1;a++){

      scanf("%*c%d",&score[i][a]);

    }

    scanf("%*c");
 
    i++;

  }

  double alpha[1000],sigma[1000]={};
  double ave[1000],sigma2[1000]={};

  int b,c;

  for(b=0;b<=i-1;b++){

    for(c=0;c<=n[b]-1;c++){

      sigma[b]+=score[b][c];

    }

    ave[b]=sigma[b]/n[b];

    for(c=0;c<=n[b]-1;c++){

      sigma2[b]+=pow((score[b][c]-ave[b]),2);

    }

    alpha[b]=sqrt(sigma2[b]/n[b]);

  }

  int d;

  for(d=0;d<=i-1;d++){

    printf("%f\n",alpha[d]);

  }

  return 0;

}

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

int v[100010],w[100010],idx[100010];
int c(const void*p,const void*q){
	if((double)v[*(int*)p]/w[*(int*)p]>(double)v[*(int*)q]/w[*(int*)q])return -1;
	return 1;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d%d",v+i,w+i);
	for(int i=0;i<n;i++)idx[i]=i;
	qsort(idx,n,sizeof(int),c);
	double ans=0;
	for(int i=0;i<n;i++){
		if(m<=w[idx[i]]){
			ans+=(double)v[idx[i]]/w[idx[i]]*m;
			break;
		}
		ans+=v[idx[i]];
		m-=w[idx[i]];
	}
	printf("%f\n",ans);
}


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

#define mod 1000000007
#define ll long long

ll bow(ll x, ll y) {
  ll res = 1;
  for (ll i = 1; i <= y; ++i) {
    res = res * x % mod;
  }
  return res;
}

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int r,c;
    cin >> r >> c;
    int a[r+1][c+1];
    rep(i,r){
        rep(j,c) cin >> a[i][j];
    }
    rep(i,r){
        int cnt =0;
        rep(j,c) cnt += a[i][j];
        a[i][c] = cnt;      
    }
    rep(i,c+1){
        int cnt = 0;
        rep(j,r) cnt += a[j][i];
        a[r][i] = cnt;
    }
    rep(i,r+1){
        rep(j,c+1){
             cout << a[i][j];
             if(j != c)cout  << " ";
        }
        cout << endl;
    }
return 0;
}


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

int f(int n){
    return 3*n+1;
}
 
int main() {
    int s;
    cin >> s;
    bool a=true;
    vector<int> S(100000);
    for(int i=0;i<100000;i++){
        S.at(i)=s;
        if(s%2==0) s/=2;
        else s=f(s);
        for(int j=0;j<i;j++){
            if(S.at(i)==S.at(j)){
                cout << max(i,j)+1 << endl;
                a=false;
                break;
            }
        }
        if(a==false) break;
    }
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  switch(N%10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 1e18+1
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    ll N,K;
    cin >> N >> K;
    ll ans = INF;
    // check
    ll d = N%K;
    ll m = abs(N-K);
    chmin(ans,d);
    chmin(ans,m);
    chmin(ans,abs(d-K));
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long ll;
ll a[N],sum[N],n;
int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++) scanf("%lld",a+i);
    sort(a+1,a+n+1);
    for (int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
    int i = n-1;
    for (;i >= 0;i--) if (2*sum[i] < a[i+1]) break;
    printf("%d\n",n-i);
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    int k;
    cin >> s >> k;
    set<string> st;
    for(int i = 0;i < s.size();i++)
    {
        for(int j = 1;j <= k;j++)
        {
            st.insert(s.substr(i,j));
        }
    }
    auto itr = st.begin();
    for(int i = 0;i < k - 1;i++)
    {
        itr++;
    }
    cout << *itr << "\n";

    return 0;
}

Measured memory_bytes: 1664
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        Scanner scanner = new Scanner(System.in);

        while(true) {
            Integer a = scanner.nextInt();
            Integer b = scanner.nextInt();

            if (a == 0 && b == 0) {
                break;
            }
            AtomicInteger count = new AtomicInteger(0);
            List<String> used = new ArrayList<>();
            IntStream.range(1, a + 1)
                     .forEach(x -> {
                         IntStream.range(1, a + 1)
                                  .filter(y -> y != x)
                                  .forEach(y -> {
                                      IntStream.range(1, a + 1)
                                               .filter(z -> z != x && z != y)
                                               .filter(z -> x + y + z == b)
                                               .forEach(z -> {
                                                   String sorted = Arrays.asList(x, y, z)
                                                                         .stream()
                                                                         .sorted()
                                                                         .collect(Collectors.toList())
                                                                         .toString();
                                                   if (used.contains(sorted)) {
                                                       return;
                                                   }
                                                   used.add(sorted);
                                                   count.getAndAdd(1);
                                               });
                                  });
                     });
            System.out.println(count.get());
        }
    }
}



Measured memory_bytes: 92200
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		if(N % K == 0) System.out.println(0);
		else System.out.println(1);
	}
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M), distance(N, 2000000000), point(N);
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < M; i++) cin >> c[i] >> d[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int tmp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if (distance[i] > tmp) {
        distance[i] = tmp;
        point[i] = j+1;
      }
    }
  }
  for (int i = 0; i < N; i++) cout << point[i] << endl;
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int h, w;
  cin >> h >> w;
  vector<string> vec;
  for(int i = 0; i < h; i++){
    string s;
    cin >> s;
    vec.pb(s);
  }
  for(int i = 0; i < w + 2; i++)cout << "#";
  cout << endl;
  for(int i = 0; i < h; i++){
    cout << "#";
    cout << vec[i];
    cout << "#" << endl;
  }
  for(int i = 0; i < w + 2; i++)cout << "#";
  cout << endl;
	return 0;
}


Measured memory_bytes: 256
//-.-.-.-.-.-.-.-.-.-Make it Work, Make it Right, Make it Fast-.-.-.-.-.-.-.-.-.-.-.-.-.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pob pop_back
#define pf push_front
#define popb pop_back()
#define popf pop_front()
#define ll long long int
#define llu long long unsigned int 
#define lu long unsigned int 
#define ff first
#define ss second 
#define S size()
#define inf 1e8
#define clr(a) memset(a, 0, sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dc(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define PI 3.1415926535897932384626433832795
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define vii vector<pii>
using namespace std;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}  
//----------------------------------------START------------------------------------------
int main()
{
	ll n,m;
	cin>>n>>m;
	ll x;
	cin>>x;
	 double z=max(n,m)*1.0;
	//ll ans=min(x/n+(x%n)/m+(x%n)%m,x/m+(x%m)/n+(x%m)%n);
	cout<<int(ceil(x/z))<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<climits>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<stack>
#include<functional>
#include<queue>
using namespace std;

int main(){
    int N,M,A,B,C1,C2,d[20][20],S,G,Mny,V;
    fill_n((int*)d,20*20,INT_MAX/2);
    cin>>N>>M;
    for(int i=0;i<M;i++){
        scanf("%d,%d,%d,%d",&A,&B,&C1,&C2); A--; B--;
        d[A][B] = C1; d[B][A] = C2;
    }
    scanf("%d,%d,%d,%d",&S,&G,&Mny,&V); S--; G--;
    for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    printf("%d\n",Mny-V-d[S][G]-d[G][S]);
    return 0;
}

Measured memory_bytes: 1224
def fib(n):
    F = {}
    F[0], F[1] = 1, 1

    if n == 1 or n == 0:
        return 1

    for i in range(2, n+1):
        F[i] = F[i-1] + F[i-2]
    
    return F[n]

n = int(input())
print(fib(n))


Measured memory_bytes: 5600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    VI a(3);
    REP(i,3) cin >> a[i];
    sort(ALL(a));
    cout << a[2] - a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

a = 0
lis = []

while n-1 != 0:
  for i in range(2):
    lis.append(min(l))
    l.remove(min(l))
  a = sum(lis)/2
  del lis[:]
  l.append(a)
  n-=1
print(a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int c=0;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s.at(i)==s.at(i+1)){
            c++;
        }
    }
    if(c==0){
        cout<<"Good"<<endl;
    }else{
        cout<<"Bad"<<endl;
    }
}

Measured memory_bytes: 256