akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
int H, W;
vector<string> S;
vii g;
vector<vector<pair<int, int>>> n;
vii h, w;

void solve() {

	cin >> H >> W;
	S.resize(H);
	g.resize(H);
	h.resize(H);
	w.resize(W);
	n.resize(H);

	for (int i = 0; i < H; i++) {
		cin >> S[i];
		g[i].resize(W);
		n[i].resize(W);
		int tmp = 0;
		int cnt = 0;
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				tmp++;
				h[i].eb(cnt);
				cnt = 0;
				n[i][j].fst = -1;
			}
			else {
				n[i][j].fst = tmp;
				cnt++;
			}
		}
		h[i].eb(cnt);
	}

	for (int i = 0; i < W; i++) {
		int tmp = 0;
		int cnt = 0;
		for (int j = 0; j < H; j++) {
			if (S[j][i] == '#') {
				tmp++;
				w[i].eb(cnt);
				cnt = 0;
				n[j][i].scd = -1;
			}
			else {
				n[j][i].scd = tmp;
				cnt++;
			}
		}
		w[i].eb(cnt);
	}

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int tmp1 = (n[i][j].fst != -1) ? h[i][n[i][j].fst] : 0;
			int tmp2 = (n[i][j].scd != -1) ? w[j][n[i][j].scd] : 0;
			ans = max(ans, tmp1 + tmp2 - 1);
		}
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 83968
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mx 200005
#define ll long long int
#define loop(i, n, a) for (i = a; i < n; ++i)
#define dloop(i, n) for (i = n - 1; i >= 0; --i)
#define test while (t--)
#define all(s) s.begin(), s.end()
#define input(v, n)         \
    for (i = 0; i < n; ++i) \
    {                       \
        cin >> x;           \
        v.pb(x);            \
    }                           
#define display(v, n, a)     \
    for (i = a; i < n; ++i)  \
    {                        \
        cout << v[i] << " "; \
    }                        \
    cout << endl;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
