akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int N,M;
int dp[1000009];
string S;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)break;
		scanf("%d",&M);
		cin >> S;
		int now=0;
		int ans=0;
		if(S[0]=='I')dp[0]=1;
		else dp[0]=0;
		if((int)S.length()>1&&S[1]=='I')dp[1]=1;
		else dp[1]=0;
		for(int i=2;i<M;i++){
			if(dp[i-2]>0){
				if(S[i-1]=='O'&&S[i]=='I')dp[i]=dp[i-2]+1;
				else if(S[i]=='I')dp[i]=1;
				else dp[i]=0;
			}
			else{
				if(S[i]=='I')dp[i]=1;
				else dp[i]=0;
			}
		}
		for(int i=0;i<M;i++){
			//printf("%d:%d\n",i,dp[i]);
			if(dp[i]>=N+1)ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int main()
{
	int n;
	cin >> n;
	double t, a, b;
	cin >> t >> a;
	double minn = 999999.0;
	int ans;
	for(int i = 1; i <= n; i++){
		cin >> b;
		if(abs(t - (b * 0.006) - a) < minn){
			minn = abs(t - (b * 0.006) - a);
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

int main() {
    int H,W,h,w; cin >> H >> W >> h >> w;

    int ans = (H*W) - (h*W) - (w*(H-h));

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



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

using namespace std;

int n;
vector<double> p;
vector<vector<double>> dp;

int main(){
    cin>>n;
    p.assign(n+1, 0.0);
    dp.assign(n+1, vector<double>(n+1, 0.0));
    for(int i = 1; i <= n; i++){
        cin>>p[i];
    }
    double cur = 1.0;
    for(int i = 0; i <= n; i++){
        cur *= (1.0 - p[i]);
        dp[i][0] = cur;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <=n; j++){
            dp[i][j] = (dp[i-1][j-1] * p[i]) + (dp[i-1][j] * (1.0 - p[i]));
        }
    }
    double res = 0.0;
    for(int i = n/2 + 1; i <= n; i++){
        res += dp[n][i];
    }
    cout<<setprecision(10);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const long double EPS = 1e-9;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<char> &o) {
    string a;
    in >> a;
    for (char c : a) o.insert(c);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//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 ll MAX = 1000000000000;

map<ll, int> factorize(ll n) {
    map<ll, int> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}

ll rec(ll n) {
    auto f = factorize(n);

    int ans = 0;

    for (auto &e : f) {

        ll a = e.first;
        ll b = e.second;

        int r = 1;

        while (r <= b) {
            b -= r;
            r++;
            ans++;
        }
    }

    return ans;

}

int main() {

    ll n;
    cin >> n;

    cout << rec(n) << endl;

}


Measured memory_bytes: 3632
n, m = list(map(int, input().split()))
hm = {i + 1: hi for i, hi in enumerate(list(map(int, input().split())))}
bad_h = []
for i in range(m):
    ai, bi = list(map(int, input().split()))
    if hm[ai] == hm[bi]:
        bad_h.append(ai)
        bad_h.append(bi)
    elif hm[ai] < hm[bi]:
        bad_h.append(ai)
    else:
        bad_h.append(bi)
print(len(hm) - len(set(bad_h)))


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

int main(void)
{
	int coin[301], coin_next[301];
	int i, j, k;
	int paid;
	int a;
	
//	for (i = 1; i <= 300; i++){
//		coin[i] = 1;
//	}
	memset(coin, 0, sizeof(coin));
	coin[0] = 1;

	for (i = 1; i <= 17; i++){					// 種別
//		memcpy(coin_next, coin, sizeof(coin));
		memset(coin_next, 0, sizeof(coin_next));
		for (j = 0; j <= 300 / (i * i); j++){	// 枚数
			for (k = 0; k <= 300; k++){
				if (coin[k] != 0){
					if (k + (i * i) * j <= 300){
	//					coin_next[k + (i * i) * j] += coin[k] + coin[k + (i * i) * j];
						coin_next[k + (i * i) * j] += coin[k];
					}
				}
			}
		}
		memcpy(coin, coin_next, sizeof(coin));

//printf("<%d>", i * i);
		
//for (a = 1; a <= 30; a++){
//	printf("%d ", coin[a]);
//}
//printf("\n");
	}

	while (1){
		scanf("%d", &paid);
		if (paid == 0){
			break;
		}

		printf("%d\n", coin[paid]);
	}
	return (0);
}

Measured memory_bytes: 604
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9+7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void solve() {
	ll n;
	cin >> n;
	Array a(n);
	REP(i, n) cin >> a[i];

	map<ll, ll> mp;
	REP(i, n) mp[a[i]]++;

	ll sum = 0;
	for (auto i : mp) sum += i.second * (i.second - 1) / 2;

	REP(i, n) {
		ll ans = sum;
		ll x = mp[a[i]];
		ans -= x * (x - 1) / 2;
		ans += (x - 1) * (x - 2) / 2;
		cout << ans << en;
	}
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 11136
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int a[101001];
int main()
{
	int n,i,j;
	cin>>n;
	long long s=0,g=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a+0,a+n);
	long long minn=212120012;
	for(i=a[0];i<=a[n-1];i++){
		g=0;
		for(j=0;j<n;j++){
			g+=pow(a[j]-i,2);
		}
		if(minn>g) minn=g;
	}
	cout<<minn;
	return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007 
using namespace std;
int n,i,j,a[3005],x,y,f[3005];
int top,nex[6005],to[6005],fir[3005];
int lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
	return 0;
}
int read(){
	int xx=0,flag=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
	if(ch=='-'){
		flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return flag*xx;
}
int ss(int u,int v){
	f[v]=0;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(to[top1]!=u){
			ss(v,to[top1]);
			if(f[to[top1]]==0&&a[to[top1]]<a[v])
				f[v]=1;
		}
	return 0;
}
int main(){
	n=read();
	for(i=1;i<=n;i++)
		a[i]=read();
	for(i=1;i<n;i++){
		x=read();y=read();
		lj(x,y);
		lj(y,x);
	}
	for(i=1;i<=n;i++){
		ss(i,i);
		if(f[i]==1)
			printf("%d ",i);
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "OK" << endl ; else cout << "NG" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
ll n,m,q ;

ll DFS(vll &a,vll &b,vll &c,vll &d,vll v,ll num){
	v.emplace_back(num) ;
	if(v.size()==n){
		ll res = 0 ;
		for(int i=0;i<q;i++){
			if(v.at(b.at(i)-1)-v.at(a.at(i)-1)==c.at(i)) res += d.at(i) ;
		}
		return res ;
	}else{
		ll res = 0 ;
		for(int i=v.at(v.size()-1);i<=m;i++){
			res = max(res,DFS(a,b,c,d,v,i)) ;
		}
		return res ;
	}
}


int main(){
	cin >> n >> m >> q ;
	vll a(q),b(q),c(q),d(q) ;
	for(int i=0;i<q;i++){
		cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i) ;
	}
	ll ans = 0 ;
	vll v = {} ;
	for(int i=1;i<=m;i++){
		ans = max(ans,DFS(a,b,c,d,v,i)) ;
	}
	cout << ans << endl ;
}



Measured memory_bytes: 3636
import math
import statistics
N = int(input())
A = [int(x) for x in input().split()]
avg = math.floor(statistics.mean(A))
a = 0
b = 0
for i in range(len(A)):
    a += (A[i] - avg)**2
    b += (A[i] - avg - 1)**2
print(min(a,b))

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

#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n'
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define INF 1e+18

using namespace std;
bool dp[100001] ; 
ll res[100001] ; 
ll answer ; 
int main()
{
	ios_base::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	
	int n , W ;
	cin >> n >> W ;
	int a , b ; 
	vector < pii  > v ;
	for(int i = 0 ; i < n ; i++){
		cin >> a >> b ;
		v.pb({a, b}) ;
	}
	sort(all(v)) ; 
	dp[0] = 1 ; 
	for(auto i : v){
		ll weight = i.F ;
		ll value = i.S ; 
		for(int j = W ; j >= weight ; j--){
			if(dp[j - weight]){
				dp[j] = 1 ;
				res[j] = max(res[j] , res[j - weight] + value) ; 
				answer = max(answer , res[j]) ; 
			}
		}
	}
	cout << answer << endl ;
	return 0 ;

}



Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
    int n,d;
    scanf("%d%d",&n,&d);

    if(n % (1+2*d) == 0){
        printf("%d\n", ( n / (1+2*d) ) );
    }else{
        printf("%d\n", ( n / (1+2*d) + 1 ) );
    }

    return 0;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long
  
using namespace std;
  
const int N = 1e3 + 7;
const int mod = 1e9 + 7;

int mx, n, m, q, a[N], b[N], c[N], d[N], vc[N];

void rec( int ind, int x ) {
	vc[ind] = x;
	if ( ind == n ) {
		int cnt = 0;
		for ( int i = 0; i < q; i++ ) {
			if ( vc[b[i]] - vc[a[i]] == c[i] ) {
				cnt += d[i];
			}
		}
		mx = max( mx, cnt );
		return;
	}
	for ( int k = x; k <= m; k++ ) {
		rec( ind + 1, k );
	} 
}

int32_t main() {
    speed;
    cin >> n >> m >> q;
    for ( int i = 0; i < q; i++ ) {
    	cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    for ( int i = 1; i <= m; i++ ) {
    	rec( 1, i );
    }
    cout << mx;
}


Measured memory_bytes: 3676
#include <iostream>
#include <map>
#include <set>
#define ll long long


using namespace std;

ll H, W, N;

int main(){
    cin >> H >> W >> N;
    int a, b;
    map<pair<int, int>, int> mp;

    for (int i = 0; i < N; ++i)
    {
        pair<int, int> p;
        cin >> a >> b;
        mp[pair<int, int>(a-1, b-1) ]++;
        mp[pair<int, int>(a-1, b) ]++;
        mp[pair<int, int>(a, b-1) ]++;
        mp[pair<int, int>(a, b) ]++;
        mp[pair<int, int>(a+1, b+1) ]++;
        mp[pair<int, int>(a+1, b) ]++;
        mp[pair<int, int>(a, b+1) ]++;
        mp[pair<int, int>(a+1, b-1) ]++;
        mp[pair<int, int>(a-1, b+1) ]++;
    }
    ll ans[10] = {0};
    ll size = 0;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr)
    {
        if(itr->first.first > 1 && itr->first.second > 1 && itr->first.first < H && itr->first.second < W ){
            ans[itr->second]++;
            size++;
        }
    }
    ans[0] = (W - 2) * (H - 2) - size;

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


}

Measured memory_bytes: 42496
f = 0
n, m = gets.chomp.split(" ").map(&:to_i)
a = []
n.times do
  a.push(gets.chomp)
end
b = []
m.times do
  b.push(gets.chomp)
end
d = n - m
(0..d).each do |dx|
  (0..d).each do |dy|
    yyy = 0
    (dy..dy+m-1).each do |yy|
      break unless(a[yy][dx..(dx+m-1)] == b[yyy][0..(m-1)])
      yyy += 1
      f = 1 if(yyy == m)
    end
  end
end
puts (f == 1)? "Yes": "No"

Measured memory_bytes: 1788
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstring>
using namespace std;

struct edge {
	int to, cap;
	double cost;
	int rev;
};

const int MAX_V = 210;
const int INF = 1e8;

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

void add_edge(int from, int to, int cap, double cost) {
	G[from].push_back((edge){to, cap, cost, G[to].size()});
	G[to].push_back((edge){from, 0, cost, G[from].size() - 1});
}

int dfs(int v, int t, int f, double x) {
	if (v == t) return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge&e = G[v][i];
		if (!used[e.to] && e.cap > 0 && e.cost <= x) {
			int d = dfs(e.to, t, min(f, e.cap), x);
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t, double x) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF, x);
		if (f == 0) return flow;
		flow += f;
	}
}

int sq(int n) {
	return n * n;
}

int main() {
	int N, M;
	while (cin >> N >> M, N | M) {
		int V = N + M + 2;
		for (int i = 0; i < V; i++) G[i].clear();
		int s = N + M, t = s + 1;

		vector<int> t_xi(N), t_yi(N), t_vi(N);
		vector<int> b_xi(M), b_yi(M);
		for (int i = 0; i < N; i++) {
			cin >> t_xi[i] >> t_yi[i] >> t_vi[i];
		}

		for (int i = 0; i < M; i++) {
			cin >> b_xi[i] >> b_yi[i];
		}
		/*

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				double d = sqrt(sq(t_xi[i] - b_xi[j]) + sq(t_yi[i] - b_yi[j])) / (double)t_vi[i];
				add_edge(i, j + N, 1, d);
			}
		}

		for (int i = 0; i < N; i++) {
			add_edge(s, i, 1, 0.0);
		}

		for (int i = 0; i < M; i++) {
			add_edge(N + i, t, 1, 0.0);
		}
		*/

		double lb = 0.0, ub = 1e6;
		for (int i = 0; i < 100; i++) {
			double mid = (lb + ub) / 2.0;
			for (int i = 0; i < V; i++) G[i].clear();

			for (int i = 0; i < N; i++) {
				for (int j = 0; j < M; j++) {
					double d = sqrt(sq(t_xi[i] - b_xi[j]) + sq(t_yi[i] - b_yi[j])) / (double)t_vi[i];
					add_edge(i, j + N, 1, d);
				}
			}

			for (int i = 0; i < N; i++) {
				add_edge(s, i, 1, 0.0);
			}

			for (int i = 0; i < M; i++) {
				add_edge(N + i, t, 1, 0.0);
			}

			int res = max_flow(s, t, mid);
			if (res == M) {
				ub = mid;
			} else {
				lb = mid;
			}
		}
		cout << fixed << setprecision(10) << ub << endl;
	}
	return 0;
}

Measured memory_bytes: 1928
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let l: Vec<i32> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();

    let x = 4u32.pow(n as u32);
    let mut ans = std::i32::MAX;

    for bit in 0..x {
        let mut sumA = 0i32;
        let mut sumB = 0i32;
        let mut sumC = 0i32;
        let mut cost = 0i32 ;
        let mut t = bit;
        let mut cursor = 0;
        while t > 0 {
            let m = t % 4;
            if m == 1 {
                if sumA > 0 {
                    cost += 10;
                }
                sumA += l[cursor];
            } else if m == 2 {
                if sumB > 0 {
                    cost += 10;
                }
                sumB += l[cursor];
            } else if m == 3 {
                if sumC > 0 {
                    cost += 10;
                }
                sumC += l[cursor];
            }
            t /= 4;
            cursor += 1;
        }
        if sumA == 0 || sumB == 0 || sumC == 0 {
            continue;
        }
        ans = std::cmp::min(ans, cost + (a - sumA).abs() + (b - sumB).abs() + (c - sumC).abs());
    }

    println!("{}", ans);
}


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

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> xt(n);
  vector<int> yt(m);
  int i;
  for(i = 0;i < n;i++){
    cin >> xt[i];
  }
  for(i = 0;i < m;i++){
    cin >> yt[i];
  }
  sort(xt.begin(),xt.end());
  sort(yt.begin(),yt.end());
  if(xt[n-1] < yt[0] && x < yt[0] && xt[n-1] < y){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
ac = [0]*(N+1)
for i in range(N):
    ac[i+1] = ac[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Measured memory_bytes: 7748
#include <stdio.h>

int main(void){
  int i,j,k,n,m,l,a[100][100],b[100][100];
  long int s;
  scanf("%d%d%d",&n,&m,&l);

//行列A
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);

//行列B
  for(i=0;i<m;i++)
    for(j=0;j<l;j++)
      scanf("%d",&b[i][j]);

//行列C
  for(i=0;i<n;i++)
    for(j=0;j<l;j++){
      s = 0;
      for(k=0;k<m;k++)
        s += a[i][k] * b[k][j] ;
      printf("%ld", s);
      if(j+1 == l)
        printf("\n");
      else
        printf(" ");
    }

  return 0;
}



Measured memory_bytes: 2728
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 105;
int t[maxn][maxn],a[maxn][maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
            scanf("%d",&a[i][j]);
    }
    t[1][n] = a[1][n] + a[2][n];
    t[2][n] = a[2][n];
    for(int i=n-1;i>=1;i--)
    {
        t[2][i] = t[2][i+1] + a[2][i];

        t[1][i] = max(t[2][i],t[1][i+1]) + a[1][i];
    }
   /* for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
            printf("%d ",t[i][j]);
        cout<<endl;
    }*/
    printf("%d\n",t[1][1]);
  return 0;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
macro_rules! chmax {
    ($ base : expr ,$ cmp : expr ) => {
        $base = max($base, $cmp);
    };
}
fn main() {
    input! {
        n:usize,
        a:[Usize1;n],
    }
    let mut ans = 0;
    for (i, &x) in a.iter().enumerate() {
        if a[x] == i {
            ans += 1;
        }
    }
    println!("{}", ans / 2);
}


Measured memory_bytes: 3252
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());
		int y = Y/1000;		//1,5,10の和とする
		boolean flag = false;
		sc.close();
		int[] ans = new int[3];
		if (N*10<y){
			//N枚の最高金額がY円以下（不適）
			Arrays.fill(ans, -1);
		}else if(N>y){
			//N枚の最低金額がY円以上（不敵）
			Arrays.fill(ans, -1);
		}else{
			for(int a_1=0; a_1<N+1; a_1++){
				if(flag)break;
				for(int a_2=0;a_1+a_2<N+1;a_2++){
					int a_3 = N - (a_1+a_2);
					int sum = a_1*10 + a_2*5 + a_3;
					if(sum == y){
						ans[0] = a_1;
						ans[1] = a_2;
						ans[2] = a_3;
						flag = true;
						break;
					}
				}
			}
			if(!flag){
				Arrays.fill(ans, -1);
			}
		}
		for(int i : ans){
			System.out.print(i+" ");
		}
		
	}
	
	public static int sum(Integer[] b){
		int sum=0;
		for(int n : b){
			sum += n;
		}
		return sum;
	}
}


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

int K;

int main() {
    cin >> K;
    queue<long long> que;
    for (int i = 1; i < 10; i++) {
        que.push(i);
    }
    for (int i = 0; i < K - 1; i++) {
        long long now = que.front();
        que.pop();
        long long n = now * 10 + (now % 10);

        if (now % 10 != 0) { que.push(n - 1); }
        que.push(n);
        if (now % 10 != 9) { que.push(n + 1); }
    }
    cout << que.front() << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int MAX[500001];
int maxheapify(int);
int i,x,H,r,l,n=0;

int main(void){
  scanf("%d",&x);
  for(i=1;i<=x;i++){
    scanf("%d",&MAX[i]);
  }
  
  for(i=x/2;i>0;i--){
    maxheapify(i);
  }
  
  for(i=1;i<=x;i++){
    printf(" %d",MAX[i]);
  }
  
  printf("\n");
  return 0;
}
  
int maxheapify(i){
  l=2*i;
  r=2*i+1;
  if(l<=x && MAX[l]>MAX[i])H=l;
  else H=i;
  if(r<=x && MAX[r]>MAX[H])H=r;
  if(H!=i){
    n=MAX[i];
    MAX[i]=MAX[H];
    MAX[H]=n;
    return maxheapify(H);
  }
  return 0;
}

Measured memory_bytes: 2548
import java.util.Scanner;
class Main{
	
    public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String A =sc.next();
String B=sc.next();
String C =sc.next();
System.out.println(A.charAt(A.length()-1)==B.charAt(0)&&B.charAt(B.length()-1)==C.charAt(0)?"YES":"NO");
 }
}
  

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"

using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}


typedef pair <int, int> pii;
int n;
vector <int> v;
db res;

void cleanup() {
    return;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    res = v[0];
    for (int i = 1; i < n; i++) {
        res = (res + v[i]) / 2;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
    int tc = 1;
//    cin >> tc;
    while (tc--) {
        solve();
        cleanup();
    }
}


Measured memory_bytes: 256
use std::vec::Vec;
use::std::collections::VecDeque;


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, q) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..n - 1 {
      let v: Vec<usize> = read_vec();
      tree[v[0] - 1].push(v[1]- 1);
      tree[v[1] - 1].push(v[0]- 1);
    }
    let mut value: Vec<usize> = vec![0; n];
    let mut xq: Vec<(usize, usize)> = Vec::new();
    for _ in 0..q {
      let v: Vec<usize> = read_vec();
      xq.push((v[0] - 1, v[1]));
      value[v[0] - 1] += v[1];
    }
      //println!("{:?}", value);
    bfs_dist(n, &tree, &mut value);
      //println!("{:?}", value);

    for i in 0..n {
      print!("{} ", value[i]);
    }
}


