akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}
bool arr[100010];
int arr2[100010];

void makeArr(int l, int r) {
  for(int i=l; i<=r; ++i) {
    if(i<2) arr[i] = false;
    else if(i==2) arr[i] = true;
    else if(i%2==0) arr[i] = false;
    else {
      double sqrtn = sqrt(i);
      for(int j=3; j<=sqrtn; j+=2) {
        if(i%j==0) {
          arr[i] = false;
          goto next;
        }
      }
      arr[i] = true;
    }
    next:
      continue;
  }
}

bool makeArr2(int l, int r) {
  int cnt = 0;
  for(int i=l; i<=r; ++i) {
    if(arr[i] && arr[(i+1)/2]) cnt++;
    arr2[i] = cnt;
    //cout << i << " " << cnt << endl;
  }
}

int main() {
  int Q; cin >> Q;
  vector<int> l(Q), r(Q);
  int nmin=INT_MAX, nmax=0;
  rep(i,Q) {
    cin >> l[i] >> r[i];
    chmin(nmin, l[i]); chmin(nmin, r[i]);
    chmax(nmax, l[i]); chmax(nmax, r[i]);
  }
  makeArr((nmin+1)/2, nmax);
  makeArr2(nmin, nmax);

  rep(i,Q) {
    cout << arr2[r[i]] - arr2[l[i]-1] << endl;
  }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> n >> s;
  size_t l = 0, r = count(s.begin(), s.end(), '.'), ans = r;
  for (char c : s) {
    if (c == '#')
      ++l;
    else
      --r;
    ans = min(ans, l + r);
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\';
  return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <stack>

std::stack<int> st;
int main() {
	int x = 0;
	while(std::cin >> x) {
		if(x == 0) {
			int y = st.top(); //トップの値を取得
			st.pop(); //トップの値を消去(pop)
			std::cout << y << std::endl;
		} else {
			st.push(x); //トップに値を積む(push)
		}
	}
}


Measured memory_bytes: 2980
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int a, b;
  int ans = 0;

  cin >> a >> b;

  if((a < b) || (a <= 2*b)){
    cout << 0 << endl;
    return 0;
  }
  ans = a - 2*b;
  cout << ans << endl;
}


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

int main(){
  int N,X;
  cin>>N>>X;
  int D[N];
  int min;
  int sum=0;
  int ans;
  
  for(int i=0;i<N;i++){
    cin>>D[i];
    if(i==0)min=D[0];
    if(min>D[i])min=D[i];
    sum+=D[i];
  }
  X-=sum;
  ans = N+X/min;
  cout<<ans<<endl;
}

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

int main(){
  ll n;
  cin >>n;
  if(n%2 == 0) cout << n << endl;
  else cout << 2*n << endl;
  return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll h;
	scanf("%lld", &h);
	ll siz = 1;
	while (siz <= h)siz <<= 1;
	printf("%lld\n", siz - 1);

	Please AC;
}


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

int main(){
    int n,m,i,j,flag;
    char c,c1,c2,str[10000][3];
    
    while(1){
        scanf("%d",&n);
        if(n == 0){
            break;
        }
        
        getchar();
        
        memset(str,'\0',sizeof(str));
        
        for(i = 0;i < n;i++){
            scanf("%c %c",&c1,&c2);
            getchar();
            str[i][0] = c1;
            str[i][1] = c2;
            str[i][2] = '\0';
        }
        
        scanf("%d",&m);
        getchar();
        
        for(i = 0;i < m;i++){
            scanf("%c",&c);
            getchar();
            flag = 0;
            for(j = 0;j < n;j++){
                if(str[j][0] == c){
                    flag = 1;
                    break;
                }
            }
            printf("%c",flag ? str[j][1] : c);
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 612
import itertools
from collections import Counter

n=int(input())
s=input()

t=s[:n][::-1]
u=s[n:]
tc=Counter()
uc=Counter()
for i in itertools.product(range(2),repeat=n):
	t0=""
	t1=""
	u0=""
	u1=""
	for j in range(n):
		if not i[j]:
			t0+=t[j]
			u0+=u[j]
		else:
			t1+=t[j]
			u1+=u[j]
	tc[t0+"-"+t1]+=1
	uc[u0+"-"+u1]+=1

ans=0
for i in tc.keys():
	ans+=tc[i]*uc[i]
print(ans)


Measured memory_bytes: 65476
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [i - 1 for i in list(map(int, input().rstrip('\n').split()))]
    cnt = 0
    for i in range(len(a)):
        if i == a[a[i]]:
            cnt += 1
    print(cnt // 2)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56236
import itertools
N,M,Q=map(int,input().split())
ABCD=[list(map(int,input().split())) for _ in range(Q)]
tl=[]
for i in range(1,M+1):
    tl.append([i])
for i in range(N):
    t=[]
    for l in tl:
        for j in range(1,M+1):
            if l[-1]<=j:
                t.append(l+[j])
    tl=t[:]
ans=0
for l in tl:
    t=0
    for a,b,c,d in ABCD:
        if l[b-1]-l[a-1]==c:
            t+=d
    ans=max(ans,t)
print(ans)

Measured memory_bytes: 148520
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#define MAX_INT 2147483647
using namespace std;
int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  vector<int>a(n+1,0);
  for(int i=0;i<q;i++){
    int com,x,y;
    scanf("%d %d %d",&com,&x,&y);
    if(com){
      int sum=0;
      for(int j=x;j<=y;j++)
       sum+=a[j];
      printf("%d\n",sum);
    }else{
      a[x]+=y;
    }
  }
  return 0;
}

Measured memory_bytes: 3240
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c,_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


Measured memory_bytes: 5600
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    static long A,B;
    //static int[] A,B;
    static HashSet<Integer>[] graph;
    public static void main(String[] args)throws IOException {
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        Scanner sc = new Scanner(System.in);
        A = sc.nextLong(); B = sc.nextLong();
        if(B==0){
            System.out.println(0);
            return;
        }
        long ans;
        if(A<=1) ans = solve(B);
        else ans = solve(B)^solve(A-1);
        System.out.println(ans);
    }
    static long solve(long B){
        long ans = 0;
        long back = B;
        back = back%4;
        if(back==1||back==2) ans = 1;
        for(int i=1;i<50;i++){
            long cur  = 1L<<i;
            if(cur>B) break;
            long backup = B-(cur-1);
            long remain = backup%(2*cur);
            if(remain<cur&&remain%2==1) ans += cur;
        }
        return ans;
    }
}

Measured memory_bytes: 21844
import numpy as np


def main(N, a):
    ans = 0
    for i in range(N):
        if i % 2 == 0 and a[i] % 2 == 1:
            ans += 1
    return ans


N = int(input())
a = list(map(int, input().split()))
print(main(N, a))


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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


int main() {
	//体力：a,c
	int a,b,c,d;
	cin >> a>> b>>c>>d;
	
	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}



}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b,c;
  ci(a>>b>>c);
  ll an=2*min(b,c);
  ll d=min(b,c);
  b-=d;
  c-=d;
  if(b>0)
    an+=b;
  else
    an+=min(a,c);
  c-=min(a,c);
  if(c>0)
    an++;
  co(an);
}

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

using namespace std;

int main()
{
	int K;
	int sum = 0;

	cin >> K;

	for (int i = 1; i <= K; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			for (int t = 1; t <= K; t++)
			{
				int d = 1;
				int e = 1;
				while (e <= i && e <= j && e <= t) {
					if (i % e == 0 && j % e == 0 && t % e == 0)
						d = e;
					e++;
				}
				sum += d;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) (((a)+(b)-1)/(b))
#define all(x) x.begin(), x.end()
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define dbg(msg, var) cerr << msg << " " << var << endl;

using namespace std;

const int MAX = 100010;
const int MOD = 123456789;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// End Template //

ll dp1[100010], dp2[100010];

int main()
{sws;

    ll n, c, x, v;
    cin >> n >> c;

    vector<pair<ll, ll>> vet;
    for(int i=0;i<n;i++){
        cin >> x >> v;
        vet.pb({x, v});
    }

    ll ans = 0;

    ll best=0, now=0, lst=0;
    for(int i=0;i<n;i++){
        x = vet[i].ff;
        v = vet[i].ss;
        now+=v-(x-lst);
        lst=x;
        dp1[i] = best = max(best, now);
    }

    ans = max(ans, best);

    best=0; now=0; lst=c;
    for(int i=n-1;i>=0;i--){
        x = vet[i].ff;
        v = vet[i].ss;
        now+=v-(lst-x);
        lst = x;
        dp2[n-i-1] = best = max(best, now);
    }

    ans = max(ans, best);

    // for(int i=0;i<n;i++)
    //     cout << dp1[i] << " ";
    // cout << endl;

    // for(int i=0;i<n;i++)
    //     cout << dp2[i] << " ";
    // cout << endl;

    ll sum=0;
    for(int i=0;i<n-1;i++){
        x = vet[i].ff;
        v = vet[i].ss;
        sum+=v;
        ans = max(ans, sum-2*x + dp2[n-1-i - 1]);
    }


    sum=0;
    for(int i=0;i<n-1;i++){
        x = vet[n-1-i].ff;
        v = vet[n-1-i].ss;
        sum+=v;
        ans = max(ans, sum-2*(c-x) + dp1[n-1-i - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6312
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, X;
int cntP[60], cntB[60], cntW[60];

int solve(int X, int level) {
    int sum = 0;
    if(level == 0) return 1;
    
    if(X == 1) {
        return 0;
    }
    X--;
    if(X <= cntW[level-1]) {
        return sum + solve(X, level-1);
    }
    X -= cntW[level-1]; sum += cntP[level-1];
    if(X == 1) {
        return sum + 1;
    }
    X--; sum++;
    if(X <= cntW[level-1]) {
        return sum + solve(X, level-1);
    }
    X -= cntW[level-1]; sum += cntP[level-1];
    if(X == 1) {
        return sum;
    }
    assert(false);
    return 0;
}

signed main() {
    cin >> N >> X;
    cntP[0] = 1, cntB[0] = 0, cntW[0] = 1;

    for(int i=1; i<=N; i++) {
        cntP[i] = 2 * cntP[i-1] + 1;
        cntB[i] = 2 * cntB[i-1] + 2;
        cntW[i] = cntP[i] + cntB[i];
    }

    cout << solve(X, N) << endl;
    return 0;
}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveStringArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var s = inputArray[0];


			var c = 'a';

			var min = s.Length;

			//a~zまですべて試す

			for (int i = 0; i < 27; i++) {
				var cha = (char)(c + i);

				var count = 0;
				var str = s.Select(x => x).ToArray();
				while (str.Length>0) {

					if (str.All(x =>x ==cha)) {
						break;
					}
					str = getNextStr(str, cha);
					count++;
				}

				min = Math.Min(min, count);

			}

			//答えの出力
			var ans = min;
			Console.WriteLine(ans);

		}


		private	static char[] getNextStr(char[] str, char cha) {

			var nextStr = new char[str.Length - 1];

			for (int i = 0; i < str.Length-1; i++) {
				nextStr[i] = str[i] == cha | str[i + 1] == cha ? cha : str[i];
			}
			return nextStr;
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 27260
N=int(input())
p=list(map(int,input().split()))

a=[30000*(i+1) for i in range(N)]
b=[30000*(N-i) for i in range(N)]

for i in range(0,N):
    a[p[i]-1]+=i
    b[p[i]-1]+=i

print(*a)
print(*b)


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

int main()
{
    int n,i,sum = 0;
    vector<char>v;

    cin>>n;
    char ch;
    for(i = 0;i < n;i++)
    {
       cin>>ch;
       v.push_back(ch);
    }


    for(i = 0;i < n;i++)
    {
        if(v[i]=='A' && v[i+1]=='B' && v[i+2]=='C')
            sum++;

    }
    cout<<sum<<endl;

    return 0;

}


Measured memory_bytes: 764
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;


int main(){
    ll n,y,ans1,ans2,ans3;
    cin>>n>>y;
    bool fl=false;
    for(ll i=0;i<=n;i++){
        if(fl)break;
        for(ll j=0;j<=n;j++){
            if(fl)break;
            if(10000*i+5000*j+1000*(n-i-j)==y&&(n-i-j)>=0){
                ans1=i;
                ans2=j;
                ans3=n-i-j;
                fl=true;
            }
        }
    }
    if(fl){
        cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
    }
    else{
        cout<<-1<<" "<<-1<<" "<<-1<<endl;
    }

    return 0;
}


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

int a[200005];

int main(){
    int n; cin>>n;
    long long ans=0;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n;++i)if(a[i]>i){ cout<<-1<<endl; exit(0); }
    for(int i=1;i<n;++i)if(a[i]>a[i-1]+1){ cout<<-1<<endl; exit(0); }
    for(int i=n-1;i>=0;--i){
        if(a[i]==a[i+1]-1)continue;
        ans+=a[i];
    }
    cout<<ans<<endl;
}


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

int dp[1001][1001];
int main() {
    int q;
    cin>>q;
    int ans[150] = {0};
    for (int i = 0; i < q; ++i) {
        memset(dp, 0, sizeof(dp));
        string x, y;
        cin>>x>>y;
        int xlen = x.length();
        int ylen = y.length();
        for(int ix = 0; ix < xlen; ++ix) {
            for(int iy = 0; iy < ylen; ++iy) {
                if (x[ix] == y[iy]) {
                    dp[ix + 1][iy + 1] = max(max(dp[ix][iy] + 1, dp[ix + 1][iy]), dp[ix][iy+1]);
                } else {
                    dp[ix + 1][iy + 1] = max(dp[ix + 1][iy], dp[ix][iy+1]);
                }
            }
        }
        ans[i] = dp[xlen][ylen];
    }

    for(int i = 0; i < q; ++i) {
        cout<<ans[i]<<endl;
    }

}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI 3.141592653589793
#define vi vector<int>
inline double degcos(double ang) {return cos(ang*PI/180);}
inline double degsin(double ang) {return sin(ang*PI/180);}
#define for(i,j,k,in) for (int i = j; i < k; i += in)


/*---END OF TEMPLATE---*/




int dist[2005][2005];
int n;
int main()
{
    //Step 1: Input the graph using adjacency list.
    memset(dist,1,sizeof(dist));
    int x,y;
    cin >> n >> x >> y;
    x--;y--;
    int tot[2005];
    memset(tot,0,sizeof(tot));
    for (i,0,n,1) {
        for (j,0,n,1) {
            dist[j][i] = min(i-j,min(abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(j-x)));
            tot[dist[j][i]]++;
        }
    }
    for (i,1,n,1) {
        cout << tot[i] << endl;
    }


    
}


Measured memory_bytes: 16000
from sys import stdin
for line in stdin:
    a, b, c, d, e, f = map(float, line.split())
    anss = ['%.3f' % ((c * e - f * b) / (a * e - b * d)), '%.3f' % ((c * d - a * f) / (b * d - a * e))]
    for index, ans in enumerate(anss):
        if ans == '-0.000':
            anss[index] = '0.000'
    print(' '.join(anss))


Measured memory_bytes: 5580
import java.io.*;
import java.util.StringTokenizer;
import java.util.Arrays;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while (!(buf = br.readLine()).equals("0")) {
				int n = Integer.parseInt(buf);

				int m[][] = new int[n+1][n+1];
				Arrays.fill(m[n],0);
				for (int i=0;i<n;i++) {
					StringTokenizer st = new StringTokenizer(br.readLine());
					Arrays.fill(m[i],0);
					for (int j=0;j<n;j++) {
						m[i][j] = Integer.parseInt(st.nextToken());
						m[i][n] += m[i][j];
						m[n][j] += m[i][j];
					}
				}
				for (int i=0;i<n;i++) {
					m[n][n] += m[n][i];
				}
				for (int i=0;i<=n;i++) {
					for (int j=0;j<=n;j++) {
						System.out.printf("%5d",m[i][j]);
					}
					System.out.println("");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 22572
#ABC121D-XORWorld.py

from sys import stdin

A, B = list(map(int, stdin.readline().split()))

N = B - A + 1

if A & 1 != 1:
    if N % 2 == 0:
        if N % 4 == 0:
            print(0)
        else:
            print(1)
    else:
        if (N - 1) % 4 == 0:
            print(B ^ 0)
        else:
            print(B ^ 1)
else:
    if (N - 1) % 2 == 0:
        if (N - 1) % 4 == 0:
            print(A ^ 0)
        else:
            print(A ^ 1)
    else:
        if (N - 2) % 4 == 0:
            print(A ^ B ^ 0)
        else:
            print(A ^ B ^ 1)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int H, W;
	int i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if((i+j) % 2 == 0){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


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

bool judge(string s, char c){
	for(int i = 0; i < 3; i++){
		if(s[3*i] == c && s[3*i+1] == c && s[3*i+2] == c){
			return true;
		}
		if(s[i] == c && s[i+3] == c && s[i+6] == c){
			return true;
		}
	}
	if(s[0] == c && s[4] == c && s[8] == c){
		return true;
	}
	if(s[2] == c && s[4] == c && s[6] == c){
		return true;
	}
	return false;
}
int main(){
	string s;
	while(getline(cin,s)){
		if(judge(s,'o')){
			cout << 'o' << endl;
		}else if(judge(s,'x')){
			cout << 'x' << endl;
		}else {
			cout << 'd' << endl;
		}
	}
	return 0;
}

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

int main() {
  ll n,k,p=1;
  ll a=0;
  cin >> n >> k;

  while(n>=p){
    a++;
    p = p * k;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int inf=1e9+1;
int timp[100010],logg[100010],urm[20][100010];
long long sum[100010],rmqmin[20][100010],rmqmax[20][100010];

long long get_min(int x,int y)
{
    int l=logg[y-x+1];
    return min(rmqmin[l][x],rmqmin[l][y-(1<<l)+1]);
}

long long get_max(int x,int y)
{
    int l=logg[y-x+1];
    return max(rmqmax[l][x],rmqmax[l][y-(1<<l)+1]);
}

int main()
{
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int cap,n,q;
    scanf("%d%d",&cap,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&timp[i]);
        if(i&1) sum[i]=sum[i-1]-(timp[i]-timp[i-1]);
        else sum[i]=sum[i-1]+(timp[i]-timp[i-1]);
    }
    for(int i=2;i<=n;i++) logg[i]=logg[i/2]+1;
    for(int i=1;i<=n;i++) rmqmin[0][i]=rmqmax[0][i]=sum[i];
    for(int i=1;i<=logg[n];i++)
    {
        int lim=n-(1<<i)+1;
        for(int j=1;j<=lim;j++)
        {
            rmqmin[i][j]=min(rmqmin[i-1][j],rmqmin[i-1][j+(1<<(i-1))]);
            rmqmax[i][j]=max(rmqmax[i-1][j],rmqmax[i-1][j+(1<<(i-1))]);
        }
    }
    for(int i=1;i<=n;i++)
    {
        int st=i+1,dr=n;
        long long val=-sum[i];
        if((i&1)==0) val+=cap;
        while(st<=dr)
        {
            int mid=(st+dr)/2;
            if(val+get_min(i+1,mid)<0 || val+get_max(i+1,mid)>cap) dr=mid-1;
            else st=mid+1;
        }
        urm[0][i]=st;
    }
    for(int i=0;i<=logg[n];i++) urm[i][n+1]=n+1;
    timp[n+1]=inf;
    for(int i=1;i<=logg[n];i++)
        for(int j=1;j<=n;j++)
            urm[i][j]=urm[i-1][urm[i-1][j]];
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        int t,val;
        scanf("%d%d",&t,&val);
        int st=1,dr=n;
        while(st<=dr)
        {
            int mid=(st+dr)/2;
            if(val+get_min(1,mid)<0 || val+get_max(1,mid)>cap) dr=mid-1;
            else st=mid+1;
        }
        int poz=st;
        if(timp[poz]>=t)
        {
            int st=1,dr=n;
            while(st<=dr)
            {
                int mid=(st+dr)/2;
                if(t<timp[mid]) dr=mid-1;
                else st=mid+1;
            }
            long long sol=val+sum[dr];
            if(dr&1) sol+=t-timp[dr];
            else sol-=t-timp[dr];
            if(sol<0) sol=0;
            if(sol>cap) sol=cap;
            printf("%lld\n",sol);
        }
        else
        {
            for(int j=logg[n];j>=0;j--)
                if(timp[urm[j][poz]]<t) poz=urm[j][poz];
            long long sol;
            if(poz&1) sol=0;
            else sol=cap;
            int st=1,dr=n;
            while(st<=dr)
            {
                int mid=(st+dr)/2;
                if(t<timp[mid]) dr=mid-1;
                else st=mid+1;
            }
            sol+=sum[dr]-sum[poz];
            if(dr&1) sol+=t-timp[dr];
            else sol-=t-timp[dr];
            if(sol<0) sol=0;
            if(sol>cap) sol=cap;
            printf("%lld\n",sol);
        }
    }
    return 0;
}


Measured memory_bytes: 38784
#include<bits/stdc++.h>
using namespace std;
int a,b;
string A,B;
int main(){
	cin>>a>>b;
	for(int i=1;i<=a;i++)B+=b+'0';
	for(int i=1;i<=b;i++)A+=a+'0';
	cout<<min(A,B);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   998244353 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
   int p , q , r ;
   cin >> p >> q >> r ;
   cout << min(p+q,min(p+r,q+r));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t ;
    t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}
// number of subset having xor in 2ki ow


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

int main(void)
{
	int num, temp= 0;
	long long int input, total= 0;

	cin>>num;
	for(int i= 0; i < num; i++)
	{
		cin>>input;

		if(input == 0)
			temp= 0;

		input+= temp;
		total+= input/2;
		temp= input%2;
	}
	cout<<total<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        
        if(X % 2 == 0 && X != 2){
            X++;
        }
        for(int i = 3; i < X; i += 2){
            if(i == X){
                break;
            }
            if(X % i == 0){
                X += 2;
                i = 3;
            }
        }
        
        System.out.println(X);
    }
}


Measured memory_bytes: 21972
S=str(input())
ans=0
before="0"
nex=""
ii=0
for i in range(len(S)):
  nex=nex+S[i]
  #print("before",before,"nex",nex,"ans",ans)
  if ii<len(before):
    if before[ii]==S[i] and ii==len(before)-1:
      ii=+1
    else:
      ans+=1
      before=nex
      ii=0
      nex=""
  else:
    ans+=1
    before=nex
    ii=0
    nex=""
print(ans)

Measured memory_bytes: 3500
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  map<int, int> mp;
  mp[0] = 1;
  ll ans = 0;
  ll sum = 0;

  REP(i, n) {
    int a;
    cin >> a;

    sum += a;
    sum %= m;
    ans += mp[sum];
    mp[sum]++;
  }

  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = -1e18;
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> ans(n), cnt(n, -1);
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    int q;
    cin >> q;
    vector<int> v(q), d(q), c(q);
    rep(i, 0, q) {
        cin >> v[q - 1 - i] >> d[q - 1 - i] >> c[q - 1 - i];
        v[q - 1 - i]--;
    }
    rep(i, 0, q) {
        if (cnt[v[i]] >= d[i]) continue;
        queue<int> que;
        que.push(v[i]);
        int dep = d[i];
        while (!que.empty()) {
            for (int j = que.size(); j > 0; j--) {
                int k = que.front();
                que.pop();
                if (ans[k] == 0) ans[k] = c[i];
                cnt[k] = dep;
                if (dep) {
                    for (int to : g[k])
                        if (cnt[to] < dep - 1) {
                            que.push(to);
                        }
                }
            }
            if (dep == 0) break;
            dep--;
        }
    }
    rep(i, 0, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 8952
n,*a=`dd`.split.map &:to_i
a=a.sort.reverse
i=(0...n).find{|x|a[x]<x+1}||n
j=(i...n).find{|x|a[x]<i}||n
puts (a[i-1]-i)%2+(j-i)%2>0?:First: :Second

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

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define int ll

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int n;
	cin >> n;
	int sum = 0;

	int a[n]; F0R(i, n) cin >> a[i], sum += a[i];

	int ans = 0;
	F0R(i, n) {
		(ans += (a[i] % MOD * (sum % MOD - a[i] % MOD + MOD) % MOD) % MOD) %= MOD;
		sum -= a[i];
	}

	cout << ans;
}

int32_t main() {
	_

#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
	solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



Measured memory_bytes: 5352
#include <stdio.h>
int main(){
	int a,b;
	int i,j,k;
	int ans;
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0){
			break;
		}
		ans=0;
		for(i=1;i<a-1;i++){
			for(j=i+1;j<a;j++){
				for(k=j+1;k<a+1;k++){
					if(i+j+k==b) ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	q := io.NextInt()
	for i := 0; i < q; i++ {
		io.Println(solve(io.NextInt()))
	}
}

func solve(n int) int {
	f := func(n int) int {
		max := 0
		for i := 10; ; i *= 10 {
			a := n / i
			b := n % i
			if a == 0 {
				break
			}
			max = intMax(a*b, max)
		}
		return max
	}

	cnt := 0
	for {
		if n < 10 {
			break
		}
		n = f(n)
		cnt++
	}

	return cnt
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1120
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";
type PickData = {
  index: number;
  isPicked: boolean;
};

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const cnt = (() => {
    const css: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );

    const getBlackCnt = (hPicks: PickData[], wPicks: PickData[]) =>
      hPicks
        .filter(({ isPicked }) => isPicked)
        .map(({ index }) => {
          const i = index;
          return wPicks
            .filter(({ isPicked }) => isPicked)
            .map(({ index }) => {
              const j = index;
              return (css[i][j] === "Black" ? 1 : 0) as number;
            })
            .reduce((acc, x) => acc + x, 0);
        })
        .reduce((acc, x) => acc + x, 0);

    const initialBlackCnt = getBlackCnt(
      range(H).map((i) => ({ index: i, isPicked: true })),
      range(W).map((j) => ({ index: j, isPicked: true }))
    );

    const wPickFn = (n: number, hPicks: PickData[], wPicks: PickData[]): number =>
      n >= W
        ? (() => {
            const hCnt = getBlackCnt(
              range(H).map((i) => ({ index: i, isPicked: true })),
              wPicks
            );
            const wCnt = getBlackCnt(
              hPicks,
              range(W).map((j) => ({ index: j, isPicked: true }))
            );
            const hwCnt = getBlackCnt(hPicks, wPicks);

            return initialBlackCnt - (hCnt + wCnt - hwCnt);
          })() === K
          ? 1
          : 0
        : wPickFn(n + 1, hPicks, wPicks) +
          wPickFn(
            n + 1,
            hPicks,
            wPicks.map(({ index, isPicked }) => {
              const j = index;
              return j === n ? { index: j, isPicked: true } : { index: j, isPicked: isPicked };
            })
          );

    const hPickFn = (n: number, hPicks: PickData[]): number =>
      n >= H
        ? wPickFn(
            0,
            hPicks,
            range(W).map((j) => ({ index: j, isPicked: false }))
          )
        : hPickFn(n + 1, hPicks) +
          hPickFn(
            n + 1,
            hPicks.map(({ index, isPicked }) => {
              const i = index;
              return i === n ? { index: i, isPicked: true } : { index: i, isPicked: isPicked };
            })
          );

    return hPickFn(
      0,
      range(H).map((i) => ({ index: i, isPicked: false }))
    );
  })();

  console.log(cnt);
}


Measured memory_bytes: 41148
import java.util.*;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		int plus=a+b;
		int minus=a-b;
		int z=a*b;
		
		int max=Math.max(Math.max(plus,minus),z);
			
		System.out.println(max);
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<vector<int>> v(n);
  rep(i,n-1){
    int a,b;cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<int> c(n);
  rep(i,n)cin >> c[i];
  sort(ALL(c),greater<int>());
  queue<int> que;
  que.push(0);
  vector<int> res(n,-1);
  res[0] = c[0];
  int i = 1;
  ll k = 0;
  while(!que.empty()){
    int ov = que.front();que.pop();
    for(int nv : v[ov]){
      if(res[nv] != -1)continue;
      res[nv] = c[i];
      k += c[i];
      i++;
      que.push(nv);
    }
  }
  cout << k << "\n";
  rep(j,n)cout << res[j] << " ";
  cout << "\n";








  return 0;
}

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

int main()
{
    unsigned long n, t;
    std::cin >> n >> t;
    std::vector<unsigned long> prices(n);
    for(unsigned long i = 0; i != n; ++i)
    {
        std::cin >> prices[i];
    }

    unsigned long maxProfit = 0;
    unsigned long counter;

    std::vector<unsigned long> max(n);
    max[n - 1] = prices[n - 1];
    for(unsigned long i = n - 1; i != 0; --i)
    {
        max[i - 1] = std::max(max[i], prices[i - 1]);
    }
    for(unsigned long i = 0; i != n; ++i)
    {
        if(i != 0 && prices[i - 1] < prices[i])
            continue;
        unsigned long profit = max[i] - prices[i];
        if(profit > maxProfit)
        {
            maxProfit = profit;
            counter = 1;
        }
        else if(profit == maxProfit)
        {
            ++counter;
        }
    }
    std::cout << counter << std::endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  int x = (b - 2*a);
  int y = (4*a-b);
  if (x&1 || x<0) cout << "No"; else 
  if (y&1 || y<0) cout << "No"; else cout << "Yes";
  return 0;
}

Measured memory_bytes: 3636
while True:
    n=int(input())
    if n==0:
        break
    else:
        max_s=0
        min_s=2000
        sum_s=0
        for i in range(n):
            s=int(input())
            sum_s=sum_s+s
            if s<min_s:
                min_s=s
            if s>max_s:
                max_s=s
        print((sum_s-max_s-min_s)//(n-2))


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    // 実験より
    // 奇数の時s=2+3+...+n-1
    // 偶数の時s=1+2+...+n-1
    vector<pint> vec;
    int s;
    bool chk[n][n];
    rep (i, 0, n) rep (j, 0, n) chk[i][j] = 1;
    set<pint> st;
    if (n % 2 == 1) {
        s = (n - 1 + 2) * (n - 2) / 2;
        rep (i, 0, n) {
            rep (j, 0, n) {
                if (i == j) continue;
                if (i + j != n - 2)
                    st.insert ({min (i + 1, j + 1), max (i + 1, j + 1)});
            }
        }
    } else {
        s = (1 + n - 1) * (n - 1) / 2;
        rep (i, 0, n) {
            rep (j, 0, n) {
                if (i == j) continue;
                if (i + j != n - 1)
                    st.insert ({min (i + 1, j + 1), max (i + 1, j + 1)});
            }
        }
    }
    int m = st.size();
    cout << m << "\n";
    for (auto p : st) {
        cout << p.first << " " << p.second << "\n";
    }
}

Measured memory_bytes: 3840
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int n=0;n<N;n++) a[n]=sc.nextInt();
        	
        Arrays.sort(a);
        //maximize nCr
        //when r is fixed, the best n is the largest one
        int left = a[N-1];
        //the best r is the closest to n/2
        int right = -1;
        for(int n=0;n<N-1;n++){
        	if(Math.abs(right-left/2.0) > Math.abs(a[n]-left/2.0)) right = a[n];
        }
        
        System.out.println(left+" "+right);
        
    }
}

Measured memory_bytes: 50916
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    int n,k;
    cin>>n>>k;
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i]=INT_MAX;
    }
    vector<int>stones;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        stones.push_back(a);
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=k+i;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(stones[i]-stones[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;
int k;
const int mxK = 1e5+5;

bool dp[mxK];

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

    vector<int> values(100);
    cin >> n >> k;

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

    for(int i=0; i<=k; ++i) {
        if(dp[i])
            continue;
        for(int j=0; j<n; ++j) {
            temp = values[j];
            if(i+temp<=k && !dp[i])
                dp[i+temp]=true;
        }
    }
    cout << (dp[k]?"First":"Second") << endl;
    return 0;

}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int N = 2e5 + 7;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[N];

void init() {
	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mul(i, f[i - 1]);
	}
}

int C(int n, int k) {
	int ans = 1;
	for (int i = 0; i < k; i++) {
		ans = mul(ans, n - i);
	}
	ans = divv(ans, f[k]);
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	init();	

	int n, a, b;
	cin >> n >> a >> b;
	int ans = binpow(2, n);
	ans = sub(ans, 1);
	ans = sub(ans, C(n, a));
	ans = sub(ans, C(n, b));
	cout << ans << endl;
}


Measured memory_bytes: 1792