akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadInt();
            var b = ReadInt();
            var h = ReadInt();

            WriteLine(((a+b)*h)/2);
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>p(n),q(n),k(n);
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];
    for(int i=0;i<n;i++) k[i]=i+1;
    sort(k.begin(),k.end());
    int a,b;
    int m=0;
    do
    {
        m++;
        if(k==p)
        a=m;
        if(k==q)
        b=m;
    }while (next_permutation(k.begin(),k.end()));
    cout<<abs(a-b)<<"\n";
    
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200005], n;
ll sum[200005], ans = 100000000000000;
int main()
{
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", a + i);
		sum[i] = sum[i - 1] + a[i];
	}
	for (int j = 3; j < n; j++)
	{ 
		ll m1 = lower_bound(sum + 1, sum + j, sum[j - 1] / 2) - sum;
		if (abs(sum[m1] - (sum[j - 1] - sum[m1])) > abs(sum[m1 - 1] - (sum[j - 1] - sum[m1 - 1])))
		{
			m1 = m1 - 1;
		}
		ll n1 = min(sum[m1], sum[j - 1] - sum[m1]);
		m1 = max(sum[m1], sum[j - 1] - sum[m1]);
		ll m2 = lower_bound(sum + j, sum + n + 1, sum[j - 1] + (sum[n] - sum[j - 1])/ 2) - sum;
		//cout << "*" << sum[j - 1] + (sum[n] - sum[j - 1])/ 2 << "* ";
		if (abs(sum[m2] - sum[j - 1] - (sum[n] - sum[m2])) > abs(sum[m2 - 1] - sum[j - 1] - (sum[n] - sum[m2 - 1])))
		{
			m2 = m2 - 1; 
		}
		ll n2 = min(sum[m2] - sum[j - 1], sum[n] - sum[m2]);
		m2 = max(sum[m2] - sum[j - 1], sum[n] - sum[m2]);
		//cout << m1 << "*" << n1 << "*" << m2 << "*" << n2 << endl;
		ans = min(max(m1, m2) - min(n1, n2), ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}
 
int main() {
  ll n;
  cin >> n;
  vec c(n);
  for(ll i=0;i<n;i++) cin >> c[i];
  sort(c.rbegin(),c.rend());
  ll ans=0;
  for(ll i=0;i<n;i++) {
    (ans+=c[i]*(i+2)%mod)%=mod;
  }
  (ans*=mpow(4,n-1))%=mod;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
int n,k,ans,a[100001];
int abs(int a){
    if(a<0)return -a;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        if(a[i]<=k/2)ans+=a[i]*2;
        else ans+=abs(a[i]-k)*2;
    printf("%d\n",ans);
}

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

#define N 100

int main() {
	static char cc[N + 1][16];
	int n, i, j;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < n; i++)
		for (j = i + 1; j < n; j++)
			if (strcmp(cc[i], cc[j]) == 0) {
				printf("No\n");
				return 0;
			}
	for (i = 0; i < n - 1; i++)
		if (cc[i][strlen(cc[i]) - 1] != cc[i + 1][0]) {
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}


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

const int MOD = 998244353;

int main(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> lr;
    for (int i = 0; i < k; i++) {
        int l, r;
        cin >> l >> r;
        lr.emplace_back(l, r);
    }
    vector<int> dp(n+1);
    dp[0] = 1;
    dp[1] = -1;
    for (int i = 0; i < n; i++) {
        if (i) dp[i] = (dp[i] + dp[i-1]) % MOD;
        for (auto p : lr) {
            if (i + p.first < n) {
                dp[i + p.first] = (dp[i + p.first] + dp[i]) % MOD;
            }
            if (i + p.second < n) {
                dp[i + p.second + 1] = (dp[i + p.second + 1] - dp[i] + MOD) % MOD;
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4028
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll a;
int main(){
		cin>>a;
		cout<<a + a*a + a*a*a<<'\n';
}


Measured memory_bytes: 3640
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define amen ;
#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;
typedef unsigned int ui;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m;
    cin >> m >> n;
    vector <int> v(n), t;
    for (auto &it : v)
        cin >> it;
    sort(all(v));
    for (int i = 1; i < n; i++)
    {
        t.pb(v[i] - v[i-1]);
    }
    sort(all(t));
    int ans = 0;
    for (int i = 0; i < n - m; i++)
    {
        ans += t[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r,p,c;
  int j;
  int card[50];
  while(1){
    cin>>n>>r;
    if(n==0 && r==0) break;
    j=1;
    for(int i=n-1;i>=0;i--){
      card[i]=j;
      j++;
    }
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(card,card+p-1,card+p+c-1);
   }
    cout<<card[0]<<endl;
  }
  return 0;
}



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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll ans = 0;
    cin >> n;
    vector<ll> a, b;
    rep (i, n) {
        ll x, y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }
    for (int i = n - 1; i >= 0; --i) {
        a[i] += ans;
        if (a[i] % b[i] == 0) continue;
        ans += b[i] - (a[i] % b[i]);
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int n;
    cin>>n;
    vector<int> p(n);
    rep(i,n){
        cin>>p.at(i);
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        if((p.at(i-1)-p.at(i))*(p.at(i)-p.at(i+1))>0){ans++;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int x, y;
    int a, b;

    std::cin >> x >> y;

    a = 4*x - y;
    if (a < 0 || a % 2 != 0) {
        std::cout << "No" << std::endl;
        return 0;
    }
    a /= 2;
    b = x - a;

    if (b < 0) {
        std::cout << "No" << std::endl;
        return 0;
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 3632
# https://atcoder.jp/contests/abc108/tasks/arc102_a

N, K = map(int, input().split())

ans = 0
if K % 2 == 0:
    # 余りが 全部 0 か全部 K//2 である数字の組み合わせ
    c1 = len([i for i in range(K, N + 1, K)])
    ans += c1 * c1 * c1
    c2 = len([i for i in range(K // 2, N + 1, K)])
    ans += c2 * c2 * c2
else:
    # 余りが 全部 K//2 である数字の組み合わせ
    c1 = len([i for i in range(K, N + 1, K)])
    ans += c1 * c1 * c1

print(ans)


Measured memory_bytes: 11032
from bisect import bisect_left
N,K = map(int,input().split())
V = list(map(int,input().split()))
vmax = -10**9
for n in range(min(N,K)+1):
    A = V[:n]
    for m in range(min(N,K)-n+1):
        B = V[N-m:]
        B = sorted(A+B)
        ind = bisect_left(B,0)
        k = min(K-m-n,ind)
        cnt = sum(B[k:])
        vmax = max(vmax,cnt)
print(vmax)

Measured memory_bytes: 74048
//解説2
//試合を頂点として、各選手が行う試合の順番を矢印とした有向グラフを構成し、
//その最長経路を解とする方針
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N-1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];

//試合のIDを返す関数
int toId(int i, int j) {
    if(i > j) swap(i, j);
    return id[i][j];
}

bool visit[MAX_V];
bool calc[MAX_V]; //ある頂点からの最長経路が計算し終わっているかどうかを判定する
int dp[MAX_V]; //ある頂点からの最長経路を書き込むdpテーブル
int dfs(int v) {
    if(visit[v]) {
        //計算が終わっていないにも拘らず訪問済みとなっている場合、
        //閉路を持っているため試合の割り振りが不可能
        if(calc[v]) return dp[v];
        else return -1;
    }
    visit[v] = true;
    dp[v] = 1;
    //グラフの向きが逆向きであるため、現在の頂点から矢印が伸びている先の
    //頂点からの最長経路+1が、現在の頂点からの最長経路候補である。
    for(int u: to[v]) {
        int res = dfs(u);
        if(res == -1) return -1;
        dp[v] = max(dp[v], res+1);
    }
    calc[v] = true;
    return dp[v];
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N-1));
    rep(i, N) rep(j, N-1) {
        cin >> A[i][j];
        A[i][j]--;
    }

    int V = 0; //頂点数→ID
    //試合にIDを割り当てる
    rep(i, N) rep(j, N) {
        if(i < j) {
            id[i][j] = V++;
        }
    }

    rep(i, N) {
        rep(j, N-1) {
            //配列の中身を試合のIDに書き換える
            A[i][j] = toId(i, A[i][j]);
        }
        rep(j, N-2) {
            //辺を引く（逆向き）
            to[A[i][j+1]].push_back(A[i][j]);
        }
    }

    int ans = 0;
    rep(i, V) {
        int res = dfs(i);
        if(res == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, res);
    }

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

Measured memory_bytes: 38528
import numpy as np

n, k = map(int, input().split())
l = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1, n):
  start_index = max(i-k, 0)
  dp[i] = np.min(dp[start_index:i]+np.abs(l[start_index:i]-l[i]))

print(dp[-1])

Measured memory_bytes: 22864
# coidng: utf-8

def main():
  count = int(input())
  monsters = list(map(int, input().split()))
  monsters_at_start = sum(monsters)
  heroes = list(map(int, input().split()))
  
  for i, hero in enumerate(heroes):
    if monsters[i] >= hero:
      monsters[i] -= hero
      
    elif monsters[i] < hero:
      hero -= monsters[i]
      monsters[i] = 0
      if monsters[i + 1] >= hero:
        monsters[i + 1] -= hero
        
      else:
        monsters[i + 1] = 0
        
  print(monsters_at_start - sum(monsters))
  
  return 0

if __name__== '__main__':
  main()

Measured memory_bytes: 18624
#木作って終わり、問題文難しい
#

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m,k = map(int, input().split())
    
    def find(par, x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par, par[x])
            return par[x]
    
    def unite(par, x,y):
        x = find(par,x)
        y = find(par,y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    
    def same(par, x,y):
        return find(par, x) == find(par, y)
    
    def size(par, x):
        return -par[find(par, x)]

    friend = [-1]*n
    adj = [0]*n
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1] += 1
        adj[b-1] += 1
        unite(friend, a-1, b-1)

    res = []
    for i in range(n):
        p = size(friend, i) - 1 -adj[i]
        res.append(p)

    for _ in range(k):
        a,b = map(int, input().split())
        if same(friend, a-1, b-1):
            res[a-1] -= 1
            res[b-1] -= 1

    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    set <char> st;
    rep(i,s.length()){
    	st.insert(s[i]);
	}
	set <char>::iterator it;
	lli count=0;
	lli check=0;
	iterate(st){
		count=0;
		rep(i,s.length()){
		if(s[i]==*it)
		count++;
		}
		if(count!=2){
			check=1;
			break;
		}
	}
	if(check==0)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int p, n;
double lans_value, rans_value;
int ans[4];

void stern_brocot(int lnumer, int ldenom, int rnumer, int rdenom){
    // This node corresponds to the interval (lnumer / ldenom, rnumer / rdenom).
    int nnumer = (lnumer + rnumer), ndenom = (ldenom + rdenom);
    if(n < nnumer || n < ndenom) return;
    double pivot = (double)nnumer / ndenom;
    if(pivot < sqrt(p)){
        if(lans_value < pivot){
            lans_value = pivot;
            ans[0] = nnumer;
            ans[1] = ndenom;
        }
        stern_brocot(nnumer, ndenom, rnumer, rdenom);
    }else{
        if(pivot < rans_value){
            rans_value = pivot;
            ans[2] = nnumer;
            ans[3] = ndenom;
        }
        stern_brocot(lnumer, ldenom, nnumer, ndenom);
    }
}

int main(){
    while(1){
        cin >> p >> n;
        if(p==0) break;
        lans_value = 0, rans_value = 1000000;
        stern_brocot(0, 1, 1, 0);
        cout << ans[2] << "/" << ans[3] << " " << ans[0] << "/" << ans[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll fac[200005];
ll rfac[200005];

ll f(ll a, ll x)
{
    ll res = 1;

    while (x > 0)
    {
        if (x & 1)
            res = a * res % mod;

        a = a * a % mod;

        x >>= 1;
    }
    return res;
}

ll nCr(ll n, ll r)
{
    if (n == 0 || r == 0)
        return 1;
    return fac[n] * rfac[r] % mod * rfac[n - r] % mod;
}

ll n, m, k;

int main()
{
    cin >> n >> m >> k;

    ll t = n * m;

    fac[0] = rfac[0] = 1;
    for (ll i = 1; i <= t; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        rfac[i] = f(fac[i], mod - 2);
    }

    ll ans = 0;
    ll tmp = 0;
    for (ll i = 1; i < n; i++)
    {
        tmp = (tmp + i * (n - i) % mod) % mod;
    }

    ans = tmp * m % mod * m % mod * nCr(n * m - 2, k - 2) % mod;

    tmp = 0;
    for (ll i = 1; i < m; i++)
    {
        tmp = (tmp + i * (m - i) % mod) % mod;
    }

    ans = (ans + tmp * n % mod * n % mod * nCr(n * m - 2, k - 2) % mod) % mod;

    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	long int N;
  	cin >>N;
  	long int g[N];
 	for(long int i=0;i<N;i++){
    cin >>g[i];
    }
   long int mini=2000000000,dif=0,maxdif=-2000000000;
  	for(long int i=0;i<N;i++){
      	dif=g[i]-mini;
      	maxdif=max(maxdif,dif);
    	mini=min(mini,g[i]);
    }
  	cout <<maxdif<<endl;
}


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

int main(){
  int X;
  cin >> X;
  int ans = 1;
  for(int i=2;i<=X;i++){
    for(int j=2;j<11;j++){
      if(pow(i,j)>X) break;
      else if(pow(i,j)<=X && pow(i,j)>ans) ans = pow(i,j); 
    }
  }
  cout << ans << endl;
}

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

int main(){
    int N , L[10],otherSum = 0 , longest;
    cin >> N;

    for(int i = 0; i < N;i++){
        cin >> L[i];
    }
    sort(L,L+N,greater<int>());
    longest = L[0];
    for(int i = 1 ;i < N ; i++){
        otherSum += L[i];
    }

    if(longest >= otherSum){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b;
	int i,sum;
	int suma=0,sumb=0;
	for(i=0;i<4;i++){
		scanf("%d",&a);
		suma+=a;
	}
	for(i=0;i<4;i++){
		scanf("%d",&b);
		sumb+=b;
	}
	sum=suma>=sumb?suma:sumb;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 592
pub fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let s = buf.trim();
    let mut p1 = 0;
    let mut p2 = 0;
    for (i, c) in s.char_indices() {
        match (i%2, c) {
            (0, '0') | (1, '1') => p1 += 1,
            (0, '1') | (1, '0') => p2 += 1,
            _ => (),
        }
    }
    println!("{}", std::cmp::min(p1, p2));
}



Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
	string a;
	int j = 0;
	cin >> a;
	for(int i = 0; i < a.size(); i++) {
		j = i;
		while(a[i] == 'C' && j < a.size()) {
			j++;
			if(a[j] == 'F') {
				cout << "Yes" << endl;
				return 0;
			} 
		}
	}
	cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= putStrLn

solve :: String -> String
solve = f . null . filter (odd . length) . group . sort
  where
    f True = "Yes"
    f False = "No"

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(long.Parse).OrderByDescending(x => x).ToArray();

        long cf = 0;
        var q = new Queue<long>();
        q.Enqueue(A.First());
        foreach (var a in A.Skip(1))
        {
            var max = q.Dequeue();
            cf += max;
            q.Enqueue(a);
            q.Enqueue(a);
        }

        Console.WriteLine(cf);
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    REP(i, M) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].pb(v);
    }
    int S, T;
    cin >> S >> T;
    --S; --T;

    int INF = 100000000;
    vector<vector<int>> dp(N, vector<int>(3, INF));
    using tri = tuple<int, int, int>;
    priority_queue<tri, vector<tri>, greater<tri>> q;
    q.push(tri(0, S, 0));
    while (!q.empty()) {
        int d, from, r;
        tie(d, from, r) = q.top();
        q.pop();
        if (dp[from][r] < d) {
            continue;
        }
        for (int to: g[from]) {
            int new_d = d + 1;
            int new_r = (r + 1) % 3;
            if (dp[to][new_r] > new_d) {
                dp[to][new_r] = new_d;
                q.push(tri(new_d, to, new_r));
            }
        }
    }
    /*
    REP(i, N) REP(r, 3) {
        printf("dp[%d][%d] = %d\n", i, r, dp[i][r]);
    }
    */

    if (dp[T][0] != INF) {
        cout << (dp[T][0] / 3) << endl;
    } else {
        cout << (-1) << endl;
    }
    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
//#define TEST


int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\stdout", "w", stdout);
    }

    int N, M;
    cin >> N >> M;
    vector<int> L(M+1), R(M+1);
    vector<pii> v(2*M);
    FOR(i, M) {
        cin >> L[i] >> R[i];
        v[2*i] = make_pair(L[i], 0);
        v[2*i+1] = make_pair(R[i]+1, 1);
    }
    sort(v.begin(), v.end());
    int open = 0;
    int a = -1;
    int sol = 0;
    for(auto p : v){
        if (p.second == 0){
            open++;
            if (open == M){
                a = p.first;
            }
        }
        else{
            if (open == M){
                sol += p.first - a;
            }
            open--;
        }
    }
    cout << sol << '\n';

    if (argc == 2 && atoi(argv[1]) == 123456789)
        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
mincnt = 10e9
for i in A:
    cnt = 0
    while i % 2 == 0:
        cnt += 1
        i = i//2
    mincnt = min(mincnt, cnt)

print(mincnt)

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

using namespace std;

int main(){
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3000
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <cstring>
#include <ctime>
#include <cassert>


#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;


map <ll, ll> dp;
ll solve(ll x)
{
    if (x == 1)
        re 2;
    if (dp[x])
        re dp[x];
    ll ans = 2 * solve(x / 2);
    dp[x] = ans;
    re ans;
}
int main()
{
    //freopen("distance.in", "r", stdin);
    //freopen("distance.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll h;
    cin >> h;
    cout << solve(h) - 1;
}
/// ACTUAL CODE STARTS HERE:
//  I'm red in soul
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

struct DP
{
	ll value;
	bool update;
};

class DPF
{
public:
	DPF()
	{
		cin >> s >> t;
		s.insert(0, " ");
		t.insert(0, " ");
	}
	void Run()
	{
		vector<vector<DP>> dp((ll)s.size() + 1, vector<DP>((ll)t.size() + 1));

		rep(j, 1, (ll)s.size())
		{
			rep(i, 1, (ll)t.size())
			{
				if (s[j] == t[i] && dp[j - 1][i + 1].value < dp[j - 1][i].value + 1)
				{
					dp[j][i + 1].value = dp[j - 1][i].value + 1;
					dp[j][i + 1].update = true;
				}
				else
				{
					dp[j][i + 1].value = max(dp[j - 1][i + 1].value, dp[j][i].value);
					dp[j][i + 1].update = false;
				}
			}
		}

		ll lcs_max = dp[(ll)s.size()-1][(ll)t.size()].value;
		vector<ll> lcs_t;
		repr(j, (ll)dp.size() - 1, 0)
		{
			repr(i, (ll)dp[j].size() - 1, 0)
			{
				if (lcs_t.size() != 0 && lcs_t.back() < i)
					continue;
				if (dp[j][i].update && dp[j][i].value == lcs_max)
				{
					lcs_t.push_back(i - 1);
					lcs_max--;
					break;
				}
			}
		}
		reverse(all(lcs_t));

		for(const auto & e: lcs_t)
			cout << t[e];
	}
private:
	string s;
	string t;
};

int main(void)
{
	DPF dpf;
	dpf.Run();

	return 0;
}


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

vector<unsigned long long> next_p_mod(unsigned N, long long mod) { //next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++)
  {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n, unsigned long long mod) {
   unsigned long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void comb(vector<vector <long long int> > &v,unsigned long long mod) {
  //vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
    return modpow(a, mod - 2, mod);
}


// modinv
/*void modinv(unsigned long long N, unsigned long long mod,unsigned long long *inv) {
 // unsigned long long inv[N] ;
  for (unsigned long long i = 1; i < N; i++) {
    inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    assert(inv[i] * i % mod == 1);
  }
  //return 0;
}*/

int main() {
  ll L,R;
  ll chk=0;
  ll C;
  int checkL,checkR;
//  unsigned long long mod = 1000000000 + 7;
  unsigned long long mod = 2019;
  cin >> L >> R;
  C =L*R%mod;
  checkL=L/2019;
  checkR=R/2019;
//  cout<<"/ "<<checkL<<" : "<<checkR<<endl;
  //cout<<"mod "<<L%mod<<" : "<<R%mod<<endl
  
  if(checkL!=checkR){//
    C=0;
  }else{
    for(int i=L%mod;i<R%mod;i++){
      for(int j=i+1;j<R%mod+1;j++){
        if(C>i*j%mod){
          C=i*j%mod;
        }
      }
    }
  }
  cout<<C<<endl;
  //cout<<L%mod<<endl;
  //cout<<R%mod<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#define LL long long
using namespace std;

int main(){
    int n;
    while(cin>>n){
        int debt=100000;
        while(n--){
            debt*=1.05;
            if(debt%1000!=0){
                debt=(debt/1000+1)*1000;
            }
        }
        cout<<debt<<endl;
    }
    return 0;
}



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

int main(){
	int a[4],b[2];
	for(int i=0;i<4;i++) scanf("%d",a+i);
	for(int i=0;i<2;i++) scanf("%d",b+i);
	sort(a,a+4);
	sort(b,b+2);
	int ans = 0;
	for(int i=3;i>0;i--) ans+=a[i];
	ans+=b[1];
	printf("%d\n",ans);
	return 0;
}	

Measured memory_bytes: 2744
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i) = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

// TODO: write
int main() {
  ll n;cin>>n;
  ll ans = INFL;
  for(ll i = 1;i*i <= n;++i){
    if(n%i == 0)chmin(ans,(ll)(n/i+i-2));
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if(s[0] == s[1] && s[3] == s[2] && s[1] != s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
}



Measured memory_bytes: 256
from collections import deque

num, quan = map(int,input().split())


name = deque([])
time = deque([])
for i in range(num):
    n,t = map(str,input().split())
    name.append(n)
    time.append(int(t))

counttime = 0

while len(time) != 0:
    a = name.popleft()
    name.append(a)
    
    b = time.popleft()
    b = b - quan
    
    if b > 0:
        time.append(b)
        counttime += quan
    else:
        c = b + quan
        counttime += c
        print(name[-1]+" "+str(counttime))
        name.pop()


Measured memory_bytes: 9640
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char c[301]; int K, U, P, C;
int main() {
	scanf("%s", c);
	for (int i = 0; i < strlen(c); i++) {
		if (c[i] == 'K') K++;
		if (c[i] == 'U') U++;
		if (c[i] == 'P') P++;
		if (c[i] == 'C') C++;
	}
	printf("%d\n", min({ K, U, P, C }));
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int A, B;
    cin >> A >> B;
    int ans = max({A + B, A - B, A * B});
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
int main(void){
  char n[100];
  int i=0, len, c=0;
  
  scanf("%s",&n);
  len = strlen(n);
  
  while(1){
    if (n[i] != n[len-1])
      c ++;
    i ++;
    len --;
    if (len - i <= 1)
      break; 
  }
  printf("%d",c);
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 2e6+10;

string s, t;

void solve()
{
	const int n = s.length(), m=t.length();
	int ans = t.length();
	for(int i=0;i+m<=n;++i){
		int cnt=0;
		for(int j=0;j<m;++j)if(s[i+j]!=t[j])cnt++;
		ans=min(ans,cnt);
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s >> t;
	solve();
	return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict
n, W = map(int, input().split())
dd = defaultdict(list)
for i in range(n):
    weight, value = map(int, input().split())
    dd[weight].append(value)

a = min(dd.keys())
b, c, d = a+1, a+2, a+3
Vcum = defaultdict(lambda: [0])
for k in [a, b, c, d]:
    s = 0
    dd[k].sort(reverse=True)
    for val in dd[k]:
        s += val
        Vcum[k].append(s)

ans = 0
for w in range(len(dd[a])+1):
    for x in range(len(dd[b])+1):
        for y in range(len(dd[c])+1):
            for z in range(len(dd[d])+1):
                if W < a*w+b*x+c*y+d*z:
                    continue
                val = Vcum[a][w]+Vcum[b][x]+Vcum[c][y]+Vcum[d][z]
                ans = max(ans, val)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

#define INF (1 << 28)

using namespace std;

#define MAX_V 12000

struct edge{
	int to;
	int cost;
};

typedef pair<int, int> P; // first??????????????¢???second??????????????????

bool used[MAX_V];
vector<edge> G[MAX_V];
int d[MAX_V];

void shortest_path1(int s, int V){ // V???????????°
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // ????????????????°???????????????´??°
	}
}

int cost[5001][5001];

int fare[5001];
int range[5001];

void shortest_path2(int s, int V){
	for(int i = 0; i < V; i++){
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || d[u] < d[add_v])){
				add_v = u;
			}
		} // ??´??°????????????????±????
		
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		
		for(int u = 0; u < V; u++){
			d[u] = min(d[u], d[add_v] + cost[add_v][u]);
		} // ???????????????????????????????°???????????????´??°
	}
}

int main(){
	
	int N, K;
	
	cin >> N >> K;
	
	for(int i = 0; i < N; i++){
		cin >> fare[i] >> range[i];
	}
	
	for(int i = 0; i < K; i++){
		int num1, num2;
		cin >> num1 >> num2;
		num1--;
		num2--;
		
		edge e1, e2;
		e1.to = num2;
		e2.to = num1;
		e1.cost = 1;
		e2.cost = 1;
		G[num1].push_back(e1);
		G[num2].push_back(e2);
	}
	
	for(int i = 0; i < N; i++){
		shortest_path1(i, N);
		for(int j = 0; j < N; j++){
			if(d[j] <= range[i]){
				cost[i][j] = fare[i];
			}else{
				cost[i][j] = INF;
			}
			//cout << cost[i][j] << " ";
		}
		//cout << endl;
	}
	
	shortest_path2(0, N);
	
	cout << d[N - 1] << endl;
	
	
	return 0;
}

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

int main(){
  int ma,ans,cou;
  int me[6] = {500,100,50,10,5,1};
  while(1){
    cou=0;
    cin >> ma;
    if(ma == 0) break;
    ans = 1000 - ma;
    while(ans != 0){
      for(int i=0;i<6;i++){
	if(ans >= me[i]){
	  ans -= me[i];
	  cou++;
	  break;
	}
      }
    }
    cout << cou << endl;
  }
}
  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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 main(){
    vector <ll> A(3);
    rep(i,3) cin >> A[i];
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(),A.end()),A.end());
    cout << A.size() << endl;
    return 0;
}


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

#define MAX_N 300005
#define MOD 998244353

using i64 = long long int;

i64 ncr[MAX_N];

i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) {
    i64 d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

i64 multi_inv(i64 a, i64 md) {
    i64 x, y;
    extgcd(md, a, x, y);
    return (y > 0 ? y : md + y);
}

void set_ncr(i64 n) {
    ncr[0] = 1;
    for (i64 i = 1; i <= n; i++) {
        i64 inv = multi_inv(i, MOD);
        ncr[i] = (n - i + 1) * ncr[i - 1] % MOD;
        ncr[i] = ncr[i] * inv % MOD;
    }
}

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

    set_ncr(n);

    i64 ans = 0;
    for(i64 i=0;i<=n;++i){
        if(k-(a*i)>=0 && (k-a*i)%b==0 && (k-a*i)/b<=n){
            ans = (ans + (ncr[i] * ncr[(k-a*i)/b]) % MOD) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect


from math import factorial
# 組み合わせ
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def main():
    a, b = map(int, input().split())
    ans = max(a + b, a - b, a * b)
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)
# define swap_int(a,b) int t=a;a=b;b=t;

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

   int res=0;
   int v[20],c[20];
   for(int i=0 ; i < n ; i++ ){
      cin >> v[i] ;
   }
   for(int i=0 ; i < n ; i++ ){
      cin >> c[i];
   }
   for(int i=0 ; i < n ; i++ ){
      if((v[i]-c[i])>0)res+=(v[i]-c[i]);
   }
   p(res)
} 

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

using namespace std;

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	vector<int> month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

	int a, b;
	cin >> a >> b;

	int ans = 0;
	for (int i = 1; i <= 12; i++) {
		for (int j = 1; j <= month[i - 1]; j++) {
			ans = i == j ? ans + 1 : ans;

			if (i == a && j == b) {
				cout << ans << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import itertools

N,M,X= (int(x) for x in input().split(' '))
all_book =[]
min_price = 10**5*12 +1
c_lst = []
for i in range(N):
    book_lst= [int(x) for x in input().split(' ')]
    all_book.append(book_lst)
for k in range(1,N+1):
    for m in itertools.combinations(all_book, k):
        if len(m) > 1:
            combined1 = [i*0 for i in range(M+1)]
            for i in range(len(m)):
                combined1 = [x + y for (x, y) in zip(combined1, m[i])]
            c_lst.append(combined1)
        elif len(m) == 1:
            c_lst.append(m[0])
for l in range(len(c_lst)):
    if min(c_lst[l][1:M+1]) >= X:
        if min_price > c_lst[l][0]:
            min_price = c_lst[l][0]
if min_price == 10**5*12 +1:
    min_price = -1

print(min_price)

Measured memory_bytes: 11432
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=300+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int arr[MAXN][MAXN];
int vis[MAXN];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int t=1;
    memset(arr,0,sizeof(arr));
    memset(vis,0,sizeof(vis));
    int NU=0;
    int num=-1;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        bool flag=true;
        for(int j=0;j<s.size();j++)
        {
            if(s[j]=='#')
            {
                flag=false;
                if(num==-1)num=i;
                arr[i][j+1]=t++;
            }
        }
        if(flag)vis[i]=1,NU++;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(arr[i][j]==0)arr[i][j]=arr[i][j-1];
        }
        for(int j=m;j>=1;j--)
        {
            if(arr[i][j]==0)arr[i][j]=arr[i][j+1];
        }
    }
    if(NU)
    {
        for(int i=num-1;i>=1;i--)
        {
            for(int j=1;j<=m;j++)
            {
                arr[i][j]=arr[i+1][j];
            }
        }
        for(int i=num+1;i<=n;i++)
        {
            if(vis[i])
            {
                for(int j=1;j<=m;j++)
                {
                    arr[i][j]=arr[i-1][j];
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;

const int Nmax = 8;
bool graph[Nmax][Nmax];

int dfs(int v,int N, bool visited[Nmax]) {
	bool all_visited = true;

	for (int i = 0; i < N; i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}

	if (all_visited) return 1;

	int ret = 0;

	for (int i = 0; i < N; i++) {
		if (graph[v][i] == false || visited[i]) continue;
		visited[i] = true;
		ret += dfs(i, N, visited);
		visited[i] = false;
	}

	return ret;
}

int main() {
	int N, M, a, b;
	cin >> N >> M;
	bool visited[Nmax];

	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		graph[a-1][b-1] = graph[b-1][a-1] = true;
		visited[i] = false;
	}
	visited[0] = true;

	cout << dfs(0, N, visited) << endl;
	return 0;
}

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

int main(void){
	int N;
	string a;
	set<string> s;

	cin >> N;

	for(int i=0; i < N ;i++){
		cin >> a;
		s.insert(a.c_str());
		a.clear();
	}
	cout << s.size() << endl;




	return 0;
}


Measured memory_bytes: 15556
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
bool isSame(int N)
{
	char s[10];
	sprintf(s,"%d",N);
	int len=strlen(s);
	char ch=s[0];
	for (int i=1;i<len;i++){
		if (ch!=s[i]){
			return false;
		}
	}
	return true;
}
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	while(true){
		if (isSame(N)){
			cout<<N<<endl;
			return 0;
		}else{
			N++;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
G = [[] for n in range(N)]
vc = N*[0]
ec = (N-1)*[0]
h = 1

for n in range(N-1):
  a,b = map(int,input().split())
  G[a-1].append((b-1,n))

for v,g in enumerate(G):
  t = 1
  for b,i in g:
    if vc[v]==t:
      t+=1
    vc[b] = t
    ec[i] = t
    h = max(h,t)
    t+=1

print(h)
for n in range(N-1):
  print(ec[n])

Measured memory_bytes: 32420
#include <stdio.h>
int main()
{
  int a,count=0,i,j,n[100],mini=0,swap;
  scanf("%d",&a);

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

  for(i=0;i<a-1;i++){
    mini=i;
    for(j=i;j<a;j++){
      if(n[j]<n[mini])
	mini=j;
    }
    if(n[i]>n[mini]) count++;
    swap = n[i];
    n[i]=n[mini];
    n[mini]=swap;
  }
  for(i=0;i<a-1;i++)
    {
      printf("%d ",n[i]);
    }
  printf("%d",n[a-1]);
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        double n = double.Parse(Console.ReadLine());
        double[] arr = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray();
        double sum = arr.Sum();
        double sum2 = arr.Select(v => v * v).Sum();//各2乗のsum
        double minXd = sum / n;
        int aI = (int)(minXd + 0.5); //minXdの近いほうの整数値
        double a = (double)aI;
        double yD = n * (a * a) - 2 * sum * a + sum2;
        int y = (int)yD;
        Console.WriteLine(y);
      
    }

  

}




Measured memory_bytes: 13396