fn bfs_dist(n: usize, g: &Vec<Vec<usize>>, value: &mut Vec<usize>) {
  let mut visit = vec![false; n];
  let mut q = VecDeque::new();

  //init
  visit[0] = true;
  q.push_back(0);
  //println!("{:?}", g);
  while let Some(now) = q.pop_front() {
    let back = value[now];
    for &e in &g[now] {
      if !visit[e] {
          visit[e] = true;
          value[e] += back;
          q.push_back(e);
      }
    }
  }
}


Measured memory_bytes: 27584
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N =2e6+200;
template <class Ruby_Rose> inline void read(Ruby_Rose &x)
{
 	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}

int main()
{
	int a, b, c;
	read(a), read(b), read(c);
	if(a+b+c>=22){cout<<"bust\n";
	}
	else cout<<"win";
	return 0;
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			System.out.println((n*(n-1)/2)+(m*(m-1)/2));
			
		}

	}

Measured memory_bytes: 21204
#include<iostream>
#include<string>

using namespace std;

int main(){
    int h, w, n, sr, sc;
    cin >> h >> w >> n >> sr >> sc;
    string s, t;
    cin >> s >> t;
    int p1 = 1;
    int p2 = h;
    int p3 = 1;
    int p4 = w;
    bool f = true;
    for(int i = n - 1; i >= 0; i--){
        if(i < n - 1){
            if(t[i] == 'D'){p1--; p1 = max(p1, 1);}
            else if(t[i] == 'U'){p2++; p2 = min(p2, h);}
            else if(t[i] == 'R'){p3--; p3 = max(p3, 1);}
            else if(t[i] == 'L'){p4++; p4 = min(p4, w);}
        }
        if(s[i] == 'U'){p1++;}
        else if(s[i] == 'D'){p2--;}
        else if(s[i] == 'L'){p3++;}
        else if(s[i] == 'R'){p4--;}
        if(p1 > p2 || p3 > p4){
            f = false;
            break;
        }
    }
    if(sr < p1 || p2 < sr ){ f = false; }
    if(sc < p3 || p4 < sc ){ f = false; }
    cout << (f? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int D;
vector<ll> c(26);
vector<vector<ll>> s;

ll score(vector<int> t){
  vector<ll> last(26,0);
  ll ans=0;
  for(ll i=0;i<D;i++){
    ans+=s.at(i).at(t.at(i));
    last.at(t.at(i))=i+1;
    for(ll j=0;j<26;j++){
      ans-=c.at(j)*((i+1)-last.at(j));
    }
  }
  return ans;
}


int main(){
  cin>>D;
  for(int i=0;i<26;i++){
    cin>>c.at(i);
  }
  s.resize(D);
  for(int i=0;i<D;i++){
    s.at(i).resize(26);
    for(int j=0;j<26;j++){
      cin>>s.at(i).at(j);
    }
  }

  vector<ll> last(26,0);
  vector<int> t(D);
  for(ll i=0;i<D;i++){
    int k=0;
    for(int j=0;j<26;j++){
      if(c.at(j)*((i+1)-last.at(j))-0*s.at(i).at(j)>c.at(k)*((i+1)-last.at(k))-0*s.at(i).at(k)){
        k=j;
      }
    }
    t.at(i)=k;
    last.at(k)=i+1;
    cout<<t.at(i)+1<<endl;
  }
}


Measured memory_bytes: 3724
s = input()
rs = s[::-1]

# 回文チェック
for i in range(len(s)):
    if s[i] != rs[i]:
        print('No')
        exit(0)

# 前半の回文チェック
zs = s[:len(s)//2]
rzs = zs[::-1]
for i in range(len(zs)):
    if zs[i] != rzs[i]:
        print('No')
        exit(0)

# 後半の回文チェック
ks = s[len(s)//2+1:]
rks = ks[::-1]
for i in range(len(ks)):
    if ks[i] != rks[i]:
        print('No')
        exit(0)

print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vdouble = vector<double>;

int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int main(){
	ll H,A,ans=0;
	cin>>H>>A;
	
	REP(i,10000){
		if(H>0){
			ans++;
			H-=A;
		}
		else break;
	}
	
	cout<<ans<<endl;
	
}

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

int main() {
  int N,K,x;
  cin >> N >>K;
  int A= 0;
  for(int i = 0; i<N; i++) {
    cin>>x;
     if(K>2*x){A+=2*x;}
    else{A+=2*(K-x);}
        }
  cout <<A;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
typedef long long int lli;
struct idgate
{
    int L;
    int R;
};
int main(void)
{
    int N, M;
    cin >> N >> M;
    idgate *I;
    I = new idgate[M];
  	int count = 0;

    for (int i = 0; i < M; i++)
    {
        cin >> I[i].L >> I[i].R;
    }  	
  	int maxL=I[0].L;
  	int minR=I[0].R;
    for (int i = 0; i < M; i++)
    {
      if(maxL<I[i].L){
      	maxL = I[i].L;
      }
      if(minR>I[i].R){
      	minR = I[i].R;
      }
    }
  	for (int i = maxL; i <= minR ; i++)
    {
     	count++; 
    }
    cout << count++ << endl;
    return 0;
}

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

string HandleAB(string s) {
	int cnt_a = 0, cnt_b = 0, nxt_b = 0;
	string ans = "";
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'a') {
			cnt_a++;
		} else {
			if (cnt_b == nxt_b) {
				ans += "ab";
				nxt_b = cnt_a;
			}
			++cnt_b;
		}
	}
	return ans;
}

string HandleBA(string s) {
	string ans;
	while (!s.empty()) {
		if (s > ans) {
			ans = s;
		}
		int fst_a = 0;
		for (int i = 0; i < s.length(); ++i) {
			if (s[i] == 'a') {
				fst_a = i;
				break;
			}
		}
		s = s.substr(1, fst_a - 1) + s.substr(fst_a + 1);
	}
	return ans;
}

string Solve(string s) {
	if (s.empty()) {
		return s;
	}
	int break_point = 0;
	int diff = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'a') {
			diff++;
		} else {
			diff--;
		}
		if (diff == 0) {
			break_point = i+1;
			break;
		}
	}
	string suffix = Solve(s.substr(break_point));
	s = s.substr(0, break_point);
	if (s[0] == 'a') {
		s = HandleAB(s) + suffix;
	} else {
		s = HandleBA(s) + suffix;
	}
	if (s > suffix) {
		return s;
	} else {
		return suffix;
	}
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	cout << Solve(s) << endl;
	return 0;
}

Measured memory_bytes: 11008
package main

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

func main() {
	data := []int{}
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		i, _ := strconv.Atoi(sc.Text())
		data = append(data, i)
	}

	// データの中で一番1桁目が1に近いものを選ぶ
	last := 10
	lastMenuIndex := 0
	for i := 0; i < len(data); i++ {
		firstDigit := data[i] % 10
		if firstDigit != 0 && last > firstDigit {
			last = firstDigit
			lastMenuIndex = i
		}
	}

	total := 0
	for i := 0; i < len(data); i++ {
		if i == lastMenuIndex {
			total += data[i]
		} else {
			total += int(math.Ceil(math.Ceil(float64(data[i])/10) * 10))
		}
	}
	fmt.Println(total)
}