int main()
{
    vi v;
    int i,x;
    input(v,5);
    loop(i,5,0)
    {
        if(v[i]==0)
        break;
    }
    cout<<i+1;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;

void dfs(const string& s, int cnt) {
  if (s.size() == N) {
    cout << s << endl;
    return;
  }

  for (int i = 0; i <= cnt; ++i) {
    char c = 'a' + i;
    dfs(s + c, cnt);
  }
  char c = 'a' + cnt + 1;
  dfs(s + c, cnt + 1);
}

int main() {
  cin >> N;
  string s;
  dfs("a", 0);
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


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

    cout << (a * b % 2 == 0 ? "Even" : "Odd") << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}

template <typename T>
struct SegmentTree{
    using F = function<T(T,T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;

    SegmentTree(){}
    SegmentTree(F f,T ti):f(f),ti(ti){}

    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }

    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }

    void set_val(int k,T x){
        dat[k+=n]=x;
        //dat[k+=n]+=x;
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }

    T query(int a,int b){ //[a,b)
        if(a>=b) return ti;
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    auto f=[](int a,int b){return a+b;};
    vc<SegmentTree<int>> segs;
    rep(i,26){
        SegmentTree<int> seg(f,0);
        vi v(N,0);
        rep(j,N){
            if(int(S[j]-'a')==i){
                v[j]=1;
            }
        }
        seg.build(v);
        segs.eb(seg);
    }
    rep(q,Q){
        int s; cin >> s;
        if(s==1){
            int x; char c; cin >> x >> c;
            x--;
            segs[(int)(S[x]-'a')].set_val(x,0);
            segs[(int)(c-'a')].set_val(x,1);
            S[x]=c;
        } else {
            int a,b; cin >> a >> b;
            a--;
            int cnt=0;
            rep(i,26){
                if(segs[i].query(a,b)>0) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 146160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double h = sc.nextDouble();
		double m = sc.nextDouble();
		double l = (h / 6 + m / 360);
		double s = (m / 30);
		double kakudo = Math.abs(s-l) * Math.PI;
		double ans = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(kakudo));
		System.out.println(ans);
	}
}


Measured memory_bytes: 28892
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

long long powMod(long long x, long long n, long long m) {
    long long res = 1;
    while (n > 0) {
        if ((n & 1) == 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u % m;
}

int main() {

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

    long long ans = (powMod(2, n, MOD) - 1 + MOD) % MOD;

    long long c_left = 1;
    long long c_right = 1;
    for (int i = 0; i < a; i++) {
        c_left = c_left * (n - i) % MOD;
        c_right = c_right * (a - i) % MOD;
    }
    ans = (ans + MOD - c_left * modinv(c_right, MOD) % MOD) % MOD;

    c_left = 1;
    c_right = 1;

    for (int i = 0; i < b; i++) {
        c_left = c_left * (n - i) % MOD;
        c_right = c_right * (b - i) % MOD;
    }
    ans = (ans + MOD - c_left * modinv(c_right, MOD) % MOD) % MOD;
    
    cout << ans << endl;
    
    return 0;
}

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

int main() {
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = (double)w*h/2;
    int num = (w==x*2 && h == y*2) ? 1 : 0;
    printf("%.10f %d\n",ans,num);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,k;
int main(){
	cin>>n>>k;
	if((n-2)*(n-1)/2<k){
		cout<<-1<<endl;
		return 0;
	}
	int nc=(n-1)*(n-2)/2;
	cout<<n-1+nc-k<<endl;
	for(int i=1;i<=n-1;i++){
		cout<<i<<" "<<n<<endl;
	}
	for(int i=1;i<=n-2;i++){
		for(int j=i+1;j<=n-1;j++){
			if(k==nc)break;
			cout<<i<<" "<<j<<endl;
			nc--;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # りストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


n = int(input())
w = [None]*n
for i in range(n):
    w[i] = input()
# print(w)

if has_duplicates2(w):
    print('No')
    exit()

for i in range(n-1):
    #print(w[i][-1], w[i+1][0])
    if w[i][-1] != w[i+1][0]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3832
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b;
    cin>>n>>m;
  cout<<n*(n-1)/2+m*(m-1)/2;
}
 
 
signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int num_1 = sc.nextInt();
        int num_2 = sc.nextInt();
        String ans;
        ans = ((num_1 * num_2) % 2) == 0 ? "Even" : "Odd"; 
        System.out.println(ans);

    }
}


Measured memory_bytes: 21712
#include <bits/stdc++.h> // Replace needed headers for speed up

// -------------8<------- start of library -------8<------------------------
template<typename T>
struct RangeMinimumQuery {
    const T INF;
    int n;
    std::vector<T> val;

    RangeMinimumQuery(int size) : INF(std::numeric_limits<T>::max()), n(1) {
        while (n < size) n <<= 1;
        val.assign(2 * n + 1, INF);
    }
    void update(int idx, T a) {
        idx += n - 1;
        val[idx] = a;
        while (idx > 0) {
            idx = (idx - 1) >> 1;
            val[idx] = std::min(val[idx * 2 + 1], val[idx * 2 + 2]);
        }
    }
    T find(int l, int r) {
        T res = INF;
        l += n - 1;
        r += n - 1;
        while (l < r) {
            if ((l & 1) == 0) res = std::min(res, val[l]);
            if ((r & 1) == 0) res = std::min(res, val[r - 1]);
            l >>= 1;
            r = (r - 1) >> 1;
        }
        return res;
    }
};

// -------------8<------- end of library ---------8-------------------------
int main() {
    int n, q;
    std::cin >> n >> q;

    RangeMinimumQuery<int> rmq(n);
    for (int i = 0, com, x, y; i < q; ++i) {
        std::cin >> com >> x >> y;
        if (com == 0) rmq.update(x, y);
        else std::cout << rmq.find(x, y + 1) << '\n';
    }

    return 0;
}



Measured memory_bytes: 3876
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MAX_DIGIT = 50;
long long dp[100][2]; // dp[上から i 桁まで][ smaller ]

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    for (int d = 0; d < MAX_DIGIT; ++d) {
        long long mask = 1LL<<(MAX_DIGIT - d - 1);
        
        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        
        // X の d 桁目を 0, 1 にしたときのコスト
        long long cost0 = mask * num;
        long long cost1 = mask * (N - num);
        
        // smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        
        // exact -> smaller
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                chmax(dp[d+1][1], dp[d][0] + cost0);
            }
        
            if (K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
            else chmax(dp[d+1][0], dp[d][0] + cost0);
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

Measured memory_bytes: 1024
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n = Scanner.nextInt
	val l = Array.fill(n)(Scanner.nextLong)

	var cnt = 0

	loop(0, n) { i =>
		loop(i+1, n) { j =>
			loop(j+1, n) { k =>
				if (l(i) + l(j) > l(k) && l(j) + l(k) > l(i) && l(k) + l(i) > l(j) &&
						l(i) != l(j) && l(j) != l(k) && l(k) != l(i))
					cnt += 1
			}
		}
	}

	pw.println(cnt)
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54892
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cstdlib>
#include<cmath>

using namespace std;

#define MAX_V 100001
#define INF (1e9 + 1)
#define REP(i,n) for(long long int (i)=0;(i) < (n);(i)++)
#define REV(i,n) for(long long int (i)=(n-1);(i) > -1;(i)--)

int a,b;
char s[100][101];



int main(){
  cin >> a >> b;
  REP(i,100){
     REP(j,100){
       if(i<50) s[i][j] = '.';
       else s[i][j] = '#';
     }
   }


  REP(i,b-1){
    int r = (i / 50)*2;
    int c = (i % 50)*2;
    s[r][c] = '#';
  }
  REP(i,a-1){
    int r = ( i / 50 ) * 2 ;
    int c = (i % 50) * 2;
    s[r+51][c] = '.';
  }

  printf("100 100\n");
  REP(i,100){
    REP(j,100){
      printf("%c",s[i][j]);
    }
    printf("\n");
  }
  return 0;
}

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

int N, A[100000];

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i] *= 2;
    }

    int64_t a = A[0];
    for(int i=1;i<N-1;i++){
        if(i % 2 == 1) a -= A[i];
        else a += A[i];
    }

    vector<int64_t> ans(N);
    ans[0] = (a + A[N-1]) / 2;
    for(int i=1;i<N;i++){
        ans[i] = A[i-1] - ans[i-1];
    }

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

Measured memory_bytes: 2432
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1

for i in range(n):
    ans *= a[i]
    if(ans > 1000000000000000000):
        break
    
if(ans > 1000000000000000000):
    print(-1)
    
else:
    print(ans)


Measured memory_bytes: 84632
n = int(input())
a = list(map(int, input().split()))

for i in range(n-1):
    if a[i] < a[i+1]:
        frag = True
        break
    elif a[i] > a[i+1]:
        frag = False
        break
skip = False
ans = 1

for i in range(n-1):
    beforefrag = frag
    if a[i] > a[i+1]:
        frag = False
    elif a[i] < a[i+1]:
        frag = True
    else:
        continue

    if skip:
        skip = False
        continue

    if beforefrag != frag:
        skip = True
        ans += 1

print(ans)

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

int main () {
  string a ;
  cin >> a ;
  
  int pre = 100 ;
  
  bool x = false ;
  
  for (int i = 0 ; i < a.size() ; i++ ){
    if (a[i] == 'C') {
      pre = i ;
      break ;
    }
  }
  for (int i = pre ; i < a.size(); i++ ){
    if (a[i] == 'F') {
      x = true ;
    }
  }
  if(x) cout << "Yes" << endl ;
  else cout << "No" << endl ;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;


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

	string s;
	cin >> s;

	int l = s.length();
	
	string s0;
	FOR(i, 0, l) {
		if (i % 2 == 0) s0 += "0";
		else s0 += "1";
	}
	//cout << "s0: " << s0 << endl;

	string s1;
	FOR(i, 0, l) {
		if (i % 2 == 0) s1 += "1";
		else s1 += "0";
	}
	//cout << "s1: " << s1 << endl;

	int count0 = 0;
	int count1 = 0;
	FOR(i, 0, l) {
		if (s[i] != s0[i]) count0++;
		if (s[i] != s1[i]) count1++;
	}

	//cout << count0 << " vs " << count1 << endl;
	cout << min(count0, count1) << endl;

}

Measured memory_bytes: 720
def main():
    S = input()
    S1 = S[0]+S[1]
    S2 = S[2]+S[3]
    
    isS1YY = True if 0 <= int(S1)  and int(S1) <= 99 else False
    isS2MM = True if 1 <= int(S2) and int(S2) <= 12 else False
    isS1MM = True if 1 <= int(S1) and int(S1) <= 12 else False
    isS2YY = True if 0 <= int(S2) and int(S2) <= 99 else False
    if isS1YY and isS2MM and isS1MM is False or isS2YY is False:
        print('YYMM')
        exit()
    if isS1MM and isS2YY:
        if isS1YY == False or isS2MM == False:
            print('MMYY')
            exit()
    if isS1YY and isS2MM and isS1MM and isS2YY:
        print('AMBIGUOUS')
        exit()
    print('NA')
main()

Measured memory_bytes: 3064
package main

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

var sc *bufio.Scanner

func nextString() string {
	sc.Scan()
	i := sc.Text()
	return i
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func printList(a []int) {
	for i, v := range a {
		fmt.Print(v)
		if i == len(a)-1 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

func selectionSort(a []int) ([]int, int) {
	count := 0
	minj := 0
	for i := range a {
		minj = i
		for j := i; j < len(a); j++ {
			if a[minj] > a[j] {
				minj = j
			}
		}
		if i != minj {
			a[i], a[minj] = a[minj], a[i]
			count++
		}
	}
	return a, count
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}
	a, count := selectionSort(a)
	printList(a)
	fmt.Println(count)
}



Measured memory_bytes: 1128
n,m = map(int, input().split())

x = n
mm = n

x = n%m
if x ==0:
  print('0')
else:

  for i in range(n):
    dif = x-m

    if dif < 0:
      mm = min(mm,abs(abs(dif)-m),abs(dif))
      break
    mm = min(mm,dif)
    x = dif
  print(mm)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
  int x,y,b,p,n;
 
  cin >> n;
  while(n--){
    cin >> x >> y >> b >> p;
    if(b >= 5 && p >= 2){
      cout << (x*b+y*p)*0.8 << endl;
    }
    else if(b >= 5 && p < 2){
      double tmp = (x*b+y*p);
      p = 2;
      cout << min(tmp,(x*b+y*p)*0.8) << endl;
    }
    else if(b < 5 && p >= 2){
      double tmp = (x*b+y*p);
      b = 5;
      cout << min(tmp,(x*b+y*p)*0.8) << endl;
    }
    else cout << x*b+y*p << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3276
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False

for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        ans+=str(b)
        if c==s[2]:
          ans+="+"
        ans+=str(c)
        if d==s[3]:
          ans+="+"
        ans+=str(d)
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")         
          


Measured memory_bytes: 3064
#include <iostream>
#include <unordered_map>

using namespace std;

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

    unordered_map<long long, int> factor;

    long long a = 2;

    long long N0 = N;

    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    while (N > 1) {
        if (N % a == 0) {
            N /= a;
            factor[a] += 1;
        } else {
            a++;

            if (N < a * a) {
                a = N;
            }
        }
    }

    int count = 0;

    for (const auto& f : factor) {
        int e_sum = f.second;

        int e = 1;

        while (true) {
            if (e_sum >= e) {
                count++;
                e_sum -= e;
                e++;
            } else {
                break;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define PP P<P<int,int>,int >
using namespace std;
priority_queue<PP,V<PP>,greater< PP > > q;
int n;
V<int> v[100005];
P<int,int> f[100005][3];
P<int,int> next(P<int,int> s){
	RE MP(s.F+(s.S==2),(s.S+1)%3);
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m;int x,y;cin>>n>>m;
	FOR(i,1,m){
		cin>>x>>y;
		v[x].PB(y);
	}
	FOR(i,1,n)f[i][0]=f[i][1]=f[i][2]=MP(-1,0);
	int s,t;
	cin>>s>>t;
	q.push(MP(MP(0,0),s));
	while(!q.empty()){
		PP cur=q.top();
		q.pop();
		P<int,int> ne=next(cur.F);
		if(f[cur.S][ne.S].F!=-1)continue;
		if(cur.S==t&&cur.F.S==0){
			cout<<cur.F.F;RE 0;
		}
		f[cur.S][ne.S]=cur.F;
		for(int i=0;i<v[cur.S].size();i++){
			q.push(MP(ne,v[cur.S][i]));
		}
	}
	cout<<-1;
	RE 0;
}




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

using namespace std;


void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> cnt(n+1);
    for (int _ = 0; _ < m; _++) {
        int x,y;
        cin >> x >> y;
        if (x==1) cnt[y]++;
        if (y==n) cnt[x]++;
    }
    for (int i = 2; i < n; i++) {
        if (cnt[i] == 2){
            cout << "POSSIBLE";
            return;
        }
    }
    cout << "IMPOSSIBLE";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
#include <math.h>
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <string>

#define YES "YES"
#define NO "NO"
#define space ' '

using namespace std;

void func();

int main(void)
{
	
	func();

	return 0;
}


void func()
{
	string in;
	cin >> in;

	for (int i = in.size(); i-- > 0;)
	{
		cout << in[i];
	}
	cout << endl;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define se second
#define endl "\n"
#define pii pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define ALL(c) (c).begin(),()c.end() 

#define PI 3.14159265358979323846
const int N = 3e5 + 10;
const int INF=2e9;

int MOD=1e9+7;

void solve() {
    int n,tot=0;
    cin>>n;
    vi v(n);
    
    for(int i=0;i<n;i++)
        cin>>v[i];
        
    for(int i=0;i<n;i++) {
		   int cnt=0;
		    for(int j=0;j<i;j++) {
				   if(v[j]>v[i]){
				      cnt++;
				      break;
				   }
				}
				if(cnt==0)
				   tot++;		    
		}
		
		
		cout<<tot;  
        
	
	}  

int32_t main() {
  cool;
  int t = 1;
  while (t--)
	solve();

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc133/tasks/abc133_d

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll l, r, ans = INFL;
    cin >> l >> r;
    // 2 * 1010 などを考慮しなきゃ駄目
    r = min(r, l + 2019);
    for (ll i = l; i <= r; i++) {
        for (ll j = i + 1; j <= r; j++) {
            ans = min(ans, (i * j) % 2019LL);
            if (ans == 0) {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) printf("Case %d: \n",n);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdin)
#define MAX 1000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n ,r;
    cin>>r>>n;
    if(r<10)
        cout<<(n + (100 *(10 - r)))<<endl;
    else
        cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    int N,K;cin>>N>>K;
    vector<int> pre_vec(K+10,0);
    pre_vec[0] = 1;
    rep(i,N) {
        int a;cin>>a;
        vector<int> new_vec1(K+10,0),new_vec2(K+10,0);
        new_vec1[0] = pre_vec[0];
        rep(j,K) {
            new_vec1[j+1] = (new_vec1[j] + pre_vec[j+1])%MOD;
        }
        new_vec2 = new_vec1;
        rep(j,K-a+1) {
            new_vec2[j+a+1] = (new_vec2[j+a+1] - new_vec1[j] + MOD)%MOD;
        }
        pre_vec = new_vec2;
    }
    cout<<pre_vec[K]<<endl;
}

Measured memory_bytes: 4572
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, M;
    cin >> N >> M;
    cout << int(pow(2, M)) * ((N - M) * 100 + M * 1900) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

ll mod = 998244353;
ll dp[3001][3];
// dp[sum][t]
// [t]
// [0] = only (L)
// [1] = (L, x, ..)
// [2] = (L, .x. ,  R)
int main() {
	int n, s; cin >> n >> s;
	vi a(n); rep(i, n) cin >> a[i];
	for(int i=0;i<n;i++) {
		dp[0][0]++; dp[0][0] %= mod;
		
		
		for(int j=s;~j;j--) {
			if(j + a[i] <= s)
				dp[j+a[i]][1] += dp[j][1], dp[j+a[i]][1] %= mod;
		}
		dp[a[i]][1] += dp[0][0]; dp[a[i]][1] %= mod;
		for(int j=s;~j;j--) {
			dp[j][2] += dp[j][1], dp[j][2] %= mod;
		}
	}
	cout << dp[s][2];
}

Measured memory_bytes: 384
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

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

		while (true) {
			String s = sc.next();
			if (s.equals("0")) {
				break;
			}

			int n = s.length();
			int step = -1;
			boolean flag = false;
			LinkedList<String> list = new LinkedList<String>();
			LinkedList<String> next = new LinkedList<String>();
			HashSet<String> set = new HashSet<String>();

			list.add(s);

			while (!list.isEmpty() && !flag) {
				step++;
				for (String t: list) {
					if (!set.contains(t)) {
						set.add(t);
						char bug[] = t.toCharArray();
						boolean b = true;
						for (int i = 0; i < n - 1; i++) {
							if (bug[i] != bug[i + 1]) {
								b = false;
								char le = bug[i];
								char ri = bug[i + 1];
								char an = le != 'r' && ri != 'r' ? 'r' : le != 'g' && ri != 'g' ? 'g' : 'b';
								bug[i] = an;
								bug[i + 1] = an;
								next.add(new String(bug));
								bug[i] = le;
								bug[i + 1] = ri;
							}
						}
						if (b) {
							flag = true;
							break;
						}
					}
				}
				list = next;
				next = new LinkedList<String>();
			}
			
			System.out.println(flag ? step : "NA");
		}
	}
}

Measured memory_bytes: 61372
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;

int ans=INFTY;
int h,w,k,split[11]={};
int A[11][1005];
//split:横方向の分割を管理
int x,h2,w2,r,m,j,s,s2,z,re,a;
void solve(){
    x=0;
    h2=0;
    w2=0;
    s=w;
    s2=0;
    z=0;
    while(s2<w){
        h2=0;
        while(h2<h){
            m=0;
            r=1;
            j=h2;
            while(split[j]==0){
                j++;
                r++;
            }
            re=0;
            REP(i,w){
                a=0;
                REP(q,r){
                    a+=A[q][i];
                }
                re=max(re,a);
            }
            if(re>k){
                return;
            }
            w2=s2;
            while(w2<w&&m<=k){
                REP(y,r){
                    m+=A[h2+y][w2];
                }
                w2++;
            }
            if(m>k) w2--;
            s=min(s,w2);
            h2+=r;

        }
        s2=s;
        s=w;
        if(s2!=w){
            z++;
        }
        
    }
    REP(p,h-1) z+=split[p];
    ans=min(z,ans); 
}

void splitter(int i){
    if(i<h-1){
        split[i]=0;
        splitter(i+1);
        split[i]=1;
        splitter(i+1);
    }
    else solve();
    return;
}


//縦にしか割れないのであれば貪欲に溶けるので横にどう割るかを全探索する
int main(){
    string s;
    cin>>h>>w>>k;
    REP(i,h){
        cin>>s;
        REP(j,w) A[i][j]=s[j]-'0';
        }

    split[h-1]=1;
    splitter(0);
    cout<<ans<<endl;
}

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

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
	vector<int> nums;
	function<void(int, int, int, int, int)> solve = [&](int dig, int x, int c1, int c2, int c3) {
		if (dig == 10) {
			return;
		} else {
			if (c1 > 0 && c2 > 0 && c3 > 0) {
				nums.push_back(x);
			}
			solve(dig + 1, x * 10 + 7, c1 + 1, c2, c3);
			solve(dig + 1, x * 10 + 5, c1, c2 + 1, c3);
			solve(dig + 1, x * 10 + 3, c1, c2, c3 + 1);
		}
	};
	solve(0, 0, 0, 0, 0);
	sort(nums.begin(), nums.end());
	nums.resize(distance(nums.begin(), unique(nums.begin(), nums.end())));
	int n;
	cin >> n;
	cout << upper_bound(nums.begin(), nums.end(), n) - nums.begin() << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	return 0;
}

Measured memory_bytes: 512
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/09/20 20:59:36
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string o,e; cin>>o>>e;
  for (int i = 0; i < o.size()+e.size(); i++) {
    if (i%2==0)
      cout << o[i/2];
    else
      cout << e[i/2];
  }
  cout << endl;

  return 0;
}


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


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    N, X, Y = map(int,input().split())
    ans = [0] * N # 最短距離が0~Nになるときの数をカウントする用のリスト
    for i in range(1, N + 1): # i<jなるすべての頂点の組について最短距離を求める
        for j in range(i + 1, N + 1):
            dist1 = j - i # 単純にiとjの距離差
            dist2 = abs(X - i) + abs(Y - j) + 1 #
            d = min(dist1, dist2) #最短距離を求める
            ans[d] += 1 # 最短距離がdとなる組の個数を1増やす
    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){
    string S_A,S_B,S_C;
    cin >> S_A >> S_B >> S_C;
    queue<char> a,b,c;
    for(int i=0;i<S_A.size();i++){
        a.push(S_A[i]);
    }
    for(int i=0;i<S_B.size();i++){
        b.push(S_B[i]);
    }
    for(int i=0;i<S_C.size();i++){
        c.push(S_C[i]);
    }
    char next = 'a';
    char ans;
    while(1){
        if(next == 'a'){
            if(a.empty()){
                cout << "A" << endl;
                return 0;
            }
            next = a.front();
            a.pop();
        }
        else if(next == 'b'){
            if(b.empty()){
                cout << "B" << endl;
                return 0;
            }
            next = b.front();
            b.pop();
        }
        else{
            if(c.empty()){
                cout << "C" << endl;
                return 0;
            }
            next = c.front();
            c.pop();
        }
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll a[100010],b[100010];
bool vis[100010]={0};
vector<ll> v1,v2;
ll r1,r2;
int res;
int main()
{
	r1=r2=0;
	cin >>n;
	for (int i=0;i<n;i++) cin >>a[i],r1+=a[i];
	for (int i=0;i<n;i++)
	{
		cin >>b[i],r2+=b[i];
		if (a[i]<b[i]) v1.push_back(b[i]-a[i]);
		else if (a[i]>b[i]) v2.push_back(a[i]-b[i]);
	}
	if (r1<r2)
	{
		cout <<"-1";
		return 0;
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	res=v1.size();
	int t=v2.size();
	for (int i=0;i<v1.size();i++)
	{
		for (int j=v2.size()-1;j>=0;j--)
		{
			vis[j]=1;
			if (v2[j]<v1[i])
			{
				v1[i]-=v2[j];
				v2.pop_back();
			}
			else if (v2[j]==v1[i])
			{
				v2.pop_back();
				v1[i]=0;
				break;
			}
			else
			{
				v2[j]-=v1[i];
				v1[i]=0;
				break;
			}
		}
	}
	res+=count(vis,vis+t,1);
	cout <<res;
	return 0;
}

Measured memory_bytes: 2804
import java.util.*;

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

        int n = scan.nextInt();
        long answer = 0;
        for(int i = 0; i < n; i++){
            answer += scan.nextInt();
            answer --;
        }
        System.out.println(answer);

    }
}


Measured memory_bytes: 26072
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    int m;
    cin >> m;
    vector<string> t(m);
    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int co = 0;
        for (int j = 0; j < n; j++)
        {
            if (s[j] == s[i]) {
                co++;
            }
        }
        for (int k = 0; k < m; k++)
        {
            if (t[k] == s[i]) {
                co--;
            }
        }
        ans = max(ans,co);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

char a[20],b[20],c[20],d[30]="abcdefghijklmnopqrstuvwxyz",e[30]="ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
int x,y,z ;

int main(void){

    scanf ("%s%s%s",a,b,c) ;
    
    for (int i=0; i<30; i++ ){
        
        if ( a[0]==d[i] ){
            x = i ;
        }
        
        if ( b[0]==d[i] ){
            y = i ;
        }
        
        if ( c[0]==d[i] ){
            z = i ; 
        }
        
    }
    
    printf ("%c%c%c",e[x],e[y],e[z]) ;
    
    return 0 ;
    
}

Measured memory_bytes: 128
#include <stdio.h>
 
int egara(char c){
  if( c == 'S') return 0;
  if( c == 'H') return 1;
  if( c == 'C') return 2;
  if( c == 'D') return 3;
  return 0;
}

char Egara(int n){
  if( n == 0) return 'S';
  if( n == 1) return 'H';
  if( n == 2) return 'C';
  if( n == 3) return 'D';
  return 'S';
}
int main(){
  int n,a[4][13],i,j,m;
  char c,d;
  
  for( i = 0; i < 4; i++){
    for( j = 0; j < 13; j++){
      a[i][j]=1;
    }
  }
  scanf("%d\n",&n);
  for( i = 0; i < n; i++){
    scanf("%c %d\n",&c,&m);
    a[egara(c)][m-1]=0;
  }
  
for(i = 0; i < 4; i++){
    for( j = 0; j < 13; j++){
      if(a[i][j])
      
      printf("%c %d\n",Egara(i),j+1);
    }
  }
  return 0;
}



Measured memory_bytes: 2052
#include<iostream>

using namespace std;

int main(){
    int w, d;
    while(cin >> w >> d, w){
        int h[25] = {};
        int ans = 0;
        for(int i = 0; i < w; i++){
            int a;
            cin >> a;
            h[a]++;
            ans += a;
        }
        for(int i = 0; i < d; i++){
            int a;
            cin >> a;
            if(h[a])h[a]--;
            else ans += a;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 2980
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
	int na[1000] = {0};
double sig;
	while (1)
	{
		int n, i;
		double sum = 0;
		memset(na, 0, sizeof(int)*1000);
		
		scanf("%d", &n);
		if (n == 0)
			break;
		
		for (i = 0; i < n; i++)
		{
			int s = 0;
			scanf("%d", &s);
			na[i] = s;
			sum += s;
		}
		//printf("????¨?=%d\n", sum);
		//printf("??????=%d\n", sum/n);
		
		sig = 0;
		for (i = 0; i < n; i++)
		{
			//printf("??????=%d\n", na[i] - (sum/n));
			//printf("?????£=(??????^2)=%.8f\n", pow(na[i] - (sum/n), 2));
			sig += (pow(na[i] - (sum/n), 2));
		}
		//printf("?????£(??2)=%.8f\n", sig / n);
		//printf("?¨??????????(??)=%.8f\n", sqrt(sig / n));
		printf("%.8f\n", sqrt(sig / n));
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;

	cin >> N;

	vector<SINT32> DATA(N);
	vector<SINT32> DP(N);
	
	for (SINT32 i = 0; i < N; i++) {
		cin >> DATA[i];
	}

	DP[0] = 0;
	DP[1] = ABS(DATA[1] - DATA[0]);

	for (SINT32 i = 2; i < N; i++) {
		DP[i] = MIN (DP[i-2] + ABS(DATA[i] - DATA[i-2]),DP[i-1] + ABS(DATA[i] - DATA[i-1]));
	}

	cout << DP[N-1] << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, cnt=0, mx=0;
    cin >> n;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
        if(h[i] >= mx) mx = h[i];
        if(h[i] >= mx) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,p[ohara];
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
unordered_map<ll,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>a>>b;
    rep(i,n)cin>>p[i];
    rep(i,n){
        if(p[i]>a)continue;
        rep(j,n){
            if(a+1<=p[j]&&p[j]<=b){
                rep(k,n){
                    if(mp[i]==1||mp[j]==1||mp[k]==1)continue;
                    if(p[k]>=b+1){
                        ans++;
                        mp[i]=1;
                        mp[j]=1;
                        mp[k]=1;
                    }
                }
            }
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;   cin >> s;
    int K;  cin >> K;
    int n = s.size(); 
    vector<int[4][2]>dp(n+1);   //dp[i][j][k]:=i桁目までで非0がj個k=0:nを超えない　
    dp[0][0][1] = 1;
    rep(i, n)   rep(j, 4)   rep(k, 2){
        int d = s[i] - '0';
        rep(nd, 10){
            int ni = i + 1, nj = j, nk = k;
            if(nd)  nj++;
            if(nj > K)  continue;
            if(k){
                if(nd > d)  continue;
                if(nd < d) nk = 0;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    cout << dp[n][K][0] + dp[n][K][1] << endl;
}


Measured memory_bytes: 256