akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

int dfs(int next,int prev, vector<int> (e[]) , int K) {
    int color_num = prev == -1 ? K - 1 : K - 2;
    if (K - e[next].size() < 0) return 0;
    int case_num = 1;
    for (int a : e[next]) {
        if (a == prev) continue;
        case_num *= color_num;
        case_num %= (int)1e9 + 7;
        color_num --;
    }
    for (int a : e[next]) {
        if (a == prev) continue;
        case_num *= dfs(a, next, e, K);
        case_num %= (int)1e9 + 7;
    }
    return case_num;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> e[N];
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a --; b --;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int ans = (K * dfs(0, -1, e, K)) % ((int)1e9 + 7);
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<ll> L(N);
  rep(i, N) cin >> L[i];
  sort(L.begin(), L.end());

  ll ans = 0;
  if (N >= 3) {
    for (int i = 0; i < N - 2; i++) {
      for (int j = i + 1; j < N - 1; j++) {
        if (L[i] == L[j]) continue;
        for (int k = j + 1; k < N; k++) {
          if (L[j] == L[k]) continue;
          if (L[i] + L[j] > L[k]) {
            ans++;
          } else {
            break;
          }
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int[] intArr = new int[2];
        intArr[0] = Integer.parseInt(strArr[0]);
        intArr[1] = Integer.parseInt(strArr[1]);

        int length = (intArr[0] + intArr[1]) * 2;
        int square = intArr[0] * intArr[1];

        System.out.println(square + " " + length);
    }

}


Measured memory_bytes: 24236
#include <stdio.h>

int main(void) {
    int i;
    int sum = 0;
    int h, n;
    int a[100000];

    scanf("%d%d", &h, &n);

    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);

    for (i = 0; i < n; i++)
        sum += a[i];

    if (h <= sum)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 512
<?php
  $s = trim(fgets(STDIN));
  $k = trim(fgets(STDIN));
  
  $str_array = str_split($s);
  $cnt = count($str_array);
  $num = 0;
  $is_change = false;
  if ($cnt === 1) {
    echo intval(($cnt * $k) / 2) . PHP_EOL;
    return;
  }

  $start_str = $str_array[0];
  $last_str = $str_array[$cnt - 1];

  $s_str_cnt = 1;
  $b_str_cnt = 1;
  $is_toplast_same = ($start_str === $last_str);
  $is_last_change = false;
  $last_cnt = $cnt - 1;
  $is_same = true;

  for($i = 1; $i < $cnt; $i++) {
    if ($is_same && $start_str === $str_array[$i]) {
      $s_str_cnt++;
    } else {
      $is_same = false;
    }
    if ($str_array[$i] === $str_array[$i - 1] && !$is_change) {
      $num += 1;
      $is_change = true;
      if ($i === $last_cnt) {
        $is_last_change = true;
      }
    } else {
      $is_change = false;
    }
  }


  if ($is_same) {
    echo intval(($cnt * $k) / 2) .PHP_EOL;
    return;
  } else {
    for ($j = 2; $j <= $cnt; $j++) {
      if ($last_str === $str_array[$cnt - $j]) {
        $b_str_cnt++;
      } else {
        break;
      }
    }
  }
  $ans = $num * $k;
  if ($is_toplast_same &&
      !$is_last_change &&
      ($s_str_cnt + $b_str_cnt) % 2 === 0) {
    $ans += $k - 1;
  }
  echo $ans . PHP_EOL;


Measured memory_bytes: 4604
import sys
input=sys.stdin.readline
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ai=0
bi=0
ci=0
ans=0
for i in range(x+y):
    if ai<x:
        if bi<y:
            if ci<c:
                m=max(p[ai],q[bi],r[ci])
                ans+=m
                if p[ai]==m:
                    ai+=1
                elif q[bi]==m:
                    bi+=1
                elif r[ci]==m:
                    ci+=1
            else:
                m=max(p[ai],q[bi])
                ans+=m
                if p[ai]==m:
                    ai+=1
                elif q[bi]==m:
                    bi+=1
        else:
            if ci<c:
                m=max(p[ai],r[ci])
                ans+=m
                if p[ai]==m:
                    ai+=1
                elif r[ci]==m:
                    ci+=1
            else:
                m=p[ai]
                ans+=m
                if p[ai]==m:
                    ai+=1
    else:
        if bi<y:
            if ci<c:
                m=max(q[bi],r[ci])
                ans+=m
                if q[bi]==m:
                    bi+=1
                elif r[ci]==m:
                    ci+=1
            else:
                m=q[bi]
                ans+=m
                if q[bi]==m:
                    bi+=1
print(ans)

Measured memory_bytes: 92516
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

struct edge {
    int t, c, h, r;
    edge() = default;
    edge(int t, int c, int h, int r) : t(t), c(c), h(h), r(r) {}
};

const int INF = 1LL << 30;
int N, M, H, K;
int a[510], b[510], c[510], h[510], r[510];
int S, T, P;
int l[300], d[300];
vector<int> k[300];
vector<edge> g[510];

int calc(int bit) {
    vector<vector<int>> dis(N, vector<int>(H + 1, INF));
    using P = tuple<int, int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    dis[S][0] = 0;
    que.emplace(0, S, 0);
    while (!que.empty()) {
        int dd, vv, hh;
        tie(dd, vv, hh) = que.top();
        que.pop();
        if (dd > dis[vv][hh]) continue;
        for (auto& e : g[vv]) if (hh + e.h <= H) {
            if (dis[e.t][hh + e.h] > dis[vv][hh] + (bit >> e.r & 1 ? 0 : e.c)) {
                dis[e.t][hh + e.h] = dis[vv][hh] + (bit >> e.r & 1 ? 0 : e.c);
                que.emplace(dis[e.t][hh + e.h], e.t, hh + e.h);
            }
        }
    }
    int res = INF;
    REP (i, H + 1) res = min(res, dis[T][i]);
    return res;
}

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

    while (cin >> N >> M >> H >> K, N) {
        REP (i, 510) g[i].clear();
        REP (i, M) {
            cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i];
            a[i]--; b[i]--, r[i]--;
            g[a[i]].emplace_back(b[i], c[i], h[i], r[i]);
            g[b[i]].emplace_back(a[i], c[i], h[i], r[i]);
        }
        cin >> S >> T >> P;
        S--; T--;

        vector<int> mask(P, 0);
        REP (i, 300) k[i].clear();
        REP (i, P) {
            cin >> l[i] >> d[i];
            k[i].resize(l[i]);
            REP (j, l[i]) {
                cin >> k[i][j];
                k[i][j]--;
                mask[i] |= 1 << k[i][j];
            }
        }

        vector<vector<int>> dp(P + 1, vector<int>(1LL << K, INF));
        dp[0][0] = 0;
        REP (i, P) {
            REP (j, 1LL << K) dp[i + 1][j] = dp[i][j];
            REP (j, 1LL << K) if (dp[i][j] != INF) {
                dp[i + 1][j | mask[i]] = min(dp[i + 1][j | mask[i]], dp[i][j] + d[i]);
            }
        }

        int ans = INF;
        REP (bit, 1LL << K) ans = min(ans, calc(bit) + dp[P][bit]);
        cout << (ans == INF ? -1 : ans) << endl;
    }
}


Measured memory_bytes: 3804
n, k = map(int,input().split())
dcic = {}
aa = set([])
for i in range(n):
    a,b = map(int,input().split())
    aa.add(a)
    if a in dcic:
        dcic[a] = dcic[a] + b
    else:
        dcic.update({a:b})
        
bb = list(sorted(list(aa)))
cc = 0
s = 0
for i in range(len(bb)):
    if s < k:
        s = s + dcic[bb[i]]
        cc = bb[i]
    else:
        ccc = bb[i]
print(cc)

Measured memory_bytes: 13100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    
    auto calc = [&](vector<ll> x) {
        if (n % 2) return x[(n + 1) / 2 - 1];
        else return (x[n / 2 - 1] + x[n / 2]) / 2;
    };
    
    if (n % 2) {
        cout << calc(b) - calc(a) + 1 << endl;
    } else {
        rep(i, n) {
            a[i] *= 2;
            b[i] *= 2;
        }
        cout << calc(b) - calc(a) + 1 << endl;
    }
}



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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        long long sum = 0;
        set<long long> div;
        for(int i=1; i*i<=n; i++){
            if(n % i == 0){
                if(i != n) div.emplace(i);
                if(n / i != n) div.emplace(n / i);
            }
        }

        for(auto i:div){
            sum += i;
        }

        if(n == sum){
            cout << "perfect number" << endl;
        }
        else if(n > sum){
            cout << "deficient number" << endl;
        }
        else{
            cout << "abundant number" << endl;
        }
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll,ll> P;
template <typename T> std::string tostr(const T& t){std::ostringstream os; os<<t; return os.str();}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
 
