akhauriyash/Code-Regression huggingface dataset:
cat_num, enemy_num = gets.split.map(&:to_i)
win_prob = (1..cat_num).map {gets.split.map(&:to_f)}

one_pos = []
(0..(1<<cat_num)-1).each do |x|
    one_pos[x] = (0..cat_num-1).select {|i| x[i] == 1}
end

table = [[1] * cat_num * 2 ** cat_num]
(1..enemy_num).each do |k|
    table.unshift([0] * cat_num * 2 ** cat_num)
    retry_best = [0] * 2 ** cat_num
    (1..(1<<cat_num)-1).each do |x|
        one_pos[x].each do |c|
            pr = win_prob[c][-k]
            y = (c << cat_num) + x
            table[0][y] = pr * table[1][y] + (1 - pr) * retry_best[x - (1 << c)]
            retry_best[x] = table[0][y] if table[0][y] > retry_best[x]
        end
    end
    table.pop
end
printf("%.10f\n", table[0].max)

Measured memory_bytes: 117568
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
void calc(vector<int>& a){
  int n=a.size();
  vector<int> tmp;
  rep(i,n){
    if(a[i]%2==1)tmp.push_back(a[i]);
  }
  rep(i,n){
    if(a[i]%2==0)tmp.push_back(a[i]);
  }
}
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  //sort(a.begin(),a.end());
  //sort(b.begin(),b.end());
  calc(a);
  calc(b);
  vector<int> sub(n,0);
  int sum_b=0;int sum_a=0;
  rep(i,n){
    sub[i]=b[i]-a[i];
    sum_a+=a[i];
    sum_b+=b[i];
  }
  bool ok=true;
  int k=sum_b-sum_a;
  if(k<0)ok=false;
  int even=0;
  rep(i,n){
    if(sub[i]>0){
      even+=sub[i]/2;
    }
  }
  int hoge=0;
  rep(i,n){
    if(sub[i]<0){
      even-=(-1)*sub[i];
      hoge-=sub[i];
    }
  }
  rep(i,n){
    //printf("sub[%lld]=%lld\n",i,sub[i]);
  }
  //cout<<hoge<<endl;
  if(hoge>k)ok=false;
  if(even<0)ok=false;
  if(ok)cout<<"Yes";
  else cout<<"No";
  cout<<endl;
  //cout<<even<<endl;
  return 0;
}


Measured memory_bytes: 640
from collections import deque