Measured memory_bytes: 640
n = int(input())
sortlist = list(map(int,input().split()))

print(' '.join(map(str, sortlist)))
for i in range(1,n):
    temp = sortlist[i]
    if temp < sortlist[i-1]:
        j = i
        while True:
            sortlist[j] = sortlist[j-1]
            j -= 1
            if j ==0 or temp >= sortlist[j-1]:
                break
        sortlist[j] = temp
        print(' '.join(map(str, sortlist)))
    else:
        print(' '.join(map(str, sortlist)))




Measured memory_bytes: 5600
n = int(input())
p_s = [int(v) for v in input().split()]

ans = 0
for i in range(1, n - 1):
  if p_s[i - 1] < p_s[i] < p_s[i + 1] or p_s[i + 1] < p_s[i] < p_s[i - 1]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char a[3001][3001];
ll dp[3001][3001];
#define mm 1000000007
ll path(ll u,ll v,ll n,ll m)
{
    if(u<0 ||v<0 || u>=n || v>=m)
        return 0;
    else if(u==n-1 && v==m-1)
        return 1;
        if(a[u][v]=='#')
            return 0;
        if(dp[u][v]!=-1)
            return dp[u][v];
    return (dp[u][v]=(path(u+1,v,n,m)+path(u,v+1,n,m))%mm);

}
int main()
{

    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {

            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
   // bool status[n][m]={false};
    cout<<path(0,0,n,m);
}


Measured memory_bytes: 74112
#include <stdio.h>

int main( void )
{
	char str[1001] = { 0 };
	int i = 0;
	int sum = 0;
	
	while( 1 ){
		scanf("%c", &str[i]);
		
		if(str[i] == '\n'){
			if(i == 1 && str[0] == '0'){
				break;
			}
			else{
				printf("%d\n", sum);
				sum = 0;
				i = 0;
			}
		}
		else{
			sum += str[i] - 0x30;
			i++;
		}
	}
	
	return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 200010;
int n, a[maxn], p[maxn], f[maxn];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) p[a[i]] = i;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        if (p[i] > p[i-1]) {
            f[i] = f[i-1]+1;
        } else f[i] = 1;
        ans = max(ans, f[i]);
    }
    printf("%d\n", n-ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 != m2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


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

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

  int sum_ali = 0, sum_bob = 0;
  for (int i = 0; i < n; i += 2) sum_ali += a.at(i);
  for (int i = 1; i < n; i += 2) sum_bob += a.at(i);

  cout << sum_ali - sum_bob << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    n,k=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[0]*n
    dp[0]=0
    for i in range(1,n):
        dp[i]=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)])
    print(dp[-1])