int main(){ 
    int n,m,ans=0;
    cin>>n>>m;
    vector<int> cost(m);
    vector<P> pa(m);
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        pa[i]={a,b};
        cost[i]=c;
    }
    //ワーシャルフロイド
    vector<vector<ll>> dist(n, vector<ll>(n,INF));
    for(int i=0;i<n;i++){
        dist[i][i]=0;
    }
    for(int i=0;i<m;i++){
        dist[pa[i].first][pa[i].second]=cost[i];
        dist[pa[i].second][pa[i].first]=cost[i];
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    ans=m;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(dist[j][pa[i].first]+cost[i]==dist[j][pa[i].second]){
                ans--;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
import math

def calc(x, y, r, d, nd):
	x = x + r * math.cos(math.radians(d))
	y = y + r * math.sin(math.radians(d))
	d -= nd
	return x, y, d

x = y = 0
d = 90

while True:
	r, nd = map(int, input().split(","))
	if r == nd == 0: break
	x, y, d = calc(x, y, r, d, nd)

print(int(x))
print(int(y))

Measured memory_bytes: 7980
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N=40;
const int mod=998244853;
const ull p1=5557;
const int p2=2333;

struct node{
	ull x; int y;
	node(){}
	node(ull x,int y):x(x),y(y){}
	friend node operator+(node a,node b){
		return node(a.x+b.x,(a.y+b.y)%mod);
	}
	friend node operator-(node a,node b){
		return node(a.x-b.x,(a.y-b.y+mod)%mod);
	}
	friend node operator*(node a,node b){
		return node(a.x*b.x,1ll*a.y*b.y%mod);
	}
	friend bool operator<(node a,node b){
		return a.x<b.x||(a.x==b.x&&a.y<b.y);
	}
}p[N],s1,s2;
int n,x;
ll ans;
char s[N];
map<node,int> mp;

void init(){
	int i;
	p[0]=node(1,1);
	for (i=1;i<=n;i++) p[i]=p[i-1]*node(p1,p2);
}

int main(){
	int i,j;
	scanf("%d",&n);
	scanf("%s",s+1);
	init();
	for (i=0;i<(1<<n);i++){
		s1=s2=node(0,0); x=0;
		for (j=1;j<=n;j++)
			if ((i>>j-1)&1){
				s1=s1*node(p1,p2)+node(s[j],s[j]);
				x++;
			}
		for (j=n;j>=1;j--)
			if (!((i>>j-1)&1)) s2=s2*node(p1,p2)+node(s[j],s[j]);
		mp[s1*p[n-x]-s2]++;
	}
	for (i=0;i<(1<<n);i++){
		s1=s2=node(0,0); x=0;
		for (j=1;j<=n;j++)
			if ((i>>j-1)&1){
				s1=s1*node(p1,p2)+node(s[j+n],s[j+n]);
				x++;
			}
		for (j=n;j>=1;j--)
			if (!((i>>j-1)&1)) s2=s2*node(p1,p2)+node(s[j+n],s[j+n]);
		ans+=1ll*mp[s2*p[x]-s1];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'o
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	double r;
    cin>>r;
    cout<<fixed;
    cout<<2*(double(22)/double(7))*r;
	return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    ll x, a, b;
    cin >> x;
    a = (x / 500) * 1000;
    x = x - (x / 500) * 500;
    b = (x / 5) * 5;
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main(){
	int A1;
	int A2;
	int A3;
	scanf("%d %d %d",&A1,&A2,&A3);
//	printf("%d",A1+A2+A3);
	if(A1+A2+A3>=22){
		printf("bust\n");
	}
	else if(A1+A2+A3){
		printf("win\n");
	}
	
	return 0;
}

Measured memory_bytes: 1660
A, B, C, X, Y = map(int, input().split())
cost1 =  A+B; cost2 = C*2
 
if X == Y :
  print( X* min( cost1, cost2))
elif X> Y:
  print( min( Y* min( cost1, cost2) + (X-Y)*A , X* min( cost1, cost2)))
else :
  print( min( X* min( cost1, cost2) + (Y-X)*B , Y* min( cost1, cost2)))

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

 int  main()
{
  long long int  x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<long long int > p;
  vector<long long int > q;
  vector<long long int > r;
  long long int  d;
  for(long long int  i=0;i<a;i++){
      cin>>d;
      p.push_back(d);
  }
  for(long long int  i=0;i<b;i++){
      cin>>d;
      q.push_back(d);
  }
  for(long long int  i=0;i<c;i++){
      cin>>d;
      r.push_back(d);
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  reverse(p.begin(),p.end());
  reverse(q.begin(),q.end());
  reverse(r.begin(),r.end()); 
  vector<long long int > v;
  for(long long int  i=0;i<x;i++)v.push_back(p[i]);
  for(long long int  i=0;i<y;i++)v.push_back(q[i]);
  for(long long int  i=0;i<min(x+y,c);i++)v.push_back(r[i]);
  
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  long long int  ans=0;
  for(long long int  i=0;i<x+y;i++){
      ans=ans+v[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 8688
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <tuple>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <tuple>

using namespace std;

#define endl '\n'

using ull = unsigned long int;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const int precision = 13;
  cout.precision(precision);
  cout.setf(ios_base::fixed);

  int n, W; cin >> n >> W;
  vector<ll> dp(W+1, 0);

  for (int i = 0; i < n; ++i) {
    ll w, v; cin >>  w >> v;
    for (int j = W; j - w >= 0; --j) {
      if (j-w == 0 or dp[j-w]) {
        dp[j] = max(dp[j], dp[j-w] + v);
      }
    }
  }

  cout << *max_element(dp.begin(), dp.end()) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m;
  while(cin>>n>>m,n){
    double t[n][n],mm=0,dp[m][n]={};
    r(i,n)r(j,n)cin>>t[i][j];
    r(i,n)dp[0][i]=1;
    for(int i=1;i<m;i++)r(j,n)r(k,n)
      dp[i][j]=max(dp[i][j],dp[i-1][k]*t[k][j]);
    r(i,n)mm=max(mm,dp[m-1][i]);
    printf("%.2f\n",mm);
  }
}

Measured memory_bytes: 3300
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    int N;
    cin >> N;
    vector<ll> A(N+1),l(N+1),h(N+1);

    rep(i,1,N+1){
        cin >> A[i];
    }

    l[N] = h[N] = 2;

//    if(A[N] > 2){
//        cout << -1 << endl;
//        return 0;
//    }

    for(int i = N; i > 0; i--){
        if(h[i] < A[i]){
            cout << -1 << endl;
            return 0;
        }

        ll low = l[i] / A[i] * A[i];
        if(low < l[i]) low += A[i];
        ll high = h[i] / A[i] * A[i];

        if(low > high){
            cout << -1 << endl;
            return 0;
        }

        if(low < l[i] || low > h[i]){
            cout << -1 << endl;
            return 0;
        }
        if(high < l[i] || high > h[i]){
            cout << -1 << endl;
            return 0;
        }

        l[i-1] = low;
        h[i-1] = high + (A[i] - 1);
    }


    cout << l[0] << " " << h[0] << endl;


    return 0;
}


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

#define INF 1E18



int main(){
    string s;
    cin >> s;
    ll n = s.length();

    ll ans1 = 0;
    ll ans2 = 0;

    rep(i,n){
        if(i%2 == 0 && s[i]!='0') ans1++;
        if(i%2 == 1 && s[i]!='1') ans1++;
    }

    rep(i,n){
        if(i%2 == 0 && s[i]!='1') ans2++;
        if(i%2 == 1 && s[i]!='0') ans2++;
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val n: Int = sc.nextLine.toInt
    val k: Int = sc.nextLine.toInt

    def go(n: Int, acc: Int): Int ={
      if (n == 0) acc
      else{
        if (acc < k) go(n-1, acc * 2)
        else go(n-1, acc + k)
      }
    }
    println(go(n, 1))
  }
}


Measured memory_bytes: 27332
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1


def main():
    n = int(input())
    A = list(map(int, input().split()))
    q = partition(A, 0, len(A)-1)
    for i in range(q):
        print(A[i], end=" ")
    print("[{}]".format(A[q]), end=" ")
    for i in range(q+1, n):
        if i == n-1:
            print(A[i])
        else:
            print(A[i], end=" ")


if __name__ == '__main__':
    main()



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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  vector<int> dpa(N);
  vector<int> dpb(N);
  vector<int> dpc(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
  }
  dpa.at(0) = a.at(0);
  dpb.at(0) = b.at(0);
  dpc.at(0) = c.at(0);

  for (int i = 1; i < N; i++) {
    dpa.at(i) = a.at(i) + max(dpb.at(i - 1), dpc.at(i - 1));
    dpb.at(i) = b.at(i) + max(dpa.at(i - 1), dpc.at(i - 1));
    dpc.at(i) = c.at(i) + max(dpa.at(i - 1), dpb.at(i - 1));
  }

  cout << max(max(dpa.at(N - 1), dpb.at(N - 1)), dpc.at(N - 1)) << endl;
  return 0;
}


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	ll k;
	cin >> k;
	vector<ll> a(k);
	rep (i, 0, k) {
		cin >> a[i];
	}
	ll minn = 2, maks = 2;
	for (int i = k - 1; i >= 0; i--) {
		ll dmin = minn / a[i] * a[i];
		if (dmin < minn) {
			dmin += a[i];
		}
		ll dmax = maks / a[i] * a[i];
		if (dmin > dmax) {
			cout << "-1";
			return 0;
		}
		minn = dmin;
		maks = dmax + a[i] - 1; 
	}
	cout << minn << " " << maks;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

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

int main() {
  string s; cin >> s;
  int n = s.size();
  map<char, int> mp;
  rep(i, n) {
    mp[s[i]-'a']++;
  }
  if (n == 1) {
    cout << "YES\n";
  }
  else if (n == 2) {
    cout << (mp.size() == 2 ? "YES\n" : "NO\n");
  }
  else {
    int max = std::max(mp[0], std::max(mp[1], mp[2]));
    bool ng = 0;
    rep(i, 3) {
      if (max - mp[i] > 1) {
        ng = 1;
      }
    }
    cout << (ng ? "NO\n" : "YES\n");
  }
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):                                          # 根を見つける関数を定義（同時にxを直接根にくっつける操作も行う）
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])        # 右辺で再帰的に根を探索。根に到達すると一つ目のif判定に引っかかるので、
                                                                # 最終的にself.parents[根]が返ってくる。
                                                                # これを左辺に代入することで、根が親になるように変更する。（根までの距離が長いとO(N)になってしまうので）
            return self.parents[x]

    def union(self, x, y):                                      # 二つの木をくっつける（子を多く持つ方を根とした親子関係）。これは破壊的操作を行う。
        x = self.find(x)                                        # xをxの根に置き換える
        y = self.find(y)                                        # yをyの根に置き換える

        if x == y:                                              # 根が同じなら置き換える必要なし
            return

        if self.parents[x] > self.parents[y]:                   # 子がたくさんある方を x とする（出来るだけ浅い木にするため）
            x, y = y, x

        self.parents[x] += self.parents[y]                      # xの子の数を更新
        self.parents[y] = x                                     # yの親を更新

    def same(self, x, y):                                       # xとyが同じ根の子かを判定
        return self.find(x) == self.find(y)

    def size(self, x):                                          # xの根のparent（= 要素数）を返す
        return -self.parents[self.find(x)]

    def members(self, x):                                       # xが属するグループの要素をリストとして返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):                                            # 全ての根の要素をリストとして返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):                                      # グループの数を返す
        return len(self.roots())

    def all_group_members(self):                                # {根:[根の子のリスト],...}を辞書で返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):                                          # print(self) での返し方を定義
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


##############################################################################################################

V, E, K = map(int, input().split())                            # V: 頂点数　E: 辺の数

tree = UnionFind(V)

edges = [[] for _ in range(V)]
for _ in range(E):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree.union(a, b)
    edges[a].append(b)
    edges[b].append(a)


blocks = [[] for _ in range(V)]
for _ in range(K):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    blocks[a].append(b)
    blocks[b].append(a)

res = []
for x in range(V):
    n = tree.size(x)
    temp = n-1
    for y in edges[x]:
        if tree.same(x,y):
            temp -= 1
    for y in blocks[x]:
        if tree.same(x,y):
            temp -= 1
    res.append(temp)

print(*res)

Measured memory_bytes: 104340
#include "bits/stdc++.h"
#include<stdio.h>
#include <sstream>
#define pi 3.141592653589793238462
#define limit 100005
#define mo 1000000007;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli mod=9999999999999983;
lli primes[6]={1125899906842597,1495921043,1005985879,1495921043,1005985879,1495921043};
using namespace std;
vector<lli>adj[2000009];
lli parent[2000009];
lli vis[2000009];
lli level[2000009];
lli dist[2000009];
lli dp[100009];
lli arr[100009];
lli brr[2000009];
lli crr[2000009];
lli hashing[2000009];
lli ar[509][509];
lli br[509][509];
lli cr[509][509];
lli multiply(lli a,lli b){return ((a%mod)*(b%mod))%mod;}
lli add(lli a,lli b){return ((a%mod)+(b%mod))%mod;}
lli sub(lli a,lli b){return ((a%mod)-(b%mod)+mod)%mod;}
#define deb(x) cout<< #x << " " << x <<endl;
//deb(n);

lli power(lli x, lli y,lli p)
{
	lli res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=((res%p)*(x%p))%p;
		y=y>>1;
		x=((x%p)*(x%p))%p;
	}
	return res;
}


int main()
{
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int start_s = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    vector< lli>vect,vt,vct;
    vector<lli>::iterator itt;
    set<lli>st;
    set<lli>::iterator itr;
    map<lli,lli>mp,mpp,mp1,mp2;
    map<lli,lli>::iterator it;

    lli i,j,k,n,m,res1,res2,q,t,a,b,c,maxi=INT_MIN,mini=INT_MAX,sum=0,ans=0,res=0,val=0,ans1=0,ans2=0,rem=0,diff=0,cnt=0,l,r,flag=0,e,index,val1=0,val2=0,z,h=0,u,v,mid,len,tot,fl=0;
    string str,str1,str2;


char ch;
cin>>ch;

cout<<char(ch+1)<<endl;
    //cin>>n;


}


Measured memory_bytes: 47360
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,n,k,temp,happ;
	temp=0;
	happ=0;
	string s;
	cin>>n>>k;
	cin>>s;
	for(i=0;i<n-1;i++)
	{
		if (s[i]!=s[i+1])
		{
			temp++;
		}
	}
	for (i=1;i<n-1;i++)
	{
		if (s[i]=='L' && s[i-1]=='L')
		{
			happ++;
		}
		if (s[i]=='R' && s[i+1]=='R')
		{
			happ++;
		}		
	}
		if (s[0]=='R' && s[1]=='R')
		{
			happ++;
		}
		if (s[n-1]=='L' && s[n-2]=='L')
		{
			happ++;
		}
	cout<<happ+(fmin(temp,k*2))<<endl;	
}

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

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

int main(){
	while(1){
		int n, m;
		cin>>n>>m;
		if(n==0) break;
		int a[n];
		REP(i, n) cin>>a[i];
		sort(a, a+n, greater<int>());
		int sum = 0;
		REP(i, n) sum+=a[i];
		for(int i=m-1; i<n; i+=m){
			sum-=a[i];
		}
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int l[n];
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l, l+n);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += lower_bound(l, l + n, l[i] + l[j]) - l - 1 - j;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();
        int sum = 0;
        for(int x = 0; x <= k; x++){
            for(int y = 0; y <= k; y++){
                int z = s-(x+y);
                if(0 <= z && z <= k)sum++;
            }
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
int main(void)
{
	double r, S, L, pi;

	pi = 3.141592653589;

	scanf("%lf",&r);

	if ((0 < r) && (r < 10000))
	{
		L = 2 * pi * r;
		S = pi * r * r;

		printf("%.6f %.6f\n", S, L);
	}
	return 0;
}

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

int main(int argc, char const *argv[]){
	int r,g,b;
	cin >> r >> g >> b;
	if((100 * r + 10 * g + b) % 4 == 0)	cout << "YES\n" << endl;
	else puts("NO\n");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int student[31];

int main(){
  int n;
  for( int i = 1 ; i <= 30 ; i++  ){
  student[i] = 0;
  }
  while( cin >> n ) student[n] = 1;
  for( int i = 1 ; i <= 30 ; i++ ){
    if( !(student[i]) ) cout << i << endl;
  }
}

Measured memory_bytes: 1160
use proconio::input;
use std::collections::{HashMap, VecDeque};

fn main() {
    input! {
        n: usize,
        ab: [(usize, usize); n-1],
        mut cc: [usize; n],
    }

    if n == 1 {
        println!("{}", cc[0]);
        println!("{}", cc[0]);
        return;
    }

    let mut map = HashMap::new();

    for &(a, b) in ab.iter() {
        map.entry(a).or_insert_with(|| vec![]).push(b);
        map.entry(b).or_insert_with(|| vec![]).push(a);
    }

    cc.sort();
    cc.reverse();
    let mut cc = VecDeque::from(cc);
    let score = cc.iter().skip(1).sum::<usize>();

    let mut nums = vec![None; n];

    let mut queue = VecDeque::new();
    queue.push_back(1);

    while let Some(vert) = queue.pop_front() {
        if nums[vert - 1].is_some() {
            continue;
        }
        let c = cc.pop_front().unwrap();
        nums[vert - 1] = Some(c);
        for &e in &map[&vert] {
            queue.push_back(e);
        }
    }

    let dd = nums
        .into_iter()
        .map(|d| d.unwrap().to_string())
        .collect::<Vec<_>>()
        .join(" ");

    println!("{}", score);
    println!("{}", dd);
}


Measured memory_bytes: 4164
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int dp[3001][3001] = {};
int main()
{
  string s, t;
  cin >> s >> t;

  FOR(i, 1, s.length() + 1)
  {
    FOR(j, 1, t.length() + 1)
    {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(dp[i - 1][j - 1], max(dp[i][j - 1], dp[i - 1][j]));
    }
  }
  string ans = "";
  int l = dp[s.length()][t.length()];

  // 復元
  int ci = s.length(), cj = t.length();
  while (ans.length() < l && ci >= 0)
  {
    bool update = false;
    for (int i = ci; i > 0; i--)
    {
      if (s[i - 1] == t[cj - 1] && dp[i][cj] == l - ans.length())
      {
        ans = s[i - 1] + ans;
        ci = i - 1;
        cj--;
        update = true;
        break;
      }
    }
    if (update)
      continue;

    for (int j = cj; j > 0; j--)
    {
      if (s[ci - 1] == t[j - 1] && dp[ci][j] == l - ans.length())
      {
        ans = s[ci - 1] + ans;
        ci--;
        cj = j - 1;
        update = true;
        break;
      }
    }
    if (update)
      continue;

    if (!update)
    {
      ci--;
      cj--;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[502][502];
int main() {
	ll h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	ll ans=0;
	vector<vector<ll>>b(4);
	for(int i=0;i<h-1;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]%2!=0){
				ans++;
				b[0].push_back(i+1);
				b[1].push_back(j+1);
				b[2].push_back(i+2);
				b[3].push_back(j+1);
				a[i+1][j]++;
			}
		}
	}
	for(int i=0;i<w-1;i++){
		if(a[h-1][i]%2!=0){
			ans++;
			b[0].push_back(h);
			b[1].push_back(i+1);
			b[2].push_back(h);
			b[3].push_back(i+2);
			a[h-1][i+1]++;
		}
	}
	cout << ans<<endl;
	for(int i=0;i<ans;i++){
		for(int j=0;j<4;j++){
			cout << b[j][i];
			if(j!=3){
				cout << " ";
			}
		}
		if(i!=ans-1){
		cout << endl;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 8148
# coding: utf-8

n, m = map(int, input().split())

sc_list = []
s_list = []
result = 0
for _ in range(m):
    sc_list.append(list(map(int, input().split())))
sc_list = list(map(list, set(map(tuple, sc_list))))
for sc in sc_list:
    if sc[0] == 1 and sc[1] == 0 and n != 1:
        print(-1)
        exit()
    result += sc[1] * (10 ** (n - sc[0]))
    s_list.append(sc[0])
if not len(set(s_list)) == len(sc_list):
    print(-1)
    exit()
if n == 3 and result < 100:
    result += 100
if n == 2 and result >= 100:
    print(-1)
    exit()
if n == 2 and result < 10:
    result += 10
if n == 1 and result >= 10:
    print(-1)
    exit()

print(result)


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

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n;
    cin >> n;
    ll ans = LONG_LONG_MAX;
    for(ll i=1;i*i<=n;i++) {
    	if(n%i == 0) {
    		ans = min(ans, n/i + i);
    	}
    }
    cout << ans - 2<< "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main()
{
    ll a,b,n;
    cin >> a >> b >> n;

    cout << (long long)((double)a*(double)min(b-1,n)/b) << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;

int i, j, k;

int main() {
	string s;
	cin >> s;
	if ((s[0] == 'Y')&(s[1] == 'A')&(s[2] == 'K')&(s[3] == 'I')) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, W; cin >> N >> W;
    vector<ll> w0, w1, w2, w3;
    ll wo, vo;
    cin >> wo >> vo;
    w0.push_back(vo);

    for(int i=0; i<N-1; ++i){
        ll w, v; cin >> w >> v;
        if(w == wo) w0.push_back(v);
        else if(w == wo+1) w1.push_back(v);
        else if(w == wo+2) w2.push_back(v);
        else w3.push_back(v); 
    }

    sort(w0.begin(), w0.end(), greater<ll>());
    sort(w1.begin(), w1.end(), greater<ll>());
    sort(w2.begin(), w2.end(), greater<ll>());
    sort(w3.begin(), w3.end(), greater<ll>());

    ll ans = 0;
    for(int i=0; i<=w0.size(); ++i){
        for(int j=0; j<=w1.size(); ++j){
            for(int k=0; k<=w2.size(); ++k){
                for(int l=0; l<=w3.size(); ++l){
                    ll tw = 0, tv = 0;
                    tw = wo*i + (wo+1)*j + (wo+2)*k + (wo+3)*l;
                    if(tw > W) continue;
                    for(int a=0; a<i; ++a) tv += w0[a];
                    for(int a=0; a<j; ++a) tv += w1[a];
                    for(int a=0; a<k; ++a) tv += w2[a];
                    for(int a=0; a<l; ++a) tv += w3[a];
                    ans = max(ans, tv);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N  = int(input())
A = list (map(int,input().split()))
for i in range(N):
    v = A[i]
    j = i -1
    while (j >= 0) and (A[j]>v):
        A[j+1] = A[j]
        j -= 1
    A[j+1]= v
    print(" ".join(map(str,A)))

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int cond = 0;
  
  for(int i=A; i<=B; i++) {
    if(i%K==0) {
      cond = 1;
      break;
    }
  }
  
  cout << (cond==1 ? "OK" : "NG") << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <complex>
#include <cstdio>
using namespace std;

int main () {
    int counter = 1;
    int n;
    while (cin >> n, n) {
        vector<complex<double> > ps(n);
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            ps[i] = complex<double> (x, y);
        }

        double area = 0;
        for (int i = 0; i < n; i++) {
            area += ps[i].real() * ps[(i+1)%n].imag() - ps[i].imag() * ps[(i+1)%n].real();
        }
        area *= 0.5;
        area = (area > 0) ? area : -area;

        printf("%d %.1f\n", counter++, area);
    }
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = a; i < b + 1; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
  
 	public static void main(String[] args){
     
      Scanner s = new Scanner(System.in);
      int x1 = s.nextInt();
      int x2 = s.nextInt();
      int x3 = s.nextInt();
      int x4 = s.nextInt();
      int x5 = s.nextInt();
      if(x1 == 0)
        System.out.println(1);
      if(x2 == 0)
        System.out.println(2);
      if(x3 == 0)
        System.out.println(3);
      if(x4 == 0)
        System.out.println(4);
      if(x5 == 0)
        System.out.println(5);
      
    }
  
  
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

struct BIT{
    ll N;
    vector<ll> bit;
    BIT(ll N) : bit(N+1),N(N){};

    ll sum(ll i){
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i& -i;
        }
        return s;
    }

    void add(ll i,ll x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

//数列の値の範囲を[1,n]に変える
vector<ll> convert_array(vector<ll> z){
    ll n = z.size();
    vector<ll> temp = z;
    sort(all(temp));
    for(int i = 0; i < n; i++){
        z[i] = lower_bound(all(temp), z[i]) - temp.begin() + 1;
    }
    return z;
}

//反転数を求める
ll inverse_number(vector<ll> z){
    ll n = z.size();
    ll inv_num = 0;
    z = convert_array(z);

    BIT b(n);
    for(int i = 0; i <= n; i++){
        b.bit[i] = 0;
    }

    for(int i = 0; i < n; i++){
        inv_num += i - b.sum(z[i]);
        b.add(z[i],1);
    }

    return inv_num;
}

//数列の変形をしてxが中央値の候補かどうか調べる
bool check(ll x,vector<ll> z){
    ll n = z.size();
    vector<ll> b(n);
    for(int i = 0; i < n; i++){
        if(z[i] >= x) b[i] = 1;
        else b[i] = -1;
    }
    vector<ll> s(n+1,0);  //ここ長さn+1になることに注意
    for(int i = 1; i <= n; i++){
        s[i] = s[i-1] + b[i-1];
    }

    return (n*(n+1)/2 - inverse_number(s)) >= (n*(n+1)/2+1)/2;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    ll low = *min_element(all(a))-1, high = *max_element(all(a))+1;

    while(high - low > 1){
        ll mid = (low+high)/2;
        if(check(mid,a)) low = mid;
        else high = mid;
    }

    cout << low << endl;

    return 0;
}

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

int main() {
  int N, K, P=1;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    if(P*2<P+K){
      P*=2;
    }
    else{
      P+=K;
    }
  }
  
  cout << P << endl;
}


Measured memory_bytes: 256
from sys import stdin

input = stdin.readline

N = int(input())

txy = [[int(j) for j in input().split()] for i in range(N)]


def main():
    pt = 0
    px = 0
    py = 0

    flg = False

    for t, x, y in txy:
        # 到達 あるいは 通過
        if abs(x - px) + abs(y - py) <= t - pt:
            # 距離と時間の偶奇が一致しない 戻れない
            if (abs(x - px) + abs(y - py)) % 2 != (t - pt) % 2:
                break
            else:
                pt = t
                px = x
                py = y
        # 到達しない
        else:
            break
    else:
        # break しなかった 完走
        flg = True

    print("Yes" if flg else "No")
    return


main()


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

int main()
{
    int n;
    cin >> n;
    map<int, int> a_cnt;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        rep(i, -1, 2)
            a_cnt[a + i]++;
    }

    int ans = 0;
    for (auto a_c: a_cnt)
        ans = max(ans, a_c.second);
    cout << ans << endl;
    return 0;
}

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

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double at=360*h/12+30*m/60, bt=360*m/60;
  double dt=abs(at-bt);
  double x=sqrt(a*a+b*b-2*a*b*cos(dt*M_PI/180));
  cout << fixed << setprecision(10) << x;
  return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;   cin >> n;
    vector<ll> v;
    ll tmp=n;
    for(ll i=1; i*i<=tmp; i++){
        if(tmp%i==0){
            v.push_back(i);
            if(i!=tmp/i) v.push_back(tmp/i);
        }
    }
    ll res=LINF;
    for(auto x: v){
        string obj=to_string(n/x);
        string tp = to_string(x);
        res = min(res, max((ll)obj.size(), (ll)tp.size()));
    }
    cout << res << endl;
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define rep(i,a) for(int i = 0 ; i < a ; i++) 

bool maze[8][8];

bool inmaze(int x,int y){
  return (0<=x && x<8) && (0<=y && y<8);
}

int dfs(int x,int y){
  if(!inmaze(x,y))return 0;
  maze[x][y] = false;
  int cnt = 0;
  loop(i,-3,4){
    if(maze[x+i][y]){
      dfs(x+i,y);
    }
    if(maze[x][y+i]){
      dfs(x,y+i);
    }
  }
    
}
int main(void){
  int n;
  cin>>n;
  rep(k,n){
    string s;
    rep(i,8){
      cin>>s;
      rep(j,8)maze[i][j] = s[j] - '0';
    }
    int x,y;
    cin>>x>>y;
    dfs(--y,--x);
    if(k)cout<<endl;
    cout<<"Data "<<k+1<<":"<<endl;
    rep(i,8){
      if(i)cout<<endl;
      rep(j,8)cout<<maze[i][j];   
    }
  }
  cout<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n, m;
	cin >> n >> m;
	ll arr[m];
	REP(i, 0, m) cin >> arr[i];
	
	sort(arr, arr+m);
	ll d[m-1];
	REP(i, 0, m-1) d[i] = arr[i+1]-arr[i];
	ll ans =0;
	sort(d, d+m-1);
	REP(i, 0, m-n){
		ans += d[i];
	}
	cout << ans;

}


Measured memory_bytes: 1792