akhauriyash/Code-Regression huggingface dataset:
s = str(input())

if 1 <= int(s[0:2]) <= 12 : #3桁目４桁目
    
    if  1 <= int(s[2:4]) <= 12 :
        print("AMBIGUOUS")
        
    else:
        print("MMYY")
else:
    if 1 <= int(s[2:4]) <= 12 :
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int grd[1010][1010];
int main(){
	while(true){
	int h,w,n;	cin>>h>>w>>n;
	if(h==0)	return 0;
	memset(dp,0,sizeof(dp));	memset(grd,0,sizeof(grd));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)	cin>>grd[i][j];
	}
	dp[0][0]=n-1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j+1<w){
				if(grd[i][j]==1)	dp[i][j+1]+=(dp[i][j]+1)/2;
				else 	dp[i][j+1]+=dp[i][j]/2;
			}
			if(i+1<h){
				if(grd[i][j]==1)	dp[i+1][j]+=dp[i][j]/2;
				else 	dp[i+1][j]+=(dp[i][j]+1)/2;
			}
			dp[i][j]%=2;
		}
	}
	int x=0,y=0;
	while(x<w&&y<h){
		if((grd[y][x]^dp[y][x])==1)	x++;
		else 	y++;
	}
	cout<<y+1<<" "<<x+1<<endl;
	}
}

Measured memory_bytes: 9136
#include<stdio.h>
 
int main(){
  int N;
  unsigned long long a[100001]={0};
  scanf("%d",&N);
 
  int i;
  for(i=0;i<N;i++){
    scanf("%llu",&a[i]);
  }
  int flg=0;
  unsigned long long t=a[0];
  for(i=1;i<N;i++){
    if(a[i]==0){
      flg=1;
    }
    t=t*a[i];
  }
  if(t>1000000000000000000){
    printf("-1");
  }else if(flg==0 && t==0){
    printf("-1");
  }else{
    printf("%llu",t);
  }
  return 0;
}

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

using namespace std;

int main() {
  int n, k; cin >> n; cin >> k;
  vector<int> x;
  for (int i = 0; i < n; ++i) {
    int in; cin >> in;
    x.push_back(in);
  }
  int d = 0;
  for (int i = 0; i < n; ++i) {
    int a = x[i] * 2;
    int b = abs(k - x[i]) * 2;
    d += min(a, b);
  }
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 256
program answer
  implicit none

  character(len=100):: S, T, U
  integer :: i, j, a

  read(*,*) S
  read(*,*) T

  a=len_trim(S)
  
  
  do i = 1, a
     if(S==t) then
        write(*,*) 'Yes'
        stop
     end if
     U=S
     do j = 1, a-1
        S(j+1:j+1)=U(j:j)
     end do
     S(1:1)=U(a:a)
  end do
     
     write(*,*) 'No'     

  stop
 end program answer


Measured memory_bytes: 2788
N = int(input())
ans = ''
for i in range(1, 99):
  if N <= 26 ** i:
    N -= 1
    for j in range(i):
      ans += chr(ord('a') + N % 26)
      N //= 26
    break
  else:
    N -= 26 ** i
print(ans[::-1]) 

Measured memory_bytes: 9176
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	ll k;
	cin >> k;

	ll t = 7;
	t %= k;
	if (t == 0) {
		cout << 1 << "\n";
		return 0;
	}

	rep(i, 1e7) {
		t *= 10;
		t += 7;
		t %= k;
		if (t == 0) {
			cout << i + 2 << "\n";
			return 0;
		}
	}

	cout << "-1" << "\n";

	return 0;
}


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

#define llong long long 

int how;
llong int in[101];
llong int score[21][100];

llong int solve(llong int sum, llong int d){
	if(sum < 0 || sum > 20) return 0;
	if(score[sum][d] != -1) return score[sum][d];
	if(d == how - 1){
		if(sum == in[how])return score[sum][d] = 1;
		else return score[sum][d] = 0;	
	}

	llong int ret;
	if(sum == 0 && d == 0){
		ret = solve(in[1], 1);
	}else{
		ret = solve(sum - in[d + 1], d + 1) + solve(sum + in[d + 1], d + 1);
	}

	return score[sum][d] = ret;
}