if __name__=='__main__':
    main()

Measured memory_bytes: 13980
X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
colored_p = []
colored_q = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else colored_p[len(colored_p) - 1]
    q_min = q[len(q) - 1] if len(q) > 0 else colored_q[len(colored_q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored_p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored_q.append(i)
 
print(sum(p) + sum(q) + sum(colored_p) + sum(colored_q))

Measured memory_bytes: 21552
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[301000],tail,t,c[301000];
long long p[301000],ans,num;
int main()
{
	int i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		c[i]=a[i];
	}
	t=1;num=1;
	for(i=2;i<=n;i++)
	{
		if(a[i]&a[i-1])
		{
			while((a[i]&a[i-1]))
			{
				ans+=num;
				num--;
				a[i-1]=a[i-1]^c[t];
				t++;
			}
			a[i]=a[i-1]^a[i];
			num++;
		}
		else
		{
			a[i]=a[i]^a[i-1];
			num++;
		}
	}
	ans+=(1+num)*num/2;
	cout<<ans;
	return 0;
}

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

class BIT:
    def __init__(self, size):
        self.bit = [0] * (size + 1)
        self.size = size

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.bit[i] += x
            i += i & -i

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = float('inf')
for b in range(1 << N):
    even = []
    odd = []
    for i in range(N):
        if b >> i & 1:  # red
            if i % 2 == 0:
                even.append((A[i], i))
            else:
                odd.append((A[i], i))
        else:  # blue
            if i % 2 == 0:
                odd.append((B[i], i))
            else:
                even.append((B[i], i))
    if len(even) != (N + 1) // 2 or len(odd) != N // 2:
        continue
    even.sort()
    odd.sort()
    num = []
    for i in range(len(odd)):
        num += [even[i], odd[i]]
    if N % 2 == 1:
        num += [even[-1]]
    ok = True
    for i in range(N-1):
        if num[i][0] > num[i+1][0]:
            ok = False
            break
    if not ok:
        continue
    tmp = 0
    bit = BIT(N)
    for i in range(1, N):
        bit.add(i, 1)
    for i in range(N):
        j = num[i][1]
        tmp += bit.sum(j) - i
        bit.add(0, 1)
        bit.add(j, -1)
    ans = min(ans, tmp)
print(ans if ans < float('inf') else -1)

Measured memory_bytes: 55260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;
const int mod = 1'000'000'007;
int main() {
  int N ;
  cin >> N;
  vector<ll> num(N);
  ll sum = 0;
  ll ans = 0;
  rep(i,N){
      cin >> num[i];
      ans = (ans + (ll)num[i]*sum % mod) % mod;
      sum = (sum+num[i]) % mod ;
  }
  
  cout << ans <<  endl;
}



Measured memory_bytes: 4852
function Main(input) {
	var arr = input.split('');
 
  	var year = String(arr[0] + arr[1] + arr[2] + arr[3]);
  	year = "2018";
  	
  	console.log(year + arr[4] + arr[5] +  arr[6] + arr[7] + arr[8] + arr[9]);
}	
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	int goukei;
	
	scanf("%d %d %d %d %d %d" , &c1, &c5, &c10, &c50, &c100, &c500);
	
	goukei = (1 * c1) + (5 * c5) + (10 * c10) + (50 * c50) + (100 * c100) + (500 * c500);
	
	if (goukei >= 1000){
		printf("1\n");
	}
	
	else {
		printf("0\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int n, t, a; cin >> n >> t >> a;

	vector<double>h(n);
	rep(i, n)cin >> h[i];

	vector<int>hl(n);
	rep(i, n) {
		hl[i] = t * 1000.0 - (h[i] * 6.0);
	}
	vector<double>ab(n);
	rep(i, n) {
		ab[i] =	hl[i] - a * 1000.0;
	}

	rep(i, n) {
		if (ab[i] < 0) {
			ab[i] = -1 * ab[i];
		}
	}
	int ans = INF;
	int now = 0;
	rep(i, n) {
		if (ab[i] < ans) {
			now = i;
			ans = ab[i];
		}
	}
	cout << now + 1 << endl;
}


Measured memory_bytes: 256
'use strict'

function main(input) {

    input = input.split(' ').map(v => ~~v)

    let ans = (input[0] + input[1] >= input[2] && input[0] <= input[2]) ? 'YES' : 'NO'
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

struct Point {
    int x, y, gr;
    Point(int x = 0, int y = 0, int gr = 0) : x(x), y(y), gr(gr) {}
};

int n;
Point a[210];
bool f[210];

bool operator< (Point a, Point b) {
    return a.x < b.x;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i].x >> a[i].y;
        a[i].gr = 1;
    }
    FOR(i,n+1,n+n) {
        cin >> a[i].x >> a[i].y;
        a[i].gr = 2;
    }
    sort(a+1, a+n+n+1);
    FOR(i,1,n+n) f[i] = true;
    int res = 0;
    FOR(i,1,n+n)
        if (a[i].gr == 2) {
            int vt = 0;
            int MaxY = -1;
            FOR(j,1,i-1)
                if (a[j].gr == 1 && f[j] && a[j].y < a[i].y) {
                    if (a[j].y > MaxY) {
                        MaxY = a[j].y;
                        vt = j;
                    }
                }
            if (vt) {
                f[vt] = false;
                res++;
            }
        }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  queue<int64_t> q;
  rep(i, 9) { q.push(i + 1); }

  rep(i, K - 1) {
    int64_t v = q.front();
    q.pop();
    int r = v % 10;
    for (int d = -1; d <= 1; d++) {
      int s = r + d;
      if (s < 0 || s > 9) {
        continue;
      }

      q.push(v * 10 + s);
    }
  }
  cout << q.front() << endl;
  return 0;
}

Measured memory_bytes: 5144
#include <stdio.h>
int no_digits(int a)
{
	int num=0;
	while(a!=0)
	{
		a=a/10;
		num++;
	}
	return num;
}
int main()
{
	int n;
	 scanf("%d",&n);
	 int i,count=0;
	 for(i=1;i<=n;i++)
	 {
	 	if(no_digits(i)%2!=0)
	 		count++;
	 }
	 printf("%d\n",count);
	return 0;
}

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

int main(){
  int money;
  bool isFirst = true;
  while(cin >> money, money){
    if(isFirst) isFirst = false;
    else cout << endl;
    int c[4], cnt[4];
    int coin[] = {10, 50, 100, 500};
    for(int i = 0; i < 4; i++) cin >> c[i];
    int sum = 500 * c[3] + 100 * c[2] + 50 * c[1] + 10 * c[0] - money;
    cnt[3] = sum / 500;
    cnt[2] = sum % 500 / 100;
    cnt[1] = sum % 100 / 50;
    cnt[0] = sum % 50 / 10;
    for(int i = 0; i < 4; i++){
      if(c[i] - cnt[i] > 0) cout << coin[i] << " " << c[i] - cnt[i] << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    bool ans = true;

    if ( S[0] != 'A' ) { ans = false; }

    int cnt = 0;
    for ( int i = 2; i < S.length()-1; i++ ) {
        if ( S[i] == 'C' ) { cnt++; }
    }
    if ( cnt != 1 ) { ans = false; }

    cnt = 0;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( isupper(S[i]) ) { cnt++; }
    }
    if ( cnt != 2 ) { ans = false; }

    cout << ( ans ? "AC" : "WA" ) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int n,a[100001],dp[100001],i;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    dp[2]=abs(a[1]-a[2]);
    for(i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], ptr = 1;
vector<int> v[N];
int which[N], ans = 0;

void dfs(int s, int p, int prev){
   which[s] = a[ptr];
   ++ptr;
   ans += min(which[s], prev);
   for(auto i: v[s]){
      if(i != p){
         dfs(i, s, which[s]);
      }
   }
}

int32_t main(){_

   cin>>n;

   for (int i = 0; i < n-1; ++i)
   {
      int x, y;
      cin>>x>>y;
      v[x].pb(y);
      swap(x, y);
      v[x].pb(y);
   }

   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
   }

   sort(a+1, a+n+1);
   reverse(a+1, a+n+1);

   dfs(1, -1, 0);

   cout<<ans<<endl;
   for (int i = 1; i <= n; ++i)
   {
      cout<<which[i]<<' ';
   }

   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 15488