def main():
    h, w = map(int, input().split())
    cs = list(map(int, input().split()))
    ds = list(map(int, input().split()))
    S = [[s for s in input()] for _ in range(h)]

    curq = deque()
    nexq = deque([(cs[0] - 1, cs[1] - 1)])
    l = 0
    while len(nexq) > 0:
        curq, nexq = nexq, deque()
        while len(curq) > 0:
            y, x = curq.popleft()
            if S[y][x] != ".":
                continue

            S[y][x] = l
            for dy in range(-2, 3):
                for dx in range(-2, 3):
                    if 0 <= y + dy < h and 0 <= x + dx < w and S[y + dy][x + dx] == ".":
                        if abs(dx) + abs(dy) < 2:
                            curq.append((y + dy, x + dx))
                        else:
                            nexq.append((y + dy, x + dx))
        l += 1

    ans = S[ds[0] - 1][ds[1] - 1]
    print(ans if ans != "." else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 182576
#include <bits/stdc++.h>
/**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define LOG2(X) ((unsigned) (8*sizeof(int) - __builtin_clz((X)) - 1))
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int a[9];
int n;
int A, B, C;
int go(int i, int aa, int bb, int cc){
	if(i == n){
		if(aa>0 && bb>0 && cc>0)
			return abs(A-aa) + abs(B-bb) + abs(C-cc);
		return 1000000000;
	}
	int ans = 1000000000;
	ans = min(ans,go(i+1,aa,bb,cc));
	ans = min(ans, go(i+1, aa+a[i], bb, cc) + (aa > 0 ? 10 : 0));
	ans = min(ans, go(i+1, aa, bb+a[i], cc) + (bb > 0 ? 10 : 0));
	ans = min(ans, go(i+1, aa, bb, cc+a[i]) + (cc > 0 ? 10 : 0));
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	cin>>n>>A>>B>>C;
	for(int i=0; i<n; i++) cin>>a[i];
	cout<<go(0,0,0,0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    char a,b,c,ap=0,bp=0,cp=0;
    cin>>a>>b>>c;
    if(a=='a'){ap++;}
    if(a=='b'){bp++;}
    if(a=='c'){cp++;}
     if(b=='a'){ap++;}
    if(b=='b'){bp++;}
    if(b=='c'){cp++;}
     if(c=='a'){ap++;}
    if(c=='b'){bp++;}
    if(c=='c'){cp++;}
    if(ap==1 && bp==1 && cp==1)
    {
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    long long n,W,w[200000],v[200000],dp[101][100001]={0};
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i];
    rep(i,n)rep(j,W+1){
        if(j>=w[i]) dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
        else dp[i+1][j]=dp[i][j];
    }
    cout<<dp[n][W];
}

Measured memory_bytes: 82176
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 1000000007;

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

i32 inv (i32 a) {
  return mod_pow (a, mod - 2);
}

i32 *fact = NULL;
i32 *iFact = NULL;
void init_fact (const i32 n) {
  fact = (i32 *) calloc (n + 1, sizeof (i32));
  fact[0] = 1;
  for (i32 i = 1; i <= n; ++i) {
    fact[i] = (i64) i * fact[i - 1] % mod;
  }
  iFact = (i32 *) calloc (n + 1, sizeof (i32));
  iFact[n] = inv (fact[n]);
  for (i32 i = n - 1; i >= 0; --i) {
    iFact[i] = (i64) (i + 1) * iFact[i + 1] % mod;
  }
}

i32 comb (i32 n, i32 k) {
  if (!(0 <= k && k <= n)) return 0;
  return (i64) fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}

void run (void) {
  i32 b, w;
  scanf ("%" SCNi32 "%" SCNi32, &b, &w);
  init_fact (b + w);
  const i32 q = inv (2);
  char *s = (char *) calloc ((b + w) * 11, sizeof (char));
  char *buf = s;
  i32 ans = q;
  for (i32 i = 1, qq = (i64) q * q % mod; i <= b + w; ++i, qq = (i64) qq * q % mod) {
    if (ans == 0) {
      *(buf++) = '0';
      *(buf++) = '\n';
    } else {
      i32 t = ans;
      i32 d[10];
      i32 top = 0;
      while (t > 0) {
        d[top++] = t % 10;
        t /= 10;
      }
      while (top > 0) {
        *(buf++) = '0' + d[--top];
      }
      *(buf++) = i == b + w ? '\0' : '\n';
    }
    if (i >= b) {
      ans = (ans + (i64) comb (i - 1, b - 1) * (mod - qq)) % mod;
    }
    if (i >= w) {
      ans = (ans + (i64) comb (i - 1, w - 1) * qq) % mod;
    }
  }
  puts (s);
}

int main (void) {
  run();
  return 0;
}


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

#define F first
#define S second
#define B begin
#define E end
#define PB push_back

typedef vector<int> vi;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, d;
    ll p,q;
    cin>>n>>d;
    int cnt =0;
    while(n--){

      cin>>p>>q;
      if(sqrt(p*p+q*q) <= d)
        cnt++;
    }
    cout<<cnt<<"\n";
}



Measured memory_bytes: 3544
s = gets.chomp
c = 0
a = 0
(s.size).downto(0){|i|
  if s[i]=='A'
    a += c
  elsif i>0 && (s[i-1]=='B' && s[i]=='C')
    c += 1
  elsif !(s[i]=='B' && s[i+1]=='C')
    c = 0
  end
}
p a

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

/*
templates for competitive programming
type long long -> type ll 
define constants : EPS, INF, MOD, PI
define macros : REP, FOR, ALL, SORT, REVERSE
define number theory functions: qp(a, b), qp(a, b, mo), gcd(a, b)
define dx, dy
*/
   typedef long long unsigned int ll;

   const double EPS = (1e-7);
   const int INF =(1e9);
   const double PI = (acos(-1));
   const int MOD = (int(1e9) + 7);

   #define REP(i, n) for(int i = 0; i < (int)(n); i++)
   #define FOR(i, a, b) for (int i = (a); i < (b); i++)
   #define ALL(x) (x).begin(),(x).end())
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

void solve() {

}

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll N;
   cin >> N;
   vector<ll> A(N), B(N), C(N);
   REP(i, N){
       cin >> A[i];
   }
   REP(i,N){
       cin >> B[i];
   }
   REP(i, N){
       cin >> C[i];
   }
   SORT(A);
   SORT(B);
   SORT(C);
   
   ll temp1 = 0;
   ll temp2 = 0;
   vector<ll> A_cum(N + 1);
   vector<ll> B_cum(N + 1);
   vector<ll> C_cum(N + 1);
   REP(i, N){
       C_cum[i + 1] = i + 1;
   }
   REP(i, N){
       while (B[i] >= C[temp1] && temp1 <= N - 1){
           temp1++;
       }
       B_cum[i + 1] = B_cum[i] + C_cum[N] - C_cum[temp1];
   }
   REP(i, N){
       while (A[i] >= B[temp2] && temp2 <= N - 1){
           temp2++;
       }
       A_cum[i + 1] = A_cum[i] + B_cum[N] - B_cum[temp2];
   }
   cout << A_cum[N] << endl;
}


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