int main(){
	fill_n(in, 101, -1);
	fill_n(*score, 21 * 100, -1);
	cin >> how;
	for(int i = 1; i <= how; i++){
		cin >> in[i];
	}
	cout << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 3132
# D - Chat in a Circle
def main():
    N, *A = map(int, open(0).read().split())
    A.sort(reverse=True)
    res = A[0] + 2 * sum(A[1 : N // 2]) + (A[N // 2] if N % 2 else 0)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31748
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		int tmp;
		String ans = "";
		while (N > 0){
			N-=1;
			tmp = (int) (N % 26);
			ans += (char)(tmp + 'a');
			N /= 26;
		}
		for(int i=ans.length();i>0;--i){
			System.out.print(ans.charAt(i-1));
		}
	}
}


Measured memory_bytes: 39260
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  multiset<int> st;
  int diam = 0;
  REP(i, n) {
    int a;
    cin >> a;
    st.insert(a);
    diam = max(diam, a);
  }
  if (diam % 2 == 0) {
    for (int i = diam; i > diam / 2; --i) {
      if (st.find(i) != st.end()) {
        st.erase(st.find(i));
      } else {
        cout << "Impossible" << endl;
        return 0;
      }
    }
    for (int i = diam / 2; i <= diam; ++i) {
      if (st.find(i) != st.end()) {
        st.erase(st.find(i));
      } else {
        cout << "Impossible" << endl;
        return 0;
      }
    }
    if (st.empty()) {
      cout << "Possible" << endl;
      return 0;
    } else if (*st.begin() < diam / 2 + 1) {
      cout << "Impossible" << endl;
      return 0;
    }
    cout << "Possible" << endl;
  } else {
    for (int i = diam; i >= (diam + 1) / 2; --i) {
      if (st.find(i) != st.end()) {
        st.erase(st.find(i));
      } else {
        cout << "Impossible" << endl;
        return 0;
      }
    }
    for (int i = (diam + 1) / 2; i <= diam; ++i) {
      if (st.find(i) != st.end()) {
        st.erase(st.find(i));
      } else {
        cout << "Impossible" << endl;
        return 0;
      }
    }
    if (st.empty()) {
      cout << "Possible" << endl;
      return 0;
    } else if (*st.begin() < (diam + 1) / 2 + 1) {
      cout << "Impossible" << endl;
      return 0;
    }
    cout << "Possible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
 
 
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
   
}
    
ll maxl(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
ll minl(ll a,ll b){
    if(a>b)return b;
    return a;
}
 
ll mod = 998244353;
 
ll mulmod(ll a, ll b,ll c){ 
    ll res = 0; 
    a = a % c; 
    while (b > 0){ 
        if (b % 2 == 1){ 
            res = (res + a) % c;
        }
        a = (a * 2) % c; 
        b /= 2; 
    } 
    return res % c; 
}
 
int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 
 
int a[100005];
int tree[200005];
 
void build(int st,int low,int high){
    if(low==high){
        tree[st] = a[high]%2;
        return;
    }
    int mid = low+(high-low)/2;
    build(2*st,low,mid);
    build(2*st+1,mid+1,high);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
void update(int st,int start,int end,int ind,int val){
    if(start==end){
        tree[st] = val%2;
        return;
    }
    int mid = start+(end-start)/2;
    if(ind<=mid){
        update(2*st,start,mid,ind,val);
    }
    else update(2*st+1,mid+1,end,ind,val);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
int query(int st,int start,int end,int low,int high){
    if(start>high || end<low)return 0;
    int mid = start + (end-start)/2;
    if(start==low && end==high){
        return tree[st];
    }
    if(low>mid)return query(2*st+1,mid+1,end,low,high);
    if(high<=mid)return query(2*st,start,mid,low,high);
    return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}

vector < vector<int> > e;
vector<int> v;
vector<int> val;

void edge(int a,int b){
    e[a].pb(b);
    e[b].pb(a);
}

void DFS(int i,int sum){
    v[i] = 1;
    sum+=val[i];
    val[i] = sum;
    for(int j=0;j<e[i].size();j++){
        if(v[e[i][j]]==0){
            DFS(e[i][j],sum);
        }
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	int n,a,b,q;
	cin >> n>> q;
	v.resize(n+1);
	e.resize(n+1);
	val.resize(n+1);
	for(int i=0;i<=n;i++){
	    val[i] = 0;
	    v[i] = 0;
	}
	for(int i=0;i<n-1;i++){
	    cin >> a >> b;
	    edge(a,b);
	}
	for(int i=0;i<q;i++){
	    int p,x;
	    cin >> p >> x;
	    val[p]+=x;
	}
	DFS(1,0);
	for(int i=1;i<=n;i++){
	    cout << val[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 21120
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll sx, sy, tx, ty, dx, dy, i;

    cin >> sx >> sy >> tx >> ty;

    dx = tx-sx;
    dy = ty-sy;

    for(i=1; i<=dy; i++){
        cout << "U";
    }
    for(i=1; i<=dx; i++){
        cout << "R";
    }
    for(i=1; i<=dy; i++){
        cout << "D";
    }
    for(i=1; i<=dx; i++){
        cout << "L";
    }

    cout << "L";
    for(i=1; i<=dy+1; i++){
        cout << "U";
    }
    for(i=1; i<=dx+1; i++){
        cout << "R";
    }
    cout << "D";

    cout << "R";
    for(i=1; i<=dy+1; i++){
        cout << "D";
    }
    for(i=1; i<=dx+1; i++){
        cout << "L";
    }
    cout << "U" << 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++)
 
int main() {
    int A,B;
    cin >> A >> B;
    rep(i,100000){
        int a = i * 0.08;
        int b = i * 0.10;
        if(a == A && B == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 205050

ll n,m;
ll p;
ll a[N];

main(){
    n=in();
    int h=in(),w=in();
    cout<<(n-h+1)*(n-w+1);
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def shave(stack:list, nex:int, prv:int):
    res = prv-nex
    while res > 0:
        if res >= stack[-1][1]:
            _,y = stack.pop()
            res -= y
        else:
            stack[-1][1] -= res
            res = 0
            

def normalize(stack: list):
    if stack[-1][0] == stack[-2][0]:
        stack[-2][1] += stack[-1][1]
        stack.pop()
        
def add(stack:list):
    if stack[-1][1] == 1:
        stack[-1][0] += 1
    else:
        stack[-1][1] -= 1
        stack.append([stack[-1][0]+1, 1])
        
def kuriagari(stack:list):
    _, y = stack.pop()
    add(stack)
    normalize(stack)
    stack.append([1,y])
    
def check(a:list, upto:int):
    stack = [[0,0]]
    for i in range(n):
        if a[i+1] > a[i]:
            stack.append([1, a[i+1]-a[i]])
            normalize(stack)
        else:
            shave(stack, a[i+1], a[i])
            
            if stack[-1][0] == upto and stack[-1][1] == a[i+1]:
                return False

            elif stack[-1][0] == upto:
                kuriagari(stack)
            
            else:
                add(stack)
                normalize(stack)
                
    return True
   
    
def binsearch(a:list):
    low = 0
    high = 10**9+1
    
    while high-low > 1:
        mid = (high+low) // 2
        if check(a, mid):
            high = mid
        else:
            low = mid
            
    return high

n = ni()
a = [0] + list(li())
ans = binsearch(a)
print(ans)

Measured memory_bytes: 83152
open Printf open Scanf
open Array

let rv f p q = f q p

let () = scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  sort (rv compare) a;
  let ans = ref 0 in
  let dp = make (k+1) false in
  iteri (fun i v ->
    if v>=k then ans := i+1
    else (
      for w=k downto 1 do
        if dp.(w) then (
          if w+v < k then dp.(w+v) <- true
          else ans := i+1
        )
      done;
      dp.(v) <- true;
    )
  ) a;
  print_int @@ n - !ans





Measured memory_bytes: 4480
#include <iostream>
using namespace std;
int w, h, x, y, r;
void readInput() {
	cin >> w >> h >> x >> y >> r;
}
bool isOver() {
	if ((x - r) < 0) return true;
	if ((x + r) > w) return true;
	if ((y - r) < 0) return true;
	if ((y + r) > h) return true;
	return false;
}
int main() {
	readInput();
	if (isOver()) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
string str;
long long ans=0,res=0;
int main()
{
	cin>>str;
	for(int state=0;state<(1<<(str.length()-1));state++)
	{
		for(int i=0;i<str.length();i++)
		{
			res=res*10+str[i]-'0';
			if((state>>i)&1)
				ans+=res,
				res=0;
		}
		ans+=res;
		res=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;
int N,K;

int func(int n){
    int ans=0;
    while(n<K) {n*=2; ans++;}
    return ans;
}

int main(){
    cin >> N >> K;
    double ans = 0;
    for(int i=1;i<=N;i++){
        int jou = func(i);
        ans += pow(0.5, jou) / N;
    }
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll dp[51][2501] = {};
	
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, a; cin >> n >> a;
	vi x(n); rep(i, n) cin >> x[i];
	dp[0][0] = 1;
	
	rep(i, n){
		for(int j = i; j >= 0; j--) rep(k, 50 * j + 1) if(dp[j][k])
		dp[j + 1][k + x[i]] += dp[j][k];
	}
	ll ans = 0;
	for(int i = 1; i <= n && i * a <= 2500; i++) ans += dp[i][i * a];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

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

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll l, r;
	cin >> l >> r;

	ll ans = INT64_MAX;
	ll loopCnt = 0;

	bool isBreak = false;;
	for (ll i = l; i < r; i++) {
		for (ll j = i + 1; j <= r; j++) {
			if (loopCnt >= (ll)1e5) {
				isBreak = true;
				break;
			}


			ll score = (i * j) % 2019LL;
			ans = min(ans, score);

			loopCnt++;
		}

		if (isBreak) {
			break;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        if(n < 1200)
        {
            WriteLine("ABC");
        }
        else
        {
            WriteLine("ARC");
        }
        ReadLine();
    }
}


Measured memory_bytes: 17544
#include<stdio.h>

int main(){
  
  int i, n;
  int k=10000;
  int A[2000000], B[2000000], C[10000]={};
  scanf("%d",&n);
  for(i=1;i<n+1;i++)
    scanf("%d",&A[i]);
  for(i=1;i<n+1;i++)
    C[A[i]]++;
  for(i=1;i<k+1;i++)
    C[i]=C[i]+C[i-1];
  for(i=n;i>=1;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
  for(i=1;i<n+1;i++){
    if(i!=n) printf("%d ",B[i]);
    else printf("%d\n",B[i]);
  }
  return 0;
}



Measured memory_bytes: 17448
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
using namespace std;
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  string s; cin>>s; int k=0,n=s.size(); 
  for(int i=0;i<=n-1;i++)
  {  
    int c=s[i]-48; 
    k=(k+c)%9; 
  }
  if(!k){puts("Yes"); } else puts("No");  
  return 0; 
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    int originA = ceil(A / 0.08);
    int originB = ceil(B / 0.1);

    int maxA = ceil((A+1) / 0.08);
    int maxB = ceil((B + 1) / 0.1);

//    cout << originA << maxA << originB << maxB << endl;

    if (max(originA, originB) < min(maxA, maxB)) {
        cout << max(originA, originB) << endl;
    } else {
        cout << "-1" << endl;
    }
}



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

int s[100];

int main(){
	int n;
	while(scanf("%d", &n),n){
		for(int i = 0; i < n; i++) scanf("%d", &s[i]);
		sort(s,s+n);
		int sum = 0;
		for(int i = 1; i < n-1; i++){
			sum += s[i];
		}
		printf("%d\n", sum/(n-2));
	}
}

Measured memory_bytes: 1044
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,m; cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}

Measured memory_bytes: 256
while True:
    n_line = input()
    if n_line == "0":
        break
    score_a, score_b = (0, 0)
    for i in range(int(n_line)):
        a, b = [int(x) for x in input().split(" ")]
        if a > b:
            score_a += a + b
        elif a < b:
            score_b += a + b
        else:
            score_a += a
            score_b += b
    print("{} {}".format(score_a, score_b))

Measured memory_bytes: 7612
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char str[] = new char[s.length() + 5];
        int pos = 0;
        int spos = 0;
        /*
         * A = 1 BC = 2 その他 区切れ 3
         */
        Arrays.fill(str, '3');
        for (int i = 0; i < s.length(); i++) {
            if (spos == s.length()) {
                break;
            }
            if (s.charAt(spos) == 'A') {
                str[pos] = '1';
                pos++;
                spos++;
            } else if (s.charAt(spos) == 'B') {
                if (spos == s.length() - 1) {
                    str[pos] = '3';
                    break;
                }
                if (s.charAt(spos + 1) == 'C') {
                    str[pos] = '2';
                    pos++;
                    spos++;
                    spos++;
                } else if (s.charAt(spos + 1) == 'A') {
                    str[pos] = '3';
                    str[pos + 1] = '1';
                    pos++;
                    pos++;
                    spos++;
                    spos++;
                } else {
                    str[pos] = '3';
                    pos++;
                    spos++;
                    spos++;
                }
            } else {
                str[pos] = '3';
                pos++;
                spos++;
            }
        }
        long ans = 0;
        long bccnt = 0;
        long acnt = 0;
        for (int i = 0; i < s.length() + 1; i++) {
            if (str[i] == '3') {
                ans += bccnt;
                bccnt = 0;
                acnt = 0;
            }
            if (str[i] == '1') {
                acnt++;
            }
            if (str[i] == '2') {
                bccnt += acnt;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 28380
import java.io.*;
import java.util.*;
// i want to become the best
class Main{
	public static HashMap<Long,Integer> hmprod = new HashMap<>();
	public static HashMap<Long,Integer> hmlcm = new HashMap<>();
	//public static long[] list = new 
	public static void main(String[] args) throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		long[] list = Arrays.stream(reader.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	    //System.out.println(list[1]*list[2]>=list[0]?"Yes":"No");
		long gcd = list[0];
		for(int i = 0;i<n;i++){
			if(i!=0) {
				gcd = GCD(gcd,list[i]);
			}
			//lcm(list[i]);
			prod(list[i]);
		}
		if(hmprod.equals(hmlcm)) System.out.println("pairwise coprime");
		else if(gcd==1) System.out.println("setwise coprime");
		else System.out.println("not coprime");
	}
	static long GCD(long a, long b) 
    { 
    	long sum = a+b;
    	b = Math.max(b,a);
    	a = sum-b;
     while (b > 0)
    {
        long temp = b;
        b = a % b; // % is remainder
        a = temp;
    }
    return a;    } 
	public static void prod(long a){
		if(a%2==0){
			int j = 0;
			while(a%2==0){
				a=a/2;
				j++;
			}
			hmprod.put(2L,j+hmprod.getOrDefault(2L,0));
			hmlcm.put(2L,Math.max(j,hmlcm.getOrDefault(2L,0)));
		}
		for(long i = 3;i*i<=a;i=i+2){
			if(a%i==0){
				int cnt = 0;
				while(a%i==0){
					a=a/i;
					cnt++;
				}
				hmprod.put(i,cnt+hmprod.getOrDefault(i,0));
				hmlcm.put(i,Math.max(cnt,hmlcm.getOrDefault(i,0)));
			}
		}
		if(a!=1) hmprod.put(a,1+hmprod.getOrDefault(a,0));
		if(a!=1) hmlcm.put(a,Math.max(1,hmlcm.getOrDefault(a,0))); 
	}
}
class pair implements Comparable<pair>{
		long a = 0;
		int b = 0;
		public pair(long a,int b){
			this.a = a;
			this.b = b;
		}
		@Override
		public int compareTo(pair p){
			if(this.a == p.a) return -(Integer.compare(this.b,p.b));
			else return -(Long.compare(this.a,p.a));
		}
		@Override
		public String toString(){
			return a+" "+b;
		}
	}


Measured memory_bytes: 165672
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

vector<int> merry = {1,2,1,2,1,4,1,4};

int cannotGetIn(vector<int> c, int n) {
    vector<int> merry2;
    FOR(i,n,8) {
        merry2.push_back(merry[i]);
    }
    REP(i,n) {
        merry2.push_back(merry[i]);
    }
    int cnt = 0;
    REP(i,8) {
        cnt += max(0,c[i]-merry2[i]);
    }
    return cnt;
}

vector<int> getMerry(int n) {
    vector<int> merry2;
    FOR(i,n,8) {
        merry2.push_back(merry[i]);
    }
    REP(i,n) {
        merry2.push_back(merry[i]);
    }
    return merry2;
}

int getNum(vector<int> v) {
    int ans = 0;
    int ord = 10000000;
    REP(i,8) {
        ans += v[i]*ord;
        ord /= 10;
    }
    return ans;
}

int main() {
    vector<int> c(8);
    while(cin>>c[0]>>c[1]>>c[2]>>c[3]>>c[4]>>c[5]>>c[6]>>c[7]) {
        int over = 1e9;
        int ans = 1e9;
        REP(i,8) {
            int l = cannotGetIn(c, i);
            if (l == over) {
                ans = min(ans,getNum(getMerry(i)));
            }
            if (l < over) {
                ans = getNum(getMerry(i));
                over = l;
            }
        }
        REP(i,7) {
            cout << to_string(ans)[i] << " ";
        }
        cout << to_string(ans)[7] << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int alice = 0;
    int bob = 0;
    for (int i=n-1; i>=0; i--) {
        if (n % 2 == 0) {
            if ((i + 1) % 2 == 0) alice += a[i];
            else bob += a[i];
        } else {
            if (i % 2 == 0) alice += a[i];
            else bob += a[i];
        }
    }
    cout << alice - bob << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << 2 * a - 1 << endl;
  }else if (a < b){
    cout << 2 * b - 1 << endl;
  }else {
    cout << 2 * a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\n"
ll fact(int a)
{   if(a==0) return 1;
    return a*fact(a-1);
}
using namespace std;

int main()
{    ios::sync_with_stdio(0); cin.tie(0);
     ll n,m;
     cin>>n>>m;
     
     cout<<(n*(n-1))/2 + (m*(m-1))/2;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

class Po {
public:
	long long a;
	int yo;
	Po() {};
	bool operator<(Po &rdt) {
		return this->a < rdt.a;
	}
	bool operator>(Po &rdt) {
		return this->a > rdt.a;
	}
};

int w, h;
long long n, ans = 0;
vector<long long> p, q;
vector<Po> pq;
vector<long long> ps, qs, pqs;

int main() {
	cin >> w >> h;
	p.resize(w);
	ps.resize(w);
	q.resize(h);
	qs.resize(h);
	pq.resize(w + h);
	pqs.resize(w + h);
	for (int i = 0; i < w; i++) {
		cin >> p[i];
		pq[i].a = p[i];
		pq[i].yo = 0;
		pqs[i] = 1;
		ps[i] = 1;
	}
	for (int i = 0; i < h; i++) {
		cin >> q[i];
		pq[w + i].a = q[i];
		pq[w + i].yo = 1;
		pqs[w + i] = 1;
		qs[i] = 1;
	}

	sort(pq.begin(), pq.end());
	long long a = w, b = h;
	for (int i = 0; i < w + h;i++) {
		if (pq[i].yo == 0) {
			pqs[i] += b;
			a--;
		}
		else {
			pqs[i] += a;
			b--;
		}
		ans += pqs[i] * pq[i].a;
	}



	cout << ans << endl;
	//cin >> n;
	return 0;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;


int A,B,C,X,Y;
int ans;
int main(){
    cin>>A>>B>>C>>X>>Y;
    if(min(A,B) > C*2){
        ans += C*2*max(X,Y);
    }
    else if(A+B > C*2){
        ans+=C*2*min(X,Y);
        if(X>Y){
            if(A > C*2){
                ans += (X-Y)*C*2;
            }
            else ans+=(X-Y)*A;
        }else{
            if(B > C*2){
                ans += (Y-X)*C*2;
            }
            else ans+=(Y-X)*B;
        }
    }else{
        ans+=A*X+B*Y;
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
#include<queue>
#include <cstdint>


using namespace std;
int comp(const void* a,const void *b){
	if(*((long *)a)>*(long *)b){
		return 1;
	}else if(*((long *)a)==*(long *)b){
		return 0;
	}else{
		return -1;
	}
}
int main() {
	uint64_t n,k;
	cin>>n>>k;
	uint64_t *a = new uint64_t[n];
	for(uint64_t i=0;i<n;i++){
		cin>>a[i];
	}
	uint32_t count1[64];
	for(int i=0;i<64;i++){
		count1[i]=0;
		for(uint64_t j=0;j<n;j++){
			if(a[j]&((uint64_t)1<<i)){
				count1[i]++;
			}
		}
	}
	uint64_t freesum=0;
	uint64_t obeysum = 0;
	for(int i=0;i<64;i++){
		if(k&((uint64_t)1<<i)){
			obeysum = max((n-count1[i])*((uint64_t)1<<i)+obeysum,freesum+count1[i]*((uint64_t)1<<i));
		}else{
			obeysum = obeysum + count1[i]*((uint64_t)1<<i);
		}
		if(count1[i]<=(n/2)){
			freesum = freesum + (n-count1[i])*((uint64_t)1<<i);
		}else{
			freesum = freesum + count1[i]*((uint64_t)1<<i);
		}
	}
	cout<<obeysum<<endl;
	delete[] a;
	return 0;

}


Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys
from collections import deque

def solve(n: int, a: "List[int]"):
    ## 左右左と追加していく
    li = deque()

    for i in range(n):
        if i%2==0:
            li.appendleft(a[i])
        else:
            li.append(a[i])
    
    if n%2 == 0:
        li = list(li)[::-1]
    
    
    print(" ".join(map(str,list(li))))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48312
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
string s;

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

	int x = 0;
	int ans = 0;

	for (int i = 0;i < n;i++) {
		if (s[i] == 'I') x++;
		else x--;
		ans = max(ans, x);
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    int N;cin>>N;
    int C[N],S[N],F[N];
    C[0]=0;S[0]=0;F[0]=0;
    for(int i=1;i<N;i++)cin>>C[i]>>S[i]>>F[i];
    for(int i=1;i<N;i++){
        int now=0;
        for(int j=i;j<N;j++){
            if(now<S[j])now=S[j]+C[j];
            else if(now%F[j]==0)now+=C[j];
            else now=S[j]+(now-S[j]+F[j]-1)/F[j]*F[j]+C[j];
        }
        cout<<now<<endl;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int H = scanner.nextInt();
		int W = scanner.nextInt();
		
		scanner.close();

		int Hatake = H * W;
		int Michi = H + W - 1;
		int A = Hatake - Michi;
		

		System.out.println(A);

	}
}

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

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

	long long a, b, c; cin >> a >> b >> c;
	long long k; cin >> k;
	if (k % 2 == 0)cout << a - b;
	else cout << b - a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Stack;

// ALDS1_3_D
public class Main {
	void run() throws IOException {
		Stack<Integer> st = new Stack<Integer>();
		ArrayDeque<Integer> area = new ArrayDeque<Integer>();
		ArrayList<Integer> height = new ArrayList<Integer>();
		int A = 0; int k = 0; int L = 0; int h = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split("");
		int len = str.length;
		// /の高さを格納
		for (int i = 0; i < len; i++) {
			switch(str[i]) {
			case "\\":
				h--;
				height.add(null);
				break;
			case "/":
				height.add(h);
				h++;
				break;
			default:
				height.add(null);
				break;
			}
		}
		h = 0;
		// \を格納する際に，それ以降に対応する/がない場合は格納しない処理をとる
		for (int i = 0; i < len; i++) {
			switch(str[i]) {
			case "\\":
				h--;
				if (height.subList(i, height.size()).contains(h)) st.push(i);
				break;
			case "/":
				if (!st.empty()) {
					int l = i - st.pop();
					A = A + l;
					L = L + l;
					if (st.empty()) {
						area.addLast(L);
						k += 1;
						L = 0;
					}
				}
				h++;
				break;
			case "_":
				if (i == len) 
				break;
			default:
				break;
			}
		}
		System.out.println(A);
		System.out.print(k);
		for (Integer n : area) {
			System.out.print(" " + n);
		}
		System.out.println();
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}


Measured memory_bytes: 30044
k = int(input())

a = []

def dfs(x):
    if x > 3234566667:
        return
    a.append(x)
    for i in range(10):
        if abs(x % 10 - i) <= 1:
            dfs(x * 10 + i)

for i in range(1, 10):
    dfs(i)

a = sorted(a)
print(a[k - 1])


Measured memory_bytes: 8512
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, d = map(int, readline().split())
xy = map(int, read().split())

cnt = 0

for x, y in zip(xy, xy):
    if d >= (x**2 + y**2)**0.5:
        cnt += 1

print(cnt)


Measured memory_bytes: 36664
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V< V< P<int, int> > > xy(n);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y; cin >> x >> y;
            xy[i].emplace_back(x - 1, y);
        }
    }

    int ans = 0;
    for (int state = 0; state < (1 << n); state++) {
        bool all_honest = true;
        for (int i = 0; i < n; i++) {
            if ((state >> i) & 1) {
                for (P<int, int> tmpxy: xy[i]) {
                    if ( tmpxy.second == 1 && (!((state >> tmpxy.first) & 1)) ) {
                        all_honest = false;
                    }
                    if ( tmpxy.second == 0 && ((state >> tmpxy.first) & 1) ) {
                        all_honest = false;
                    }
                }
            }
        }
        if (all_honest) chmax(ans, __builtin_popcount(state));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main(){
    ll n, m;
    cin >> n >> m;
    priority_queue<pair<ll, pair<ll, ll>>> que;
    REP(i, n){
        ll a;
        cin >> a;
        que.push({a, {0, a}});
    }
    REP(i, m){
        auto tmp = que.top(); que.pop();
        ll a = tmp.first, b = tmp.second.second, c = tmp.second.first;
        que.push({(b >> (c + 1)), {c + 1, b}});
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top().first;
        que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4852
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        mut d: [usize; n],
    }
    d.sort();
    let x = d[n / 2 - 1];
    let y = d[n / 2];
    println!("{}", y - x);
}


Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll sz;
ll power(ll x, ll y){
    ll ret = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1) {
            ret = (ret * x) % MOD;
        }
        y >>= 1LL;
        x = (x * x) % MOD;
    }
    return ret;
}
ll modInverse(ll num){
    ll M = MOD;
    return power(num, M - 2);
}
ll fac[1000001];

ll arr[1000001];
map<pair<ll, ll>, ll> mapa;
ll nCr(ll n, ll r){
    if(r == 0)return 1;
    if(n < r)return 0;
    if(mapa.find(make_pair(n, r)) != mapa.end())return mapa[make_pair(n, r)];
    return mapa[make_pair(n, r)] = (fac[n] * modInverse(fac[r]) % MOD * modInverse(fac[n - r]) % MOD) % MOD;
}
ll idx[1000001];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
//    cout << nCr(10, 2);
    fac[0] = 1;
    for(ll i = 1; i <= 1000000; i ++){
        fac[i] = fac[i - 1] * i % MOD;
    }
    cin >> sz;
    sz ++;
    set<ll> st;
    memset(idx, -1, sizeof idx);
    ll tmp1, tmp2;
    for(int i = 0; i < sz; i ++){
        cin >> arr[i];
        if(idx[arr[i] - 1] == -1){
            idx[arr[i] - 1] = i;
        }
        else{
            tmp1 = idx[arr[i] - 1];
            tmp2 = i;
        }
        st.insert(arr[i]);
    }
//    cout << nCr(4, 4) << endl;
    cout << (int)st.size() << endl;
    
    for(ll i = 2; i <= sz; i ++){
        ll t =  nCr(sz, i) - nCr(tmp1 + (sz - tmp2 - 1), i - 1);
        if(t < 0)t += MOD;
        cout <<t << endl;
    }
    
//    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 37760
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n]    <- readInt
  cities <- map toPair <$> readInts n
  print $ solve n cities

solve :: Int -> [(Int, Int)] -> Double
solve n c = sum (map (\b -> f b cities 0) bit)
  / fromIntegral (product [1, 2 .. n])
 where
  cities = V.map (\(x, y) -> (fromIntegral x, fromIntegral y)) $ V.fromList c
  bit    = permutations [0, 1 .. n - 1]

f :: [Int] -> V.Vector (Double, Double) -> Double -> Double
f [_         ] _ acc = acc
f (x : y : xs) c acc = f (y : xs) c (acc + g (c V.! x) (c V.! y))

g (x, y) (a, b) = sqrt ((a - x) ^ 2 + (b - y) ^ 2)




Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int N;
    cin >> N;
    if(1<=N && N<=999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
whxy = [ float(x) for x in input().split(" ")]
zyusinx = float(whxy[0] / 2)
zyusiny = float(whxy[1] / 2)

result2 = '0'
if zyusinx == whxy[2] and zyusiny == whxy[3]:
    result2 = '1'

square = float((whxy[0]*whxy[1]) / 2 )
print(str(square) + ' ' + result2)

Measured memory_bytes: 3064
N, W = map(int, input().split())
v, w = [], []
for _ in range(N):
    vv, ww = map(int, input().split())
    v.append(vv)
    w.append(ww)


'''
dp[i+1][ww]: i番目までの品物から容量がwを超えないように入れた時の価値の合計の最大値
0 <= ww <= W
0 <= i <= N
'''
# dp table
# (N+1)*(W+1)
dp = [[0]*(W+1)] # dp[0][ww]

for i in range(N):
    dp.append([0]*(W+1))
    for ww in range(W+1):
        if ww >= w[i]:
            dp[i+1][ww] = max(dp[i][ww], dp[i][ww-w[i]]+ v[i])
        else:
            dp[i+1][ww] = dp[i][ww]

print(dp[N][W])


Measured memory_bytes: 25496