int main(){
//	freopen("input","r",stdin);
	int n;
	scanf("%d",&n);
	int c[n+1],s[n+1],f[n+1];
	int time[n+1][n+1];
	for(int i=1;i<=n-1;i++){
		scanf("%d %d %d",&c[i],&s[i],&f[i]);
		
	}
	for(int i=1;i<=n-1;i++)
		time[i][i] = s[i];
	for(int i=1;i<=n-1;i++){
		for(int j=i+1;j<=n-1;j++){
			time[i][j] = time[i][j-1]+c[j-1] + (f[j] - (time[i][j-1]+c[j-1])%f[j])%f[j];
			time[i][j] = max(time[i][j],s[j]);
		}
	}
	for(int i=1;i<=n-1;i++)
		printf("%d\n",time[i][n-1]+c[n-1]);
	printf("0\n");
	return 0;
}


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

int main() {
  int N;
  cin >> N;

  vector<int> d(N);
  rep(i, N) cin >> d[i];

  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
using namespace std;

 struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ
    vector<int>sz;//要素数

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
            sz[i]=1;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
            sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
            sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	UF tree(n);
	vector<int> node;
	node.pb(1);
	bool ng = false;
	if((s[0]!='1')||(s[n-2]!='1'))
		ng = true;
	rep(i,n)
	{
		if(s[i]=='1'){
			if(s[n-2-i]=='1'){
				node.pb(i + 1);
			}
			else
				ng = true;
		}
	}
	if(s.back()=='1')
		ng = true;
	if(ng){
		cout << -1 << "\n";
		return;
	}
	node.pb(n);
	rep(i,node.size()-1){
		int sub = node[i + 1] - node[i];
		rep(j,sub){
			cout << node[i + 1] << " " << node[i + 1] - j - 1 << "\n";
		}
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3272
#include<iostream>
#include<vector>

using namespace std;
bool p[101];

void init_p(){
	for(int i = 2; i <= 100; i++){
		p[i] = true;
	}
	for(int i = 2; i <= 10; i++){
		if(p[i] == true){
			for(int j = i * 2; j <= 100; j *= i){
				p[j] = false;
			}
		}
	}
}

int main(){
	int n, ans = 0;
	cin >> n;
	init_p();
	vector<int> c(101), prime;
	for(int i = 2; i <= n; i++){
		if(p[i]) prime.emplace_back(i);
	}
	for(int i = 2; i <= n; i++){
		int t = i;
		for(int j = 0; j < prime.size(); j++){
			int q = prime[j];
			while(t % q == 0){
				c[q]++;
				t /= q;
			}
		}
	}
	int c2 = 0, c4 = 0, c14 = 0, c24 = 0, c74 = 0;
	for(int i = 2; i <= n; i++){
		if(c[i] >= 2) c2++;
		if(c[i] >= 4) c4++;
		if(c[i] >= 14) c14++;
		if(c[i] >= 24) c24++;
		if(c[i] >= 74) c74++;
	}
	if(c4 >= 2 && c2 >= 1) ans += c4 * (c4 - 1) / 2 * (c2 - 2);
	if(c14 >= 1 && c4 >= 1) ans += c14 * (c4 - 1);
	if(c24 >= 1 && c2 >= 1) ans += c24 * (c2 - 1);
	if(c74) ans += c74;
	cout << ans << endl;
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unsigned long long x;
    cin >> x;
    unsigned long long sum=100;
    unsigned long long year =0;
    while(1){
        sum += 0.01*sum;
      //  cout << sum << " ";
        year++;
        if(sum>=x){
            cout << year;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3612
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int, input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    # print(N)
    # print(M)
    # print(sc)
    # 1桁
    if N == 1:
        for i in range(10):
            string_i = str(i)
            ok = True
            for s,c in sc:
                if string_i[s-1] != str(c):
                    ok = False
            if ok:
                print(i)
                return 
        else:
            print(-1)
            return
    # 2桁以上
    else:
        start = 10 ** (N-1)
        end = 10 ** (N)
        for i in range(start, end): #2桁なら10から99,3桁なら100から999
            string_i = str(i)
            ok = True
            for s,c in sc:
                if string_i[s-1] != str(c):
                    ok = False
            if ok:
                print(i)
                return 
        else:
            print(-1)
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

int cnt[10][10];

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++){
    string s = to_string(i);
    cnt[s[0] - '0'][s[sz(s) - 1] - '0']++;
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) ans += cnt[i][j] * cnt[j][i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3780
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    for (int i = 0; i < N; i++)
    {
        if ((i + 1) == K)
        {
            if (S[i] == 'A')
            {
                cout << 'a';
            }
            if (S[i] == 'B')
            {
                cout << 'b';
            }
            if (S[i] == 'C')
            {
                cout << 'c';
            }
        }
        else
        {
            cout << S[i];
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    string s; cin>>s;
    map<char, int> m;
    for(char c : s) 
        m[c]++;
    if(m.size() == 2){
        for(auto ele : m)
            if(ele.second != 2){
                OUT("No");
                return 0;
            }
        OUT("Yes");
        return 0;
    }
    OUT("No");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,i,j,T,N,sum=0,all_sum=0,ans=0;
  scanf("%d",&N);
  int W[N];

  for(i=0;i<N;i++){
    scanf("%d",&W[i]);
    all_sum += W[i];
  }
 
  
  for(j=0;j<N;j++){
    sum+=W[j];
    if(sum >= all_sum/2){
      break;
    }
  }
  j++;


  a = (all_sum/2) - (sum-W[j-1]);
  b = sum - (all_sum/2);

  
  if(a >= b){
    T = j;
 
  }else{
    T = j-1;

  }

  a=0;
  b=0;
  
  for(i = 0;i<T;i++){
    a += W[i];
  }
  for(i=0;i<N-T;i++){
    b += W[N-1-i];
  }
  ans = a-b;
  if(ans<0) ans*=-1;
  
  printf("%d",ans);
  
  
  
  

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  int a, b;
  scanf("%d %d", &a, &b);
  if((a+b)%2 == 0){
    printf("%d\n", (a+b)/2);
  }else{
    printf("%d\n", (a+b+1)/2);
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int sum = a + b + c;
  int max = max(a, max(b ,c));
  int ans;
  rep(i, max, max + 2) {
    if ( (i * 3 - sum) % 2 != 0 ) continue;
    ans = (i * 3 - sum) / 2;
    break;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int N,T,H,L;
int t[111];
int h[111];
int main(void){
  cin >> N >> T >> H >> L;
  for(int i = 0; i < N; i++){
    cin >> t[i] >> h[i];
  }

  int sum=0,i;
  for(i = 0;; i=(i+1)%N){
    if(t[i]){
      t[i]--;
      T++;
      sum += 10;
    }else{
      if(!h[i]) break;
      h[i]--;
      sum += 100;
    }
    if(T > L) break;
    if(sum >= 90){
      if(sum-90 > T*10) break;
      t[i] += sum/10-9;
      T -= sum/10-9;
      sum = 0;
    }
  }
  cout << i + 1 << endl;
}

Measured memory_bytes: 1164
import itertools
import numpy as np
N = int(input())
xy = np.array([list(map(int, input().split())) for i in range(N)])
p = itertools.permutations(range(N))
print(np.mean([np.linalg.norm(xy[list(p_i)[:-1]]-xy[list(p_i)[1:]], axis=1).sum() for p_i in p]))

Measured memory_bytes: 25264
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
#include<algorithm>
using namespace std;


int main() {
	string s;
	cin >> s;
	int sum=0;
	int ans = 0;
	for (int i = 0;i < s.size();i++)
	{
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'T' || s[i] == 'G')
		{
			sum++;
		}
		else
		{
			if (ans < sum)
			{
				ans = sum;
				sum = 0;
			}
		}
	}
	if (ans < sum)
	{
		ans = sum;
		sum = 0;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int X;
  if (1 <= b && b <= 9){
    X = 10 * a + b;
  }
  else if (10 <= b && b <= 99){
    X = 100 * a + b;
  }
  else{
    X = 1000 * a + b;
  }
  for(int k=1;k<1001;k++){
    if (k * k == X) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>


signed main(){
	
	int x,y;cin >>x>>y;
	int ans;
	
	if(x*y>0)
	{
		if(x<=y) ans = y-x;
		else ans =x-y+2;
	}
	
	if(x*y < 0)
	{
		x=abs(x),y=abs(y);
		ans = abs(x-y)+1;
	}
	
	if(x*y==0)
	{
		if(x==0 and y==0) ans=0;
		else if(x==0)
		{
			if(y<0) ans = -y+1;
			else ans = y;
		}
		else if(y==0)
		{
			if(x<0) ans = -x;
			else ans = x+1;
		}		
	}
	
	
	
	cout << ans << endl;
	
}

Measured memory_bytes: 256
use proconio::{input,fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize; n],
    }

    a.sort();
    a.reverse();

    let ans = (0..n - 1).map(|k| a[(k + 1) / 2]).sum::<usize>();
    println!("{}", ans);


}


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

int main() {
  
  long long N,ans;
  cin >> N;
  
  vector<long long> A(N),B(N);
  
  for (int i=0; i<N; i++) {
    cin >> A[i] >> B[i];
  }
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  
  if (N % 2 == 0) {
    ans = B[N/2] + B[N/2-1] - A[N/2] - A[N/2-1];
    ans++;
  }
  else {
    ans = B[N/2] - A[N/2];
    ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 6428
package main

import "fmt"

func main() {
	var N, D int
	fmt.Scanf("%d", &N)
	fmt.Scanf("%d", &D)

	if (N % (2 * D + 1)) == 0 {
		fmt.Println(N / (2 * D + 1))
	} else {
		fmt.Println(N / (2 * D + 1) + 1)
	}
}


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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 1001001001;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];

int main(){
    int n,k;cin >> n >> k;
    int div = n;
    vector<int> v;
    while (div != 0) {
        v.push_back(div%k);
        div/=k;
    }
    cout << v.size() << endl;
}



Measured memory_bytes: 4352
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let soc = split_on_char

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let t = rds () in
  let result = S.map (fun c ->
    match c with
    | '?' -> 'D'
    | x -> x
  ) t in
  puts result
;;


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

int main()
{
  while(true){
    int n, q;
    cin >> n;
    cin >> q;
    if(n == 0 && q == 0) break;

    int v[101] = {0};
    int m, day;
    for(int i = 0 ; i < n ; i++){
      cin >> m;
      for(int j = 0 ; j < m ; j++){
	cin >> day;
	v[day]++;
      }
    }
    int max = q - 1, d = 0;
    for(int i = 1 ; i <= 100 ; i++){
      if(max < v[i]){
	max = v[i];
	d = i;
      }
    }
    cout << d << '\n';
  }
  
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 18;
const int INF = 1e4;
int n,ans;
int a[mxN+3],b[mxN+3],c[mxN+3],d[mxN+3],p[mxN+3],p2[mxN+3];

bool cmp(int x,int y) {return c[x]<c[y]||(c[x]==c[y]&&x<y);}

void solve()
{
//	printf("solve\n");
//	for(int i=1; i<=n; i++) printf("%d ",c[i]); puts("");
//	for(int i=1; i<=n; i++) printf("%d ",d[i]); puts("");
	for(int i=1; i<=n; i++) p[i] = i;
	sort(p+1,p+n+1,cmp);
	for(int l=1; l<=n; l++)
	{
		int r = l; while(r<n&&c[p[r+1]]==c[p[l]]) {r++;}
		int cnt0 = 0,cnt1 = 0;
		for(int i=l; i<=r; i++) {if(i&1) cnt1--; else cnt0--;}
		for(int i=l; i<=r; i++) {if(d[p[i]]) cnt1++; else cnt0++;}
//		printf("[%d,%d]",l,r); puts("");
		if(cnt0||cnt1) return;
		for(int i=l,j0=l,j1=l; i<=r; i++)
		{
			if(i&1)
			{
				while(j1<r&&!d[p[j1]]) {j1++;}
				p2[i] = p[j1]; j1++;
			}
			else
			{
				while(j0<r&&d[p[j0]]) {j0++;}
				p2[i] = p[j0]; j0++;
			}
		}
		l = r;
	}
	int ret = 0;
	for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) ret += (p2[i]>p2[j]);
	ans = min(ans,ret);
}

int main()
{
	n = read(); ans = INF;
	for(int i=1; i<=n; i++) a[i] = read();
	for(int i=1; i<=n; i++) b[i] = read();
	for(int sta=0; sta<(1<<n); sta++)
	{
		for(int i=1; i<=n; i++)
		{
			c[i] = (sta&(1<<i-1))?b[i]:a[i];
			d[i] = ((sta>>i-1)^i)&1;
		}
		solve();
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}

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

int main() {
  int X, fx=0;
  cin >>X;
  
  // ここにプログラムを追記
  int tmp_X = X;
  while(tmp_X != 0){
  	fx +=tmp_X%10;
    tmp_X/=10;
  }
  if (X%fx)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

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

void Main()
{
    long n;
    cin >> n;
    long a[n+1];
    long node = 1;
    long n_node[n+1];
    for(int i = 0; i <= n; ++i ){
        cin >> a[i];
    }
    for(int i = n; i >= 0; --i ){
        if(i == n){
            n_node[i] = a[i];
        }else{
            n_node[i] = n_node[i+1] + a[i];
        }
        
        // cerr << i << ": " << n_node[i] << endl;
    }
    for(int i = 0; i <= n; ++i ){
        if(node <= 0 || n_node[i] <= 0){
            cout << -1 << endl;
            return;
        }
        if(node < n_node[i]){
            n_node[i] = node;
        }
        if(n_node[i] < node){
            node = n_node[i];
        }
        // cerr << i << ": " << node << ' ' << a[i] << endl;

        node = 2 * (node - a[i]);
        if(i == n && node != 0){
            cout << -1 << endl;
            return;
        }
    }
    unsigned long usum = 0;
    for(int i = 0; i <= n; ++i ){
        usum += (unsigned long)(n_node[i]);
    }

    cout << usum << endl;

    // 0 0
    // 1 00
    // 2 0001
    // 3 000000
    // 4 000000000011

    // 0 0
    // 1 0   0
    // 2 0 0 1
    // 3 0 0
    // 4 1 1

    // 0 0
    // 1 

}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 5200
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int itr = 0;
vector<vector<int>> tree(10000);
vector<int>  V(10000), c(10000);
ll ans;
void dfs(int n, int per) {
    for (auto e : tree[n]) {
        if (e != per) {
            dfs(e, n);
        }
    }
    V[n] = c[itr];
    if (n != 0) ans += c[itr];
    itr++;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i, N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    REP(i, N) {
        cin >> c[i];
    }
    sort(c.begin(),c.begin()+N);
    dfs(0, -1);
    cout << ans << endl;
    REP(i, N) {
        cout << V[i] << " ";
    }
    cout << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std ;
int main () {
  int N;
  cin>>N;
  double ans=0;
    for(int i=0; i<N;i++){
      double num;
      string s;
      cin >> num >> s;
      if(s== "BTC"){
        num *= 380000;
        ans += num;
      }else{
        ans += num;
      }
    }
   cout<<ans<<endl;
   return 0;
}

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

int main()
{

int k;
  cin>>k;
 string s;
  cin>>s;
  if(s.length()<=k)
  {
  cout<<s;
    return 0;
  }
  else
  {
     string neww=s.substr(0,k);
    neww+="...";
    cout<<neww;
  }
  
   
}

Measured memory_bytes: 3628
// 4_abc127_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<pair<int, int>> p(m);
    rep(i, m){
        int b, c;
        cin >> b >> c;
        p[i] = make_pair(c, b);
    }
    sort(p.begin(), p.end(), greater<pair<int, int>>());

    int cnt = 0;
    int flag = 0;
    rep(i, m){
        int b = p[i].second;
        int c = p[i].first;
        rep(j, b){
            a[cnt] = max(a[cnt], c);
            cnt++;
            if(cnt == n){
                flag = 1;
                break;
            }
        }
        if(flag) break;
    }

    ll ans = 0;
    rep(i, n){
        ans += a[i];
    }

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


Measured memory_bytes: 1408
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let xs1 = input.trim().split('').map(v=>parseInt(v,10));
   let x =0;
   for(let i=0; i<xs1.length; i++){
   x += xs1[i];
   }
   if(xs[0]%x==0){
     console.log('Yes');
   }else{
     console.log('No');
   }
  }
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(){
    double n,m,a=0,sum=0,l,ans;
    int s[10000]={};
    while(1){
        cin>>n;
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            cin>>l;
            s[i]=l;
            sum=sum+l;
        }
        m=sum/n;
        for(int i=0;i<n;i++){
            a=a+(((s[i]-m)*(s[i]-m))/n);
        }
        ans=sqrt(a);
        printf("%.8lf\n", ans);
        sum=0;
        a=0;
    }
    return 0;
}


Measured memory_bytes: 3264
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int N,M,D,k=0,sum=0;
	char C;
	cin>>N>>M>>D;
	int A[N+2][M+2]={0};
	for(int i=1;i<=N;i++){
		for(int j=1;j<=M;j++){
			cin>>C;
			if(C=='.'){A[i][j]=1;}
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=M;j++){
			if(A[i][j]==1){
				k=0;
				while(1){
					if(A[i][j+k]!=1){break;}
					else if(k>=D-1){sum++;break;}
					k++;
				}
				k=0;
				while(1){
					if(A[i+k][j]!=1){break;}
					else if(k>=D-1){sum++;break;}
					k++;
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


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


int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if(K-A <=0){
    cout << K <<endl;
  }
  
  else if(K-A-B <=0){
    cout << A <<endl;
  }
  
  else{
    cout << A+A-K+B <<endl;
  }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    i64 m = N / 1000 + (N % 1000 > 0);
    i64 ans = 1000 * m - N;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
def resolve():
	xmin,ymin=0,0
	w,h,n=map(int,input().split())
	xmax,ymax=w,h
	for _ in range(n):
		x,y,a=map(int,input().split())
		if a==1:
			xmin=max(x,xmin)
		elif a==2:
			xmax=min(x,xmax)
		elif a==3:
			ymin=max(y,ymin)
		else:
			ymax=min(y,ymax)
	print((max(xmax-xmin,0))*max((ymax-ymin),0))
resolve()

Measured memory_bytes: 38256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
int dp[maxn],h[maxn];
int main(){
	migmig;
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	dp[1]=0;
	for(int i=2;i<=n;i++){
		dp[i]=inf;
	}
	for(int i=2;i<=k;i++){
		for(int j=1;j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	for(int i=k+1;i<=n;i++){
		for(int j=i-k;j<=i;j++){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n];
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
typedef long long int ll;
using namespace std;
ll a[205] = {0,1,32,243,1024,3125,7776,16807,32768,59049,100000,161051,248832,371293,537824,759375,1048576,1419857,1889568,2476099,3200000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176,69343957,79235168,90224199,102400000,115856201,130691232,147008443,164916224,184528125,205962976,229345007,254803968,282475249,312500000,345025251,380204032,418195493,459165024,503284375,550731776,601692057,656356768,714924299,777600000,844596301,916132832,992436543,1073741824,1160290625,1252332576,1350125107,1453933568,1564031349,1680700000,1804229351,1934917632,2073071593,2219006624,2373046875,2535525376,2706784157,2887174368,3077056399,3276800000,3486784401,3707398432,3939040643,4182119424,4437053125,4704270176,4984209207,5277319168,5584059449,5904900000,6240321451,6590815232,6956883693,7339040224,7737809375,8153726976,8587340257,9039207968,9509900499,10000000000,10510100501,11040808032,11592740743,12166529024,12762815625,13382255776,14025517307,14693280768,15386239549,16105100000,16850581551,17623416832,18424351793,19254145824,20113571875,21003416576,21924480357,22877577568,23863536599,24883200000,25937424601,27027081632,28153056843,29316250624,30517578125,31757969376,33038369407,34359738368,35723051649,37129300000,38579489651,40074642432,41615795893,43204003424,44840334375,46525874176,48261724457,50049003168,51888844699,53782400000,55730836701,57735339232,59797108943,61917364224,64097340625,66338290976,68641485507,71008211968,73439775749,75937500000,78502725751,81136812032,83841135993,86617093024,89466096875,92389579776,95388992557,98465804768,101621504799,104857600000,108175616801,111577100832,115063617043,118636749824,122298103125,126049300576,129891985607,133827821568,137858491849,141985700000,146211169851,150536645632,154963892093,159494694624,164130859375,168874213376,173726604657,178689902368,183765996899,188956800000,194264244901,199690286432,205236901143,210906087424,216699865625,222620278176,228669389707,234849287168,241162079949,247609900000,254194901951,260919263232,267785184193,274794888224,281950621875,289254654976,296709280757,304316815968,312079600999};
int main(){
	io;
	int x;
	cin >> x;
	for(int i = 0;i < 205;++i){
		for(int j = 0;j < 205;++j){
			if(a[i] - a[j] == x){
				cout << i << " " << j;
				return 0;
			}
		}
	}
	for(int i = 0;i < 205;++i){
		for(int j = 0;j < 205;++j){
			if(a[i] + a[j] == x){
				cout << i << " " << (-1)*j;
				return 0;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 3640
#include <iostream>
#include <array>

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

    long long int n;

    while (std::cin >> n, n) {
        std::array<long long int, 7> arr{{}};
        int age;
        for (; n--;) {
            std::cin >> age;
            age = (age > 69 ? 60 : age);
            ++arr[age / 10];
        }
        
        std::cout << arr[0] << "\n"
                  << arr[1] << "\n"
                  << arr[2] << "\n"
                  << arr[3] << "\n"
                  << arr[4] << "\n"
                  << arr[5] << "\n"
                  << arr[6] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1200
def main():
    N = int(input())
    A = []
    for _ in range(N):
        a = list(map(int, input().split()))
        a = [i-1 for i in a]
        a.reverse()
        A.append(a)
    t = N * (N - 1) / 2
    d = 0
    n = set(range(N))
    while True:
        p = 0
        l = set()
        d += 1
        for i in n:
            if A[i] == [] or i in l:
                continue
            j = A[i][-1]
            if A[i][-1] not in l and A[j][-1] == i:
                l.add(i)
                l.add(A[i][-1])
                A[j].pop() 
                A[i].pop()
                t -= 1
                p += 1
        n = l
        if t == 0:
            print(d)
            break
        if p == 0:
            print(-1)
            break
main()


Measured memory_bytes: 61532
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int maxx=0;
  int ans=0;
  for(int i=0 ;i<n; ++i)
  {
    int k;
    cin >> k;
    if (k>maxx)
    {
      ans++;
      maxx=k;
    } else
    if (k==maxx)
    {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

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

long long n,a,m,k,q,b,c=1;
string ss,s1,s2;
int main(){
    cin>>ss;
    set<char>s;
    for (int i=0; i<4; i++){
        s.insert(ss[i]);
    }
    if (s.size()==2){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    I ins;
    ins = vec;
    sort(ALL(vec));
    int l = N/2;
    int w = vec.at(N/2-1);
    REP(a,N){
        if(ins.at(a)<=w){
            COUT(vec.at(N/2));
        }else{
            COUT(vec.at(N/2-1));
        }
    }
    return 0;
}


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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  x -= a;
  x %= b;
  cout << x << endl;
    
  
  return 0;
}


Measured memory_bytes: 256